169 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
172 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
174 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
176 if (!is_object($outputlangs)) {
177 $outputlangs = $langs;
181 $outputlangs->charset_output =
'ISO-8859-1';
185 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries",
"compta"));
192 global $outputlangsbis;
193 $outputlangsbis =
null;
197 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries",
"compta"));
200 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
205 $realpatharray = array();
206 $this->atleastonephoto =
false;
208 $objphoto =
new Product($this->db);
210 for ($i = 0; $i < $nblines; $i++) {
211 if (empty(
$object->lines[$i]->fk_product)) {
217 $objphoto->fetch(
$object->lines[$i]->fk_product);
220 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
221 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
223 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
224 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
229 foreach ($pdir as $midir) {
231 if (
$conf->entity != $objphoto->entity) {
232 $dir =
$conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
234 $dir =
$conf->product->dir_output.
'/'.$midir;
237 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
239 if ($obj[
'photo_vignette']) {
240 $filename = $obj[
'photo_vignette'];
242 $filename = $obj[
'photo'];
245 $filename = $obj[
'photo'];
248 $realpath = $dir.$filename;
250 $this->atleastonephoto =
true;
255 if ($realpath && $arephoto) {
256 $realpatharray[$i] = $realpath;
271 $file = $dir.
"/SPECIMEN.pdf";
275 $file = $dir.
"/".$objectref.
".pdf";
280 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir",
"Null dir");
284 if (!file_exists($dir)) {
286 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
291 if (file_exists($dir)) {
293 if (!is_object($hookmanager)) {
294 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
297 $hookmanager->initHooks(array(
'pdfgeneration'));
298 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
300 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
303 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
308 $pdf->setAutoPageBreak(
true, 0);
310 $heightforinfotot = 40;
312 $heightforfooter = $this->marge_basse + 8;
314 $heightforfooter += 6;
317 if (class_exists(
'TCPDF')) {
318 $pdf->setPrintHeader(
false);
319 $pdf->setPrintFooter(
false);
324 $logodir =
$conf->mycompany->dir_output;
325 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
326 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
328 $pagecount = $pdf->setSourceFile($logodir.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
329 $tplidx = $pdf->importPage(1);
334 $pdf->SetDrawColor(128, 128, 128);
336 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
337 $pdf->SetSubject($outputlangs->transnoentities(
"PdfOrderTitle"));
338 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
339 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
340 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfOrderTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
342 $pdf->SetCompression(
false);
346 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
349 for ($i = 0; $i < $nblines; $i++) {
350 if (
$object->lines[$i]->remise_percent) {
351 $this->atleastonediscount++;
358 if (!empty($tplidx)) {
359 $pdf->useTemplate($tplidx);
362 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis :
null));
363 $top_shift = $pagehead[
'top_shift'];
364 $shipp_shift = $pagehead[
'shipp_shift'];
365 $pdf->SetFont(
'',
'', $default_font_size - 1);
366 $pdf->MultiCell(0, 3,
'');
367 $pdf->SetTextColor(0, 0, 0);
370 $tab_top = 90 + $top_shift + $shipp_shift;
371 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
372 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
374 $tab_top_newpage += $this->tabTitleHeight;
377 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
379 $nexY = $tab_top - 1;
382 $height_incoterms = 0;
383 if (isModEnabled(
'incoterm')) {
384 $desc_incoterms =
$object->getIncotermsForPDF();
385 if ($desc_incoterms) {
388 $pdf->SetFont(
'',
'', $default_font_size - 1);
389 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
390 $nexY = max($pdf->GetY(), $nexY);
391 $height_incoterms = $nexY - $tab_top;
394 $pdf->SetDrawColor(192, 192, 192);
395 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
397 $tab_top = $nexY + 6;
402 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
405 if (is_object(
$object->thirdparty)) {
406 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
407 $salerepobj =
new User($this->db);
408 $salerepobj->fetch($salereparray[0][
'id']);
409 if (!empty($salerepobj->signature)) {
410 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
415 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
416 if (!empty($extranote)) {
420 $pagenb = $pdf->getPage();
424 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
425 $pageposbeforenote = $pagenb;
432 $pdf->startTransaction();
434 $pdf->SetFont(
'',
'', $default_font_size - 1);
435 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
437 $pageposafternote = $pdf->getPage();
438 $posyafter = $pdf->GetY();
440 if ($pageposafternote > $pageposbeforenote) {
441 $pdf->rollbackTransaction(
true);
444 while ($pagenb < $pageposafternote) {
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
454 $pdf->setTopMargin($tab_top_newpage);
456 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
460 $pdf->setPage($pageposbeforenote);
461 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
462 $pdf->SetFont(
'',
'', $default_font_size - 1);
463 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
464 $pageposafternote = $pdf->getPage();
466 $posyafter = $pdf->GetY();
468 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
469 $pdf->AddPage(
'',
'',
true);
472 $pdf->setPage($pageposafternote);
473 $pdf->setTopMargin($tab_top_newpage);
475 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
481 $i = $pageposbeforenote;
482 while ($i < $pageposafternote) {
486 $pdf->SetDrawColor(128, 128, 128);
488 if ($i > $pageposbeforenote) {
489 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
490 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
492 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
493 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
497 $pdf->setPageOrientation(
'',
true, 0);
504 $pdf->setPage($pageposafternote);
505 if (!empty($tplidx)) {
506 $pdf->useTemplate($tplidx);
511 $height_note = $posyafter - $tab_top_newpage;
512 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
515 $pdf->commitTransaction();
516 $posyafter = $pdf->GetY();
517 $height_note = $posyafter - $tab_top;
518 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
521 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
523 $pdf->AddPage(
'',
'',
true);
526 $pdf->setPage($pageposafternote);
527 if (!empty($tplidx)) {
528 $pdf->useTemplate($tplidx);
534 $posyafter = $tab_top_newpage;
538 $tab_height -= $height_note;
539 $tab_top = $posyafter + 6;
549 $pdf->startTransaction();
550 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
551 $pdf->rollbackTransaction(
true);
553 $nexY = $tab_top + $this->tabTitleHeight;
556 $pageposbeforeprintlines = $pdf->getPage();
557 $pagenb = $pageposbeforeprintlines;
559 $pdf_sub_options = array();
560 $pdf_sub_options[
'titleshowuponpdf'] = 1;
561 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
563 for ($i = 0; $i < $nblines; $i++) {
564 $linePosition = $i + 1;
567 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
569 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
570 $level =
$object->lines[$i]->qty;
572 if (isset($sub_options[
'titleshowuponpdf'])) {
573 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
574 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
575 unset($pdf_sub_options[
'titleshowuponpdf']);
577 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
578 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
579 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
580 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
583 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
584 unset($pdf_sub_options[
'titleshowuponpdf']);
586 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
587 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
592 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
593 $object->lines[$i]->pagebreak =
true;
597 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
600 if (!empty($tplidx)) {
601 $pdf->useTemplate($tplidx);
604 $pdf->setPage($pdf->getNumPages());
605 $nexY = $curY = $tab_top_newpage;
611 $pdf->SetFont(
'',
'', $default_font_size - 1);
612 $pdf->SetTextColor(0, 0, 0);
615 $imglinesize = array();
616 if (!empty($realpatharray[$i])) {
620 $pdf->setTopMargin($tab_top_newpage);
621 $pdf->setPageOrientation(
'',
true, $heightforfooter);
622 $pageposbefore = $pdf->getPage();
626 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
632 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
633 $pdf->AddPage(
'',
'',
true);
634 if (!empty($tplidx)) {
635 $pdf->useTemplate($tplidx);
637 $pdf->setPage($pageposbefore + 1);
638 $pdf->setPageOrientation(
'',
true, $heightforfooter);
639 $curY = $tab_top_newpage;
640 $showpricebeforepagebreak = 0;
647 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
648 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
650 $posYAfterImage = $curY + $imglinesize[
'height'];
656 $pdf->setPageOrientation(
'',
true, $heightforfooter);
660 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
665 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
670 $pdf->setPage($pageposbefore);
671 $pdf->setTopMargin($this->marge_haute);
672 $pdf->setPageOrientation(
'',
false, $heightforfooter);
675 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
676 $pdf->setPage($afterPosData[
'page']);
677 $curY = $tab_top_newpage;
680 $pdf->SetFont(
'',
'', $default_font_size - 1);
694 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
714 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
721 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
724 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
725 if (isModEnabled(
'multicurrency') &&
$object->multicurrency_code !=
$conf->currency) {
726 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
728 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
741 if (!empty(
$object->lines[$i]->array_options)) {
742 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
757 'nexY' => & $afterPosData[
'y'],
758 'outputlangs' => $outputlangs,
759 'hidedetails' => $hidedetails
761 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
765 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
766 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
768 $tvaligne =
$object->lines[$i]->total_tva;
771 $localtax1ligne =
$object->lines[$i]->total_localtax1;
772 $localtax2ligne =
$object->lines[$i]->total_localtax2;
773 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
774 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
775 $localtax1_type =
$object->lines[$i]->localtax1_type;
776 $localtax2_type =
$object->lines[$i]->localtax2_type;
778 $vatrate = (string)
$object->lines[$i]->tva_tx;
781 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
782 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
784 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
785 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
789 if ($localtax1_type && $localtax1ligne != 0) {
790 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
791 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
793 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
796 if ($localtax2_type && $localtax2ligne != 0) {
797 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
798 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
800 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
804 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
809 if (!isset($this->tva[$vatrate])) {
810 $this->tva[$vatrate] = 0;
812 $this->tva[$vatrate] += $tvaligne;
813 $vatcode =
$object->lines[$i]->vat_src_code;
814 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
815 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
817 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
820 $pdf->setPage($afterPosData[
'page']);
821 $nexY = $afterPosData[
'y'];
824 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
825 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
827 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
828 $pdf->SetLineStyle(array(
'dash' => 0));
836 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
838 if (!empty($tplidx)) {
839 $pdf->useTemplate($tplidx);
842 $pdf->setPage($pagenb);
846 $drawTabNumbPage = $pdf->getNumPages();
847 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
850 $pdf->setPageOrientation(
'',
false, 0);
852 $drawTabHideTop = $hidetop;
853 $drawTabTop = $tab_top_newpage;
854 $drawTabBottom = $this->page_hauteur - $heightforfooter;
857 if ($i == $pageposbeforeprintlines) {
859 $drawTabTop = $tab_top;
860 } elseif (!$drawTabHideTop) {
862 $drawTabTop -= $this->tabTitleHeight;
869 if ($i == $pdf->getNumPages()) {
871 $drawTabBottom -= $heightforfreetext + $heightforinfotot;
874 $drawTabHeight = $drawTabBottom - $drawTabTop;
875 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
877 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
883 $pdf->setPageOrientation(
'',
true, 0);
886 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
889 if (!empty($tplidx)) {
890 $pdf->useTemplate($tplidx);
895 $pdf->SetTextColor(0, 0, 0);
897 $pdf->setPage($pdf->getNumPages());
899 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
909 if (method_exists($pdf,
'AliasNbPages')) {
910 $pdf->AliasNbPages();
916 $termsofsale =
$conf->order->dir_output.
'/'.$termsofsalefilename;
917 if (!empty(
$conf->order->multidir_output[
$conf->entity])) {
918 $termsofsale =
$conf->order->multidir_output[
$conf->entity].
'/'.$termsofsalefilename;
920 if (file_exists($termsofsale) && is_readable($termsofsale)) {
921 $pagecount = $pdf->setSourceFile($termsofsale);
922 for ($i = 1; $i <= $pagecount; $i++) {
923 $tplIdx = $pdf->importPage($i);
924 if ($tplIdx !==
false) {
925 $s = $pdf->getTemplatesize($tplIdx);
926 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
927 $pdf->useTemplate($tplIdx);
929 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
937 $pdf->Output($file,
'F');
940 $hookmanager->initHooks(array(
'pdfgeneration'));
941 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
943 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
945 $this->error = $hookmanager->error;
946 $this->errors = $hookmanager->errors;
951 $this->result = array(
'fullpath' => $file);
955 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
959 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
989 global
$conf, $mysoc;
992 $pdf->SetFont(
'',
'', $default_font_size - 1);
997 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
998 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
999 $pdf->SetXY($this->marge_gauche, $posy);
1000 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1002 $posy = $pdf->GetY() + 4;
1011 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1012 $pdf->SetXY($this->marge_gauche, $posy);
1013 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1014 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1016 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1017 $pdf->SetXY($posxval, $posy);
1018 $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);
1019 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1020 if (
$object->deposit_percent > 0) {
1021 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', (
string)
$object->deposit_percent, $lib_condition_paiement);
1023 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1025 $posy = $pdf->GetY() + 3;
1056 if (!empty(
$object->delivery_date)) {
1057 $outputlangs->load(
"sendings");
1058 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1059 $pdf->SetXY($this->marge_gauche, $posy);
1060 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1061 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1062 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1063 $pdf->SetXY($posxval, $posy);
1065 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1067 $posy = $pdf->GetY() + 1;
1069 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1070 $pdf->SetXY($this->marge_gauche, $posy);
1071 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1072 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1073 $pdf->SetTextColor(0, 0, 0);
1074 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1075 $pdf->SetXY($posxval, $posy);
1076 $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 :
'');
1077 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1078 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1080 $posy = $pdf->GetY() + 1;
1084 if (
$object->mode_reglement_code
1085 &&
$object->mode_reglement_code !=
'CHQ'
1086 &&
$object->mode_reglement_code !=
'VIR') {
1087 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1088 $pdf->SetXY($this->marge_gauche, $posy);
1089 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1090 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1092 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1093 $pdf->SetXY($posxval, $posy);
1094 $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);
1095 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1097 $posy = $pdf->GetY() + 2;
1101 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1105 $account =
new Account($this->db);
1108 $pdf->SetXY($this->marge_gauche, $posy);
1109 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1110 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1111 $posy = $pdf->GetY() + 1;
1114 $pdf->SetXY($this->marge_gauche, $posy);
1115 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1116 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1117 $posy = $pdf->GetY() + 2;
1120 if (
$conf->global->FACTURE_CHQ_NUMBER == -1) {
1121 $pdf->SetXY($this->marge_gauche, $posy);
1122 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1123 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1124 $posy = $pdf->GetY() + 1;
1127 $pdf->SetXY($this->marge_gauche, $posy);
1128 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1129 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1130 $posy = $pdf->GetY() + 2;
1137 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1139 $bankid = (
$object->fk_account <= 0 ?
$conf->global->FACTURE_RIB_NUMBER :
$object->fk_account);
1143 $account =
new Account($this->db);
1144 $account->fetch($bankid);
1146 $curx = $this->marge_gauche;
1149 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1172 global
$conf, $mysoc, $hookmanager;
1179 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1180 $default_font_size--;
1185 $pdf->SetFont(
'',
'', $default_font_size - 1);
1190 if ($this->page_largeur < 210) {
1193 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1199 $total_ht = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1 ?
$object->multicurrency_total_ht :
$object->total_ht);
1202 $total_discount_on_lines = 0;
1203 $multicurrency_total_discount_on_lines = 0;
1204 foreach (
$object->lines as $i => $line) {
1208 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1209 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1211 if ($line->total_ht < 0) {
1212 $total_discount_on_lines += -$line->total_ht;
1213 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1217 if ($total_discount_on_lines > 0) {
1219 $pdf->SetFillColor(255, 255, 255);
1220 $pdf->SetXY($col1x, $tab2_top);
1221 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1222 $pdf->SetXY($col2x, $tab2_top);
1224 $total_before_discount_to_show = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? (
$object->multicurrency_total_ht + $multicurrency_total_discount_on_lines) : (
$object->total_ht + $total_discount_on_lines));
1225 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1229 $pdf->SetFillColor(255, 255, 255);
1230 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1231 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1232 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1234 $total_discount_to_show = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1235 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1241 $pdf->SetFillColor(255, 255, 255);
1242 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1243 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1244 $total_ht = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
1245 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1246 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1249 $pdf->SetFillColor(248, 248, 248);
1251 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
1252 $total_ttc_origin =
$object->total_ttc;
1254 $this->atleastoneratenotnull = 0;
1256 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1257 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1261 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1262 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1265 foreach ($localtax_rate as $tvakey => $tvaval) {
1269 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1272 if (preg_match(
'/\*/', (
string) $tvakey)) {
1273 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1274 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1276 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1280 $totalvat .= $tvacompl;
1282 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1285 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1287 $total_localtax = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1289 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1290 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1296 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1297 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1300 foreach ($localtax_rate as $tvakey => $tvaval) {
1305 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1308 if (preg_match(
'/\*/', (
string) $tvakey)) {
1309 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1310 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1312 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1316 $totalvat .= $tvacompl;
1318 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1321 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1323 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1325 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1326 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1332 foreach ($this->tva_array as $tvakey => $tvaval) {
1334 $this->atleastoneratenotnull++;
1337 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1340 if (preg_match(
'/\*/', $tvakey)) {
1341 $tvakey = str_replace(
'*',
'', $tvakey);
1342 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1344 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1347 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1349 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1351 $totalvat .= $tvacompl;
1353 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1355 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1357 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1358 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
1363 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1364 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1368 foreach ($localtax_rate as $tvakey => $tvaval) {
1373 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1376 if (preg_match(
'/\*/', (
string) $tvakey)) {
1377 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1378 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1380 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1384 $totalvat .= $tvacompl;
1386 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1389 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1391 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1393 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1394 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1400 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1401 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1405 foreach ($localtax_rate as $tvakey => $tvaval) {
1411 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1414 if (preg_match(
'/\*/', (
string) $tvakey)) {
1415 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1416 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1418 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1422 $totalvat .= $tvacompl;
1424 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1427 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1429 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1431 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1432 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1440 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1441 $pdf->SetTextColor(0, 0, 60);
1442 $pdf->SetFillColor(224, 224, 224);
1443 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC", $mysoc->country_code) :
''), $useborder,
'L',
true);
1445 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1446 if (!isModEnabled(
"multicurrency") ||
$object->multicurrency_tx == 1 ||
getDolGlobalInt(
'MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1447 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1449 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1453 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1454 $pdf->SetTextColor(0, 0, 60);
1455 $pdf->SetFillColor(224, 224, 224);
1456 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).
')', $useborder,
'L',
true);
1458 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1459 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder,
'L',
true);
1464 $pdf->SetTextColor(0, 0, 0);
1466 $creditnoteamount = 0;
1467 $depositsamount = 0;
1471 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1476 if ($deja_regle > 0) {
1480 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1481 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1482 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1483 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1486 $pdf->SetTextColor(0, 0, 60);
1487 $pdf->SetFillColor(224, 224, 224);
1488 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1489 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1491 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1492 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1494 $pdf->SetFont(
'',
'', $default_font_size - 1);
1495 $pdf->SetTextColor(0, 0, 0);
1498 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1500 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1502 $this->error = $hookmanager->error;
1503 $this->errors = $hookmanager->errors;
1507 return ($tab2_top + ($tab2_hl * $index));
1584 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1587 global
$conf, $langs, $hookmanager, $mysoc;
1589 $ltrdirection =
'L';
1590 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1591 $ltrdirection =
'R';
1595 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1601 $pdf->SetTextColor(0, 0, 60);
1602 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1606 $posy = $this->marge_haute;
1607 $posx = $this->page_largeur - $this->marge_droite - $w;
1609 $pdf->SetXY($this->marge_gauche, $posy);
1613 if ($this->emetteur->logo) {
1614 $logodir =
$conf->mycompany->dir_output;
1619 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1621 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1623 if (is_readable($logo)) {
1625 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1627 $pdf->SetTextColor(200, 0, 0);
1628 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1629 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1630 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1633 $text = $this->emetteur->name;
1634 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1638 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1639 $pdf->SetXY($posx, $posy);
1640 $pdf->SetTextColor(0, 0, 60);
1641 $title = $outputlangs->transnoentities($titlekey);
1642 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1644 $title .= $outputlangsbis->transnoentities($titlekey);
1646 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1647 if (
$object->statut == $object::STATUS_DRAFT) {
1648 $pdf->SetTextColor(128, 0, 0);
1649 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1652 $pdf->MultiCell($w, 3, $title,
'',
'R');
1654 $pdf->SetFont(
'',
'B', $default_font_size);
1669 $pdf->SetFont(
'',
'', $default_font_size - 2);
1673 $pdf->SetXY($posx, $posy);
1674 $pdf->SetTextColor(0, 0, 60);
1675 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
1680 if (!empty(
$object->project->ref)) {
1682 $pdf->SetXY($posx, $posy);
1683 $pdf->SetTextColor(0, 0, 60);
1684 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1690 if (!empty(
$object->project->ref)) {
1691 $outputlangs->load(
"projects");
1693 $pdf->SetXY($posx, $posy);
1694 $pdf->SetTextColor(0, 0, 60);
1695 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1701 $pdf->SetXY($posx, $posy);
1702 $pdf->SetTextColor(0, 0, 60);
1703 $title = $outputlangs->transnoentities(
"OrderDate");
1704 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1705 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1707 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1711 $pdf->SetXY($posx, $posy);
1712 $pdf->SetTextColor(0, 0, 60);
1713 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
1718 $pdf->SetXY($posx, $posy);
1719 $pdf->SetTextColor(0, 0, 60);
1720 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
1725 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1726 if (count($arrayidcontact) > 0) {
1727 $usertmp =
new User($this->db);
1728 $usertmp->fetch($arrayidcontact[0]);
1730 $pdf->SetXY($posx, $posy);
1731 $pdf->SetTextColor(0, 0, 60);
1732 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1741 $current_y = $pdf->getY();
1743 if ($current_y < $pdf->getY()) {
1744 $top_shift = $pdf->getY() - $current_y;
1749 $carac_emetteur =
'';
1751 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1752 if (count($arrayidcontact) > 0) {
1753 $object->fetch_user($arrayidcontact[0]);
1754 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1755 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1757 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1761 $carac_emetteur .=
"\n";
1768 $posy += $top_shift;
1769 $posx = $this->marge_gauche;
1771 $posx = $this->page_largeur - $this->marge_droite - 80;
1775 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1780 $pdf->SetTextColor(0, 0, 0);
1781 $pdf->SetFont(
'',
'', $default_font_size - 2);
1782 $pdf->SetXY($posx, $posy - 5);
1783 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1784 $pdf->SetXY($posx, $posy);
1785 $pdf->SetFillColor(230, 230, 230);
1786 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1787 $pdf->SetTextColor(0, 0, 60);
1792 $pdf->SetXY($posx + 2, $posy + 3);
1793 $pdf->SetFont(
'',
'B', $default_font_size);
1794 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1795 $posy = $pdf->getY();
1799 $pdf->SetXY($posx + 2, $posy);
1800 $pdf->SetFont(
'',
'', $default_font_size - 1);
1801 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1804 $usecontact =
false;
1805 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1806 if (count($arrayidcontact) > 0) {
1808 $result =
$object->fetch_contact($arrayidcontact[0]);
1813 $thirdparty =
$object->contact;
1815 $thirdparty =
$object->thirdparty;
1818 if (is_object($thirdparty)) {
1821 $carac_client_name =
'';
1828 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1829 if ($this->page_largeur < 210) {
1833 $posy += $top_shift;
1834 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1836 $posx = $this->marge_gauche;
1841 $pdf->SetTextColor(0, 0, 0);
1842 $pdf->SetFont(
'',
'', $default_font_size - 2);
1843 $pdf->SetXY($posx + 2, $posy - 5);
1844 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1845 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1849 $pdf->SetXY($posx + 2, $posy + 3);
1850 $pdf->SetFont(
'',
'B', $default_font_size);
1852 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1854 $posy = $pdf->getY();
1857 $pdf->SetFont(
'',
'', $default_font_size - 1);
1858 $pdf->SetXY($posx + 2, $posy);
1860 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1864 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1866 if (!empty($idaddressshipping)) {
1867 $contactshipping =
$object->fetch_contact($idaddressshipping[0]);
1868 $companystatic =
new Societe($this->db);
1869 $companystatic->fetch(
$object->contact->fk_soc);
1876 if (!empty($carac_client_shipping)) {
1877 $posy += $hautcadre;
1882 $pdf->SetXY($posx + 2, $posy - 5);
1883 $pdf->SetFont(
'',
'', $default_font_size - 2);
1884 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1885 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1888 $pdf->SetXY($posx + 2, $posy + 1);
1889 $pdf->SetFont(
'',
'B', $default_font_size);
1890 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
1892 $posy = $pdf->getY();
1895 $pdf->SetXY($posx + 2, $posy);
1896 $pdf->SetFont(
'',
'', $default_font_size - 1);
1897 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
1899 $shipp_shift += $hautcadre + 10;
1904 $pdf->SetTextColor(0, 0, 0);
1906 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);