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 = $heightforqrinvoice_firstpage = 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++;
418 if ($categoryOfOperation < 2) {
419 $lineProductType =
$object->lines[$i]->product_type;
425 if ($nbProduct > 0 && $nbService > 0) {
427 $categoryOfOperation = 2;
432 if ($categoryOfOperation <= 0) {
434 if ($nbProduct == 0 && $nbService > 0) {
435 $categoryOfOperation = 1;
438 $this->categoryOfOperation = $categoryOfOperation;
441 if (
$object->situation_cycle_ref) {
442 $this->situationinvoice =
true;
447 if (!empty($tplidx)) {
448 $pdf->useTemplate($tplidx);
453 $pagehead = $this->
_pagehead($pdf,
$object, 1, $outputlangs, $outputlangsbis);
454 $top_shift = $pagehead[
'top_shift'];
455 $shipp_shift = $pagehead[
'shipp_shift'];
456 $pdf->SetFont(
'',
'', $default_font_size - 1);
457 $pdf->MultiCell(0, 3,
'');
458 $pdf->SetTextColor(0, 0, 0);
463 $this->tab_top = 90 + $top_shift + $shipp_shift;
464 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
467 $extra_under_address_shift = 0;
470 $qrcodestring =
$object->buildZATCAQRString();
473 $qrcodestring =
$object->buildSwitzerlandQRString();
477 $qrcodestring =
$object->buildEPCQrCodeString();
482 $qrcodecolor = array(
'25',
'25',
'25');
487 'fgcolor' => $qrcodecolor,
492 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
496 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
497 $pdf->SetFont(
'',
'', $default_font_size - 4);
498 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L', 0);
502 $extra_under_address_shift += 25;
510 'outputlangs' => $outputlangs,
511 'hidedetails' => $hidedetails
513 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
514 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
515 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
518 $this->tab_top += $extra_under_address_shift;
519 $this->tab_top_newpage += 0;
523 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1,
$object, $langs);
525 $nexY = $this->tab_top - 1;
528 $height_incoterms = 0;
529 if (isModEnabled(
'incoterm')) {
530 $desc_incoterms =
$object->getIncotermsForPDF();
531 if ($desc_incoterms) {
534 $pdf->SetFont(
'',
'', $default_font_size - 1);
535 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
536 $nexY = max($pdf->GetY(), $nexY);
537 $height_incoterms = $nexY - $this->tab_top;
540 $pdf->SetDrawColor(192, 192, 192);
541 $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');
543 $this->tab_top = $nexY + 6;
544 $height_incoterms += 4;
549 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
552 if (is_object(
$object->thirdparty)) {
553 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
554 $salerepobj =
new User($this->db);
555 $salerepobj->fetch($salereparray[0][
'id']);
556 if (!empty($salerepobj->signature)) {
557 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
563 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
564 if (!empty($extranote)) {
568 $pagenb = $pdf->getPage();
572 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
573 $pageposbeforenote = $pagenb;
580 $pdf->startTransaction();
582 $pdf->SetFont(
'',
'', $default_font_size - 1);
583 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
585 $pageposafternote = $pdf->getPage();
586 $posyafter = $pdf->GetY();
588 if ($pageposafternote > $pageposbeforenote) {
589 $pdf->rollbackTransaction(
true);
592 while ($pagenb < $pageposafternote) {
595 if (!empty($tplidx)) {
596 $pdf->useTemplate($tplidx);
601 $pdf->setTopMargin($this->tab_top_newpage);
603 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
607 $pdf->setPage($pageposbeforenote);
608 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
609 $pdf->SetFont(
'',
'', $default_font_size - 1);
610 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
611 $pageposafternote = $pdf->getPage();
613 $posyafter = $pdf->GetY();
615 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
616 $pdf->AddPage(
'',
'',
true);
619 $pdf->setPage($pageposafternote);
620 $pdf->setTopMargin($this->tab_top_newpage);
622 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
628 $i = $pageposbeforenote;
629 while ($i < $pageposafternote) {
633 $pdf->SetDrawColor(128, 128, 128);
635 if ($i > $pageposbeforenote) {
636 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
637 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
639 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
640 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
644 $pdf->setPageOrientation(
'', 1, 0);
651 $pdf->setPage($pageposafternote);
652 if (!empty($tplidx)) {
653 $pdf->useTemplate($tplidx);
658 $height_note = $posyafter - $this->tab_top_newpage;
659 $pdf->RoundedRect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
662 $pdf->commitTransaction();
663 $posyafter = $pdf->GetY();
664 $height_note = $posyafter - $this->tab_top;
665 $pdf->RoundedRect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius,
'1234',
'D');
668 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
670 $pdf->AddPage(
'',
'',
true);
673 $pdf->setPage($pageposafternote);
674 if (!empty($tplidx)) {
675 $pdf->useTemplate($tplidx);
681 $posyafter = $this->tab_top_newpage;
685 $tab_height -= $height_note;
686 $this->tab_top = $posyafter + 6;
695 $pdf->startTransaction();
696 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
697 $pdf->rollbackTransaction(
true);
699 $nexY = $this->tab_top + $this->tabTitleHeight;
702 $pageposbeforeprintlines = $pdf->getPage();
703 $pagenb = $pageposbeforeprintlines;
704 for ($i = 0; $i < $nblines; $i++) {
705 $linePosition = $i + 1;
709 if (isset(
$object->lines[$i]->pagebreak) &&
$object->lines[$i]->pagebreak) {
712 if (!empty($tplidx)) {
713 $pdf->useTemplate($tplidx);
716 $pdf->setPage($pdf->getNumPages());
717 $nexY = $this->tab_top_newpage;
722 $pdf->SetFont(
'',
'', $default_font_size - 1);
723 $pdf->SetTextColor(0, 0, 0);
726 $imglinesize = array();
727 if (!empty($realpatharray[$i])) {
731 $pdf->setTopMargin($this->tab_top_newpage);
732 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
733 $pageposbefore = $pdf->getPage();
737 $showpricebeforepagebreak =
getDolGlobalInt(
'MAIN_PDF_DATA_ON_FIRST_PAGE');
742 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imageTopMargin + $imglinesize[
'height']) > ($this->page_hauteur - $this->heightforfooter)) {
743 $pdf->AddPage(
'',
'',
true);
744 if (!empty($tplidx)) {
745 $pdf->useTemplate($tplidx);
747 $pdf->setPage($pageposbefore + 1);
748 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
749 $curY = $this->tab_top_newpage;
750 $showpricebeforepagebreak = 0;
753 $pdf->setPageOrientation(
'', 0, $this->heightforfooter + $this->heightforfreetext);
754 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
755 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + $imageTopMargin, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
757 $posYAfterImage = $curY + $imglinesize[
'height'];
764 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
774 $pdf->setPage($pageposbefore);
775 $pdf->setTopMargin($this->marge_haute);
777 $pdf->setPageOrientation(
'', 0, $this->heightforfooter);
780 if ($afterPosData[
'page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $this->heightforfooter))) {
781 $pdf->setPage($afterPosData[
'page']);
782 $curY = $this->tab_top_newpage;
785 $pdf->SetFont(
'',
'', $default_font_size - 1);
842 if (!empty(
$object->lines[$i]->array_options)) {
843 foreach (
$object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
859 'nexY' => & $afterPosData[
'y'],
860 'outputlangs' => $outputlangs,
861 'hidedetails' => $hidedetails
863 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
871 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
872 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
873 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
874 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
876 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
879 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
880 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
882 $tvaligne = $sign *
$object->lines[$i]->total_tva;
886 $localtax1ligne =
$object->lines[$i]->total_localtax1;
887 $localtax2ligne =
$object->lines[$i]->total_localtax2;
888 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
889 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
890 $localtax1_type =
$object->lines[$i]->localtax1_type;
891 $localtax2_type =
$object->lines[$i]->localtax2_type;
904 $vatrate = (string)
$object->lines[$i]->tva_tx;
907 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
908 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
910 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
911 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
915 if ($localtax1_type && $localtax1ligne != 0) {
916 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
917 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
919 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
922 if ($localtax2_type && $localtax2ligne != 0) {
923 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
924 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
926 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
930 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
935 if (!isset($this->tva[$vatrate])) {
936 $this->tva[$vatrate] = 0;
938 $this->tva[$vatrate] += $tvaligne;
939 $vatcode =
$object->lines[$i]->vat_src_code;
941 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'tot_ht'])) {
942 $this->tva_array[$vatrate . ($vatcode ?
' (' . $vatcode .
')' :
'')][
'tot_ht'] = 0;
944 $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);
946 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
947 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
949 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
953 $pdf->setPage($afterPosData[
'page']);
954 $nexY = $afterPosData[
'y'];
957 if (
getDolGlobalString(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData[
'y'] < $this->page_hauteur - $this->heightforfooter - 5) {
958 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
960 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
961 $pdf->SetLineStyle(array(
'dash' => 0));
969 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
971 if ($afterPosData[
'y'] > $this->page_hauteur - $page_bottom_margin) {
973 if (!empty($tplidx)) {
974 $pdf->useTemplate($tplidx);
977 $pdf->setPage($pagenb);
981 $drawTabNumbPage = $pdf->getNumPages();
982 for ($i=$pageposbeforeprintlines; $i<=$drawTabNumbPage; $i++) {
985 $pdf->setPageOrientation(
'', 0, 0);
987 $drawTabHideTop = $hidetop;
988 $drawTabTop = $this->tab_top_newpage;
989 $drawTabBottom = $this->page_hauteur - $this->heightforfooter;;
992 if ($i == $pageposbeforeprintlines) {
994 $drawTabTop = $this->tab_top;
995 } elseif (!$drawTabHideTop) {
997 $drawTabTop-= $this->tabTitleHeight;
1004 if ($i == $pdf->getNumPages()) {
1006 $drawTabBottom-= $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $outputlangs);
1009 $drawTabHeight = $drawTabBottom - $drawTabTop;
1010 $this->
_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom,
$object->multicurrency_code, $outputlangsbis);
1012 $hideFreeText = $i != $pdf->getNumPages() ? 1 : 0;
1019 $pdf->setPageOrientation(
'', 1, 0);
1022 if (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
1025 if (!empty($tplidx)) {
1026 $pdf->useTemplate($tplidx);
1032 $pdf->SetTextColor(0, 0, 0);
1034 $pdf->setPage($pdf->getNumPages());
1036 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1042 $posy = $this->
drawTotalTable($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1045 $listofpayments =
$object->getListOfPayments(
'', 0, 1);
1046 if ((count($listofpayments) || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1051 if (method_exists($pdf,
'AliasNbPages')) {
1052 $pdf->AliasNbPages();
1055 if (!empty($mysoc->termsofsale) &&
getDolGlobalInt(
'MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) {
1056 $termsofsale =
$conf->mycompany->dir_output.
'/'.$mysoc->termsofsale;
1057 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
1058 $termsofsale =
$conf->mycompany->multidir_output[
$object->entity].
'/'.$mysoc->termsofsale;
1060 if (file_exists($termsofsale) && is_readable($termsofsale)) {
1061 $pagecount = $pdf->setSourceFile($termsofsale);
1062 for ($i = 1; $i <= $pagecount; $i++) {
1063 $tplIdx = $pdf->importPage($i);
1064 if ($tplIdx!==
false) {
1065 $s = $pdf->getTemplatesize($tplIdx);
1066 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1067 $pdf->useTemplate($tplIdx);
1069 setEventMessages(
null, array($termsofsale.
' cannot be added, probably protected PDF'),
'warnings');
1081 $pdf->Output($file,
'F');
1084 $hookmanager->initHooks(array(
'pdfgeneration'));
1085 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
1087 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1089 $this->error = $hookmanager->error;
1090 $this->errors = $hookmanager->errors;
1095 $this->result = array(
'fullpath' => $file);
1099 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1103 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1126 $tab3_top = $posy + 8;
1129 if ($this->page_largeur < 210) {
1135 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1137 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1140 $pdf->SetFont(
'',
'', $default_font_size - 3);
1141 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1142 $pdf->MultiCell(60, 3, $title, 0,
'L', 0);
1144 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1146 $pdf->SetFont(
'',
'', $default_font_size - 4);
1147 $pdf->SetXY($tab3_posx, $tab3_top);
1148 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
1149 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1150 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
1151 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1152 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
1153 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1154 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
1156 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1160 $pdf->SetFont(
'',
'', $default_font_size - 4);
1164 $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,";
1165 $sql .=
" re.description, re.fk_facture_source,";
1166 $sql .=
" f.type, f.datef";
1167 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1168 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
1169 $resql = $this->db->query($sql);
1171 $num = $this->db->num_rows($resql);
1173 $invoice =
new Facture($this->db);
1176 $obj = $this->db->fetch_object($resql);
1178 if ($obj->type == 2) {
1179 $text = $outputlangs->transnoentities(
"CreditNote");
1180 } elseif ($obj->type == 3) {
1181 $text = $outputlangs->transnoentities(
"Deposit");
1182 } elseif ($obj->type == 0) {
1183 $text = $outputlangs->transnoentities(
"ExcessReceived");
1185 $text = $outputlangs->transnoentities(
"UnknownType");
1188 $invoice->fetch($obj->fk_facture_source);
1190 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1191 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1192 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1193 $pdf->MultiCell(20, 3,
price((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1194 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1195 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1196 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1197 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1199 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1204 $this->error = $this->db->lasterror();
1210 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1213 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1214 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1216 $sql .=
" ORDER BY p.datep";
1218 $resql = $this->db->query($sql);
1220 $num = $this->db->num_rows($resql);
1225 $row = $this->db->fetch_object($resql);
1226 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1227 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1228 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1229 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1230 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1231 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1233 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1234 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1235 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1236 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1237 $y = $maxY = max($pdf->GetY() - 3 - $tab3_top, $maxY);
1238 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1243 return $tab3_top + $y + 3;
1245 $this->error = $this->db->lasterror();
1263 global
$conf, $mysoc, $hookmanager;
1267 $pdf->SetFont(
'',
'', $default_font_size - 1);
1269 krsort($this->tva_array);
1276 $pdf->SetFillColor(224, 224, 224);
1278 $pdf->SetFont(
'',
'', $default_font_size - 2);
1279 $pdf->SetXY($this->marge_gauche, $posy);
1280 $titre = $outputlangs->transnoentities(
"VAT");
1281 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1283 $pdf->SetFont(
'',
'', $default_font_size - 2);
1284 $pdf->SetXY($this->marge_gauche + 25, $posy);
1285 $titre = $outputlangs->transnoentities(
"NetTotal");
1286 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1288 $pdf->SetFont(
'',
'', $default_font_size - 2);
1289 $pdf->SetXY($this->marge_gauche + 50, $posy);
1290 $titre = $outputlangs->transnoentities(
"VATAmount");
1291 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1293 $pdf->SetFont(
'',
'', $default_font_size - 2);
1294 $pdf->SetXY($this->marge_gauche + 75, $posy);
1295 $titre = $outputlangs->transnoentities(
"AmountTotal");
1296 $pdf->MultiCell(25, 4, $titre, 0,
'L',
true);
1298 $posy = $pdf->GetY();
1303 foreach ($this->tva_array as $tvakey => $tvaval) {
1304 $pdf->SetFont(
'',
'', $default_font_size - 2);
1305 $pdf->SetXY($this->marge_gauche, $posy);
1306 $titre = round((
float) $tvakey, 2) .
"%";
1307 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1309 $pdf->SetFont(
'',
'', $default_font_size - 2);
1310 $pdf->SetXY($this->marge_gauche + 25, $posy);
1311 $titre =
price($tvaval[
'tot_ht']);
1312 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1313 $tot_ht += $tvaval[
'tot_ht'];
1315 $pdf->SetFont(
'',
'', $default_font_size - 2);
1316 $pdf->SetXY($this->marge_gauche + 50, $posy);
1317 $titre =
price($tvaval[
'amount']);
1318 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1319 $tot_tva += $tvaval[
'amount'];
1321 $pdf->SetFont(
'',
'', $default_font_size - 2);
1322 $pdf->SetXY($this->marge_gauche + 75, $posy);
1323 $titre =
price($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1324 $pdf->MultiCell(25, 4, $titre, 0,
'L');
1325 $tot_ttc += ($tvaval[
'tot_ht'] + $tvaval[
'amount']);
1327 $posy = $pdf->GetY();
1332 if (in_array($this->emetteur->country_code, array(
'FR')) && empty(
$object->total_tva)) {
1333 $pdf->SetFont(
'',
'', $default_font_size - 2);
1334 $pdf->SetXY($this->marge_gauche, $posy);
1335 if (empty($mysoc->tva_assuj)) {
1336 if ($mysoc->forme_juridique_code == 92) {
1337 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1339 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1341 } elseif (
getDolGlobalString(
"INVOICE_VAT_SHOW_REVERSE_CHARGE_MENTION") && $this->emetteur->country_code !=
$object->thirdparty->country_code && $this->emetteur->isInEEC() &&
$object->thirdparty->isInEEC()) {
1342 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedReverseChargeProcedure"), 0,
'L', 0);
1344 $posy = $pdf->GetY() + 4;
1349 if ($this->page_largeur < 210) {
1355 $pdf->SetFont(
'',
'', $default_font_size - 2);
1356 $pdf->SetXY($this->marge_gauche, $posy);
1357 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1358 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1360 $pdf->SetFont(
'',
'', $default_font_size - 2);
1361 $pdf->SetXY($posxval, $posy);
1362 $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);
1363 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1364 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1366 $posy = $pdf->GetY() + 3;
1370 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1371 $pdf->SetFont(
'',
'', $default_font_size - 2);
1372 $pdf->SetXY($this->marge_gauche, $posy);
1373 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1374 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1376 $pdf->SetFont(
'',
'', $default_font_size - 2);
1377 $pdf->SetXY($posxval, $posy);
1378 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1379 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1381 $posy = $pdf->GetY() + 3;
1386 if (empty(
$object->mode_reglement_code)
1389 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1393 $outputlangs->load(
"errors");
1395 $pdf->SetXY($this->marge_gauche, $posy);
1396 $pdf->SetTextColor(200, 0, 0);
1397 $pdf->SetFont(
'',
'', $default_font_size - 2);
1398 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1399 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L', 0);
1400 $pdf->SetTextColor(0, 0, 0);
1402 $posy = $pdf->GetY() + 1;
1406 if (!empty(
$object->mode_reglement_code)
1407 &&
$object->mode_reglement_code !=
'CHQ'
1408 &&
$object->mode_reglement_code !=
'VIR') {
1409 $pdf->SetFont(
'',
'', $default_font_size - 2);
1410 $pdf->SetXY($this->marge_gauche, $posy);
1411 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1412 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1414 $pdf->SetFont(
'',
'', $default_font_size - 2);
1415 $pdf->SetXY($posxval, $posy);
1416 $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);
1419 if (
$object->mode_reglement_code ==
"PRE") {
1420 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1423 $bac->fetch(0,
'',
$object->thirdparty->id);
1424 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1425 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1428 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1430 $posy = $pdf->GetY();
1436 if ($this->emetteur->country_code ==
'FR') {
1438 $pdf->SetXY($this->marge_gauche, $posy);
1439 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1441 $posy = $pdf->GetY() + 1;
1446 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1447 $useonlinepayment = 0;
1451 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1452 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1453 $useonlinepayment = count($validpaymentmethod);
1458 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1461 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1462 $servicename = $langs->transnoentities(
'Online');
1463 $paiement_url = getOnlinePaymentUrl(0,
'invoice',
$object->ref, 0,
'', 0);
1464 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1466 $pdf->SetXY($this->marge_gauche, $posy);
1467 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
'',
'',
dol_htmlentitiesbr($linktopay), 0, 1);
1469 $posy = $pdf->GetY() + 1;
1474 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1480 $account =
new Account($this->db);
1483 $pdf->SetXY($this->marge_gauche, $posy);
1484 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1485 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L', 0);
1486 $posy = $pdf->GetY() + 1;
1489 $pdf->SetXY($this->marge_gauche, $posy);
1490 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1491 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1492 $posy = $pdf->GetY() + 2;
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', $this->emetteur->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($this->emetteur->getFullAddress()), 0,
'L', 0);
1505 $posy = $pdf->GetY() + 2;
1512 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1518 $account =
new Account($this->db);
1519 $account->fetch($bankid);
1521 $curx = $this->marge_gauche;
1524 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1532 $qrCodeColor = array(
'25',
'25',
'25');
1536 'fgcolor' => $qrCodeColor,
1538 'module_width' => 1,
1539 'module_height' => 1
1542 $EPCQrCodeString =
$object->buildEPCQrCodeString();
1543 $pdf->write2DBarcode($EPCQrCodeString,
'QRCODE,M', $qrPosX, $qrPosY, 25, 25, $styleQr,
'N');
1545 $pdf->SetXY($qrPosX + 30, $posy + 5);
1546 $pdf->SetFont(
'',
'', $default_font_size - 5);
1547 $pdf->MultiCell(30, 3, $outputlangs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L', 0);
1548 $posy = $pdf->GetY() + 2;
1553 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
1556 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'StructuredCommunication').
": " . $outputlangs->convToOutputCharset($invoicePaymentKey), 0,
'L', 0);
1579 global $mysoc, $hookmanager;
1590 if (is_object($outputlangsbis)) {
1591 $pdf->SetFont(
'',
'', $default_font_size - 2);
1593 $pdf->SetFont(
'',
'', $default_font_size - 1);
1599 if ($this->page_largeur < 210) {
1603 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1609 $parameters = array(
1611 'outputlangs' => $outputlangs,
1613 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1618 foreach (
$object->lines as $line) {
1619 if ($line->product_type != 9) {
1620 $percent += $line->situation_percent;
1626 $avancementGlobal = $percent / $i;
1628 $avancementGlobal = 0;
1631 $object->fetchPreviousNextSituationInvoice();
1632 $TPreviousIncoice =
$object->tab_previous_situation_invoice;
1635 $total_a_payer_ttc = 0;
1636 foreach ($TPreviousIncoice as &$fac) {
1637 $total_a_payer += $fac->total_ht;
1638 $total_a_payer_ttc += $fac->total_ttc;
1640 $total_a_payer +=
$object->total_ht;
1641 $total_a_payer_ttc +=
$object->total_ttc;
1643 if (!empty($avancementGlobal)) {
1644 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1645 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1648 $total_a_payer_ttc = 0;
1652 if (!empty($TPreviousIncoice)) {
1653 $pdf->setY($tab2_top);
1654 $posy = $pdf->GetY();
1656 foreach ($TPreviousIncoice as &$fac) {
1657 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1662 $pdf->setY($this->tab_top_newpage);
1664 $pdf->setY($this->marge_haute);
1666 $posy = $pdf->GetY();
1671 $pdf->SetFillColor(255, 255, 255);
1672 $pdf->SetXY($col1x, $posy);
1673 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1675 $pdf->SetXY($col2x, $posy);
1679 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1682 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1684 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1693 $pdf->SetFillColor(255, 255, 255);
1694 $pdf->SetXY($col1x, $posy);
1695 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle",
$object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1697 $pdf->SetXY($col2x, $posy);
1700 $facSign =
$object->total_ht >= 0 ?
'+' :
'';
1708 $displayAmount =
' '.$facSign.
' '.
price(
$object->total_ht, 0, $outputlangs);
1709 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1714 $pdf->SetFont(
'',
'', $default_font_size - 1);
1715 $pdf->SetFillColor(255, 255, 255);
1716 $pdf->SetXY($col1x, $posy);
1717 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", $avancementGlobal), 0,
'L', 1);
1719 $pdf->SetXY($col2x, $posy);
1720 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R', 1);
1721 $pdf->SetFont(
'',
'', $default_font_size - 2);
1725 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1729 $pdf->setY($this->tab_top_newpage);
1731 $pdf->setY($this->marge_haute);
1734 $posy = $pdf->GetY();
1745 $total_ht = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1 ?
$object->multicurrency_total_ht :
$object->total_ht);
1748 $total_line_remise = 0;
1749 foreach (
$object->lines as $i => $line) {
1751 $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0);
1753 if ($line->total_ht < 0) {
1754 $total_line_remise += -$line->total_ht;
1757 if ($total_line_remise > 0) {
1758 $pdf->SetFillColor(255, 255, 255);
1759 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1760 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L', 1);
1761 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1762 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise, 0, $outputlangs), 0,
'R', 1);
1767 $pdf->SetFillColor(255, 255, 255);
1768 $pdf->SetXY($col1x, $tab2_top);
1769 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L', 1);
1770 $pdf->SetXY($col2x, $tab2_top);
1771 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise + $total_ht, 0, $outputlangs), 0,
'R', 1);
1777 $pdf->SetFillColor(255, 255, 255);
1778 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1779 $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);
1781 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
1782 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1783 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1787 $pdf->SetFillColor(255, 255, 255);
1788 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1789 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalVAT"), 0,
'L', 1);
1791 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1792 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->total_tva), 0,
'R', 1);
1796 $pdf->SetFillColor(248, 248, 248);
1798 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
1800 $this->atleastoneratenotnull = 0;
1802 $tvaisnull = (!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000']));
1803 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1807 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1808 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1812 foreach ($localtax_rate as $tvakey => $tvaval) {
1817 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1820 if (preg_match(
'/\*/', (
string) $tvakey)) {
1821 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1822 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1825 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1829 $totalvat .= $tvacompl;
1831 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1834 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1836 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1838 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1839 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1845 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1846 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1850 foreach ($localtax_rate as $tvakey => $tvaval) {
1855 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1858 if (preg_match(
'/\*/', (
string) $tvakey)) {
1859 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1860 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1862 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1866 $totalvat .= $tvacompl;
1868 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1871 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1873 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1875 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1876 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1884 foreach ($this->tva as $tvakey => $tvaval) {
1885 $sum_pdf_tva += $tvaval;
1888 if ($sum_pdf_tva !=
$object->total_tva) {
1889 if (!empty($sum_pdf_tva)) {
1890 $coef_fix_tva =
$object->total_tva / $sum_pdf_tva;
1896 foreach ($this->tva as $tvakey => $tvaval) {
1897 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1899 foreach ($this->tva_array as $tvakey => $tvaval) {
1900 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1907 foreach ($this->tva_array as $tvakey => $tvaval) {
1909 $this->atleastoneratenotnull++;
1912 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1915 if (preg_match(
'/\*/', $tvakey)) {
1916 $tvakey = str_replace(
'*',
'', $tvakey);
1917 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1919 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1922 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1924 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1926 $totalvat .= $tvacompl;
1928 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1930 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1932 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1933 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1939 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1940 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1944 foreach ($localtax_rate as $tvakey => $tvaval) {
1949 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1952 if (preg_match(
'/\*/', (
string) $tvakey)) {
1953 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1954 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1956 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1960 $totalvat .= $tvacompl;
1962 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
1965 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1967 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1969 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1970 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1976 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1977 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1981 foreach ($localtax_rate as $tvakey => $tvaval) {
1987 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1990 if (preg_match(
'/\*/', (
string) $tvakey)) {
1991 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1992 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1994 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1998 $totalvat .= $tvacompl;
2000 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
2003 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
2005 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
2007 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2008 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
2016 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2017 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L', 1);
2019 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2020 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R', 1);
2025 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2026 $pdf->SetTextColor(0, 0, 60);
2027 $pdf->SetFillColor(224, 224, 224);
2028 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
2030 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2031 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
2035 if (
$object->displayRetainedWarranty()) {
2036 $pdf->SetTextColor(40, 40, 40);
2037 $pdf->SetFillColor(255, 255, 255);
2039 $retainedWarranty =
$object->getRetainedWarrantyAmount();
2040 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
2044 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2045 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L', 1);
2047 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2048 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
2052 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2054 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.
$object->retained_warranty.
'%)';
2055 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
2057 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
2058 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2059 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
2064 $pdf->SetTextColor(0, 0, 0);
2066 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2067 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
2069 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
2074 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
2077 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2078 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L', 0);
2079 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2080 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
2083 if ($creditnoteamount) {
2084 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
2085 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.(($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes"))) :
'');
2087 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2088 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
2089 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2090 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
2093 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
2095 $pdf->SetFillColor(255, 255, 255);
2097 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2098 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"EscompteOfferedShort") :
''), $useborder,
'L', 1);
2099 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2100 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT'), 0, $outputlangs), $useborder,
'R', 1);
2106 $pdf->SetTextColor(0, 0, 60);
2107 $pdf->SetFillColor(224, 224, 224);
2108 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
2109 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
2110 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
2111 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
2113 $pdf->SetFont(
'',
'', $default_font_size - 1);
2114 $pdf->SetTextColor(0, 0, 0);
2117 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
2119 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
2121 $this->error = $hookmanager->error;
2122 $this->errors = $hookmanager->errors;
2126 return ($tab2_top + ($tab2_hl * $index));
2222 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
2225 global
$conf, $langs;
2227 $ltrdirection =
'L';
2228 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
2229 $ltrdirection =
'R';
2233 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2239 $pdf->SetTextColor(0, 0, 60);
2240 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2244 $posy = $this->marge_haute;
2245 $posx = $this->page_largeur - $this->marge_droite - $w;
2247 $pdf->SetXY($this->marge_gauche, $posy);
2251 if ($this->emetteur->logo) {
2252 $logodir =
$conf->mycompany->dir_output;
2253 if (!empty(
$conf->mycompany->multidir_output[
$object->entity])) {
2254 $logodir =
$conf->mycompany->multidir_output[
$object->entity];
2257 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2259 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2261 if (is_readable($logo)) {
2263 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2265 $pdf->SetTextColor(200, 0, 0);
2266 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2267 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2268 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2271 $text = $this->emetteur->name;
2272 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2276 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2277 $pdf->SetXY($posx, $posy);
2278 $pdf->SetTextColor(0, 0, 60);
2279 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2281 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2284 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2287 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2290 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2292 if ($this->situationinvoice) {
2293 $langs->loadLangs(array(
"other"));
2294 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
2296 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2299 if ($this->situationinvoice) {
2300 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2302 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2303 } elseif (
$object->type == 1) {
2304 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2305 } elseif (
$object->type == 2) {
2306 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2307 } elseif (
$object->type == 3) {
2308 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2309 } elseif (
$object->type == 4) {
2310 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2313 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
2314 if (
$object->status == $object::STATUS_DRAFT) {
2315 $pdf->SetTextColor(128, 0, 0);
2316 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2319 $pdf->MultiCell($w, 3, $title,
'',
'R');
2321 $pdf->SetFont(
'',
'B', $default_font_size);
2335 $pdf->SetFont(
'',
'', $default_font_size - 2);
2339 $pdf->SetXY($posx, $posy);
2340 $pdf->SetTextColor(0, 0, 60);
2341 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset(
$object->ref_customer), 65),
'',
'R');
2346 if (!empty(
$object->project->ref)) {
2348 $pdf->SetXY($posx, $posy);
2349 $pdf->SetTextColor(0, 0, 60);
2350 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
2356 if (!empty(
$object->project->ref)) {
2357 $outputlangs->load(
"projects");
2359 $pdf->SetXY($posx, $posy);
2360 $pdf->SetTextColor(0, 0, 60);
2361 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
2365 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
2366 if (
$object->type == 0 && $objectidnext) {
2367 $objectreplacing =
new Facture($this->db);
2368 $objectreplacing->fetch($objectidnext);
2371 $pdf->SetXY($posx, $posy);
2372 $pdf->SetTextColor(0, 0, 60);
2373 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2376 $objectreplaced =
new Facture($this->db);
2377 $objectreplaced->fetch(
$object->fk_facture_source);
2380 $pdf->SetXY($posx, $posy);
2381 $pdf->SetTextColor(0, 0, 60);
2382 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2385 $objectreplaced =
new Facture($this->db);
2386 $objectreplaced->fetch(
$object->fk_facture_source);
2389 $pdf->SetXY($posx, $posy);
2390 $pdf->SetTextColor(0, 0, 60);
2391 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2395 $pdf->SetXY($posx, $posy);
2396 $pdf->SetTextColor(0, 0, 60);
2398 $title = $outputlangs->transnoentities(
"DateInvoice");
2399 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2400 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2402 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2406 $pdf->SetXY($posx, $posy);
2407 $pdf->SetTextColor(0, 0, 60);
2408 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2413 $pdf->SetXY($posx, $posy);
2414 $pdf->SetTextColor(0, 0, 60);
2415 $title = $outputlangs->transnoentities(
"DateDue");
2416 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2417 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2419 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2424 $pdf->SetXY($posx, $posy);
2425 $pdf->SetTextColor(0, 0, 60);
2426 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2431 $pdf->SetXY($posx, $posy);
2432 $pdf->SetTextColor(0, 0, 60);
2433 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerAccountancyCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_compta_client),
'',
'R');
2438 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2439 if (count($arrayidcontact) > 0) {
2440 $usertmp =
new User($this->db);
2441 $usertmp->fetch($arrayidcontact[0]);
2443 $pdf->SetXY($posx, $posy);
2444 $pdf->SetTextColor(0, 0, 60);
2445 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2454 $current_y = $pdf->getY();
2456 if ($current_y < $pdf->getY()) {
2457 $top_shift = $pdf->getY() - $current_y;
2462 $carac_emetteur =
'';
2464 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2465 if (count($arrayidcontact) > 0) {
2466 $object->fetch_user($arrayidcontact[0]);
2467 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2468 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2469 $carac_emetteur .=
"\n";
2476 $posy += $top_shift;
2477 $posx = $this->marge_gauche;
2479 $posx = $this->page_largeur - $this->marge_droite - 80;
2487 $pdf->SetTextColor(0, 0, 0);
2488 $pdf->SetFont(
'',
'', $default_font_size - 2);
2489 $pdf->SetXY($posx, $posy - 5);
2490 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2491 $pdf->SetXY($posx, $posy);
2492 $pdf->SetFillColor(230, 230, 230);
2493 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'F');
2494 $pdf->SetTextColor(0, 0, 60);
2499 $pdf->SetXY($posx + 2, $posy + 3);
2500 $pdf->SetFont(
'',
'B', $default_font_size);
2501 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2502 $posy = $pdf->getY();
2506 $pdf->SetXY($posx + 2, $posy);
2507 $pdf->SetFont(
'',
'', $default_font_size - 1);
2508 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2511 $usecontact =
false;
2512 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2513 if (count($arrayidcontact) > 0) {
2515 $result =
$object->fetch_contact($arrayidcontact[0]);
2519 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset(
$conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2520 $thirdparty =
$object->contact;
2522 $thirdparty =
$object->thirdparty;
2532 if ($this->page_largeur < 210) {
2536 $posy += $top_shift;
2537 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2539 $posx = $this->marge_gauche;
2544 $pdf->SetTextColor(0, 0, 0);
2545 $pdf->SetFont(
'',
'', $default_font_size - 2);
2546 $pdf->SetXY($posx + 2, $posy - 5);
2547 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2548 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2552 $pdf->SetXY($posx + 2, $posy + 3);
2553 $pdf->SetFont(
'',
'B', $default_font_size);
2555 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2557 $posy = $pdf->getY();
2560 $pdf->SetFont(
'',
'', $default_font_size - 1);
2561 $pdf->SetXY($posx + 2, $posy);
2563 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2567 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2569 if (!empty($idaddressshipping)) {
2570 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2571 $companystatic =
new Societe($this->db);
2572 $companystatic->fetch(
$object->contact->fk_soc);
2574 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic,
$object->contact, ($usecontact ? 1 : 0),
'target',
$object);
2579 if (!empty($carac_client_shipping)) {
2580 $posy += $hautcadre;
2585 $pdf->SetXY($posx + 2, $posy - 5);
2586 $pdf->SetFont(
'',
'', $default_font_size - 2);
2587 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2588 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
2591 $pdf->SetXY($posx + 2, $posy + 3);
2592 $pdf->SetFont(
'',
'B', $default_font_size);
2593 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2595 $posy = $pdf->getY();
2598 $pdf->SetXY($posx + 2, $posy);
2599 $pdf->SetFont(
'',
'', $default_font_size - 1);
2600 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2602 $shipp_shift += $hautcadre + 10;
2607 $pdf->SetTextColor(0, 0, 0);
2609 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);