173 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
176 global $user, $langs,
$conf,
$mysoc, $db, $hookmanager, $nblines;
178 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
180 if (!is_object($outputlangs)) {
181 $outputlangs = $langs;
185 $outputlangs->charset_output =
'ISO-8859-1';
189 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"sendginds",
"compta"));
196 global $outputlangsbis;
197 $outputlangsbis =
null;
201 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"sendginds",
"compta"));
204 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
209 $realpatharray = array();
210 $this->atleastonephoto =
false;
212 $objphoto =
new Product($this->db);
214 for ($i = 0; $i < $nblines; $i++) {
215 if (empty(
$object->lines[$i]->fk_product)) {
221 $objphoto->fetch(
$object->lines[$i]->fk_product);
224 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
225 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
227 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
228 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
233 foreach ($pdir as $midir) {
235 $entity = $objphoto->entity;
236 if ($entity !==
null &&
$conf->entity != $entity) {
237 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
239 $dir =
$conf->product->dir_output.
'/'.$midir;
242 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
244 if ($obj[
'photo_vignette']) {
245 $filename = $obj[
'photo_vignette'];
247 $filename = $obj[
'photo'];
250 $filename = $obj[
'photo'];
253 $realpath = $dir.$filename;
255 $this->atleastonephoto =
true;
260 if ($realpath && $arephoto) {
261 $realpatharray[$i] = $realpath;
276 $file = $dir.
"/SPECIMEN.pdf";
280 $file = $dir.
"/".$objectref.
".pdf";
285 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir",
"Null dir");
289 if (!file_exists($dir)) {
291 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
296 if (file_exists($dir)) {
298 if (!is_object($hookmanager)) {
299 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
302 $hookmanager->initHooks(array(
'pdfgeneration'));
303 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
305 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
308 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
313 $pdf->setAutoPageBreak(
true, 0);
315 $heightforinfotot = 40;
317 $heightforfooter = $this->marge_basse + 8;
319 $heightforfooter += 6;
322 if (class_exists(
'TCPDF')) {
323 $pdf->setPrintHeader(
false);
324 $pdf->setPrintFooter(
false);
329 $logodir =
$conf->mycompany->dir_output;
330 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
333 $pagecount = $pdf->setSourceFile($logodir.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
334 $tplidx = $pdf->importPage(1);
339 $pdf->SetDrawColor(128, 128, 128);
341 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
342 $pdf->SetSubject($outputlangs->transnoentities(
"PdfOrderTitle"));
343 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
344 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
345 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfOrderTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
347 $pdf->SetCompression(
false);
351 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
354 for ($i = 0; $i < $nblines; $i++) {
355 if (
$object->lines[$i]->remise_percent) {
356 $this->atleastonediscount++;
363 if (!empty($tplidx)) {
364 $pdf->useTemplate($tplidx);
367 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis :
null));
368 $top_shift = $pagehead[
'top_shift'];
369 $shipp_shift = $pagehead[
'shipp_shift'];
370 $pdf->SetFont(
'',
'', $default_font_size - 1);
371 $pdf->MultiCell(0, 3,
'');
372 $pdf->SetTextColor(0, 0, 0);
375 $tab_top = 80 + $this->marge_haute + $top_shift + $shipp_shift;
376 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
377 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
379 $tab_top_newpage += $this->tabTitleHeight;
382 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
384 $nexY = $tab_top - 1;
387 $height_incoterms = 0;
389 $desc_incoterms =
$object->getIncotermsForPDF();
390 if ($desc_incoterms) {
393 $pdf->SetFont(
'',
'', $default_font_size - 1);
394 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
395 $nexY = max($pdf->GetY(), $nexY);
396 $height_incoterms = $nexY - $tab_top;
399 $pdf->SetDrawColor(192, 192, 192);
400 $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');
402 $tab_top = $nexY + 6;
407 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
410 if (is_object(
$object->thirdparty)) {
411 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
412 $salerepobj =
new User($this->db);
413 $salerepobj->fetch($salereparray[0][
'id']);
414 if (!empty($salerepobj->signature)) {
415 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
420 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
421 if (!empty($extranote)) {
425 $pagenb = $pdf->getPage();
429 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
430 $pageposbeforenote = $pagenb;
437 $pdf->startTransaction();
439 $pdf->SetFont(
'',
'', $default_font_size - 1);
440 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
442 $pageposafternote = $pdf->getPage();
443 $posyafter = $pdf->GetY();
445 if ($pageposafternote > $pageposbeforenote) {
446 $pdf->rollbackTransaction(
true);
449 while ($pagenb < $pageposafternote) {
452 if (!empty($tplidx)) {
453 $pdf->useTemplate($tplidx);
459 $pdf->setTopMargin($tab_top_newpage);
461 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
465 $pdf->setPage($pageposbeforenote);
466 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
467 $pdf->SetFont(
'',
'', $default_font_size - 1);
468 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
469 $pageposafternote = $pdf->getPage();
471 $posyafter = $pdf->GetY();
473 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
474 $pdf->AddPage(
'',
'',
true);
477 $pdf->setPage($pageposafternote);
478 $pdf->setTopMargin($tab_top_newpage);
480 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
486 $i = $pageposbeforenote;
487 while ($i < $pageposafternote) {
491 $pdf->SetDrawColor(128, 128, 128);
493 if ($i > $pageposbeforenote) {
494 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
495 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
497 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
498 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
502 $pdf->setPageOrientation(
'',
true, 0);
509 $pdf->setPage($pageposafternote);
510 if (!empty($tplidx)) {
511 $pdf->useTemplate($tplidx);
516 $height_note = $posyafter - $tab_top_newpage;
517 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
520 $pdf->commitTransaction();
521 $posyafter = $pdf->GetY();
522 $height_note = $posyafter - $tab_top;
523 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
526 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
528 $pdf->AddPage(
'',
'',
true);
531 $pdf->setPage($pageposafternote);
532 if (!empty($tplidx)) {
533 $pdf->useTemplate($tplidx);
539 $posyafter = $tab_top_newpage;
543 $tab_height -= $height_note;
544 $tab_top = $posyafter + 6;
554 $pdf->startTransaction();
555 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
556 $pdf->rollbackTransaction(
true);
558 $nexY = $tab_top + $this->tabTitleHeight;
561 $pageposbeforeprintlines = $pdf->getPage();
562 $pagenb = $pageposbeforeprintlines;
564 $pdf_sub_options = array();
565 $pdf_sub_options[
'titleshowuponpdf'] = 1;
566 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
567 $pdf_sub_options_before_title = array();
571 for ($i = 0; $i < $nblines; $i++) {
572 $linePosition = $i + 1;
575 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
577 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
578 $level =
$object->lines[$i]->qty;
580 if ($level > 0 && !isset($pdf_sub_options_before_title[(
int) $level])) {
581 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
585 if (isset($sub_options[
'titleshowuponpdf'])) {
586 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
587 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
588 unset($pdf_sub_options[
'titleshowuponpdf']);
590 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
591 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
592 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
593 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
596 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
597 unset($pdf_sub_options[
'titleshowuponpdf']);
599 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
600 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
604 if ($level < 0 && isset($pdf_sub_options_before_title[(
int) abs($level)])) {
605 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
606 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
607 if ($tmplevel >= abs($level)) {
608 unset($pdf_sub_options_before_title[$tmplevel]);
614 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
616 $pdf_sub_options = array();
617 $pdf_sub_options[
'titleshowuponpdf'] = 1;
618 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
625 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
626 $object->lines[$i]->pagebreak =
true;
630 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
633 if (!empty($tplidx)) {
634 $pdf->useTemplate($tplidx);
637 $pdf->setPage($pdf->getNumPages());
638 $nexY = $curY = $tab_top_newpage;
644 $pdf->SetFont(
'',
'', $default_font_size - 1);
645 $pdf->SetTextColor(0, 0, 0);
648 $imglinesize = array();
649 if (!empty($realpatharray[$i])) {
653 $pdf->setTopMargin($tab_top_newpage);
654 $pdf->setPageOrientation(
'',
true, $heightforfooter);
655 $pageposbefore = $pdf->getPage();
659 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
665 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
666 $pdf->AddPage(
'',
'',
true);
667 if (!empty($tplidx)) {
668 $pdf->useTemplate($tplidx);
670 $pdf->setPage($pageposbefore + 1);
671 $pdf->setPageOrientation(
'',
true, $heightforfooter);
672 $curY = $tab_top_newpage;
673 $showpricebeforepagebreak = 0;
680 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
681 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
683 $posYAfterImage = $curY + $imglinesize[
'height'];
689 $pdf->setPageOrientation(
'',
true, $heightforfooter);
693 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
698 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
703 $pdf->setPage($pageposbefore);
704 $pdf->setTopMargin($this->marge_haute);
705 $pdf->setPageOrientation(
'',
false, $heightforfooter);
708 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
709 $pdf->setPage($afterPosData[
'page']);
710 $curY = $tab_top_newpage;
713 $pdf->SetFont(
'',
'', $default_font_size - 1);
727 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
747 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
754 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
757 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
759 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
761 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
768 if ($this->
getColumnStatus(
'totalincltax') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
774 if (!empty(
$object->lines[$i]->array_options)) {
775 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
790 'nexY' => & $afterPosData[
'y'],
791 'outputlangs' => $outputlangs,
792 'hidedetails' => $hidedetails
794 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
799 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
801 $tvaligne =
$object->lines[$i]->total_tva;
804 $localtax1ligne =
$object->lines[$i]->total_localtax1;
805 $localtax2ligne =
$object->lines[$i]->total_localtax2;
806 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
807 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
808 $localtax1_type =
$object->lines[$i]->localtax1_type;
809 $localtax2_type =
$object->lines[$i]->localtax2_type;
814 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
815 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
817 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
818 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
822 if ($localtax1_type && $localtax1ligne != 0) {
823 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
824 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
826 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
829 if ($localtax2_type && $localtax2ligne != 0) {
830 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
831 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
833 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
837 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
842 if (!isset($this->tva[$vatrate])) {
843 $this->tva[$vatrate] = 0;
845 $this->tva[$vatrate] += $tvaligne;
846 $vatcode =
$object->lines[$i]->vat_src_code;
847 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
848 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
850 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
853 if (!$hidenextline) {
855 $pdf->setPage($afterPosData[
'page']);
856 $nexY = $afterPosData[
'y'];
859 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
860 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
862 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
863 $pdf->SetLineStyle(array(
'dash' => 0));
866 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
875 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
877 if (!empty($tplidx)) {
878 $pdf->useTemplate($tplidx);
881 $pdf->setPage($pagenb);
885 $drawTabNumbPage = $pdf->getNumPages();
886 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
889 $pdf->setPageOrientation(
'',
false, 0);
891 $drawTabHideTop = $hidetop;
892 $drawTabTop = $tab_top_newpage;
893 $drawTabBottom = $this->page_hauteur - $heightforfooter;
896 if ($i == $pageposbeforeprintlines) {
898 $drawTabTop = $tab_top;
899 } elseif (!$drawTabHideTop) {
901 $drawTabTop -= $this->tabTitleHeight;
908 if ($i == $pdf->getNumPages()) {
910 $drawTabBottom -= $heightforfreetext + $heightforinfotot;
913 $drawTabHeight = $drawTabBottom - $drawTabTop;
914 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
916 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
922 $pdf->setPageOrientation(
'',
true, 0);
925 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
928 if (!empty($tplidx)) {
929 $pdf->useTemplate($tplidx);
934 $pdf->SetTextColor(0, 0, 0);
936 $pdf->setPage($pdf->getNumPages());
938 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
948 if (method_exists($pdf,
'AliasNbPages')) {
949 $pdf->AliasNbPages();
954 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_ORDER') && $termsofsalefilename) {
955 $termsofsale =
$conf->order->dir_output.
'/'.$termsofsalefilename;
956 if (!empty(
$conf->order->multidir_output[
$conf->entity])) {
957 $termsofsale =
$conf->order->multidir_output[
$conf->entity].
'/'.$termsofsalefilename;
959 if (file_exists($termsofsale) && is_readable($termsofsale)) {
960 $pagecount = $pdf->setSourceFile($termsofsale);
961 for ($i = 1; $i <= $pagecount; $i++) {
962 $tplIdx = $pdf->importPage($i);
963 if ($tplIdx !==
false) {
964 $s = $pdf->getTemplatesize($tplIdx);
965 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
966 $pdf->useTemplate($tplIdx);
968 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
976 $pdf->Output($file,
'F');
979 $hookmanager->initHooks(array(
'pdfgeneration'));
980 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
982 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
983 $this->warnings = $hookmanager->warnings;
985 $this->error = $hookmanager->error;
986 $this->errors = $hookmanager->errors;
993 $this->result = array(
'fullpath' => $file);
997 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1001 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
1034 $pdf->SetFont(
'',
'', $default_font_size - 1);
1039 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1040 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1041 $pdf->SetXY($this->marge_gauche, $posy);
1042 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1044 $posy = $pdf->GetY() + 4;
1053 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1054 $pdf->SetXY($this->marge_gauche, $posy);
1055 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1056 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1058 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1059 $pdf->SetXY($posxval, $posy);
1060 $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);
1061 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1062 if (
$object->deposit_percent > 0) {
1063 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', (
string)
$object->deposit_percent, $lib_condition_paiement);
1065 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1067 $posy = $pdf->GetY() + 3;
1098 if (!empty(
$object->delivery_date)) {
1099 $outputlangs->load(
"sendings");
1100 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1101 $pdf->SetXY($this->marge_gauche, $posy);
1102 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1103 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1104 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1105 $pdf->SetXY($posxval, $posy);
1107 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1109 $posy = $pdf->GetY() + 1;
1111 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1112 $pdf->SetXY($this->marge_gauche, $posy);
1113 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1114 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1115 $pdf->SetTextColor(0, 0, 0);
1116 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1117 $pdf->SetXY($posxval, $posy);
1118 $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 :
'');
1119 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1120 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1122 $posy = $pdf->GetY() + 1;
1126 if (
$object->mode_reglement_code
1127 &&
$object->mode_reglement_code !=
'CHQ'
1128 &&
$object->mode_reglement_code !=
'VIR') {
1129 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1130 $pdf->SetXY($this->marge_gauche, $posy);
1131 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1132 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1134 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1135 $pdf->SetXY($posxval, $posy);
1136 $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);
1137 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1139 $posy = $pdf->GetY() + 2;
1143 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1147 $account =
new Account($this->db);
1150 $pdf->SetXY($this->marge_gauche, $posy);
1151 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1152 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1153 $posy = $pdf->GetY() + 1;
1156 $pdf->SetXY($this->marge_gauche, $posy);
1157 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1158 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1159 $posy = $pdf->GetY() + 2;
1163 $pdf->SetXY($this->marge_gauche, $posy);
1164 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1165 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1166 $posy = $pdf->GetY() + 1;
1169 $pdf->SetXY($this->marge_gauche, $posy);
1170 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1171 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1172 $posy = $pdf->GetY() + 2;
1179 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1181 $bankid = (
$object->fk_account <= 0 ?
$conf->global->FACTURE_RIB_NUMBER :
$object->fk_account);
1185 $account =
new Account($this->db);
1186 $account->fetch($bankid);
1188 $curx = $this->marge_gauche;
1191 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1221 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1222 $default_font_size--;
1227 $pdf->SetFont(
'',
'', $default_font_size - 1);
1232 if ($this->page_largeur < 210) {
1235 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1244 $total_discount_on_lines = 0;
1245 $multicurrency_total_discount_on_lines = 0;
1246 foreach (
$object->lines as $i => $line) {
1250 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1251 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1253 if ($line->total_ht < 0) {
1254 $total_discount_on_lines += -$line->total_ht;
1255 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1259 if ($total_discount_on_lines > 0) {
1260 if ($this->showAmountBeforeDiscount) {
1262 $pdf->SetFillColor(255, 255, 255);
1263 $pdf->SetXY($col1x, $tab2_top);
1264 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1265 $pdf->SetXY($col2x, $tab2_top);
1267 $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));
1268 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1273 if ($this->showDiscountAmount) {
1274 $pdf->SetFillColor(255, 255, 255);
1275 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1276 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1277 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1279 $total_discount_to_show = ((
isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1280 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1287 $pdf->SetFillColor(255, 255, 255);
1288 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1289 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1291 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1292 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1295 $pdf->SetFillColor(248, 248, 248);
1298 $total_ttc_origin =
$object->total_ttc;
1300 $this->atleastoneratenotnull = 0;
1302 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1303 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1307 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1308 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1311 foreach ($localtax_rate as $tvakey => $tvaval) {
1315 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1318 if (preg_match(
'/\*/', (
string) $tvakey)) {
1319 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1320 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1322 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1326 $totalvat .= $tvacompl;
1328 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1331 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1335 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1336 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1342 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1343 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1346 foreach ($localtax_rate as $tvakey => $tvaval) {
1351 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1354 if (preg_match(
'/\*/', (
string) $tvakey)) {
1355 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1356 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1358 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1362 $totalvat .= $tvacompl;
1364 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1367 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1371 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1372 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1378 foreach ($this->tva_array as $tvakey => $tvaval) {
1379 if ((
float) $tvakey != 0) {
1380 $this->atleastoneratenotnull++;
1383 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1386 if (preg_match(
'/\*/', $tvakey)) {
1387 $tvakey = str_replace(
'*',
'', $tvakey);
1388 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1390 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1393 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1395 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1397 $totalvat .= $tvacompl;
1399 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1401 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1403 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1404 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
1409 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1410 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1414 foreach ($localtax_rate as $tvakey => $tvaval) {
1419 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1422 if (preg_match(
'/\*/', (
string) $tvakey)) {
1423 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1424 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1426 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1430 $totalvat .= $tvacompl;
1432 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1435 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1439 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1440 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1446 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1447 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1451 foreach ($localtax_rate as $tvakey => $tvaval) {
1457 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1460 if (preg_match(
'/\*/', (
string) $tvakey)) {
1461 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1462 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1464 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1468 $totalvat .= $tvacompl;
1470 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1473 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1477 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1478 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1486 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1487 $pdf->SetTextColor(0, 0, 60);
1488 $pdf->SetFillColor(224, 224, 224);
1489 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1491 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1493 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1495 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1499 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1500 $pdf->SetTextColor(0, 0, 60);
1501 $pdf->SetFillColor(224, 224, 224);
1502 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1504 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1505 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1510 $pdf->SetTextColor(0, 0, 0);
1512 $creditnoteamount = 0;
1513 $depositsamount = 0;
1517 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1522 if ($deja_regle > 0) {
1526 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1527 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1528 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1529 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1532 $pdf->SetTextColor(0, 0, 60);
1533 $pdf->SetFillColor(224, 224, 224);
1534 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1535 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1537 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1538 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1540 $pdf->SetFont(
'',
'', $default_font_size - 1);
1541 $pdf->SetTextColor(0, 0, 0);
1544 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1546 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1548 $this->error = $hookmanager->error;
1549 $this->errors = $hookmanager->errors;
1553 return ($tab2_top + ($tab2_hl * $index));
1630 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1635 $ltrdirection =
'L';
1636 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1637 $ltrdirection =
'R';
1641 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1647 $pdf->SetTextColor(0, 0, 60);
1648 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1652 $posy = $this->marge_haute;
1653 $posx = $this->page_largeur - $this->marge_droite - $w;
1655 $pdf->SetXY($this->marge_gauche, $posy);
1659 if ($this->emetteur->logo) {
1660 $logodir =
$conf->mycompany->dir_output;
1665 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1667 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1669 if (is_readable($logo)) {
1671 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1673 $pdf->SetTextColor(200, 0, 0);
1674 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1675 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1676 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1679 $text = $this->emetteur->name;
1680 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1684 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1685 $pdf->SetXY($posx, $posy);
1686 $pdf->SetTextColor(0, 0, 60);
1687 $title = $outputlangs->transnoentities($titlekey);
1688 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1690 $title .= $outputlangsbis->transnoentities($titlekey);
1692 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1693 if (
$object->status == $object::STATUS_DRAFT) {
1694 $pdf->SetTextColor(128, 0, 0);
1695 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1698 $pdf->MultiCell($w, 3, $title,
'',
'R');
1700 $pdf->SetFont(
'',
'B', $default_font_size);
1715 $pdf->SetFont(
'',
'', $default_font_size - 2);
1719 $pdf->SetXY($posx, $posy);
1720 $pdf->SetTextColor(0, 0, 60);
1721 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset((
string)
$object->ref_client), 65),
'',
'R');
1726 if (!empty(
$object->project->ref)) {
1728 $pdf->SetXY($posx, $posy);
1729 $pdf->SetTextColor(0, 0, 60);
1730 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
dol_trunc(
$object->project->title, 50)),
'',
'R');
1736 if (!empty(
$object->project->ref)) {
1737 $outputlangs->load(
"projects");
1739 $pdf->SetXY($posx, $posy);
1740 $pdf->SetTextColor(0, 0, 60);
1741 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1747 $pdf->SetXY($posx, $posy);
1748 $pdf->SetTextColor(0, 0, 60);
1749 $title = $outputlangs->transnoentities(
"OrderDate");
1750 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1751 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1753 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1757 $pdf->SetXY($posx, $posy);
1758 $pdf->SetTextColor(0, 0, 60);
1759 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
1764 $pdf->SetXY($posx, $posy);
1765 $pdf->SetTextColor(0, 0, 60);
1766 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
1771 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1772 if (count($arrayidcontact) > 0) {
1773 $usertmp =
new User($this->db);
1774 $usertmp->fetch($arrayidcontact[0]);
1776 $pdf->SetXY($posx, $posy);
1777 $pdf->SetTextColor(0, 0, 60);
1778 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1787 $current_y = $pdf->getY();
1789 if ($current_y < $pdf->getY()) {
1790 $top_shift = $pdf->getY() - $current_y;
1795 $carac_emetteur =
'';
1797 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1798 if (count($arrayidcontact) > 0) {
1799 $object->fetch_user($arrayidcontact[0]);
1800 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1801 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1803 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1807 $carac_emetteur .=
"\n";
1813 $posy =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
1814 $posy += $top_shift;
1815 $posx = $this->marge_gauche;
1817 $posx = $this->page_largeur - $this->marge_droite - 80;
1821 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1826 $pdf->SetTextColor(0, 0, 0);
1827 $pdf->SetFont(
'',
'', $default_font_size - 2);
1828 $pdf->SetXY($posx, $posy - 5);
1829 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1830 $pdf->SetXY($posx, $posy);
1831 $pdf->SetFillColor(230, 230, 230);
1832 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1833 $pdf->SetTextColor(0, 0, 60);
1838 $pdf->SetXY($posx + 2, $posy + 3);
1839 $pdf->SetFont(
'',
'B', $default_font_size);
1840 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1841 $posy = $pdf->getY();
1845 $pdf->SetXY($posx + 2, $posy);
1846 $pdf->SetFont(
'',
'', $default_font_size - 1);
1847 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1850 $usecontact =
false;
1851 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1852 if (count($arrayidcontact) > 0) {
1854 $result =
$object->fetch_contact($arrayidcontact[0]);
1859 $thirdparty =
$object->contact;
1861 $thirdparty =
$object->thirdparty;
1864 if (is_object($thirdparty)) {
1867 $carac_client_name =
'';
1874 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1875 if ($this->page_largeur < 210) {
1878 $posy =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : 32 + $this->marge_haute;
1879 $posy += $top_shift;
1880 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1882 $posx = $this->marge_gauche;
1887 $pdf->SetTextColor(0, 0, 0);
1888 $pdf->SetFont(
'',
'', $default_font_size - 2);
1889 $pdf->SetXY($posx + 2, $posy - 5);
1890 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1891 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1895 $pdf->SetXY($posx + 2, $posy + 3);
1896 $pdf->SetFont(
'',
'B', $default_font_size);
1898 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1900 $posy = $pdf->getY();
1903 $pdf->SetFont(
'',
'', $default_font_size - 1);
1904 $pdf->SetXY($posx + 2, $posy);
1906 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1910 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1912 if (!empty($idaddressshipping)) {
1913 $contactshipping =
$object->fetch_contact($idaddressshipping[0]);
1914 $companystatic =
new Societe($this->db);
1915 $companystatic->fetch(
$object->contact->fk_soc);
1922 if (!empty($carac_client_shipping)) {
1923 $posy += $hautcadre;
1928 $pdf->SetXY($posx + 2, $posy - 5);
1929 $pdf->SetFont(
'',
'', $default_font_size - 2);
1930 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1931 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1934 $pdf->SetXY($posx + 2, $posy + 1);
1935 $pdf->SetFont(
'',
'B', $default_font_size);
1936 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
1938 $posy = $pdf->getY();
1941 $pdf->SetXY($posx + 2, $posy);
1942 $pdf->SetFont(
'',
'', $default_font_size - 1);
1943 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
1945 $shipp_shift += $hautcadre + 10;
1950 $pdf->SetTextColor(0, 0, 0);
1952 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);