204 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
207 global $user, $langs,
$conf, $mysoc, $db, $hookmanager, $nblines;
209 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
211 if (!is_object($outputlangs)) {
212 $outputlangs = $langs;
216 $outputlangs->charset_output =
'ISO-8859-1';
220 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
222 global $outputlangsbis;
223 $outputlangsbis =
null;
227 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies",
"compta"));
235 $nblines = count(
$object->lines);
243 $realpatharray = array();
244 $this->atleastonephoto =
false;
246 $objphoto =
new Product($this->db);
248 for ($i = 0; $i < $nblines; $i++) {
249 if (empty(
$object->lines[$i]->fk_product)) {
253 $objphoto->fetch(
$object->lines[$i]->fk_product);
257 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
258 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
260 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
261 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
265 foreach ($pdir as $midir) {
267 if (
$conf->entity != $objphoto->entity) {
268 $dir =
$conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
270 $dir =
$conf->product->dir_output.
'/'.$midir;
273 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
275 if ($obj[
'photo_vignette']) {
276 $filename = $obj[
'photo_vignette'];
278 $filename = $obj[
'photo'];
281 $filename = $obj[
'photo'];
284 $realpath = $dir.$filename;
286 $this->atleastonephoto =
true;
291 if ($realpath && $arephoto) {
292 $realpatharray[$i] = $realpath;
299 if (
$conf->facture->multidir_output[
$conf->entity]) {
302 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
303 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
304 $amount_deposits_included =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
308 $dir =
$conf->facture->multidir_output[
$conf->entity];
309 $file = $dir.
"/SPECIMEN.pdf";
312 $dir =
$conf->facture->multidir_output[
$object->entity].
"/".$objectref;
313 $file = $dir.
"/".$objectref.
".pdf";
315 if (!file_exists($dir)) {
317 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
322 if (file_exists($dir)) {
324 if (!is_object($hookmanager)) {
325 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
328 $hookmanager->initHooks(array(
'pdfgeneration'));
329 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
331 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
334 $nblines = count(
$object->lines);
335 $nbpayments = count(
$object->getListOfPayments());
340 $pdf->SetAutoPageBreak(1, 0);
342 $this->heightforinfotot = 50 + (4 * $nbpayments);
343 $this->heightforfreetext =
getDolGlobalInt(
'MAIN_PDF_FREETEXT_HEIGHT', 5);
344 $this->heightforfooter = $this->marge_basse + (!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22);
346 $heightforqrinvoice = 0;
350 $this->heightforinfotot = 30 + (4 * $nbpayments);
354 if (class_exists(
'TCPDF')) {
355 $pdf->setPrintHeader(
false);
356 $pdf->setPrintFooter(
false);
362 $logodir =
$conf->mycompany->dir_output;
363 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
364 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
366 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
367 $tplidx = $pdf->importPage(1);
372 $pdf->SetDrawColor(128, 128, 128);
374 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
375 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
376 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
377 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
378 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
380 $pdf->SetCompression(
false);
384 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
385 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
396 'Name' => $this->emetteur->name,
397 'Location' =>
getCountry($this->emetteur->country_code,
''),
398 'Reason' =>
'INVOICE',
399 'ContactInfo' => $this->emetteur->email
401 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
405 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
409 $categoryOfOperation = 0;
412 for ($i = 0; $i < $nblines; $i++) {
413 if (
$object->lines[$i]->remise_percent) {
414 $this->atleastonediscount++;
419 if (preg_match(
'/^\((.*)\)$/',
$object->lines[$i]->desc, $reg)) {
420 if ($reg[1] ==
'DEPOSIT') {
431 if ($categoryOfOperation < 2) {
432 $lineProductType =
$object->lines[$i]->product_type;
438 if ($nbProduct > 0 && $nbService > 0) {
440 $categoryOfOperation = 2;
445 if ($categoryOfOperation <= 0) {
447 if ($nbProduct == 0 && $nbService > 0) {
448 $categoryOfOperation = 1;
451 $this->categoryOfOperation = $categoryOfOperation;
454 if (
$object->situation_cycle_ref) {
455 $this->situationinvoice =
true;
460 if (!empty($tplidx)) {
461 $pdf->useTemplate($tplidx);
466 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
467 $top_shift = $pagehead[
'top_shift'];
468 $shipp_shift = $pagehead[
'shipp_shift'];
469 $pdf->SetFont(
'',
'', $default_font_size - 1);
470 $pdf->MultiCell(0, 3,
'');
471 $pdf->SetTextColor(0, 0, 0);
476 $this->tab_top = 90 + $top_shift + $shipp_shift;
477 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
480 $extra_under_address_shift = 0;
483 $qrcodestring =
$object->buildZATCAQRString();
486 $qrcodestring =
$object->buildSwitzerlandQRString();
490 $qrcodestring =
$object->buildEPCQrCodeString();
495 $qrcodecolor = array(
'25',
'25',
'25');
500 'fgcolor' => $qrcodecolor,
505 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
509 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
510 $pdf->SetFont(
'',
'', $default_font_size - 4);
511 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L', 0);
515 $extra_under_address_shift += 25;
523 'outputlangs' => $outputlangs,
524 'hidedetails' => $hidedetails
526 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
527 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
528 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
531 $this->tab_top += $extra_under_address_shift;
532 $this->tab_top_newpage += 0;
536 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
538 $nexY = $this->tab_top - 1;
541 $height_incoterms = 0;
542 if (isModEnabled(
'incoterm')) {
543 $desc_incoterms =
$object->getIncotermsForPDF();
544 if ($desc_incoterms) {
547 $pdf->SetFont(
'',
'', $default_font_size - 1);
548 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
549 $nexY = max($pdf->GetY(), $nexY);
550 $height_incoterms = $nexY - $this->tab_top;
553 $pdf->SetDrawColor(192, 192, 192);
554 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
556 $this->tab_top = $nexY + 6;
557 $height_incoterms += 4;
562 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
565 if (is_object(
$object->thirdparty)) {
566 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
567 $salerepobj =
new User($this->db);
568 $salerepobj->fetch($salereparray[0][
'id']);
569 if (!empty($salerepobj->signature)) {
570 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
576 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
577 if (!empty($extranote)) {
581 $pagenb = $pdf->getPage();
585 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
586 $pageposbeforenote = $pagenb;
593 $pdf->startTransaction();
595 $pdf->SetFont(
'',
'', $default_font_size - 1);
596 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
598 $pageposafternote = $pdf->getPage();
599 $posyafter = $pdf->GetY();
601 if ($pageposafternote > $pageposbeforenote) {
602 $pdf->rollbackTransaction(
true);
605 while ($pagenb < $pageposafternote) {
608 if (!empty($tplidx)) {
609 $pdf->useTemplate($tplidx);
614 $pdf->setTopMargin($this->tab_top_newpage);
616 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
620 $pdf->setPage($pageposbeforenote);
621 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
622 $pdf->SetFont(
'',
'', $default_font_size - 1);
623 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
624 $pageposafternote = $pdf->getPage();
626 $posyafter = $pdf->GetY();
628 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
629 $pdf->AddPage(
'',
'',
true);
632 $pdf->setPage($pageposafternote);
633 $pdf->setTopMargin($this->tab_top_newpage);
635 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
641 $i = $pageposbeforenote;
642 while ($i < $pageposafternote) {
646 $pdf->SetDrawColor(128, 128, 128);
648 if ($i > $pageposbeforenote) {
649 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
650 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
652 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
653 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
657 $pdf->setPageOrientation(
'', 1, 0);
664 $pdf->setPage($pageposafternote);
665 if (!empty($tplidx)) {
666 $pdf->useTemplate($tplidx);
671 $height_note = $posyafter - $this->tab_top_newpage;
672 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
675 $pdf->commitTransaction();
676 $posyafter = $pdf->GetY();
677 $height_note = $posyafter - $this->tab_top;
678 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
681 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
683 $pdf->AddPage(
'',
'',
true);
686 $pdf->setPage($pageposafternote);
687 if (!empty($tplidx)) {
688 $pdf->useTemplate($tplidx);
694 $posyafter = $this->tab_top_newpage;
698 $tab_height -= $height_note;
699 $this->tab_top = $posyafter + 6;
708 $pdf->startTransaction();
709 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
710 $pdf->rollbackTransaction(
true);
712 $nexY = $this->tab_top + $this->tabTitleHeight;
715 $pageposbeforeprintlines = $pdf->getPage();
716 $pagenb = $pageposbeforeprintlines;
717 for ($i = 0; $i < $nblines; $i++) {
718 $linePosition = $i + 1;
722 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
725 if (!empty($tplidx)) {
726 $pdf->useTemplate($tplidx);
729 $pdf->setPage($pdf->getNumPages());
730 $nexY = $this->tab_top_newpage;
735 $pdf->SetFont(
'',
'', $default_font_size - 1);
736 $pdf->SetTextColor(0, 0, 0);
739 $imglinesize = array();
740 if (!empty($realpatharray[$i])) {
744 $pdf->setTopMargin($this->tab_top_newpage);
745 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
746 $pageposbefore = $pdf->getPage();
750 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
755 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
756 $pdf->AddPage(
'',
'',
true);
757 if (!empty($tplidx)) {
758 $pdf->useTemplate($tplidx);
760 $pdf->setPage($pageposbefore + 1);
761 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
762 $curY = $this->tab_top_newpage;
763 $showpricebeforepagebreak = 0;
766 $pdf->setPageOrientation(
'', 0, $this->heightforfooter + $this->heightforfreetext);
767 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
768 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
770 $posYAfterImage = $curY + $imglinesize[
'height'];
777 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
787 $pdf->setPage($pageposbefore);
788 $pdf->setTopMargin($this->marge_haute);
790 $pdf->setPageOrientation(
'', 0, $this->heightforfooter);
793 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
794 $pdf->setPage($afterPosData[
'page']);
795 $curY = $this->tab_top_newpage;
798 $pdf->SetFont(
'',
'', $default_font_size - 1);
855 if (!empty(
$object->lines[$i]->array_options)) {
856 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
872 'nexY' => & $afterPosData[
'y'],
873 'outputlangs' => $outputlangs,
874 'hidedetails' => $hidedetails
876 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
884 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
885 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
886 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
887 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
889 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
892 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
893 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
895 $tvaligne = $sign *
$object->lines[$i]->total_tva;
899 $localtax1ligne =
$object->lines[$i]->total_localtax1;
900 $localtax2ligne =
$object->lines[$i]->total_localtax2;
901 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
902 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
903 $localtax1_type =
$object->lines[$i]->localtax1_type;
904 $localtax2_type =
$object->lines[$i]->localtax2_type;
917 $vatrate = (string)
$object->lines[$i]->tva_tx;
920 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
921 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
923 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
924 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
928 if ($localtax1_type && $localtax1ligne != 0) {
929 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
930 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
932 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
935 if ($localtax2_type && $localtax2ligne != 0) {
936 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
937 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
939 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
943 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
948 if (!isset($this->tva[$vatrate])) {
949 $this->tva[$vatrate] = 0;
951 $this->tva[$vatrate] += $tvaligne;
952 $vatcode =
$object->lines[$i]->vat_src_code;
954 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
955 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
957 $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);
959 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
960 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
962 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
966 $pdf->setPage($afterPosData[
'page']);
967 $nexY = $afterPosData[
'y'];
970 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
971 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
973 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
974 $pdf->SetLineStyle(array(
'dash' => 0));
982 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
984 if (isset($afterPosData[
'y']) && $afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
986 if (!empty($tplidx)) {
987 $pdf->useTemplate($tplidx);
990 $pdf->setPage($pagenb);
994 $drawTabNumbPage = $pdf->getNumPages();
995 for ($i=$pageposbeforeprintlines; $i<=$drawTabNumbPage; $i++) {
998 $pdf->setPageOrientation(
'', 0, 0);
1000 $drawTabHideTop = $hidetop;
1001 $drawTabTop = $this->tab_top_newpage;
1002 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;
1005 if ($i == $pageposbeforeprintlines) {
1007 $drawTabTop = $this->tab_top;
1008 } elseif (!$drawTabHideTop) {
1010 $drawTabTop-= $this->tabTitleHeight;
1012 $drawTabHideTop = 1;
1017 if ($i == $pdf->getNumPages()) {
1019 $drawTabBottom-= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1022 $drawTabHeight = $drawTabBottom - $drawTabTop;
1023 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
1025 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1032 $pdf->setPageOrientation(
'', 1, 0);
1035 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1038 if (!empty($tplidx)) {
1039 $pdf->useTemplate($tplidx);
1045 $pdf->SetTextColor(0, 0, 0);
1047 $pdf->setPage($pdf->getNumPages());
1049 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1055 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1058 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1059 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1064 if (method_exists($pdf,
'AliasNbPages')) {
1065 $pdf->AliasNbPages();
1068 if (!empty($mysoc->termsofsale) &&
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) {
1069 $termsofsale =
$conf->mycompany->dir_output.
'/'.$mysoc->termsofsale;
1070 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
1071 $termsofsale =
$conf->mycompany->multidir_output[
$object->entity].
'/'.$mysoc->termsofsale;
1073 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1074 $pagecount = $pdf->setSourceFile($termsofsale);
1075 for ($i = 1; $i <= $pagecount; $i++) {
1076 $tplIdx = $pdf->importPage($i);
1077 if ($tplIdx!==
false) {
1078 $s = $pdf->getTemplatesize($tplIdx);
1079 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1080 $pdf->useTemplate($tplIdx);
1082 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1094 $pdf->Output($file,
'F');
1097 $hookmanager->initHooks(array(
'pdfgeneration'));
1098 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1100 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1102 $this->error = $hookmanager->error;
1103 $this->errors = $hookmanager->errors;
1108 $this->result = array(
'fullpath' => $file);
1112 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1116 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1139 $tab3_top = $posy + 8;
1142 if ($this->page_largeur < 210) {
1148 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1150 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1153 $pdf->SetFont(
'',
'', $default_font_size - 3);
1154 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1155 $pdf->MultiCell(60, 3, $title, 0,
'L', 0);
1157 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1159 $pdf->SetFont(
'',
'', $default_font_size - 4);
1160 $pdf->SetXY($tab3_posx, $tab3_top);
1161 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
1162 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1163 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
1164 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1165 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
1166 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1167 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
1169 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1173 $pdf->SetFont(
'',
'', $default_font_size - 4);
1177 $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,";
1178 $sql .=
" re.description, re.fk_facture_source,";
1179 $sql .=
" f.type, f.datef";
1180 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1181 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1182 $resql = $this->db->query($sql);
1184 $num = $this->db->num_rows($resql);
1186 $invoice =
new Facture($this->db);
1189 $obj = $this->db->fetch_object($resql);
1191 if ($obj->type == 2) {
1192 $text = $outputlangs->transnoentities(
"CreditNote");
1193 } elseif ($obj->type == 3) {
1194 $text = $outputlangs->transnoentities(
"Deposit");
1195 } elseif ($obj->type == 0) {
1196 $text = $outputlangs->transnoentities(
"ExcessReceived");
1198 $text = $outputlangs->transnoentities(
"UnknownType");
1201 $invoice->fetch($obj->fk_facture_source);
1203 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1204 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1205 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1206 $pdf->MultiCell(20, 3,
price((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1207 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1208 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1209 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1210 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1212 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1217 $this->error = $this->db->lasterror();
1223 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1226 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1227 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1229 $sql .=
" ORDER BY p.datep";
1231 $resql = $this->db->query($sql);
1233 $num = $this->db->num_rows($resql);
1238 $row = $this->db->fetch_object($resql);
1239 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1240 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1241 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1242 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1243 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1244 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1246 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1247 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1248 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1249 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1250 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1251 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1256 return $tab3_top + $y + 3;
1258 $this->error = $this->db->lasterror();
1276 global
$conf, $mysoc, $hookmanager;
1280 $pdf->SetFont(
'',
'', $default_font_size - 1);
1282 krsort($this->tva_array);
1289 $pdf->SetFillColor(224, 224, 224);
1291 $pdf->SetFont(
'',
'', $default_font_size - 2);
1292 $pdf->SetXY($this->marge_gauche, $posy);
1293 $titre = $outputlangs->transnoentities(
"VAT");
1294 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1296 $pdf->SetFont(
'',
'', $default_font_size - 2);
1297 $pdf->SetXY($this->marge_gauche + 25, $posy);
1298 $titre = $outputlangs->transnoentities(
"NetTotal");
1299 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1301 $pdf->SetFont(
'',
'', $default_font_size - 2);
1302 $pdf->SetXY($this->marge_gauche + 50, $posy);
1303 $titre = $outputlangs->transnoentities(
"VATAmount");
1304 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1306 $pdf->SetFont(
'',
'', $default_font_size - 2);
1307 $pdf->SetXY($this->marge_gauche + 75, $posy);
1308 $titre = $outputlangs->transnoentities(
"AmountTotal");
1309 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1311 $posy = $pdf->GetY();
1316 foreach ($this->tva_array as $tvakey => $tvaval) {
1317 $pdf->SetFont(
'',
'', $default_font_size - 2);
1318 $pdf->SetXY($this->marge_gauche, $posy);
1319 $titre = round((
float) $tvakey, 2) .
"%";
1320 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1322 $pdf->SetFont(
'',
'', $default_font_size - 2);
1323 $pdf->SetXY($this->marge_gauche + 25, $posy);
1324 $titre =
price($tvaval[
'tot_ht']);
1325 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1326 $tot_ht += $tvaval[
'tot_ht'];
1328 $pdf->SetFont(
'',
'', $default_font_size - 2);
1329 $pdf->SetXY($this->marge_gauche + 50, $posy);
1330 $titre =
price($tvaval[
'amount']);
1331 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1332 $tot_tva += $tvaval[
'amount'];
1334 $pdf->SetFont(
'',
'', $default_font_size - 2);
1335 $pdf->SetXY($this->marge_gauche + 75, $posy);
1336 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1337 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1338 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1340 $posy = $pdf->GetY();
1345 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1346 $pdf->SetFont(
'',
'', $default_font_size - 2);
1347 $pdf->SetXY($this->marge_gauche, $posy);
1348 if (empty($mysoc->tva_assuj)) {
1349 if ($mysoc->forme_juridique_code == 92) {
1350 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1352 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1354 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1355 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L', 0);
1357 $posy = $pdf->GetY() + 4;
1362 if ($this->page_largeur < 210) {
1368 $pdf->SetFont(
'',
'', $default_font_size - 2);
1369 $pdf->SetXY($this->marge_gauche, $posy);
1370 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1371 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1373 $pdf->SetFont(
'',
'', $default_font_size - 2);
1374 $pdf->SetXY($posxval, $posy);
1375 $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);
1376 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1377 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1379 $posy = $pdf->GetY() + 3;
1383 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1384 $pdf->SetFont(
'',
'', $default_font_size - 2);
1385 $pdf->SetXY($this->marge_gauche, $posy);
1386 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1387 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1389 $pdf->SetFont(
'',
'', $default_font_size - 2);
1390 $pdf->SetXY($posxval, $posy);
1391 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1392 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1394 $posy = $pdf->GetY() + 3;
1399 if (empty(
$object->mode_reglement_code)
1402 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1406 $outputlangs->load(
"errors");
1408 $pdf->SetXY($this->marge_gauche, $posy);
1409 $pdf->SetTextColor(200, 0, 0);
1410 $pdf->SetFont(
'',
'', $default_font_size - 2);
1411 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1412 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L', 0);
1413 $pdf->SetTextColor(0, 0, 0);
1415 $posy = $pdf->GetY() + 1;
1419 if (!empty(
$object->mode_reglement_code)
1420 &&
$object->mode_reglement_code !=
'CHQ'
1421 &&
$object->mode_reglement_code !=
'VIR') {
1422 $pdf->SetFont(
'',
'', $default_font_size - 2);
1423 $pdf->SetXY($this->marge_gauche, $posy);
1424 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1425 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1427 $pdf->SetFont(
'',
'', $default_font_size - 2);
1428 $pdf->SetXY($posxval, $posy);
1429 $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);
1432 if (
$object->mode_reglement_code ==
"PRE") {
1433 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1436 $bac->fetch(0,
'',
$object->thirdparty->id);
1437 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1438 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1441 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1443 $posy = $pdf->GetY();
1449 if ($this->emetteur->country_code ==
'FR') {
1451 $pdf->SetXY($this->marge_gauche, $posy);
1452 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1454 $posy = $pdf->GetY() + 1;
1459 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1460 $useonlinepayment = 0;
1464 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1465 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1466 $useonlinepayment = count($validpaymentmethod);
1471 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1474 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1475 $servicename = $langs->transnoentities(
'Online');
1476 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1477 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1479 $pdf->SetXY($this->marge_gauche, $posy);
1480 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
'',
'',
dol_htmlentitiesbr($linktopay), 0, 1);
1482 $posy = $pdf->GetY() + 1;
1487 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1493 $account =
new Account($this->db);
1496 $pdf->SetXY($this->marge_gauche, $posy);
1497 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1498 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L', 0);
1499 $posy = $pdf->GetY() + 1;
1502 $pdf->SetXY($this->marge_gauche, $posy);
1503 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1504 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1505 $posy = $pdf->GetY() + 2;
1509 $pdf->SetXY($this->marge_gauche, $posy);
1510 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1511 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1512 $posy = $pdf->GetY() + 1;
1515 $pdf->SetXY($this->marge_gauche, $posy);
1516 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1517 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1518 $posy = $pdf->GetY() + 2;
1525 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1531 $account =
new Account($this->db);
1532 $account->fetch($bankid);
1534 $curx = $this->marge_gauche;
1537 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1545 $qrCodeColor = array(
'25',
'25',
'25');
1549 'fgcolor' => $qrCodeColor,
1551 'module_width' => 1,
1552 'module_height' => 1
1555 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1556 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr,
'N');
1558 $pdf->SetXY($qrPosX + 30, $posy + 5);
1559 $pdf->SetFont(
'',
'', $default_font_size - 5);
1560 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L', 0);
1561 $posy = $pdf->GetY() + 2;
1566 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1569 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L', 0);
1592 global $mysoc, $hookmanager;
1603 if (is_object($outputlangsbis)) {
1604 $pdf->SetFont(
'',
'', $default_font_size - 2);
1606 $pdf->SetFont(
'',
'', $default_font_size - 1);
1612 if ($this->page_largeur < 210) {
1616 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1622 $parameters = array(
1624 'outputlangs' => $outputlangs,
1626 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1631 foreach (
$object->lines as $line) {
1632 if ($line->product_type != 9) {
1633 $percent += $line->situation_percent;
1639 $avancementGlobal = $percent / $i;
1641 $avancementGlobal = 0;
1644 $object->fetchPreviousNextSituationInvoice();
1645 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1648 $total_a_payer_ttc = 0;
1649 foreach ($TPreviousIncoice as &$fac) {
1650 $total_a_payer += $fac->total_ht;
1651 $total_a_payer_ttc += $fac->total_ttc;
1653 $total_a_payer +=
$object->total_ht;
1654 $total_a_payer_ttc +=
$object->total_ttc;
1656 if (!empty($avancementGlobal)) {
1657 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1658 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1661 $total_a_payer_ttc = 0;
1665 if (!empty($TPreviousIncoice)) {
1666 $pdf->setY($tab2_top);
1667 $posy = $pdf->GetY();
1669 foreach ($TPreviousIncoice as &$fac) {
1670 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1675 $pdf->setY($this->tab_top_newpage);
1677 $pdf->setY($this->marge_haute);
1679 $posy = $pdf->GetY();
1684 $pdf->SetFillColor(255, 255, 255);
1685 $pdf->SetXY($col1x, $posy);
1686 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1688 $pdf->SetXY($col2x, $posy);
1692 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1695 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1697 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1706 $pdf->SetFillColor(255, 255, 255);
1707 $pdf->SetXY($col1x, $posy);
1708 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle",
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1710 $pdf->SetXY($col2x, $posy);
1713 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1721 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1722 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1727 $pdf->SetFont(
'',
'', $default_font_size - 1);
1728 $pdf->SetFillColor(255, 255, 255);
1729 $pdf->SetXY($col1x, $posy);
1730 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", $avancementGlobal), 0,
'L', 1);
1732 $pdf->SetXY($col2x, $posy);
1733 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R', 1);
1734 $pdf->SetFont(
'',
'', $default_font_size - 2);
1738 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1742 $pdf->setY($this->tab_top_newpage);
1744 $pdf->setY($this->marge_haute);
1747 $posy = $pdf->GetY();
1758 $total_ht = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1 ?
$object->multicurrency_total_ht :
$object->total_ht);
1761 $total_line_remise_print = $total_line_remise = 0;
1762 foreach (
$object->lines as $i => $line) {
1764 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1766 if ($line->total_ht < 0) {
1767 $total_line_remise += -$line->total_ht;
1769 $usemc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1);
1770 $total_line_remise_print = $total_line_remise;
1772 $ratio = (!empty(
$object->total_ht) ? (float)
$object->multicurrency_total_ht / (
float)
$object->total_ht : 0);
1773 if (!empty($ratio)) $total_line_remise_print =
price2num($total_line_remise * $ratio,
'MT');
1776 if ($total_line_remise > 0) {
1778 $pdf->SetFillColor(255, 255, 255);
1779 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1780 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L', 1);
1781 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1782 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise_print, 0, $outputlangs), 0,
'R', 1);
1787 $pdf->SetFillColor(255, 255, 255);
1788 $pdf->SetXY($col1x, $tab2_top);
1789 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L', 1);
1790 $pdf->SetXY($col2x, $tab2_top);
1791 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise_print + $total_ht, 0, $outputlangs), 0,
'R', 1);
1797 $pdf->SetFillColor(255, 255, 255);
1798 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1799 $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', 1);
1801 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
1802 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1803 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1807 $pdf->SetFillColor(255, 255, 255);
1808 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1809 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L', 1);
1811 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1812 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R', 1);
1816 $pdf->SetFillColor(248, 248, 248);
1818 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
1820 $this->atleastoneratenotnull = 0;
1822 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1823 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1827 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1828 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1832 foreach ($localtax_rate as $tvakey => $tvaval) {
1837 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1840 if (preg_match(
'/\*/', (
string) $tvakey)) {
1841 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1842 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1845 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1849 $totalvat .= $tvacompl;
1851 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1854 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1856 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1858 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1859 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1865 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1866 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1870 foreach ($localtax_rate as $tvakey => $tvaval) {
1875 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1878 if (preg_match(
'/\*/', (
string) $tvakey)) {
1879 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1880 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1882 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1886 $totalvat .= $tvacompl;
1888 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1891 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1893 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1895 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1896 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1904 foreach ($this->tva as $tvakey => $tvaval) {
1905 $sum_pdf_tva += $tvaval;
1908 if ($sum_pdf_tva !=
$object->total_tva) {
1909 if (!empty($sum_pdf_tva)) {
1910 $coef_fix_tva =
$object->total_tva / $sum_pdf_tva;
1916 foreach ($this->tva as $tvakey => $tvaval) {
1917 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1919 foreach ($this->tva_array as $tvakey => $tvaval) {
1920 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1927 foreach ($this->tva_array as $tvakey => $tvaval) {
1929 $this->atleastoneratenotnull++;
1932 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1935 if (preg_match(
'/\*/', $tvakey)) {
1936 $tvakey = str_replace(
'*',
'', $tvakey);
1937 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1939 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1942 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1944 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1946 $totalvat .= $tvacompl;
1948 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1950 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1952 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1953 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1959 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1960 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1964 foreach ($localtax_rate as $tvakey => $tvaval) {
1969 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1972 if (preg_match(
'/\*/', (
string) $tvakey)) {
1973 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1974 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1976 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1980 $totalvat .= $tvacompl;
1982 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1985 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1987 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1989 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1990 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1996 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1997 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
2001 foreach ($localtax_rate as $tvakey => $tvaval) {
2007 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2010 if (preg_match(
'/\*/', (
string) $tvakey)) {
2011 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
2012 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
2014 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
2018 $totalvat .= $tvacompl;
2020 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
2023 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
2025 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
2027 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2028 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
2036 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2037 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L', 1);
2039 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2040 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R', 1);
2045 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2046 $pdf->SetTextColor(0, 0, 60);
2047 $pdf->SetFillColor(224, 224, 224);
2048 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
2050 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2051 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
2055 if (
$object->displayRetainedWarranty()) {
2056 $pdf->SetTextColor(40, 40, 40);
2057 $pdf->SetFillColor(255, 255, 255);
2059 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2060 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2064 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2065 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L', 1);
2067 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2068 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
2072 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2074 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2075 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2077 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
2078 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2079 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
2084 $pdf->SetTextColor(0, 0, 0);
2086 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2087 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2089 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2094 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
2097 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2098 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L', 0);
2099 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2100 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
2103 if ($creditnoteamount) {
2104 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
2105 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.(($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes"))) :
'');
2107 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2108 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
2109 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2110 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
2113 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2115 $pdf->SetFillColor(255, 255, 255);
2117 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2118 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"EscompteOfferedShort") :
''), $useborder,
'L', 1);
2119 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2120 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT'), 0, $outputlangs), $useborder,
'R', 1);
2126 $pdf->SetTextColor(0, 0, 60);
2127 $pdf->SetFillColor(224, 224, 224);
2128 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2129 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
2130 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2131 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
2133 $pdf->SetFont(
'',
'', $default_font_size - 1);
2134 $pdf->SetTextColor(0, 0, 0);
2137 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2139 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2141 $this->error = $hookmanager->error;
2142 $this->errors = $hookmanager->errors;
2146 return ($tab2_top + ($tab2_hl * $index));
2242 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2245 global
$conf, $langs;
2247 $ltrdirection =
'L';
2248 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2249 $ltrdirection =
'R';
2253 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2259 $pdf->SetTextColor(0, 0, 60);
2260 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2264 $posy = $this->marge_haute;
2265 $posx = $this->page_largeur - $this->marge_droite - $w;
2267 $pdf->SetXY($this->marge_gauche, $posy);
2271 if ($this->emetteur->logo) {
2272 $logodir =
$conf->mycompany->dir_output;
2273 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
2274 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
2277 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2279 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2281 if (is_readable($logo)) {
2283 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2285 $pdf->SetTextColor(200, 0, 0);
2286 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2287 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2288 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2291 $text = $this->emetteur->name;
2292 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2296 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2297 $pdf->SetXY($posx, $posy);
2298 $pdf->SetTextColor(0, 0, 60);
2299 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2301 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2304 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2307 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2310 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2312 if ($this->situationinvoice) {
2313 $outputlangs->loadLangs(array(
"other"));
2314 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2316 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2319 if ($this->situationinvoice) {
2320 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2322 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2323 } elseif (
$object->type == 1) {
2324 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2325 } elseif (
$object->type == 2) {
2326 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2327 } elseif (
$object->type == 3) {
2328 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2329 } elseif (
$object->type == 4) {
2330 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2333 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2334 if (
$object->status == $object::STATUS_DRAFT) {
2335 $pdf->SetTextColor(128, 0, 0);
2336 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2339 $pdf->MultiCell($w, 3, $title,
'',
'R');
2341 $pdf->SetFont(
'',
'B', $default_font_size);
2355 $pdf->SetFont(
'',
'', $default_font_size - 2);
2359 $pdf->SetXY($posx, $posy);
2360 $pdf->SetTextColor(0, 0, 60);
2361 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2366 if (!empty(
$object->project->ref)) {
2368 $pdf->SetXY($posx, $posy);
2369 $pdf->SetTextColor(0, 0, 60);
2370 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2376 if (!empty(
$object->project->ref)) {
2377 $outputlangs->load(
"projects");
2379 $pdf->SetXY($posx, $posy);
2380 $pdf->SetTextColor(0, 0, 60);
2381 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2385 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2386 if (
$object->type == 0 && $objectidnext) {
2387 $objectreplacing =
new Facture($this->db);
2388 $objectreplacing->fetch($objectidnext);
2391 $pdf->SetXY($posx, $posy);
2392 $pdf->SetTextColor(0, 0, 60);
2393 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2396 $objectreplaced =
new Facture($this->db);
2397 $objectreplaced->fetch(
$object->fk_facture_source);
2400 $pdf->SetXY($posx, $posy);
2401 $pdf->SetTextColor(0, 0, 60);
2402 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2405 $objectreplaced =
new Facture($this->db);
2406 $objectreplaced->fetch(
$object->fk_facture_source);
2409 $pdf->SetXY($posx, $posy);
2410 $pdf->SetTextColor(0, 0, 60);
2411 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2415 $pdf->SetXY($posx, $posy);
2416 $pdf->SetTextColor(0, 0, 60);
2418 $title = $outputlangs->transnoentities(
"DateInvoice");
2419 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2420 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2422 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2426 $pdf->SetXY($posx, $posy);
2427 $pdf->SetTextColor(0, 0, 60);
2428 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2433 $pdf->SetXY($posx, $posy);
2434 $pdf->SetTextColor(0, 0, 60);
2435 $title = $outputlangs->transnoentities(
"DateDue");
2436 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2437 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2439 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2444 $pdf->SetXY($posx, $posy);
2445 $pdf->SetTextColor(0, 0, 60);
2446 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2451 $pdf->SetXY($posx, $posy);
2452 $pdf->SetTextColor(0, 0, 60);
2453 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2458 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2459 if (count($arrayidcontact) > 0) {
2460 $usertmp =
new User($this->db);
2461 $usertmp->fetch($arrayidcontact[0]);
2463 $pdf->SetXY($posx, $posy);
2464 $pdf->SetTextColor(0, 0, 60);
2465 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2474 $current_y = $pdf->getY();
2476 if ($current_y < $pdf->getY()) {
2477 $top_shift = $pdf->getY() - $current_y;
2482 $carac_emetteur =
'';
2484 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2485 if (count($arrayidcontact) > 0) {
2486 $object->fetch_user($arrayidcontact[0]);
2487 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2488 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2489 $carac_emetteur .=
"\n";
2496 $posy += $top_shift;
2497 $posx = $this->marge_gauche;
2499 $posx = $this->page_largeur - $this->marge_droite - 80;
2507 $pdf->SetTextColor(0, 0, 0);
2508 $pdf->SetFont(
'',
'', $default_font_size - 2);
2509 $pdf->SetXY($posx, $posy - 5);
2510 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2511 $pdf->SetXY($posx, $posy);
2512 $pdf->SetFillColor(230, 230, 230);
2513 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2514 $pdf->SetTextColor(0, 0, 60);
2519 $pdf->SetXY($posx + 2, $posy + 3);
2520 $pdf->SetFont(
'',
'B', $default_font_size);
2521 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2522 $posy = $pdf->getY();
2526 $pdf->SetXY($posx + 2, $posy);
2527 $pdf->SetFont(
'',
'', $default_font_size - 1);
2528 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2531 $usecontact =
false;
2532 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2533 if (count($arrayidcontact) > 0) {
2535 $result =
$object->fetch_contact($arrayidcontact[0]);
2539 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2540 $thirdparty =
$object->contact;
2542 $thirdparty =
$object->thirdparty;
2552 if ($this->page_largeur < 210) {
2556 $posy += $top_shift;
2557 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2559 $posx = $this->marge_gauche;
2564 $pdf->SetTextColor(0, 0, 0);
2565 $pdf->SetFont(
'',
'', $default_font_size - 2);
2566 $pdf->SetXY($posx + 2, $posy - 5);
2567 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2568 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2572 $pdf->SetXY($posx + 2, $posy + 3);
2573 $pdf->SetFont(
'',
'B', $default_font_size);
2575 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2577 $posy = $pdf->getY();
2580 $pdf->SetFont(
'',
'', $default_font_size - 1);
2581 $pdf->SetXY($posx + 2, $posy);
2583 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2587 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2589 if (!empty($idaddressshipping)) {
2590 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2591 $companystatic =
new Societe($this->db);
2592 $companystatic->fetch(
$object->contact->fk_soc);
2599 if (!empty($carac_client_shipping)) {
2600 $posy += $hautcadre;
2605 $pdf->SetXY($posx + 2, $posy - 5);
2606 $pdf->SetFont(
'',
'', $default_font_size - 2);
2607 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2608 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2611 $pdf->SetXY($posx + 2, $posy + 3);
2612 $pdf->SetFont(
'',
'B', $default_font_size);
2613 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2615 $posy = $pdf->getY();
2618 $pdf->SetXY($posx + 2, $posy);
2619 $pdf->SetFont(
'',
'', $default_font_size - 1);
2620 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2622 $shipp_shift += $hautcadre + 10;
2627 $pdf->SetTextColor(0, 0, 0);
2629 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);