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 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
359 $top_shift = $pagehead[
'top_shift'];
360 $shipp_shift = $pagehead[
'shipp_shift'];
361 $pdf->SetFont(
'',
'', $default_font_size - 1);
362 $pdf->MultiCell(0, 3,
'');
363 $pdf->SetTextColor(0, 0, 0);
366 $tab_top = 80 + $this->marge_haute + $top_shift + $shipp_shift;
367 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute + $top_shift : $this->marge_haute);
368 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
370 $tab_top_newpage += $this->tabTitleHeight;
376 $height_incoterms = 0;
378 $desc_incoterms =
$object->getIncotermsForPDF();
379 if ($desc_incoterms) {
382 $pdf->SetFont(
'',
'', $default_font_size - 1);
383 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
384 $nexY = max($pdf->GetY(), $nexY);
385 $height_incoterms = $nexY - $tab_top;
388 $pdf->SetDrawColor(192, 192, 192);
389 $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');
391 $tab_top = $nexY + 6;
392 $height_incoterms += 4;
397 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
400 if (is_object(
$object->thirdparty)) {
401 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
402 $salerepobj =
new User($this->db);
403 $salerepobj->fetch($salereparray[0][
'id']);
404 if (!empty($salerepobj->signature)) {
405 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
410 $object->note_public = $save_note_public;
413 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
414 if (!empty($extranote)) {
419 $tmpuser =
new User($this->db);
420 $tmpuser->fetch(
$object->user_author_id);
422 $creator_info = $langs->trans(
"CaseFollowedBy").
' '.$tmpuser->getFullName($langs);
423 if ($tmpuser->email) {
424 $creator_info .=
', '.$langs->trans(
"EMail").
': '.$tmpuser->email;
426 if ($tmpuser->office_phone) {
427 $creator_info .=
', '.$langs->trans(
"Phone").
': '.$tmpuser->office_phone;
430 $notetoshow =
dol_concatdesc((
string) $notetoshow, $creator_info);
433 $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
435 $pagenb = $pdf->getPage();
439 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
440 $pageposbeforenote = $pagenb;
447 $pdf->startTransaction();
449 $pdf->SetFont(
'',
'', $default_font_size - 1);
450 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
452 $pageposafternote = $pdf->getPage();
453 $posyafter = $pdf->GetY();
455 if ($pageposafternote > $pageposbeforenote) {
456 $pdf->rollbackTransaction(
true);
459 while ($pagenb < $pageposafternote) {
462 if (!empty($tplidx)) {
463 $pdf->useTemplate($tplidx);
469 $pdf->setTopMargin($tab_top_newpage);
471 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
475 $pdf->setPage($pageposbeforenote);
476 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
477 $pdf->SetFont(
'',
'', $default_font_size - 1);
478 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
479 $pageposafternote = $pdf->getPage();
481 $posyafter = $pdf->GetY();
483 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
484 $pdf->AddPage(
'',
'',
true);
487 $pdf->setPage($pageposafternote);
488 $pdf->setTopMargin($tab_top_newpage);
490 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
496 $i = $pageposbeforenote;
497 while ($i < $pageposafternote) {
501 $pdf->SetDrawColor(128, 128, 128);
503 if ($i > $pageposbeforenote) {
504 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
505 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
507 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
508 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
512 $pdf->setPageOrientation(
'',
true, 0);
519 $pdf->setPage($pageposafternote);
520 if (!empty($tplidx)) {
521 $pdf->useTemplate($tplidx);
526 $height_note = $posyafter - $tab_top_newpage;
527 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
530 $pdf->commitTransaction();
531 $posyafter = $pdf->GetY();
532 $height_note = $posyafter - $tab_top;
533 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
536 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
538 $pdf->AddPage(
'',
'',
true);
541 $pdf->setPage($pageposafternote);
542 if (!empty($tplidx)) {
543 $pdf->useTemplate($tplidx);
549 $posyafter = $tab_top_newpage;
552 $tab_height -= $height_note;
553 $tab_top = $posyafter + 6;
562 $pdf->startTransaction();
563 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
564 $pdf->rollbackTransaction(
true);
566 $nexY = $tab_top + $this->tabTitleHeight;
569 $pageposbeforeprintlines = $pdf->getPage();
570 $pagenb = $pageposbeforeprintlines;
572 $pdf_sub_options = array();
573 $pdf_sub_options[
'titleshowuponpdf'] = 1;
574 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
575 $pdf_sub_options_before_title = array();
579 for ($i = 0; $i < $nblines; $i++) {
580 $linePosition = $i + 1;
583 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
586 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
587 $level =
$object->lines[$i]->qty;
589 if ($level > 0 && !isset($pdf_sub_options_before_title[(
int) $level])) {
590 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
594 if (isset($sub_options[
'titleshowuponpdf'])) {
595 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
596 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
597 unset($pdf_sub_options[
'titleshowuponpdf']);
599 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
600 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
601 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
602 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
605 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
606 unset($pdf_sub_options[
'titleshowuponpdf']);
608 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
609 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
613 if ($level < 0 && isset($pdf_sub_options_before_title[(
int) abs($level)])) {
614 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
615 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
616 if ($tmplevel >= abs($level)) {
617 unset($pdf_sub_options_before_title[$tmplevel]);
623 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
625 $pdf_sub_options = array();
626 $pdf_sub_options[
'titleshowuponpdf'] = 1;
627 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
633 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
634 $object->lines[$i]->pagebreak =
true;
638 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
641 if (!empty($tplidx)) {
642 $pdf->useTemplate($tplidx);
645 $pdf->setPage($pdf->getNumPages());
646 $nexY = $curY = $tab_top_newpage;
651 $pdf->SetFont(
'',
'', $default_font_size - 1);
652 $pdf->SetTextColor(0, 0, 0);
655 $imglinesize = array();
656 if (!empty($realpatharray[$i])) {
660 $pdf->setTopMargin($tab_top_newpage);
661 $pdf->setPageOrientation(
'',
true, $heightforfooter);
662 $pageposbefore = $pdf->getPage();
666 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
673 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
674 $pdf->AddPage(
'',
'',
true);
675 if (!empty($tplidx)) {
676 $pdf->useTemplate($tplidx);
678 $pdf->setPage($pageposbefore + 1);
679 $pdf->setPageOrientation(
'',
true, $heightforfooter);
680 $curY = $tab_top_newpage;
681 $showpricebeforepagebreak = 0;
684 $pdf->setPageOrientation(
'',
false, $heightforfooter + $heightforfreetext);
686 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
687 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
689 $posYAfterImage = $curY + $imglinesize[
'height'];
696 $pdf->setPageOrientation(
'',
true, $heightforfooter);
699 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
704 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
709 $pdf->setPage($pageposbefore);
710 $pdf->setTopMargin($this->marge_haute);
712 $pdf->setPageOrientation(
'',
false, $heightforfooter);
716 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
717 $pdf->setPage($afterPosData[
'page']);
718 $curY = $tab_top_newpage;
721 $pdf->SetFont(
'',
'', $default_font_size - 1);
736 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
756 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE &&
$object->lines[$i]->remise_percent) {
763 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
766 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
768 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
770 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
777 if ($this->
getColumnStatus(
'totalincltax') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
783 if (!empty(
$object->lines[$i]->array_options)) {
784 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
800 'nexY' => & $afterPosData[
'y'],
801 'outputlangs' => $outputlangs,
802 'hidedetails' => $hidedetails
804 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
809 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
811 $tvaligne =
$object->lines[$i]->total_tva;
814 $localtax1ligne =
$object->lines[$i]->total_localtax1;
815 $localtax2ligne =
$object->lines[$i]->total_localtax2;
816 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
817 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
818 $localtax1_type =
$object->lines[$i]->localtax1_type;
819 $localtax2_type =
$object->lines[$i]->localtax2_type;
821 $vatrate = (string)
$object->lines[$i]->tva_tx;
824 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
825 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
827 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
828 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
832 if ($localtax1_type && $localtax1ligne != 0) {
833 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
834 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
836 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
839 if ($localtax2_type && $localtax2ligne != 0) {
840 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
841 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
843 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
847 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
852 if (!isset($this->tva[$vatrate])) {
853 $this->tva[$vatrate] = 0;
855 $this->tva[$vatrate] += $tvaligne;
856 $vatcode =
$object->lines[$i]->vat_src_code;
857 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
858 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
860 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
863 if (!$hidenextline) {
865 $pdf->setPage($afterPosData[
'page']);
866 $nexY = $afterPosData[
'y'];
869 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
870 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
872 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
873 $pdf->SetLineStyle(array(
'dash' => 0));
877 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
887 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
889 if (!empty($tplidx)) {
890 $pdf->useTemplate($tplidx);
893 $pdf->setPage($pagenb);
897 $drawTabNumbPage = $pdf->getNumPages();
898 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
901 $pdf->setPageOrientation(
'',
false, 0);
903 $drawTabHideTop = $hidetop;
904 $drawTabTop = $tab_top_newpage;
905 $drawTabBottom = $this->page_hauteur - $heightforfooter;
908 if ($i == $pageposbeforeprintlines) {
910 $drawTabTop = $tab_top;
911 } elseif (!$drawTabHideTop) {
913 $drawTabTop -= $this->tabTitleHeight;
920 if ($i == $pdf->getNumPages()) {
922 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
925 $drawTabHeight = $drawTabBottom - $drawTabTop;
926 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
928 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
934 $pdf->setPageOrientation(
'',
true, 0);
937 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
940 if (!empty($tplidx)) {
941 $pdf->useTemplate($tplidx);
946 $pdf->SetTextColor(0, 0, 0);
948 $pdf->setPage($pdf->getNumPages());
950 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
963 $keywords = $outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name);
964 $pdf->SetKeyWords($keywords.
" PAGESIGN=".$pdf->getPage());
968 if (method_exists($pdf,
'AliasNbPages')) {
969 $pdf->AliasNbPages();
975 $termsofsale =
$conf->propal->dir_output.
'/'.$termsofsalefilename;
977 $termsofsale =
$conf->propal->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
979 if (file_exists($termsofsale) && is_readable($termsofsale)) {
980 $pagecount = $pdf->setSourceFile($termsofsale);
981 for ($i = 1; $i <= $pagecount; $i++) {
982 $tplIdx = $pdf->importPage($i);
983 if ($tplIdx !==
false) {
984 $s = $pdf->getTemplatesize($tplIdx);
985 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
986 $pdf->useTemplate($tplIdx);
988 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
996 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
998 $already_merged = array();
999 foreach (
$object->lines as $line) {
1000 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
1005 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
1007 $filetomerge->fetch_by_product($line->fk_product);
1010 $already_merged[] = $line->fk_product;
1012 $product =
new Product($this->db);
1013 $product->fetch($line->fk_product);
1015 if ($product->entity !=
$conf->entity) {
1016 $entity_product_file = $product->entity;
1018 $entity_product_file =
$conf->entity;
1022 if (count($filetomerge->lines) > 0) {
1023 foreach ($filetomerge->lines as $linefile) {
1024 if (!empty($linefile->id) && !empty($linefile->file_name)) {
1025 $filetomerge_dir =
null;
1028 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1030 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1034 $filetomerge_dir =
$conf->product->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1036 $filetomerge_dir =
$conf->service->multidir_output[$entity_product_file ??
$conf->entity].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1040 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, $filetomerge_dir ===
null ? LOG_ERR : LOG_DEBUG);
1041 if ($filetomerge_dir ===
null) {
1046 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
1047 if (file_exists($infile) && is_readable($infile)) {
1048 $pagecount = $pdf->setSourceFile($infile);
1049 for ($i = 1; $i <= $pagecount; $i++) {
1050 $tplIdx = $pdf->importPage($i);
1051 if ($tplIdx !==
false) {
1052 $s = $pdf->getTemplatesize($tplIdx);
1053 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1054 $pdf->useTemplate($tplIdx);
1056 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
1069 $pdf->Output($file,
'F');
1072 $hookmanager->initHooks(array(
'pdfgeneration'));
1073 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1075 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1076 $this->warnings = $hookmanager->warnings;
1078 $this->error = $hookmanager->error;
1079 $this->errors = $hookmanager->errors;
1086 $this->result = array(
'fullpath' => $file);
1090 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1094 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1114 $pdf->SetFont(
'',
'', $default_font_size - 1);
1119 if ($this->emetteur->country_code ==
'FR' && empty(
$mysoc->tva_assuj)) {
1120 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1121 $pdf->SetXY($this->marge_gauche, $posy);
1122 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1124 $posy = $pdf->GetY() + 4;
1129 $displaydate =
"daytext";
1131 $displaydate =
"day";
1135 if (!empty(
$object->delivery_date)) {
1136 $outputlangs->load(
"sendings");
1137 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1138 $pdf->SetXY($this->marge_gauche, $posy);
1139 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1140 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1141 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1142 $pdf->SetXY($posxval, $posy);
1144 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1146 $posy = $pdf->GetY() + 1;
1148 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1149 $pdf->SetXY($this->marge_gauche, $posy);
1150 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1151 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1152 $pdf->SetTextColor(0, 0, 0);
1153 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1154 $pdf->SetXY($posxval, $posy);
1155 $lib_availability = ($outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(
$object->availability);
1156 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1157 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1159 $posy = $pdf->GetY() + 1;
1164 $outputlangs->load(
"sendings");
1166 $shipping_method_id =
$object->shipping_method_id;
1167 if (
getDolGlobalString(
'SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1168 $shipping_method_id = $this->emetteur->shipping_method_id;
1170 $shipping_method_code =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1171 $shipping_method_label =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1173 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1174 $pdf->SetXY($this->marge_gauche, $posy);
1175 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
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(
"SendingMethod".strtoupper($shipping_method_code)) !=
"SendingMethod".strtoupper($shipping_method_code)) ? $outputlangs->trans(
"SendingMethod".strtoupper($shipping_method_code)) : $shipping_method_label;
1181 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1182 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1184 $posy = $pdf->GetY() + 1;
1189 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1190 $pdf->SetXY($this->marge_gauche, $posy);
1191 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1192 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1194 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1195 $pdf->SetXY($posxval, $posy);
1196 $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);
1197 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1198 if (
$object->deposit_percent > 0) {
1199 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__',
$object->deposit_percent, $lib_condition_paiement);
1201 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1203 $posy = $pdf->GetY() + 3;
1208 if (
$object->mode_reglement_code
1209 &&
$object->mode_reglement_code !=
'CHQ'
1210 &&
$object->mode_reglement_code !=
'VIR') {
1211 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1212 $pdf->SetXY($this->marge_gauche, $posy);
1213 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1214 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1215 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1216 $pdf->SetXY($posxval, $posy);
1217 $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);
1218 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1220 $posy = $pdf->GetY() + 2;
1224 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1228 $account =
new Account($this->db);
1231 $pdf->SetXY($this->marge_gauche, $posy);
1232 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1233 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1234 $posy = $pdf->GetY() + 1;
1237 $pdf->SetXY($this->marge_gauche, $posy);
1238 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1239 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1240 $posy = $pdf->GetY() + 2;
1244 $pdf->SetXY($this->marge_gauche, $posy);
1245 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1246 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1247 $posy = $pdf->GetY() + 1;
1250 $pdf->SetXY($this->marge_gauche, $posy);
1251 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1252 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1253 $posy = $pdf->GetY() + 2;
1260 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1266 $account =
new Account($this->db);
1267 $account->fetch((
int) $bankid);
1269 $curx = $this->marge_gauche;
1272 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1303 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1304 $default_font_size--;
1309 $pdf->SetFont(
'',
'', $default_font_size - 1);
1314 if ($this->page_largeur < 210) {
1317 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1326 $total_discount_on_lines = 0;
1327 $multicurrency_total_discount_on_lines = 0;
1328 foreach (
$object->lines as $i => $line) {
1332 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1333 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1335 if ($line->total_ht < 0) {
1336 $total_discount_on_lines += -$line->total_ht;
1337 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1341 if ($total_discount_on_lines > 0) {
1342 if ($this->showAmountBeforeDiscount) {
1344 $pdf->SetFillColor(255, 255, 255);
1345 $pdf->SetXY($col1x, $tab2_top);
1346 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1347 $pdf->SetXY($col2x, $tab2_top);
1349 $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));
1350 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1355 if ($this->showDiscountAmount) {
1356 $pdf->SetFillColor(255, 255, 255);
1357 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1358 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount") . (is_object($outputlangsbis) ?
' / ' . $outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1359 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1361 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1362 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1369 $pdf->SetFillColor(255, 255, 255);
1370 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1371 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1374 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1375 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1378 $pdf->SetFillColor(248, 248, 248);
1381 $total_ttc_origin =
$object->total_ttc;
1383 $this->atleastoneratenotnull = 0;
1385 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1386 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1392 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1393 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1397 foreach ($localtax_rate as $tvakey => $tvaval) {
1402 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1405 if (preg_match(
'/\*/', $tvakey)) {
1406 $tvakey = str_replace(
'*',
'', $tvakey);
1407 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1409 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1411 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1412 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1416 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1417 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1425 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1426 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1430 foreach ($localtax_rate as $tvakey => $tvaval) {
1435 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1438 if (preg_match(
'/\*/', $tvakey)) {
1439 $tvakey = str_replace(
'*',
'', $tvakey);
1440 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1442 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1444 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1445 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1449 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1450 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1457 foreach ($this->tva as $tvakey => $tvaval) {
1459 $this->atleastoneratenotnull++;
1462 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1465 if (preg_match(
'/\*/', $tvakey)) {
1466 $tvakey = str_replace(
'*',
'', $tvakey);
1467 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1469 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1471 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
1472 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1474 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1475 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
1482 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1483 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1487 foreach ($localtax_rate as $tvakey => $tvaval) {
1492 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1495 if (preg_match(
'/\*/', $tvakey)) {
1496 $tvakey = str_replace(
'*',
'', $tvakey);
1497 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1499 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1502 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1503 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1507 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1508 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1516 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1517 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1521 foreach ($localtax_rate as $tvakey => $tvaval) {
1527 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1530 if (preg_match(
'/\*/', $tvakey)) {
1531 $tvakey = str_replace(
'*',
'', $tvakey);
1532 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1534 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1538 $totalvat .= $tvacompl;
1540 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1543 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1547 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1548 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1556 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1557 $pdf->SetTextColor(0, 0, 60);
1558 $pdf->SetFillColor(224, 224, 224);
1559 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1561 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1563 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1565 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1569 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1570 $pdf->SetTextColor(0, 0, 60);
1571 $pdf->SetFillColor(224, 224, 224);
1572 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1574 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1575 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1580 $pdf->SetTextColor(0, 0, 0);
1588 if ($deja_regle > 0) {
1592 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1593 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1595 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1596 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1614 $pdf->SetTextColor(0, 0, 60);
1615 $pdf->SetFillColor(224, 224, 224);
1616 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1617 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1619 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1620 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1622 $pdf->SetFont(
'',
'', $default_font_size - 1);
1623 $pdf->SetTextColor(0, 0, 0);
1626 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1628 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1630 $this->error = $hookmanager->error;
1631 $this->errors = $hookmanager->errors;
1635 return ($tab2_top + ($tab2_hl * $index));
1718 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1720 global
$conf, $langs;
1722 $ltrdirection =
'L';
1723 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1724 $ltrdirection =
'R';
1728 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1734 $pdf->SetTextColor(0, 0, 60);
1735 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1739 $posy = $this->marge_haute;
1740 $posx = $this->page_largeur - $this->marge_droite - $w;
1742 $pdf->SetXY($this->marge_gauche, $posy);
1745 $logodir =
$conf->mycompany->dir_output;
1746 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
1749 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size, $ltrdirection);
1751 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1752 $pdf->SetXY($posx, $posy);
1753 $pdf->SetTextColor(0, 0, 60);
1754 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1755 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1756 if (
$object->status == $object::STATUS_DRAFT) {
1757 $pdf->SetTextColor(128, 0, 0);
1758 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1761 $pdf->MultiCell($w, 4, $title,
'',
'R');
1763 $pdf->SetFont(
'',
'B', $default_font_size);
1778 $pdf->SetFont(
'',
'', $default_font_size - 2);
1781 if ($ref_customer) {
1783 $pdf->SetXY($posx, $posy);
1784 $pdf->SetTextColor(0, 0, 60);
1785 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
pdf_truncate_text($pdf, $outputlangs->convToOutputCharset($ref_customer), 65),
'',
'R');
1790 if (!empty(
$object->project->title)) {
1792 $pdf->SetXY($posx, $posy);
1793 $pdf->SetTextColor(0, 0, 60);
1794 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
pdf_truncate_text($pdf,
$object->project->title, 50),
'',
'R');
1795 $posy = $pdf->getY();
1801 if (!empty(
$object->project->ref)) {
1802 $outputlangs->load(
"projects");
1804 $pdf->SetXY($posx, $posy);
1805 $pdf->SetTextColor(0, 0, 60);
1806 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
1811 $displaydate =
"daytext";
1813 $displaydate =
"day";
1817 $posy = $pdf->getY();
1818 $pdf->SetXY($posx, $posy);
1819 $pdf->SetTextColor(0, 0, 60);
1820 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1823 $pdf->SetXY($posx, $posy);
1824 $pdf->SetTextColor(0, 0, 60);
1826 $title = $outputlangs->transnoentities(
"DateEndPropal");
1827 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1828 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1830 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1834 $pdf->SetXY($posx, $posy);
1835 $pdf->SetTextColor(0, 0, 60);
1836 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
1841 $pdf->SetXY($posx, $posy);
1842 $pdf->SetTextColor(0, 0, 60);
1843 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
1848 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1849 if (count($arrayidcontact) > 0) {
1850 $usertmp =
new User($this->db);
1851 $usertmp->fetch($arrayidcontact[0]);
1853 $pdf->SetXY($posx, $posy);
1854 $pdf->SetTextColor(0, 0, 60);
1855 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1863 $current_y = $pdf->getY();
1865 if ($current_y < $pdf->getY()) {
1866 $top_shift = $pdf->getY() - $current_y;
1871 $carac_emetteur =
'';
1873 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1874 if (count($arrayidcontact) > 0) {
1875 $object->fetch_user($arrayidcontact[0]);
1876 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1877 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1879 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1883 $carac_emetteur .=
"\n";
1890 $posy += $top_shift + $this->marge_haute;
1891 $posx = $this->marge_gauche;
1893 $posx = $this->page_largeur - $this->marge_droite - 80;
1902 $pdf->SetTextColor(0, 0, 0);
1903 $pdf->SetFont(
'',
'', $default_font_size - 2);
1904 $pdf->SetXY($posx, $posy - 5);
1905 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1906 $pdf->SetXY($posx, $posy);
1907 $pdf->SetFillColor(230, 230, 230);
1908 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1909 $pdf->SetTextColor(0, 0, 60);
1914 $pdf->SetXY($posx + 2, $posy + 3);
1915 $pdf->SetFont(
'',
'B', $default_font_size);
1916 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1917 $posy = $pdf->getY();
1921 $pdf->SetXY($posx + 2, $posy);
1922 $pdf->SetFont(
'',
'', $default_font_size - 1);
1923 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1927 $usecontact =
false;
1928 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1929 if (count($arrayidcontact) > 0) {
1931 $result =
$object->fetch_contact($arrayidcontact[0]);
1935 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1936 $thirdparty =
$object->contact;
1938 $thirdparty =
$object->thirdparty;
1948 if ($this->page_largeur < 210) {
1951 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? 30 + $this->marge_haute : 32 + $this->marge_haute;
1952 $posy += $top_shift;
1953 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1955 $posx = $this->marge_gauche;
1960 $pdf->SetTextColor(0, 0, 0);
1961 $pdf->SetFont(
'',
'', $default_font_size - 2);
1962 $pdf->SetXY($posx + 2, $posy - 5);
1963 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1964 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1968 $pdf->SetXY($posx + 2, $posy + 3);
1969 $pdf->SetFont(
'',
'B', $default_font_size);
1971 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1973 $posy = $pdf->getY();
1976 $pdf->SetFont(
'',
'', $default_font_size - 1);
1977 $pdf->SetXY($posx + 2, $posy);
1979 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1982 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
1984 if (!empty($idaddressshipping)) {
1985 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
1986 $companystatic =
new Societe($this->db);
1987 $companystatic->fetch(
$object->contact->fk_soc);
1994 if (!empty($carac_client_shipping)) {
1995 $posy += $hautcadre;
2000 $pdf->SetXY($posx + 2, $posy - 5);
2001 $pdf->SetFont(
'',
'', $default_font_size - 2);
2002 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2003 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2006 $pdf->SetXY($posx + 2, $posy + 3);
2007 $pdf->SetFont(
'',
'B', $default_font_size);
2008 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2010 $posy = $pdf->getY();
2013 $pdf->SetXY($posx + 2, $posy);
2014 $pdf->SetFont(
'',
'', $default_font_size - 1);
2015 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2017 $shipp_shift += $hautcadre + 10;
2021 $pdf->SetTextColor(0, 0, 0);
2023 return array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);