dolibarr  17.0.4
pdf_crabe.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
8  * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
11  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  * or see https://www.gnu.org/
27  */
28 
35 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
36 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
40 
41 
46 {
50  public $db;
51 
55  public $name;
56 
60  public $description;
61 
65  public $update_main_doc_field;
66 
70  public $type;
71 
76  public $phpmin = array(7, 0);
77 
82  public $version = 'dolibarr';
83 
87  public $page_largeur;
88 
92  public $page_hauteur;
93 
97  public $format;
98 
102  public $marge_gauche;
103 
107  public $marge_droite;
108 
112  public $marge_haute;
113 
117  public $marge_basse;
118 
123  public $emetteur;
124 
128  public $situationinvoice;
129 
133  public $posxprogress;
134 
138  public $categoryOfOperation = -1; // unknown by default
139 
140 
146  public function __construct($db)
147  {
148  global $conf, $langs, $mysoc;
149 
150  // Translations
151  $langs->loadLangs(array("main", "bills"));
152 
153  $this->db = $db;
154  $this->name = "crabe";
155  $this->description = $langs->trans('PDFCrabeDescription');
156  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
157 
158  // Dimension page
159  $this->type = 'pdf';
160  $formatarray = pdf_getFormat();
161  $this->page_largeur = $formatarray['width'];
162  $this->page_hauteur = $formatarray['height'];
163  $this->format = array($this->page_largeur, $this->page_hauteur);
164  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
165  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
166  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
167  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
168 
169  $this->option_logo = 1; // Display logo
170  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
171  $this->option_modereg = 1; // Display payment mode
172  $this->option_condreg = 1; // Display payment terms
173  $this->option_multilang = 1; // Available in several languages
174  $this->option_escompte = 1; // Displays if there has been a discount
175  $this->option_credit_note = 1; // Support credit notes
176  $this->option_freetext = 1; // Support add of a personalised text
177  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
178  $this->watermark = '';
179 
180  // Get source company
181  $this->emetteur = $mysoc;
182  if (empty($this->emetteur->country_code)) {
183  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
184  }
185 
186  // Define position of columns
187  $this->posxdesc = $this->marge_gauche + 1;
188  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
189  $this->posxtva = 101;
190  $this->posxup = 118;
191  $this->posxqty = 135;
192  $this->posxunit = 151;
193  } else {
194  $this->posxtva = 106;
195  $this->posxup = 122;
196  $this->posxqty = 145;
197  $this->posxunit = 162;
198  }
199  $this->posxprogress = 151; // Only displayed for situation invoices
200  $this->posxdiscount = 162;
201  $this->posxprogress = 174;
202  $this->postotalht = 174;
203  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
204  $this->posxtva = $this->posxup;
205  }
206  $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
207  if ($this->page_largeur < 210) { // To work with US executive format
208  $this->posxpicture -= 20;
209  $this->posxtva -= 20;
210  $this->posxup -= 20;
211  $this->posxqty -= 20;
212  $this->posxunit -= 20;
213  $this->posxdiscount -= 20;
214  $this->posxprogress -= 20;
215  $this->postotalht -= 20;
216  }
217 
218  $this->tva = array();
219  $this->tva_array = array();
220  $this->localtax1 = array();
221  $this->localtax2 = array();
222  $this->atleastoneratenotnull = 0;
223  $this->atleastonediscount = 0;
224  $this->situationinvoice = false;
225  }
226 
227 
228  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
240  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
241  {
242  // phpcs:enable
243  global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
244 
245  dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
246 
247  if (!is_object($outputlangs)) {
248  $outputlangs = $langs;
249  }
250  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
251  if (!empty($conf->global->MAIN_USE_FPDF)) {
252  $outputlangs->charset_output = 'ISO-8859-1';
253  }
254 
255  // Load translation files required by the page
256  $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
257 
258  // Show Draft Watermark
259  if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
260  $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
261  }
262 
263  global $outputlangsbis;
264  $outputlangsbis = null;
265  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
266  $outputlangsbis = new Translate('', $conf);
267  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
268  $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
269  }
270 
271  $nblines = count($object->lines);
272 
273  // Loop on each lines to detect if there is at least one image to show
274  $realpatharray = array();
275  if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
276  for ($i = 0; $i < $nblines; $i++) {
277  if (empty($object->lines[$i]->fk_product)) {
278  continue;
279  }
280 
281  $objphoto = new Product($this->db);
282  $objphoto->fetch($object->lines[$i]->fk_product);
283 
284  $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
285  $dir = $conf->product->dir_output.'/'.$pdir;
286 
287  $realpath = '';
288  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
289  $filename = $obj['photo'];
290  //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
291  $realpath = $dir.$filename;
292  break;
293  }
294 
295  if ($realpath) {
296  $realpatharray[$i] = $realpath;
297  }
298  }
299  }
300  if (count($realpatharray) == 0) {
301  $this->posxpicture = $this->posxtva;
302  }
303 
304  if ($conf->facture->dir_output) {
305  $object->fetch_thirdparty();
306 
307  $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
308  $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
309  $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
310 
311  // Definition of $dir and $file
312  if ($object->specimen) {
313  $dir = empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity];
314  $file = $dir."/SPECIMEN.pdf";
315  } else {
316  $objectref = dol_sanitizeFileName($object->ref);
317  $dir = (empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity])."/".$objectref;
318  $file = $dir."/".$objectref.".pdf";
319  }
320  if (!file_exists($dir)) {
321  if (dol_mkdir($dir) < 0) {
322  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
323  return 0;
324  }
325  }
326 
327  if (file_exists($dir)) {
328  // Add pdfgeneration hook
329  if (!is_object($hookmanager)) {
330  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
331  $hookmanager = new HookManager($this->db);
332  }
333  $hookmanager->initHooks(array('pdfgeneration'));
334  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
335  global $action;
336  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
337 
338  // Set nblines with the new facture lines content after hook
339  $nblines = count($object->lines);
340  $nbpayments = count($object->getListOfPayments());
341 
342  // Create pdf instance
343  $pdf = pdf_getInstance($this->format);
344  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
345  $pdf->SetAutoPageBreak(1, 0);
346 
347  $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
348  if ($heightforinfotot > 220) {
349  $heightforinfotot = 220;
350  }
351  $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
352  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
353  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
354  $heightforfooter += 6;
355  }
356 
357  if (class_exists('TCPDF')) {
358  $pdf->setPrintHeader(false);
359  $pdf->setPrintFooter(false);
360  }
361  $pdf->SetFont(pdf_getPDFFont($outputlangs));
362 
363  // Set path to the background PDF File
364  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
365  $logodir = $conf->mycompany->dir_output;
366  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
367  $logodir = $conf->mycompany->multidir_output[$object->entity];
368  }
369  $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
370  $tplidx = $pdf->importPage(1);
371  }
372 
373  $pdf->Open();
374  $pagenb = 0;
375  $pdf->SetDrawColor(128, 128, 128);
376 
377  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
378  $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
379  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
380  $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
381  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
382  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
383  $pdf->SetCompression(false);
384  }
385 
386  // Set certificate
387  $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
388  $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
389  // If user has no certificate, we try to take the company one
390  if (!$cert) {
391  $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
392  }
393  if (!$certprivate) {
394  $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ? '' : $conf->global->CERTIFICATE_CRT_PRIVATE;
395  }
396  // If a certificate is found
397  if ($cert) {
398  $info = array(
399  'Name' => $this->emetteur->name,
400  'Location' => getCountry($this->emetteur->country_code, 0),
401  'Reason' => 'INVOICE',
402  'ContactInfo' => $this->emetteur->email
403  );
404  $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
405  }
406 
407  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
408 
409  // Set $this->atleastonediscount if you have at least one discount
410  // and determine category of operation
411  $categoryOfOperation = 0;
412  $nbProduct = 0;
413  $nbService = 0;
414  for ($i = 0; $i < $nblines; $i++) {
415  if ($object->lines[$i]->remise_percent) {
416  $this->atleastonediscount++;
417  }
418 
419  // determine category of operation
420  if ($categoryOfOperation < 2) {
421  $lineProductType = $object->lines[$i]->product_type;
422  if ($lineProductType == Product::TYPE_PRODUCT) {
423  $nbProduct++;
424  } elseif ($lineProductType == Product::TYPE_SERVICE) {
425  $nbService++;
426  }
427  if ($nbProduct > 0 && $nbService > 0) {
428  // mixed products and services
429  $categoryOfOperation = 2;
430  }
431  }
432  }
433  // determine category of operation
434  if ($categoryOfOperation <= 0) {
435  // only services
436  if ($nbProduct == 0 && $nbService > 0) {
437  $categoryOfOperation = 1;
438  }
439  }
440  $this->categoryOfOperation = $categoryOfOperation;
441  if (empty($this->atleastonediscount)) { // retrieve space not used by discount
442  $delta = ($this->posxprogress - $this->posxdiscount);
443  $this->posxpicture += $delta;
444  $this->posxtva += $delta;
445  $this->posxup += $delta;
446  $this->posxqty += $delta;
447  $this->posxunit += $delta;
448  $this->posxdiscount += $delta;
449  // post of fields after are not modified, stay at same position
450  }
451 
452  $progress_width = 0;
453  // Situation invoice handling
454  if ($object->situation_cycle_ref && empty($conf->global->MAIN_PDF_HIDE_SITUATION)) {
455  $this->situationinvoice = true;
456  $progress_width = 10;
457  $this->posxpicture -= $progress_width;
458  $this->posxtva -= $progress_width;
459  $this->posxup -= $progress_width;
460  $this->posxqty -= $progress_width;
461  $this->posxunit -= $progress_width;
462  $this->posxdiscount -= $progress_width;
463  $this->posxprogress -= $progress_width;
464  }
465 
466  // New page
467  $pdf->AddPage();
468  if (!empty($tplidx)) {
469  $pdf->useTemplate($tplidx);
470  }
471  $pagenb++;
472 
473  // Output header (logo, ref and address blocks). This is first call for first page.
474  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
475  $pdf->SetFont('', '', $default_font_size - 1);
476  $pdf->MultiCell(0, 3, ''); // Set interline to 3
477  $pdf->SetTextColor(0, 0, 0);
478 
479  // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher
480 
481  // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
482  $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
483  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
484 
485  // You can add more thing under header here, if you increase $extra_under_address_shift too.
486  $extra_under_address_shift = 0;
487  $qrcodestring = '';
488  if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
489  $qrcodestring = $object->buildZATCAQRString();
490  } elseif (!empty($conf->global->INVOICE_ADD_SWISS_QR_CODE)) {
491  $qrcodestring = $object->buildSwitzerlandQRString();
492  }
493  if ($qrcodestring) {
494  $qrcodecolor = array('25', '25', '25');
495  // set style for QR-code
496  $styleQr = array(
497  'border' => false,
498  'padding' => 0,
499  'fgcolor' => $qrcodecolor,
500  'bgcolor' => false, //array(255,255,255)
501  'module_width' => 1, // width of a single module in points
502  'module_height' => 1 // height of a single module in points
503  );
504  $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N');
505  $extra_under_address_shift += 25;
506  }
507 
508  // Call hook printUnderHeaderPDFline
509  $parameters = array(
510  'object' => $object,
511  'i' => $i,
512  'pdf' =>& $pdf,
513  'outputlangs' => $outputlangs,
514  'hidedetails' => $hidedetails
515  );
516  $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
517  if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
518  $extra_under_address_shift += $hookmanager->resArray['extra_under_header_shift'];
519  }
520 
521  $tab_top += $extra_under_address_shift;
522  $tab_top_newpage += 0;
523 
524  // Incoterm
525  $height_incoterms = 0;
526  if (isModEnabled('incoterm')) {
527  $desc_incoterms = $object->getIncotermsForPDF();
528  if ($desc_incoterms) {
529  $tab_top -= 2;
530 
531  $pdf->SetFont('', '', $default_font_size - 1);
532  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
533  $nexY = $pdf->GetY();
534  $height_incoterms = $nexY - $tab_top;
535 
536  // Rect takes a length in 3rd parameter
537  $pdf->SetDrawColor(192, 192, 192);
538  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
539 
540  $tab_top = $nexY + 6;
541  }
542  }
543 
544  // Display notes
545  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
546  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
547  // Get first sale rep
548  if (is_object($object->thirdparty)) {
549  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
550  $salerepobj = new User($this->db);
551  $salerepobj->fetch($salereparray[0]['id']);
552  if (!empty($salerepobj->signature)) {
553  $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
554  }
555  }
556  }
557  // Extrafields in note
558  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
559  if (!empty($extranote)) {
560  $notetoshow = dol_concatdesc($notetoshow, $extranote);
561  }
562  if ($notetoshow) {
563  $tab_top -= 2;
564 
565  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
566  complete_substitutions_array($substitutionarray, $outputlangs, $object);
567 
568  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
569  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
570 
571  $pdf->SetFont('', '', $default_font_size - 1);
572  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
573  $nexY = $pdf->GetY();
574  $height_note = $nexY - $tab_top;
575 
576  // Rect takes a length in 3rd parameter
577  $pdf->SetDrawColor(192, 192, 192);
578  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
579 
580  $tab_top = $nexY + 6;
581  }
582 
583  $iniY = $tab_top + 7;
584  $curY = $tab_top + 7;
585  $nexY = $tab_top + 7;
586 
587  // Loop on each lines
588  for ($i = 0; $i < $nblines; $i++) {
589  $curY = $nexY;
590  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
591  $pdf->SetTextColor(0, 0, 0);
592 
593  // Define size of image if we need it
594  $imglinesize = array();
595  if (!empty($realpatharray[$i])) {
596  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
597  }
598 
599  $pdf->setTopMargin($tab_top_newpage);
600  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
601  $pageposbefore = $pdf->getPage();
602 
603  $showpricebeforepagebreak = 1;
604  $posYAfterImage = 0;
605  $posYAfterDescription = 0;
606 
607  // We start with Photo of product line
608  if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
609  $pdf->AddPage('', '', true);
610  if (!empty($tplidx)) {
611  $pdf->useTemplate($tplidx);
612  }
613  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
614  $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
615  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
616  }
617  $pdf->setPage($pageposbefore + 1);
618 
619  $curY = $tab_top_newpage;
620 
621  // Allows data in the first page if description is long enough to break in multiples pages
622  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
623  $showpricebeforepagebreak = 1;
624  } else {
625  $showpricebeforepagebreak = 0;
626  }
627  }
628 
629  if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
630  $curX = $this->posxpicture - 1;
631  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
632  // $pdf->Image does not increase value return by getY, so we save it manually
633  $posYAfterImage = $curY + $imglinesize['height'];
634  }
635 
636  // Description of product line
637  $curX = $this->posxdesc - 1;
638 
639  $pdf->startTransaction();
640  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
641  $pageposafter = $pdf->getPage();
642  if ($pageposafter > $pageposbefore) { // There is a pagebreak
643  $pdf->rollbackTransaction(true);
644  $pageposafter = $pageposbefore;
645  //print $pageposafter.'-'.$pageposbefore;exit;
646  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
647  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
648  $pageposafter = $pdf->getPage();
649  $posyafter = $pdf->GetY();
650  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
651  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
652  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
653  $pdf->AddPage('', '', true);
654  if (!empty($tplidx)) {
655  $pdf->useTemplate($tplidx);
656  }
657  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
658  $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
659  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
660  }
661  $pdf->setPage($pageposafter + 1);
662  }
663  } else {
664  // We found a page break
665 
666  // Allows data in the first page if description is long enough to break in multiples pages
667  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
668  $showpricebeforepagebreak = 1;
669  } else {
670  $showpricebeforepagebreak = 0;
671  }
672  }
673  } else // No pagebreak
674  {
675  $pdf->commitTransaction();
676  }
677  $posYAfterDescription = $pdf->GetY();
678 
679  $nexY = $pdf->GetY();
680  $pageposafter = $pdf->getPage();
681  $pdf->setPage($pageposbefore);
682  $pdf->setTopMargin($this->marge_haute);
683  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
684 
685  // We suppose that a too long description or photo were moved completely on next page
686  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
687  $pdf->setPage($pageposafter);
688  $curY = $tab_top_newpage;
689  }
690 
691  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
692 
693  // VAT Rate
694  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
695  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
696  $pdf->SetXY($this->posxtva - 5, $curY);
697  $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
698  }
699 
700  // Unit price before discount
701  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
702  $pdf->SetXY($this->posxup, $curY);
703  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
704 
705  // Quantity
706  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
707  $pdf->SetXY($this->posxqty, $curY);
708  $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
709 
710  // Unit
711  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
712  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
713  $pdf->SetXY($this->posxunit, $curY);
714  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
715  }
716 
717  // Discount on line
718  if ($object->lines[$i]->remise_percent) {
719  $pdf->SetXY($this->posxdiscount - 2, $curY);
720  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
721  $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
722  }
723 
724  // Situation progress
725  if ($this->situationinvoice) {
726  $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
727  $pdf->SetXY($this->posxprogress, $curY);
728  $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0, 'R');
729  }
730 
731  // Total HT line
732  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
733  $pdf->SetXY($this->postotalht, $curY);
734  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
735 
736 
737  $sign = 1;
738  if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
739  $sign = -1;
740  }
741  // Collection of totals by value of VAT in $this->tva["taux"]=total_tva
742  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
743  if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
744  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
745  $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
746  } else {
747  $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
748  }
749  } else {
750  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
751  $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
752  } else {
753  $tvaligne = $sign * $object->lines[$i]->total_tva;
754  }
755  }
756 
757  $localtax1ligne = $object->lines[$i]->total_localtax1;
758  $localtax2ligne = $object->lines[$i]->total_localtax2;
759  $localtax1_rate = $object->lines[$i]->localtax1_tx;
760  $localtax2_rate = $object->lines[$i]->localtax2_tx;
761  $localtax1_type = $object->lines[$i]->localtax1_type;
762  $localtax2_type = $object->lines[$i]->localtax2_type;
763 
764  if ($object->remise_percent) {
765  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
766  }
767  if ($object->remise_percent) {
768  $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
769  }
770  if ($object->remise_percent) {
771  $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
772  }
773 
774  $vatrate = (string) $object->lines[$i]->tva_tx;
775 
776  // Retrieve type from database for backward compatibility with old records
777  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
778  && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
779  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
780  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
781  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
782  }
783 
784  // retrieve global local tax
785  if ($localtax1_type && $localtax1ligne != 0) {
786  if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
787  $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
788  } else {
789  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
790  }
791  }
792  if ($localtax2_type && $localtax2ligne != 0) {
793  if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
794  $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
795  } else {
796  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
797  }
798  }
799 
800  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
801  $vatrate .= '*';
802  }
803 
804  // Fill $this->tva and $this->tva_array
805  if (!isset($this->tva[$vatrate])) {
806  $this->tva[$vatrate] = 0;
807  }
808  $this->tva[$vatrate] += $tvaligne; // ->tva is abandonned, we use now ->tva_array that is more complete
809  $vatcode = $object->lines[$i]->vat_src_code;
810  if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
811  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
812  }
813  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
814 
815  if ($posYAfterImage > $posYAfterDescription) {
816  $nexY = $posYAfterImage;
817  }
818 
819  // Add line
820  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
821  $pdf->setPage($pageposafter);
822  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
823  //$pdf->SetDrawColor(190,190,200);
824  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
825  $pdf->SetLineStyle(array('dash'=>0));
826  }
827 
828  $nexY += 2; // Add space between lines
829 
830  // Detect if some page were added automatically and output _tableau for past pages
831  while ($pagenb < $pageposafter) {
832  $pdf->setPage($pagenb);
833  if ($pagenb == 1) {
834  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
835  } else {
836  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
837  }
838  $this->_pagefoot($pdf, $object, $outputlangs, 1);
839  $pagenb++;
840  $pdf->setPage($pagenb);
841  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
842  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
843  $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
844  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
845  }
846  if (!empty($tplidx)) {
847  $pdf->useTemplate($tplidx);
848  }
849  }
850  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
851  if ($pagenb == 1) {
852  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
853  } else {
854  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
855  }
856  $this->_pagefoot($pdf, $object, $outputlangs, 1);
857  // New page
858  $pdf->AddPage();
859  if (!empty($tplidx)) {
860  $pdf->useTemplate($tplidx);
861  }
862  $pagenb++;
863  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
864  $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
865  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
866  }
867  }
868  }
869 
870  // Show square
871  if ($pagenb == 1) {
872  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
873  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
874  } else {
875  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
876  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
877  }
878  dol_syslog("bottomlasttab=".$bottomlasttab." this->page_hauteur=".$this->page_hauteur." heightforinfotot=".$heightforinfotot." heightforfreetext=".$heightforfreetext." heightforfooter=".$heightforfooter);
879 
880  // Display info area
881  $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
882 
883  // Display total area
884  $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
885 
886  // Display Payments area
887  if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
888  $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
889  }
890 
891  // Pagefoot
892  $this->_pagefoot($pdf, $object, $outputlangs);
893  if (method_exists($pdf, 'AliasNbPages')) {
894  $pdf->AliasNbPages();
895  }
896 
897  $pdf->Close();
898 
899  $pdf->Output($file, 'F');
900 
901  // Add pdfgeneration hook
902  $hookmanager->initHooks(array('pdfgeneration'));
903  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
904  global $action;
905  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
906  if ($reshook < 0) {
907  $this->error = $hookmanager->error;
908  $this->errors = $hookmanager->errors;
909  }
910 
911  if (!empty($conf->global->MAIN_UMASK)) {
912  @chmod($file, octdec($conf->global->MAIN_UMASK));
913  }
914 
915  $this->result = array('fullpath'=>$file);
916 
917  return 1; // No error
918  } else {
919  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
920  return 0;
921  }
922  } else {
923  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
924  return 0;
925  }
926  }
927 
928 
929  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
930  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
941  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
942  {
943  // phpcs:enable
944  global $conf;
945 
946  $sign = 1;
947  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
948  $sign = -1;
949  }
950 
951  $current_page = $pdf->getPage();
952  $tab3_posx = 120;
953  $tab3_top = $posy + 8;
954  $tab3_width = 80;
955  $tab3_height = 4;
956  if ($this->page_largeur < 210) { // To work with US executive format
957  $tab3_posx -= 15;
958  }
959 
960  $default_font_size = pdf_getPDFFontSize($outputlangs);
961 
962  $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
963 
964  $y = 0;
965 
966  $pdf->SetFont('', '', $default_font_size - 4);
967 
968 
969  // Loop on each discount available (deposits and credit notes and excess of payment included)
970  $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,";
971  $sql .= " re.description, re.fk_facture_source,";
972  $sql .= " f.type, f.datef";
973  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
974  $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
975  $resql = $this->db->query($sql);
976  if ($resql) {
977  $num = $this->db->num_rows($resql);
978  $i = 0;
979  $invoice = new Facture($this->db);
980  while ($i < $num) {
981  $y += 3;
982  if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
983  $y = 0;
984  $current_page++;
985  $pdf->AddPage('', '', true);
986  if (!empty($tplidx)) {
987  $pdf->useTemplate($tplidx);
988  }
989  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
990  $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
991  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
992  }
993  $pdf->setPage($current_page);
994  $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
995  }
996 
997  $obj = $this->db->fetch_object($resql);
998 
999  if ($obj->type == 2) {
1000  $text = $outputlangs->transnoentities("CreditNote");
1001  } elseif ($obj->type == 3) {
1002  $text = $outputlangs->transnoentities("Deposit");
1003  } elseif ($obj->type == 0) {
1004  $text = $outputlangs->transnoentities("ExcessReceived");
1005  } else {
1006  $text = $outputlangs->transnoentities("UnknownType");
1007  }
1008 
1009  $invoice->fetch($obj->fk_facture_source);
1010 
1011  $pdf->SetXY($tab3_posx, $tab3_top + $y);
1012  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1013  $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1014  $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1015  $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1016  $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1017  $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1018  $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1019 
1020  $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1021 
1022  $i++;
1023  }
1024  } else {
1025  $this->error = $this->db->lasterror();
1026  return -1;
1027  }
1028 
1029  // Loop on each payment
1030  // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
1031  $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1032  $sql .= " cp.code";
1033  $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1034  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1035  $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1036  //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1037  $sql .= " ORDER BY p.datep";
1038 
1039  $resql = $this->db->query($sql);
1040  if ($resql) {
1041  $num = $this->db->num_rows($resql);
1042  $i = 0;
1043  while ($i < $num) {
1044  $y += 3;
1045  if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1046  $y = 0;
1047  $current_page++;
1048  $pdf->AddPage('', '', true);
1049  if (!empty($tplidx)) {
1050  $pdf->useTemplate($tplidx);
1051  }
1052  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1053  $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs);
1054  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1055  }
1056  $pdf->setPage($current_page);
1057  $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1058  }
1059 
1060  $row = $this->db->fetch_object($resql);
1061 
1062  $pdf->SetXY($tab3_posx, $tab3_top + $y);
1063  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1064  $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1065  $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1066  $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1067  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1068 
1069  $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1070  $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1071  $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1072 
1073  $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1074 
1075  $i++;
1076  }
1077 
1078  return $tab3_top + $y + 3;
1079  } else {
1080  $this->error = $this->db->lasterror();
1081  return -1;
1082  }
1083  }
1084 
1085  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1086  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1100  protected function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
1101  {
1102  // phpcs:enable
1103  $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1104  if ($object->type == 2) {
1105  $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1106  }
1107 
1108  $pdf->SetFont('', '', $default_font_size - 3);
1109  $pdf->SetXY($tab3_posx, $tab3_top - 4);
1110  $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1111 
1112  $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1113 
1114  $pdf->SetFont('', '', $default_font_size - 4);
1115  $pdf->SetXY($tab3_posx, $tab3_top);
1116  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1117  $pdf->SetXY($tab3_posx + 21, $tab3_top);
1118  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1119  $pdf->SetXY($tab3_posx + 40, $tab3_top);
1120  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1121  $pdf->SetXY($tab3_posx + 58, $tab3_top);
1122  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1123 
1124  $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1125  }
1126 
1127  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1128  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1139  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1140  {
1141  // phpcs:enable
1142  global $conf, $mysoc;
1143 
1144  $default_font_size = pdf_getPDFFontSize($outputlangs);
1145 
1146  $pdf->SetFont('', '', $default_font_size - 1);
1147 
1148  // If France, show VAT mention if not applicable
1149  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1150  $pdf->SetFont('', 'B', $default_font_size - 2);
1151  $pdf->SetXY($this->marge_gauche, $posy);
1152  if ($mysoc->forme_juridique_code == 92) {
1153  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1154  } else {
1155  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1156  }
1157 
1158  $posy = $pdf->GetY() + 4;
1159  }
1160 
1161  $posxval = 52;
1162  $posxend = 110; // End of x for text on left side
1163  if ($this->page_largeur < 210) { // To work with US executive format
1164  $posxend -= 10;
1165  }
1166 
1167  // Show payments conditions
1168  if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1169  $pdf->SetFont('', 'B', $default_font_size - 2);
1170  $pdf->SetXY($this->marge_gauche, $posy);
1171  $titre = $outputlangs->transnoentities("PaymentConditions").':';
1172  $pdf->MultiCell(43, 4, $titre, 0, 'L');
1173 
1174  $pdf->SetFont('', '', $default_font_size - 2);
1175  $pdf->SetXY($posxval, $posy);
1176  $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);
1177  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1178  $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
1179 
1180  $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1181  }
1182 
1183  // Show category of operations
1184  if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1185  $pdf->SetFont('', 'B', $default_font_size - 2);
1186  $pdf->SetXY($this->marge_gauche, $posy);
1187  $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1188  $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1189 
1190  $pdf->SetFont('', '', $default_font_size - 2);
1191  $pdf->SetXY($posxval, $posy);
1192  $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1193  $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1194 
1195  $posy = $pdf->GetY() + 3; // for 2 lines
1196  }
1197 
1198  if ($object->type != 2) {
1199  // Check a payment mode is defined
1200  if (empty($object->mode_reglement_code)
1201  && empty($conf->global->FACTURE_CHQ_NUMBER)
1202  && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1203  $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1204  } elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
1205  || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1206  // Avoid having any valid PDF with setup that is not complete
1207  $outputlangs->load("errors");
1208 
1209  $pdf->SetXY($this->marge_gauche, $posy);
1210  $pdf->SetTextColor(200, 0, 0);
1211  $pdf->SetFont('', 'B', $default_font_size - 2);
1212  $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1213  $pdf->MultiCell(80, 3, $this->error, 0, 'L', 0);
1214  $pdf->SetTextColor(0, 0, 0);
1215 
1216  $posy = $pdf->GetY() + 1;
1217  }
1218 
1219  // Show payment mode
1220  if (!empty($object->mode_reglement_code)
1221  && $object->mode_reglement_code != 'CHQ'
1222  && $object->mode_reglement_code != 'VIR') {
1223  $pdf->SetFont('', 'B', $default_font_size - 2);
1224  $pdf->SetXY($this->marge_gauche, $posy);
1225  $titre = $outputlangs->transnoentities("PaymentMode").':';
1226  $pdf->MultiCell(80, 5, $titre, 0, 'L');
1227 
1228  $pdf->SetFont('', '', $default_font_size - 2);
1229  $pdf->SetXY($posxval, $posy);
1230  $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);
1231  //#21654: add account number used for the debit
1232  if ($object->mode_reglement_code == "PRE") {
1233  require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1234  $bac = new CompanyBankAccount($this->db);
1235  $bac->fetch(0, $object->thirdparty->id);
1236  $iban= $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1237  $lib_mode_reg .= $outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1238  }
1239  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
1240 
1241  $posy = $pdf->GetY();
1242  }
1243 
1244  // Show if Option VAT debit option is on also if transmitter is french
1245  // Decret n°2099-1299 2022-10-07
1246  // French mention : "Option pour le paiement de la taxe d'après les débits"
1247  if ($this->emetteur->country_code == 'FR') {
1248  if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1249  $pdf->SetXY($this->marge_gauche, $posy);
1250  $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1251 
1252  $posy = $pdf->GetY() + 1;
1253  }
1254  }
1255 
1256  // Show online payment link
1257  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1258  $useonlinepayment = 0;
1259  if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1260  if (isModEnabled('paypal')) {
1261  $useonlinepayment++;
1262  }
1263  if (isModEnabled('stripe')) {
1264  $useonlinepayment++;
1265  }
1266  if (isModEnabled('paybox')) {
1267  $useonlinepayment++;
1268  }
1269  }
1270 
1271  if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
1272  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1273  global $langs;
1274 
1275  $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1276  $servicename = $langs->transnoentities('Online');
1277  $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
1278  $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1279 
1280  $pdf->SetXY($this->marge_gauche, $posy);
1281  $pdf->writeHTMLCell(80, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1282 
1283  $posy = $pdf->GetY() + 1;
1284  }
1285  }
1286 
1287  // Show payment mode CHQ
1288  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1289  // If payment mode unregulated or payment mode forced to CHQ
1290  if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
1291  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1292 
1293  if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1294  $account = new Account($this->db);
1295  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1296 
1297  $pdf->SetXY($this->marge_gauche, $posy);
1298  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1299  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1300  $posy = $pdf->GetY() + 1;
1301 
1302  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1303  $pdf->SetXY($this->marge_gauche, $posy);
1304  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1305  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1306  $posy = $pdf->GetY() + 2;
1307  }
1308  }
1309  if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1310  $pdf->SetXY($this->marge_gauche, $posy);
1311  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1312  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1313  $posy = $pdf->GetY() + 1;
1314 
1315  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1316  $pdf->SetXY($this->marge_gauche, $posy);
1317  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1318  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1319  $posy = $pdf->GetY() + 2;
1320  }
1321  }
1322  }
1323  }
1324 
1325  // If payment mode not forced or forced to VIR, show payment with BAN
1326  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1327  if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1328  $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1329  if ($object->fk_bank > 0) {
1330  $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1331  }
1332  $account = new Account($this->db);
1333  $account->fetch($bankid);
1334 
1335  $curx = $this->marge_gauche;
1336  $cury = $posy;
1337 
1338  $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1339 
1340  $posy += 2;
1341  }
1342  }
1343  }
1344 
1345  return $posy;
1346  }
1347 
1348 
1349  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1350  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1362  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1363  {
1364  // phpcs:enable
1365  global $conf, $mysoc, $hookmanager;
1366 
1367  $sign = 1;
1368  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1369  $sign = -1;
1370  }
1371 
1372  $default_font_size = pdf_getPDFFontSize($outputlangs);
1373 
1374  $outputlangsbis = null;
1375  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1376  $outputlangsbis = new Translate('', $conf);
1377  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1378  $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
1379  $default_font_size--;
1380  }
1381 
1382  $tab2_top = $posy;
1383  $tab2_hl = 4;
1384  $pdf->SetFont('', '', $default_font_size - 1);
1385 
1386  // Total table
1387  $col1x = 120;
1388  $col2x = 170;
1389  if ($this->page_largeur < 210) { // To work with US executive format
1390  $col1x -= 15;
1391  $col2x -= 10;
1392  }
1393  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1394 
1395  $useborder = 0;
1396  $index = 0;
1397 
1398  // Total HT
1399  $pdf->SetFillColor(255, 255, 255);
1400  $pdf->SetXY($col1x, $tab2_top + 0);
1401  $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);
1402 
1403  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1404  $pdf->SetXY($col2x, $tab2_top + 0);
1405  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1406 
1407  // Show VAT by rates and total
1408  $pdf->SetFillColor(248, 248, 248);
1409 
1410  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1411 
1412  $this->atleastoneratenotnull = 0;
1413  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1414  $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1415  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1416  // Nothing to do
1417  } else {
1418  // FIXME amount of vat not supported with multicurrency
1419 
1420  //Local tax 1 before VAT
1421  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1422  //{
1423  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1424  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1425  continue;
1426  }
1427 
1428  foreach ($localtax_rate as $tvakey => $tvaval) {
1429  if ($tvakey != 0) { // On affiche pas taux 0
1430  //$this->atleastoneratenotnull++;
1431 
1432  $index++;
1433  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1434 
1435  $tvacompl = '';
1436  if (preg_match('/\*/', $tvakey)) {
1437  $tvakey = str_replace('*', '', $tvakey);
1438  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1439  }
1440 
1441  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1442  $totalvat .= ' ';
1443  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1444  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1445 
1446  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1447  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1448  }
1449  }
1450  }
1451  //}
1452  //Local tax 2 before VAT
1453  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1454  //{
1455  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1456  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1457  continue;
1458  }
1459 
1460  foreach ($localtax_rate as $tvakey => $tvaval) {
1461  if ($tvakey != 0) { // On affiche pas taux 0
1462  //$this->atleastoneratenotnull++;
1463 
1464  $index++;
1465  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1466 
1467  $tvacompl = '';
1468  if (preg_match('/\*/', $tvakey)) {
1469  $tvakey = str_replace('*', '', $tvakey);
1470  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1471  }
1472  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1473  $totalvat .= ' ';
1474  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1475  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1476 
1477  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1478  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1479  }
1480  }
1481  }
1482 
1483  //}
1484 
1485  // VAT
1486  foreach ($this->tva_array as $tvakey => $tvaval) {
1487  if ($tvakey != 0) { // On affiche pas taux 0
1488  $this->atleastoneratenotnull++;
1489 
1490  $index++;
1491  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1492 
1493  $tvacompl = '';
1494  if (preg_match('/\*/', $tvakey)) {
1495  $tvakey = str_replace('*', '', $tvakey);
1496  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1497  }
1498  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1499  $totalvat .= ' ';
1500  if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1501  $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1502  } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1503  $totalvat .= $tvaval['vatcode'].$tvacompl;
1504  } else {
1505  $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1506  }
1507  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1508 
1509  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1510  $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1511  }
1512  }
1513 
1514  //Local tax 1 after VAT
1515  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1516  //{
1517  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1518  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1519  continue;
1520  }
1521 
1522  foreach ($localtax_rate as $tvakey => $tvaval) {
1523  if ($tvakey != 0) { // On affiche pas taux 0
1524  //$this->atleastoneratenotnull++;
1525 
1526  $index++;
1527  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1528 
1529  $tvacompl = '';
1530  if (preg_match('/\*/', $tvakey)) {
1531  $tvakey = str_replace('*', '', $tvakey);
1532  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1533  }
1534  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
1535  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1536 
1537  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1538  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1539  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1540  }
1541  }
1542  }
1543  //}
1544  //Local tax 2 after VAT
1545  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1546  //{
1547  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1548  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1549  continue;
1550  }
1551 
1552  foreach ($localtax_rate as $tvakey => $tvaval) {
1553  //$this->atleastoneratenotnull++;
1554 
1555  $index++;
1556  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1557 
1558  $tvacompl = '';
1559  if (preg_match('/\*/', $tvakey)) {
1560  $tvakey = str_replace('*', '', $tvakey);
1561  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1562  }
1563  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1564 
1565  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1566  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1567 
1568  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1569  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1570  }
1571  }
1572  //}
1573 
1574  // Revenue stamp
1575  if (price2num($object->revenuestamp) != 0) {
1576  $index++;
1577  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1578  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1579 
1580  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1581  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1582  }
1583 
1584  // Total TTC
1585  $index++;
1586  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1587  $pdf->SetTextColor(0, 0, 60);
1588  $pdf->SetFillColor(224, 224, 224);
1589  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1590 
1591  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1592  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1593 
1594  // Retained warranty
1595  if ($object->displayRetainedWarranty()) {
1596  $pdf->SetTextColor(40, 40, 40);
1597  $pdf->SetFillColor(255, 255, 255);
1598 
1599  $retainedWarranty = $object->getRetainedWarrantyAmount();
1600  $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1601 
1602  // Billed - retained warranty
1603  $index++;
1604  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1605  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1606 
1607  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1608  $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1609 
1610  // retained warranty
1611  $index++;
1612  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1613 
1614  $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
1615  $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1616 
1617  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1618  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1619  $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1620  }
1621  }
1622  }
1623 
1624  $pdf->SetTextColor(0, 0, 0);
1625  $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1626  $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1627  //print "x".$creditnoteamount."-".$depositsamount;exit;
1628  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1629  if (!empty($object->paye)) {
1630  $resteapayer = 0;
1631  }
1632 
1633  if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1634  // Already paid + Deposits
1635  $index++;
1636  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1637  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1638  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1639  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1640 
1641  // Credit note
1642  if ($creditnoteamount) {
1643  $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1644  $index++;
1645  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1646  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1647  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1648  $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1649  }
1650 
1651  // Escompte
1652  if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1653  $index++;
1654  $pdf->SetFillColor(255, 255, 255);
1655 
1656  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1657  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1658  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1659  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1660 
1661  $resteapayer = 0;
1662  }
1663 
1664  $index++;
1665  $pdf->SetTextColor(0, 0, 60);
1666  $pdf->SetFillColor(224, 224, 224);
1667  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1668  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1669  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1670  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1671 
1672  $pdf->SetFont('', '', $default_font_size - 1);
1673  $pdf->SetTextColor(0, 0, 0);
1674  }
1675 
1676  $index++;
1677  return ($tab2_top + ($tab2_hl * $index));
1678  }
1679 
1680  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1694  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1695  {
1696  global $conf;
1697 
1698  // Force to disable hidetop and hidebottom
1699  $hidebottom = 0;
1700  if ($hidetop) {
1701  $hidetop = -1;
1702  }
1703 
1704  $currency = !empty($currency) ? $currency : $conf->currency;
1705  $default_font_size = pdf_getPDFFontSize($outputlangs);
1706 
1707  // Amount in (at tab_top - 1)
1708  $pdf->SetTextColor(0, 0, 0);
1709  $pdf->SetFont('', '', $default_font_size - 2);
1710 
1711  if (empty($hidetop)) {
1712  // Show category of operations
1713  if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1714  $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1715  $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1716  $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1717  }
1718 
1719  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1720  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1721  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1722 
1723  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1724  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1725  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1726  }
1727  }
1728 
1729  $pdf->SetDrawColor(128, 128, 128);
1730  $pdf->SetFont('', '', $default_font_size - 1);
1731 
1732  // Output Rect
1733  $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
1734 
1735  if (empty($hidetop)) {
1736  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
1737 
1738  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1739  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1740  }
1741 
1742  if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
1743  $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1744  if (empty($hidetop)) {
1745  //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1746  //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1747  }
1748  }
1749 
1750  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1751  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1752  if (empty($hidetop)) {
1753  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1754  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1755  }
1756  }
1757 
1758  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1759  if (empty($hidetop)) {
1760  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1761  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1762  }
1763 
1764  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1765  if (empty($hidetop)) {
1766  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1767  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1768  }
1769 
1770  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1771  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1772  if (empty($hidetop)) {
1773  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1774  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1775  }
1776  }
1777 
1778  if ($this->atleastonediscount) {
1779  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1780  if (empty($hidetop)) {
1781  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1782  $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1783  }
1784  }
1785 
1786  if ($this->situationinvoice) {
1787  $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1788  if (empty($hidetop)) {
1789  $pdf->SetXY($this->posxprogress, $tab_top + 1);
1790  $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities("ProgressShort"), '', 'C');
1791  }
1792  }
1793 
1794  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1795  if (empty($hidetop)) {
1796  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1797  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1798  }
1799  }
1800 
1801  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1812  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
1813  {
1814  global $conf, $langs;
1815 
1816  $ltrdirection = 'L';
1817  if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
1818 
1819  // Load traductions files required by page
1820  $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
1821 
1822  $default_font_size = pdf_getPDFFontSize($outputlangs);
1823 
1824  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1825 
1826  $pdf->SetTextColor(0, 0, 60);
1827  $pdf->SetFont('', 'B', $default_font_size + 3);
1828 
1829  $w = 110;
1830 
1831  $posy = $this->marge_haute;
1832  $posx = $this->page_largeur - $this->marge_droite - $w;
1833 
1834  $pdf->SetXY($this->marge_gauche, $posy);
1835 
1836  // Logo
1837  if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
1838  if ($this->emetteur->logo) {
1839  $logodir = $conf->mycompany->dir_output;
1840  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1841  $logodir = $conf->mycompany->multidir_output[$object->entity];
1842  }
1843  if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
1844  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1845  } else {
1846  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1847  }
1848  if (is_readable($logo)) {
1849  $height = pdf_getHeightForLogo($logo);
1850  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1851  } else {
1852  $pdf->SetTextColor(200, 0, 0);
1853  $pdf->SetFont('', 'B', $default_font_size - 2);
1854  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1855  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1856  }
1857  } else {
1858  $text = $this->emetteur->name;
1859  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1860  }
1861  }
1862 
1863  $pdf->SetFont('', 'B', $default_font_size + 3);
1864  $pdf->SetXY($posx, $posy);
1865  $pdf->SetTextColor(0, 0, 60);
1866  $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1867  if ($object->type == 1) {
1868  $title = $outputlangs->transnoentities("InvoiceReplacement");
1869  }
1870  if ($object->type == 2) {
1871  $title = $outputlangs->transnoentities("InvoiceAvoir");
1872  }
1873  if ($object->type == 3) {
1874  $title = $outputlangs->transnoentities("InvoiceDeposit");
1875  }
1876  if ($object->type == 4) {
1877  $title = $outputlangs->transnoentities("InvoiceProForma");
1878  }
1879  if ($this->situationinvoice) {
1880  $title = $outputlangs->transnoentities("PDFInvoiceSituation");
1881  }
1882  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1883  $title .= ' - ';
1884  if ($object->type == 0) {
1885  if ($this->situationinvoice) {
1886  $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
1887  }
1888  $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
1889  } elseif ($object->type == 1) {
1890  $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
1891  } elseif ($object->type == 2) {
1892  $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
1893  } elseif ($object->type == 3) {
1894  $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
1895  } elseif ($object->type == 4) {
1896  $title .= $outputlangsbis->transnoentities("InvoiceProForma");
1897  }
1898  }
1899  $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
1900  if ($object->statut == $object::STATUS_DRAFT) {
1901  $pdf->SetTextColor(128, 0, 0);
1902  $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1903  }
1904 
1905  $pdf->MultiCell($w, 3, $title, '', 'R');
1906 
1907  $pdf->SetFont('', 'B', $default_font_size);
1908 
1909  /*
1910  $posy += 5;
1911  $pdf->SetXY($posx, $posy);
1912  $pdf->SetTextColor(0, 0, 60);
1913  $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1914  if ($object->statut == $object::STATUS_DRAFT) {
1915  $pdf->SetTextColor(128, 0, 0);
1916  $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1917  }
1918  $pdf->MultiCell($w, 4, $textref, '', 'R');*/
1919 
1920  $posy += 3;
1921  $pdf->SetFont('', '', $default_font_size - 2);
1922 
1923  if ($object->ref_client) {
1924  $posy += 4;
1925  $pdf->SetXY($posx, $posy);
1926  $pdf->SetTextColor(0, 0, 60);
1927  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1928  }
1929 
1930  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1931  $object->fetch_projet();
1932  if (!empty($object->project->ref)) {
1933  $posy += 3;
1934  $pdf->SetXY($posx, $posy);
1935  $pdf->SetTextColor(0, 0, 60);
1936  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1937  }
1938  }
1939 
1940  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1941  $object->fetch_projet();
1942  if (!empty($object->project->ref)) {
1943  $outputlangs->load("projects");
1944  $posy += 3;
1945  $pdf->SetXY($posx, $posy);
1946  $pdf->SetTextColor(0, 0, 60);
1947  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1948  }
1949  }
1950 
1951  $objectidnext = $object->getIdReplacingInvoice('validated');
1952  if ($object->type == 0 && $objectidnext) {
1953  $objectreplacing = new Facture($this->db);
1954  $objectreplacing->fetch($objectidnext);
1955 
1956  $posy += 3;
1957  $pdf->SetXY($posx, $posy);
1958  $pdf->SetTextColor(0, 0, 60);
1959  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1960  }
1961  if ($object->type == 1) {
1962  $objectreplaced = new Facture($this->db);
1963  $objectreplaced->fetch($object->fk_facture_source);
1964 
1965  $posy += 4;
1966  $pdf->SetXY($posx, $posy);
1967  $pdf->SetTextColor(0, 0, 60);
1968  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1969  }
1970  if ($object->type == 2 && !empty($object->fk_facture_source)) {
1971  $objectreplaced = new Facture($this->db);
1972  $objectreplaced->fetch($object->fk_facture_source);
1973 
1974  $posy += 3;
1975  $pdf->SetXY($posx, $posy);
1976  $pdf->SetTextColor(0, 0, 60);
1977  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1978  }
1979 
1980  $posy += 4;
1981  $pdf->SetXY($posx, $posy);
1982  $pdf->SetTextColor(0, 0, 60);
1983  $title = $outputlangs->transnoentities("DateInvoice");
1984  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1985  $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
1986  }
1987  $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1988 
1989  if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
1990  $posy += 4;
1991  $pdf->SetXY($posx, $posy);
1992  $pdf->SetTextColor(0, 0, 60);
1993  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
1994  }
1995 
1996  if ($object->type != 2) {
1997  $posy += 3;
1998  $pdf->SetXY($posx, $posy);
1999  $pdf->SetTextColor(0, 0, 60);
2000  $title = $outputlangs->transnoentities("DateDue");
2001  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2002  $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2003  }
2004  $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2005  }
2006 
2007  if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2008  $posy += 3;
2009  $pdf->SetXY($posx, $posy);
2010  $pdf->SetTextColor(0, 0, 60);
2011  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2012  }
2013 
2014  // Get contact
2015  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2016  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2017  if (count($arrayidcontact) > 0) {
2018  $usertmp = new User($this->db);
2019  $usertmp->fetch($arrayidcontact[0]);
2020  $posy += 4;
2021  $pdf->SetXY($posx, $posy);
2022  $pdf->SetTextColor(0, 0, 60);
2023  $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2024  }
2025  }
2026 
2027  $posy += 1;
2028 
2029  $top_shift = 0;
2030  // Show list of linked objects
2031  $current_y = $pdf->getY();
2032  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2033  if ($current_y < $pdf->getY()) {
2034  $top_shift = $pdf->getY() - $current_y;
2035  }
2036 
2037  if ($showaddress) {
2038  // Sender properties
2039  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2040 
2041  // Show sender
2042  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2043  $posy += $top_shift;
2044  $posx = $this->marge_gauche;
2045  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2046  $posx = $this->page_largeur - $this->marge_droite - 80;
2047  }
2048 
2049  $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2050  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2051 
2052 
2053  // Show sender frame
2054  if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2055  $pdf->SetTextColor(0, 0, 0);
2056  $pdf->SetFont('', '', $default_font_size - 2);
2057  $pdf->SetXY($posx, $posy - 5);
2058  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2059  $pdf->SetXY($posx, $posy);
2060  $pdf->SetFillColor(230, 230, 230);
2061  $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
2062  $pdf->SetTextColor(0, 0, 60);
2063  }
2064 
2065  // Show sender name
2066  if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2067  $pdf->SetXY($posx + 2, $posy + 3);
2068  $pdf->SetFont('', 'B', $default_font_size);
2069  $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2070  $posy = $pdf->getY();
2071  }
2072 
2073  // Show sender information
2074  $pdf->SetXY($posx + 2, $posy);
2075  $pdf->SetFont('', '', $default_font_size - 1);
2076  $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2077 
2078 
2079  // If BILLING contact defined on invoice, we use it
2080  $usecontact = false;
2081  $arrayidcontact = $object->getIdContact('external', 'BILLING');
2082  if (count($arrayidcontact) > 0) {
2083  $usecontact = true;
2084  $result = $object->fetch_contact($arrayidcontact[0]);
2085  }
2086 
2087  // Recipient name
2088  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)))) {
2089  $thirdparty = $object->contact;
2090  } else {
2091  $thirdparty = $object->thirdparty;
2092  }
2093 
2094  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2095 
2096  $mode = 'target';
2097  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
2098 
2099  // Show recipient
2100  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2101  if ($this->page_largeur < 210) {
2102  $widthrecbox = 84; // To work with US executive format
2103  }
2104  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2105  $posy += $top_shift;
2106  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2107  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2108  $posx = $this->marge_gauche;
2109  }
2110 
2111  // Show recipient frame
2112  if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2113  $pdf->SetTextColor(0, 0, 0);
2114  $pdf->SetFont('', '', $default_font_size - 2);
2115  $pdf->SetXY($posx + 2, $posy - 5);
2116  $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2117  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2118  }
2119 
2120  // Show recipient name
2121  $pdf->SetXY($posx + 2, $posy + 3);
2122  $pdf->SetFont('', 'B', $default_font_size);
2123  $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2124 
2125  $posy = $pdf->getY();
2126 
2127  // Show recipient information
2128  $pdf->SetFont('', '', $default_font_size - 1);
2129  $pdf->SetXY($posx + 2, $posy);
2130  $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2131 
2132  // Show shipping address
2133  if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2134  $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2135 
2136  if (!empty($idaddressshipping)) {
2137  $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2138  $companystatic = new Societe($this->db);
2139  $companystatic->fetch($object->contact->fk_soc);
2140  $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs);
2141  $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
2142  } else {
2143  $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2144  $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);;
2145  }
2146  if (!empty($carac_client_shipping)) {
2147  $posy += $hautcadre;
2148 
2149  // Show shipping frame
2150  $pdf->SetXY($posx + 2, $posy - 5);
2151  $pdf->SetFont('', '', $default_font_size - 2);
2152  $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2153  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2154 
2155  // Show shipping name
2156  $pdf->SetXY($posx + 2, $posy + 3);
2157  $pdf->SetFont('', 'B', $default_font_size);
2158  $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2159 
2160  $posy = $pdf->getY();
2161 
2162  // Show shipping information
2163  $pdf->SetXY($posx+2, $posy);
2164  $pdf->SetFont('', '', $default_font_size - 1);
2165  $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2166  $top_shift += $hautcadre;
2167  }
2168  }
2169  }
2170 
2171  $pdf->SetTextColor(0, 0, 0);
2172  return $top_shift;
2173  }
2174 
2175  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2185  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2186  {
2187  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2188  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);
2189  }
2190 }
Class to manage bank accounts.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage bank accounts description of third parties.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
Class to manage hooks.
Parent class of invoice document generators.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:47
Class to generate the customer invoice PDF with template Crabe.
__construct($db)
Constructor.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
Function _tableau_versements_header.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2514
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2269
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1359
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:1001
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1886
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition: pdf.lib.php:2218
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1824
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2132
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:749
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:723
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1323
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:824
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:434
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:2175
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1971
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41