206 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
209 global $user, $langs,
$conf,
$mysoc, $hookmanager, $nblines;
211 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
213 if (!is_object($outputlangs)) {
214 $outputlangs = $langs;
218 $outputlangs->charset_output =
'ISO-8859-1';
222 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
224 global $outputlangsbis;
225 $outputlangsbis =
null;
229 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
237 $nblines = count(
$object->lines);
245 $realpatharray = array();
246 $this->atleastonephoto =
false;
248 $objphoto =
new Product($this->db);
250 for ($i = 0; $i < $nblines; $i++) {
251 if (empty(
$object->lines[$i]->fk_product)) {
255 $objphoto->fetch(
$object->lines[$i]->fk_product);
259 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
260 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
262 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
263 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
268 foreach ($pdir as $midir) {
270 $entity = $objphoto->entity;
271 if ($entity !==
null &&
$conf->entity != $entity) {
272 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
274 $dir =
$conf->product->dir_output.
'/'.$midir;
277 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
279 if ($obj[
'photo_vignette']) {
280 $filename = $obj[
'photo_vignette'];
282 $filename = $obj[
'photo'];
285 $filename = $obj[
'photo'];
288 $realpath = $dir.$filename;
290 $this->atleastonephoto =
true;
295 if (!empty($realpath) && $arephoto) {
296 $realpatharray[$i] = $realpath;
303 if (
$conf->facture->multidir_output[
$conf->entity]) {
307 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
308 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
312 $dir =
$conf->facture->multidir_output[
$conf->entity];
313 $file = $dir.
"/SPECIMEN.pdf";
316 $dir =
$conf->facture->multidir_output[
$object->entity ??
$conf->entity].
"/".$objectref;
317 $file = $dir.
"/".$objectref.
".pdf";
319 if (!file_exists($dir)) {
321 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
326 if (file_exists($dir)) {
328 if (!is_object($hookmanager)) {
329 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
332 $hookmanager->initHooks(array(
'pdfgeneration'));
333 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
335 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
338 $nblines = count(
$object->lines);
339 $nbpayments = count(
$object->getListOfPayments());
344 $pdf->setAutoPageBreak(
true, 0);
347 $this->heightforinfotot = 50;
349 $this->heightforinfotot += (4 * $nbpayments);
351 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
352 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
354 $heightforqrinvoice = 0;
358 $this->heightforinfotot = 30 + (4 * $nbpayments);
362 if (class_exists(
'TCPDF')) {
363 $pdf->setPrintHeader(
false);
364 $pdf->setPrintFooter(
false);
370 $logodir =
$conf->mycompany->dir_output;
371 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
374 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
375 $tplidx = $pdf->importPage(1);
380 $pdf->SetDrawColor(128, 128, 128);
382 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
383 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
384 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
385 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)) :
''));
386 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
388 $pdf->SetCompression(
false);
398 'Name' => $this->emetteur->name,
399 'Location' =>
getCountry($this->emetteur->country_code,
''),
400 'Reason' =>
'INVOICE',
401 'ContactInfo' => $this->emetteur->email
403 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
407 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
411 $categoryOfOperation = 0;
414 for ($i = 0; $i < $nblines; $i++) {
417 if ($line->remise_percent) {
418 $this->atleastonediscount++;
422 if ($line->isDepositLine()) {
427 if ($categoryOfOperation < 2) {
428 $lineProductType = $line->product_type;
434 if ($nbProduct > 0 && $nbService > 0) {
436 $categoryOfOperation = 2;
441 if ($categoryOfOperation <= 0) {
443 if ($nbProduct == 0 && $nbService > 0) {
444 $categoryOfOperation = 1;
447 $this->categoryOfOperation = $categoryOfOperation;
450 if (
$object->situation_cycle_ref) {
451 $this->situationinvoice =
true;
456 if (!empty($tplidx)) {
457 $pdf->useTemplate($tplidx);
462 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
463 $top_shift = $pagehead[
'top_shift'];
464 $shipp_shift = $pagehead[
'shipp_shift'];
465 $pdf->SetFont(
'',
'', $default_font_size - 1);
466 $pdf->MultiCell(0, 3,
'');
467 $pdf->SetTextColor(0, 0, 0);
472 $this->tab_top = $this->marge_haute + 80 + $top_shift + $shipp_shift;
473 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
476 $extra_under_address_shift = 0;
479 $qrcodestring =
$object->buildZATCAQRString();
482 $qrcodestring =
$object->buildSwitzerlandQRString();
487 $qrcodestring =
$object->buildEPCQrCodeString();
492 $qrcodecolor = array(
'25',
'25',
'25');
497 'fgcolor' => $qrcodecolor,
502 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
506 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
507 $pdf->SetFont(
'',
'', $default_font_size - 4);
508 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
512 $extra_under_address_shift += 25;
520 'outputlangs' => $outputlangs,
521 'hidedetails' => $hidedetails
523 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
524 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
525 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
528 $this->tab_top += $extra_under_address_shift;
529 $this->tab_top_newpage += 0;
533 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
535 $nexY = $this->tab_top - 1;
538 $height_incoterms = 0;
540 $desc_incoterms =
$object->getIncotermsForPDF();
541 if ($desc_incoterms) {
544 $pdf->SetFont(
'',
'', $default_font_size - 1);
545 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
546 $nexY = max($pdf->GetY(), $nexY);
547 $height_incoterms = $nexY - $this->tab_top;
550 $pdf->SetDrawColor(192, 192, 192);
551 $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');
553 $this->tab_top = $nexY + 6;
554 $height_incoterms += 4;
559 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
562 if (is_object(
$object->thirdparty)) {
563 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
564 $salerepobj =
new User($this->db);
565 $salerepobj->fetch($salereparray[0][
'id']);
566 if (!empty($salerepobj->signature)) {
567 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
573 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
574 if (!empty($extranote)) {
578 $pagenb = $pdf->getPage();
582 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
583 $pageposbeforenote = $pagenb;
590 $pdf->startTransaction();
592 $pdf->SetFont(
'',
'', $default_font_size - 1);
593 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
595 $pageposafternote = $pdf->getPage();
596 $posyafter = $pdf->GetY();
598 if ($pageposafternote > $pageposbeforenote) {
599 $pdf->rollbackTransaction(
true);
602 while ($pagenb < $pageposafternote) {
605 if (!empty($tplidx)) {
606 $pdf->useTemplate($tplidx);
611 $pdf->setTopMargin($this->tab_top_newpage);
613 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
617 $pdf->setPage($pageposbeforenote);
618 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
619 $pdf->SetFont(
'',
'', $default_font_size - 1);
620 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
621 $pageposafternote = $pdf->getPage();
623 $posyafter = $pdf->GetY();
625 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
626 $pdf->AddPage(
'',
'',
true);
629 $pdf->setPage($pageposafternote);
630 $pdf->setTopMargin($this->tab_top_newpage);
632 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
638 $i = $pageposbeforenote;
639 while ($i < $pageposafternote) {
643 $pdf->SetDrawColor(128, 128, 128);
645 if ($i > $pageposbeforenote) {
646 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
647 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
649 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
650 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
654 $pdf->setPageOrientation(
'',
true, 0);
661 $pdf->setPage($pageposafternote);
662 if (!empty($tplidx)) {
663 $pdf->useTemplate($tplidx);
668 $height_note = $posyafter - $this->tab_top_newpage;
669 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
672 $pdf->commitTransaction();
673 $posyafter = $pdf->GetY();
674 $height_note = $posyafter - $this->tab_top;
675 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
678 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
680 $pdf->AddPage(
'',
'',
true);
683 $pdf->setPage($pageposafternote);
684 if (!empty($tplidx)) {
685 $pdf->useTemplate($tplidx);
691 $posyafter = $this->tab_top_newpage;
695 $tab_height -= $height_note;
696 $this->tab_top = $posyafter + 6;
705 $pdf->startTransaction();
706 $this->pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
707 $pdf->rollbackTransaction(
true);
709 $nexY = $this->tab_top + $this->tabTitleHeight;
712 $pageposbeforeprintlines = $pdf->getPage();
713 $pagenb = $pageposbeforeprintlines;
715 $pdf_sub_options = array();
716 $pdf_sub_options[
'titleshowuponpdf'] = 1;
717 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
718 $pdf_sub_options_before_title = array();
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 ($level > 0 && !isset($pdf_sub_options_before_title[(
int) $level])) {
732 $pdf_sub_options_before_title[(int) $level] = $pdf_sub_options;
736 if (isset($sub_options[
'titleshowuponpdf'])) {
737 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
738 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
739 unset($pdf_sub_options[
'titleshowuponpdf']);
741 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
742 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
743 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
744 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
747 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
748 unset($pdf_sub_options[
'titleshowuponpdf']);
750 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
751 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
755 if ($level < 0 && isset($pdf_sub_options_before_title[(
int) abs($level)])) {
756 $pdf_sub_options = $pdf_sub_options_before_title[(int) abs($level)];
757 foreach (array_keys($pdf_sub_options_before_title) as $tmplevel) {
758 if ($tmplevel >= abs($level)) {
759 unset($pdf_sub_options_before_title[$tmplevel]);
765 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && isset($sub_options[
'subtotalshowtotalexludingvatonpdf']) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
767 $pdf_sub_options = array();
768 $pdf_sub_options[
'titleshowuponpdf'] = 1;
769 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
775 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
776 $object->lines[$i]->pagebreak =
true;
780 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
783 if (!empty($tplidx)) {
784 $pdf->useTemplate($tplidx);
787 $pdf->setPage($pdf->getNumPages());
788 $nexY = $curY = $this->tab_top_newpage;
793 $pdf->SetFont(
'',
'', $default_font_size - 1);
794 $pdf->SetTextColor(0, 0, 0);
797 $imglinesize = array();
798 if (!empty($realpatharray[$i])) {
802 $pdf->setTopMargin($this->tab_top_newpage);
803 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
804 $pageposbefore = $pdf->getPage();
808 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
813 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
814 $pdf->AddPage(
'',
'',
true);
815 if (!empty($tplidx)) {
816 $pdf->useTemplate($tplidx);
818 $pdf->setPage($pageposbefore + 1);
819 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
820 $curY = $this->tab_top_newpage;
821 $showpricebeforepagebreak = 0;
824 $pdf->setPageOrientation(
'',
false, $this->heightforfooter + $this->heightforfreetext);
826 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
827 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
829 $posYAfterImage = $curY + $imglinesize[
'height'];
836 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
840 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
845 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
851 $pdf->setPage($pageposbefore);
852 $pdf->setTopMargin($this->marge_haute);
854 $pdf->setPageOrientation(
'',
false, $this->heightforfooter);
857 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
858 $pdf->setPage($afterPosData[
'page']);
859 $curY = $this->tab_top_newpage;
862 $pdf->SetFont(
'',
'', $default_font_size - 1);
876 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
901 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
908 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
911 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
913 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
915 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
922 if ($this->
getColumnStatus(
'totalincltax') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
928 if (!empty(
$object->lines[$i]->array_options)) {
929 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
945 'nexY' => & $afterPosData[
'y'],
946 'outputlangs' => $outputlangs,
947 'hidedetails' => $hidedetails
949 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
961 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
963 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
965 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
969 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
971 $tvaligne = $sign *
$object->lines[$i]->total_tva;
975 $localtax1ligne =
$object->lines[$i]->total_localtax1;
976 $localtax2ligne =
$object->lines[$i]->total_localtax2;
977 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
978 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
979 $localtax1_type =
$object->lines[$i]->localtax1_type;
980 $localtax2_type =
$object->lines[$i]->localtax2_type;
985 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
986 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
988 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
989 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
993 if ($localtax1_type && $localtax1ligne != 0) {
994 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
995 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
997 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
1000 if ($localtax2_type && $localtax2ligne != 0) {
1001 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
1002 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
1004 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
1008 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
1013 if (!isset($this->tva[$vatrate])) {
1014 $this->tva[$vatrate] = 0;
1016 $this->tva[$vatrate] += $tvaligne;
1017 $vatcode =
$object->lines[$i]->vat_src_code;
1018 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
1019 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
1022 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
1023 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
1025 $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);
1027 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1030 if (!$hidenextline) {
1032 $pdf->setPage($afterPosData[
'page']);
1033 $nexY = $afterPosData[
'y'];
1036 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1037 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1039 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1040 $pdf->SetLineStyle(array(
'dash' => 0));
1044 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && (isset($sub_options[
'titleshowuponpdf']) || isset($sub_options[
'titleshowtotalexludingvatonpdf'])) &&
getDolGlobalString(
'SUBTOTAL_HIDE_LINES_UNDER_TITLE')) {
1053 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
1055 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
1057 if (!empty($tplidx)) {
1058 $pdf->useTemplate($tplidx);
1061 $pdf->setPage($pagenb);
1065 $drawTabNumbPage = $pdf->getNumPages();
1066 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1069 $pdf->setPageOrientation(
'',
false, 0);
1071 $drawTabHideTop = $hidetop;
1072 $drawTabTop = $this->tab_top_newpage;
1073 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1076 if ($i == $pageposbeforeprintlines) {
1078 $drawTabTop = $this->tab_top;
1079 } elseif (!$drawTabHideTop) {
1081 $drawTabTop -= $this->tabTitleHeight;
1083 $drawTabHideTop = 1;
1088 if ($i == $pdf->getNumPages()) {
1090 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1093 $drawTabHeight = $drawTabBottom - $drawTabTop;
1094 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object, $outputlangsbis);
1096 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1103 $pdf->setPageOrientation(
'',
true, 0);
1106 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1109 if (!empty($tplidx)) {
1110 $pdf->useTemplate($tplidx);
1116 $pdf->SetTextColor(0, 0, 0);
1118 $pdf->setPage($pdf->getNumPages());
1120 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1126 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1129 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1130 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1135 if (method_exists($pdf,
'AliasNbPages')) {
1136 $pdf->AliasNbPages();
1141 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1142 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1143 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1144 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1147 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1148 $pagecount = $pdf->setSourceFile($termsofsale);
1149 for ($i = 1; $i <= $pagecount; $i++) {
1150 $tplIdx = $pdf->importPage($i);
1151 if ($tplIdx !==
false) {
1152 $s = $pdf->getTemplatesize($tplIdx);
1153 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1154 $pdf->useTemplate($tplIdx);
1156 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1168 $pdf->Output($file,
'F');
1171 $hookmanager->initHooks(array(
'pdfgeneration'));
1172 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1174 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1175 $this->warnings = $hookmanager->warnings;
1177 $this->error = $hookmanager->error;
1178 $this->errors = $hookmanager->errors;
1185 $this->result = array(
'fullpath' => $file);
1189 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1193 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1216 $tab3_top = $posy + 8;
1219 if ($this->page_largeur < 210) {
1225 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1227 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1230 $pdf->SetFont(
'',
'', $default_font_size - 3);
1231 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1232 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1234 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1236 $pdf->SetFont(
'',
'', $default_font_size - 4);
1237 $pdf->SetXY($tab3_posx, $tab3_top);
1238 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1239 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1240 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1241 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1242 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1243 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1244 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1246 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1250 $pdf->SetFont(
'',
'', $default_font_size - 4);
1254 $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,";
1255 $sql .=
" re.description, re.fk_facture_source,";
1256 $sql .=
" f.type, f.datef";
1257 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1258 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1259 $resql = $this->db->query($sql);
1261 $num = $this->db->num_rows($resql);
1263 $invoice =
new Facture($this->db);
1266 $obj = $this->db->fetch_object($resql);
1268 if ($obj->type == 2) {
1269 $text = $outputlangs->transnoentities(
"CreditNote");
1270 } elseif ($obj->type == 3) {
1271 $text = $outputlangs->transnoentities(
"Deposit");
1272 } elseif ($obj->type == 0) {
1273 $text = $outputlangs->transnoentities(
"ExcessReceived");
1275 $text = $outputlangs->transnoentities(
"UnknownType");
1278 $invoice->fetch($obj->fk_facture_source);
1280 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1281 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1282 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1283 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1284 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1285 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1286 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1287 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1289 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1294 $this->error = $this->db->lasterror();
1300 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1302 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1303 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1304 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1306 $sql .=
" ORDER BY p.datep";
1308 $resql = $this->db->query($sql);
1310 $num = $this->db->num_rows($resql);
1315 $row = $this->db->fetch_object($resql);
1316 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1317 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1318 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1319 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1320 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1321 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1323 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1324 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1325 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1326 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1327 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1328 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1333 return $tab3_top + $y + 3;
1335 $this->error = $this->db->lasterror();
1357 $pdf->SetFont(
'',
'', $default_font_size - 1);
1359 krsort($this->tva_array);
1366 $pdf->SetFillColor(224, 224, 224);
1368 $pdf->SetFont(
'',
'', $default_font_size - 2);
1369 $pdf->SetXY($this->marge_gauche, $posy);
1370 $titre = $outputlangs->transnoentities(
"VAT");
1371 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1373 $pdf->SetFont(
'',
'', $default_font_size - 2);
1374 $pdf->SetXY($this->marge_gauche + 25, $posy);
1375 $titre = $outputlangs->transnoentities(
"NetTotal");
1376 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1378 $pdf->SetFont(
'',
'', $default_font_size - 2);
1379 $pdf->SetXY($this->marge_gauche + 50, $posy);
1380 $titre = $outputlangs->transnoentities(
"VATAmount");
1381 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1383 $pdf->SetFont(
'',
'', $default_font_size - 2);
1384 $pdf->SetXY($this->marge_gauche + 75, $posy);
1385 $titre = $outputlangs->transnoentities(
"AmountTotal");
1386 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1388 $posy = $pdf->GetY();
1393 foreach ($this->tva_array as $tvakey => $tvaval) {
1394 $pdf->SetFont(
'',
'', $default_font_size - 2);
1395 $pdf->SetXY($this->marge_gauche, $posy);
1396 $titre = round((
float) $tvakey, 2) .
"%";
1397 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1399 $pdf->SetFont(
'',
'', $default_font_size - 2);
1400 $pdf->SetXY($this->marge_gauche + 25, $posy);
1401 $titre =
price($tvaval[
'tot_ht']);
1402 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1403 $tot_ht += $tvaval[
'tot_ht'];
1405 $pdf->SetFont(
'',
'', $default_font_size - 2);
1406 $pdf->SetXY($this->marge_gauche + 50, $posy);
1407 $titre =
price($tvaval[
'amount']);
1408 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1409 $tot_tva += $tvaval[
'amount'];
1411 $pdf->SetFont(
'',
'', $default_font_size - 2);
1412 $pdf->SetXY($this->marge_gauche + 75, $posy);
1413 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1414 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1415 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1417 $posy = $pdf->GetY();
1422 $showvatmention = 0;
1423 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1424 $pdf->SetFont(
'',
'', $default_font_size - 2);
1425 $pdf->SetXY($this->marge_gauche, $posy);
1426 if (empty(
$mysoc->tva_assuj)) {
1427 if (
$mysoc->forme_juridique_code == 92) {
1428 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1430 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1433 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1434 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1437 $posy = $pdf->GetY();
1440 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1442 if ($showvatmention) {
1448 if ($this->page_largeur < 210) {
1455 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1456 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1457 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1458 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1459 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1460 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1461 $sql .=
" AND f.fk_statut > 0";
1462 $sql .=
" ORDER BY f.datef ASC";
1465 $invoices = array();
1466 $resql = $this->db->query($sql);
1468 while ($obj = $this->db->fetch_object($resql)) {
1470 $old_balance += $obj->total_ttc;
1472 $this->db->free($resql);
1476 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1477 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1478 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1479 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1480 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1481 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1482 $sql_payments .=
" ORDER BY p.datep ASC";
1484 $total_payments = 0;
1485 $resql_payments = $this->db->query($sql_payments);
1486 if ($resql_payments) {
1487 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1488 $total_payments += $obj_payment->amount;
1490 $this->db->free($resql_payments);
1494 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1495 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1496 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1497 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1498 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1499 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1501 $current_date_payments = 0;
1502 $resql_current_date = $this->db->query($sql_current_date_payments);
1503 if ($resql_current_date) {
1504 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1505 $current_date_payments += $obj_current->amount;
1507 $this->db->free($resql_current_date);
1511 $old_balance -= $total_payments;
1514 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1516 $pdf->SetFillColor(224, 224, 224);
1517 $pdf->SetFont(
'',
'', $default_font_size - 2);
1518 $pdf->SetXY($this->marge_gauche, $posy);
1519 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1520 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1522 $pdf->SetFont(
'',
'', $default_font_size - 2);
1523 $pdf->SetXY($posxval + 8, $posy);
1524 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1525 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1527 $posy = $pdf->GetY() + 1;
1532 $pdf->SetFont(
'',
'', $default_font_size - 2);
1533 $pdf->SetXY($this->marge_gauche, $posy);
1534 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1535 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1537 $pdf->SetFont(
'',
'', $default_font_size - 2);
1538 $pdf->SetXY($posxval, $posy);
1539 $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);
1540 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1541 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1543 $posy = $pdf->GetY() + 3;
1547 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1548 $pdf->SetFont(
'',
'', $default_font_size - 2);
1549 $pdf->SetXY($this->marge_gauche, $posy);
1550 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1551 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1553 $pdf->SetFont(
'',
'', $default_font_size - 2);
1554 $pdf->SetXY($posxval, $posy);
1555 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1556 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1558 $posy = $pdf->GetY() + 3;
1563 if (empty(
$object->mode_reglement_code)
1566 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1570 $outputlangs->load(
"errors");
1572 $pdf->SetXY($this->marge_gauche, $posy);
1573 $pdf->SetTextColor(200, 0, 0);
1574 $pdf->SetFont(
'',
'', $default_font_size - 2);
1575 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1576 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1577 $pdf->SetTextColor(0, 0, 0);
1579 $posy = $pdf->GetY() + 1;
1583 if (!empty(
$object->mode_reglement_code)
1584 &&
$object->mode_reglement_code !=
'CHQ'
1585 &&
$object->mode_reglement_code !=
'VIR') {
1586 $pdf->SetFont(
'',
'', $default_font_size - 2);
1587 $pdf->SetXY($this->marge_gauche, $posy);
1588 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1589 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1591 $pdf->SetFont(
'',
'', $default_font_size - 2);
1592 $pdf->SetXY($posxval, $posy);
1593 $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);
1596 if (
$object->mode_reglement_code ==
"PRE") {
1597 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1600 $bac->fetch(0,
'',
$object->thirdparty->id);
1601 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1602 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1605 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1607 $posy = $pdf->GetY();
1613 if ($this->emetteur->country_code ==
'FR') {
1615 $pdf->SetXY($this->marge_gauche, $posy);
1616 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1618 $posy = $pdf->GetY() + 1;
1623 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1624 $useonlinepayment = 0;
1628 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1629 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1630 $useonlinepayment = count($validpaymentmethod);
1635 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1638 $langs->loadLangs(array(
'payment',
'stripe'));
1639 $servicename = $langs->transnoentities(
'Online');
1640 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1641 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1643 $pdf->SetXY($this->marge_gauche, $posy);
1644 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1646 $posy = $pdf->GetY() + 1;
1651 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1657 $account =
new Account($this->db);
1660 $pdf->SetXY($this->marge_gauche, $posy);
1661 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1662 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1663 $posy = $pdf->GetY() + 1;
1666 $pdf->SetXY($this->marge_gauche, $posy);
1667 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1668 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1669 $posy = $pdf->GetY() + 2;
1673 $pdf->SetXY($this->marge_gauche, $posy);
1674 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1675 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1676 $posy = $pdf->GetY() + 1;
1679 $pdf->SetXY($this->marge_gauche, $posy);
1680 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1681 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1682 $posy = $pdf->GetY() + 2;
1689 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1695 $account =
new Account($this->db);
1696 $account->fetch($bankid);
1698 $curx = $this->marge_gauche;
1701 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1707 $qrPosX = $this->marge_gauche + 5;
1709 $qrCodeColor = array(
'25',
'25',
'25');
1713 'fgcolor' => $qrCodeColor,
1715 'module_width' => 1,
1716 'module_height' => 1
1719 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1720 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1722 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1723 $pdf->SetFont(
'',
'', $default_font_size - 5);
1724 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1725 $posy = $pdf->GetY() + 2;
1730 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1733 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1756 global
$mysoc, $hookmanager;
1767 if (is_object($outputlangsbis)) {
1768 $pdf->SetFont(
'',
'', $default_font_size - 2);
1770 $pdf->SetFont(
'',
'', $default_font_size - 1);
1776 if ($this->page_largeur < 210) {
1780 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1786 $parameters = array(
1788 'outputlangs' => $outputlangs,
1790 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1795 foreach (
$object->lines as $line) {
1796 if ($line->product_type != 9) {
1797 $percent += $line->situation_percent;
1803 $avancementGlobal = $percent / $i;
1805 $avancementGlobal = 0;
1808 $object->fetchPreviousNextSituationInvoice();
1809 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1812 $total_a_payer_ttc = 0;
1813 foreach ($TPreviousIncoice as &$fac) {
1814 $total_a_payer += $fac->total_ht;
1815 $total_a_payer_ttc += $fac->total_ttc;
1817 $total_a_payer +=
$object->total_ht;
1818 $total_a_payer_ttc +=
$object->total_ttc;
1820 if (!empty($avancementGlobal)) {
1821 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1822 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1825 $total_a_payer_ttc = 0;
1829 if (!empty($TPreviousIncoice)) {
1830 $pdf->setY($tab2_top);
1831 $posy = $pdf->GetY();
1833 foreach ($TPreviousIncoice as &$fac) {
1834 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1839 $pdf->setY($this->tab_top_newpage);
1841 $pdf->setY($this->marge_haute);
1843 $posy = $pdf->GetY();
1848 $pdf->SetFillColor(255, 255, 255);
1849 $pdf->SetXY($col1x, $posy);
1850 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string) $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1852 $pdf->SetXY($col2x, $posy);
1856 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1859 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1861 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1870 $pdf->SetFillColor(255, 255, 255);
1871 $pdf->SetXY($col1x, $posy);
1872 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1874 $pdf->SetXY($col2x, $posy);
1877 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1885 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1886 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1891 $pdf->SetFont(
'',
'', $default_font_size - 1);
1892 $pdf->SetFillColor(255, 255, 255);
1893 $pdf->SetXY($col1x, $posy);
1894 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", (
string) $avancementGlobal), 0,
'L',
true);
1896 $pdf->SetXY($col2x, $posy);
1897 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R',
true);
1898 $pdf->SetFont(
'',
'', $default_font_size - 2);
1902 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1906 $pdf->setY($this->tab_top_newpage);
1908 $pdf->setY($this->marge_haute);
1911 $posy = $pdf->GetY();
1925 $total_discount_on_lines = 0;
1926 $multicurrency_total_discount_on_lines = 0;
1927 foreach (
$object->lines as $i => $line) {
1931 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1932 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1934 if ($line->total_ht < 0) {
1935 $total_discount_on_lines += -$line->total_ht;
1936 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1941 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
1943 if ($this->showAmountBeforeDiscount &&
$object->type != 2) {
1944 $pdf->SetFillColor(255, 255, 255);
1945 $pdf->SetXY($col1x, $tab2_top);
1946 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1947 $pdf->SetXY($col2x, $tab2_top);
1949 $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));
1950 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1956 if ($this->showDiscountAmount &&
$object->type != 2) {
1957 $pdf->SetFillColor(255, 255, 255);
1958 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1959 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1960 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1962 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1963 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1970 $pdf->SetFillColor(255, 255, 255);
1971 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1972 $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);
1975 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1976 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1980 $pdf->SetFillColor(255, 255, 255);
1981 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1982 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1984 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1985 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1989 $pdf->SetFillColor(248, 248, 248);
1992 $total_ttc_origin =
$object->total_ttc;
1994 $this->atleastoneratenotnull = 0;
1999 if (!empty($this->tva_array) && count($this->tva_array) == 1 ) {
2000 $tva_el = reset($this->tva_array);
2001 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) $tvaisnull =
true;
2003 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
2007 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
2012 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2013 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
2015 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2016 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
2021 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2022 $pdf->SetTextColor(0, 0, 60);
2023 $pdf->SetFillColor(224, 224, 224);
2024 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
2026 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2028 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2030 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2034 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2035 $pdf->SetTextColor(0, 0, 60);
2036 $pdf->SetFillColor(224, 224, 224);
2037 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2039 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2040 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2044 if (
$object->displayRetainedWarranty()) {
2045 $pdf->SetTextColor(40, 40, 40);
2046 $pdf->SetFillColor(255, 255, 255);
2048 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
2049 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2053 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2054 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2056 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2057 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2061 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2063 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2064 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2066 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2067 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2068 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2073 $pdf->SetTextColor(0, 0, 0);
2075 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2078 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2081 $deja_regle_origin = 0;
2082 $creditnoteamount_origin = 0;
2083 $depositsamount_origin = 0;
2084 $resteapayer_origin = 0;
2086 $deja_regle_origin =
$object->getSommePaiement(0);
2087 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
2088 $depositsamount_origin =
$object->getSumDepositsUsed(0);
2089 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
2093 $resteapayer_origin = 0;
2096 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
2098 $pdf->SetFont(
'',
'', $default_font_size - 1);
2099 $pdf->SetTextColor(0, 0, 0);
2101 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2103 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2105 $this->error = $hookmanager->error;
2106 $this->errors = $hookmanager->errors;
2110 return ($tab2_top + ($tab2_hl * $index));
2220 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2223 global
$conf, $langs;
2225 $ltrdirection =
'L';
2226 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2227 $ltrdirection =
'R';
2231 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2237 $pdf->SetTextColor(0, 0, 60);
2238 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2242 $posy = $this->marge_haute;
2243 $posx = $this->page_largeur - $this->marge_droite - $w;
2245 $pdf->SetXY($this->marge_gauche, $posy);
2249 if ($this->emetteur->logo) {
2250 $logodir =
$conf->mycompany->dir_output;
2251 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2255 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2257 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2259 if (is_readable($logo)) {
2261 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2263 $pdf->SetTextColor(200, 0, 0);
2264 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2265 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2266 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2269 $text = $this->emetteur->name;
2270 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2274 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2275 $pdf->SetXY($posx, $posy);
2276 $pdf->SetTextColor(0, 0, 60);
2278 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2280 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2283 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2286 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2288 if ($this->situationinvoice) {
2289 $outputlangs->loadLangs(array(
"other"));
2290 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2291 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2293 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2296 if ($this->situationinvoice) {
2297 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2299 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2300 } elseif (
$object->type == 1) {
2301 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2302 } elseif (
$object->type == 2) {
2303 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2304 } elseif (
$object->type == 3) {
2305 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2306 } elseif (
$object->type == 4) {
2307 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2310 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2311 if (
$object->status == $object::STATUS_DRAFT) {
2312 $pdf->SetTextColor(128, 0, 0);
2313 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2316 $pdf->MultiCell($w, 3, $title,
'',
'R');
2317 $posy = $pdf->GetY();
2319 if (!empty($subtitle)) {
2320 $pdf->SetFont(
'',
'B', $default_font_size);
2321 $pdf->SetXY($posx, $posy);
2322 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2323 $posy = $pdf->GetY();
2326 $pdf->SetFont(
'',
'', $default_font_size - 2);
2343 $pdf->SetFont(
'',
'', $default_font_size - 2);
2347 $pdf->SetXY($posx, $posy);
2348 $pdf->SetTextColor(0, 0, 60);
2349 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2354 if (!empty(
$object->project->title)) {
2356 $pdf->SetXY($posx, $posy);
2357 $pdf->SetTextColor(0, 0, 60);
2358 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
dol_trunc(
$object->project->title, 50),
'',
'R');
2359 $posy = $pdf->getY();
2365 if (!empty(
$object->project->ref)) {
2366 $outputlangs->load(
"projects");
2368 $pdf->SetXY($posx, $posy);
2369 $pdf->SetTextColor(0, 0, 60);
2370 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2374 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2375 if (
$object->type == 0 && $objectidnext) {
2376 $objectreplacing =
new Facture($this->db);
2377 $objectreplacing->fetch($objectidnext);
2380 $pdf->SetXY($posx, $posy);
2381 $pdf->SetTextColor(0, 0, 60);
2382 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2385 $objectreplaced =
new Facture($this->db);
2386 $objectreplaced->fetch(
$object->fk_facture_source);
2389 $pdf->SetXY($posx, $posy);
2390 $pdf->SetTextColor(0, 0, 60);
2391 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2394 $objectreplaced =
new Facture($this->db);
2395 $objectreplaced->fetch(
$object->fk_facture_source);
2398 $pdf->SetXY($posx, $posy);
2399 $pdf->SetTextColor(0, 0, 60);
2400 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2404 $pdf->SetXY($posx, $posy);
2405 $pdf->SetTextColor(0, 0, 60);
2407 $title = $outputlangs->transnoentities(
"DateInvoice");
2408 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2409 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2411 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2415 $pdf->SetXY($posx, $posy);
2416 $pdf->SetTextColor(0, 0, 60);
2417 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2422 $pdf->SetXY($posx, $posy);
2423 $pdf->SetTextColor(0, 0, 60);
2424 $title = $outputlangs->transnoentities(
"DateDue");
2425 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2426 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2428 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2433 $pdf->SetXY($posx, $posy);
2434 $pdf->SetTextColor(0, 0, 60);
2435 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2440 $pdf->SetXY($posx, $posy);
2441 $pdf->SetTextColor(0, 0, 60);
2442 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2447 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2448 if (count($arrayidcontact) > 0) {
2449 $usertmp =
new User($this->db);
2450 $usertmp->fetch($arrayidcontact[0]);
2452 $pdf->SetXY($posx, $posy);
2453 $pdf->SetTextColor(0, 0, 60);
2454 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2464 $current_y = $pdf->getY();
2466 if ($current_y < $pdf->getY()) {
2467 $top_shift = $pdf->getY() - $current_y;
2473 $carac_emetteur =
'';
2475 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2476 if (count($arrayidcontact) > 0) {
2477 $object->fetch_user($arrayidcontact[0]);
2478 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2479 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2480 $carac_emetteur .=
"\n";
2487 $posy = (
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32);
2488 $posy += $top_shift;
2489 $posx = $this->marge_gauche;
2491 $posx = $this->page_largeur - $this->marge_droite - 80;
2499 $pdf->SetTextColor(0, 0, 0);
2500 $pdf->SetFont(
'',
'', $default_font_size - 2);
2501 $pdf->SetXY($posx, $posy - 5);
2502 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2503 $pdf->SetXY($posx, $posy);
2504 $pdf->SetFillColor(230, 230, 230);
2505 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2506 $pdf->SetTextColor(0, 0, 60);
2511 $pdf->SetXY($posx + 2, $posy + 3);
2512 $pdf->SetFont(
'',
'B', $default_font_size);
2513 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2514 $posy = $pdf->getY();
2518 $pdf->SetXY($posx + 2, $posy);
2519 $pdf->SetFont(
'',
'', $default_font_size - 1);
2520 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2523 $usecontact =
false;
2524 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2525 if (count($arrayidcontact) > 0) {
2527 $result =
$object->fetch_contact($arrayidcontact[0]);
2531 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2532 $thirdparty =
$object->contact;
2534 $thirdparty =
$object->thirdparty;
2544 if ($this->page_largeur < 210) {
2547 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2548 $posy += $top_shift;
2549 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2551 $posx = $this->marge_gauche;
2556 $pdf->SetTextColor(0, 0, 0);
2557 $pdf->SetFont(
'',
'', $default_font_size - 2);
2558 $pdf->SetXY($posx + 2, $posy - 5);
2559 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2560 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2564 $pdf->SetXY($posx + 2, $posy + 3);
2565 $pdf->SetFont(
'',
'B', $default_font_size);
2567 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2569 $posy = $pdf->getY();
2572 $pdf->SetFont(
'',
'', $default_font_size - 1);
2573 $pdf->SetXY($posx + 2, $posy);
2575 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2579 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2581 if (!empty($idaddressshipping)) {
2582 $object->fetch_contact($idaddressshipping[0]);
2583 $companystatic =
new Societe($this->db);
2584 $companystatic->fetch(
$object->contact->fk_soc);
2591 $carac_client_name_shipping =
'';
2592 $carac_client_shipping =
'';
2594 if (!empty($carac_client_shipping)) {
2595 $posy += $hautcadre;
2600 $pdf->SetXY($posx + 2, $posy - 5);
2601 $pdf->SetFont(
'',
'', $default_font_size - 2);
2602 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2603 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2606 $pdf->SetXY($posx + 2, $posy + 3);
2607 $pdf->SetFont(
'',
'B', $default_font_size);
2608 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2610 $posy = $pdf->getY();
2613 $pdf->SetXY($posx + 2, $posy);
2614 $pdf->SetFont(
'',
'', $default_font_size - 1);
2615 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2617 $shipp_shift += $hautcadre + 10;
2622 $pdf->SetTextColor(0, 0, 0);
2624 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);