259 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
262 global $user, $langs,
$conf,
$mysoc, $hookmanager, $nblines;
264 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
266 if (!is_object($outputlangs)) {
267 $outputlangs = $langs;
271 $outputlangs->charset_output =
'ISO-8859-1';
275 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
277 global $outputlangsbis;
278 $outputlangsbis =
null;
282 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
286 setEventMessage($langs->trans(
'WarningsObjectIsNotASituation'),
'warnings');
290 $this->TDataSituation = $this->getDataSituation(
$object);
297 $nblines = count(
$object->lines);
305 $realpatharray = array();
306 $this->atleastonephoto =
false;
308 $objphoto =
new Product($this->db);
310 for ($i = 0; $i < $nblines; $i++) {
311 if (empty(
$object->lines[$i]->fk_product)) {
315 $objphoto->fetch(
$object->lines[$i]->fk_product);
319 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
320 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
322 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
323 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
328 foreach ($pdir as $midir) {
330 $entity = $objphoto->entity;
331 if ($entity !==
null &&
$conf->entity != $entity) {
332 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
334 $dir =
$conf->product->dir_output.
'/'.$midir;
337 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
339 if ($obj[
'photo_vignette']) {
340 $filename = $obj[
'photo_vignette'];
342 $filename = $obj[
'photo'];
345 $filename = $obj[
'photo'];
348 $realpath = $dir.$filename;
350 $this->atleastonephoto =
true;
355 if (!empty($realpath) && $arephoto) {
356 $realpatharray[$i] = $realpath;
363 if (
$conf->facture->multidir_output[
$conf->entity]) {
367 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
368 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
372 $dir =
$conf->facture->multidir_output[
$conf->entity];
373 $file = $dir.
"/SPECIMEN.pdf";
376 $dir =
$conf->facture->multidir_output[
$object->entity ??
$conf->entity].
"/".$objectref;
377 $file = $dir.
"/".$objectref.
".pdf";
379 if (!file_exists($dir)) {
381 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
386 if (file_exists($dir)) {
388 if (!is_object($hookmanager)) {
389 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
392 $hookmanager->initHooks(array(
'pdfgeneration'));
393 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
395 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
398 $nblines = count(
$object->lines);
399 $nbpayments = count(
$object->getListOfPayments());
400 $nbprevsituation = is_array(
$object->tab_previous_situation_invoice) ? count(
$object->tab_previous_situation_invoice) : 0;
405 $pdf->setAutoPageBreak(
true, 0);
408 $this->heightforinfotot = 50;
410 $this->heightforinfotot += (4 * ($nbpayments + 3));
412 if ($nbprevsituation > 0) {
413 $this->heightforinfotot += (4 * ($nbprevsituation + 3));
415 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
416 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
418 $heightforqrinvoice = 0;
422 $this->heightforinfotot = 30 + (4 * $nbpayments);
426 if (class_exists(
'TCPDF')) {
427 $pdf->setPrintHeader(
false);
428 $pdf->setPrintFooter(
false);
434 $logodir =
$conf->mycompany->dir_output;
435 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
438 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
439 $this->tplidx = $pdf->importPage(1);
444 $pdf->SetDrawColor(128, 128, 128);
446 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
447 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceSituationTitle"));
448 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
449 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)) :
''));
450 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
452 $pdf->SetCompression(
false);
462 'Name' => $this->emetteur->name,
463 'Location' =>
getCountry($this->emetteur->country_code,
''),
464 'Reason' =>
'INVOICE',
465 'ContactInfo' => $this->emetteur->email
467 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
471 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
475 $categoryOfOperation = 0;
478 for ($i = 0; $i < $nblines; $i++) {
480 if ($line->remise_percent) {
481 $this->atleastonediscount++;
485 if ($line->isDepositLine()) {
490 if ($categoryOfOperation < 2) {
491 $lineProductType = $line->product_type;
497 if ($nbProduct > 0 && $nbService > 0) {
499 $categoryOfOperation = 2;
504 if ($categoryOfOperation <= 0) {
506 if ($nbProduct == 0 && $nbService > 0) {
507 $categoryOfOperation = 1;
510 $this->categoryOfOperation = $categoryOfOperation;
513 if (
$object->situation_cycle_ref) {
514 $this->situationinvoice =
true;
519 if (!empty($this->tplidx)) {
520 $pdf->useTemplate($this->tplidx);
525 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
526 $top_shift = $pagehead[
'top_shift'];
527 $shipp_shift = $pagehead[
'shipp_shift'];
528 $pdf->SetFont(
'',
'', $default_font_size - 1);
529 $pdf->MultiCell(0, 3,
'');
530 $pdf->SetTextColor(0, 0, 0);
535 $this->tab_top = $this->marge_haute + 80 + $top_shift + $shipp_shift;
536 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
539 $extra_under_address_shift = 0;
542 $qrcodestring =
$object->buildZATCAQRString();
545 $qrcodestring =
$object->buildSwitzerlandQRString();
549 $qrcodestring =
$object->buildEPCQrCodeString();
554 $qrcodecolor = array(
'25',
'25',
'25');
559 'fgcolor' => $qrcodecolor,
564 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
568 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
569 $pdf->SetFont(
'',
'', $default_font_size - 4);
570 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
574 $extra_under_address_shift += 25;
582 'outputlangs' => $outputlangs,
583 'hidedetails' => $hidedetails
585 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
586 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
587 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
590 $this->tab_top += $extra_under_address_shift;
591 $this->tab_top_newpage += 0;
595 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
597 $nexY = $this->tab_top - 1;
607 $tab_height_newpage = 150;
609 $this->
tableFirstPage(
$object, $pdf, $tab_top, $this->page_hauteur - 100 - $this->heightforfreetext - $this->heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
611 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
619 $pdf->setTopMargin($this->tab_top_newpage);
634 $nexY = $this->tab_top_newpage + $this->tabTitleHeight;
637 $pageposbeforeprintlines = $pdf->getPage();
638 $pagenb = $pageposbeforeprintlines;
640 $pdf_sub_options = array();
641 $pdf_sub_options[
'titleshowuponpdf'] = 1;
642 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
644 for ($i = 0; $i < $nblines; $i++) {
645 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
647 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
648 $level =
$object->lines[$i]->qty;
650 if (isset($sub_options[
'titleshowuponpdf'])) {
651 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
652 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
653 unset($pdf_sub_options[
'titleshowuponpdf']);
655 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
656 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
657 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
658 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
661 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
662 unset($pdf_sub_options[
'titleshowuponpdf']);
664 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
665 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
670 $parameters = array(
'i' => $i,
'object' =>
$object);
671 $reshook = $hookmanager->executeHooks(
'beforePrintPDFline', $parameters, $this, $action);
672 if ($reshook > 0 && !empty($hookmanager->resArray[
'object'])) {
673 $object = $hookmanager->resArray[
'object'];
675 $linePosition = $i + 1;
678 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
680 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
681 $level =
$object->lines[$i]->qty;
683 if (isset($sub_options[
'titleshowuponpdf'])) {
684 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
685 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
686 unset($pdf_sub_options[
'titleshowuponpdf']);
688 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
689 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
690 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
691 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
694 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
695 unset($pdf_sub_options[
'titleshowuponpdf']);
697 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
698 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
702 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
703 $object->lines[$i]->pagebreak =
true;
707 $pdf->SetFont(
'',
'', $default_font_size - 1);
708 $pdf->SetTextColor(0, 0, 0);
711 $imglinesize = array();
712 if (!empty($realpatharray[$i])) {
716 $pdf->setTopMargin($this->tab_top_newpage);
717 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot);
718 $pageposbefore = $pdf->getPage();
721 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
724 $posYAfterDescription = 0;
729 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($posy + $imglinesize[
'height']) > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
730 $pdf->AddPage(
'',
'',
true);
731 if (!empty($this->tplidx)) {
732 $pdf->useTemplate($this->tplidx);
734 $pdf->setPage($pageposbefore + 1);
735 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
736 $posy = $this->tab_top_newpage;
737 $showpricebeforepagebreak = 0;
741 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
742 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $posy + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
744 $posYAfterImage = $posy + $imglinesize[
'height'];
751 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
755 $pdf->startTransaction();
758 $pageposafter = $pdf->getPage();
760 if ($pageposafter > $pageposbefore) {
761 $pdf->rollbackTransaction(
true);
762 $pageposafter = $pageposbefore;
763 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
767 $pageposafter = $pdf->getPage();
768 $posyafter = $pdf->GetY();
770 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
771 if ($i == ($nblines - 1)) {
772 $pdf->AddPage(
'',
'',
true);
773 if (!empty($this->tplidx)) {
774 $pdf->useTemplate($this->tplidx);
776 $pdf->setPage($pageposafter + 1);
782 $showpricebeforepagebreak = 1;
784 $showpricebeforepagebreak = 0;
788 $pdf->commitTransaction();
790 $posYAfterDescription = $pdf->GetY();
793 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
795 $pageposafter = $pdf->getPage();
796 $pdf->setPage($pageposbefore);
797 $pdf->setTopMargin($this->marge_haute);
798 $pdf->setPageOrientation(
'',
true, 0);
801 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
802 $pdf->setPage($pageposafter);
803 $posy = $this->tab_top_newpage;
806 $pdf->SetFont(
'',
'', $default_font_size - 1);
817 $nexY = max($pdf->GetY(), $nexY);
821 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
824 $nexY = max($pdf->GetY(), $nexY);
832 $nexY = max($pdf->GetY(), $nexY);
839 $nexY = max($pdf->GetY(), $nexY);
846 $nexY = max($pdf->GetY(), $nexY);
850 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
853 $nexY = max($pdf->GetY(), $nexY);
858 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
861 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
863 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
865 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
869 $nexY = max($pdf->GetY(), $nexY);
876 $columkey =
'btpsomme';
878 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht_without_progress'], 0,
'', 1, -1, 2);
880 $nexY = max($pdf->GetY(), $nexY);
884 $columkey =
'progress_amount';
886 $printval =
price(
$object->lines[$i]->total_ht, 0,
'', 1, -1, 2);
888 $nexY = max($pdf->GetY(), $nexY);
891 $columkey =
'prev_progress';
893 $printval = $TInfosLigneSituationPrecedente[
'progress_prec'].
'%';
895 $nexY = max($pdf->GetY(), $nexY);
898 $columkey =
'prev_progress_amount';
900 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht'], 0,
'', 1, -1, 2);
902 $nexY = max($pdf->GetY(), $nexY);
911 'nexY' => & $afterPosData[
'y'],
912 'outputlangs' => $outputlangs,
913 'hidedetails' => $hidedetails
915 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
924 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
926 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
928 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
932 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
934 $tvaligne = $sign *
$object->lines[$i]->total_tva;
938 $localtax1ligne =
$object->lines[$i]->total_localtax1;
939 $localtax2ligne =
$object->lines[$i]->total_localtax2;
940 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
941 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
942 $localtax1_type =
$object->lines[$i]->localtax1_type;
943 $localtax2_type =
$object->lines[$i]->localtax2_type;
948 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
949 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
951 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
952 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
956 if ($localtax1_type && $localtax1ligne != 0) {
957 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
958 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
960 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
963 if ($localtax2_type && $localtax2ligne != 0) {
964 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
965 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
967 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
971 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
977 $vatcode =
$object->lines[$i]->vat_src_code;
978 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
979 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
982 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
983 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
985 $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);
987 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
991 $pdf->setPage($afterPosData[
'page']);
992 $nexY = max($nexY, $posYAfterImage);
995 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
996 $pdf->setPage($pageposafter);
997 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
999 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1000 $pdf->SetLineStyle(array(
'dash' => 0));
1004 while ($pagenb < $pageposafter) {
1005 $pdf->setPage($pagenb);
1006 $tabtop = $this->tab_top;
1007 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1008 if ($pagenb != $pageposbeforeprintlines) {
1009 $tabtop = $this->tab_top_newpage;
1010 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1013 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1017 $pdf->setPage($pagenb);
1018 $pdf->setPageOrientation(
'',
true, 0);
1022 if (!empty($this->tplidx)) {
1023 $pdf->useTemplate($this->tplidx);
1027 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
1028 $tabtop = $this->tab_top;
1029 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1030 if ($pagenb != $pageposbeforeprintlines) {
1031 $tabtop = $this->tab_top_newpage;
1032 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1035 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1040 if (!empty($this->tplidx)) {
1041 $pdf->useTemplate($this->tplidx);
1052 $tabtop = $this->tab_top_newpage;
1053 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1054 $tabTitleHeight = 0;
1055 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1058 $pdf->SetTextColor(0, 0, 0);
1060 $pdf->setPage($pdf->getNumPages());
1062 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1069 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1072 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1073 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1080 if (method_exists($pdf,
'AliasNbPages')) {
1081 $pdf->AliasNbPages();
1085 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1086 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1087 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1088 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1090 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1091 $pagecount = $pdf->setSourceFile($termsofsale);
1092 for ($i = 1; $i <= $pagecount; $i++) {
1093 $tplIdx = $pdf->importPage($i);
1094 if ($tplIdx !==
false) {
1095 $s = $pdf->getTemplatesize($tplIdx);
1096 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1097 $pdf->useTemplate($tplIdx);
1099 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1105 $this->resumeLastPage($pdf,
$object, 0, $tab_top, $outputlangs, $outputlangsbis);
1106 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1115 $pdf->Output($file,
'F');
1118 $hookmanager->initHooks(array(
'pdfgeneration'));
1119 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1121 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1122 $this->warnings = $hookmanager->warnings;
1124 $this->error = $hookmanager->error;
1125 $this->errors = $hookmanager->errors;
1132 $this->result = array(
'fullpath' => $file);
1136 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1140 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1163 $tab3_top = $posy + 8;
1166 if ($this->page_largeur < 210) {
1172 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1174 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1177 $pdf->SetFont(
'',
'', $default_font_size - 3);
1178 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1179 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1181 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1183 $pdf->SetFont(
'',
'', $default_font_size - 4);
1184 $pdf->SetXY($tab3_posx, $tab3_top);
1185 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1186 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1187 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1188 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1189 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1190 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1191 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1193 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1197 $pdf->SetFont(
'',
'', $default_font_size - 4);
1201 $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,";
1202 $sql .=
" re.description, re.fk_facture_source,";
1203 $sql .=
" f.type, f.datef";
1204 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1205 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1206 $resql = $this->db->query($sql);
1208 $num = $this->db->num_rows($resql);
1210 $invoice =
new Facture($this->db);
1213 $obj = $this->db->fetch_object($resql);
1215 if ($obj->type == 2) {
1216 $text = $outputlangs->transnoentities(
"CreditNote");
1217 } elseif ($obj->type == 3) {
1218 $text = $outputlangs->transnoentities(
"Deposit");
1219 } elseif ($obj->type == 0) {
1220 $text = $outputlangs->transnoentities(
"ExcessReceived");
1222 $text = $outputlangs->transnoentities(
"UnknownType");
1225 $invoice->fetch($obj->fk_facture_source);
1227 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1228 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1229 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1230 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1231 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1232 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1233 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1234 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1236 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1241 $this->error = $this->db->lasterror();
1247 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1249 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1250 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1251 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1253 $sql .=
" ORDER BY p.datep";
1255 $resql = $this->db->query($sql);
1257 $num = $this->db->num_rows($resql);
1262 $row = $this->db->fetch_object($resql);
1263 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1264 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1265 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1266 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1267 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1268 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1270 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1271 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1272 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1273 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1274 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1275 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1280 return $tab3_top + $y + 3;
1282 $this->error = $this->db->lasterror();
1304 $pdf->SetFont(
'',
'', $default_font_size - 1);
1306 krsort($this->tva_array);
1313 $pdf->SetFillColor(224, 224, 224);
1315 $pdf->SetFont(
'',
'', $default_font_size - 2);
1316 $pdf->SetXY($this->marge_gauche, $posy);
1317 $titre = $outputlangs->transnoentities(
"VAT");
1318 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1320 $pdf->SetFont(
'',
'', $default_font_size - 2);
1321 $pdf->SetXY($this->marge_gauche + 25, $posy);
1322 $titre = $outputlangs->transnoentities(
"NetTotal");
1323 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1325 $pdf->SetFont(
'',
'', $default_font_size - 2);
1326 $pdf->SetXY($this->marge_gauche + 50, $posy);
1327 $titre = $outputlangs->transnoentities(
"VATAmount");
1328 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1330 $pdf->SetFont(
'',
'', $default_font_size - 2);
1331 $pdf->SetXY($this->marge_gauche + 75, $posy);
1332 $titre = $outputlangs->transnoentities(
"AmountTotal");
1333 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1335 $posy = $pdf->GetY();
1340 foreach ($this->tva_array as $tvakey => $tvaval) {
1341 $pdf->SetFont(
'',
'', $default_font_size - 2);
1342 $pdf->SetXY($this->marge_gauche, $posy);
1343 $titre = round((
float) $tvakey, 2) .
"%";
1344 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1346 $pdf->SetFont(
'',
'', $default_font_size - 2);
1347 $pdf->SetXY($this->marge_gauche + 25, $posy);
1348 $titre =
price($tvaval[
'tot_ht']);
1349 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1350 $tot_ht += $tvaval[
'tot_ht'];
1352 $pdf->SetFont(
'',
'', $default_font_size - 2);
1353 $pdf->SetXY($this->marge_gauche + 50, $posy);
1354 $titre =
price($tvaval[
'amount']);
1355 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1356 $tot_tva += $tvaval[
'amount'];
1358 $pdf->SetFont(
'',
'', $default_font_size - 2);
1359 $pdf->SetXY($this->marge_gauche + 75, $posy);
1360 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1361 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1362 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1364 $posy = $pdf->GetY();
1369 $showvatmention = 0;
1370 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1371 $pdf->SetFont(
'',
'', $default_font_size - 2);
1372 $pdf->SetXY($this->marge_gauche, $posy);
1373 if (empty(
$mysoc->tva_assuj)) {
1374 if (
$mysoc->forme_juridique_code == 92) {
1375 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1377 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1380 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1381 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1384 $posy = $pdf->GetY();
1387 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1389 if ($showvatmention) {
1396 if ($this->page_largeur < 210) {
1403 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1404 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1405 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1406 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1407 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1408 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1409 $sql .=
" AND f.fk_statut > 0";
1410 $sql .=
" ORDER BY f.datef ASC";
1413 $invoices = array();
1414 $resql = $this->db->query($sql);
1416 while ($obj = $this->db->fetch_object($resql)) {
1418 $old_balance += $obj->total_ttc;
1420 $this->db->free($resql);
1424 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1425 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1426 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1427 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1428 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1429 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1430 $sql_payments .=
" ORDER BY p.datep ASC";
1432 $total_payments = 0;
1433 $resql_payments = $this->db->query($sql_payments);
1434 if ($resql_payments) {
1435 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1436 $total_payments += $obj_payment->amount;
1438 $this->db->free($resql_payments);
1442 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1443 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1444 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1445 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1446 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1447 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1449 $current_date_payments = 0;
1450 $resql_current_date = $this->db->query($sql_current_date_payments);
1451 if ($resql_current_date) {
1452 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1453 $current_date_payments += $obj_current->amount;
1455 $this->db->free($resql_current_date);
1459 $old_balance -= $total_payments;
1462 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1464 $pdf->SetFillColor(224, 224, 224);
1465 $pdf->SetFont(
'',
'', $default_font_size - 2);
1466 $pdf->SetXY($this->marge_gauche, $posy);
1467 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1468 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1470 $pdf->SetFont(
'',
'', $default_font_size - 2);
1471 $pdf->SetXY($posxval + 8, $posy);
1472 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1473 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1475 $posy = $pdf->GetY() + 1;
1480 $pdf->SetFont(
'',
'', $default_font_size - 2);
1481 $pdf->SetXY($this->marge_gauche, $posy);
1482 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1483 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1485 $pdf->SetFont(
'',
'', $default_font_size - 2);
1486 $pdf->SetXY($posxval, $posy);
1487 $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);
1488 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1489 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1491 $posy = $pdf->GetY() + 3;
1495 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1496 $pdf->SetFont(
'',
'', $default_font_size - 2);
1497 $pdf->SetXY($this->marge_gauche, $posy);
1498 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1499 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1501 $pdf->SetFont(
'',
'', $default_font_size - 2);
1502 $pdf->SetXY($posxval, $posy);
1503 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1504 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1506 $posy = $pdf->GetY() + 3;
1511 if (empty(
$object->mode_reglement_code)
1514 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1518 $outputlangs->load(
"errors");
1520 $pdf->SetXY($this->marge_gauche, $posy);
1521 $pdf->SetTextColor(200, 0, 0);
1522 $pdf->SetFont(
'',
'', $default_font_size - 2);
1523 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1524 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1525 $pdf->SetTextColor(0, 0, 0);
1527 $posy = $pdf->GetY() + 1;
1531 if (!empty(
$object->mode_reglement_code)
1532 &&
$object->mode_reglement_code !=
'CHQ'
1533 &&
$object->mode_reglement_code !=
'VIR') {
1534 $pdf->SetFont(
'',
'', $default_font_size - 2);
1535 $pdf->SetXY($this->marge_gauche, $posy);
1536 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1537 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1539 $pdf->SetFont(
'',
'', $default_font_size - 2);
1540 $pdf->SetXY($posxval, $posy);
1541 $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);
1544 if (
$object->mode_reglement_code ==
"PRE") {
1545 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1548 $bac->fetch(0,
'',
$object->thirdparty->id);
1549 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1550 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1553 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1555 $posy = $pdf->GetY();
1561 if ($this->emetteur->country_code ==
'FR') {
1563 $pdf->SetXY($this->marge_gauche, $posy);
1564 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1566 $posy = $pdf->GetY() + 1;
1571 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1572 $useonlinepayment = 0;
1576 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1577 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1578 $useonlinepayment = count($validpaymentmethod);
1583 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1586 $langs->loadLangs(array(
'payment',
'stripe'));
1587 $servicename = $langs->transnoentities(
'Online');
1588 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1589 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1591 $pdf->SetXY($this->marge_gauche, $posy);
1592 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1594 $posy = $pdf->GetY() + 1;
1599 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1605 $account =
new Account($this->db);
1608 $pdf->SetXY($this->marge_gauche, $posy);
1609 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1610 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1611 $posy = $pdf->GetY() + 1;
1614 $pdf->SetXY($this->marge_gauche, $posy);
1615 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1616 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1617 $posy = $pdf->GetY() + 2;
1621 $pdf->SetXY($this->marge_gauche, $posy);
1622 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1623 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1624 $posy = $pdf->GetY() + 1;
1627 $pdf->SetXY($this->marge_gauche, $posy);
1628 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1629 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1630 $posy = $pdf->GetY() + 2;
1637 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1643 $account =
new Account($this->db);
1644 $account->fetch($bankid);
1646 $curx = $this->marge_gauche;
1649 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1655 $qrPosX = $this->marge_gauche + 5;
1657 $qrCodeColor = array(
'25',
'25',
'25');
1661 'fgcolor' => $qrCodeColor,
1663 'module_width' => 1,
1664 'module_height' => 1
1667 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1668 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1670 $pdf->SetXY($qrPosX + 25, $posy + 5);
1671 $pdf->SetFont(
'',
'', $default_font_size - 5);
1672 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1673 $posy = $pdf->GetY() + 2;
1678 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1681 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1713 $tab2_top = $posy - 4;
1715 if (is_object($outputlangsbis)) {
1716 $pdf->SetFont(
'',
'', $default_font_size - 2);
1718 $pdf->SetFont(
'',
'', $default_font_size - 1);
1724 if ($this->page_largeur < 210) {
1728 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1734 $pdf->SetFillColor(255, 255, 255);
1735 $pdf->SetXY($col1x, $tab2_top + 0);
1736 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1739 $pdf->SetXY($col2x, $tab2_top + 0);
1740 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1744 $pdf->SetFillColor(255, 255, 255);
1745 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1746 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1748 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1749 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1753 $pdf->SetFillColor(248, 248, 248);
1756 $total_ttc_origin =
$object->total_ttc;
1758 $this->atleastoneratenotnull = 0;
1761 if (!empty($this->tva_array) && count($this->tva_array) == 1) {
1762 $tva_el = reset($this->tva_array);
1763 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) {
1767 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1771 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1776 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1777 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1779 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1780 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1785 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1786 $pdf->SetTextColor(0, 0, 60);
1787 $pdf->SetFillColor(224, 224, 224);
1788 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1790 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1792 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1794 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1798 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1799 $pdf->SetTextColor(0, 0, 60);
1800 $pdf->SetFillColor(224, 224, 224);
1801 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1803 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1804 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1809 if (
$object->displayRetainedWarranty()) {
1810 $pdf->SetTextColor(40, 40, 40);
1811 $pdf->SetFillColor(255, 255, 255);
1813 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
1814 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
1818 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1819 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
1821 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1822 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
1826 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1828 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
1829 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
1831 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
1832 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1833 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
1838 $pdf->SetTextColor(0, 0, 0);
1840 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1843 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1846 $deja_regle_origin = 0;
1847 $creditnoteamount_origin = 0;
1848 $depositsamount_origin = 0;
1849 $resteapayer_origin = 0;
1851 $deja_regle_origin =
$object->getSommePaiement(0);
1852 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
1853 $depositsamount_origin =
$object->getSumDepositsUsed(0);
1854 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
1858 $resteapayer_origin = 0;
1861 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
1863 $pdf->SetFont(
'',
'', $default_font_size - 1);
1864 $pdf->SetTextColor(0, 0, 0);
1866 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1868 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1870 $this->error = $hookmanager->error;
1871 $this->errors = $hookmanager->errors;
1875 return ($tab2_top + ($tab2_hl * $index));
2001 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2004 global
$conf, $langs;
2006 $ltrdirection =
'L';
2007 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2008 $ltrdirection =
'R';
2012 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2018 $pdf->SetTextColor(0, 0, 60);
2019 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2023 $posy = $this->marge_haute;
2024 $posx = $this->page_largeur - $this->marge_droite - $w;
2026 $pdf->SetXY($this->marge_gauche, $posy);
2029 $logodir =
$conf->mycompany->dir_output;
2030 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2033 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size, $ltrdirection);
2035 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2036 $pdf->SetXY($posx, $posy);
2037 $pdf->SetTextColor(0, 0, 60);
2039 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2041 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2044 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2047 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2049 if ($this->situationinvoice) {
2050 $outputlangs->loadLangs(array(
"other"));
2051 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2052 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2054 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2057 if ($this->situationinvoice) {
2058 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2060 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2061 } elseif (
$object->type == 1) {
2062 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2063 } elseif (
$object->type == 2) {
2064 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2065 } elseif (
$object->type == 3) {
2066 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2067 } elseif (
$object->type == 4) {
2068 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2071 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2072 if (
$object->status == $object::STATUS_DRAFT) {
2073 $pdf->SetTextColor(128, 0, 0);
2074 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2077 $pdf->MultiCell($w, 3, $title,
'',
'R');
2078 if (!empty($subtitle)) {
2079 $pdf->SetFont(
'',
'B', $default_font_size);
2080 $pdf->SetXY($posx, $posy + 5);
2081 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2085 $pdf->SetFont(
'',
'', $default_font_size - 2);
2102 $pdf->SetFont(
'',
'', $default_font_size - 2);
2106 $pdf->SetXY($posx, $posy);
2107 $pdf->SetTextColor(0, 0, 60);
2108 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2113 if (!empty(
$object->project->title)) {
2115 $pdf->SetXY($posx, $posy);
2116 $pdf->SetTextColor(0, 0, 60);
2117 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
$object->project->title,
'',
'R');
2123 if (!empty(
$object->project->ref)) {
2124 $outputlangs->load(
"projects");
2126 $pdf->SetXY($posx, $posy);
2127 $pdf->SetTextColor(0, 0, 60);
2128 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2132 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2133 if (
$object->type == 0 && $objectidnext) {
2134 $objectreplacing =
new Facture($this->db);
2135 $objectreplacing->fetch($objectidnext);
2138 $pdf->SetXY($posx, $posy);
2139 $pdf->SetTextColor(0, 0, 60);
2140 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2143 $objectreplaced =
new Facture($this->db);
2144 $objectreplaced->fetch(
$object->fk_facture_source);
2147 $pdf->SetXY($posx, $posy);
2148 $pdf->SetTextColor(0, 0, 60);
2149 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2152 $objectreplaced =
new Facture($this->db);
2153 $objectreplaced->fetch(
$object->fk_facture_source);
2156 $pdf->SetXY($posx, $posy);
2157 $pdf->SetTextColor(0, 0, 60);
2158 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2162 $pdf->SetXY($posx, $posy);
2163 $pdf->SetTextColor(0, 0, 60);
2165 $title = $outputlangs->transnoentities(
"DateInvoice");
2166 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2167 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2169 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2173 $pdf->SetXY($posx, $posy);
2174 $pdf->SetTextColor(0, 0, 60);
2175 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2180 $pdf->SetXY($posx, $posy);
2181 $pdf->SetTextColor(0, 0, 60);
2182 $title = $outputlangs->transnoentities(
"DateDue");
2183 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2184 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2186 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2191 $pdf->SetXY($posx, $posy);
2192 $pdf->SetTextColor(0, 0, 60);
2193 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2198 $pdf->SetXY($posx, $posy);
2199 $pdf->SetTextColor(0, 0, 60);
2200 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2205 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2206 if (count($arrayidcontact) > 0) {
2207 $usertmp =
new User($this->db);
2208 $usertmp->fetch($arrayidcontact[0]);
2210 $pdf->SetXY($posx, $posy);
2211 $pdf->SetTextColor(0, 0, 60);
2212 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2222 $current_y = $pdf->getY();
2224 if ($current_y < $pdf->getY()) {
2225 $top_shift = $pdf->getY() - $current_y;
2231 $carac_emetteur =
'';
2233 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2234 if (count($arrayidcontact) > 0) {
2235 $object->fetch_user($arrayidcontact[0]);
2236 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2237 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2238 $carac_emetteur .=
"\n";
2244 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2245 $posy += $top_shift;
2246 $posx = $this->marge_gauche;
2248 $posx = $this->page_largeur - $this->marge_droite - 80;
2256 $pdf->SetTextColor(0, 0, 0);
2257 $pdf->SetFont(
'',
'', $default_font_size - 2);
2258 $pdf->SetXY($posx, $posy - 5);
2259 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2260 $pdf->SetXY($posx, $posy);
2261 $pdf->SetFillColor(230, 230, 230);
2262 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2263 $pdf->SetTextColor(0, 0, 60);
2268 $pdf->SetXY($posx + 2, $posy + 3);
2269 $pdf->SetFont(
'',
'B', $default_font_size);
2270 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2271 $posy = $pdf->getY();
2275 $pdf->SetXY($posx + 2, $posy);
2276 $pdf->SetFont(
'',
'', $default_font_size - 1);
2277 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2280 $usecontact =
false;
2281 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2282 if (count($arrayidcontact) > 0) {
2284 $result =
$object->fetch_contact($arrayidcontact[0]);
2288 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2289 $thirdparty =
$object->contact;
2291 $thirdparty =
$object->thirdparty;
2301 if ($this->page_largeur < 210) {
2304 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2305 $posy += $top_shift;
2306 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2308 $posx = $this->marge_gauche;
2313 $pdf->SetTextColor(0, 0, 0);
2314 $pdf->SetFont(
'',
'', $default_font_size - 2);
2315 $pdf->SetXY($posx + 2, $posy - 5);
2316 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2317 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2321 $pdf->SetXY($posx + 2, $posy + 3);
2322 $pdf->SetFont(
'',
'B', $default_font_size);
2324 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2326 $posy = $pdf->getY();
2329 $pdf->SetFont(
'',
'', $default_font_size - 1);
2330 $pdf->SetXY($posx + 2, $posy);
2332 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2336 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2338 if (!empty($idaddressshipping)) {
2339 $object->fetch_contact($idaddressshipping[0]);
2340 $companystatic =
new Societe($this->db);
2341 $companystatic->fetch(
$object->contact->fk_soc);
2348 if (!empty($carac_client_shipping)) {
2349 $posy += $hautcadre;
2354 $pdf->SetXY($posx + 2, $posy - 5);
2355 $pdf->SetFont(
'',
'', $default_font_size - 2);
2356 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2357 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2360 $pdf->SetXY($posx + 2, $posy + 3);
2361 $pdf->SetFont(
'',
'B', $default_font_size);
2362 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2364 $posy = $pdf->getY();
2367 $pdf->SetXY($posx + 2, $posy);
2368 $pdf->SetFont(
'',
'', $default_font_size - 1);
2369 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2371 $shipp_shift += $hautcadre;
2376 $pdf->SetTextColor(0, 0, 0);
2378 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);
2722 public function tableFirstPage(
$object, &$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
2724 global $user,
$conf;
2726 $form =
new Form($this->db);
2730 if (!$displayWarranty) {
2741 $currency = !empty($currency) ? $currency : (
string)
$conf->currency;
2745 $pdf->SetTextColor(0, 0, 0);
2746 $pdf->SetFont(
'',
'', $default_font_size - 2);
2748 if (empty($hidetop)) {
2749 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
2750 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
2751 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2753 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
2757 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius,
'1001',
'F', explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2759 $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')));
2763 $pdf->SetDrawColor(128, 128, 128);
2764 $pdf->SetFont(
'',
'', $default_font_size - 1);
2766 $height_incoterms = 0;
2768 $desc_incoterms =
$object->getIncotermsForPDF();
2769 if ($desc_incoterms) {
2770 $this->tab_top -= 2;
2771 $posybefore = $pdf->GetY();
2772 $pdf->SetFont(
'',
'', $default_font_size - 1);
2773 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
2776 $pdf->SetDrawColor(192, 192, 192);
2777 $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');
2778 $posyafter = $pdf->GetY();
2779 $tab_top += $posyafter - $posybefore + 2;
2783 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
2786 if (is_object(
$object->thirdparty)) {
2787 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
2788 $salerepobj =
new User($this->db);
2789 $salerepobj->fetch($salereparray[0][
'id']);
2790 if (!empty($salerepobj->signature)) {
2791 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
2797 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
2798 if (!empty($extranote)) {
2804 $posybefore = $pdf->GetY();
2810 $pdf->SetFont(
'',
'', $default_font_size - 1);
2811 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
2813 $posyafter = $pdf->GetY();
2814 $tab_top += $posyafter - $posybefore + 2;
2819 $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');
2821 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
2822 if (empty($hidetop)) {
2823 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
2824 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceOldCumulation"),
'',
'C');
2828 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
2829 if (empty($hidetop)) {
2830 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
2831 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceNewCumulation"),
'',
'C');
2834 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
2835 if (empty($hidetop)) {
2836 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
2837 $pdf->MultiCell(36, 2, $outputlangs->transnoentities(
"CurrentSituationTotal", (
string)
$object->situation_counter),
'',
'C');
2841 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2843 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
2845 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
2847 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
2849 if ($displayWarranty) {
2850 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
2856 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
2857 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceMainTask"),
'',
'L');
2859 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
2860 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceAdditionalTask"),
'',
'L');
2862 $form->load_cache_vatrates(
"'".
$object->thirdparty->country_code.
"'");
2865 foreach ($form->cache_vatrates as $TVatInfo) {
2866 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2868 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2873 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
2874 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalHT").
' '.$TVatInfo[
'label'],
'',
'L');
2876 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2877 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
2878 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"VAT").
' '.$TVatInfo[
'label'],
'',
'L');
2884 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
2885 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalTTC"),
'',
'L');
2888 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2889 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
2890 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalSituationInvoice"),
'',
'L');
2891 $pdf->SetFont(
'',
'', $default_font_size - 2);
2893 if ($displayWarranty) {
2894 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
2895 $pdf->MultiCell(80, 2, $outputlangs->trans(
"TotalSituationInvoiceWithRetainedWarranty", (
string)
$object->retained_warranty),
'',
'L');
2896 $nextY = $tab_top + 93;
2898 $nextY = $tab_top + 74;
2901 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2902 $pdf->SetXY($this->marge_gauche + 2, $nextY);
2903 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"SituationTotalRayToRest"),
'',
'L');
2904 $pdf->SetFont(
'',
'', $default_font_size - 2);
2908 $TToDisplay = array(
2914 $x = $this->marge_gauche + 85;
2918 foreach ($TToDisplay as $col) {
2920 $pdf->SetXY($x, $tab_top + 8);
2921 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2924 $pdf->SetXY($x, $tab_top + 12);
2925 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'travaux_sup'], 0,
'', 1, -1, 2),
'',
'R');
2928 foreach ($form->cache_vatrates as $TVatInfo) {
2929 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2930 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2936 $pdf->SetXY($x, $tab_top + 24 + $i);
2937 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2940 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2941 $pdf->SetXY($x, $tab_top + 28 + $i);
2942 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'TVA'], 0,
'', 1, -1, 2),
'',
'R');
2949 $pdf->SetXY($x, $tab_top + 33 + $i);
2950 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2953 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2954 $pdf->SetXY($x, $tab_top + 58);
2955 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2956 $pdf->SetFont(
'',
'', $default_font_size - 2);
2959 if ($displayWarranty) {
2961 $pdf->SetXY($x, $tab_top + 74);
2962 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'retenue_garantie'], 0,
'', 1, -1, 2),
'',
'R');
2963 $nextY = $tab_top + 93;
2965 $nextY = $tab_top + 74;
2969 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2970 $pdf->SetXY($x, $nextY);
2971 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'total_a_payer'], 0,
'', 1, -1, 2),
'',
'R');
2972 $pdf->SetFont(
'',
'', $default_font_size - 2);