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 = 80 + $this->marge_haute + $top_shift;
365 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute + $top_shift : $this->marge_haute);
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;
576 for ($i = 0; $i < $nblines; $i++) {
577 $linePosition = $i + 1;
580 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
583 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
584 $level =
$object->lines[$i]->qty;
587 if (isset($sub_options[
'titleshowuponpdf'])) {
588 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
589 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
590 unset($pdf_sub_options[
'titleshowuponpdf']);
592 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
593 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
594 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
595 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
598 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
599 unset($pdf_sub_options[
'titleshowuponpdf']);
601 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
602 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
607 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
609 $pdf_sub_options = array();
610 $pdf_sub_options[
'titleshowuponpdf'] = 1;
611 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
617 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
618 $object->lines[$i]->pagebreak =
true;
622 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
625 if (!empty($tplidx)) {
626 $pdf->useTemplate($tplidx);
629 $pdf->setPage($pdf->getNumPages());
630 $nexY = $curY = $tab_top_newpage;
635 $pdf->SetFont(
'',
'', $default_font_size - 1);
636 $pdf->SetTextColor(0, 0, 0);
639 $imglinesize = array();
640 if (!empty($realpatharray[$i])) {
644 $pdf->setTopMargin($tab_top_newpage);
645 $pdf->setPageOrientation(
'',
true, $heightforfooter);
646 $pageposbefore = $pdf->getPage();
650 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
657 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
658 $pdf->AddPage(
'',
'',
true);
659 if (!empty($tplidx)) {
660 $pdf->useTemplate($tplidx);
662 $pdf->setPage($pageposbefore + 1);
663 $pdf->setPageOrientation(
'',
true, $heightforfooter);
664 $curY = $tab_top_newpage;
665 $showpricebeforepagebreak = 0;
668 $pdf->setPageOrientation(
'',
false, $heightforfooter + $heightforfreetext);
670 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
671 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
673 $posYAfterImage = $curY + $imglinesize[
'height'];
680 $pdf->setPageOrientation(
'',
true, $heightforfooter);
683 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
688 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
693 $pdf->setPage($pageposbefore);
694 $pdf->setTopMargin($this->marge_haute);
696 $pdf->setPageOrientation(
'',
false, $heightforfooter);
700 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
701 $pdf->setPage($afterPosData[
'page']);
702 $curY = $tab_top_newpage;
705 $pdf->SetFont(
'',
'', $default_font_size - 1);
720 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
740 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE &&
$object->lines[$i]->remise_percent) {
747 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
750 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
752 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
754 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
767 if (!empty(
$object->lines[$i]->array_options)) {
768 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
784 'nexY' => & $afterPosData[
'y'],
785 'outputlangs' => $outputlangs,
786 'hidedetails' => $hidedetails
788 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
793 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
795 $tvaligne =
$object->lines[$i]->total_tva;
798 $localtax1ligne =
$object->lines[$i]->total_localtax1;
799 $localtax2ligne =
$object->lines[$i]->total_localtax2;
800 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
801 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
802 $localtax1_type =
$object->lines[$i]->localtax1_type;
803 $localtax2_type =
$object->lines[$i]->localtax2_type;
819 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
820 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
822 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
823 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
827 if ($localtax1_type && $localtax1ligne != 0) {
828 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
829 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
831 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
834 if ($localtax2_type && $localtax2ligne != 0) {
835 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
836 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
838 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
842 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
847 if (!isset($this->tva[$vatrate])) {
848 $this->tva[$vatrate] = 0;
850 $this->tva[$vatrate] += $tvaligne;
851 $vatcode =
$object->lines[$i]->vat_src_code;
852 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
853 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
855 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
858 if (!$hidenextline) {
860 $pdf->setPage($afterPosData[
'page']);
861 $nexY = $afterPosData[
'y'];
864 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
865 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
867 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
868 $pdf->SetLineStyle(array(
'dash' => 0));
872 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
882 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
884 if (!empty($tplidx)) {
885 $pdf->useTemplate($tplidx);
888 $pdf->setPage($pagenb);
892 $drawTabNumbPage = $pdf->getNumPages();
893 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
896 $pdf->setPageOrientation(
'',
false, 0);
898 $drawTabHideTop = $hidetop;
899 $drawTabTop = $tab_top_newpage;
900 $drawTabBottom = $this->page_hauteur - $heightforfooter;
903 if ($i == $pageposbeforeprintlines) {
905 $drawTabTop = $tab_top;
906 } elseif (!$drawTabHideTop) {
908 $drawTabTop -= $this->tabTitleHeight;
915 if ($i == $pdf->getNumPages()) {
917 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
920 $drawTabHeight = $drawTabBottom - $drawTabTop;
921 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
923 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
929 $pdf->setPageOrientation(
'',
true, 0);
932 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
935 if (!empty($tplidx)) {
936 $pdf->useTemplate($tplidx);
941 $pdf->SetTextColor(0, 0, 0);
943 $pdf->setPage($pdf->getNumPages());
945 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
958 $keywords = $outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name);
959 $pdf->SetKeyWords($keywords.
" PAGESIGN=".$pdf->getPage());
963 if (method_exists($pdf,
'AliasNbPages')) {
964 $pdf->AliasNbPages();
969 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_PROPAL') && $termsofsalefilename) {
970 $termsofsale =
$conf->propal->dir_output.
'/'.$termsofsalefilename;
972 $termsofsale =
$conf->propal->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
974 if (file_exists($termsofsale) && is_readable($termsofsale)) {
975 $pagecount = $pdf->setSourceFile($termsofsale);
976 for ($i = 1; $i <= $pagecount; $i++) {
977 $tplIdx = $pdf->importPage($i);
978 if ($tplIdx !==
false) {
979 $s = $pdf->getTemplatesize($tplIdx);
980 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
981 $pdf->useTemplate($tplIdx);
983 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
991 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
993 $already_merged = array();
994 foreach (
$object->lines as $line) {
995 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
1000 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
1002 $filetomerge->fetch_by_product($line->fk_product);
1005 $already_merged[] = $line->fk_product;
1007 $product =
new Product($this->db);
1008 $product->fetch($line->fk_product);
1010 if ($product->entity !=
$conf->entity) {
1011 $entity_product_file = $product->entity;
1013 $entity_product_file =
$conf->entity;
1017 if (count($filetomerge->lines) > 0) {
1018 foreach ($filetomerge->lines as $linefile) {
1019 if (!empty($linefile->id) && !empty($linefile->file_name)) {
1020 $filetomerge_dir =
null;
1023 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1025 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1029 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1031 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1035 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, $filetomerge_dir ===
null ? LOG_ERR : LOG_DEBUG);
1036 if ($filetomerge_dir ===
null) {
1041 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
1042 if (file_exists($infile) && is_readable($infile)) {
1043 $pagecount = $pdf->setSourceFile($infile);
1044 for ($i = 1; $i <= $pagecount; $i++) {
1045 $tplIdx = $pdf->importPage($i);
1046 if ($tplIdx !==
false) {
1047 $s = $pdf->getTemplatesize($tplIdx);
1048 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1049 $pdf->useTemplate($tplIdx);
1051 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
1064 $pdf->Output($file,
'F');
1067 $hookmanager->initHooks(array(
'pdfgeneration'));
1068 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1070 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1071 $this->warnings = $hookmanager->warnings;
1073 $this->error = $hookmanager->error;
1074 $this->errors = $hookmanager->errors;
1081 $this->result = array(
'fullpath' => $file);
1085 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1089 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1109 $pdf->SetFont(
'',
'', $default_font_size - 1);
1114 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1115 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1116 $pdf->SetXY($this->marge_gauche, $posy);
1117 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1119 $posy = $pdf->GetY() + 4;
1124 $displaydate =
"daytext";
1126 $displaydate =
"day";
1130 if (!empty(
$object->delivery_date)) {
1131 $outputlangs->load(
"sendings");
1132 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1133 $pdf->SetXY($this->marge_gauche, $posy);
1134 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1135 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1136 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1137 $pdf->SetXY($posxval, $posy);
1139 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1141 $posy = $pdf->GetY() + 1;
1143 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1144 $pdf->SetXY($this->marge_gauche, $posy);
1145 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1146 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1147 $pdf->SetTextColor(0, 0, 0);
1148 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1149 $pdf->SetXY($posxval, $posy);
1150 $lib_availability = ($outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(
$object->availability);
1151 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1152 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1154 $posy = $pdf->GetY() + 1;
1159 $outputlangs->load(
"sendings");
1161 $shipping_method_id =
$object->shipping_method_id;
1162 if (
getDolGlobalString(
'SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1163 $shipping_method_id = $this->emetteur->shipping_method_id;
1165 $shipping_method_code =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1166 $shipping_method_label =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1168 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1169 $pdf->SetXY($this->marge_gauche, $posy);
1170 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
1171 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1173 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1174 $pdf->SetXY($posxval, $posy);
1175 $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;
1176 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1177 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1179 $posy = $pdf->GetY() + 1;
1184 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1185 $pdf->SetXY($this->marge_gauche, $posy);
1186 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1187 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1189 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1190 $pdf->SetXY($posxval, $posy);
1191 $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);
1192 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1193 if (
$object->deposit_percent > 0) {
1194 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__',
$object->deposit_percent, $lib_condition_paiement);
1196 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1198 $posy = $pdf->GetY() + 3;
1203 if (
$object->mode_reglement_code
1204 &&
$object->mode_reglement_code !=
'CHQ'
1205 &&
$object->mode_reglement_code !=
'VIR') {
1206 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1207 $pdf->SetXY($this->marge_gauche, $posy);
1208 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1209 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1210 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1211 $pdf->SetXY($posxval, $posy);
1212 $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);
1213 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1215 $posy = $pdf->GetY() + 2;
1219 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1223 $account =
new Account($this->db);
1226 $pdf->SetXY($this->marge_gauche, $posy);
1227 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1228 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1229 $posy = $pdf->GetY() + 1;
1232 $pdf->SetXY($this->marge_gauche, $posy);
1233 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1234 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1235 $posy = $pdf->GetY() + 2;
1239 $pdf->SetXY($this->marge_gauche, $posy);
1240 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1241 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1242 $posy = $pdf->GetY() + 1;
1245 $pdf->SetXY($this->marge_gauche, $posy);
1246 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1247 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1248 $posy = $pdf->GetY() + 2;
1255 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1261 $account =
new Account($this->db);
1262 $account->fetch((
int) $bankid);
1264 $curx = $this->marge_gauche;
1267 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1298 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1299 $default_font_size--;
1304 $pdf->SetFont(
'',
'', $default_font_size - 1);
1309 if ($this->page_largeur < 210) {
1312 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1321 $total_discount_on_lines = 0;
1322 $multicurrency_total_discount_on_lines = 0;
1323 foreach (
$object->lines as $i => $line) {
1327 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1328 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1330 if ($line->total_ht < 0) {
1331 $total_discount_on_lines += -$line->total_ht;
1332 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1336 if ($total_discount_on_lines > 0) {
1337 if ($this->showAmountBeforeDiscount) {
1339 $pdf->SetFillColor(255, 255, 255);
1340 $pdf->SetXY($col1x, $tab2_top);
1341 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1342 $pdf->SetXY($col2x, $tab2_top);
1344 $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));
1345 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1350 if ($this->showDiscountAmount) {
1351 $pdf->SetFillColor(255, 255, 255);
1352 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1353 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1354 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1356 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1357 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1364 $pdf->SetFillColor(255, 255, 255);
1365 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1366 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1369 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1370 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1373 $pdf->SetFillColor(248, 248, 248);
1376 $total_ttc_origin =
$object->total_ttc;
1378 $this->atleastoneratenotnull = 0;
1380 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1381 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1387 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1388 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1392 foreach ($localtax_rate as $tvakey => $tvaval) {
1397 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1400 if (preg_match(
'/\*/', $tvakey)) {
1401 $tvakey = str_replace(
'*',
'', $tvakey);
1402 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1404 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1406 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1407 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1411 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1412 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1420 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1421 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1425 foreach ($localtax_rate as $tvakey => $tvaval) {
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(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1439 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1440 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1444 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1445 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1452 foreach ($this->tva as $tvakey => $tvaval) {
1454 $this->atleastoneratenotnull++;
1457 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1460 if (preg_match(
'/\*/', $tvakey)) {
1461 $tvakey = str_replace(
'*',
'', $tvakey);
1462 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1464 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1466 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
1467 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1469 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1470 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
1477 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1478 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1482 foreach ($localtax_rate as $tvakey => $tvaval) {
1487 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1490 if (preg_match(
'/\*/', $tvakey)) {
1491 $tvakey = str_replace(
'*',
'', $tvakey);
1492 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1494 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1497 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1498 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1502 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1503 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1511 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1512 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1516 foreach ($localtax_rate as $tvakey => $tvaval) {
1522 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1525 if (preg_match(
'/\*/', $tvakey)) {
1526 $tvakey = str_replace(
'*',
'', $tvakey);
1527 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1529 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1533 $totalvat .= $tvacompl;
1535 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1538 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1542 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1543 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1551 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1552 $pdf->SetTextColor(0, 0, 60);
1553 $pdf->SetFillColor(224, 224, 224);
1554 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1556 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1558 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1560 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1564 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1565 $pdf->SetTextColor(0, 0, 60);
1566 $pdf->SetFillColor(224, 224, 224);
1567 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1569 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1570 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1575 $pdf->SetTextColor(0, 0, 0);
1583 if ($deja_regle > 0) {
1587 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1588 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1590 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1591 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1609 $pdf->SetTextColor(0, 0, 60);
1610 $pdf->SetFillColor(224, 224, 224);
1611 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1612 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1614 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1615 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1617 $pdf->SetFont(
'',
'', $default_font_size - 1);
1618 $pdf->SetTextColor(0, 0, 0);
1621 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1623 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1625 $this->error = $hookmanager->error;
1626 $this->errors = $hookmanager->errors;
1630 return ($tab2_top + ($tab2_hl * $index));
1713 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1715 global
$conf, $langs;
1717 $ltrdirection =
'L';
1718 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1719 $ltrdirection =
'R';
1723 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1729 $pdf->SetTextColor(0, 0, 60);
1730 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1734 $posy = $this->marge_haute;
1735 $posx = $this->page_largeur - $this->marge_droite - $w;
1737 $pdf->SetXY($this->marge_gauche, $posy);
1741 if ($this->emetteur->logo) {
1742 $logodir =
$conf->mycompany->dir_output;
1743 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
1747 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1749 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1751 if (is_readable($logo)) {
1753 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1755 $pdf->SetTextColor(200, 0, 0);
1756 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1757 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1758 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1761 $text = $this->emetteur->name;
1762 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1766 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1767 $pdf->SetXY($posx, $posy);
1768 $pdf->SetTextColor(0, 0, 60);
1769 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1770 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1771 if (
$object->status == $object::STATUS_DRAFT) {
1772 $pdf->SetTextColor(128, 0, 0);
1773 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1776 $pdf->MultiCell($w, 4, $title,
'',
'R');
1778 $pdf->SetFont(
'',
'B', $default_font_size);
1793 $pdf->SetFont(
'',
'', $default_font_size - 2);
1796 if ($ref_customer) {
1798 $pdf->SetXY($posx, $posy);
1799 $pdf->SetTextColor(0, 0, 60);
1800 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($ref_customer), 65),
'',
'R');
1805 if (!empty(
$object->project->title)) {
1807 $pdf->SetXY($posx, $posy);
1808 $pdf->SetTextColor(0, 0, 60);
1809 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
dol_trunc(
$object->project->title, 50),
'',
'R');
1815 if (!empty(
$object->project->ref)) {
1816 $outputlangs->load(
"projects");
1818 $pdf->SetXY($posx, $posy);
1819 $pdf->SetTextColor(0, 0, 60);
1820 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
1825 $displaydate =
"daytext";
1827 $displaydate =
"day";
1831 $posy = $pdf->getY();
1832 $pdf->SetXY($posx, $posy);
1833 $pdf->SetTextColor(0, 0, 60);
1834 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1837 $pdf->SetXY($posx, $posy);
1838 $pdf->SetTextColor(0, 0, 60);
1840 $title = $outputlangs->transnoentities(
"DateEndPropal");
1841 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1842 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1844 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1848 $pdf->SetXY($posx, $posy);
1849 $pdf->SetTextColor(0, 0, 60);
1850 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
1855 $pdf->SetXY($posx, $posy);
1856 $pdf->SetTextColor(0, 0, 60);
1857 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
1862 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1863 if (count($arrayidcontact) > 0) {
1864 $usertmp =
new User($this->db);
1865 $usertmp->fetch($arrayidcontact[0]);
1867 $pdf->SetXY($posx, $posy);
1868 $pdf->SetTextColor(0, 0, 60);
1869 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1877 $current_y = $pdf->getY();
1879 if ($current_y < $pdf->getY()) {
1880 $top_shift = $pdf->getY() - $current_y;
1885 $carac_emetteur =
'';
1887 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1888 if (count($arrayidcontact) > 0) {
1889 $object->fetch_user($arrayidcontact[0]);
1890 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1891 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1893 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1897 $carac_emetteur .=
"\n";
1904 $posy += $top_shift + $this->marge_haute;
1905 $posx = $this->marge_gauche;
1907 $posx = $this->page_largeur - $this->marge_droite - 80;
1916 $pdf->SetTextColor(0, 0, 0);
1917 $pdf->SetFont(
'',
'', $default_font_size - 2);
1918 $pdf->SetXY($posx, $posy - 5);
1919 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1920 $pdf->SetXY($posx, $posy);
1921 $pdf->SetFillColor(230, 230, 230);
1922 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1923 $pdf->SetTextColor(0, 0, 60);
1928 $pdf->SetXY($posx + 2, $posy + 3);
1929 $pdf->SetFont(
'',
'B', $default_font_size);
1930 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1931 $posy = $pdf->getY();
1935 $pdf->SetXY($posx + 2, $posy);
1936 $pdf->SetFont(
'',
'', $default_font_size - 1);
1937 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1941 $usecontact =
false;
1942 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1943 if (count($arrayidcontact) > 0) {
1945 $result =
$object->fetch_contact($arrayidcontact[0]);
1949 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1950 $thirdparty =
$object->contact;
1952 $thirdparty =
$object->thirdparty;
1962 if ($this->page_largeur < 210) {
1965 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? 30 + $this->marge_haute : 32 + $this->marge_haute;
1966 $posy += $top_shift;
1967 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1969 $posx = $this->marge_gauche;
1974 $pdf->SetTextColor(0, 0, 0);
1975 $pdf->SetFont(
'',
'', $default_font_size - 2);
1976 $pdf->SetXY($posx + 2, $posy - 5);
1977 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1978 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1982 $pdf->SetXY($posx + 2, $posy + 3);
1983 $pdf->SetFont(
'',
'B', $default_font_size);
1985 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1987 $posy = $pdf->getY();
1990 $pdf->SetFont(
'',
'', $default_font_size - 1);
1991 $pdf->SetXY($posx + 2, $posy);
1993 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1996 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1998 if (!empty($idaddressshipping)) {
1999 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2000 $companystatic =
new Societe($this->db);
2001 $companystatic->fetch(
$object->contact->fk_soc);
2008 if (!empty($carac_client_shipping)) {
2009 $posy += $hautcadre;
2014 $pdf->SetXY($posx + 2, $posy - 5);
2015 $pdf->SetFont(
'',
'', $default_font_size - 2);
2016 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2017 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2020 $pdf->SetXY($posx + 2, $posy + 3);
2021 $pdf->SetFont(
'',
'B', $default_font_size);
2022 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2024 $posy = $pdf->getY();
2027 $pdf->SetXY($posx + 2, $posy);
2028 $pdf->SetFont(
'',
'', $default_font_size - 1);
2029 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2031 $shipp_shift += $hautcadre + 10;
2035 $pdf->SetTextColor(0, 0, 0);
2036 return $shipp_shift;