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