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 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK))) {
225 $this->watermark = $conf->global->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);
949 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
952 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
953 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
954 $pdf->SetXY($this->marge_gauche, $posy);
955 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
957 $posy = $pdf->GetY() + 4;
962 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
965 if ($object->cond_reglement_code || $object->cond_reglement) {
966 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
967 $pdf->SetXY($this->marge_gauche, $posy);
968 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
969 $pdf->MultiCell(43, 4, $titre, 0,
'L');
971 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
972 $pdf->SetXY($posxval, $posy);
973 $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);
974 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
975 if ($object->deposit_percent > 0) {
976 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
978 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
980 $posy = $pdf->GetY() + 3;
1011 if (!empty($object->delivery_date)) {
1012 $outputlangs->load(
"sendings");
1013 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1014 $pdf->SetXY($this->marge_gauche, $posy);
1015 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1016 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1017 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1018 $pdf->SetXY($posxval, $posy);
1019 $dlp =
dol_print_date($object->delivery_date,
"daytext",
false, $outputlangs,
true);
1020 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1022 $posy = $pdf->GetY() + 1;
1023 } elseif ($object->availability_code || $object->availability) {
1024 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1025 $pdf->SetXY($this->marge_gauche, $posy);
1026 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1027 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1028 $pdf->SetTextColor(0, 0, 0);
1029 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1030 $pdf->SetXY($posxval, $posy);
1031 $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 :
'');
1032 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1033 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1035 $posy = $pdf->GetY() + 1;
1039 if ($object->mode_reglement_code
1040 && $object->mode_reglement_code !=
'CHQ'
1041 && $object->mode_reglement_code !=
'VIR') {
1042 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1043 $pdf->SetXY($this->marge_gauche, $posy);
1044 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1045 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1047 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1048 $pdf->SetXY($posxval, $posy);
1049 $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);
1050 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1052 $posy = $pdf->GetY() + 2;
1056 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1058 if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
1059 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1061 $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1063 $pdf->SetXY($this->marge_gauche, $posy);
1064 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1065 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1066 $posy = $pdf->GetY() + 1;
1068 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1069 $pdf->SetXY($this->marge_gauche, $posy);
1070 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1071 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1072 $posy = $pdf->GetY() + 2;
1075 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1076 $pdf->SetXY($this->marge_gauche, $posy);
1077 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1078 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1079 $posy = $pdf->GetY() + 1;
1081 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1082 $pdf->SetXY($this->marge_gauche, $posy);
1083 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1084 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1085 $posy = $pdf->GetY() + 2;
1092 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1093 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1094 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1095 if ($object->fk_bank > 0) {
1096 $bankid = $object->fk_bank;
1099 $account->fetch($bankid);
1101 $curx = $this->marge_gauche;
1104 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1125 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis =
null)
1127 global $conf, $mysoc, $hookmanager;
1131 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1132 $outputlangsbis =
new Translate(
'', $conf);
1133 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1134 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1135 $default_font_size--;
1140 $pdf->SetFont(
'',
'', $default_font_size - 1);
1145 if ($this->page_largeur < 210) {
1148 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1154 $pdf->SetFillColor(255, 255, 255);
1155 $pdf->SetXY($col1x, $tab2_top + 0);
1156 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L', 1);
1157 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1158 $pdf->SetXY($col2x, $tab2_top + 0);
1159 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0,
'R', 1);
1162 $pdf->SetFillColor(248, 248, 248);
1164 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1166 $this->atleastoneratenotnull = 0;
1167 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1168 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1169 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1175 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1176 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1179 foreach ($localtax_rate as $tvakey => $tvaval) {
1183 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1186 if (preg_match(
'/\*/', $tvakey)) {
1187 $tvakey = str_replace(
'*',
'', $tvakey);
1188 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1190 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1192 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1193 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1195 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1196 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1204 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1205 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1208 foreach ($localtax_rate as $tvakey => $tvaval) {
1213 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1216 if (preg_match(
'/\*/', $tvakey)) {
1217 $tvakey = str_replace(
'*',
'', $tvakey);
1218 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1220 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1222 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1223 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1225 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1226 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1233 foreach ($this->tva_array as $tvakey => $tvaval) {
1235 $this->atleastoneratenotnull++;
1238 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1241 if (preg_match(
'/\*/', $tvakey)) {
1242 $tvakey = str_replace(
'*',
'', $tvakey);
1243 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1245 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1248 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1250 $totalvat .= ($tvaval[
'vatcode'] ? $tvaval[
'vatcode'] :
vatrate($tvaval[
'vatrate'], 1)).$tvacompl;
1252 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1254 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1256 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1257 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1264 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1265 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1269 foreach ($localtax_rate as $tvakey => $tvaval) {
1274 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1277 if (preg_match(
'/\*/', $tvakey)) {
1278 $tvakey = str_replace(
'*',
'', $tvakey);
1279 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1281 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1283 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1285 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1286 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1287 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1295 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1296 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1300 foreach ($localtax_rate as $tvakey => $tvaval) {
1306 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1309 if (preg_match(
'/\*/', $tvakey)) {
1310 $tvakey = str_replace(
'*',
'', $tvakey);
1311 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1313 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1316 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1317 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1319 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1320 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1328 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1329 $pdf->SetTextColor(0, 0, 60);
1330 $pdf->SetFillColor(224, 224, 224);
1331 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC", $mysoc->country_code) :
''), $useborder,
'L', 1);
1333 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1334 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1338 $pdf->SetTextColor(0, 0, 0);
1340 $creditnoteamount = 0;
1341 $depositsamount = 0;
1345 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1346 if (!empty($object->paye)) {
1350 if ($deja_regle > 0) {
1354 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1355 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L', 0);
1356 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1357 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R', 0);
1360 $pdf->SetTextColor(0, 0, 60);
1361 $pdf->SetFillColor(224, 224, 224);
1362 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1363 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1365 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1366 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1368 $pdf->SetFont(
'',
'', $default_font_size - 1);
1369 $pdf->SetTextColor(0, 0, 0);
1373 return ($tab2_top + ($tab2_hl * $index));
1391 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
1401 $currency = !empty($currency) ? $currency : $conf->currency;
1405 $pdf->SetTextColor(0, 0, 0);
1406 $pdf->SetFont(
'',
'', $default_font_size - 2);
1408 if (empty($hidetop)) {
1409 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1410 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1411 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
1414 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1415 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1418 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1419 $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));
1423 $pdf->SetDrawColor(128, 128, 128);
1424 $pdf->SetFont(
'',
'', $default_font_size - 1);
1427 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1430 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1432 if (empty($hidetop)) {
1433 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
1450 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1453 global $conf, $langs, $hookmanager;
1455 $ltrdirection =
'L';
1456 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1459 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1465 $pdf->SetTextColor(0, 0, 60);
1466 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1470 $posy = $this->marge_haute;
1471 $posx = $this->page_largeur - $this->marge_droite - $w;
1473 $pdf->SetXY($this->marge_gauche, $posy);
1476 if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
1477 if ($this->emetteur->logo) {
1478 $logodir = $conf->mycompany->dir_output;
1479 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1480 $logodir = $conf->mycompany->multidir_output[$object->entity];
1482 if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
1483 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1485 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1487 if (is_readable($logo)) {
1489 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1491 $pdf->SetTextColor(200, 0, 0);
1492 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1493 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1494 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1497 $text = $this->emetteur->name;
1498 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1502 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1503 $pdf->SetXY($posx, $posy);
1504 $pdf->SetTextColor(0, 0, 60);
1505 $title = $outputlangs->transnoentities($titlekey);
1506 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1508 $title .= $outputlangsbis->transnoentities($titlekey);
1510 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1511 if ($object->statut == $object::STATUS_DRAFT) {
1512 $pdf->SetTextColor(128, 0, 0);
1513 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1516 $pdf->MultiCell($w, 3, $title,
'',
'R');
1518 $pdf->SetFont(
'',
'B', $default_font_size);
1533 $pdf->SetFont(
'',
'', $default_font_size - 2);
1535 if ($object->ref_client) {
1537 $pdf->SetXY($posx, $posy);
1538 $pdf->SetTextColor(0, 0, 60);
1539 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
1542 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1543 $object->fetch_projet();
1544 if (!empty($object->project->ref)) {
1546 $pdf->SetXY($posx, $posy);
1547 $pdf->SetTextColor(0, 0, 60);
1548 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1552 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1553 $object->fetch_projet();
1554 if (!empty($object->project->ref)) {
1555 $outputlangs->load(
"projects");
1557 $pdf->SetXY($posx, $posy);
1558 $pdf->SetTextColor(0, 0, 60);
1559 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1565 $pdf->SetXY($posx, $posy);
1566 $pdf->SetTextColor(0, 0, 60);
1567 $title = $outputlangs->transnoentities(
"OrderDate");
1568 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1569 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1571 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1573 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
1575 $pdf->SetXY($posx, $posy);
1576 $pdf->SetTextColor(0, 0, 60);
1577 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1581 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1582 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1583 if (count($arrayidcontact) > 0) {
1584 $usertmp =
new User($this->
db);
1585 $usertmp->fetch($arrayidcontact[0]);
1587 $pdf->SetXY($posx, $posy);
1588 $pdf->SetTextColor(0, 0, 60);
1589 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1597 $current_y = $pdf->getY();
1598 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1599 if ($current_y < $pdf->getY()) {
1600 $top_shift = $pdf->getY() - $current_y;
1605 $carac_emetteur =
'';
1607 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1608 if (count($arrayidcontact) > 0) {
1609 $object->fetch_user($arrayidcontact[0]);
1610 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1611 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)).
"\n";
1614 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1617 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1618 $posy += $top_shift;
1619 $posx = $this->marge_gauche;
1620 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1621 $posx = $this->page_largeur - $this->marge_droite - 80;
1624 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1625 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1629 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
1630 $pdf->SetTextColor(0, 0, 0);
1631 $pdf->SetFont(
'',
'', $default_font_size - 2);
1632 $pdf->SetXY($posx, $posy - 5);
1633 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1634 $pdf->SetXY($posx, $posy);
1635 $pdf->SetFillColor(230, 230, 230);
1636 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1637 $pdf->SetTextColor(0, 0, 60);
1641 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
1642 $pdf->SetXY($posx + 2, $posy + 3);
1643 $pdf->SetFont(
'',
'B', $default_font_size);
1644 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1645 $posy = $pdf->getY();
1649 $pdf->SetXY($posx + 2, $posy);
1650 $pdf->SetFont(
'',
'', $default_font_size - 1);
1651 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1654 $usecontact =
false;
1655 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1656 if (count($arrayidcontact) > 0) {
1658 $result = $object->fetch_contact($arrayidcontact[0]);
1662 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)))) {
1663 $thirdparty = $object->contact;
1665 $thirdparty = $object->thirdparty;
1671 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
1674 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1675 if ($this->page_largeur < 210) {
1678 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1679 $posy += $top_shift;
1680 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1681 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1682 $posx = $this->marge_gauche;
1686 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
1687 $pdf->SetTextColor(0, 0, 0);
1688 $pdf->SetFont(
'',
'', $default_font_size - 2);
1689 $pdf->SetXY($posx + 2, $posy - 5);
1690 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1691 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1695 $pdf->SetXY($posx + 2, $posy + 3);
1696 $pdf->SetFont(
'',
'B', $default_font_size);
1697 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1699 $posy = $pdf->getY();
1702 $pdf->SetFont(
'',
'', $default_font_size - 1);
1703 $pdf->SetXY($posx + 2, $posy);
1704 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1707 $pdf->SetTextColor(0, 0, 0);
1722 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1725 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1726 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);
1741 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1743 global $conf, $hookmanager;
1746 $this->defaultContentsFieldsStyle = array(
1748 'padding' => array(1, 0.5, 1, 0.5),
1752 $this->defaultTitlesFieldsStyle = array(
1754 'padding' => array(0.5, 0, 0.5, 0),
1776 $this->cols[
'desc'] = array(
1781 'textkey' =>
'Designation',
1785 'padding' => array(0.5, 0.5, 0.5, 0.5),
1789 'padding' => array(1, 0.5, 1, 1.5),
1795 $this->cols[
'photo'] = array(
1797 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1800 'textkey' =>
'Photo',
1804 'padding' => array(0, 0, 0, 0),
1806 'border-left' =>
false,
1809 if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1810 $this->cols[
'photo'][
'status'] =
true;
1814 $this->cols[
'vat'] = array(
1821 'border-left' =>
true,
1824 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1825 $this->cols[
'vat'][
'status'] =
true;
1829 $this->cols[
'subprice'] = array(
1834 'textkey' =>
'PriceUHT'
1836 'border-left' =>
true,
1841 $nblines = count($object->lines);
1842 for ($i = 0; $i < $nblines; $i++) {
1844 $tmpwidth = max($tmpwidth, $tmpwidth2);
1846 if ($tmpwidth > 10) {
1847 $this->cols[
'subprice'][
'width'] += (2 * ($tmpwidth - 10));
1851 $this->cols[
'qty'] = array(
1858 'border-left' =>
true,
1862 $this->cols[
'unit'] = array(
1869 'border-left' =>
true,
1871 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1872 $this->cols[
'unit'][
'status'] =
true;
1876 $this->cols[
'discount'] = array(
1881 'textkey' =>
'ReductionShort'
1883 'border-left' =>
true,
1885 if ($this->atleastonediscount) {
1886 $this->cols[
'discount'][
'status'] =
true;
1889 $rank = $rank + 1000;
1890 $this->cols[
'totalexcltax'] = array(
1893 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ?
true :
false,
1895 'textkey' =>
'TotalHTShort'
1897 'border-left' =>
true,
1900 $rank = $rank + 1010;
1901 $this->cols[
'totalincltax'] = array(
1904 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ?
false :
true,
1906 'textkey' =>
'TotalTTCShort'
1908 'border-left' =>
true,
1912 if (!empty($object->lines)) {
1913 $line = reset($object->lines);
1917 $parameters = array(
1918 'object' => $object,
1919 'outputlangs' => $outputlangs,
1920 'hidedetails' => $hidedetails,
1921 'hidedesc' => $hidedesc,
1922 'hideref' => $hideref
1925 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
1928 } elseif (empty($reshook)) {
1929 $this->cols = array_replace($this->cols, $hookmanager->resArray);
1931 $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.