265 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
268 global $user, $langs,
$conf,
$mysoc, $hookmanager, $nblines;
270 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
272 if (!is_object($outputlangs)) {
273 $outputlangs = $langs;
277 $outputlangs->charset_output =
'ISO-8859-1';
281 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
283 global $outputlangsbis;
284 $outputlangsbis =
null;
288 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
292 setEventMessage($langs->trans(
'WarningsObjectIsNotASituation'),
'warnings');
300 $nblines = count(
$object->lines);
308 $realpatharray = array();
309 $this->atleastonephoto =
false;
311 $objphoto =
new Product($this->db);
313 for ($i = 0; $i < $nblines; $i++) {
314 if (empty(
$object->lines[$i]->fk_product)) {
318 $objphoto->fetch(
$object->lines[$i]->fk_product);
322 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
323 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
325 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
326 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
331 foreach ($pdir as $midir) {
333 $entity = $objphoto->entity;
334 if ($entity !==
null &&
$conf->entity != $entity) {
335 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
337 $dir =
$conf->product->dir_output.
'/'.$midir;
340 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
342 if ($obj[
'photo_vignette']) {
343 $filename = $obj[
'photo_vignette'];
345 $filename = $obj[
'photo'];
348 $filename = $obj[
'photo'];
351 $realpath = $dir.$filename;
353 $this->atleastonephoto =
true;
358 if (!empty($realpath) && $arephoto) {
359 $realpatharray[$i] = $realpath;
366 if (
$conf->facture->multidir_output[
$conf->entity]) {
370 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
371 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
375 $dir =
$conf->facture->multidir_output[
$conf->entity];
376 $file = $dir.
"/SPECIMEN.pdf";
379 $dir =
$conf->facture->multidir_output[
$object->entity ??
$conf->entity].
"/".$objectref;
380 $file = $dir.
"/".$objectref.
".pdf";
382 if (!file_exists($dir)) {
384 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
389 if (file_exists($dir)) {
391 if (!is_object($hookmanager)) {
392 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
395 $hookmanager->initHooks(array(
'pdfgeneration'));
396 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
398 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
401 $nblines = count(
$object->lines);
402 $nbpayments = count(
$object->getListOfPayments());
403 $nbprevsituation = is_array(
$object->tab_previous_situation_invoice) ? count(
$object->tab_previous_situation_invoice) : 0;
408 $pdf->setAutoPageBreak(
true, 0);
411 $this->heightforinfotot = 50;
413 $this->heightforinfotot += (4 * ($nbpayments + 3));
415 if ($nbprevsituation > 0) {
416 $this->heightforinfotot += (4 * ($nbprevsituation + 3));
418 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
419 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
421 $heightforqrinvoice = 0;
425 $this->heightforinfotot = 30 + (4 * $nbpayments);
429 if (class_exists(
'TCPDF')) {
430 $pdf->setPrintHeader(
false);
431 $pdf->setPrintFooter(
false);
437 $logodir =
$conf->mycompany->dir_output;
438 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
441 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
442 $this->tplidx = $pdf->importPage(1);
447 $pdf->SetDrawColor(128, 128, 128);
449 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
450 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceSituationTitle"));
451 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
452 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)) :
''));
453 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
455 $pdf->SetCompression(
false);
465 'Name' => $this->emetteur->name,
466 'Location' =>
getCountry($this->emetteur->country_code,
''),
467 'Reason' =>
'INVOICE',
468 'ContactInfo' => $this->emetteur->email
470 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
474 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
478 $categoryOfOperation = 0;
481 for ($i = 0; $i < $nblines; $i++) {
483 if ($line->remise_percent) {
484 $this->atleastonediscount++;
488 if ($line->isDepositLine()) {
493 if ($categoryOfOperation < 2) {
494 $lineProductType = $line->product_type;
500 if ($nbProduct > 0 && $nbService > 0) {
502 $categoryOfOperation = 2;
507 if ($categoryOfOperation <= 0) {
509 if ($nbProduct == 0 && $nbService > 0) {
510 $categoryOfOperation = 1;
513 $this->categoryOfOperation = $categoryOfOperation;
516 if (
$object->situation_cycle_ref) {
517 $this->situationinvoice =
true;
522 if (!empty($this->tplidx)) {
523 $pdf->useTemplate($this->tplidx);
528 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
529 $top_shift = $pagehead[
'top_shift'];
530 $shipp_shift = $pagehead[
'shipp_shift'];
531 $pdf->SetFont(
'',
'', $default_font_size - 1);
532 $pdf->MultiCell(0, 3,
'');
533 $pdf->SetTextColor(0, 0, 0);
538 $this->tab_top = $this->marge_haute + 80 + $top_shift + $shipp_shift;
539 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
542 $extra_under_address_shift = 0;
545 $qrcodestring =
$object->buildZATCAQRString();
548 $qrcodestring =
$object->buildSwitzerlandQRString();
553 $qrcodestring =
$object->buildEPCQrCodeString();
558 $qrcodecolor = array(
'25',
'25',
'25');
563 'fgcolor' => $qrcodecolor,
568 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
572 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
573 $pdf->SetFont(
'',
'', $default_font_size - 4);
574 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
578 $extra_under_address_shift += 25;
586 'outputlangs' => $outputlangs,
587 'hidedetails' => $hidedetails
589 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
590 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
591 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
594 $this->tab_top += $extra_under_address_shift;
595 $this->tab_top_newpage += 0;
599 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
601 $nexY = $this->tab_top - 1;
611 $tab_height_newpage = 150;
613 $this->
tableFirstPage($pdf, $tab_top, $this->page_hauteur - 100 - $this->heightforfreetext - $this->heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
615 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
623 $pdf->setTopMargin($this->tab_top_newpage + $this->tabTitleHeight + 2);
638 $nexY = $this->tab_top_newpage + $this->tabTitleHeight;
641 $pageposbeforeprintlines = $pdf->getPage();
642 $pagenb = $pageposbeforeprintlines;
644 $pdf_sub_options = array();
645 $pdf_sub_options[
'titleshowuponpdf'] = 1;
646 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
648 for ($i = 0; $i < $nblines; $i++) {
649 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
651 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
652 $level =
$object->lines[$i]->qty;
654 if (isset($sub_options[
'titleshowuponpdf'])) {
655 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
656 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
657 unset($pdf_sub_options[
'titleshowuponpdf']);
659 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
660 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
661 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
662 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
665 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
666 unset($pdf_sub_options[
'titleshowuponpdf']);
668 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
669 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
674 $parameters = array(
'i' => $i,
'object' =>
$object);
675 $reshook = $hookmanager->executeHooks(
'beforePrintPDFline', $parameters, $this, $action);
676 if ($reshook > 0 && !empty($hookmanager->resArray[
'object'])) {
677 $object = $hookmanager->resArray[
'object'];
679 $linePosition = $i + 1;
682 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
684 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
685 $level =
$object->lines[$i]->qty;
687 if (isset($sub_options[
'titleshowuponpdf'])) {
688 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
689 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
690 unset($pdf_sub_options[
'titleshowuponpdf']);
692 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
693 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
694 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
695 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
698 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
699 unset($pdf_sub_options[
'titleshowuponpdf']);
701 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
702 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
706 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
707 $object->lines[$i]->pagebreak =
true;
711 $pdf->SetFont(
'',
'', $default_font_size - 1);
712 $pdf->SetTextColor(0, 0, 0);
715 $imglinesize = array();
716 if (!empty($realpatharray[$i])) {
720 $pdf->setTopMargin($this->tab_top_newpage + $this->tabTitleHeight + 2);
721 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot);
722 $pageposbefore = $pdf->getPage();
725 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
728 $posYAfterDescription = 0;
733 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($posy + $imglinesize[
'height']) > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
734 $pdf->AddPage(
'',
'',
true);
735 if (!empty($this->tplidx)) {
736 $pdf->useTemplate($this->tplidx);
738 $pdf->setPage($pageposbefore + 1);
739 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
740 $posy = $this->tab_top_newpage + $this->tabTitleHeight;
744 $showpricebeforepagebreak = 0;
748 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
749 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $posy + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
751 $posYAfterImage = $posy + $imglinesize[
'height'];
758 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
762 $pdf->startTransaction();
765 $pageposafter = $pdf->getPage();
767 if ($pageposafter > $pageposbefore) {
768 $pdf->rollbackTransaction(
true);
769 $pageposafter = $pageposbefore;
770 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
774 $pageposafter = $pdf->getPage();
775 $posyafter = $pdf->GetY();
777 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
778 if ($i == ($nblines - 1)) {
779 $pdf->AddPage(
'',
'',
true);
780 if (!empty($this->tplidx)) {
781 $pdf->useTemplate($this->tplidx);
783 $pdf->setPage($pageposafter + 1);
789 $showpricebeforepagebreak = 1;
791 $showpricebeforepagebreak = 0;
795 $pdf->commitTransaction();
797 $posYAfterDescription = $pdf->GetY();
800 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
802 $pageposafter = $pdf->getPage();
803 $pdf->setPage($pageposbefore);
804 $pdf->setTopMargin($this->marge_haute);
805 $pdf->setPageOrientation(
'',
true, 0);
808 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
809 $pdf->setPage($pageposafter);
810 $posy = $this->tab_top_newpage + $this->tabTitleHeight;
815 $pdf->SetFont(
'',
'', $default_font_size - 1);
826 $nexY = max($pdf->GetY(), $nexY);
830 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
833 $nexY = max($pdf->GetY(), $nexY);
841 $nexY = max($pdf->GetY(), $nexY);
848 $nexY = max($pdf->GetY(), $nexY);
855 $nexY = max($pdf->GetY(), $nexY);
859 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
862 $nexY = max($pdf->GetY(), $nexY);
867 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
870 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
872 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
874 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
878 $nexY = max($pdf->GetY(), $nexY);
885 $columkey =
'btpsomme';
887 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht_without_progress'], 0,
'', 1, -1, 2);
889 $nexY = max($pdf->GetY(), $nexY);
893 $columkey =
'progress_amount';
895 $printval =
price(
$object->lines[$i]->total_ht, 0,
'', 1, -1, 2);
897 $nexY = max($pdf->GetY(), $nexY);
900 $columkey =
'prev_progress';
902 $printval = $TInfosLigneSituationPrecedente[
'progress_prec'].
'%';
904 $nexY = max($pdf->GetY(), $nexY);
907 $columkey =
'prev_progress_amount';
909 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht'], 0,
'', 1, -1, 2);
911 $nexY = max($pdf->GetY(), $nexY);
920 'nexY' => & $afterPosData[
'y'],
921 'outputlangs' => $outputlangs,
922 'hidedetails' => $hidedetails
924 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
933 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
935 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
937 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
941 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
943 $tvaligne = $sign *
$object->lines[$i]->total_tva;
947 $localtax1ligne =
$object->lines[$i]->total_localtax1;
948 $localtax2ligne =
$object->lines[$i]->total_localtax2;
949 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
950 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
951 $localtax1_type =
$object->lines[$i]->localtax1_type;
952 $localtax2_type =
$object->lines[$i]->localtax2_type;
957 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
958 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
960 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
961 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
965 if ($localtax1_type && $localtax1ligne != 0) {
966 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
967 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
969 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
972 if ($localtax2_type && $localtax2ligne != 0) {
973 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
974 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
976 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
980 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
986 $vatcode =
$object->lines[$i]->vat_src_code;
987 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
988 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
991 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
992 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
994 $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);
996 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1000 $pdf->setPage($afterPosData[
'page']);
1001 $nexY = max($nexY, $posYAfterImage);
1004 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1005 $pdf->setPage($pageposafter);
1006 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1008 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1009 $pdf->SetLineStyle(array(
'dash' => 0));
1013 while ($pagenb < $pageposafter) {
1014 $pdf->setPage($pagenb);
1015 $tabtop = $this->tab_top_newpage;
1016 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1017 if ($pagenb != $pageposbeforeprintlines) {
1018 $tabtop = $this->tab_top_newpage;
1019 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1022 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1026 $pdf->setPage($pagenb);
1027 $pdf->setPageOrientation(
'',
true, 0);
1031 if (!empty($this->tplidx)) {
1032 $pdf->useTemplate($this->tplidx);
1036 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
1037 $tabtop = $this->tab_top_newpage;
1038 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1039 if ($pagenb != $pageposbeforeprintlines) {
1040 $tabtop = $this->tab_top_newpage;
1041 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1044 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1049 if (!empty($this->tplidx)) {
1050 $pdf->useTemplate($this->tplidx);
1061 $tabtop = $this->tab_top_newpage;
1062 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1063 $tabTitleHeight = 0;
1064 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1067 $pdf->SetTextColor(0, 0, 0);
1069 $pdf->setPage($pdf->getNumPages());
1071 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1078 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1081 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1082 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1089 if (method_exists($pdf,
'AliasNbPages')) {
1090 $pdf->AliasNbPages();
1094 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1095 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1096 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1097 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1099 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1100 $pagecount = $pdf->setSourceFile($termsofsale);
1101 for ($i = 1; $i <= $pagecount; $i++) {
1102 $tplIdx = $pdf->importPage($i);
1103 if ($tplIdx !==
false) {
1104 $s = $pdf->getTemplatesize($tplIdx);
1105 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1106 $pdf->useTemplate($tplIdx);
1108 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1114 $this->resumeLastPage($pdf,
$object, 0, $tab_top, $outputlangs, $outputlangsbis);
1115 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1124 $pdf->Output($file,
'F');
1127 $hookmanager->initHooks(array(
'pdfgeneration'));
1128 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1130 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1131 $this->warnings = $hookmanager->warnings;
1133 $this->error = $hookmanager->error;
1134 $this->errors = $hookmanager->errors;
1141 $this->result = array(
'fullpath' => $file);
1145 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1149 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1172 $tab3_top = $posy + 8;
1175 if ($this->page_largeur < 210) {
1181 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1183 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1186 $pdf->SetFont(
'',
'', $default_font_size - 3);
1187 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1188 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1190 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1192 $pdf->SetFont(
'',
'', $default_font_size - 4);
1193 $pdf->SetXY($tab3_posx, $tab3_top);
1194 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1195 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1196 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1197 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1198 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1199 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1200 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1202 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1206 $pdf->SetFont(
'',
'', $default_font_size - 4);
1210 $sql =
"SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
1211 $sql .=
" re.description, re.fk_facture_source,";
1212 $sql .=
" f.type, f.datef";
1213 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1214 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1215 $resql = $this->db->query($sql);
1217 $num = $this->db->num_rows($resql);
1219 $invoice =
new Facture($this->db);
1222 $obj = $this->db->fetch_object($resql);
1224 if ($obj->type == 2) {
1225 $text = $outputlangs->transnoentities(
"CreditNote");
1226 } elseif ($obj->type == 3) {
1227 $text = $outputlangs->transnoentities(
"Deposit");
1228 } elseif ($obj->type == 0) {
1229 $text = $outputlangs->transnoentities(
"ExcessReceived");
1231 $text = $outputlangs->transnoentities(
"UnknownType");
1234 $invoice->fetch($obj->fk_facture_source);
1236 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1237 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1238 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1239 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1240 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1241 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1242 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1243 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1245 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1250 $this->error = $this->db->lasterror();
1256 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1259 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1260 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1262 $sql .=
" ORDER BY p.datep";
1264 $resql = $this->db->query($sql);
1266 $num = $this->db->num_rows($resql);
1271 $row = $this->db->fetch_object($resql);
1272 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1273 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1274 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1275 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1276 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1277 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1279 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1280 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1281 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1282 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1283 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1284 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1289 return $tab3_top + $y + 3;
1291 $this->error = $this->db->lasterror();
1313 $pdf->SetFont(
'',
'', $default_font_size - 1);
1315 krsort($this->tva_array);
1322 $pdf->SetFillColor(224, 224, 224);
1324 $pdf->SetFont(
'',
'', $default_font_size - 2);
1325 $pdf->SetXY($this->marge_gauche, $posy);
1326 $titre = $outputlangs->transnoentities(
"VAT");
1327 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1329 $pdf->SetFont(
'',
'', $default_font_size - 2);
1330 $pdf->SetXY($this->marge_gauche + 25, $posy);
1331 $titre = $outputlangs->transnoentities(
"NetTotal");
1332 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1334 $pdf->SetFont(
'',
'', $default_font_size - 2);
1335 $pdf->SetXY($this->marge_gauche + 50, $posy);
1336 $titre = $outputlangs->transnoentities(
"VATAmount");
1337 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1339 $pdf->SetFont(
'',
'', $default_font_size - 2);
1340 $pdf->SetXY($this->marge_gauche + 75, $posy);
1341 $titre = $outputlangs->transnoentities(
"AmountTotal");
1342 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1344 $posy = $pdf->GetY();
1349 foreach ($this->tva_array as $tvakey => $tvaval) {
1350 $pdf->SetFont(
'',
'', $default_font_size - 2);
1351 $pdf->SetXY($this->marge_gauche, $posy);
1352 $titre = round((
float) $tvakey, 2) .
"%";
1353 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1355 $pdf->SetFont(
'',
'', $default_font_size - 2);
1356 $pdf->SetXY($this->marge_gauche + 25, $posy);
1357 $titre =
price($tvaval[
'tot_ht']);
1358 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1359 $tot_ht += $tvaval[
'tot_ht'];
1361 $pdf->SetFont(
'',
'', $default_font_size - 2);
1362 $pdf->SetXY($this->marge_gauche + 50, $posy);
1363 $titre =
price($tvaval[
'amount']);
1364 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1365 $tot_tva += $tvaval[
'amount'];
1367 $pdf->SetFont(
'',
'', $default_font_size - 2);
1368 $pdf->SetXY($this->marge_gauche + 75, $posy);
1369 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1370 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1371 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1373 $posy = $pdf->GetY();
1378 $showvatmention = 0;
1379 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1380 $pdf->SetFont(
'',
'', $default_font_size - 2);
1381 $pdf->SetXY($this->marge_gauche, $posy);
1382 if (empty(
$mysoc->tva_assuj)) {
1383 if (
$mysoc->forme_juridique_code == 92) {
1384 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1386 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1389 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1390 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1393 $posy = $pdf->GetY();
1396 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1398 if ($showvatmention) {
1405 if ($this->page_largeur < 210) {
1412 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1413 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1414 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1415 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1416 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1417 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1418 $sql .=
" AND f.fk_statut > 0";
1419 $sql .=
" ORDER BY f.datef ASC";
1422 $invoices = array();
1423 $resql = $this->db->query($sql);
1425 while ($obj = $this->db->fetch_object($resql)) {
1427 $old_balance += $obj->total_ttc;
1429 $this->db->free($resql);
1433 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1434 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1435 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1436 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1437 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1438 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1439 $sql_payments .=
" ORDER BY p.datep ASC";
1441 $total_payments = 0;
1442 $resql_payments = $this->db->query($sql_payments);
1443 if ($resql_payments) {
1444 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1445 $total_payments += $obj_payment->amount;
1447 $this->db->free($resql_payments);
1451 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1452 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1453 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1454 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1455 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1456 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1458 $current_date_payments = 0;
1459 $resql_current_date = $this->db->query($sql_current_date_payments);
1460 if ($resql_current_date) {
1461 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1462 $current_date_payments += $obj_current->amount;
1464 $this->db->free($resql_current_date);
1468 $old_balance -= $total_payments;
1471 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1473 $pdf->SetFillColor(224, 224, 224);
1474 $pdf->SetFont(
'',
'', $default_font_size - 2);
1475 $pdf->SetXY($this->marge_gauche, $posy);
1476 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1477 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1479 $pdf->SetFont(
'',
'', $default_font_size - 2);
1480 $pdf->SetXY($posxval + 8, $posy);
1481 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1482 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1484 $posy = $pdf->GetY() + 1;
1489 $pdf->SetFont(
'',
'', $default_font_size - 2);
1490 $pdf->SetXY($this->marge_gauche, $posy);
1491 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1492 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1494 $pdf->SetFont(
'',
'', $default_font_size - 2);
1495 $pdf->SetXY($posxval, $posy);
1496 $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);
1497 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1498 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1500 $posy = $pdf->GetY() + 3;
1504 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1505 $pdf->SetFont(
'',
'', $default_font_size - 2);
1506 $pdf->SetXY($this->marge_gauche, $posy);
1507 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1508 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1510 $pdf->SetFont(
'',
'', $default_font_size - 2);
1511 $pdf->SetXY($posxval, $posy);
1512 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1513 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1515 $posy = $pdf->GetY() + 3;
1520 if (empty(
$object->mode_reglement_code)
1523 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1527 $outputlangs->load(
"errors");
1529 $pdf->SetXY($this->marge_gauche, $posy);
1530 $pdf->SetTextColor(200, 0, 0);
1531 $pdf->SetFont(
'',
'', $default_font_size - 2);
1532 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1533 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1534 $pdf->SetTextColor(0, 0, 0);
1536 $posy = $pdf->GetY() + 1;
1540 if (!empty(
$object->mode_reglement_code)
1541 &&
$object->mode_reglement_code !=
'CHQ'
1542 &&
$object->mode_reglement_code !=
'VIR') {
1543 $pdf->SetFont(
'',
'', $default_font_size - 2);
1544 $pdf->SetXY($this->marge_gauche, $posy);
1545 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1546 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1548 $pdf->SetFont(
'',
'', $default_font_size - 2);
1549 $pdf->SetXY($posxval, $posy);
1550 $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);
1553 if (
$object->mode_reglement_code ==
"PRE") {
1554 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1557 $bac->fetch(0,
'',
$object->thirdparty->id);
1558 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1559 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1562 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1564 $posy = $pdf->GetY();
1570 if ($this->emetteur->country_code ==
'FR') {
1572 $pdf->SetXY($this->marge_gauche, $posy);
1573 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1575 $posy = $pdf->GetY() + 1;
1580 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1581 $useonlinepayment = 0;
1585 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1586 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1587 $useonlinepayment = count($validpaymentmethod);
1592 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1595 $langs->loadLangs(array(
'payment',
'stripe'));
1596 $servicename = $langs->transnoentities(
'Online');
1597 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1598 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1600 $pdf->SetXY($this->marge_gauche, $posy);
1601 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1603 $posy = $pdf->GetY() + 1;
1608 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1614 $account =
new Account($this->db);
1617 $pdf->SetXY($this->marge_gauche, $posy);
1618 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1619 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1620 $posy = $pdf->GetY() + 1;
1623 $pdf->SetXY($this->marge_gauche, $posy);
1624 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1625 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1626 $posy = $pdf->GetY() + 2;
1630 $pdf->SetXY($this->marge_gauche, $posy);
1631 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1632 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1633 $posy = $pdf->GetY() + 1;
1636 $pdf->SetXY($this->marge_gauche, $posy);
1637 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1638 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1639 $posy = $pdf->GetY() + 2;
1646 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1652 $account =
new Account($this->db);
1653 $account->fetch($bankid);
1655 $curx = $this->marge_gauche;
1658 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1664 $qrPosX = $this->marge_gauche + 5;
1666 $qrCodeColor = array(
'25',
'25',
'25');
1670 'fgcolor' => $qrCodeColor,
1672 'module_width' => 1,
1673 'module_height' => 1
1676 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1677 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1679 $pdf->SetXY($qrPosX + 25, $posy + 5);
1680 $pdf->SetFont(
'',
'', $default_font_size - 5);
1681 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1682 $posy = $pdf->GetY() + 2;
1687 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1690 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1722 $tab2_top = $posy - 4;
1724 if (is_object($outputlangsbis)) {
1725 $pdf->SetFont(
'',
'', $default_font_size - 2);
1727 $pdf->SetFont(
'',
'', $default_font_size - 1);
1733 if ($this->page_largeur < 210) {
1737 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1743 $pdf->SetFillColor(255, 255, 255);
1744 $pdf->SetXY($col1x, $tab2_top + 0);
1745 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1748 $pdf->SetXY($col2x, $tab2_top + 0);
1749 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1753 $pdf->SetFillColor(255, 255, 255);
1754 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1755 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1757 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1758 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1762 $pdf->SetFillColor(248, 248, 248);
1765 $total_ttc_origin =
$object->total_ttc;
1767 $this->atleastoneratenotnull = 0;
1770 if (!empty($this->tva_array) && count($this->tva_array) == 1) {
1771 $tva_el = reset($this->tva_array);
1772 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) {
1776 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1780 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1785 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1786 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1788 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1789 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1794 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1795 $pdf->SetTextColor(0, 0, 60);
1796 $pdf->SetFillColor(224, 224, 224);
1797 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1799 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1801 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1803 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1807 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1808 $pdf->SetTextColor(0, 0, 60);
1809 $pdf->SetFillColor(224, 224, 224);
1810 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1812 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1813 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1818 if (
$object->displayRetainedWarranty()) {
1819 $pdf->SetTextColor(40, 40, 40);
1820 $pdf->SetFillColor(255, 255, 255);
1822 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
1823 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
1827 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1828 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
1830 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1831 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
1835 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1837 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
1838 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
1840 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
1841 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1842 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
1847 $pdf->SetTextColor(0, 0, 0);
1849 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1852 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1855 $deja_regle_origin = 0;
1856 $creditnoteamount_origin = 0;
1857 $depositsamount_origin = 0;
1858 $resteapayer_origin = 0;
1860 $deja_regle_origin =
$object->getSommePaiement(0);
1861 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
1862 $depositsamount_origin =
$object->getSumDepositsUsed(0);
1863 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
1867 $resteapayer_origin = 0;
1870 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
1872 $pdf->SetFont(
'',
'', $default_font_size - 1);
1873 $pdf->SetTextColor(0, 0, 0);
1875 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1877 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1879 $this->error = $hookmanager->error;
1880 $this->errors = $hookmanager->errors;
1884 return ($tab2_top + ($tab2_hl * $index));
2010 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2013 global
$conf, $langs;
2015 $ltrdirection =
'L';
2016 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2017 $ltrdirection =
'R';
2021 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2027 $pdf->SetTextColor(0, 0, 60);
2028 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2032 $posy = $this->marge_haute;
2033 $posx = $this->page_largeur - $this->marge_droite - $w;
2035 $pdf->SetXY($this->marge_gauche, $posy);
2039 if ($this->emetteur->logo) {
2040 $logodir =
$conf->mycompany->dir_output;
2041 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2045 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2047 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2049 if (is_readable($logo)) {
2051 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2053 $pdf->SetTextColor(200, 0, 0);
2054 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2055 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2056 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2059 $text = $this->emetteur->name;
2060 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2064 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2065 $pdf->SetXY($posx, $posy);
2066 $pdf->SetTextColor(0, 0, 60);
2068 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2070 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2073 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2076 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2078 if ($this->situationinvoice) {
2079 $outputlangs->loadLangs(array(
"other"));
2080 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2081 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2083 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2086 if ($this->situationinvoice) {
2087 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2089 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2090 } elseif (
$object->type == 1) {
2091 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2092 } elseif (
$object->type == 2) {
2093 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2094 } elseif (
$object->type == 3) {
2095 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2096 } elseif (
$object->type == 4) {
2097 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2100 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2101 if (
$object->status == $object::STATUS_DRAFT) {
2102 $pdf->SetTextColor(128, 0, 0);
2103 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2106 $pdf->MultiCell($w, 3, $title,
'',
'R');
2107 if (!empty($subtitle)) {
2108 $pdf->SetFont(
'',
'B', $default_font_size);
2109 $pdf->SetXY($posx, $posy + 5);
2110 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2114 $pdf->SetFont(
'',
'', $default_font_size - 2);
2131 $pdf->SetFont(
'',
'', $default_font_size - 2);
2135 $pdf->SetXY($posx, $posy);
2136 $pdf->SetTextColor(0, 0, 60);
2137 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2142 if (!empty(
$object->project->title)) {
2144 $pdf->SetXY($posx, $posy);
2145 $pdf->SetTextColor(0, 0, 60);
2146 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
dol_trunc(
$object->project->title, 50),
'',
'R');
2152 if (!empty(
$object->project->ref)) {
2153 $outputlangs->load(
"projects");
2155 $pdf->SetXY($posx, $posy);
2156 $pdf->SetTextColor(0, 0, 60);
2157 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2161 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2162 if (
$object->type == 0 && $objectidnext) {
2163 $objectreplacing =
new Facture($this->db);
2164 $objectreplacing->fetch($objectidnext);
2167 $pdf->SetXY($posx, $posy);
2168 $pdf->SetTextColor(0, 0, 60);
2169 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2172 $objectreplaced =
new Facture($this->db);
2173 $objectreplaced->fetch(
$object->fk_facture_source);
2176 $pdf->SetXY($posx, $posy);
2177 $pdf->SetTextColor(0, 0, 60);
2178 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2181 $objectreplaced =
new Facture($this->db);
2182 $objectreplaced->fetch(
$object->fk_facture_source);
2185 $pdf->SetXY($posx, $posy);
2186 $pdf->SetTextColor(0, 0, 60);
2187 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2191 $pdf->SetXY($posx, $posy);
2192 $pdf->SetTextColor(0, 0, 60);
2194 $title = $outputlangs->transnoentities(
"DateInvoice");
2195 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2196 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2198 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2202 $pdf->SetXY($posx, $posy);
2203 $pdf->SetTextColor(0, 0, 60);
2204 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2209 $pdf->SetXY($posx, $posy);
2210 $pdf->SetTextColor(0, 0, 60);
2211 $title = $outputlangs->transnoentities(
"DateDue");
2212 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2213 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2215 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2220 $pdf->SetXY($posx, $posy);
2221 $pdf->SetTextColor(0, 0, 60);
2222 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2227 $pdf->SetXY($posx, $posy);
2228 $pdf->SetTextColor(0, 0, 60);
2229 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2234 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2235 if (count($arrayidcontact) > 0) {
2236 $usertmp =
new User($this->db);
2237 $usertmp->fetch($arrayidcontact[0]);
2239 $pdf->SetXY($posx, $posy);
2240 $pdf->SetTextColor(0, 0, 60);
2241 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2251 $current_y = $pdf->getY();
2253 if ($current_y < $pdf->getY()) {
2254 $top_shift = $pdf->getY() - $current_y;
2260 $carac_emetteur =
'';
2262 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2263 if (count($arrayidcontact) > 0) {
2264 $object->fetch_user($arrayidcontact[0]);
2265 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2266 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2267 $carac_emetteur .=
"\n";
2273 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2274 $posy += $top_shift;
2275 $posx = $this->marge_gauche;
2277 $posx = $this->page_largeur - $this->marge_droite - 80;
2285 $pdf->SetTextColor(0, 0, 0);
2286 $pdf->SetFont(
'',
'', $default_font_size - 2);
2287 $pdf->SetXY($posx, $posy - 5);
2288 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2289 $pdf->SetXY($posx, $posy);
2290 $pdf->SetFillColor(230, 230, 230);
2291 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2292 $pdf->SetTextColor(0, 0, 60);
2297 $pdf->SetXY($posx + 2, $posy + 3);
2298 $pdf->SetFont(
'',
'B', $default_font_size);
2299 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2300 $posy = $pdf->getY();
2304 $pdf->SetXY($posx + 2, $posy);
2305 $pdf->SetFont(
'',
'', $default_font_size - 1);
2306 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2309 $usecontact =
false;
2310 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2311 if (count($arrayidcontact) > 0) {
2313 $result =
$object->fetch_contact($arrayidcontact[0]);
2317 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2318 $thirdparty =
$object->contact;
2320 $thirdparty =
$object->thirdparty;
2330 if ($this->page_largeur < 210) {
2333 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2334 $posy += $top_shift;
2335 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2337 $posx = $this->marge_gauche;
2342 $pdf->SetTextColor(0, 0, 0);
2343 $pdf->SetFont(
'',
'', $default_font_size - 2);
2344 $pdf->SetXY($posx + 2, $posy - 5);
2345 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2346 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2350 $pdf->SetXY($posx + 2, $posy + 3);
2351 $pdf->SetFont(
'',
'B', $default_font_size);
2353 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2355 $posy = $pdf->getY();
2358 $pdf->SetFont(
'',
'', $default_font_size - 1);
2359 $pdf->SetXY($posx + 2, $posy);
2361 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2365 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2367 if (!empty($idaddressshipping)) {
2368 $object->fetch_contact($idaddressshipping[0]);
2369 $companystatic =
new Societe($this->db);
2370 $companystatic->fetch(
$object->contact->fk_soc);
2377 if (!empty($carac_client_shipping)) {
2378 $posy += $hautcadre;
2383 $pdf->SetXY($posx + 2, $posy - 5);
2384 $pdf->SetFont(
'',
'', $default_font_size - 2);
2385 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2386 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2389 $pdf->SetXY($posx + 2, $posy + 3);
2390 $pdf->SetFont(
'',
'B', $default_font_size);
2391 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2393 $posy = $pdf->getY();
2396 $pdf->SetXY($posx + 2, $posy);
2397 $pdf->SetFont(
'',
'', $default_font_size - 1);
2398 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2400 $shipp_shift += $hautcadre;
2405 $pdf->SetTextColor(0, 0, 0);
2407 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);
2750 public function tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
2758 if (!$displayWarranty) {
2769 $currency = !empty($currency) ? $currency : (
string)
$conf->currency;
2773 $pdf->SetTextColor(0, 0, 0);
2774 $pdf->SetFont(
'',
'', $default_font_size - 2);
2776 if (empty($hidetop)) {
2777 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
2778 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
2779 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2781 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
2785 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius,
'1001',
'F', explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2787 $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')));
2791 $pdf->SetDrawColor(128, 128, 128);
2792 $pdf->SetFont(
'',
'', $default_font_size - 1);
2794 $height_incoterms = 0;
2796 $desc_incoterms =
$object->getIncotermsForPDF();
2797 if ($desc_incoterms) {
2798 $this->tab_top -= 2;
2799 $posybefore = $pdf->GetY();
2800 $pdf->SetFont(
'',
'', $default_font_size - 1);
2801 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
2804 $pdf->SetDrawColor(192, 192, 192);
2805 $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');
2806 $posyafter = $pdf->GetY();
2807 $tab_top += $posyafter - $posybefore + 2;
2811 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
2814 if (is_object(
$object->thirdparty)) {
2815 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
2816 $salerepobj =
new User($this->db);
2817 $salerepobj->fetch($salereparray[0][
'id']);
2818 if (!empty($salerepobj->signature)) {
2819 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
2825 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
2826 if (!empty($extranote)) {
2832 $posybefore = $pdf->GetY();
2838 $pdf->SetFont(
'',
'', $default_font_size - 1);
2839 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
2841 $posyafter = $pdf->GetY();
2842 $tab_top += $posyafter - $posybefore + 2;
2847 $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');
2849 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
2850 if (empty($hidetop)) {
2851 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
2852 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceOldCumulation"),
'',
'C');
2856 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
2857 if (empty($hidetop)) {
2858 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
2859 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceNewCumulation"),
'',
'C');
2862 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
2863 if (empty($hidetop)) {
2864 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
2865 $pdf->MultiCell(36, 2, $outputlangs->transnoentities(
"CurrentSituationTotal", (
string)
$object->situation_counter),
'',
'C');
2869 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2871 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
2873 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
2875 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
2877 if ($displayWarranty) {
2878 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
2884 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
2885 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceMainTask"),
'',
'L');
2887 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
2888 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceAdditionalTask"),
'',
'L');
2890 $form->load_cache_vatrates(
"'".
$object->thirdparty->country_code.
"'");
2893 foreach ($form->cache_vatrates as $TVatInfo) {
2894 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2896 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2901 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
2902 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalHT").
' '.$TVatInfo[
'label'],
'',
'L');
2904 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2905 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
2906 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"VAT").
' '.$TVatInfo[
'label'],
'',
'L');
2912 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
2913 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalTTC"),
'',
'L');
2916 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2917 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
2918 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalSituationInvoice"),
'',
'L');
2919 $pdf->SetFont(
'',
'', $default_font_size - 2);
2921 if ($displayWarranty) {
2922 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
2923 $pdf->MultiCell(80, 2, $outputlangs->trans(
"TotalSituationInvoiceWithRetainedWarranty", (
string)
$object->retained_warranty),
'',
'L');
2924 $nextY = $tab_top + 93;
2926 $nextY = $tab_top + 74;
2929 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2930 $pdf->SetXY($this->marge_gauche + 2, $nextY);
2931 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"SituationTotalRayToRest"),
'',
'L');
2932 $pdf->SetFont(
'',
'', $default_font_size - 2);
2936 $TToDisplay = array(
2942 $x = $this->marge_gauche + 85;
2946 foreach ($TToDisplay as $col) {
2948 $pdf->SetXY($x, $tab_top + 8);
2949 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2952 $pdf->SetXY($x, $tab_top + 12);
2953 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'travaux_sup'], 0,
'', 1, -1, 2),
'',
'R');
2956 foreach ($form->cache_vatrates as $TVatInfo) {
2957 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2958 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2964 $pdf->SetXY($x, $tab_top + 24 + $i);
2965 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2968 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2969 $pdf->SetXY($x, $tab_top + 28 + $i);
2970 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'TVA'], 0,
'', 1, -1, 2),
'',
'R');
2977 $pdf->SetXY($x, $tab_top + 33 + $i);
2978 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2981 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2982 $pdf->SetXY($x, $tab_top + 58);
2983 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2984 $pdf->SetFont(
'',
'', $default_font_size - 2);
2987 if ($displayWarranty) {
2989 $pdf->SetXY($x, $tab_top + 74);
2990 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'retenue_garantie'], 0,
'', 1, -1, 2),
'',
'R');
2991 $nextY = $tab_top + 93;
2993 $nextY = $tab_top + 74;
2997 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2998 $pdf->SetXY($x, $nextY);
2999 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'total_a_payer'], 0,
'', 1, -1, 2),
'',
'R');
3000 $pdf->SetFont(
'',
'', $default_font_size - 2);