212 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
215 global $user, $langs,
$conf,
$mysoc, $hookmanager, $nblines;
217 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
219 if (!is_object($outputlangs)) {
220 $outputlangs = $langs;
224 $outputlangs->charset_output =
'ISO-8859-1';
228 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
230 global $outputlangsbis;
231 $outputlangsbis =
null;
235 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
243 $nblines = count(
$object->lines);
251 $realpatharray = array();
252 $this->atleastonephoto =
false;
254 $objphoto =
new Product($this->db);
256 for ($i = 0; $i < $nblines; $i++) {
257 if (empty(
$object->lines[$i]->fk_product)) {
261 $objphoto->fetch(
$object->lines[$i]->fk_product);
265 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
266 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
268 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
269 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
274 foreach ($pdir as $midir) {
276 $entity = $objphoto->entity;
277 if ($entity !==
null &&
$conf->entity != $entity) {
278 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
280 $dir =
$conf->product->dir_output.
'/'.$midir;
283 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
285 if ($obj[
'photo_vignette']) {
286 $filename = $obj[
'photo_vignette'];
288 $filename = $obj[
'photo'];
291 $filename = $obj[
'photo'];
294 $realpath = $dir.$filename;
296 $this->atleastonephoto =
true;
301 if (!empty($realpath) && $arephoto) {
302 $realpatharray[$i] = $realpath;
309 if (
$conf->facture->multidir_output[
$conf->entity]) {
313 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
314 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
318 $dir =
$conf->facture->multidir_output[
$conf->entity];
319 $file = $dir.
"/SPECIMEN.pdf";
322 $dir =
$conf->facture->multidir_output[
$object->entity ??
$conf->entity].
"/".$objectref;
323 $file = $dir.
"/".$objectref.
".pdf";
325 if (!file_exists($dir)) {
327 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
332 if (file_exists($dir)) {
334 if (!is_object($hookmanager)) {
335 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
338 $hookmanager->initHooks(array(
'pdfgeneration'));
339 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
341 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
344 $nblines = count(
$object->lines);
345 $nbpayments = count(
$object->getListOfPayments());
350 $pdf->setAutoPageBreak(
true, 0);
353 $this->heightforinfotot = 50;
355 $this->heightforinfotot += (4 * $nbpayments);
357 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
358 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
360 $heightforqrinvoice = 0;
364 $this->heightforinfotot = 30 + (4 * $nbpayments);
368 if (class_exists(
'TCPDF')) {
369 $pdf->setPrintHeader(
false);
370 $pdf->setPrintFooter(
false);
376 $logodir =
$conf->mycompany->dir_output;
377 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
380 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
381 $tplidx = $pdf->importPage(1);
386 $pdf->SetDrawColor(128, 128, 128);
388 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
389 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
390 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
391 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)) :
''));
392 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
394 $pdf->SetCompression(
false);
404 'Name' => $this->emetteur->name,
405 'Location' =>
getCountry($this->emetteur->country_code,
''),
406 'Reason' =>
'INVOICE',
407 'ContactInfo' => $this->emetteur->email
409 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
413 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
417 $categoryOfOperation = 0;
420 for ($i = 0; $i < $nblines; $i++) {
423 if ($line->remise_percent) {
424 $this->atleastonediscount++;
428 if ($line->isDepositLine()) {
433 if ($categoryOfOperation < 2) {
434 $lineProductType = $line->product_type;
440 if ($nbProduct > 0 && $nbService > 0) {
442 $categoryOfOperation = 2;
447 if ($categoryOfOperation <= 0) {
449 if ($nbProduct == 0 && $nbService > 0) {
450 $categoryOfOperation = 1;
453 $this->categoryOfOperation = $categoryOfOperation;
456 if (
$object->situation_cycle_ref) {
457 $this->situationinvoice =
true;
462 if (!empty($tplidx)) {
463 $pdf->useTemplate($tplidx);
468 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
469 $top_shift = $pagehead[
'top_shift'];
470 $shipp_shift = $pagehead[
'shipp_shift'];
471 $pdf->SetFont(
'',
'', $default_font_size - 1);
472 $pdf->MultiCell(0, 3,
'');
473 $pdf->SetTextColor(0, 0, 0);
478 $this->tab_top = $this->marge_haute + 80 + $top_shift + $shipp_shift;
479 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
482 $extra_under_address_shift = 0;
485 $qrcodestring =
$object->buildZATCAQRString();
488 $qrcodestring =
$object->buildSwitzerlandQRString();
493 $qrcodestring =
$object->buildEPCQrCodeString();
498 $qrcodecolor = array(
'25',
'25',
'25');
503 'fgcolor' => $qrcodecolor,
508 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
512 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
513 $pdf->SetFont(
'',
'', $default_font_size - 4);
514 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
518 $extra_under_address_shift += 25;
524 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_fi.lib.php';
526 if ($fibarcodedata !=
'') {
532 'cellfitalign' =>
'',
534 'hpadding' =>
'auto',
536 'fgcolor' => array(0, 0, 0),
540 $pdf->write1DBarcode($fibarcodedata,
'C128C', $this->marge_gauche, $this->tab_top + $extra_under_address_shift, 90, 13, 0.35, $styleBc,
'N');
541 $pdf->SetXY($this->marge_gauche, $pdf->GetY());
542 $pdf->SetFont(
'',
'', $default_font_size - 4);
543 $pdf->MultiCell(90, 3, $outputlangs->transnoentitiesnoconv(
"FIVirtualBarcode").
': '.
dolFIFormatVirtualBarcode($fibarcodedata), 0,
'L',
false);
544 $extra_under_address_shift += 22;
553 'outputlangs' => $outputlangs,
554 'hidedetails' => $hidedetails
556 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
557 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
558 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
561 $this->tab_top += $extra_under_address_shift;
562 $this->tab_top_newpage += 0;
566 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
568 $nexY = $this->tab_top - 1;
571 $height_incoterms = 0;
573 $desc_incoterms =
$object->getIncotermsForPDF();
574 if ($desc_incoterms) {
577 $pdf->SetFont(
'',
'', $default_font_size - 1);
578 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
579 $nexY = max($pdf->GetY(), $nexY);
580 $height_incoterms = $nexY - $this->tab_top;
583 $pdf->SetDrawColor(192, 192, 192);
584 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
586 $this->tab_top = $nexY + 6;
587 $height_incoterms += 4;
592 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
595 if (is_object(
$object->thirdparty)) {
596 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
597 $salerepobj =
new User($this->db);
598 $salerepobj->fetch($salereparray[0][
'id']);
599 if (!empty($salerepobj->signature)) {
600 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
606 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
607 if (!empty($extranote)) {
611 $pagenb = $pdf->getPage();
615 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
616 $pageposbeforenote = $pagenb;
623 $pdf->startTransaction();
625 $pdf->SetFont(
'',
'', $default_font_size - 1);
626 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
628 $pageposafternote = $pdf->getPage();
629 $posyafter = $pdf->GetY();
631 if ($pageposafternote > $pageposbeforenote) {
632 $pdf->rollbackTransaction(
true);
635 while ($pagenb < $pageposafternote) {
638 if (!empty($tplidx)) {
639 $pdf->useTemplate($tplidx);
644 $pdf->setTopMargin($this->tab_top_newpage);
646 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
650 $pdf->setPage($pageposbeforenote);
651 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
652 $pdf->SetFont(
'',
'', $default_font_size - 1);
653 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
654 $pageposafternote = $pdf->getPage();
656 $posyafter = $pdf->GetY();
658 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
659 $pdf->AddPage(
'',
'',
true);
662 $pdf->setPage($pageposafternote);
663 $pdf->setTopMargin($this->tab_top_newpage);
665 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
671 $i = $pageposbeforenote;
672 while ($i < $pageposafternote) {
676 $pdf->SetDrawColor(128, 128, 128);
678 if ($i > $pageposbeforenote) {
679 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
680 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
682 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
683 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
687 $pdf->setPageOrientation(
'',
true, 0);
694 $pdf->setPage($pageposafternote);
695 if (!empty($tplidx)) {
696 $pdf->useTemplate($tplidx);
701 $height_note = $posyafter - $this->tab_top_newpage;
702 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
705 $pdf->commitTransaction();
706 $posyafter = $pdf->GetY();
707 $height_note = $posyafter - $this->tab_top;
708 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
711 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
713 $pdf->AddPage(
'',
'',
true);
716 $pdf->setPage($pageposafternote);
717 if (!empty($tplidx)) {
718 $pdf->useTemplate($tplidx);
724 $posyafter = $this->tab_top_newpage;
728 $tab_height -= $height_note;
729 $this->tab_top = $posyafter + 6;
738 $pdf->startTransaction();
739 $this->pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
740 $pdf->rollbackTransaction(
true);
742 $nexY = $this->tab_top + $this->tabTitleHeight;
745 $pageposbeforeprintlines = $pdf->getPage();
746 $pagenb = $pageposbeforeprintlines;
748 $pdf_sub_options = array();
749 $pdf_sub_options[
'titleshowuponpdf'] = 1;
750 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
751 $pdf_sub_options_before_title = array();
755 for ($i = 0; $i < $nblines; $i++) {
756 $linePosition = $i + 1;
759 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
761 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
762 $level =
$object->lines[$i]->qty;
764 if ($level > 0 && !isset($pdf_sub_options_before_title[(
int) $level])) {
765 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
769 if (isset($sub_options[
'titleshowuponpdf'])) {
770 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
771 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
772 unset($pdf_sub_options[
'titleshowuponpdf']);
774 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
775 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
776 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
777 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
780 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
781 unset($pdf_sub_options[
'titleshowuponpdf']);
783 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
784 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
788 if ($level < 0 && isset($pdf_sub_options_before_title[(
int) abs($level)])) {
789 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
790 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
791 if ($tmplevel >= abs($level)) {
792 unset($pdf_sub_options_before_title[$tmplevel]);
798 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
800 $pdf_sub_options = array();
801 $pdf_sub_options[
'titleshowuponpdf'] = 1;
802 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
808 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
809 $object->lines[$i]->pagebreak =
true;
813 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
816 if (!empty($tplidx)) {
817 $pdf->useTemplate($tplidx);
820 $pdf->setPage($pdf->getNumPages());
821 $nexY = $curY = $this->tab_top_newpage;
826 $pdf->SetFont(
'',
'', $default_font_size - 1);
827 $pdf->SetTextColor(0, 0, 0);
830 $imglinesize = array();
831 if (!empty($realpatharray[$i])) {
835 $pdf->setTopMargin($this->tab_top_newpage);
836 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
837 $pageposbefore = $pdf->getPage();
841 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
846 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
847 $pdf->AddPage(
'',
'',
true);
848 if (!empty($tplidx)) {
849 $pdf->useTemplate($tplidx);
851 $pdf->setPage($pageposbefore + 1);
852 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
853 $curY = $this->tab_top_newpage;
854 $showpricebeforepagebreak = 0;
857 $pdf->setPageOrientation(
'',
false, $this->heightforfooter + $this->heightforfreetext);
859 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
860 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
862 $posYAfterImage = $curY + $imglinesize[
'height'];
869 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
873 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
878 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
884 $pdf->setPage($pageposbefore);
885 $pdf->setTopMargin($this->marge_haute);
887 $pdf->setPageOrientation(
'',
false, $this->heightforfooter);
890 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
891 $pdf->setPage($afterPosData[
'page']);
892 $curY = $this->tab_top_newpage;
895 $pdf->SetFont(
'',
'', $default_font_size - 1);
909 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
934 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
941 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
944 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
946 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
948 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
955 if ($this->
getColumnStatus(
'totalincltax') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
961 if (!empty(
$object->lines[$i]->array_options)) {
962 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
978 'nexY' => & $afterPosData[
'y'],
979 'outputlangs' => $outputlangs,
980 'hidedetails' => $hidedetails
982 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
992 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE &&
$object->lines[$i]->product_type != 9) {
995 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
997 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
999 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
1003 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
1005 $tvaligne = $sign *
$object->lines[$i]->total_tva;
1009 $localtax1ligne =
$object->lines[$i]->total_localtax1;
1010 $localtax2ligne =
$object->lines[$i]->total_localtax2;
1011 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
1012 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
1013 $localtax1_type =
$object->lines[$i]->localtax1_type;
1014 $localtax2_type =
$object->lines[$i]->localtax2_type;
1016 $vatrate = (string)
$object->lines[$i]->tva_tx;
1019 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
1020 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
1022 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
1023 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
1027 if ($localtax1_type && $localtax1ligne != 0) {
1028 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
1029 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
1031 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
1034 if ($localtax2_type && $localtax2ligne != 0) {
1035 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
1036 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
1038 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
1042 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
1047 if (!isset($this->tva[$vatrate])) {
1048 $this->tva[$vatrate] = 0;
1050 $this->tva[$vatrate] += $tvaligne;
1051 $vatcode =
$object->lines[$i]->vat_src_code;
1052 if (empty($this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'amount'])) {
1053 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'amount'] = 0;
1056 if (empty($this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'])) {
1057 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
1059 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'amount'] + $tvaligne,
'tot_ht' => $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] +
$object->lines[$i]->total_ht);
1061 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'amount'] + $tvaligne);
1065 if (!$hidenextline) {
1067 $pdf->setPage($afterPosData[
'page']);
1068 $nexY = $afterPosData[
'y'];
1071 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1072 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1074 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1075 $pdf->SetLineStyle(array(
'dash' => 0));
1079 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
1088 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
1090 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
1092 if (!empty($tplidx)) {
1093 $pdf->useTemplate($tplidx);
1096 $pdf->setPage($pagenb);
1100 $drawTabNumbPage = $pdf->getNumPages();
1101 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1104 $pdf->setPageOrientation(
'',
false, 0);
1106 $drawTabHideTop = $hidetop;
1107 $drawTabTop = $this->tab_top_newpage;
1108 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1111 if ($i == $pageposbeforeprintlines) {
1113 $drawTabTop = $this->tab_top;
1114 } elseif (!$drawTabHideTop) {
1116 $drawTabTop -= $this->tabTitleHeight;
1118 $drawTabHideTop = 1;
1123 if ($i == $pdf->getNumPages()) {
1125 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1128 $drawTabHeight = $drawTabBottom - $drawTabTop;
1129 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object, $outputlangsbis);
1131 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1138 $pdf->setPageOrientation(
'',
true, 0);
1141 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1144 if (!empty($tplidx)) {
1145 $pdf->useTemplate($tplidx);
1151 $pdf->SetTextColor(0, 0, 0);
1153 $pdf->setPage($pdf->getNumPages());
1155 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1161 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1164 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1165 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1170 if (method_exists($pdf,
'AliasNbPages')) {
1171 $pdf->AliasNbPages();
1177 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1178 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1179 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1182 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1183 $pagecount = $pdf->setSourceFile($termsofsale);
1184 for ($i = 1; $i <= $pagecount; $i++) {
1185 $tplIdx = $pdf->importPage($i);
1186 if ($tplIdx !==
false) {
1187 $s = $pdf->getTemplatesize($tplIdx);
1188 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1189 $pdf->useTemplate($tplIdx);
1191 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1203 $pdf->Output($file,
'F');
1206 $hookmanager->initHooks(array(
'pdfgeneration'));
1207 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1209 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1210 $this->warnings = $hookmanager->warnings;
1212 $this->error = $hookmanager->error;
1213 $this->errors = $hookmanager->errors;
1220 $this->result = array(
'fullpath' => $file);
1224 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1228 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1392 $pdf->SetFont(
'',
'', $default_font_size - 1);
1394 krsort($this->tva_array);
1401 $pdf->SetFillColor(224, 224, 224);
1403 $pdf->SetFont(
'',
'', $default_font_size - 2);
1404 $pdf->SetXY($this->marge_gauche, $posy);
1405 $titre = $outputlangs->transnoentities(
"VAT");
1406 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1408 $pdf->SetFont(
'',
'', $default_font_size - 2);
1409 $pdf->SetXY($this->marge_gauche + 25, $posy);
1410 $titre = $outputlangs->transnoentities(
"NetTotal");
1411 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1413 $pdf->SetFont(
'',
'', $default_font_size - 2);
1414 $pdf->SetXY($this->marge_gauche + 50, $posy);
1415 $titre = $outputlangs->transnoentities(
"VATAmount");
1416 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1418 $pdf->SetFont(
'',
'', $default_font_size - 2);
1419 $pdf->SetXY($this->marge_gauche + 75, $posy);
1420 $titre = $outputlangs->transnoentities(
"AmountTotal");
1421 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1423 $posy = $pdf->GetY();
1428 foreach ($this->tva_array as $tvakey => $tvaval) {
1429 $pdf->SetFont(
'',
'', $default_font_size - 2);
1430 $pdf->SetXY($this->marge_gauche, $posy);
1431 $titre = round((
float) $tvakey, 2) .
"%";
1432 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1434 $pdf->SetFont(
'',
'', $default_font_size - 2);
1435 $pdf->SetXY($this->marge_gauche + 25, $posy);
1436 $titre =
price($tvaval[
'tot_ht']);
1437 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1438 $tot_ht += $tvaval[
'tot_ht'];
1440 $pdf->SetFont(
'',
'', $default_font_size - 2);
1441 $pdf->SetXY($this->marge_gauche + 50, $posy);
1442 $titre =
price($tvaval[
'amount']);
1443 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1444 $tot_tva += $tvaval[
'amount'];
1446 $pdf->SetFont(
'',
'', $default_font_size - 2);
1447 $pdf->SetXY($this->marge_gauche + 75, $posy);
1448 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1449 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1450 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1452 $posy = $pdf->GetY();
1457 $showvatmention = 0;
1458 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1459 $pdf->SetFont(
'',
'', $default_font_size - 2);
1460 $pdf->SetXY($this->marge_gauche, $posy);
1461 if (empty(
$mysoc->tva_assuj)) {
1462 if (
$mysoc->forme_juridique_code == 92) {
1463 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1465 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1468 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1469 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1472 $posy = $pdf->GetY();
1475 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1477 if ($showvatmention) {
1483 if ($this->page_largeur < 210) {
1490 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1491 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1492 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1493 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1494 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1495 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1496 $sql .=
" AND f.fk_statut > 0";
1497 $sql .=
" ORDER BY f.datef ASC";
1500 $invoices = array();
1501 $resql = $this->db->query($sql);
1503 while ($obj = $this->db->fetch_object($resql)) {
1505 $old_balance += $obj->total_ttc;
1507 $this->db->free($resql);
1511 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1512 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1513 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1514 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1515 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1516 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1517 $sql_payments .=
" ORDER BY p.datep ASC";
1519 $total_payments = 0;
1520 $resql_payments = $this->db->query($sql_payments);
1521 if ($resql_payments) {
1522 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1523 $total_payments += $obj_payment->amount;
1525 $this->db->free($resql_payments);
1529 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1530 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1531 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1532 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1533 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1534 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1536 $current_date_payments = 0;
1537 $resql_current_date = $this->db->query($sql_current_date_payments);
1538 if ($resql_current_date) {
1539 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1540 $current_date_payments += $obj_current->amount;
1542 $this->db->free($resql_current_date);
1546 $old_balance -= $total_payments;
1549 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1551 $pdf->SetFillColor(224, 224, 224);
1552 $pdf->SetFont(
'',
'', $default_font_size - 2);
1553 $pdf->SetXY($this->marge_gauche, $posy);
1554 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1555 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1557 $pdf->SetFont(
'',
'', $default_font_size - 2);
1558 $pdf->SetXY($posxval + 8, $posy);
1559 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1560 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1562 $posy = $pdf->GetY() + 1;
1567 $pdf->SetFont(
'',
'', $default_font_size - 2);
1568 $pdf->SetXY($this->marge_gauche, $posy);
1569 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1570 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1572 $pdf->SetFont(
'',
'', $default_font_size - 2);
1573 $pdf->SetXY($posxval, $posy);
1574 $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);
1575 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1576 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1578 $posy = $pdf->GetY() + 3;
1582 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1583 $pdf->SetFont(
'',
'', $default_font_size - 2);
1584 $pdf->SetXY($this->marge_gauche, $posy);
1585 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1586 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1588 $pdf->SetFont(
'',
'', $default_font_size - 2);
1589 $pdf->SetXY($posxval, $posy);
1590 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1591 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1593 $posy = $pdf->GetY() + 3;
1598 if (empty(
$object->mode_reglement_code)
1601 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1605 $outputlangs->load(
"errors");
1607 $pdf->SetXY($this->marge_gauche, $posy);
1608 $pdf->SetTextColor(200, 0, 0);
1609 $pdf->SetFont(
'',
'', $default_font_size - 2);
1610 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1611 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1612 $pdf->SetTextColor(0, 0, 0);
1614 $posy = $pdf->GetY() + 1;
1618 if (!empty(
$object->mode_reglement_code)
1619 &&
$object->mode_reglement_code !=
'CHQ'
1620 &&
$object->mode_reglement_code !=
'VIR') {
1621 $pdf->SetFont(
'',
'', $default_font_size - 2);
1622 $pdf->SetXY($this->marge_gauche, $posy);
1623 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1624 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1626 $pdf->SetFont(
'',
'', $default_font_size - 2);
1627 $pdf->SetXY($posxval, $posy);
1628 $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);
1631 if (
$object->mode_reglement_code ==
"PRE") {
1632 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1635 $bac->fetch(0,
'',
$object->thirdparty->id);
1636 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1637 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
pdf_truncate_text($pdf, $iban, 6,
'right',
''));
1640 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1642 $posy = $pdf->GetY();
1648 if ($this->emetteur->country_code ==
'FR') {
1650 $pdf->SetXY($this->marge_gauche, $posy);
1651 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1653 $posy = $pdf->GetY() + 1;
1658 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1659 $useonlinepayment = 0;
1663 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1664 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1665 $useonlinepayment = count($validpaymentmethod);
1670 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1673 $langs->loadLangs(array(
'payment',
'stripe'));
1674 $servicename = $langs->transnoentities(
'Online');
1675 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1676 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1678 $pdf->SetXY($this->marge_gauche, $posy);
1679 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1681 $posy = $pdf->GetY() + 1;
1686 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1692 $account =
new Account($this->db);
1695 $pdf->SetXY($this->marge_gauche, $posy);
1696 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1697 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1698 $posy = $pdf->GetY() + 1;
1701 $pdf->SetXY($this->marge_gauche, $posy);
1702 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1703 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1704 $posy = $pdf->GetY() + 2;
1708 $pdf->SetXY($this->marge_gauche, $posy);
1709 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1710 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1711 $posy = $pdf->GetY() + 1;
1714 $pdf->SetXY($this->marge_gauche, $posy);
1715 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1716 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1717 $posy = $pdf->GetY() + 2;
1725 $showbankblock = ((empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR')
1727 if (!empty(
$object->payment_reference) && !$showbankblock) {
1728 include_once DOL_DOCUMENT_ROOT.
'/core/lib/paymentref.lib.php';
1729 $pdf->SetXY($this->marge_gauche, $posy);
1731 $pdf->SetFont(
'',
'B', $default_font_size - 3);
1732 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentReference').
": " . $outputlangs->convToOutputCharset(
dolPayRefFormatForDisplay(
$object->payment_reference,
$mysoc->country_code)), 0,
'L',
false);
1733 $posy = $pdf->GetY() + 1;
1737 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1743 $account =
new Account($this->db);
1744 $account->fetch($bankid);
1746 $curx = $this->marge_gauche;
1749 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1754 if (!empty(
$object->payment_reference)) {
1755 include_once DOL_DOCUMENT_ROOT.
'/core/lib/paymentref.lib.php';
1757 $pdf->SetXY($this->marge_gauche, $posy);
1758 $pdf->SetFont(
'',
'B', $default_font_size - 3);
1759 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentReference').
": " . $outputlangs->convToOutputCharset(
dolPayRefFormatForDisplay(
$object->payment_reference,
$mysoc->country_code)), 0,
'L',
false);
1760 $posy = $pdf->GetY();
1767 $qrPosX = $this->marge_gauche + 5;
1769 $qrCodeColor = array(
'25',
'25',
'25');
1773 'fgcolor' => $qrCodeColor,
1775 'module_width' => 1,
1776 'module_height' => 1
1779 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1780 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1782 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1783 $pdf->SetFont(
'',
'', $default_font_size - 5);
1784 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1786 $posy = max($pdf->GetY(), $qrPosY + 20) + 2;
1787 $pdf->SetXY($this->marge_gauche, $posy);
1793 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1796 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1819 global
$mysoc, $hookmanager;
1830 if (is_object($outputlangsbis)) {
1831 $pdf->SetFont(
'',
'', $default_font_size - 2);
1833 $pdf->SetFont(
'',
'', $default_font_size - 1);
1839 if ($this->page_largeur < 210) {
1843 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1849 $parameters = array(
1851 'outputlangs' => $outputlangs,
1853 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1858 foreach (
$object->lines as $line) {
1859 if ($line->product_type != 9) {
1860 $percent += $line->situation_percent;
1866 $avancementGlobal = $percent / $i;
1868 $avancementGlobal = 0;
1871 $object->fetchPreviousNextSituationInvoice();
1872 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1875 $total_a_payer_ttc = 0;
1876 foreach ($TPreviousIncoice as &$fac) {
1877 $total_a_payer += $fac->total_ht;
1878 $total_a_payer_ttc += $fac->total_ttc;
1880 $total_a_payer +=
$object->total_ht;
1881 $total_a_payer_ttc +=
$object->total_ttc;
1883 if (!empty($avancementGlobal)) {
1884 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1885 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1888 $total_a_payer_ttc = 0;
1893 if (!empty($TPreviousIncoice)) {
1894 $pdf->setY($tab2_top);
1895 $posy = $pdf->GetY();
1897 foreach ($TPreviousIncoice as &$fac) {
1898 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1903 $pdf->setY($this->tab_top_newpage);
1905 $pdf->setY($this->marge_haute);
1907 $posy = $pdf->GetY();
1912 $pdf->SetFillColor(255, 255, 255);
1913 $pdf->SetXY($col1x, $posy);
1914 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string) $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1916 $pdf->SetXY($col2x, $posy);
1920 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1923 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1925 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1934 $pdf->SetFillColor(255, 255, 255);
1935 $pdf->SetXY($col1x, $posy);
1936 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1938 $pdf->SetXY($col2x, $posy);
1941 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1949 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1950 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1955 $pdf->SetFont(
'',
'', $default_font_size - 1);
1956 $pdf->SetFillColor(255, 255, 255);
1957 $pdf->SetXY($col1x, $posy);
1958 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", (
string) $avancementGlobal), 0,
'L',
true);
1960 $pdf->SetXY($col2x, $posy);
1961 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R',
true);
1962 $pdf->SetFont(
'',
'', $default_font_size - 2);
1966 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1970 $pdf->setY($this->tab_top_newpage);
1972 $pdf->setY($this->marge_haute);
1975 $posy = $pdf->GetY();
1989 $total_discount_on_lines = 0;
1990 $multicurrency_total_discount_on_lines = 0;
1991 foreach (
$object->lines as $i => $line) {
1995 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1996 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1998 if ($line->total_ht < 0) {
1999 $total_discount_on_lines += -$line->total_ht;
2000 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
2005 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
2007 if ($this->showAmountBeforeDiscount &&
$object->type != 2) {
2008 $pdf->SetFillColor(255, 255, 255);
2009 $pdf->SetXY($col1x, $tab2_top);
2010 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
2011 $pdf->SetXY($col2x, $tab2_top);
2013 $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));
2014 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
2020 if ($this->showDiscountAmount &&
$object->type != 2) {
2021 $pdf->SetFillColor(255, 255, 255);
2022 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
2023 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
2024 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
2026 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
2027 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
2034 $pdf->SetFillColor(255, 255, 255);
2035 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2036 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total") :
''), 0,
'L',
true);
2039 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2040 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
2044 $pdf->SetFillColor(255, 255, 255);
2045 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2046 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
2048 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2049 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
2053 $pdf->SetFillColor(248, 248, 248);
2056 $total_ttc_origin =
$object->total_ttc;
2058 $this->atleastoneratenotnull = 0;
2063 if (!empty($this->tva_array) && count($this->tva_array) == 1 ) {
2064 $tva_el = reset($this->tva_array);
2065 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) $tvaisnull =
true;
2067 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
2071 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
2076 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2077 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
2079 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2080 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
2085 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2086 $pdf->SetTextColor(0, 0, 60);
2087 $pdf->SetFillColor(224, 224, 224);
2088 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
2090 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2092 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2094 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2098 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2099 $pdf->SetTextColor(0, 0, 60);
2100 $pdf->SetFillColor(224, 224, 224);
2101 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2103 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2104 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2108 if (
$object->displayRetainedWarranty()) {
2109 $pdf->SetTextColor(40, 40, 40);
2110 $pdf->SetFillColor(255, 255, 255);
2112 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
2113 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2117 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2118 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2120 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2121 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2125 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2127 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2128 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2130 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2131 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2132 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2137 $pdf->SetTextColor(0, 0, 0);
2139 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2142 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2145 $deja_regle_origin = 0;
2146 $creditnoteamount_origin = 0;
2147 $depositsamount_origin = 0;
2148 $resteapayer_origin = 0;
2150 $deja_regle_origin =
$object->getSommePaiement(0);
2151 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
2152 $depositsamount_origin =
$object->getSumDepositsUsed(0);
2153 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
2157 $resteapayer_origin = 0;
2160 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
2162 $pdf->SetFont(
'',
'', $default_font_size - 1);
2163 $pdf->SetTextColor(0, 0, 0);
2165 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2167 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2169 $this->error = $hookmanager->error;
2170 $this->errors = $hookmanager->errors;
2174 return ($tab2_top + ($tab2_hl * $index));
2284 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2287 global
$conf, $langs;
2289 $ltrdirection =
'L';
2290 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2291 $ltrdirection =
'R';
2295 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2301 $pdf->SetTextColor(0, 0, 60);
2302 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2306 $posy = $this->marge_haute;
2307 $posx = $this->page_largeur - $this->marge_droite - $w;
2309 $pdf->SetXY($this->marge_gauche, $posy);
2312 $logodir =
$conf->mycompany->dir_output;
2313 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2316 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size, $ltrdirection);
2318 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2319 $pdf->SetXY($posx, $posy);
2320 $pdf->SetTextColor(0, 0, 60);
2322 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2324 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2327 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2330 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2332 if ($this->situationinvoice) {
2333 $outputlangs->loadLangs(array(
"other"));
2334 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2335 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2337 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2340 if ($this->situationinvoice) {
2341 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2343 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2344 } elseif (
$object->type == 1) {
2345 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2346 } elseif (
$object->type == 2) {
2347 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2348 } elseif (
$object->type == 3) {
2349 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2350 } elseif (
$object->type == 4) {
2351 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2354 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2355 if (
$object->status == $object::STATUS_DRAFT) {
2356 $pdf->SetTextColor(128, 0, 0);
2357 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2360 $pdf->MultiCell($w, 3, $title,
'',
'R');
2361 $posy = $pdf->GetY();
2363 if (!empty($subtitle)) {
2364 $pdf->SetFont(
'',
'B', $default_font_size);
2365 $pdf->SetXY($posx, $posy);
2366 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2367 $posy = $pdf->GetY();
2370 $pdf->SetFont(
'',
'', $default_font_size - 2);
2387 $pdf->SetFont(
'',
'', $default_font_size - 2);
2391 $pdf->SetXY($posx, $posy);
2392 $pdf->SetTextColor(0, 0, 60);
2393 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
pdf_truncate_text($pdf, $outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2398 if (!empty(
$object->project->title)) {
2400 $pdf->SetXY($posx, $posy);
2401 $pdf->SetTextColor(0, 0, 60);
2402 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
pdf_truncate_text($pdf,
$object->project->title, 50),
'',
'R');
2403 $posy = $pdf->getY();
2409 if (!empty(
$object->project->ref)) {
2410 $outputlangs->load(
"projects");
2412 $pdf->SetXY($posx, $posy);
2413 $pdf->SetTextColor(0, 0, 60);
2414 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2418 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2419 if (
$object->type == 0 && $objectidnext) {
2420 $objectreplacing =
new Facture($this->db);
2421 $objectreplacing->fetch($objectidnext);
2424 $pdf->SetXY($posx, $posy);
2425 $pdf->SetTextColor(0, 0, 60);
2426 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2429 $objectreplaced =
new Facture($this->db);
2430 $objectreplaced->fetch(
$object->fk_facture_source);
2433 $pdf->SetXY($posx, $posy);
2434 $pdf->SetTextColor(0, 0, 60);
2435 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2438 $objectreplaced =
new Facture($this->db);
2439 $objectreplaced->fetch(
$object->fk_facture_source);
2442 $pdf->SetXY($posx, $posy);
2443 $pdf->SetTextColor(0, 0, 60);
2444 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2448 $pdf->SetXY($posx, $posy);
2449 $pdf->SetTextColor(0, 0, 60);
2451 $title = $outputlangs->transnoentities(
"DateInvoice");
2452 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2453 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2455 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2459 $pdf->SetXY($posx, $posy);
2460 $pdf->SetTextColor(0, 0, 60);
2461 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2466 $pdf->SetXY($posx, $posy);
2467 $pdf->SetTextColor(0, 0, 60);
2468 $title = $outputlangs->transnoentities(
"DateDue");
2469 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2470 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2472 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2477 $pdf->SetXY($posx, $posy);
2478 $pdf->SetTextColor(0, 0, 60);
2479 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2484 $pdf->SetXY($posx, $posy);
2485 $pdf->SetTextColor(0, 0, 60);
2486 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2491 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2492 if (count($arrayidcontact) > 0) {
2493 $usertmp =
new User($this->db);
2494 $usertmp->fetch($arrayidcontact[0]);
2496 $pdf->SetXY($posx, $posy);
2497 $pdf->SetTextColor(0, 0, 60);
2498 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2508 $current_y = $pdf->getY();
2510 if ($current_y < $pdf->getY()) {
2511 $top_shift = $pdf->getY() - $current_y;
2517 $carac_emetteur =
'';
2519 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2520 if (count($arrayidcontact) > 0) {
2521 $object->fetch_user($arrayidcontact[0]);
2522 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2523 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2524 $carac_emetteur .=
"\n";
2531 $posy = (
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32);
2532 $posy += $top_shift;
2533 $posx = $this->marge_gauche;
2535 $posx = $this->page_largeur - $this->marge_droite - 80;
2543 $pdf->SetTextColor(0, 0, 0);
2544 $pdf->SetFont(
'',
'', $default_font_size - 2);
2545 $pdf->SetXY($posx, $posy - 5);
2546 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2547 $pdf->SetXY($posx, $posy);
2548 $pdf->SetFillColor(230, 230, 230);
2549 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2550 $pdf->SetTextColor(0, 0, 60);
2555 $pdf->SetXY($posx + 2, $posy + 3);
2556 $pdf->SetFont(
'',
'B', $default_font_size);
2557 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2558 $posy = $pdf->getY();
2562 $pdf->SetXY($posx + 2, $posy);
2563 $pdf->SetFont(
'',
'', $default_font_size - 1);
2564 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2567 $usecontact =
false;
2568 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2569 if (count($arrayidcontact) > 0) {
2571 $result =
$object->fetch_contact($arrayidcontact[0]);
2575 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2576 $thirdparty =
$object->contact;
2578 $thirdparty =
$object->thirdparty;
2588 if ($this->page_largeur < 210) {
2591 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2592 $posy += $top_shift;
2593 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2595 $posx = $this->marge_gauche;
2600 $pdf->SetTextColor(0, 0, 0);
2601 $pdf->SetFont(
'',
'', $default_font_size - 2);
2602 $pdf->SetXY($posx + 2, $posy - 5);
2603 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2604 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2608 $pdf->SetXY($posx + 2, $posy + 3);
2609 $pdf->SetFont(
'',
'B', $default_font_size);
2611 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2613 $posy = $pdf->getY();
2616 $pdf->SetFont(
'',
'', $default_font_size - 1);
2617 $pdf->SetXY($posx + 2, $posy);
2619 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2623 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2625 if (!empty($idaddressshipping)) {
2626 $object->fetch_contact($idaddressshipping[0]);
2627 $companystatic =
new Societe($this->db);
2628 $companystatic->fetch(
$object->contact->fk_soc);
2635 $carac_client_name_shipping =
'';
2636 $carac_client_shipping =
'';
2638 if (!empty($carac_client_shipping)) {
2639 $posy += $hautcadre;
2644 $pdf->SetXY($posx + 2, $posy - 5);
2645 $pdf->SetFont(
'',
'', $default_font_size - 2);
2646 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2647 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2650 $pdf->SetXY($posx + 2, $posy + 3);
2651 $pdf->SetFont(
'',
'B', $default_font_size);
2652 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2654 $posy = $pdf->getY();
2657 $pdf->SetXY($posx + 2, $posy);
2658 $pdf->SetFont(
'',
'', $default_font_size - 1);
2659 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2661 $shipp_shift += $hautcadre + 10;
2666 $pdf->SetTextColor(0, 0, 0);
2668 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);