260 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
263 global $user, $langs,
$conf,
$mysoc, $hookmanager, $nblines;
265 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
267 if (!is_object($outputlangs)) {
268 $outputlangs = $langs;
272 $outputlangs->charset_output =
'ISO-8859-1';
276 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
278 global $outputlangsbis;
279 $outputlangsbis =
null;
283 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
287 setEventMessage($langs->trans(
'WarningsObjectIsNotASituation'),
'warnings');
291 $this->TDataSituation = $this->getDataSituation(
$object);
298 $nblines = count(
$object->lines);
306 $realpatharray = array();
307 $this->atleastonephoto =
false;
309 $objphoto =
new Product($this->db);
311 for ($i = 0; $i < $nblines; $i++) {
312 if (empty(
$object->lines[$i]->fk_product)) {
316 $objphoto->fetch(
$object->lines[$i]->fk_product);
320 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
321 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
323 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
324 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
329 foreach ($pdir as $midir) {
331 $entity = $objphoto->entity;
332 if ($entity !==
null &&
$conf->entity != $entity) {
333 $dir =
$conf->product->multidir_output[$entity].
'/'.$midir;
335 $dir =
$conf->product->dir_output.
'/'.$midir;
338 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
340 if ($obj[
'photo_vignette']) {
341 $filename = $obj[
'photo_vignette'];
343 $filename = $obj[
'photo'];
346 $filename = $obj[
'photo'];
349 $realpath = $dir.$filename;
351 $this->atleastonephoto =
true;
356 if (!empty($realpath) && $arephoto) {
357 $realpatharray[$i] = $realpath;
364 if (
$conf->facture->multidir_output[
$conf->entity]) {
368 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
369 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
373 $dir =
$conf->facture->multidir_output[
$conf->entity];
374 $file = $dir.
"/SPECIMEN.pdf";
377 $dir =
$conf->facture->multidir_output[
$object->entity ??
$conf->entity].
"/".$objectref;
378 $file = $dir.
"/".$objectref.
".pdf";
380 if (!file_exists($dir)) {
382 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
387 if (file_exists($dir)) {
389 if (!is_object($hookmanager)) {
390 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
393 $hookmanager->initHooks(array(
'pdfgeneration'));
394 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
396 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
399 $nblines = count(
$object->lines);
400 $nbpayments = count(
$object->getListOfPayments());
401 $nbprevsituation = is_array(
$object->tab_previous_situation_invoice) ? count(
$object->tab_previous_situation_invoice) : 0;
406 $pdf->setAutoPageBreak(
true, 0);
409 $this->heightforinfotot = 50;
411 $this->heightforinfotot += (4 * ($nbpayments + 3));
413 if ($nbprevsituation > 0) {
414 $this->heightforinfotot += (4 * ($nbprevsituation + 3));
416 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
417 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
419 $heightforqrinvoice = 0;
423 $this->heightforinfotot = 30 + (4 * $nbpayments);
427 if (class_exists(
'TCPDF')) {
428 $pdf->setPrintHeader(
false);
429 $pdf->setPrintFooter(
false);
435 $logodir =
$conf->mycompany->dir_output;
436 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
439 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
440 $this->tplidx = $pdf->importPage(1);
445 $pdf->SetDrawColor(128, 128, 128);
447 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
448 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceSituationTitle"));
449 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
450 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)) :
''));
451 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
453 $pdf->SetCompression(
false);
463 'Name' => $this->emetteur->name,
464 'Location' =>
getCountry($this->emetteur->country_code,
''),
465 'Reason' =>
'INVOICE',
466 'ContactInfo' => $this->emetteur->email
468 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
472 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
476 $categoryOfOperation = 0;
479 for ($i = 0; $i < $nblines; $i++) {
481 if ($line->remise_percent) {
482 $this->atleastonediscount++;
486 if ($line->isDepositLine()) {
491 if ($categoryOfOperation < 2) {
492 $lineProductType = $line->product_type;
498 if ($nbProduct > 0 && $nbService > 0) {
500 $categoryOfOperation = 2;
505 if ($categoryOfOperation <= 0) {
507 if ($nbProduct == 0 && $nbService > 0) {
508 $categoryOfOperation = 1;
511 $this->categoryOfOperation = $categoryOfOperation;
514 if (
$object->situation_cycle_ref) {
515 $this->situationinvoice =
true;
520 if (!empty($this->tplidx)) {
521 $pdf->useTemplate($this->tplidx);
526 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
527 $top_shift = $pagehead[
'top_shift'];
528 $shipp_shift = $pagehead[
'shipp_shift'];
529 $pdf->SetFont(
'',
'', $default_font_size - 1);
530 $pdf->MultiCell(0, 3,
'');
531 $pdf->SetTextColor(0, 0, 0);
536 $this->tab_top = $this->marge_haute + 80 + $top_shift + $shipp_shift;
537 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? $this->marge_haute + 32 + $top_shift : $this->marge_haute);
540 $extra_under_address_shift = 0;
543 $qrcodestring =
$object->buildZATCAQRString();
546 $qrcodestring =
$object->buildSwitzerlandQRString();
550 $qrcodestring =
$object->buildEPCQrCodeString();
555 $qrcodecolor = array(
'25',
'25',
'25');
560 'fgcolor' => $qrcodecolor,
565 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
569 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
570 $pdf->SetFont(
'',
'', $default_font_size - 4);
571 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
575 $extra_under_address_shift += 25;
583 'outputlangs' => $outputlangs,
584 'hidedetails' => $hidedetails
586 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
587 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
588 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
591 $this->tab_top += $extra_under_address_shift;
592 $this->tab_top_newpage += 0;
596 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
598 $nexY = $this->tab_top - 1;
608 $tab_height_newpage = 150;
610 $this->
tableFirstPage(
$object, $pdf, $tab_top, $this->page_hauteur - 100 - $this->heightforfreetext - $this->heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
612 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
620 $pdf->setTopMargin($this->tab_top_newpage);
635 $nexY = $this->tab_top_newpage + $this->tabTitleHeight;
638 $pageposbeforeprintlines = $pdf->getPage();
639 $pagenb = $pageposbeforeprintlines;
641 $pdf_sub_options = array();
642 $pdf_sub_options[
'titleshowuponpdf'] = 1;
643 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = 1;
645 for ($i = 0; $i < $nblines; $i++) {
646 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
648 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
649 $level =
$object->lines[$i]->qty;
651 if (isset($sub_options[
'titleshowuponpdf'])) {
652 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
653 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
654 unset($pdf_sub_options[
'titleshowuponpdf']);
656 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
657 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
658 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
659 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
662 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
663 unset($pdf_sub_options[
'titleshowuponpdf']);
665 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
666 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
671 $parameters = array(
'i' => $i,
'object' =>
$object);
672 $reshook = $hookmanager->executeHooks(
'beforePrintPDFline', $parameters, $this, $action);
673 if ($reshook > 0 && !empty($hookmanager->resArray[
'object'])) {
674 $object = $hookmanager->resArray[
'object'];
676 $linePosition = $i + 1;
679 $sub_options =
$object->lines[$i]->extraparams[
"subtotal"] ?? array();
681 if (
$object->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
682 $level =
$object->lines[$i]->qty;
684 if (isset($sub_options[
'titleshowuponpdf'])) {
685 $pdf_sub_options[
'titleshowuponpdf'] = isset($pdf_sub_options[
'titleshowuponpdf']) && $pdf_sub_options[
'titleshowuponpdf'] < $level ? $pdf_sub_options[
'titleshowuponpdf'] : $level;
686 } elseif (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
687 unset($pdf_sub_options[
'titleshowuponpdf']);
689 if (isset($sub_options[
'titleshowtotalexludingvatonpdf'])) {
690 $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] = isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] < $level ? $pdf_sub_options[
'titleshowtotalexludingvatonpdf'] : $level;
691 } elseif (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
692 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
695 if (isset($pdf_sub_options[
'titleshowuponpdf']) && abs($level) <= $pdf_sub_options[
'titleshowuponpdf']) {
696 unset($pdf_sub_options[
'titleshowuponpdf']);
698 if (isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']) && abs($level) <= $pdf_sub_options[
'titleshowtotalexludingvatonpdf']) {
699 unset($pdf_sub_options[
'titleshowtotalexludingvatonpdf']);
703 if (($curY + 6) > ($this->page_hauteur - $this->heightforfooter) || isset($sub_options[
'titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $this->tab_top + $this->tabTitleHeight)) {
704 $object->lines[$i]->pagebreak =
true;
708 $pdf->SetFont(
'',
'', $default_font_size - 1);
709 $pdf->SetTextColor(0, 0, 0);
712 $imglinesize = array();
713 if (!empty($realpatharray[$i])) {
717 $pdf->setTopMargin($this->tab_top_newpage);
718 $pdf->setPageOrientation(
'',
true, $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot);
719 $pageposbefore = $pdf->getPage();
722 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
725 $posYAfterDescription = 0;
730 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($posy + $imglinesize[
'height']) > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
731 $pdf->AddPage(
'',
'',
true);
732 if (!empty($this->tplidx)) {
733 $pdf->useTemplate($this->tplidx);
735 $pdf->setPage($pageposbefore + 1);
736 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
737 $posy = $this->tab_top_newpage;
741 $showpricebeforepagebreak = 0;
745 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
746 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $posy + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
748 $posYAfterImage = $posy + $imglinesize[
'height'];
755 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
759 $pdf->startTransaction();
762 $pageposafter = $pdf->getPage();
764 if ($pageposafter > $pageposbefore) {
765 $pdf->rollbackTransaction(
true);
766 $pageposafter = $pageposbefore;
767 $pdf->setPageOrientation(
'',
true, $this->heightforfooter);
771 $pageposafter = $pdf->getPage();
772 $posyafter = $pdf->GetY();
774 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot))) {
775 if ($i == ($nblines - 1)) {
776 $pdf->AddPage(
'',
'',
true);
777 if (!empty($this->tplidx)) {
778 $pdf->useTemplate($this->tplidx);
780 $pdf->setPage($pageposafter + 1);
786 $showpricebeforepagebreak = 1;
788 $showpricebeforepagebreak = 0;
792 $pdf->commitTransaction();
794 $posYAfterDescription = $pdf->GetY();
797 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
799 $pageposafter = $pdf->getPage();
800 $pdf->setPage($pageposbefore);
801 $pdf->setTopMargin($this->marge_haute);
802 $pdf->setPageOrientation(
'',
true, 0);
805 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
806 $pdf->setPage($pageposafter);
807 $posy = $this->tab_top_newpage;
812 $pdf->SetFont(
'',
'', $default_font_size - 1);
823 $nexY = max($pdf->GetY(), $nexY);
827 if ($this->
getColumnStatus(
'subprice') &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowuponpdf'])) {
830 $nexY = max($pdf->GetY(), $nexY);
838 $nexY = max($pdf->GetY(), $nexY);
845 $nexY = max($pdf->GetY(), $nexY);
852 $nexY = max($pdf->GetY(), $nexY);
856 if ($this->
getColumnStatus(
'discount') &&
$object->lines[$i]->remise_percent &&
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE) {
859 $nexY = max($pdf->GetY(), $nexY);
864 if (
$object->lines[$i]->special_code != SUBTOTALS_SPECIAL_CODE && isset($pdf_sub_options[
'titleshowtotalexludingvatonpdf'])) {
867 } elseif (
$object->lines[$i]->qty < 0 && isset($sub_options[
'subtotalshowtotalexludingvatonpdf'])) {
869 $total_excl_tax =
$object->getSubtotalLineMulticurrencyAmount(
$object->lines[$i]);
871 $total_excl_tax =
$object->getSubtotalLineAmount(
$object->lines[$i]);
875 $nexY = max($pdf->GetY(), $nexY);
882 $columkey =
'btpsomme';
884 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht_without_progress'], 0,
'', 1, -1, 2);
886 $nexY = max($pdf->GetY(), $nexY);
890 $columkey =
'progress_amount';
892 $printval =
price(
$object->lines[$i]->total_ht, 0,
'', 1, -1, 2);
894 $nexY = max($pdf->GetY(), $nexY);
897 $columkey =
'prev_progress';
899 $printval = $TInfosLigneSituationPrecedente[
'progress_prec'].
'%';
901 $nexY = max($pdf->GetY(), $nexY);
904 $columkey =
'prev_progress_amount';
906 $printval =
price($TInfosLigneSituationPrecedente[
'total_ht'], 0,
'', 1, -1, 2);
908 $nexY = max($pdf->GetY(), $nexY);
917 'nexY' => & $afterPosData[
'y'],
918 'outputlangs' => $outputlangs,
919 'hidedetails' => $hidedetails
921 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
930 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
932 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
934 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
938 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
940 $tvaligne = $sign *
$object->lines[$i]->total_tva;
944 $localtax1ligne =
$object->lines[$i]->total_localtax1;
945 $localtax2ligne =
$object->lines[$i]->total_localtax2;
946 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
947 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
948 $localtax1_type =
$object->lines[$i]->localtax1_type;
949 $localtax2_type =
$object->lines[$i]->localtax2_type;
951 $vatrate = (string)
$object->lines[$i]->tva_tx;
954 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
955 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
957 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
958 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
962 if ($localtax1_type && $localtax1ligne != 0) {
963 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
964 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
966 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
969 if ($localtax2_type && $localtax2ligne != 0) {
970 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
971 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
973 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
977 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
983 $vatcode =
$object->lines[$i]->vat_src_code;
984 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
985 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
988 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
989 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
991 $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);
993 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
997 $pdf->setPage($afterPosData[
'page']);
998 $nexY = max($nexY, $posYAfterImage);
1001 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
1002 $pdf->setPage($pageposafter);
1003 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
1005 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
1006 $pdf->SetLineStyle(array(
'dash' => 0));
1010 while ($pagenb < $pageposafter) {
1011 $pdf->setPage($pagenb);
1012 $tabtop = $this->tab_top;
1013 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1014 if ($pagenb != $pageposbeforeprintlines) {
1015 $tabtop = $this->tab_top_newpage;
1016 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1019 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1023 $pdf->setPage($pagenb);
1024 $pdf->setPageOrientation(
'',
true, 0);
1028 if (!empty($this->tplidx)) {
1029 $pdf->useTemplate($this->tplidx);
1033 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
1034 $tabtop = $this->tab_top;
1035 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1036 if ($pagenb != $pageposbeforeprintlines) {
1037 $tabtop = $this->tab_top_newpage;
1038 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter;
1041 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1046 if (!empty($this->tplidx)) {
1047 $pdf->useTemplate($this->tplidx);
1058 $tabtop = $this->tab_top_newpage;
1059 $tabhauteur = $this->page_hauteur - $tabtop - $this->heightforfooter - $this->heightforinfotot - $this->heightforfreetext;
1060 $tabTitleHeight = 0;
1061 $this->
_tableau($pdf, $tabtop, $tabhauteur, 0, $outputlangs, $hidetop, 1,
$object->multicurrency_code, $outputlangsbis);
1064 $pdf->SetTextColor(0, 0, 0);
1066 $pdf->setPage($pdf->getNumPages());
1068 $bottomlasttab = $tabtop + $tabhauteur + $tabTitleHeight + 10;
1075 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1078 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1079 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1086 if (method_exists($pdf,
'AliasNbPages')) {
1087 $pdf->AliasNbPages();
1091 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
1092 $termsofsale =
$conf->invoice->dir_output.
'/'.$termsofsalefilename;
1093 if (!empty(
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity])) {
1094 $termsofsale =
$conf->invoice->multidir_output[
$object->entity ??
$conf->entity].
'/'.$termsofsalefilename;
1096 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1097 $pagecount = $pdf->setSourceFile($termsofsale);
1098 for ($i = 1; $i <= $pagecount; $i++) {
1099 $tplIdx = $pdf->importPage($i);
1100 if ($tplIdx !==
false) {
1101 $s = $pdf->getTemplatesize($tplIdx);
1102 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1103 $pdf->useTemplate($tplIdx);
1105 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1111 $this->resumeLastPage($pdf,
$object, 0, $tab_top, $outputlangs, $outputlangsbis);
1112 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter + 1;
1121 $pdf->Output($file,
'F');
1124 $hookmanager->initHooks(array(
'pdfgeneration'));
1125 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1127 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1128 $this->warnings = $hookmanager->warnings;
1130 $this->error = $hookmanager->error;
1131 $this->errors = $hookmanager->errors;
1138 $this->result = array(
'fullpath' => $file);
1142 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1146 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1169 $tab3_top = $posy + 8;
1172 if ($this->page_largeur < 210) {
1178 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1180 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1183 $pdf->SetFont(
'',
'', $default_font_size - 3);
1184 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1185 $pdf->MultiCell(60, 3, $title, 0,
'L',
false);
1187 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1189 $pdf->SetFont(
'',
'', $default_font_size - 4);
1190 $pdf->SetXY($tab3_posx, $tab3_top);
1191 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L',
false);
1192 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1193 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L',
false);
1194 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1195 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L',
false);
1196 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1197 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L',
false);
1199 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1203 $pdf->SetFont(
'',
'', $default_font_size - 4);
1207 $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,";
1208 $sql .=
" re.description, re.fk_facture_source,";
1209 $sql .=
" f.type, f.datef";
1210 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1211 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1212 $resql = $this->db->query($sql);
1214 $num = $this->db->num_rows($resql);
1216 $invoice =
new Facture($this->db);
1219 $obj = $this->db->fetch_object($resql);
1221 if ($obj->type == 2) {
1222 $text = $outputlangs->transnoentities(
"CreditNote");
1223 } elseif ($obj->type == 3) {
1224 $text = $outputlangs->transnoentities(
"Deposit");
1225 } elseif ($obj->type == 0) {
1226 $text = $outputlangs->transnoentities(
"ExcessReceived");
1228 $text = $outputlangs->transnoentities(
"UnknownType");
1231 $invoice->fetch($obj->fk_facture_source);
1233 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1234 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1235 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1236 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1237 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1238 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1239 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1240 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1242 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1247 $this->error = $this->db->lasterror();
1253 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1256 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1257 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1259 $sql .=
" ORDER BY p.datep";
1261 $resql = $this->db->query($sql);
1263 $num = $this->db->num_rows($resql);
1268 $row = $this->db->fetch_object($resql);
1269 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1270 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1271 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1272 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1273 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1274 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1276 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1277 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1278 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1279 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1280 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1281 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1286 return $tab3_top + $y + 3;
1288 $this->error = $this->db->lasterror();
1310 $pdf->SetFont(
'',
'', $default_font_size - 1);
1312 krsort($this->tva_array);
1319 $pdf->SetFillColor(224, 224, 224);
1321 $pdf->SetFont(
'',
'', $default_font_size - 2);
1322 $pdf->SetXY($this->marge_gauche, $posy);
1323 $titre = $outputlangs->transnoentities(
"VAT");
1324 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1326 $pdf->SetFont(
'',
'', $default_font_size - 2);
1327 $pdf->SetXY($this->marge_gauche + 25, $posy);
1328 $titre = $outputlangs->transnoentities(
"NetTotal");
1329 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1331 $pdf->SetFont(
'',
'', $default_font_size - 2);
1332 $pdf->SetXY($this->marge_gauche + 50, $posy);
1333 $titre = $outputlangs->transnoentities(
"VATAmount");
1334 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1336 $pdf->SetFont(
'',
'', $default_font_size - 2);
1337 $pdf->SetXY($this->marge_gauche + 75, $posy);
1338 $titre = $outputlangs->transnoentities(
"AmountTotal");
1339 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1341 $posy = $pdf->GetY();
1346 foreach ($this->tva_array as $tvakey => $tvaval) {
1347 $pdf->SetFont(
'',
'', $default_font_size - 2);
1348 $pdf->SetXY($this->marge_gauche, $posy);
1349 $titre = round((
float) $tvakey, 2) .
"%";
1350 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1352 $pdf->SetFont(
'',
'', $default_font_size - 2);
1353 $pdf->SetXY($this->marge_gauche + 25, $posy);
1354 $titre =
price($tvaval[
'tot_ht']);
1355 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1356 $tot_ht += $tvaval[
'tot_ht'];
1358 $pdf->SetFont(
'',
'', $default_font_size - 2);
1359 $pdf->SetXY($this->marge_gauche + 50, $posy);
1360 $titre =
price($tvaval[
'amount']);
1361 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1362 $tot_tva += $tvaval[
'amount'];
1364 $pdf->SetFont(
'',
'', $default_font_size - 2);
1365 $pdf->SetXY($this->marge_gauche + 75, $posy);
1366 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1367 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1368 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1370 $posy = $pdf->GetY();
1375 $showvatmention = 0;
1376 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1377 $pdf->SetFont(
'',
'', $default_font_size - 2);
1378 $pdf->SetXY($this->marge_gauche, $posy);
1379 if (empty(
$mysoc->tva_assuj)) {
1380 if (
$mysoc->forme_juridique_code == 92) {
1381 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1383 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1386 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1387 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1390 $posy = $pdf->GetY();
1393 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1395 if ($showvatmention) {
1402 if ($this->page_largeur < 210) {
1409 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1410 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1411 $sql .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1412 $sql .=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1413 $sql .=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1414 $sql .=
" AND f.rowid < " . ((int)
$object->id);
1415 $sql .=
" AND f.fk_statut > 0";
1416 $sql .=
" ORDER BY f.datef ASC";
1419 $invoices = array();
1420 $resql = $this->db->query($sql);
1422 while ($obj = $this->db->fetch_object($resql)) {
1424 $old_balance += $obj->total_ttc;
1426 $this->db->free($resql);
1430 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1431 $sql_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1432 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1433 $sql_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1434 $sql_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1435 $sql_payments .=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1436 $sql_payments .=
" ORDER BY p.datep ASC";
1438 $total_payments = 0;
1439 $resql_payments = $this->db->query($sql_payments);
1440 if ($resql_payments) {
1441 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1442 $total_payments += $obj_payment->amount;
1444 $this->db->free($resql_payments);
1448 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1449 $sql_current_date_payments .=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1450 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1451 $sql_current_date_payments .=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1452 $sql_current_date_payments .=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1453 $sql_current_date_payments .=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1455 $current_date_payments = 0;
1456 $resql_current_date = $this->db->query($sql_current_date_payments);
1457 if ($resql_current_date) {
1458 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1459 $current_date_payments += $obj_current->amount;
1461 $this->db->free($resql_current_date);
1465 $old_balance -= $total_payments;
1468 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1470 $pdf->SetFillColor(224, 224, 224);
1471 $pdf->SetFont(
'',
'', $default_font_size - 2);
1472 $pdf->SetXY($this->marge_gauche, $posy);
1473 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1474 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1476 $pdf->SetFont(
'',
'', $default_font_size - 2);
1477 $pdf->SetXY($posxval + 8, $posy);
1478 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1479 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1481 $posy = $pdf->GetY() + 1;
1486 $pdf->SetFont(
'',
'', $default_font_size - 2);
1487 $pdf->SetXY($this->marge_gauche, $posy);
1488 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1489 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1491 $pdf->SetFont(
'',
'', $default_font_size - 2);
1492 $pdf->SetXY($posxval, $posy);
1493 $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);
1494 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1495 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1497 $posy = $pdf->GetY() + 3;
1501 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1502 $pdf->SetFont(
'',
'', $default_font_size - 2);
1503 $pdf->SetXY($this->marge_gauche, $posy);
1504 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1505 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1507 $pdf->SetFont(
'',
'', $default_font_size - 2);
1508 $pdf->SetXY($posxval, $posy);
1509 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1510 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1512 $posy = $pdf->GetY() + 3;
1517 if (empty(
$object->mode_reglement_code)
1520 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1524 $outputlangs->load(
"errors");
1526 $pdf->SetXY($this->marge_gauche, $posy);
1527 $pdf->SetTextColor(200, 0, 0);
1528 $pdf->SetFont(
'',
'', $default_font_size - 2);
1529 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1530 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L',
false);
1531 $pdf->SetTextColor(0, 0, 0);
1533 $posy = $pdf->GetY() + 1;
1537 if (!empty(
$object->mode_reglement_code)
1538 &&
$object->mode_reglement_code !=
'CHQ'
1539 &&
$object->mode_reglement_code !=
'VIR') {
1540 $pdf->SetFont(
'',
'', $default_font_size - 2);
1541 $pdf->SetXY($this->marge_gauche, $posy);
1542 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1543 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1545 $pdf->SetFont(
'',
'', $default_font_size - 2);
1546 $pdf->SetXY($posxval, $posy);
1547 $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);
1550 if (
$object->mode_reglement_code ==
"PRE") {
1551 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1554 $bac->fetch(0,
'',
$object->thirdparty->id);
1555 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1556 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
pdf_truncate_text($pdf, $iban, 6,
'right',
''));
1559 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1561 $posy = $pdf->GetY();
1567 if ($this->emetteur->country_code ==
'FR') {
1569 $pdf->SetXY($this->marge_gauche, $posy);
1570 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1572 $posy = $pdf->GetY() + 1;
1577 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1578 $useonlinepayment = 0;
1582 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1583 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1584 $useonlinepayment = count($validpaymentmethod);
1589 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1592 $langs->loadLangs(array(
'payment',
'stripe'));
1593 $servicename = $langs->transnoentities(
'Online');
1594 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1595 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1597 $pdf->SetXY($this->marge_gauche, $posy);
1598 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
null,
null,
dol_htmlentitiesbr($linktopay), 0, 1);
1600 $posy = $pdf->GetY() + 1;
1605 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1611 $account =
new Account($this->db);
1614 $pdf->SetXY($this->marge_gauche, $posy);
1615 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1616 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1617 $posy = $pdf->GetY() + 1;
1620 $pdf->SetXY($this->marge_gauche, $posy);
1621 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1622 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1623 $posy = $pdf->GetY() + 2;
1627 $pdf->SetXY($this->marge_gauche, $posy);
1628 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1629 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1630 $posy = $pdf->GetY() + 1;
1633 $pdf->SetXY($this->marge_gauche, $posy);
1634 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1635 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1636 $posy = $pdf->GetY() + 2;
1643 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1649 $account =
new Account($this->db);
1650 $account->fetch($bankid);
1652 $curx = $this->marge_gauche;
1655 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1661 $qrPosX = $this->marge_gauche + 5;
1663 $qrCodeColor = array(
'25',
'25',
'25');
1667 'fgcolor' => $qrCodeColor,
1669 'module_width' => 1,
1670 'module_height' => 1
1673 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1674 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 20, 20, $styleQr,
'N');
1676 $pdf->SetXY($qrPosX + 25, $posy + 5);
1677 $pdf->SetFont(
'',
'', $default_font_size - 5);
1678 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
1679 $posy = $pdf->GetY() + 2;
1684 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1687 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1719 $tab2_top = $posy - 4;
1721 if (is_object($outputlangsbis)) {
1722 $pdf->SetFont(
'',
'', $default_font_size - 2);
1724 $pdf->SetFont(
'',
'', $default_font_size - 1);
1730 if ($this->page_largeur < 210) {
1734 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1740 $pdf->SetFillColor(255, 255, 255);
1741 $pdf->SetXY($col1x, $tab2_top + 0);
1742 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L',
true);
1745 $pdf->SetXY($col2x, $tab2_top + 0);
1746 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht, 0, $outputlangs), 0,
'R',
true);
1750 $pdf->SetFillColor(255, 255, 255);
1751 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1752 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1754 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1755 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1759 $pdf->SetFillColor(248, 248, 248);
1762 $total_ttc_origin =
$object->total_ttc;
1764 $this->atleastoneratenotnull = 0;
1767 if (!empty($this->tva_array) && count($this->tva_array) == 1) {
1768 $tva_el = reset($this->tva_array);
1769 if ($tva_el[
'vatrate'] ==
'0.000' && is_float($tva_el[
'amount'])) {
1773 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1777 pdfWriteVATArray($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl);
1782 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1783 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp",
$mysoc->country_code) :
''), $useborder,
'L',
true);
1785 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1786 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1791 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1792 $pdf->SetTextColor(0, 0, 60);
1793 $pdf->SetFillColor(224, 224, 224);
1794 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L',
true);
1796 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1798 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1800 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1804 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1805 $pdf->SetTextColor(0, 0, 60);
1806 $pdf->SetFillColor(224, 224, 224);
1807 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
'').
' ('.$outputlangs->getCurrencySymbol(
$mysoc->currency_code).
')', $useborder,
'L',
true);
1809 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1810 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc_origin, 0, $outputlangs, 1, -1, -1,
$mysoc->currency_code), $useborder,
'L',
true);
1815 if (
$object->displayRetainedWarranty()) {
1816 $pdf->SetTextColor(40, 40, 40);
1817 $pdf->SetFillColor(255, 255, 255);
1819 $retainedWarranty =
$object->getRetainedWarrantyAmount(
'MT');
1820 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
1824 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1825 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
1827 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1828 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
1832 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1834 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
1835 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
1837 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
1838 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1839 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
1844 $pdf->SetTextColor(0, 0, 0);
1846 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1849 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1852 $deja_regle_origin = 0;
1853 $creditnoteamount_origin = 0;
1854 $depositsamount_origin = 0;
1855 $resteapayer_origin = 0;
1857 $deja_regle_origin =
$object->getSommePaiement(0);
1858 $creditnoteamount_origin =
$object->getSumCreditNotesUsed(0);
1859 $depositsamount_origin =
$object->getSumDepositsUsed(0);
1860 $resteapayer_origin =
price2num($total_ttc_origin - $deja_regle_origin - $creditnoteamount_origin - $depositsamount_origin,
'MT');
1864 $resteapayer_origin = 0;
1867 pdfWriteAlreadyPaid($this, $index, $pdf, $outputlangs, $outputlangsbis,
$object, $col1x, $col2x, $largcol2, $tab2_top, $tab2_hl, $deja_regle, $creditnoteamount, $depositsamount, $resteapayer, $resteapayer_origin);
1869 $pdf->SetFont(
'',
'', $default_font_size - 1);
1870 $pdf->SetTextColor(0, 0, 0);
1872 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
1874 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
1876 $this->error = $hookmanager->error;
1877 $this->errors = $hookmanager->errors;
1881 return ($tab2_top + ($tab2_hl * $index));
2007 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2010 global
$conf, $langs;
2012 $ltrdirection =
'L';
2013 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2014 $ltrdirection =
'R';
2018 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2024 $pdf->SetTextColor(0, 0, 60);
2025 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2029 $posy = $this->marge_haute;
2030 $posx = $this->page_largeur - $this->marge_droite - $w;
2032 $pdf->SetXY($this->marge_gauche, $posy);
2035 $logodir =
$conf->mycompany->dir_output;
2036 if (!empty(
$conf->mycompany->multidir_output[
$object->entity ??
$conf->entity])) {
2039 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size, $ltrdirection);
2041 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2042 $pdf->SetXY($posx, $posy);
2043 $pdf->SetTextColor(0, 0, 60);
2045 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2047 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2050 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2053 $title = $outputlangs->transnoentities(
"PdfInvoiceDepositTitle");
2055 if ($this->situationinvoice) {
2056 $outputlangs->loadLangs(array(
"other"));
2057 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2058 $subtitle = $outputlangs->transnoentities(
"PDFSituationTitle", (
string)
$object->situation_counter);
2060 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2063 if ($this->situationinvoice) {
2064 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2066 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2067 } elseif (
$object->type == 1) {
2068 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2069 } elseif (
$object->type == 2) {
2070 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2071 } elseif (
$object->type == 3) {
2072 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2073 } elseif (
$object->type == 4) {
2074 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2077 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2078 if (
$object->status == $object::STATUS_DRAFT) {
2079 $pdf->SetTextColor(128, 0, 0);
2080 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2083 $pdf->MultiCell($w, 3, $title,
'',
'R');
2084 if (!empty($subtitle)) {
2085 $pdf->SetFont(
'',
'B', $default_font_size);
2086 $pdf->SetXY($posx, $posy + 5);
2087 $pdf->MultiCell($w, 6, $subtitle,
'',
'R');
2091 $pdf->SetFont(
'',
'', $default_font_size - 2);
2108 $pdf->SetFont(
'',
'', $default_font_size - 2);
2112 $pdf->SetXY($posx, $posy);
2113 $pdf->SetTextColor(0, 0, 60);
2114 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
pdf_truncate_text($pdf, $outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2119 if (!empty(
$object->project->title)) {
2121 $pdf->SetXY($posx, $posy);
2122 $pdf->SetTextColor(0, 0, 60);
2123 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".
pdf_truncate_text($pdf,
$object->project->title, 50),
'',
'R');
2129 if (!empty(
$object->project->ref)) {
2130 $outputlangs->load(
"projects");
2132 $pdf->SetXY($posx, $posy);
2133 $pdf->SetTextColor(0, 0, 60);
2134 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".
$object->project->ref,
'',
'R');
2138 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2139 if (
$object->type == 0 && $objectidnext) {
2140 $objectreplacing =
new Facture($this->db);
2141 $objectreplacing->fetch($objectidnext);
2144 $pdf->SetXY($posx, $posy);
2145 $pdf->SetTextColor(0, 0, 60);
2146 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2149 $objectreplaced =
new Facture($this->db);
2150 $objectreplaced->fetch(
$object->fk_facture_source);
2153 $pdf->SetXY($posx, $posy);
2154 $pdf->SetTextColor(0, 0, 60);
2155 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2158 $objectreplaced =
new Facture($this->db);
2159 $objectreplaced->fetch(
$object->fk_facture_source);
2162 $pdf->SetXY($posx, $posy);
2163 $pdf->SetTextColor(0, 0, 60);
2164 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2168 $pdf->SetXY($posx, $posy);
2169 $pdf->SetTextColor(0, 0, 60);
2171 $title = $outputlangs->transnoentities(
"DateInvoice");
2172 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2173 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2175 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2179 $pdf->SetXY($posx, $posy);
2180 $pdf->SetTextColor(0, 0, 60);
2181 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2186 $pdf->SetXY($posx, $posy);
2187 $pdf->SetTextColor(0, 0, 60);
2188 $title = $outputlangs->transnoentities(
"DateDue");
2189 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2190 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2192 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2197 $pdf->SetXY($posx, $posy);
2198 $pdf->SetTextColor(0, 0, 60);
2199 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_client),
'',
'R');
2204 $pdf->SetXY($posx, $posy);
2205 $pdf->SetTextColor(0, 0, 60);
2206 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities((
string)
$object->thirdparty->code_compta_client),
'',
'R');
2211 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2212 if (count($arrayidcontact) > 0) {
2213 $usertmp =
new User($this->db);
2214 $usertmp->fetch($arrayidcontact[0]);
2216 $pdf->SetXY($posx, $posy);
2217 $pdf->SetTextColor(0, 0, 60);
2218 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2228 $current_y = $pdf->getY();
2230 if ($current_y < $pdf->getY()) {
2231 $top_shift = $pdf->getY() - $current_y;
2237 $carac_emetteur =
'';
2239 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2240 if (count($arrayidcontact) > 0) {
2241 $object->fetch_user($arrayidcontact[0]);
2242 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2243 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2244 $carac_emetteur .=
"\n";
2250 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2251 $posy += $top_shift;
2252 $posx = $this->marge_gauche;
2254 $posx = $this->page_largeur - $this->marge_droite - 80;
2262 $pdf->SetTextColor(0, 0, 0);
2263 $pdf->SetFont(
'',
'', $default_font_size - 2);
2264 $pdf->SetXY($posx, $posy - 5);
2265 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2266 $pdf->SetXY($posx, $posy);
2267 $pdf->SetFillColor(230, 230, 230);
2268 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2269 $pdf->SetTextColor(0, 0, 60);
2274 $pdf->SetXY($posx + 2, $posy + 3);
2275 $pdf->SetFont(
'',
'B', $default_font_size);
2276 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2277 $posy = $pdf->getY();
2281 $pdf->SetXY($posx + 2, $posy);
2282 $pdf->SetFont(
'',
'', $default_font_size - 1);
2283 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2286 $usecontact =
false;
2287 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2288 if (count($arrayidcontact) > 0) {
2290 $result =
$object->fetch_contact($arrayidcontact[0]);
2294 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2295 $thirdparty =
$object->contact;
2297 $thirdparty =
$object->thirdparty;
2307 if ($this->page_largeur < 210) {
2310 $posy =
getDolGlobalString(
'MAIN_PDF_USE_ISO_LOCATION') ? $this->marge_haute + 30 : $this->marge_haute + 32;
2311 $posy += $top_shift;
2312 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2314 $posx = $this->marge_gauche;
2319 $pdf->SetTextColor(0, 0, 0);
2320 $pdf->SetFont(
'',
'', $default_font_size - 2);
2321 $pdf->SetXY($posx + 2, $posy - 5);
2322 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2323 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2327 $pdf->SetXY($posx + 2, $posy + 3);
2328 $pdf->SetFont(
'',
'B', $default_font_size);
2330 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2332 $posy = $pdf->getY();
2335 $pdf->SetFont(
'',
'', $default_font_size - 1);
2336 $pdf->SetXY($posx + 2, $posy);
2338 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2342 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2344 if (!empty($idaddressshipping)) {
2345 $object->fetch_contact($idaddressshipping[0]);
2346 $companystatic =
new Societe($this->db);
2347 $companystatic->fetch(
$object->contact->fk_soc);
2354 if (!empty($carac_client_shipping)) {
2355 $posy += $hautcadre;
2360 $pdf->SetXY($posx + 2, $posy - 5);
2361 $pdf->SetFont(
'',
'', $default_font_size - 2);
2362 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2363 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2366 $pdf->SetXY($posx + 2, $posy + 3);
2367 $pdf->SetFont(
'',
'B', $default_font_size);
2368 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2370 $posy = $pdf->getY();
2373 $pdf->SetXY($posx + 2, $posy);
2374 $pdf->SetFont(
'',
'', $default_font_size - 1);
2375 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2377 $shipp_shift += $hautcadre;
2382 $pdf->SetTextColor(0, 0, 0);
2384 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);
2728 public function tableFirstPage(
$object, &$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
2730 global $user,
$conf;
2732 $form =
new Form($this->db);
2736 if (!$displayWarranty) {
2747 $currency = !empty($currency) ? $currency : (string)
$conf->currency;
2751 $pdf->SetTextColor(0, 0, 0);
2752 $pdf->SetFont(
'',
'', $default_font_size - 2);
2754 if (empty($hidetop)) {
2755 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
2756 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 8);
2757 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2759 $width = $this->page_largeur - $this->marge_gauche - $this->marge_droite - 83;
2763 $pdf->RoundedRect($this->posx_cumul_anterieur - 1, $tab_top, $width, 5, $this->corner_radius,
'1001',
'F', explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2765 $pdf->RoundedRect($this->marge_gauche, $tab_top + 92.5, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius,
'1001',
'F', array(), explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2769 $pdf->SetDrawColor(128, 128, 128);
2770 $pdf->SetFont(
'',
'', $default_font_size - 1);
2772 $height_incoterms = 0;
2774 $desc_incoterms =
$object->getIncotermsForPDF();
2775 if ($desc_incoterms) {
2776 $this->tab_top -= 2;
2777 $posybefore = $pdf->GetY();
2778 $pdf->SetFont(
'',
'', $default_font_size - 1);
2779 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
2782 $pdf->SetDrawColor(192, 192, 192);
2783 $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');
2784 $posyafter = $pdf->GetY();
2785 $tab_top += $posyafter - $posybefore + 2;
2789 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
2792 if (is_object(
$object->thirdparty)) {
2793 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
2794 $salerepobj =
new User($this->db);
2795 $salerepobj->fetch($salereparray[0][
'id']);
2796 if (!empty($salerepobj->signature)) {
2797 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
2803 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
2804 if (!empty($extranote)) {
2810 $posybefore = $pdf->GetY();
2816 $pdf->SetFont(
'',
'', $default_font_size - 1);
2817 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
2819 $posyafter = $pdf->GetY();
2820 $tab_top += $posyafter - $posybefore + 2;
2825 $this->
printRoundedRectBtp($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom,
'D');
2827 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top, $this->posx_cumul_anterieur - 1, $tab_top + $tab_height);
2828 if (empty($hidetop)) {
2829 $pdf->SetXY($this->posx_cumul_anterieur - 1, $tab_top + 0.5);
2830 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceOldCumulation"),
'',
'C');
2834 $pdf->line($this->posx_new_cumul - 1, $tab_top, $this->posx_new_cumul - 1, $tab_top + $tab_height);
2835 if (empty($hidetop)) {
2836 $pdf->SetXY($this->posx_new_cumul - 1, $tab_top + 0.5);
2837 $pdf->MultiCell(35, 2, $outputlangs->transnoentities(
"SituationInvoiceNewCumulation"),
'',
'C');
2840 $pdf->line($this->posx_current - 1, $tab_top, $this->posx_current - 1, $tab_top + $tab_height);
2841 if (empty($hidetop)) {
2842 $pdf->SetXY($this->posx_current - 1, $tab_top + 0.5);
2843 $pdf->MultiCell(36, 2, $outputlangs->transnoentities(
"CurrentSituationTotal", (
string)
$object->situation_counter),
'',
'C');
2847 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2849 $pdf->line($this->posx_cumul_anterieur - 1, $tab_top + 24, $this->page_largeur - $this->marge_droite, $tab_top + 24);
2851 $pdf->line($this->marge_gauche, $tab_top + 55, $this->page_largeur - $this->marge_droite, $tab_top + 55);
2853 $pdf->line($this->marge_gauche, $tab_top + 65, $this->page_largeur - $this->marge_droite, $tab_top + 65);
2855 if ($displayWarranty) {
2856 $pdf->line($this->marge_gauche, $tab_top + 85, $this->page_largeur - $this->marge_droite, $tab_top + 85);
2862 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 8);
2863 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceMainTask"),
'',
'L');
2865 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 12);
2866 $pdf->MultiCell(60, 2, $outputlangs->transnoentities(
"SituationInvoiceAdditionalTask"),
'',
'L');
2868 $form->load_cache_vatrates(
"'".
$object->thirdparty->country_code.
"'");
2871 foreach ($form->cache_vatrates as $TVatInfo) {
2872 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2874 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2879 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 24 + $i);
2880 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalHT").
' '.$TVatInfo[
'label'],
'',
'L');
2882 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2883 $pdf->SetXY($this->marge_gauche + 10, $tab_top + 28 + $i);
2884 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"VAT").
' '.$TVatInfo[
'label'],
'',
'L');
2890 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 33 + $i);
2891 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalTTC"),
'',
'L');
2894 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2895 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 58);
2896 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"TotalSituationInvoice"),
'',
'L');
2897 $pdf->SetFont(
'',
'', $default_font_size - 2);
2899 if ($displayWarranty) {
2900 $pdf->SetXY($this->marge_gauche + 2, $tab_top + 74);
2901 $pdf->MultiCell(80, 2, $outputlangs->trans(
"TotalSituationInvoiceWithRetainedWarranty", (
string)
$object->retained_warranty),
'',
'L');
2902 $nextY = $tab_top + 93;
2904 $nextY = $tab_top + 74;
2907 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2908 $pdf->SetXY($this->marge_gauche + 2, $nextY);
2909 $pdf->MultiCell(80, 2, $outputlangs->transnoentities(
"SituationTotalRayToRest"),
'',
'L');
2910 $pdf->SetFont(
'',
'', $default_font_size - 2);
2914 $TToDisplay = array(
2920 $x = $this->marge_gauche + 85;
2924 foreach ($TToDisplay as $col) {
2926 $pdf->SetXY($x, $tab_top + 8);
2927 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2930 $pdf->SetXY($x, $tab_top + 12);
2931 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'travaux_sup'], 0,
'', 1, -1, 2),
'',
'R');
2934 foreach ($form->cache_vatrates as $TVatInfo) {
2935 $tva_tx_formated = sprintf(
"%01.3f", (
float) $TVatInfo[
'txtva']);
2936 if (empty($this->TDataSituation[
'current'][$tva_tx_formated])) {
2942 $pdf->SetXY($x, $tab_top + 24 + $i);
2943 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'HT'], 0,
'', 1, -1, 2),
'',
'R');
2946 if (! empty($this->TDataSituation[
'current'][$tva_tx_formated][
'TVA'])) {
2947 $pdf->SetXY($x, $tab_top + 28 + $i);
2948 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][$tva_tx_formated][
'TVA'], 0,
'', 1, -1, 2),
'',
'R');
2955 $pdf->SetXY($x, $tab_top + 33 + $i);
2956 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2959 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2960 $pdf->SetXY($x, $tab_top + 58);
2961 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'TTC'], 0,
'', 1, -1, 2),
'',
'R');
2962 $pdf->SetFont(
'',
'', $default_font_size - 2);
2965 if ($displayWarranty) {
2967 $pdf->SetXY($x, $tab_top + 74);
2968 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'retenue_garantie'], 0,
'', 1, -1, 2),
'',
'R');
2969 $nextY = $tab_top + 93;
2971 $nextY = $tab_top + 74;
2975 $pdf->SetFont(
'',
'B', $default_font_size - 1);
2976 $pdf->SetXY($x, $nextY);
2977 $pdf->MultiCell(32, 2,
price($this->TDataSituation[$col][
'total_a_payer'], 0,
'', 1, -1, 2),
'',
'R');
2978 $pdf->SetFont(
'',
'', $default_font_size - 2);