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",
"sendginds",
"compta"));
192 global $outputlangsbis;
193 $outputlangsbis =
null;
195 $outputlangsbis =
new Translate(
'', $conf);
197 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"sendginds",
"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 $entity = $objphoto->entity;
232 if ($entity !==
null && $conf->entity != $entity) {
233 $dir = $conf->product->multidir_output[$entity].
'/'.$midir;
235 $dir = $conf->product->dir_output.
'/'.$midir;
238 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
240 if ($obj[
'photo_vignette']) {
241 $filename = $obj[
'photo_vignette'];
243 $filename = $obj[
'photo'];
246 $filename = $obj[
'photo'];
249 $realpath = $dir.$filename;
251 $this->atleastonephoto =
true;
256 if ($realpath && $arephoto) {
257 $realpatharray[$i] = $realpath;
272 $file = $dir.
"/SPECIMEN.pdf";
276 $file = $dir.
"/".$objectref.
".pdf";
281 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir",
"Null dir");
285 if (!file_exists($dir)) {
287 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
292 if (file_exists($dir)) {
294 if (!is_object($hookmanager)) {
295 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
298 $hookmanager->initHooks(array(
'pdfgeneration'));
299 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
301 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
304 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
309 $pdf->setAutoPageBreak(
true, 0);
311 $heightforinfotot = 40;
313 $heightforfooter = $this->marge_basse + 8;
315 $heightforfooter += 6;
318 if (class_exists(
'TCPDF')) {
319 $pdf->setPrintHeader(
false);
320 $pdf->setPrintFooter(
false);
325 $logodir = $conf->mycompany->dir_output;
326 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
327 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
329 $pagecount = $pdf->setSourceFile($logodir.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
330 $tplidx = $pdf->importPage(1);
335 $pdf->SetDrawColor(128, 128, 128);
337 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
338 $pdf->SetSubject($outputlangs->transnoentities(
"PdfOrderTitle"));
339 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
340 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
341 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfOrderTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
343 $pdf->SetCompression(
false);
347 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
350 for ($i = 0; $i < $nblines; $i++) {
351 if (
$object->lines[$i]->remise_percent) {
352 $this->atleastonediscount++;
359 if (!empty($tplidx)) {
360 $pdf->useTemplate($tplidx);
363 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis :
null));
364 $top_shift = $pagehead[
'top_shift'];
365 $shipp_shift = $pagehead[
'shipp_shift'];
366 $pdf->SetFont(
'',
'', $default_font_size - 1);
367 $pdf->MultiCell(0, 3,
'');
368 $pdf->SetTextColor(0, 0, 0);
371 $tab_top = 90 + $top_shift + $shipp_shift;
372 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
373 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
375 $tab_top_newpage += $this->tabTitleHeight;
378 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
380 $nexY = $tab_top - 1;
383 $height_incoterms = 0;
385 $desc_incoterms =
$object->getIncotermsForPDF();
386 if ($desc_incoterms) {
389 $pdf->SetFont(
'',
'', $default_font_size - 1);
390 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
391 $nexY = max($pdf->GetY(), $nexY);
392 $height_incoterms = $nexY - $tab_top;
395 $pdf->SetDrawColor(192, 192, 192);
396 $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');
398 $tab_top = $nexY + 6;
403 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
406 if (is_object(
$object->thirdparty)) {
407 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
408 $salerepobj =
new User($this->db);
409 $salerepobj->fetch($salereparray[0][
'id']);
410 if (!empty($salerepobj->signature)) {
411 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
416 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
417 if (!empty($extranote)) {
421 $pagenb = $pdf->getPage();
425 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
426 $pageposbeforenote = $pagenb;
433 $pdf->startTransaction();
435 $pdf->SetFont(
'',
'', $default_font_size - 1);
436 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
438 $pageposafternote = $pdf->getPage();
439 $posyafter = $pdf->GetY();
441 if ($pageposafternote > $pageposbeforenote) {
442 $pdf->rollbackTransaction(
true);
445 while ($pagenb < $pageposafternote) {
448 if (!empty($tplidx)) {
449 $pdf->useTemplate($tplidx);
455 $pdf->setTopMargin($tab_top_newpage);
457 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
461 $pdf->setPage($pageposbeforenote);
462 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
463 $pdf->SetFont(
'',
'', $default_font_size - 1);
464 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
465 $pageposafternote = $pdf->getPage();
467 $posyafter = $pdf->GetY();
469 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
470 $pdf->AddPage(
'',
'',
true);
473 $pdf->setPage($pageposafternote);
474 $pdf->setTopMargin($tab_top_newpage);
476 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
482 $i = $pageposbeforenote;
483 while ($i < $pageposafternote) {
487 $pdf->SetDrawColor(128, 128, 128);
489 if ($i > $pageposbeforenote) {
490 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
491 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
493 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
494 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
498 $pdf->setPageOrientation(
'',
true, 0);
505 $pdf->setPage($pageposafternote);
506 if (!empty($tplidx)) {
507 $pdf->useTemplate($tplidx);
512 $height_note = $posyafter - $tab_top_newpage;
513 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
516 $pdf->commitTransaction();
517 $posyafter = $pdf->GetY();
518 $height_note = $posyafter - $tab_top;
519 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
522 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
524 $pdf->AddPage(
'',
'',
true);
527 $pdf->setPage($pageposafternote);
528 if (!empty($tplidx)) {
529 $pdf->useTemplate($tplidx);
535 $posyafter = $tab_top_newpage;
539 $tab_height -= $height_note;
540 $tab_top = $posyafter + 6;
550 $pdf->startTransaction();
551 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
552 $pdf->rollbackTransaction(
true);
554 $nexY = $tab_top + $this->tabTitleHeight;
557 $pageposbeforeprintlines = $pdf->getPage();
558 $pagenb = $pageposbeforeprintlines;
560 $pdf_sub_options = array();
561 $pdf_sub_options[
'titleshowuponpdf'] = 1;
562 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
566 for ($i = 0; $i < $nblines; $i++) {
567 $linePosition = $i + 1;
570 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
572 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
573 $level =
$object->lines[$i]->qty;
576 if (isset($sub_options[
'titleshowuponpdf'])) {
577 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
578 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
579 unset($pdf_sub_options[
'titleshowuponpdf']);
581 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
582 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
583 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
584 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
587 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
588 unset($pdf_sub_options[
'titleshowuponpdf']);
590 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
591 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
596 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
598 $pdf_sub_options = array();
599 $pdf_sub_options[
'titleshowuponpdf'] = 1;
600 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
607 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
608 $object->lines[$i]->pagebreak =
true;
612 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
615 if (!empty($tplidx)) {
616 $pdf->useTemplate($tplidx);
619 $pdf->setPage($pdf->getNumPages());
620 $nexY = $curY = $tab_top_newpage;
626 $pdf->SetFont(
'',
'', $default_font_size - 1);
627 $pdf->SetTextColor(0, 0, 0);
630 $imglinesize = array();
631 if (!empty($realpatharray[$i])) {
635 $pdf->setTopMargin($tab_top_newpage);
636 $pdf->setPageOrientation(
'',
true, $heightforfooter);
637 $pageposbefore = $pdf->getPage();
641 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
647 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
648 $pdf->AddPage(
'',
'',
true);
649 if (!empty($tplidx)) {
650 $pdf->useTemplate($tplidx);
652 $pdf->setPage($pageposbefore + 1);
653 $pdf->setPageOrientation(
'',
true, $heightforfooter);
654 $curY = $tab_top_newpage;
655 $showpricebeforepagebreak = 0;
662 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
663 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
665 $posYAfterImage = $curY + $imglinesize[
'height'];
671 $pdf->setPageOrientation(
'',
true, $heightforfooter);
675 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
680 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
685 $pdf->setPage($pageposbefore);
686 $pdf->setTopMargin($this->marge_haute);
687 $pdf->setPageOrientation(
'',
false, $heightforfooter);
690 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
691 $pdf->setPage($afterPosData[
'page']);
692 $curY = $tab_top_newpage;
695 $pdf->SetFont(
'',
'', $default_font_size - 1);
709 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
729 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
736 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
739 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
741 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
743 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
756 if (!empty(
$object->lines[$i]->array_options)) {
757 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
772 'nexY' => & $afterPosData[
'y'],
773 'outputlangs' => $outputlangs,
774 'hidedetails' => $hidedetails
776 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
781 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
783 $tvaligne =
$object->lines[$i]->total_tva;
786 $localtax1ligne =
$object->lines[$i]->total_localtax1;
787 $localtax2ligne =
$object->lines[$i]->total_localtax2;
788 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
789 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
790 $localtax1_type =
$object->lines[$i]->localtax1_type;
791 $localtax2_type =
$object->lines[$i]->localtax2_type;
793 $vatrate = (string)
$object->lines[$i]->tva_tx;
796 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
797 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
799 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
800 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
804 if ($localtax1_type && $localtax1ligne != 0) {
805 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
806 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
808 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
811 if ($localtax2_type && $localtax2ligne != 0) {
812 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
813 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
815 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
819 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
824 if (!isset($this->tva[$vatrate])) {
825 $this->tva[$vatrate] = 0;
827 $this->tva[$vatrate] += $tvaligne;
828 $vatcode =
$object->lines[$i]->vat_src_code;
829 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
830 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
832 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
835 if (!$hidenextline) {
837 $pdf->setPage($afterPosData[
'page']);
838 $nexY = $afterPosData[
'y'];
841 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
842 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
844 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
845 $pdf->SetLineStyle(array(
'dash' => 0));
848 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
857 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
859 if (!empty($tplidx)) {
860 $pdf->useTemplate($tplidx);
863 $pdf->setPage($pagenb);
867 $drawTabNumbPage = $pdf->getNumPages();
868 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
871 $pdf->setPageOrientation(
'',
false, 0);
873 $drawTabHideTop = $hidetop;
874 $drawTabTop = $tab_top_newpage;
875 $drawTabBottom = $this->page_hauteur - $heightforfooter;
878 if ($i == $pageposbeforeprintlines) {
880 $drawTabTop = $tab_top;
881 } elseif (!$drawTabHideTop) {
883 $drawTabTop -= $this->tabTitleHeight;
890 if ($i == $pdf->getNumPages()) {
892 $drawTabBottom -= $heightforfreetext + $heightforinfotot;
895 $drawTabHeight = $drawTabBottom - $drawTabTop;
896 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
898 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
904 $pdf->setPageOrientation(
'',
true, 0);
907 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
910 if (!empty($tplidx)) {
911 $pdf->useTemplate($tplidx);
916 $pdf->SetTextColor(0, 0, 0);
918 $pdf->setPage($pdf->getNumPages());
920 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
930 if (method_exists($pdf,
'AliasNbPages')) {
931 $pdf->AliasNbPages();
936 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_ORDER') && $termsofsalefilename) {
937 $termsofsale = $conf->order->dir_output.
'/'.$termsofsalefilename;
938 if (!empty($conf->order->multidir_output[$conf->entity])) {
939 $termsofsale = $conf->order->multidir_output[$conf->entity].
'/'.$termsofsalefilename;
941 if (file_exists($termsofsale) && is_readable($termsofsale)) {
942 $pagecount = $pdf->setSourceFile($termsofsale);
943 for ($i = 1; $i <= $pagecount; $i++) {
944 $tplIdx = $pdf->importPage($i);
945 if ($tplIdx !==
false) {
946 $s = $pdf->getTemplatesize($tplIdx);
947 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
948 $pdf->useTemplate($tplIdx);
950 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
958 $pdf->Output($file,
'F');
961 $hookmanager->initHooks(array(
'pdfgeneration'));
962 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
964 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
965 $this->warnings = $hookmanager->warnings;
967 $this->error = $hookmanager->error;
968 $this->errors = $hookmanager->errors;
975 $this->result = array(
'fullpath' => $file);
979 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
983 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
1016 $pdf->SetFont(
'',
'', $default_font_size - 1);
1021 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1022 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1023 $pdf->SetXY($this->marge_gauche, $posy);
1024 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1026 $posy = $pdf->GetY() + 4;
1035 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1036 $pdf->SetXY($this->marge_gauche, $posy);
1037 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1038 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1040 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1041 $pdf->SetXY($posxval, $posy);
1042 $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);
1043 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1044 if (
$object->deposit_percent > 0) {
1045 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', (
string)
$object->deposit_percent, $lib_condition_paiement);
1047 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1049 $posy = $pdf->GetY() + 3;
1080 if (!empty(
$object->delivery_date)) {
1081 $outputlangs->load(
"sendings");
1082 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1083 $pdf->SetXY($this->marge_gauche, $posy);
1084 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1085 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1086 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1087 $pdf->SetXY($posxval, $posy);
1089 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1091 $posy = $pdf->GetY() + 1;
1093 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1094 $pdf->SetXY($this->marge_gauche, $posy);
1095 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1096 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1097 $pdf->SetTextColor(0, 0, 0);
1098 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1099 $pdf->SetXY($posxval, $posy);
1100 $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 :
'');
1101 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1102 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1104 $posy = $pdf->GetY() + 1;
1108 if (
$object->mode_reglement_code
1109 &&
$object->mode_reglement_code !=
'CHQ'
1110 &&
$object->mode_reglement_code !=
'VIR') {
1111 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1112 $pdf->SetXY($this->marge_gauche, $posy);
1113 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1114 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1116 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1117 $pdf->SetXY($posxval, $posy);
1118 $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);
1119 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1121 $posy = $pdf->GetY() + 2;
1125 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1129 $account =
new Account($this->db);
1132 $pdf->SetXY($this->marge_gauche, $posy);
1133 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1134 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1135 $posy = $pdf->GetY() + 1;
1138 $pdf->SetXY($this->marge_gauche, $posy);
1139 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1140 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1141 $posy = $pdf->GetY() + 2;
1145 $pdf->SetXY($this->marge_gauche, $posy);
1146 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1147 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1148 $posy = $pdf->GetY() + 1;
1151 $pdf->SetXY($this->marge_gauche, $posy);
1152 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1153 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1154 $posy = $pdf->GetY() + 2;
1161 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1163 $bankid = (
$object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER :
$object->fk_account);
1167 $account =
new Account($this->db);
1168 $account->fetch($bankid);
1170 $curx = $this->marge_gauche;
1173 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1196 global $conf,
$mysoc, $hookmanager;
1201 $outputlangsbis =
new Translate(
'', $conf);
1203 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1204 $default_font_size--;
1209 $pdf->SetFont(
'',
'', $default_font_size - 1);
1214 if ($this->page_largeur < 210) {
1217 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1226 $total_discount_on_lines = 0;
1227 $multicurrency_total_discount_on_lines = 0;
1228 foreach (
$object->lines as $i => $line) {
1232 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1233 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1235 if ($line->total_ht < 0) {
1236 $total_discount_on_lines += -$line->total_ht;
1237 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1241 if ($total_discount_on_lines > 0) {
1243 $pdf->SetFillColor(255, 255, 255);
1244 $pdf->SetXY($col1x, $tab2_top);
1245 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1246 $pdf->SetXY($col2x, $tab2_top);
1248 $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));
1249 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1253 $pdf->SetFillColor(255, 255, 255);
1254 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1255 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1256 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1258 $total_discount_to_show = ((
isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1259 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1265 $pdf->SetFillColor(255, 255, 255);
1266 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1267 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1269 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1270 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1273 $pdf->SetFillColor(248, 248, 248);
1276 $total_ttc_origin =
$object->total_ttc;
1278 $this->atleastoneratenotnull = 0;
1280 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1281 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1285 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1286 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1289 foreach ($localtax_rate as $tvakey => $tvaval) {
1293 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1296 if (preg_match(
'/\*/', (
string) $tvakey)) {
1297 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1298 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1300 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1304 $totalvat .= $tvacompl;
1306 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1309 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1313 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1314 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1320 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1321 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1324 foreach ($localtax_rate as $tvakey => $tvaval) {
1329 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1332 if (preg_match(
'/\*/', (
string) $tvakey)) {
1333 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1334 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1336 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1340 $totalvat .= $tvacompl;
1342 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1345 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1349 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1350 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1356 foreach ($this->tva_array as $tvakey => $tvaval) {
1358 $this->atleastoneratenotnull++;
1361 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1364 if (preg_match(
'/\*/', $tvakey)) {
1365 $tvakey = str_replace(
'*',
'', $tvakey);
1366 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1368 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1371 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1373 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1375 $totalvat .= $tvacompl;
1377 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1379 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1381 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1382 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
1387 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1388 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1392 foreach ($localtax_rate as $tvakey => $tvaval) {
1397 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1400 if (preg_match(
'/\*/', (
string) $tvakey)) {
1401 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1402 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1404 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1408 $totalvat .= $tvacompl;
1410 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1413 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1417 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1418 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1424 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1425 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1429 foreach ($localtax_rate as $tvakey => $tvaval) {
1435 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1438 if (preg_match(
'/\*/', (
string) $tvakey)) {
1439 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1440 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1442 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1446 $totalvat .= $tvacompl;
1448 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1451 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1455 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1456 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1464 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1465 $pdf->SetTextColor(0, 0, 60);
1466 $pdf->SetFillColor(224, 224, 224);
1467 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1469 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1471 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1473 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1477 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1478 $pdf->SetTextColor(0, 0, 60);
1479 $pdf->SetFillColor(224, 224, 224);
1480 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1482 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1483 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1488 $pdf->SetTextColor(0, 0, 0);
1490 $creditnoteamount = 0;
1491 $depositsamount = 0;
1495 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1500 if ($deja_regle > 0) {
1504 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1505 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1506 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1507 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1510 $pdf->SetTextColor(0, 0, 60);
1511 $pdf->SetFillColor(224, 224, 224);
1512 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1513 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1515 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1516 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1518 $pdf->SetFont(
'',
'', $default_font_size - 1);
1519 $pdf->SetTextColor(0, 0, 0);
1522 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1524 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1526 $this->error = $hookmanager->error;
1527 $this->errors = $hookmanager->errors;
1531 return ($tab2_top + ($tab2_hl * $index));
1608 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1611 global $conf, $langs, $hookmanager,
$mysoc;
1613 $ltrdirection =
'L';
1614 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1615 $ltrdirection =
'R';
1619 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1625 $pdf->SetTextColor(0, 0, 60);
1626 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1630 $posy = $this->marge_haute;
1631 $posx = $this->page_largeur - $this->marge_droite - $w;
1633 $pdf->SetXY($this->marge_gauche, $posy);
1637 if ($this->emetteur->logo) {
1638 $logodir = $conf->mycompany->dir_output;
1643 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1645 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1647 if (is_readable($logo)) {
1649 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1651 $pdf->SetTextColor(200, 0, 0);
1652 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1653 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1654 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1657 $text = $this->emetteur->name;
1658 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1662 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1663 $pdf->SetXY($posx, $posy);
1664 $pdf->SetTextColor(0, 0, 60);
1665 $title = $outputlangs->transnoentities($titlekey);
1666 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1668 $title .= $outputlangsbis->transnoentities($titlekey);
1670 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1671 if (
$object->statut == $object::STATUS_DRAFT) {
1672 $pdf->SetTextColor(128, 0, 0);
1673 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1676 $pdf->MultiCell($w, 3, $title,
'',
'R');
1678 $pdf->SetFont(
'',
'B', $default_font_size);
1693 $pdf->SetFont(
'',
'', $default_font_size - 2);
1697 $pdf->SetXY($posx, $posy);
1698 $pdf->SetTextColor(0, 0, 60);
1699 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_client), 65),
'',
'R');
1704 if (!empty(
$object->project->ref)) {
1706 $pdf->SetXY($posx, $posy);
1707 $pdf->SetTextColor(0, 0, 60);
1708 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1714 if (!empty(
$object->project->ref)) {
1715 $outputlangs->load(
"projects");
1717 $pdf->SetXY($posx, $posy);
1718 $pdf->SetTextColor(0, 0, 60);
1719 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1725 $pdf->SetXY($posx, $posy);
1726 $pdf->SetTextColor(0, 0, 60);
1727 $title = $outputlangs->transnoentities(
"OrderDate");
1728 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1729 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1731 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1735 $pdf->SetXY($posx, $posy);
1736 $pdf->SetTextColor(0, 0, 60);
1737 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
1742 $pdf->SetXY($posx, $posy);
1743 $pdf->SetTextColor(0, 0, 60);
1744 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
1749 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1750 if (count($arrayidcontact) > 0) {
1751 $usertmp =
new User($this->db);
1752 $usertmp->fetch($arrayidcontact[0]);
1754 $pdf->SetXY($posx, $posy);
1755 $pdf->SetTextColor(0, 0, 60);
1756 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1765 $current_y = $pdf->getY();
1767 if ($current_y < $pdf->getY()) {
1768 $top_shift = $pdf->getY() - $current_y;
1773 $carac_emetteur =
'';
1775 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1776 if (count($arrayidcontact) > 0) {
1777 $object->fetch_user($arrayidcontact[0]);
1778 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1779 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1781 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1785 $carac_emetteur .=
"\n";
1792 $posy += $top_shift;
1793 $posx = $this->marge_gauche;
1795 $posx = $this->page_largeur - $this->marge_droite - 80;
1799 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1804 $pdf->SetTextColor(0, 0, 0);
1805 $pdf->SetFont(
'',
'', $default_font_size - 2);
1806 $pdf->SetXY($posx, $posy - 5);
1807 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1808 $pdf->SetXY($posx, $posy);
1809 $pdf->SetFillColor(230, 230, 230);
1810 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1811 $pdf->SetTextColor(0, 0, 60);
1816 $pdf->SetXY($posx + 2, $posy + 3);
1817 $pdf->SetFont(
'',
'B', $default_font_size);
1818 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1819 $posy = $pdf->getY();
1823 $pdf->SetXY($posx + 2, $posy);
1824 $pdf->SetFont(
'',
'', $default_font_size - 1);
1825 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1828 $usecontact =
false;
1829 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1830 if (count($arrayidcontact) > 0) {
1832 $result =
$object->fetch_contact($arrayidcontact[0]);
1837 $thirdparty =
$object->contact;
1839 $thirdparty =
$object->thirdparty;
1842 if (is_object($thirdparty)) {
1845 $carac_client_name =
'';
1852 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1853 if ($this->page_largeur < 210) {
1857 $posy += $top_shift;
1858 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1860 $posx = $this->marge_gauche;
1865 $pdf->SetTextColor(0, 0, 0);
1866 $pdf->SetFont(
'',
'', $default_font_size - 2);
1867 $pdf->SetXY($posx + 2, $posy - 5);
1868 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1869 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1873 $pdf->SetXY($posx + 2, $posy + 3);
1874 $pdf->SetFont(
'',
'B', $default_font_size);
1876 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1878 $posy = $pdf->getY();
1881 $pdf->SetFont(
'',
'', $default_font_size - 1);
1882 $pdf->SetXY($posx + 2, $posy);
1884 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1888 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1890 if (!empty($idaddressshipping)) {
1891 $contactshipping =
$object->fetch_contact($idaddressshipping[0]);
1892 $companystatic =
new Societe($this->db);
1893 $companystatic->fetch(
$object->contact->fk_soc);
1900 if (!empty($carac_client_shipping)) {
1901 $posy += $hautcadre;
1906 $pdf->SetXY($posx + 2, $posy - 5);
1907 $pdf->SetFont(
'',
'', $default_font_size - 2);
1908 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1909 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1912 $pdf->SetXY($posx + 2, $posy + 1);
1913 $pdf->SetFont(
'',
'B', $default_font_size);
1914 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
1916 $posy = $pdf->getY();
1919 $pdf->SetXY($posx + 2, $posy);
1920 $pdf->SetFont(
'',
'', $default_font_size - 1);
1921 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
1923 $shipp_shift += $hautcadre + 10;
1928 $pdf->SetTextColor(0, 0, 0);
1930 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);