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