179 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
182 global $user, $langs,
$conf,
$mysoc, $db, $hookmanager, $nblines;
184 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
186 if (!is_object($outputlangs)) {
187 $outputlangs = $langs;
191 $outputlangs->charset_output =
'ISO-8859-1';
195 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"sendginds",
"compta"));
202 global $outputlangsbis;
203 $outputlangsbis =
null;
207 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"sendginds",
"compta"));
210 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
215 $realpatharray = array();
216 $this->atleastonephoto =
false;
218 $objphoto =
new Product($this->db);
220 for ($i = 0; $i < $nblines; $i++) {
221 if (empty(
$object->lines[$i]->fk_product)) {
227 $objphoto->fetch(
$object->lines[$i]->fk_product);
230 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
231 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
233 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
234 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
239 foreach ($pdir as $midir) {
241 $entity = $objphoto->entity;
242 if ($entity !==
null &&
$conf->entity != $entity) {
243 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
245 $dir =
$conf->product->dir_output.
'/'.$midir;
248 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
250 if ($obj[
'photo_vignette']) {
251 $filename = $obj[
'photo_vignette'];
253 $filename = $obj[
'photo'];
256 $filename = $obj[
'photo'];
259 $realpath = $dir.$filename;
261 $this->atleastonephoto =
true;
266 if ($realpath && $arephoto) {
267 $realpatharray[$i] = $realpath;
282 $file = $dir.
"/SPECIMEN.pdf";
286 $file = $dir.
"/".$objectref.
".pdf";
291 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir",
"Null dir");
295 if (!file_exists($dir)) {
297 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
302 if (file_exists($dir)) {
304 if (!is_object($hookmanager)) {
305 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
308 $hookmanager->initHooks(array(
'pdfgeneration'));
309 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
311 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
314 $nblines = (is_array(
$object->lines) ? count(
$object->lines) : 0);
319 $pdf->setAutoPageBreak(
true, 0);
321 $heightforinfotot = 40;
323 $heightforfooter = $this->marge_basse + 8;
325 $heightforfooter += 6;
328 if (class_exists(
'TCPDF')) {
329 $pdf->setPrintHeader(
false);
330 $pdf->setPrintFooter(
false);
335 $logodir =
$conf->mycompany->dir_output;
336 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
339 $pagecount = $pdf->setSourceFile($logodir.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
340 $tplidx = $pdf->importPage(1);
345 $pdf->SetDrawColor(128, 128, 128);
347 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
348 $pdf->SetSubject($outputlangs->transnoentities(
"PdfOrderTitle"));
349 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
350 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
351 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfOrderTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
353 $pdf->SetCompression(
false);
357 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
360 for ($i = 0; $i < $nblines; $i++) {
361 if (
$object->lines[$i]->remise_percent) {
362 $this->atleastonediscount++;
369 if (!empty($tplidx)) {
370 $pdf->useTemplate($tplidx);
373 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis :
null));
374 $top_shift = $pagehead[
'top_shift'];
375 $shipp_shift = $pagehead[
'shipp_shift'];
376 $pdf->SetFont(
'',
'', $default_font_size - 1);
377 $pdf->MultiCell(0, 3,
'');
378 $pdf->SetTextColor(0, 0, 0);
381 $tab_top = 80 + $this->marge_haute + $top_shift + $shipp_shift;
382 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
383 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
385 $tab_top_newpage += $this->tabTitleHeight;
388 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
390 $nexY = $tab_top - 1;
393 $height_incoterms = 0;
395 $desc_incoterms =
$object->getIncotermsForPDF();
396 if ($desc_incoterms) {
399 $pdf->SetFont(
'',
'', $default_font_size - 1);
400 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
401 $nexY = max($pdf->GetY(), $nexY);
402 $height_incoterms = $nexY - $tab_top;
405 $pdf->SetDrawColor(192, 192, 192);
406 $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');
408 $tab_top = $nexY + 6;
413 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
416 if (is_object(
$object->thirdparty)) {
417 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
418 $salerepobj =
new User($this->db);
419 $salerepobj->fetch($salereparray[0][
'id']);
420 if (!empty($salerepobj->signature)) {
421 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
426 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
427 if (!empty($extranote)) {
431 $pagenb = $pdf->getPage();
435 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
436 $pageposbeforenote = $pagenb;
443 $pdf->startTransaction();
445 $pdf->SetFont(
'',
'', $default_font_size - 1);
446 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
448 $pageposafternote = $pdf->getPage();
449 $posyafter = $pdf->GetY();
451 if ($pageposafternote > $pageposbeforenote) {
452 $pdf->rollbackTransaction(
true);
455 while ($pagenb < $pageposafternote) {
458 if (!empty($tplidx)) {
459 $pdf->useTemplate($tplidx);
465 $pdf->setTopMargin($tab_top_newpage);
467 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
471 $pdf->setPage($pageposbeforenote);
472 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
473 $pdf->SetFont(
'',
'', $default_font_size - 1);
474 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
475 $pageposafternote = $pdf->getPage();
477 $posyafter = $pdf->GetY();
479 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
480 $pdf->AddPage(
'',
'',
true);
483 $pdf->setPage($pageposafternote);
484 $pdf->setTopMargin($tab_top_newpage);
486 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
492 $i = $pageposbeforenote;
493 while ($i < $pageposafternote) {
497 $pdf->SetDrawColor(128, 128, 128);
499 if ($i > $pageposbeforenote) {
500 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
501 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
503 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
504 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
508 $pdf->setPageOrientation(
'',
true, 0);
515 $pdf->setPage($pageposafternote);
516 if (!empty($tplidx)) {
517 $pdf->useTemplate($tplidx);
522 $height_note = $posyafter - $tab_top_newpage;
523 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
526 $pdf->commitTransaction();
527 $posyafter = $pdf->GetY();
528 $height_note = $posyafter - $tab_top;
529 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
532 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
534 $pdf->AddPage(
'',
'',
true);
537 $pdf->setPage($pageposafternote);
538 if (!empty($tplidx)) {
539 $pdf->useTemplate($tplidx);
545 $posyafter = $tab_top_newpage;
549 $tab_height -= $height_note;
550 $tab_top = $posyafter + 6;
560 $pdf->startTransaction();
561 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
562 $pdf->rollbackTransaction(
true);
564 $nexY = $tab_top + $this->tabTitleHeight;
567 $pageposbeforeprintlines = $pdf->getPage();
568 $pagenb = $pageposbeforeprintlines;
570 $pdf_sub_options = array();
571 $pdf_sub_options[
'titleshowuponpdf'] = 1;
572 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
573 $pdf_sub_options_before_title = array();
577 for ($i = 0; $i < $nblines; $i++) {
578 $linePosition = $i + 1;
581 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
583 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
584 $level =
$object->lines[$i]->qty;
586 if ($level > 0 && !isset($pdf_sub_options_before_title[(
int) $level])) {
587 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
591 if (isset($sub_options[
'titleshowuponpdf'])) {
592 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
593 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
594 unset($pdf_sub_options[
'titleshowuponpdf']);
596 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
597 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
598 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
599 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
602 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
603 unset($pdf_sub_options[
'titleshowuponpdf']);
605 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
606 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
610 if ($level < 0 && isset($pdf_sub_options_before_title[(
int) abs($level)])) {
611 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
612 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
613 if ($tmplevel >= abs($level)) {
614 unset($pdf_sub_options_before_title[$tmplevel]);
620 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
622 $pdf_sub_options = array();
623 $pdf_sub_options[
'titleshowuponpdf'] = 1;
624 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
631 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
632 $object->lines[$i]->pagebreak =
true;
636 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
639 if (!empty($tplidx)) {
640 $pdf->useTemplate($tplidx);
643 $pdf->setPage($pdf->getNumPages());
644 $nexY = $curY = $tab_top_newpage;
650 $pdf->SetFont(
'',
'', $default_font_size - 1);
651 $pdf->SetTextColor(0, 0, 0);
654 $imglinesize = array();
655 if (!empty($realpatharray[$i])) {
659 $pdf->setTopMargin($tab_top_newpage);
660 $pdf->setPageOrientation(
'',
true, $heightforfooter);
661 $pageposbefore = $pdf->getPage();
665 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
671 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
672 $pdf->AddPage(
'',
'',
true);
673 if (!empty($tplidx)) {
674 $pdf->useTemplate($tplidx);
676 $pdf->setPage($pageposbefore + 1);
677 $pdf->setPageOrientation(
'',
true, $heightforfooter);
678 $curY = $tab_top_newpage;
679 $showpricebeforepagebreak = 0;
686 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
687 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
689 $posYAfterImage = $curY + $imglinesize[
'height'];
695 $pdf->setPageOrientation(
'',
true, $heightforfooter);
699 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
704 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
709 $pdf->setPage($pageposbefore);
710 $pdf->setTopMargin($this->marge_haute);
711 $pdf->setPageOrientation(
'',
false, $heightforfooter);
714 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
715 $pdf->setPage($afterPosData[
'page']);
716 $curY = $tab_top_newpage;
719 $pdf->SetFont(
'',
'', $default_font_size - 1);
733 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
753 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
760 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
763 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
765 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
767 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
774 if ($this->
getColumnStatus(
'totalincltax') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
780 if (!empty(
$object->lines[$i]->array_options)) {
781 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
796 'nexY' => & $afterPosData[
'y'],
797 'outputlangs' => $outputlangs,
798 'hidedetails' => $hidedetails
800 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
805 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
807 $tvaligne =
$object->lines[$i]->total_tva;
810 $localtax1ligne =
$object->lines[$i]->total_localtax1;
811 $localtax2ligne =
$object->lines[$i]->total_localtax2;
812 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
813 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
814 $localtax1_type =
$object->lines[$i]->localtax1_type;
815 $localtax2_type =
$object->lines[$i]->localtax2_type;
817 $vatrate = (string)
$object->lines[$i]->tva_tx;
820 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
821 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
823 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
824 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
828 if ($localtax1_type && $localtax1ligne != 0) {
829 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
830 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
832 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
835 if ($localtax2_type && $localtax2ligne != 0) {
836 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
837 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
839 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
843 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
848 if (!isset($this->tva[$vatrate])) {
849 $this->tva[$vatrate] = 0;
851 $this->tva[$vatrate] += $tvaligne;
852 $vatcode =
$object->lines[$i]->vat_src_code;
853 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
854 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
856 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
859 if (!$hidenextline) {
861 $pdf->setPage($afterPosData[
'page']);
862 $nexY = $afterPosData[
'y'];
865 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
866 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
868 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
869 $pdf->SetLineStyle(array(
'dash' => 0));
872 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
881 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
883 if (!empty($tplidx)) {
884 $pdf->useTemplate($tplidx);
887 $pdf->setPage($pagenb);
891 $drawTabNumbPage = $pdf->getNumPages();
892 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
895 $pdf->setPageOrientation(
'',
false, 0);
897 $drawTabHideTop = $hidetop;
898 $drawTabTop = $tab_top_newpage;
899 $drawTabBottom = $this->page_hauteur - $heightforfooter;
902 if ($i == $pageposbeforeprintlines) {
904 $drawTabTop = $tab_top;
905 } elseif (!$drawTabHideTop) {
907 $drawTabTop -= $this->tabTitleHeight;
914 if ($i == $pdf->getNumPages()) {
916 $drawTabBottom -= $heightforfreetext + $heightforinfotot;
919 $drawTabHeight = $drawTabBottom - $drawTabTop;
920 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
922 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
928 $pdf->setPageOrientation(
'',
true, 0);
931 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
934 if (!empty($tplidx)) {
935 $pdf->useTemplate($tplidx);
940 $pdf->SetTextColor(0, 0, 0);
942 $pdf->setPage($pdf->getNumPages());
944 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
954 if (method_exists($pdf,
'AliasNbPages')) {
955 $pdf->AliasNbPages();
961 $termsofsale =
$conf->order->dir_output.
'/'.$termsofsalefilename;
962 if (!empty(
$conf->order->multidir_output[
$conf->entity])) {
963 $termsofsale =
$conf->order->multidir_output[
$conf->entity].
'/'.$termsofsalefilename;
965 if (file_exists($termsofsale) && is_readable($termsofsale)) {
966 $pagecount = $pdf->setSourceFile($termsofsale);
967 for ($i = 1; $i <= $pagecount; $i++) {
968 $tplIdx = $pdf->importPage($i);
969 if ($tplIdx !==
false) {
970 $s = $pdf->getTemplatesize($tplIdx);
971 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
972 $pdf->useTemplate($tplIdx);
974 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
982 $pdf->Output($file,
'F');
985 $hookmanager->initHooks(array(
'pdfgeneration'));
986 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
988 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
989 $this->warnings = $hookmanager->warnings;
991 $this->error = $hookmanager->error;
992 $this->errors = $hookmanager->errors;
999 $this->result = array(
'fullpath' => $file);
1003 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1007 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
1040 $pdf->SetFont(
'',
'', $default_font_size - 1);
1045 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1046 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1047 $pdf->SetXY($this->marge_gauche, $posy);
1048 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1050 $posy = $pdf->GetY() + 4;
1059 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1060 $pdf->SetXY($this->marge_gauche, $posy);
1061 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1062 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1064 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1065 $pdf->SetXY($posxval, $posy);
1066 $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);
1067 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1068 if (
$object->deposit_percent > 0) {
1069 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', (
string)
$object->deposit_percent, $lib_condition_paiement);
1071 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1073 $posy = $pdf->GetY() + 3;
1104 if (!empty(
$object->delivery_date)) {
1105 $outputlangs->load(
"sendings");
1106 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1107 $pdf->SetXY($this->marge_gauche, $posy);
1108 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1109 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1110 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1111 $pdf->SetXY($posxval, $posy);
1113 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1115 $posy = $pdf->GetY() + 1;
1117 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1118 $pdf->SetXY($this->marge_gauche, $posy);
1119 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1120 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1121 $pdf->SetTextColor(0, 0, 0);
1122 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1123 $pdf->SetXY($posxval, $posy);
1124 $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 :
'');
1125 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1126 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1128 $posy = $pdf->GetY() + 1;
1132 if (
$object->mode_reglement_code
1133 &&
$object->mode_reglement_code !=
'CHQ'
1134 &&
$object->mode_reglement_code !=
'VIR') {
1135 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1136 $pdf->SetXY($this->marge_gauche, $posy);
1137 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1138 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1140 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1141 $pdf->SetXY($posxval, $posy);
1142 $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);
1143 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1145 $posy = $pdf->GetY() + 2;
1149 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1153 $account =
new Account($this->db);
1156 $pdf->SetXY($this->marge_gauche, $posy);
1157 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1158 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1159 $posy = $pdf->GetY() + 1;
1162 $pdf->SetXY($this->marge_gauche, $posy);
1163 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1164 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1165 $posy = $pdf->GetY() + 2;
1169 $pdf->SetXY($this->marge_gauche, $posy);
1170 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1171 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1172 $posy = $pdf->GetY() + 1;
1175 $pdf->SetXY($this->marge_gauche, $posy);
1176 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1177 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1178 $posy = $pdf->GetY() + 2;
1185 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1187 $bankid = (
$object->fk_account <= 0 ?
$conf->global->FACTURE_RIB_NUMBER :
$object->fk_account);
1191 $account =
new Account($this->db);
1192 $account->fetch($bankid);
1194 $curx = $this->marge_gauche;
1197 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1227 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1228 $default_font_size--;
1233 $pdf->SetFont(
'',
'', $default_font_size - 1);
1238 if ($this->page_largeur < 210) {
1241 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1250 $total_discount_on_lines = 0;
1251 $multicurrency_total_discount_on_lines = 0;
1252 foreach (
$object->lines as $i => $line) {
1256 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1257 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1259 if ($line->total_ht < 0) {
1260 $total_discount_on_lines += -$line->total_ht;
1261 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1265 if ($total_discount_on_lines > 0) {
1266 if ($this->showAmountBeforeDiscount) {
1268 $pdf->SetFillColor(255, 255, 255);
1269 $pdf->SetXY($col1x, $tab2_top);
1270 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1271 $pdf->SetXY($col2x, $tab2_top);
1273 $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));
1274 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1279 if ($this->showDiscountAmount) {
1280 $pdf->SetFillColor(255, 255, 255);
1281 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1282 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1283 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1285 $total_discount_to_show = ((
isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1286 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1293 $pdf->SetFillColor(255, 255, 255);
1294 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1295 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1297 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1298 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1301 $pdf->SetFillColor(248, 248, 248);
1304 $total_ttc_origin =
$object->total_ttc;
1306 $this->atleastoneratenotnull = 0;
1308 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1309 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1313 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1314 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1317 foreach ($localtax_rate as $tvakey => $tvaval) {
1321 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1324 if (preg_match(
'/\*/', (
string) $tvakey)) {
1325 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1326 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1328 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1332 $totalvat .= $tvacompl;
1334 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1337 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1341 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1342 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1348 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1349 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1352 foreach ($localtax_rate as $tvakey => $tvaval) {
1357 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1360 if (preg_match(
'/\*/', (
string) $tvakey)) {
1361 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1362 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1364 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1368 $totalvat .= $tvacompl;
1370 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1373 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1377 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1378 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1384 foreach ($this->tva_array as $tvakey => $tvaval) {
1386 $this->atleastoneratenotnull++;
1389 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1392 if (preg_match(
'/\*/', $tvakey)) {
1393 $tvakey = str_replace(
'*',
'', $tvakey);
1394 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1396 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1399 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1401 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1403 $totalvat .= $tvacompl;
1405 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1407 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1409 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1410 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
1415 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1416 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1420 foreach ($localtax_rate as $tvakey => $tvaval) {
1425 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1428 if (preg_match(
'/\*/', (
string) $tvakey)) {
1429 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1430 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1432 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1436 $totalvat .= $tvacompl;
1438 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1441 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1445 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1446 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1452 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1453 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1457 foreach ($localtax_rate as $tvakey => $tvaval) {
1463 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1466 if (preg_match(
'/\*/', (
string) $tvakey)) {
1467 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1468 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1470 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1474 $totalvat .= $tvacompl;
1476 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1479 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1483 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1484 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1492 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1493 $pdf->SetTextColor(0, 0, 60);
1494 $pdf->SetFillColor(224, 224, 224);
1495 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1497 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1499 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1501 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1505 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1506 $pdf->SetTextColor(0, 0, 60);
1507 $pdf->SetFillColor(224, 224, 224);
1508 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1510 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1511 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1516 $pdf->SetTextColor(0, 0, 0);
1518 $creditnoteamount = 0;
1519 $depositsamount = 0;
1523 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1528 if ($deja_regle > 0) {
1532 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1533 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1534 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1535 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1538 $pdf->SetTextColor(0, 0, 60);
1539 $pdf->SetFillColor(224, 224, 224);
1540 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1541 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1543 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1544 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1546 $pdf->SetFont(
'',
'', $default_font_size - 1);
1547 $pdf->SetTextColor(0, 0, 0);
1550 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1552 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1554 $this->error = $hookmanager->error;
1555 $this->errors = $hookmanager->errors;
1559 return ($tab2_top + ($tab2_hl * $index));
1636 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1641 $ltrdirection =
'L';
1642 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1643 $ltrdirection =
'R';
1647 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1653 $pdf->SetTextColor(0, 0, 60);
1654 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1658 $posy = $this->marge_haute;
1659 $posx = $this->page_largeur - $this->marge_droite - $w;
1661 $pdf->SetXY($this->marge_gauche, $posy);
1664 $logodir =
$conf->mycompany->dir_output;
1666 if (!empty($multidiroutput)) {
1667 $logodir = $multidiroutput;
1669 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size,
'L');
1671 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1672 $pdf->SetXY($posx, $posy);
1673 $pdf->SetTextColor(0, 0, 60);
1674 $title = $outputlangs->transnoentities($titlekey);
1675 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1677 $title .= $outputlangsbis->transnoentities($titlekey);
1679 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1680 if (
$object->status == $object::STATUS_DRAFT) {
1681 $pdf->SetTextColor(128, 0, 0);
1682 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1685 $pdf->MultiCell($w, 3, $title,
'',
'R');
1687 $pdf->SetFont(
'',
'B', $default_font_size);
1702 $pdf->SetFont(
'',
'', $default_font_size - 2);
1706 $pdf->SetXY($posx, $posy);
1707 $pdf->SetTextColor(0, 0, 60);
1708 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
pdf_truncate_text($pdf, $outputlangs->convToOutputCharset((
string)
$object->ref_client), 65),
'',
'R');
1713 if (!empty(
$object->project->ref)) {
1715 $pdf->SetXY($posx, $posy);
1716 $pdf->SetTextColor(0, 0, 60);
1717 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
pdf_truncate_text($pdf,
$object->project->title, 50)),
'',
'R');
1723 if (!empty(
$object->project->ref)) {
1724 $outputlangs->load(
"projects");
1726 $pdf->SetXY($posx, $posy);
1727 $pdf->SetTextColor(0, 0, 60);
1728 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1734 $pdf->SetXY($posx, $posy);
1735 $pdf->SetTextColor(0, 0, 60);
1736 $title = $outputlangs->transnoentities(
"OrderDate");
1737 if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1738 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1740 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1744 $pdf->SetXY($posx, $posy);
1745 $pdf->SetTextColor(0, 0, 60);
1746 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
1751 $pdf->SetXY($posx, $posy);
1752 $pdf->SetTextColor(0, 0, 60);
1753 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
1758 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1759 if (count($arrayidcontact) > 0) {
1760 $usertmp =
new User($this->db);
1761 $usertmp->fetch($arrayidcontact[0]);
1763 $pdf->SetXY($posx, $posy);
1764 $pdf->SetTextColor(0, 0, 60);
1765 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1774 $current_y = $pdf->getY();
1776 if ($current_y < $pdf->getY()) {
1777 $top_shift = $pdf->getY() - $current_y;
1782 $carac_emetteur =
'';
1784 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1785 if (count($arrayidcontact) > 0) {
1786 $object->fetch_user($arrayidcontact[0]);
1787 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1788 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1790 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1794 $carac_emetteur .=
"\n";
1800 $posy =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
1801 $posy += $top_shift;
1802 $posx = $this->marge_gauche;
1804 $posx = $this->page_largeur - $this->marge_droite - 80;
1808 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1813 $pdf->SetTextColor(0, 0, 0);
1814 $pdf->SetFont(
'',
'', $default_font_size - 2);
1815 $pdf->SetXY($posx, $posy - 5);
1816 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1817 $pdf->SetXY($posx, $posy);
1818 $pdf->SetFillColor(230, 230, 230);
1819 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1820 $pdf->SetTextColor(0, 0, 60);
1825 $pdf->SetXY($posx + 2, $posy + 3);
1826 $pdf->SetFont(
'',
'B', $default_font_size);
1827 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1828 $posy = $pdf->getY();
1832 $pdf->SetXY($posx + 2, $posy);
1833 $pdf->SetFont(
'',
'', $default_font_size - 1);
1834 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1837 $usecontact =
false;
1838 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1839 if (count($arrayidcontact) > 0) {
1841 $result =
$object->fetch_contact($arrayidcontact[0]);
1846 $thirdparty =
$object->contact;
1848 $thirdparty =
$object->thirdparty;
1851 if (is_object($thirdparty)) {
1854 $carac_client_name =
'';
1861 $widthrecbox =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1862 if ($this->page_largeur < 210) {
1865 $posy =
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : 32 + $this->marge_haute;
1866 $posy += $top_shift;
1867 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1869 $posx = $this->marge_gauche;
1874 $pdf->SetTextColor(0, 0, 0);
1875 $pdf->SetFont(
'',
'', $default_font_size - 2);
1876 $pdf->SetXY($posx + 2, $posy - 5);
1877 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1878 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1882 $pdf->SetXY($posx + 2, $posy + 3);
1883 $pdf->SetFont(
'',
'B', $default_font_size);
1885 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1887 $posy = $pdf->getY();
1890 $pdf->SetFont(
'',
'', $default_font_size - 1);
1891 $pdf->SetXY($posx + 2, $posy);
1893 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1897 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1899 if (!empty($idaddressshipping)) {
1900 $contactshipping =
$object->fetch_contact($idaddressshipping[0]);
1901 $companystatic =
new Societe($this->db);
1902 $companystatic->fetch(
$object->contact->fk_soc);
1909 if (!empty($carac_client_shipping)) {
1910 $posy += $hautcadre;
1915 $pdf->SetXY($posx + 2, $posy - 5);
1916 $pdf->SetFont(
'',
'', $default_font_size - 2);
1917 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1918 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1921 $pdf->SetXY($posx + 2, $posy + 1);
1922 $pdf->SetFont(
'',
'B', $default_font_size);
1923 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
1925 $posy = $pdf->getY();
1928 $pdf->SetXY($posx + 2, $posy);
1929 $pdf->SetFont(
'',
'', $default_font_size - 1);
1930 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
1932 $shipp_shift += $hautcadre + 10;
1937 $pdf->SetTextColor(0, 0, 0);
1939 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);