34 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
35 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
64 public $update_main_doc_field;
75 public $phpmin = array(5, 6);
81 public $version =
'dolibarr';
101 public $marge_gauche;
106 public $marge_droite;
127 public $situationinvoice;
143 global $conf, $langs, $mysoc;
146 $langs->loadLangs(array(
"main",
"bills"));
149 $this->
name =
"sponge";
150 $this->
description = $langs->trans(
'PDFSpongeDescription');
151 $this->update_main_doc_field = 1;
156 $this->page_largeur = $formatarray[
'width'];
157 $this->page_hauteur = $formatarray[
'height'];
158 $this->format = array($this->page_largeur, $this->page_hauteur);
159 $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
160 $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
161 $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
162 $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
164 $this->option_logo = 1;
165 $this->option_tva = 1;
166 $this->option_modereg = 1;
167 $this->option_condreg = 1;
168 $this->option_multilang = 1;
169 $this->option_escompte = 1;
170 $this->option_credit_note = 1;
171 $this->option_freetext = 1;
172 $this->option_draft_watermark = 1;
173 $this->watermark =
'';
176 $this->emetteur = $mysoc;
177 if (empty($this->emetteur->country_code)) {
178 $this->emetteur->country_code = substr($langs->defaultlang, -2);
182 $this->posxdesc = $this->marge_gauche + 1;
185 $this->tabTitleHeight = 5;
189 $this->tva = array();
190 $this->tva_array = array();
191 $this->localtax1 = array();
192 $this->localtax2 = array();
193 $this->atleastoneratenotnull = 0;
194 $this->atleastonediscount = 0;
195 $this->situationinvoice =
false;
211 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
214 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
216 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
218 if (!is_object($outputlangs)) {
219 $outputlangs = $langs;
222 if (!empty($conf->global->MAIN_USE_FPDF)) {
223 $outputlangs->charset_output =
'ISO-8859-1';
227 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
229 global $outputlangsbis;
230 $outputlangsbis =
null;
231 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
232 $outputlangsbis =
new Translate(
'', $conf);
233 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
234 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
238 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
239 $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
242 $nblines = count($object->lines);
245 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
246 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
250 $realpatharray = array();
251 $this->atleastonephoto =
false;
252 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
255 for ($i = 0; $i < $nblines; $i++) {
256 if (empty($object->lines[$i]->fk_product)) {
260 $objphoto->fetch($object->lines[$i]->fk_product);
262 if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
263 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
264 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
266 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
267 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
271 foreach ($pdir as $midir) {
273 if ($conf->entity != $objphoto->entity) {
274 $dir = $conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
276 $dir = $conf->product->dir_output.
'/'.$midir;
279 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
280 if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) {
281 if ($obj[
'photo_vignette']) {
282 $filename = $obj[
'photo_vignette'];
284 $filename = $obj[
'photo'];
287 $filename = $obj[
'photo'];
290 $realpath = $dir.$filename;
292 $this->atleastonephoto =
true;
297 if ($realpath && $arephoto) {
298 $realpatharray[$i] = $realpath;
305 if ($conf->facture->multidir_output[$conf->entity]) {
306 $object->fetch_thirdparty();
308 $deja_regle = $object->getSommePaiement((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
309 $amount_credit_notes_included = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
310 $amount_deposits_included = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
313 if ($object->specimen) {
314 $dir = $conf->facture->multidir_output[$conf->entity];
315 $file = $dir.
"/SPECIMEN.pdf";
318 $dir = $conf->facture->multidir_output[$object->entity].
"/".$objectref;
319 $file = $dir.
"/".$objectref.
".pdf";
321 if (!file_exists($dir)) {
323 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
328 if (file_exists($dir)) {
330 if (!is_object($hookmanager)) {
331 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
334 $hookmanager->initHooks(array(
'pdfgeneration'));
335 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
337 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
340 $nblines = count($object->lines);
341 $nbpayments = count($object->getListOfPayments());
346 $pdf->SetAutoPageBreak(1, 0);
348 $heightforinfotot = 50 + (4 * $nbpayments);
349 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
350 $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
352 if (class_exists(
'TCPDF')) {
353 $pdf->setPrintHeader(
false);
354 $pdf->setPrintFooter(
false);
359 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
360 $logodir = $conf->mycompany->dir_output;
361 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
362 $logodir = $conf->mycompany->multidir_output[$object->entity];
364 $pagecount = $pdf->setSourceFile($logodir.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
365 $tplidx = $pdf->importPage(1);
370 $pdf->SetDrawColor(128, 128, 128);
372 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
373 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
374 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
375 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
376 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
377 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
378 $pdf->SetCompression(
false);
382 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
383 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
386 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
389 $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ?
'' : $conf->global->CERTIFICATE_CRT_PRIVATE;
394 'Name' => $this->emetteur->name,
395 'Location' =>
getCountry($this->emetteur->country_code, 0),
396 'Reason' =>
'INVOICE',
397 'ContactInfo' => $this->emetteur->email
399 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
402 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
405 for ($i = 0; $i < $nblines; $i++) {
406 if ($object->lines[$i]->remise_percent) {
407 $this->atleastonediscount++;
413 if ($object->situation_cycle_ref) {
414 $this->situationinvoice =
true;
419 if (!empty($tplidx)) {
420 $pdf->useTemplate($tplidx);
425 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
426 $pdf->SetFont(
'',
'', $default_font_size - 1);
427 $pdf->MultiCell(0, 3,
'');
428 $pdf->SetTextColor(0, 0, 0);
433 $tab_top = 90 + $top_shift;
434 $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
437 $extra_under_address_shift = 0;
439 if (! empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
440 $qrcodestring = $object->buildZATCAQRString();
441 } elseif (! empty($conf->global->INVOICE_ADD_SWISS_QR_CODE)) {
442 $qrcodestring = $object->buildSwitzerlandQRString();
445 $qrcodecolor = array(
'25',
'25',
'25');
450 'fgcolor' => $qrcodecolor,
455 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr,
'N');
456 $extra_under_address_shift += 25;
464 'outputlangs' => $outputlangs,
465 'hidedetails' => $hidedetails
467 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
468 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
469 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_header_shift'];
472 $tab_top += $extra_under_address_shift;
473 $tab_top_newpage += 0;
477 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
479 $nexY = $tab_top - 1;
482 $height_incoterms = 0;
483 if (!empty($conf->incoterm->enabled)) {
484 $desc_incoterms = $object->getIncotermsForPDF();
485 if ($desc_incoterms) {
488 $pdf->SetFont(
'',
'', $default_font_size - 1);
489 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
490 $nexY = max($pdf->GetY(), $nexY);
491 $height_incoterms = $nexY - $tab_top;
494 $pdf->SetDrawColor(192, 192, 192);
495 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
497 $tab_top = $nexY + 6;
498 $height_incoterms += 4;
503 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
504 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
506 if (is_object($object->thirdparty)) {
507 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
508 $salerepobj =
new User($this->
db);
509 $salerepobj->fetch($salereparray[0][
'id']);
510 if (!empty($salerepobj->signature)) {
511 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
517 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
518 if (!empty($extranote)) {
522 $pagenb = $pdf->getPage();
526 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
527 $pageposbeforenote = $pagenb;
534 $pdf->startTransaction();
536 $pdf->SetFont(
'',
'', $default_font_size - 1);
537 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
539 $pageposafternote = $pdf->getPage();
540 $posyafter = $pdf->GetY();
542 if ($pageposafternote > $pageposbeforenote) {
543 $pdf->rollbackTransaction(
true);
546 while ($pagenb < $pageposafternote) {
549 if (!empty($tplidx)) {
550 $pdf->useTemplate($tplidx);
552 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
553 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
556 $pdf->setTopMargin($tab_top_newpage);
558 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
562 $pdf->setPage($pageposbeforenote);
563 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
564 $pdf->SetFont(
'',
'', $default_font_size - 1);
565 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
566 $pageposafternote = $pdf->getPage();
568 $posyafter = $pdf->GetY();
570 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
571 $pdf->AddPage(
'',
'',
true);
574 $pdf->setPage($pageposafternote);
575 $pdf->setTopMargin($tab_top_newpage);
577 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
583 $i = $pageposbeforenote;
584 while ($i < $pageposafternote) {
588 $pdf->SetDrawColor(128, 128, 128);
590 if ($i > $pageposbeforenote) {
591 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
592 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
594 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
595 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
599 $pdf->setPageOrientation(
'', 1, 0);
600 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
606 $pdf->setPage($pageposafternote);
607 if (!empty($tplidx)) {
608 $pdf->useTemplate($tplidx);
610 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
611 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
613 $height_note = $posyafter - $tab_top_newpage;
614 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
617 $pdf->commitTransaction();
618 $posyafter = $pdf->GetY();
619 $height_note = $posyafter - $tab_top;
620 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
623 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
625 $pdf->AddPage(
'',
'',
true);
628 $pdf->setPage($pageposafternote);
629 if (!empty($tplidx)) {
630 $pdf->useTemplate($tplidx);
632 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
633 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
636 $posyafter = $tab_top_newpage;
640 $tab_height = $tab_height - $height_note;
641 $tab_top = $posyafter + 6;
650 $pdf->startTransaction();
651 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
652 $pdf->rollbackTransaction(
true);
654 $nexY = $tab_top + $this->tabTitleHeight;
657 $pageposbeforeprintlines = $pdf->getPage();
658 $pagenb = $pageposbeforeprintlines;
659 for ($i = 0; $i < $nblines; $i++) {
661 $pdf->SetFont(
'',
'', $default_font_size - 1);
662 $pdf->SetTextColor(0, 0, 0);
665 $imglinesize = array();
666 if (!empty($realpatharray[$i])) {
670 $pdf->setTopMargin($tab_top_newpage);
671 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
672 $pageposbefore = $pdf->getPage();
674 $showpricebeforepagebreak = 1;
676 $posYAfterDescription = 0;
680 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
681 $pdf->AddPage(
'',
'',
true);
682 if (!empty($tplidx)) {
683 $pdf->useTemplate($tplidx);
685 $pdf->setPage($pageposbefore + 1);
687 $curY = $tab_top_newpage;
690 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
691 $showpricebeforepagebreak = 1;
693 $showpricebeforepagebreak = 0;
697 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
698 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
700 $posYAfterImage = $curY + $imglinesize[
'height'];
706 $pdf->startTransaction();
708 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
709 $pageposafter = $pdf->getPage();
711 if ($pageposafter > $pageposbefore) {
712 $pdf->rollbackTransaction(
true);
713 $pageposafter = $pageposbefore;
714 $pdf->setPageOrientation(
'', 1, $heightforfooter);
716 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
718 $pageposafter = $pdf->getPage();
719 $posyafter = $pdf->GetY();
721 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
722 if ($i == ($nblines - 1)) {
723 $pdf->AddPage(
'',
'',
true);
724 if (!empty($tplidx)) {
725 $pdf->useTemplate($tplidx);
727 $pdf->setPage($pageposafter + 1);
732 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
733 $showpricebeforepagebreak = 1;
735 $showpricebeforepagebreak = 0;
740 $pdf->commitTransaction();
742 $posYAfterDescription = $pdf->GetY();
745 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
747 $pageposafter = $pdf->getPage();
748 $pdf->setPage($pageposbefore);
749 $pdf->setTopMargin($this->marge_haute);
750 $pdf->setPageOrientation(
'', 1, 0);
753 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
754 $pdf->setPage($pageposafter);
755 $curY = $tab_top_newpage;
758 $pdf->SetFont(
'',
'', $default_font_size - 1);
764 $nexY = max($pdf->GetY(), $nexY);
771 $nexY = max($pdf->GetY(), $nexY);
779 $nexY = max($pdf->GetY(), $nexY);
786 $nexY = max($pdf->GetY(), $nexY);
791 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
793 $nexY = max($pdf->GetY(), $nexY);
797 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
800 $nexY = max($pdf->GetY(), $nexY);
807 $nexY = max($pdf->GetY(), $nexY);
814 $nexY = max($pdf->GetY(), $nexY);
818 if (!empty($object->lines[$i]->array_options)) {
819 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
821 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
823 $nexY = max($pdf->GetY(), $nexY);
835 'outputlangs' => $outputlangs,
836 'hidedetails' => $hidedetails
838 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
842 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
846 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
847 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
848 if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
849 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
851 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
854 if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
855 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
857 $tvaligne = $sign * $object->lines[$i]->total_tva;
861 $localtax1ligne = $object->lines[$i]->total_localtax1;
862 $localtax2ligne = $object->lines[$i]->total_localtax2;
863 $localtax1_rate = $object->lines[$i]->localtax1_tx;
864 $localtax2_rate = $object->lines[$i]->localtax2_tx;
865 $localtax1_type = $object->lines[$i]->localtax1_type;
866 $localtax2_type = $object->lines[$i]->localtax2_type;
868 if ($object->remise_percent) {
869 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
871 if ($object->remise_percent) {
872 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
874 if ($object->remise_percent) {
875 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
878 $vatrate = (string) $object->lines[$i]->tva_tx;
881 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
882 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
884 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
885 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
889 if ($localtax1_type && $localtax1ligne != 0) {
890 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
892 if ($localtax2_type && $localtax2ligne != 0) {
893 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
896 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
901 if (!isset($this->tva[$vatrate])) {
902 $this->tva[$vatrate] = 0;
904 $this->tva[$vatrate] += $tvaligne;
905 $vatcode = $object->lines[$i]->vat_src_code;
906 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
907 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
909 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
911 $nexY = max($nexY, $posYAfterImage);
914 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
915 $pdf->setPage($pageposafter);
916 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
918 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
919 $pdf->SetLineStyle(array(
'dash'=>0));
923 while ($pagenb < $pageposafter) {
924 $pdf->setPage($pagenb);
925 if ($pagenb == $pageposbeforeprintlines) {
926 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
928 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
930 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
932 $pdf->setPage($pagenb);
933 $pdf->setPageOrientation(
'', 1, 0);
934 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
935 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
937 if (!empty($tplidx)) {
938 $pdf->useTemplate($tplidx);
942 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
943 if ($pagenb == $pageposafter) {
944 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
946 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
948 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
951 if (!empty($tplidx)) {
952 $pdf->useTemplate($tplidx);
955 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
956 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
962 if ($pagenb == $pageposbeforeprintlines) {
963 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
964 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
966 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
967 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
971 $posy = $this->
drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
974 $posy = $this->
drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
977 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
982 $this->
_pagefoot($pdf, $object, $outputlangs);
983 if (method_exists($pdf,
'AliasNbPages')) {
984 $pdf->AliasNbPages();
989 $pdf->Output($file,
'F');
992 $hookmanager->initHooks(array(
'pdfgeneration'));
993 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
995 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
997 $this->error = $hookmanager->error;
998 $this->errors = $hookmanager->errors;
1001 if (!empty($conf->global->MAIN_UMASK)) {
1002 @chmod($file, octdec($conf->global->MAIN_UMASK));
1005 $this->result = array(
'fullpath'=>$file);
1009 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1013 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1033 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1038 $tab3_top = $posy + 8;
1041 if ($this->page_largeur < 210) {
1047 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1048 if ($object->type == 2) {
1049 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1052 $pdf->SetFont(
'',
'', $default_font_size - 3);
1053 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1054 $pdf->MultiCell(60, 3, $title, 0,
'L', 0);
1056 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1058 $pdf->SetFont(
'',
'', $default_font_size - 4);
1059 $pdf->SetXY($tab3_posx, $tab3_top);
1060 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
1061 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1062 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
1063 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1064 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
1065 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1066 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
1068 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1072 $pdf->SetFont(
'',
'', $default_font_size - 4);
1076 $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,";
1077 $sql .=
" re.description, re.fk_facture_source,";
1078 $sql .=
" f.type, f.datef";
1079 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1080 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1083 $num = $this->
db->num_rows(
$resql);
1088 $obj = $this->
db->fetch_object(
$resql);
1090 if ($obj->type == 2) {
1091 $text = $outputlangs->transnoentities(
"CreditNote");
1092 } elseif ($obj->type == 3) {
1093 $text = $outputlangs->transnoentities(
"Deposit");
1094 } elseif ($obj->type == 0) {
1095 $text = $outputlangs->transnoentities(
"ExcessReceived");
1097 $text = $outputlangs->transnoentities(
"UnknownType");
1100 $invoice->fetch($obj->fk_facture_source);
1102 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1103 $pdf->MultiCell(20, 3,
dol_print_date($this->
db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1104 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1105 $pdf->MultiCell(20, 3,
price((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1106 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1107 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1108 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1109 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1111 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1116 $this->error = $this->
db->lasterror();
1122 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1124 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1125 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1126 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1128 $sql .=
" ORDER BY p.datep";
1132 $num = $this->
db->num_rows(
$resql);
1136 $row = $this->
db->fetch_object(
$resql);
1138 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1139 $pdf->MultiCell(20, 3,
dol_print_date($this->
db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1140 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1141 $pdf->MultiCell(20, 3,
price($sign * ((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1142 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1143 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1145 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1146 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1147 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1149 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1154 return $tab3_top + $y + 3;
1156 $this->error = $this->
db->lasterror();
1172 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1174 global $conf, $mysoc;
1178 $pdf->SetFont(
'',
'', $default_font_size - 1);
1181 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1182 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1183 $pdf->SetXY($this->marge_gauche, $posy);
1184 if ($mysoc->forme_juridique_code == 92) {
1185 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1187 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1190 $posy = $pdf->GetY() + 4;
1195 if ($this->page_largeur < 210) {
1200 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1201 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1202 $pdf->SetXY($this->marge_gauche, $posy);
1203 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1204 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1206 $pdf->SetFont(
'',
'', $default_font_size - 2);
1207 $pdf->SetXY($posxval, $posy);
1208 $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);
1209 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1210 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1212 $posy = $pdf->GetY() + 3;
1215 if ($object->type != 2) {
1217 if (empty($object->mode_reglement_code)
1218 && empty($conf->global->FACTURE_CHQ_NUMBER)
1219 && empty($conf->global->FACTURE_RIB_NUMBER)) {
1220 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1221 } elseif (($object->mode_reglement_code ==
'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
1222 || ($object->mode_reglement_code ==
'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))) {
1224 $outputlangs->load(
"errors");
1226 $pdf->SetXY($this->marge_gauche, $posy);
1227 $pdf->SetTextColor(200, 0, 0);
1228 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1229 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1230 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L', 0);
1231 $pdf->SetTextColor(0, 0, 0);
1233 $posy = $pdf->GetY() + 1;
1237 if (!empty($object->mode_reglement_code)
1238 && $object->mode_reglement_code !=
'CHQ'
1239 && $object->mode_reglement_code !=
'VIR') {
1240 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1241 $pdf->SetXY($this->marge_gauche, $posy);
1242 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1243 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1245 $pdf->SetFont(
'',
'', $default_font_size - 2);
1246 $pdf->SetXY($posxval, $posy);
1247 $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);
1248 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1250 $posy = $pdf->GetY();
1254 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1255 $useonlinepayment = 0;
1256 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1257 if (!empty($conf->paypal->enabled)) {
1258 $useonlinepayment++;
1260 if (!empty($conf->stripe->enabled)) {
1261 $useonlinepayment++;
1263 if (!empty($conf->paybox->enabled)) {
1264 $useonlinepayment++;
1269 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1272 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1273 $servicename = $langs->transnoentities(
'Online');
1274 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1275 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1277 $pdf->SetXY($this->marge_gauche, $posy);
1278 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
'',
'',
dol_htmlentitiesbr($linktopay), 0, 1);
1280 $posy = $pdf->GetY() + 1;
1285 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1287 if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
1288 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1290 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1292 $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1294 $pdf->SetXY($this->marge_gauche, $posy);
1295 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1296 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1297 $posy = $pdf->GetY() + 1;
1299 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1300 $pdf->SetXY($this->marge_gauche, $posy);
1301 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1302 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1303 $posy = $pdf->GetY() + 2;
1306 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1307 $pdf->SetXY($this->marge_gauche, $posy);
1308 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1309 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1310 $posy = $pdf->GetY() + 1;
1312 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1313 $pdf->SetXY($this->marge_gauche, $posy);
1314 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1315 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1316 $posy = $pdf->GetY() + 2;
1323 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1324 if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) {
1325 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1326 if ($object->fk_bank > 0) {
1327 $bankid = $object->fk_bank;
1330 $account->fetch($bankid);
1332 $curx = $this->marge_gauche;
1335 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1357 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1359 global $conf, $mysoc, $hookmanager;
1362 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1370 if (is_object($outputlangsbis)) {
1371 $pdf->SetFont(
'',
'', $default_font_size - 2);
1373 $pdf->SetFont(
'',
'', $default_font_size - 1);
1379 if ($this->page_largeur < 210) {
1383 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1389 $parameters = array(
1390 'object' => &$object,
1391 'outputlangs' => $outputlangs,
1393 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1398 foreach ($object->lines as $line) {
1399 $percent += $line->situation_percent;
1404 $avancementGlobal = $percent / $i;
1406 $avancementGlobal = 0;
1409 $object->fetchPreviousNextSituationInvoice();
1410 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1413 $total_a_payer_ttc = 0;
1414 foreach ($TPreviousIncoice as &$fac) {
1415 $total_a_payer += $fac->total_ht;
1416 $total_a_payer_ttc += $fac->total_ttc;
1418 $total_a_payer += $object->total_ht;
1419 $total_a_payer_ttc += $object->total_ttc;
1421 if (!empty($avancementGlobal)) {
1422 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1423 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1426 $total_a_payer_ttc = 0;
1430 if (!empty($TPreviousIncoice)) {
1431 $pdf->setY($tab2_top);
1432 $posy = $pdf->GetY();
1434 foreach ($TPreviousIncoice as &$fac) {
1435 if ($posy > $this->page_hauteur - 4) {
1436 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
1438 $pdf->setY($this->marge_haute);
1439 $posy = $pdf->GetY();
1444 $pdf->SetFillColor(255, 255, 255);
1445 $pdf->SetXY($col1x, $posy);
1446 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1448 $pdf->SetXY($col2x, $posy);
1452 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1455 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1457 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1466 $pdf->SetFillColor(255, 255, 255);
1467 $pdf->SetXY($col1x, $posy);
1468 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1470 $pdf->SetXY($col2x, $posy);
1473 $facSign = $object->total_ht >= 0 ?
'+' :
'';
1476 if ($fac->type === facture::TYPE_CREDIT_NOTE) {
1481 $displayAmount =
' '.$facSign.
' '.
price($object->total_ht, 0, $outputlangs);
1482 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1487 $pdf->SetFont(
'',
'', $default_font_size - 1);
1488 $pdf->SetFillColor(255, 255, 255);
1489 $pdf->SetXY($col1x, $posy);
1490 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", $avancementGlobal), 0,
'L', 1);
1492 $pdf->SetXY($col2x, $posy);
1493 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R', 1);
1494 $pdf->SetFont(
'',
'', $default_font_size - 2);
1498 if ($posy > $this->page_hauteur - 4) {
1500 $pdf->setY($this->marge_haute);
1501 $posy = $pdf->GetY();
1512 $total_ht = (!empty($conf->multicurrency->enabled) && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1515 $total_line_remise = 0;
1516 foreach ($object->lines as $i => $line) {
1519 if ($line->total_ht < 0) {
1520 $total_line_remise += -$line->total_ht;
1523 if ($total_line_remise > 0) {
1524 if (!empty($conf->global->MAIN_SHOW_AMOUNT_DISCOUNT)) {
1525 $pdf->SetFillColor(255, 255, 255);
1526 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1527 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L', 1);
1528 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1529 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise, 0, $outputlangs), 0,
'R', 1);
1534 if (!empty($conf->global->MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT)) {
1535 $pdf->SetFillColor(255, 255, 255);
1536 $pdf->SetXY($col1x, $tab2_top + 0);
1537 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L', 1);
1538 $pdf->SetXY($col2x, $tab2_top + 0);
1539 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise + $total_ht, 0, $outputlangs), 0,
'R', 1);
1546 $pdf->SetFillColor(255, 255, 255);
1547 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1548 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ?
"TotalHT" :
"Total").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ?
"TotalHT" :
"Total") :
''), 0,
'L', 1);
1550 $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1551 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1552 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1555 $pdf->SetFillColor(248, 248, 248);
1557 $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1559 $this->atleastoneratenotnull = 0;
1560 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1561 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1562 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1570 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1571 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1575 foreach ($localtax_rate as $tvakey => $tvaval) {
1580 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1583 if (preg_match(
'/\*/', $tvakey)) {
1584 $tvakey = str_replace(
'*',
'', $tvakey);
1585 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1588 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1590 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1591 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1593 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1594 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1602 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1603 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1607 foreach ($localtax_rate as $tvakey => $tvaval) {
1612 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1615 if (preg_match(
'/\*/', $tvakey)) {
1616 $tvakey = str_replace(
'*',
'', $tvakey);
1617 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1619 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1621 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1622 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1624 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1625 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1632 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1634 foreach ($this->tva as $tvakey => $tvaval) {
1635 $sum_pdf_tva += $tvaval;
1638 if ($sum_pdf_tva != $object->total_tva) {
1639 if (!empty($sum_pdf_tva)) {
1640 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1646 foreach ($this->tva as $tvakey => $tvaval) {
1647 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1649 foreach ($this->tva_array as $tvakey => $tvaval) {
1650 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1656 foreach ($this->tva_array as $tvakey => $tvaval) {
1658 $this->atleastoneratenotnull++;
1661 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1664 if (preg_match(
'/\*/', $tvakey)) {
1665 $tvakey = str_replace(
'*',
'', $tvakey);
1666 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1668 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1671 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1673 $totalvat .= ($tvaval[
'vatcode'] ? $tvaval[
'vatcode'] :
vatrate($tvaval[
'vatrate'], 1)).$tvacompl;
1675 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1677 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1679 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1680 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1687 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1688 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1692 foreach ($localtax_rate as $tvakey => $tvaval) {
1697 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1700 if (preg_match(
'/\*/', $tvakey)) {
1701 $tvakey = str_replace(
'*',
'', $tvakey);
1702 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1704 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1706 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1708 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1709 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1710 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1718 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1719 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1723 foreach ($localtax_rate as $tvakey => $tvaval) {
1729 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1732 if (preg_match(
'/\*/', $tvakey)) {
1733 $tvakey = str_replace(
'*',
'', $tvakey);
1734 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1736 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1739 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1740 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1742 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1743 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1750 if (
price2num($object->revenuestamp) != 0) {
1752 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1753 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L', 1);
1755 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1756 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1761 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1762 $pdf->SetTextColor(0, 0, 60);
1763 $pdf->SetFillColor(224, 224, 224);
1764 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
1766 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1767 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1771 if ($object->displayRetainedWarranty()) {
1772 $pdf->SetTextColor(40, 40, 40);
1773 $pdf->SetFillColor(255, 255, 255);
1775 $retainedWarranty = $object->getRetainedWarrantyAmount();
1776 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1780 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1781 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1783 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1784 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1788 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1790 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.$object->retained_warranty.
'%)';
1791 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1793 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1794 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1795 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1800 $pdf->SetTextColor(0, 0, 0);
1802 $creditnoteamount = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
1803 $depositsamount = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
1805 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1806 if (!empty($object->paye)) {
1810 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1813 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1814 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L', 0);
1815 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1816 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1819 if ($creditnoteamount) {
1820 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1821 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes")) :
'');
1823 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1824 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1825 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1826 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1845 $pdf->SetTextColor(0, 0, 60);
1846 $pdf->SetFillColor(224, 224, 224);
1847 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1848 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1849 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1850 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1852 $pdf->SetFont(
'',
'', $default_font_size - 1);
1853 $pdf->SetTextColor(0, 0, 0);
1857 return ($tab2_top + ($tab2_hl * $index));
1871 return parent::liste_modeles($db, $maxfilenamelength);
1889 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
1899 $currency = !empty($currency) ? $currency : $conf->currency;
1903 $pdf->SetTextColor(0, 0, 0);
1904 $pdf->SetFont(
'',
'', $default_font_size - 2);
1906 if (empty($hidetop)) {
1907 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1908 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1909 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
1912 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1913 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1916 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1917 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1921 $pdf->SetDrawColor(128, 128, 128);
1922 $pdf->SetFont(
'',
'', $default_font_size - 1);
1925 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1928 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
1930 if (empty($hidetop)) {
1931 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
1946 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
1948 global $conf, $langs;
1950 $ltrdirection =
'L';
1951 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1954 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
1960 $pdf->SetTextColor(0, 0, 60);
1961 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1965 $posy = $this->marge_haute;
1966 $posx = $this->page_largeur - $this->marge_droite - $w;
1968 $pdf->SetXY($this->marge_gauche, $posy);
1971 if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
1972 if ($this->emetteur->logo) {
1973 $logodir = $conf->mycompany->dir_output;
1974 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1975 $logodir = $conf->mycompany->multidir_output[$object->entity];
1977 if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
1978 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1980 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1982 if (is_readable($logo)) {
1984 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1986 $pdf->SetTextColor(200, 0, 0);
1987 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1988 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1989 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1992 $text = $this->emetteur->name;
1993 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1997 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1998 $pdf->SetXY($posx, $posy);
1999 $pdf->SetTextColor(0, 0, 60);
2000 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2001 if ($object->type == 1) {
2002 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2004 if ($object->type == 2) {
2005 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2007 if ($object->type == 3) {
2008 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2010 if ($object->type == 4) {
2011 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2013 if ($this->situationinvoice) {
2014 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation");
2016 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2018 if ($object->type == 0) {
2019 if ($this->situationinvoice) {
2020 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2022 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2023 } elseif ($object->type == 1) {
2024 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2025 } elseif ($object->type == 2) {
2026 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2027 } elseif ($object->type == 3) {
2028 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2029 } elseif ($object->type == 4) {
2030 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2033 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
2034 if ($object->statut == $object::STATUS_DRAFT) {
2035 $pdf->SetTextColor(128, 0, 0);
2036 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2039 $pdf->MultiCell($w, 3, $title,
'',
'R');
2041 $pdf->SetFont(
'',
'B', $default_font_size);
2055 $pdf->SetFont(
'',
'', $default_font_size - 2);
2057 if ($object->ref_client) {
2059 $pdf->SetXY($posx, $posy);
2060 $pdf->SetTextColor(0, 0, 60);
2061 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65),
'',
'R');
2064 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
2065 $object->fetch_projet();
2066 if (!empty($object->project->ref)) {
2068 $pdf->SetXY($posx, $posy);
2069 $pdf->SetTextColor(0, 0, 60);
2070 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
2074 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
2075 $object->fetch_projet();
2076 if (!empty($object->project->ref)) {
2077 $outputlangs->load(
"projects");
2079 $pdf->SetXY($posx, $posy);
2080 $pdf->SetTextColor(0, 0, 60);
2081 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
2085 $objectidnext = $object->getIdReplacingInvoice(
'validated');
2086 if ($object->type == 0 && $objectidnext) {
2087 $objectreplacing =
new Facture($this->
db);
2088 $objectreplacing->fetch($objectidnext);
2091 $pdf->SetXY($posx, $posy);
2092 $pdf->SetTextColor(0, 0, 60);
2093 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2095 if ($object->type == 1) {
2096 $objectreplaced =
new Facture($this->
db);
2097 $objectreplaced->fetch($object->fk_facture_source);
2100 $pdf->SetXY($posx, $posy);
2101 $pdf->SetTextColor(0, 0, 60);
2102 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2104 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2105 $objectreplaced =
new Facture($this->
db);
2106 $objectreplaced->fetch($object->fk_facture_source);
2109 $pdf->SetXY($posx, $posy);
2110 $pdf->SetTextColor(0, 0, 60);
2111 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2115 $pdf->SetXY($posx, $posy);
2116 $pdf->SetTextColor(0, 0, 60);
2118 $title = $outputlangs->transnoentities(
"DateInvoice");
2119 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2120 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2122 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2124 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2126 $pdf->SetXY($posx, $posy);
2127 $pdf->SetTextColor(0, 0, 60);
2128 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2131 if ($object->type != 2) {
2133 $pdf->SetXY($posx, $posy);
2134 $pdf->SetTextColor(0, 0, 60);
2135 $title = $outputlangs->transnoentities(
"DateDue");
2136 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2137 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2139 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2142 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2144 $pdf->SetXY($posx, $posy);
2145 $pdf->SetTextColor(0, 0, 60);
2146 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2150 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2151 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2152 if (count($arrayidcontact) > 0) {
2153 $usertmp =
new User($this->
db);
2154 $usertmp->fetch($arrayidcontact[0]);
2156 $pdf->SetXY($posx, $posy);
2157 $pdf->SetTextColor(0, 0, 60);
2158 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2166 $current_y = $pdf->getY();
2167 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2168 if ($current_y < $pdf->getY()) {
2169 $top_shift = $pdf->getY() - $current_y;
2174 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2177 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2178 $posy += $top_shift;
2179 $posx = $this->marge_gauche;
2180 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2181 $posx = $this->page_largeur - $this->marge_droite - 80;
2184 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2185 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2189 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2190 $pdf->SetTextColor(0, 0, 0);
2191 $pdf->SetFont(
'',
'', $default_font_size - 2);
2192 $pdf->SetXY($posx, $posy - 5);
2193 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2194 $pdf->SetXY($posx, $posy);
2195 $pdf->SetFillColor(230, 230, 230);
2196 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2197 $pdf->SetTextColor(0, 0, 60);
2201 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2202 $pdf->SetXY($posx + 2, $posy + 3);
2203 $pdf->SetFont(
'',
'B', $default_font_size);
2204 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2205 $posy = $pdf->getY();
2209 $pdf->SetXY($posx + 2, $posy);
2210 $pdf->SetFont(
'',
'', $default_font_size - 1);
2211 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2214 $usecontact =
false;
2215 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2216 if (count($arrayidcontact) > 0) {
2218 $result = $object->fetch_contact($arrayidcontact[0]);
2222 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
2223 $thirdparty = $object->contact;
2225 $thirdparty = $object->thirdparty;
2231 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2234 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2235 if ($this->page_largeur < 210) {
2238 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2239 $posy += $top_shift;
2240 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2241 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2242 $posx = $this->marge_gauche;
2246 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2247 $pdf->SetTextColor(0, 0, 0);
2248 $pdf->SetFont(
'',
'', $default_font_size - 2);
2249 $pdf->SetXY($posx + 2, $posy - 5);
2250 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2251 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2255 $pdf->SetXY($posx + 2, $posy + 3);
2256 $pdf->SetFont(
'',
'B', $default_font_size);
2257 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2259 $posy = $pdf->getY();
2262 $pdf->SetFont(
'',
'', $default_font_size - 1);
2263 $pdf->SetXY($posx + 2, $posy);
2264 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2267 $pdf->SetTextColor(0, 0, 0);
2281 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2284 $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
2285 return pdf_pagefoot($pdf, $outputlangs,
'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
2298 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2300 global $conf, $hookmanager;
2303 $this->defaultContentsFieldsStyle = array(
2305 'padding' => array(1, 0.5, 1, 0.5),
2309 $this->defaultTitlesFieldsStyle = array(
2311 'padding' => array(0.5, 0, 0.5, 0),
2333 $this->cols[
'desc'] = array(
2338 'textkey' =>
'Designation',
2342 'padding' => array(0.5, 0.5, 0.5, 0.5),
2346 'padding' => array(1, 0.5, 1, 1.5),
2352 $this->cols[
'photo'] = array(
2354 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
2357 'textkey' =>
'Photo',
2361 'padding' => array(0, 0, 0, 0),
2363 'border-left' =>
false,
2366 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
2367 $this->cols[
'photo'][
'status'] =
true;
2372 $this->cols[
'vat'] = array(
2379 'border-left' =>
true,
2382 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
2383 $this->cols[
'vat'][
'status'] =
true;
2387 $this->cols[
'subprice'] = array(
2392 'textkey' =>
'PriceUHT'
2394 'border-left' =>
true,
2399 $nblines = count($object->lines);
2400 for ($i = 0; $i < $nblines; $i++) {
2402 $tmpwidth = max($tmpwidth, $tmpwidth2);
2404 if ($tmpwidth > 10) {
2405 $this->cols[
'subprice'][
'width'] += (2 * ($tmpwidth - 10));
2409 $this->cols[
'qty'] = array(
2416 'border-left' =>
true,
2420 $this->cols[
'progress'] = array(
2425 'textkey' =>
'Progress'
2427 'border-left' =>
true,
2430 if ($this->situationinvoice) {
2431 $this->cols[
'progress'][
'status'] =
true;
2435 $this->cols[
'unit'] = array(
2442 'border-left' =>
true,
2444 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
2445 $this->cols[
'unit'][
'status'] =
true;
2449 $this->cols[
'discount'] = array(
2454 'textkey' =>
'ReductionShort'
2456 'border-left' =>
true,
2458 if ($this->atleastonediscount) {
2459 $this->cols[
'discount'][
'status'] =
true;
2462 $rank = $rank + 1000;
2463 $this->cols[
'totalexcltax'] = array(
2466 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ?
true :
false,
2468 'textkey' =>
'TotalHT'
2470 'border-left' =>
true,
2473 $rank = $rank + 1010;
2474 $this->cols[
'totalincltax'] = array(
2477 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ?
false :
true,
2479 'textkey' =>
'TotalTTC'
2481 'border-left' =>
true,
2485 if (!empty($object->lines)) {
2486 $line = reset($object->lines);
2490 $parameters = array(
2491 'object' => $object,
2492 'outputlangs' => $outputlangs,
2493 'hidedetails' => $hidedetails,
2494 'hidedesc' => $hidedesc,
2495 'hideref' => $hideref
2498 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
2501 } elseif (empty($reshook)) {
2502 $this->cols = array_replace($this->cols, $hookmanager->resArray);
2504 $this->cols = $hookmanager->resArray;