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 = 90 + $top_shift + $shipp_shift;
473 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
476 $extra_under_address_shift = 0;
479 $qrcodestring =
$object->buildZATCAQRString();
482 $qrcodestring =
$object->buildSwitzerlandQRString();
486 $qrcodestring =
$object->buildEPCQrCodeString();
491 $qrcodecolor = array(
'25',
'25',
'25');
496 'fgcolor' => $qrcodecolor,
501 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
505 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
506 $pdf->SetFont(
'',
'', $default_font_size - 4);
507 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
511 $extra_under_address_shift += 25;
519 'outputlangs' => $outputlangs,
520 'hidedetails' => $hidedetails
522 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
523 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
524 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
527 $this->tab_top += $extra_under_address_shift;
528 $this->tab_top_newpage += 0;
532 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
534 $nexY = $this->tab_top - 1;
537 $height_incoterms = 0;
539 $desc_incoterms =
$object->getIncotermsForPDF();
540 if ($desc_incoterms) {
543 $pdf->SetFont(
'',
'', $default_font_size - 1);
544 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
545 $nexY = max($pdf->GetY(), $nexY);
546 $height_incoterms = $nexY - $this->tab_top;
549 $pdf->SetDrawColor(192, 192, 192);
550 $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');
552 $this->tab_top = $nexY + 6;
553 $height_incoterms += 4;
558 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
561 if (is_object(
$object->thirdparty)) {
562 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
563 $salerepobj =
new User($this->db);
564 $salerepobj->fetch($salereparray[0][
'id']);
565 if (!empty($salerepobj->signature)) {
566 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
572 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
573 if (!empty($extranote)) {
577 $pagenb = $pdf->getPage();
581 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
582 $pageposbeforenote = $pagenb;
589 $pdf->startTransaction();
591 $pdf->SetFont(
'',
'', $default_font_size - 1);
592 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
594 $pageposafternote = $pdf->getPage();
595 $posyafter = $pdf->GetY();
597 if ($pageposafternote > $pageposbeforenote) {
598 $pdf->rollbackTransaction(
true);
601 while ($pagenb < $pageposafternote) {
604 if (!empty($tplidx)) {
605 $pdf->useTemplate($tplidx);
610 $pdf->setTopMargin($this->tab_top_newpage);
612 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
616 $pdf->setPage($pageposbeforenote);
617 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
618 $pdf->SetFont(
'',
'', $default_font_size - 1);
619 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
620 $pageposafternote = $pdf->getPage();
622 $posyafter = $pdf->GetY();
624 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
625 $pdf->AddPage(
'',
'',
true);
628 $pdf->setPage($pageposafternote);
629 $pdf->setTopMargin($this->tab_top_newpage);
631 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext);
637 $i = $pageposbeforenote;
638 while ($i < $pageposafternote) {
642 $pdf->SetDrawColor(128, 128, 128);
644 if ($i > $pageposbeforenote) {
645 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
646 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
648 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
649 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
653 $pdf->setPageOrientation(
'',
true, 0);
660 $pdf->setPage($pageposafternote);
661 if (!empty($tplidx)) {
662 $pdf->useTemplate($tplidx);
667 $height_note = $posyafter - $this->tab_top_newpage;
668 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
671 $pdf->commitTransaction();
672 $posyafter = $pdf->GetY();
673 $height_note = $posyafter - $this->tab_top;
674 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
677 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
679 $pdf->AddPage(
'',
'',
true);
682 $pdf->setPage($pageposafternote);
683 if (!empty($tplidx)) {
684 $pdf->useTemplate($tplidx);
690 $posyafter = $this->tab_top_newpage;
694 $tab_height -= $height_note;
695 $this->tab_top = $posyafter + 6;
704 $pdf->startTransaction();
705 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
706 $pdf->rollbackTransaction(
true);
708 $nexY = $this->tab_top + $this->tabTitleHeight;
711 $pageposbeforeprintlines = $pdf->getPage();
712 $pagenb = $pageposbeforeprintlines;
714 $pdf_sub_options = array();
715 $pdf_sub_options[
'titleshowuponpdf'] = 1;
716 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
718 for ($i = 0; $i < $nblines; $i++) {
719 $linePosition = $i + 1;
722 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
724 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
725 $level =
$object->lines[$i]->qty;
727 if (isset($sub_options[
'titleshowuponpdf'])) {
728 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
729 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
730 unset($pdf_sub_options[
'titleshowuponpdf']);
732 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
733 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
734 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
735 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
738 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
739 unset($pdf_sub_options[
'titleshowuponpdf']);
741 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
742 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
747 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
748 $object->lines[$i]->pagebreak =
true;
752 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
755 if (!empty($tplidx)) {
756 $pdf->useTemplate($tplidx);
759 $pdf->setPage($pdf->getNumPages());
760 $nexY = $curY = $this->tab_top_newpage;
765 $pdf->SetFont(
'',
'', $default_font_size - 1);
766 $pdf->SetTextColor(0, 0, 0);
769 $imglinesize = array();
770 if (!empty($realpatharray[$i])) {
774 $pdf->setTopMargin($this->tab_top_newpage);
775 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
776 $pageposbefore = $pdf->getPage();
780 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
785 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
786 $pdf->AddPage(
'',
'',
true);
787 if (!empty($tplidx)) {
788 $pdf->useTemplate($tplidx);
790 $pdf->setPage($pageposbefore + 1);
791 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
792 $curY = $this->tab_top_newpage;
793 $showpricebeforepagebreak = 0;
796 $pdf->setPageOrientation(
'',
false, $this->heightforfooter + $this->heightforfreetext);
798 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
799 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
801 $posYAfterImage = $curY + $imglinesize[
'height'];
808 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
812 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
817 pdf_render_subtotals($pdf, $this, $curY,
$object, $i, $outputlangs, $hideref, $hidedesc, $bg_color,
true,
true);
823 $pdf->setPage($pageposbefore);
824 $pdf->setTopMargin($this->marge_haute);
826 $pdf->setPageOrientation(
'',
false, $this->heightforfooter);
829 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
830 $pdf->setPage($afterPosData[
'page']);
831 $curY = $this->tab_top_newpage;
834 $pdf->SetFont(
'',
'', $default_font_size - 1);
848 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
873 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
880 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
883 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
885 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
887 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
900 if (!empty(
$object->lines[$i]->array_options)) {
901 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
917 'nexY' => & $afterPosData[
'y'],
918 'outputlangs' => $outputlangs,
919 'hidedetails' => $hidedetails
921 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
931 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
933 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
935 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
939 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
941 $tvaligne = $sign *
$object->lines[$i]->total_tva;
945 $localtax1ligne =
$object->lines[$i]->total_localtax1;
946 $localtax2ligne =
$object->lines[$i]->total_localtax2;
947 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
948 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
949 $localtax1_type =
$object->lines[$i]->localtax1_type;
950 $localtax2_type =
$object->lines[$i]->localtax2_type;
955 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
956 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
958 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
959 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
963 if ($localtax1_type && $localtax1ligne != 0) {
964 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
965 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
967 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
970 if ($localtax2_type && $localtax2ligne != 0) {
971 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
972 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
974 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
978 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
983 if (!isset($this->tva[$vatrate])) {
984 $this->tva[$vatrate] = 0;
986 $this->tva[$vatrate] += $tvaligne;
987 $vatcode =
$object->lines[$i]->vat_src_code;
988 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
989 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
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 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1001 $pdf->setPage($afterPosData[
'page']);
1002 $nexY = $afterPosData[
'y'];
1005 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1006 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1008 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1009 $pdf->SetLineStyle(array(
'dash' => 0));
1017 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
1019 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
1021 if (!empty($tplidx)) {
1022 $pdf->useTemplate($tplidx);
1025 $pdf->setPage($pagenb);
1029 $drawTabNumbPage = $pdf->getNumPages();
1030 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1033 $pdf->setPageOrientation(
'',
false, 0);
1035 $drawTabHideTop = $hidetop;
1036 $drawTabTop = $this->tab_top_newpage;
1037 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1040 if ($i == $pageposbeforeprintlines) {
1042 $drawTabTop = $this->tab_top;
1043 } elseif (!$drawTabHideTop) {
1045 $drawTabTop -= $this->tabTitleHeight;
1047 $drawTabHideTop = 1;
1052 if ($i == $pdf->getNumPages()) {
1054 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1057 $drawTabHeight = $drawTabBottom - $drawTabTop;
1058 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object, $outputlangsbis);
1060 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1067 $pdf->setPageOrientation(
'',
true, 0);
1070 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1073 if (!empty($tplidx)) {
1074 $pdf->useTemplate($tplidx);
1080 $pdf->SetTextColor(0, 0, 0);
1082 $pdf->setPage($pdf->getNumPages());
1084 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1090 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1093 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1094 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1099 if (method_exists($pdf,
'AliasNbPages')) {
1100 $pdf->AliasNbPages();
1105 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1106 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1107 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1108 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1111 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1112 $pagecount = $pdf->setSourceFile($termsofsale);
1113 for ($i = 1; $i <= $pagecount; $i++) {
1114 $tplIdx = $pdf->importPage($i);
1115 if ($tplIdx !==
false) {
1116 $s = $pdf->getTemplatesize($tplIdx);
1117 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1118 $pdf->useTemplate($tplIdx);
1120 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1132 $pdf->Output($file,
'F');
1135 $hookmanager->initHooks(array(
'pdfgeneration'));
1136 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1138 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1139 $this->warnings = $hookmanager->warnings;
1141 $this->error = $hookmanager->error;
1142 $this->errors = $hookmanager->errors;
1149 $this->result = array(
'fullpath' => $file);
1153 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1157 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1180 $tab3_top = $posy + 8;
1183 if ($this->page_largeur < 210) {
1189 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1191 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1194 $pdf->SetFont(
'',
'', $default_font_size - 3);
1195 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1196 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1198 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1200 $pdf->SetFont(
'',
'', $default_font_size - 4);
1201 $pdf->SetXY($tab3_posx, $tab3_top);
1202 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1203 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1204 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1205 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1206 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1207 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1208 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1210 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1214 $pdf->SetFont(
'',
'', $default_font_size - 4);
1218 $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,";
1219 $sql .=
" re.description, re.fk_facture_source,";
1220 $sql .=
" f.type, f.datef";
1221 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1222 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1223 $resql = $this->db->query($sql);
1225 $num = $this->db->num_rows($resql);
1227 $invoice =
new Facture($this->db);
1230 $obj = $this->db->fetch_object($resql);
1232 if ($obj->type == 2) {
1233 $text = $outputlangs->transnoentities(
"CreditNote");
1234 } elseif ($obj->type == 3) {
1235 $text = $outputlangs->transnoentities(
"Deposit");
1236 } elseif ($obj->type == 0) {
1237 $text = $outputlangs->transnoentities(
"ExcessReceived");
1239 $text = $outputlangs->transnoentities(
"UnknownType");
1242 $invoice->fetch($obj->fk_facture_source);
1244 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1245 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1246 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1247 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1248 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1249 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1250 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1251 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1253 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1258 $this->error = $this->db->lasterror();
1264 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1267 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1268 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1270 $sql .=
" ORDER BY p.datep";
1272 $resql = $this->db->query($sql);
1274 $num = $this->db->num_rows($resql);
1279 $row = $this->db->fetch_object($resql);
1280 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1281 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1282 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1283 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1284 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1285 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1287 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1288 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1289 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1290 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1291 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1292 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1297 return $tab3_top + $y + 3;
1299 $this->error = $this->db->lasterror();
1321 $pdf->SetFont(
'',
'', $default_font_size - 1);
1323 krsort($this->tva_array);
1330 $pdf->SetFillColor(224, 224, 224);
1332 $pdf->SetFont(
'',
'', $default_font_size - 2);
1333 $pdf->SetXY($this->marge_gauche, $posy);
1334 $titre = $outputlangs->transnoentities(
"VAT");
1335 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1337 $pdf->SetFont(
'',
'', $default_font_size - 2);
1338 $pdf->SetXY($this->marge_gauche + 25, $posy);
1339 $titre = $outputlangs->transnoentities(
"NetTotal");
1340 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1342 $pdf->SetFont(
'',
'', $default_font_size - 2);
1343 $pdf->SetXY($this->marge_gauche + 50, $posy);
1344 $titre = $outputlangs->transnoentities(
"VATAmount");
1345 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1347 $pdf->SetFont(
'',
'', $default_font_size - 2);
1348 $pdf->SetXY($this->marge_gauche + 75, $posy);
1349 $titre = $outputlangs->transnoentities(
"AmountTotal");
1350 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1352 $posy = $pdf->GetY();
1357 foreach ($this->tva_array as $tvakey => $tvaval) {
1358 $pdf->SetFont(
'',
'', $default_font_size - 2);
1359 $pdf->SetXY($this->marge_gauche, $posy);
1360 $titre = round((
float) $tvakey, 2) .
"%";
1361 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1363 $pdf->SetFont(
'',
'', $default_font_size - 2);
1364 $pdf->SetXY($this->marge_gauche + 25, $posy);
1365 $titre =
price($tvaval[
'tot_ht']);
1366 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1367 $tot_ht += $tvaval[
'tot_ht'];
1369 $pdf->SetFont(
'',
'', $default_font_size - 2);
1370 $pdf->SetXY($this->marge_gauche + 50, $posy);
1371 $titre =
price($tvaval[
'amount']);
1372 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1373 $tot_tva += $tvaval[
'amount'];
1375 $pdf->SetFont(
'',
'', $default_font_size - 2);
1376 $pdf->SetXY($this->marge_gauche + 75, $posy);
1377 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1378 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1379 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1381 $posy = $pdf->GetY();
1386 $showvatmention = 0;
1387 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1388 $pdf->SetFont(
'',
'', $default_font_size - 2);
1389 $pdf->SetXY($this->marge_gauche, $posy);
1390 if (empty(
$mysoc->tva_assuj)) {
1391 if (
$mysoc->forme_juridique_code == 92) {
1392 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1394 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1397 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1398 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1401 $posy = $pdf->GetY();
1404 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1406 if ($showvatmention) {
1412 if ($this->page_largeur < 210) {
1419 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1420 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1421 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1422 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1423 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1424 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1425 $sql .=
" AND f.fk_statut > 0";
1426 $sql .=
" ORDER BY f.datef ASC";
1429 $invoices = array();
1430 $resql = $this->db->query($sql);
1432 while ($obj = $this->db->fetch_object($resql)) {
1434 $old_balance += $obj->total_ttc;
1436 $this->db->free($resql);
1440 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1441 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1442 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1443 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1444 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1445 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1446 $sql_payments .=
" ORDER BY p.datep ASC";
1448 $total_payments = 0;
1449 $resql_payments = $this->db->query($sql_payments);
1450 if ($resql_payments) {
1451 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1452 $total_payments += $obj_payment->amount;
1454 $this->db->free($resql_payments);
1458 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1459 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1460 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1461 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1462 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1463 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1465 $current_date_payments = 0;
1466 $resql_current_date = $this->db->query($sql_current_date_payments);
1467 if ($resql_current_date) {
1468 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1469 $current_date_payments += $obj_current->amount;
1471 $this->db->free($resql_current_date);
1475 $old_balance -= $total_payments;
1478 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1480 $pdf->SetFillColor(224, 224, 224);
1481 $pdf->SetFont(
'',
'', $default_font_size - 2);
1482 $pdf->SetXY($this->marge_gauche, $posy);
1483 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1484 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1486 $pdf->SetFont(
'',
'', $default_font_size - 2);
1487 $pdf->SetXY($posxval + 8, $posy);
1488 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1489 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1491 $posy = $pdf->GetY() + 1;
1496 $pdf->SetFont(
'',
'', $default_font_size - 2);
1497 $pdf->SetXY($this->marge_gauche, $posy);
1498 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1499 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1501 $pdf->SetFont(
'',
'', $default_font_size - 2);
1502 $pdf->SetXY($posxval, $posy);
1503 $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);
1504 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1505 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1507 $posy = $pdf->GetY() + 3;
1511 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1512 $pdf->SetFont(
'',
'', $default_font_size - 2);
1513 $pdf->SetXY($this->marge_gauche, $posy);
1514 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1515 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1517 $pdf->SetFont(
'',
'', $default_font_size - 2);
1518 $pdf->SetXY($posxval, $posy);
1519 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1520 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1522 $posy = $pdf->GetY() + 3;
1527 if (empty(
$object->mode_reglement_code)
1530 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1534 $outputlangs->load(
"errors");
1536 $pdf->SetXY($this->marge_gauche, $posy);
1537 $pdf->SetTextColor(200, 0, 0);
1538 $pdf->SetFont(
'',
'', $default_font_size - 2);
1539 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1540 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1541 $pdf->SetTextColor(0, 0, 0);
1543 $posy = $pdf->GetY() + 1;
1547 if (!empty(
$object->mode_reglement_code)
1548 &&
$object->mode_reglement_code !=
'CHQ'
1549 &&
$object->mode_reglement_code !=
'VIR') {
1550 $pdf->SetFont(
'',
'', $default_font_size - 2);
1551 $pdf->SetXY($this->marge_gauche, $posy);
1552 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1553 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1555 $pdf->SetFont(
'',
'', $default_font_size - 2);
1556 $pdf->SetXY($posxval, $posy);
1557 $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);
1560 if (
$object->mode_reglement_code ==
"PRE") {
1561 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1564 $bac->fetch(0,
'',
$object->thirdparty->id);
1565 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1566 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1569 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1571 $posy = $pdf->GetY();
1577 if ($this->emetteur->country_code ==
'FR') {
1579 $pdf->SetXY($this->marge_gauche, $posy);
1580 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1582 $posy = $pdf->GetY() + 1;
1587 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1588 $useonlinepayment = 0;
1592 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1593 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1594 $useonlinepayment = count($validpaymentmethod);
1599 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1602 $langs->loadLangs(array(
'payment',
'stripe'));
1603 $servicename = $langs->transnoentities(
'Online');
1604 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1605 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1607 $pdf->SetXY($this->marge_gauche, $posy);
1608 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1610 $posy = $pdf->GetY() + 1;
1615 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1621 $account =
new Account($this->db);
1624 $pdf->SetXY($this->marge_gauche, $posy);
1625 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1626 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1627 $posy = $pdf->GetY() + 1;
1630 $pdf->SetXY($this->marge_gauche, $posy);
1631 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1632 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1633 $posy = $pdf->GetY() + 2;
1637 $pdf->SetXY($this->marge_gauche, $posy);
1638 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1639 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1640 $posy = $pdf->GetY() + 1;
1643 $pdf->SetXY($this->marge_gauche, $posy);
1644 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1645 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1646 $posy = $pdf->GetY() + 2;
1653 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1659 $account =
new Account($this->db);
1660 $account->fetch($bankid);
1662 $curx = $this->marge_gauche;
1665 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1671 $qrPosX = $this->marge_gauche + 5;
1673 $qrCodeColor = array(
'25',
'25',
'25');
1677 'fgcolor' => $qrCodeColor,
1679 'module_width' => 1,
1680 'module_height' => 1
1683 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1684 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1686 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1687 $pdf->SetFont(
'',
'', $default_font_size - 5);
1688 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1689 $posy = $pdf->GetY() + 2;
1694 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1697 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1720 global
$mysoc, $hookmanager;
1731 if (is_object($outputlangsbis)) {
1732 $pdf->SetFont(
'',
'', $default_font_size - 2);
1734 $pdf->SetFont(
'',
'', $default_font_size - 1);
1740 if ($this->page_largeur < 210) {
1744 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1750 $parameters = array(
1752 'outputlangs' => $outputlangs,
1754 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1759 foreach (
$object->lines as $line) {
1760 if ($line->product_type != 9) {
1761 $percent += $line->situation_percent;
1767 $avancementGlobal = $percent / $i;
1769 $avancementGlobal = 0;
1772 $object->fetchPreviousNextSituationInvoice();
1773 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1776 $total_a_payer_ttc = 0;
1777 foreach ($TPreviousIncoice as &$fac) {
1778 $total_a_payer += $fac->total_ht;
1779 $total_a_payer_ttc += $fac->total_ttc;
1781 $total_a_payer +=
$object->total_ht;
1782 $total_a_payer_ttc +=
$object->total_ttc;
1784 if (!empty($avancementGlobal)) {
1785 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1786 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1789 $total_a_payer_ttc = 0;
1793 if (!empty($TPreviousIncoice)) {
1794 $pdf->setY($tab2_top);
1795 $posy = $pdf->GetY();
1797 foreach ($TPreviousIncoice as &$fac) {
1798 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1803 $pdf->setY($this->tab_top_newpage);
1805 $pdf->setY($this->marge_haute);
1807 $posy = $pdf->GetY();
1812 $pdf->SetFillColor(255, 255, 255);
1813 $pdf->SetXY($col1x, $posy);
1814 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string) $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1816 $pdf->SetXY($col2x, $posy);
1820 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1823 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1825 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1834 $pdf->SetFillColor(255, 255, 255);
1835 $pdf->SetXY($col1x, $posy);
1836 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1838 $pdf->SetXY($col2x, $posy);
1841 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1849 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1850 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1855 $pdf->SetFont(
'',
'', $default_font_size - 1);
1856 $pdf->SetFillColor(255, 255, 255);
1857 $pdf->SetXY($col1x, $posy);
1858 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", (
string) $avancementGlobal), 0,
'L',
true);
1860 $pdf->SetXY($col2x, $posy);
1861 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R',
true);
1862 $pdf->SetFont(
'',
'', $default_font_size - 2);
1866 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1870 $pdf->setY($this->tab_top_newpage);
1872 $pdf->setY($this->marge_haute);
1875 $posy = $pdf->GetY();
1889 $total_discount_on_lines = 0;
1890 $multicurrency_total_discount_on_lines = 0;
1891 foreach (
$object->lines as $i => $line) {
1895 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1896 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1898 if ($line->total_ht < 0) {
1899 $total_discount_on_lines += -$line->total_ht;
1900 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1905 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
1907 if ($this->showAmountBeforeDiscount &&
$object->type != 2) {
1908 $pdf->SetFillColor(255, 255, 255);
1909 $pdf->SetXY($col1x, $tab2_top);
1910 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1911 $pdf->SetXY($col2x, $tab2_top);
1913 $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));
1914 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1920 if ($this->showDiscountAmount &&
$object->type != 2) {
1921 $pdf->SetFillColor(255, 255, 255);
1922 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1923 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1924 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1926 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1927 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1934 $pdf->SetFillColor(255, 255, 255);
1935 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1936 $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);
1939 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1940 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1944 $pdf->SetFillColor(255, 255, 255);
1945 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1946 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1948 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1949 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1953 $pdf->SetFillColor(248, 248, 248);
1956 $total_ttc_origin =
$object->total_ttc;
1958 $this->atleastoneratenotnull = 0;
1963 if (!empty($this->tva_array) && count($this->tva_array) == 1 ) {
1964 $tva_el = reset($this->tva_array);
1965 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) $tvaisnull =
true;
1967 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1971 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1976 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1977 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1979 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1980 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1985 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1986 $pdf->SetTextColor(0, 0, 60);
1987 $pdf->SetFillColor(224, 224, 224);
1988 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1990 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1992 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1994 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1998 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1999 $pdf->SetTextColor(0, 0, 60);
2000 $pdf->SetFillColor(224, 224, 224);
2001 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2003 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2004 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2008 if (
$object->displayRetainedWarranty()) {
2009 $pdf->SetTextColor(40, 40, 40);
2010 $pdf->SetFillColor(255, 255, 255);
2012 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
2013 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2017 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2018 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2020 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2021 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2025 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2027 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2028 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2030 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2031 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2032 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2037 $pdf->SetTextColor(0, 0, 0);
2039 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2042 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2045 $deja_regle_origin = 0;
2046 $creditnoteamount_origin = 0;
2047 $depositsamount_origin = 0;
2048 $resteapayer_origin = 0;
2050 $deja_regle_origin =
$object->getSommePaiement(0);
2051 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
2052 $depositsamount_origin =
$object->getSumDepositsUsed(0);
2053 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
2057 $resteapayer_origin = 0;
2060 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
2062 $pdf->SetFont(
'',
'', $default_font_size - 1);
2063 $pdf->SetTextColor(0, 0, 0);
2065 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2067 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2069 $this->error = $hookmanager->error;
2070 $this->errors = $hookmanager->errors;
2074 return ($tab2_top + ($tab2_hl * $index));
2184 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2187 global
$conf, $langs;
2189 $ltrdirection =
'L';
2190 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2191 $ltrdirection =
'R';
2195 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2201 $pdf->SetTextColor(0, 0, 60);
2202 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2206 $posy = $this->marge_haute;
2207 $posx = $this->page_largeur - $this->marge_droite - $w;
2209 $pdf->SetXY($this->marge_gauche, $posy);
2213 if ($this->emetteur->logo) {
2214 $logodir =
$conf->mycompany->dir_output;
2215 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2219 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2221 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2223 if (is_readable($logo)) {
2225 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2227 $pdf->SetTextColor(200, 0, 0);
2228 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2229 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2230 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2233 $text = $this->emetteur->name;
2234 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2238 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2239 $pdf->SetXY($posx, $posy);
2240 $pdf->SetTextColor(0, 0, 60);
2242 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2244 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2247 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2250 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2252 if ($this->situationinvoice) {
2253 $outputlangs->loadLangs(array(
"other"));
2254 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2255 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2257 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2260 if ($this->situationinvoice) {
2261 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2263 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2264 } elseif (
$object->type == 1) {
2265 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2266 } elseif (
$object->type == 2) {
2267 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2268 } elseif (
$object->type == 3) {
2269 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2270 } elseif (
$object->type == 4) {
2271 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2274 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2275 if (
$object->status == $object::STATUS_DRAFT) {
2276 $pdf->SetTextColor(128, 0, 0);
2277 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2280 $pdf->MultiCell($w, 3, $title,
'',
'R');
2281 $posy = $pdf->GetY();
2283 if (!empty($subtitle)) {
2284 $pdf->SetFont(
'',
'B', $default_font_size);
2285 $pdf->SetXY($posx, $posy);
2286 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2287 $posy = $pdf->GetY();
2290 $pdf->SetFont(
'',
'', $default_font_size - 2);
2307 $pdf->SetFont(
'',
'', $default_font_size - 2);
2311 $pdf->SetXY($posx, $posy);
2312 $pdf->SetTextColor(0, 0, 60);
2313 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2318 if (!empty(
$object->project->title)) {
2320 $pdf->SetXY($posx, $posy);
2321 $pdf->SetTextColor(0, 0, 60);
2322 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
$object->project->title,
'',
'R');
2328 if (!empty(
$object->project->ref)) {
2329 $outputlangs->load(
"projects");
2331 $pdf->SetXY($posx, $posy);
2332 $pdf->SetTextColor(0, 0, 60);
2333 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2337 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2338 if (
$object->type == 0 && $objectidnext) {
2339 $objectreplacing =
new Facture($this->db);
2340 $objectreplacing->fetch($objectidnext);
2343 $pdf->SetXY($posx, $posy);
2344 $pdf->SetTextColor(0, 0, 60);
2345 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2348 $objectreplaced =
new Facture($this->db);
2349 $objectreplaced->fetch(
$object->fk_facture_source);
2352 $pdf->SetXY($posx, $posy);
2353 $pdf->SetTextColor(0, 0, 60);
2354 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2357 $objectreplaced =
new Facture($this->db);
2358 $objectreplaced->fetch(
$object->fk_facture_source);
2361 $pdf->SetXY($posx, $posy);
2362 $pdf->SetTextColor(0, 0, 60);
2363 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2367 $pdf->SetXY($posx, $posy);
2368 $pdf->SetTextColor(0, 0, 60);
2370 $title = $outputlangs->transnoentities(
"DateInvoice");
2371 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2372 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2374 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2378 $pdf->SetXY($posx, $posy);
2379 $pdf->SetTextColor(0, 0, 60);
2380 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2385 $pdf->SetXY($posx, $posy);
2386 $pdf->SetTextColor(0, 0, 60);
2387 $title = $outputlangs->transnoentities(
"DateDue");
2388 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2389 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2391 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2396 $pdf->SetXY($posx, $posy);
2397 $pdf->SetTextColor(0, 0, 60);
2398 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2403 $pdf->SetXY($posx, $posy);
2404 $pdf->SetTextColor(0, 0, 60);
2405 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2410 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2411 if (count($arrayidcontact) > 0) {
2412 $usertmp =
new User($this->db);
2413 $usertmp->fetch($arrayidcontact[0]);
2415 $pdf->SetXY($posx, $posy);
2416 $pdf->SetTextColor(0, 0, 60);
2417 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2427 $current_y = $pdf->getY();
2429 if ($current_y < $pdf->getY()) {
2430 $top_shift = $pdf->getY() - $current_y;
2436 $carac_emetteur =
'';
2438 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2439 if (count($arrayidcontact) > 0) {
2440 $object->fetch_user($arrayidcontact[0]);
2441 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2442 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2443 $carac_emetteur .=
"\n";
2450 $posy += $top_shift;
2451 $posx = $this->marge_gauche;
2453 $posx = $this->page_largeur - $this->marge_droite - 80;
2461 $pdf->SetTextColor(0, 0, 0);
2462 $pdf->SetFont(
'',
'', $default_font_size - 2);
2463 $pdf->SetXY($posx, $posy - 5);
2464 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2465 $pdf->SetXY($posx, $posy);
2466 $pdf->SetFillColor(230, 230, 230);
2467 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2468 $pdf->SetTextColor(0, 0, 60);
2473 $pdf->SetXY($posx + 2, $posy + 3);
2474 $pdf->SetFont(
'',
'B', $default_font_size);
2475 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2476 $posy = $pdf->getY();
2480 $pdf->SetXY($posx + 2, $posy);
2481 $pdf->SetFont(
'',
'', $default_font_size - 1);
2482 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2485 $usecontact =
false;
2486 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2487 if (count($arrayidcontact) > 0) {
2489 $result =
$object->fetch_contact($arrayidcontact[0]);
2493 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2494 $thirdparty =
$object->contact;
2496 $thirdparty =
$object->thirdparty;
2506 if ($this->page_largeur < 210) {
2510 $posy += $top_shift;
2511 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2513 $posx = $this->marge_gauche;
2518 $pdf->SetTextColor(0, 0, 0);
2519 $pdf->SetFont(
'',
'', $default_font_size - 2);
2520 $pdf->SetXY($posx + 2, $posy - 5);
2521 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2522 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2526 $pdf->SetXY($posx + 2, $posy + 3);
2527 $pdf->SetFont(
'',
'B', $default_font_size);
2529 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2531 $posy = $pdf->getY();
2534 $pdf->SetFont(
'',
'', $default_font_size - 1);
2535 $pdf->SetXY($posx + 2, $posy);
2537 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2541 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2543 if (!empty($idaddressshipping)) {
2544 $object->fetch_contact($idaddressshipping[0]);
2545 $companystatic =
new Societe($this->db);
2546 $companystatic->fetch(
$object->contact->fk_soc);
2553 if (!empty($carac_client_shipping)) {
2554 $posy += $hautcadre;
2559 $pdf->SetXY($posx + 2, $posy - 5);
2560 $pdf->SetFont(
'',
'', $default_font_size - 2);
2561 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2562 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2565 $pdf->SetXY($posx + 2, $posy + 3);
2566 $pdf->SetFont(
'',
'B', $default_font_size);
2567 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2569 $posy = $pdf->getY();
2572 $pdf->SetXY($posx + 2, $posy);
2573 $pdf->SetFont(
'',
'', $default_font_size - 1);
2574 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2576 $shipp_shift += $hautcadre + 10;
2581 $pdf->SetTextColor(0, 0, 0);
2583 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);