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;
729 for ($i = 0; $i < $nblines; $i++) {
730 $linePosition = $i + 1;
733 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
735 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
736 $level =
$object->lines[$i]->qty;
739 if (isset($sub_options[
'titleshowuponpdf'])) {
740 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
741 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
742 unset($pdf_sub_options[
'titleshowuponpdf']);
744 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
745 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
746 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
747 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
750 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
751 unset($pdf_sub_options[
'titleshowuponpdf']);
753 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
754 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
759 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
761 $pdf_sub_options = array();
762 $pdf_sub_options[
'titleshowuponpdf'] = 1;
763 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
769 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
770 $object->lines[$i]->pagebreak =
true;
774 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
777 if (!empty($tplidx)) {
778 $pdf->useTemplate($tplidx);
781 $pdf->setPage($pdf->getNumPages());
782 $nexY = $curY = $this->tab_top_newpage;
787 $pdf->SetFont(
'',
'', $default_font_size - 1);
788 $pdf->SetTextColor(0, 0, 0);
791 $imglinesize = array();
792 if (!empty($realpatharray[$i])) {
796 $pdf->setTopMargin($this->tab_top_newpage);
797 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
798 $pageposbefore = $pdf->getPage();
802 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
807 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
808 $pdf->AddPage(
'',
'',
true);
809 if (!empty($tplidx)) {
810 $pdf->useTemplate($tplidx);
812 $pdf->setPage($pageposbefore + 1);
813 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
814 $curY = $this->tab_top_newpage;
815 $showpricebeforepagebreak = 0;
818 $pdf->setPageOrientation(
'',
false, $this->heightforfooter + $this->heightforfreetext);
820 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
821 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
823 $posYAfterImage = $curY + $imglinesize[
'height'];
830 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
834 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
839 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
845 $pdf->setPage($pageposbefore);
846 $pdf->setTopMargin($this->marge_haute);
848 $pdf->setPageOrientation(
'',
false, $this->heightforfooter);
851 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
852 $pdf->setPage($afterPosData[
'page']);
853 $curY = $this->tab_top_newpage;
856 $pdf->SetFont(
'',
'', $default_font_size - 1);
870 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
895 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
902 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
905 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
907 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
909 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
922 if (!empty(
$object->lines[$i]->array_options)) {
923 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
939 'nexY' => & $afterPosData[
'y'],
940 'outputlangs' => $outputlangs,
941 'hidedetails' => $hidedetails
943 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
951 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
953 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent) &&
getDolGlobalInt(
'INVOICE_USE_SITUATION') != 2) {
955 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
957 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
961 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
963 $tvaligne = $sign *
$object->lines[$i]->total_tva;
967 $localtax1ligne =
$object->lines[$i]->total_localtax1;
968 $localtax2ligne =
$object->lines[$i]->total_localtax2;
969 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
970 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
971 $localtax1_type =
$object->lines[$i]->localtax1_type;
972 $localtax2_type =
$object->lines[$i]->localtax2_type;
974 $vatrate = (string)
$object->lines[$i]->tva_tx;
977 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
978 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
980 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
981 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
985 if ($localtax1_type && $localtax1ligne != 0) {
986 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
987 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
989 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
992 if ($localtax2_type && $localtax2ligne != 0) {
993 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
994 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
996 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
1000 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
1005 if (!isset($this->tva[$vatrate])) {
1006 $this->tva[$vatrate] = 0;
1008 $this->tva[$vatrate] += $tvaligne;
1009 $vatcode =
$object->lines[$i]->vat_src_code;
1010 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
1011 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
1014 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
1015 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
1017 $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);
1019 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1022 if (!$hidenextline) {
1024 $pdf->setPage($afterPosData[
'page']);
1025 $nexY = $afterPosData[
'y'];
1028 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1029 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1031 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1032 $pdf->SetLineStyle(array(
'dash' => 0));
1036 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
1045 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
1047 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
1049 if (!empty($tplidx)) {
1050 $pdf->useTemplate($tplidx);
1053 $pdf->setPage($pagenb);
1057 $drawTabNumbPage = $pdf->getNumPages();
1058 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1061 $pdf->setPageOrientation(
'',
false, 0);
1063 $drawTabHideTop = $hidetop;
1064 $drawTabTop = $this->tab_top_newpage;
1065 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1068 if ($i == $pageposbeforeprintlines) {
1070 $drawTabTop = $this->tab_top;
1071 } elseif (!$drawTabHideTop) {
1073 $drawTabTop -= $this->tabTitleHeight;
1075 $drawTabHideTop = 1;
1080 if ($i == $pdf->getNumPages()) {
1082 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1085 $drawTabHeight = $drawTabBottom - $drawTabTop;
1086 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object, $outputlangsbis);
1088 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1095 $pdf->setPageOrientation(
'',
true, 0);
1098 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1101 if (!empty($tplidx)) {
1102 $pdf->useTemplate($tplidx);
1108 $pdf->SetTextColor(0, 0, 0);
1110 $pdf->setPage($pdf->getNumPages());
1112 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1118 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1121 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1122 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1127 if (method_exists($pdf,
'AliasNbPages')) {
1128 $pdf->AliasNbPages();
1133 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1134 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
1135 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
1136 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
1139 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1140 $pagecount = $pdf->setSourceFile($termsofsale);
1141 for ($i = 1; $i <= $pagecount; $i++) {
1142 $tplIdx = $pdf->importPage($i);
1143 if ($tplIdx !==
false) {
1144 $s = $pdf->getTemplatesize($tplIdx);
1145 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1146 $pdf->useTemplate($tplIdx);
1148 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1160 $pdf->Output($file,
'F');
1163 $hookmanager->initHooks(array(
'pdfgeneration'));
1164 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1166 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1167 $this->warnings = $hookmanager->warnings;
1169 $this->error = $hookmanager->error;
1170 $this->errors = $hookmanager->errors;
1177 $this->result = array(
'fullpath' => $file);
1181 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1185 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1349 $pdf->SetFont(
'',
'', $default_font_size - 1);
1351 krsort($this->tva_array);
1358 $pdf->SetFillColor(224, 224, 224);
1360 $pdf->SetFont(
'',
'', $default_font_size - 2);
1361 $pdf->SetXY($this->marge_gauche, $posy);
1362 $titre = $outputlangs->transnoentities(
"VAT");
1363 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1365 $pdf->SetFont(
'',
'', $default_font_size - 2);
1366 $pdf->SetXY($this->marge_gauche + 25, $posy);
1367 $titre = $outputlangs->transnoentities(
"NetTotal");
1368 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1370 $pdf->SetFont(
'',
'', $default_font_size - 2);
1371 $pdf->SetXY($this->marge_gauche + 50, $posy);
1372 $titre = $outputlangs->transnoentities(
"VATAmount");
1373 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1375 $pdf->SetFont(
'',
'', $default_font_size - 2);
1376 $pdf->SetXY($this->marge_gauche + 75, $posy);
1377 $titre = $outputlangs->transnoentities(
"AmountTotal");
1378 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1380 $posy = $pdf->GetY();
1385 foreach ($this->tva_array as $tvakey => $tvaval) {
1386 $pdf->SetFont(
'',
'', $default_font_size - 2);
1387 $pdf->SetXY($this->marge_gauche, $posy);
1388 $titre = round((
float) $tvakey, 2) .
"%";
1389 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1391 $pdf->SetFont(
'',
'', $default_font_size - 2);
1392 $pdf->SetXY($this->marge_gauche + 25, $posy);
1393 $titre =
price($tvaval[
'tot_ht']);
1394 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1395 $tot_ht += $tvaval[
'tot_ht'];
1397 $pdf->SetFont(
'',
'', $default_font_size - 2);
1398 $pdf->SetXY($this->marge_gauche + 50, $posy);
1399 $titre =
price($tvaval[
'amount']);
1400 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1401 $tot_tva += $tvaval[
'amount'];
1403 $pdf->SetFont(
'',
'', $default_font_size - 2);
1404 $pdf->SetXY($this->marge_gauche + 75, $posy);
1405 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1406 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1407 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1409 $posy = $pdf->GetY();
1414 $showvatmention = 0;
1415 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1416 $pdf->SetFont(
'',
'', $default_font_size - 2);
1417 $pdf->SetXY($this->marge_gauche, $posy);
1418 if (empty(
$mysoc->tva_assuj)) {
1419 if (
$mysoc->forme_juridique_code == 92) {
1420 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1422 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1425 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1426 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1429 $posy = $pdf->GetY();
1432 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1434 if ($showvatmention) {
1440 if ($this->page_largeur < 210) {
1447 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1448 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1449 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1450 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1451 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1452 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1453 $sql .=
" AND f.fk_statut > 0";
1454 $sql .=
" ORDER BY f.datef ASC";
1457 $invoices = array();
1458 $resql = $this->db->query($sql);
1460 while ($obj = $this->db->fetch_object($resql)) {
1462 $old_balance += $obj->total_ttc;
1464 $this->db->free($resql);
1468 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1469 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1470 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1471 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1472 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1473 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1474 $sql_payments .=
" ORDER BY p.datep ASC";
1476 $total_payments = 0;
1477 $resql_payments = $this->db->query($sql_payments);
1478 if ($resql_payments) {
1479 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1480 $total_payments += $obj_payment->amount;
1482 $this->db->free($resql_payments);
1486 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1487 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1488 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1489 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1490 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1491 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1493 $current_date_payments = 0;
1494 $resql_current_date = $this->db->query($sql_current_date_payments);
1495 if ($resql_current_date) {
1496 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1497 $current_date_payments += $obj_current->amount;
1499 $this->db->free($resql_current_date);
1503 $old_balance -= $total_payments;
1506 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1508 $pdf->SetFillColor(224, 224, 224);
1509 $pdf->SetFont(
'',
'', $default_font_size - 2);
1510 $pdf->SetXY($this->marge_gauche, $posy);
1511 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1512 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1514 $pdf->SetFont(
'',
'', $default_font_size - 2);
1515 $pdf->SetXY($posxval + 8, $posy);
1516 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1517 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1519 $posy = $pdf->GetY() + 1;
1524 $pdf->SetFont(
'',
'', $default_font_size - 2);
1525 $pdf->SetXY($this->marge_gauche, $posy);
1526 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1527 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1529 $pdf->SetFont(
'',
'', $default_font_size - 2);
1530 $pdf->SetXY($posxval, $posy);
1531 $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);
1532 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1533 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1535 $posy = $pdf->GetY() + 3;
1539 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1540 $pdf->SetFont(
'',
'', $default_font_size - 2);
1541 $pdf->SetXY($this->marge_gauche, $posy);
1542 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1543 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1545 $pdf->SetFont(
'',
'', $default_font_size - 2);
1546 $pdf->SetXY($posxval, $posy);
1547 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1548 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1550 $posy = $pdf->GetY() + 3;
1555 if (empty(
$object->mode_reglement_code)
1558 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1562 $outputlangs->load(
"errors");
1564 $pdf->SetXY($this->marge_gauche, $posy);
1565 $pdf->SetTextColor(200, 0, 0);
1566 $pdf->SetFont(
'',
'', $default_font_size - 2);
1567 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1568 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1569 $pdf->SetTextColor(0, 0, 0);
1571 $posy = $pdf->GetY() + 1;
1575 if (!empty(
$object->mode_reglement_code)
1576 &&
$object->mode_reglement_code !=
'CHQ'
1577 &&
$object->mode_reglement_code !=
'VIR') {
1578 $pdf->SetFont(
'',
'', $default_font_size - 2);
1579 $pdf->SetXY($this->marge_gauche, $posy);
1580 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1581 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1583 $pdf->SetFont(
'',
'', $default_font_size - 2);
1584 $pdf->SetXY($posxval, $posy);
1585 $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);
1588 if (
$object->mode_reglement_code ==
"PRE") {
1589 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1592 $bac->fetch(0,
'',
$object->thirdparty->id);
1593 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1594 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1597 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1599 $posy = $pdf->GetY();
1605 if ($this->emetteur->country_code ==
'FR') {
1607 $pdf->SetXY($this->marge_gauche, $posy);
1608 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1610 $posy = $pdf->GetY() + 1;
1615 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1616 $useonlinepayment = 0;
1620 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1621 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1622 $useonlinepayment = count($validpaymentmethod);
1627 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1630 $langs->loadLangs(array(
'payment',
'stripe'));
1631 $servicename = $langs->transnoentities(
'Online');
1632 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1633 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1635 $pdf->SetXY($this->marge_gauche, $posy);
1636 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1638 $posy = $pdf->GetY() + 1;
1643 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1649 $account =
new Account($this->db);
1652 $pdf->SetXY($this->marge_gauche, $posy);
1653 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1654 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1655 $posy = $pdf->GetY() + 1;
1658 $pdf->SetXY($this->marge_gauche, $posy);
1659 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1660 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1661 $posy = $pdf->GetY() + 2;
1665 $pdf->SetXY($this->marge_gauche, $posy);
1666 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1667 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1668 $posy = $pdf->GetY() + 1;
1671 $pdf->SetXY($this->marge_gauche, $posy);
1672 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1673 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1674 $posy = $pdf->GetY() + 2;
1681 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1687 $account =
new Account($this->db);
1688 $account->fetch($bankid);
1690 $curx = $this->marge_gauche;
1693 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1699 $qrPosX = $this->marge_gauche + 5;
1701 $qrCodeColor = array(
'25',
'25',
'25');
1705 'fgcolor' => $qrCodeColor,
1707 'module_width' => 1,
1708 'module_height' => 1
1711 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1712 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1714 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1715 $pdf->SetFont(
'',
'', $default_font_size - 5);
1716 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1717 $posy = $pdf->GetY() + 2;
1722 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1725 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1748 global
$mysoc, $hookmanager;
1759 if (is_object($outputlangsbis)) {
1760 $pdf->SetFont(
'',
'', $default_font_size - 2);
1762 $pdf->SetFont(
'',
'', $default_font_size - 1);
1768 if ($this->page_largeur < 210) {
1772 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1778 $parameters = array(
1780 'outputlangs' => $outputlangs,
1782 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1787 foreach (
$object->lines as $line) {
1788 if ($line->product_type != 9) {
1789 $percent += $line->situation_percent;
1795 $avancementGlobal = $percent / $i;
1797 $avancementGlobal = 0;
1800 $object->fetchPreviousNextSituationInvoice();
1801 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1804 $total_a_payer_ttc = 0;
1805 foreach ($TPreviousIncoice as &$fac) {
1806 $total_a_payer += $fac->total_ht;
1807 $total_a_payer_ttc += $fac->total_ttc;
1809 $total_a_payer +=
$object->total_ht;
1810 $total_a_payer_ttc +=
$object->total_ttc;
1812 if (!empty($avancementGlobal)) {
1813 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1814 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1817 $total_a_payer_ttc = 0;
1821 if (!empty($TPreviousIncoice)) {
1822 $pdf->setY($tab2_top);
1823 $posy = $pdf->GetY();
1825 foreach ($TPreviousIncoice as &$fac) {
1826 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1831 $pdf->setY($this->tab_top_newpage);
1833 $pdf->setY($this->marge_haute);
1835 $posy = $pdf->GetY();
1840 $pdf->SetFillColor(255, 255, 255);
1841 $pdf->SetXY($col1x, $posy);
1842 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string) $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1844 $pdf->SetXY($col2x, $posy);
1848 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1851 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1853 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1862 $pdf->SetFillColor(255, 255, 255);
1863 $pdf->SetXY($col1x, $posy);
1864 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1866 $pdf->SetXY($col2x, $posy);
1869 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1877 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1878 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1883 $pdf->SetFont(
'',
'', $default_font_size - 1);
1884 $pdf->SetFillColor(255, 255, 255);
1885 $pdf->SetXY($col1x, $posy);
1886 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", (
string) $avancementGlobal), 0,
'L',
true);
1888 $pdf->SetXY($col2x, $posy);
1889 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R',
true);
1890 $pdf->SetFont(
'',
'', $default_font_size - 2);
1894 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1898 $pdf->setY($this->tab_top_newpage);
1900 $pdf->setY($this->marge_haute);
1903 $posy = $pdf->GetY();
1917 $total_discount_on_lines = 0;
1918 $multicurrency_total_discount_on_lines = 0;
1919 foreach (
$object->lines as $i => $line) {
1923 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1924 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1926 if ($line->total_ht < 0) {
1927 $total_discount_on_lines += -$line->total_ht;
1928 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1933 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
1936 $pdf->SetFillColor(255, 255, 255);
1937 $pdf->SetXY($col1x, $tab2_top);
1938 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1939 $pdf->SetXY($col2x, $tab2_top);
1941 $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));
1942 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1949 $pdf->SetFillColor(255, 255, 255);
1950 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1951 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1952 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1954 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1955 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1962 $pdf->SetFillColor(255, 255, 255);
1963 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1964 $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);
1967 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1968 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1972 $pdf->SetFillColor(255, 255, 255);
1973 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1974 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1976 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1977 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1981 $pdf->SetFillColor(248, 248, 248);
1984 $total_ttc_origin =
$object->total_ttc;
1986 $this->atleastoneratenotnull = 0;
1988 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1989 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1993 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1994 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1998 foreach ($localtax_rate as $tvakey => $tvaval) {
1999 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
2003 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2006 if (preg_match(
'/\*/', (
string) $tvakey)) {
2007 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2008 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2011 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
2015 $totalvat .= $tvacompl;
2017 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2020 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2024 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2025 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2031 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
2032 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
2036 foreach ($localtax_rate as $tvakey => $tvaval) {
2037 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
2041 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2044 if (preg_match(
'/\*/', (
string) $tvakey)) {
2045 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2046 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2048 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
2052 $totalvat .= $tvacompl;
2054 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2057 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2061 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2062 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2070 foreach ($this->tva as $tvakey => $tvaval) {
2071 $sum_pdf_tva += $tvaval;
2074 if ($sum_pdf_tva !=
$object->total_tva) {
2075 if (!empty($sum_pdf_tva)) {
2076 $coef_fix_tva =
$object->total_tva / $sum_pdf_tva;
2082 foreach ($this->tva as $tvakey => $tvaval) {
2083 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
2085 foreach ($this->tva_array as $tvakey => $tvaval) {
2086 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
2093 foreach ($this->tva_array as $tvakey => $tvaval) {
2095 $this->atleastoneratenotnull++;
2098 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2101 if (preg_match(
'/\*/', $tvakey)) {
2102 $tvakey = str_replace(
'*',
'', $tvakey);
2103 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2105 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
2108 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
2110 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
2112 $totalvat .= $tvacompl;
2114 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
2116 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2118 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2120 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
2126 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
2127 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2131 foreach ($localtax_rate as $tvakey => $tvaval) {
2132 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
2136 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2139 if (preg_match(
'/\*/', (
string) $tvakey)) {
2140 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2141 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2143 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
2147 $totalvat .= $tvacompl;
2149 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2152 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2156 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2157 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2163 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
2164 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2168 foreach ($localtax_rate as $tvakey => $tvaval) {
2170 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
2174 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2177 if (preg_match(
'/\*/', (
string) $tvakey)) {
2178 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2179 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2181 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
2185 $totalvat .= $tvacompl;
2187 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2190 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2194 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2195 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2203 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2204 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
2206 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2207 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
2212 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2213 $pdf->SetTextColor(0, 0, 60);
2214 $pdf->SetFillColor(224, 224, 224);
2215 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
2217 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2219 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2221 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2225 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2226 $pdf->SetTextColor(0, 0, 60);
2227 $pdf->SetFillColor(224, 224, 224);
2228 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2230 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2231 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2235 if (
$object->displayRetainedWarranty()) {
2236 $pdf->SetTextColor(40, 40, 40);
2237 $pdf->SetFillColor(255, 255, 255);
2239 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2240 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2244 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2245 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2247 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2248 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2252 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2254 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2255 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2257 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2258 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2259 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2264 $pdf->SetTextColor(0, 0, 0);
2266 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2269 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2272 $deja_regle_origin = 0;
2273 $creditnoteamount_origin = 0;
2274 $depositsamount_origin = 0;
2275 $resteapayer_origin = 0;
2277 $deja_regle_origin =
$object->getSommePaiement(0);
2278 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
2279 $depositsamount_origin =
$object->getSumDepositsUsed(0);
2280 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
2284 $resteapayer_origin = 0;
2287 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
2290 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2291 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L',
false);
2292 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2294 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R',
false);
2307 if ($creditnoteamount) {
2308 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
2309 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.(($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes"))) :
'');
2311 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2312 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L',
false);
2313 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2314 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R',
false);
2317 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2319 $pdf->SetFillColor(255, 255, 255);
2321 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2322 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"EscompteOfferedShort") :
''), $useborder,
'L',
true);
2323 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2324 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT'), 0, $outputlangs), $useborder,
'R',
true);
2327 $resteapayer_origin = 0;
2331 $pdf->SetTextColor(0, 0, 60);
2332 $pdf->SetFillColor(224, 224, 224);
2333 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2334 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
2335 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2337 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2339 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2343 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2344 $pdf->SetTextColor(0, 0, 60);
2345 $pdf->SetFillColor(224, 224, 224);
2346 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2348 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2349 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2352 $pdf->SetFont(
'',
'', $default_font_size - 1);
2353 $pdf->SetTextColor(0, 0, 0);
2356 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2358 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2360 $this->error = $hookmanager->error;
2361 $this->errors = $hookmanager->errors;
2365 return ($tab2_top + ($tab2_hl * $index));
2475 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2478 global $conf, $langs;
2480 $ltrdirection =
'L';
2481 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2482 $ltrdirection =
'R';
2486 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2492 $pdf->SetTextColor(0, 0, 60);
2493 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2497 $posy = $this->marge_haute;
2498 $posx = $this->page_largeur - $this->marge_droite - $w;
2500 $pdf->SetXY($this->marge_gauche, $posy);
2504 if ($this->emetteur->logo) {
2505 $logodir = $conf->mycompany->dir_output;
2506 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
2507 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
2510 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2512 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2514 if (is_readable($logo)) {
2516 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2518 $pdf->SetTextColor(200, 0, 0);
2519 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2520 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2521 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2524 $text = $this->emetteur->name;
2525 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2529 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2530 $pdf->SetXY($posx, $posy);
2531 $pdf->SetTextColor(0, 0, 60);
2533 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2535 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2538 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2541 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2544 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2546 if ($this->situationinvoice) {
2547 $outputlangs->loadLangs(array(
"other"));
2548 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2549 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2551 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2554 if ($this->situationinvoice) {
2555 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2557 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2558 } elseif (
$object->type == 1) {
2559 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2560 } elseif (
$object->type == 2) {
2561 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2562 } elseif (
$object->type == 3) {
2563 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2564 } elseif (
$object->type == 4) {
2565 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2568 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2569 if (
$object->status == $object::STATUS_DRAFT) {
2570 $pdf->SetTextColor(128, 0, 0);
2571 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2574 $pdf->MultiCell($w, 3, $title,
'',
'R');
2575 if (!empty($subtitle)) {
2576 $pdf->SetFont(
'',
'B', $default_font_size);
2577 $pdf->SetXY($posx, $posy + 5);
2578 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2582 $pdf->SetFont(
'',
'', $default_font_size - 2);
2599 $pdf->SetFont(
'',
'', $default_font_size - 2);
2603 $pdf->SetXY($posx, $posy);
2604 $pdf->SetTextColor(0, 0, 60);
2605 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2610 if (!empty(
$object->project->ref)) {
2612 $pdf->SetXY($posx, $posy);
2613 $pdf->SetTextColor(0, 0, 60);
2614 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2620 if (!empty(
$object->project->ref)) {
2621 $outputlangs->load(
"projects");
2623 $pdf->SetXY($posx, $posy);
2624 $pdf->SetTextColor(0, 0, 60);
2625 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2629 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2630 if (
$object->type == 0 && $objectidnext) {
2631 $objectreplacing =
new Facture($this->db);
2632 $objectreplacing->fetch($objectidnext);
2635 $pdf->SetXY($posx, $posy);
2636 $pdf->SetTextColor(0, 0, 60);
2637 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2640 $objectreplaced =
new Facture($this->db);
2641 $objectreplaced->fetch(
$object->fk_facture_source);
2644 $pdf->SetXY($posx, $posy);
2645 $pdf->SetTextColor(0, 0, 60);
2646 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2649 $objectreplaced =
new Facture($this->db);
2650 $objectreplaced->fetch(
$object->fk_facture_source);
2653 $pdf->SetXY($posx, $posy);
2654 $pdf->SetTextColor(0, 0, 60);
2655 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2659 $pdf->SetXY($posx, $posy);
2660 $pdf->SetTextColor(0, 0, 60);
2662 $title = $outputlangs->transnoentities(
"DateInvoice");
2663 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2664 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2666 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2670 $pdf->SetXY($posx, $posy);
2671 $pdf->SetTextColor(0, 0, 60);
2672 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2677 $pdf->SetXY($posx, $posy);
2678 $pdf->SetTextColor(0, 0, 60);
2679 $title = $outputlangs->transnoentities(
"DateDue");
2680 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2681 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2683 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2688 $pdf->SetXY($posx, $posy);
2689 $pdf->SetTextColor(0, 0, 60);
2690 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2695 $pdf->SetXY($posx, $posy);
2696 $pdf->SetTextColor(0, 0, 60);
2697 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2702 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2703 if (count($arrayidcontact) > 0) {
2704 $usertmp =
new User($this->db);
2705 $usertmp->fetch($arrayidcontact[0]);
2707 $pdf->SetXY($posx, $posy);
2708 $pdf->SetTextColor(0, 0, 60);
2709 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2719 $current_y = $pdf->getY();
2721 if ($current_y < $pdf->getY()) {
2722 $top_shift = $pdf->getY() - $current_y;
2728 $carac_emetteur =
'';
2730 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2731 if (count($arrayidcontact) > 0) {
2732 $object->fetch_user($arrayidcontact[0]);
2733 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2734 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2735 $carac_emetteur .=
"\n";
2742 $posy += $top_shift;
2743 $posx = $this->marge_gauche;
2745 $posx = $this->page_largeur - $this->marge_droite - 80;
2753 $pdf->SetTextColor(0, 0, 0);
2754 $pdf->SetFont(
'',
'', $default_font_size - 2);
2755 $pdf->SetXY($posx, $posy - 5);
2756 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2757 $pdf->SetXY($posx, $posy);
2758 $pdf->SetFillColor(230, 230, 230);
2759 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2760 $pdf->SetTextColor(0, 0, 60);
2765 $pdf->SetXY($posx + 2, $posy + 3);
2766 $pdf->SetFont(
'',
'B', $default_font_size);
2767 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2768 $posy = $pdf->getY();
2772 $pdf->SetXY($posx + 2, $posy);
2773 $pdf->SetFont(
'',
'', $default_font_size - 1);
2774 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2777 $usecontact =
false;
2778 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2779 if (count($arrayidcontact) > 0) {
2781 $result =
$object->fetch_contact($arrayidcontact[0]);
2785 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2786 $thirdparty =
$object->contact;
2788 $thirdparty =
$object->thirdparty;
2798 if ($this->page_largeur < 210) {
2802 $posy += $top_shift;
2803 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2805 $posx = $this->marge_gauche;
2810 $pdf->SetTextColor(0, 0, 0);
2811 $pdf->SetFont(
'',
'', $default_font_size - 2);
2812 $pdf->SetXY($posx + 2, $posy - 5);
2813 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2814 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2818 $pdf->SetXY($posx + 2, $posy + 3);
2819 $pdf->SetFont(
'',
'B', $default_font_size);
2821 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2823 $posy = $pdf->getY();
2826 $pdf->SetFont(
'',
'', $default_font_size - 1);
2827 $pdf->SetXY($posx + 2, $posy);
2829 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2833 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2835 if (!empty($idaddressshipping)) {
2836 $object->fetch_contact($idaddressshipping[0]);
2837 $companystatic =
new Societe($this->db);
2838 $companystatic->fetch(
$object->contact->fk_soc);
2845 if (!empty($carac_client_shipping)) {
2846 $posy += $hautcadre;
2851 $pdf->SetXY($posx + 2, $posy - 5);
2852 $pdf->SetFont(
'',
'', $default_font_size - 2);
2853 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2854 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2857 $pdf->SetXY($posx + 2, $posy + 3);
2858 $pdf->SetFont(
'',
'B', $default_font_size);
2859 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2861 $posy = $pdf->getY();
2864 $pdf->SetXY($posx + 2, $posy);
2865 $pdf->SetFont(
'',
'', $default_font_size - 1);
2866 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2868 $shipp_shift += $hautcadre + 10;
2873 $pdf->SetTextColor(0, 0, 0);
2875 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);