202 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
205 global $user, $langs, $conf,
$mysoc, $hookmanager, $nblines;
207 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
209 if (!is_object($outputlangs)) {
210 $outputlangs = $langs;
214 $outputlangs->charset_output =
'ISO-8859-1';
218 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
225 global $outputlangsbis;
226 $outputlangsbis =
null;
228 $outputlangsbis =
new Translate(
'', $conf);
230 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
233 $nblines = count(
$object->lines);
236 $realpatharray = array();
238 for ($i = 0; $i < $nblines; $i++) {
239 if (empty(
$object->lines[$i]->fk_product)) {
243 $objphoto =
new Product($this->db);
244 $objphoto->fetch(
$object->lines[$i]->fk_product);
246 $pdir =
get_exdir(
$object->lines[$i]->fk_product, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
247 $dir = $conf->product->dir_output.
'/'.$pdir;
250 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
251 $filename = $obj[
'photo'];
253 $realpath = $dir.$filename;
258 $realpatharray[$i] = $realpath;
262 if (count($realpatharray) == 0) {
263 $this->posxpicture = $this->posxtva;
266 if ($conf->facture->dir_output) {
270 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
271 $amount_deposits_included =
$object->getSumDepositsUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
275 $dir = empty($conf->facture->multidir_output[
$object->entity ?? $conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[
$object->entity ?? $conf->entity];
276 $file = $dir.
"/SPECIMEN.pdf";
279 $dir = (empty($conf->facture->multidir_output[
$object->entity ?? $conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[
$object->entity ?? $conf->entity]).
"/".$objectref;
280 $file = $dir.
"/".$objectref.
".pdf";
282 if (!file_exists($dir)) {
284 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
289 if (file_exists($dir)) {
291 if (!is_object($hookmanager)) {
292 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
295 $hookmanager->initHooks(array(
'pdfgeneration'));
296 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
298 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
301 $nblines = count(
$object->lines);
302 $nbpayments = count(
$object->getListOfPayments());
307 $pdf->setAutoPageBreak(
true, 0);
309 $heightforinfotot = 50 + (4 * $nbpayments);
310 if ($heightforinfotot > 220) {
311 $heightforinfotot = 220;
314 $heightforfooter = $this->marge_basse + 8;
316 $heightforfooter += 6;
319 $heightforqrinvoice_firstpage = 0;
322 if ($heightforqrinvoice_firstpage > 0) {
324 $heightforinfotot = 30 + (4 * $nbpayments);
328 if (class_exists(
'TCPDF')) {
329 $pdf->setPrintHeader(
false);
330 $pdf->setPrintFooter(
false);
336 $logodir = $conf->mycompany->dir_output;
337 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
338 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
340 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
341 $tplidx = $pdf->importPage(1);
346 $pdf->SetDrawColor(128, 128, 128);
348 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
349 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
350 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
351 $pdf->SetAuthor(
$mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
352 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
354 $pdf->SetCompression(
false);
358 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
359 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
370 'Name' => $this->emetteur->name,
371 'Location' =>
getCountry($this->emetteur->country_code,
''),
372 'Reason' =>
'INVOICE',
373 'ContactInfo' => $this->emetteur->email
375 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
379 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
383 $categoryOfOperation = 0;
386 for ($i = 0; $i < $nblines; $i++) {
387 if (
$object->lines[$i]->remise_percent) {
388 $this->atleastonediscount++;
394 if (preg_match(
'/^\((.*)\)$/',
$object->lines[$i]->desc, $reg)) {
395 if ($reg[1] ==
'DEPOSIT') {
407 if (preg_match(
'/^\((.*)\)$/',
$object->lines[$i]->desc, $reg)) {
408 if ($reg[1] ==
'DEPOSIT') {
419 if ($categoryOfOperation < 2) {
420 $lineProductType =
$object->lines[$i]->product_type;
426 if ($nbProduct > 0 && $nbService > 0) {
428 $categoryOfOperation = 2;
433 if ($categoryOfOperation <= 0) {
435 if ($nbProduct == 0 && $nbService > 0) {
436 $categoryOfOperation = 1;
439 $this->categoryOfOperation = $categoryOfOperation;
440 if (empty($this->atleastonediscount)) {
441 $delta = ($this->posxprogress - $this->posxdiscount);
442 $this->posxpicture += $delta;
443 $this->posxtva += $delta;
444 $this->posxup += $delta;
445 $this->posxqty += $delta;
446 $this->posxunit += $delta;
447 $this->posxdiscount += $delta;
454 $this->situationinvoice =
true;
455 $progress_width = 10;
456 $this->posxpicture -= $progress_width;
457 $this->posxtva -= $progress_width;
458 $this->posxup -= $progress_width;
459 $this->posxqty -= $progress_width;
460 $this->posxunit -= $progress_width;
461 $this->posxdiscount -= $progress_width;
462 $this->posxprogress -= $progress_width;
467 if (!empty($tplidx)) {
468 $pdf->useTemplate($tplidx);
474 $pdf->SetFont(
'',
'', $default_font_size - 1);
475 $pdf->MultiCell(0, 3,
'');
476 $pdf->SetTextColor(0, 0, 0);
481 $tab_top = 90 + $top_shift;
482 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
485 $extra_under_address_shift = 0;
488 $qrcodestring =
$object->buildZATCAQRString();
491 $qrcodestring =
$object->buildSwitzerlandQRString();
495 $qrcodestring =
$object->buildEPCQrCodeString();
500 $qrcodecolor = array(
'25',
'25',
'25');
505 'fgcolor' => $qrcodecolor,
510 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr,
'N');
514 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
515 $pdf->SetFont(
'',
'', $default_font_size - 4);
516 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L',
false);
520 $extra_under_address_shift += 25;
528 'outputlangs' => $outputlangs,
529 'hidedetails' => $hidedetails
531 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
532 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
533 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
536 $tab_top += $extra_under_address_shift;
537 $tab_top_newpage += 0;
540 $height_incoterms = 0;
542 $desc_incoterms =
$object->getIncotermsForPDF();
543 if ($desc_incoterms) {
546 $pdf->SetFont(
'',
'', $default_font_size - 1);
547 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
548 $nexY = $pdf->GetY();
549 $height_incoterms = $nexY - $tab_top;
552 $pdf->SetDrawColor(192, 192, 192);
553 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
555 $tab_top = $nexY + 6;
560 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
563 if (is_object(
$object->thirdparty)) {
564 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
565 $salerepobj =
new User($this->db);
566 $salerepobj->fetch($salereparray[0][
'id']);
567 if (!empty($salerepobj->signature)) {
568 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
573 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
574 if (!empty($extranote)) {
586 $pdf->SetFont(
'',
'', $default_font_size - 1);
587 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
588 $nexY = $pdf->GetY();
589 $height_note = $nexY - $tab_top;
592 $pdf->SetDrawColor(192, 192, 192);
593 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1, $this->corner_radius,
'1234',
'D');
595 $tab_top = $nexY + 6;
598 $iniY = $tab_top + 7;
599 $curY = $tab_top + 7;
600 $nexY = $tab_top + 7;
603 for ($i = 0; $i < $nblines; $i++) {
605 $pdf->SetFont(
'',
'', $default_font_size - 1);
606 $pdf->SetTextColor(0, 0, 0);
609 $imglinesize = array();
610 if (!empty($realpatharray[$i])) {
614 $pdf->setTopMargin($tab_top_newpage);
615 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
616 $pdf->setPageOrientation(
'',
true, $page_bottom_margin);
617 $pageposbefore = $pdf->getPage();
619 $showpricebeforepagebreak = 1;
621 $posYAfterDescription = 0;
624 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
625 $pdf->AddPage(
'',
'',
true);
626 if (!empty($tplidx)) {
627 $pdf->useTemplate($tplidx);
631 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
633 $pdf->setPage($pageposbefore + 1);
635 $curY = $tab_top_newpage;
639 $showpricebeforepagebreak = 1;
641 $showpricebeforepagebreak = 0;
645 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
646 $curX = $this->posxpicture - 1;
647 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
649 $posYAfterImage = $curY + $imglinesize[
'height'];
653 $curX = $this->posxdesc - 1;
655 $pdf->startTransaction();
656 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
657 $pageposafter = $pdf->getPage();
658 if ($pageposafter > $pageposbefore) {
659 $pdf->rollbackTransaction(
true);
660 $pageposafter = $pageposbefore;
662 $pdf->setPageOrientation(
'',
true, $heightforfooter);
663 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
664 $pageposafter = $pdf->getPage();
665 $posyafter = $pdf->GetY();
667 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
668 if ($i == ($nblines - 1)) {
669 $pdf->AddPage(
'',
'',
true);
670 if (!empty($tplidx)) {
671 $pdf->useTemplate($tplidx);
675 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
677 $pdf->setPage($pageposafter + 1);
684 $showpricebeforepagebreak = 1;
686 $showpricebeforepagebreak = 0;
690 $pdf->commitTransaction();
692 $posYAfterDescription = $pdf->GetY();
694 $nexY = $pdf->GetY();
695 $pageposafter = $pdf->getPage();
696 $pdf->setPage($pageposbefore);
697 $pdf->setTopMargin($this->marge_haute);
698 $pdf->setPageOrientation(
'',
true, 0);
701 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
702 $pdf->setPage($pageposafter);
703 $curY = $tab_top_newpage;
706 $pdf->SetFont(
'',
'', $default_font_size - 1);
711 $pdf->SetXY($this->posxtva - 5, $curY);
712 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0,
'R');
717 $pdf->SetXY($this->posxup, $curY);
718 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R',
false);
722 $pdf->SetXY($this->posxqty, $curY);
723 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
728 $pdf->SetXY($this->posxunit, $curY);
729 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
733 if (
$object->lines[$i]->remise_percent) {
734 $pdf->SetXY($this->posxdiscount - 2, $curY);
736 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0,
'R');
740 if ($this->situationinvoice) {
742 $pdf->SetXY($this->posxprogress, $curY);
743 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0,
'R');
748 $pdf->SetXY($this->postotalht, $curY);
749 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R',
false);
757 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
758 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
760 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
762 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
766 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
768 $tvaligne = $sign *
$object->lines[$i]->total_tva;
772 $localtax1ligne =
$object->lines[$i]->total_localtax1;
773 $localtax2ligne =
$object->lines[$i]->total_localtax2;
774 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
775 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
776 $localtax1_type =
$object->lines[$i]->localtax1_type;
777 $localtax2_type =
$object->lines[$i]->localtax2_type;
779 $vatrate = (string)
$object->lines[$i]->tva_tx;
782 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
783 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
785 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
786 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
790 if ($localtax1_type && $localtax1ligne != 0) {
791 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
792 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
794 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
797 if ($localtax2_type && $localtax2ligne != 0) {
798 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
799 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
801 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
805 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
810 if (!isset($this->tva[$vatrate])) {
811 $this->tva[$vatrate] = 0;
813 $this->tva[$vatrate] += $tvaligne;
814 $vatcode =
$object->lines[$i]->vat_src_code;
816 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
817 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
819 $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);
821 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
822 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
824 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
827 if ($posYAfterImage > $posYAfterDescription) {
828 $nexY = $posYAfterImage;
833 $pdf->setPage($pageposafter);
834 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
836 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
837 $pdf->SetLineStyle(array(
'dash' => 0));
843 while ($pagenb < $pageposafter) {
844 $pdf->setPage($pagenb);
846 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
848 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
852 $pdf->setPage($pagenb);
853 $pdf->setPageOrientation(
'',
true, 0);
856 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
858 if (!empty($tplidx)) {
859 $pdf->useTemplate($tplidx);
862 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
864 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
866 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
871 if (!empty($tplidx)) {
872 $pdf->useTemplate($tplidx);
877 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
884 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
885 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
887 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
888 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
890 dol_syslog(
"bottomlasttab=".$bottomlasttab.
" this->page_hauteur=".$this->page_hauteur.
" heightforinfotot=".$heightforinfotot.
" heightforfreetext=".$heightforfreetext.
" heightforfooter=".$heightforfooter);
896 $posy = $this->
_tableau_tot($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
899 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
900 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
906 if (method_exists($pdf,
'AliasNbPages')) {
907 $pdf->AliasNbPages();
920 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
921 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
922 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
923 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
925 if (file_exists($termsofsale) && is_readable($termsofsale)) {
926 $pagecount = $pdf->setSourceFile($termsofsale);
927 for ($i = 1; $i <= $pagecount; $i++) {
928 $tplIdx = $pdf->importPage($i);
929 if ($tplIdx !==
false) {
930 $s = $pdf->getTemplatesize($tplIdx);
931 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
932 $pdf->useTemplate($tplIdx);
934 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
942 $pdf->Output($file,
'F');
945 $hookmanager->initHooks(array(
'pdfgeneration'));
946 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
948 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
949 $this->warnings = $hookmanager->warnings;
951 $this->error = $hookmanager->error;
952 $this->errors = $hookmanager->errors;
959 $this->result = array(
'fullpath' => $file);
963 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
967 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
994 $current_page = $pdf->getPage();
996 $tab3_top = $posy + 8;
999 if ($this->page_largeur < 210) {
1009 $pdf->SetFont(
'',
'', $default_font_size - 4);
1013 $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,";
1014 $sql .=
" re.description, re.fk_facture_source,";
1015 $sql .=
" f.type, f.datef";
1016 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1017 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1018 $resql = $this->db->query($sql);
1020 $num = $this->db->num_rows($resql);
1022 $invoice =
new Facture($this->db);
1025 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1028 $pdf->AddPage(
'',
'',
true);
1034 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1036 $pdf->setPage($current_page);
1040 $obj = $this->db->fetch_object($resql);
1042 if ($obj->type == 2) {
1043 $text = $outputlangs->transnoentities(
"CreditNote");
1044 } elseif ($obj->type == 3) {
1045 $text = $outputlangs->transnoentities(
"Deposit");
1046 } elseif ($obj->type == 0) {
1047 $text = $outputlangs->transnoentities(
"ExcessReceived");
1049 $text = $outputlangs->transnoentities(
"UnknownType");
1052 $invoice->fetch($obj->fk_facture_source);
1054 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1055 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1056 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1057 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1058 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1059 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1060 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1061 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1063 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1068 $this->error = $this->db->lasterror();
1074 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1076 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1077 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1078 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1080 $sql .=
" ORDER BY p.datep";
1082 $resql = $this->db->query($sql);
1084 $num = $this->db->num_rows($resql);
1089 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1092 $pdf->AddPage(
'',
'',
true);
1098 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1100 $pdf->setPage($current_page);
1104 $row = $this->db->fetch_object($resql);
1106 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1107 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1108 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1109 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1110 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1111 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1113 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1114 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1115 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1116 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1117 $y = $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1118 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1123 return $tab3_top + $y + 3;
1125 $this->error = $this->db->lasterror();
1191 $pdf->SetFont(
'',
'', $default_font_size - 1);
1193 krsort($this->tva_array);
1200 $pdf->SetFillColor(224, 224, 224);
1202 $pdf->SetFont(
'',
'', $default_font_size - 2);
1203 $pdf->SetXY($this->marge_gauche, $posy);
1204 $titre = $outputlangs->transnoentities(
"VAT");
1205 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1207 $pdf->SetFont(
'',
'', $default_font_size - 2);
1208 $pdf->SetXY($this->marge_gauche + 25, $posy);
1209 $titre = $outputlangs->transnoentities(
"NetTotal");
1210 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1212 $pdf->SetFont(
'',
'', $default_font_size - 2);
1213 $pdf->SetXY($this->marge_gauche + 50, $posy);
1214 $titre = $outputlangs->transnoentities(
"VATAmount");
1215 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1217 $pdf->SetFont(
'',
'', $default_font_size - 2);
1218 $pdf->SetXY($this->marge_gauche + 75, $posy);
1219 $titre = $outputlangs->transnoentities(
"AmountTotal");
1220 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1222 $posy = $pdf->GetY();
1227 foreach ($this->tva_array as $tvakey => $tvaval) {
1228 $pdf->SetFont(
'',
'', $default_font_size - 2);
1229 $pdf->SetXY($this->marge_gauche, $posy);
1230 $titre = round((
float) $tvakey, 2) .
"%";
1231 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1233 $pdf->SetFont(
'',
'', $default_font_size - 2);
1234 $pdf->SetXY($this->marge_gauche + 25, $posy);
1235 $titre =
price($tvaval[
'tot_ht']);
1236 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1237 $tot_ht += $tvaval[
'tot_ht'];
1239 $pdf->SetFont(
'',
'', $default_font_size - 2);
1240 $pdf->SetXY($this->marge_gauche + 50, $posy);
1241 $titre =
price($tvaval[
'amount']);
1242 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1243 $tot_tva += $tvaval[
'amount'];
1245 $pdf->SetFont(
'',
'', $default_font_size - 2);
1246 $pdf->SetXY($this->marge_gauche + 75, $posy);
1247 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1248 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1249 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1251 $posy = $pdf->GetY();
1256 $showvatmention = 0;
1257 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1258 $pdf->SetFont(
'',
'', $default_font_size - 2);
1259 $pdf->SetXY($this->marge_gauche, $posy);
1260 if (empty(
$mysoc->tva_assuj)) {
1261 if (
$mysoc->forme_juridique_code == 92) {
1262 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1264 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1267 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1268 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1271 $posy = $pdf->GetY();
1274 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1276 if ($showvatmention) {
1282 if ($this->page_largeur < 210) {
1289 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1290 $sql.=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1291 $sql.=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1292 $sql.=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1293 $sql.=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1294 $sql.=
" AND f.rowid < " . ((int)
$object->id);
1295 $sql.=
" AND f.fk_statut > 0";
1296 $sql.=
" ORDER BY f.datef ASC";
1299 $invoices = array();
1300 $resql = $this->db->query($sql);
1302 while ($obj = $this->db->fetch_object($resql)) {
1304 $old_balance += $obj->total_ttc;
1306 $this->db->free($resql);
1310 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1311 $sql_payments.=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1312 $sql_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1313 $sql_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1314 $sql_payments.=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1315 $sql_payments.=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1316 $sql_payments.=
" ORDER BY p.datep ASC";
1318 $total_payments = 0;
1319 $resql_payments = $this->db->query($sql_payments);
1320 if ($resql_payments) {
1321 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1322 $total_payments += $obj_payment->amount;
1324 $this->db->free($resql_payments);
1328 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1329 $sql_current_date_payments.=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1330 $sql_current_date_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1331 $sql_current_date_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1332 $sql_current_date_payments.=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1333 $sql_current_date_payments.=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1335 $current_date_payments = 0;
1336 $resql_current_date = $this->db->query($sql_current_date_payments);
1337 if ($resql_current_date) {
1338 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1339 $current_date_payments += $obj_current->amount;
1341 $this->db->free($resql_current_date);
1345 $old_balance -= $total_payments;
1348 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1350 $pdf->SetFillColor(224, 224, 224);
1351 $pdf->SetFont(
'',
'', $default_font_size - 2);
1352 $pdf->SetXY($this->marge_gauche, $posy);
1353 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1354 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1356 $pdf->SetFont(
'',
'', $default_font_size - 2);
1357 $pdf->SetXY($posxval+8, $posy);
1358 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1359 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1361 $posy = $pdf->GetY() + 1;
1366 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1367 $pdf->SetXY($this->marge_gauche, $posy);
1368 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1369 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1371 $pdf->SetFont(
'',
'', $default_font_size - 2);
1372 $pdf->SetXY($posxval, $posy);
1373 $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);
1374 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1375 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1377 $posy = $pdf->GetY() + 3;
1381 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1382 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1383 $pdf->SetXY($this->marge_gauche, $posy);
1384 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1385 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1387 $pdf->SetFont(
'',
'', $default_font_size - 2);
1388 $pdf->SetXY($posxval, $posy);
1389 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1390 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1392 $posy = $pdf->GetY() + 3;
1397 if (empty(
$object->mode_reglement_code)
1400 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1404 $outputlangs->load(
"errors");
1406 $pdf->SetXY($this->marge_gauche, $posy);
1407 $pdf->SetTextColor(200, 0, 0);
1408 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1409 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1410 $pdf->MultiCell(80, 3, $this->error, 0,
'L',
false);
1411 $pdf->SetTextColor(0, 0, 0);
1413 $posy = $pdf->GetY() + 1;
1417 if (!empty(
$object->mode_reglement_code)
1418 &&
$object->mode_reglement_code !=
'CHQ'
1419 &&
$object->mode_reglement_code !=
'VIR') {
1420 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1421 $pdf->SetXY($this->marge_gauche, $posy);
1422 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1423 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1425 $pdf->SetFont(
'',
'', $default_font_size - 2);
1426 $pdf->SetXY($posxval, $posy);
1427 $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);
1429 if (
$object->mode_reglement_code ==
"PRE") {
1430 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1433 $bac->fetch(0,
'',
$object->thirdparty->id);
1434 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1435 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1437 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1439 $posy = $pdf->GetY();
1445 if ($this->emetteur->country_code ==
'FR') {
1447 $pdf->SetXY($this->marge_gauche, $posy);
1448 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1450 $posy = $pdf->GetY() + 1;
1455 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1456 $useonlinepayment = 0;
1460 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1461 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1462 $useonlinepayment = count($validpaymentmethod);
1466 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1469 $langs->loadLangs(array(
'payment',
'stripe'));
1470 $servicename = $langs->transnoentities(
'Online');
1472 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1473 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1475 $pdf->SetXY($this->marge_gauche, $posy);
1478 $posy = $pdf->GetY() + 1;
1483 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1489 $account =
new Account($this->db);
1492 $pdf->SetXY($this->marge_gauche, $posy);
1493 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1494 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1495 $posy = $pdf->GetY() + 1;
1498 $pdf->SetXY($this->marge_gauche, $posy);
1499 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1500 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1501 $posy = $pdf->GetY() + 2;
1505 $pdf->SetXY($this->marge_gauche, $posy);
1506 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1507 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1508 $posy = $pdf->GetY() + 1;
1511 $pdf->SetXY($this->marge_gauche, $posy);
1512 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1513 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1514 $posy = $pdf->GetY() + 2;
1521 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1527 $account =
new Account($this->db);
1528 $account->fetch((
int) $bankid);
1530 $curx = $this->marge_gauche;
1533 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1538 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1541 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1567 global $conf,
$mysoc, $hookmanager;
1576 $outputlangsbis =
null;
1578 $outputlangsbis =
new Translate(
'', $conf);
1580 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1581 $default_font_size--;
1586 $pdf->SetFont(
'',
'', $default_font_size - 1);
1591 if ($this->page_largeur < 210) {
1595 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1604 $total_discount_on_lines = 0;
1605 $multicurrency_total_discount_on_lines = 0;
1606 foreach (
$object->lines as $i => $line) {
1610 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1611 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1613 if ($line->total_ht < 0) {
1614 $total_discount_on_lines += -$line->total_ht;
1615 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1619 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
1621 $pdf->SetFillColor(255, 255, 255);
1622 $pdf->SetXY($col1x, $tab2_top);
1623 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1624 $pdf->SetXY($col2x, $tab2_top);
1626 $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));
1627 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1631 $pdf->SetFillColor(255, 255, 255);
1632 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1633 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1634 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1636 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1637 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1643 $pdf->SetFillColor(255, 255, 255);
1644 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1645 $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);
1648 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1649 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1653 $pdf->SetFillColor(255, 255, 255);
1654 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1657 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1658 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1662 $pdf->SetFillColor(248, 248, 248);
1666 $this->atleastoneratenotnull = 0;
1668 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1669 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1673 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1674 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1678 foreach ($localtax_rate as $tvakey => $tvaval) {
1679 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1683 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1686 if (preg_match(
'/\*/', (
string) $tvakey)) {
1687 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1688 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1691 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1695 $totalvat .= $tvacompl;
1697 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1700 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1704 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1705 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1711 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1712 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1716 foreach ($localtax_rate as $tvakey => $tvaval) {
1717 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1721 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1724 if (preg_match(
'/\*/', (
string) $tvakey)) {
1725 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1726 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1728 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1732 $totalvat .= $tvacompl;
1734 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1737 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1741 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1742 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1749 foreach ($this->tva_array as $tvakey => $tvaval) {
1751 $this->atleastoneratenotnull++;
1754 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1757 if (preg_match(
'/\*/', $tvakey)) {
1758 $tvakey = str_replace(
'*',
'', $tvakey);
1759 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1761 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1764 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1766 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1768 $totalvat .= $tvacompl;
1770 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1772 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1773 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1774 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
1780 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1781 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1785 foreach ($localtax_rate as $tvakey => $tvaval) {
1786 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1790 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1793 if (preg_match(
'/\*/', (
string) $tvakey)) {
1794 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1795 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1797 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).
' ';
1800 $totalvat .= $tvacompl;
1802 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1805 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1809 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1810 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1816 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1817 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1821 foreach ($localtax_rate as $tvakey => $tvaval) {
1822 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1826 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1829 if (preg_match(
'/\*/', (
string) $tvakey)) {
1830 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1831 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1833 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).
' ';
1836 $totalvat .= $tvacompl;
1838 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1841 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1845 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1846 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1854 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1855 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp"), $useborder,
'L',
true);
1857 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1858 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1863 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1864 $pdf->SetTextColor(0, 0, 60);
1865 $pdf->SetFillColor(224, 224, 224);
1866 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L',
true);
1868 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1869 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1872 if (
$object->displayRetainedWarranty()) {
1873 $pdf->SetTextColor(40, 40, 40);
1874 $pdf->SetFillColor(255, 255, 255);
1876 $retainedWarranty =
$object->getRetainedWarrantyAmount();
1877 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
1881 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1882 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
1884 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1885 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
1889 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1891 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
1892 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
1894 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
1895 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1896 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
1901 $pdf->SetTextColor(0, 0, 0);
1902 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1905 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1910 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1913 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1914 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L',
false);
1915 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1916 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R',
false);
1919 if ($creditnoteamount) {
1920 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1922 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1923 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L',
false);
1924 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1925 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R',
false);
1929 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1931 $pdf->SetFillColor(255, 255, 255);
1933 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1934 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L',
true);
1935 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1936 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R',
true);
1942 $pdf->SetTextColor(0, 0, 60);
1943 $pdf->SetFillColor(224, 224, 224);
1944 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1945 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L',
true);
1946 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1947 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1949 $pdf->SetFont(
'',
'', $default_font_size - 1);
1950 $pdf->SetTextColor(0, 0, 0);
1958 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1959 $pdf->MultiCell($col2x - $col1x, $tab2_hl,
getDolGlobalString(
'BILL_TEXT_TOTAL_FOOTER'), 0,
'L',
false);
1962 return ($tab2_top + ($tab2_hl * $index));
1979 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1989 $currency = !empty($currency) ? $currency : $conf->currency;
1993 $pdf->SetTextColor(0, 0, 0);
1994 $pdf->SetFont(
'',
'', $default_font_size - 2);
1996 if (empty($hidetop)) {
1998 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1999 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
2000 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2001 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2004 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
2005 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2006 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2009 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius,
'1001',
'F', array(), explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
2013 $pdf->SetDrawColor(128, 128, 128);
2014 $pdf->SetFont(
'',
'', $default_font_size - 1);
2017 $this->
printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom,
'D');
2019 if (empty($hidetop)) {
2020 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2022 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
2023 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
2027 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
2035 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
2036 if (empty($hidetop)) {
2037 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
2038 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
2042 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
2043 if (empty($hidetop)) {
2044 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
2045 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
2048 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
2049 if (empty($hidetop)) {
2050 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
2051 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
2055 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
2056 if (empty($hidetop)) {
2057 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
2058 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
2062 if ($this->atleastonediscount) {
2063 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
2064 if (empty($hidetop)) {
2065 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
2066 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
2070 if ($this->situationinvoice) {
2071 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
2072 if (empty($hidetop)) {
2073 $pdf->SetXY($this->posxprogress, $tab_top + 1);
2074 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities(
"ProgressShort"),
'',
'C');
2078 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
2079 if (empty($hidetop)) {
2080 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
2081 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
2096 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2099 global $conf, $langs;
2101 $ltrdirection =
'L';
2102 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2103 $ltrdirection =
'R';
2107 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2113 $pdf->SetTextColor(0, 0, 60);
2114 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2118 $posy = $this->marge_haute;
2119 $posx = $this->page_largeur - $this->marge_droite - $w;
2121 $pdf->SetXY($this->marge_gauche, $posy);
2125 if ($this->emetteur->logo) {
2126 $logodir = $conf->mycompany->dir_output;
2127 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
2128 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
2131 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2133 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2135 if (is_readable($logo)) {
2137 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2139 $pdf->SetTextColor(200, 0, 0);
2140 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2141 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2142 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2145 $text = $this->emetteur->name;
2146 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2150 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2151 $pdf->SetXY($posx, $posy);
2152 $pdf->SetTextColor(0, 0, 60);
2153 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2155 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2158 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2161 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2164 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2166 if ($this->situationinvoice) {
2167 $outputlangs->loadLangs(array(
"other"));
2168 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2170 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2173 if ($this->situationinvoice) {
2174 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2176 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2177 } elseif (
$object->type == 1) {
2178 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2179 } elseif (
$object->type == 2) {
2180 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2181 } elseif (
$object->type == 3) {
2182 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2183 } elseif (
$object->type == 4) {
2184 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2187 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2188 if (
$object->status == $object::STATUS_DRAFT) {
2189 $pdf->SetTextColor(128, 0, 0);
2190 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2193 $pdf->MultiCell($w, 3, $title,
'',
'R');
2195 $pdf->SetFont(
'',
'', $default_font_size - 2);
2212 $pdf->SetFont(
'',
'', $default_font_size - 2);
2216 $pdf->SetXY($posx, $posy);
2217 $pdf->SetTextColor(0, 0, 60);
2218 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset(
$object->ref_customer),
'',
'R');
2223 if (!empty(
$object->project->ref)) {
2225 $pdf->SetXY($posx, $posy);
2226 $pdf->SetTextColor(0, 0, 60);
2227 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2233 if (!empty(
$object->project->ref)) {
2234 $outputlangs->load(
"projects");
2236 $pdf->SetXY($posx, $posy);
2237 $pdf->SetTextColor(0, 0, 60);
2238 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2242 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2243 if (
$object->type == 0 && $objectidnext) {
2244 $objectreplacing =
new Facture($this->db);
2245 $objectreplacing->fetch($objectidnext);
2248 $pdf->SetXY($posx, $posy);
2249 $pdf->SetTextColor(0, 0, 60);
2250 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2253 $objectreplaced =
new Facture($this->db);
2254 $objectreplaced->fetch(
$object->fk_facture_source);
2257 $pdf->SetXY($posx, $posy);
2258 $pdf->SetTextColor(0, 0, 60);
2259 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2262 $objectreplaced =
new Facture($this->db);
2263 $objectreplaced->fetch(
$object->fk_facture_source);
2266 $pdf->SetXY($posx, $posy);
2267 $pdf->SetTextColor(0, 0, 60);
2268 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2272 $pdf->SetXY($posx, $posy);
2273 $pdf->SetTextColor(0, 0, 60);
2274 $title = $outputlangs->transnoentities(
"DateInvoice");
2275 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2276 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2278 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2282 $pdf->SetXY($posx, $posy);
2283 $pdf->SetTextColor(0, 0, 60);
2284 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2289 $pdf->SetXY($posx, $posy);
2290 $pdf->SetTextColor(0, 0, 60);
2291 $title = $outputlangs->transnoentities(
"DateDue");
2292 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2293 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2295 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2300 $pdf->SetXY($posx, $posy);
2301 $pdf->SetTextColor(0, 0, 60);
2302 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2307 $pdf->SetXY($posx, $posy);
2308 $pdf->SetTextColor(0, 0, 60);
2309 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2314 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2315 if (count($arrayidcontact) > 0) {
2316 $usertmp =
new User($this->db);
2317 $usertmp->fetch($arrayidcontact[0]);
2319 $pdf->SetXY($posx, $posy);
2320 $pdf->SetTextColor(0, 0, 60);
2321 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2330 $current_y = $pdf->getY();
2332 if ($current_y < $pdf->getY()) {
2333 $top_shift = $pdf->getY() - $current_y;
2339 $carac_emetteur =
'';
2341 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2342 if (count($arrayidcontact) > 0) {
2343 $object->fetch_user($arrayidcontact[0]);
2344 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2345 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2346 $carac_emetteur .=
"\n";
2353 $posy += $top_shift;
2354 $posx = $this->marge_gauche;
2356 $posx = $this->page_largeur - $this->marge_droite - 80;
2365 $pdf->SetTextColor(0, 0, 0);
2366 $pdf->SetFont(
'',
'', $default_font_size - 2);
2367 $pdf->SetXY($posx, $posy - 5);
2368 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2369 $pdf->SetXY($posx, $posy);
2370 $pdf->SetFillColor(230, 230, 230);
2371 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2372 $pdf->SetTextColor(0, 0, 60);
2377 $pdf->SetXY($posx + 2, $posy + 3);
2378 $pdf->SetFont(
'',
'B', $default_font_size);
2379 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2380 $posy = $pdf->getY();
2384 $pdf->SetXY($posx + 2, $posy);
2385 $pdf->SetFont(
'',
'', $default_font_size - 1);
2386 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2390 $usecontact =
false;
2391 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2392 if (count($arrayidcontact) > 0) {
2394 $result =
$object->fetch_contact($arrayidcontact[0]);
2398 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2399 $thirdparty =
$object->contact;
2401 $thirdparty =
$object->thirdparty;
2411 if ($this->page_largeur < 210) {
2415 $posy += $top_shift;
2416 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2418 $posx = $this->marge_gauche;
2423 $pdf->SetTextColor(0, 0, 0);
2424 $pdf->SetFont(
'',
'', $default_font_size - 2);
2425 $pdf->SetXY($posx + 2, $posy - 5);
2426 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2427 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2431 $pdf->SetXY($posx + 2, $posy + 3);
2432 $pdf->SetFont(
'',
'B', $default_font_size);
2434 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2436 $posy = $pdf->getY();
2439 $pdf->SetFont(
'',
'', $default_font_size - 1);
2440 $pdf->SetXY($posx + 2, $posy);
2442 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2446 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2448 if (!empty($idaddressshipping)) {
2449 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2450 $companystatic =
new Societe($this->db);
2451 $companystatic->fetch(
$object->contact->fk_soc);
2458 if (!empty($carac_client_shipping)) {
2459 $posy += $hautcadre;
2464 $pdf->SetXY($posx + 2, $posy - 5);
2465 $pdf->SetFont(
'',
'', $default_font_size - 2);
2466 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2467 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2470 $pdf->SetXY($posx + 2, $posy + 3);
2471 $pdf->SetFont(
'',
'B', $default_font_size);
2472 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2474 $posy = $pdf->getY();
2477 $pdf->SetXY($posx + 2, $posy);
2478 $pdf->SetFont(
'',
'', $default_font_size - 1);
2479 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2481 $top_shift += $hautcadre + 10;
2486 $pdf->SetTextColor(0, 0, 0);