35 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
64 public $update_main_doc_field;
75 public $phpmin = array(7, 0);
81 public $version =
'dolibarr';
101 public $marge_gauche;
106 public $marge_droite;
127 public $situationinvoice;
143 global $conf, $langs, $mysoc;
146 $langs->loadLangs(array(
"main",
"bills"));
149 $this->
name =
"standard";
150 $this->
description = $langs->trans(
'DocumentModelStandardPDF');
151 $this->update_main_doc_field = 1;
156 $this->page_largeur = $formatarray[
'width'];
157 $this->page_hauteur = $formatarray[
'height'];
158 $this->format = array($this->page_largeur, $this->page_hauteur);
165 $this->emetteur = $mysoc;
166 if (empty($this->emetteur->country_code)) {
167 $this->emetteur->country_code = substr($langs->defaultlang, -2);
171 $this->posxdesc = $this->marge_gauche + 1;
174 $this->tabTitleHeight = 5;
178 $this->tva = array();
179 $this->localtax1 = array();
180 $this->localtax2 = array();
181 $this->atleastoneratenotnull = 0;
182 $this->atleastonediscount = 0;
183 $this->situationinvoice =
false;
199 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
202 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
204 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
206 if (!is_object($outputlangs)) {
207 $outputlangs = $langs;
210 if (!empty($conf->global->MAIN_USE_FPDF)) {
211 $outputlangs->charset_output =
'ISO-8859-1';
215 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
217 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
218 global $outputlangsbis;
219 $outputlangsbis =
new Translate(
'', $conf);
220 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
221 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
224 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
227 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
228 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
232 $realpatharray = array();
233 $this->atleastonephoto =
false;
287 if ($conf->asset->dir_output.
'/asset') {
288 $object->fetch_thirdparty();
291 if ($object->specimen) {
292 $dir = $conf->asset->dir_output.
'/asset';
293 $file = $dir.
"/SPECIMEN.pdf";
296 $dir = $conf->asset->dir_output.
'/asset/'.$objectref;
297 $file = $dir.
"/".$objectref.
".pdf";
299 if (!file_exists($dir)) {
301 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
306 if (file_exists($dir)) {
308 if (!is_object($hookmanager)) {
309 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
312 $hookmanager->initHooks(array(
'pdfgeneration'));
313 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
315 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
318 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
323 $pdf->SetAutoPageBreak(1, 0);
325 $heightforinfotot = 50;
326 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
327 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
329 if (class_exists(
'TCPDF')) {
330 $pdf->setPrintHeader(
false);
331 $pdf->setPrintFooter(
false);
336 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
337 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
338 $tplidx = $pdf->importPage(1);
343 $pdf->SetDrawColor(128, 128, 128);
345 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
346 $pdf->SetSubject($outputlangs->transnoentities(
"PdfTitle"));
347 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
348 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
349 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
351 $pdf->SetCompression(
false);
355 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
358 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
363 'Name' => $this->emetteur->name,
364 'Location' =>
getCountry($this->emetteur->country_code, 0),
366 'ContactInfo' => $this->emetteur->email
368 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
371 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
375 if (!empty($tplidx)) {
376 $pdf->useTemplate($tplidx);
380 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
381 $pdf->SetFont(
'',
'', $default_font_size - 1);
382 $pdf->MultiCell(0, 3,
'');
383 $pdf->SetTextColor(0, 0, 0);
385 $tab_top = 90 + $top_shift;
386 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
387 $tab_height = 130 - $top_shift;
388 $tab_height_newpage = 150;
390 $tab_height_newpage -= $top_shift;
393 $nexY = $tab_top - 1;
396 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
398 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
399 if (!empty($extranote)) {
403 $pagenb = $pdf->getPage();
407 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
408 $pageposbeforenote = $pagenb;
415 $pdf->startTransaction();
417 $pdf->SetFont(
'',
'', $default_font_size - 1);
418 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
420 $pageposafternote = $pdf->getPage();
421 $posyafter = $pdf->GetY();
423 if ($pageposafternote > $pageposbeforenote) {
424 $pdf->rollbackTransaction(
true);
427 while ($pagenb < $pageposafternote) {
430 if (!empty($tplidx)) {
431 $pdf->useTemplate($tplidx);
434 $this->
_pagehead($pdf, $object, 0, $outputlangs);
437 $pdf->setTopMargin($tab_top_newpage);
439 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
443 $pdf->setPage($pageposbeforenote);
444 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
445 $pdf->SetFont(
'',
'', $default_font_size - 1);
446 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
447 $pageposafternote = $pdf->getPage();
449 $posyafter = $pdf->GetY();
451 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
452 $pdf->AddPage(
'',
'',
true);
455 $pdf->setPage($pageposafternote);
456 $pdf->setTopMargin($tab_top_newpage);
458 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
464 $i = $pageposbeforenote;
465 while ($i < $pageposafternote) {
469 $pdf->SetDrawColor(128, 128, 128);
471 if ($i > $pageposbeforenote) {
472 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
473 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
475 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
476 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
480 $pdf->setPageOrientation(
'', 1, 0);
481 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
487 $pdf->setPage($pageposafternote);
488 if (!empty($tplidx)) {
489 $pdf->useTemplate($tplidx);
492 $this->
_pagehead($pdf, $object, 0, $outputlangs);
494 $height_note = $posyafter - $tab_top_newpage;
495 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
498 $pdf->commitTransaction();
499 $posyafter = $pdf->GetY();
500 $height_note = $posyafter - $tab_top;
501 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
504 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
506 $pdf->AddPage(
'',
'',
true);
509 $pdf->setPage($pageposafternote);
510 if (!empty($tplidx)) {
511 $pdf->useTemplate($tplidx);
514 $this->
_pagehead($pdf, $object, 0, $outputlangs);
517 $posyafter = $tab_top_newpage;
521 $tab_height = $tab_height - $height_note;
522 $tab_top = $posyafter + 6;
531 $pdf->startTransaction();
532 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
533 $pdf->rollbackTransaction(
true);
535 $nexY = $tab_top + $this->tabTitleHeight;
538 $pageposbeforeprintlines = $pdf->getPage();
539 $pagenb = $pageposbeforeprintlines;
540 for ($i = 0; $i < $nblines; $i++) {
542 $pdf->SetFont(
'',
'', $default_font_size - 1);
543 $pdf->SetTextColor(0, 0, 0);
546 $imglinesize = array();
547 if (!empty($realpatharray[$i])) {
551 $pdf->setTopMargin($tab_top_newpage);
552 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
553 $pageposbefore = $pdf->getPage();
555 $showpricebeforepagebreak = 1;
560 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
561 $pdf->AddPage(
'',
'',
true);
562 if (!empty($tplidx)) {
563 $pdf->useTemplate($tplidx);
565 $pdf->setPage($pageposbefore + 1);
567 $curY = $tab_top_newpage;
570 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
571 $showpricebeforepagebreak = 1;
573 $showpricebeforepagebreak = 0;
577 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
578 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
580 $posYAfterImage = $curY + $imglinesize[
'height'];
586 $pdf->startTransaction();
588 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
589 $pageposafter = $pdf->getPage();
591 if ($pageposafter > $pageposbefore) {
592 $pdf->rollbackTransaction(
true);
593 $pdf->setPageOrientation(
'', 1, $heightforfooter);
595 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
597 $pageposafter = $pdf->getPage();
598 $posyafter = $pdf->GetY();
600 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
601 if ($i == ($nblines - 1)) {
602 $pdf->AddPage(
'',
'',
true);
603 if (!empty($tplidx)) {
604 $pdf->useTemplate($tplidx);
606 $pdf->setPage($pageposafter + 1);
611 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
612 $showpricebeforepagebreak = 1;
614 $showpricebeforepagebreak = 0;
619 $pdf->commitTransaction();
623 $nexY = $pdf->GetY();
624 $pageposafter = $pdf->getPage();
625 $pdf->setPage($pageposbefore);
626 $pdf->setTopMargin($this->marge_haute);
627 $pdf->setPageOrientation(
'', 1, 0);
630 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
631 $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
634 $pdf->SetFont(
'',
'', $default_font_size - 1);
641 $nexY = max($pdf->GetY(), $nexY);
645 if (!empty($object->lines[$i]->array_options)) {
646 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
648 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
650 $nexY = max($pdf->GetY(), $nexY);
662 'outputlangs' => $outputlangs,
663 'hidedetails' => $hidedetails
665 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
670 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
671 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
672 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
673 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
675 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
678 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
679 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
681 $tvaligne = $sign * $object->lines[$i]->total_tva;
685 $localtax1ligne = $object->lines[$i]->total_localtax1;
686 $localtax2ligne = $object->lines[$i]->total_localtax2;
687 $localtax1_rate = $object->lines[$i]->localtax1_tx;
688 $localtax2_rate = $object->lines[$i]->localtax2_tx;
689 $localtax1_type = $object->lines[$i]->localtax1_type;
690 $localtax2_type = $object->lines[$i]->localtax2_type;
692 if ($object->remise_percent) {
693 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
695 if ($object->remise_percent) {
696 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
698 if ($object->remise_percent) {
699 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
702 $vatrate = (string) $object->lines[$i]->tva_tx;
705 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
706 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
708 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
709 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
713 if ($localtax1_type && $localtax1ligne != 0) {
714 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
716 if ($localtax2_type && $localtax2ligne != 0) {
717 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
720 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
723 if (!isset($this->tva[$vatrate])) {
724 $this->tva[$vatrate] = 0;
726 $this->tva[$vatrate] += $tvaligne;
728 $nexY = max($nexY, $posYAfterImage);
731 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
732 $pdf->setPage($pageposafter);
733 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
735 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
736 $pdf->SetLineStyle(array(
'dash'=>0));
740 while ($pagenb < $pageposafter) {
741 $pdf->setPage($pagenb);
742 if ($pagenb == $pageposbeforeprintlines) {
743 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
745 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
747 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
749 $pdf->setPage($pagenb);
750 $pdf->setPageOrientation(
'', 1, 0);
752 $this->
_pagehead($pdf, $object, 0, $outputlangs);
756 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
757 if ($pagenb == $pageposafter) {
758 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
760 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
762 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
765 if (!empty($tplidx)) {
766 $pdf->useTemplate($tplidx);
770 $this->
_pagehead($pdf, $object, 0, $outputlangs);
776 if ($pagenb == $pageposbeforeprintlines) {
777 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
778 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
780 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
781 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
799 $this->
_pagefoot($pdf, $object, $outputlangs);
800 if (method_exists($pdf,
'AliasNbPages')) {
801 $pdf->AliasNbPages();
806 $pdf->Output($file,
'F');
809 $hookmanager->initHooks(array(
'pdfgeneration'));
810 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
812 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
814 $this->error = $hookmanager->error;
815 $this->errors = $hookmanager->errors;
818 if (!empty($conf->global->MAIN_UMASK)) {
819 @chmod($file, octdec($conf->global->MAIN_UMASK));
822 $this->result = array(
'fullpath'=>$file);
826 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
830 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
846 return parent::liste_modeles($db, $maxfilenamelength);
864 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
874 $currency = !empty($currency) ? $currency : $conf->currency;
878 $pdf->SetTextColor(0, 0, 0);
879 $pdf->SetFont(
'',
'', $default_font_size - 2);
881 if (empty($hidetop)) {
882 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
883 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
884 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
887 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
888 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
891 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
892 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
896 $pdf->SetDrawColor(128, 128, 128);
897 $pdf->SetFont(
'',
'', $default_font_size - 1);
900 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
903 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
905 if (empty($hidetop)) {
906 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
921 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
923 global $conf, $langs;
926 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
933 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
934 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
937 $pdf->SetTextColor(0, 0, 60);
938 $pdf->SetFont(
'',
'B', $default_font_size + 3);
942 $posy = $this->marge_haute;
943 $posx = $this->page_largeur - $this->marge_droite - $w;
945 $pdf->SetXY($this->marge_gauche, $posy);
949 if ($this->emetteur->logo) {
950 $logodir = $conf->mycompany->dir_output;
951 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
952 $logodir = $conf->mycompany->multidir_output[$object->entity];
955 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
957 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
959 if (is_readable($logo)) {
961 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
963 $pdf->SetTextColor(200, 0, 0);
964 $pdf->SetFont(
'',
'B', $default_font_size - 2);
965 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
966 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
969 $text = $this->emetteur->name;
970 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
974 $pdf->SetFont(
'',
'B', $default_font_size + 3);
975 $pdf->SetXY($posx, $posy);
976 $pdf->SetTextColor(0, 0, 60);
977 $title = $outputlangs->transnoentities(
"PdfTitle");
978 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
980 $title .= $outputlangsbis->transnoentities(
"PdfTitle");
982 $pdf->MultiCell($w, 3, $title,
'',
'R');
984 $pdf->SetFont(
'',
'B', $default_font_size);
987 $pdf->SetXY($posx, $posy);
988 $pdf->SetTextColor(0, 0, 60);
989 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref);
990 if ($object->statut == $object::STATUS_DRAFT) {
991 $pdf->SetTextColor(128, 0, 0);
992 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
994 $pdf->MultiCell($w, 4, $textref,
'',
'R');
997 $pdf->SetFont(
'',
'', $default_font_size - 2);
999 if ($object->ref_client) {
1001 $pdf->SetXY($posx, $posy);
1002 $pdf->SetTextColor(0, 0, 60);
1003 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset($object->ref_client),
'',
'R');
1006 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1007 $object->fetch_projet();
1008 if (!empty($object->project->ref)) {
1010 $pdf->SetXY($posx, $posy);
1011 $pdf->SetTextColor(0, 0, 60);
1012 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->projet->title),
'',
'R');
1016 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1017 $object->fetch_projet();
1018 if (!empty($object->project->ref)) {
1019 $outputlangs->load(
"projects");
1021 $pdf->SetXY($posx, $posy);
1022 $pdf->SetTextColor(0, 0, 60);
1023 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1028 $pdf->SetXY($posx, $posy);
1029 $pdf->SetTextColor(0, 0, 60);
1031 $title = $outputlangs->transnoentities(
"Date");
1032 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1033 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
1035 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs),
'',
'R');
1037 if ($object->thirdparty->code_client) {
1039 $pdf->SetXY($posx, $posy);
1040 $pdf->SetTextColor(0, 0, 60);
1041 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1045 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1046 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1047 if (count($arrayidcontact) > 0) {
1048 $usertmp =
new User($this->
db);
1049 $usertmp->fetch($arrayidcontact[0]);
1051 $pdf->SetXY($posx, $posy);
1052 $pdf->SetTextColor(0, 0, 60);
1053 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1061 $current_y = $pdf->getY();
1062 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1063 if ($current_y < $pdf->getY()) {
1064 $top_shift = $pdf->getY() - $current_y;
1069 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1072 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1073 $posy += $top_shift;
1074 $posx = $this->marge_gauche;
1075 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1076 $posx = $this->page_largeur - $this->marge_droite - 80;
1079 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1080 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1084 $pdf->SetTextColor(0, 0, 0);
1085 $pdf->SetFont(
'',
'', $default_font_size - 2);
1086 $pdf->SetXY($posx, $posy - 5);
1087 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
1088 $pdf->SetXY($posx, $posy);
1089 $pdf->SetFillColor(230, 230, 230);
1090 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1091 $pdf->SetTextColor(0, 0, 60);
1094 $pdf->SetXY($posx + 2, $posy + 3);
1095 $pdf->SetFont(
'',
'B', $default_font_size);
1096 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1097 $posy = $pdf->getY();
1100 $pdf->SetXY($posx + 2, $posy);
1101 $pdf->SetFont(
'',
'', $default_font_size - 1);
1102 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
1105 $usecontact =
false;
1106 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
1107 if (count($arrayidcontact) > 0) {
1109 $result = $object->fetch_contact($arrayidcontact[0]);
1113 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
1114 $thirdparty = $object->contact;
1116 $thirdparty = $object->thirdparty;
1119 if (is_object($thirdparty)) {
1123 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1126 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1127 if ($this->page_largeur < 210) {
1130 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1131 $posy += $top_shift;
1132 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1133 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1134 $posx = $this->marge_gauche;
1138 $pdf->SetTextColor(0, 0, 0);
1139 $pdf->SetFont(
'',
'', $default_font_size - 2);
1140 $pdf->SetXY($posx + 2, $posy - 5);
1141 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo").
":", 0,
'L');
1142 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1145 $pdf->SetXY($posx + 2, $posy + 3);
1146 $pdf->SetFont(
'',
'B', $default_font_size);
1147 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0,
'L');
1149 $posy = $pdf->getY();
1152 $pdf->SetFont(
'',
'', $default_font_size - 1);
1153 $pdf->SetXY($posx + 2, $posy);
1154 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
1157 $pdf->SetTextColor(0, 0, 0);
1171 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1173 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1174 return pdf_pagefoot($pdf, $outputlangs,
'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1187 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1189 global $conf, $hookmanager;
1192 $this->defaultContentsFieldsStyle = array(
1194 'padding' => array(1, 0.5, 1, 0.5),
1198 $this->defaultTitlesFieldsStyle = array(
1200 'padding' => array(0.5, 0, 0.5, 0),
1222 $this->cols[
'desc'] = array(
1227 'textkey' =>
'Designation',
1231 'padding' => array(0.5, 0.5, 0.5, 0.5),
1235 'padding' => array(1, 0.5, 1, 1.5),
1241 $this->cols[
'photo'] = array(
1243 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1246 'textkey' =>
'Photo',
1250 'padding' => array(0, 0, 0, 0),
1252 'border-left' =>
false,
1255 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1256 $this->cols[
'photo'][
'status'] =
true;
1261 $this->cols[
'vat'] = array(
1268 'border-left' =>
true,
1271 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1272 $this->cols[
'vat'][
'status'] =
true;
1276 $this->cols[
'subprice'] = array(
1281 'textkey' =>
'PriceUHT'
1283 'border-left' =>
true,
1287 $this->cols[
'qty'] = array(
1294 'border-left' =>
true,
1298 $this->cols[
'progress'] = array(
1303 'textkey' =>
'Progress'
1305 'border-left' =>
true,
1308 if ($this->situationinvoice) {
1309 $this->cols[
'progress'][
'status'] =
true;
1313 $this->cols[
'unit'] = array(
1320 'border-left' =>
true,
1323 $this->cols[
'unit'][
'status'] =
true;
1327 $this->cols[
'discount'] = array(
1332 'textkey' =>
'ReductionShort'
1334 'border-left' =>
true,
1336 if ($this->atleastonediscount) {
1337 $this->cols[
'discount'][
'status'] =
true;
1340 $rank = $rank + 1000;
1341 $this->cols[
'totalexcltax'] = array(
1346 'textkey' =>
'TotalHT'
1348 'border-left' =>
true,
1352 if (!empty($object->lines)) {
1353 $line = reset($object->lines);
1357 $parameters = array(
1358 'object' => $object,
1359 'outputlangs' => $outputlangs,
1360 'hidedetails' => $hidedetails,
1361 'hidedesc' => $hidedesc,
1362 'hideref' => $hideref
1365 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
1368 } elseif (empty($reshook)) {
1369 $this->cols = array_replace($this->cols, $hookmanager->resArray);
1371 $this->cols = $hookmanager->resArray;
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Parent class for documents models.
Class to manage translations.
Class to manage Dolibarr users.
Class to manage PDF template standard_asset.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
__construct($db)
Constructor.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.