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();
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);
933 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
935 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
937 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
941 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
943 $tvaligne = $sign *
$object->lines[$i]->total_tva;
947 $localtax1ligne =
$object->lines[$i]->total_localtax1;
948 $localtax2ligne =
$object->lines[$i]->total_localtax2;
949 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
950 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
951 $localtax1_type =
$object->lines[$i]->localtax1_type;
952 $localtax2_type =
$object->lines[$i]->localtax2_type;
957 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
958 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
960 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
961 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
965 if ($localtax1_type && $localtax1ligne != 0) {
966 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
967 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
969 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
972 if ($localtax2_type && $localtax2ligne != 0) {
973 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
974 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
976 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
980 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
985 if (!isset($this->tva[$vatrate])) {
986 $this->tva[$vatrate] = 0;
988 $this->tva[$vatrate] += $tvaligne;
989 $vatcode =
$object->lines[$i]->vat_src_code;
990 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
991 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
994 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
995 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
997 $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);
999 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
1003 $pdf->setPage($afterPosData[
'page']);
1004 $nexY = $afterPosData[
'y'];
1007 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1008 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1010 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1011 $pdf->SetLineStyle(array(
'dash' => 0));
1019 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
1021 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
1023 if (!empty($tplidx)) {
1024 $pdf->useTemplate($tplidx);
1027 $pdf->setPage($pagenb);
1031 $drawTabNumbPage = $pdf->getNumPages();
1032 for ($i = $pageposbeforeprintlines; $i <= $drawTabNumbPage; $i++) {
1035 $pdf->setPageOrientation(
'',
false, 0);
1037 $drawTabHideTop = $hidetop;
1038 $drawTabTop = $this->tab_top_newpage;
1039 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1042 if ($i == $pageposbeforeprintlines) {
1044 $drawTabTop = $this->tab_top;
1045 } elseif (!$drawTabHideTop) {
1047 $drawTabTop -= $this->tabTitleHeight;
1049 $drawTabHideTop = 1;
1054 if ($i == $pdf->getNumPages()) {
1056 $drawTabBottom -= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1059 $drawTabHeight = $drawTabBottom - $drawTabTop;
1060 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object, $outputlangsbis);
1062 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1069 $pdf->setPageOrientation(
'',
true, 0);
1072 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1075 if (!empty($tplidx)) {
1076 $pdf->useTemplate($tplidx);
1082 $pdf->SetTextColor(0, 0, 0);
1084 $pdf->setPage($pdf->getNumPages());
1086 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1092 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1095 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1096 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1101 if (method_exists($pdf,
'AliasNbPages')) {
1102 $pdf->AliasNbPages();
1107 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1108 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1109 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1110 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1113 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1114 $pagecount = $pdf->setSourceFile($termsofsale);
1115 for ($i = 1; $i <= $pagecount; $i++) {
1116 $tplIdx = $pdf->importPage($i);
1117 if ($tplIdx !==
false) {
1118 $s = $pdf->getTemplatesize($tplIdx);
1119 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1120 $pdf->useTemplate($tplIdx);
1122 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1134 $pdf->Output($file,
'F');
1137 $hookmanager->initHooks(array(
'pdfgeneration'));
1138 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1140 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1141 $this->warnings = $hookmanager->warnings;
1143 $this->error = $hookmanager->error;
1144 $this->errors = $hookmanager->errors;
1151 $this->result = array(
'fullpath' => $file);
1155 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1159 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1182 $tab3_top = $posy + 8;
1185 if ($this->page_largeur < 210) {
1191 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1193 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1196 $pdf->SetFont(
'',
'', $default_font_size - 3);
1197 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1198 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1200 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1202 $pdf->SetFont(
'',
'', $default_font_size - 4);
1203 $pdf->SetXY($tab3_posx, $tab3_top);
1204 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1205 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1206 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1207 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1208 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1209 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1210 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1212 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1216 $pdf->SetFont(
'',
'', $default_font_size - 4);
1220 $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,";
1221 $sql .=
" re.description, re.fk_facture_source,";
1222 $sql .=
" f.type, f.datef";
1223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1224 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1225 $resql = $this->db->query($sql);
1227 $num = $this->db->num_rows($resql);
1229 $invoice =
new Facture($this->db);
1232 $obj = $this->db->fetch_object($resql);
1234 if ($obj->type == 2) {
1235 $text = $outputlangs->transnoentities(
"CreditNote");
1236 } elseif ($obj->type == 3) {
1237 $text = $outputlangs->transnoentities(
"Deposit");
1238 } elseif ($obj->type == 0) {
1239 $text = $outputlangs->transnoentities(
"ExcessReceived");
1241 $text = $outputlangs->transnoentities(
"UnknownType");
1244 $invoice->fetch($obj->fk_facture_source);
1246 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1247 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1248 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1249 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1250 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1251 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1252 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1253 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1255 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1260 $this->error = $this->db->lasterror();
1266 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1268 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1269 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1270 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1272 $sql .=
" ORDER BY p.datep";
1274 $resql = $this->db->query($sql);
1276 $num = $this->db->num_rows($resql);
1281 $row = $this->db->fetch_object($resql);
1282 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1283 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1284 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1285 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1286 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1287 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1289 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1290 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1291 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1292 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1293 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1294 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1299 return $tab3_top + $y + 3;
1301 $this->error = $this->db->lasterror();
1323 $pdf->SetFont(
'',
'', $default_font_size - 1);
1325 krsort($this->tva_array);
1332 $pdf->SetFillColor(224, 224, 224);
1334 $pdf->SetFont(
'',
'', $default_font_size - 2);
1335 $pdf->SetXY($this->marge_gauche, $posy);
1336 $titre = $outputlangs->transnoentities(
"VAT");
1337 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1339 $pdf->SetFont(
'',
'', $default_font_size - 2);
1340 $pdf->SetXY($this->marge_gauche + 25, $posy);
1341 $titre = $outputlangs->transnoentities(
"NetTotal");
1342 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1344 $pdf->SetFont(
'',
'', $default_font_size - 2);
1345 $pdf->SetXY($this->marge_gauche + 50, $posy);
1346 $titre = $outputlangs->transnoentities(
"VATAmount");
1347 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1349 $pdf->SetFont(
'',
'', $default_font_size - 2);
1350 $pdf->SetXY($this->marge_gauche + 75, $posy);
1351 $titre = $outputlangs->transnoentities(
"AmountTotal");
1352 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1354 $posy = $pdf->GetY();
1359 foreach ($this->tva_array as $tvakey => $tvaval) {
1360 $pdf->SetFont(
'',
'', $default_font_size - 2);
1361 $pdf->SetXY($this->marge_gauche, $posy);
1362 $titre = round((
float) $tvakey, 2) .
"%";
1363 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1365 $pdf->SetFont(
'',
'', $default_font_size - 2);
1366 $pdf->SetXY($this->marge_gauche + 25, $posy);
1367 $titre =
price($tvaval[
'tot_ht']);
1368 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1369 $tot_ht += $tvaval[
'tot_ht'];
1371 $pdf->SetFont(
'',
'', $default_font_size - 2);
1372 $pdf->SetXY($this->marge_gauche + 50, $posy);
1373 $titre =
price($tvaval[
'amount']);
1374 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1375 $tot_tva += $tvaval[
'amount'];
1377 $pdf->SetFont(
'',
'', $default_font_size - 2);
1378 $pdf->SetXY($this->marge_gauche + 75, $posy);
1379 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1380 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1381 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1383 $posy = $pdf->GetY();
1388 $showvatmention = 0;
1389 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1390 $pdf->SetFont(
'',
'', $default_font_size - 2);
1391 $pdf->SetXY($this->marge_gauche, $posy);
1392 if (empty(
$mysoc->tva_assuj)) {
1393 if (
$mysoc->forme_juridique_code == 92) {
1394 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1396 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1399 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1400 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1403 $posy = $pdf->GetY();
1406 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1408 if ($showvatmention) {
1414 if ($this->page_largeur < 210) {
1421 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1422 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1423 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1424 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1425 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1426 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1427 $sql .=
" AND f.fk_statut > 0";
1428 $sql .=
" ORDER BY f.datef ASC";
1431 $invoices = array();
1432 $resql = $this->db->query($sql);
1434 while ($obj = $this->db->fetch_object($resql)) {
1436 $old_balance += $obj->total_ttc;
1438 $this->db->free($resql);
1442 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1443 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1444 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1445 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1446 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1447 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1448 $sql_payments .=
" ORDER BY p.datep ASC";
1450 $total_payments = 0;
1451 $resql_payments = $this->db->query($sql_payments);
1452 if ($resql_payments) {
1453 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1454 $total_payments += $obj_payment->amount;
1456 $this->db->free($resql_payments);
1460 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1461 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1462 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1463 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1464 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1465 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1467 $current_date_payments = 0;
1468 $resql_current_date = $this->db->query($sql_current_date_payments);
1469 if ($resql_current_date) {
1470 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1471 $current_date_payments += $obj_current->amount;
1473 $this->db->free($resql_current_date);
1477 $old_balance -= $total_payments;
1480 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1482 $pdf->SetFillColor(224, 224, 224);
1483 $pdf->SetFont(
'',
'', $default_font_size - 2);
1484 $pdf->SetXY($this->marge_gauche, $posy);
1485 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1486 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1488 $pdf->SetFont(
'',
'', $default_font_size - 2);
1489 $pdf->SetXY($posxval + 8, $posy);
1490 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1491 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1493 $posy = $pdf->GetY() + 1;
1498 $pdf->SetFont(
'',
'', $default_font_size - 2);
1499 $pdf->SetXY($this->marge_gauche, $posy);
1500 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1501 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1503 $pdf->SetFont(
'',
'', $default_font_size - 2);
1504 $pdf->SetXY($posxval, $posy);
1505 $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);
1506 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1507 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1509 $posy = $pdf->GetY() + 3;
1513 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1514 $pdf->SetFont(
'',
'', $default_font_size - 2);
1515 $pdf->SetXY($this->marge_gauche, $posy);
1516 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1517 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1519 $pdf->SetFont(
'',
'', $default_font_size - 2);
1520 $pdf->SetXY($posxval, $posy);
1521 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1522 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1524 $posy = $pdf->GetY() + 3;
1529 if (empty(
$object->mode_reglement_code)
1532 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1536 $outputlangs->load(
"errors");
1538 $pdf->SetXY($this->marge_gauche, $posy);
1539 $pdf->SetTextColor(200, 0, 0);
1540 $pdf->SetFont(
'',
'', $default_font_size - 2);
1541 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1542 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1543 $pdf->SetTextColor(0, 0, 0);
1545 $posy = $pdf->GetY() + 1;
1549 if (!empty(
$object->mode_reglement_code)
1550 &&
$object->mode_reglement_code !=
'CHQ'
1551 &&
$object->mode_reglement_code !=
'VIR') {
1552 $pdf->SetFont(
'',
'', $default_font_size - 2);
1553 $pdf->SetXY($this->marge_gauche, $posy);
1554 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1555 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1557 $pdf->SetFont(
'',
'', $default_font_size - 2);
1558 $pdf->SetXY($posxval, $posy);
1559 $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);
1562 if (
$object->mode_reglement_code ==
"PRE") {
1563 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1566 $bac->fetch(0,
'',
$object->thirdparty->id);
1567 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1568 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1571 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1573 $posy = $pdf->GetY();
1579 if ($this->emetteur->country_code ==
'FR') {
1581 $pdf->SetXY($this->marge_gauche, $posy);
1582 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1584 $posy = $pdf->GetY() + 1;
1589 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1590 $useonlinepayment = 0;
1594 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1595 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1596 $useonlinepayment = count($validpaymentmethod);
1601 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1604 $langs->loadLangs(array(
'payment',
'stripe'));
1605 $servicename = $langs->transnoentities(
'Online');
1606 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1607 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1609 $pdf->SetXY($this->marge_gauche, $posy);
1610 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1612 $posy = $pdf->GetY() + 1;
1617 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1623 $account =
new Account($this->db);
1626 $pdf->SetXY($this->marge_gauche, $posy);
1627 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1628 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1629 $posy = $pdf->GetY() + 1;
1632 $pdf->SetXY($this->marge_gauche, $posy);
1633 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1634 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1635 $posy = $pdf->GetY() + 2;
1639 $pdf->SetXY($this->marge_gauche, $posy);
1640 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1641 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1642 $posy = $pdf->GetY() + 1;
1645 $pdf->SetXY($this->marge_gauche, $posy);
1646 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1647 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1648 $posy = $pdf->GetY() + 2;
1655 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1661 $account =
new Account($this->db);
1662 $account->fetch($bankid);
1664 $curx = $this->marge_gauche;
1667 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1673 $qrPosX = $this->marge_gauche + 5;
1675 $qrCodeColor = array(
'25',
'25',
'25');
1679 'fgcolor' => $qrCodeColor,
1681 'module_width' => 1,
1682 'module_height' => 1
1685 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1686 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1688 $pdf->SetXY($qrPosX + 25, $qrPosY + 5);
1689 $pdf->SetFont(
'',
'', $default_font_size - 5);
1690 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1691 $posy = $pdf->GetY() + 2;
1696 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1699 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1722 global
$mysoc, $hookmanager;
1733 if (is_object($outputlangsbis)) {
1734 $pdf->SetFont(
'',
'', $default_font_size - 2);
1736 $pdf->SetFont(
'',
'', $default_font_size - 1);
1742 if ($this->page_largeur < 210) {
1746 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1752 $parameters = array(
1754 'outputlangs' => $outputlangs,
1756 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1761 foreach (
$object->lines as $line) {
1762 if ($line->product_type != 9) {
1763 $percent += $line->situation_percent;
1769 $avancementGlobal = $percent / $i;
1771 $avancementGlobal = 0;
1774 $object->fetchPreviousNextSituationInvoice();
1775 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1778 $total_a_payer_ttc = 0;
1779 foreach ($TPreviousIncoice as &$fac) {
1780 $total_a_payer += $fac->total_ht;
1781 $total_a_payer_ttc += $fac->total_ttc;
1783 $total_a_payer +=
$object->total_ht;
1784 $total_a_payer_ttc +=
$object->total_ttc;
1786 if (!empty($avancementGlobal)) {
1787 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1788 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1791 $total_a_payer_ttc = 0;
1795 if (!empty($TPreviousIncoice)) {
1796 $pdf->setY($tab2_top);
1797 $posy = $pdf->GetY();
1799 foreach ($TPreviousIncoice as &$fac) {
1800 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1805 $pdf->setY($this->tab_top_newpage);
1807 $pdf->setY($this->marge_haute);
1809 $posy = $pdf->GetY();
1814 $pdf->SetFillColor(255, 255, 255);
1815 $pdf->SetXY($col1x, $posy);
1816 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string) $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1818 $pdf->SetXY($col2x, $posy);
1822 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1825 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1827 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1836 $pdf->SetFillColor(255, 255, 255);
1837 $pdf->SetXY($col1x, $posy);
1838 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L',
true);
1840 $pdf->SetXY($col2x, $posy);
1843 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1851 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1852 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R',
true);
1857 $pdf->SetFont(
'',
'', $default_font_size - 1);
1858 $pdf->SetFillColor(255, 255, 255);
1859 $pdf->SetXY($col1x, $posy);
1860 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", (
string) $avancementGlobal), 0,
'L',
true);
1862 $pdf->SetXY($col2x, $posy);
1863 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R',
true);
1864 $pdf->SetFont(
'',
'', $default_font_size - 2);
1868 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1872 $pdf->setY($this->tab_top_newpage);
1874 $pdf->setY($this->marge_haute);
1877 $posy = $pdf->GetY();
1891 $total_discount_on_lines = 0;
1892 $multicurrency_total_discount_on_lines = 0;
1893 foreach (
$object->lines as $i => $line) {
1897 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1898 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1900 if ($line->total_ht < 0) {
1901 $total_discount_on_lines += -$line->total_ht;
1902 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1907 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
1909 if ($this->showAmountBeforeDiscount &&
$object->type != 2) {
1910 $pdf->SetFillColor(255, 255, 255);
1911 $pdf->SetXY($col1x, $tab2_top);
1912 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1913 $pdf->SetXY($col2x, $tab2_top);
1915 $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));
1916 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1922 if ($this->showDiscountAmount &&
$object->type != 2) {
1923 $pdf->SetFillColor(255, 255, 255);
1924 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1925 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1926 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1928 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1929 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1936 $pdf->SetFillColor(255, 255, 255);
1937 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1938 $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);
1941 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1942 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1946 $pdf->SetFillColor(255, 255, 255);
1947 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1948 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1950 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1951 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1955 $pdf->SetFillColor(248, 248, 248);
1958 $total_ttc_origin =
$object->total_ttc;
1960 $this->atleastoneratenotnull = 0;
1965 if (!empty($this->tva_array) && count($this->tva_array) == 1 ) {
1966 $tva_el = reset($this->tva_array);
1967 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) $tvaisnull =
true;
1969 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1973 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1978 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1979 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1981 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1982 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1987 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1988 $pdf->SetTextColor(0, 0, 60);
1989 $pdf->SetFillColor(224, 224, 224);
1990 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1992 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1994 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1996 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
2000 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2001 $pdf->SetTextColor(0, 0, 60);
2002 $pdf->SetFillColor(224, 224, 224);
2003 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
2005 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2006 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
2010 if (
$object->displayRetainedWarranty()) {
2011 $pdf->SetTextColor(40, 40, 40);
2012 $pdf->SetFillColor(255, 255, 255);
2014 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
2015 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2019 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2020 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
2022 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2023 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
2027 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2029 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2030 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2032 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
2033 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2034 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
2039 $pdf->SetTextColor(0, 0, 0);
2041 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2044 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2047 $deja_regle_origin = 0;
2048 $creditnoteamount_origin = 0;
2049 $depositsamount_origin = 0;
2050 $resteapayer_origin = 0;
2052 $deja_regle_origin =
$object->getSommePaiement(0);
2053 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
2054 $depositsamount_origin =
$object->getSumDepositsUsed(0);
2055 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
2059 $resteapayer_origin = 0;
2062 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
2064 $pdf->SetFont(
'',
'', $default_font_size - 1);
2065 $pdf->SetTextColor(0, 0, 0);
2067 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2069 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2071 $this->error = $hookmanager->error;
2072 $this->errors = $hookmanager->errors;
2076 return ($tab2_top + ($tab2_hl * $index));
2186 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2189 global
$conf, $langs;
2191 $ltrdirection =
'L';
2192 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2193 $ltrdirection =
'R';
2197 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2203 $pdf->SetTextColor(0, 0, 60);
2204 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2208 $posy = $this->marge_haute;
2209 $posx = $this->page_largeur - $this->marge_droite - $w;
2211 $pdf->SetXY($this->marge_gauche, $posy);
2215 if ($this->emetteur->logo) {
2216 $logodir =
$conf->mycompany->dir_output;
2217 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2221 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2223 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2225 if (is_readable($logo)) {
2227 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2229 $pdf->SetTextColor(200, 0, 0);
2230 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2231 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2232 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2235 $text = $this->emetteur->name;
2236 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2240 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2241 $pdf->SetXY($posx, $posy);
2242 $pdf->SetTextColor(0, 0, 60);
2244 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2246 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2249 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2252 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2254 if ($this->situationinvoice) {
2255 $outputlangs->loadLangs(array(
"other"));
2256 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2257 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2259 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2262 if ($this->situationinvoice) {
2263 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2265 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2266 } elseif (
$object->type == 1) {
2267 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2268 } elseif (
$object->type == 2) {
2269 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2270 } elseif (
$object->type == 3) {
2271 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2272 } elseif (
$object->type == 4) {
2273 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2276 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2277 if (
$object->status == $object::STATUS_DRAFT) {
2278 $pdf->SetTextColor(128, 0, 0);
2279 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2282 $pdf->MultiCell($w, 3, $title,
'',
'R');
2283 $posy = $pdf->GetY();
2285 if (!empty($subtitle)) {
2286 $pdf->SetFont(
'',
'B', $default_font_size);
2287 $pdf->SetXY($posx, $posy);
2288 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2289 $posy = $pdf->GetY();
2292 $pdf->SetFont(
'',
'', $default_font_size - 2);
2309 $pdf->SetFont(
'',
'', $default_font_size - 2);
2313 $pdf->SetXY($posx, $posy);
2314 $pdf->SetTextColor(0, 0, 60);
2315 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2320 if (!empty(
$object->project->title)) {
2322 $pdf->SetXY($posx, $posy);
2323 $pdf->SetTextColor(0, 0, 60);
2324 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
$object->project->title,
'',
'R');
2330 if (!empty(
$object->project->ref)) {
2331 $outputlangs->load(
"projects");
2333 $pdf->SetXY($posx, $posy);
2334 $pdf->SetTextColor(0, 0, 60);
2335 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2339 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2340 if (
$object->type == 0 && $objectidnext) {
2341 $objectreplacing =
new Facture($this->db);
2342 $objectreplacing->fetch($objectidnext);
2345 $pdf->SetXY($posx, $posy);
2346 $pdf->SetTextColor(0, 0, 60);
2347 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2350 $objectreplaced =
new Facture($this->db);
2351 $objectreplaced->fetch(
$object->fk_facture_source);
2354 $pdf->SetXY($posx, $posy);
2355 $pdf->SetTextColor(0, 0, 60);
2356 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2359 $objectreplaced =
new Facture($this->db);
2360 $objectreplaced->fetch(
$object->fk_facture_source);
2363 $pdf->SetXY($posx, $posy);
2364 $pdf->SetTextColor(0, 0, 60);
2365 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2369 $pdf->SetXY($posx, $posy);
2370 $pdf->SetTextColor(0, 0, 60);
2372 $title = $outputlangs->transnoentities(
"DateInvoice");
2373 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2374 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2376 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2380 $pdf->SetXY($posx, $posy);
2381 $pdf->SetTextColor(0, 0, 60);
2382 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2387 $pdf->SetXY($posx, $posy);
2388 $pdf->SetTextColor(0, 0, 60);
2389 $title = $outputlangs->transnoentities(
"DateDue");
2390 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2391 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2393 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2398 $pdf->SetXY($posx, $posy);
2399 $pdf->SetTextColor(0, 0, 60);
2400 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2405 $pdf->SetXY($posx, $posy);
2406 $pdf->SetTextColor(0, 0, 60);
2407 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2412 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2413 if (count($arrayidcontact) > 0) {
2414 $usertmp =
new User($this->db);
2415 $usertmp->fetch($arrayidcontact[0]);
2417 $pdf->SetXY($posx, $posy);
2418 $pdf->SetTextColor(0, 0, 60);
2419 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2429 $current_y = $pdf->getY();
2431 if ($current_y < $pdf->getY()) {
2432 $top_shift = $pdf->getY() - $current_y;
2438 $carac_emetteur =
'';
2440 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2441 if (count($arrayidcontact) > 0) {
2442 $object->fetch_user($arrayidcontact[0]);
2443 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2444 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2445 $carac_emetteur .=
"\n";
2452 $posy = (
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32);
2453 $posy += $top_shift;
2454 $posx = $this->marge_gauche;
2456 $posx = $this->page_largeur - $this->marge_droite - 80;
2464 $pdf->SetTextColor(0, 0, 0);
2465 $pdf->SetFont(
'',
'', $default_font_size - 2);
2466 $pdf->SetXY($posx, $posy - 5);
2467 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2468 $pdf->SetXY($posx, $posy);
2469 $pdf->SetFillColor(230, 230, 230);
2470 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2471 $pdf->SetTextColor(0, 0, 60);
2476 $pdf->SetXY($posx + 2, $posy + 3);
2477 $pdf->SetFont(
'',
'B', $default_font_size);
2478 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2479 $posy = $pdf->getY();
2483 $pdf->SetXY($posx + 2, $posy);
2484 $pdf->SetFont(
'',
'', $default_font_size - 1);
2485 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2488 $usecontact =
false;
2489 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2490 if (count($arrayidcontact) > 0) {
2492 $result =
$object->fetch_contact($arrayidcontact[0]);
2496 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2497 $thirdparty =
$object->contact;
2499 $thirdparty =
$object->thirdparty;
2509 if ($this->page_largeur < 210) {
2512 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2513 $posy += $top_shift;
2514 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2516 $posx = $this->marge_gauche;
2521 $pdf->SetTextColor(0, 0, 0);
2522 $pdf->SetFont(
'',
'', $default_font_size - 2);
2523 $pdf->SetXY($posx + 2, $posy - 5);
2524 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2525 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2529 $pdf->SetXY($posx + 2, $posy + 3);
2530 $pdf->SetFont(
'',
'B', $default_font_size);
2532 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2534 $posy = $pdf->getY();
2537 $pdf->SetFont(
'',
'', $default_font_size - 1);
2538 $pdf->SetXY($posx + 2, $posy);
2540 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2544 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2546 if (!empty($idaddressshipping)) {
2547 $object->fetch_contact($idaddressshipping[0]);
2548 $companystatic =
new Societe($this->db);
2549 $companystatic->fetch(
$object->contact->fk_soc);
2556 if (!empty($carac_client_shipping)) {
2557 $posy += $hautcadre;
2562 $pdf->SetXY($posx + 2, $posy - 5);
2563 $pdf->SetFont(
'',
'', $default_font_size - 2);
2564 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2565 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2568 $pdf->SetXY($posx + 2, $posy + 3);
2569 $pdf->SetFont(
'',
'B', $default_font_size);
2570 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2572 $posy = $pdf->getY();
2575 $pdf->SetXY($posx + 2, $posy);
2576 $pdf->SetFont(
'',
'', $default_font_size - 1);
2577 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2579 $shipp_shift += $hautcadre + 10;
2584 $pdf->SetTextColor(0, 0, 0);
2586 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);