161 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
164 global $user, $langs, $conf,
$mysoc, $db, $hookmanager, $nblines;
166 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
168 if (!is_object($outputlangs)) {
169 $outputlangs = $langs;
173 $outputlangs->charset_output =
'ISO-8859-1';
177 $langfiles = array(
"main",
"dict",
"companies",
"bills",
"products",
"propal",
"compta");
178 $outputlangs->loadLangs($langfiles);
185 global $outputlangsbis;
186 $outputlangsbis =
null;
188 $outputlangsbis =
new Translate(
'', $conf);
190 $outputlangsbis->loadLangs($langfiles);
193 $nblines = count(
$object->lines);
198 $realpatharray = array();
199 $this->atleastonephoto =
false;
201 $objphoto =
new Product($this->db);
203 for ($i = 0; $i < $nblines; $i++) {
204 if (empty(
$object->lines[$i]->fk_product)) {
208 $objphoto->fetch(
$object->lines[$i]->fk_product);
212 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
213 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
215 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
216 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
221 foreach ($pdir as $midir) {
223 $entity = $objphoto->entity;
224 if ($entity !==
null && $conf->entity != $entity) {
225 $dir = $conf->product->multidir_output[$entity].
'/'.$midir;
227 $dir = $conf->product->dir_output.
'/'.$midir;
230 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
232 if ($obj[
'photo_vignette']) {
233 $filename = $obj[
'photo_vignette'];
235 $filename = $obj[
'photo'];
238 $filename = $obj[
'photo'];
241 $realpath = $dir.$filename;
243 $this->atleastonephoto =
true;
248 if ($realpath && $arephoto) {
249 $realpatharray[$i] = $realpath;
254 if (count($realpatharray) == 0) {
255 $this->posxpicture = $this->posxtva;
258 if ($conf->propal->multidir_output[$conf->entity]) {
265 $dir = $conf->propal->multidir_output[$conf->entity];
266 $file = $dir.
"/SPECIMEN.pdf";
269 $dir = $conf->propal->multidir_output[
$object->entity ?? $conf->entity].
"/".$objectref;
270 $file = $dir.
"/".$objectref.
".pdf";
273 if (!file_exists($dir)) {
275 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
280 if (file_exists($dir)) {
282 if (!is_object($hookmanager)) {
283 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
286 $hookmanager->initHooks(array(
'pdfgeneration'));
287 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
289 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
292 $nblines = count(
$object->lines);
298 $pdf->setAutoPageBreak(
true, 0);
300 if (class_exists(
'TCPDF')) {
301 $pdf->setPrintHeader(
false);
302 $pdf->setPrintFooter(
false);
307 $logodir = $conf->mycompany->dir_output;
308 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
309 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
311 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
312 $tplidx = $pdf->importPage(1);
317 $pdf->SetDrawColor(128, 128, 128);
319 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
320 $pdf->SetSubject($outputlangs->transnoentities(
"PdfCommercialProposalTitle"));
321 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
322 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
323 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
325 $pdf->SetCompression(
false);
329 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
332 for ($i = 0; $i < $nblines; $i++) {
333 if (
$object->lines[$i]->remise_percent) {
334 $this->atleastonediscount++;
341 if (!empty($tplidx)) {
342 $pdf->useTemplate($tplidx);
346 $heightforinfotot = 40;
349 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
352 $save_note_public =
$object->note_public;
354 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
355 $pdf->SetFont(
'',
'', $default_font_size - 1);
356 $pdf->MultiCell(0, 3,
'');
357 $pdf->SetTextColor(0, 0, 0);
360 $tab_top = 90 + $top_shift;
361 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
362 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
364 $tab_top_newpage += $this->tabTitleHeight;
370 $height_incoterms = 0;
372 $desc_incoterms =
$object->getIncotermsForPDF();
373 if ($desc_incoterms) {
376 $pdf->SetFont(
'',
'', $default_font_size - 1);
377 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
378 $nexY = max($pdf->GetY(), $nexY);
379 $height_incoterms = $nexY - $tab_top;
382 $pdf->SetDrawColor(192, 192, 192);
383 $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');
385 $tab_top = $nexY + 6;
386 $height_incoterms += 4;
391 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
394 if (is_object(
$object->thirdparty)) {
395 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
396 $salerepobj =
new User($this->db);
397 $salerepobj->fetch($salereparray[0][
'id']);
398 if (!empty($salerepobj->signature)) {
399 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
404 $object->note_public = $save_note_public;
407 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
408 if (!empty($extranote)) {
413 $tmpuser =
new User($this->db);
414 $tmpuser->fetch(
$object->user_author_id);
416 $creator_info = $langs->trans(
"CaseFollowedBy").
' '.$tmpuser->getFullName($langs);
417 if ($tmpuser->email) {
418 $creator_info .=
', '.$langs->trans(
"EMail").
': '.$tmpuser->email;
420 if ($tmpuser->office_phone) {
421 $creator_info .=
', '.$langs->trans(
"Phone").
': '.$tmpuser->office_phone;
424 $notetoshow =
dol_concatdesc((
string) $notetoshow, $creator_info);
427 $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
429 $pagenb = $pdf->getPage();
433 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
434 $pageposbeforenote = $pagenb;
441 $pdf->startTransaction();
443 $pdf->SetFont(
'',
'', $default_font_size - 1);
444 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
446 $pageposafternote = $pdf->getPage();
447 $posyafter = $pdf->GetY();
449 if ($pageposafternote > $pageposbeforenote) {
450 $pdf->rollbackTransaction(
true);
453 while ($pagenb < $pageposafternote) {
456 if (!empty($tplidx)) {
457 $pdf->useTemplate($tplidx);
463 $pdf->setTopMargin($tab_top_newpage);
465 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
469 $pdf->setPage($pageposbeforenote);
470 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
471 $pdf->SetFont(
'',
'', $default_font_size - 1);
472 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
473 $pageposafternote = $pdf->getPage();
475 $posyafter = $pdf->GetY();
477 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
478 $pdf->AddPage(
'',
'',
true);
481 $pdf->setPage($pageposafternote);
482 $pdf->setTopMargin($tab_top_newpage);
484 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
490 $i = $pageposbeforenote;
491 while ($i < $pageposafternote) {
495 $pdf->SetDrawColor(128, 128, 128);
497 if ($i > $pageposbeforenote) {
498 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
499 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
501 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
502 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
506 $pdf->setPageOrientation(
'',
true, 0);
513 $pdf->setPage($pageposafternote);
514 if (!empty($tplidx)) {
515 $pdf->useTemplate($tplidx);
520 $height_note = $posyafter - $tab_top_newpage;
521 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
524 $pdf->commitTransaction();
525 $posyafter = $pdf->GetY();
526 $height_note = $posyafter - $tab_top;
527 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
530 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
532 $pdf->AddPage(
'',
'',
true);
535 $pdf->setPage($pageposafternote);
536 if (!empty($tplidx)) {
537 $pdf->useTemplate($tplidx);
543 $posyafter = $tab_top_newpage;
546 $tab_height -= $height_note;
547 $tab_top = $posyafter + 6;
556 $pdf->startTransaction();
557 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
558 $pdf->rollbackTransaction(
true);
560 $nexY = $tab_top + $this->tabTitleHeight;
563 $pageposbeforeprintlines = $pdf->getPage();
564 $pagenb = $pageposbeforeprintlines;
566 $pdf_sub_options = array();
567 $pdf_sub_options[
'titleshowuponpdf'] = 1;
568 $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;
579 if (isset($sub_options[
'titleshowuponpdf'])) {
580 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
581 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
582 unset($pdf_sub_options[
'titleshowuponpdf']);
584 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
585 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
586 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
587 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
590 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
591 unset($pdf_sub_options[
'titleshowuponpdf']);
593 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
594 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
599 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
600 $object->lines[$i]->pagebreak =
true;
604 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
607 if (!empty($tplidx)) {
608 $pdf->useTemplate($tplidx);
611 $pdf->setPage($pdf->getNumPages());
612 $nexY = $curY = $tab_top_newpage;
617 $pdf->SetFont(
'',
'', $default_font_size - 1);
618 $pdf->SetTextColor(0, 0, 0);
621 $imglinesize = array();
622 if (!empty($realpatharray[$i])) {
626 $pdf->setTopMargin($tab_top_newpage);
627 $pdf->setPageOrientation(
'',
true, $heightforfooter);
628 $pageposbefore = $pdf->getPage();
632 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
639 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
640 $pdf->AddPage(
'',
'',
true);
641 if (!empty($tplidx)) {
642 $pdf->useTemplate($tplidx);
644 $pdf->setPage($pageposbefore + 1);
645 $pdf->setPageOrientation(
'',
true, $heightforfooter);
646 $curY = $tab_top_newpage;
647 $showpricebeforepagebreak = 0;
650 $pdf->setPageOrientation(
'',
false, $heightforfooter + $heightforfreetext);
652 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
653 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
655 $posYAfterImage = $curY + $imglinesize[
'height'];
662 $pdf->setPageOrientation(
'',
true, $heightforfooter);
665 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
670 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
675 $pdf->setPage($pageposbefore);
676 $pdf->setTopMargin($this->marge_haute);
678 $pdf->setPageOrientation(
'',
false, $heightforfooter);
682 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
683 $pdf->setPage($afterPosData[
'page']);
684 $curY = $tab_top_newpage;
687 $pdf->SetFont(
'',
'', $default_font_size - 1);
702 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
722 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE &&
$object->lines[$i]->remise_percent) {
729 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
732 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
734 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
736 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
749 if (!empty(
$object->lines[$i]->array_options)) {
750 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
766 'nexY' => & $afterPosData[
'y'],
767 'outputlangs' => $outputlangs,
768 'hidedetails' => $hidedetails
770 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
775 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
777 $tvaligne =
$object->lines[$i]->total_tva;
780 $localtax1ligne =
$object->lines[$i]->total_localtax1;
781 $localtax2ligne =
$object->lines[$i]->total_localtax2;
782 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
783 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
784 $localtax1_type =
$object->lines[$i]->localtax1_type;
785 $localtax2_type =
$object->lines[$i]->localtax2_type;
798 $vatrate = (string)
$object->lines[$i]->tva_tx;
801 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
802 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
804 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
805 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
809 if ($localtax1_type && $localtax1ligne != 0) {
810 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
811 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
813 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
816 if ($localtax2_type && $localtax2ligne != 0) {
817 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
818 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
820 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
824 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
829 if (!isset($this->tva[$vatrate])) {
830 $this->tva[$vatrate] = 0;
832 $this->tva[$vatrate] += $tvaligne;
833 $vatcode =
$object->lines[$i]->vat_src_code;
834 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
835 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
837 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
842 $pdf->setPage($afterPosData[
'page']);
843 $nexY = $afterPosData[
'y'];
846 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
847 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
849 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
850 $pdf->SetLineStyle(array(
'dash' => 0));
859 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
861 if (!empty($tplidx)) {
862 $pdf->useTemplate($tplidx);
865 $pdf->setPage($pagenb);
869 $drawTabNumbPage = $pdf->getNumPages();
870 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
873 $pdf->setPageOrientation(
'',
false, 0);
875 $drawTabHideTop = $hidetop;
876 $drawTabTop = $tab_top_newpage;
877 $drawTabBottom = $this->page_hauteur - $heightforfooter;
880 if ($i == $pageposbeforeprintlines) {
882 $drawTabTop = $tab_top;
883 } elseif (!$drawTabHideTop) {
885 $drawTabTop -= $this->tabTitleHeight;
892 if ($i == $pdf->getNumPages()) {
894 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
897 $drawTabHeight = $drawTabBottom - $drawTabTop;
898 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
900 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
906 $pdf->setPageOrientation(
'',
true, 0);
909 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
912 if (!empty($tplidx)) {
913 $pdf->useTemplate($tplidx);
918 $pdf->SetTextColor(0, 0, 0);
920 $pdf->setPage($pdf->getNumPages());
922 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
935 $keywords = $outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name);
936 $pdf->SetKeyWords($keywords.
" PAGESIGN=".$pdf->getPage());
940 if (method_exists($pdf,
'AliasNbPages')) {
941 $pdf->AliasNbPages();
946 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_PROPAL') && $termsofsalefilename) {
947 $termsofsale = $conf->propal->dir_output.
'/'.$termsofsalefilename;
948 if (!empty($conf->propal->multidir_output[
$object->entity ?? $conf->entity])) {
949 $termsofsale = $conf->propal->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
951 if (file_exists($termsofsale) && is_readable($termsofsale)) {
952 $pagecount = $pdf->setSourceFile($termsofsale);
953 for ($i = 1; $i <= $pagecount; $i++) {
954 $tplIdx = $pdf->importPage($i);
955 if ($tplIdx !==
false) {
956 $s = $pdf->getTemplatesize($tplIdx);
957 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
958 $pdf->useTemplate($tplIdx);
960 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
968 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
970 $already_merged = array();
971 foreach (
$object->lines as $line) {
972 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
977 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
979 $filetomerge->fetch_by_product($line->fk_product);
982 $already_merged[] = $line->fk_product;
984 $product =
new Product($this->db);
985 $product->fetch($line->fk_product);
987 if ($product->entity != $conf->entity) {
988 $entity_product_file = $product->entity;
990 $entity_product_file = $conf->entity;
994 if (count($filetomerge->lines) > 0) {
995 foreach ($filetomerge->lines as $linefile) {
996 if (!empty($linefile->id) && !empty($linefile->file_name)) {
997 $filetomerge_dir =
null;
1000 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1002 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1006 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1008 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1012 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, $filetomerge_dir ===
null ? LOG_ERR : LOG_DEBUG);
1013 if ($filetomerge_dir ===
null) {
1018 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
1019 if (file_exists($infile) && is_readable($infile)) {
1020 $pagecount = $pdf->setSourceFile($infile);
1021 for ($i = 1; $i <= $pagecount; $i++) {
1022 $tplIdx = $pdf->importPage($i);
1023 if ($tplIdx !==
false) {
1024 $s = $pdf->getTemplatesize($tplIdx);
1025 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1026 $pdf->useTemplate($tplIdx);
1028 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
1041 $pdf->Output($file,
'F');
1044 $hookmanager->initHooks(array(
'pdfgeneration'));
1045 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1047 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1048 $this->warnings = $hookmanager->warnings;
1050 $this->error = $hookmanager->error;
1051 $this->errors = $hookmanager->errors;
1058 $this->result = array(
'fullpath' => $file);
1062 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1066 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1086 $pdf->SetFont(
'',
'', $default_font_size - 1);
1091 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1092 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1093 $pdf->SetXY($this->marge_gauche, $posy);
1094 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1096 $posy = $pdf->GetY() + 4;
1101 $displaydate =
"daytext";
1103 $displaydate =
"day";
1107 if (!empty(
$object->delivery_date)) {
1108 $outputlangs->load(
"sendings");
1109 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1110 $pdf->SetXY($this->marge_gauche, $posy);
1111 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1112 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1113 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1114 $pdf->SetXY($posxval, $posy);
1116 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1118 $posy = $pdf->GetY() + 1;
1120 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1121 $pdf->SetXY($this->marge_gauche, $posy);
1122 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1123 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1124 $pdf->SetTextColor(0, 0, 0);
1125 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1126 $pdf->SetXY($posxval, $posy);
1127 $lib_availability = ($outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(
$object->availability);
1128 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1129 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1131 $posy = $pdf->GetY() + 1;
1136 $outputlangs->load(
"sendings");
1138 $shipping_method_id =
$object->shipping_method_id;
1139 if (
getDolGlobalString(
'SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1140 $shipping_method_id = $this->emetteur->shipping_method_id;
1142 $shipping_method_code =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1143 $shipping_method_label =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1145 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1146 $pdf->SetXY($this->marge_gauche, $posy);
1147 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
1148 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1150 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1151 $pdf->SetXY($posxval, $posy);
1152 $lib_condition_paiement = ($outputlangs->transnoentities(
"SendingMethod".strtoupper($shipping_method_code)) !=
"SendingMethod".strtoupper($shipping_method_code)) ? $outputlangs->trans(
"SendingMethod".strtoupper($shipping_method_code)) : $shipping_method_label;
1153 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1154 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1156 $posy = $pdf->GetY() + 1;
1161 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1162 $pdf->SetXY($this->marge_gauche, $posy);
1163 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1164 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1166 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1167 $pdf->SetXY($posxval, $posy);
1168 $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);
1169 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1170 if (
$object->deposit_percent > 0) {
1171 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__',
$object->deposit_percent, $lib_condition_paiement);
1173 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1175 $posy = $pdf->GetY() + 3;
1180 if (
$object->mode_reglement_code
1181 &&
$object->mode_reglement_code !=
'CHQ'
1182 &&
$object->mode_reglement_code !=
'VIR') {
1183 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1184 $pdf->SetXY($this->marge_gauche, $posy);
1185 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1186 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1187 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1188 $pdf->SetXY($posxval, $posy);
1189 $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);
1190 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1192 $posy = $pdf->GetY() + 2;
1196 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1200 $account =
new Account($this->db);
1203 $pdf->SetXY($this->marge_gauche, $posy);
1204 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1205 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1206 $posy = $pdf->GetY() + 1;
1209 $pdf->SetXY($this->marge_gauche, $posy);
1210 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1211 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1212 $posy = $pdf->GetY() + 2;
1216 $pdf->SetXY($this->marge_gauche, $posy);
1217 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1218 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1219 $posy = $pdf->GetY() + 1;
1222 $pdf->SetXY($this->marge_gauche, $posy);
1223 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1224 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1225 $posy = $pdf->GetY() + 2;
1232 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1238 $account =
new Account($this->db);
1239 $account->fetch((
int) $bankid);
1241 $curx = $this->marge_gauche;
1244 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1268 global $conf,
$mysoc, $hookmanager;
1273 $outputlangsbis =
new Translate(
'', $conf);
1275 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1276 $default_font_size--;
1281 $pdf->SetFont(
'',
'', $default_font_size - 1);
1286 if ($this->page_largeur < 210) {
1289 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1298 $total_discount_on_lines = 0;
1299 $multicurrency_total_discount_on_lines = 0;
1300 foreach (
$object->lines as $i => $line) {
1304 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1305 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1307 if ($line->total_ht < 0) {
1308 $total_discount_on_lines += -$line->total_ht;
1309 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1313 if ($total_discount_on_lines > 0) {
1315 $pdf->SetFillColor(255, 255, 255);
1316 $pdf->SetXY($col1x, $tab2_top);
1317 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1318 $pdf->SetXY($col2x, $tab2_top);
1320 $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));
1321 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1325 $pdf->SetFillColor(255, 255, 255);
1326 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1327 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1328 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1330 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1331 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1337 $pdf->SetFillColor(255, 255, 255);
1338 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1339 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1342 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1343 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1346 $pdf->SetFillColor(248, 248, 248);
1349 $total_ttc_origin =
$object->total_ttc;
1351 $this->atleastoneratenotnull = 0;
1353 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1354 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1360 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1361 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1365 foreach ($localtax_rate as $tvakey => $tvaval) {
1370 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1373 if (preg_match(
'/\*/', $tvakey)) {
1374 $tvakey = str_replace(
'*',
'', $tvakey);
1375 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1377 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1379 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1380 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1384 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1385 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1393 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1394 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1398 foreach ($localtax_rate as $tvakey => $tvaval) {
1403 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1406 if (preg_match(
'/\*/', $tvakey)) {
1407 $tvakey = str_replace(
'*',
'', $tvakey);
1408 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1410 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1412 $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);
1425 foreach ($this->tva as $tvakey => $tvaval) {
1427 $this->atleastoneratenotnull++;
1430 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1433 if (preg_match(
'/\*/', $tvakey)) {
1434 $tvakey = str_replace(
'*',
'', $tvakey);
1435 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1437 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1439 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
1440 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1442 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1443 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
1450 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1451 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1455 foreach ($localtax_rate as $tvakey => $tvaval) {
1460 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1463 if (preg_match(
'/\*/', $tvakey)) {
1464 $tvakey = str_replace(
'*',
'', $tvakey);
1465 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1467 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1470 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1471 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1475 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1476 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1484 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1485 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1489 foreach ($localtax_rate as $tvakey => $tvaval) {
1495 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1498 if (preg_match(
'/\*/', $tvakey)) {
1499 $tvakey = str_replace(
'*',
'', $tvakey);
1500 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1502 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1506 $totalvat .= $tvacompl;
1508 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1511 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1515 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1516 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1524 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1525 $pdf->SetTextColor(0, 0, 60);
1526 $pdf->SetFillColor(224, 224, 224);
1527 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1529 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1531 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1533 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1537 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1538 $pdf->SetTextColor(0, 0, 60);
1539 $pdf->SetFillColor(224, 224, 224);
1540 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1542 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1543 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1548 $pdf->SetTextColor(0, 0, 0);
1556 if ($deja_regle > 0) {
1560 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1561 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1563 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1564 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1582 $pdf->SetTextColor(0, 0, 60);
1583 $pdf->SetFillColor(224, 224, 224);
1584 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1585 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1587 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1588 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1590 $pdf->SetFont(
'',
'', $default_font_size - 1);
1591 $pdf->SetTextColor(0, 0, 0);
1594 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1596 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1598 $this->error = $hookmanager->error;
1599 $this->errors = $hookmanager->errors;
1603 return ($tab2_top + ($tab2_hl * $index));
1686 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1688 global $conf, $langs;
1690 $ltrdirection =
'L';
1691 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1692 $ltrdirection =
'R';
1696 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1702 $pdf->SetTextColor(0, 0, 60);
1703 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1707 $posy = $this->marge_haute;
1708 $posx = $this->page_largeur - $this->marge_droite - $w;
1710 $pdf->SetXY($this->marge_gauche, $posy);
1714 if ($this->emetteur->logo) {
1715 $logodir = $conf->mycompany->dir_output;
1716 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
1717 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
1720 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1722 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1724 if (is_readable($logo)) {
1726 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1728 $pdf->SetTextColor(200, 0, 0);
1729 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1730 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1731 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1734 $text = $this->emetteur->name;
1735 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1739 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1740 $pdf->SetXY($posx, $posy);
1741 $pdf->SetTextColor(0, 0, 60);
1742 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1743 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1744 if (
$object->status == $object::STATUS_DRAFT) {
1745 $pdf->SetTextColor(128, 0, 0);
1746 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1749 $pdf->MultiCell($w, 4, $title,
'',
'R');
1751 $pdf->SetFont(
'',
'B', $default_font_size);
1766 $pdf->SetFont(
'',
'', $default_font_size - 2);
1769 if ($ref_customer) {
1771 $pdf->SetXY($posx, $posy);
1772 $pdf->SetTextColor(0, 0, 60);
1773 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($ref_customer), 65),
'',
'R');
1778 if (!empty(
$object->project->ref)) {
1780 $pdf->SetXY($posx, $posy);
1781 $pdf->SetTextColor(0, 0, 60);
1782 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1788 if (!empty(
$object->project->ref)) {
1789 $outputlangs->load(
"projects");
1791 $pdf->SetXY($posx, $posy);
1792 $pdf->SetTextColor(0, 0, 60);
1793 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1798 $displaydate =
"daytext";
1800 $displaydate =
"day";
1804 $posy = $pdf->getY();
1805 $pdf->SetXY($posx, $posy);
1806 $pdf->SetTextColor(0, 0, 60);
1807 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1810 $pdf->SetXY($posx, $posy);
1811 $pdf->SetTextColor(0, 0, 60);
1813 $title = $outputlangs->transnoentities(
"DateEndPropal");
1814 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1815 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1817 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1821 $pdf->SetXY($posx, $posy);
1822 $pdf->SetTextColor(0, 0, 60);
1823 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
1828 $pdf->SetXY($posx, $posy);
1829 $pdf->SetTextColor(0, 0, 60);
1830 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
1835 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1836 if (count($arrayidcontact) > 0) {
1837 $usertmp =
new User($this->db);
1838 $usertmp->fetch($arrayidcontact[0]);
1840 $pdf->SetXY($posx, $posy);
1841 $pdf->SetTextColor(0, 0, 60);
1842 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1850 $current_y = $pdf->getY();
1852 if ($current_y < $pdf->getY()) {
1853 $top_shift = $pdf->getY() - $current_y;
1858 $carac_emetteur =
'';
1860 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1861 if (count($arrayidcontact) > 0) {
1862 $object->fetch_user($arrayidcontact[0]);
1863 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1864 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1866 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1870 $carac_emetteur .=
"\n";
1877 $posy += $top_shift;
1878 $posx = $this->marge_gauche;
1880 $posx = $this->page_largeur - $this->marge_droite - 80;
1889 $pdf->SetTextColor(0, 0, 0);
1890 $pdf->SetFont(
'',
'', $default_font_size - 2);
1891 $pdf->SetXY($posx, $posy - 5);
1892 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1893 $pdf->SetXY($posx, $posy);
1894 $pdf->SetFillColor(230, 230, 230);
1895 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1896 $pdf->SetTextColor(0, 0, 60);
1901 $pdf->SetXY($posx + 2, $posy + 3);
1902 $pdf->SetFont(
'',
'B', $default_font_size);
1903 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1904 $posy = $pdf->getY();
1908 $pdf->SetXY($posx + 2, $posy);
1909 $pdf->SetFont(
'',
'', $default_font_size - 1);
1910 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1914 $usecontact =
false;
1915 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1916 if (count($arrayidcontact) > 0) {
1918 $result =
$object->fetch_contact($arrayidcontact[0]);
1922 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1923 $thirdparty =
$object->contact;
1925 $thirdparty =
$object->thirdparty;
1935 if ($this->page_largeur < 210) {
1939 $posy += $top_shift;
1940 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1942 $posx = $this->marge_gauche;
1947 $pdf->SetTextColor(0, 0, 0);
1948 $pdf->SetFont(
'',
'', $default_font_size - 2);
1949 $pdf->SetXY($posx + 2, $posy - 5);
1950 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1951 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1955 $pdf->SetXY($posx + 2, $posy + 3);
1956 $pdf->SetFont(
'',
'B', $default_font_size);
1958 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1960 $posy = $pdf->getY();
1963 $pdf->SetFont(
'',
'', $default_font_size - 1);
1964 $pdf->SetXY($posx + 2, $posy);
1966 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1969 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1971 if (!empty($idaddressshipping)) {
1972 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
1973 $companystatic =
new Societe($this->db);
1974 $companystatic->fetch(
$object->contact->fk_soc);
1981 if (!empty($carac_client_shipping)) {
1982 $posy += $hautcadre;
1987 $pdf->SetXY($posx + 2, $posy - 5);
1988 $pdf->SetFont(
'',
'', $default_font_size - 2);
1989 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1990 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1993 $pdf->SetXY($posx + 2, $posy + 3);
1994 $pdf->SetFont(
'',
'B', $default_font_size);
1995 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
1997 $posy = $pdf->getY();
2000 $pdf->SetXY($posx + 2, $posy);
2001 $pdf->SetFont(
'',
'', $default_font_size - 1);
2002 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2004 $shipp_shift += $hautcadre + 10;
2008 $pdf->SetTextColor(0, 0, 0);
2009 return $shipp_shift;