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;
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 if (
$conf->entity != $objphoto->entity) {
224 $dir =
$conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
226 $dir =
$conf->product->dir_output.
'/'.$midir;
229 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
231 if ($obj[
'photo_vignette']) {
232 $filename = $obj[
'photo_vignette'];
234 $filename = $obj[
'photo'];
237 $filename = $obj[
'photo'];
240 $realpath = $dir.$filename;
242 $this->atleastonephoto =
true;
247 if ($realpath && $arephoto) {
248 $realpatharray[$i] = $realpath;
253 if (count($realpatharray) == 0) {
254 $this->posxpicture = $this->posxtva;
257 if (
$conf->propal->multidir_output[
$conf->entity]) {
264 $dir =
$conf->propal->multidir_output[
$conf->entity];
265 $file = $dir.
"/SPECIMEN.pdf";
268 $dir =
$conf->propal->multidir_output[
$object->entity].
"/".$objectref;
269 $file = $dir.
"/".$objectref.
".pdf";
272 if (!file_exists($dir)) {
274 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
279 if (file_exists($dir)) {
281 if (!is_object($hookmanager)) {
282 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
285 $hookmanager->initHooks(array(
'pdfgeneration'));
286 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
288 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
291 $nblines = count(
$object->lines);
297 $pdf->setAutoPageBreak(
true, 0);
299 if (class_exists(
'TCPDF')) {
300 $pdf->setPrintHeader(
false);
301 $pdf->setPrintFooter(
false);
306 $logodir =
$conf->mycompany->dir_output;
307 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
308 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
310 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
311 $tplidx = $pdf->importPage(1);
316 $pdf->SetDrawColor(128, 128, 128);
318 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
319 $pdf->SetSubject($outputlangs->transnoentities(
"PdfCommercialProposalTitle"));
320 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
321 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
322 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
324 $pdf->SetCompression(
false);
328 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
331 for ($i = 0; $i < $nblines; $i++) {
332 if (
$object->lines[$i]->remise_percent) {
333 $this->atleastonediscount++;
340 if (!empty($tplidx)) {
341 $pdf->useTemplate($tplidx);
345 $heightforinfotot = 40;
348 $heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
351 $save_note_public =
$object->note_public;
353 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
354 $pdf->SetFont(
'',
'', $default_font_size - 1);
355 $pdf->MultiCell(0, 3,
'');
356 $pdf->SetTextColor(0, 0, 0);
359 $tab_top = 90 + $top_shift;
360 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
361 if (!$hidetop &&
getDolGlobalInt(
'MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
363 $tab_top_newpage += $this->tabTitleHeight;
369 $height_incoterms = 0;
370 if (isModEnabled(
'incoterm')) {
371 $desc_incoterms =
$object->getIncotermsForPDF();
372 if ($desc_incoterms) {
375 $pdf->SetFont(
'',
'', $default_font_size - 1);
376 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
377 $nexY = max($pdf->GetY(), $nexY);
378 $height_incoterms = $nexY - $tab_top;
381 $pdf->SetDrawColor(192, 192, 192);
382 $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');
384 $tab_top = $nexY + 6;
385 $height_incoterms += 4;
390 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
393 if (is_object(
$object->thirdparty)) {
394 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
395 $salerepobj =
new User($this->db);
396 $salerepobj->fetch($salereparray[0][
'id']);
397 if (!empty($salerepobj->signature)) {
398 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
403 $object->note_public = $save_note_public;
406 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
407 if (!empty($extranote)) {
412 $tmpuser =
new User($this->db);
413 $tmpuser->fetch(
$object->user_author_id);
415 $creator_info = $langs->trans(
"CaseFollowedBy").
' '.$tmpuser->getFullName($langs);
416 if ($tmpuser->email) {
417 $creator_info .=
', '.$langs->trans(
"EMail").
': '.$tmpuser->email;
419 if ($tmpuser->office_phone) {
420 $creator_info .=
', '.$langs->trans(
"Phone").
': '.$tmpuser->office_phone;
423 $notetoshow =
dol_concatdesc((
string) $notetoshow, $creator_info);
426 $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
428 $pagenb = $pdf->getPage();
432 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
433 $pageposbeforenote = $pagenb;
440 $pdf->startTransaction();
442 $pdf->SetFont(
'',
'', $default_font_size - 1);
443 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
445 $pageposafternote = $pdf->getPage();
446 $posyafter = $pdf->GetY();
448 if ($pageposafternote > $pageposbeforenote) {
449 $pdf->rollbackTransaction(
true);
452 while ($pagenb < $pageposafternote) {
455 if (!empty($tplidx)) {
456 $pdf->useTemplate($tplidx);
462 $pdf->setTopMargin($tab_top_newpage);
464 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
468 $pdf->setPage($pageposbeforenote);
469 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
470 $pdf->SetFont(
'',
'', $default_font_size - 1);
471 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
472 $pageposafternote = $pdf->getPage();
474 $posyafter = $pdf->GetY();
476 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
477 $pdf->AddPage(
'',
'',
true);
480 $pdf->setPage($pageposafternote);
481 $pdf->setTopMargin($tab_top_newpage);
483 $pdf->setPageOrientation(
'',
true, $heightforfooter + $heightforfreetext);
489 $i = $pageposbeforenote;
490 while ($i < $pageposafternote) {
494 $pdf->SetDrawColor(128, 128, 128);
496 if ($i > $pageposbeforenote) {
497 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
498 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
500 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
501 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
505 $pdf->setPageOrientation(
'',
true, 0);
512 $pdf->setPage($pageposafternote);
513 if (!empty($tplidx)) {
514 $pdf->useTemplate($tplidx);
519 $height_note = $posyafter - $tab_top_newpage;
520 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
523 $pdf->commitTransaction();
524 $posyafter = $pdf->GetY();
525 $height_note = $posyafter - $tab_top;
526 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 2, $this->corner_radius,
'1234',
'D');
529 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
531 $pdf->AddPage(
'',
'',
true);
534 $pdf->setPage($pageposafternote);
535 if (!empty($tplidx)) {
536 $pdf->useTemplate($tplidx);
542 $posyafter = $tab_top_newpage;
545 $tab_height -= $height_note;
546 $tab_top = $posyafter + 6;
555 $pdf->startTransaction();
556 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
557 $pdf->rollbackTransaction(
true);
559 $nexY = $tab_top + $this->tabTitleHeight;
562 $pageposbeforeprintlines = $pdf->getPage();
563 $pagenb = $pageposbeforeprintlines;
565 $pdf_sub_options = array();
566 $pdf_sub_options[
'titleshowuponpdf'] = 1;
567 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
569 for ($i = 0; $i < $nblines; $i++) {
570 $linePosition = $i + 1;
573 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
575 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
576 $level =
$object->lines[$i]->qty;
578 if (isset($sub_options[
'titleshowuponpdf'])) {
579 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
580 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
581 unset($pdf_sub_options[
'titleshowuponpdf']);
583 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
584 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
585 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
586 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
589 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
590 unset($pdf_sub_options[
'titleshowuponpdf']);
592 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
593 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
598 if (($curY + 6) > ($this->page_hauteur - $heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight)) {
599 $object->lines[$i]->pagebreak =
true;
603 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
606 if (!empty($tplidx)) {
607 $pdf->useTemplate($tplidx);
610 $pdf->setPage($pdf->getNumPages());
611 $nexY = $curY = $tab_top_newpage;
616 $pdf->SetFont(
'',
'', $default_font_size - 1);
617 $pdf->SetTextColor(0, 0, 0);
620 $imglinesize = array();
621 if (!empty($realpatharray[$i])) {
625 $pdf->setTopMargin($tab_top_newpage);
626 $pdf->setPageOrientation(
'',
true, $heightforfooter);
627 $pageposbefore = $pdf->getPage();
631 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
638 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $heightforfooter)) {
639 $pdf->AddPage(
'',
'',
true);
640 if (!empty($tplidx)) {
641 $pdf->useTemplate($tplidx);
643 $pdf->setPage($pageposbefore + 1);
644 $pdf->setPageOrientation(
'',
true, $heightforfooter);
645 $curY = $tab_top_newpage;
646 $showpricebeforepagebreak = 0;
649 $pdf->setPageOrientation(
'',
false, $heightforfooter + $heightforfreetext);
651 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
652 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
654 $posYAfterImage = $curY + $imglinesize[
'height'];
661 $pdf->setPageOrientation(
'',
true, $heightforfooter);
664 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
669 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
674 $pdf->setPage($pageposbefore);
675 $pdf->setTopMargin($this->marge_haute);
677 $pdf->setPageOrientation(
'',
false, $heightforfooter);
681 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
682 $pdf->setPage($afterPosData[
'page']);
683 $curY = $tab_top_newpage;
686 $pdf->SetFont(
'',
'', $default_font_size - 1);
701 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
721 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE &&
$object->lines[$i]->remise_percent) {
728 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
731 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
732 if (isModEnabled(
'multicurrency') &&
$object->multicurrency_code !=
$conf->currency) {
733 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
735 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
748 if (!empty(
$object->lines[$i]->array_options)) {
749 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
765 'nexY' => & $afterPosData[
'y'],
766 'outputlangs' => $outputlangs,
767 'hidedetails' => $hidedetails
769 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
773 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
774 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
776 $tvaligne =
$object->lines[$i]->total_tva;
779 $localtax1ligne =
$object->lines[$i]->total_localtax1;
780 $localtax2ligne =
$object->lines[$i]->total_localtax2;
781 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
782 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
783 $localtax1_type =
$object->lines[$i]->localtax1_type;
784 $localtax2_type =
$object->lines[$i]->localtax2_type;
797 $vatrate = (string)
$object->lines[$i]->tva_tx;
800 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
801 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
803 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
804 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
808 if ($localtax1_type && $localtax1ligne != 0) {
809 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
810 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
812 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
815 if ($localtax2_type && $localtax2ligne != 0) {
816 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
817 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
819 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
823 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
828 if (!isset($this->tva[$vatrate])) {
829 $this->tva[$vatrate] = 0;
831 $this->tva[$vatrate] += $tvaligne;
832 $vatcode =
$object->lines[$i]->vat_src_code;
833 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
834 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
836 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
841 $pdf->setPage($afterPosData[
'page']);
842 $nexY = $afterPosData[
'y'];
845 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $heightforfooter - 5) {
846 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
848 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
849 $pdf->SetLineStyle(array(
'dash' => 0));
858 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) {
860 if (!empty($tplidx)) {
861 $pdf->useTemplate($tplidx);
864 $pdf->setPage($pagenb);
868 $drawTabNumbPage = $pdf->getNumPages();
869 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
872 $pdf->setPageOrientation(
'',
false, 0);
874 $drawTabHideTop = $hidetop;
875 $drawTabTop = $tab_top_newpage;
876 $drawTabBottom = $this->page_hauteur - $heightforfooter;
879 if ($i == $pageposbeforeprintlines) {
881 $drawTabTop = $tab_top;
882 } elseif (!$drawTabHideTop) {
884 $drawTabTop -= $this->tabTitleHeight;
891 if ($i == $pdf->getNumPages()) {
893 $drawTabBottom -= $heightforsignature + $heightforfreetext + $heightforinfotot;
896 $drawTabHeight = $drawTabBottom - $drawTabTop;
897 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
899 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
905 $pdf->setPageOrientation(
'',
true, 0);
908 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
911 if (!empty($tplidx)) {
912 $pdf->useTemplate($tplidx);
917 $pdf->SetTextColor(0, 0, 0);
919 $pdf->setPage($pdf->getNumPages());
921 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
934 $keywords = $outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfCommercialProposalTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name);
935 $pdf->SetKeyWords($keywords.
" PAGESIGN=".$pdf->getPage());
939 if (method_exists($pdf,
'AliasNbPages')) {
940 $pdf->AliasNbPages();
946 $termsofsale =
$conf->propal->dir_output.
'/'.$termsofsalefilename;
947 if (!empty(
$conf->propal->multidir_output[
$object->entity])) {
948 $termsofsale =
$conf->propal->multidir_output[
$object->entity].
'/'.$termsofsalefilename;
950 if (file_exists($termsofsale) && is_readable($termsofsale)) {
951 $pagecount = $pdf->setSourceFile($termsofsale);
952 for ($i = 1; $i <= $pagecount; $i++) {
953 $tplIdx = $pdf->importPage($i);
954 if ($tplIdx !==
false) {
955 $s = $pdf->getTemplatesize($tplIdx);
956 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
957 $pdf->useTemplate($tplIdx);
959 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
967 require_once DOL_DOCUMENT_ROOT.
'/product/class/propalmergepdfproduct.class.php';
969 $already_merged = array();
970 foreach (
$object->lines as $line) {
971 if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
976 $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
978 $filetomerge->fetch_by_product($line->fk_product);
981 $already_merged[] = $line->fk_product;
983 $product =
new Product($this->db);
984 $product->fetch($line->fk_product);
986 if ($product->entity !=
$conf->entity) {
987 $entity_product_file = $product->entity;
989 $entity_product_file =
$conf->entity;
993 if (count($filetomerge->lines) > 0) {
994 foreach ($filetomerge->lines as $linefile) {
995 if (!empty($linefile->id) && !empty($linefile->file_name)) {
996 $filetomerge_dir =
null;
998 if (isModEnabled(
"product")) {
999 $filetomerge_dir =
$conf->product->multidir_output[(int) $entity_product_file].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1000 } elseif (isModEnabled(
"service")) {
1001 $filetomerge_dir =
$conf->service->multidir_output[(int) $entity_product_file].
'/'.
get_exdir($product->id, 2, 0, 0, $product,
'product').$product->id.
"/photos";
1004 if (isModEnabled(
"product")) {
1005 $filetomerge_dir =
$conf->product->multidir_output[(int) $entity_product_file].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1006 } elseif (isModEnabled(
"service")) {
1007 $filetomerge_dir =
$conf->service->multidir_output[(int) $entity_product_file].
'/'.
get_exdir(0, 0, 0, 0, $product,
'product');
1011 dol_syslog(get_class($this).
':: upload_dir='.$filetomerge_dir, $filetomerge_dir ===
null ? LOG_ERR : LOG_DEBUG);
1012 if ($filetomerge_dir ===
null) {
1017 $infile = $filetomerge_dir.
'/'.$linefile->file_name;
1018 if (file_exists($infile) && is_readable($infile)) {
1019 $pagecount = $pdf->setSourceFile($infile);
1020 for ($i = 1; $i <= $pagecount; $i++) {
1021 $tplIdx = $pdf->importPage($i);
1022 if ($tplIdx !==
false) {
1023 $s = $pdf->getTemplatesize($tplIdx);
1024 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1025 $pdf->useTemplate($tplIdx);
1027 setEventMessages(
null, array($infile.
' cannot be added, probably protected PDF'),
'warnings');
1040 $pdf->Output($file,
'F');
1043 $hookmanager->initHooks(array(
'pdfgeneration'));
1044 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1046 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1048 $this->error = $hookmanager->error;
1049 $this->errors = $hookmanager->errors;
1054 $this->result = array(
'fullpath' => $file);
1058 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
1062 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"PROP_OUTPUTDIR");
1082 $pdf->SetFont(
'',
'', $default_font_size - 1);
1087 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1088 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1089 $pdf->SetXY($this->marge_gauche, $posy);
1090 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1092 $posy = $pdf->GetY() + 4;
1097 $displaydate =
"daytext";
1099 $displaydate =
"day";
1103 if (!empty(
$object->delivery_date)) {
1104 $outputlangs->load(
"sendings");
1105 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1106 $pdf->SetXY($this->marge_gauche, $posy);
1107 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
1108 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1109 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1110 $pdf->SetXY($posxval, $posy);
1112 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
1114 $posy = $pdf->GetY() + 1;
1116 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1117 $pdf->SetXY($this->marge_gauche, $posy);
1118 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
1119 $pdf->MultiCell(80, 4, $titre, 0,
'L');
1120 $pdf->SetTextColor(0, 0, 0);
1121 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1122 $pdf->SetXY($posxval, $posy);
1123 $lib_availability = ($outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities(
"AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(
$object->availability);
1124 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
1125 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
1127 $posy = $pdf->GetY() + 1;
1132 $outputlangs->load(
"sendings");
1134 $shipping_method_id =
$object->shipping_method_id;
1135 if (
getDolGlobalString(
'SOCIETE_ASK_FOR_SHIPPING_METHOD') && !empty($this->emetteur->shipping_method_id)) {
1136 $shipping_method_id = $this->emetteur->shipping_method_id;
1138 $shipping_method_code =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'code');
1139 $shipping_method_label =
dol_getIdFromCode($this->db, (
string) $shipping_method_id,
'c_shipment_mode',
'rowid',
'libelle');
1141 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1142 $pdf->SetXY($this->marge_gauche, $posy);
1143 $titre = $outputlangs->transnoentities(
"SendingMethod").
':';
1144 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1146 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1147 $pdf->SetXY($posxval, $posy);
1148 $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;
1149 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1150 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1152 $posy = $pdf->GetY() + 1;
1157 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1158 $pdf->SetXY($this->marge_gauche, $posy);
1159 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1160 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1162 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1163 $pdf->SetXY($posxval, $posy);
1164 $lib_condition_paiement = $outputlangs->transnoentities(
"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);
1165 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1166 if (
$object->deposit_percent > 0) {
1167 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__',
$object->deposit_percent, $lib_condition_paiement);
1169 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1171 $posy = $pdf->GetY() + 3;
1176 if (
$object->mode_reglement_code
1177 &&
$object->mode_reglement_code !=
'CHQ'
1178 &&
$object->mode_reglement_code !=
'VIR') {
1179 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1180 $pdf->SetXY($this->marge_gauche, $posy);
1181 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1182 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1183 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1184 $pdf->SetXY($posxval, $posy);
1185 $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);
1186 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1188 $posy = $pdf->GetY() + 2;
1192 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1196 $account =
new Account($this->db);
1199 $pdf->SetXY($this->marge_gauche, $posy);
1200 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1201 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1202 $posy = $pdf->GetY() + 1;
1205 $pdf->SetXY($this->marge_gauche, $posy);
1206 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1207 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1208 $posy = $pdf->GetY() + 2;
1212 $pdf->SetXY($this->marge_gauche, $posy);
1213 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1214 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1215 $posy = $pdf->GetY() + 1;
1218 $pdf->SetXY($this->marge_gauche, $posy);
1219 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1220 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1221 $posy = $pdf->GetY() + 2;
1228 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1234 $account =
new Account($this->db);
1235 $account->fetch($bankid);
1237 $curx = $this->marge_gauche;
1240 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1264 global
$conf, $mysoc, $hookmanager;
1271 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1272 $default_font_size--;
1277 $pdf->SetFont(
'',
'', $default_font_size - 1);
1282 if ($this->page_largeur < 210) {
1285 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1291 $total_ht = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1 ?
$object->multicurrency_total_ht :
$object->total_ht);
1294 $total_discount_on_lines = 0;
1295 $multicurrency_total_discount_on_lines = 0;
1296 foreach (
$object->lines as $i => $line) {
1300 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1301 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1303 if ($line->total_ht < 0) {
1304 $total_discount_on_lines += -$line->total_ht;
1305 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1309 if ($total_discount_on_lines > 0) {
1311 $pdf->SetFillColor(255, 255, 255);
1312 $pdf->SetXY($col1x, $tab2_top);
1313 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1314 $pdf->SetXY($col2x, $tab2_top);
1316 $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));
1317 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1321 $pdf->SetFillColor(255, 255, 255);
1322 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1323 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1324 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1326 $total_discount_to_show = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1327 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1333 $pdf->SetFillColor(255, 255, 255);
1334 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1335 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1337 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
1338 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1339 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R',
true);
1342 $pdf->SetFillColor(248, 248, 248);
1344 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
1345 $total_ttc_origin =
$object->total_ttc;
1347 $this->atleastoneratenotnull = 0;
1349 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1350 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1356 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1357 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1361 foreach ($localtax_rate as $tvakey => $tvaval) {
1366 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1369 if (preg_match(
'/\*/', $tvakey)) {
1370 $tvakey = str_replace(
'*',
'', $tvakey);
1371 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1373 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1375 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1376 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1378 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1380 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1381 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1389 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1390 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1394 foreach ($localtax_rate as $tvakey => $tvaval) {
1399 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1402 if (preg_match(
'/\*/', $tvakey)) {
1403 $tvakey = str_replace(
'*',
'', $tvakey);
1404 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1406 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1408 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1409 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1411 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1413 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1414 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1421 foreach ($this->tva as $tvakey => $tvaval) {
1423 $this->atleastoneratenotnull++;
1426 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1429 if (preg_match(
'/\*/', $tvakey)) {
1430 $tvakey = str_replace(
'*',
'', $tvakey);
1431 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1433 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1435 $totalvat .=
vatrate($tvakey,
true).$tvacompl;
1436 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1438 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1439 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R',
true);
1446 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1447 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1451 foreach ($localtax_rate as $tvakey => $tvaval) {
1456 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1459 if (preg_match(
'/\*/', $tvakey)) {
1460 $tvakey = str_replace(
'*',
'', $tvakey);
1461 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1463 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1466 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1467 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1469 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1471 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1472 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1480 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1481 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1485 foreach ($localtax_rate as $tvakey => $tvaval) {
1491 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1494 if (preg_match(
'/\*/', $tvakey)) {
1495 $tvakey = str_replace(
'*',
'', $tvakey);
1496 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1498 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1502 $totalvat .= $tvacompl;
1504 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1507 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1509 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1511 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1512 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1520 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1521 $pdf->SetTextColor(0, 0, 60);
1522 $pdf->SetFillColor(224, 224, 224);
1523 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1525 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1526 if (!isModEnabled(
"multicurrency") ||
$object->multicurrency_tx == 1 ||
getDolGlobalInt(
'MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
1527 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1529 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1533 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1534 $pdf->SetTextColor(0, 0, 60);
1535 $pdf->SetFillColor(224, 224, 224);
1536 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).
')', $useborder,
'L',
true);
1538 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1539 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder,
'L',
true);
1544 $pdf->SetTextColor(0, 0, 0);
1552 if ($deja_regle > 0) {
1556 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1557 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
1559 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1560 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
1578 $pdf->SetTextColor(0, 0, 60);
1579 $pdf->SetFillColor(224, 224, 224);
1580 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1581 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
1583 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1584 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1586 $pdf->SetFont(
'',
'', $default_font_size - 1);
1587 $pdf->SetTextColor(0, 0, 0);
1590 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1592 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1594 $this->error = $hookmanager->error;
1595 $this->errors = $hookmanager->errors;
1599 return ($tab2_top + ($tab2_hl * $index));
1682 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1684 global
$conf, $langs;
1686 $ltrdirection =
'L';
1687 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1688 $ltrdirection =
'R';
1692 $outputlangs->loadLangs(array(
"main",
"propal",
"companies",
"bills"));
1698 $pdf->SetTextColor(0, 0, 60);
1699 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1703 $posy = $this->marge_haute;
1704 $posx = $this->page_largeur - $this->marge_droite - $w;
1706 $pdf->SetXY($this->marge_gauche, $posy);
1710 if ($this->emetteur->logo) {
1711 $logodir =
$conf->mycompany->dir_output;
1712 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
1713 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
1716 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1718 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1720 if (is_readable($logo)) {
1722 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1724 $pdf->SetTextColor(200, 0, 0);
1725 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1726 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1727 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1730 $text = $this->emetteur->name;
1731 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1735 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1736 $pdf->SetXY($posx, $posy);
1737 $pdf->SetTextColor(0, 0, 60);
1738 $title = $outputlangs->transnoentities(
"PdfCommercialProposalTitle");
1739 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1740 if (
$object->status == $object::STATUS_DRAFT) {
1741 $pdf->SetTextColor(128, 0, 0);
1742 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1745 $pdf->MultiCell($w, 4, $title,
'',
'R');
1747 $pdf->SetFont(
'',
'B', $default_font_size);
1762 $pdf->SetFont(
'',
'', $default_font_size - 2);
1765 if ($ref_customer) {
1767 $pdf->SetXY($posx, $posy);
1768 $pdf->SetTextColor(0, 0, 60);
1769 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($ref_customer), 65),
'',
'R');
1774 if (!empty(
$object->project->ref)) {
1776 $pdf->SetXY($posx, $posy);
1777 $pdf->SetTextColor(0, 0, 60);
1778 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1784 if (!empty(
$object->project->ref)) {
1785 $outputlangs->load(
"projects");
1787 $pdf->SetXY($posx, $posy);
1788 $pdf->SetTextColor(0, 0, 60);
1789 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1794 $displaydate =
"daytext";
1796 $displaydate =
"day";
1800 $posy = $pdf->getY();
1801 $pdf->SetXY($posx, $posy);
1802 $pdf->SetTextColor(0, 0, 60);
1803 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date, $displaydate,
false, $outputlangs,
true),
'',
'R');
1806 $pdf->SetXY($posx, $posy);
1807 $pdf->SetTextColor(0, 0, 60);
1809 $title = $outputlangs->transnoentities(
"DateEndPropal");
1810 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1811 $title .=
' - '.$outputlangsbis->transnoentities(
"DateEndPropal");
1813 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->fin_validite, $displaydate,
false, $outputlangs,
true),
'',
'R');
1817 $pdf->SetXY($posx, $posy);
1818 $pdf->SetTextColor(0, 0, 60);
1819 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
1824 $pdf->SetXY($posx, $posy);
1825 $pdf->SetTextColor(0, 0, 60);
1826 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
1831 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1832 if (count($arrayidcontact) > 0) {
1833 $usertmp =
new User($this->db);
1834 $usertmp->fetch($arrayidcontact[0]);
1836 $pdf->SetXY($posx, $posy);
1837 $pdf->SetTextColor(0, 0, 60);
1838 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1846 $current_y = $pdf->getY();
1848 if ($current_y < $pdf->getY()) {
1849 $top_shift = $pdf->getY() - $current_y;
1854 $carac_emetteur =
'';
1856 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1857 if (count($arrayidcontact) > 0) {
1858 $object->fetch_user($arrayidcontact[0]);
1859 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1860 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1862 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1866 $carac_emetteur .=
"\n";
1873 $posy += $top_shift;
1874 $posx = $this->marge_gauche;
1876 $posx = $this->page_largeur - $this->marge_droite - 80;
1884 $pdf->SetTextColor(0, 0, 0);
1885 $pdf->SetFont(
'',
'', $default_font_size - 2);
1886 $pdf->SetXY($posx, $posy - 5);
1887 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1888 $pdf->SetXY($posx, $posy);
1889 $pdf->SetFillColor(230, 230, 230);
1890 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
1891 $pdf->SetTextColor(0, 0, 60);
1896 $pdf->SetXY($posx + 2, $posy + 3);
1897 $pdf->SetFont(
'',
'B', $default_font_size);
1898 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1899 $posy = $pdf->getY();
1903 $pdf->SetXY($posx + 2, $posy);
1904 $pdf->SetFont(
'',
'', $default_font_size - 1);
1905 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1909 $usecontact =
false;
1910 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1911 if (count($arrayidcontact) > 0) {
1913 $result =
$object->fetch_contact($arrayidcontact[0]);
1917 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1918 $thirdparty =
$object->contact;
1920 $thirdparty =
$object->thirdparty;
1930 if ($this->page_largeur < 210) {
1934 $posy += $top_shift;
1935 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1937 $posx = $this->marge_gauche;
1942 $pdf->SetTextColor(0, 0, 0);
1943 $pdf->SetFont(
'',
'', $default_font_size - 2);
1944 $pdf->SetXY($posx + 2, $posy - 5);
1945 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1946 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1950 $pdf->SetXY($posx + 2, $posy + 3);
1951 $pdf->SetFont(
'',
'B', $default_font_size);
1953 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1955 $posy = $pdf->getY();
1958 $pdf->SetFont(
'',
'', $default_font_size - 1);
1959 $pdf->SetXY($posx + 2, $posy);
1961 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1964 $pdf->SetTextColor(0, 0, 0);