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;
905 $this->result = array(
'fullpath'=>$file);
909 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
913 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
942 global $conf, $mysoc;
945 $pdf->SetFont(
'',
'', $default_font_size - 1);
948 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
949 $pdf->SetFont(
'',
'B', $default_font_size - 2);
950 $pdf->SetXY($this->marge_gauche, $posy);
951 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
953 $posy = $pdf->GetY() + 4;
959 if ($object->cond_reglement_code || $object->cond_reglement) {
960 $pdf->SetFont(
'',
'B', $default_font_size - 2);
961 $pdf->SetXY($this->marge_gauche, $posy);
962 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
963 $pdf->MultiCell(43, 4, $titre, 0,
'L');
965 $pdf->SetFont(
'',
'', $default_font_size - 2);
966 $pdf->SetXY($posxval, $posy);
967 $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);
968 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
969 if ($object->deposit_percent > 0) {
970 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
972 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
974 $posy = $pdf->GetY() + 3;
1005 if (!empty($object->delivery_date)) {
1006 $outputlangs->load(
"sendings");
1007 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1008 $pdf->SetXY($this->marge_gauche, $posy);
1009 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1010 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1011 $pdf->SetFont(
'',
'', $default_font_size - 2);
1012 $pdf->SetXY($posxval, $posy);
1013 $dlp =
dol_print_date($object->delivery_date,
"daytext",
false, $outputlangs,
true);
1014 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1016 $posy = $pdf->GetY() + 1;
1017 } elseif ($object->availability_code || $object->availability) {
1018 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1019 $pdf->SetXY($this->marge_gauche, $posy);
1020 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1021 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1022 $pdf->SetTextColor(0, 0, 0);
1023 $pdf->SetFont(
'',
'', $default_font_size - 2);
1024 $pdf->SetXY($posxval, $posy);
1025 $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 :
'');
1026 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1027 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1029 $posy = $pdf->GetY() + 1;
1033 if ($object->mode_reglement_code
1034 && $object->mode_reglement_code !=
'CHQ'
1035 && $object->mode_reglement_code !=
'VIR') {
1036 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1037 $pdf->SetXY($this->marge_gauche, $posy);
1038 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1039 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1041 $pdf->SetFont(
'',
'', $default_font_size - 2);
1042 $pdf->SetXY($posxval, $posy);
1043 $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);
1044 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1046 $posy = $pdf->GetY() + 2;
1050 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1052 if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
1053 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1055 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1057 $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1059 $pdf->SetXY($this->marge_gauche, $posy);
1060 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1061 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1062 $posy = $pdf->GetY() + 1;
1064 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1065 $pdf->SetXY($this->marge_gauche, $posy);
1066 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1067 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1068 $posy = $pdf->GetY() + 2;
1071 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1072 $pdf->SetXY($this->marge_gauche, $posy);
1073 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1074 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1075 $posy = $pdf->GetY() + 1;
1077 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1078 $pdf->SetXY($this->marge_gauche, $posy);
1079 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1080 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1081 $posy = $pdf->GetY() + 2;
1088 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1089 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1090 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1091 if ($object->fk_bank > 0) {
1092 $bankid = $object->fk_bank;
1095 $account->fetch($bankid);
1097 $curx = $this->marge_gauche;
1100 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1121 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis =
null)
1123 global $conf, $mysoc, $hookmanager;
1127 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1128 $outputlangsbis =
new Translate(
'', $conf);
1129 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1130 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1131 $default_font_size--;
1136 $pdf->SetFont(
'',
'', $default_font_size - 1);
1141 if ($this->page_largeur < 210) {
1144 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1150 $pdf->SetFillColor(255, 255, 255);
1151 $pdf->SetXY($col1x, $tab2_top);
1152 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L', 1);
1153 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1154 $pdf->SetXY($col2x, $tab2_top);
1155 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0,
'R', 1);
1158 $pdf->SetFillColor(248, 248, 248);
1160 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1162 $this->atleastoneratenotnull = 0;
1163 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1164 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1165 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1171 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1172 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1175 foreach ($localtax_rate as $tvakey => $tvaval) {
1179 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1182 if (preg_match(
'/\*/', $tvakey)) {
1183 $tvakey = str_replace(
'*',
'', $tvakey);
1184 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1186 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1188 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1189 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1191 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1192 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1200 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1201 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1204 foreach ($localtax_rate as $tvakey => $tvaval) {
1209 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1212 if (preg_match(
'/\*/', $tvakey)) {
1213 $tvakey = str_replace(
'*',
'', $tvakey);
1214 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1216 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1218 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1219 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1221 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1222 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1229 foreach ($this->tva_array as $tvakey => $tvaval) {
1231 $this->atleastoneratenotnull++;
1234 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1237 if (preg_match(
'/\*/', $tvakey)) {
1238 $tvakey = str_replace(
'*',
'', $tvakey);
1239 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1241 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1244 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1246 $totalvat .= ($tvaval[
'vatcode'] ? $tvaval[
'vatcode'] :
vatrate($tvaval[
'vatrate'], 1)).$tvacompl;
1248 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1250 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1252 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1253 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1260 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1261 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1265 foreach ($localtax_rate as $tvakey => $tvaval) {
1270 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1273 if (preg_match(
'/\*/', $tvakey)) {
1274 $tvakey = str_replace(
'*',
'', $tvakey);
1275 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1277 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1279 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1281 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1282 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1283 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1291 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1292 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1296 foreach ($localtax_rate as $tvakey => $tvaval) {
1302 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1305 if (preg_match(
'/\*/', $tvakey)) {
1306 $tvakey = str_replace(
'*',
'', $tvakey);
1307 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1309 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1312 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1313 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1315 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1316 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1324 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1325 $pdf->SetTextColor(0, 0, 60);
1326 $pdf->SetFillColor(224, 224, 224);
1327 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC", $mysoc->country_code) :
''), $useborder,
'L', 1);
1329 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1330 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1334 $pdf->SetTextColor(0, 0, 0);
1336 $creditnoteamount = 0;
1337 $depositsamount = 0;
1341 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1342 if (!empty($object->paye)) {
1346 if ($deja_regle > 0) {
1350 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1351 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L', 0);
1352 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1353 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R', 0);
1356 $pdf->SetTextColor(0, 0, 60);
1357 $pdf->SetFillColor(224, 224, 224);
1358 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1359 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1361 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1362 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1364 $pdf->SetFont(
'',
'', $default_font_size - 1);
1365 $pdf->SetTextColor(0, 0, 0);
1369 return ($tab2_top + ($tab2_hl * $index));
1387 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
1397 $currency = !empty($currency) ? $currency : $conf->currency;
1401 $pdf->SetTextColor(0, 0, 0);
1402 $pdf->SetFont(
'',
'', $default_font_size - 2);
1404 if (empty($hidetop)) {
1405 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1406 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1407 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
1410 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1411 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1414 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1415 $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));
1419 $pdf->SetDrawColor(128, 128, 128);
1420 $pdf->SetFont(
'',
'', $default_font_size - 1);
1423 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1426 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1428 if (empty($hidetop)) {
1429 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
1446 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1449 global $conf, $langs, $hookmanager;
1451 $ltrdirection =
'L';
1452 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1455 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1461 $pdf->SetTextColor(0, 0, 60);
1462 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1466 $posy = $this->marge_haute;
1467 $posx = $this->page_largeur - $this->marge_droite - $w;
1469 $pdf->SetXY($this->marge_gauche, $posy);
1473 if ($this->emetteur->logo) {
1474 $logodir = $conf->mycompany->dir_output;
1475 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1476 $logodir = $conf->mycompany->multidir_output[$object->entity];
1479 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1481 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1483 if (is_readable($logo)) {
1485 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1487 $pdf->SetTextColor(200, 0, 0);
1488 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1489 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1490 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1493 $text = $this->emetteur->name;
1494 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1498 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1499 $pdf->SetXY($posx, $posy);
1500 $pdf->SetTextColor(0, 0, 60);
1501 $title = $outputlangs->transnoentities($titlekey);
1502 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1504 $title .= $outputlangsbis->transnoentities($titlekey);
1506 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1507 if ($object->statut == $object::STATUS_DRAFT) {
1508 $pdf->SetTextColor(128, 0, 0);
1509 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1512 $pdf->MultiCell($w, 3, $title,
'',
'R');
1514 $pdf->SetFont(
'',
'B', $default_font_size);
1529 $pdf->SetFont(
'',
'', $default_font_size - 2);
1531 if ($object->ref_client) {
1533 $pdf->SetXY($posx, $posy);
1534 $pdf->SetTextColor(0, 0, 60);
1535 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
1538 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1539 $object->fetch_projet();
1540 if (!empty($object->project->ref)) {
1542 $pdf->SetXY($posx, $posy);
1543 $pdf->SetTextColor(0, 0, 60);
1544 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1548 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1549 $object->fetch_projet();
1550 if (!empty($object->project->ref)) {
1551 $outputlangs->load(
"projects");
1553 $pdf->SetXY($posx, $posy);
1554 $pdf->SetTextColor(0, 0, 60);
1555 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1561 $pdf->SetXY($posx, $posy);
1562 $pdf->SetTextColor(0, 0, 60);
1563 $title = $outputlangs->transnoentities(
"OrderDate");
1564 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1565 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1567 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1569 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
1571 $pdf->SetXY($posx, $posy);
1572 $pdf->SetTextColor(0, 0, 60);
1573 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
1577 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1578 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1579 if (count($arrayidcontact) > 0) {
1580 $usertmp =
new User($this->
db);
1581 $usertmp->fetch($arrayidcontact[0]);
1583 $pdf->SetXY($posx, $posy);
1584 $pdf->SetTextColor(0, 0, 60);
1585 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1593 $current_y = $pdf->getY();
1594 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
1595 if ($current_y < $pdf->getY()) {
1596 $top_shift = $pdf->getY() - $current_y;
1601 $carac_emetteur =
'';
1603 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1604 if (count($arrayidcontact) > 0) {
1605 $object->fetch_user($arrayidcontact[0]);
1606 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1607 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)).
"\n";
1610 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1613 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1614 $posy += $top_shift;
1615 $posx = $this->marge_gauche;
1616 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1617 $posx = $this->page_largeur - $this->marge_droite - 80;
1620 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1621 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1625 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
1626 $pdf->SetTextColor(0, 0, 0);
1627 $pdf->SetFont(
'',
'', $default_font_size - 2);
1628 $pdf->SetXY($posx, $posy - 5);
1629 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1630 $pdf->SetXY($posx, $posy);
1631 $pdf->SetFillColor(230, 230, 230);
1632 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
1633 $pdf->SetTextColor(0, 0, 60);
1637 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
1638 $pdf->SetXY($posx + 2, $posy + 3);
1639 $pdf->SetFont(
'',
'B', $default_font_size);
1640 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1641 $posy = $pdf->getY();
1645 $pdf->SetXY($posx + 2, $posy);
1646 $pdf->SetFont(
'',
'', $default_font_size - 1);
1647 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1650 $usecontact =
false;
1651 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1652 if (count($arrayidcontact) > 0) {
1654 $result = $object->fetch_contact($arrayidcontact[0]);
1658 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)))) {
1659 $thirdparty = $object->contact;
1661 $thirdparty = $object->thirdparty;
1667 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
1670 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1671 if ($this->page_largeur < 210) {
1674 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1675 $posy += $top_shift;
1676 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1677 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1678 $posx = $this->marge_gauche;
1682 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
1683 $pdf->SetTextColor(0, 0, 0);
1684 $pdf->SetFont(
'',
'', $default_font_size - 2);
1685 $pdf->SetXY($posx + 2, $posy - 5);
1686 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1687 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1691 $pdf->SetXY($posx + 2, $posy + 3);
1692 $pdf->SetFont(
'',
'B', $default_font_size);
1693 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1695 $posy = $pdf->getY();
1698 $pdf->SetFont(
'',
'', $default_font_size - 1);
1699 $pdf->SetXY($posx + 2, $posy);
1700 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1703 $pdf->SetTextColor(0, 0, 0);
1718 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1721 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1722 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);
1737 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1739 global $conf, $hookmanager;
1742 $this->defaultContentsFieldsStyle = array(
1744 'padding' => array(1, 0.5, 1, 0.5),
1748 $this->defaultTitlesFieldsStyle = array(
1750 'padding' => array(0.5, 0, 0.5, 0),
1772 $this->cols[
'desc'] = array(
1777 'textkey' =>
'Designation',
1781 'padding' => array(0.5, 0.5, 0.5, 0.5),
1785 'padding' => array(1, 0.5, 1, 1.5),
1791 $this->cols[
'photo'] = array(
1793 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
1796 'textkey' =>
'Photo',
1800 'padding' => array(0, 0, 0, 0),
1802 'border-left' =>
false,
1805 if (!empty($conf->global->MAIN_GENERATE_ORDERS_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1806 $this->cols[
'photo'][
'status'] =
true;
1810 $this->cols[
'vat'] = array(
1817 'border-left' =>
true,
1820 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1821 $this->cols[
'vat'][
'status'] =
true;
1825 $this->cols[
'subprice'] = array(
1830 'textkey' =>
'PriceUHT'
1832 'border-left' =>
true,
1837 $nblines = count($object->lines);
1838 for ($i = 0; $i < $nblines; $i++) {
1840 $tmpwidth = max($tmpwidth, $tmpwidth2);
1842 if ($tmpwidth > 10) {
1843 $this->cols[
'subprice'][
'width'] += (2 * ($tmpwidth - 10));
1847 $this->cols[
'qty'] = array(
1854 'border-left' =>
true,
1858 $this->cols[
'unit'] = array(
1865 'border-left' =>
true,
1868 $this->cols[
'unit'][
'status'] =
true;
1872 $this->cols[
'discount'] = array(
1877 'textkey' =>
'ReductionShort'
1879 'border-left' =>
true,
1881 if ($this->atleastonediscount) {
1882 $this->cols[
'discount'][
'status'] =
true;
1885 $rank = $rank + 1000;
1886 $this->cols[
'totalexcltax'] = array(
1889 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ?
true :
false,
1891 'textkey' =>
'TotalHT'
1893 'border-left' =>
true,
1896 $rank = $rank + 1010;
1897 $this->cols[
'totalincltax'] = array(
1900 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ?
false :
true,
1902 'textkey' =>
'TotalTTC'
1904 'border-left' =>
true,
1908 if (!empty($object->lines)) {
1909 $line = reset($object->lines);
1913 $parameters = array(
1914 'object' => $object,
1915 'outputlangs' => $outputlangs,
1916 'hidedetails' => $hidedetails,
1917 'hidedesc' => $hidedesc,
1918 'hideref' => $hideref
1921 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
1924 } elseif (empty($reshook)) {
1925 $this->cols = array_replace($this->cols, $hookmanager->resArray);
1927 $this->cols = $hookmanager->resArray;