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;
570 for ($i = 0; $i < $nblines; $i++) {
571 $linePosition = $i + 1;
574 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
576 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
577 $level =
$object->lines[$i]->qty;
580 if (isset($sub_options[
'titleshowuponpdf'])) {
581 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
582 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
583 unset($pdf_sub_options[
'titleshowuponpdf']);
585 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
586 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
587 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
588 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
591 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
592 unset($pdf_sub_options[
'titleshowuponpdf']);
594 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
595 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
600 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
602 $pdf_sub_options = array();
603 $pdf_sub_options[
'titleshowuponpdf'] = 1;
604 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
611 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
612 $object->lines[$i]->pagebreak =
true;
616 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
619 if (!empty($tplidx)) {
620 $pdf->useTemplate($tplidx);
623 $pdf->setPage($pdf->getNumPages());
624 $nexY = $curY = $tab_top_newpage;
630 $pdf->SetFont(
'',
'', $default_font_size - 1);
631 $pdf->SetTextColor(0, 0, 0);
634 $imglinesize = array();
635 if (!empty($realpatharray[$i])) {
639 $pdf->setTopMargin($tab_top_newpage);
640 $pdf->setPageOrientation(
'',
true, $heightforfooter);
641 $pageposbefore = $pdf->getPage();
645 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
651 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
652 $pdf->AddPage(
'',
'',
true);
653 if (!empty($tplidx)) {
654 $pdf->useTemplate($tplidx);
656 $pdf->setPage($pageposbefore + 1);
657 $pdf->setPageOrientation(
'',
true, $heightforfooter);
658 $curY = $tab_top_newpage;
659 $showpricebeforepagebreak = 0;
666 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
667 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
669 $posYAfterImage = $curY + $imglinesize[
'height'];
675 $pdf->setPageOrientation(
'',
true, $heightforfooter);
679 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
684 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
689 $pdf->setPage($pageposbefore);
690 $pdf->setTopMargin($this->marge_haute);
691 $pdf->setPageOrientation(
'',
false, $heightforfooter);
694 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
695 $pdf->setPage($afterPosData[
'page']);
696 $curY = $tab_top_newpage;
699 $pdf->SetFont(
'',
'', $default_font_size - 1);
713 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
733 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
740 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
743 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
745 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
747 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
760 if (!empty(
$object->lines[$i]->array_options)) {
761 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
776 'nexY' => & $afterPosData[
'y'],
777 'outputlangs' => $outputlangs,
778 'hidedetails' => $hidedetails
780 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
785 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
787 $tvaligne =
$object->lines[$i]->total_tva;
790 $localtax1ligne =
$object->lines[$i]->total_localtax1;
791 $localtax2ligne =
$object->lines[$i]->total_localtax2;
792 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
793 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
794 $localtax1_type =
$object->lines[$i]->localtax1_type;
795 $localtax2_type =
$object->lines[$i]->localtax2_type;
800 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
801 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
803 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
804 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
808 if ($localtax1_type && $localtax1ligne != 0) {
809 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
810 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
812 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
815 if ($localtax2_type && $localtax2ligne != 0) {
816 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
817 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
819 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
823 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
828 if (!isset($this->tva[$vatrate])) {
829 $this->tva[$vatrate] = 0;
831 $this->tva[$vatrate] += $tvaligne;
832 $vatcode =
$object->lines[$i]->vat_src_code;
833 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
834 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
836 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
839 if (!$hidenextline) {
841 $pdf->setPage($afterPosData[
'page']);
842 $nexY = $afterPosData[
'y'];
845 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
846 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
848 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
849 $pdf->SetLineStyle(array(
'dash' => 0));
852 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
861 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
863 if (!empty($tplidx)) {
864 $pdf->useTemplate($tplidx);
867 $pdf->setPage($pagenb);
871 $drawTabNumbPage = $pdf->getNumPages();
872 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
875 $pdf->setPageOrientation(
'',
false, 0);
877 $drawTabHideTop = $hidetop;
878 $drawTabTop = $tab_top_newpage;
879 $drawTabBottom = $this->page_hauteur - $heightforfooter;
882 if ($i == $pageposbeforeprintlines) {
884 $drawTabTop = $tab_top;
885 } elseif (!$drawTabHideTop) {
887 $drawTabTop -= $this->tabTitleHeight;
894 if ($i == $pdf->getNumPages()) {
896 $drawTabBottom -= $heightforfreetext + $heightforinfotot;
899 $drawTabHeight = $drawTabBottom - $drawTabTop;
900 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
902 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
908 $pdf->setPageOrientation(
'',
true, 0);
911 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
914 if (!empty($tplidx)) {
915 $pdf->useTemplate($tplidx);
920 $pdf->SetTextColor(0, 0, 0);
922 $pdf->setPage($pdf->getNumPages());
924 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
934 if (method_exists($pdf,
'AliasNbPages')) {
935 $pdf->AliasNbPages();
940 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_ORDER') && $termsofsalefilename) {
941 $termsofsale =
$conf->order->dir_output.
'/'.$termsofsalefilename;
942 if (!empty(
$conf->order->multidir_output[
$conf->entity])) {
943 $termsofsale =
$conf->order->multidir_output[
$conf->entity].
'/'.$termsofsalefilename;
945 if (file_exists($termsofsale) && is_readable($termsofsale)) {
946 $pagecount = $pdf->setSourceFile($termsofsale);
947 for ($i = 1; $i <= $pagecount; $i++) {
948 $tplIdx = $pdf->importPage($i);
949 if ($tplIdx !==
false) {
950 $s = $pdf->getTemplatesize($tplIdx);
951 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
952 $pdf->useTemplate($tplIdx);
954 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
962 $pdf->Output($file,
'F');
965 $hookmanager->initHooks(array(
'pdfgeneration'));
966 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
968 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
969 $this->warnings = $hookmanager->warnings;
971 $this->error = $hookmanager->error;
972 $this->errors = $hookmanager->errors;
979 $this->result = array(
'fullpath' => $file);
983 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
987 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
1020 $pdf->SetFont(
'',
'', $default_font_size - 1);
1025 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1026 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1027 $pdf->SetXY($this->marge_gauche, $posy);
1028 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1030 $posy = $pdf->GetY() + 4;
1039 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1040 $pdf->SetXY($this->marge_gauche, $posy);
1041 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1042 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1044 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1045 $pdf->SetXY($posxval, $posy);
1046 $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);
1047 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1048 if (
$object->deposit_percent > 0) {
1049 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', (
string)
$object->deposit_percent, $lib_condition_paiement);
1051 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1053 $posy = $pdf->GetY() + 3;
1084 if (!empty(
$object->delivery_date)) {
1085 $outputlangs->load(
"sendings");
1086 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1087 $pdf->SetXY($this->marge_gauche, $posy);
1088 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1089 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1090 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1091 $pdf->SetXY($posxval, $posy);
1093 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1095 $posy = $pdf->GetY() + 1;
1097 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1098 $pdf->SetXY($this->marge_gauche, $posy);
1099 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1100 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1101 $pdf->SetTextColor(0, 0, 0);
1102 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1103 $pdf->SetXY($posxval, $posy);
1104 $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 :
'');
1105 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1106 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1108 $posy = $pdf->GetY() + 1;
1112 if (
$object->mode_reglement_code
1113 &&
$object->mode_reglement_code !=
'CHQ'
1114 &&
$object->mode_reglement_code !=
'VIR') {
1115 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1116 $pdf->SetXY($this->marge_gauche, $posy);
1117 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1118 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1120 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1121 $pdf->SetXY($posxval, $posy);
1122 $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);
1123 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1125 $posy = $pdf->GetY() + 2;
1129 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1133 $account =
new Account($this->db);
1136 $pdf->SetXY($this->marge_gauche, $posy);
1137 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1138 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1139 $posy = $pdf->GetY() + 1;
1142 $pdf->SetXY($this->marge_gauche, $posy);
1143 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1144 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1145 $posy = $pdf->GetY() + 2;
1149 $pdf->SetXY($this->marge_gauche, $posy);
1150 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1151 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1152 $posy = $pdf->GetY() + 1;
1155 $pdf->SetXY($this->marge_gauche, $posy);
1156 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1157 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1158 $posy = $pdf->GetY() + 2;
1165 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1167 $bankid = (
$object->fk_account <= 0 ?
$conf->global->FACTURE_RIB_NUMBER :
$object->fk_account);
1171 $account =
new Account($this->db);
1172 $account->fetch($bankid);
1174 $curx = $this->marge_gauche;
1177 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1207 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1208 $default_font_size--;
1213 $pdf->SetFont(
'',
'', $default_font_size - 1);
1218 if ($this->page_largeur < 210) {
1221 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1230 $total_discount_on_lines = 0;
1231 $multicurrency_total_discount_on_lines = 0;
1232 foreach (
$object->lines as $i => $line) {
1236 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1237 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1239 if ($line->total_ht < 0) {
1240 $total_discount_on_lines += -$line->total_ht;
1241 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1245 if ($total_discount_on_lines > 0) {
1246 if ($this->showAmountBeforeDiscount) {
1248 $pdf->SetFillColor(255, 255, 255);
1249 $pdf->SetXY($col1x, $tab2_top);
1250 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1251 $pdf->SetXY($col2x, $tab2_top);
1253 $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));
1254 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1259 if ($this->showDiscountAmount) {
1260 $pdf->SetFillColor(255, 255, 255);
1261 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1262 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1263 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1265 $total_discount_to_show = ((
isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1266 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1273 $pdf->SetFillColor(255, 255, 255);
1274 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1275 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1277 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1278 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1281 $pdf->SetFillColor(248, 248, 248);
1284 $total_ttc_origin =
$object->total_ttc;
1286 $this->atleastoneratenotnull = 0;
1288 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1289 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1293 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1294 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1297 foreach ($localtax_rate as $tvakey => $tvaval) {
1301 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1304 if (preg_match(
'/\*/', (
string) $tvakey)) {
1305 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1306 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1308 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1312 $totalvat .= $tvacompl;
1314 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1317 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1321 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1322 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1328 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1329 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1332 foreach ($localtax_rate as $tvakey => $tvaval) {
1337 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1340 if (preg_match(
'/\*/', (
string) $tvakey)) {
1341 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1342 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1344 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1348 $totalvat .= $tvacompl;
1350 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1353 $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($total_localtax, 0, $outputlangs), 0,
'R',
true);
1364 foreach ($this->tva_array as $tvakey => $tvaval) {
1366 $this->atleastoneratenotnull++;
1369 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1372 if (preg_match(
'/\*/', $tvakey)) {
1373 $tvakey = str_replace(
'*',
'', $tvakey);
1374 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1376 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1379 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1381 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1383 $totalvat .= $tvacompl;
1385 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1387 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1389 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1390 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
1395 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1396 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1400 foreach ($localtax_rate as $tvakey => $tvaval) {
1405 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1408 if (preg_match(
'/\*/', (
string) $tvakey)) {
1409 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1410 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1412 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1416 $totalvat .= $tvacompl;
1418 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1421 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1425 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1426 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1432 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1433 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1437 foreach ($localtax_rate as $tvakey => $tvaval) {
1443 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1446 if (preg_match(
'/\*/', (
string) $tvakey)) {
1447 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1448 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1450 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1454 $totalvat .= $tvacompl;
1456 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1459 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1463 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1464 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1472 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1473 $pdf->SetTextColor(0, 0, 60);
1474 $pdf->SetFillColor(224, 224, 224);
1475 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1477 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1479 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1481 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1485 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1486 $pdf->SetTextColor(0, 0, 60);
1487 $pdf->SetFillColor(224, 224, 224);
1488 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1490 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1491 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1496 $pdf->SetTextColor(0, 0, 0);
1498 $creditnoteamount = 0;
1499 $depositsamount = 0;
1503 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1508 if ($deja_regle > 0) {
1512 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1513 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1514 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1515 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1518 $pdf->SetTextColor(0, 0, 60);
1519 $pdf->SetFillColor(224, 224, 224);
1520 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1521 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1523 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1524 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1526 $pdf->SetFont(
'',
'', $default_font_size - 1);
1527 $pdf->SetTextColor(0, 0, 0);
1530 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1532 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1534 $this->error = $hookmanager->error;
1535 $this->errors = $hookmanager->errors;
1539 return ($tab2_top + ($tab2_hl * $index));
1616 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1621 $ltrdirection =
'L';
1622 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1623 $ltrdirection =
'R';
1627 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1633 $pdf->SetTextColor(0, 0, 60);
1634 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1638 $posy = $this->marge_haute;
1639 $posx = $this->page_largeur - $this->marge_droite - $w;
1641 $pdf->SetXY($this->marge_gauche, $posy);
1644 $logodir =
$conf->mycompany->dir_output;
1646 if (!empty($multidiroutput)) {
1647 $logodir = $multidiroutput;
1649 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size,
'L');
1651 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1652 $pdf->SetXY($posx, $posy);
1653 $pdf->SetTextColor(0, 0, 60);
1654 $title = $outputlangs->transnoentities($titlekey);
1655 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1657 $title .= $outputlangsbis->transnoentities($titlekey);
1659 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1660 if (
$object->status == $object::STATUS_DRAFT) {
1661 $pdf->SetTextColor(128, 0, 0);
1662 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1665 $pdf->MultiCell($w, 3, $title,
'',
'R');
1667 $pdf->SetFont(
'',
'B', $default_font_size);
1682 $pdf->SetFont(
'',
'', $default_font_size - 2);
1686 $pdf->SetXY($posx, $posy);
1687 $pdf->SetTextColor(0, 0, 60);
1688 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset((
string)
$object->ref_client), 65),
'',
'R');
1693 if (!empty(
$object->project->ref)) {
1695 $pdf->SetXY($posx, $posy);
1696 $pdf->SetTextColor(0, 0, 60);
1697 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1703 if (!empty(
$object->project->ref)) {
1704 $outputlangs->load(
"projects");
1706 $pdf->SetXY($posx, $posy);
1707 $pdf->SetTextColor(0, 0, 60);
1708 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1714 $pdf->SetXY($posx, $posy);
1715 $pdf->SetTextColor(0, 0, 60);
1716 $title = $outputlangs->transnoentities(
"OrderDate");
1717 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1718 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1720 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1724 $pdf->SetXY($posx, $posy);
1725 $pdf->SetTextColor(0, 0, 60);
1726 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
1731 $pdf->SetXY($posx, $posy);
1732 $pdf->SetTextColor(0, 0, 60);
1733 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
1738 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1739 if (count($arrayidcontact) > 0) {
1740 $usertmp =
new User($this->db);
1741 $usertmp->fetch($arrayidcontact[0]);
1743 $pdf->SetXY($posx, $posy);
1744 $pdf->SetTextColor(0, 0, 60);
1745 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1754 $current_y = $pdf->getY();
1756 if ($current_y < $pdf->getY()) {
1757 $top_shift = $pdf->getY() - $current_y;
1762 $carac_emetteur =
'';
1764 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1765 if (count($arrayidcontact) > 0) {
1766 $object->fetch_user($arrayidcontact[0]);
1767 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1768 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1770 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1774 $carac_emetteur .=
"\n";
1780 $posy =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute : $this->marge_haute + 32;
1781 $posy += $top_shift;
1782 $posx = $this->marge_gauche;
1784 $posx = $this->page_largeur - $this->marge_droite - 80;
1788 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1793 $pdf->SetTextColor(0, 0, 0);
1794 $pdf->SetFont(
'',
'', $default_font_size - 2);
1795 $pdf->SetXY($posx, $posy - 5);
1796 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1797 $pdf->SetXY($posx, $posy);
1798 $pdf->SetFillColor(230, 230, 230);
1799 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1800 $pdf->SetTextColor(0, 0, 60);
1805 $pdf->SetXY($posx + 2, $posy + 3);
1806 $pdf->SetFont(
'',
'B', $default_font_size);
1807 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1808 $posy = $pdf->getY();
1812 $pdf->SetXY($posx + 2, $posy);
1813 $pdf->SetFont(
'',
'', $default_font_size - 1);
1814 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1817 $usecontact =
false;
1818 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1819 if (count($arrayidcontact) > 0) {
1821 $result =
$object->fetch_contact($arrayidcontact[0]);
1826 $thirdparty =
$object->contact;
1828 $thirdparty =
$object->thirdparty;
1831 if (is_object($thirdparty)) {
1834 $carac_client_name =
'';
1841 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1842 if ($this->page_largeur < 210) {
1845 $posy =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : 32 + $this->marge_haute;
1846 $posy += $top_shift;
1847 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1849 $posx = $this->marge_gauche;
1854 $pdf->SetTextColor(0, 0, 0);
1855 $pdf->SetFont(
'',
'', $default_font_size - 2);
1856 $pdf->SetXY($posx + 2, $posy - 5);
1857 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1858 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1862 $pdf->SetXY($posx + 2, $posy + 3);
1863 $pdf->SetFont(
'',
'B', $default_font_size);
1865 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1867 $posy = $pdf->getY();
1870 $pdf->SetFont(
'',
'', $default_font_size - 1);
1871 $pdf->SetXY($posx + 2, $posy);
1873 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1877 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1879 if (!empty($idaddressshipping)) {
1880 $contactshipping =
$object->fetch_contact($idaddressshipping[0]);
1881 $companystatic =
new Societe($this->db);
1882 $companystatic->fetch(
$object->contact->fk_soc);
1889 if (!empty($carac_client_shipping)) {
1890 $posy += $hautcadre;
1895 $pdf->SetXY($posx + 2, $posy - 5);
1896 $pdf->SetFont(
'',
'', $default_font_size - 2);
1897 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1898 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1901 $pdf->SetXY($posx + 2, $posy + 1);
1902 $pdf->SetFont(
'',
'B', $default_font_size);
1903 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
1905 $posy = $pdf->getY();
1908 $pdf->SetXY($posx + 2, $posy);
1909 $pdf->SetFont(
'',
'', $default_font_size - 1);
1910 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
1912 $shipp_shift += $hautcadre + 10;
1917 $pdf->SetTextColor(0, 0, 0);
1919 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);