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;
808 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
809 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
811 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
812 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
816 if ($localtax1_type && $localtax1ligne != 0) {
817 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
818 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
820 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
823 if ($localtax2_type && $localtax2ligne != 0) {
824 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
825 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
827 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
831 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
836 if (!isset($this->tva[$vatrate])) {
837 $this->tva[$vatrate] = 0;
839 $this->tva[$vatrate] += $tvaligne;
840 $vatcode =
$object->lines[$i]->vat_src_code;
841 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
842 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
844 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
847 if (!$hidenextline) {
849 $pdf->setPage($afterPosData[
'page']);
850 $nexY = $afterPosData[
'y'];
853 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
854 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
856 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
857 $pdf->SetLineStyle(array(
'dash' => 0));
861 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
871 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
873 if (!empty($tplidx)) {
874 $pdf->useTemplate($tplidx);
877 $pdf->setPage($pagenb);
881 $drawTabNumbPage = $pdf->getNumPages();
882 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
885 $pdf->setPageOrientation(
'',
false, 0);
887 $drawTabHideTop = $hidetop;
888 $drawTabTop = $tab_top_newpage;
889 $drawTabBottom = $this->page_hauteur - $heightforfooter;
892 if ($i == $pageposbeforeprintlines) {
894 $drawTabTop = $tab_top;
895 } elseif (!$drawTabHideTop) {
897 $drawTabTop -= $this->tabTitleHeight;
904 if ($i == $pdf->getNumPages()) {
906 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
909 $drawTabHeight = $drawTabBottom - $drawTabTop;
910 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
912 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
918 $pdf->setPageOrientation(
'',
true, 0);
921 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
924 if (!empty($tplidx)) {
925 $pdf->useTemplate($tplidx);
930 $pdf->SetTextColor(0, 0, 0);
932 $pdf->setPage($pdf->getNumPages());
934 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
947 $keywords = $outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name);
948 $pdf->SetKeyWords($keywords.
" PAGESIGN=".$pdf->getPage());
952 if (method_exists($pdf,
'AliasNbPages')) {
953 $pdf->AliasNbPages();
958 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_PROPAL') && $termsofsalefilename) {
959 $termsofsale =
$conf->propal->dir_output.
'/'.$termsofsalefilename;
961 $termsofsale =
$conf->propal->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
963 if (file_exists($termsofsale) && is_readable($termsofsale)) {
964 $pagecount = $pdf->setSourceFile($termsofsale);
965 for ($i = 1; $i <= $pagecount; $i++) {
966 $tplIdx = $pdf->importPage($i);
967 if ($tplIdx !==
false) {
968 $s = $pdf->getTemplatesize($tplIdx);
969 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
970 $pdf->useTemplate($tplIdx);
972 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
980 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
982 $already_merged = array();
983 foreach (
$object->lines as $line) {
984 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
989 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
991 $filetomerge->fetch_by_product($line->fk_product);
994 $already_merged[] = $line->fk_product;
996 $product =
new Product($this->db);
997 $product->fetch($line->fk_product);
999 if ($product->entity !=
$conf->entity) {
1000 $entity_product_file = $product->entity;
1002 $entity_product_file =
$conf->entity;
1006 if (count($filetomerge->lines) > 0) {
1007 foreach ($filetomerge->lines as $linefile) {
1008 if (!empty($linefile->id) && !empty($linefile->file_name)) {
1009 $filetomerge_dir =
null;
1012 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1014 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1018 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1020 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1024 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, $filetomerge_dir ===
null ? LOG_ERR : LOG_DEBUG);
1025 if ($filetomerge_dir ===
null) {
1030 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
1031 if (file_exists($infile) && is_readable($infile)) {
1032 $pagecount = $pdf->setSourceFile($infile);
1033 for ($i = 1; $i <= $pagecount; $i++) {
1034 $tplIdx = $pdf->importPage($i);
1035 if ($tplIdx !==
false) {
1036 $s = $pdf->getTemplatesize($tplIdx);
1037 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1038 $pdf->useTemplate($tplIdx);
1040 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
1053 $pdf->Output($file,
'F');
1056 $hookmanager->initHooks(array(
'pdfgeneration'));
1057 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1059 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1060 $this->warnings = $hookmanager->warnings;
1062 $this->error = $hookmanager->error;
1063 $this->errors = $hookmanager->errors;
1070 $this->result = array(
'fullpath' => $file);
1074 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1078 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1098 $pdf->SetFont(
'',
'', $default_font_size - 1);
1103 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1104 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1105 $pdf->SetXY($this->marge_gauche, $posy);
1106 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1108 $posy = $pdf->GetY() + 4;
1113 $displaydate =
"daytext";
1115 $displaydate =
"day";
1119 if (!empty(
$object->delivery_date)) {
1120 $outputlangs->load(
"sendings");
1121 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1122 $pdf->SetXY($this->marge_gauche, $posy);
1123 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1124 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1125 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1126 $pdf->SetXY($posxval, $posy);
1128 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1130 $posy = $pdf->GetY() + 1;
1132 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1133 $pdf->SetXY($this->marge_gauche, $posy);
1134 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1135 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1136 $pdf->SetTextColor(0, 0, 0);
1137 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1138 $pdf->SetXY($posxval, $posy);
1139 $lib_availability = ($outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(
$object->availability);
1140 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1141 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1143 $posy = $pdf->GetY() + 1;
1148 $outputlangs->load(
"sendings");
1150 $shipping_method_id =
$object->shipping_method_id;
1151 if (
getDolGlobalString(
'SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1152 $shipping_method_id = $this->emetteur->shipping_method_id;
1154 $shipping_method_code =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1155 $shipping_method_label =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1157 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1158 $pdf->SetXY($this->marge_gauche, $posy);
1159 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
1160 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1162 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1163 $pdf->SetXY($posxval, $posy);
1164 $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;
1165 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1166 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1168 $posy = $pdf->GetY() + 1;
1173 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1174 $pdf->SetXY($this->marge_gauche, $posy);
1175 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1176 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1178 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1179 $pdf->SetXY($posxval, $posy);
1180 $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);
1181 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1182 if (
$object->deposit_percent > 0) {
1183 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__',
$object->deposit_percent, $lib_condition_paiement);
1185 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1187 $posy = $pdf->GetY() + 3;
1192 if (
$object->mode_reglement_code
1193 &&
$object->mode_reglement_code !=
'CHQ'
1194 &&
$object->mode_reglement_code !=
'VIR') {
1195 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1196 $pdf->SetXY($this->marge_gauche, $posy);
1197 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1198 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1199 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1200 $pdf->SetXY($posxval, $posy);
1201 $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);
1202 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1204 $posy = $pdf->GetY() + 2;
1208 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1212 $account =
new Account($this->db);
1215 $pdf->SetXY($this->marge_gauche, $posy);
1216 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1217 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1218 $posy = $pdf->GetY() + 1;
1221 $pdf->SetXY($this->marge_gauche, $posy);
1222 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1223 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1224 $posy = $pdf->GetY() + 2;
1228 $pdf->SetXY($this->marge_gauche, $posy);
1229 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1230 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1231 $posy = $pdf->GetY() + 1;
1234 $pdf->SetXY($this->marge_gauche, $posy);
1235 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1236 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1237 $posy = $pdf->GetY() + 2;
1244 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1250 $account =
new Account($this->db);
1251 $account->fetch((
int) $bankid);
1253 $curx = $this->marge_gauche;
1256 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1287 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1288 $default_font_size--;
1293 $pdf->SetFont(
'',
'', $default_font_size - 1);
1298 if ($this->page_largeur < 210) {
1301 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1310 $total_discount_on_lines = 0;
1311 $multicurrency_total_discount_on_lines = 0;
1312 foreach (
$object->lines as $i => $line) {
1316 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1317 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1319 if ($line->total_ht < 0) {
1320 $total_discount_on_lines += -$line->total_ht;
1321 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1325 if ($total_discount_on_lines > 0) {
1326 if ($this->showAmountBeforeDiscount) {
1328 $pdf->SetFillColor(255, 255, 255);
1329 $pdf->SetXY($col1x, $tab2_top);
1330 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1331 $pdf->SetXY($col2x, $tab2_top);
1333 $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));
1334 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1339 if ($this->showDiscountAmount) {
1340 $pdf->SetFillColor(255, 255, 255);
1341 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1342 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1343 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1345 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1346 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1353 $pdf->SetFillColor(255, 255, 255);
1354 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1355 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1358 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1359 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1362 $pdf->SetFillColor(248, 248, 248);
1365 $total_ttc_origin =
$object->total_ttc;
1367 $this->atleastoneratenotnull = 0;
1369 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1370 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1376 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1377 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1381 foreach ($localtax_rate as $tvakey => $tvaval) {
1386 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1389 if (preg_match(
'/\*/', $tvakey)) {
1390 $tvakey = str_replace(
'*',
'', $tvakey);
1391 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1393 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1395 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1396 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1400 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1401 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1409 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1410 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1414 foreach ($localtax_rate as $tvakey => $tvaval) {
1419 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1422 if (preg_match(
'/\*/', $tvakey)) {
1423 $tvakey = str_replace(
'*',
'', $tvakey);
1424 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1426 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1428 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1429 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1433 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1434 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1441 foreach ($this->tva as $tvakey => $tvaval) {
1443 $this->atleastoneratenotnull++;
1446 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1449 if (preg_match(
'/\*/', $tvakey)) {
1450 $tvakey = str_replace(
'*',
'', $tvakey);
1451 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1453 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1455 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
1456 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1458 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1459 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
1466 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1467 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1471 foreach ($localtax_rate as $tvakey => $tvaval) {
1476 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1479 if (preg_match(
'/\*/', $tvakey)) {
1480 $tvakey = str_replace(
'*',
'', $tvakey);
1481 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1483 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1486 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1487 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1491 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1492 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1500 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1501 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1505 foreach ($localtax_rate as $tvakey => $tvaval) {
1511 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1514 if (preg_match(
'/\*/', $tvakey)) {
1515 $tvakey = str_replace(
'*',
'', $tvakey);
1516 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1518 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1522 $totalvat .= $tvacompl;
1524 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1527 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1531 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1532 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1540 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1541 $pdf->SetTextColor(0, 0, 60);
1542 $pdf->SetFillColor(224, 224, 224);
1543 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1545 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1547 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1549 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1553 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1554 $pdf->SetTextColor(0, 0, 60);
1555 $pdf->SetFillColor(224, 224, 224);
1556 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1558 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1559 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1564 $pdf->SetTextColor(0, 0, 0);
1572 if ($deja_regle > 0) {
1576 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1577 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1579 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1580 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1598 $pdf->SetTextColor(0, 0, 60);
1599 $pdf->SetFillColor(224, 224, 224);
1600 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1601 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1603 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1604 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1606 $pdf->SetFont(
'',
'', $default_font_size - 1);
1607 $pdf->SetTextColor(0, 0, 0);
1610 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1612 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1614 $this->error = $hookmanager->error;
1615 $this->errors = $hookmanager->errors;
1619 return ($tab2_top + ($tab2_hl * $index));
1702 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1704 global
$conf, $langs;
1706 $ltrdirection =
'L';
1707 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1708 $ltrdirection =
'R';
1712 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1718 $pdf->SetTextColor(0, 0, 60);
1719 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1723 $posy = $this->marge_haute;
1724 $posx = $this->page_largeur - $this->marge_droite - $w;
1726 $pdf->SetXY($this->marge_gauche, $posy);
1729 $logodir =
$conf->mycompany->dir_output;
1730 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
1733 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size, $ltrdirection);
1735 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1736 $pdf->SetXY($posx, $posy);
1737 $pdf->SetTextColor(0, 0, 60);
1738 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1739 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1740 if (
$object->status == $object::STATUS_DRAFT) {
1741 $pdf->SetTextColor(128, 0, 0);
1742 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1745 $pdf->MultiCell($w, 4, $title,
'',
'R');
1747 $pdf->SetFont(
'',
'B', $default_font_size);
1762 $pdf->SetFont(
'',
'', $default_font_size - 2);
1765 if ($ref_customer) {
1767 $pdf->SetXY($posx, $posy);
1768 $pdf->SetTextColor(0, 0, 60);
1769 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($ref_customer), 65),
'',
'R');
1774 if (!empty(
$object->project->title)) {
1776 $pdf->SetXY($posx, $posy);
1777 $pdf->SetTextColor(0, 0, 60);
1778 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
$object->project->title,
'',
'R');
1784 if (!empty(
$object->project->ref)) {
1785 $outputlangs->load(
"projects");
1787 $pdf->SetXY($posx, $posy);
1788 $pdf->SetTextColor(0, 0, 60);
1789 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
1794 $displaydate =
"daytext";
1796 $displaydate =
"day";
1800 $posy = $pdf->getY();
1801 $pdf->SetXY($posx, $posy);
1802 $pdf->SetTextColor(0, 0, 60);
1803 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1806 $pdf->SetXY($posx, $posy);
1807 $pdf->SetTextColor(0, 0, 60);
1809 $title = $outputlangs->transnoentities(
"DateEndPropal");
1810 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1811 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1813 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1817 $pdf->SetXY($posx, $posy);
1818 $pdf->SetTextColor(0, 0, 60);
1819 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
1824 $pdf->SetXY($posx, $posy);
1825 $pdf->SetTextColor(0, 0, 60);
1826 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
1831 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1832 if (count($arrayidcontact) > 0) {
1833 $usertmp =
new User($this->db);
1834 $usertmp->fetch($arrayidcontact[0]);
1836 $pdf->SetXY($posx, $posy);
1837 $pdf->SetTextColor(0, 0, 60);
1838 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1846 $current_y = $pdf->getY();
1848 if ($current_y < $pdf->getY()) {
1849 $top_shift = $pdf->getY() - $current_y;
1854 $carac_emetteur =
'';
1856 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1857 if (count($arrayidcontact) > 0) {
1858 $object->fetch_user($arrayidcontact[0]);
1859 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1860 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1862 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1866 $carac_emetteur .=
"\n";
1873 $posy += $top_shift + $this->marge_haute;
1874 $posx = $this->marge_gauche;
1876 $posx = $this->page_largeur - $this->marge_droite - 80;
1885 $pdf->SetTextColor(0, 0, 0);
1886 $pdf->SetFont(
'',
'', $default_font_size - 2);
1887 $pdf->SetXY($posx, $posy - 5);
1888 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1889 $pdf->SetXY($posx, $posy);
1890 $pdf->SetFillColor(230, 230, 230);
1891 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1892 $pdf->SetTextColor(0, 0, 60);
1897 $pdf->SetXY($posx + 2, $posy + 3);
1898 $pdf->SetFont(
'',
'B', $default_font_size);
1899 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1900 $posy = $pdf->getY();
1904 $pdf->SetXY($posx + 2, $posy);
1905 $pdf->SetFont(
'',
'', $default_font_size - 1);
1906 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1910 $usecontact =
false;
1911 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1912 if (count($arrayidcontact) > 0) {
1914 $result =
$object->fetch_contact($arrayidcontact[0]);
1918 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1919 $thirdparty =
$object->contact;
1921 $thirdparty =
$object->thirdparty;
1931 if ($this->page_largeur < 210) {
1934 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? 30 + $this->marge_haute : 32 + $this->marge_haute;
1935 $posy += $top_shift;
1936 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1938 $posx = $this->marge_gauche;
1943 $pdf->SetTextColor(0, 0, 0);
1944 $pdf->SetFont(
'',
'', $default_font_size - 2);
1945 $pdf->SetXY($posx + 2, $posy - 5);
1946 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1947 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1951 $pdf->SetXY($posx + 2, $posy + 3);
1952 $pdf->SetFont(
'',
'B', $default_font_size);
1954 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1956 $posy = $pdf->getY();
1959 $pdf->SetFont(
'',
'', $default_font_size - 1);
1960 $pdf->SetXY($posx + 2, $posy);
1962 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1965 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1967 if (!empty($idaddressshipping)) {
1968 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
1969 $companystatic =
new Societe($this->db);
1970 $companystatic->fetch(
$object->contact->fk_soc);
1977 if (!empty($carac_client_shipping)) {
1978 $posy += $hautcadre;
1983 $pdf->SetXY($posx + 2, $posy - 5);
1984 $pdf->SetFont(
'',
'', $default_font_size - 2);
1985 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
1986 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1989 $pdf->SetXY($posx + 2, $posy + 3);
1990 $pdf->SetFont(
'',
'B', $default_font_size);
1991 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
1993 $posy = $pdf->getY();
1996 $pdf->SetXY($posx + 2, $posy);
1997 $pdf->SetFont(
'',
'', $default_font_size - 1);
1998 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2000 $shipp_shift += $hautcadre + 10;
2004 $pdf->SetTextColor(0, 0, 0);
2005 return $shipp_shift;