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