165 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
168 global $user, $langs,
$conf,
$mysoc, $db, $hookmanager, $nblines;
170 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
172 if (!is_object($outputlangs)) {
173 $outputlangs = $langs;
177 $outputlangs->charset_output =
'ISO-8859-1';
181 $langfiles = array(
"main",
"dict",
"companies",
"bills",
"products",
"propal",
"compta");
182 $outputlangs->loadLangs($langfiles);
189 global $outputlangsbis;
190 $outputlangsbis =
null;
194 $outputlangsbis->loadLangs($langfiles);
197 $nblines = count(
$object->lines);
202 $realpatharray = array();
203 $this->atleastonephoto =
false;
205 $objphoto =
new Product($this->db);
207 for ($i = 0; $i < $nblines; $i++) {
208 if (empty(
$object->lines[$i]->fk_product)) {
212 $objphoto->fetch(
$object->lines[$i]->fk_product);
216 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
217 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
219 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
220 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
225 foreach ($pdir as $midir) {
227 $entity = $objphoto->entity;
228 if ($entity !==
null &&
$conf->entity != $entity) {
229 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
231 $dir =
$conf->product->dir_output.
'/'.$midir;
234 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
236 if ($obj[
'photo_vignette']) {
237 $filename = $obj[
'photo_vignette'];
239 $filename = $obj[
'photo'];
242 $filename = $obj[
'photo'];
245 $realpath = $dir.$filename;
247 $this->atleastonephoto =
true;
252 if ($realpath && $arephoto) {
253 $realpatharray[$i] = $realpath;
258 if (count($realpatharray) == 0) {
259 $this->posxpicture = $this->posxtva;
262 if (
$conf->propal->multidir_output[
$conf->entity]) {
269 $dir =
$conf->propal->multidir_output[
$conf->entity];
270 $file = $dir.
"/SPECIMEN.pdf";
273 $dir =
$conf->propal->multidir_output[
$object->entity ??
$conf->entity].
"/".$objectref;
274 $file = $dir.
"/".$objectref.
".pdf";
277 if (!file_exists($dir)) {
279 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
284 if (file_exists($dir)) {
286 if (!is_object($hookmanager)) {
287 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
290 $hookmanager->initHooks(array(
'pdfgeneration'));
291 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
293 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
296 $nblines = count(
$object->lines);
302 $pdf->setAutoPageBreak(
true, 0);
304 if (class_exists(
'TCPDF')) {
305 $pdf->setPrintHeader(
false);
306 $pdf->setPrintFooter(
false);
311 $logodir =
$conf->mycompany->dir_output;
312 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
315 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
316 $tplidx = $pdf->importPage(1);
321 $pdf->SetDrawColor(128, 128, 128);
323 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
324 $pdf->SetSubject($outputlangs->transnoentities(
"PdfCommercialProposalTitle"));
325 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
326 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
327 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
329 $pdf->SetCompression(
false);
333 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
336 for ($i = 0; $i < $nblines; $i++) {
337 if (
$object->lines[$i]->remise_percent) {
338 $this->atleastonediscount++;
345 if (!empty($tplidx)) {
346 $pdf->useTemplate($tplidx);
350 $heightforinfotot = 40;
353 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
356 $save_note_public =
$object->note_public;
358 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
359 $pdf->SetFont(
'',
'', $default_font_size - 1);
360 $pdf->MultiCell(0, 3,
'');
361 $pdf->SetTextColor(0, 0, 0);
364 $tab_top = 90 + $top_shift;
365 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
366 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
368 $tab_top_newpage += $this->tabTitleHeight;
374 $height_incoterms = 0;
376 $desc_incoterms =
$object->getIncotermsForPDF();
377 if ($desc_incoterms) {
380 $pdf->SetFont(
'',
'', $default_font_size - 1);
381 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
382 $nexY = max($pdf->GetY(), $nexY);
383 $height_incoterms = $nexY - $tab_top;
386 $pdf->SetDrawColor(192, 192, 192);
387 $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');
389 $tab_top = $nexY + 6;
390 $height_incoterms += 4;
395 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
398 if (is_object(
$object->thirdparty)) {
399 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
400 $salerepobj =
new User($this->db);
401 $salerepobj->fetch($salereparray[0][
'id']);
402 if (!empty($salerepobj->signature)) {
403 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
408 $object->note_public = $save_note_public;
411 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
412 if (!empty($extranote)) {
417 $tmpuser =
new User($this->db);
418 $tmpuser->fetch(
$object->user_author_id);
420 $creator_info = $langs->trans(
"CaseFollowedBy").
' '.$tmpuser->getFullName($langs);
421 if ($tmpuser->email) {
422 $creator_info .=
', '.$langs->trans(
"EMail").
': '.$tmpuser->email;
424 if ($tmpuser->office_phone) {
425 $creator_info .=
', '.$langs->trans(
"Phone").
': '.$tmpuser->office_phone;
428 $notetoshow =
dol_concatdesc((
string) $notetoshow, $creator_info);
431 $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
433 $pagenb = $pdf->getPage();
437 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
438 $pageposbeforenote = $pagenb;
445 $pdf->startTransaction();
447 $pdf->SetFont(
'',
'', $default_font_size - 1);
448 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
450 $pageposafternote = $pdf->getPage();
451 $posyafter = $pdf->GetY();
453 if ($pageposafternote > $pageposbeforenote) {
454 $pdf->rollbackTransaction(
true);
457 while ($pagenb < $pageposafternote) {
460 if (!empty($tplidx)) {
461 $pdf->useTemplate($tplidx);
467 $pdf->setTopMargin($tab_top_newpage);
469 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
473 $pdf->setPage($pageposbeforenote);
474 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
475 $pdf->SetFont(
'',
'', $default_font_size - 1);
476 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
477 $pageposafternote = $pdf->getPage();
479 $posyafter = $pdf->GetY();
481 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
482 $pdf->AddPage(
'',
'',
true);
485 $pdf->setPage($pageposafternote);
486 $pdf->setTopMargin($tab_top_newpage);
488 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
494 $i = $pageposbeforenote;
495 while ($i < $pageposafternote) {
499 $pdf->SetDrawColor(128, 128, 128);
501 if ($i > $pageposbeforenote) {
502 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
503 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
505 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
506 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
510 $pdf->setPageOrientation(
'',
true, 0);
517 $pdf->setPage($pageposafternote);
518 if (!empty($tplidx)) {
519 $pdf->useTemplate($tplidx);
524 $height_note = $posyafter - $tab_top_newpage;
525 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
528 $pdf->commitTransaction();
529 $posyafter = $pdf->GetY();
530 $height_note = $posyafter - $tab_top;
531 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
534 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
536 $pdf->AddPage(
'',
'',
true);
539 $pdf->setPage($pageposafternote);
540 if (!empty($tplidx)) {
541 $pdf->useTemplate($tplidx);
547 $posyafter = $tab_top_newpage;
550 $tab_height -= $height_note;
551 $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;
574 for ($i = 0; $i < $nblines; $i++) {
575 $linePosition = $i + 1;
578 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
580 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
581 $level =
$object->lines[$i]->qty;
583 if (isset($sub_options[
'titleshowuponpdf'])) {
584 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
585 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
586 unset($pdf_sub_options[
'titleshowuponpdf']);
588 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
589 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
590 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
591 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
594 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
595 unset($pdf_sub_options[
'titleshowuponpdf']);
597 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
598 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
603 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
604 $object->lines[$i]->pagebreak =
true;
608 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
611 if (!empty($tplidx)) {
612 $pdf->useTemplate($tplidx);
615 $pdf->setPage($pdf->getNumPages());
616 $nexY = $curY = $tab_top_newpage;
621 $pdf->SetFont(
'',
'', $default_font_size - 1);
622 $pdf->SetTextColor(0, 0, 0);
625 $imglinesize = array();
626 if (!empty($realpatharray[$i])) {
630 $pdf->setTopMargin($tab_top_newpage);
631 $pdf->setPageOrientation(
'',
true, $heightforfooter);
632 $pageposbefore = $pdf->getPage();
636 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
643 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
644 $pdf->AddPage(
'',
'',
true);
645 if (!empty($tplidx)) {
646 $pdf->useTemplate($tplidx);
648 $pdf->setPage($pageposbefore + 1);
649 $pdf->setPageOrientation(
'',
true, $heightforfooter);
650 $curY = $tab_top_newpage;
651 $showpricebeforepagebreak = 0;
654 $pdf->setPageOrientation(
'',
false, $heightforfooter + $heightforfreetext);
656 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
657 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
659 $posYAfterImage = $curY + $imglinesize[
'height'];
666 $pdf->setPageOrientation(
'',
true, $heightforfooter);
669 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
674 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
679 $pdf->setPage($pageposbefore);
680 $pdf->setTopMargin($this->marge_haute);
682 $pdf->setPageOrientation(
'',
false, $heightforfooter);
686 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
687 $pdf->setPage($afterPosData[
'page']);
688 $curY = $tab_top_newpage;
691 $pdf->SetFont(
'',
'', $default_font_size - 1);
706 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
726 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE &&
$object->lines[$i]->remise_percent) {
733 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
736 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
738 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
740 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
753 if (!empty(
$object->lines[$i]->array_options)) {
754 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
770 'nexY' => & $afterPosData[
'y'],
771 'outputlangs' => $outputlangs,
772 'hidedetails' => $hidedetails
774 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
779 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
781 $tvaligne =
$object->lines[$i]->total_tva;
784 $localtax1ligne =
$object->lines[$i]->total_localtax1;
785 $localtax2ligne =
$object->lines[$i]->total_localtax2;
786 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
787 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
788 $localtax1_type =
$object->lines[$i]->localtax1_type;
789 $localtax2_type =
$object->lines[$i]->localtax2_type;
805 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
806 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
808 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
809 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
813 if ($localtax1_type && $localtax1ligne != 0) {
814 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
815 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
817 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
820 if ($localtax2_type && $localtax2ligne != 0) {
821 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
822 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
824 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
828 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
833 if (!isset($this->tva[$vatrate])) {
834 $this->tva[$vatrate] = 0;
836 $this->tva[$vatrate] += $tvaligne;
837 $vatcode =
$object->lines[$i]->vat_src_code;
838 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
839 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
841 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
846 $pdf->setPage($afterPosData[
'page']);
847 $nexY = $afterPosData[
'y'];
850 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
851 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
853 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
854 $pdf->SetLineStyle(array(
'dash' => 0));
863 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
865 if (!empty($tplidx)) {
866 $pdf->useTemplate($tplidx);
869 $pdf->setPage($pagenb);
873 $drawTabNumbPage = $pdf->getNumPages();
874 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
877 $pdf->setPageOrientation(
'',
false, 0);
879 $drawTabHideTop = $hidetop;
880 $drawTabTop = $tab_top_newpage;
881 $drawTabBottom = $this->page_hauteur - $heightforfooter;
884 if ($i == $pageposbeforeprintlines) {
886 $drawTabTop = $tab_top;
887 } elseif (!$drawTabHideTop) {
889 $drawTabTop -= $this->tabTitleHeight;
896 if ($i == $pdf->getNumPages()) {
898 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
901 $drawTabHeight = $drawTabBottom - $drawTabTop;
902 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
904 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
910 $pdf->setPageOrientation(
'',
true, 0);
913 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
916 if (!empty($tplidx)) {
917 $pdf->useTemplate($tplidx);
922 $pdf->SetTextColor(0, 0, 0);
924 $pdf->setPage($pdf->getNumPages());
926 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
939 $keywords = $outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name);
940 $pdf->SetKeyWords($keywords.
" PAGESIGN=".$pdf->getPage());
944 if (method_exists($pdf,
'AliasNbPages')) {
945 $pdf->AliasNbPages();
950 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_PROPAL') && $termsofsalefilename) {
951 $termsofsale =
$conf->propal->dir_output.
'/'.$termsofsalefilename;
953 $termsofsale =
$conf->propal->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
955 if (file_exists($termsofsale) && is_readable($termsofsale)) {
956 $pagecount = $pdf->setSourceFile($termsofsale);
957 for ($i = 1; $i <= $pagecount; $i++) {
958 $tplIdx = $pdf->importPage($i);
959 if ($tplIdx !==
false) {
960 $s = $pdf->getTemplatesize($tplIdx);
961 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
962 $pdf->useTemplate($tplIdx);
964 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
972 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
974 $already_merged = array();
975 foreach (
$object->lines as $line) {
976 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
981 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
983 $filetomerge->fetch_by_product($line->fk_product);
986 $already_merged[] = $line->fk_product;
988 $product =
new Product($this->db);
989 $product->fetch($line->fk_product);
991 if ($product->entity !=
$conf->entity) {
992 $entity_product_file = $product->entity;
994 $entity_product_file =
$conf->entity;
998 if (count($filetomerge->lines) > 0) {
999 foreach ($filetomerge->lines as $linefile) {
1000 if (!empty($linefile->id) && !empty($linefile->file_name)) {
1001 $filetomerge_dir =
null;
1004 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1006 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1010 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1012 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1016 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, $filetomerge_dir ===
null ? LOG_ERR : LOG_DEBUG);
1017 if ($filetomerge_dir ===
null) {
1022 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
1023 if (file_exists($infile) && is_readable($infile)) {
1024 $pagecount = $pdf->setSourceFile($infile);
1025 for ($i = 1; $i <= $pagecount; $i++) {
1026 $tplIdx = $pdf->importPage($i);
1027 if ($tplIdx !==
false) {
1028 $s = $pdf->getTemplatesize($tplIdx);
1029 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1030 $pdf->useTemplate($tplIdx);
1032 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
1045 $pdf->Output($file,
'F');
1048 $hookmanager->initHooks(array(
'pdfgeneration'));
1049 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1051 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1052 $this->warnings = $hookmanager->warnings;
1054 $this->error = $hookmanager->error;
1055 $this->errors = $hookmanager->errors;
1062 $this->result = array(
'fullpath' => $file);
1066 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1070 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1090 $pdf->SetFont(
'',
'', $default_font_size - 1);
1095 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1096 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1097 $pdf->SetXY($this->marge_gauche, $posy);
1098 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1100 $posy = $pdf->GetY() + 4;
1105 $displaydate =
"daytext";
1107 $displaydate =
"day";
1111 if (!empty(
$object->delivery_date)) {
1112 $outputlangs->load(
"sendings");
1113 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1114 $pdf->SetXY($this->marge_gauche, $posy);
1115 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1116 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1117 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1118 $pdf->SetXY($posxval, $posy);
1120 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1122 $posy = $pdf->GetY() + 1;
1124 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1125 $pdf->SetXY($this->marge_gauche, $posy);
1126 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1127 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1128 $pdf->SetTextColor(0, 0, 0);
1129 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1130 $pdf->SetXY($posxval, $posy);
1131 $lib_availability = ($outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(
$object->availability);
1132 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1133 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1135 $posy = $pdf->GetY() + 1;
1140 $outputlangs->load(
"sendings");
1142 $shipping_method_id =
$object->shipping_method_id;
1143 if (
getDolGlobalString(
'SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1144 $shipping_method_id = $this->emetteur->shipping_method_id;
1146 $shipping_method_code =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1147 $shipping_method_label =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1149 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1150 $pdf->SetXY($this->marge_gauche, $posy);
1151 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
1152 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1154 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1155 $pdf->SetXY($posxval, $posy);
1156 $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;
1157 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1158 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1160 $posy = $pdf->GetY() + 1;
1165 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1166 $pdf->SetXY($this->marge_gauche, $posy);
1167 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1168 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1170 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1171 $pdf->SetXY($posxval, $posy);
1172 $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);
1173 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1174 if (
$object->deposit_percent > 0) {
1175 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__',
$object->deposit_percent, $lib_condition_paiement);
1177 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1179 $posy = $pdf->GetY() + 3;
1184 if (
$object->mode_reglement_code
1185 &&
$object->mode_reglement_code !=
'CHQ'
1186 &&
$object->mode_reglement_code !=
'VIR') {
1187 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1188 $pdf->SetXY($this->marge_gauche, $posy);
1189 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1190 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1191 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1192 $pdf->SetXY($posxval, $posy);
1193 $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);
1194 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1196 $posy = $pdf->GetY() + 2;
1200 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1204 $account =
new Account($this->db);
1207 $pdf->SetXY($this->marge_gauche, $posy);
1208 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1209 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1210 $posy = $pdf->GetY() + 1;
1213 $pdf->SetXY($this->marge_gauche, $posy);
1214 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1215 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1216 $posy = $pdf->GetY() + 2;
1220 $pdf->SetXY($this->marge_gauche, $posy);
1221 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1222 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1223 $posy = $pdf->GetY() + 1;
1226 $pdf->SetXY($this->marge_gauche, $posy);
1227 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1228 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1229 $posy = $pdf->GetY() + 2;
1236 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1242 $account =
new Account($this->db);
1243 $account->fetch((
int) $bankid);
1245 $curx = $this->marge_gauche;
1248 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1279 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1280 $default_font_size--;
1285 $pdf->SetFont(
'',
'', $default_font_size - 1);
1290 if ($this->page_largeur < 210) {
1293 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1302 $total_discount_on_lines = 0;
1303 $multicurrency_total_discount_on_lines = 0;
1304 foreach (
$object->lines as $i => $line) {
1308 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1309 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1311 if ($line->total_ht < 0) {
1312 $total_discount_on_lines += -$line->total_ht;
1313 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1317 if ($total_discount_on_lines > 0) {
1318 if ($this->showAmountBeforeDiscount) {
1320 $pdf->SetFillColor(255, 255, 255);
1321 $pdf->SetXY($col1x, $tab2_top);
1322 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1323 $pdf->SetXY($col2x, $tab2_top);
1325 $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));
1326 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1331 if ($this->showDiscountAmount) {
1332 $pdf->SetFillColor(255, 255, 255);
1333 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1334 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1335 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1337 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1338 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1345 $pdf->SetFillColor(255, 255, 255);
1346 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1347 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1350 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1351 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1354 $pdf->SetFillColor(248, 248, 248);
1357 $total_ttc_origin =
$object->total_ttc;
1359 $this->atleastoneratenotnull = 0;
1361 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1362 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1368 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1369 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1373 foreach ($localtax_rate as $tvakey => $tvaval) {
1378 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1381 if (preg_match(
'/\*/', $tvakey)) {
1382 $tvakey = str_replace(
'*',
'', $tvakey);
1383 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1385 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1387 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1388 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1392 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1393 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1401 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1402 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1406 foreach ($localtax_rate as $tvakey => $tvaval) {
1411 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1414 if (preg_match(
'/\*/', $tvakey)) {
1415 $tvakey = str_replace(
'*',
'', $tvakey);
1416 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1418 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1420 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1421 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1425 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1426 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1433 foreach ($this->tva as $tvakey => $tvaval) {
1435 $this->atleastoneratenotnull++;
1438 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1441 if (preg_match(
'/\*/', $tvakey)) {
1442 $tvakey = str_replace(
'*',
'', $tvakey);
1443 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1445 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1447 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
1448 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1450 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1451 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
1458 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1459 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1463 foreach ($localtax_rate as $tvakey => $tvaval) {
1468 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1471 if (preg_match(
'/\*/', $tvakey)) {
1472 $tvakey = str_replace(
'*',
'', $tvakey);
1473 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1475 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1478 $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 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1493 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1497 foreach ($localtax_rate as $tvakey => $tvaval) {
1503 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1506 if (preg_match(
'/\*/', $tvakey)) {
1507 $tvakey = str_replace(
'*',
'', $tvakey);
1508 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1510 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1514 $totalvat .= $tvacompl;
1516 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1519 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1523 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1524 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1532 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1533 $pdf->SetTextColor(0, 0, 60);
1534 $pdf->SetFillColor(224, 224, 224);
1535 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1537 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1539 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1541 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1545 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1546 $pdf->SetTextColor(0, 0, 60);
1547 $pdf->SetFillColor(224, 224, 224);
1548 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1550 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1551 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1556 $pdf->SetTextColor(0, 0, 0);
1564 if ($deja_regle > 0) {
1568 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1569 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1571 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1572 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1590 $pdf->SetTextColor(0, 0, 60);
1591 $pdf->SetFillColor(224, 224, 224);
1592 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1593 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1595 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1596 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1598 $pdf->SetFont(
'',
'', $default_font_size - 1);
1599 $pdf->SetTextColor(0, 0, 0);
1602 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1604 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1606 $this->error = $hookmanager->error;
1607 $this->errors = $hookmanager->errors;
1611 return ($tab2_top + ($tab2_hl * $index));
1694 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1696 global
$conf, $langs;
1698 $ltrdirection =
'L';
1699 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1700 $ltrdirection =
'R';
1704 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1710 $pdf->SetTextColor(0, 0, 60);
1711 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1715 $posy = $this->marge_haute;
1716 $posx = $this->page_largeur - $this->marge_droite - $w;
1718 $pdf->SetXY($this->marge_gauche, $posy);
1722 if ($this->emetteur->logo) {
1723 $logodir =
$conf->mycompany->dir_output;
1724 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
1728 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1730 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1732 if (is_readable($logo)) {
1734 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1736 $pdf->SetTextColor(200, 0, 0);
1737 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1738 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1739 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1742 $text = $this->emetteur->name;
1743 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1747 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1748 $pdf->SetXY($posx, $posy);
1749 $pdf->SetTextColor(0, 0, 60);
1750 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1751 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1752 if (
$object->status == $object::STATUS_DRAFT) {
1753 $pdf->SetTextColor(128, 0, 0);
1754 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1757 $pdf->MultiCell($w, 4, $title,
'',
'R');
1759 $pdf->SetFont(
'',
'B', $default_font_size);
1774 $pdf->SetFont(
'',
'', $default_font_size - 2);
1777 if ($ref_customer) {
1779 $pdf->SetXY($posx, $posy);
1780 $pdf->SetTextColor(0, 0, 60);
1781 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($ref_customer), 65),
'',
'R');
1786 if (!empty(
$object->project->title)) {
1788 $pdf->SetXY($posx, $posy);
1789 $pdf->SetTextColor(0, 0, 60);
1790 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
$object->project->title,
'',
'R');
1796 if (!empty(
$object->project->ref)) {
1797 $outputlangs->load(
"projects");
1799 $pdf->SetXY($posx, $posy);
1800 $pdf->SetTextColor(0, 0, 60);
1801 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
1806 $displaydate =
"daytext";
1808 $displaydate =
"day";
1812 $posy = $pdf->getY();
1813 $pdf->SetXY($posx, $posy);
1814 $pdf->SetTextColor(0, 0, 60);
1815 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1818 $pdf->SetXY($posx, $posy);
1819 $pdf->SetTextColor(0, 0, 60);
1821 $title = $outputlangs->transnoentities(
"DateEndPropal");
1822 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1823 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1825 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1829 $pdf->SetXY($posx, $posy);
1830 $pdf->SetTextColor(0, 0, 60);
1831 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
1836 $pdf->SetXY($posx, $posy);
1837 $pdf->SetTextColor(0, 0, 60);
1838 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
1843 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1844 if (count($arrayidcontact) > 0) {
1845 $usertmp =
new User($this->db);
1846 $usertmp->fetch($arrayidcontact[0]);
1848 $pdf->SetXY($posx, $posy);
1849 $pdf->SetTextColor(0, 0, 60);
1850 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1858 $current_y = $pdf->getY();
1860 if ($current_y < $pdf->getY()) {
1861 $top_shift = $pdf->getY() - $current_y;
1866 $carac_emetteur =
'';
1868 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1869 if (count($arrayidcontact) > 0) {
1870 $object->fetch_user($arrayidcontact[0]);
1871 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1872 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1874 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1878 $carac_emetteur .=
"\n";
1885 $posy += $top_shift;
1886 $posx = $this->marge_gauche;
1888 $posx = $this->page_largeur - $this->marge_droite - 80;
1897 $pdf->SetTextColor(0, 0, 0);
1898 $pdf->SetFont(
'',
'', $default_font_size - 2);
1899 $pdf->SetXY($posx, $posy - 5);
1900 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1901 $pdf->SetXY($posx, $posy);
1902 $pdf->SetFillColor(230, 230, 230);
1903 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1904 $pdf->SetTextColor(0, 0, 60);
1909 $pdf->SetXY($posx + 2, $posy + 3);
1910 $pdf->SetFont(
'',
'B', $default_font_size);
1911 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1912 $posy = $pdf->getY();
1916 $pdf->SetXY($posx + 2, $posy);
1917 $pdf->SetFont(
'',
'', $default_font_size - 1);
1918 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1922 $usecontact =
false;
1923 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1924 if (count($arrayidcontact) > 0) {
1926 $result =
$object->fetch_contact($arrayidcontact[0]);
1930 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1931 $thirdparty =
$object->contact;
1933 $thirdparty =
$object->thirdparty;
1943 if ($this->page_largeur < 210) {
1947 $posy += $top_shift;
1948 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1950 $posx = $this->marge_gauche;
1955 $pdf->SetTextColor(0, 0, 0);
1956 $pdf->SetFont(
'',
'', $default_font_size - 2);
1957 $pdf->SetXY($posx + 2, $posy - 5);
1958 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1959 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1963 $pdf->SetXY($posx + 2, $posy + 3);
1964 $pdf->SetFont(
'',
'B', $default_font_size);
1966 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1968 $posy = $pdf->getY();
1971 $pdf->SetFont(
'',
'', $default_font_size - 1);
1972 $pdf->SetXY($posx + 2, $posy);
1974 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1977 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1979 if (!empty($idaddressshipping)) {
1980 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
1981 $companystatic =
new Societe($this->db);
1982 $companystatic->fetch(
$object->contact->fk_soc);
1989 if (!empty($carac_client_shipping)) {
1990 $posy += $hautcadre;
1995 $pdf->SetXY($posx + 2, $posy - 5);
1996 $pdf->SetFont(
'',
'', $default_font_size - 2);
1997 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1998 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2001 $pdf->SetXY($posx + 2, $posy + 3);
2002 $pdf->SetFont(
'',
'B', $default_font_size);
2003 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2005 $posy = $pdf->getY();
2008 $pdf->SetXY($posx + 2, $posy);
2009 $pdf->SetFont(
'',
'', $default_font_size - 1);
2010 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2012 $shipp_shift += $hautcadre + 10;
2016 $pdf->SetTextColor(0, 0, 0);
2017 return $shipp_shift;