264 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
267 global $user, $langs, $conf,
$mysoc, $hookmanager, $nblines;
269 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
271 if (!is_object($outputlangs)) {
272 $outputlangs = $langs;
276 $outputlangs->charset_output =
'ISO-8859-1';
280 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
282 global $outputlangsbis;
283 $outputlangsbis =
null;
285 $outputlangsbis =
new Translate(
'', $conf);
287 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
291 setEventMessage($langs->trans(
'WarningsObjectIsNotASituation'),
'warnings');
299 $nblines = count(
$object->lines);
307 $realpatharray = array();
308 $this->atleastonephoto =
false;
310 $objphoto =
new Product($this->db);
312 for ($i = 0; $i < $nblines; $i++) {
313 if (empty(
$object->lines[$i]->fk_product)) {
317 $objphoto->fetch(
$object->lines[$i]->fk_product);
321 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
322 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
324 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
325 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
330 foreach ($pdir as $midir) {
332 $entity = $objphoto->entity;
333 if ($entity !==
null && $conf->entity != $entity) {
334 $dir = $conf->product->multidir_output[$entity].
'/'.$midir;
336 $dir = $conf->product->dir_output.
'/'.$midir;
339 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
341 if ($obj[
'photo_vignette']) {
342 $filename = $obj[
'photo_vignette'];
344 $filename = $obj[
'photo'];
347 $filename = $obj[
'photo'];
350 $realpath = $dir.$filename;
352 $this->atleastonephoto =
true;
357 if ($realpath && $arephoto) {
358 $realpatharray[$i] = $realpath;
365 if ($conf->facture->multidir_output[$conf->entity]) {
369 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
370 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
374 $dir = $conf->facture->multidir_output[$conf->entity];
375 $file = $dir.
"/SPECIMEN.pdf";
378 $dir = $conf->facture->multidir_output[
$object->entity ?? $conf->entity].
"/".$objectref;
379 $file = $dir.
"/".$objectref.
".pdf";
381 if (!file_exists($dir)) {
383 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
388 if (file_exists($dir)) {
390 if (!is_object($hookmanager)) {
391 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
394 $hookmanager->initHooks(array(
'pdfgeneration'));
395 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
397 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
400 $nblines = count(
$object->lines);
401 $nbpayments = count(
$object->getListOfPayments());
402 $nbprevsituation = is_array(
$object->tab_previous_situation_invoice) ? count(
$object->tab_previous_situation_invoice) : 0;
407 $pdf->setAutoPageBreak(
true, 0);
410 $this->heightforinfotot = 50;
412 $this->heightforinfotot += (4 * ($nbpayments + 3));
414 if ($nbprevsituation > 0) {
415 $this->heightforinfotot += (4 * ($nbprevsituation + 3));
417 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
418 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
420 $heightforqrinvoice = 0;
424 $this->heightforinfotot = 30 + (4 * $nbpayments);
428 if (class_exists(
'TCPDF')) {
429 $pdf->setPrintHeader(
false);
430 $pdf->setPrintFooter(
false);
436 $logodir = $conf->mycompany->dir_output;
437 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
438 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
440 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
441 $this->tplidx = $pdf->importPage(1);
446 $pdf->SetDrawColor(128, 128, 128);
448 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
449 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceSituationTitle"));
450 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
451 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
452 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
454 $pdf->SetCompression(
false);
458 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
459 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
470 'Name' => $this->emetteur->name,
471 'Location' =>
getCountry($this->emetteur->country_code,
''),
472 'Reason' =>
'INVOICE',
473 'ContactInfo' => $this->emetteur->email
475 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
479 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
483 $categoryOfOperation = 0;
486 for ($i = 0; $i < $nblines; $i++) {
487 if (
$object->lines[$i]->remise_percent) {
488 $this->atleastonediscount++;
493 if (preg_match(
'/^\((.*)\)$/',
$object->lines[$i]->desc, $reg)) {
494 if ($reg[1] ==
'DEPOSIT') {
505 if ($categoryOfOperation < 2) {
506 $lineProductType =
$object->lines[$i]->product_type;
512 if ($nbProduct > 0 && $nbService > 0) {
514 $categoryOfOperation = 2;
519 if ($categoryOfOperation <= 0) {
521 if ($nbProduct == 0 && $nbService > 0) {
522 $categoryOfOperation = 1;
525 $this->categoryOfOperation = $categoryOfOperation;
528 if (
$object->situation_cycle_ref) {
529 $this->situationinvoice =
true;
534 if (!empty($this->tplidx)) {
535 $pdf->useTemplate($this->tplidx);
540 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
541 $top_shift = $pagehead[
'top_shift'];
542 $shipp_shift = $pagehead[
'shipp_shift'];
543 $pdf->SetFont(
'',
'', $default_font_size - 1);
544 $pdf->MultiCell(0, 3,
'');
545 $pdf->SetTextColor(0, 0, 0);
550 $this->tab_top = 90 + $top_shift + $shipp_shift;
551 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
554 $extra_under_address_shift = 0;
557 $qrcodestring =
$object->buildZATCAQRString();
560 $qrcodestring =
$object->buildSwitzerlandQRString();
564 $qrcodestring =
$object->buildEPCQrCodeString();
569 $qrcodecolor = array(
'25',
'25',
'25');
574 'fgcolor' => $qrcodecolor,
579 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
583 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
584 $pdf->SetFont(
'',
'', $default_font_size - 4);
585 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
589 $extra_under_address_shift += 25;
597 'outputlangs' => $outputlangs,
598 'hidedetails' => $hidedetails
600 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
601 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
602 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
605 $this->tab_top += $extra_under_address_shift;
606 $this->tab_top_newpage += 0;
610 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
612 $nexY = $this->tab_top - 1;
622 $tab_height_newpage = 150;
624 $this->
tableFirstPage($pdf, $tab_top, $this->page_hauteur - 100 - $this->heightforfreetext - $this->heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
626 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
634 $pdf->setTopMargin($this->tab_top_newpage);
637 $height_incoterms = 0;
639 $desc_incoterms =
$object->getIncotermsForPDF();
640 if ($desc_incoterms) {
643 $pdf->SetFont(
'',
'', $default_font_size - 1);
644 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
645 $nexY = max($pdf->GetY(), $nexY);
646 $height_incoterms = $nexY - $this->tab_top;
649 $pdf->SetDrawColor(192, 192, 192);
650 $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');
652 $this->tab_top = $nexY + 6;
653 $height_incoterms += 4;
658 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
661 if (is_object(
$object->thirdparty)) {
662 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
663 $salerepobj =
new User($this->db);
664 $salerepobj->fetch($salereparray[0][
'id']);
665 if (!empty($salerepobj->signature)) {
666 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
672 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
673 if (!empty($extranote)) {
677 $pagenb = $pdf->getPage();
681 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
682 $pageposbeforenote = $pagenb;
689 $pdf->startTransaction();
691 $pdf->SetFont(
'',
'', $default_font_size - 1);
692 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
694 $pageposafternote = $pdf->getPage();
695 $posyafter = $pdf->GetY();
697 if ($pageposafternote > $pageposbeforenote) {
698 $pdf->rollbackTransaction(
true);
701 while ($pagenb < $pageposafternote) {
704 if (!empty($this->tplidx)) {
705 $pdf->useTemplate($this->tplidx);
710 $pdf->setTopMargin($this->tab_top_newpage);
712 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
716 $pdf->setPage($pageposbeforenote);
717 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
718 $pdf->SetFont(
'',
'', $default_font_size - 1);
719 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
720 $pageposafternote = $pdf->getPage();
722 $posyafter = $pdf->GetY();
724 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
725 $pdf->AddPage(
'',
'',
true);
728 $pdf->setPage($pageposafternote);
729 $pdf->setTopMargin($this->tab_top_newpage);
731 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
737 $i = $pageposbeforenote;
738 while ($i < $pageposafternote) {
742 $pdf->SetDrawColor(128, 128, 128);
744 if ($i > $pageposbeforenote) {
745 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
746 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
748 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
749 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
753 $pdf->setPageOrientation(
'',
true, 0);
760 $pdf->setPage($pageposafternote);
761 if (!empty($this->tplidx)) {
762 $pdf->useTemplate($this->tplidx);
767 $height_note = $posyafter - $this->tab_top_newpage;
768 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
771 $pdf->commitTransaction();
772 $posyafter = $pdf->GetY();
773 $height_note = $posyafter - $this->tab_top;
774 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
777 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
779 $pdf->AddPage(
'',
'',
true);
782 $pdf->setPage($pageposafternote);
783 if (!empty($this->tplidx)) {
784 $pdf->useTemplate($this->tplidx);
790 $posyafter = $this->tab_top_newpage;
794 $tab_height -= $height_note;
795 $this->tab_top = $posyafter + 6;
811 $nexY = $this->tab_top_newpage + $this->tabTitleHeight;
814 $pageposbeforeprintlines = $pdf->getPage();
815 $pagenb = $pageposbeforeprintlines;
817 for ($i = 0; $i < $nblines; $i++) {
818 $linePosition = $i + 1;
822 $pdf->SetFont(
'',
'', $default_font_size - 1);
823 $pdf->SetTextColor(0, 0, 0);
826 $imglinesize = array();
827 if (!empty($realpatharray[$i])) {
831 $pdf->setTopMargin($this->tab_top_newpage);
832 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot);
833 $pageposbefore = $pdf->getPage();
836 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
839 $posYAfterDescription = 0;
844 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($posy + $imglinesize[
'height']) > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
845 $pdf->AddPage(
'',
'',
true);
846 if (!empty($this->tplidx)) {
847 $pdf->useTemplate($this->tplidx);
849 $pdf->setPage($pageposbefore + 1);
850 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
851 $posy = $this->tab_top_newpage;
852 $showpricebeforepagebreak = 0;
856 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
857 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $posy + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
859 $posYAfterImage = $posy + $imglinesize[
'height'];
866 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
870 $pdf->startTransaction();
873 $pageposafter = $pdf->getPage();
875 if ($pageposafter > $pageposbefore) {
876 $pdf->rollbackTransaction(
true);
877 $pageposafter = $pageposbefore;
878 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
882 $pageposafter = $pdf->getPage();
883 $posyafter = $pdf->GetY();
885 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
886 if ($i == ($nblines - 1)) {
887 $pdf->AddPage(
'',
'',
true);
888 if (!empty($this->tplidx)) {
889 $pdf->useTemplate($this->tplidx);
891 $pdf->setPage($pageposafter + 1);
897 $showpricebeforepagebreak = 1;
899 $showpricebeforepagebreak = 0;
903 $pdf->commitTransaction();
905 $posYAfterDescription = $pdf->GetY();
908 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
910 $pageposafter = $pdf->getPage();
911 $pdf->setPage($pageposbefore);
912 $pdf->setTopMargin($this->marge_haute);
913 $pdf->setPageOrientation(
'',
true, 0);
916 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
917 $pdf->setPage($pageposafter);
918 $posy = $this->tab_top_newpage;
921 $pdf->SetFont(
'',
'', $default_font_size - 1);
932 $nexY = max($pdf->GetY(), $nexY);
939 $nexY = max($pdf->GetY(), $nexY);
947 $nexY = max($pdf->GetY(), $nexY);
954 $nexY = max($pdf->GetY(), $nexY);
961 $nexY = max($pdf->GetY(), $nexY);
968 $nexY = max($pdf->GetY(), $nexY);
975 $nexY = max($pdf->GetY(), $nexY);
982 $columkey =
'btpsomme';
984 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht_without_progress'], 0,
'', 1, -1, 2);
986 $nexY = max($pdf->GetY(), $nexY);
990 $columkey =
'progress_amount';
992 $printval =
price(
$object->lines[$i]->total_ht, 0,
'', 1, -1, 2);
994 $nexY = max($pdf->GetY(), $nexY);
997 $columkey =
'prev_progress';
999 $printval = $TInfosLigneSituationPrecedente[
'progress_prec'].
'%';
1001 $nexY = max($pdf->GetY(), $nexY);
1004 $columkey =
'prev_progress_amount';
1006 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht'], 0,
'', 1, -1, 2);
1008 $nexY = max($pdf->GetY(), $nexY);
1012 $parameters = array(
1017 'nexY' => & $afterPosData[
'y'],
1018 'outputlangs' => $outputlangs,
1019 'hidedetails' => $hidedetails
1021 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
1029 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
1030 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
1032 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
1034 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
1038 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
1040 $tvaligne = $sign *
$object->lines[$i]->total_tva;
1044 $localtax1ligne =
$object->lines[$i]->total_localtax1;
1045 $localtax2ligne =
$object->lines[$i]->total_localtax2;
1046 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
1047 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
1048 $localtax1_type =
$object->lines[$i]->localtax1_type;
1049 $localtax2_type =
$object->lines[$i]->localtax2_type;
1051 $vatrate = (string)
$object->lines[$i]->tva_tx;
1054 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
1055 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
1057 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
1058 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
1062 if ($localtax1_type && $localtax1ligne != 0) {
1063 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
1064 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
1066 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
1069 if ($localtax2_type && $localtax2ligne != 0) {
1070 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
1071 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
1073 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
1077 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
1082 if (!isset($this->tva[$vatrate])) {
1083 $this->tva[$vatrate] = 0;
1085 $this->tva[$vatrate] += $tvaligne;
1086 $vatcode =
$object->lines[$i]->vat_src_code;
1087 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
1088 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
1091 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
1092 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
1094 $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);
1096 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1100 $pdf->setPage($afterPosData[
'page']);
1101 $nexY = max($nexY, $posYAfterImage);
1104 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1105 $pdf->setPage($pageposafter);
1106 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1108 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1109 $pdf->SetLineStyle(array(
'dash' => 0));
1113 while ($pagenb < $pageposafter) {
1114 $pdf->setPage($pagenb);
1115 $tabtop = $this->tab_top;
1116 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1117 if ($pagenb != $pageposbeforeprintlines) {
1118 $tabtop = $this->tab_top_newpage;
1119 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1122 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1126 $pdf->setPage($pagenb);
1127 $pdf->setPageOrientation(
'',
true, 0);
1131 if (!empty($this->tplidx)) {
1132 $pdf->useTemplate($this->tplidx);
1136 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
1137 $tabtop = $this->tab_top;
1138 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1139 if ($pagenb != $pageposbeforeprintlines) {
1140 $tabtop = $this->tab_top_newpage;
1141 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1144 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1149 if (!empty($this->tplidx)) {
1150 $pdf->useTemplate($this->tplidx);
1161 $tabtop = $this->tab_top_newpage;
1162 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1163 $tabTitleHeight = 0;
1164 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1167 $pdf->SetTextColor(0, 0, 0);
1169 $pdf->setPage($pdf->getNumPages());
1171 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1178 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1181 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1182 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1189 if (method_exists($pdf,
'AliasNbPages')) {
1190 $pdf->AliasNbPages();
1194 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1195 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
1196 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
1197 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
1199 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1200 $pagecount = $pdf->setSourceFile($termsofsale);
1201 for ($i = 1; $i <= $pagecount; $i++) {
1202 $tplIdx = $pdf->importPage($i);
1203 if ($tplIdx !==
false) {
1204 $s = $pdf->getTemplatesize($tplIdx);
1205 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1206 $pdf->useTemplate($tplIdx);
1208 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1214 $this->resumeLastPage($pdf,
$object, 0, $tab_top, $outputlangs, $outputlangsbis);
1215 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1224 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1225 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
1226 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
1227 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
1229 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1230 $pagecount = $pdf->setSourceFile($termsofsale);
1231 for ($i = 1; $i <= $pagecount; $i++) {
1232 $tplIdx = $pdf->importPage($i);
1233 if ($tplIdx !==
false) {
1234 $s = $pdf->getTemplatesize($tplIdx);
1235 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1236 $pdf->useTemplate($tplIdx);
1238 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1246 $pdf->Output($file,
'F');
1249 $hookmanager->initHooks(array(
'pdfgeneration'));
1250 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1252 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1253 $this->warnings = $hookmanager->warnings;
1255 $this->error = $hookmanager->error;
1256 $this->errors = $hookmanager->errors;
1263 $this->result = array(
'fullpath' => $file);
1267 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1271 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1431 global $conf,
$mysoc, $hookmanager;
1435 $pdf->SetFont(
'',
'', $default_font_size - 1);
1437 krsort($this->tva_array);
1444 $pdf->SetFillColor(224, 224, 224);
1446 $pdf->SetFont(
'',
'', $default_font_size - 2);
1447 $pdf->SetXY($this->marge_gauche, $posy);
1448 $titre = $outputlangs->transnoentities(
"VAT");
1449 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1451 $pdf->SetFont(
'',
'', $default_font_size - 2);
1452 $pdf->SetXY($this->marge_gauche + 25, $posy);
1453 $titre = $outputlangs->transnoentities(
"NetTotal");
1454 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1456 $pdf->SetFont(
'',
'', $default_font_size - 2);
1457 $pdf->SetXY($this->marge_gauche + 50, $posy);
1458 $titre = $outputlangs->transnoentities(
"VATAmount");
1459 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1461 $pdf->SetFont(
'',
'', $default_font_size - 2);
1462 $pdf->SetXY($this->marge_gauche + 75, $posy);
1463 $titre = $outputlangs->transnoentities(
"AmountTotal");
1464 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1466 $posy = $pdf->GetY();
1471 foreach ($this->tva_array as $tvakey => $tvaval) {
1472 $pdf->SetFont(
'',
'', $default_font_size - 2);
1473 $pdf->SetXY($this->marge_gauche, $posy);
1474 $titre = round((
float) $tvakey, 2) .
"%";
1475 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1477 $pdf->SetFont(
'',
'', $default_font_size - 2);
1478 $pdf->SetXY($this->marge_gauche + 25, $posy);
1479 $titre =
price($tvaval[
'tot_ht']);
1480 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1481 $tot_ht += $tvaval[
'tot_ht'];
1483 $pdf->SetFont(
'',
'', $default_font_size - 2);
1484 $pdf->SetXY($this->marge_gauche + 50, $posy);
1485 $titre =
price($tvaval[
'amount']);
1486 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1487 $tot_tva += $tvaval[
'amount'];
1489 $pdf->SetFont(
'',
'', $default_font_size - 2);
1490 $pdf->SetXY($this->marge_gauche + 75, $posy);
1491 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1492 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1493 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1495 $posy = $pdf->GetY();
1500 $showvatmention = 0;
1501 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1502 $pdf->SetFont(
'',
'', $default_font_size - 2);
1503 $pdf->SetXY($this->marge_gauche, $posy);
1504 if (empty(
$mysoc->tva_assuj)) {
1505 if (
$mysoc->forme_juridique_code == 92) {
1506 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1508 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1511 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1512 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1515 $posy = $pdf->GetY();
1518 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1520 if ($showvatmention) {
1527 if ($this->page_largeur < 210) {
1534 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1535 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1536 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1537 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1538 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1539 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1540 $sql .=
" AND f.fk_statut > 0";
1541 $sql .=
" ORDER BY f.datef ASC";
1544 $invoices = array();
1545 $resql = $this->db->query($sql);
1547 while ($obj = $this->db->fetch_object($resql)) {
1549 $old_balance += $obj->total_ttc;
1551 $this->db->free($resql);
1555 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1556 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1557 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1558 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1559 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1560 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1561 $sql_payments .=
" ORDER BY p.datep ASC";
1563 $total_payments = 0;
1564 $resql_payments = $this->db->query($sql_payments);
1565 if ($resql_payments) {
1566 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1567 $total_payments += $obj_payment->amount;
1569 $this->db->free($resql_payments);
1573 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1574 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1575 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1576 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1577 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1578 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1580 $current_date_payments = 0;
1581 $resql_current_date = $this->db->query($sql_current_date_payments);
1582 if ($resql_current_date) {
1583 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1584 $current_date_payments += $obj_current->amount;
1586 $this->db->free($resql_current_date);
1590 $old_balance -= $total_payments;
1593 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1595 $pdf->SetFillColor(224, 224, 224);
1596 $pdf->SetFont(
'',
'', $default_font_size - 2);
1597 $pdf->SetXY($this->marge_gauche, $posy);
1598 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1599 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1601 $pdf->SetFont(
'',
'', $default_font_size - 2);
1602 $pdf->SetXY($posxval + 8, $posy);
1603 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1604 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1606 $posy = $pdf->GetY() + 1;
1611 $pdf->SetFont(
'',
'', $default_font_size - 2);
1612 $pdf->SetXY($this->marge_gauche, $posy);
1613 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1614 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1616 $pdf->SetFont(
'',
'', $default_font_size - 2);
1617 $pdf->SetXY($posxval, $posy);
1618 $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);
1619 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1620 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1622 $posy = $pdf->GetY() + 3;
1626 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1627 $pdf->SetFont(
'',
'', $default_font_size - 2);
1628 $pdf->SetXY($this->marge_gauche, $posy);
1629 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1630 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1632 $pdf->SetFont(
'',
'', $default_font_size - 2);
1633 $pdf->SetXY($posxval, $posy);
1634 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1635 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1637 $posy = $pdf->GetY() + 3;
1642 if (empty(
$object->mode_reglement_code)
1645 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1649 $outputlangs->load(
"errors");
1651 $pdf->SetXY($this->marge_gauche, $posy);
1652 $pdf->SetTextColor(200, 0, 0);
1653 $pdf->SetFont(
'',
'', $default_font_size - 2);
1654 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1655 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1656 $pdf->SetTextColor(0, 0, 0);
1658 $posy = $pdf->GetY() + 1;
1662 if (!empty(
$object->mode_reglement_code)
1663 &&
$object->mode_reglement_code !=
'CHQ'
1664 &&
$object->mode_reglement_code !=
'VIR') {
1665 $pdf->SetFont(
'',
'', $default_font_size - 2);
1666 $pdf->SetXY($this->marge_gauche, $posy);
1667 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1668 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1670 $pdf->SetFont(
'',
'', $default_font_size - 2);
1671 $pdf->SetXY($posxval, $posy);
1672 $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);
1675 if (
$object->mode_reglement_code ==
"PRE") {
1676 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1679 $bac->fetch(0,
'',
$object->thirdparty->id);
1680 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1681 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1684 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1686 $posy = $pdf->GetY();
1692 if ($this->emetteur->country_code ==
'FR') {
1694 $pdf->SetXY($this->marge_gauche, $posy);
1695 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1697 $posy = $pdf->GetY() + 1;
1702 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1703 $useonlinepayment = 0;
1707 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1708 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1709 $useonlinepayment = count($validpaymentmethod);
1714 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1717 $langs->loadLangs(array(
'payment',
'stripe'));
1718 $servicename = $langs->transnoentities(
'Online');
1719 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1720 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1722 $pdf->SetXY($this->marge_gauche, $posy);
1723 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1725 $posy = $pdf->GetY() + 1;
1730 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1736 $account =
new Account($this->db);
1739 $pdf->SetXY($this->marge_gauche, $posy);
1740 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1741 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1742 $posy = $pdf->GetY() + 1;
1745 $pdf->SetXY($this->marge_gauche, $posy);
1746 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1747 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1748 $posy = $pdf->GetY() + 2;
1752 $pdf->SetXY($this->marge_gauche, $posy);
1753 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1754 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1755 $posy = $pdf->GetY() + 1;
1758 $pdf->SetXY($this->marge_gauche, $posy);
1759 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1760 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1761 $posy = $pdf->GetY() + 2;
1768 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1774 $account =
new Account($this->db);
1775 $account->fetch($bankid);
1777 $curx = $this->marge_gauche;
1780 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1788 $qrCodeColor = array(
'25',
'25',
'25');
1792 'fgcolor' => $qrCodeColor,
1794 'module_width' => 1,
1795 'module_height' => 1
1798 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1799 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr,
'N');
1801 $pdf->SetXY($qrPosX + 30, $posy + 5);
1802 $pdf->SetFont(
'',
'', $default_font_size - 5);
1803 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1804 $posy = $pdf->GetY() + 2;
1809 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1812 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1835 global $conf,
$mysoc, $hookmanager;
1845 $outputlangsbis =
new Translate(
'', $conf);
1847 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1848 $default_font_size--;
1851 $tab2_top = $posy - 4;
1853 if (is_object($outputlangsbis)) {
1854 $pdf->SetFont(
'',
'', $default_font_size - 2);
1856 $pdf->SetFont(
'',
'', $default_font_size - 1);
1862 if ($this->page_largeur < 210) {
1866 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1872 $pdf->SetFillColor(255, 255, 255);
1873 $pdf->SetXY($col1x, $tab2_top + 0);
1874 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1877 $pdf->SetXY($col2x, $tab2_top + 0);
1878 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1882 $pdf->SetFillColor(255, 255, 255);
1883 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1884 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1886 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1887 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1891 $pdf->SetFillColor(248, 248, 248);
1894 $total_ttc_origin =
$object->total_ttc;
1896 $this->atleastoneratenotnull = 0;
1898 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1899 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1903 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1904 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1908 foreach ($localtax_rate as $tvakey => $tvaval) {
1909 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1913 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1916 if (preg_match(
'/\*/', (
string) $tvakey)) {
1917 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1918 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1921 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1925 $totalvat .= $tvacompl;
1927 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1930 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1934 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1935 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1941 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1942 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1946 foreach ($localtax_rate as $tvakey => $tvaval) {
1947 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1951 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1954 if (preg_match(
'/\*/', (
string) $tvakey)) {
1955 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1956 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1958 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1962 $totalvat .= $tvacompl;
1964 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1967 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1971 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1972 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1981 $nblines = count(
$object->lines);
1982 for ($i = 0; $i < $nblines; $i++) {
1983 $tvaligne =
$object->lines[$i]->total_tva;
1984 $vatrate = (string)
$object->lines[$i]->tva_tx;
1986 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
1989 if (! isset($tvas[$vatrate])) {
1990 $tvas[$vatrate] = 0;
1992 $tvas[$vatrate] += $tvaligne;
1995 foreach ($tvas as $tvakey => $tvaval) {
1997 $this->atleastoneratenotnull++;
2000 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2003 if (preg_match(
'/\*/', $tvakey)) {
2004 $tvakey = str_replace(
'*',
'', $tvakey);
2005 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2007 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
2010 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
2012 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
2014 $totalvat .= $tvacompl;
2016 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
2018 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2020 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2021 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
2027 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
2028 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2032 foreach ($localtax_rate as $tvakey => $tvaval) {
2033 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
2037 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2040 if (preg_match(
'/\*/', (
string) $tvakey)) {
2041 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2042 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2044 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
2048 $totalvat .= $tvacompl;
2050 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2053 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2057 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2058 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2064 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
2065 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2069 foreach ($localtax_rate as $tvakey => $tvaval) {
2071 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
2075 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2078 if (preg_match(
'/\*/', (
string) $tvakey)) {
2079 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2080 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2082 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
2086 $totalvat .= $tvacompl;
2088 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2091 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2095 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2096 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2105 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2106 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
2108 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2109 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
2114 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2115 $pdf->SetTextColor(0, 0, 60);
2116 $pdf->SetFillColor(224, 224, 224);
2117 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
2119 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2121 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2123 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2127 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2128 $pdf->SetTextColor(0, 0, 60);
2129 $pdf->SetFillColor(224, 224, 224);
2130 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2132 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2133 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2138 if (
$object->displayRetainedWarranty()) {
2139 $pdf->SetTextColor(40, 40, 40);
2140 $pdf->SetFillColor(255, 255, 255);
2142 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2143 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2147 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2148 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2150 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2151 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2155 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2157 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2158 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2160 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2161 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2162 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2167 $pdf->SetTextColor(0, 0, 0);
2175 if ($deja_regle > 0) {
2179 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2180 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
2182 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2183 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
2202 $pdf->SetTextColor(0, 0, 60);
2203 $pdf->SetFillColor(224, 224, 224);
2204 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2205 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
2206 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2207 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2209 $pdf->SetFont(
'',
'', $default_font_size - 1);
2210 $pdf->SetTextColor(0, 0, 0);
2213 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2215 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2217 $this->error = $hookmanager->error;
2218 $this->errors = $hookmanager->errors;
2222 return ($tab2_top + ($tab2_hl * $index));
2348 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2351 global $conf, $langs;
2353 $ltrdirection =
'L';
2354 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2355 $ltrdirection =
'R';
2359 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2365 $pdf->SetTextColor(0, 0, 60);
2366 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2370 $posy = $this->marge_haute;
2371 $posx = $this->page_largeur - $this->marge_droite - $w;
2373 $pdf->SetXY($this->marge_gauche, $posy);
2377 if ($this->emetteur->logo) {
2378 $logodir = $conf->mycompany->dir_output;
2379 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
2380 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
2383 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2385 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2387 if (is_readable($logo)) {
2389 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2391 $pdf->SetTextColor(200, 0, 0);
2392 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2393 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2394 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2397 $text = $this->emetteur->name;
2398 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2402 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2403 $pdf->SetXY($posx, $posy);
2404 $pdf->SetTextColor(0, 0, 60);
2405 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2407 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2410 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2413 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2416 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2418 if ($this->situationinvoice) {
2419 $outputlangs->loadLangs(array(
"other"));
2420 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" (#".((int)
$object->situation_counter).
")";
2422 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2425 if ($this->situationinvoice) {
2426 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2428 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2429 } elseif (
$object->type == 1) {
2430 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2431 } elseif (
$object->type == 2) {
2432 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2433 } elseif (
$object->type == 3) {
2434 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2435 } elseif (
$object->type == 4) {
2436 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2439 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2440 if (
$object->status == $object::STATUS_DRAFT) {
2441 $pdf->SetTextColor(128, 0, 0);
2442 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2445 $pdf->MultiCell($w, 3, $title,
'',
'R');
2447 $pdf->SetFont(
'',
'', $default_font_size - 2);
2464 $pdf->SetFont(
'',
'', $default_font_size - 2);
2468 $pdf->SetXY($posx, $posy);
2469 $pdf->SetTextColor(0, 0, 60);
2470 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2475 if (!empty(
$object->project->ref)) {
2477 $pdf->SetXY($posx, $posy);
2478 $pdf->SetTextColor(0, 0, 60);
2479 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2485 if (!empty(
$object->project->ref)) {
2486 $outputlangs->load(
"projects");
2488 $pdf->SetXY($posx, $posy);
2489 $pdf->SetTextColor(0, 0, 60);
2490 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2494 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2495 if (
$object->type == 0 && $objectidnext) {
2496 $objectreplacing =
new Facture($this->db);
2497 $objectreplacing->fetch($objectidnext);
2500 $pdf->SetXY($posx, $posy);
2501 $pdf->SetTextColor(0, 0, 60);
2502 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2505 $objectreplaced =
new Facture($this->db);
2506 $objectreplaced->fetch(
$object->fk_facture_source);
2509 $pdf->SetXY($posx, $posy);
2510 $pdf->SetTextColor(0, 0, 60);
2511 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2514 $objectreplaced =
new Facture($this->db);
2515 $objectreplaced->fetch(
$object->fk_facture_source);
2518 $pdf->SetXY($posx, $posy);
2519 $pdf->SetTextColor(0, 0, 60);
2520 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2524 $pdf->SetXY($posx, $posy);
2525 $pdf->SetTextColor(0, 0, 60);
2527 $title = $outputlangs->transnoentities(
"DateInvoice");
2528 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2529 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2531 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2535 $pdf->SetXY($posx, $posy);
2536 $pdf->SetTextColor(0, 0, 60);
2537 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2542 $pdf->SetXY($posx, $posy);
2543 $pdf->SetTextColor(0, 0, 60);
2544 $title = $outputlangs->transnoentities(
"DateDue");
2545 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2546 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2548 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2553 $pdf->SetXY($posx, $posy);
2554 $pdf->SetTextColor(0, 0, 60);
2555 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2560 $pdf->SetXY($posx, $posy);
2561 $pdf->SetTextColor(0, 0, 60);
2562 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2567 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2568 if (count($arrayidcontact) > 0) {
2569 $usertmp =
new User($this->db);
2570 $usertmp->fetch($arrayidcontact[0]);
2572 $pdf->SetXY($posx, $posy);
2573 $pdf->SetTextColor(0, 0, 60);
2574 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2584 $current_y = $pdf->getY();
2586 if ($current_y < $pdf->getY()) {
2587 $top_shift = $pdf->getY() - $current_y;
2597 $posy += $top_shift;
2598 $posx = $this->marge_gauche;
2600 $posx = $this->page_largeur - $this->marge_droite - 80;
2608 $pdf->SetTextColor(0, 0, 0);
2609 $pdf->SetFont(
'',
'', $default_font_size - 2);
2610 $pdf->SetXY($posx, $posy - 5);
2611 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2612 $pdf->SetXY($posx, $posy);
2613 $pdf->SetFillColor(230, 230, 230);
2614 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2615 $pdf->SetTextColor(0, 0, 60);
2620 $pdf->SetXY($posx + 2, $posy + 3);
2621 $pdf->SetFont(
'',
'B', $default_font_size);
2622 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2623 $posy = $pdf->getY();
2627 $pdf->SetXY($posx + 2, $posy);
2628 $pdf->SetFont(
'',
'', $default_font_size - 1);
2629 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2632 $usecontact =
false;
2633 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2634 if (count($arrayidcontact) > 0) {
2636 $result =
$object->fetch_contact($arrayidcontact[0]);
2640 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2641 $thirdparty =
$object->contact;
2643 $thirdparty =
$object->thirdparty;
2653 if ($this->page_largeur < 210) {
2657 $posy += $top_shift;
2658 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2660 $posx = $this->marge_gauche;
2665 $pdf->SetTextColor(0, 0, 0);
2666 $pdf->SetFont(
'',
'', $default_font_size - 2);
2667 $pdf->SetXY($posx + 2, $posy - 5);
2668 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2669 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2673 $pdf->SetXY($posx + 2, $posy + 3);
2674 $pdf->SetFont(
'',
'B', $default_font_size);
2676 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2678 $posy = $pdf->getY();
2681 $pdf->SetFont(
'',
'', $default_font_size - 1);
2682 $pdf->SetXY($posx + 2, $posy);
2684 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2688 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2690 if (!empty($idaddressshipping)) {
2691 $object->fetch_contact($idaddressshipping[0]);
2692 $companystatic =
new Societe($this->db);
2693 $companystatic->fetch(
$object->contact->fk_soc);
2700 if (!empty($carac_client_shipping)) {
2701 $posy += $hautcadre;
2706 $pdf->SetXY($posx + 2, $posy - 5);
2707 $pdf->SetFont(
'',
'', $default_font_size - 2);
2708 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2709 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2712 $pdf->SetXY($posx + 2, $posy + 3);
2713 $pdf->SetFont(
'',
'B', $default_font_size);
2714 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2716 $posy = $pdf->getY();
2719 $pdf->SetXY($posx + 2, $posy);
2720 $pdf->SetFont(
'',
'', $default_font_size - 1);
2721 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2723 $shipp_shift += $hautcadre;
2728 $pdf->SetTextColor(0, 0, 0);
2730 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);
3054 public function tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
3058 $form =
new Form($db);
3062 if (!$displayWarranty) {
3073 $currency = !empty($currency) ? $currency : (string) $conf->currency;
3077 $pdf->SetTextColor(0, 0, 0);
3078 $pdf->SetFont(
'',
'', $default_font_size - 2);
3080 if (empty($hidetop)) {
3081 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
3082 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
3083 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
3085 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
3089 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius,
'1001',
'F', explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
3091 $pdf->RoundedRect($this->marge_gauche, $tab_top + 92.5, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius,
'1001',
'F', array(), explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
3095 $pdf->SetDrawColor(128, 128, 128);
3096 $pdf->SetFont(
'',
'', $default_font_size - 1);
3100 $this->
printRoundedRectBtp($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom,
'D');
3102 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
3103 if (empty($hidetop)) {
3104 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
3105 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceOldCumulation"),
'',
'C');
3109 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
3110 if (empty($hidetop)) {
3111 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
3112 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceNewCumulation"),
'',
'C');
3115 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
3116 if (empty($hidetop)) {
3117 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
3118 $pdf->MultiCell(36, 2, $outputlangs->transnoentities(
"CurrentSituationTotal", (
string)
$object->situation_counter),
'',
'C');
3122 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
3124 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
3126 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
3128 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
3130 if ($displayWarranty) {
3131 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
3137 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
3138 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceMainTask"),
'',
'L');
3140 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
3141 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceAdditionalTask"),
'',
'L');
3143 $form->load_cache_vatrates(
"'".
$object->thirdparty->country_code.
"'");
3146 foreach ($form->cache_vatrates as $TVatInfo) {
3147 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
3149 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
3154 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
3155 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalHT").
' '.$TVatInfo[
'label'],
'',
'L');
3157 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
3158 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
3159 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"VAT").
' '.$TVatInfo[
'label'],
'',
'L');
3165 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
3166 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalTTC"),
'',
'L');
3169 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3170 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
3171 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalSituationInvoice"),
'',
'L');
3172 $pdf->SetFont(
'',
'', $default_font_size - 2);
3174 if ($displayWarranty) {
3175 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
3176 $pdf->MultiCell(80, 2, $outputlangs->trans(
"TotalSituationInvoiceWithRetainedWarranty", (
string)
$object->retained_warranty),
'',
'L');
3177 $nextY = $tab_top + 93;
3179 $nextY = $tab_top + 74;
3182 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3183 $pdf->SetXY($this->marge_gauche + 2, $nextY);
3184 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"SituationTotalRayToRest"),
'',
'L');
3185 $pdf->SetFont(
'',
'', $default_font_size - 2);
3189 $TToDisplay = array(
3195 $x = $this->marge_gauche + 85;
3199 foreach ($TToDisplay as $col) {
3201 $pdf->SetXY($x, $tab_top + 8);
3202 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
3205 $pdf->SetXY($x, $tab_top + 12);
3206 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'travaux_sup'], 0,
'', 1, -1, 2),
'',
'R');
3209 foreach ($form->cache_vatrates as $TVatInfo) {
3210 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
3211 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
3217 $pdf->SetXY($x, $tab_top + 24 + $i);
3218 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
3221 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
3222 $pdf->SetXY($x, $tab_top + 28 + $i);
3223 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'TVA'], 0,
'', 1, -1, 2),
'',
'R');
3230 $pdf->SetXY($x, $tab_top + 33 + $i);
3231 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
3234 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3235 $pdf->SetXY($x, $tab_top + 58);
3236 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
3237 $pdf->SetFont(
'',
'', $default_font_size - 2);
3240 if ($displayWarranty) {
3242 $pdf->SetXY($x, $tab_top + 74);
3243 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'retenue_garantie'], 0,
'', 1, -1, 2),
'',
'R');
3244 $nextY = $tab_top + 93;
3246 $nextY = $tab_top + 74;
3250 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3251 $pdf->SetXY($x, $nextY);
3252 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'total_a_payer'], 0,
'', 1, -1, 2),
'',
'R');
3253 $pdf->SetFont(
'',
'', $default_font_size - 2);