161 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
164 global $user, $langs, $conf,
$mysoc, $db, $hookmanager, $nblines;
166 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
168 if (!is_object($outputlangs)) {
169 $outputlangs = $langs;
173 $outputlangs->charset_output =
'ISO-8859-1';
177 $langfiles = array(
"main",
"dict",
"companies",
"bills",
"products",
"propal",
"compta");
178 $outputlangs->loadLangs($langfiles);
185 global $outputlangsbis;
186 $outputlangsbis =
null;
188 $outputlangsbis =
new Translate(
'', $conf);
190 $outputlangsbis->loadLangs($langfiles);
193 $nblines = count(
$object->lines);
198 $realpatharray = array();
199 $this->atleastonephoto =
false;
201 $objphoto =
new Product($this->db);
203 for ($i = 0; $i < $nblines; $i++) {
204 if (empty(
$object->lines[$i]->fk_product)) {
208 $objphoto->fetch(
$object->lines[$i]->fk_product);
212 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
213 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
215 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
216 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
221 foreach ($pdir as $midir) {
223 $entity = $objphoto->entity;
224 if ($entity !==
null && $conf->entity != $entity) {
225 $dir = $conf->product->multidir_output[$entity].
'/'.$midir;
227 $dir = $conf->product->dir_output.
'/'.$midir;
230 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
232 if ($obj[
'photo_vignette']) {
233 $filename = $obj[
'photo_vignette'];
235 $filename = $obj[
'photo'];
238 $filename = $obj[
'photo'];
241 $realpath = $dir.$filename;
243 $this->atleastonephoto =
true;
248 if ($realpath && $arephoto) {
249 $realpatharray[$i] = $realpath;
254 if (count($realpatharray) == 0) {
255 $this->posxpicture = $this->posxtva;
258 if ($conf->propal->multidir_output[$conf->entity]) {
265 $dir = $conf->propal->multidir_output[$conf->entity];
266 $file = $dir.
"/SPECIMEN.pdf";
269 $dir = $conf->propal->multidir_output[
$object->entity ?? $conf->entity].
"/".$objectref;
270 $file = $dir.
"/".$objectref.
".pdf";
273 if (!file_exists($dir)) {
275 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
280 if (file_exists($dir)) {
282 if (!is_object($hookmanager)) {
283 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
286 $hookmanager->initHooks(array(
'pdfgeneration'));
287 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
289 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
292 $nblines = count(
$object->lines);
298 $pdf->setAutoPageBreak(
true, 0);
300 if (class_exists(
'TCPDF')) {
301 $pdf->setPrintHeader(
false);
302 $pdf->setPrintFooter(
false);
307 $logodir = $conf->mycompany->dir_output;
308 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
309 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
311 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
312 $tplidx = $pdf->importPage(1);
317 $pdf->SetDrawColor(128, 128, 128);
319 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
320 $pdf->SetSubject($outputlangs->transnoentities(
"PdfCommercialProposalTitle"));
321 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
322 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
323 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
325 $pdf->SetCompression(
false);
329 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
332 for ($i = 0; $i < $nblines; $i++) {
333 if (
$object->lines[$i]->remise_percent) {
334 $this->atleastonediscount++;
341 if (!empty($tplidx)) {
342 $pdf->useTemplate($tplidx);
346 $heightforinfotot = 40;
349 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
352 $save_note_public =
$object->note_public;
354 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
355 $top_shift = $pagehead[
'top_shift'];
356 $shipp_shift = $pagehead[
'shipp_shift'];
357 $pdf->SetFont(
'',
'', $default_font_size - 1);
358 $pdf->MultiCell(0, 3,
'');
359 $pdf->SetTextColor(0, 0, 0);
362 $tab_top = 90 + $top_shift + $shipp_shift;
363 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
364 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
366 $tab_top_newpage += $this->tabTitleHeight;
372 $height_incoterms = 0;
374 $desc_incoterms =
$object->getIncotermsForPDF();
375 if ($desc_incoterms) {
378 $pdf->SetFont(
'',
'', $default_font_size - 1);
379 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
380 $nexY = max($pdf->GetY(), $nexY);
381 $height_incoterms = $nexY - $tab_top;
384 $pdf->SetDrawColor(192, 192, 192);
385 $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');
387 $tab_top = $nexY + 6;
388 $height_incoterms += 4;
393 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
396 if (is_object(
$object->thirdparty)) {
397 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
398 $salerepobj =
new User($this->db);
399 $salerepobj->fetch($salereparray[0][
'id']);
400 if (!empty($salerepobj->signature)) {
401 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
406 $object->note_public = $save_note_public;
409 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
410 if (!empty($extranote)) {
415 $tmpuser =
new User($this->db);
416 $tmpuser->fetch(
$object->user_author_id);
418 $creator_info = $langs->trans(
"CaseFollowedBy").
' '.$tmpuser->getFullName($langs);
419 if ($tmpuser->email) {
420 $creator_info .=
', '.$langs->trans(
"EMail").
': '.$tmpuser->email;
422 if ($tmpuser->office_phone) {
423 $creator_info .=
', '.$langs->trans(
"Phone").
': '.$tmpuser->office_phone;
426 $notetoshow =
dol_concatdesc((
string) $notetoshow, $creator_info);
429 $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
431 $pagenb = $pdf->getPage();
435 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
436 $pageposbeforenote = $pagenb;
443 $pdf->startTransaction();
445 $pdf->SetFont(
'',
'', $default_font_size - 1);
446 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
448 $pageposafternote = $pdf->getPage();
449 $posyafter = $pdf->GetY();
451 if ($pageposafternote > $pageposbeforenote) {
452 $pdf->rollbackTransaction(
true);
455 while ($pagenb < $pageposafternote) {
458 if (!empty($tplidx)) {
459 $pdf->useTemplate($tplidx);
465 $pdf->setTopMargin($tab_top_newpage);
467 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
471 $pdf->setPage($pageposbeforenote);
472 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
473 $pdf->SetFont(
'',
'', $default_font_size - 1);
474 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
475 $pageposafternote = $pdf->getPage();
477 $posyafter = $pdf->GetY();
479 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
480 $pdf->AddPage(
'',
'',
true);
483 $pdf->setPage($pageposafternote);
484 $pdf->setTopMargin($tab_top_newpage);
486 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
492 $i = $pageposbeforenote;
493 while ($i < $pageposafternote) {
497 $pdf->SetDrawColor(128, 128, 128);
499 if ($i > $pageposbeforenote) {
500 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
501 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
503 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
504 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
508 $pdf->setPageOrientation(
'',
true, 0);
515 $pdf->setPage($pageposafternote);
516 if (!empty($tplidx)) {
517 $pdf->useTemplate($tplidx);
522 $height_note = $posyafter - $tab_top_newpage;
523 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
526 $pdf->commitTransaction();
527 $posyafter = $pdf->GetY();
528 $height_note = $posyafter - $tab_top;
529 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
532 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
534 $pdf->AddPage(
'',
'',
true);
537 $pdf->setPage($pageposafternote);
538 if (!empty($tplidx)) {
539 $pdf->useTemplate($tplidx);
545 $posyafter = $tab_top_newpage;
548 $tab_height -= $height_note;
549 $tab_top = $posyafter + 6;
558 $pdf->startTransaction();
559 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
560 $pdf->rollbackTransaction(
true);
562 $nexY = $tab_top + $this->tabTitleHeight;
565 $pageposbeforeprintlines = $pdf->getPage();
566 $pagenb = $pageposbeforeprintlines;
568 $pdf_sub_options = array();
569 $pdf_sub_options[
'titleshowuponpdf'] = 1;
570 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
571 $pdf_sub_options_before_title = array();
575 for ($i = 0; $i < $nblines; $i++) {
576 $linePosition = $i + 1;
579 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
581 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
582 $level =
$object->lines[$i]->qty;
584 if ($level > 0 && !isset($pdf_sub_options_before_title[(
int) $level])) {
585 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
589 if (isset($sub_options[
'titleshowuponpdf'])) {
590 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
591 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
592 unset($pdf_sub_options[
'titleshowuponpdf']);
594 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
595 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
596 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
597 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
600 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
601 unset($pdf_sub_options[
'titleshowuponpdf']);
603 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
604 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
608 if ($level < 0 && isset($pdf_sub_options_before_title[(
int) abs($level)])) {
609 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
610 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
611 if ($tmplevel >= abs($level)) {
612 unset($pdf_sub_options_before_title[$tmplevel]);
618 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
620 $pdf_sub_options = array();
621 $pdf_sub_options[
'titleshowuponpdf'] = 1;
622 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
628 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
629 $object->lines[$i]->pagebreak =
true;
633 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
636 if (!empty($tplidx)) {
637 $pdf->useTemplate($tplidx);
640 $pdf->setPage($pdf->getNumPages());
641 $nexY = $curY = $tab_top_newpage;
646 $pdf->SetFont(
'',
'', $default_font_size - 1);
647 $pdf->SetTextColor(0, 0, 0);
650 $imglinesize = array();
651 if (!empty($realpatharray[$i])) {
655 $pdf->setTopMargin($tab_top_newpage);
656 $pdf->setPageOrientation(
'',
true, $heightforfooter);
657 $pageposbefore = $pdf->getPage();
661 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
668 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
669 $pdf->AddPage(
'',
'',
true);
670 if (!empty($tplidx)) {
671 $pdf->useTemplate($tplidx);
673 $pdf->setPage($pageposbefore + 1);
674 $pdf->setPageOrientation(
'',
true, $heightforfooter);
675 $curY = $tab_top_newpage;
676 $showpricebeforepagebreak = 0;
679 $pdf->setPageOrientation(
'',
false, $heightforfooter + $heightforfreetext);
681 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
682 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
684 $posYAfterImage = $curY + $imglinesize[
'height'];
691 $pdf->setPageOrientation(
'',
true, $heightforfooter);
694 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
699 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
704 $pdf->setPage($pageposbefore);
705 $pdf->setTopMargin($this->marge_haute);
707 $pdf->setPageOrientation(
'',
false, $heightforfooter);
711 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
712 $pdf->setPage($afterPosData[
'page']);
713 $curY = $tab_top_newpage;
716 $pdf->SetFont(
'',
'', $default_font_size - 1);
731 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
751 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE &&
$object->lines[$i]->remise_percent) {
758 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
761 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
763 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
765 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
772 if ($this->
getColumnStatus(
'totalincltax') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
778 if (!empty(
$object->lines[$i]->array_options)) {
779 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
795 'nexY' => & $afterPosData[
'y'],
796 'outputlangs' => $outputlangs,
797 'hidedetails' => $hidedetails
799 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
804 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
806 $tvaligne =
$object->lines[$i]->total_tva;
809 $localtax1ligne =
$object->lines[$i]->total_localtax1;
810 $localtax2ligne =
$object->lines[$i]->total_localtax2;
811 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
812 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
813 $localtax1_type =
$object->lines[$i]->localtax1_type;
814 $localtax2_type =
$object->lines[$i]->localtax2_type;
827 $vatrate = (string)
$object->lines[$i]->tva_tx;
830 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
831 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
833 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
834 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
838 if ($localtax1_type && $localtax1ligne != 0) {
839 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
840 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
842 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
845 if ($localtax2_type && $localtax2ligne != 0) {
846 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
847 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
849 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
853 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
858 if (!isset($this->tva[$vatrate])) {
859 $this->tva[$vatrate] = 0;
861 $this->tva[$vatrate] += $tvaligne;
862 $vatcode =
$object->lines[$i]->vat_src_code;
863 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
864 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
866 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
869 if (!$hidenextline) {
871 $pdf->setPage($afterPosData[
'page']);
872 $nexY = $afterPosData[
'y'];
875 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
876 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
878 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
879 $pdf->SetLineStyle(array(
'dash' => 0));
883 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
893 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
895 if (!empty($tplidx)) {
896 $pdf->useTemplate($tplidx);
899 $pdf->setPage($pagenb);
903 $drawTabNumbPage = $pdf->getNumPages();
904 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
907 $pdf->setPageOrientation(
'',
false, 0);
909 $drawTabHideTop = $hidetop;
910 $drawTabTop = $tab_top_newpage;
911 $drawTabBottom = $this->page_hauteur - $heightforfooter;
914 if ($i == $pageposbeforeprintlines) {
916 $drawTabTop = $tab_top;
917 } elseif (!$drawTabHideTop) {
919 $drawTabTop -= $this->tabTitleHeight;
926 if ($i == $pdf->getNumPages()) {
928 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
931 $drawTabHeight = $drawTabBottom - $drawTabTop;
932 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
934 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
940 $pdf->setPageOrientation(
'',
true, 0);
943 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
946 if (!empty($tplidx)) {
947 $pdf->useTemplate($tplidx);
952 $pdf->SetTextColor(0, 0, 0);
954 $pdf->setPage($pdf->getNumPages());
956 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
969 $keywords = $outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name);
970 $pdf->SetKeyWords($keywords.
" PAGESIGN=".$pdf->getPage());
974 if (method_exists($pdf,
'AliasNbPages')) {
975 $pdf->AliasNbPages();
980 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_PROPAL') && $termsofsalefilename) {
981 $termsofsale = $conf->propal->dir_output.
'/'.$termsofsalefilename;
982 if (!empty($conf->propal->multidir_output[
$object->entity ?? $conf->entity])) {
983 $termsofsale = $conf->propal->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
985 if (file_exists($termsofsale) && is_readable($termsofsale)) {
986 $pagecount = $pdf->setSourceFile($termsofsale);
987 for ($i = 1; $i <= $pagecount; $i++) {
988 $tplIdx = $pdf->importPage($i);
989 if ($tplIdx !==
false) {
990 $s = $pdf->getTemplatesize($tplIdx);
991 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
992 $pdf->useTemplate($tplIdx);
994 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1002 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
1004 $already_merged = array();
1005 foreach (
$object->lines as $line) {
1006 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
1011 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
1013 $filetomerge->fetch_by_product($line->fk_product);
1016 $already_merged[] = $line->fk_product;
1018 $product =
new Product($this->db);
1019 $product->fetch($line->fk_product);
1021 if ($product->entity != $conf->entity) {
1022 $entity_product_file = $product->entity;
1024 $entity_product_file = $conf->entity;
1028 if (count($filetomerge->lines) > 0) {
1029 foreach ($filetomerge->lines as $linefile) {
1030 if (!empty($linefile->id) && !empty($linefile->file_name)) {
1031 $filetomerge_dir =
null;
1034 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1036 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1040 $filetomerge_dir = $conf->product->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1042 $filetomerge_dir = $conf->service->multidir_output[$entity_product_file ?? $conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1046 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, $filetomerge_dir ===
null ? LOG_ERR : LOG_DEBUG);
1047 if ($filetomerge_dir ===
null) {
1052 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
1053 if (file_exists($infile) && is_readable($infile)) {
1054 $pagecount = $pdf->setSourceFile($infile);
1055 for ($i = 1; $i <= $pagecount; $i++) {
1056 $tplIdx = $pdf->importPage($i);
1057 if ($tplIdx !==
false) {
1058 $s = $pdf->getTemplatesize($tplIdx);
1059 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1060 $pdf->useTemplate($tplIdx);
1062 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
1075 $pdf->Output($file,
'F');
1078 $hookmanager->initHooks(array(
'pdfgeneration'));
1079 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1081 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1082 $this->warnings = $hookmanager->warnings;
1084 $this->error = $hookmanager->error;
1085 $this->errors = $hookmanager->errors;
1092 $this->result = array(
'fullpath' => $file);
1096 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1100 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1120 $pdf->SetFont(
'',
'', $default_font_size - 1);
1125 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1126 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1127 $pdf->SetXY($this->marge_gauche, $posy);
1128 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1130 $posy = $pdf->GetY() + 4;
1135 $displaydate =
"daytext";
1137 $displaydate =
"day";
1141 if (!empty(
$object->delivery_date)) {
1142 $outputlangs->load(
"sendings");
1143 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1144 $pdf->SetXY($this->marge_gauche, $posy);
1145 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1146 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1147 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1148 $pdf->SetXY($posxval, $posy);
1150 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1152 $posy = $pdf->GetY() + 1;
1154 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1155 $pdf->SetXY($this->marge_gauche, $posy);
1156 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1157 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1158 $pdf->SetTextColor(0, 0, 0);
1159 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1160 $pdf->SetXY($posxval, $posy);
1161 $lib_availability = ($outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(
$object->availability);
1162 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1163 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1165 $posy = $pdf->GetY() + 1;
1170 $outputlangs->load(
"sendings");
1172 $shipping_method_id =
$object->shipping_method_id;
1173 if (
getDolGlobalString(
'SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1174 $shipping_method_id = $this->emetteur->shipping_method_id;
1176 $shipping_method_code =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1177 $shipping_method_label =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1179 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1180 $pdf->SetXY($this->marge_gauche, $posy);
1181 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
1182 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1184 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1185 $pdf->SetXY($posxval, $posy);
1186 $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;
1187 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1188 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1190 $posy = $pdf->GetY() + 1;
1195 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1196 $pdf->SetXY($this->marge_gauche, $posy);
1197 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1198 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1200 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1201 $pdf->SetXY($posxval, $posy);
1202 $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);
1203 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1204 if (
$object->deposit_percent > 0) {
1205 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__',
$object->deposit_percent, $lib_condition_paiement);
1207 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1209 $posy = $pdf->GetY() + 3;
1214 if (
$object->mode_reglement_code
1215 &&
$object->mode_reglement_code !=
'CHQ'
1216 &&
$object->mode_reglement_code !=
'VIR') {
1217 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1218 $pdf->SetXY($this->marge_gauche, $posy);
1219 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1220 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1221 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1222 $pdf->SetXY($posxval, $posy);
1223 $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);
1224 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1226 $posy = $pdf->GetY() + 2;
1230 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1234 $account =
new Account($this->db);
1237 $pdf->SetXY($this->marge_gauche, $posy);
1238 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1239 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1240 $posy = $pdf->GetY() + 1;
1243 $pdf->SetXY($this->marge_gauche, $posy);
1244 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1245 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1246 $posy = $pdf->GetY() + 2;
1250 $pdf->SetXY($this->marge_gauche, $posy);
1251 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1252 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1253 $posy = $pdf->GetY() + 1;
1256 $pdf->SetXY($this->marge_gauche, $posy);
1257 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1258 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1259 $posy = $pdf->GetY() + 2;
1266 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1272 $account =
new Account($this->db);
1273 $account->fetch((
int) $bankid);
1275 $curx = $this->marge_gauche;
1278 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1302 global $conf,
$mysoc, $hookmanager;
1307 $outputlangsbis =
new Translate(
'', $conf);
1309 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1310 $default_font_size--;
1315 $pdf->SetFont(
'',
'', $default_font_size - 1);
1320 if ($this->page_largeur < 210) {
1323 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1332 $total_discount_on_lines = 0;
1333 $multicurrency_total_discount_on_lines = 0;
1334 foreach (
$object->lines as $i => $line) {
1338 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1339 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1341 if ($line->total_ht < 0) {
1342 $total_discount_on_lines += -$line->total_ht;
1343 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1347 if ($total_discount_on_lines > 0) {
1349 $pdf->SetFillColor(255, 255, 255);
1350 $pdf->SetXY($col1x, $tab2_top);
1351 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1352 $pdf->SetXY($col2x, $tab2_top);
1354 $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));
1355 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1359 $pdf->SetFillColor(255, 255, 255);
1360 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1361 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1362 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1364 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1365 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1371 $pdf->SetFillColor(255, 255, 255);
1372 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1373 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1376 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1377 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1380 $pdf->SetFillColor(248, 248, 248);
1383 $total_ttc_origin =
$object->total_ttc;
1385 $this->atleastoneratenotnull = 0;
1387 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1388 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1394 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1395 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1399 foreach ($localtax_rate as $tvakey => $tvaval) {
1404 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1407 if (preg_match(
'/\*/', $tvakey)) {
1408 $tvakey = str_replace(
'*',
'', $tvakey);
1409 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1411 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1413 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1414 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1418 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1419 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1427 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1428 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1432 foreach ($localtax_rate as $tvakey => $tvaval) {
1437 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1440 if (preg_match(
'/\*/', $tvakey)) {
1441 $tvakey = str_replace(
'*',
'', $tvakey);
1442 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1444 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1446 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1447 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1451 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1452 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1459 foreach ($this->tva as $tvakey => $tvaval) {
1461 $this->atleastoneratenotnull++;
1464 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1467 if (preg_match(
'/\*/', $tvakey)) {
1468 $tvakey = str_replace(
'*',
'', $tvakey);
1469 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1471 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1473 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
1474 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1476 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1477 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
1484 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1485 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1489 foreach ($localtax_rate as $tvakey => $tvaval) {
1494 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1497 if (preg_match(
'/\*/', $tvakey)) {
1498 $tvakey = str_replace(
'*',
'', $tvakey);
1499 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1501 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1504 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1505 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1509 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1510 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1518 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1519 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1523 foreach ($localtax_rate as $tvakey => $tvaval) {
1529 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1532 if (preg_match(
'/\*/', $tvakey)) {
1533 $tvakey = str_replace(
'*',
'', $tvakey);
1534 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1536 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1540 $totalvat .= $tvacompl;
1542 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1545 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1549 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1550 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1558 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1559 $pdf->SetTextColor(0, 0, 60);
1560 $pdf->SetFillColor(224, 224, 224);
1561 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1563 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1565 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1567 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1571 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1572 $pdf->SetTextColor(0, 0, 60);
1573 $pdf->SetFillColor(224, 224, 224);
1574 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1576 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1577 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1582 $pdf->SetTextColor(0, 0, 0);
1590 if ($deja_regle > 0) {
1594 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1595 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1597 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1598 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1616 $pdf->SetTextColor(0, 0, 60);
1617 $pdf->SetFillColor(224, 224, 224);
1618 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1619 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1621 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1622 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1624 $pdf->SetFont(
'',
'', $default_font_size - 1);
1625 $pdf->SetTextColor(0, 0, 0);
1628 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1630 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1632 $this->error = $hookmanager->error;
1633 $this->errors = $hookmanager->errors;
1637 return ($tab2_top + ($tab2_hl * $index));
1720 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1722 global $conf, $langs;
1724 $ltrdirection =
'L';
1725 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1726 $ltrdirection =
'R';
1730 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1736 $pdf->SetTextColor(0, 0, 60);
1737 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1741 $posy = $this->marge_haute;
1742 $posx = $this->page_largeur - $this->marge_droite - $w;
1744 $pdf->SetXY($this->marge_gauche, $posy);
1748 if ($this->emetteur->logo) {
1749 $logodir = $conf->mycompany->dir_output;
1750 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
1751 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
1754 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1756 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1758 if (is_readable($logo)) {
1760 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1762 $pdf->SetTextColor(200, 0, 0);
1763 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1764 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1765 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1768 $text = $this->emetteur->name;
1769 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1773 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1774 $pdf->SetXY($posx, $posy);
1775 $pdf->SetTextColor(0, 0, 60);
1776 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1777 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1778 if (
$object->status == $object::STATUS_DRAFT) {
1779 $pdf->SetTextColor(128, 0, 0);
1780 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1783 $pdf->MultiCell($w, 4, $title,
'',
'R');
1785 $pdf->SetFont(
'',
'B', $default_font_size);
1800 $pdf->SetFont(
'',
'', $default_font_size - 2);
1803 if ($ref_customer) {
1805 $pdf->SetXY($posx, $posy);
1806 $pdf->SetTextColor(0, 0, 60);
1807 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($ref_customer), 65),
'',
'R');
1812 if (!empty(
$object->project->ref)) {
1814 $pdf->SetXY($posx, $posy);
1815 $pdf->SetTextColor(0, 0, 60);
1816 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1817 $posy = $pdf->getY();
1823 if (!empty(
$object->project->ref)) {
1824 $outputlangs->load(
"projects");
1826 $pdf->SetXY($posx, $posy);
1827 $pdf->SetTextColor(0, 0, 60);
1828 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1833 $displaydate =
"daytext";
1835 $displaydate =
"day";
1839 $posy = $pdf->getY();
1840 $pdf->SetXY($posx, $posy);
1841 $pdf->SetTextColor(0, 0, 60);
1842 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1845 $pdf->SetXY($posx, $posy);
1846 $pdf->SetTextColor(0, 0, 60);
1848 $title = $outputlangs->transnoentities(
"DateEndPropal");
1849 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1850 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1852 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1856 $pdf->SetXY($posx, $posy);
1857 $pdf->SetTextColor(0, 0, 60);
1858 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
1863 $pdf->SetXY($posx, $posy);
1864 $pdf->SetTextColor(0, 0, 60);
1865 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
1870 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1871 if (count($arrayidcontact) > 0) {
1872 $usertmp =
new User($this->db);
1873 $usertmp->fetch($arrayidcontact[0]);
1875 $pdf->SetXY($posx, $posy);
1876 $pdf->SetTextColor(0, 0, 60);
1877 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1885 $current_y = $pdf->getY();
1887 if ($current_y < $pdf->getY()) {
1888 $top_shift = $pdf->getY() - $current_y;
1893 $carac_emetteur =
'';
1895 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1896 if (count($arrayidcontact) > 0) {
1897 $object->fetch_user($arrayidcontact[0]);
1898 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1899 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1901 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1905 $carac_emetteur .=
"\n";
1912 $posy += $top_shift;
1913 $posx = $this->marge_gauche;
1915 $posx = $this->page_largeur - $this->marge_droite - 80;
1924 $pdf->SetTextColor(0, 0, 0);
1925 $pdf->SetFont(
'',
'', $default_font_size - 2);
1926 $pdf->SetXY($posx, $posy - 5);
1927 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1928 $pdf->SetXY($posx, $posy);
1929 $pdf->SetFillColor(230, 230, 230);
1930 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1931 $pdf->SetTextColor(0, 0, 60);
1936 $pdf->SetXY($posx + 2, $posy + 3);
1937 $pdf->SetFont(
'',
'B', $default_font_size);
1938 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1939 $posy = $pdf->getY();
1943 $pdf->SetXY($posx + 2, $posy);
1944 $pdf->SetFont(
'',
'', $default_font_size - 1);
1945 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1949 $usecontact =
false;
1950 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1951 if (count($arrayidcontact) > 0) {
1953 $result =
$object->fetch_contact($arrayidcontact[0]);
1957 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1958 $thirdparty =
$object->contact;
1960 $thirdparty =
$object->thirdparty;
1970 if ($this->page_largeur < 210) {
1974 $posy += $top_shift;
1975 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1977 $posx = $this->marge_gauche;
1982 $pdf->SetTextColor(0, 0, 0);
1983 $pdf->SetFont(
'',
'', $default_font_size - 2);
1984 $pdf->SetXY($posx + 2, $posy - 5);
1985 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1986 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1990 $pdf->SetXY($posx + 2, $posy + 3);
1991 $pdf->SetFont(
'',
'B', $default_font_size);
1993 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1995 $posy = $pdf->getY();
1998 $pdf->SetFont(
'',
'', $default_font_size - 1);
1999 $pdf->SetXY($posx + 2, $posy);
2001 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
2004 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2006 if (!empty($idaddressshipping)) {
2007 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2008 $companystatic =
new Societe($this->db);
2009 $companystatic->fetch(
$object->contact->fk_soc);
2016 if (!empty($carac_client_shipping)) {
2017 $posy += $hautcadre;
2022 $pdf->SetXY($posx + 2, $posy - 5);
2023 $pdf->SetFont(
'',
'', $default_font_size - 2);
2024 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2025 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2028 $pdf->SetXY($posx + 2, $posy + 3);
2029 $pdf->SetFont(
'',
'B', $default_font_size);
2030 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2032 $posy = $pdf->getY();
2035 $pdf->SetXY($posx + 2, $posy);
2036 $pdf->SetFont(
'',
'', $default_font_size - 1);
2037 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2039 $shipp_shift += $hautcadre + 10;
2043 $pdf->SetTextColor(0, 0, 0);
2045 return array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);