203 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
206 global $user, $langs, $conf,
$mysoc, $hookmanager, $nblines;
208 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
210 if (!is_object($outputlangs)) {
211 $outputlangs = $langs;
215 $outputlangs->charset_output =
'ISO-8859-1';
219 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
221 global $outputlangsbis;
222 $outputlangsbis =
null;
224 $outputlangsbis =
new Translate(
'', $conf);
226 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
234 $nblines = count(
$object->lines);
242 $realpatharray = array();
243 $this->atleastonephoto =
false;
245 $objphoto =
new Product($this->db);
247 for ($i = 0; $i < $nblines; $i++) {
248 if (empty(
$object->lines[$i]->fk_product)) {
252 $objphoto->fetch(
$object->lines[$i]->fk_product);
256 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
257 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
259 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
260 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
265 foreach ($pdir as $midir) {
267 $entity = $objphoto->entity;
268 if ($entity !==
null && $conf->entity != $entity) {
269 $dir = $conf->product->multidir_output[$entity].
'/'.$midir;
271 $dir = $conf->product->dir_output.
'/'.$midir;
274 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
276 if ($obj[
'photo_vignette']) {
277 $filename = $obj[
'photo_vignette'];
279 $filename = $obj[
'photo'];
282 $filename = $obj[
'photo'];
285 $realpath = $dir.$filename;
287 $this->atleastonephoto =
true;
292 if (!empty($realpath) && $arephoto) {
293 $realpatharray[$i] = $realpath;
300 if ($conf->facture->multidir_output[$conf->entity]) {
304 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
305 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
309 $dir = $conf->facture->multidir_output[$conf->entity];
310 $file = $dir.
"/SPECIMEN.pdf";
313 $dir = $conf->facture->multidir_output[
$object->entity ?? $conf->entity].
"/".$objectref;
314 $file = $dir.
"/".$objectref.
".pdf";
316 if (!file_exists($dir)) {
318 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
323 if (file_exists($dir)) {
325 if (!is_object($hookmanager)) {
326 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
329 $hookmanager->initHooks(array(
'pdfgeneration'));
330 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
332 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
335 $nblines = count(
$object->lines);
336 $nbpayments = count(
$object->getListOfPayments());
341 $pdf->setAutoPageBreak(
true, 0);
344 $this->heightforinfotot = 50;
346 $this->heightforinfotot += (4 * $nbpayments);
348 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
349 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
351 $heightforqrinvoice = 0;
355 $this->heightforinfotot = 30 + (4 * $nbpayments);
359 if (class_exists(
'TCPDF')) {
360 $pdf->setPrintHeader(
false);
361 $pdf->setPrintFooter(
false);
367 $logodir = $conf->mycompany->dir_output;
368 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
369 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
371 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
372 $tplidx = $pdf->importPage(1);
377 $pdf->SetDrawColor(128, 128, 128);
379 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
380 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
381 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
382 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
383 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
385 $pdf->SetCompression(
false);
389 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
390 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
401 'Name' => $this->emetteur->name,
402 'Location' =>
getCountry($this->emetteur->country_code,
''),
403 'Reason' =>
'INVOICE',
404 'ContactInfo' => $this->emetteur->email
406 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
410 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
414 $categoryOfOperation = 0;
417 for ($i = 0; $i < $nblines; $i++) {
418 if (
$object->lines[$i]->remise_percent) {
419 $this->atleastonediscount++;
424 if (preg_match(
'/^\((.*)\)$/',
$object->lines[$i]->desc, $reg)) {
425 if ($reg[1] ==
'DEPOSIT') {
436 if ($categoryOfOperation < 2) {
437 $lineProductType =
$object->lines[$i]->product_type;
443 if ($nbProduct > 0 && $nbService > 0) {
445 $categoryOfOperation = 2;
450 if ($categoryOfOperation <= 0) {
452 if ($nbProduct == 0 && $nbService > 0) {
453 $categoryOfOperation = 1;
456 $this->categoryOfOperation = $categoryOfOperation;
459 if (
$object->situation_cycle_ref) {
460 $this->situationinvoice =
true;
465 if (!empty($tplidx)) {
466 $pdf->useTemplate($tplidx);
471 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
472 $top_shift = $pagehead[
'top_shift'];
473 $shipp_shift = $pagehead[
'shipp_shift'];
474 $pdf->SetFont(
'',
'', $default_font_size - 1);
475 $pdf->MultiCell(0, 3,
'');
476 $pdf->SetTextColor(0, 0, 0);
481 $this->tab_top = 90 + $top_shift + $shipp_shift;
482 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
485 $extra_under_address_shift = 0;
488 $qrcodestring =
$object->buildZATCAQRString();
491 $qrcodestring =
$object->buildSwitzerlandQRString();
495 $qrcodestring =
$object->buildEPCQrCodeString();
500 $qrcodecolor = array(
'25',
'25',
'25');
505 'fgcolor' => $qrcodecolor,
510 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
514 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
515 $pdf->SetFont(
'',
'', $default_font_size - 4);
516 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
520 $extra_under_address_shift += 25;
528 'outputlangs' => $outputlangs,
529 'hidedetails' => $hidedetails
531 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
532 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
533 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
536 $this->tab_top += $extra_under_address_shift;
537 $this->tab_top_newpage += 0;
541 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
543 $nexY = $this->tab_top - 1;
546 $height_incoterms = 0;
548 $desc_incoterms =
$object->getIncotermsForPDF();
549 if ($desc_incoterms) {
552 $pdf->SetFont(
'',
'', $default_font_size - 1);
553 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
554 $nexY = max($pdf->GetY(), $nexY);
555 $height_incoterms = $nexY - $this->tab_top;
558 $pdf->SetDrawColor(192, 192, 192);
559 $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');
561 $this->tab_top = $nexY + 6;
562 $height_incoterms += 4;
567 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
570 if (is_object(
$object->thirdparty)) {
571 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
572 $salerepobj =
new User($this->db);
573 $salerepobj->fetch($salereparray[0][
'id']);
574 if (!empty($salerepobj->signature)) {
575 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
581 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
582 if (!empty($extranote)) {
586 $pagenb = $pdf->getPage();
590 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
591 $pageposbeforenote = $pagenb;
598 $pdf->startTransaction();
600 $pdf->SetFont(
'',
'', $default_font_size - 1);
601 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
603 $pageposafternote = $pdf->getPage();
604 $posyafter = $pdf->GetY();
606 if ($pageposafternote > $pageposbeforenote) {
607 $pdf->rollbackTransaction(
true);
610 while ($pagenb < $pageposafternote) {
613 if (!empty($tplidx)) {
614 $pdf->useTemplate($tplidx);
619 $pdf->setTopMargin($this->tab_top_newpage);
621 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
625 $pdf->setPage($pageposbeforenote);
626 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
627 $pdf->SetFont(
'',
'', $default_font_size - 1);
628 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
629 $pageposafternote = $pdf->getPage();
631 $posyafter = $pdf->GetY();
633 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
634 $pdf->AddPage(
'',
'',
true);
637 $pdf->setPage($pageposafternote);
638 $pdf->setTopMargin($this->tab_top_newpage);
640 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
646 $i = $pageposbeforenote;
647 while ($i < $pageposafternote) {
651 $pdf->SetDrawColor(128, 128, 128);
653 if ($i > $pageposbeforenote) {
654 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
655 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
657 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
658 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
662 $pdf->setPageOrientation(
'',
true, 0);
669 $pdf->setPage($pageposafternote);
670 if (!empty($tplidx)) {
671 $pdf->useTemplate($tplidx);
676 $height_note = $posyafter - $this->tab_top_newpage;
677 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
680 $pdf->commitTransaction();
681 $posyafter = $pdf->GetY();
682 $height_note = $posyafter - $this->tab_top;
683 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
686 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
688 $pdf->AddPage(
'',
'',
true);
691 $pdf->setPage($pageposafternote);
692 if (!empty($tplidx)) {
693 $pdf->useTemplate($tplidx);
699 $posyafter = $this->tab_top_newpage;
703 $tab_height -= $height_note;
704 $this->tab_top = $posyafter + 6;
713 $pdf->startTransaction();
714 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
715 $pdf->rollbackTransaction(
true);
717 $nexY = $this->tab_top + $this->tabTitleHeight;
720 $pageposbeforeprintlines = $pdf->getPage();
721 $pagenb = $pageposbeforeprintlines;
723 $pdf_sub_options = array();
724 $pdf_sub_options[
'titleshowuponpdf'] = 1;
725 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
727 for ($i = 0; $i < $nblines; $i++) {
728 $linePosition = $i + 1;
731 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
733 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
734 $level =
$object->lines[$i]->qty;
736 if (isset($sub_options[
'titleshowuponpdf'])) {
737 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
738 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
739 unset($pdf_sub_options[
'titleshowuponpdf']);
741 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
742 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
743 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
744 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
747 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
748 unset($pdf_sub_options[
'titleshowuponpdf']);
750 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
751 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
756 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
757 $object->lines[$i]->pagebreak =
true;
761 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
764 if (!empty($tplidx)) {
765 $pdf->useTemplate($tplidx);
768 $pdf->setPage($pdf->getNumPages());
769 $nexY = $curY = $this->tab_top_newpage;
774 $pdf->SetFont(
'',
'', $default_font_size - 1);
775 $pdf->SetTextColor(0, 0, 0);
778 $imglinesize = array();
779 if (!empty($realpatharray[$i])) {
783 $pdf->setTopMargin($this->tab_top_newpage);
784 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
785 $pageposbefore = $pdf->getPage();
789 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
794 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
795 $pdf->AddPage(
'',
'',
true);
796 if (!empty($tplidx)) {
797 $pdf->useTemplate($tplidx);
799 $pdf->setPage($pageposbefore + 1);
800 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
801 $curY = $this->tab_top_newpage;
802 $showpricebeforepagebreak = 0;
805 $pdf->setPageOrientation(
'',
false, $this->heightforfooter + $this->heightforfreetext);
807 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
808 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
810 $posYAfterImage = $curY + $imglinesize[
'height'];
817 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
821 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
826 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
832 $pdf->setPage($pageposbefore);
833 $pdf->setTopMargin($this->marge_haute);
835 $pdf->setPageOrientation(
'',
false, $this->heightforfooter);
838 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
839 $pdf->setPage($afterPosData[
'page']);
840 $curY = $this->tab_top_newpage;
843 $pdf->SetFont(
'',
'', $default_font_size - 1);
857 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
882 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
889 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
892 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
894 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
896 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
909 if (!empty(
$object->lines[$i]->array_options)) {
910 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
926 'nexY' => & $afterPosData[
'y'],
927 'outputlangs' => $outputlangs,
928 'hidedetails' => $hidedetails
930 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
938 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
940 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent) &&
getDolGlobalInt(
'INVOICE_USE_SITUATION') != 2) {
942 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
944 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
948 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
950 $tvaligne = $sign *
$object->lines[$i]->total_tva;
954 $localtax1ligne =
$object->lines[$i]->total_localtax1;
955 $localtax2ligne =
$object->lines[$i]->total_localtax2;
956 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
957 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
958 $localtax1_type =
$object->lines[$i]->localtax1_type;
959 $localtax2_type =
$object->lines[$i]->localtax2_type;
961 $vatrate = (string)
$object->lines[$i]->tva_tx;
964 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
965 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
967 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
968 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
972 if ($localtax1_type && $localtax1ligne != 0) {
973 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
974 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
976 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
979 if ($localtax2_type && $localtax2ligne != 0) {
980 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
981 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
983 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
987 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
992 if (!isset($this->tva[$vatrate])) {
993 $this->tva[$vatrate] = 0;
995 $this->tva[$vatrate] += $tvaligne;
996 $vatcode =
$object->lines[$i]->vat_src_code;
997 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
998 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
1001 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
1002 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
1004 $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);
1006 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1010 $pdf->setPage($afterPosData[
'page']);
1011 $nexY = $afterPosData[
'y'];
1014 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1015 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1017 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1018 $pdf->SetLineStyle(array(
'dash' => 0));
1026 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
1028 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
1030 if (!empty($tplidx)) {
1031 $pdf->useTemplate($tplidx);
1034 $pdf->setPage($pagenb);
1038 $drawTabNumbPage = $pdf->getNumPages();
1039 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1042 $pdf->setPageOrientation(
'',
false, 0);
1044 $drawTabHideTop = $hidetop;
1045 $drawTabTop = $this->tab_top_newpage;
1046 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1049 if ($i == $pageposbeforeprintlines) {
1051 $drawTabTop = $this->tab_top;
1052 } elseif (!$drawTabHideTop) {
1054 $drawTabTop -= $this->tabTitleHeight;
1056 $drawTabHideTop = 1;
1061 if ($i == $pdf->getNumPages()) {
1063 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1066 $drawTabHeight = $drawTabBottom - $drawTabTop;
1067 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object, $outputlangsbis);
1069 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1076 $pdf->setPageOrientation(
'',
true, 0);
1079 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1082 if (!empty($tplidx)) {
1083 $pdf->useTemplate($tplidx);
1089 $pdf->SetTextColor(0, 0, 0);
1091 $pdf->setPage($pdf->getNumPages());
1093 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1099 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1102 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1103 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1108 if (method_exists($pdf,
'AliasNbPages')) {
1109 $pdf->AliasNbPages();
1114 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1115 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
1116 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
1117 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
1120 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1121 $pagecount = $pdf->setSourceFile($termsofsale);
1122 for ($i = 1; $i <= $pagecount; $i++) {
1123 $tplIdx = $pdf->importPage($i);
1124 if ($tplIdx !==
false) {
1125 $s = $pdf->getTemplatesize($tplIdx);
1126 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1127 $pdf->useTemplate($tplIdx);
1129 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1141 $pdf->Output($file,
'F');
1144 $hookmanager->initHooks(array(
'pdfgeneration'));
1145 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1147 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1148 $this->warnings = $hookmanager->warnings;
1150 $this->error = $hookmanager->error;
1151 $this->errors = $hookmanager->errors;
1158 $this->result = array(
'fullpath' => $file);
1162 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1166 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1189 $tab3_top = $posy + 8;
1192 if ($this->page_largeur < 210) {
1198 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1200 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1203 $pdf->SetFont(
'',
'', $default_font_size - 3);
1204 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1205 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1207 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1209 $pdf->SetFont(
'',
'', $default_font_size - 4);
1210 $pdf->SetXY($tab3_posx, $tab3_top);
1211 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1212 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1213 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1214 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1215 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1216 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1217 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1219 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1223 $pdf->SetFont(
'',
'', $default_font_size - 4);
1227 $sql =
"SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
1228 $sql .=
" re.description, re.fk_facture_source,";
1229 $sql .=
" f.type, f.datef";
1230 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1231 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1232 $resql = $this->db->query($sql);
1234 $num = $this->db->num_rows($resql);
1236 $invoice =
new Facture($this->db);
1239 $obj = $this->db->fetch_object($resql);
1241 if ($obj->type == 2) {
1242 $text = $outputlangs->transnoentities(
"CreditNote");
1243 } elseif ($obj->type == 3) {
1244 $text = $outputlangs->transnoentities(
"Deposit");
1245 } elseif ($obj->type == 0) {
1246 $text = $outputlangs->transnoentities(
"ExcessReceived");
1248 $text = $outputlangs->transnoentities(
"UnknownType");
1251 $invoice->fetch($obj->fk_facture_source);
1253 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1254 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1255 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1256 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1257 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1258 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1259 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1260 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1262 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1267 $this->error = $this->db->lasterror();
1273 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1276 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1277 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1279 $sql .=
" ORDER BY p.datep";
1281 $resql = $this->db->query($sql);
1283 $num = $this->db->num_rows($resql);
1288 $row = $this->db->fetch_object($resql);
1289 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1290 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1291 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1292 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1293 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1294 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1296 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1297 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1298 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1299 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1300 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1301 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1306 return $tab3_top + $y + 3;
1308 $this->error = $this->db->lasterror();
1330 $pdf->SetFont(
'',
'', $default_font_size - 1);
1332 krsort($this->tva_array);
1339 $pdf->SetFillColor(224, 224, 224);
1341 $pdf->SetFont(
'',
'', $default_font_size - 2);
1342 $pdf->SetXY($this->marge_gauche, $posy);
1343 $titre = $outputlangs->transnoentities(
"VAT");
1344 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1346 $pdf->SetFont(
'',
'', $default_font_size - 2);
1347 $pdf->SetXY($this->marge_gauche + 25, $posy);
1348 $titre = $outputlangs->transnoentities(
"NetTotal");
1349 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1351 $pdf->SetFont(
'',
'', $default_font_size - 2);
1352 $pdf->SetXY($this->marge_gauche + 50, $posy);
1353 $titre = $outputlangs->transnoentities(
"VATAmount");
1354 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1356 $pdf->SetFont(
'',
'', $default_font_size - 2);
1357 $pdf->SetXY($this->marge_gauche + 75, $posy);
1358 $titre = $outputlangs->transnoentities(
"AmountTotal");
1359 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1361 $posy = $pdf->GetY();
1366 foreach ($this->tva_array as $tvakey => $tvaval) {
1367 $pdf->SetFont(
'',
'', $default_font_size - 2);
1368 $pdf->SetXY($this->marge_gauche, $posy);
1369 $titre = round((
float) $tvakey, 2) .
"%";
1370 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1372 $pdf->SetFont(
'',
'', $default_font_size - 2);
1373 $pdf->SetXY($this->marge_gauche + 25, $posy);
1374 $titre =
price($tvaval[
'tot_ht']);
1375 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1376 $tot_ht += $tvaval[
'tot_ht'];
1378 $pdf->SetFont(
'',
'', $default_font_size - 2);
1379 $pdf->SetXY($this->marge_gauche + 50, $posy);
1380 $titre =
price($tvaval[
'amount']);
1381 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1382 $tot_tva += $tvaval[
'amount'];
1384 $pdf->SetFont(
'',
'', $default_font_size - 2);
1385 $pdf->SetXY($this->marge_gauche + 75, $posy);
1386 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1387 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1388 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1390 $posy = $pdf->GetY();
1395 $showvatmention = 0;
1396 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1397 $pdf->SetFont(
'',
'', $default_font_size - 2);
1398 $pdf->SetXY($this->marge_gauche, $posy);
1399 if (empty(
$mysoc->tva_assuj)) {
1400 if (
$mysoc->forme_juridique_code == 92) {
1401 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1403 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1406 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1407 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1410 $posy = $pdf->GetY();
1413 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1415 if ($showvatmention) {
1421 if ($this->page_largeur < 210) {
1428 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1429 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1430 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1431 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1432 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1433 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1434 $sql .=
" AND f.fk_statut > 0";
1435 $sql .=
" ORDER BY f.datef ASC";
1438 $invoices = array();
1439 $resql = $this->db->query($sql);
1441 while ($obj = $this->db->fetch_object($resql)) {
1443 $old_balance += $obj->total_ttc;
1445 $this->db->free($resql);
1449 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1450 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1451 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1452 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1453 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1454 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1455 $sql_payments .=
" ORDER BY p.datep ASC";
1457 $total_payments = 0;
1458 $resql_payments = $this->db->query($sql_payments);
1459 if ($resql_payments) {
1460 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1461 $total_payments += $obj_payment->amount;
1463 $this->db->free($resql_payments);
1467 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1468 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1469 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1470 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1471 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1472 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1474 $current_date_payments = 0;
1475 $resql_current_date = $this->db->query($sql_current_date_payments);
1476 if ($resql_current_date) {
1477 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1478 $current_date_payments += $obj_current->amount;
1480 $this->db->free($resql_current_date);
1484 $old_balance -= $total_payments;
1487 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1489 $pdf->SetFillColor(224, 224, 224);
1490 $pdf->SetFont(
'',
'', $default_font_size - 2);
1491 $pdf->SetXY($this->marge_gauche, $posy);
1492 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1493 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1495 $pdf->SetFont(
'',
'', $default_font_size - 2);
1496 $pdf->SetXY($posxval + 8, $posy);
1497 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1498 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1500 $posy = $pdf->GetY() + 1;
1505 $pdf->SetFont(
'',
'', $default_font_size - 2);
1506 $pdf->SetXY($this->marge_gauche, $posy);
1507 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1508 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1510 $pdf->SetFont(
'',
'', $default_font_size - 2);
1511 $pdf->SetXY($posxval, $posy);
1512 $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);
1513 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1514 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1516 $posy = $pdf->GetY() + 3;
1520 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1521 $pdf->SetFont(
'',
'', $default_font_size - 2);
1522 $pdf->SetXY($this->marge_gauche, $posy);
1523 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1524 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1526 $pdf->SetFont(
'',
'', $default_font_size - 2);
1527 $pdf->SetXY($posxval, $posy);
1528 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1529 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1531 $posy = $pdf->GetY() + 3;
1536 if (empty(
$object->mode_reglement_code)
1539 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1543 $outputlangs->load(
"errors");
1545 $pdf->SetXY($this->marge_gauche, $posy);
1546 $pdf->SetTextColor(200, 0, 0);
1547 $pdf->SetFont(
'',
'', $default_font_size - 2);
1548 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1549 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1550 $pdf->SetTextColor(0, 0, 0);
1552 $posy = $pdf->GetY() + 1;
1556 if (!empty(
$object->mode_reglement_code)
1557 &&
$object->mode_reglement_code !=
'CHQ'
1558 &&
$object->mode_reglement_code !=
'VIR') {
1559 $pdf->SetFont(
'',
'', $default_font_size - 2);
1560 $pdf->SetXY($this->marge_gauche, $posy);
1561 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1562 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1564 $pdf->SetFont(
'',
'', $default_font_size - 2);
1565 $pdf->SetXY($posxval, $posy);
1566 $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);
1569 if (
$object->mode_reglement_code ==
"PRE") {
1570 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1573 $bac->fetch(0,
'',
$object->thirdparty->id);
1574 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1575 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1578 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1580 $posy = $pdf->GetY();
1586 if ($this->emetteur->country_code ==
'FR') {
1588 $pdf->SetXY($this->marge_gauche, $posy);
1589 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1591 $posy = $pdf->GetY() + 1;
1596 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1597 $useonlinepayment = 0;
1601 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1602 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1603 $useonlinepayment = count($validpaymentmethod);
1608 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1611 $langs->loadLangs(array(
'payment',
'stripe'));
1612 $servicename = $langs->transnoentities(
'Online');
1613 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1614 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1616 $pdf->SetXY($this->marge_gauche, $posy);
1617 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1619 $posy = $pdf->GetY() + 1;
1624 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1630 $account =
new Account($this->db);
1633 $pdf->SetXY($this->marge_gauche, $posy);
1634 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1635 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1636 $posy = $pdf->GetY() + 1;
1639 $pdf->SetXY($this->marge_gauche, $posy);
1640 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1641 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1642 $posy = $pdf->GetY() + 2;
1646 $pdf->SetXY($this->marge_gauche, $posy);
1647 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1648 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1649 $posy = $pdf->GetY() + 1;
1652 $pdf->SetXY($this->marge_gauche, $posy);
1653 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1654 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1655 $posy = $pdf->GetY() + 2;
1662 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1668 $account =
new Account($this->db);
1669 $account->fetch($bankid);
1671 $curx = $this->marge_gauche;
1674 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1680 $qrPosX = $this->marge_gauche + 5;
1682 $qrCodeColor = array(
'25',
'25',
'25');
1686 'fgcolor' => $qrCodeColor,
1688 'module_width' => 1,
1689 'module_height' => 1
1692 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1693 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1695 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1696 $pdf->SetFont(
'',
'', $default_font_size - 5);
1697 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1698 $posy = $pdf->GetY() + 2;
1703 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1706 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1729 global
$mysoc, $hookmanager;
1740 if (is_object($outputlangsbis)) {
1741 $pdf->SetFont(
'',
'', $default_font_size - 2);
1743 $pdf->SetFont(
'',
'', $default_font_size - 1);
1749 if ($this->page_largeur < 210) {
1753 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1759 $parameters = array(
1761 'outputlangs' => $outputlangs,
1763 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1768 foreach (
$object->lines as $line) {
1769 if ($line->product_type != 9) {
1770 $percent += $line->situation_percent;
1776 $avancementGlobal = $percent / $i;
1778 $avancementGlobal = 0;
1781 $object->fetchPreviousNextSituationInvoice();
1782 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1785 $total_a_payer_ttc = 0;
1786 foreach ($TPreviousIncoice as &$fac) {
1787 $total_a_payer += $fac->total_ht;
1788 $total_a_payer_ttc += $fac->total_ttc;
1790 $total_a_payer +=
$object->total_ht;
1791 $total_a_payer_ttc +=
$object->total_ttc;
1793 if (!empty($avancementGlobal)) {
1794 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1795 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1798 $total_a_payer_ttc = 0;
1802 if (!empty($TPreviousIncoice)) {
1803 $pdf->setY($tab2_top);
1804 $posy = $pdf->GetY();
1806 foreach ($TPreviousIncoice as &$fac) {
1807 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1812 $pdf->setY($this->tab_top_newpage);
1814 $pdf->setY($this->marge_haute);
1816 $posy = $pdf->GetY();
1821 $pdf->SetFillColor(255, 255, 255);
1822 $pdf->SetXY($col1x, $posy);
1823 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string) $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1825 $pdf->SetXY($col2x, $posy);
1829 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1832 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1834 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1843 $pdf->SetFillColor(255, 255, 255);
1844 $pdf->SetXY($col1x, $posy);
1845 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1847 $pdf->SetXY($col2x, $posy);
1850 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1858 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1859 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1864 $pdf->SetFont(
'',
'', $default_font_size - 1);
1865 $pdf->SetFillColor(255, 255, 255);
1866 $pdf->SetXY($col1x, $posy);
1867 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", (
string) $avancementGlobal), 0,
'L',
true);
1869 $pdf->SetXY($col2x, $posy);
1870 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R',
true);
1871 $pdf->SetFont(
'',
'', $default_font_size - 2);
1875 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1879 $pdf->setY($this->tab_top_newpage);
1881 $pdf->setY($this->marge_haute);
1884 $posy = $pdf->GetY();
1898 $total_discount_on_lines = 0;
1899 $multicurrency_total_discount_on_lines = 0;
1900 foreach (
$object->lines as $i => $line) {
1904 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1905 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1907 if ($line->total_ht < 0) {
1908 $total_discount_on_lines += -$line->total_ht;
1909 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1914 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
1917 $pdf->SetFillColor(255, 255, 255);
1918 $pdf->SetXY($col1x, $tab2_top);
1919 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1920 $pdf->SetXY($col2x, $tab2_top);
1922 $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));
1923 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1930 $pdf->SetFillColor(255, 255, 255);
1931 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1932 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1933 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1935 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1936 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1943 $pdf->SetFillColor(255, 255, 255);
1944 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1945 $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);
1948 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1949 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1953 $pdf->SetFillColor(255, 255, 255);
1954 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1955 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1957 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1958 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1962 $pdf->SetFillColor(248, 248, 248);
1965 $total_ttc_origin =
$object->total_ttc;
1967 $this->atleastoneratenotnull = 0;
1969 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1970 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1974 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1975 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1979 foreach ($localtax_rate as $tvakey => $tvaval) {
1980 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1984 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1987 if (preg_match(
'/\*/', (
string) $tvakey)) {
1988 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1989 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1992 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1996 $totalvat .= $tvacompl;
1998 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2001 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2005 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2006 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2012 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
2013 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
2017 foreach ($localtax_rate as $tvakey => $tvaval) {
2018 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
2022 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2025 if (preg_match(
'/\*/', (
string) $tvakey)) {
2026 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2027 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2029 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
2033 $totalvat .= $tvacompl;
2035 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2038 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2042 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2043 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2051 foreach ($this->tva as $tvakey => $tvaval) {
2052 $sum_pdf_tva += $tvaval;
2055 if ($sum_pdf_tva !=
$object->total_tva) {
2056 if (!empty($sum_pdf_tva)) {
2057 $coef_fix_tva =
$object->total_tva / $sum_pdf_tva;
2063 foreach ($this->tva as $tvakey => $tvaval) {
2064 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
2066 foreach ($this->tva_array as $tvakey => $tvaval) {
2067 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
2074 foreach ($this->tva_array as $tvakey => $tvaval) {
2076 $this->atleastoneratenotnull++;
2079 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2082 if (preg_match(
'/\*/', $tvakey)) {
2083 $tvakey = str_replace(
'*',
'', $tvakey);
2084 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2086 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
2089 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
2091 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
2093 $totalvat .= $tvacompl;
2095 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
2097 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2099 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2101 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
2107 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
2108 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2112 foreach ($localtax_rate as $tvakey => $tvaval) {
2113 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
2117 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2120 if (preg_match(
'/\*/', (
string) $tvakey)) {
2121 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2122 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2124 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
2128 $totalvat .= $tvacompl;
2130 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2133 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2137 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2138 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2144 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
2145 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2149 foreach ($localtax_rate as $tvakey => $tvaval) {
2151 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
2155 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2158 if (preg_match(
'/\*/', (
string) $tvakey)) {
2159 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2160 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2162 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
2166 $totalvat .= $tvacompl;
2168 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2171 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2175 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2176 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2184 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2185 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
2187 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2188 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
2193 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2194 $pdf->SetTextColor(0, 0, 60);
2195 $pdf->SetFillColor(224, 224, 224);
2196 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
2198 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2200 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2202 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2206 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2207 $pdf->SetTextColor(0, 0, 60);
2208 $pdf->SetFillColor(224, 224, 224);
2209 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2211 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2212 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2216 if (
$object->displayRetainedWarranty()) {
2217 $pdf->SetTextColor(40, 40, 40);
2218 $pdf->SetFillColor(255, 255, 255);
2220 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2221 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2225 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2226 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2228 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2229 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2233 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2235 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2236 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2238 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2239 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2240 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2245 $pdf->SetTextColor(0, 0, 0);
2247 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2250 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2253 $deja_regle_origin = 0;
2254 $creditnoteamount_origin = 0;
2255 $depositsamount_origin = 0;
2256 $resteapayer_origin = 0;
2258 $deja_regle_origin =
$object->getSommePaiement(0);
2259 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
2260 $depositsamount_origin =
$object->getSumDepositsUsed(0);
2261 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
2265 $resteapayer_origin = 0;
2268 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
2271 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2272 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L',
false);
2273 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2275 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R',
false);
2288 if ($creditnoteamount) {
2289 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
2290 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.(($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes"))) :
'');
2292 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2293 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L',
false);
2294 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2295 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R',
false);
2298 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2300 $pdf->SetFillColor(255, 255, 255);
2302 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2303 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"EscompteOfferedShort") :
''), $useborder,
'L',
true);
2304 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2305 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT'), 0, $outputlangs), $useborder,
'R',
true);
2308 $resteapayer_origin = 0;
2312 $pdf->SetTextColor(0, 0, 60);
2313 $pdf->SetFillColor(224, 224, 224);
2314 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2315 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
2316 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2318 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2320 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2324 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2325 $pdf->SetTextColor(0, 0, 60);
2326 $pdf->SetFillColor(224, 224, 224);
2327 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2329 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2330 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2333 $pdf->SetFont(
'',
'', $default_font_size - 1);
2334 $pdf->SetTextColor(0, 0, 0);
2337 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2339 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2341 $this->error = $hookmanager->error;
2342 $this->errors = $hookmanager->errors;
2346 return ($tab2_top + ($tab2_hl * $index));
2456 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2459 global $conf, $langs;
2461 $ltrdirection =
'L';
2462 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2463 $ltrdirection =
'R';
2467 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2473 $pdf->SetTextColor(0, 0, 60);
2474 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2478 $posy = $this->marge_haute;
2479 $posx = $this->page_largeur - $this->marge_droite - $w;
2481 $pdf->SetXY($this->marge_gauche, $posy);
2485 if ($this->emetteur->logo) {
2486 $logodir = $conf->mycompany->dir_output;
2487 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
2488 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
2491 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2493 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2495 if (is_readable($logo)) {
2497 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2499 $pdf->SetTextColor(200, 0, 0);
2500 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2501 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2502 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2505 $text = $this->emetteur->name;
2506 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2510 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2511 $pdf->SetXY($posx, $posy);
2512 $pdf->SetTextColor(0, 0, 60);
2514 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2516 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2519 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2522 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2525 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2527 if ($this->situationinvoice) {
2528 $outputlangs->loadLangs(array(
"other"));
2529 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2530 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2532 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2535 if ($this->situationinvoice) {
2536 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2538 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2539 } elseif (
$object->type == 1) {
2540 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2541 } elseif (
$object->type == 2) {
2542 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2543 } elseif (
$object->type == 3) {
2544 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2545 } elseif (
$object->type == 4) {
2546 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2549 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2550 if (
$object->status == $object::STATUS_DRAFT) {
2551 $pdf->SetTextColor(128, 0, 0);
2552 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2555 $pdf->MultiCell($w, 3, $title,
'',
'R');
2556 if (!empty($subtitle)) {
2557 $pdf->SetFont(
'',
'B', $default_font_size);
2558 $pdf->SetXY($posx, $posy + 5);
2559 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2563 $pdf->SetFont(
'',
'', $default_font_size - 2);
2580 $pdf->SetFont(
'',
'', $default_font_size - 2);
2584 $pdf->SetXY($posx, $posy);
2585 $pdf->SetTextColor(0, 0, 60);
2586 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2591 if (!empty(
$object->project->ref)) {
2593 $pdf->SetXY($posx, $posy);
2594 $pdf->SetTextColor(0, 0, 60);
2595 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2601 if (!empty(
$object->project->ref)) {
2602 $outputlangs->load(
"projects");
2604 $pdf->SetXY($posx, $posy);
2605 $pdf->SetTextColor(0, 0, 60);
2606 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2610 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2611 if (
$object->type == 0 && $objectidnext) {
2612 $objectreplacing =
new Facture($this->db);
2613 $objectreplacing->fetch($objectidnext);
2616 $pdf->SetXY($posx, $posy);
2617 $pdf->SetTextColor(0, 0, 60);
2618 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2621 $objectreplaced =
new Facture($this->db);
2622 $objectreplaced->fetch(
$object->fk_facture_source);
2625 $pdf->SetXY($posx, $posy);
2626 $pdf->SetTextColor(0, 0, 60);
2627 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2630 $objectreplaced =
new Facture($this->db);
2631 $objectreplaced->fetch(
$object->fk_facture_source);
2634 $pdf->SetXY($posx, $posy);
2635 $pdf->SetTextColor(0, 0, 60);
2636 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2640 $pdf->SetXY($posx, $posy);
2641 $pdf->SetTextColor(0, 0, 60);
2643 $title = $outputlangs->transnoentities(
"DateInvoice");
2644 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2645 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2647 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2651 $pdf->SetXY($posx, $posy);
2652 $pdf->SetTextColor(0, 0, 60);
2653 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2658 $pdf->SetXY($posx, $posy);
2659 $pdf->SetTextColor(0, 0, 60);
2660 $title = $outputlangs->transnoentities(
"DateDue");
2661 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2662 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2664 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2669 $pdf->SetXY($posx, $posy);
2670 $pdf->SetTextColor(0, 0, 60);
2671 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2676 $pdf->SetXY($posx, $posy);
2677 $pdf->SetTextColor(0, 0, 60);
2678 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2683 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2684 if (count($arrayidcontact) > 0) {
2685 $usertmp =
new User($this->db);
2686 $usertmp->fetch($arrayidcontact[0]);
2688 $pdf->SetXY($posx, $posy);
2689 $pdf->SetTextColor(0, 0, 60);
2690 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2700 $current_y = $pdf->getY();
2702 if ($current_y < $pdf->getY()) {
2703 $top_shift = $pdf->getY() - $current_y;
2709 $carac_emetteur =
'';
2711 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2712 if (count($arrayidcontact) > 0) {
2713 $object->fetch_user($arrayidcontact[0]);
2714 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2715 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2716 $carac_emetteur .=
"\n";
2723 $posy += $top_shift;
2724 $posx = $this->marge_gauche;
2726 $posx = $this->page_largeur - $this->marge_droite - 80;
2734 $pdf->SetTextColor(0, 0, 0);
2735 $pdf->SetFont(
'',
'', $default_font_size - 2);
2736 $pdf->SetXY($posx, $posy - 5);
2737 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2738 $pdf->SetXY($posx, $posy);
2739 $pdf->SetFillColor(230, 230, 230);
2740 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2741 $pdf->SetTextColor(0, 0, 60);
2746 $pdf->SetXY($posx + 2, $posy + 3);
2747 $pdf->SetFont(
'',
'B', $default_font_size);
2748 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2749 $posy = $pdf->getY();
2753 $pdf->SetXY($posx + 2, $posy);
2754 $pdf->SetFont(
'',
'', $default_font_size - 1);
2755 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2758 $usecontact =
false;
2759 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2760 if (count($arrayidcontact) > 0) {
2762 $result =
$object->fetch_contact($arrayidcontact[0]);
2766 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2767 $thirdparty =
$object->contact;
2769 $thirdparty =
$object->thirdparty;
2779 if ($this->page_largeur < 210) {
2783 $posy += $top_shift;
2784 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2786 $posx = $this->marge_gauche;
2791 $pdf->SetTextColor(0, 0, 0);
2792 $pdf->SetFont(
'',
'', $default_font_size - 2);
2793 $pdf->SetXY($posx + 2, $posy - 5);
2794 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2795 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2799 $pdf->SetXY($posx + 2, $posy + 3);
2800 $pdf->SetFont(
'',
'B', $default_font_size);
2802 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2804 $posy = $pdf->getY();
2807 $pdf->SetFont(
'',
'', $default_font_size - 1);
2808 $pdf->SetXY($posx + 2, $posy);
2810 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2814 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2816 if (!empty($idaddressshipping)) {
2817 $object->fetch_contact($idaddressshipping[0]);
2818 $companystatic =
new Societe($this->db);
2819 $companystatic->fetch(
$object->contact->fk_soc);
2826 if (!empty($carac_client_shipping)) {
2827 $posy += $hautcadre;
2832 $pdf->SetXY($posx + 2, $posy - 5);
2833 $pdf->SetFont(
'',
'', $default_font_size - 2);
2834 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2835 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2838 $pdf->SetXY($posx + 2, $posy + 3);
2839 $pdf->SetFont(
'',
'B', $default_font_size);
2840 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2842 $posy = $pdf->getY();
2845 $pdf->SetXY($posx + 2, $posy);
2846 $pdf->SetFont(
'',
'', $default_font_size - 1);
2847 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2849 $shipp_shift += $hautcadre + 10;
2854 $pdf->SetTextColor(0, 0, 0);
2856 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);