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';
92 public $situationinvoice;
108 global $conf, $langs, $mysoc;
111 $langs->loadLangs(array(
"main",
"bills"));
114 $this->
name =
"standard";
115 $this->
description = $langs->trans(
'DocumentModelStandardPDF');
116 $this->update_main_doc_field = 1;
121 $this->page_largeur = $formatarray[
'width'];
122 $this->page_hauteur = $formatarray[
'height'];
123 $this->format = array($this->page_largeur, $this->page_hauteur);
130 $this->emetteur = $mysoc;
131 if (empty($this->emetteur->country_code)) {
132 $this->emetteur->country_code = substr($langs->defaultlang, -2);
136 $this->posxdesc = $this->marge_gauche + 1;
139 $this->tabTitleHeight = 5;
143 $this->tva = array();
144 $this->localtax1 = array();
145 $this->localtax2 = array();
146 $this->atleastoneratenotnull = 0;
147 $this->atleastonediscount = 0;
148 $this->situationinvoice =
false;
164 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
167 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
169 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
171 if (!is_object($outputlangs)) {
172 $outputlangs = $langs;
175 if (!empty($conf->global->MAIN_USE_FPDF)) {
176 $outputlangs->charset_output =
'ISO-8859-1';
180 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
182 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
183 global $outputlangsbis;
184 $outputlangsbis =
new Translate(
'', $conf);
185 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
186 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
189 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
192 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
193 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
197 $realpatharray = array();
198 $this->atleastonephoto =
false;
252 if ($conf->mymodule->dir_output.
'/myobject') {
253 $object->fetch_thirdparty();
256 if ($object->specimen) {
257 $dir = $conf->mymodule->dir_output.
'/myobject';
258 $file = $dir.
"/SPECIMEN.pdf";
261 $dir = $conf->mymodule->dir_output.
'/myobject/'.$objectref;
262 $file = $dir.
"/".$objectref.
".pdf";
264 if (!file_exists($dir)) {
266 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
271 if (file_exists($dir)) {
273 if (!is_object($hookmanager)) {
274 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
277 $hookmanager->initHooks(array(
'pdfgeneration'));
278 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
280 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
283 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
288 $pdf->SetAutoPageBreak(1, 0);
290 $heightforinfotot = 50;
291 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
292 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
294 if (class_exists(
'TCPDF')) {
295 $pdf->setPrintHeader(
false);
296 $pdf->setPrintFooter(
false);
301 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
302 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
303 $tplidx = $pdf->importPage(1);
308 $pdf->SetDrawColor(128, 128, 128);
310 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
311 $pdf->SetSubject($outputlangs->transnoentities(
"PdfTitle"));
312 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
313 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
314 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
316 $pdf->SetCompression(
false);
320 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
323 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
328 'Name' => $this->emetteur->name,
329 'Location' =>
getCountry($this->emetteur->country_code, 0),
330 'Reason' =>
'MYOBJECT',
331 'ContactInfo' => $this->emetteur->email
333 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
336 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
340 if (!empty($tplidx)) {
341 $pdf->useTemplate($tplidx);
345 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
346 $pdf->SetFont(
'',
'', $default_font_size - 1);
347 $pdf->MultiCell(0, 3,
'');
348 $pdf->SetTextColor(0, 0, 0);
350 $tab_top = 90 + $top_shift;
351 $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
352 $tab_height = 130 - $top_shift;
353 $tab_height_newpage = 150;
354 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
355 $tab_height_newpage -= $top_shift;
358 $nexY = $tab_top - 1;
361 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
363 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
364 if (!empty($extranote)) {
368 $pagenb = $pdf->getPage();
372 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
373 $pageposbeforenote = $pagenb;
380 $pdf->startTransaction();
382 $pdf->SetFont(
'',
'', $default_font_size - 1);
383 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
385 $pageposafternote = $pdf->getPage();
386 $posyafter = $pdf->GetY();
388 if ($pageposafternote > $pageposbeforenote) {
389 $pdf->rollbackTransaction(
true);
392 while ($pagenb < $pageposafternote) {
395 if (!empty($tplidx)) {
396 $pdf->useTemplate($tplidx);
398 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
399 $this->
_pagehead($pdf, $object, 0, $outputlangs);
402 $pdf->setTopMargin($tab_top_newpage);
404 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
408 $pdf->setPage($pageposbeforenote);
409 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
410 $pdf->SetFont(
'',
'', $default_font_size - 1);
411 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
412 $pageposafternote = $pdf->getPage();
414 $posyafter = $pdf->GetY();
416 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
417 $pdf->AddPage(
'',
'',
true);
420 $pdf->setPage($pageposafternote);
421 $pdf->setTopMargin($tab_top_newpage);
423 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
429 $i = $pageposbeforenote;
430 while ($i < $pageposafternote) {
434 $pdf->SetDrawColor(128, 128, 128);
436 if ($i > $pageposbeforenote) {
437 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
438 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
440 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
441 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
445 $pdf->setPageOrientation(
'', 1, 0);
446 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
452 $pdf->setPage($pageposafternote);
453 if (!empty($tplidx)) {
454 $pdf->useTemplate($tplidx);
456 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
457 $this->
_pagehead($pdf, $object, 0, $outputlangs);
459 $height_note = $posyafter - $tab_top_newpage;
460 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
463 $pdf->commitTransaction();
464 $posyafter = $pdf->GetY();
465 $height_note = $posyafter - $tab_top;
466 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
469 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
471 $pdf->AddPage(
'',
'',
true);
474 $pdf->setPage($pageposafternote);
475 if (!empty($tplidx)) {
476 $pdf->useTemplate($tplidx);
478 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
479 $this->
_pagehead($pdf, $object, 0, $outputlangs);
482 $posyafter = $tab_top_newpage;
486 $tab_height = $tab_height - $height_note;
487 $tab_top = $posyafter + 6;
496 $pdf->startTransaction();
497 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
498 $pdf->rollbackTransaction(
true);
500 $nexY = $tab_top + $this->tabTitleHeight;
503 $pageposbeforeprintlines = $pdf->getPage();
504 $pagenb = $pageposbeforeprintlines;
505 for ($i = 0; $i < $nblines; $i++) {
507 $pdf->SetFont(
'',
'', $default_font_size - 1);
508 $pdf->SetTextColor(0, 0, 0);
511 $imglinesize = array();
512 if (!empty($realpatharray[$i])) {
516 $pdf->setTopMargin($tab_top_newpage);
517 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
518 $pageposbefore = $pdf->getPage();
520 $showpricebeforepagebreak = 1;
525 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
526 $pdf->AddPage(
'',
'',
true);
527 if (!empty($tplidx)) {
528 $pdf->useTemplate($tplidx);
530 $pdf->setPage($pageposbefore + 1);
532 $curY = $tab_top_newpage;
535 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
536 $showpricebeforepagebreak = 1;
538 $showpricebeforepagebreak = 0;
542 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
543 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
545 $posYAfterImage = $curY + $imglinesize[
'height'];
551 $pdf->startTransaction();
553 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
554 $pageposafter = $pdf->getPage();
556 if ($pageposafter > $pageposbefore) {
557 $pdf->rollbackTransaction(
true);
558 $pdf->setPageOrientation(
'', 1, $heightforfooter);
560 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
562 $pageposafter = $pdf->getPage();
563 $posyafter = $pdf->GetY();
565 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
566 if ($i == ($nblines - 1)) {
567 $pdf->AddPage(
'',
'',
true);
568 if (!empty($tplidx)) {
569 $pdf->useTemplate($tplidx);
571 $pdf->setPage($pageposafter + 1);
576 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
577 $showpricebeforepagebreak = 1;
579 $showpricebeforepagebreak = 0;
584 $pdf->commitTransaction();
588 $nexY = $pdf->GetY();
589 $pageposafter = $pdf->getPage();
590 $pdf->setPage($pageposbefore);
591 $pdf->setTopMargin($this->marge_haute);
592 $pdf->setPageOrientation(
'', 1, 0);
595 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
596 $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
599 $pdf->SetFont(
'',
'', $default_font_size - 1);
606 $nexY = max($pdf->GetY(), $nexY);
610 if (!empty($object->lines[$i]->array_options)) {
611 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
613 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
615 $nexY = max($pdf->GetY(), $nexY);
627 'outputlangs' => $outputlangs,
628 'hidedetails' => $hidedetails
630 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
635 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
636 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
637 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
638 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
640 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
643 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
644 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
646 $tvaligne = $sign * $object->lines[$i]->total_tva;
650 $localtax1ligne = $object->lines[$i]->total_localtax1;
651 $localtax2ligne = $object->lines[$i]->total_localtax2;
652 $localtax1_rate = $object->lines[$i]->localtax1_tx;
653 $localtax2_rate = $object->lines[$i]->localtax2_tx;
654 $localtax1_type = $object->lines[$i]->localtax1_type;
655 $localtax2_type = $object->lines[$i]->localtax2_type;
657 if ($object->remise_percent) {
658 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
660 if ($object->remise_percent) {
661 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
663 if ($object->remise_percent) {
664 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
667 $vatrate = (string) $object->lines[$i]->tva_tx;
670 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
671 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
673 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
674 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
678 if ($localtax1_type && $localtax1ligne != 0) {
679 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
681 if ($localtax2_type && $localtax2ligne != 0) {
682 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
685 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
688 if (!isset($this->tva[$vatrate])) {
689 $this->tva[$vatrate] = 0;
691 $this->tva[$vatrate] += $tvaligne;
693 $nexY = max($nexY, $posYAfterImage);
696 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
697 $pdf->setPage($pageposafter);
698 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
700 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
701 $pdf->SetLineStyle(array(
'dash'=>0));
705 while ($pagenb < $pageposafter) {
706 $pdf->setPage($pagenb);
707 if ($pagenb == $pageposbeforeprintlines) {
708 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
710 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
712 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
714 $pdf->setPage($pagenb);
715 $pdf->setPageOrientation(
'', 1, 0);
716 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
717 $this->
_pagehead($pdf, $object, 0, $outputlangs);
719 if (!empty($tplidx)) {
720 $pdf->useTemplate($tplidx);
724 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
725 if ($pagenb == $pageposafter) {
726 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
728 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
730 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
733 if (!empty($tplidx)) {
734 $pdf->useTemplate($tplidx);
737 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
738 $this->
_pagehead($pdf, $object, 0, $outputlangs);
744 if ($pagenb == $pageposbeforeprintlines) {
745 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
746 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
748 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
749 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
767 $this->
_pagefoot($pdf, $object, $outputlangs);
768 if (method_exists($pdf,
'AliasNbPages')) {
769 $pdf->AliasNbPages();
774 $pdf->Output($file,
'F');
777 $hookmanager->initHooks(array(
'pdfgeneration'));
778 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
780 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
782 $this->error = $hookmanager->error;
783 $this->errors = $hookmanager->errors;
786 if (!empty($conf->global->MAIN_UMASK)) {
787 @chmod($file, octdec($conf->global->MAIN_UMASK));
790 $this->result = array(
'fullpath'=>$file);
794 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
798 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
814 return parent::liste_modeles($db, $maxfilenamelength);
832 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
842 $currency = !empty($currency) ? $currency : $conf->currency;
846 $pdf->SetTextColor(0, 0, 0);
847 $pdf->SetFont(
'',
'', $default_font_size - 2);
849 if (empty($hidetop)) {
850 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
851 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
852 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
855 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
856 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
859 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
860 $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));
864 $pdf->SetDrawColor(128, 128, 128);
865 $pdf->SetFont(
'',
'', $default_font_size - 1);
868 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
871 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
873 if (empty($hidetop)) {
874 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
889 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
891 global $conf, $langs;
894 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
901 if ($object->statut == $object::STATUS_DRAFT &&
getDolGlobalString(
'MYMODULE_DRAFT_WATERMARK')) {
905 $pdf->SetTextColor(0, 0, 60);
906 $pdf->SetFont(
'',
'B', $default_font_size + 3);
910 $posy = $this->marge_haute;
911 $posx = $this->page_largeur - $this->marge_droite - $w;
913 $pdf->SetXY($this->marge_gauche, $posy);
917 if ($this->emetteur->logo) {
918 $logodir = $conf->mycompany->dir_output;
919 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
920 $logodir = $conf->mycompany->multidir_output[$object->entity];
923 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
925 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
927 if (is_readable($logo)) {
929 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
931 $pdf->SetTextColor(200, 0, 0);
932 $pdf->SetFont(
'',
'B', $default_font_size - 2);
933 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
934 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
937 $text = $this->emetteur->name;
938 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
942 $pdf->SetFont(
'',
'B', $default_font_size + 3);
943 $pdf->SetXY($posx, $posy);
944 $pdf->SetTextColor(0, 0, 60);
945 $title = $outputlangs->transnoentities(
"PdfTitle");
946 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
948 $title .= $outputlangsbis->transnoentities(
"PdfTitle");
950 $pdf->MultiCell($w, 3, $title,
'',
'R');
952 $pdf->SetFont(
'',
'B', $default_font_size);
955 $pdf->SetXY($posx, $posy);
956 $pdf->SetTextColor(0, 0, 60);
957 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref);
958 if ($object->statut == $object::STATUS_DRAFT) {
959 $pdf->SetTextColor(128, 0, 0);
960 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
962 $pdf->MultiCell($w, 4, $textref,
'',
'R');
965 $pdf->SetFont(
'',
'', $default_font_size - 2);
967 if ($object->ref_client) {
969 $pdf->SetXY($posx, $posy);
970 $pdf->SetTextColor(0, 0, 60);
971 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset($object->ref_client),
'',
'R');
974 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
975 $object->fetch_projet();
976 if (!empty($object->project->ref)) {
978 $pdf->SetXY($posx, $posy);
979 $pdf->SetTextColor(0, 0, 60);
980 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->projet->title),
'',
'R');
984 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
985 $object->fetch_projet();
986 if (!empty($object->project->ref)) {
987 $outputlangs->load(
"projects");
989 $pdf->SetXY($posx, $posy);
990 $pdf->SetTextColor(0, 0, 60);
991 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
996 $pdf->SetXY($posx, $posy);
997 $pdf->SetTextColor(0, 0, 60);
999 $title = $outputlangs->transnoentities(
"Date");
1000 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1001 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
1003 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs),
'',
'R');
1005 if ($object->thirdparty->code_client) {
1007 $pdf->SetXY($posx, $posy);
1008 $pdf->SetTextColor(0, 0, 60);
1009 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1013 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1014 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1015 if (count($arrayidcontact) > 0) {
1016 $usertmp =
new User($this->
db);
1017 $usertmp->fetch($arrayidcontact[0]);
1019 $pdf->SetXY($posx, $posy);
1020 $pdf->SetTextColor(0, 0, 60);
1021 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1029 $current_y = $pdf->getY();
1030 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1031 if ($current_y < $pdf->getY()) {
1032 $top_shift = $pdf->getY() - $current_y;
1037 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1040 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1041 $posy += $top_shift;
1042 $posx = $this->marge_gauche;
1043 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1044 $posx = $this->page_largeur - $this->marge_droite - 80;
1047 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1048 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1052 $pdf->SetTextColor(0, 0, 0);
1053 $pdf->SetFont(
'',
'', $default_font_size - 2);
1054 $pdf->SetXY($posx, $posy - 5);
1055 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
1056 $pdf->SetXY($posx, $posy);
1057 $pdf->SetFillColor(230, 230, 230);
1058 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1059 $pdf->SetTextColor(0, 0, 60);
1062 $pdf->SetXY($posx + 2, $posy + 3);
1063 $pdf->SetFont(
'',
'B', $default_font_size);
1064 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1065 $posy = $pdf->getY();
1068 $pdf->SetXY($posx + 2, $posy);
1069 $pdf->SetFont(
'',
'', $default_font_size - 1);
1070 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
1073 $usecontact =
false;
1074 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
1075 if (count($arrayidcontact) > 0) {
1077 $result = $object->fetch_contact($arrayidcontact[0]);
1081 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))) {
1082 $thirdparty = $object->contact;
1084 $thirdparty = $object->thirdparty;
1087 if (is_object($thirdparty)) {
1091 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1094 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1095 if ($this->page_largeur < 210) {
1098 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1099 $posy += $top_shift;
1100 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1101 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1102 $posx = $this->marge_gauche;
1106 $pdf->SetTextColor(0, 0, 0);
1107 $pdf->SetFont(
'',
'', $default_font_size - 2);
1108 $pdf->SetXY($posx + 2, $posy - 5);
1109 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo").
":", 0,
'L');
1110 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1113 $pdf->SetXY($posx + 2, $posy + 3);
1114 $pdf->SetFont(
'',
'B', $default_font_size);
1115 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0,
'L');
1117 $posy = $pdf->getY();
1120 $pdf->SetFont(
'',
'', $default_font_size - 1);
1121 $pdf->SetXY($posx + 2, $posy);
1122 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
1125 $pdf->SetTextColor(0, 0, 0);
1139 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1142 $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1143 return pdf_pagefoot($pdf, $outputlangs,
'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1156 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1158 global $conf, $hookmanager;
1161 $this->defaultContentsFieldsStyle = array(
1163 'padding' => array(1, 0.5, 1, 0.5),
1167 $this->defaultTitlesFieldsStyle = array(
1169 'padding' => array(0.5, 0, 0.5, 0),
1191 $this->cols[
'desc'] = array(
1196 'textkey' =>
'Designation',
1200 'padding' => array(0.5, 0.5, 0.5, 0.5),
1204 'padding' => array(1, 0.5, 1, 1.5),
1210 $this->cols[
'photo'] = array(
1212 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1215 'textkey' =>
'Photo',
1219 'padding' => array(0, 0, 0, 0),
1221 'border-left' =>
false,
1224 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1225 $this->cols[
'photo'][
'status'] =
true;
1230 $this->cols[
'vat'] = array(
1237 'border-left' =>
true,
1240 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1241 $this->cols[
'vat'][
'status'] =
true;
1245 $this->cols[
'subprice'] = array(
1250 'textkey' =>
'PriceUHT'
1252 'border-left' =>
true,
1256 $this->cols[
'qty'] = array(
1263 'border-left' =>
true,
1267 $this->cols[
'progress'] = array(
1272 'textkey' =>
'Progress'
1274 'border-left' =>
true,
1277 if ($this->situationinvoice) {
1278 $this->cols[
'progress'][
'status'] =
true;
1282 $this->cols[
'unit'] = array(
1289 'border-left' =>
true,
1291 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1292 $this->cols[
'unit'][
'status'] =
true;
1296 $this->cols[
'discount'] = array(
1301 'textkey' =>
'ReductionShort'
1303 'border-left' =>
true,
1305 if ($this->atleastonediscount) {
1306 $this->cols[
'discount'][
'status'] =
true;
1309 $rank = $rank + 1000;
1310 $this->cols[
'totalexcltax'] = array(
1315 'textkey' =>
'TotalHT'
1317 'border-left' =>
true,
1321 if (!empty($object->lines)) {
1322 $line = reset($object->lines);
1326 $parameters = array(
1327 'object' => $object,
1328 'outputlangs' => $outputlangs,
1329 'hidedetails' => $hidedetails,
1330 'hidedesc' => $hidedesc,
1331 'hideref' => $hideref
1334 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
1337 } elseif (empty($reshook)) {
1338 $this->cols = array_replace($this->cols, $hookmanager->resArray);
1340 $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_myobject.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
__construct($db)
Constructor.
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...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.