33 require_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
34 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
68 public $update_main_doc_field;
79 public $phpmin = array(7, 0);
85 public $version =
'dolibarr';
105 public $marge_gauche;
110 public $marge_droite;
141 global $conf, $langs, $mysoc;
144 $langs->loadLangs(array(
"main",
"bills",
"products"));
147 $this->
name =
"eratosthene";
148 $this->
description = $langs->trans(
'PDFEratostheneDescription');
149 $this->update_main_doc_field = 1;
154 $this->page_largeur = $formatarray[
'width'];
155 $this->page_hauteur = $formatarray[
'height'];
156 $this->format = array($this->page_largeur, $this->page_hauteur);
162 $this->option_logo = 1;
163 $this->option_tva = 1;
164 $this->option_modereg = 1;
165 $this->option_condreg = 1;
166 $this->option_multilang = 1;
167 $this->option_escompte = 0;
168 $this->option_credit_note = 0;
169 $this->option_freetext = 1;
170 $this->option_draft_watermark = 1;
171 $this->watermark =
'';
174 $this->emetteur = $mysoc;
175 if (empty($this->emetteur->country_code)) {
176 $this->emetteur->country_code = substr($langs->defaultlang, -2);
180 $this->posxdesc = $this->marge_gauche + 1;
183 $this->tabTitleHeight = 5;
187 $this->tva = array();
188 $this->tva_array = array();
189 $this->localtax1 = array();
190 $this->localtax2 = array();
191 $this->atleastoneratenotnull = 0;
192 $this->atleastonediscount = 0;
207 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
210 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
212 if (!is_object($outputlangs)) {
213 $outputlangs = $langs;
216 if (!empty($conf->global->MAIN_USE_FPDF)) {
217 $outputlangs->charset_output =
'ISO-8859-1';
221 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
224 if ($object->statut == $object::STATUS_DRAFT &&
getDolGlobalString(
'COMMANDE_DRAFT_WATERMARK')) {
228 global $outputlangsbis;
229 $outputlangsbis =
null;
230 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
231 $outputlangsbis =
new Translate(
'', $conf);
232 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
233 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
236 $nblines = count($object->lines);
239 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
240 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
244 $realpatharray = array();
245 $this->atleastonephoto =
false;
246 if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE)) {
249 for ($i = 0; $i < $nblines; $i++) {
250 if (empty($object->lines[$i]->fk_product)) {
254 $objphoto->fetch($object->lines[$i]->fk_product);
257 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
258 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
260 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
261 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
265 foreach ($pdir as $midir) {
267 if ($conf->entity != $objphoto->entity) {
268 $dir = $conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
270 $dir = $conf->product->dir_output.
'/'.$midir;
273 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
275 if ($obj[
'photo_vignette']) {
276 $filename = $obj[
'photo_vignette'];
278 $filename = $obj[
'photo'];
281 $filename = $obj[
'photo'];
284 $realpath = $dir.$filename;
286 $this->atleastonephoto =
true;
291 if ($realpath && $arephoto) {
292 $realpatharray[$i] = $realpath;
299 if ($conf->commande->multidir_output[$conf->entity]) {
300 $object->fetch_thirdparty();
305 if ($object->specimen) {
306 $dir = $conf->commande->multidir_output[$conf->entity];
307 $file = $dir.
"/SPECIMEN.pdf";
310 $dir = $conf->commande->multidir_output[$object->entity].
"/".$objectref;
311 $file = $dir.
"/".$objectref.
".pdf";
314 if (!file_exists($dir)) {
316 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
321 if (file_exists($dir)) {
323 if (!is_object($hookmanager)) {
324 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
327 $hookmanager->initHooks(array(
'pdfgeneration'));
328 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
330 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
333 $nblines = count($object->lines);
338 $pdf->SetAutoPageBreak(1, 0);
340 $heightforinfotot = 40;
341 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
342 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
344 if (class_exists(
'TCPDF')) {
345 $pdf->setPrintHeader(
false);
346 $pdf->setPrintFooter(
false);
350 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
351 $logodir = $conf->mycompany->dir_output;
352 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
353 $logodir = $conf->mycompany->multidir_output[$object->entity];
355 $pagecount = $pdf->setSourceFile($logodir.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
356 $tplidx = $pdf->importPage(1);
361 $pdf->SetDrawColor(128, 128, 128);
363 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
364 $pdf->SetSubject($outputlangs->transnoentities(
"PdfOrderTitle"));
365 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
366 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
367 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfOrderTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
369 $pdf->SetCompression(
false);
372 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
375 for ($i = 0; $i < $nblines; $i++) {
376 if ($object->lines[$i]->remise_percent) {
377 $this->atleastonediscount++;
384 if (!empty($tplidx)) {
385 $pdf->useTemplate($tplidx);
388 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
389 $pdf->SetFont(
'',
'', $default_font_size - 1);
390 $pdf->MultiCell(0, 3,
'');
391 $pdf->SetTextColor(0, 0, 0);
394 $tab_top = 90 + $top_shift;
395 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
397 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
400 $height_incoterms = 0;
402 $desc_incoterms = $object->getIncotermsForPDF();
403 if ($desc_incoterms) {
406 $pdf->SetFont(
'',
'', $default_font_size - 1);
407 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
408 $nexY = max($pdf->GetY(), $nexY);
409 $height_incoterms = $nexY - $tab_top;
412 $pdf->SetDrawColor(192, 192, 192);
413 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
415 $tab_top = $nexY + 6;
420 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
421 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
423 if (is_object($object->thirdparty)) {
424 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
425 $salerepobj =
new User($this->
db);
426 $salerepobj->fetch($salereparray[0][
'id']);
427 if (!empty($salerepobj->signature)) {
428 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
434 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
435 if (!empty($extranote)) {
439 $pagenb = $pdf->getPage();
443 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
444 $pageposbeforenote = $pagenb;
451 $pdf->startTransaction();
453 $pdf->SetFont(
'',
'', $default_font_size - 1);
454 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
456 $pageposafternote = $pdf->getPage();
457 $posyafter = $pdf->GetY();
459 if ($pageposafternote > $pageposbeforenote) {
460 $pdf->rollbackTransaction(
true);
463 while ($pagenb < $pageposafternote) {
466 if (!empty($tplidx)) {
467 $pdf->useTemplate($tplidx);
470 $this->
_pagehead($pdf, $object, 0, $outputlangs);
473 $pdf->setTopMargin($tab_top_newpage);
475 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
479 $pdf->setPage($pageposbeforenote);
480 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
481 $pdf->SetFont(
'',
'', $default_font_size - 1);
482 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
483 $pageposafternote = $pdf->getPage();
485 $posyafter = $pdf->GetY();
487 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
488 $pdf->AddPage(
'',
'',
true);
491 $pdf->setPage($pageposafternote);
492 $pdf->setTopMargin($tab_top_newpage);
494 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
500 $i = $pageposbeforenote;
501 while ($i < $pageposafternote) {
505 $pdf->SetDrawColor(128, 128, 128);
507 if ($i > $pageposbeforenote) {
508 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
509 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
511 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
512 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
516 $pdf->setPageOrientation(
'', 1, 0);
517 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
523 $pdf->setPage($pageposafternote);
524 if (!empty($tplidx)) {
525 $pdf->useTemplate($tplidx);
528 $this->
_pagehead($pdf, $object, 0, $outputlangs);
530 $height_note = $posyafter - $tab_top_newpage;
531 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
534 $pdf->commitTransaction();
535 $posyafter = $pdf->GetY();
536 $height_note = $posyafter - $tab_top;
537 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
540 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
542 $pdf->AddPage(
'',
'',
true);
545 $pdf->setPage($pageposafternote);
546 if (!empty($tplidx)) {
547 $pdf->useTemplate($tplidx);
550 $this->
_pagehead($pdf, $object, 0, $outputlangs);
553 $posyafter = $tab_top_newpage;
557 $tab_height = $tab_height - $height_note;
558 $tab_top = $posyafter + 6;
568 $pdf->startTransaction();
569 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
570 $pdf->rollbackTransaction(
true);
572 $nexY = $tab_top + $this->tabTitleHeight;
575 $pageposbeforeprintlines = $pdf->getPage();
576 $pagenb = $pageposbeforeprintlines;
577 for ($i = 0; $i < $nblines; $i++) {
579 $pdf->SetFont(
'',
'', $default_font_size - 1);
580 $pdf->SetTextColor(0, 0, 0);
583 $imglinesize = array();
584 if (!empty($realpatharray[$i])) {
588 $pdf->setTopMargin($tab_top_newpage);
589 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
590 $pageposbefore = $pdf->getPage();
593 $showpricebeforepagebreak = 1;
595 $posYAfterDescription = 0;
599 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
600 $pdf->AddPage(
'',
'',
true);
601 if (!empty($tplidx)) {
602 $pdf->useTemplate($tplidx);
604 $pdf->setPage($pageposbefore + 1);
606 $curY = $tab_top_newpage;
609 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
610 $showpricebeforepagebreak = 1;
612 $showpricebeforepagebreak = 0;
616 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
617 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
619 $posYAfterImage = $curY + $imglinesize[
'height'];
625 $pdf->startTransaction();
627 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
628 $pageposafter = $pdf->getPage();
630 if ($pageposafter > $pageposbefore) {
631 $pdf->rollbackTransaction(
true);
632 $pageposafter = $pageposbefore;
634 $pdf->setPageOrientation(
'', 1, $heightforfooter);
636 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
637 $pageposafter = $pdf->getPage();
638 $posyafter = $pdf->GetY();
639 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
640 if ($i == ($nblines - 1)) {
641 $pdf->AddPage(
'',
'',
true);
642 if (!empty($tplidx)) {
643 $pdf->useTemplate($tplidx);
646 $pdf->setPage($pageposafter + 1);
651 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
652 $showpricebeforepagebreak = 1;
654 $showpricebeforepagebreak = 0;
659 $pdf->commitTransaction();
661 $posYAfterDescription = $pdf->GetY();
665 $nexY = max($pdf->GetY(), $posYAfterImage);
668 $pageposafter = $pdf->getPage();
670 $pdf->setPage($pageposbefore);
671 $pdf->setTopMargin($this->marge_haute);
672 $pdf->setPageOrientation(
'', 1, 0);
675 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
676 $pdf->setPage($pageposafter);
677 $curY = $tab_top_newpage;
680 $pdf->SetFont(
'',
'', $default_font_size - 1);
686 $nexY = max($pdf->GetY(), $nexY);
693 $nexY = max($pdf->GetY(), $nexY);
701 $nexY = max($pdf->GetY(), $nexY);
707 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
709 $nexY = max($pdf->GetY(), $nexY);
713 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
716 $nexY = max($pdf->GetY(), $nexY);
723 $nexY = max($pdf->GetY(), $nexY);
730 $nexY = max($pdf->GetY(), $nexY);
734 if (!empty($object->lines[$i]->array_options)) {
735 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
737 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
739 $nexY = max($pdf->GetY(), $nexY);
750 'outputlangs' => $outputlangs,
751 'hidedetails' => $hidedetails
753 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
757 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
758 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
760 $tvaligne = $object->lines[$i]->total_tva;
763 $localtax1ligne = $object->lines[$i]->total_localtax1;
764 $localtax2ligne = $object->lines[$i]->total_localtax2;
765 $localtax1_rate = $object->lines[$i]->localtax1_tx;
766 $localtax2_rate = $object->lines[$i]->localtax2_tx;
767 $localtax1_type = $object->lines[$i]->localtax1_type;
768 $localtax2_type = $object->lines[$i]->localtax2_type;
770 if ($object->remise_percent) {
771 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
773 if ($object->remise_percent) {
774 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
776 if ($object->remise_percent) {
777 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
780 $vatrate = (string) $object->lines[$i]->tva_tx;
783 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
784 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
786 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
787 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
791 if ($localtax1_type && $localtax1ligne != 0) {
792 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
794 if ($localtax2_type && $localtax2ligne != 0) {
795 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
798 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
803 if (!isset($this->tva[$vatrate])) {
804 $this->tva[$vatrate] = 0;
806 $this->tva[$vatrate] += $tvaligne;
807 $vatcode = $object->lines[$i]->vat_src_code;
808 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
809 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
811 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
814 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
815 $pdf->setPage($pageposafter);
816 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
818 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
819 $pdf->SetLineStyle(array(
'dash'=>0));
824 while ($pagenb < $pageposafter) {
825 $pdf->setPage($pagenb);
826 if ($pagenb == $pageposbeforeprintlines) {
827 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
829 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
831 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
833 $pdf->setPage($pagenb);
834 $pdf->setPageOrientation(
'', 1, 0);
836 $this->
_pagehead($pdf, $object, 0, $outputlangs);
838 if (!empty($tplidx)) {
839 $pdf->useTemplate($tplidx);
842 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
843 if ($pagenb == $pageposafter) {
844 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
846 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
848 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
851 if (!empty($tplidx)) {
852 $pdf->useTemplate($tplidx);
856 $this->
_pagehead($pdf, $object, 0, $outputlangs);
862 if ($pagenb == $pageposbeforeprintlines) {
863 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
865 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
867 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
870 $posy = $this->
drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
873 $posy = $this->
drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
884 $this->
_pagefoot($pdf, $object, $outputlangs);
885 if (method_exists($pdf,
'AliasNbPages')) {
886 $pdf->AliasNbPages();
891 $pdf->Output($file,
'F');
894 $hookmanager->initHooks(array(
'pdfgeneration'));
895 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
897 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
899 $this->error = $hookmanager->error;
900 $this->errors = $hookmanager->errors;
903 if (!empty($conf->global->MAIN_UMASK)) {
904 @chmod($file, octdec($conf->global->MAIN_UMASK));
907 $this->result = array(
'fullpath'=>$file);
911 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
915 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
944 global $conf, $mysoc;
947 $pdf->SetFont(
'',
'', $default_font_size - 1);
950 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
951 $pdf->SetFont(
'',
'B', $default_font_size - 2);
952 $pdf->SetXY($this->marge_gauche, $posy);
953 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
955 $posy = $pdf->GetY() + 4;
961 if ($object->cond_reglement_code || $object->cond_reglement) {
962 $pdf->SetFont(
'',
'B', $default_font_size - 2);
963 $pdf->SetXY($this->marge_gauche, $posy);
964 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
965 $pdf->MultiCell(43, 4, $titre, 0,
'L');
967 $pdf->SetFont(
'',
'', $default_font_size - 2);
968 $pdf->SetXY($posxval, $posy);
969 $lib_condition_paiement = $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) != (
'PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
970 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
971 if ($object->deposit_percent > 0) {
972 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
974 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
976 $posy = $pdf->GetY() + 3;
1007 if (!empty($object->delivery_date)) {
1008 $outputlangs->load(
"sendings");
1009 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1010 $pdf->SetXY($this->marge_gauche, $posy);
1011 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1012 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1013 $pdf->SetFont(
'',
'', $default_font_size - 2);
1014 $pdf->SetXY($posxval, $posy);
1015 $dlp =
dol_print_date($object->delivery_date,
"daytext",
false, $outputlangs,
true);
1016 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1018 $posy = $pdf->GetY() + 1;
1019 } elseif ($object->availability_code || $object->availability) {
1020 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1021 $pdf->SetXY($this->marge_gauche, $posy);
1022 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1023 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1024 $pdf->SetTextColor(0, 0, 0);
1025 $pdf->SetFont(
'',
'', $default_font_size - 2);
1026 $pdf->SetXY($posxval, $posy);
1027 $lib_availability = $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) != (
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability :
'');
1028 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1029 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1031 $posy = $pdf->GetY() + 1;
1035 if ($object->mode_reglement_code
1036 && $object->mode_reglement_code !=
'CHQ'
1037 && $object->mode_reglement_code !=
'VIR') {
1038 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1039 $pdf->SetXY($this->marge_gauche, $posy);
1040 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1041 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1043 $pdf->SetFont(
'',
'', $default_font_size - 2);
1044 $pdf->SetXY($posxval, $posy);
1045 $lib_mode_reg = $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) != (
'PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1046 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1048 $posy = $pdf->GetY() + 2;
1052 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1054 if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
1055 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1057 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1059 $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1061 $pdf->SetXY($this->marge_gauche, $posy);
1062 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1063 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1064 $posy = $pdf->GetY() + 1;
1066 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1067 $pdf->SetXY($this->marge_gauche, $posy);
1068 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1069 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1070 $posy = $pdf->GetY() + 2;
1073 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1074 $pdf->SetXY($this->marge_gauche, $posy);
1075 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1076 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1077 $posy = $pdf->GetY() + 1;
1079 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1080 $pdf->SetXY($this->marge_gauche, $posy);
1081 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1082 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1083 $posy = $pdf->GetY() + 2;
1090 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1091 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1092 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1093 if ($object->fk_bank > 0) {
1094 $bankid = $object->fk_bank;
1097 $account->fetch($bankid);
1099 $curx = $this->marge_gauche;
1102 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1123 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis =
null)
1125 global $conf, $mysoc, $hookmanager;
1129 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1130 $outputlangsbis =
new Translate(
'', $conf);
1131 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1132 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1133 $default_font_size--;
1138 $pdf->SetFont(
'',
'', $default_font_size - 1);
1143 if ($this->page_largeur < 210) {
1146 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1152 $pdf->SetFillColor(255, 255, 255);
1153 $pdf->SetXY($col1x, $tab2_top);
1154 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L', 1);
1155 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1156 $pdf->SetXY($col2x, $tab2_top);
1157 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0,
'R', 1);
1160 $pdf->SetFillColor(248, 248, 248);
1162 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1164 $this->atleastoneratenotnull = 0;
1165 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1166 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1167 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1173 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1174 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1177 foreach ($localtax_rate as $tvakey => $tvaval) {
1181 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1184 if (preg_match(
'/\*/', $tvakey)) {
1185 $tvakey = str_replace(
'*',
'', $tvakey);
1186 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1188 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1190 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1191 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1193 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1194 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1202 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1203 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1206 foreach ($localtax_rate as $tvakey => $tvaval) {
1211 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1214 if (preg_match(
'/\*/', $tvakey)) {
1215 $tvakey = str_replace(
'*',
'', $tvakey);
1216 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1218 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1220 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1221 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1223 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1224 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1231 foreach ($this->tva_array as $tvakey => $tvaval) {
1233 $this->atleastoneratenotnull++;
1236 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1239 if (preg_match(
'/\*/', $tvakey)) {
1240 $tvakey = str_replace(
'*',
'', $tvakey);
1241 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1243 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1246 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1248 $totalvat .= ($tvaval[
'vatcode'] ? $tvaval[
'vatcode'] :
vatrate($tvaval[
'vatrate'], 1)).$tvacompl;
1250 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1252 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1254 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1255 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1262 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1263 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1267 foreach ($localtax_rate as $tvakey => $tvaval) {
1272 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1275 if (preg_match(
'/\*/', $tvakey)) {
1276 $tvakey = str_replace(
'*',
'', $tvakey);
1277 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1279 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1281 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1283 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1284 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1285 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1293 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1294 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1298 foreach ($localtax_rate as $tvakey => $tvaval) {
1304 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1307 if (preg_match(
'/\*/', $tvakey)) {
1308 $tvakey = str_replace(
'*',
'', $tvakey);
1309 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1311 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1314 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1315 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1317 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1318 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1326 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1327 $pdf->SetTextColor(0, 0, 60);
1328 $pdf->SetFillColor(224, 224, 224);
1329 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC", $mysoc->country_code) :
''), $useborder,
'L', 1);
1331 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1332 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1336 $pdf->SetTextColor(0, 0, 0);
1338 $creditnoteamount = 0;
1339 $depositsamount = 0;
1343 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1344 if (!empty($object->paye)) {
1348 if ($deja_regle > 0) {
1352 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1353 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L', 0);
1354 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1355 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R', 0);
1358 $pdf->SetTextColor(0, 0, 60);
1359 $pdf->SetFillColor(224, 224, 224);
1360 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1361 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1363 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1364 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1366 $pdf->SetFont(
'',
'', $default_font_size - 1);
1367 $pdf->SetTextColor(0, 0, 0);
1371 return ($tab2_top + ($tab2_hl * $index));
1389 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
1399 $currency = !empty($currency) ? $currency : $conf->currency;
1403 $pdf->SetTextColor(0, 0, 0);
1404 $pdf->SetFont(
'',
'', $default_font_size - 2);
1406 if (empty($hidetop)) {
1407 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1408 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1409 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
1412 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1413 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1416 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1417 $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));
1421 $pdf->SetDrawColor(128, 128, 128);
1422 $pdf->SetFont(
'',
'', $default_font_size - 1);
1425 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1428 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1430 if (empty($hidetop)) {
1431 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
1448 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1451 global $conf, $langs, $hookmanager;
1453 $ltrdirection =
'L';
1454 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1457 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1463 $pdf->SetTextColor(0, 0, 60);
1464 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1468 $posy = $this->marge_haute;
1469 $posx = $this->page_largeur - $this->marge_droite - $w;
1471 $pdf->SetXY($this->marge_gauche, $posy);
1475 if ($this->emetteur->logo) {
1476 $logodir = $conf->mycompany->dir_output;
1477 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1478 $logodir = $conf->mycompany->multidir_output[$object->entity];
1481 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1483 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1485 if (is_readable($logo)) {
1487 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1489 $pdf->SetTextColor(200, 0, 0);
1490 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1491 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1492 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1495 $text = $this->emetteur->name;
1496 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1500 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1501 $pdf->SetXY($posx, $posy);
1502 $pdf->SetTextColor(0, 0, 60);
1503 $title = $outputlangs->transnoentities($titlekey);
1504 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1506 $title .= $outputlangsbis->transnoentities($titlekey);
1508 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1509 if ($object->statut == $object::STATUS_DRAFT) {
1510 $pdf->SetTextColor(128, 0, 0);
1511 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1514 $pdf->MultiCell($w, 3, $title,
'',
'R');
1516 $pdf->SetFont(
'',
'B', $default_font_size);
1531 $pdf->SetFont(
'',
'', $default_font_size - 2);
1533 if ($object->ref_client) {
1535 $pdf->SetXY($posx, $posy);
1536 $pdf->SetTextColor(0, 0, 60);
1537 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
1540 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1541 $object->fetch_projet();
1542 if (!empty($object->project->ref)) {
1544 $pdf->SetXY($posx, $posy);
1545 $pdf->SetTextColor(0, 0, 60);
1546 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1550 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1551 $object->fetch_projet();
1552 if (!empty($object->project->ref)) {
1553 $outputlangs->load(
"projects");
1555 $pdf->SetXY($posx, $posy);
1556 $pdf->SetTextColor(0, 0, 60);
1557 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1563 $pdf->SetXY($posx, $posy);
1564 $pdf->SetTextColor(0, 0, 60);
1565 $title = $outputlangs->transnoentities(
"OrderDate");
1566 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1567 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1569 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1571 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
1573 $pdf->SetXY($posx, $posy);
1574 $pdf->SetTextColor(0, 0, 60);
1575 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1579 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1580 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1581 if (count($arrayidcontact) > 0) {
1582 $usertmp =
new User($this->
db);
1583 $usertmp->fetch($arrayidcontact[0]);
1585 $pdf->SetXY($posx, $posy);
1586 $pdf->SetTextColor(0, 0, 60);
1587 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1595 $current_y = $pdf->getY();
1596 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1597 if ($current_y < $pdf->getY()) {
1598 $top_shift = $pdf->getY() - $current_y;
1603 $carac_emetteur =
'';
1605 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1606 if (count($arrayidcontact) > 0) {
1607 $object->fetch_user($arrayidcontact[0]);
1608 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1609 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)).
"\n";
1612 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1615 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1616 $posy += $top_shift;
1617 $posx = $this->marge_gauche;
1618 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1619 $posx = $this->page_largeur - $this->marge_droite - 80;
1622 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1623 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1627 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
1628 $pdf->SetTextColor(0, 0, 0);
1629 $pdf->SetFont(
'',
'', $default_font_size - 2);
1630 $pdf->SetXY($posx, $posy - 5);
1631 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1632 $pdf->SetXY($posx, $posy);
1633 $pdf->SetFillColor(230, 230, 230);
1634 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1635 $pdf->SetTextColor(0, 0, 60);
1639 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
1640 $pdf->SetXY($posx + 2, $posy + 3);
1641 $pdf->SetFont(
'',
'B', $default_font_size);
1642 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1643 $posy = $pdf->getY();
1647 $pdf->SetXY($posx + 2, $posy);
1648 $pdf->SetFont(
'',
'', $default_font_size - 1);
1649 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1652 $usecontact =
false;
1653 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1654 if (count($arrayidcontact) > 0) {
1656 $result = $object->fetch_contact($arrayidcontact[0]);
1660 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1661 $thirdparty = $object->contact;
1663 $thirdparty = $object->thirdparty;
1669 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
1672 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1673 if ($this->page_largeur < 210) {
1676 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1677 $posy += $top_shift;
1678 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1679 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1680 $posx = $this->marge_gauche;
1684 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
1685 $pdf->SetTextColor(0, 0, 0);
1686 $pdf->SetFont(
'',
'', $default_font_size - 2);
1687 $pdf->SetXY($posx + 2, $posy - 5);
1688 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1689 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1693 $pdf->SetXY($posx + 2, $posy + 3);
1694 $pdf->SetFont(
'',
'B', $default_font_size);
1695 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1697 $posy = $pdf->getY();
1700 $pdf->SetFont(
'',
'', $default_font_size - 1);
1701 $pdf->SetXY($posx + 2, $posy);
1702 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1705 $pdf->SetTextColor(0, 0, 0);
1720 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1723 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1724 return pdf_pagefoot($pdf, $outputlangs,
'ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
1739 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1741 global $conf, $hookmanager;
1744 $this->defaultContentsFieldsStyle = array(
1746 'padding' => array(1, 0.5, 1, 0.5),
1750 $this->defaultTitlesFieldsStyle = array(
1752 'padding' => array(0.5, 0, 0.5, 0),
1774 $this->cols[
'desc'] = array(
1779 'textkey' =>
'Designation',
1783 'padding' => array(0.5, 0.5, 0.5, 0.5),
1787 'padding' => array(1, 0.5, 1, 1.5),
1793 $this->cols[
'photo'] = array(
1795 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1798 'textkey' =>
'Photo',
1802 'padding' => array(0, 0, 0, 0),
1804 'border-left' =>
false,
1807 if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1808 $this->cols[
'photo'][
'status'] =
true;
1812 $this->cols[
'vat'] = array(
1819 'border-left' =>
true,
1822 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1823 $this->cols[
'vat'][
'status'] =
true;
1827 $this->cols[
'subprice'] = array(
1832 'textkey' =>
'PriceUHT'
1834 'border-left' =>
true,
1839 $nblines = count($object->lines);
1840 for ($i = 0; $i < $nblines; $i++) {
1842 $tmpwidth = max($tmpwidth, $tmpwidth2);
1844 if ($tmpwidth > 10) {
1845 $this->cols[
'subprice'][
'width'] += (2 * ($tmpwidth - 10));
1849 $this->cols[
'qty'] = array(
1856 'border-left' =>
true,
1860 $this->cols[
'unit'] = array(
1867 'border-left' =>
true,
1870 $this->cols[
'unit'][
'status'] =
true;
1874 $this->cols[
'discount'] = array(
1879 'textkey' =>
'ReductionShort'
1881 'border-left' =>
true,
1883 if ($this->atleastonediscount) {
1884 $this->cols[
'discount'][
'status'] =
true;
1887 $rank = $rank + 1000;
1888 $this->cols[
'totalexcltax'] = array(
1891 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ?
true :
false,
1893 'textkey' =>
'TotalHT'
1895 'border-left' =>
true,
1898 $rank = $rank + 1010;
1899 $this->cols[
'totalincltax'] = array(
1902 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ?
false :
true,
1904 'textkey' =>
'TotalTTC'
1906 'border-left' =>
true,
1910 if (!empty($object->lines)) {
1911 $line = reset($object->lines);
1915 $parameters = array(
1916 'object' => $object,
1917 'outputlangs' => $outputlangs,
1918 'hidedetails' => $hidedetails,
1919 'hidedesc' => $hidedesc,
1920 'hideref' => $hideref
1923 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
1926 } elseif (empty($reshook)) {
1927 $this->cols = array_replace($this->cols, $hookmanager->resArray);
1929 $this->cols = $hookmanager->resArray;
Class to manage bank accounts.
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 orders models.
Class to manage products or services.
Class to manage translations.
Class to manage Dolibarr users.
Class to generate PDF orders with template Eratosthene.
__construct($db)
Constructor.
drawInfoTable(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null, $titlekey="PdfOrderTitle")
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis=null)
Show total to pay.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
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...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
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_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
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_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
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_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
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_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations 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_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
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.
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.