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(5, 6);
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);
159 $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
160 $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
161 $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
162 $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
165 $this->emetteur = $mysoc;
166 if (empty($this->emetteur->country_code)) $this->emetteur->country_code = substr($langs->defaultlang, -2);
169 $this->posxdesc = $this->marge_gauche + 1;
172 $this->tabTitleHeight = 5;
176 $this->tva = array();
177 $this->localtax1 = array();
178 $this->localtax2 = array();
179 $this->atleastoneratenotnull = 0;
180 $this->atleastonediscount = 0;
181 $this->situationinvoice =
false;
197 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
200 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
202 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
204 if (!is_object($outputlangs)) $outputlangs = $langs;
206 if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output =
'ISO-8859-1';
209 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
211 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
212 global $outputlangsbis;
213 $outputlangsbis =
new Translate(
'', $conf);
214 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
215 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
218 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
221 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
222 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
226 $realpatharray = array();
227 $this->atleastonephoto =
false;
283 if ($conf->mymodule->dir_output.
'/myobject')
285 $object->fetch_thirdparty();
288 if ($object->specimen)
290 $dir = $conf->mymodule->dir_output.
'/myobject';
291 $file = $dir.
"/SPECIMEN.pdf";
294 $dir = $conf->mymodule->dir_output.
'/myobject/'.$objectref;
295 $file = $dir.
"/".$objectref.
".pdf";
297 if (!file_exists($dir))
301 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
306 if (file_exists($dir))
309 if (!is_object($hookmanager))
311 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
314 $hookmanager->initHooks(array(
'pdfgeneration'));
315 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
317 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
320 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
325 $pdf->SetAutoPageBreak(1, 0);
327 $heightforinfotot = 50;
328 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
329 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
331 if (class_exists(
'TCPDF'))
333 $pdf->setPrintHeader(
false);
334 $pdf->setPrintFooter(
false);
339 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
341 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
342 $tplidx = $pdf->importPage(1);
347 $pdf->SetDrawColor(128, 128, 128);
349 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
350 $pdf->SetSubject($outputlangs->transnoentities(
"PdfTitle"));
351 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
352 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
353 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
354 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(
false);
357 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
360 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
365 'Name' => $this->emetteur->name,
366 'Location' =>
getCountry($this->emetteur->country_code, 0),
367 'Reason' =>
'MYOBJECT',
368 'ContactInfo' => $this->emetteur->email
370 $pdf->setSignature($cert, $cert, $this->emetteur->name,
'', 2, $info);
373 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
377 if (!empty($tplidx)) $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 = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
387 $tab_height = 130 - $top_shift;
388 $tab_height_newpage = 150;
389 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift;
391 $nexY = $tab_top - 1;
394 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
396 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
397 if (!empty($extranote))
402 $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)
425 $pdf->rollbackTransaction(
true);
428 while ($pagenb < $pageposafternote) {
431 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
432 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
434 $pdf->setTopMargin($tab_top_newpage);
436 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
440 $pdf->setPage($pageposbeforenote);
441 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
442 $pdf->SetFont(
'',
'', $default_font_size - 1);
443 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
444 $pageposafternote = $pdf->getPage();
446 $posyafter = $pdf->GetY();
448 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))
450 $pdf->AddPage(
'',
'',
true);
453 $pdf->setPage($pageposafternote);
454 $pdf->setTopMargin($tab_top_newpage);
456 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
462 $i = $pageposbeforenote;
463 while ($i < $pageposafternote) {
467 $pdf->SetDrawColor(128, 128, 128);
469 if ($i > $pageposbeforenote) {
470 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
471 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
473 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
474 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
478 $pdf->setPageOrientation(
'', 1, 0);
479 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
485 $pdf->setPage($pageposafternote);
486 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
487 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
488 $height_note = $posyafter - $tab_top_newpage;
489 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
492 $pdf->commitTransaction();
493 $posyafter = $pdf->GetY();
494 $height_note = $posyafter - $tab_top;
495 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
498 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20)))
501 $pdf->AddPage(
'',
'',
true);
504 $pdf->setPage($pageposafternote);
505 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
506 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
508 $posyafter = $tab_top_newpage;
512 $tab_height = $tab_height - $height_note;
513 $tab_top = $posyafter + 6;
522 $pdf->startTransaction();
523 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
524 $pdf->rollbackTransaction(
true);
526 $nexY = $tab_top + $this->tabTitleHeight;
529 $pageposbeforeprintlines = $pdf->getPage();
530 $pagenb = $pageposbeforeprintlines;
531 for ($i = 0; $i < $nblines; $i++)
534 $pdf->SetFont(
'',
'', $default_font_size - 1);
535 $pdf->SetTextColor(0, 0, 0);
538 $imglinesize = array();
541 $pdf->setTopMargin($tab_top_newpage);
542 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
543 $pageposbefore = $pdf->getPage();
545 $showpricebeforepagebreak = 1;
551 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))
553 $pdf->AddPage(
'',
'',
true);
554 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
555 $pdf->setPage($pageposbefore + 1);
557 $curY = $tab_top_newpage;
560 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
561 $showpricebeforepagebreak = 1;
562 else $showpricebeforepagebreak = 0;
565 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height']))
567 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
569 $posYAfterImage = $curY + $imglinesize[
'height'];
576 $pdf->startTransaction();
578 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
579 $pageposafter = $pdf->getPage();
581 if ($pageposafter > $pageposbefore)
583 $pdf->rollbackTransaction(
true);
584 $pdf->setPageOrientation(
'', 1, $heightforfooter);
586 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
588 $pageposafter = $pdf->getPage();
589 $posyafter = $pdf->GetY();
591 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)))
593 if ($i == ($nblines - 1))
595 $pdf->AddPage(
'',
'',
true);
596 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
597 $pdf->setPage($pageposafter + 1);
602 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
603 $showpricebeforepagebreak = 1;
604 else $showpricebeforepagebreak = 0;
608 $pdf->commitTransaction();
612 $nexY = $pdf->GetY();
613 $pageposafter = $pdf->getPage();
614 $pdf->setPage($pageposbefore);
615 $pdf->setTopMargin($this->marge_haute);
616 $pdf->setPageOrientation(
'', 1, 0);
619 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
620 $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
623 $pdf->SetFont(
'',
'', $default_font_size - 1);
631 $nexY = max($pdf->GetY(), $nexY);
635 if (!empty($object->lines[$i]->array_options)) {
636 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
641 $nexY = max($pdf->GetY(), $nexY);
653 'outputlangs' => $outputlangs,
654 'hidedetails' => $hidedetails
656 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
661 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
662 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent))
664 if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
665 else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
667 if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
668 else $tvaligne = $sign * $object->lines[$i]->total_tva;
671 $localtax1ligne = $object->lines[$i]->total_localtax1;
672 $localtax2ligne = $object->lines[$i]->total_localtax2;
673 $localtax1_rate = $object->lines[$i]->localtax1_tx;
674 $localtax2_rate = $object->lines[$i]->localtax2_tx;
675 $localtax1_type = $object->lines[$i]->localtax1_type;
676 $localtax2_type = $object->lines[$i]->localtax2_type;
678 if ($object->remise_percent) $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
679 if ($object->remise_percent) $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
680 if ($object->remise_percent) $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
682 $vatrate = (string) $object->lines[$i]->tva_tx;
685 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
686 && (!empty($localtax1_rate) || !empty($localtax2_rate)))
689 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
690 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
694 if ($localtax1_type && $localtax1ligne != 0) {
695 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
697 if ($localtax2_type && $localtax2ligne != 0) {
698 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
701 if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate .=
'*';
702 if (!isset($this->tva[$vatrate])) $this->tva[$vatrate] = 0;
703 $this->tva[$vatrate] += $tvaligne;
705 $nexY = max($nexY, $posYAfterImage);
708 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
709 $pdf->setPage($pageposafter);
710 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
712 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
713 $pdf->SetLineStyle(array(
'dash'=>0));
717 while ($pagenb < $pageposafter) {
718 $pdf->setPage($pagenb);
719 if ($pagenb == $pageposbeforeprintlines) {
720 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
722 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
724 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
726 $pdf->setPage($pagenb);
727 $pdf->setPageOrientation(
'', 1, 0);
728 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
731 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
732 if ($pagenb == $pageposafter) {
733 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
735 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
737 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
740 if (!empty($tplidx)) $pdf->useTemplate($tplidx);
742 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->
_pagehead($pdf, $object, 0, $outputlangs);
747 if ($pagenb == $pageposbeforeprintlines)
749 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
750 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
752 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
753 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
771 $this->
_pagefoot($pdf, $object, $outputlangs);
772 if (method_exists($pdf,
'AliasNbPages')) $pdf->AliasNbPages();
776 $pdf->Output($file,
'F');
779 $hookmanager->initHooks(array(
'pdfgeneration'));
780 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
782 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
785 $this->error = $hookmanager->error;
786 $this->errors = $hookmanager->errors;
789 if (!empty($conf->global->MAIN_UMASK))
790 @chmod($file, octdec($conf->global->MAIN_UMASK));
792 $this->result = array(
'fullpath'=>$file);
796 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
800 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
816 return parent::liste_modeles($db, $maxfilenamelength);
834 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis = null)
840 if ($hidetop) $hidetop = -1;
842 $currency = !empty($currency) ? $currency : $conf->currency;
846 $pdf->SetTextColor(0, 0, 0);
847 $pdf->SetFont(
'',
'', $default_font_size - 2);
851 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
852 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
853 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
856 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
857 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
860 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
861 $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));
865 $pdf->SetDrawColor(128, 128, 128);
866 $pdf->SetFont(
'',
'', $default_font_size - 1);
869 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
872 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
874 if (empty($hidetop)) {
875 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
890 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
892 global $conf, $langs;
895 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
902 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK)))
904 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur,
'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
907 $pdf->SetTextColor(0, 0, 60);
908 $pdf->SetFont(
'',
'B', $default_font_size + 3);
912 $posy = $this->marge_haute;
913 $posx = $this->page_largeur - $this->marge_droite - $w;
915 $pdf->SetXY($this->marge_gauche, $posy);
918 if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO))
920 if ($this->emetteur->logo)
922 $logodir = $conf->mycompany->dir_output;
923 if (!empty($conf->mycompany->multidir_output[$object->entity])) $logodir = $conf->mycompany->multidir_output[$object->entity];
924 if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO))
926 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
928 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
930 if (is_readable($logo))
933 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
935 $pdf->SetTextColor(200, 0, 0);
936 $pdf->SetFont(
'',
'B', $default_font_size - 2);
937 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
938 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
941 $text = $this->emetteur->name;
942 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
946 $pdf->SetFont(
'',
'B', $default_font_size + 3);
947 $pdf->SetXY($posx, $posy);
948 $pdf->SetTextColor(0, 0, 60);
949 $title = $outputlangs->transnoentities(
"PdfTitle");
950 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
952 $title .= $outputlangsbis->transnoentities(
"PdfTitle");
954 $pdf->MultiCell($w, 3, $title,
'',
'R');
956 $pdf->SetFont(
'',
'B', $default_font_size);
959 $pdf->SetXY($posx, $posy);
960 $pdf->SetTextColor(0, 0, 60);
961 $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref);
962 if ($object->statut == $object::STATUS_DRAFT)
964 $pdf->SetTextColor(128, 0, 0);
965 $textref .=
' - '.$outputlangs->transnoentities(
"NotValidated");
967 $pdf->MultiCell($w, 4, $textref,
'',
'R');
970 $pdf->SetFont(
'',
'', $default_font_size - 2);
972 if ($object->ref_client)
975 $pdf->SetXY($posx, $posy);
976 $pdf->SetTextColor(0, 0, 60);
977 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset($object->ref_client),
'',
'R');
980 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE))
982 $object->fetch_projet();
983 if (!empty($object->project->ref))
986 $pdf->SetXY($posx, $posy);
987 $pdf->SetTextColor(0, 0, 60);
988 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->projet->title),
'',
'R');
992 if (!empty($conf->global->PDF_SHOW_PROJECT))
994 $object->fetch_projet();
995 if (!empty($object->project->ref))
998 $pdf->SetXY($posx, $posy);
999 $pdf->SetTextColor(0, 0, 60);
1000 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->projet->ref),
'',
'R');
1005 $pdf->SetXY($posx, $posy);
1006 $pdf->SetTextColor(0, 0, 60);
1008 $title = $outputlangs->transnoentities(
"Date");
1009 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1010 $title .=
' - '.$outputlangsbis->transnoentities(
"Date");
1012 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs),
'',
'R');
1014 if ($object->thirdparty->code_client)
1017 $pdf->SetXY($posx, $posy);
1018 $pdf->SetTextColor(0, 0, 60);
1019 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1023 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1025 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1026 if (count($arrayidcontact) > 0)
1028 $usertmp =
new User($this->
db);
1029 $usertmp->fetch($arrayidcontact[0]);
1031 $pdf->SetXY($posx, $posy);
1032 $pdf->SetTextColor(0, 0, 60);
1033 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1041 $current_y = $pdf->getY();
1042 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1043 if ($current_y < $pdf->getY())
1045 $top_shift = $pdf->getY() - $current_y;
1051 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1054 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1055 $posy += $top_shift;
1056 $posx = $this->marge_gauche;
1057 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->page_largeur - $this->marge_droite - 80;
1059 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1060 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1064 $pdf->SetTextColor(0, 0, 0);
1065 $pdf->SetFont(
'',
'', $default_font_size - 2);
1066 $pdf->SetXY($posx, $posy - 5);
1067 $pdf->MultiCell(66, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0,
'L');
1068 $pdf->SetXY($posx, $posy);
1069 $pdf->SetFillColor(230, 230, 230);
1070 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1071 $pdf->SetTextColor(0, 0, 60);
1074 $pdf->SetXY($posx + 2, $posy + 3);
1075 $pdf->SetFont(
'',
'B', $default_font_size);
1076 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1077 $posy = $pdf->getY();
1080 $pdf->SetXY($posx + 2, $posy);
1081 $pdf->SetFont(
'',
'', $default_font_size - 1);
1082 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0,
'L');
1085 $usecontact =
false;
1086 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
1087 if (count($arrayidcontact) > 0)
1090 $result = $object->fetch_contact($arrayidcontact[0]);
1094 if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1095 $thirdparty = $object->contact;
1097 $thirdparty = $object->thirdparty;
1100 if (is_object($thirdparty)) {
1104 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1107 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1108 if ($this->page_largeur < 210) $widthrecbox = 84;
1109 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1110 $posy += $top_shift;
1111 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1112 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx = $this->marge_gauche;
1115 $pdf->SetTextColor(0, 0, 0);
1116 $pdf->SetFont(
'',
'', $default_font_size - 2);
1117 $pdf->SetXY($posx + 2, $posy - 5);
1118 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo").
":", 0,
'L');
1119 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1122 $pdf->SetXY($posx + 2, $posy + 3);
1123 $pdf->SetFont(
'',
'B', $default_font_size);
1124 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0,
'L');
1126 $posy = $pdf->getY();
1129 $pdf->SetFont(
'',
'', $default_font_size - 1);
1130 $pdf->SetXY($posx + 2, $posy);
1131 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
1134 $pdf->SetTextColor(0, 0, 0);
1148 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1151 $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1152 return pdf_pagefoot($pdf, $outputlangs,
'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1165 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1167 global $conf, $hookmanager;
1170 $this->defaultContentsFieldsStyle = array(
1172 'padding' => array(1, 0.5, 1, 0.5),
1176 $this->defaultTitlesFieldsStyle = array(
1178 'padding' => array(0.5, 0, 0.5, 0),
1200 $this->cols[
'desc'] = array(
1205 'textkey' =>
'Designation',
1209 'padding' => array(0.5, 0.5, 0.5, 0.5),
1213 'padding' => array(1, 0.5, 1, 1.5),
1219 $this->cols[
'photo'] = array(
1221 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1224 'textkey' =>
'Photo',
1228 'padding' => array(0, 0, 0, 0),
1230 'border-left' =>
false,
1233 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto))
1235 $this->cols[
'photo'][
'status'] =
true;
1240 $this->cols[
'vat'] = array(
1247 'border-left' =>
true,
1250 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1252 $this->cols[
'vat'][
'status'] =
true;
1256 $this->cols[
'subprice'] = array(
1261 'textkey' =>
'PriceUHT'
1263 'border-left' =>
true,
1267 $this->cols[
'qty'] = array(
1274 'border-left' =>
true,
1278 $this->cols[
'progress'] = array(
1283 'textkey' =>
'Progress'
1285 'border-left' =>
true,
1288 if ($this->situationinvoice)
1290 $this->cols[
'progress'][
'status'] =
true;
1294 $this->cols[
'unit'] = array(
1301 'border-left' =>
true,
1303 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1304 $this->cols[
'unit'][
'status'] =
true;
1308 $this->cols[
'discount'] = array(
1313 'textkey' =>
'ReductionShort'
1315 'border-left' =>
true,
1317 if ($this->atleastonediscount) {
1318 $this->cols[
'discount'][
'status'] =
true;
1321 $rank = $rank + 1000;
1322 $this->cols[
'totalexcltax'] = array(
1327 'textkey' =>
'TotalHT'
1329 'border-left' =>
true,
1333 if (!empty($object->lines)) {
1334 $line = reset($object->lines);
1338 $parameters = array(
1339 'object' => $object,
1340 'outputlangs' => $outputlangs,
1341 'hidedetails' => $hidedetails,
1342 'hidedesc' => $hidedesc,
1343 'hideref' => $hideref
1346 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
1350 } elseif (empty($reshook))
1352 $this->cols = array_replace($this->cols, $hookmanager->resArray);
1354 $this->cols = $hookmanager->resArray;
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
getExtrafieldContent($object, $extrafieldKey)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
write_file($object, $outputlangs, $srctemplatepath= '', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Class to manage PDF template standard_myobject.
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
__construct($db)
Constructor.
Class to manage Dolibarr users.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency= '', $outputlangsbis=null)
Show table for lines.
Parent class for documents models.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
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...
printStdColumnContent($pdf, &$curY, $colKey, $columnText= '')
print standard column content
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
$conf db name
Only used if Module[ID]Name translation string is not found.
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...
$conf db
API class for accounts.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
getColumnStatus($colKey)
get column status from column key
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects 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_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
pdf_build_address($outputlangs, $sourcecompany, $targetcompany= '', $targetcontact= '', $usecontact=0, $mode= 'source', $object=null)
Return a string with full address formated for output on documents.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
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...