203 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
206 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
208 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
210 if (!is_object($outputlangs)) {
211 $outputlangs = $langs;
215 $outputlangs->charset_output =
'ISO-8859-1';
219 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
221 global $outputlangsbis;
222 $outputlangsbis =
null;
226 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
234 $nblines = count(
$object->lines);
242 $realpatharray = array();
243 $this->atleastonephoto =
false;
245 $objphoto =
new Product($this->db);
247 for ($i = 0; $i < $nblines; $i++) {
248 if (empty(
$object->lines[$i]->fk_product)) {
252 $objphoto->fetch(
$object->lines[$i]->fk_product);
256 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
257 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
259 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
260 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
265 foreach ($pdir as $midir) {
267 if (
$conf->entity != $objphoto->entity) {
268 $dir =
$conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
270 $dir =
$conf->product->dir_output.
'/'.$midir;
273 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
275 if ($obj[
'photo_vignette']) {
276 $filename = $obj[
'photo_vignette'];
278 $filename = $obj[
'photo'];
281 $filename = $obj[
'photo'];
284 $realpath = $dir.$filename;
286 $this->atleastonephoto =
true;
291 if ($realpath && $arephoto) {
292 $realpatharray[$i] = $realpath;
299 if (
$conf->facture->multidir_output[
$conf->entity]) {
302 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
303 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
304 $amount_deposits_included =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
308 $dir =
$conf->facture->multidir_output[
$conf->entity];
309 $file = $dir.
"/SPECIMEN.pdf";
312 $dir =
$conf->facture->multidir_output[
$object->entity].
"/".$objectref;
313 $file = $dir.
"/".$objectref.
".pdf";
315 if (!file_exists($dir)) {
317 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
322 if (file_exists($dir)) {
324 if (!is_object($hookmanager)) {
325 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
328 $hookmanager->initHooks(array(
'pdfgeneration'));
329 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
331 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
334 $nblines = count(
$object->lines);
335 $nbpayments = count(
$object->getListOfPayments());
340 $pdf->setAutoPageBreak(
true, 0);
342 $this->heightforinfotot = 50 + (4 * $nbpayments);
343 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
344 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
346 $heightforqrinvoice = 0;
350 $this->heightforinfotot = 30 + (4 * $nbpayments);
354 if (class_exists(
'TCPDF')) {
355 $pdf->setPrintHeader(
false);
356 $pdf->setPrintFooter(
false);
362 $logodir =
$conf->mycompany->dir_output;
363 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
364 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
366 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
367 $tplidx = $pdf->importPage(1);
372 $pdf->SetDrawColor(128, 128, 128);
374 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
375 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
376 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
377 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
378 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
380 $pdf->SetCompression(
false);
384 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
385 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
396 'Name' => $this->emetteur->name,
397 'Location' =>
getCountry($this->emetteur->country_code,
''),
398 'Reason' =>
'INVOICE',
399 'ContactInfo' => $this->emetteur->email
401 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
405 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
409 $categoryOfOperation = 0;
412 for ($i = 0; $i < $nblines; $i++) {
413 if (
$object->lines[$i]->remise_percent) {
414 $this->atleastonediscount++;
419 if (preg_match(
'/^\((.*)\)$/',
$object->lines[$i]->desc, $reg)) {
420 if ($reg[1] ==
'DEPOSIT') {
431 if ($categoryOfOperation < 2) {
432 $lineProductType =
$object->lines[$i]->product_type;
438 if ($nbProduct > 0 && $nbService > 0) {
440 $categoryOfOperation = 2;
445 if ($categoryOfOperation <= 0) {
447 if ($nbProduct == 0 && $nbService > 0) {
448 $categoryOfOperation = 1;
451 $this->categoryOfOperation = $categoryOfOperation;
454 if (
$object->situation_cycle_ref) {
455 $this->situationinvoice =
true;
460 if (!empty($tplidx)) {
461 $pdf->useTemplate($tplidx);
466 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
467 $top_shift = $pagehead[
'top_shift'];
468 $shipp_shift = $pagehead[
'shipp_shift'];
469 $pdf->SetFont(
'',
'', $default_font_size - 1);
470 $pdf->MultiCell(0, 3,
'');
471 $pdf->SetTextColor(0, 0, 0);
476 $this->tab_top = 90 + $top_shift + $shipp_shift;
477 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
480 $extra_under_address_shift = 0;
483 $qrcodestring =
$object->buildZATCAQRString();
486 $qrcodestring =
$object->buildSwitzerlandQRString();
490 $qrcodestring =
$object->buildEPCQrCodeString();
495 $qrcodecolor = array(
'25',
'25',
'25');
500 'fgcolor' => $qrcodecolor,
505 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
509 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
510 $pdf->SetFont(
'',
'', $default_font_size - 4);
511 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
515 $extra_under_address_shift += 25;
523 'outputlangs' => $outputlangs,
524 'hidedetails' => $hidedetails
526 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
527 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
528 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
531 $this->tab_top += $extra_under_address_shift;
532 $this->tab_top_newpage += 0;
536 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
538 $nexY = $this->tab_top - 1;
541 $height_incoterms = 0;
542 if (isModEnabled(
'incoterm')) {
543 $desc_incoterms =
$object->getIncotermsForPDF();
544 if ($desc_incoterms) {
547 $pdf->SetFont(
'',
'', $default_font_size - 1);
548 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
549 $nexY = max($pdf->GetY(), $nexY);
550 $height_incoterms = $nexY - $this->tab_top;
553 $pdf->SetDrawColor(192, 192, 192);
554 $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');
556 $this->tab_top = $nexY + 6;
557 $height_incoterms += 4;
562 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
565 if (is_object(
$object->thirdparty)) {
566 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
567 $salerepobj =
new User($this->db);
568 $salerepobj->fetch($salereparray[0][
'id']);
569 if (!empty($salerepobj->signature)) {
570 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
576 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
577 if (!empty($extranote)) {
581 $pagenb = $pdf->getPage();
585 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
586 $pageposbeforenote = $pagenb;
593 $pdf->startTransaction();
595 $pdf->SetFont(
'',
'', $default_font_size - 1);
596 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
598 $pageposafternote = $pdf->getPage();
599 $posyafter = $pdf->GetY();
601 if ($pageposafternote > $pageposbeforenote) {
602 $pdf->rollbackTransaction(
true);
605 while ($pagenb < $pageposafternote) {
608 if (!empty($tplidx)) {
609 $pdf->useTemplate($tplidx);
614 $pdf->setTopMargin($this->tab_top_newpage);
616 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
620 $pdf->setPage($pageposbeforenote);
621 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
622 $pdf->SetFont(
'',
'', $default_font_size - 1);
623 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
624 $pageposafternote = $pdf->getPage();
626 $posyafter = $pdf->GetY();
628 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
629 $pdf->AddPage(
'',
'',
true);
632 $pdf->setPage($pageposafternote);
633 $pdf->setTopMargin($this->tab_top_newpage);
635 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
641 $i = $pageposbeforenote;
642 while ($i < $pageposafternote) {
646 $pdf->SetDrawColor(128, 128, 128);
648 if ($i > $pageposbeforenote) {
649 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
650 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
652 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
653 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
657 $pdf->setPageOrientation(
'',
true, 0);
664 $pdf->setPage($pageposafternote);
665 if (!empty($tplidx)) {
666 $pdf->useTemplate($tplidx);
671 $height_note = $posyafter - $this->tab_top_newpage;
672 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
675 $pdf->commitTransaction();
676 $posyafter = $pdf->GetY();
677 $height_note = $posyafter - $this->tab_top;
678 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
681 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
683 $pdf->AddPage(
'',
'',
true);
686 $pdf->setPage($pageposafternote);
687 if (!empty($tplidx)) {
688 $pdf->useTemplate($tplidx);
694 $posyafter = $this->tab_top_newpage;
698 $tab_height -= $height_note;
699 $this->tab_top = $posyafter + 6;
708 $pdf->startTransaction();
709 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
710 $pdf->rollbackTransaction(
true);
712 $nexY = $this->tab_top + $this->tabTitleHeight;
715 $pageposbeforeprintlines = $pdf->getPage();
716 $pagenb = $pageposbeforeprintlines;
718 $pdf_sub_options = array();
719 $pdf_sub_options[
'titleshowuponpdf'] = 1;
720 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
722 for ($i = 0; $i < $nblines; $i++) {
723 $linePosition = $i + 1;
726 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
728 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
729 $level =
$object->lines[$i]->qty;
731 if (isset($sub_options[
'titleshowuponpdf'])) {
732 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
733 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
734 unset($pdf_sub_options[
'titleshowuponpdf']);
736 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
737 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
738 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
739 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
742 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
743 unset($pdf_sub_options[
'titleshowuponpdf']);
745 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
746 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
751 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
752 $object->lines[$i]->pagebreak =
true;
756 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
759 if (!empty($tplidx)) {
760 $pdf->useTemplate($tplidx);
763 $pdf->setPage($pdf->getNumPages());
764 $nexY = $curY = $this->tab_top_newpage;
769 $pdf->SetFont(
'',
'', $default_font_size - 1);
770 $pdf->SetTextColor(0, 0, 0);
773 $imglinesize = array();
774 if (!empty($realpatharray[$i])) {
778 $pdf->setTopMargin($this->tab_top_newpage);
779 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
780 $pageposbefore = $pdf->getPage();
784 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
789 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
790 $pdf->AddPage(
'',
'',
true);
791 if (!empty($tplidx)) {
792 $pdf->useTemplate($tplidx);
794 $pdf->setPage($pageposbefore + 1);
795 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
796 $curY = $this->tab_top_newpage;
797 $showpricebeforepagebreak = 0;
800 $pdf->setPageOrientation(
'',
false, $this->heightforfooter + $this->heightforfreetext);
802 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
803 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
805 $posYAfterImage = $curY + $imglinesize[
'height'];
812 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
816 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
821 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
827 $pdf->setPage($pageposbefore);
828 $pdf->setTopMargin($this->marge_haute);
830 $pdf->setPageOrientation(
'',
false, $this->heightforfooter);
833 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
834 $pdf->setPage($afterPosData[
'page']);
835 $curY = $this->tab_top_newpage;
838 $pdf->SetFont(
'',
'', $default_font_size - 1);
852 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
877 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
884 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
887 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
888 if (isModEnabled(
'multicurrency') &&
$object->multicurrency_code !=
$conf->currency) {
889 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
891 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
904 if (!empty(
$object->lines[$i]->array_options)) {
905 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
921 'nexY' => & $afterPosData[
'y'],
922 'outputlangs' => $outputlangs,
923 'hidedetails' => $hidedetails
925 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
933 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
934 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
935 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
936 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
938 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
941 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
942 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
944 $tvaligne = $sign *
$object->lines[$i]->total_tva;
948 $localtax1ligne =
$object->lines[$i]->total_localtax1;
949 $localtax2ligne =
$object->lines[$i]->total_localtax2;
950 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
951 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
952 $localtax1_type =
$object->lines[$i]->localtax1_type;
953 $localtax2_type =
$object->lines[$i]->localtax2_type;
955 $vatrate = (string)
$object->lines[$i]->tva_tx;
958 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
959 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
961 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
962 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
966 if ($localtax1_type && $localtax1ligne != 0) {
967 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
968 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
970 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
973 if ($localtax2_type && $localtax2ligne != 0) {
974 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
975 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
977 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
981 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
986 if (!isset($this->tva[$vatrate])) {
987 $this->tva[$vatrate] = 0;
989 $this->tva[$vatrate] += $tvaligne;
990 $vatcode =
$object->lines[$i]->vat_src_code;
992 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
993 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
995 $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);
997 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
998 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
1000 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1004 $pdf->setPage($afterPosData[
'page']);
1005 $nexY = $afterPosData[
'y'];
1008 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1009 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1011 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1012 $pdf->SetLineStyle(array(
'dash' => 0));
1020 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
1022 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
1024 if (!empty($tplidx)) {
1025 $pdf->useTemplate($tplidx);
1028 $pdf->setPage($pagenb);
1032 $drawTabNumbPage = $pdf->getNumPages();
1033 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1036 $pdf->setPageOrientation(
'',
false, 0);
1038 $drawTabHideTop = $hidetop;
1039 $drawTabTop = $this->tab_top_newpage;
1040 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1043 if ($i == $pageposbeforeprintlines) {
1045 $drawTabTop = $this->tab_top;
1046 } elseif (!$drawTabHideTop) {
1048 $drawTabTop -= $this->tabTitleHeight;
1050 $drawTabHideTop = 1;
1055 if ($i == $pdf->getNumPages()) {
1057 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1060 $drawTabHeight = $drawTabBottom - $drawTabTop;
1061 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
1063 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1070 $pdf->setPageOrientation(
'',
true, 0);
1073 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1076 if (!empty($tplidx)) {
1077 $pdf->useTemplate($tplidx);
1083 $pdf->SetTextColor(0, 0, 0);
1085 $pdf->setPage($pdf->getNumPages());
1087 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1093 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1096 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1097 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1102 if (method_exists($pdf,
'AliasNbPages')) {
1103 $pdf->AliasNbPages();
1107 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1108 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1109 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1110 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1112 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1113 $pagecount = $pdf->setSourceFile($termsofsale);
1114 for ($i = 1; $i <= $pagecount; $i++) {
1115 $tplIdx = $pdf->importPage($i);
1116 if ($tplIdx !==
false) {
1117 $s = $pdf->getTemplatesize($tplIdx);
1118 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1119 $pdf->useTemplate($tplIdx);
1121 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1133 $pdf->Output($file,
'F');
1136 $hookmanager->initHooks(array(
'pdfgeneration'));
1137 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1139 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1141 $this->error = $hookmanager->error;
1142 $this->errors = $hookmanager->errors;
1147 $this->result = array(
'fullpath' => $file);
1151 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1155 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1315 global
$conf, $mysoc, $hookmanager;
1319 $pdf->SetFont(
'',
'', $default_font_size - 1);
1321 krsort($this->tva_array);
1328 $pdf->SetFillColor(224, 224, 224);
1330 $pdf->SetFont(
'',
'', $default_font_size - 2);
1331 $pdf->SetXY($this->marge_gauche, $posy);
1332 $titre = $outputlangs->transnoentities(
"VAT");
1333 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1335 $pdf->SetFont(
'',
'', $default_font_size - 2);
1336 $pdf->SetXY($this->marge_gauche + 25, $posy);
1337 $titre = $outputlangs->transnoentities(
"NetTotal");
1338 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1340 $pdf->SetFont(
'',
'', $default_font_size - 2);
1341 $pdf->SetXY($this->marge_gauche + 50, $posy);
1342 $titre = $outputlangs->transnoentities(
"VATAmount");
1343 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1345 $pdf->SetFont(
'',
'', $default_font_size - 2);
1346 $pdf->SetXY($this->marge_gauche + 75, $posy);
1347 $titre = $outputlangs->transnoentities(
"AmountTotal");
1348 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1350 $posy = $pdf->GetY();
1355 foreach ($this->tva_array as $tvakey => $tvaval) {
1356 $pdf->SetFont(
'',
'', $default_font_size - 2);
1357 $pdf->SetXY($this->marge_gauche, $posy);
1358 $titre = round((
float) $tvakey, 2) .
"%";
1359 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1361 $pdf->SetFont(
'',
'', $default_font_size - 2);
1362 $pdf->SetXY($this->marge_gauche + 25, $posy);
1363 $titre =
price($tvaval[
'tot_ht']);
1364 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1365 $tot_ht += $tvaval[
'tot_ht'];
1367 $pdf->SetFont(
'',
'', $default_font_size - 2);
1368 $pdf->SetXY($this->marge_gauche + 50, $posy);
1369 $titre =
price($tvaval[
'amount']);
1370 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1371 $tot_tva += $tvaval[
'amount'];
1373 $pdf->SetFont(
'',
'', $default_font_size - 2);
1374 $pdf->SetXY($this->marge_gauche + 75, $posy);
1375 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1376 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1377 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1379 $posy = $pdf->GetY();
1384 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1385 $pdf->SetFont(
'',
'', $default_font_size - 2);
1386 $pdf->SetXY($this->marge_gauche, $posy);
1387 if (empty($mysoc->tva_assuj)) {
1388 if ($mysoc->forme_juridique_code == 92) {
1389 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1391 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1393 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1394 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1396 $posy = $pdf->GetY() + 4;
1401 if ($this->page_largeur < 210) {
1407 $pdf->SetFont(
'',
'', $default_font_size - 2);
1408 $pdf->SetXY($this->marge_gauche, $posy);
1409 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1410 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1412 $pdf->SetFont(
'',
'', $default_font_size - 2);
1413 $pdf->SetXY($posxval, $posy);
1414 $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);
1415 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1416 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1418 $posy = $pdf->GetY() + 3;
1422 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1423 $pdf->SetFont(
'',
'', $default_font_size - 2);
1424 $pdf->SetXY($this->marge_gauche, $posy);
1425 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1426 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1428 $pdf->SetFont(
'',
'', $default_font_size - 2);
1429 $pdf->SetXY($posxval, $posy);
1430 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1431 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1433 $posy = $pdf->GetY() + 3;
1438 if (empty(
$object->mode_reglement_code)
1441 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1445 $outputlangs->load(
"errors");
1447 $pdf->SetXY($this->marge_gauche, $posy);
1448 $pdf->SetTextColor(200, 0, 0);
1449 $pdf->SetFont(
'',
'', $default_font_size - 2);
1450 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1451 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1452 $pdf->SetTextColor(0, 0, 0);
1454 $posy = $pdf->GetY() + 1;
1458 if (!empty(
$object->mode_reglement_code)
1459 &&
$object->mode_reglement_code !=
'CHQ'
1460 &&
$object->mode_reglement_code !=
'VIR') {
1461 $pdf->SetFont(
'',
'', $default_font_size - 2);
1462 $pdf->SetXY($this->marge_gauche, $posy);
1463 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1464 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1466 $pdf->SetFont(
'',
'', $default_font_size - 2);
1467 $pdf->SetXY($posxval, $posy);
1468 $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);
1471 if (
$object->mode_reglement_code ==
"PRE") {
1472 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1475 $bac->fetch(0,
'',
$object->thirdparty->id);
1476 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1477 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1480 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1482 $posy = $pdf->GetY();
1488 if ($this->emetteur->country_code ==
'FR') {
1490 $pdf->SetXY($this->marge_gauche, $posy);
1491 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1493 $posy = $pdf->GetY() + 1;
1498 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1499 $useonlinepayment = 0;
1503 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1504 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1505 $useonlinepayment = count($validpaymentmethod);
1510 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1513 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1514 $servicename = $langs->transnoentities(
'Online');
1515 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1516 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1518 $pdf->SetXY($this->marge_gauche, $posy);
1519 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1521 $posy = $pdf->GetY() + 1;
1526 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1532 $account =
new Account($this->db);
1535 $pdf->SetXY($this->marge_gauche, $posy);
1536 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1537 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1538 $posy = $pdf->GetY() + 1;
1541 $pdf->SetXY($this->marge_gauche, $posy);
1542 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1543 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1544 $posy = $pdf->GetY() + 2;
1548 $pdf->SetXY($this->marge_gauche, $posy);
1549 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1550 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1551 $posy = $pdf->GetY() + 1;
1554 $pdf->SetXY($this->marge_gauche, $posy);
1555 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1556 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1557 $posy = $pdf->GetY() + 2;
1564 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1570 $account =
new Account($this->db);
1571 $account->fetch($bankid);
1573 $curx = $this->marge_gauche;
1576 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1582 $qrPosX = $this->marge_gauche + 5;
1584 $qrCodeColor = array(
'25',
'25',
'25');
1588 'fgcolor' => $qrCodeColor,
1590 'module_width' => 1,
1591 'module_height' => 1
1594 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1595 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1597 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1598 $pdf->SetFont(
'',
'', $default_font_size - 5);
1599 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1600 $posy = $pdf->GetY() + 2;
1605 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1608 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1631 global $mysoc, $hookmanager;
1642 if (is_object($outputlangsbis)) {
1643 $pdf->SetFont(
'',
'', $default_font_size - 2);
1645 $pdf->SetFont(
'',
'', $default_font_size - 1);
1651 if ($this->page_largeur < 210) {
1655 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1661 $parameters = array(
1663 'outputlangs' => $outputlangs,
1665 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1670 foreach (
$object->lines as $line) {
1671 if ($line->product_type != 9) {
1672 $percent += $line->situation_percent;
1678 $avancementGlobal = $percent / $i;
1680 $avancementGlobal = 0;
1683 $object->fetchPreviousNextSituationInvoice();
1684 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1687 $total_a_payer_ttc = 0;
1688 foreach ($TPreviousIncoice as &$fac) {
1689 $total_a_payer += $fac->total_ht;
1690 $total_a_payer_ttc += $fac->total_ttc;
1692 $total_a_payer +=
$object->total_ht;
1693 $total_a_payer_ttc +=
$object->total_ttc;
1695 if (!empty($avancementGlobal)) {
1696 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1697 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1700 $total_a_payer_ttc = 0;
1704 if (!empty($TPreviousIncoice)) {
1705 $pdf->setY($tab2_top);
1706 $posy = $pdf->GetY();
1708 foreach ($TPreviousIncoice as &$fac) {
1709 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1714 $pdf->setY($this->tab_top_newpage);
1716 $pdf->setY($this->marge_haute);
1718 $posy = $pdf->GetY();
1723 $pdf->SetFillColor(255, 255, 255);
1724 $pdf->SetXY($col1x, $posy);
1725 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string) $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1727 $pdf->SetXY($col2x, $posy);
1731 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1734 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1736 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1745 $pdf->SetFillColor(255, 255, 255);
1746 $pdf->SetXY($col1x, $posy);
1747 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1749 $pdf->SetXY($col2x, $posy);
1752 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1760 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1761 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1766 $pdf->SetFont(
'',
'', $default_font_size - 1);
1767 $pdf->SetFillColor(255, 255, 255);
1768 $pdf->SetXY($col1x, $posy);
1769 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", (
string) $avancementGlobal), 0,
'L',
true);
1771 $pdf->SetXY($col2x, $posy);
1772 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R',
true);
1773 $pdf->SetFont(
'',
'', $default_font_size - 2);
1777 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1781 $pdf->setY($this->tab_top_newpage);
1783 $pdf->setY($this->marge_haute);
1786 $posy = $pdf->GetY();
1797 $total_ht = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1 ?
$object->multicurrency_total_ht :
$object->total_ht);
1800 $total_discount_on_lines = 0;
1801 $multicurrency_total_discount_on_lines = 0;
1802 foreach (
$object->lines as $i => $line) {
1806 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1807 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1809 if ($line->total_ht < 0) {
1810 $total_discount_on_lines += -$line->total_ht;
1811 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1816 if ($total_discount_on_lines > 0) {
1819 $pdf->SetFillColor(255, 255, 255);
1820 $pdf->SetXY($col1x, $tab2_top);
1821 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1822 $pdf->SetXY($col2x, $tab2_top);
1824 $total_before_discount_to_show = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? (
$object->multicurrency_total_ht + $multicurrency_total_discount_on_lines) : (
$object->total_ht + $total_discount_on_lines));
1825 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1832 $pdf->SetFillColor(255, 255, 255);
1833 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1834 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1835 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1837 $total_discount_to_show = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1838 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1845 $pdf->SetFillColor(255, 255, 255);
1846 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1847 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total") :
''), 0,
'L',
true);
1849 $total_ht = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
1850 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1851 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1855 $pdf->SetFillColor(255, 255, 255);
1856 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1857 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1859 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1860 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1864 $pdf->SetFillColor(248, 248, 248);
1866 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
1867 $total_ttc_origin =
$object->total_ttc;
1869 $this->atleastoneratenotnull = 0;
1871 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1872 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1876 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1877 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1881 foreach ($localtax_rate as $tvakey => $tvaval) {
1886 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1889 if (preg_match(
'/\*/', (
string) $tvakey)) {
1890 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1891 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1894 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1898 $totalvat .= $tvacompl;
1900 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1903 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1905 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1907 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1908 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1914 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1915 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1919 foreach ($localtax_rate as $tvakey => $tvaval) {
1924 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1927 if (preg_match(
'/\*/', (
string) $tvakey)) {
1928 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1929 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1931 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1935 $totalvat .= $tvacompl;
1937 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1940 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1942 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1944 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1945 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1953 foreach ($this->tva as $tvakey => $tvaval) {
1954 $sum_pdf_tva += $tvaval;
1957 if ($sum_pdf_tva !=
$object->total_tva) {
1958 if (!empty($sum_pdf_tva)) {
1959 $coef_fix_tva =
$object->total_tva / $sum_pdf_tva;
1965 foreach ($this->tva as $tvakey => $tvaval) {
1966 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1968 foreach ($this->tva_array as $tvakey => $tvaval) {
1969 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1976 foreach ($this->tva_array as $tvakey => $tvaval) {
1978 $this->atleastoneratenotnull++;
1981 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1984 if (preg_match(
'/\*/', $tvakey)) {
1985 $tvakey = str_replace(
'*',
'', $tvakey);
1986 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1988 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1991 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1993 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1995 $totalvat .= $tvacompl;
1997 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1999 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2001 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2003 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
2009 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
2010 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2014 foreach ($localtax_rate as $tvakey => $tvaval) {
2019 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2022 if (preg_match(
'/\*/', (
string) $tvakey)) {
2023 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2024 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2026 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
2030 $totalvat .= $tvacompl;
2032 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2035 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2037 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
2039 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2040 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2046 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
2047 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2051 foreach ($localtax_rate as $tvakey => $tvaval) {
2057 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2060 if (preg_match(
'/\*/', (
string) $tvakey)) {
2061 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2062 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2064 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
2068 $totalvat .= $tvacompl;
2070 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
2073 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
2075 $total_localtax = ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
2077 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2078 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
2086 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2087 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L',
true);
2089 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2090 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
2095 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2096 $pdf->SetTextColor(0, 0, 60);
2097 $pdf->SetFillColor(224, 224, 224);
2098 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
2100 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2101 if (!isModEnabled(
"multicurrency") ||
$object->multicurrency_tx == 1 ||
getDolGlobalInt(
'MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
2102 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2104 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2108 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2109 $pdf->SetTextColor(0, 0, 60);
2110 $pdf->SetFillColor(224, 224, 224);
2111 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).
')', $useborder,
'L',
true);
2113 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2114 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder,
'L',
true);
2118 if (
$object->displayRetainedWarranty()) {
2119 $pdf->SetTextColor(40, 40, 40);
2120 $pdf->SetFillColor(255, 255, 255);
2122 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2123 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2127 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2128 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2130 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2131 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2135 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2137 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2138 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2140 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2141 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2142 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2147 $pdf->SetTextColor(0, 0, 0);
2149 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2150 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2152 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2153 if (!isModEnabled(
"multicurrency") ||
$object->multicurrency_tx == 1 ||
getDolGlobalInt(
'MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
2155 $deja_regle_origin = 0;
2156 $creditnoteamount_origin = 0;
2157 $depositsamount_origin = 0;
2158 $resteapayer_origin = 0;
2160 $deja_regle_origin =
$object->getSommePaiement(0);
2161 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
2162 $depositsamount_origin =
$object->getSumDepositsUsed(0);
2163 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
2167 $resteapayer_origin = 0;
2170 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
2173 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2174 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L',
false);
2175 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2177 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R',
false);
2190 if ($creditnoteamount) {
2191 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
2192 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.(($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes"))) :
'');
2194 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2195 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L',
false);
2196 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2197 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R',
false);
2200 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2202 $pdf->SetFillColor(255, 255, 255);
2204 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2205 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"EscompteOfferedShort") :
''), $useborder,
'L',
true);
2206 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2207 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT'), 0, $outputlangs), $useborder,
'R',
true);
2210 $resteapayer_origin = 0;
2214 $pdf->SetTextColor(0, 0, 60);
2215 $pdf->SetFillColor(224, 224, 224);
2216 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2217 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L',
true);
2218 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2219 if (!isModEnabled(
"multicurrency") ||
$object->multicurrency_tx == 1 ||
getDolGlobalInt(
'MULTICURRENCY_SHOW_ALSO_MAIN_CURRENCY_ON_PDF') == 0) {
2220 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2222 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
2226 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2227 $pdf->SetTextColor(0, 0, 60);
2228 $pdf->SetFillColor(224, 224, 224);
2229 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
'').
' ('.$outputlangs->getCurrencySymbol($mysoc->currency_code).
')', $useborder,
'L',
true);
2231 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2232 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer_origin, 0, $outputlangs, 1, -1, -1, $mysoc->currency_code), $useborder,
'L',
true);
2235 $pdf->SetFont(
'',
'', $default_font_size - 1);
2236 $pdf->SetTextColor(0, 0, 0);
2239 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2241 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2243 $this->error = $hookmanager->error;
2244 $this->errors = $hookmanager->errors;
2248 return ($tab2_top + ($tab2_hl * $index));
2344 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2347 global
$conf, $langs;
2349 $ltrdirection =
'L';
2350 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2351 $ltrdirection =
'R';
2355 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2361 $pdf->SetTextColor(0, 0, 60);
2362 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2366 $posy = $this->marge_haute;
2367 $posx = $this->page_largeur - $this->marge_droite - $w;
2369 $pdf->SetXY($this->marge_gauche, $posy);
2373 if ($this->emetteur->logo) {
2374 $logodir =
$conf->mycompany->dir_output;
2375 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
2376 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
2379 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2381 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2383 if (is_readable($logo)) {
2385 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2387 $pdf->SetTextColor(200, 0, 0);
2388 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2389 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2390 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2393 $text = $this->emetteur->name;
2394 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2398 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2399 $pdf->SetXY($posx, $posy);
2400 $pdf->SetTextColor(0, 0, 60);
2401 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2403 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2406 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2409 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2412 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2414 if ($this->situationinvoice) {
2415 $outputlangs->loadLangs(array(
"other"));
2416 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2418 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2421 if ($this->situationinvoice) {
2422 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2424 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2425 } elseif (
$object->type == 1) {
2426 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2427 } elseif (
$object->type == 2) {
2428 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2429 } elseif (
$object->type == 3) {
2430 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2431 } elseif (
$object->type == 4) {
2432 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2435 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2436 if (
$object->status == $object::STATUS_DRAFT) {
2437 $pdf->SetTextColor(128, 0, 0);
2438 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2441 $pdf->MultiCell($w, 3, $title,
'',
'R');
2443 $pdf->SetFont(
'',
'B', $default_font_size);
2457 $pdf->SetFont(
'',
'', $default_font_size - 2);
2461 $pdf->SetXY($posx, $posy);
2462 $pdf->SetTextColor(0, 0, 60);
2463 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2468 if (!empty(
$object->project->ref)) {
2470 $pdf->SetXY($posx, $posy);
2471 $pdf->SetTextColor(0, 0, 60);
2472 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2478 if (!empty(
$object->project->ref)) {
2479 $outputlangs->load(
"projects");
2481 $pdf->SetXY($posx, $posy);
2482 $pdf->SetTextColor(0, 0, 60);
2483 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2487 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2488 if (
$object->type == 0 && $objectidnext) {
2489 $objectreplacing =
new Facture($this->db);
2490 $objectreplacing->fetch($objectidnext);
2493 $pdf->SetXY($posx, $posy);
2494 $pdf->SetTextColor(0, 0, 60);
2495 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2498 $objectreplaced =
new Facture($this->db);
2499 $objectreplaced->fetch(
$object->fk_facture_source);
2502 $pdf->SetXY($posx, $posy);
2503 $pdf->SetTextColor(0, 0, 60);
2504 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2507 $objectreplaced =
new Facture($this->db);
2508 $objectreplaced->fetch(
$object->fk_facture_source);
2511 $pdf->SetXY($posx, $posy);
2512 $pdf->SetTextColor(0, 0, 60);
2513 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2517 $pdf->SetXY($posx, $posy);
2518 $pdf->SetTextColor(0, 0, 60);
2520 $title = $outputlangs->transnoentities(
"DateInvoice");
2521 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2522 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2524 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2528 $pdf->SetXY($posx, $posy);
2529 $pdf->SetTextColor(0, 0, 60);
2530 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2535 $pdf->SetXY($posx, $posy);
2536 $pdf->SetTextColor(0, 0, 60);
2537 $title = $outputlangs->transnoentities(
"DateDue");
2538 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2539 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2541 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2546 $pdf->SetXY($posx, $posy);
2547 $pdf->SetTextColor(0, 0, 60);
2548 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2553 $pdf->SetXY($posx, $posy);
2554 $pdf->SetTextColor(0, 0, 60);
2555 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2560 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2561 if (count($arrayidcontact) > 0) {
2562 $usertmp =
new User($this->db);
2563 $usertmp->fetch($arrayidcontact[0]);
2565 $pdf->SetXY($posx, $posy);
2566 $pdf->SetTextColor(0, 0, 60);
2567 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2577 $current_y = $pdf->getY();
2579 if ($current_y < $pdf->getY()) {
2580 $top_shift = $pdf->getY() - $current_y;
2586 $carac_emetteur =
'';
2588 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2589 if (count($arrayidcontact) > 0) {
2590 $object->fetch_user($arrayidcontact[0]);
2591 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2592 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2593 $carac_emetteur .=
"\n";
2600 $posy += $top_shift;
2601 $posx = $this->marge_gauche;
2603 $posx = $this->page_largeur - $this->marge_droite - 80;
2611 $pdf->SetTextColor(0, 0, 0);
2612 $pdf->SetFont(
'',
'', $default_font_size - 2);
2613 $pdf->SetXY($posx, $posy - 5);
2614 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2615 $pdf->SetXY($posx, $posy);
2616 $pdf->SetFillColor(230, 230, 230);
2617 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2618 $pdf->SetTextColor(0, 0, 60);
2623 $pdf->SetXY($posx + 2, $posy + 3);
2624 $pdf->SetFont(
'',
'B', $default_font_size);
2625 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2626 $posy = $pdf->getY();
2630 $pdf->SetXY($posx + 2, $posy);
2631 $pdf->SetFont(
'',
'', $default_font_size - 1);
2632 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2635 $usecontact =
false;
2636 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2637 if (count($arrayidcontact) > 0) {
2639 $result =
$object->fetch_contact($arrayidcontact[0]);
2643 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2644 $thirdparty =
$object->contact;
2646 $thirdparty =
$object->thirdparty;
2656 if ($this->page_largeur < 210) {
2660 $posy += $top_shift;
2661 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2663 $posx = $this->marge_gauche;
2668 $pdf->SetTextColor(0, 0, 0);
2669 $pdf->SetFont(
'',
'', $default_font_size - 2);
2670 $pdf->SetXY($posx + 2, $posy - 5);
2671 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2672 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2676 $pdf->SetXY($posx + 2, $posy + 3);
2677 $pdf->SetFont(
'',
'B', $default_font_size);
2679 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2681 $posy = $pdf->getY();
2684 $pdf->SetFont(
'',
'', $default_font_size - 1);
2685 $pdf->SetXY($posx + 2, $posy);
2687 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2691 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2693 if (!empty($idaddressshipping)) {
2694 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2695 $companystatic =
new Societe($this->db);
2696 $companystatic->fetch(
$object->contact->fk_soc);
2703 if (!empty($carac_client_shipping)) {
2704 $posy += $hautcadre;
2709 $pdf->SetXY($posx + 2, $posy - 5);
2710 $pdf->SetFont(
'',
'', $default_font_size - 2);
2711 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2712 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2715 $pdf->SetXY($posx + 2, $posy + 3);
2716 $pdf->SetFont(
'',
'B', $default_font_size);
2717 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2719 $posy = $pdf->getY();
2722 $pdf->SetXY($posx + 2, $posy);
2723 $pdf->SetFont(
'',
'', $default_font_size - 1);
2724 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2726 $shipp_shift += $hautcadre + 10;
2731 $pdf->SetTextColor(0, 0, 0);
2733 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);