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);
639 $this->tab_top = $this->tab_top_newpage;
640 $nexY = $this->tab_top - 1;
643 $height_incoterms = 0;
645 $desc_incoterms =
$object->getIncotermsForPDF();
646 if ($desc_incoterms) {
649 $pdf->SetFont(
'',
'', $default_font_size - 1);
650 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
651 $nexY = max($pdf->GetY(), $nexY);
652 $height_incoterms = $nexY - $this->tab_top;
655 $pdf->SetDrawColor(192, 192, 192);
656 $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');
658 $this->tab_top = $nexY + 6;
659 $height_incoterms += 4;
664 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
667 if (is_object(
$object->thirdparty)) {
668 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
669 $salerepobj =
new User($this->db);
670 $salerepobj->fetch($salereparray[0][
'id']);
671 if (!empty($salerepobj->signature)) {
672 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
678 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
679 if (!empty($extranote)) {
683 $pagenb = $pdf->getPage();
687 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
688 $pageposbeforenote = $pagenb;
695 $pdf->startTransaction();
697 $pdf->SetFont(
'',
'', $default_font_size - 1);
698 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
700 $pageposafternote = $pdf->getPage();
701 $posyafter = $pdf->GetY();
703 if ($pageposafternote > $pageposbeforenote) {
704 $pdf->rollbackTransaction(
true);
707 while ($pagenb < $pageposafternote) {
710 if (!empty($this->tplidx)) {
711 $pdf->useTemplate($this->tplidx);
716 $pdf->setTopMargin($this->tab_top_newpage);
718 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
722 $pdf->setPage($pageposbeforenote);
723 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
724 $pdf->SetFont(
'',
'', $default_font_size - 1);
725 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
726 $pageposafternote = $pdf->getPage();
728 $posyafter = $pdf->GetY();
730 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
731 $pdf->AddPage(
'',
'',
true);
734 $pdf->setPage($pageposafternote);
735 $pdf->setTopMargin($this->tab_top_newpage);
737 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
743 $i = $pageposbeforenote;
744 while ($i < $pageposafternote) {
748 $pdf->SetDrawColor(128, 128, 128);
750 if ($i > $pageposbeforenote) {
751 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
752 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
754 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
755 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
759 $pdf->setPageOrientation(
'',
true, 0);
766 $pdf->setPage($pageposafternote);
767 if (!empty($this->tplidx)) {
768 $pdf->useTemplate($this->tplidx);
773 $height_note = $posyafter - $this->tab_top_newpage;
774 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
777 $pdf->commitTransaction();
778 $posyafter = $pdf->GetY();
779 $height_note = $posyafter - $this->tab_top;
780 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
783 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
785 $pdf->AddPage(
'',
'',
true);
788 $pdf->setPage($pageposafternote);
789 if (!empty($this->tplidx)) {
790 $pdf->useTemplate($this->tplidx);
796 $posyafter = $this->tab_top_newpage;
800 $tab_height -= $height_note;
801 $this->tab_top = $posyafter + 6;
817 $nexY = $this->tab_top + $this->tabTitleHeight;
823 $linetop_newpage = $this->tab_top_newpage + $this->tabTitleHeight;
830 $topmargin_newpage = $linetop_newpage + (isset($this->cols[
'desc'][
'content'][
'padding'][0]) ? $this->cols[
'desc'][
'content'][
'padding'][0] : 0);
833 $pageposbeforeprintlines = $pdf->getPage();
834 $pagenb = $pageposbeforeprintlines;
836 for ($i = 0; $i < $nblines; $i++) {
837 $linePosition = $i + 1;
841 $pdf->SetFont(
'',
'', $default_font_size - 1);
842 $pdf->SetTextColor(0, 0, 0);
845 $imglinesize = array();
846 if (!empty($realpatharray[$i])) {
850 $pdf->setTopMargin($topmargin_newpage);
851 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot);
852 $pageposbefore = $pdf->getPage();
855 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
858 $posYAfterDescription = 0;
863 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($posy + $imglinesize[
'height']) > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
864 $pdf->AddPage(
'',
'',
true);
865 if (!empty($this->tplidx)) {
866 $pdf->useTemplate($this->tplidx);
868 $pdf->setPage($pageposbefore + 1);
869 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
870 $posy = $linetop_newpage;
871 $showpricebeforepagebreak = 0;
875 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
876 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $posy + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
878 $posYAfterImage = $posy + $imglinesize[
'height'];
885 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
889 $pdf->startTransaction();
892 $pageposafter = $pdf->getPage();
894 if ($pageposafter > $pageposbefore) {
895 $pdf->rollbackTransaction(
true);
896 $pageposafter = $pageposbefore;
897 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
901 $pageposafter = $pdf->getPage();
902 $posyafter = $pdf->GetY();
904 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
905 if ($i == ($nblines - 1)) {
906 $pdf->AddPage(
'',
'',
true);
907 if (!empty($this->tplidx)) {
908 $pdf->useTemplate($this->tplidx);
910 $pdf->setPage($pageposafter + 1);
916 $showpricebeforepagebreak = 1;
918 $showpricebeforepagebreak = 0;
922 $pdf->commitTransaction();
924 $posYAfterDescription = $pdf->GetY();
927 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
929 $pageposafter = $pdf->getPage();
930 $pdf->setPage($pageposbefore);
931 $pdf->setTopMargin($this->marge_haute);
932 $pdf->setPageOrientation(
'',
true, 0);
935 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
936 $pdf->setPage($pageposafter);
937 $posy = $linetop_newpage;
940 $pdf->SetFont(
'',
'', $default_font_size - 1);
951 $nexY = max($pdf->GetY(), $nexY);
958 $nexY = max($pdf->GetY(), $nexY);
966 $nexY = max($pdf->GetY(), $nexY);
973 $nexY = max($pdf->GetY(), $nexY);
980 $nexY = max($pdf->GetY(), $nexY);
987 $nexY = max($pdf->GetY(), $nexY);
994 $nexY = max($pdf->GetY(), $nexY);
1001 $columkey =
'btpsomme';
1003 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht_without_progress'], 0,
'', 1, -1, 2);
1005 $nexY = max($pdf->GetY(), $nexY);
1009 $columkey =
'progress_amount';
1011 $printval =
price(
$object->lines[$i]->total_ht, 0,
'', 1, -1, 2);
1013 $nexY = max($pdf->GetY(), $nexY);
1016 $columkey =
'prev_progress';
1018 $printval = $TInfosLigneSituationPrecedente[
'progress_prec'].
'%';
1020 $nexY = max($pdf->GetY(), $nexY);
1023 $columkey =
'prev_progress_amount';
1025 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht'], 0,
'', 1, -1, 2);
1027 $nexY = max($pdf->GetY(), $nexY);
1031 $parameters = array(
1036 'nexY' => & $afterPosData[
'y'],
1037 'outputlangs' => $outputlangs,
1038 'hidedetails' => $hidedetails
1040 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
1048 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
1049 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
1051 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
1053 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
1057 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
1059 $tvaligne = $sign *
$object->lines[$i]->total_tva;
1063 $localtax1ligne =
$object->lines[$i]->total_localtax1;
1064 $localtax2ligne =
$object->lines[$i]->total_localtax2;
1065 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
1066 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
1067 $localtax1_type =
$object->lines[$i]->localtax1_type;
1068 $localtax2_type =
$object->lines[$i]->localtax2_type;
1070 $vatrate = (string)
$object->lines[$i]->tva_tx;
1073 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
1074 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
1076 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
1077 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
1081 if ($localtax1_type && $localtax1ligne != 0) {
1082 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
1083 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
1085 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
1088 if ($localtax2_type && $localtax2ligne != 0) {
1089 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
1090 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
1092 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
1096 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
1101 if (!isset($this->tva[$vatrate])) {
1102 $this->tva[$vatrate] = 0;
1104 $this->tva[$vatrate] += $tvaligne;
1105 $vatcode =
$object->lines[$i]->vat_src_code;
1106 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
1107 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
1110 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
1111 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
1113 $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);
1115 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1119 $pdf->setPage($afterPosData[
'page']);
1120 $nexY = max($nexY, $posYAfterImage);
1123 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1124 $pdf->setPage($pageposafter);
1125 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1127 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1128 $pdf->SetLineStyle(array(
'dash' => 0));
1132 while ($pagenb < $pageposafter) {
1133 $pdf->setPage($pagenb);
1134 $tabtop = $this->tab_top;
1135 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1136 if ($pagenb != $pageposbeforeprintlines) {
1137 $tabtop = $this->tab_top_newpage;
1138 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1141 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1145 $pdf->setPage($pagenb);
1146 $pdf->setPageOrientation(
'',
true, 0);
1150 if (!empty($this->tplidx)) {
1151 $pdf->useTemplate($this->tplidx);
1155 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
1156 $tabtop = $this->tab_top;
1157 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1158 if ($pagenb != $pageposbeforeprintlines) {
1159 $tabtop = $this->tab_top_newpage;
1160 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1163 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1168 if (!empty($this->tplidx)) {
1169 $pdf->useTemplate($this->tplidx);
1182 $tabtop = ($pdf->getPage() == $pageposbeforeprintlines) ? $this->tab_top : $this->tab_top_newpage;
1183 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1184 $tabTitleHeight = 0;
1185 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1188 $pdf->SetTextColor(0, 0, 0);
1190 $pdf->setPage($pdf->getNumPages());
1192 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1199 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1202 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1203 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1210 if (method_exists($pdf,
'AliasNbPages')) {
1211 $pdf->AliasNbPages();
1215 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1216 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
1217 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
1218 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
1220 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1221 $pagecount = $pdf->setSourceFile($termsofsale);
1222 for ($i = 1; $i <= $pagecount; $i++) {
1223 $tplIdx = $pdf->importPage($i);
1224 if ($tplIdx !==
false) {
1225 $s = $pdf->getTemplatesize($tplIdx);
1226 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1227 $pdf->useTemplate($tplIdx);
1229 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1235 $this->resumeLastPage($pdf,
$object, 0, $tab_top, $outputlangs, $outputlangsbis);
1236 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1245 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1246 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
1247 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
1248 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
1250 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1251 $pagecount = $pdf->setSourceFile($termsofsale);
1252 for ($i = 1; $i <= $pagecount; $i++) {
1253 $tplIdx = $pdf->importPage($i);
1254 if ($tplIdx !==
false) {
1255 $s = $pdf->getTemplatesize($tplIdx);
1256 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1257 $pdf->useTemplate($tplIdx);
1259 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1267 $pdf->Output($file,
'F');
1270 $hookmanager->initHooks(array(
'pdfgeneration'));
1271 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1273 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1274 $this->warnings = $hookmanager->warnings;
1276 $this->error = $hookmanager->error;
1277 $this->errors = $hookmanager->errors;
1284 $this->result = array(
'fullpath' => $file);
1288 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1292 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1452 global $conf,
$mysoc, $hookmanager;
1456 $pdf->SetFont(
'',
'', $default_font_size - 1);
1458 krsort($this->tva_array);
1465 $pdf->SetFillColor(224, 224, 224);
1467 $pdf->SetFont(
'',
'', $default_font_size - 2);
1468 $pdf->SetXY($this->marge_gauche, $posy);
1469 $titre = $outputlangs->transnoentities(
"VAT");
1470 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1472 $pdf->SetFont(
'',
'', $default_font_size - 2);
1473 $pdf->SetXY($this->marge_gauche + 25, $posy);
1474 $titre = $outputlangs->transnoentities(
"NetTotal");
1475 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1477 $pdf->SetFont(
'',
'', $default_font_size - 2);
1478 $pdf->SetXY($this->marge_gauche + 50, $posy);
1479 $titre = $outputlangs->transnoentities(
"VATAmount");
1480 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1482 $pdf->SetFont(
'',
'', $default_font_size - 2);
1483 $pdf->SetXY($this->marge_gauche + 75, $posy);
1484 $titre = $outputlangs->transnoentities(
"AmountTotal");
1485 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1487 $posy = $pdf->GetY();
1492 foreach ($this->tva_array as $tvakey => $tvaval) {
1493 $pdf->SetFont(
'',
'', $default_font_size - 2);
1494 $pdf->SetXY($this->marge_gauche, $posy);
1495 $titre = round((
float) $tvakey, 2) .
"%";
1496 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1498 $pdf->SetFont(
'',
'', $default_font_size - 2);
1499 $pdf->SetXY($this->marge_gauche + 25, $posy);
1500 $titre =
price($tvaval[
'tot_ht']);
1501 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1502 $tot_ht += $tvaval[
'tot_ht'];
1504 $pdf->SetFont(
'',
'', $default_font_size - 2);
1505 $pdf->SetXY($this->marge_gauche + 50, $posy);
1506 $titre =
price($tvaval[
'amount']);
1507 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1508 $tot_tva += $tvaval[
'amount'];
1510 $pdf->SetFont(
'',
'', $default_font_size - 2);
1511 $pdf->SetXY($this->marge_gauche + 75, $posy);
1512 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1513 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1514 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1516 $posy = $pdf->GetY();
1521 $showvatmention = 0;
1522 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1523 $pdf->SetFont(
'',
'', $default_font_size - 2);
1524 $pdf->SetXY($this->marge_gauche, $posy);
1525 if (empty(
$mysoc->tva_assuj)) {
1526 if (
$mysoc->forme_juridique_code == 92) {
1527 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1529 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1532 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1533 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1536 $posy = $pdf->GetY();
1539 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1541 if ($showvatmention) {
1548 if ($this->page_largeur < 210) {
1555 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1556 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1557 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1558 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1559 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1560 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1561 $sql .=
" AND f.fk_statut > 0";
1562 $sql .=
" ORDER BY f.datef ASC";
1565 $invoices = array();
1566 $resql = $this->db->query($sql);
1568 while ($obj = $this->db->fetch_object($resql)) {
1570 $old_balance += $obj->total_ttc;
1572 $this->db->free($resql);
1576 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1577 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1578 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1579 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1580 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1581 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1582 $sql_payments .=
" ORDER BY p.datep ASC";
1584 $total_payments = 0;
1585 $resql_payments = $this->db->query($sql_payments);
1586 if ($resql_payments) {
1587 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1588 $total_payments += $obj_payment->amount;
1590 $this->db->free($resql_payments);
1594 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1595 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1596 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1597 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1598 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1599 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1601 $current_date_payments = 0;
1602 $resql_current_date = $this->db->query($sql_current_date_payments);
1603 if ($resql_current_date) {
1604 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1605 $current_date_payments += $obj_current->amount;
1607 $this->db->free($resql_current_date);
1611 $old_balance -= $total_payments;
1614 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1616 $pdf->SetFillColor(224, 224, 224);
1617 $pdf->SetFont(
'',
'', $default_font_size - 2);
1618 $pdf->SetXY($this->marge_gauche, $posy);
1619 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1620 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1622 $pdf->SetFont(
'',
'', $default_font_size - 2);
1623 $pdf->SetXY($posxval + 8, $posy);
1624 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1625 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1627 $posy = $pdf->GetY() + 1;
1632 $pdf->SetFont(
'',
'', $default_font_size - 2);
1633 $pdf->SetXY($this->marge_gauche, $posy);
1634 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1635 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1637 $pdf->SetFont(
'',
'', $default_font_size - 2);
1638 $pdf->SetXY($posxval, $posy);
1639 $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);
1640 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1641 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1643 $posy = $pdf->GetY() + 3;
1647 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1648 $pdf->SetFont(
'',
'', $default_font_size - 2);
1649 $pdf->SetXY($this->marge_gauche, $posy);
1650 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1651 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1653 $pdf->SetFont(
'',
'', $default_font_size - 2);
1654 $pdf->SetXY($posxval, $posy);
1655 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1656 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1658 $posy = $pdf->GetY() + 3;
1663 if (empty(
$object->mode_reglement_code)
1666 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1670 $outputlangs->load(
"errors");
1672 $pdf->SetXY($this->marge_gauche, $posy);
1673 $pdf->SetTextColor(200, 0, 0);
1674 $pdf->SetFont(
'',
'', $default_font_size - 2);
1675 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1676 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1677 $pdf->SetTextColor(0, 0, 0);
1679 $posy = $pdf->GetY() + 1;
1683 if (!empty(
$object->mode_reglement_code)
1684 &&
$object->mode_reglement_code !=
'CHQ'
1685 &&
$object->mode_reglement_code !=
'VIR') {
1686 $pdf->SetFont(
'',
'', $default_font_size - 2);
1687 $pdf->SetXY($this->marge_gauche, $posy);
1688 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1689 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1691 $pdf->SetFont(
'',
'', $default_font_size - 2);
1692 $pdf->SetXY($posxval, $posy);
1693 $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);
1696 if (
$object->mode_reglement_code ==
"PRE") {
1697 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1700 $bac->fetch(0,
'',
$object->thirdparty->id);
1701 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1702 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1705 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1707 $posy = $pdf->GetY();
1713 if ($this->emetteur->country_code ==
'FR') {
1715 $pdf->SetXY($this->marge_gauche, $posy);
1716 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1718 $posy = $pdf->GetY() + 1;
1723 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1724 $useonlinepayment = 0;
1728 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1729 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1730 $useonlinepayment = count($validpaymentmethod);
1735 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1738 $langs->loadLangs(array(
'payment',
'stripe'));
1739 $servicename = $langs->transnoentities(
'Online');
1740 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1741 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1743 $pdf->SetXY($this->marge_gauche, $posy);
1744 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1746 $posy = $pdf->GetY() + 1;
1751 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1757 $account =
new Account($this->db);
1760 $pdf->SetXY($this->marge_gauche, $posy);
1761 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1762 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1763 $posy = $pdf->GetY() + 1;
1766 $pdf->SetXY($this->marge_gauche, $posy);
1767 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1768 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1769 $posy = $pdf->GetY() + 2;
1773 $pdf->SetXY($this->marge_gauche, $posy);
1774 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1775 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1776 $posy = $pdf->GetY() + 1;
1779 $pdf->SetXY($this->marge_gauche, $posy);
1780 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1781 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1782 $posy = $pdf->GetY() + 2;
1789 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1795 $account =
new Account($this->db);
1796 $account->fetch($bankid);
1798 $curx = $this->marge_gauche;
1801 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1809 $qrCodeColor = array(
'25',
'25',
'25');
1813 'fgcolor' => $qrCodeColor,
1815 'module_width' => 1,
1816 'module_height' => 1
1819 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1820 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr,
'N');
1822 $pdf->SetXY($qrPosX + 30, $posy + 5);
1823 $pdf->SetFont(
'',
'', $default_font_size - 5);
1824 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1825 $posy = $pdf->GetY() + 2;
1830 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1833 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1856 global $conf,
$mysoc, $hookmanager;
1866 $outputlangsbis =
new Translate(
'', $conf);
1868 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1869 $default_font_size--;
1872 $tab2_top = $posy - 4;
1874 if (is_object($outputlangsbis)) {
1875 $pdf->SetFont(
'',
'', $default_font_size - 2);
1877 $pdf->SetFont(
'',
'', $default_font_size - 1);
1883 if ($this->page_largeur < 210) {
1887 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1893 $pdf->SetFillColor(255, 255, 255);
1894 $pdf->SetXY($col1x, $tab2_top + 0);
1895 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1898 $pdf->SetXY($col2x, $tab2_top + 0);
1899 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1903 $pdf->SetFillColor(255, 255, 255);
1904 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1905 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1907 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1908 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1912 $pdf->SetFillColor(248, 248, 248);
1915 $total_ttc_origin =
$object->total_ttc;
1917 $this->atleastoneratenotnull = 0;
1919 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1920 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1924 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1925 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1929 foreach ($localtax_rate as $tvakey => $tvaval) {
1930 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1934 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1937 if (preg_match(
'/\*/', (
string) $tvakey)) {
1938 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1939 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1942 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1946 $totalvat .= $tvacompl;
1948 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1951 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1955 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1956 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1962 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1963 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1967 foreach ($localtax_rate as $tvakey => $tvaval) {
1968 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1972 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1975 if (preg_match(
'/\*/', (
string) $tvakey)) {
1976 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1977 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1979 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1983 $totalvat .= $tvacompl;
1985 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1988 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1992 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1993 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2001 foreach ($this->tva_array as $tvakey => $tvaval) {
2003 $this->atleastoneratenotnull++;
2006 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2009 if (preg_match(
'/\*/', $tvakey)) {
2010 $tvakey = str_replace(
'*',
'', $tvakey);
2011 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2013 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
2016 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
2018 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
2020 $totalvat .= $tvacompl;
2022 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
2024 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2026 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2027 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
2033 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
2034 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2038 foreach ($localtax_rate as $tvakey => $tvaval) {
2039 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
2043 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2046 if (preg_match(
'/\*/', (
string) $tvakey)) {
2047 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2048 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2050 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
2054 $totalvat .= $tvacompl;
2056 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2059 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2063 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2064 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2070 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
2071 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2075 foreach ($localtax_rate as $tvakey => $tvaval) {
2077 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
2081 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2084 if (preg_match(
'/\*/', (
string) $tvakey)) {
2085 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2086 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2088 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
2092 $totalvat .= $tvacompl;
2094 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2097 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2101 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2102 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2111 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2112 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
2114 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2115 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
2120 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2121 $pdf->SetTextColor(0, 0, 60);
2122 $pdf->SetFillColor(224, 224, 224);
2123 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
2125 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2127 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2129 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2133 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2134 $pdf->SetTextColor(0, 0, 60);
2135 $pdf->SetFillColor(224, 224, 224);
2136 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2138 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2139 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2144 if (
$object->displayRetainedWarranty()) {
2145 $pdf->SetTextColor(40, 40, 40);
2146 $pdf->SetFillColor(255, 255, 255);
2148 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2149 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2153 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2154 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2156 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2157 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2161 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2163 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2164 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2166 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2167 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2168 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2173 $pdf->SetTextColor(0, 0, 0);
2181 if ($deja_regle > 0) {
2185 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2186 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L',
false);
2188 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2189 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R',
false);
2208 $pdf->SetTextColor(0, 0, 60);
2209 $pdf->SetFillColor(224, 224, 224);
2210 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2211 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
2212 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2213 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2215 $pdf->SetFont(
'',
'', $default_font_size - 1);
2216 $pdf->SetTextColor(0, 0, 0);
2219 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2221 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2223 $this->error = $hookmanager->error;
2224 $this->errors = $hookmanager->errors;
2228 return ($tab2_top + ($tab2_hl * $index));
2354 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2357 global $conf, $langs;
2359 $ltrdirection =
'L';
2360 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2361 $ltrdirection =
'R';
2365 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2371 $pdf->SetTextColor(0, 0, 60);
2372 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2376 $posy = $this->marge_haute;
2377 $posx = $this->page_largeur - $this->marge_droite - $w;
2379 $pdf->SetXY($this->marge_gauche, $posy);
2383 if ($this->emetteur->logo) {
2384 $logodir = $conf->mycompany->dir_output;
2385 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
2386 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
2389 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2391 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2393 if (is_readable($logo)) {
2395 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2397 $pdf->SetTextColor(200, 0, 0);
2398 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2399 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2400 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2403 $text = $this->emetteur->name;
2404 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2408 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2409 $pdf->SetXY($posx, $posy);
2410 $pdf->SetTextColor(0, 0, 60);
2411 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2413 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2416 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2419 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2422 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2424 if ($this->situationinvoice) {
2425 $outputlangs->loadLangs(array(
"other"));
2426 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" (#".((int)
$object->situation_counter).
")";
2428 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2431 if ($this->situationinvoice) {
2432 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2434 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2435 } elseif (
$object->type == 1) {
2436 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2437 } elseif (
$object->type == 2) {
2438 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2439 } elseif (
$object->type == 3) {
2440 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2441 } elseif (
$object->type == 4) {
2442 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2445 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2446 if (
$object->status == $object::STATUS_DRAFT) {
2447 $pdf->SetTextColor(128, 0, 0);
2448 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2451 $pdf->MultiCell($w, 3, $title,
'',
'R');
2453 $pdf->SetFont(
'',
'', $default_font_size - 2);
2470 $pdf->SetFont(
'',
'', $default_font_size - 2);
2474 $pdf->SetXY($posx, $posy);
2475 $pdf->SetTextColor(0, 0, 60);
2476 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2481 if (!empty(
$object->project->ref)) {
2483 $pdf->SetXY($posx, $posy);
2484 $pdf->SetTextColor(0, 0, 60);
2485 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2491 if (!empty(
$object->project->ref)) {
2492 $outputlangs->load(
"projects");
2494 $pdf->SetXY($posx, $posy);
2495 $pdf->SetTextColor(0, 0, 60);
2496 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2500 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2501 if (
$object->type == 0 && $objectidnext) {
2502 $objectreplacing =
new Facture($this->db);
2503 $objectreplacing->fetch($objectidnext);
2506 $pdf->SetXY($posx, $posy);
2507 $pdf->SetTextColor(0, 0, 60);
2508 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2511 $objectreplaced =
new Facture($this->db);
2512 $objectreplaced->fetch(
$object->fk_facture_source);
2515 $pdf->SetXY($posx, $posy);
2516 $pdf->SetTextColor(0, 0, 60);
2517 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2520 $objectreplaced =
new Facture($this->db);
2521 $objectreplaced->fetch(
$object->fk_facture_source);
2524 $pdf->SetXY($posx, $posy);
2525 $pdf->SetTextColor(0, 0, 60);
2526 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2530 $pdf->SetXY($posx, $posy);
2531 $pdf->SetTextColor(0, 0, 60);
2533 $title = $outputlangs->transnoentities(
"DateInvoice");
2534 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2535 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2537 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2541 $pdf->SetXY($posx, $posy);
2542 $pdf->SetTextColor(0, 0, 60);
2543 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2548 $pdf->SetXY($posx, $posy);
2549 $pdf->SetTextColor(0, 0, 60);
2550 $title = $outputlangs->transnoentities(
"DateDue");
2551 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2552 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2554 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2559 $pdf->SetXY($posx, $posy);
2560 $pdf->SetTextColor(0, 0, 60);
2561 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2566 $pdf->SetXY($posx, $posy);
2567 $pdf->SetTextColor(0, 0, 60);
2568 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2573 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2574 if (count($arrayidcontact) > 0) {
2575 $usertmp =
new User($this->db);
2576 $usertmp->fetch($arrayidcontact[0]);
2578 $pdf->SetXY($posx, $posy);
2579 $pdf->SetTextColor(0, 0, 60);
2580 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2590 $current_y = $pdf->getY();
2592 if ($current_y < $pdf->getY()) {
2593 $top_shift = $pdf->getY() - $current_y;
2603 $posy += $top_shift;
2604 $posx = $this->marge_gauche;
2606 $posx = $this->page_largeur - $this->marge_droite - 80;
2614 $pdf->SetTextColor(0, 0, 0);
2615 $pdf->SetFont(
'',
'', $default_font_size - 2);
2616 $pdf->SetXY($posx, $posy - 5);
2617 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2618 $pdf->SetXY($posx, $posy);
2619 $pdf->SetFillColor(230, 230, 230);
2620 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2621 $pdf->SetTextColor(0, 0, 60);
2626 $pdf->SetXY($posx + 2, $posy + 3);
2627 $pdf->SetFont(
'',
'B', $default_font_size);
2628 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2629 $posy = $pdf->getY();
2633 $pdf->SetXY($posx + 2, $posy);
2634 $pdf->SetFont(
'',
'', $default_font_size - 1);
2635 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2638 $usecontact =
false;
2639 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2640 if (count($arrayidcontact) > 0) {
2642 $result =
$object->fetch_contact($arrayidcontact[0]);
2646 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2647 $thirdparty =
$object->contact;
2649 $thirdparty =
$object->thirdparty;
2659 if ($this->page_largeur < 210) {
2663 $posy += $top_shift;
2664 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2666 $posx = $this->marge_gauche;
2671 $pdf->SetTextColor(0, 0, 0);
2672 $pdf->SetFont(
'',
'', $default_font_size - 2);
2673 $pdf->SetXY($posx + 2, $posy - 5);
2674 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2675 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2679 $pdf->SetXY($posx + 2, $posy + 3);
2680 $pdf->SetFont(
'',
'B', $default_font_size);
2682 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2684 $posy = $pdf->getY();
2687 $pdf->SetFont(
'',
'', $default_font_size - 1);
2688 $pdf->SetXY($posx + 2, $posy);
2690 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2694 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2696 if (!empty($idaddressshipping)) {
2697 $object->fetch_contact($idaddressshipping[0]);
2698 $companystatic =
new Societe($this->db);
2699 $companystatic->fetch(
$object->contact->fk_soc);
2706 if (!empty($carac_client_shipping)) {
2707 $posy += $hautcadre;
2712 $pdf->SetXY($posx + 2, $posy - 5);
2713 $pdf->SetFont(
'',
'', $default_font_size - 2);
2714 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2715 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2718 $pdf->SetXY($posx + 2, $posy + 3);
2719 $pdf->SetFont(
'',
'B', $default_font_size);
2720 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2722 $posy = $pdf->getY();
2725 $pdf->SetXY($posx + 2, $posy);
2726 $pdf->SetFont(
'',
'', $default_font_size - 1);
2727 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2729 $shipp_shift += $hautcadre;
2734 $pdf->SetTextColor(0, 0, 0);
2736 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);
3060 public function tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
3064 $form =
new Form($db);
3068 if (!$displayWarranty) {
3079 $currency = !empty($currency) ? $currency : (string) $conf->currency;
3083 $pdf->SetTextColor(0, 0, 0);
3084 $pdf->SetFont(
'',
'', $default_font_size - 2);
3086 if (empty($hidetop)) {
3087 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
3088 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
3089 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
3091 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
3095 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius,
'1001',
'F', explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
3097 $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')));
3101 $pdf->SetDrawColor(128, 128, 128);
3102 $pdf->SetFont(
'',
'', $default_font_size - 1);
3106 $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');
3108 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
3109 if (empty($hidetop)) {
3110 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
3111 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceOldCumulation"),
'',
'C');
3115 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
3116 if (empty($hidetop)) {
3117 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
3118 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceNewCumulation"),
'',
'C');
3121 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
3122 if (empty($hidetop)) {
3123 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
3124 $pdf->MultiCell(36, 2, $outputlangs->transnoentities(
"CurrentSituationTotal", (
string)
$object->situation_counter),
'',
'C');
3128 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
3130 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
3132 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
3134 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
3136 if ($displayWarranty) {
3137 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
3143 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
3144 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceMainTask"),
'',
'L');
3146 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
3147 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceAdditionalTask"),
'',
'L');
3149 $form->load_cache_vatrates(
"'".
$object->thirdparty->country_code.
"'");
3152 foreach ($form->cache_vatrates as $TVatInfo) {
3153 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
3155 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
3160 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
3161 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalHT").
' '.$TVatInfo[
'label'],
'',
'L');
3163 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
3164 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
3165 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"VAT").
' '.$TVatInfo[
'label'],
'',
'L');
3171 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
3172 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalTTC"),
'',
'L');
3175 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3176 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
3177 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalSituationInvoice"),
'',
'L');
3178 $pdf->SetFont(
'',
'', $default_font_size - 2);
3180 if ($displayWarranty) {
3181 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
3182 $pdf->MultiCell(80, 2, $outputlangs->trans(
"TotalSituationInvoiceWithRetainedWarranty", (
string)
$object->retained_warranty),
'',
'L');
3183 $nextY = $tab_top + 93;
3185 $nextY = $tab_top + 74;
3188 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3189 $pdf->SetXY($this->marge_gauche + 2, $nextY);
3190 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"SituationTotalRayToRest"),
'',
'L');
3191 $pdf->SetFont(
'',
'', $default_font_size - 2);
3195 $TToDisplay = array(
3201 $x = $this->marge_gauche + 85;
3205 foreach ($TToDisplay as $col) {
3207 $pdf->SetXY($x, $tab_top + 8);
3208 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
3211 $pdf->SetXY($x, $tab_top + 12);
3212 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'travaux_sup'], 0,
'', 1, -1, 2),
'',
'R');
3215 foreach ($form->cache_vatrates as $TVatInfo) {
3216 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
3217 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
3223 $pdf->SetXY($x, $tab_top + 24 + $i);
3224 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
3227 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
3228 $pdf->SetXY($x, $tab_top + 28 + $i);
3229 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'TVA'], 0,
'', 1, -1, 2),
'',
'R');
3236 $pdf->SetXY($x, $tab_top + 33 + $i);
3237 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
3240 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3241 $pdf->SetXY($x, $tab_top + 58);
3242 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
3243 $pdf->SetFont(
'',
'', $default_font_size - 2);
3246 if ($displayWarranty) {
3248 $pdf->SetXY($x, $tab_top + 74);
3249 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'retenue_garantie'], 0,
'', 1, -1, 2),
'',
'R');
3250 $nextY = $tab_top + 93;
3252 $nextY = $tab_top + 74;
3256 $pdf->SetFont(
'',
'B', $default_font_size - 1);
3257 $pdf->SetXY($x, $nextY);
3258 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'total_a_payer'], 0,
'', 1, -1, 2),
'',
'R');
3259 $pdf->SetFont(
'',
'', $default_font_size - 2);