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();
552 $qrcodestring =
$object->buildEPCQrCodeString();
557 $qrcodecolor = array(
'25',
'25',
'25');
562 'fgcolor' => $qrcodecolor,
567 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
571 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
572 $pdf->SetFont(
'',
'', $default_font_size - 4);
573 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
577 $extra_under_address_shift += 25;
585 'outputlangs' => $outputlangs,
586 'hidedetails' => $hidedetails
588 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
589 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
590 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
593 $this->tab_top += $extra_under_address_shift;
594 $this->tab_top_newpage += 0;
598 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
600 $nexY = $this->tab_top - 1;
610 $tab_height_newpage = 150;
612 $this->
tableFirstPage($pdf, $tab_top, $this->page_hauteur - 100 - $this->heightforfreetext - $this->heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
614 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
622 $pdf->setTopMargin($this->tab_top_newpage);
637 $nexY = $this->tab_top_newpage + $this->tabTitleHeight;
640 $pageposbeforeprintlines = $pdf->getPage();
641 $pagenb = $pageposbeforeprintlines;
643 $pdf_sub_options = array();
644 $pdf_sub_options[
'titleshowuponpdf'] = 1;
645 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
647 for ($i = 0; $i < $nblines; $i++) {
648 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
650 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
651 $level =
$object->lines[$i]->qty;
653 if (isset($sub_options[
'titleshowuponpdf'])) {
654 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
655 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
656 unset($pdf_sub_options[
'titleshowuponpdf']);
658 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
659 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
660 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
661 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
664 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
665 unset($pdf_sub_options[
'titleshowuponpdf']);
667 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
668 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
673 $parameters = array(
'i' => $i,
'object' =>
$object);
674 $reshook = $hookmanager->executeHooks(
'beforePrintPDFline', $parameters, $this, $action);
675 if ($reshook > 0 && !empty($hookmanager->resArray[
'object'])) {
676 $object = $hookmanager->resArray[
'object'];
678 $linePosition = $i + 1;
681 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
683 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
684 $level =
$object->lines[$i]->qty;
686 if (isset($sub_options[
'titleshowuponpdf'])) {
687 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
688 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
689 unset($pdf_sub_options[
'titleshowuponpdf']);
691 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
692 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
693 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
694 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
697 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
698 unset($pdf_sub_options[
'titleshowuponpdf']);
700 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
701 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
705 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
706 $object->lines[$i]->pagebreak =
true;
710 $pdf->SetFont(
'',
'', $default_font_size - 1);
711 $pdf->SetTextColor(0, 0, 0);
714 $imglinesize = array();
715 if (!empty($realpatharray[$i])) {
719 $pdf->setTopMargin($this->tab_top_newpage);
720 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot);
721 $pageposbefore = $pdf->getPage();
724 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
727 $posYAfterDescription = 0;
732 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($posy + $imglinesize[
'height']) > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
733 $pdf->AddPage(
'',
'',
true);
734 if (!empty($this->tplidx)) {
735 $pdf->useTemplate($this->tplidx);
737 $pdf->setPage($pageposbefore + 1);
738 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
739 $posy = $this->tab_top_newpage;
743 $showpricebeforepagebreak = 0;
747 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
748 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $posy + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
750 $posYAfterImage = $posy + $imglinesize[
'height'];
757 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
761 $pdf->startTransaction();
764 $pageposafter = $pdf->getPage();
766 if ($pageposafter > $pageposbefore) {
767 $pdf->rollbackTransaction(
true);
768 $pageposafter = $pageposbefore;
769 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
773 $pageposafter = $pdf->getPage();
774 $posyafter = $pdf->GetY();
776 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
777 if ($i == ($nblines - 1)) {
778 $pdf->AddPage(
'',
'',
true);
779 if (!empty($this->tplidx)) {
780 $pdf->useTemplate($this->tplidx);
782 $pdf->setPage($pageposafter + 1);
788 $showpricebeforepagebreak = 1;
790 $showpricebeforepagebreak = 0;
794 $pdf->commitTransaction();
796 $posYAfterDescription = $pdf->GetY();
799 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
801 $pageposafter = $pdf->getPage();
802 $pdf->setPage($pageposbefore);
803 $pdf->setTopMargin($this->marge_haute);
804 $pdf->setPageOrientation(
'',
true, 0);
807 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
808 $pdf->setPage($pageposafter);
809 $posy = $this->tab_top_newpage;
814 $pdf->SetFont(
'',
'', $default_font_size - 1);
825 $nexY = max($pdf->GetY(), $nexY);
829 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
832 $nexY = max($pdf->GetY(), $nexY);
840 $nexY = max($pdf->GetY(), $nexY);
847 $nexY = max($pdf->GetY(), $nexY);
854 $nexY = max($pdf->GetY(), $nexY);
858 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
861 $nexY = max($pdf->GetY(), $nexY);
866 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
869 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
871 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
873 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
877 $nexY = max($pdf->GetY(), $nexY);
884 $columkey =
'btpsomme';
886 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht_without_progress'], 0,
'', 1, -1, 2);
888 $nexY = max($pdf->GetY(), $nexY);
892 $columkey =
'progress_amount';
894 $printval =
price(
$object->lines[$i]->total_ht, 0,
'', 1, -1, 2);
896 $nexY = max($pdf->GetY(), $nexY);
899 $columkey =
'prev_progress';
901 $printval = $TInfosLigneSituationPrecedente[
'progress_prec'].
'%';
903 $nexY = max($pdf->GetY(), $nexY);
906 $columkey =
'prev_progress_amount';
908 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht'], 0,
'', 1, -1, 2);
910 $nexY = max($pdf->GetY(), $nexY);
919 'nexY' => & $afterPosData[
'y'],
920 'outputlangs' => $outputlangs,
921 'hidedetails' => $hidedetails
923 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
932 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
934 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
936 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
940 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
942 $tvaligne = $sign *
$object->lines[$i]->total_tva;
946 $localtax1ligne =
$object->lines[$i]->total_localtax1;
947 $localtax2ligne =
$object->lines[$i]->total_localtax2;
948 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
949 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
950 $localtax1_type =
$object->lines[$i]->localtax1_type;
951 $localtax2_type =
$object->lines[$i]->localtax2_type;
956 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
957 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
959 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
960 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
964 if ($localtax1_type && $localtax1ligne != 0) {
965 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
966 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
968 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
971 if ($localtax2_type && $localtax2ligne != 0) {
972 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
973 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
975 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
979 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
985 $vatcode =
$object->lines[$i]->vat_src_code;
986 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
987 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
990 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
991 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
993 $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);
995 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
999 $pdf->setPage($afterPosData[
'page']);
1000 $nexY = max($nexY, $posYAfterImage);
1003 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1004 $pdf->setPage($pageposafter);
1005 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1007 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1008 $pdf->SetLineStyle(array(
'dash' => 0));
1012 while ($pagenb < $pageposafter) {
1013 $pdf->setPage($pagenb);
1014 $tabtop = $this->tab_top;
1015 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1016 if ($pagenb != $pageposbeforeprintlines) {
1017 $tabtop = $this->tab_top_newpage;
1018 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1021 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1025 $pdf->setPage($pagenb);
1026 $pdf->setPageOrientation(
'',
true, 0);
1030 if (!empty($this->tplidx)) {
1031 $pdf->useTemplate($this->tplidx);
1035 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
1036 $tabtop = $this->tab_top;
1037 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1038 if ($pagenb != $pageposbeforeprintlines) {
1039 $tabtop = $this->tab_top_newpage;
1040 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1043 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1048 if (!empty($this->tplidx)) {
1049 $pdf->useTemplate($this->tplidx);
1060 $tabtop = $this->tab_top_newpage;
1061 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1062 $tabTitleHeight = 0;
1063 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1066 $pdf->SetTextColor(0, 0, 0);
1068 $pdf->setPage($pdf->getNumPages());
1070 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1077 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1080 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1081 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1088 if (method_exists($pdf,
'AliasNbPages')) {
1089 $pdf->AliasNbPages();
1093 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1094 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1095 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1096 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1098 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1099 $pagecount = $pdf->setSourceFile($termsofsale);
1100 for ($i = 1; $i <= $pagecount; $i++) {
1101 $tplIdx = $pdf->importPage($i);
1102 if ($tplIdx !==
false) {
1103 $s = $pdf->getTemplatesize($tplIdx);
1104 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1105 $pdf->useTemplate($tplIdx);
1107 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1113 $this->resumeLastPage($pdf,
$object, 0, $tab_top, $outputlangs, $outputlangsbis);
1114 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1123 $pdf->Output($file,
'F');
1126 $hookmanager->initHooks(array(
'pdfgeneration'));
1127 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1129 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1130 $this->warnings = $hookmanager->warnings;
1132 $this->error = $hookmanager->error;
1133 $this->errors = $hookmanager->errors;
1140 $this->result = array(
'fullpath' => $file);
1144 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1148 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1171 $tab3_top = $posy + 8;
1174 if ($this->page_largeur < 210) {
1180 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1182 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1185 $pdf->SetFont(
'',
'', $default_font_size - 3);
1186 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1187 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1189 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1191 $pdf->SetFont(
'',
'', $default_font_size - 4);
1192 $pdf->SetXY($tab3_posx, $tab3_top);
1193 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1194 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1195 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1196 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1197 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1198 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1199 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1201 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1205 $pdf->SetFont(
'',
'', $default_font_size - 4);
1209 $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,";
1210 $sql .=
" re.description, re.fk_facture_source,";
1211 $sql .=
" f.type, f.datef";
1212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1213 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1214 $resql = $this->db->query($sql);
1216 $num = $this->db->num_rows($resql);
1218 $invoice =
new Facture($this->db);
1221 $obj = $this->db->fetch_object($resql);
1223 if ($obj->type == 2) {
1224 $text = $outputlangs->transnoentities(
"CreditNote");
1225 } elseif ($obj->type == 3) {
1226 $text = $outputlangs->transnoentities(
"Deposit");
1227 } elseif ($obj->type == 0) {
1228 $text = $outputlangs->transnoentities(
"ExcessReceived");
1230 $text = $outputlangs->transnoentities(
"UnknownType");
1233 $invoice->fetch($obj->fk_facture_source);
1235 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1236 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1237 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1238 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1239 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1240 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1241 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1242 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1244 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1249 $this->error = $this->db->lasterror();
1255 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1257 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1258 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1259 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1261 $sql .=
" ORDER BY p.datep";
1263 $resql = $this->db->query($sql);
1265 $num = $this->db->num_rows($resql);
1270 $row = $this->db->fetch_object($resql);
1271 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1272 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1273 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1274 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1275 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1276 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1278 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1279 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1280 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1281 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1282 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1283 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1288 return $tab3_top + $y + 3;
1290 $this->error = $this->db->lasterror();
1312 $pdf->SetFont(
'',
'', $default_font_size - 1);
1314 krsort($this->tva_array);
1321 $pdf->SetFillColor(224, 224, 224);
1323 $pdf->SetFont(
'',
'', $default_font_size - 2);
1324 $pdf->SetXY($this->marge_gauche, $posy);
1325 $titre = $outputlangs->transnoentities(
"VAT");
1326 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1328 $pdf->SetFont(
'',
'', $default_font_size - 2);
1329 $pdf->SetXY($this->marge_gauche + 25, $posy);
1330 $titre = $outputlangs->transnoentities(
"NetTotal");
1331 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1333 $pdf->SetFont(
'',
'', $default_font_size - 2);
1334 $pdf->SetXY($this->marge_gauche + 50, $posy);
1335 $titre = $outputlangs->transnoentities(
"VATAmount");
1336 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1338 $pdf->SetFont(
'',
'', $default_font_size - 2);
1339 $pdf->SetXY($this->marge_gauche + 75, $posy);
1340 $titre = $outputlangs->transnoentities(
"AmountTotal");
1341 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1343 $posy = $pdf->GetY();
1348 foreach ($this->tva_array as $tvakey => $tvaval) {
1349 $pdf->SetFont(
'',
'', $default_font_size - 2);
1350 $pdf->SetXY($this->marge_gauche, $posy);
1351 $titre = round((
float) $tvakey, 2) .
"%";
1352 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1354 $pdf->SetFont(
'',
'', $default_font_size - 2);
1355 $pdf->SetXY($this->marge_gauche + 25, $posy);
1356 $titre =
price($tvaval[
'tot_ht']);
1357 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1358 $tot_ht += $tvaval[
'tot_ht'];
1360 $pdf->SetFont(
'',
'', $default_font_size - 2);
1361 $pdf->SetXY($this->marge_gauche + 50, $posy);
1362 $titre =
price($tvaval[
'amount']);
1363 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1364 $tot_tva += $tvaval[
'amount'];
1366 $pdf->SetFont(
'',
'', $default_font_size - 2);
1367 $pdf->SetXY($this->marge_gauche + 75, $posy);
1368 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1369 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1370 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1372 $posy = $pdf->GetY();
1377 $showvatmention = 0;
1378 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1379 $pdf->SetFont(
'',
'', $default_font_size - 2);
1380 $pdf->SetXY($this->marge_gauche, $posy);
1381 if (empty(
$mysoc->tva_assuj)) {
1382 if (
$mysoc->forme_juridique_code == 92) {
1383 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1385 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1388 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1389 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1392 $posy = $pdf->GetY();
1395 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1397 if ($showvatmention) {
1404 if ($this->page_largeur < 210) {
1411 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1412 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1413 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1414 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1415 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1416 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1417 $sql .=
" AND f.fk_statut > 0";
1418 $sql .=
" ORDER BY f.datef ASC";
1421 $invoices = array();
1422 $resql = $this->db->query($sql);
1424 while ($obj = $this->db->fetch_object($resql)) {
1426 $old_balance += $obj->total_ttc;
1428 $this->db->free($resql);
1432 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1433 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1434 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1435 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1436 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1437 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1438 $sql_payments .=
" ORDER BY p.datep ASC";
1440 $total_payments = 0;
1441 $resql_payments = $this->db->query($sql_payments);
1442 if ($resql_payments) {
1443 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1444 $total_payments += $obj_payment->amount;
1446 $this->db->free($resql_payments);
1450 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1451 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1452 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1453 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1454 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1455 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1457 $current_date_payments = 0;
1458 $resql_current_date = $this->db->query($sql_current_date_payments);
1459 if ($resql_current_date) {
1460 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1461 $current_date_payments += $obj_current->amount;
1463 $this->db->free($resql_current_date);
1467 $old_balance -= $total_payments;
1470 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1472 $pdf->SetFillColor(224, 224, 224);
1473 $pdf->SetFont(
'',
'', $default_font_size - 2);
1474 $pdf->SetXY($this->marge_gauche, $posy);
1475 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1476 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1478 $pdf->SetFont(
'',
'', $default_font_size - 2);
1479 $pdf->SetXY($posxval + 8, $posy);
1480 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1481 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1483 $posy = $pdf->GetY() + 1;
1488 $pdf->SetFont(
'',
'', $default_font_size - 2);
1489 $pdf->SetXY($this->marge_gauche, $posy);
1490 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1491 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1493 $pdf->SetFont(
'',
'', $default_font_size - 2);
1494 $pdf->SetXY($posxval, $posy);
1495 $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);
1496 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1497 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1499 $posy = $pdf->GetY() + 3;
1503 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1504 $pdf->SetFont(
'',
'', $default_font_size - 2);
1505 $pdf->SetXY($this->marge_gauche, $posy);
1506 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1507 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1509 $pdf->SetFont(
'',
'', $default_font_size - 2);
1510 $pdf->SetXY($posxval, $posy);
1511 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1512 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1514 $posy = $pdf->GetY() + 3;
1519 if (empty(
$object->mode_reglement_code)
1522 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1526 $outputlangs->load(
"errors");
1528 $pdf->SetXY($this->marge_gauche, $posy);
1529 $pdf->SetTextColor(200, 0, 0);
1530 $pdf->SetFont(
'',
'', $default_font_size - 2);
1531 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1532 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1533 $pdf->SetTextColor(0, 0, 0);
1535 $posy = $pdf->GetY() + 1;
1539 if (!empty(
$object->mode_reglement_code)
1540 &&
$object->mode_reglement_code !=
'CHQ'
1541 &&
$object->mode_reglement_code !=
'VIR') {
1542 $pdf->SetFont(
'',
'', $default_font_size - 2);
1543 $pdf->SetXY($this->marge_gauche, $posy);
1544 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1545 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1547 $pdf->SetFont(
'',
'', $default_font_size - 2);
1548 $pdf->SetXY($posxval, $posy);
1549 $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);
1552 if (
$object->mode_reglement_code ==
"PRE") {
1553 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1556 $bac->fetch(0,
'',
$object->thirdparty->id);
1557 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1558 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1561 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1563 $posy = $pdf->GetY();
1569 if ($this->emetteur->country_code ==
'FR') {
1571 $pdf->SetXY($this->marge_gauche, $posy);
1572 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1574 $posy = $pdf->GetY() + 1;
1579 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1580 $useonlinepayment = 0;
1584 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1585 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1586 $useonlinepayment = count($validpaymentmethod);
1591 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1594 $langs->loadLangs(array(
'payment',
'stripe'));
1595 $servicename = $langs->transnoentities(
'Online');
1596 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1597 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1599 $pdf->SetXY($this->marge_gauche, $posy);
1600 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1602 $posy = $pdf->GetY() + 1;
1607 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1613 $account =
new Account($this->db);
1616 $pdf->SetXY($this->marge_gauche, $posy);
1617 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1618 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1619 $posy = $pdf->GetY() + 1;
1622 $pdf->SetXY($this->marge_gauche, $posy);
1623 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1624 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1625 $posy = $pdf->GetY() + 2;
1629 $pdf->SetXY($this->marge_gauche, $posy);
1630 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1631 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1632 $posy = $pdf->GetY() + 1;
1635 $pdf->SetXY($this->marge_gauche, $posy);
1636 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1637 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1638 $posy = $pdf->GetY() + 2;
1645 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1651 $account =
new Account($this->db);
1652 $account->fetch($bankid);
1654 $curx = $this->marge_gauche;
1657 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1663 $qrPosX = $this->marge_gauche + 5;
1665 $qrCodeColor = array(
'25',
'25',
'25');
1669 'fgcolor' => $qrCodeColor,
1671 'module_width' => 1,
1672 'module_height' => 1
1675 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1676 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1678 $pdf->SetXY($qrPosX + 25, $posy + 5);
1679 $pdf->SetFont(
'',
'', $default_font_size - 5);
1680 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1681 $posy = $pdf->GetY() + 2;
1686 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1689 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1721 $tab2_top = $posy - 4;
1723 if (is_object($outputlangsbis)) {
1724 $pdf->SetFont(
'',
'', $default_font_size - 2);
1726 $pdf->SetFont(
'',
'', $default_font_size - 1);
1732 if ($this->page_largeur < 210) {
1736 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1742 $pdf->SetFillColor(255, 255, 255);
1743 $pdf->SetXY($col1x, $tab2_top + 0);
1744 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1747 $pdf->SetXY($col2x, $tab2_top + 0);
1748 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1752 $pdf->SetFillColor(255, 255, 255);
1753 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1754 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1756 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1757 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1761 $pdf->SetFillColor(248, 248, 248);
1764 $total_ttc_origin =
$object->total_ttc;
1766 $this->atleastoneratenotnull = 0;
1769 if (!empty($this->tva_array) && count($this->tva_array) == 1) {
1770 $tva_el = reset($this->tva_array);
1771 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) {
1775 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1779 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1784 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1785 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1787 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1788 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1793 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1794 $pdf->SetTextColor(0, 0, 60);
1795 $pdf->SetFillColor(224, 224, 224);
1796 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1798 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1800 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1802 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1806 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1807 $pdf->SetTextColor(0, 0, 60);
1808 $pdf->SetFillColor(224, 224, 224);
1809 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1811 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1812 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1817 if (
$object->displayRetainedWarranty()) {
1818 $pdf->SetTextColor(40, 40, 40);
1819 $pdf->SetFillColor(255, 255, 255);
1821 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
1822 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
1826 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1827 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
1829 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1830 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
1834 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1836 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
1837 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
1839 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
1840 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1841 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
1846 $pdf->SetTextColor(0, 0, 0);
1848 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1851 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1854 $deja_regle_origin = 0;
1855 $creditnoteamount_origin = 0;
1856 $depositsamount_origin = 0;
1857 $resteapayer_origin = 0;
1859 $deja_regle_origin =
$object->getSommePaiement(0);
1860 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
1861 $depositsamount_origin =
$object->getSumDepositsUsed(0);
1862 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
1866 $resteapayer_origin = 0;
1869 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
1871 $pdf->SetFont(
'',
'', $default_font_size - 1);
1872 $pdf->SetTextColor(0, 0, 0);
1874 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1876 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1878 $this->error = $hookmanager->error;
1879 $this->errors = $hookmanager->errors;
1883 return ($tab2_top + ($tab2_hl * $index));
2009 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2012 global
$conf, $langs;
2014 $ltrdirection =
'L';
2015 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2016 $ltrdirection =
'R';
2020 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2026 $pdf->SetTextColor(0, 0, 60);
2027 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2031 $posy = $this->marge_haute;
2032 $posx = $this->page_largeur - $this->marge_droite - $w;
2034 $pdf->SetXY($this->marge_gauche, $posy);
2038 if ($this->emetteur->logo) {
2039 $logodir =
$conf->mycompany->dir_output;
2040 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2044 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2046 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2048 if (is_readable($logo)) {
2050 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2052 $pdf->SetTextColor(200, 0, 0);
2053 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2054 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2055 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2058 $text = $this->emetteur->name;
2059 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2063 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2064 $pdf->SetXY($posx, $posy);
2065 $pdf->SetTextColor(0, 0, 60);
2067 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2069 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2072 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2075 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2077 if ($this->situationinvoice) {
2078 $outputlangs->loadLangs(array(
"other"));
2079 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2080 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2082 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2085 if ($this->situationinvoice) {
2086 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2088 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2089 } elseif (
$object->type == 1) {
2090 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2091 } elseif (
$object->type == 2) {
2092 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2093 } elseif (
$object->type == 3) {
2094 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2095 } elseif (
$object->type == 4) {
2096 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2099 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2100 if (
$object->status == $object::STATUS_DRAFT) {
2101 $pdf->SetTextColor(128, 0, 0);
2102 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2105 $pdf->MultiCell($w, 3, $title,
'',
'R');
2106 if (!empty($subtitle)) {
2107 $pdf->SetFont(
'',
'B', $default_font_size);
2108 $pdf->SetXY($posx, $posy + 5);
2109 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2113 $pdf->SetFont(
'',
'', $default_font_size - 2);
2130 $pdf->SetFont(
'',
'', $default_font_size - 2);
2134 $pdf->SetXY($posx, $posy);
2135 $pdf->SetTextColor(0, 0, 60);
2136 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2141 if (!empty(
$object->project->title)) {
2143 $pdf->SetXY($posx, $posy);
2144 $pdf->SetTextColor(0, 0, 60);
2145 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
dol_trunc(
$object->project->title, 50),
'',
'R');
2151 if (!empty(
$object->project->ref)) {
2152 $outputlangs->load(
"projects");
2154 $pdf->SetXY($posx, $posy);
2155 $pdf->SetTextColor(0, 0, 60);
2156 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2160 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2161 if (
$object->type == 0 && $objectidnext) {
2162 $objectreplacing =
new Facture($this->db);
2163 $objectreplacing->fetch($objectidnext);
2166 $pdf->SetXY($posx, $posy);
2167 $pdf->SetTextColor(0, 0, 60);
2168 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2171 $objectreplaced =
new Facture($this->db);
2172 $objectreplaced->fetch(
$object->fk_facture_source);
2175 $pdf->SetXY($posx, $posy);
2176 $pdf->SetTextColor(0, 0, 60);
2177 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2180 $objectreplaced =
new Facture($this->db);
2181 $objectreplaced->fetch(
$object->fk_facture_source);
2184 $pdf->SetXY($posx, $posy);
2185 $pdf->SetTextColor(0, 0, 60);
2186 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2190 $pdf->SetXY($posx, $posy);
2191 $pdf->SetTextColor(0, 0, 60);
2193 $title = $outputlangs->transnoentities(
"DateInvoice");
2194 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2195 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2197 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2201 $pdf->SetXY($posx, $posy);
2202 $pdf->SetTextColor(0, 0, 60);
2203 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2208 $pdf->SetXY($posx, $posy);
2209 $pdf->SetTextColor(0, 0, 60);
2210 $title = $outputlangs->transnoentities(
"DateDue");
2211 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2212 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2214 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2219 $pdf->SetXY($posx, $posy);
2220 $pdf->SetTextColor(0, 0, 60);
2221 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2226 $pdf->SetXY($posx, $posy);
2227 $pdf->SetTextColor(0, 0, 60);
2228 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2233 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2234 if (count($arrayidcontact) > 0) {
2235 $usertmp =
new User($this->db);
2236 $usertmp->fetch($arrayidcontact[0]);
2238 $pdf->SetXY($posx, $posy);
2239 $pdf->SetTextColor(0, 0, 60);
2240 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2250 $current_y = $pdf->getY();
2252 if ($current_y < $pdf->getY()) {
2253 $top_shift = $pdf->getY() - $current_y;
2259 $carac_emetteur =
'';
2261 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2262 if (count($arrayidcontact) > 0) {
2263 $object->fetch_user($arrayidcontact[0]);
2264 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2265 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2266 $carac_emetteur .=
"\n";
2272 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2273 $posy += $top_shift;
2274 $posx = $this->marge_gauche;
2276 $posx = $this->page_largeur - $this->marge_droite - 80;
2284 $pdf->SetTextColor(0, 0, 0);
2285 $pdf->SetFont(
'',
'', $default_font_size - 2);
2286 $pdf->SetXY($posx, $posy - 5);
2287 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2288 $pdf->SetXY($posx, $posy);
2289 $pdf->SetFillColor(230, 230, 230);
2290 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2291 $pdf->SetTextColor(0, 0, 60);
2296 $pdf->SetXY($posx + 2, $posy + 3);
2297 $pdf->SetFont(
'',
'B', $default_font_size);
2298 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2299 $posy = $pdf->getY();
2303 $pdf->SetXY($posx + 2, $posy);
2304 $pdf->SetFont(
'',
'', $default_font_size - 1);
2305 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2308 $usecontact =
false;
2309 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2310 if (count($arrayidcontact) > 0) {
2312 $result =
$object->fetch_contact($arrayidcontact[0]);
2316 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2317 $thirdparty =
$object->contact;
2319 $thirdparty =
$object->thirdparty;
2329 if ($this->page_largeur < 210) {
2332 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2333 $posy += $top_shift;
2334 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2336 $posx = $this->marge_gauche;
2341 $pdf->SetTextColor(0, 0, 0);
2342 $pdf->SetFont(
'',
'', $default_font_size - 2);
2343 $pdf->SetXY($posx + 2, $posy - 5);
2344 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2345 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2349 $pdf->SetXY($posx + 2, $posy + 3);
2350 $pdf->SetFont(
'',
'B', $default_font_size);
2352 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2354 $posy = $pdf->getY();
2357 $pdf->SetFont(
'',
'', $default_font_size - 1);
2358 $pdf->SetXY($posx + 2, $posy);
2360 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2364 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2366 if (!empty($idaddressshipping)) {
2367 $object->fetch_contact($idaddressshipping[0]);
2368 $companystatic =
new Societe($this->db);
2369 $companystatic->fetch(
$object->contact->fk_soc);
2376 if (!empty($carac_client_shipping)) {
2377 $posy += $hautcadre;
2382 $pdf->SetXY($posx + 2, $posy - 5);
2383 $pdf->SetFont(
'',
'', $default_font_size - 2);
2384 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2385 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2388 $pdf->SetXY($posx + 2, $posy + 3);
2389 $pdf->SetFont(
'',
'B', $default_font_size);
2390 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2392 $posy = $pdf->getY();
2395 $pdf->SetXY($posx + 2, $posy);
2396 $pdf->SetFont(
'',
'', $default_font_size - 1);
2397 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2399 $shipp_shift += $hautcadre;
2404 $pdf->SetTextColor(0, 0, 0);
2406 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);
2749 public function tableFirstPage(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
2757 if (!$displayWarranty) {
2768 $currency = !empty($currency) ? $currency : (
string)
$conf->currency;
2772 $pdf->SetTextColor(0, 0, 0);
2773 $pdf->SetFont(
'',
'', $default_font_size - 2);
2775 if (empty($hidetop)) {
2776 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
2777 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
2778 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2780 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
2784 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius,
'1001',
'F', explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2786 $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')));
2790 $pdf->SetDrawColor(128, 128, 128);
2791 $pdf->SetFont(
'',
'', $default_font_size - 1);
2793 $height_incoterms = 0;
2795 $desc_incoterms =
$object->getIncotermsForPDF();
2796 if ($desc_incoterms) {
2797 $this->tab_top -= 2;
2798 $posybefore = $pdf->GetY();
2799 $pdf->SetFont(
'',
'', $default_font_size - 1);
2800 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
2803 $pdf->SetDrawColor(192, 192, 192);
2804 $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');
2805 $posyafter = $pdf->GetY();
2806 $tab_top += $posyafter - $posybefore + 2;
2810 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
2813 if (is_object(
$object->thirdparty)) {
2814 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
2815 $salerepobj =
new User($this->db);
2816 $salerepobj->fetch($salereparray[0][
'id']);
2817 if (!empty($salerepobj->signature)) {
2818 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
2824 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
2825 if (!empty($extranote)) {
2831 $posybefore = $pdf->GetY();
2837 $pdf->SetFont(
'',
'', $default_font_size - 1);
2838 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
2840 $posyafter = $pdf->GetY();
2841 $tab_top += $posyafter - $posybefore + 2;
2846 $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');
2848 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
2849 if (empty($hidetop)) {
2850 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
2851 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceOldCumulation"),
'',
'C');
2855 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
2856 if (empty($hidetop)) {
2857 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
2858 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceNewCumulation"),
'',
'C');
2861 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
2862 if (empty($hidetop)) {
2863 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
2864 $pdf->MultiCell(36, 2, $outputlangs->transnoentities(
"CurrentSituationTotal", (
string)
$object->situation_counter),
'',
'C');
2868 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2870 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
2872 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
2874 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
2876 if ($displayWarranty) {
2877 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
2883 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
2884 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceMainTask"),
'',
'L');
2886 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
2887 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceAdditionalTask"),
'',
'L');
2889 $form->load_cache_vatrates(
"'".
$object->thirdparty->country_code.
"'");
2892 foreach ($form->cache_vatrates as $TVatInfo) {
2893 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2895 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2900 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
2901 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalHT").
' '.$TVatInfo[
'label'],
'',
'L');
2903 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2904 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
2905 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"VAT").
' '.$TVatInfo[
'label'],
'',
'L');
2911 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
2912 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalTTC"),
'',
'L');
2915 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2916 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
2917 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalSituationInvoice"),
'',
'L');
2918 $pdf->SetFont(
'',
'', $default_font_size - 2);
2920 if ($displayWarranty) {
2921 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
2922 $pdf->MultiCell(80, 2, $outputlangs->trans(
"TotalSituationInvoiceWithRetainedWarranty", (
string)
$object->retained_warranty),
'',
'L');
2923 $nextY = $tab_top + 93;
2925 $nextY = $tab_top + 74;
2928 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2929 $pdf->SetXY($this->marge_gauche + 2, $nextY);
2930 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"SituationTotalRayToRest"),
'',
'L');
2931 $pdf->SetFont(
'',
'', $default_font_size - 2);
2935 $TToDisplay = array(
2941 $x = $this->marge_gauche + 85;
2945 foreach ($TToDisplay as $col) {
2947 $pdf->SetXY($x, $tab_top + 8);
2948 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2951 $pdf->SetXY($x, $tab_top + 12);
2952 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'travaux_sup'], 0,
'', 1, -1, 2),
'',
'R');
2955 foreach ($form->cache_vatrates as $TVatInfo) {
2956 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2957 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2963 $pdf->SetXY($x, $tab_top + 24 + $i);
2964 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2967 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2968 $pdf->SetXY($x, $tab_top + 28 + $i);
2969 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'TVA'], 0,
'', 1, -1, 2),
'',
'R');
2976 $pdf->SetXY($x, $tab_top + 33 + $i);
2977 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2980 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2981 $pdf->SetXY($x, $tab_top + 58);
2982 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2983 $pdf->SetFont(
'',
'', $default_font_size - 2);
2986 if ($displayWarranty) {
2988 $pdf->SetXY($x, $tab_top + 74);
2989 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'retenue_garantie'], 0,
'', 1, -1, 2),
'',
'R');
2990 $nextY = $tab_top + 93;
2992 $nextY = $tab_top + 74;
2996 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2997 $pdf->SetXY($x, $nextY);
2998 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'total_a_payer'], 0,
'', 1, -1, 2),
'',
'R');
2999 $pdf->SetFont(
'',
'', $default_font_size - 2);