36 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
37 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
66 public $update_main_doc_field;
77 public $version =
'dolibarr';
102 public $marge_droite;
118 public $heightforinfotot;
123 public $heightforfreetext;
128 public $heightforfooter;
138 public $tab_top_newpage;
149 public $situationinvoice;
160 public $categoryOfOperation = -1;
170 global $conf, $langs, $mysoc;
173 $langs->loadLangs(array(
"main",
"bills"));
176 $this->
name =
"sponge";
177 $this->
description = $langs->trans(
'PDFSpongeDescription');
178 $this->update_main_doc_field = 1;
183 $this->page_largeur = $formatarray[
'width'];
184 $this->page_hauteur = $formatarray[
'height'];
185 $this->format = array($this->page_largeur, $this->page_hauteur);
191 $this->option_logo = 1;
192 $this->option_tva = 1;
193 $this->option_modereg = 1;
194 $this->option_condreg = 1;
195 $this->option_multilang = 1;
196 $this->option_escompte = 1;
197 $this->option_credit_note = 1;
198 $this->option_freetext = 1;
199 $this->option_draft_watermark = 1;
200 $this->watermark =
'';
203 $this->emetteur = $mysoc;
204 if (empty($this->emetteur->country_code)) {
205 $this->emetteur->country_code = substr($langs->defaultlang, -2);
209 $this->posxdesc = $this->marge_gauche + 1;
212 $this->tabTitleHeight = 5;
216 $this->tva = array();
217 $this->tva_array = array();
218 $this->localtax1 = array();
219 $this->localtax2 = array();
220 $this->atleastoneratenotnull = 0;
221 $this->atleastonediscount = 0;
222 $this->situationinvoice =
false;
238 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
241 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
243 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
245 if (!is_object($outputlangs)) {
246 $outputlangs = $langs;
249 if (!empty($conf->global->MAIN_USE_FPDF)) {
250 $outputlangs->charset_output =
'ISO-8859-1';
254 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
256 global $outputlangsbis;
257 $outputlangsbis =
null;
258 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
259 $outputlangsbis =
new Translate(
'', $conf);
260 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
261 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
265 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
266 $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
269 $nblines = count($object->lines);
272 if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
273 $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
277 $realpatharray = array();
278 $this->atleastonephoto =
false;
279 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
280 $objphoto =
new Product($this->db);
282 for ($i = 0; $i < $nblines; $i++) {
283 if (empty($object->lines[$i]->fk_product)) {
287 $objphoto->fetch($object->lines[$i]->fk_product);
290 $pdir[0] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
291 $pdir[1] =
get_exdir(0, 0, 0, 0, $objphoto,
'product').dol_sanitizeFileName($objphoto->ref).
'/';
293 $pdir[0] =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
294 $pdir[1] =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$objphoto->id.
"/photos/";
298 foreach ($pdir as $midir) {
300 if ($conf->entity != $objphoto->entity) {
301 $dir = $conf->product->multidir_output[$objphoto->entity].
'/'.$midir;
303 $dir = $conf->product->dir_output.
'/'.$midir;
306 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
308 if ($obj[
'photo_vignette']) {
309 $filename = $obj[
'photo_vignette'];
311 $filename = $obj[
'photo'];
314 $filename = $obj[
'photo'];
317 $realpath = $dir.$filename;
319 $this->atleastonephoto =
true;
324 if ($realpath && $arephoto) {
325 $realpatharray[$i] = $realpath;
332 if ($conf->facture->multidir_output[$conf->entity]) {
333 $object->fetch_thirdparty();
335 $deja_regle = $object->getSommePaiement((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
336 $amount_credit_notes_included = $object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
337 $amount_deposits_included = $object->getSumDepositsUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
340 if ($object->specimen) {
341 $dir = $conf->facture->multidir_output[$conf->entity];
342 $file = $dir.
"/SPECIMEN.pdf";
345 $dir = $conf->facture->multidir_output[$object->entity].
"/".$objectref;
346 $file = $dir.
"/".$objectref.
".pdf";
348 if (!file_exists($dir)) {
350 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
355 if (file_exists($dir)) {
357 if (!is_object($hookmanager)) {
358 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
361 $hookmanager->initHooks(array(
'pdfgeneration'));
362 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
364 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
367 $nblines = count($object->lines);
368 $nbpayments = count($object->getListOfPayments());
373 $pdf->SetAutoPageBreak(1, 0);
375 $this->heightforinfotot = 50 + (4 * $nbpayments);
376 $this->heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
377 $this->heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22);
379 $heightforqrinvoice = $heightforqrinvoice_firstpage = 0;
383 $this->heightforinfotot = 30 + (4 * $nbpayments);
387 if (class_exists(
'TCPDF')) {
388 $pdf->setPrintHeader(
false);
389 $pdf->setPrintFooter(
false);
394 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
395 $logodir = $conf->mycompany->dir_output;
396 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
397 $logodir = $conf->mycompany->multidir_output[$object->entity];
399 $pagecount = $pdf->setSourceFile($logodir.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
400 $tplidx = $pdf->importPage(1);
405 $pdf->SetDrawColor(128, 128, 128);
407 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
408 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
409 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
410 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
411 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
413 $pdf->SetCompression(
false);
417 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
418 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
421 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
424 $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ?
'' : $conf->global->CERTIFICATE_CRT_PRIVATE;
429 'Name' => $this->emetteur->name,
430 'Location' =>
getCountry($this->emetteur->country_code, 0),
431 'Reason' =>
'INVOICE',
432 'ContactInfo' => $this->emetteur->email
434 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
437 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
441 $categoryOfOperation = 0;
444 for ($i = 0; $i < $nblines; $i++) {
445 if ($object->lines[$i]->remise_percent) {
446 $this->atleastonediscount++;
450 if ($categoryOfOperation < 2) {
451 $lineProductType = $object->lines[$i]->product_type;
457 if ($nbProduct > 0 && $nbService > 0) {
459 $categoryOfOperation = 2;
464 if ($categoryOfOperation <= 0) {
466 if ($nbProduct == 0 && $nbService > 0) {
467 $categoryOfOperation = 1;
470 $this->categoryOfOperation = $categoryOfOperation;
473 if ($object->situation_cycle_ref) {
474 $this->situationinvoice =
true;
479 if (!empty($tplidx)) {
480 $pdf->useTemplate($tplidx);
485 $pagehead = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
486 $top_shift = $pagehead[
'top_shift'];
487 $shipp_shift = $pagehead[
'shipp_shift'];
488 $pdf->SetFont(
'',
'', $default_font_size - 1);
489 $pdf->MultiCell(0, 3,
'');
490 $pdf->SetTextColor(0, 0, 0);
495 $this->tab_top = 90 + $top_shift + $shipp_shift;
496 $this->tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
499 $extra_under_address_shift = 0;
501 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
502 $qrcodestring = $object->buildZATCAQRString();
504 $qrcodestring = $object->buildSwitzerlandQRString();
507 $qrcodecolor = array(
'25',
'25',
'25');
512 'fgcolor' => $qrcodecolor,
517 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr,
'N');
518 $extra_under_address_shift += 25;
526 'outputlangs' => $outputlangs,
527 'hidedetails' => $hidedetails
529 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
530 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
531 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_header_shift'];
534 $this->tab_top += $extra_under_address_shift;
535 $this->tab_top_newpage += 0;
539 $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->
getHeightForQRInvoice(1, $object, $langs);
541 $nexY = $this->tab_top - 1;
544 $height_incoterms = 0;
546 $desc_incoterms = $object->getIncotermsForPDF();
547 if ($desc_incoterms) {
550 $pdf->SetFont(
'',
'', $default_font_size - 1);
551 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
552 $nexY = max($pdf->GetY(), $nexY);
553 $height_incoterms = $nexY - $this->tab_top;
556 $pdf->SetDrawColor(192, 192, 192);
557 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
559 $this->tab_top = $nexY + 6;
560 $height_incoterms += 4;
565 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
566 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
568 if (is_object($object->thirdparty)) {
569 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
570 $salerepobj =
new User($this->db);
571 $salerepobj->fetch($salereparray[0][
'id']);
572 if (!empty($salerepobj->signature)) {
573 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
579 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
580 if (!empty($extranote)) {
584 $pagenb = $pdf->getPage();
588 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
589 $pageposbeforenote = $pagenb;
596 $pdf->startTransaction();
598 $pdf->SetFont(
'',
'', $default_font_size - 1);
599 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
601 $pageposafternote = $pdf->getPage();
602 $posyafter = $pdf->GetY();
604 if ($pageposafternote > $pageposbeforenote) {
605 $pdf->rollbackTransaction(
true);
608 while ($pagenb < $pageposafternote) {
611 if (!empty($tplidx)) {
612 $pdf->useTemplate($tplidx);
615 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
617 $pdf->setTopMargin($this->tab_top_newpage);
619 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
623 $pdf->setPage($pageposbeforenote);
624 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
625 $pdf->SetFont(
'',
'', $default_font_size - 1);
626 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top,
dol_htmlentitiesbr($notetoshow), 0, 1);
627 $pageposafternote = $pdf->getPage();
629 $posyafter = $pdf->GetY();
631 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
632 $pdf->AddPage(
'',
'',
true);
635 $pdf->setPage($pageposafternote);
636 $pdf->setTopMargin($this->tab_top_newpage);
638 $pdf->setPageOrientation(
'', 1, $this->heightforfooter + $this->heightforfreetext);
644 $i = $pageposbeforenote;
645 while ($i < $pageposafternote) {
649 $pdf->SetDrawColor(128, 128, 128);
651 if ($i > $pageposbeforenote) {
652 $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
653 $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
655 $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
656 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
660 $pdf->setPageOrientation(
'', 1, 0);
667 $pdf->setPage($pageposafternote);
668 if (!empty($tplidx)) {
669 $pdf->useTemplate($tplidx);
672 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
674 $height_note = $posyafter - $this->tab_top_newpage;
675 $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
678 $pdf->commitTransaction();
679 $posyafter = $pdf->GetY();
680 $height_note = $posyafter - $this->tab_top;
681 $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
684 if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
686 $pdf->AddPage(
'',
'',
true);
689 $pdf->setPage($pageposafternote);
690 if (!empty($tplidx)) {
691 $pdf->useTemplate($tplidx);
694 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
697 $posyafter = $this->tab_top_newpage;
701 $tab_height = $tab_height - $height_note;
702 $this->tab_top = $posyafter + 6;
711 $pdf->startTransaction();
712 $this->
pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
713 $pdf->rollbackTransaction(
true);
715 $nexY = $this->tab_top + $this->tabTitleHeight;
718 $pageposbeforeprintlines = $pdf->getPage();
719 $pagenb = $pageposbeforeprintlines;
720 for ($i = 0; $i < $nblines; $i++) {
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 $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(), $object, $langs);
733 $pdf->setPageOrientation(
'', 1, $page_bottom_margin);
734 $pageposbefore = $pdf->getPage();
736 $showpricebeforepagebreak = 1;
738 $posYAfterDescription = 0;
742 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
743 $pdf->AddPage(
'',
'',
true);
744 if (!empty($tplidx)) {
745 $pdf->useTemplate($tplidx);
747 $pdf->setPage($pageposbefore + 1);
749 $curY = $this->tab_top_newpage;
752 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
753 $showpricebeforepagebreak = 1;
755 $showpricebeforepagebreak = 0;
759 if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
760 $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
762 $posYAfterImage = $curY + $imglinesize[
'height'];
768 $pdf->startTransaction();
770 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
771 $pageposafter = $pdf->getPage();
773 if ($pageposafter > $pageposbefore) {
774 $pdf->rollbackTransaction(
true);
775 $pageposafter = $pageposbefore;
776 $pdf->setPageOrientation(
'', 1, $this->heightforfooter);
778 $this->
printColDescContent($pdf, $curY,
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
780 $pageposafter = $pdf->getPage();
781 $posyafter = $pdf->GetY();
783 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
784 if ($i == ($nblines - 1)) {
785 $pdf->AddPage(
'',
'',
true);
786 if (!empty($tplidx)) {
787 $pdf->useTemplate($tplidx);
789 $pdf->setPage($pageposafter + 1);
794 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
795 $showpricebeforepagebreak = 1;
797 $showpricebeforepagebreak = 0;
802 $pdf->commitTransaction();
804 $posYAfterDescription = $pdf->GetY();
807 $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
809 $pageposafter = $pdf->getPage();
810 $pdf->setPage($pageposbefore);
811 $pdf->setTopMargin($this->marge_haute);
812 $pdf->setPageOrientation(
'', 1, 0);
815 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
816 $pdf->setPage($pageposafter);
817 $curY = $this->tab_top_newpage;
820 $pdf->SetFont(
'',
'', $default_font_size - 1);
826 $nexY = max($pdf->GetY(), $nexY);
833 $nexY = max($pdf->GetY(), $nexY);
841 $nexY = max($pdf->GetY(), $nexY);
848 $nexY = max($pdf->GetY(), $nexY);
853 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
855 $nexY = max($pdf->GetY(), $nexY);
859 if ($this->
getColumnStatus(
'discount') && $object->lines[$i]->remise_percent) {
862 $nexY = max($pdf->GetY(), $nexY);
869 $nexY = max($pdf->GetY(), $nexY);
876 $nexY = max($pdf->GetY(), $nexY);
880 if (!empty($object->lines[$i]->array_options)) {
881 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
883 $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
885 $nexY = max($pdf->GetY(), $nexY);
897 'outputlangs' => $outputlangs,
898 'hidedetails' => $hidedetails
900 $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this);
904 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
908 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
909 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
910 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
911 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
913 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
916 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
917 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
919 $tvaligne = $sign * $object->lines[$i]->total_tva;
923 $localtax1ligne = $object->lines[$i]->total_localtax1;
924 $localtax2ligne = $object->lines[$i]->total_localtax2;
925 $localtax1_rate = $object->lines[$i]->localtax1_tx;
926 $localtax2_rate = $object->lines[$i]->localtax2_tx;
927 $localtax1_type = $object->lines[$i]->localtax1_type;
928 $localtax2_type = $object->lines[$i]->localtax2_type;
941 $vatrate = (string) $object->lines[$i]->tva_tx;
944 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
945 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
947 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
948 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
952 if ($localtax1_type && $localtax1ligne != 0) {
953 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
954 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
956 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
959 if ($localtax2_type && $localtax2ligne != 0) {
960 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
961 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
963 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
967 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
972 if (!isset($this->tva[$vatrate])) {
973 $this->tva[$vatrate] = 0;
975 $this->tva[$vatrate] += $tvaligne;
976 $vatcode = $object->lines[$i]->vat_src_code;
977 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
978 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
980 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
982 $nexY = max($nexY, $posYAfterImage);
985 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
986 $pdf->setPage($pageposafter);
987 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
989 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
990 $pdf->SetLineStyle(array(
'dash'=>0));
994 while ($pagenb < $pageposafter) {
995 $pdf->setPage($pagenb);
997 if ($pagenb == $pageposbeforeprintlines) {
998 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1000 $this->
_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
1004 $pdf->setPage($pagenb);
1005 $pdf->setPageOrientation(
'', 1, 0);
1007 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1009 if (!empty($tplidx)) {
1010 $pdf->useTemplate($tplidx);
1014 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
1016 if ($pagenb == $pageposafter) {
1017 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1019 $this->
_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
1024 if (!empty($tplidx)) {
1025 $pdf->useTemplate($tplidx);
1029 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1036 if ($pagenb == $pageposbeforeprintlines) {
1037 $this->
_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
1038 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1040 $this->
_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
1041 $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1045 $posy = $this->
drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1048 $posy = $this->
drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1051 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1057 if (method_exists($pdf,
'AliasNbPages')) {
1058 $pdf->AliasNbPages();
1066 $pdf->Output($file,
'F');
1069 $hookmanager->initHooks(array(
'pdfgeneration'));
1070 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
1072 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
1074 $this->error = $hookmanager->error;
1075 $this->errors = $hookmanager->errors;
1080 $this->result = array(
'fullpath'=>$file);
1084 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
1088 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
1108 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1113 $tab3_top = $posy + 8;
1116 if ($this->page_largeur < 210) {
1122 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1123 if ($object->type == 2) {
1124 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1127 $pdf->SetFont(
'',
'', $default_font_size - 3);
1128 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1129 $pdf->MultiCell(60, 3, $title, 0,
'L', 0);
1131 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1133 $pdf->SetFont(
'',
'', $default_font_size - 4);
1134 $pdf->SetXY($tab3_posx, $tab3_top);
1135 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
1136 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1137 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
1138 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1139 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
1140 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1141 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
1143 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1147 $pdf->SetFont(
'',
'', $default_font_size - 4);
1151 $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,";
1152 $sql .=
" re.description, re.fk_facture_source,";
1153 $sql .=
" f.type, f.datef";
1154 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
1155 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1156 $resql = $this->db->query(
$sql);
1158 $num = $this->db->num_rows($resql);
1160 $invoice =
new Facture($this->db);
1163 $obj = $this->db->fetch_object($resql);
1165 if ($obj->type == 2) {
1166 $text = $outputlangs->transnoentities(
"CreditNote");
1167 } elseif ($obj->type == 3) {
1168 $text = $outputlangs->transnoentities(
"Deposit");
1169 } elseif ($obj->type == 0) {
1170 $text = $outputlangs->transnoentities(
"ExcessReceived");
1172 $text = $outputlangs->transnoentities(
"UnknownType");
1175 $invoice->fetch($obj->fk_facture_source);
1177 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1178 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1179 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1180 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1181 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1182 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1183 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1184 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1186 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1191 $this->error = $this->db->lasterror();
1197 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1199 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1200 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1201 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1203 $sql .=
" ORDER BY p.datep";
1205 $resql = $this->db->query(
$sql);
1207 $num = $this->db->num_rows($resql);
1211 $row = $this->db->fetch_object($resql);
1213 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1214 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1215 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1216 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1217 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1218 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1220 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1221 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1222 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1224 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1229 return $tab3_top + $y + 3;
1231 $this->error = $this->db->lasterror();
1247 protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1249 global $conf, $mysoc;
1253 $pdf->SetFont(
'',
'', $default_font_size - 1);
1256 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1257 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1258 $pdf->SetXY($this->marge_gauche, $posy);
1259 if ($mysoc->forme_juridique_code == 92) {
1260 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1262 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1265 $posy = $pdf->GetY() + 4;
1270 if ($this->page_largeur < 210) {
1275 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1276 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1277 $pdf->SetXY($this->marge_gauche, $posy);
1278 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1279 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0,
'L');
1281 $pdf->SetFont(
'',
'', $default_font_size - 2);
1282 $pdf->SetXY($posxval, $posy);
1283 $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);
1284 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1285 $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0,
'L');
1287 $posy = $pdf->GetY() + 3;
1291 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1292 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1293 $pdf->SetXY($this->marge_gauche, $posy);
1294 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1295 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1297 $pdf->SetFont(
'',
'', $default_font_size - 2);
1298 $pdf->SetXY($posxval, $posy);
1299 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1300 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1302 $posy = $pdf->GetY() + 3;
1305 if ($object->type != 2) {
1307 if (empty($object->mode_reglement_code)
1310 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1311 } elseif (($object->mode_reglement_code ==
'CHQ' && !
getDolGlobalInt(
'FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1312 || ($object->mode_reglement_code ==
'VIR' && !
getDolGlobalInt(
'FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1314 $outputlangs->load(
"errors");
1316 $pdf->SetXY($this->marge_gauche, $posy);
1317 $pdf->SetTextColor(200, 0, 0);
1318 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1319 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1320 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0,
'L', 0);
1321 $pdf->SetTextColor(0, 0, 0);
1323 $posy = $pdf->GetY() + 1;
1327 if (!empty($object->mode_reglement_code)
1328 && $object->mode_reglement_code !=
'CHQ'
1329 && $object->mode_reglement_code !=
'VIR') {
1330 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1331 $pdf->SetXY($this->marge_gauche, $posy);
1332 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1333 $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0,
'L');
1335 $pdf->SetFont(
'',
'', $default_font_size - 2);
1336 $pdf->SetXY($posxval, $posy);
1337 $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);
1340 if ($object->mode_reglement_code ==
"PRE") {
1341 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1343 $bac->fetch(0, $object->thirdparty->id);
1344 $iban= $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1345 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1348 $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0,
'L');
1350 $posy = $pdf->GetY();
1356 if ($this->emetteur->country_code ==
'FR') {
1357 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1358 $pdf->SetXY($this->marge_gauche, $posy);
1359 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1361 $posy = $pdf->GetY() + 1;
1366 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1367 $useonlinepayment = 0;
1368 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1370 $useonlinepayment++;
1373 $useonlinepayment++;
1376 $useonlinepayment++;
1382 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1385 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1386 $servicename = $langs->transnoentities(
'Online');
1387 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1388 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1390 $pdf->SetXY($this->marge_gauche, $posy);
1391 $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5,
'',
'',
dol_htmlentitiesbr($linktopay), 0, 1);
1393 $posy = $pdf->GetY() + 1;
1398 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1401 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1403 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1404 $account =
new Account($this->db);
1407 $pdf->SetXY($this->marge_gauche, $posy);
1408 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1409 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1410 $posy = $pdf->GetY() + 1;
1412 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1413 $pdf->SetXY($this->marge_gauche, $posy);
1414 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1415 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1416 $posy = $pdf->GetY() + 2;
1419 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1420 $pdf->SetXY($this->marge_gauche, $posy);
1421 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1422 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1423 $posy = $pdf->GetY() + 1;
1425 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1426 $pdf->SetXY($this->marge_gauche, $posy);
1427 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1428 $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1429 $posy = $pdf->GetY() + 2;
1436 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1437 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1438 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1439 if ($object->fk_bank > 0) {
1440 $bankid = $object->fk_bank;
1442 $account =
new Account($this->db);
1443 $account->fetch($bankid);
1445 $curx = $this->marge_gauche;
1448 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1470 protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1472 global $conf, $mysoc, $hookmanager;
1475 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1483 if (is_object($outputlangsbis)) {
1484 $pdf->SetFont(
'',
'', $default_font_size - 2);
1486 $pdf->SetFont(
'',
'', $default_font_size - 1);
1492 if ($this->page_largeur < 210) {
1496 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1502 $parameters = array(
1503 'object' => &$object,
1504 'outputlangs' => $outputlangs,
1506 $hookmanager->executeHooks(
'beforePercentCalculation', $parameters, $this);
1511 foreach ($object->lines as $line) {
1512 $percent += $line->situation_percent;
1517 $avancementGlobal = $percent / $i;
1519 $avancementGlobal = 0;
1522 $object->fetchPreviousNextSituationInvoice();
1523 $TPreviousIncoice = $object->tab_previous_situation_invoice;
1526 $total_a_payer_ttc = 0;
1527 foreach ($TPreviousIncoice as &$fac) {
1528 $total_a_payer += $fac->total_ht;
1529 $total_a_payer_ttc += $fac->total_ttc;
1531 $total_a_payer += $object->total_ht;
1532 $total_a_payer_ttc += $object->total_ttc;
1534 if (!empty($avancementGlobal)) {
1535 $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1536 $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1539 $total_a_payer_ttc = 0;
1543 if (!empty($TPreviousIncoice)) {
1544 $pdf->setY($tab2_top);
1545 $posy = $pdf->GetY();
1547 foreach ($TPreviousIncoice as &$fac) {
1548 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1552 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1553 $pdf->setY($this->tab_top_newpage);
1555 $pdf->setY($this->marge_haute);
1557 $posy = $pdf->GetY();
1562 $pdf->SetFillColor(255, 255, 255);
1563 $pdf->SetXY($col1x, $posy);
1564 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $fac->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1566 $pdf->SetXY($col2x, $posy);
1570 $facSign = $fac->total_ht >= 0 ?
'+' :
'';
1573 $displayAmount =
' '.$facSign.
' '.
price($fac->total_ht, 0, $outputlangs);
1575 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1584 $pdf->SetFillColor(255, 255, 255);
1585 $pdf->SetXY($col1x, $posy);
1586 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"PDFSituationTitle", $object->situation_counter).
' '.$outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
1588 $pdf->SetXY($col2x, $posy);
1591 $facSign = $object->total_ht >= 0 ?
'+' :
'';
1599 $displayAmount =
' '.$facSign.
' '.
price($object->total_ht, 0, $outputlangs);
1600 $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0,
'R', 1);
1605 $pdf->SetFont(
'',
'', $default_font_size - 1);
1606 $pdf->SetFillColor(255, 255, 255);
1607 $pdf->SetXY($col1x, $posy);
1608 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"SituationTotalProgress", $avancementGlobal), 0,
'L', 1);
1610 $pdf->SetXY($col2x, $posy);
1611 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0,
'R', 1);
1612 $pdf->SetFont(
'',
'', $default_font_size - 2);
1616 if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1619 $this->
_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1620 $pdf->setY($this->tab_top_newpage);
1622 $pdf->setY($this->marge_haute);
1625 $posy = $pdf->GetY();
1636 $total_ht = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1639 $total_line_remise = 0;
1640 foreach ($object->lines as $i => $line) {
1643 if ($line->total_ht < 0) {
1644 $total_line_remise += -$line->total_ht;
1647 if ($total_line_remise > 0) {
1648 if (!empty($conf->global->MAIN_SHOW_AMOUNT_DISCOUNT)) {
1649 $pdf->SetFillColor(255, 255, 255);
1650 $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1651 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalDiscount") :
''), 0,
'L', 1);
1652 $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1653 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise, 0, $outputlangs), 0,
'R', 1);
1658 if (!empty($conf->global->MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT)) {
1659 $pdf->SetFillColor(255, 255, 255);
1660 $pdf->SetXY($col1x, $tab2_top);
1661 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHTBeforeDiscount").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHTBeforeDiscount") :
''), 0,
'L', 1);
1662 $pdf->SetXY($col2x, $tab2_top);
1663 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_line_remise + $total_ht, 0, $outputlangs), 0,
'R', 1);
1670 $pdf->SetFillColor(255, 255, 255);
1671 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1672 $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);
1674 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1675 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1676 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1679 $pdf->SetFillColor(248, 248, 248);
1681 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1683 $this->atleastoneratenotnull = 0;
1684 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1685 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1686 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1694 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1695 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1699 foreach ($localtax_rate as $tvakey => $tvaval) {
1704 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1707 if (preg_match(
'/\*/', $tvakey)) {
1708 $tvakey = str_replace(
'*',
'', $tvakey);
1709 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1712 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1714 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1715 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1717 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1718 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1726 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1727 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1731 foreach ($localtax_rate as $tvakey => $tvaval) {
1736 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1739 if (preg_match(
'/\*/', $tvakey)) {
1740 $tvakey = str_replace(
'*',
'', $tvakey);
1741 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1743 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1745 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1746 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1748 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1749 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1756 if (
getDolGlobalInt(
'INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1758 foreach ($this->tva as $tvakey => $tvaval) {
1759 $sum_pdf_tva += $tvaval;
1762 if ($sum_pdf_tva != $object->total_tva) {
1763 if (!empty($sum_pdf_tva)) {
1764 $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1770 foreach ($this->tva as $tvakey => $tvaval) {
1771 $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1773 foreach ($this->tva_array as $tvakey => $tvaval) {
1774 $this->tva_array[$tvakey][
'amount'] = $tvaval[
'amount'] * $coef_fix_tva;
1780 foreach ($this->tva_array as $tvakey => $tvaval) {
1782 $this->atleastoneratenotnull++;
1785 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1788 if (preg_match(
'/\*/', $tvakey)) {
1789 $tvakey = str_replace(
'*',
'', $tvakey);
1790 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1792 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1795 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1797 $totalvat .= ($tvaval[
'vatcode'] ? $tvaval[
'vatcode'] :
vatrate($tvaval[
'vatrate'], 1)).$tvacompl;
1799 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1801 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1803 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1804 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1811 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1812 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1816 foreach ($localtax_rate as $tvakey => $tvaval) {
1821 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1824 if (preg_match(
'/\*/', $tvakey)) {
1825 $tvakey = str_replace(
'*',
'', $tvakey);
1826 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1828 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1830 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1832 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1833 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1834 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1842 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1843 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1847 foreach ($localtax_rate as $tvakey => $tvaval) {
1853 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1856 if (preg_match(
'/\*/', $tvakey)) {
1857 $tvakey = str_replace(
'*',
'', $tvakey);
1858 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1860 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1863 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1864 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1866 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1867 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1874 if (
price2num($object->revenuestamp) != 0) {
1876 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1877 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RevenueStamp", $mysoc->country_code) :
''), $useborder,
'L', 1);
1879 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1880 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1885 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1886 $pdf->SetTextColor(0, 0, 60);
1887 $pdf->SetFillColor(224, 224, 224);
1888 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalTTC") :
''), $useborder,
'L', 1);
1890 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1891 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1895 if ($object->displayRetainedWarranty()) {
1896 $pdf->SetTextColor(40, 40, 40);
1897 $pdf->SetFillColor(255, 255, 255);
1899 $retainedWarranty = $object->getRetainedWarrantyAmount();
1900 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1904 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1905 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1907 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1908 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1912 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1914 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RetainedWarranty") :
'').
' ('.$object->retained_warranty.
'%)';
1915 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1917 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1918 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1919 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1924 $pdf->SetTextColor(0, 0, 0);
1926 $creditnoteamount = $object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1927 $depositsamount = $object->getSumDepositsUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1929 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1930 if (!empty($object->paye)) {
1934 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1937 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1938 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"Paid") :
''), 0,
'L', 0);
1939 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1940 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1943 if ($creditnoteamount) {
1944 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1945 $labeltouse .= (is_object($outputlangsbis) ? (
' / '.($outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities(
"CreditNotes")) :
'');
1947 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1948 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1949 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1950 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1969 $pdf->SetTextColor(0, 0, 60);
1970 $pdf->SetFillColor(224, 224, 224);
1971 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1972 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"RemainderToPay") :
''), $useborder,
'L', 1);
1973 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1974 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1976 $pdf->SetFont(
'',
'', $default_font_size - 1);
1977 $pdf->SetTextColor(0, 0, 0);
1981 return ($tab2_top + ($tab2_hl * $index));
1995 return parent::liste_modeles($db, $maxfilenamelength);
2013 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
2023 $currency = !empty($currency) ? $currency : $conf->currency;
2027 $pdf->SetTextColor(0, 0, 0);
2028 $pdf->SetFont(
'',
'', $default_font_size - 2);
2030 if (empty($hidetop)) {
2032 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2033 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
2034 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2035 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2038 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
2039 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2040 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
2043 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2044 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2047 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
2048 $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));
2052 $pdf->SetDrawColor(128, 128, 128);
2053 $pdf->SetFont(
'',
'', $default_font_size - 1);
2056 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
2059 $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2061 if (empty($hidetop)) {
2062 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
2077 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
2079 global $conf, $langs;
2081 $ltrdirection =
'L';
2082 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
2085 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
2091 $pdf->SetTextColor(0, 0, 60);
2092 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2096 $posy = $this->marge_haute;
2097 $posx = $this->page_largeur - $this->marge_droite - $w;
2099 $pdf->SetXY($this->marge_gauche, $posy);
2103 if ($this->emetteur->logo) {
2104 $logodir = $conf->mycompany->dir_output;
2105 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2106 $logodir = $conf->mycompany->multidir_output[$object->entity];
2109 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
2111 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
2113 if (is_readable($logo)) {
2115 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
2117 $pdf->SetTextColor(200, 0, 0);
2118 $pdf->SetFont(
'',
'B', $default_font_size - 2);
2119 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
2120 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
2123 $text = $this->emetteur->name;
2124 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2128 $pdf->SetFont(
'',
'B', $default_font_size + 3);
2129 $pdf->SetXY($posx, $posy);
2130 $pdf->SetTextColor(0, 0, 60);
2131 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
2132 if ($object->type == 1) {
2133 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
2135 if ($object->type == 2) {
2136 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
2138 if ($object->type == 3) {
2139 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
2141 if ($object->type == 4) {
2142 $title = $outputlangs->transnoentities(
"InvoiceProForma");
2144 if ($this->situationinvoice) {
2145 $langs->loadLangs(array(
"other"));
2146 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") . $object->situation_counter .
" -";
2148 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2150 if ($object->type == 0) {
2151 if ($this->situationinvoice) {
2152 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
2154 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
2155 } elseif ($object->type == 1) {
2156 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
2157 } elseif ($object->type == 2) {
2158 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
2159 } elseif ($object->type == 3) {
2160 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
2161 } elseif ($object->type == 4) {
2162 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
2165 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
2166 if ($object->statut == $object::STATUS_DRAFT) {
2167 $pdf->SetTextColor(128, 0, 0);
2168 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
2171 $pdf->MultiCell($w, 3, $title,
'',
'R');
2173 $pdf->SetFont(
'',
'B', $default_font_size);
2187 $pdf->SetFont(
'',
'', $default_font_size - 2);
2189 if ($object->ref_customer) {
2191 $pdf->SetXY($posx, $posy);
2192 $pdf->SetTextColor(0, 0, 60);
2193 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65),
'',
'R');
2196 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
2197 $object->fetch_projet();
2198 if (!empty($object->project->ref)) {
2200 $pdf->SetXY($posx, $posy);
2201 $pdf->SetTextColor(0, 0, 60);
2202 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
2206 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
2207 $object->fetch_projet();
2208 if (!empty($object->project->ref)) {
2209 $outputlangs->load(
"projects");
2211 $pdf->SetXY($posx, $posy);
2212 $pdf->SetTextColor(0, 0, 60);
2213 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
2217 $objectidnext = $object->getIdReplacingInvoice(
'validated');
2218 if ($object->type == 0 && $objectidnext) {
2219 $objectreplacing =
new Facture($this->db);
2220 $objectreplacing->fetch($objectidnext);
2223 $pdf->SetXY($posx, $posy);
2224 $pdf->SetTextColor(0, 0, 60);
2225 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
2227 if ($object->type == 1) {
2228 $objectreplaced =
new Facture($this->db);
2229 $objectreplaced->fetch($object->fk_facture_source);
2232 $pdf->SetXY($posx, $posy);
2233 $pdf->SetTextColor(0, 0, 60);
2234 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2236 if ($object->type == 2 && !empty($object->fk_facture_source)) {
2237 $objectreplaced =
new Facture($this->db);
2238 $objectreplaced->fetch($object->fk_facture_source);
2241 $pdf->SetXY($posx, $posy);
2242 $pdf->SetTextColor(0, 0, 60);
2243 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
2247 $pdf->SetXY($posx, $posy);
2248 $pdf->SetTextColor(0, 0, 60);
2250 $title = $outputlangs->transnoentities(
"DateInvoice");
2251 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2252 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2254 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2256 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2258 $pdf->SetXY($posx, $posy);
2259 $pdf->SetTextColor(0, 0, 60);
2260 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2263 if ($object->type != 2) {
2265 $pdf->SetXY($posx, $posy);
2266 $pdf->SetTextColor(0, 0, 60);
2267 $title = $outputlangs->transnoentities(
"DateDue");
2268 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2269 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2271 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2274 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2276 $pdf->SetXY($posx, $posy);
2277 $pdf->SetTextColor(0, 0, 60);
2278 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2282 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2283 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2284 if (count($arrayidcontact) > 0) {
2285 $usertmp =
new User($this->db);
2286 $usertmp->fetch($arrayidcontact[0]);
2288 $pdf->SetXY($posx, $posy);
2289 $pdf->SetTextColor(0, 0, 60);
2290 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2299 $current_y = $pdf->getY();
2300 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2301 if ($current_y < $pdf->getY()) {
2302 $top_shift = $pdf->getY() - $current_y;
2307 $carac_emetteur =
'';
2309 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
2310 if (count($arrayidcontact) > 0) {
2311 $object->fetch_user($arrayidcontact[0]);
2312 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2313 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2314 $carac_emetteur .=
"\n";
2317 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2320 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2321 $posy += $top_shift;
2322 $posx = $this->marge_gauche;
2323 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2324 $posx = $this->page_largeur - $this->marge_droite - 80;
2327 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2328 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2331 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2332 $pdf->SetTextColor(0, 0, 0);
2333 $pdf->SetFont(
'',
'', $default_font_size - 2);
2334 $pdf->SetXY($posx, $posy - 5);
2335 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2336 $pdf->SetXY($posx, $posy);
2337 $pdf->SetFillColor(230, 230, 230);
2338 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2339 $pdf->SetTextColor(0, 0, 60);
2343 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2344 $pdf->SetXY($posx + 2, $posy + 3);
2345 $pdf->SetFont(
'',
'B', $default_font_size);
2346 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2347 $posy = $pdf->getY();
2351 $pdf->SetXY($posx + 2, $posy);
2352 $pdf->SetFont(
'',
'', $default_font_size - 1);
2353 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2356 $usecontact =
false;
2357 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2358 if (count($arrayidcontact) > 0) {
2360 $result = $object->fetch_contact($arrayidcontact[0]);
2364 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)))) {
2365 $thirdparty = $object->contact;
2367 $thirdparty = $object->thirdparty;
2373 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2376 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2377 if ($this->page_largeur < 210) {
2380 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2381 $posy += $top_shift;
2382 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2383 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2384 $posx = $this->marge_gauche;
2388 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2389 $pdf->SetTextColor(0, 0, 0);
2390 $pdf->SetFont(
'',
'', $default_font_size - 2);
2391 $pdf->SetXY($posx + 2, $posy - 5);
2392 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2393 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2397 $pdf->SetXY($posx + 2, $posy + 3);
2398 $pdf->SetFont(
'',
'B', $default_font_size);
2399 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2401 $posy = $pdf->getY();
2404 $pdf->SetFont(
'',
'', $default_font_size - 1);
2405 $pdf->SetXY($posx + 2, $posy);
2406 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2410 $idaddressshipping = $object->getIdContact(
'external',
'SHIPPING');
2412 if (!empty($idaddressshipping)) {
2413 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2414 $companystatic =
new Societe($this->db);
2415 $companystatic->fetch($object->contact->fk_soc);
2417 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact,
'target', $object);
2420 $carac_client_shipping=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'target', $object);
2422 if (!empty($carac_client_shipping)) {
2423 $posy += $hautcadre;
2426 $pdf->SetXY($posx + 2, $posy - 5);
2427 $pdf->SetFont(
'',
'', $default_font_size - 2);
2428 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2429 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2432 $pdf->SetXY($posx + 2, $posy + 3);
2433 $pdf->SetFont(
'',
'B', $default_font_size);
2434 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2436 $posy = $pdf->getY();
2439 $pdf->SetXY($posx+2, $posy);
2440 $pdf->SetFont(
'',
'', $default_font_size - 1);
2441 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2442 $shipp_shift += $hautcadre;
2447 $pdf->SetTextColor(0, 0, 0);
2449 $pagehead = array(
'top_shift' => $top_shift,
'shipp_shift' => $shipp_shift);
2464 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2466 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2467 return pdf_pagefoot($pdf, $outputlangs,
'INVOICE_FREE_TEXT', $this->emetteur, $heightforqrinvoice + $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
2480 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2482 global $conf, $hookmanager;
2485 $this->defaultContentsFieldsStyle = array(
2487 'padding' => array(1, 0.5, 1, 0.5),
2491 $this->defaultTitlesFieldsStyle = array(
2493 'padding' => array(0.5, 0, 0.5, 0),
2515 $this->cols[
'desc'] = array(
2520 'textkey' =>
'Designation',
2524 'padding' => array(0.5, 0.5, 0.5, 0.5),
2528 'padding' => array(1, 0.5, 1, 1.5),
2534 $this->cols[
'photo'] = array(
2536 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH),
2539 'textkey' =>
'Photo',
2543 'padding' => array(0, 0, 0, 0),
2545 'border-left' =>
false,
2548 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
2549 $this->cols[
'photo'][
'status'] =
true;
2554 $this->cols[
'vat'] = array(
2561 'border-left' =>
true,
2564 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
2565 $this->cols[
'vat'][
'status'] =
true;
2569 $this->cols[
'subprice'] = array(
2574 'textkey' =>
'PriceUHT'
2576 'border-left' =>
true,
2581 $nblines = count($object->lines);
2582 for ($i = 0; $i < $nblines; $i++) {
2584 $tmpwidth = max($tmpwidth, $tmpwidth2);
2586 if ($tmpwidth > 10) {
2587 $this->cols[
'subprice'][
'width'] += (2 * ($tmpwidth - 10));
2591 $this->cols[
'qty'] = array(
2598 'border-left' =>
true,
2602 $this->cols[
'progress'] = array(
2607 'textkey' =>
'ProgressShort'
2609 'border-left' =>
true,
2612 if ($this->situationinvoice) {
2613 $this->cols[
'progress'][
'status'] =
true;
2617 $this->cols[
'unit'] = array(
2624 'border-left' =>
true,
2627 $this->cols[
'unit'][
'status'] =
true;
2631 $this->cols[
'discount'] = array(
2636 'textkey' =>
'ReductionShort'
2638 'border-left' =>
true,
2640 if ($this->atleastonediscount) {
2641 $this->cols[
'discount'][
'status'] =
true;
2644 $rank = $rank + 1000;
2645 $this->cols[
'totalexcltax'] = array(
2648 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ?
true :
false,
2650 'textkey' =>
'TotalHTShort'
2652 'border-left' =>
true,
2655 $rank = $rank + 1010;
2656 $this->cols[
'totalincltax'] = array(
2659 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ?
false :
true,
2661 'textkey' =>
'TotalTTCShort'
2663 'border-left' =>
true,
2667 if (!empty($object->lines)) {
2668 $line = reset($object->lines);
2672 $parameters = array(
2673 'object' => $object,
2674 'outputlangs' => $outputlangs,
2675 'hidedetails' => $hidedetails,
2676 'hidedesc' => $hidedesc,
2677 'hideref' => $hideref
2680 $reshook = $hookmanager->executeHooks(
'defineColumnField', $parameters, $this);
2683 } elseif (empty($reshook)) {
2684 $this->cols = array_replace($this->cols, $hookmanager->resArray);
2686 $this->cols = $hookmanager->resArray;