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);
759 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent) &&
getDolGlobalInt(
'INVOICE_USE_SITUATION') != 2) {
761 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
763 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
767 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
769 $tvaligne = $sign *
$object->lines[$i]->total_tva;
773 $localtax1ligne =
$object->lines[$i]->total_localtax1;
774 $localtax2ligne =
$object->lines[$i]->total_localtax2;
775 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
776 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
777 $localtax1_type =
$object->lines[$i]->localtax1_type;
778 $localtax2_type =
$object->lines[$i]->localtax2_type;
780 $vatrate = (string)
$object->lines[$i]->tva_tx;
783 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
784 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
786 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
787 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
791 if ($localtax1_type && $localtax1ligne != 0) {
792 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
793 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
795 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
798 if ($localtax2_type && $localtax2ligne != 0) {
799 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
800 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
802 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
806 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
811 if (!isset($this->tva[$vatrate])) {
812 $this->tva[$vatrate] = 0;
814 $this->tva[$vatrate] += $tvaligne;
815 $vatcode =
$object->lines[$i]->vat_src_code;
817 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
818 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
820 $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);
822 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
823 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
825 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
828 if ($posYAfterImage > $posYAfterDescription) {
829 $nexY = $posYAfterImage;
834 $pdf->setPage($pageposafter);
835 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
837 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
838 $pdf->SetLineStyle(array(
'dash' => 0));
844 while ($pagenb < $pageposafter) {
845 $pdf->setPage($pagenb);
847 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
849 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
853 $pdf->setPage($pagenb);
854 $pdf->setPageOrientation(
'',
true, 0);
857 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
859 if (!empty($tplidx)) {
860 $pdf->useTemplate($tplidx);
863 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
865 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
867 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
872 if (!empty($tplidx)) {
873 $pdf->useTemplate($tplidx);
878 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
885 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
886 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
888 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
889 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
891 dol_syslog(
"bottomlasttab=".$bottomlasttab.
" this->page_hauteur=".$this->page_hauteur.
" heightforinfotot=".$heightforinfotot.
" heightforfreetext=".$heightforfreetext.
" heightforfooter=".$heightforfooter);
897 $posy = $this->
_tableau_tot($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
900 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
901 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
907 if (method_exists($pdf,
'AliasNbPages')) {
908 $pdf->AliasNbPages();
921 if (
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE') && $termsofsalefilename) {
922 $termsofsale = $conf->invoice->dir_output.
'/'.$termsofsalefilename;
923 if (!empty($conf->invoice->multidir_output[
$object->entity ?? $conf->entity])) {
924 $termsofsale = $conf->invoice->multidir_output[
$object->entity ?? $conf->entity].
'/'.$termsofsalefilename;
926 if (file_exists($termsofsale) && is_readable($termsofsale)) {
927 $pagecount = $pdf->setSourceFile($termsofsale);
928 for ($i = 1; $i <= $pagecount; $i++) {
929 $tplIdx = $pdf->importPage($i);
930 if ($tplIdx !==
false) {
931 $s = $pdf->getTemplatesize($tplIdx);
932 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
933 $pdf->useTemplate($tplIdx);
935 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
943 $pdf->Output($file,
'F');
946 $hookmanager->initHooks(array(
'pdfgeneration'));
947 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
949 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
950 $this->warnings = $hookmanager->warnings;
952 $this->error = $hookmanager->error;
953 $this->errors = $hookmanager->errors;
960 $this->result = array(
'fullpath' => $file);
964 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
968 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
995 $current_page = $pdf->getPage();
997 $tab3_top = $posy + 8;
1000 if ($this->page_largeur < 210) {
1010 $pdf->SetFont(
'',
'', $default_font_size - 4);
1014 $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,";
1015 $sql .=
" re.description, re.fk_facture_source,";
1016 $sql .=
" f.type, f.datef";
1017 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1018 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1019 $resql = $this->db->query($sql);
1021 $num = $this->db->num_rows($resql);
1023 $invoice =
new Facture($this->db);
1026 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1029 $pdf->AddPage(
'',
'',
true);
1035 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1037 $pdf->setPage($current_page);
1041 $obj = $this->db->fetch_object($resql);
1043 if ($obj->type == 2) {
1044 $text = $outputlangs->transnoentities(
"CreditNote");
1045 } elseif ($obj->type == 3) {
1046 $text = $outputlangs->transnoentities(
"Deposit");
1047 } elseif ($obj->type == 0) {
1048 $text = $outputlangs->transnoentities(
"ExcessReceived");
1050 $text = $outputlangs->transnoentities(
"UnknownType");
1053 $invoice->fetch($obj->fk_facture_source);
1055 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1056 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1057 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1058 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L',
false);
1059 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1060 $pdf->MultiCell(20, 3, $text, 0,
'L',
false);
1061 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1062 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L',
false);
1064 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1069 $this->error = $this->db->lasterror();
1075 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1077 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1078 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1079 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1081 $sql .=
" ORDER BY p.datep";
1083 $resql = $this->db->query($sql);
1085 $num = $this->db->num_rows($resql);
1090 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1093 $pdf->AddPage(
'',
'',
true);
1099 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1101 $pdf->setPage($current_page);
1105 $row = $this->db->fetch_object($resql);
1107 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1108 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L',
false);
1109 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1110 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L',
false);
1111 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1112 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1114 $pdf->MultiCell(20, 3, $oper, 0,
'L',
false);
1115 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1116 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1117 $pdf->MultiCell(30, 3, $row->num, 0,
'L',
false);
1118 $y = $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1119 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1124 return $tab3_top + $y + 3;
1126 $this->error = $this->db->lasterror();
1192 $pdf->SetFont(
'',
'', $default_font_size - 1);
1194 krsort($this->tva_array);
1201 $pdf->SetFillColor(224, 224, 224);
1203 $pdf->SetFont(
'',
'', $default_font_size - 2);
1204 $pdf->SetXY($this->marge_gauche, $posy);
1205 $titre = $outputlangs->transnoentities(
"VAT");
1206 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1208 $pdf->SetFont(
'',
'', $default_font_size - 2);
1209 $pdf->SetXY($this->marge_gauche + 25, $posy);
1210 $titre = $outputlangs->transnoentities(
"NetTotal");
1211 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1213 $pdf->SetFont(
'',
'', $default_font_size - 2);
1214 $pdf->SetXY($this->marge_gauche + 50, $posy);
1215 $titre = $outputlangs->transnoentities(
"VATAmount");
1216 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1218 $pdf->SetFont(
'',
'', $default_font_size - 2);
1219 $pdf->SetXY($this->marge_gauche + 75, $posy);
1220 $titre = $outputlangs->transnoentities(
"AmountTotal");
1221 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1223 $posy = $pdf->GetY();
1228 foreach ($this->tva_array as $tvakey => $tvaval) {
1229 $pdf->SetFont(
'',
'', $default_font_size - 2);
1230 $pdf->SetXY($this->marge_gauche, $posy);
1231 $titre = round((
float) $tvakey, 2) .
"%";
1232 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1234 $pdf->SetFont(
'',
'', $default_font_size - 2);
1235 $pdf->SetXY($this->marge_gauche + 25, $posy);
1236 $titre =
price($tvaval[
'tot_ht']);
1237 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1238 $tot_ht += $tvaval[
'tot_ht'];
1240 $pdf->SetFont(
'',
'', $default_font_size - 2);
1241 $pdf->SetXY($this->marge_gauche + 50, $posy);
1242 $titre =
price($tvaval[
'amount']);
1243 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1244 $tot_tva += $tvaval[
'amount'];
1246 $pdf->SetFont(
'',
'', $default_font_size - 2);
1247 $pdf->SetXY($this->marge_gauche + 75, $posy);
1248 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1249 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1250 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1252 $posy = $pdf->GetY();
1257 $showvatmention = 0;
1258 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1259 $pdf->SetFont(
'',
'', $default_font_size - 2);
1260 $pdf->SetXY($this->marge_gauche, $posy);
1261 if (empty(
$mysoc->tva_assuj)) {
1262 if (
$mysoc->forme_juridique_code == 92) {
1263 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L',
false);
1265 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L',
false);
1268 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1269 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L',
false);
1272 $posy = $pdf->GetY();
1275 $showvatmention +=
pdfCertifMention($pdf, $outputlangs, $this->emetteur, $default_font_size, $posy, $this);
1277 if ($showvatmention) {
1283 if ($this->page_largeur < 210) {
1290 $sql =
"SELECT f.rowid, f.datef, f.total_ttc";
1291 $sql.=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1292 $sql.=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1293 $sql.=
" AND f.entity IN (" .
getEntity(
'invoice') .
")";
1294 $sql.=
" AND f.datef <= '" . $this->db->idate(
$object->date) .
"'";
1295 $sql.=
" AND f.rowid < " . ((int)
$object->id);
1296 $sql.=
" AND f.fk_statut > 0";
1297 $sql.=
" ORDER BY f.datef ASC";
1300 $invoices = array();
1301 $resql = $this->db->query($sql);
1303 while ($obj = $this->db->fetch_object($resql)) {
1305 $old_balance += $obj->total_ttc;
1307 $this->db->free($resql);
1311 $sql_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1312 $sql_payments.=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1313 $sql_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1314 $sql_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1315 $sql_payments.=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1316 $sql_payments.=
" AND p.datep < '" . $this->db->idate(
$object->date) .
"'";
1317 $sql_payments.=
" ORDER BY p.datep ASC";
1319 $total_payments = 0;
1320 $resql_payments = $this->db->query($sql_payments);
1321 if ($resql_payments) {
1322 while ($obj_payment = $this->db->fetch_object($resql_payments)) {
1323 $total_payments += $obj_payment->amount;
1325 $this->db->free($resql_payments);
1329 $sql_current_date_payments =
"SELECT p.datep, pf.fk_facture, pf.amount";
1330 $sql_current_date_payments.=
" FROM " . MAIN_DB_PREFIX .
"paiement_facture as pf";
1331 $sql_current_date_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"paiement as p ON p.rowid = pf.fk_paiement";
1332 $sql_current_date_payments.=
" INNER JOIN " . MAIN_DB_PREFIX .
"facture as f ON f.rowid = pf.fk_facture";
1333 $sql_current_date_payments.=
" WHERE f.fk_soc = " . ((int)
$object->socid);
1334 $sql_current_date_payments.=
" AND DATE(p.datep) = DATE('" . $this->db->idate(
$object->date) .
"')";
1336 $current_date_payments = 0;
1337 $resql_current_date = $this->db->query($sql_current_date_payments);
1338 if ($resql_current_date) {
1339 while ($obj_current = $this->db->fetch_object($resql_current_date)) {
1340 $current_date_payments += $obj_current->amount;
1342 $this->db->free($resql_current_date);
1346 $old_balance -= $total_payments;
1349 $new_balance = $old_balance +
$object->total_ttc - $current_date_payments;
1351 $pdf->SetFillColor(224, 224, 224);
1352 $pdf->SetFont(
'',
'', $default_font_size - 2);
1353 $pdf->SetXY($this->marge_gauche, $posy);
1354 $titre = $outputlangs->transnoentities(
"PreviousBalance").
' : '.
price($old_balance);
1355 $pdf->MultiCell($posxval - $this->marge_gauche + 8, 4, $titre, 0,
'L',
true);
1357 $pdf->SetFont(
'',
'', $default_font_size - 2);
1358 $pdf->SetXY($posxval+8, $posy);
1359 $titre = $outputlangs->transnoentities(
"NewBalance").
' : '.
price($new_balance);
1360 $pdf->MultiCell($posxend - $posxval - 8, 4, $titre, 0,
'L',
true);
1362 $posy = $pdf->GetY() + 1;
1367 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1368 $pdf->SetXY($this->marge_gauche, $posy);
1369 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1370 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1372 $pdf->SetFont(
'',
'', $default_font_size - 2);
1373 $pdf->SetXY($posxval, $posy);
1374 $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);
1375 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1376 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1378 $posy = $pdf->GetY() + 3;
1382 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1383 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1384 $pdf->SetXY($this->marge_gauche, $posy);
1385 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1386 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1388 $pdf->SetFont(
'',
'', $default_font_size - 2);
1389 $pdf->SetXY($posxval, $posy);
1390 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1391 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1393 $posy = $pdf->GetY() + 3;
1398 if (empty(
$object->mode_reglement_code)
1401 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1405 $outputlangs->load(
"errors");
1407 $pdf->SetXY($this->marge_gauche, $posy);
1408 $pdf->SetTextColor(200, 0, 0);
1409 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1410 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1411 $pdf->MultiCell(80, 3, $this->error, 0,
'L',
false);
1412 $pdf->SetTextColor(0, 0, 0);
1414 $posy = $pdf->GetY() + 1;
1418 if (!empty(
$object->mode_reglement_code)
1419 &&
$object->mode_reglement_code !=
'CHQ'
1420 &&
$object->mode_reglement_code !=
'VIR') {
1421 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1422 $pdf->SetXY($this->marge_gauche, $posy);
1423 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1424 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1426 $pdf->SetFont(
'',
'', $default_font_size - 2);
1427 $pdf->SetXY($posxval, $posy);
1428 $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);
1430 if (
$object->mode_reglement_code ==
"PRE") {
1431 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1434 $bac->fetch(0,
'',
$object->thirdparty->id);
1435 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1436 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1438 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1440 $posy = $pdf->GetY();
1446 if ($this->emetteur->country_code ==
'FR') {
1448 $pdf->SetXY($this->marge_gauche, $posy);
1449 $pdf->writeHTMLCell(80, 5,
null,
null, $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1451 $posy = $pdf->GetY() + 1;
1456 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1457 $useonlinepayment = 0;
1461 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1462 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1463 $useonlinepayment = count($validpaymentmethod);
1467 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1470 $langs->loadLangs(array(
'payment',
'stripe'));
1471 $servicename = $langs->transnoentities(
'Online');
1473 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1474 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1476 $pdf->SetXY($this->marge_gauche, $posy);
1479 $posy = $pdf->GetY() + 1;
1484 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1490 $account =
new Account($this->db);
1493 $pdf->SetXY($this->marge_gauche, $posy);
1494 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1495 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L',
false);
1496 $posy = $pdf->GetY() + 1;
1499 $pdf->SetXY($this->marge_gauche, $posy);
1500 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1501 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L',
false);
1502 $posy = $pdf->GetY() + 2;
1506 $pdf->SetXY($this->marge_gauche, $posy);
1507 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1508 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L',
false);
1509 $posy = $pdf->GetY() + 1;
1512 $pdf->SetXY($this->marge_gauche, $posy);
1513 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1514 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L',
false);
1515 $posy = $pdf->GetY() + 2;
1522 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1528 $account =
new Account($this->db);
1529 $account->fetch((
int) $bankid);
1531 $curx = $this->marge_gauche;
1534 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1539 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1542 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L',
false);
1568 global $conf,
$mysoc, $hookmanager;
1577 $outputlangsbis =
null;
1579 $outputlangsbis =
new Translate(
'', $conf);
1581 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1582 $default_font_size--;
1587 $pdf->SetFont(
'',
'', $default_font_size - 1);
1592 if ($this->page_largeur < 210) {
1596 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1605 $total_discount_on_lines = 0;
1606 $multicurrency_total_discount_on_lines = 0;
1607 foreach (
$object->lines as $i => $line) {
1611 $total_discount_on_lines += (is_numeric($resdiscount) ? $resdiscount : 0);
1612 $multicurrency_total_discount_on_lines += (is_numeric($multicurrency_resdiscount) ? $multicurrency_resdiscount : 0);
1614 if ($line->total_ht < 0) {
1615 $total_discount_on_lines += -$line->total_ht;
1616 $multicurrency_total_discount_on_lines += -$line->multicurrency_total_ht;
1620 if ($total_discount_on_lines > 0 && !
$object->isSituationInvoice()) {
1622 $pdf->SetFillColor(255, 255, 255);
1623 $pdf->SetXY($col1x, $tab2_top);
1624 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L',
true);
1625 $pdf->SetXY($col2x, $tab2_top);
1627 $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));
1628 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_before_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1632 $pdf->SetFillColor(255, 255, 255);
1633 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1634 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L',
true);
1635 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1637 $total_discount_to_show = ((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $multicurrency_total_discount_on_lines : $total_discount_on_lines);
1638 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_discount_to_show, 0, $outputlangs), 0,
'R',
true);
1644 $pdf->SetFillColor(255, 255, 255);
1645 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1646 $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);
1649 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1650 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ht, 0, $outputlangs), 0,
'R',
true);
1654 $pdf->SetFillColor(255, 255, 255);
1655 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1656 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L',
true);
1658 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1659 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R',
true);
1663 $pdf->SetFillColor(248, 248, 248);
1667 $this->atleastoneratenotnull = 0;
1669 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1670 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1674 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1675 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1679 foreach ($localtax_rate as $tvakey => $tvaval) {
1680 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1684 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1687 if (preg_match(
'/\*/', (
string) $tvakey)) {
1688 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1689 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1692 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1",
$mysoc->country_code) :
'');
1696 $totalvat .= $tvacompl;
1698 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1701 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1705 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1706 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1712 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1713 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1717 foreach ($localtax_rate as $tvakey => $tvaval) {
1718 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1722 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1725 if (preg_match(
'/\*/', (
string) $tvakey)) {
1726 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1727 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1729 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2",
$mysoc->country_code) :
'');
1733 $totalvat .= $tvacompl;
1735 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1738 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1742 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1743 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1750 foreach ($this->tva_array as $tvakey => $tvaval) {
1752 $this->atleastoneratenotnull++;
1755 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1758 if (preg_match(
'/\*/', $tvakey)) {
1759 $tvakey = str_replace(
'*',
'', $tvakey);
1760 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1762 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT",
$mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT",
$mysoc->country_code) :
'');
1765 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).$tvacompl;
1767 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1769 $totalvat .= $tvacompl;
1771 $totalvat .=
vatrate((
string) $tvaval[
'vatrate'],
true).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1773 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1774 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1775 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R',
true);
1781 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1782 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1786 foreach ($localtax_rate as $tvakey => $tvaval) {
1787 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX1_LINE_IF_ZERO')) {
1791 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1794 if (preg_match(
'/\*/', (
string) $tvakey)) {
1795 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1796 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1798 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1",
$mysoc->country_code).
' ';
1801 $totalvat .= $tvacompl;
1803 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1806 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1810 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1811 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1817 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1818 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1822 foreach ($localtax_rate as $tvakey => $tvaval) {
1823 if ($tvakey != 0 ||
getDolGlobalString(
'INVOICE_SHOW_ALSO_LOCALTAX2_LINE_IF_ZERO')) {
1827 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1830 if (preg_match(
'/\*/', (
string) $tvakey)) {
1831 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1832 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1834 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2",
$mysoc->country_code).
' ';
1837 $totalvat .= $tvacompl;
1839 $totalvat .=
vatrate((
string) abs((
float) $tvakey),
true).$tvacompl;
1842 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L',
true);
1846 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1847 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R',
true);
1855 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1856 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp"), $useborder,
'L',
true);
1858 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1859 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R',
true);
1864 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1865 $pdf->SetTextColor(0, 0, 60);
1866 $pdf->SetFillColor(224, 224, 224);
1867 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L',
true);
1869 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1870 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R',
true);
1873 if (
$object->displayRetainedWarranty()) {
1874 $pdf->SetTextColor(40, 40, 40);
1875 $pdf->SetFillColor(255, 255, 255);
1877 $retainedWarranty =
$object->getRetainedWarrantyAmount();
1878 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
1882 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1883 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L',
true);
1885 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1886 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R',
true);
1890 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1892 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
1893 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
1895 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L',
true);
1896 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1897 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R',
true);
1902 $pdf->SetTextColor(0, 0, 0);
1903 $creditnoteamount =
$object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1906 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1911 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1914 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1915 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L',
false);
1916 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1917 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R',
false);
1920 if ($creditnoteamount) {
1921 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1923 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1924 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L',
false);
1925 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1926 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R',
false);
1930 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1932 $pdf->SetFillColor(255, 255, 255);
1934 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1935 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L',
true);
1936 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1937 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R',
true);
1943 $pdf->SetTextColor(0, 0, 60);
1944 $pdf->SetFillColor(224, 224, 224);
1945 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1946 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L',
true);
1947 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1948 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R',
true);
1950 $pdf->SetFont(
'',
'', $default_font_size - 1);
1951 $pdf->SetTextColor(0, 0, 0);
1959 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1960 $pdf->MultiCell($col2x - $col1x, $tab2_hl,
getDolGlobalString(
'BILL_TEXT_TOTAL_FOOTER'), 0,
'L',
false);
1963 return ($tab2_top + ($tab2_hl * $index));
1980 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1990 $currency = !empty($currency) ? $currency : $conf->currency;
1994 $pdf->SetTextColor(0, 0, 0);
1995 $pdf->SetFont(
'',
'', $default_font_size - 2);
1997 if (empty($hidetop)) {
1999 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2000 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
2001 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2002 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2005 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
2006 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2007 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2010 $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')));
2014 $pdf->SetDrawColor(128, 128, 128);
2015 $pdf->SetFont(
'',
'', $default_font_size - 1);
2018 $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');
2020 if (empty($hidetop)) {
2021 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
2023 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
2024 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
2028 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
2036 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
2037 if (empty($hidetop)) {
2038 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
2039 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
2043 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
2044 if (empty($hidetop)) {
2045 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
2046 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
2049 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
2050 if (empty($hidetop)) {
2051 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
2052 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
2056 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
2057 if (empty($hidetop)) {
2058 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
2059 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
2063 if ($this->atleastonediscount) {
2064 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
2065 if (empty($hidetop)) {
2066 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
2067 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
2071 if ($this->situationinvoice) {
2072 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
2073 if (empty($hidetop)) {
2074 $pdf->SetXY($this->posxprogress, $tab_top + 1);
2075 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities(
"ProgressShort"),
'',
'C');
2079 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
2080 if (empty($hidetop)) {
2081 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
2082 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
2097 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2100 global $conf, $langs;
2102 $ltrdirection =
'L';
2103 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2104 $ltrdirection =
'R';
2108 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2114 $pdf->SetTextColor(0, 0, 60);
2115 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2119 $posy = $this->marge_haute;
2120 $posx = $this->page_largeur - $this->marge_droite - $w;
2122 $pdf->SetXY($this->marge_gauche, $posy);
2126 if ($this->emetteur->logo) {
2127 $logodir = $conf->mycompany->dir_output;
2128 if (!empty($conf->mycompany->multidir_output[
$object->entity ?? $conf->entity])) {
2129 $logodir = $conf->mycompany->multidir_output[
$object->entity ?? $conf->entity];
2132 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2134 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2136 if (is_readable($logo)) {
2138 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2140 $pdf->SetTextColor(200, 0, 0);
2141 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2142 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2143 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2146 $text = $this->emetteur->name;
2147 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2151 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2152 $pdf->SetXY($posx, $posy);
2153 $pdf->SetTextColor(0, 0, 60);
2154 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2156 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2159 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2162 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2165 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2167 if ($this->situationinvoice) {
2168 $outputlangs->loadLangs(array(
"other"));
2169 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2171 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2174 if ($this->situationinvoice) {
2175 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2177 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2178 } elseif (
$object->type == 1) {
2179 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2180 } elseif (
$object->type == 2) {
2181 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2182 } elseif (
$object->type == 3) {
2183 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2184 } elseif (
$object->type == 4) {
2185 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2188 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2189 if (
$object->status == $object::STATUS_DRAFT) {
2190 $pdf->SetTextColor(128, 0, 0);
2191 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2194 $pdf->MultiCell($w, 3, $title,
'',
'R');
2196 $pdf->SetFont(
'',
'', $default_font_size - 2);
2213 $pdf->SetFont(
'',
'', $default_font_size - 2);
2217 $pdf->SetXY($posx, $posy);
2218 $pdf->SetTextColor(0, 0, 60);
2219 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset(
$object->ref_customer),
'',
'R');
2224 if (!empty(
$object->project->ref)) {
2226 $pdf->SetXY($posx, $posy);
2227 $pdf->SetTextColor(0, 0, 60);
2228 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2234 if (!empty(
$object->project->ref)) {
2235 $outputlangs->load(
"projects");
2237 $pdf->SetXY($posx, $posy);
2238 $pdf->SetTextColor(0, 0, 60);
2239 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2243 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2244 if (
$object->type == 0 && $objectidnext) {
2245 $objectreplacing =
new Facture($this->db);
2246 $objectreplacing->fetch($objectidnext);
2249 $pdf->SetXY($posx, $posy);
2250 $pdf->SetTextColor(0, 0, 60);
2251 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2254 $objectreplaced =
new Facture($this->db);
2255 $objectreplaced->fetch(
$object->fk_facture_source);
2258 $pdf->SetXY($posx, $posy);
2259 $pdf->SetTextColor(0, 0, 60);
2260 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2263 $objectreplaced =
new Facture($this->db);
2264 $objectreplaced->fetch(
$object->fk_facture_source);
2267 $pdf->SetXY($posx, $posy);
2268 $pdf->SetTextColor(0, 0, 60);
2269 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2273 $pdf->SetXY($posx, $posy);
2274 $pdf->SetTextColor(0, 0, 60);
2275 $title = $outputlangs->transnoentities(
"DateInvoice");
2276 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2277 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2279 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2283 $pdf->SetXY($posx, $posy);
2284 $pdf->SetTextColor(0, 0, 60);
2285 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2290 $pdf->SetXY($posx, $posy);
2291 $pdf->SetTextColor(0, 0, 60);
2292 $title = $outputlangs->transnoentities(
"DateDue");
2293 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2294 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2296 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2301 $pdf->SetXY($posx, $posy);
2302 $pdf->SetTextColor(0, 0, 60);
2303 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2308 $pdf->SetXY($posx, $posy);
2309 $pdf->SetTextColor(0, 0, 60);
2310 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2315 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2316 if (count($arrayidcontact) > 0) {
2317 $usertmp =
new User($this->db);
2318 $usertmp->fetch($arrayidcontact[0]);
2320 $pdf->SetXY($posx, $posy);
2321 $pdf->SetTextColor(0, 0, 60);
2322 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2331 $current_y = $pdf->getY();
2333 if ($current_y < $pdf->getY()) {
2334 $top_shift = $pdf->getY() - $current_y;
2340 $carac_emetteur =
'';
2342 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2343 if (count($arrayidcontact) > 0) {
2344 $object->fetch_user($arrayidcontact[0]);
2345 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2346 $carac_emetteur .= $labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2347 $carac_emetteur .=
"\n";
2354 $posy += $top_shift;
2355 $posx = $this->marge_gauche;
2357 $posx = $this->page_largeur - $this->marge_droite - 80;
2366 $pdf->SetTextColor(0, 0, 0);
2367 $pdf->SetFont(
'',
'', $default_font_size - 2);
2368 $pdf->SetXY($posx, $posy - 5);
2369 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2370 $pdf->SetXY($posx, $posy);
2371 $pdf->SetFillColor(230, 230, 230);
2372 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2373 $pdf->SetTextColor(0, 0, 60);
2378 $pdf->SetXY($posx + 2, $posy + 3);
2379 $pdf->SetFont(
'',
'B', $default_font_size);
2380 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2381 $posy = $pdf->getY();
2385 $pdf->SetXY($posx + 2, $posy);
2386 $pdf->SetFont(
'',
'', $default_font_size - 1);
2387 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2391 $usecontact =
false;
2392 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2393 if (count($arrayidcontact) > 0) {
2395 $result =
$object->fetch_contact($arrayidcontact[0]);
2399 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2400 $thirdparty =
$object->contact;
2402 $thirdparty =
$object->thirdparty;
2412 if ($this->page_largeur < 210) {
2416 $posy += $top_shift;
2417 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2419 $posx = $this->marge_gauche;
2424 $pdf->SetTextColor(0, 0, 0);
2425 $pdf->SetFont(
'',
'', $default_font_size - 2);
2426 $pdf->SetXY($posx + 2, $posy - 5);
2427 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2428 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2432 $pdf->SetXY($posx + 2, $posy + 3);
2433 $pdf->SetFont(
'',
'B', $default_font_size);
2435 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2437 $posy = $pdf->getY();
2440 $pdf->SetFont(
'',
'', $default_font_size - 1);
2441 $pdf->SetXY($posx + 2, $posy);
2443 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2447 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2449 if (!empty($idaddressshipping)) {
2450 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2451 $companystatic =
new Societe($this->db);
2452 $companystatic->fetch(
$object->contact->fk_soc);
2459 if (!empty($carac_client_shipping)) {
2460 $posy += $hautcadre;
2465 $pdf->SetXY($posx + 2, $posy - 5);
2466 $pdf->SetFont(
'',
'', $default_font_size - 2);
2467 $pdf->MultiCell($widthrecbox, 0, $outputlangs->transnoentities(
'ShippingTo'), 0,
'L',
false);
2468 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2471 $pdf->SetXY($posx + 2, $posy + 3);
2472 $pdf->SetFont(
'',
'B', $default_font_size);
2473 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2475 $posy = $pdf->getY();
2478 $pdf->SetXY($posx + 2, $posy);
2479 $pdf->SetFont(
'',
'', $default_font_size - 1);
2480 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2482 $top_shift += $hautcadre + 10;
2487 $pdf->SetTextColor(0, 0, 0);