dolibarr  19.0.0-dev
pdf_sponge.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 Ferran Marcet <fmarcet@2byte.es>
11  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
13  * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  * or see https://www.gnu.org/
28  */
29 
36 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
37 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
41 
42 
47 {
51  public $db;
52 
56  public $name;
57 
61  public $description;
62 
66  public $update_main_doc_field;
67 
71  public $type;
72 
77  public $version = 'dolibarr';
78 
82  public $page_largeur;
83 
87  public $page_hauteur;
88 
92  public $format;
93 
97  public $marge_gauche;
98 
102  public $marge_droite;
103 
107  public $marge_haute;
108 
112  public $marge_basse;
113 
114 
118  public $heightforinfotot;
119 
123  public $heightforfreetext;
124 
128  public $heightforfooter;
129 
133  public $tab_top;
134 
138  public $tab_top_newpage;
139 
144  public $emetteur;
145 
149  public $situationinvoice;
150 
151 
155  public $cols;
156 
160  public $categoryOfOperation = -1; // unknown by default
161 
162 
168  public function __construct($db)
169  {
170  global $conf, $langs, $mysoc;
171 
172  // Translations
173  $langs->loadLangs(array("main", "bills"));
174 
175  $this->db = $db;
176  $this->name = "sponge";
177  $this->description = $langs->trans('PDFSpongeDescription');
178  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
179 
180  // Dimension page
181  $this->type = 'pdf';
182  $formatarray = pdf_getFormat();
183  $this->page_largeur = $formatarray['width'];
184  $this->page_hauteur = $formatarray['height'];
185  $this->format = array($this->page_largeur, $this->page_hauteur);
186  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
187  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
188  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
189  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
190 
191  $this->option_logo = 1; // Display logo
192  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
193  $this->option_modereg = 1; // Display payment mode
194  $this->option_condreg = 1; // Display payment terms
195  $this->option_multilang = 1; // Available in several languages
196  $this->option_escompte = 1; // Displays if there has been a discount
197  $this->option_credit_note = 1; // Support credit notes
198  $this->option_freetext = 1; // Support add of a personalised text
199  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
200  $this->watermark = '';
201 
202  // Get source company
203  $this->emetteur = $mysoc;
204  if (empty($this->emetteur->country_code)) {
205  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
206  }
207 
208  // Define position of columns
209  $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
210 
211 
212  $this->tabTitleHeight = 5; // default height
213 
214  // Use new system for position of columns, view $this->defineColumnField()
215 
216  $this->tva = array();
217  $this->tva_array = array();
218  $this->localtax1 = array();
219  $this->localtax2 = array();
220  $this->atleastoneratenotnull = 0;
221  $this->atleastonediscount = 0;
222  $this->situationinvoice = false;
223  }
224 
225 
226  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
238  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
239  {
240  // phpcs:enable
241  global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
242 
243  dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
244 
245  if (!is_object($outputlangs)) {
246  $outputlangs = $langs;
247  }
248  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
249  if (!empty($conf->global->MAIN_USE_FPDF)) {
250  $outputlangs->charset_output = 'ISO-8859-1';
251  }
252 
253  // Load translation files required by the page
254  $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
255 
256  global $outputlangsbis;
257  $outputlangsbis = null;
258  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
259  $outputlangsbis = new Translate('', $conf);
260  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
261  $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
262  }
263 
264  // Show Draft Watermark
265  if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
266  $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
267  }
268 
269  $nblines = count($object->lines);
270 
271  $hidetop = 0;
272  if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
273  $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
274  }
275 
276  // Loop on each lines to detect if there is at least one image to show
277  $realpatharray = array();
278  $this->atleastonephoto = false;
279  if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
280  $objphoto = new Product($this->db);
281 
282  for ($i = 0; $i < $nblines; $i++) {
283  if (empty($object->lines[$i]->fk_product)) {
284  continue;
285  }
286 
287  $objphoto->fetch($object->lines[$i]->fk_product);
288  //var_dump($objphoto->ref);exit;
289  if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
290  $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
291  $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
292  } else {
293  $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
294  $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
295  }
296 
297  $arephoto = false;
298  foreach ($pdir as $midir) {
299  if (!$arephoto) {
300  if ($conf->entity != $objphoto->entity) {
301  $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
302  } else {
303  $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
304  }
305 
306  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
307  if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
308  if ($obj['photo_vignette']) {
309  $filename = $obj['photo_vignette'];
310  } else {
311  $filename = $obj['photo'];
312  }
313  } else {
314  $filename = $obj['photo'];
315  }
316 
317  $realpath = $dir.$filename;
318  $arephoto = true;
319  $this->atleastonephoto = true;
320  }
321  }
322  }
323 
324  if ($realpath && $arephoto) {
325  $realpatharray[$i] = $realpath;
326  }
327  }
328  }
329 
330  //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
331 
332  if ($conf->facture->multidir_output[$conf->entity]) {
333  $object->fetch_thirdparty();
334 
335  $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
336  $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
337  $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
338 
339  // Definition of $dir and $file
340  if ($object->specimen) {
341  $dir = $conf->facture->multidir_output[$conf->entity];
342  $file = $dir."/SPECIMEN.pdf";
343  } else {
344  $objectref = dol_sanitizeFileName($object->ref);
345  $dir = $conf->facture->multidir_output[$object->entity]."/".$objectref;
346  $file = $dir."/".$objectref.".pdf";
347  }
348  if (!file_exists($dir)) {
349  if (dol_mkdir($dir) < 0) {
350  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
351  return 0;
352  }
353  }
354 
355  if (file_exists($dir)) {
356  // Add pdfgeneration hook
357  if (!is_object($hookmanager)) {
358  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
359  $hookmanager = new HookManager($this->db);
360  }
361  $hookmanager->initHooks(array('pdfgeneration'));
362  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
363  global $action;
364  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
365 
366  // Set nblines with the new facture lines content after hook
367  $nblines = count($object->lines);
368  $nbpayments = count($object->getListOfPayments());
369 
370  // Create pdf instance
371  $pdf = pdf_getInstance($this->format);
372  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
373  $pdf->SetAutoPageBreak(1, 0);
374 
375  $this->heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
376  $this->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
377  $this->heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
378 
379  $heightforqrinvoice = $heightforqrinvoice_firstpage = 0;
380  if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
381  if ($this->getHeightForQRInvoice(1, $object, $langs) > 0) {
382  // Shrink infotot to a base 30
383  $this->heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
384  }
385  }
386 
387  if (class_exists('TCPDF')) {
388  $pdf->setPrintHeader(false);
389  $pdf->setPrintFooter(false);
390  }
391  $pdf->SetFont(pdf_getPDFFont($outputlangs));
392 
393  // Set path to the background PDF File
394  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
395  $logodir = $conf->mycompany->dir_output;
396  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
397  $logodir = $conf->mycompany->multidir_output[$object->entity];
398  }
399  $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
400  $tplidx = $pdf->importPage(1);
401  }
402 
403  $pdf->Open();
404  $pagenb = 0;
405  $pdf->SetDrawColor(128, 128, 128);
406 
407  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
408  $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
409  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
410  $pdf->SetAuthor($mysoc->name.($user->id > 0 ? ' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : ''));
411  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
412  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
413  $pdf->SetCompression(false);
414  }
415 
416  // Set certificate
417  $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
418  $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE;
419  // If user has no certificate, we try to take the company one
420  if (!$cert) {
421  $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
422  }
423  if (!$certprivate) {
424  $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ? '' : $conf->global->CERTIFICATE_CRT_PRIVATE;
425  }
426  // If a certificate is found
427  if ($cert) {
428  $info = array(
429  'Name' => $this->emetteur->name,
430  'Location' => getCountry($this->emetteur->country_code, 0),
431  'Reason' => 'INVOICE',
432  'ContactInfo' => $this->emetteur->email
433  );
434  $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
435  }
436 
437  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
438 
439  // Set $this->atleastonediscount if you have at least one discount
440  // and determine category of operation
441  $categoryOfOperation = 0;
442  $nbProduct = 0;
443  $nbService = 0;
444  for ($i = 0; $i < $nblines; $i++) {
445  if ($object->lines[$i]->remise_percent) {
446  $this->atleastonediscount++;
447  }
448 
449  // determine category of operation
450  if ($categoryOfOperation < 2) {
451  $lineProductType = $object->lines[$i]->product_type;
452  if ($lineProductType == Product::TYPE_PRODUCT) {
453  $nbProduct++;
454  } elseif ($lineProductType == Product::TYPE_SERVICE) {
455  $nbService++;
456  }
457  if ($nbProduct > 0 && $nbService > 0) {
458  // mixed products and services
459  $categoryOfOperation = 2;
460  }
461  }
462  }
463  // determine category of operation
464  if ($categoryOfOperation <= 0) {
465  // only services
466  if ($nbProduct == 0 && $nbService > 0) {
467  $categoryOfOperation = 1;
468  }
469  }
470  $this->categoryOfOperation = $categoryOfOperation;
471 
472  // Situation invoice handling
473  if ($object->situation_cycle_ref) {
474  $this->situationinvoice = true;
475  }
476 
477  // New page
478  $pdf->AddPage();
479  if (!empty($tplidx)) {
480  $pdf->useTemplate($tplidx);
481  }
482  $pagenb++;
483 
484  // Output header (logo, ref and address blocks). This is first call for first page.
485  $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
486  $top_shift = $pagehead['top_shift'];
487  $shipp_shift = $pagehead['shipp_shift'];
488  $pdf->SetFont('', '', $default_font_size - 1);
489  $pdf->MultiCell(0, 3, ''); // Set interline to 3
490  $pdf->SetTextColor(0, 0, 0);
491 
492  // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher
493 
494  // $this->tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks)
495  $this->tab_top = 90 + $top_shift + $shipp_shift; // top_shift is an addition for linked objects or addons (0 in most cases)
496  $this->tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
497 
498  // You can add more thing under header here, if you increase $extra_under_address_shift too.
499  $extra_under_address_shift = 0;
500  $qrcodestring = '';
501  if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
502  $qrcodestring = $object->buildZATCAQRString();
503  } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1') {
504  $qrcodestring = $object->buildSwitzerlandQRString();
505  }
506  if ($qrcodestring) {
507  $qrcodecolor = array('25', '25', '25');
508  // set style for QR-code
509  $styleQr = array(
510  'border' => false,
511  'padding' => 0,
512  'fgcolor' => $qrcodecolor,
513  'bgcolor' => false, //array(255,255,255)
514  'module_width' => 1, // width of a single module in points
515  'module_height' => 1 // height of a single module in points
516  );
517  $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $this->tab_top - 5, 25, 25, $styleQr, 'N');
518  $extra_under_address_shift += 25;
519  }
520 
521  // Call hook printUnderHeaderPDFline
522  $parameters = array(
523  'object' => $object,
524  'i' => $i,
525  'pdf' =>& $pdf,
526  'outputlangs' => $outputlangs,
527  'hidedetails' => $hidedetails
528  );
529  $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook
530  if (!empty($hookmanager->resArray['extra_under_address_shift'])) {
531  $extra_under_address_shift += $hookmanager->resArray['extra_under_header_shift'];
532  }
533 
534  $this->tab_top += $extra_under_address_shift;
535  $this->tab_top_newpage += 0;
536 
537 
538  // Define heigth of table for lines (for first page)
539  $tab_height = $this->page_hauteur - $this->tab_top - $this->heightforfooter - $this->heightforfreetext - $this->getHeightForQRInvoice(1, $object, $langs);
540 
541  $nexY = $this->tab_top - 1;
542 
543  // Incoterm
544  $height_incoterms = 0;
545  if (isModEnabled('incoterm')) {
546  $desc_incoterms = $object->getIncotermsForPDF();
547  if ($desc_incoterms) {
548  $this->tab_top -= 2;
549 
550  $pdf->SetFont('', '', $default_font_size - 1);
551  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
552  $nexY = max($pdf->GetY(), $nexY);
553  $height_incoterms = $nexY - $this->tab_top;
554 
555  // Rect takes a length in 3rd parameter
556  $pdf->SetDrawColor(192, 192, 192);
557  $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
558 
559  $this->tab_top = $nexY + 6;
560  $height_incoterms += 4;
561  }
562  }
563 
564  // Displays notes. Here we are still on code eecuted only for the first page.
565  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
566  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
567  // Get first sale rep
568  if (is_object($object->thirdparty)) {
569  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
570  $salerepobj = new User($this->db);
571  $salerepobj->fetch($salereparray[0]['id']);
572  if (!empty($salerepobj->signature)) {
573  $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
574  }
575  }
576  }
577 
578  // Extrafields in note
579  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
580  if (!empty($extranote)) {
581  $notetoshow = dol_concatdesc($notetoshow, $extranote);
582  }
583 
584  $pagenb = $pdf->getPage();
585  if ($notetoshow) {
586  $this->tab_top -= 2;
587 
588  $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
589  $pageposbeforenote = $pagenb;
590 
591  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
592  complete_substitutions_array($substitutionarray, $outputlangs, $object);
593  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
594  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
595 
596  $pdf->startTransaction();
597 
598  $pdf->SetFont('', '', $default_font_size - 1);
599  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
600  // Description
601  $pageposafternote = $pdf->getPage();
602  $posyafter = $pdf->GetY();
603 
604  if ($pageposafternote > $pageposbeforenote) {
605  $pdf->rollbackTransaction(true);
606 
607  // prepare pages to receive notes
608  while ($pagenb < $pageposafternote) {
609  $pdf->AddPage();
610  $pagenb++;
611  if (!empty($tplidx)) {
612  $pdf->useTemplate($tplidx);
613  }
614  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
615  $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
616  }
617  $pdf->setTopMargin($this->tab_top_newpage);
618  // The only function to edit the bottom margin of current page to set it.
619  $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
620  }
621 
622  // back to start
623  $pdf->setPage($pageposbeforenote);
624  $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
625  $pdf->SetFont('', '', $default_font_size - 1);
626  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $this->tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
627  $pageposafternote = $pdf->getPage();
628 
629  $posyafter = $pdf->GetY();
630 
631  if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) { // There is no space left for total+free text
632  $pdf->AddPage('', '', true);
633  $pagenb++;
634  $pageposafternote++;
635  $pdf->setPage($pageposafternote);
636  $pdf->setTopMargin($this->tab_top_newpage);
637  // The only function to edit the bottom margin of current page to set it.
638  $pdf->setPageOrientation('', 1, $this->heightforfooter + $this->heightforfreetext);
639  //$posyafter = $this->tab_top_newpage;
640  }
641 
642 
643  // apply note frame to previous pages
644  $i = $pageposbeforenote;
645  while ($i < $pageposafternote) {
646  $pdf->setPage($i);
647 
648 
649  $pdf->SetDrawColor(128, 128, 128);
650  // Draw note frame
651  if ($i > $pageposbeforenote) {
652  $height_note = $this->page_hauteur - ($this->tab_top_newpage + $this->heightforfooter);
653  $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
654  } else {
655  $height_note = $this->page_hauteur - ($this->tab_top + $this->heightforfooter);
656  $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
657  }
658 
659  // Add footer
660  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
661  $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
662 
663  $i++;
664  }
665 
666  // apply note frame to last page
667  $pdf->setPage($pageposafternote);
668  if (!empty($tplidx)) {
669  $pdf->useTemplate($tplidx);
670  }
671  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
672  $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
673  }
674  $height_note = $posyafter - $this->tab_top_newpage;
675  $pdf->Rect($this->marge_gauche, $this->tab_top_newpage - 1, $tab_width, $height_note + 1);
676  } else {
677  // No pagebreak
678  $pdf->commitTransaction();
679  $posyafter = $pdf->GetY();
680  $height_note = $posyafter - $this->tab_top;
681  $pdf->Rect($this->marge_gauche, $this->tab_top - 1, $tab_width, $height_note + 1);
682 
683 
684  if ($posyafter > ($this->page_hauteur - ($this->heightforfooter + $this->heightforfreetext + 20))) {
685  // not enough space, need to add page
686  $pdf->AddPage('', '', true);
687  $pagenb++;
688  $pageposafternote++;
689  $pdf->setPage($pageposafternote);
690  if (!empty($tplidx)) {
691  $pdf->useTemplate($tplidx);
692  }
693  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
694  $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
695  }
696 
697  $posyafter = $this->tab_top_newpage;
698  }
699  }
700 
701  $tab_height = $tab_height - $height_note;
702  $this->tab_top = $posyafter + 6;
703  } else {
704  $height_note = 0;
705  }
706 
707  // Use new auto column system
708  $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
709 
710  // Table simulation to know the height of the title line (this set this->tableTitleHeight)
711  $pdf->startTransaction();
712  $this->pdfTabTitles($pdf, $this->tab_top, $tab_height, $outputlangs, $hidetop);
713  $pdf->rollbackTransaction(true);
714 
715  $nexY = $this->tab_top + $this->tabTitleHeight;
716 
717  // Loop on each lines
718  $pageposbeforeprintlines = $pdf->getPage();
719  $pagenb = $pageposbeforeprintlines;
720  for ($i = 0; $i < $nblines; $i++) {
721  $curY = $nexY;
722  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
723  $pdf->SetTextColor(0, 0, 0);
724 
725  // Define size of image if we need it
726  $imglinesize = array();
727  if (!empty($realpatharray[$i])) {
728  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
729  }
730 
731  $pdf->setTopMargin($this->tab_top_newpage);
732  $page_bottom_margin = $this->heightforfooter + $this->heightforfreetext + $this->heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs);
733  $pdf->setPageOrientation('', 1, $page_bottom_margin);
734  $pageposbefore = $pdf->getPage();
735 
736  $showpricebeforepagebreak = 1;
737  $posYAfterImage = 0;
738  $posYAfterDescription = 0;
739 
740  if ($this->getColumnStatus('photo')) {
741  // We start with Photo of product line
742  if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - $page_bottom_margin)) { // If photo too high, we moved completely on new page
743  $pdf->AddPage('', '', true);
744  if (!empty($tplidx)) {
745  $pdf->useTemplate($tplidx);
746  }
747  $pdf->setPage($pageposbefore + 1);
748 
749  $curY = $this->tab_top_newpage;
750 
751  // Allows data in the first page if description is long enough to break in multiples pages
752  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
753  $showpricebeforepagebreak = 1;
754  } else {
755  $showpricebeforepagebreak = 0;
756  }
757  }
758 
759  if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
760  $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
761  // $pdf->Image does not increase value return by getY, so we save it manually
762  $posYAfterImage = $curY + $imglinesize['height'];
763  }
764  }
765 
766  // Description of product line
767  if ($this->getColumnStatus('desc')) {
768  $pdf->startTransaction();
769 
770  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
771  $pageposafter = $pdf->getPage();
772 
773  if ($pageposafter > $pageposbefore) { // There is a pagebreak
774  $pdf->rollbackTransaction(true);
775  $pageposafter = $pageposbefore;
776  $pdf->setPageOrientation('', 1, $this->heightforfooter); // The only function to edit the bottom margin of current page to set it.
777 
778  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
779 
780  $pageposafter = $pdf->getPage();
781  $posyafter = $pdf->GetY();
782  //var_dump($posyafter); var_dump(($this->page_hauteur - ($this->heightforfooter+$this->heightforfreetext+$this->heightforinfotot))); exit;
783  if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) { // There is no space left for total+free text
784  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
785  $pdf->AddPage('', '', true);
786  if (!empty($tplidx)) {
787  $pdf->useTemplate($tplidx);
788  }
789  $pdf->setPage($pageposafter + 1);
790  }
791  } else {
792  // We found a page break
793  // Allows data in the first page if description is long enough to break in multiples pages
794  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
795  $showpricebeforepagebreak = 1;
796  } else {
797  $showpricebeforepagebreak = 0;
798  }
799  }
800  } else // No pagebreak
801  {
802  $pdf->commitTransaction();
803  }
804  $posYAfterDescription = $pdf->GetY();
805  }
806 
807  $nexY = max($pdf->GetY(), $posYAfterImage, $posYAfterDescription);
808 
809  $pageposafter = $pdf->getPage();
810  $pdf->setPage($pageposbefore);
811  $pdf->setTopMargin($this->marge_haute);
812  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
813 
814  // We suppose that a too long description or photo were moved completely on next page
815  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
816  $pdf->setPage($pageposafter);
817  $curY = $this->tab_top_newpage;
818  }
819 
820  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
821 
822  // VAT Rate
823  if ($this->getColumnStatus('vat')) {
824  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
825  $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
826  $nexY = max($pdf->GetY(), $nexY);
827  }
828 
829  // Unit price before discount
830  if ($this->getColumnStatus('subprice')) {
831  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
832  $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
833  $nexY = max($pdf->GetY(), $nexY);
834  }
835 
836  // Quantity
837  // Enough for 6 chars
838  if ($this->getColumnStatus('qty')) {
839  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
840  $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
841  $nexY = max($pdf->GetY(), $nexY);
842  }
843 
844  // Situation progress
845  if ($this->getColumnStatus('progress')) {
846  $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
847  $this->printStdColumnContent($pdf, $curY, 'progress', $progress);
848  $nexY = max($pdf->GetY(), $nexY);
849  }
850 
851  // Unit
852  if ($this->getColumnStatus('unit')) {
853  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
854  $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
855  $nexY = max($pdf->GetY(), $nexY);
856  }
857 
858  // Discount on line
859  if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
860  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
861  $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
862  $nexY = max($pdf->GetY(), $nexY);
863  }
864 
865  // Total excl tax line (HT)
866  if ($this->getColumnStatus('totalexcltax')) {
867  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
868  $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
869  $nexY = max($pdf->GetY(), $nexY);
870  }
871 
872  // Total with tax line (TTC)
873  if ($this->getColumnStatus('totalincltax')) {
874  $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
875  $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
876  $nexY = max($pdf->GetY(), $nexY);
877  }
878 
879  // Extrafields
880  if (!empty($object->lines[$i]->array_options)) {
881  foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
882  if ($this->getColumnStatus($extrafieldColKey)) {
883  $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
884  $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
885  $nexY = max($pdf->GetY(), $nexY);
886  }
887  }
888  }
889 
890 
891  $parameters = array(
892  'object' => $object,
893  'i' => $i,
894  'pdf' =>& $pdf,
895  'curY' =>& $curY,
896  'nexY' =>& $nexY,
897  'outputlangs' => $outputlangs,
898  'hidedetails' => $hidedetails
899  );
900  $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
901 
902 
903  $sign = 1;
904  if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
905  $sign = -1;
906  }
907  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
908  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
909  if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
910  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
911  $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
912  } else {
913  $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
914  }
915  } else {
916  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
917  $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
918  } else {
919  $tvaligne = $sign * $object->lines[$i]->total_tva;
920  }
921  }
922 
923  $localtax1ligne = $object->lines[$i]->total_localtax1;
924  $localtax2ligne = $object->lines[$i]->total_localtax2;
925  $localtax1_rate = $object->lines[$i]->localtax1_tx;
926  $localtax2_rate = $object->lines[$i]->localtax2_tx;
927  $localtax1_type = $object->lines[$i]->localtax1_type;
928  $localtax2_type = $object->lines[$i]->localtax2_type;
929 
930  // TODO remise_percent is an obsolete field for object parent
931  /*if ($object->remise_percent) {
932  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
933  }
934  if ($object->remise_percent) {
935  $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
936  }
937  if ($object->remise_percent) {
938  $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
939  }*/
940 
941  $vatrate = (string) $object->lines[$i]->tva_tx;
942 
943  // Retrieve type from database for backward compatibility with old records
944  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
945  && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
946  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
947  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
948  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
949  }
950 
951  // retrieve global local tax
952  if ($localtax1_type && $localtax1ligne != 0) {
953  if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
954  $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
955  } else {
956  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
957  }
958  }
959  if ($localtax2_type && $localtax2ligne != 0) {
960  if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
961  $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
962  } else {
963  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
964  }
965  }
966 
967  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
968  $vatrate .= '*';
969  }
970 
971  // Fill $this->tva and $this->tva_array
972  if (!isset($this->tva[$vatrate])) {
973  $this->tva[$vatrate] = 0;
974  }
975  $this->tva[$vatrate] += $tvaligne; // ->tva is abandonned, we use now ->tva_array that is more complete
976  $vatcode = $object->lines[$i]->vat_src_code;
977  if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
978  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
979  }
980  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
981 
982  $nexY = max($nexY, $posYAfterImage);
983 
984  // Add line
985  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
986  $pdf->setPage($pageposafter);
987  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
988  //$pdf->SetDrawColor(190,190,200);
989  $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
990  $pdf->SetLineStyle(array('dash'=>0));
991  }
992 
993  // Detect if some page were added automatically and output _tableau for past pages
994  while ($pagenb < $pageposafter) {
995  $pdf->setPage($pagenb);
996  $heightforqrinvoice = $this->getHeightForQRInvoice($pagenb, $object, $langs);
997  if ($pagenb == $pageposbeforeprintlines) {
998  $this->_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
999  } else {
1000  $this->_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
1001  }
1002  $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1003  $pagenb++;
1004  $pdf->setPage($pagenb);
1005  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
1006  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1007  $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1008  }
1009  if (!empty($tplidx)) {
1010  $pdf->useTemplate($tplidx);
1011  }
1012  }
1013 
1014  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
1015  $heightforqrinvoice = $this->getHeightForQRInvoice($pagenb, $object, $langs);
1016  if ($pagenb == $pageposafter) {
1017  $this->_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
1018  } else {
1019  $this->_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
1020  }
1021  $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1022  // New page
1023  $pdf->AddPage();
1024  if (!empty($tplidx)) {
1025  $pdf->useTemplate($tplidx);
1026  }
1027  $pagenb++;
1028  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1029  $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1030  }
1031  }
1032  }
1033 
1034  // Show square
1035  $heightforqrinvoice = $this->getHeightForQRInvoice($pagenb, $object, $langs);
1036  if ($pagenb == $pageposbeforeprintlines) {
1037  $this->_tableau($pdf, $this->tab_top, $this->page_hauteur - $this->tab_top - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
1038  $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1039  } else {
1040  $this->_tableau($pdf, $this->tab_top_newpage, $this->page_hauteur - $this->tab_top_newpage - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
1041  $bottomlasttab = $this->page_hauteur - $this->heightforinfotot - $this->heightforfreetext - $this->heightforfooter - $heightforqrinvoice + 1;
1042  }
1043 
1044  // Display infos area
1045  $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
1046 
1047  // Display total zone
1048  $posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
1049 
1050  // Display payment area
1051  if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1052  $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
1053  }
1054 
1055  // Pagefoot
1056  $this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pageposbefore, $object, $langs));
1057  if (method_exists($pdf, 'AliasNbPages')) {
1058  $pdf->AliasNbPages();
1059  }
1060 
1061  if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') {
1062  $this->addBottomQRInvoice($pdf, $object, $outputlangs);
1063  }
1064  $pdf->Close();
1065 
1066  $pdf->Output($file, 'F');
1067 
1068  // Add pdfgeneration hook
1069  $hookmanager->initHooks(array('pdfgeneration'));
1070  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
1071  global $action;
1072  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1073  if ($reshook < 0) {
1074  $this->error = $hookmanager->error;
1075  $this->errors = $hookmanager->errors;
1076  }
1077 
1078  dolChmod($file);
1079 
1080  $this->result = array('fullpath'=>$file);
1081 
1082  return 1; // No error
1083  } else {
1084  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
1085  return 0;
1086  }
1087  } else {
1088  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
1089  return 0;
1090  }
1091  }
1092 
1093 
1103  public function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
1104  {
1105  global $conf;
1106 
1107  $sign = 1;
1108  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1109  $sign = -1;
1110  }
1111 
1112  $tab3_posx = 120;
1113  $tab3_top = $posy + 8;
1114  $tab3_width = 80;
1115  $tab3_height = 4;
1116  if ($this->page_largeur < 210) { // To work with US executive format
1117  $tab3_posx -= 15;
1118  }
1119 
1120  $default_font_size = pdf_getPDFFontSize($outputlangs);
1121 
1122  $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1123  if ($object->type == 2) {
1124  $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone");
1125  }
1126 
1127  $pdf->SetFont('', '', $default_font_size - 3);
1128  $pdf->SetXY($tab3_posx, $tab3_top - 4);
1129  $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1130 
1131  $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1132 
1133  $pdf->SetFont('', '', $default_font_size - 4);
1134  $pdf->SetXY($tab3_posx, $tab3_top);
1135  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1136  $pdf->SetXY($tab3_posx + 21, $tab3_top);
1137  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1138  $pdf->SetXY($tab3_posx + 40, $tab3_top);
1139  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1140  $pdf->SetXY($tab3_posx + 58, $tab3_top);
1141  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1142 
1143  $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1144 
1145  $y = 0;
1146 
1147  $pdf->SetFont('', '', $default_font_size - 4);
1148 
1149 
1150  // Loop on each discount available (deposits and credit notes and excess of payment included)
1151  $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
1152  $sql .= " re.description, re.fk_facture_source,";
1153  $sql .= " f.type, f.datef";
1154  $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f";
1155  $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
1156  $resql = $this->db->query($sql);
1157  if ($resql) {
1158  $num = $this->db->num_rows($resql);
1159  $i = 0;
1160  $invoice = new Facture($this->db);
1161  while ($i < $num) {
1162  $y += 3;
1163  $obj = $this->db->fetch_object($resql);
1164 
1165  if ($obj->type == 2) {
1166  $text = $outputlangs->transnoentities("CreditNote");
1167  } elseif ($obj->type == 3) {
1168  $text = $outputlangs->transnoentities("Deposit");
1169  } elseif ($obj->type == 0) {
1170  $text = $outputlangs->transnoentities("ExcessReceived");
1171  } else {
1172  $text = $outputlangs->transnoentities("UnknownType");
1173  }
1174 
1175  $invoice->fetch($obj->fk_facture_source);
1176 
1177  $pdf->SetXY($tab3_posx, $tab3_top + $y);
1178  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0);
1179  $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1180  $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
1181  $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1182  $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
1183  $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1184  $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
1185 
1186  $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1187 
1188  $i++;
1189  }
1190  } else {
1191  $this->error = $this->db->lasterror();
1192  return -1;
1193  }
1194 
1195  // Loop on each payment
1196  // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
1197  $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1198  $sql .= " cp.code";
1199  $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
1200  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1201  $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1202  //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
1203  $sql .= " ORDER BY p.datep";
1204 
1205  $resql = $this->db->query($sql);
1206  if ($resql) {
1207  $num = $this->db->num_rows($resql);
1208  $i = 0;
1209  while ($i < $num) {
1210  $y += 3;
1211  $row = $this->db->fetch_object($resql);
1212 
1213  $pdf->SetXY($tab3_posx, $tab3_top + $y);
1214  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1215  $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1216  $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
1217  $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1218  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1219 
1220  $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1221  $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1222  $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1223 
1224  $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1225 
1226  $i++;
1227  }
1228 
1229  return $tab3_top + $y + 3;
1230  } else {
1231  $this->error = $this->db->lasterror();
1232  return -1;
1233  }
1234  }
1235 
1236 
1247  protected function drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1248  {
1249  global $conf, $mysoc;
1250 
1251  $default_font_size = pdf_getPDFFontSize($outputlangs);
1252 
1253  $pdf->SetFont('', '', $default_font_size - 1);
1254 
1255  // If France, show VAT mention if not applicable
1256  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
1257  $pdf->SetFont('', 'B', $default_font_size - 2);
1258  $pdf->SetXY($this->marge_gauche, $posy);
1259  if ($mysoc->forme_juridique_code == 92) {
1260  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0);
1261  } else {
1262  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
1263  }
1264 
1265  $posy = $pdf->GetY() + 4;
1266  }
1267 
1268  $posxval = 52; // Position of values of properties shown on left side
1269  $posxend = 110; // End of x for text on left side
1270  if ($this->page_largeur < 210) { // To work with US executive format
1271  $posxend -= 10;
1272  }
1273 
1274  // Show payments conditions
1275  if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1276  $pdf->SetFont('', 'B', $default_font_size - 2);
1277  $pdf->SetXY($this->marge_gauche, $posy);
1278  $titre = $outputlangs->transnoentities("PaymentConditions").':';
1279  $pdf->MultiCell($posxval - $this->marge_gauche, 4, $titre, 0, 'L');
1280 
1281  $pdf->SetFont('', '', $default_font_size - 2);
1282  $pdf->SetXY($posxval, $posy);
1283  $lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
1284  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
1285  $pdf->MultiCell($posxend - $posxval, 4, $lib_condition_paiement, 0, 'L');
1286 
1287  $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions
1288  }
1289 
1290  // Show category of operations
1291  if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1292  $pdf->SetFont('', 'B', $default_font_size - 2);
1293  $pdf->SetXY($this->marge_gauche, $posy);
1294  $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : ';
1295  $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L');
1296 
1297  $pdf->SetFont('', '', $default_font_size - 2);
1298  $pdf->SetXY($posxval, $posy);
1299  $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
1300  $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L');
1301 
1302  $posy = $pdf->GetY() + 3; // for 2 lines
1303  }
1304 
1305  if ($object->type != 2) {
1306  // Check a payment mode is defined
1307  if (empty($object->mode_reglement_code)
1308  && !getDolGlobalInt('FACTURE_CHQ_NUMBER')
1309  && !getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1310  $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
1311  } elseif (($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))
1312  || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1313  // Avoid having any valid PDF with setup that is not complete
1314  $outputlangs->load("errors");
1315 
1316  $pdf->SetXY($this->marge_gauche, $posy);
1317  $pdf->SetTextColor(200, 0, 0);
1318  $pdf->SetFont('', 'B', $default_font_size - 2);
1319  $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1320  $pdf->MultiCell($posxend - $this->marge_gauche, 3, $this->error, 0, 'L', 0);
1321  $pdf->SetTextColor(0, 0, 0);
1322 
1323  $posy = $pdf->GetY() + 1;
1324  }
1325 
1326  // Show payment mode
1327  if (!empty($object->mode_reglement_code)
1328  && $object->mode_reglement_code != 'CHQ'
1329  && $object->mode_reglement_code != 'VIR') {
1330  $pdf->SetFont('', 'B', $default_font_size - 2);
1331  $pdf->SetXY($this->marge_gauche, $posy);
1332  $titre = $outputlangs->transnoentities("PaymentMode").':';
1333  $pdf->MultiCell($posxend - $this->marge_gauche, 5, $titre, 0, 'L');
1334 
1335  $pdf->SetFont('', '', $default_font_size - 2);
1336  $pdf->SetXY($posxval, $posy);
1337  $lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1338 
1339  //#21654: add account number used for the debit
1340  if ($object->mode_reglement_code == "PRE") {
1341  require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
1342  $bac = new CompanyBankAccount($this->db);
1343  $bac->fetch(0, $object->thirdparty->id);
1344  $iban= $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
1345  $lib_mode_reg .= ' '.$outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1));
1346  }
1347 
1348  $pdf->MultiCell($posxend - $posxval, 5, $lib_mode_reg, 0, 'L');
1349 
1350  $posy = $pdf->GetY();
1351  }
1352 
1353  // Show if Option VAT debit option is on also if transmitter is french
1354  // Decret n°2099-1299 2022-10-07
1355  // French mention : "Option pour le paiement de la taxe d'après les débits"
1356  if ($this->emetteur->country_code == 'FR') {
1357  if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1358  $pdf->SetXY($this->marge_gauche, $posy);
1359  $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1);
1360 
1361  $posy = $pdf->GetY() + 1;
1362  }
1363  }
1364 
1365  // Show online payment link
1366  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') {
1367  $useonlinepayment = 0;
1368  if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1369  if (isModEnabled('paypal')) {
1370  $useonlinepayment++;
1371  }
1372  if (isModEnabled('stripe')) {
1373  $useonlinepayment++;
1374  }
1375  if (isModEnabled('paybox')) {
1376  $useonlinepayment++;
1377  }
1378  }
1379 
1380 
1381  if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) {
1382  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1383  global $langs;
1384 
1385  $langs->loadLangs(array('payment', 'paybox', 'stripe'));
1386  $servicename = $langs->transnoentities('Online');
1387  $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', '');
1388  $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename).' <a href="'.$paiement_url.'">'.$outputlangs->transnoentities("ClickHere").'</a>';
1389 
1390  $pdf->SetXY($this->marge_gauche, $posy);
1391  $pdf->writeHTMLCell($posxend - $this->marge_gauche, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1);
1392 
1393  $posy = $pdf->GetY() + 1;
1394  }
1395  }
1396 
1397  // Show payment mode CHQ
1398  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
1399  // If payment mode unregulated or payment mode forced to CHQ
1400  if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) {
1401  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1402 
1403  if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1404  $account = new Account($this->db);
1405  $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER'));
1406 
1407  $pdf->SetXY($this->marge_gauche, $posy);
1408  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1409  $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
1410  $posy = $pdf->GetY() + 1;
1411 
1412  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1413  $pdf->SetXY($this->marge_gauche, $posy);
1414  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1415  $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
1416  $posy = $pdf->GetY() + 2;
1417  }
1418  }
1419  if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1420  $pdf->SetXY($this->marge_gauche, $posy);
1421  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
1422  $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
1423  $posy = $pdf->GetY() + 1;
1424 
1425  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1426  $pdf->SetXY($this->marge_gauche, $posy);
1427  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
1428  $pdf->MultiCell($posxend - $this->marge_gauche, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
1429  $posy = $pdf->GetY() + 2;
1430  }
1431  }
1432  }
1433  }
1434 
1435  // If payment mode not forced or forced to VIR, show payment with BAN
1436  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
1437  if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
1438  $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1439  if ($object->fk_bank > 0) {
1440  $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1441  }
1442  $account = new Account($this->db);
1443  $account->fetch($bankid);
1444 
1445  $curx = $this->marge_gauche;
1446  $cury = $posy;
1447 
1448  $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1449 
1450  $posy += 2;
1451  }
1452  }
1453  }
1454 
1455  return $posy;
1456  }
1457 
1458 
1470  protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1471  {
1472  global $conf, $mysoc, $hookmanager;
1473 
1474  $sign = 1;
1475  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1476  $sign = -1;
1477  }
1478 
1479  $default_font_size = pdf_getPDFFontSize($outputlangs);
1480 
1481  $tab2_top = $posy;
1482  $tab2_hl = 4;
1483  if (is_object($outputlangsbis)) { // When we show 2 languages we need more room for text, so we use a smaller font.
1484  $pdf->SetFont('', '', $default_font_size - 2);
1485  } else {
1486  $pdf->SetFont('', '', $default_font_size - 1);
1487  }
1488 
1489  // Total table
1490  $col1x = 120;
1491  $col2x = 170;
1492  if ($this->page_largeur < 210) { // To work with US executive format
1493  $col1x -= 15;
1494  $col2x -= 10;
1495  }
1496  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1497 
1498  $useborder = 0;
1499  $index = 0;
1500 
1501  // Add trigger to allow to edit $object
1502  $parameters = array(
1503  'object' => &$object,
1504  'outputlangs' => $outputlangs,
1505  );
1506  $hookmanager->executeHooks('beforePercentCalculation', $parameters, $this); // Note that $object may have been modified by hook
1507 
1508  // overall percentage of advancement
1509  $percent = 0;
1510  $i = 0;
1511  foreach ($object->lines as $line) {
1512  $percent += $line->situation_percent;
1513  $i++;
1514  }
1515 
1516  if (!empty($i)) {
1517  $avancementGlobal = $percent / $i;
1518  } else {
1519  $avancementGlobal = 0;
1520  }
1521 
1522  $object->fetchPreviousNextSituationInvoice();
1523  $TPreviousIncoice = $object->tab_previous_situation_invoice;
1524 
1525  $total_a_payer = 0;
1526  $total_a_payer_ttc = 0;
1527  foreach ($TPreviousIncoice as &$fac) {
1528  $total_a_payer += $fac->total_ht;
1529  $total_a_payer_ttc += $fac->total_ttc;
1530  }
1531  $total_a_payer += $object->total_ht;
1532  $total_a_payer_ttc += $object->total_ttc;
1533 
1534  if (!empty($avancementGlobal)) {
1535  $total_a_payer = $total_a_payer * 100 / $avancementGlobal;
1536  $total_a_payer_ttc = $total_a_payer_ttc * 100 / $avancementGlobal;
1537  } else {
1538  $total_a_payer = 0;
1539  $total_a_payer_ttc = 0;
1540  }
1541 
1542  $i = 1;
1543  if (!empty($TPreviousIncoice)) {
1544  $pdf->setY($tab2_top);
1545  $posy = $pdf->GetY();
1546 
1547  foreach ($TPreviousIncoice as &$fac) {
1548  if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1549  $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pdf->getPage(), $object, $outputlangs));
1550  $pdf->addPage();
1551  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1552  $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1553  $pdf->setY($this->tab_top_newpage);
1554  } else {
1555  $pdf->setY($this->marge_haute);
1556  }
1557  $posy = $pdf->GetY();
1558  }
1559 
1560  // Cumulate preceding VAT
1561  $index++;
1562  $pdf->SetFillColor(255, 255, 255);
1563  $pdf->SetXY($col1x, $posy);
1564  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $fac->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1565 
1566  $pdf->SetXY($col2x, $posy);
1567 
1568  $facSign = '';
1569  if ($i > 1) {
1570  $facSign = $fac->total_ht >= 0 ? '+' : '';
1571  }
1572 
1573  $displayAmount = ' '.$facSign.' '.price($fac->total_ht, 0, $outputlangs);
1574 
1575  $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1576 
1577  $i++;
1578  $posy += $tab2_hl;
1579 
1580  $pdf->setY($posy);
1581  }
1582 
1583  // Display current total
1584  $pdf->SetFillColor(255, 255, 255);
1585  $pdf->SetXY($col1x, $posy);
1586  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFSituationTitle", $object->situation_counter).' '.$outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1587 
1588  $pdf->SetXY($col2x, $posy);
1589  $facSign = '';
1590  if ($i > 1) {
1591  $facSign = $object->total_ht >= 0 ? '+' : ''; // management of a particular customer case
1592  }
1593 
1594  if ($fac->type === Facture::TYPE_CREDIT_NOTE) {
1595  $facSign = '-'; // les avoirs
1596  }
1597 
1598 
1599  $displayAmount = ' '.$facSign.' '.price($object->total_ht, 0, $outputlangs);
1600  $pdf->MultiCell($largcol2, $tab2_hl, $displayAmount, 0, 'R', 1);
1601 
1602  $posy += $tab2_hl;
1603 
1604  // Display all total
1605  $pdf->SetFont('', '', $default_font_size - 1);
1606  $pdf->SetFillColor(255, 255, 255);
1607  $pdf->SetXY($col1x, $posy);
1608  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("SituationTotalProgress", $avancementGlobal), 0, 'L', 1);
1609 
1610  $pdf->SetXY($col2x, $posy);
1611  $pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer * $avancementGlobal / 100, 0, $outputlangs), 0, 'R', 1);
1612  $pdf->SetFont('', '', $default_font_size - 2);
1613 
1614  $posy += $tab2_hl;
1615 
1616  if ($posy > $this->page_hauteur - 4 - $this->heightforfooter) {
1617  $pdf->addPage();
1618  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
1619  $this->_pagehead($pdf, $object, 0, $outputlangs, $outputlangsbis);
1620  $pdf->setY($this->tab_top_newpage);
1621  } else {
1622  $pdf->setY($this->marge_haute);
1623  }
1624 
1625  $posy = $pdf->GetY();
1626  }
1627 
1628  $tab2_top = $posy;
1629  $index = 0;
1630 
1631  $tab2_top += 3;
1632  }
1633 
1634 
1635  // Get Total HT
1636  $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1637 
1638  // Total remise
1639  $total_line_remise = 0;
1640  foreach ($object->lines as $i => $line) {
1641  $total_line_remise += pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); // TODO: add this method to core/lib/pdf.lib
1642  // Gestion remise sous forme de ligne négative
1643  if ($line->total_ht < 0) {
1644  $total_line_remise += -$line->total_ht;
1645  }
1646  }
1647  if ($total_line_remise > 0) {
1648  if (!empty($conf->global->MAIN_SHOW_AMOUNT_DISCOUNT)) {
1649  $pdf->SetFillColor(255, 255, 255);
1650  $pdf->SetXY($col1x, $tab2_top + $tab2_hl);
1651  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1);
1652  $pdf->SetXY($col2x, $tab2_top + $tab2_hl);
1653  $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1);
1654 
1655  $index++;
1656  }
1657  // Show total NET before discount
1658  if (!empty($conf->global->MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT)) {
1659  $pdf->SetFillColor(255, 255, 255);
1660  $pdf->SetXY($col1x, $tab2_top);
1661  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1);
1662  $pdf->SetXY($col2x, $tab2_top);
1663  $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1);
1664 
1665  $index++;
1666  }
1667  }
1668 
1669  // Total HT
1670  $pdf->SetFillColor(255, 255, 255);
1671  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1672  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ? "TotalHT" : "Total") : ''), 0, 'L', 1);
1673 
1674  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1675  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1676  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
1677 
1678  // Show VAT by rates and total
1679  $pdf->SetFillColor(248, 248, 248);
1680 
1681  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1682 
1683  $this->atleastoneratenotnull = 0;
1684  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1685  $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1686  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1687  // Nothing to do
1688  } else {
1689  // FIXME amount of vat not supported with multicurrency
1690 
1691  //Local tax 1 before VAT
1692  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1693  //{
1694  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1695  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1696  continue;
1697  }
1698 
1699  foreach ($localtax_rate as $tvakey => $tvaval) {
1700  if ($tvakey != 0) { // On affiche pas taux 0
1701  //$this->atleastoneratenotnull++;
1702 
1703  $index++;
1704  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1705 
1706  $tvacompl = '';
1707  if (preg_match('/\*/', $tvakey)) {
1708  $tvakey = str_replace('*', '', $tvakey);
1709  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1710  }
1711 
1712  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1713  $totalvat .= ' ';
1714  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1715  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1716 
1717  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1718  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1719  }
1720  }
1721  }
1722  //}
1723  //Local tax 2 before VAT
1724  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1725  //{
1726  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1727  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1728  continue;
1729  }
1730 
1731  foreach ($localtax_rate as $tvakey => $tvaval) {
1732  if ($tvakey != 0) { // On affiche pas taux 0
1733  //$this->atleastoneratenotnull++;
1734 
1735  $index++;
1736  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1737 
1738  $tvacompl = '';
1739  if (preg_match('/\*/', $tvakey)) {
1740  $tvakey = str_replace('*', '', $tvakey);
1741  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1742  }
1743  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1744  $totalvat .= ' ';
1745  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1746  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1747 
1748  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1749  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1750  }
1751  }
1752  }
1753  //}
1754 
1755  // Situations totals migth be wrong on huge amounts with old mode 1
1756  if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1 && $object->situation_cycle_ref && $object->situation_counter > 1) {
1757  $sum_pdf_tva = 0;
1758  foreach ($this->tva as $tvakey => $tvaval) {
1759  $sum_pdf_tva += $tvaval; // sum VAT amounts to compare to object
1760  }
1761 
1762  if ($sum_pdf_tva != $object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1763  if (!empty($sum_pdf_tva)) {
1764  $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1765  } else {
1766  $coef_fix_tva = 1;
1767  }
1768 
1769 
1770  foreach ($this->tva as $tvakey => $tvaval) {
1771  $this->tva[$tvakey] = $tvaval * $coef_fix_tva;
1772  }
1773  foreach ($this->tva_array as $tvakey => $tvaval) {
1774  $this->tva_array[$tvakey]['amount'] = $tvaval['amount'] * $coef_fix_tva;
1775  }
1776  }
1777  }
1778 
1779  // VAT
1780  foreach ($this->tva_array as $tvakey => $tvaval) {
1781  if ($tvakey != 0) { // On affiche pas taux 0
1782  $this->atleastoneratenotnull++;
1783 
1784  $index++;
1785  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1786 
1787  $tvacompl = '';
1788  if (preg_match('/\*/', $tvakey)) {
1789  $tvakey = str_replace('*', '', $tvakey);
1790  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1791  }
1792  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1793  $totalvat .= ' ';
1794  if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1795  $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1796  } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1797  $totalvat .= ($tvaval['vatcode'] ? $tvaval['vatcode'] : vatrate($tvaval['vatrate'], 1)).$tvacompl;
1798  } else {
1799  $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1800  }
1801  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1802 
1803  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1804  $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1805  }
1806  }
1807 
1808  //Local tax 1 after VAT
1809  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1810  //{
1811  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1812  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1813  continue;
1814  }
1815 
1816  foreach ($localtax_rate as $tvakey => $tvaval) {
1817  if ($tvakey != 0) { // On affiche pas taux 0
1818  //$this->atleastoneratenotnull++;
1819 
1820  $index++;
1821  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1822 
1823  $tvacompl = '';
1824  if (preg_match('/\*/', $tvakey)) {
1825  $tvakey = str_replace('*', '', $tvakey);
1826  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1827  }
1828  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1829  $totalvat .= ' ';
1830  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1831 
1832  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1833  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1834  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1835  }
1836  }
1837  }
1838  //}
1839  //Local tax 2 after VAT
1840  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1841  //{
1842  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1843  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1844  continue;
1845  }
1846 
1847  foreach ($localtax_rate as $tvakey => $tvaval) {
1848  // retrieve global local tax
1849  if ($tvakey != 0) { // On affiche pas taux 0
1850  //$this->atleastoneratenotnull++;
1851 
1852  $index++;
1853  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1854 
1855  $tvacompl = '';
1856  if (preg_match('/\*/', $tvakey)) {
1857  $tvakey = str_replace('*', '', $tvakey);
1858  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1859  }
1860  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1861  $totalvat .= ' ';
1862 
1863  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1864  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1865 
1866  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1867  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1868  }
1869  }
1870  }
1871 
1872 
1873  // Revenue stamp
1874  if (price2num($object->revenuestamp) != 0) {
1875  $index++;
1876  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1877  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RevenueStamp", $mysoc->country_code) : ''), $useborder, 'L', 1);
1878 
1879  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1880  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1881  }
1882 
1883  // Total TTC
1884  $index++;
1885  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1886  $pdf->SetTextColor(0, 0, 60);
1887  $pdf->SetFillColor(224, 224, 224);
1888  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
1889 
1890  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1891  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1892 
1893 
1894  // Retained warranty
1895  if ($object->displayRetainedWarranty()) {
1896  $pdf->SetTextColor(40, 40, 40);
1897  $pdf->SetFillColor(255, 255, 255);
1898 
1899  $retainedWarranty = $object->getRetainedWarrantyAmount();
1900  $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1901 
1902  // Billed - retained warranty
1903  $index++;
1904  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1905  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
1906 
1907  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1908  $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
1909 
1910  // retained warranty
1911  $index++;
1912  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1913 
1914  $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RetainedWarranty") : '').' ('.$object->retained_warranty.'%)';
1915  $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
1916 
1917  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
1918  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1919  $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
1920  }
1921  }
1922  }
1923 
1924  $pdf->SetTextColor(0, 0, 0);
1925 
1926  $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
1927  $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1928 
1929  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1930  if (!empty($object->paye)) {
1931  $resteapayer = 0;
1932  }
1933 
1934  if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1935  // Already paid + Deposits
1936  $index++;
1937  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1938  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("Paid") : ''), 0, 'L', 0);
1939  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1940  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1941 
1942  // Credit note
1943  if ($creditnoteamount) {
1944  $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
1945  $labeltouse .= (is_object($outputlangsbis) ? (' / '.($outputlangsbis->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangsbis->transnoentities("CreditNotesOrExcessReceived") : $outputlangsbis->transnoentities("CreditNotes")) : '');
1946  $index++;
1947  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1948  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
1949  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1950  $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1951  }
1952 
1953  /*
1954  if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1955  {
1956  $index++;
1957  $pdf->SetFillColor(255, 255, 255);
1958 
1959  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1960  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("EscompteOfferedShort") : ''), $useborder, 'L', 1);
1961  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1962  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1963 
1964  $resteapayer = 0;
1965  }
1966  */
1967 
1968  $index++;
1969  $pdf->SetTextColor(0, 0, 60);
1970  $pdf->SetFillColor(224, 224, 224);
1971  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1972  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
1973  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1974  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1975 
1976  $pdf->SetFont('', '', $default_font_size - 1);
1977  $pdf->SetTextColor(0, 0, 0);
1978  }
1979 
1980  $index++;
1981  return ($tab2_top + ($tab2_hl * $index));
1982  }
1983 
1984  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1992  public static function liste_modeles($db, $maxfilenamelength = 0)
1993  {
1994  // phpcs:enable
1995  return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
1996  }
1997 
1998  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2013  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
2014  {
2015  global $conf;
2016 
2017  // Force to disable hidetop and hidebottom
2018  $hidebottom = 0;
2019  if ($hidetop) {
2020  $hidetop = -1;
2021  }
2022 
2023  $currency = !empty($currency) ? $currency : $conf->currency;
2024  $default_font_size = pdf_getPDFFontSize($outputlangs);
2025 
2026  // Amount in (at tab_top - 1)
2027  $pdf->SetTextColor(0, 0, 0);
2028  $pdf->SetFont('', '', $default_font_size - 2);
2029 
2030  if (empty($hidetop)) {
2031  // Show category of operations
2032  if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
2033  $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation);
2034  $pdf->SetXY($this->marge_gauche, $tab_top - 4);
2035  $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
2036  }
2037 
2038  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
2039  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2040  $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
2041  }
2042 
2043  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
2044  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
2045 
2046  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
2047  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
2048  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
2049  }
2050  }
2051 
2052  $pdf->SetDrawColor(128, 128, 128);
2053  $pdf->SetFont('', '', $default_font_size - 1);
2054 
2055  // Output Rect
2056  $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
2057 
2058 
2059  $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
2060 
2061  if (empty($hidetop)) {
2062  $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
2063  }
2064  }
2065 
2066  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2077  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
2078  {
2079  global $conf, $langs;
2080 
2081  $ltrdirection = 'L';
2082  if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
2083 
2084  // Load traductions files required by page
2085  $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
2086 
2087  $default_font_size = pdf_getPDFFontSize($outputlangs);
2088 
2089  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
2090 
2091  $pdf->SetTextColor(0, 0, 60);
2092  $pdf->SetFont('', 'B', $default_font_size + 3);
2093 
2094  $w = 110;
2095 
2096  $posy = $this->marge_haute;
2097  $posx = $this->page_largeur - $this->marge_droite - $w;
2098 
2099  $pdf->SetXY($this->marge_gauche, $posy);
2100 
2101  // Logo
2102  if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
2103  if ($this->emetteur->logo) {
2104  $logodir = $conf->mycompany->dir_output;
2105  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
2106  $logodir = $conf->mycompany->multidir_output[$object->entity];
2107  }
2108  if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
2109  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
2110  } else {
2111  $logo = $logodir.'/logos/'.$this->emetteur->logo;
2112  }
2113  if (is_readable($logo)) {
2114  $height = pdf_getHeightForLogo($logo);
2115  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
2116  } else {
2117  $pdf->SetTextColor(200, 0, 0);
2118  $pdf->SetFont('', 'B', $default_font_size - 2);
2119  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
2120  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
2121  }
2122  } else {
2123  $text = $this->emetteur->name;
2124  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
2125  }
2126  }
2127 
2128  $pdf->SetFont('', 'B', $default_font_size + 3);
2129  $pdf->SetXY($posx, $posy);
2130  $pdf->SetTextColor(0, 0, 60);
2131  $title = $outputlangs->transnoentities("PdfInvoiceTitle");
2132  if ($object->type == 1) {
2133  $title = $outputlangs->transnoentities("InvoiceReplacement");
2134  }
2135  if ($object->type == 2) {
2136  $title = $outputlangs->transnoentities("InvoiceAvoir");
2137  }
2138  if ($object->type == 3) {
2139  $title = $outputlangs->transnoentities("InvoiceDeposit");
2140  }
2141  if ($object->type == 4) {
2142  $title = $outputlangs->transnoentities("InvoiceProForma");
2143  }
2144  if ($this->situationinvoice) {
2145  $langs->loadLangs(array("other"));
2146  $title = $outputlangs->transnoentities("PDFInvoiceSituation") . " " . $outputlangs->transnoentities("NumberingShort") . $object->situation_counter . " -";
2147  }
2148  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2149  $title .= ' - ';
2150  if ($object->type == 0) {
2151  if ($this->situationinvoice) {
2152  $title .= $outputlangsbis->transnoentities("PDFInvoiceSituation");
2153  }
2154  $title .= $outputlangsbis->transnoentities("PdfInvoiceTitle");
2155  } elseif ($object->type == 1) {
2156  $title .= $outputlangsbis->transnoentities("InvoiceReplacement");
2157  } elseif ($object->type == 2) {
2158  $title .= $outputlangsbis->transnoentities("InvoiceAvoir");
2159  } elseif ($object->type == 3) {
2160  $title .= $outputlangsbis->transnoentities("InvoiceDeposit");
2161  } elseif ($object->type == 4) {
2162  $title .= $outputlangsbis->transnoentities("InvoiceProForma");
2163  }
2164  }
2165  $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
2166  if ($object->statut == $object::STATUS_DRAFT) {
2167  $pdf->SetTextColor(128, 0, 0);
2168  $title .= ' - '.$outputlangs->transnoentities("NotValidated");
2169  }
2170 
2171  $pdf->MultiCell($w, 3, $title, '', 'R');
2172 
2173  $pdf->SetFont('', 'B', $default_font_size);
2174 
2175  /*
2176  $posy += 5;
2177  $pdf->SetXY($posx, $posy);
2178  $pdf->SetTextColor(0, 0, 60);
2179  $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
2180  if ($object->statut == $object::STATUS_DRAFT) {
2181  $pdf->SetTextColor(128, 0, 0);
2182  $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
2183  }
2184  $pdf->MultiCell($w, 4, $textref, '', 'R');*/
2185 
2186  $posy += 3;
2187  $pdf->SetFont('', '', $default_font_size - 2);
2188 
2189  if ($object->ref_customer) {
2190  $posy += 4;
2191  $pdf->SetXY($posx, $posy);
2192  $pdf->SetTextColor(0, 0, 60);
2193  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_customer), 65), '', 'R');
2194  }
2195 
2196  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
2197  $object->fetch_projet();
2198  if (!empty($object->project->ref)) {
2199  $posy += 3;
2200  $pdf->SetXY($posx, $posy);
2201  $pdf->SetTextColor(0, 0, 60);
2202  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
2203  }
2204  }
2205 
2206  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
2207  $object->fetch_projet();
2208  if (!empty($object->project->ref)) {
2209  $outputlangs->load("projects");
2210  $posy += 3;
2211  $pdf->SetXY($posx, $posy);
2212  $pdf->SetTextColor(0, 0, 60);
2213  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
2214  }
2215  }
2216 
2217  $objectidnext = $object->getIdReplacingInvoice('validated');
2218  if ($object->type == 0 && $objectidnext) {
2219  $objectreplacing = new Facture($this->db);
2220  $objectreplacing->fetch($objectidnext);
2221 
2222  $posy += 3;
2223  $pdf->SetXY($posx, $posy);
2224  $pdf->SetTextColor(0, 0, 60);
2225  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
2226  }
2227  if ($object->type == 1) {
2228  $objectreplaced = new Facture($this->db);
2229  $objectreplaced->fetch($object->fk_facture_source);
2230 
2231  $posy += 4;
2232  $pdf->SetXY($posx, $posy);
2233  $pdf->SetTextColor(0, 0, 60);
2234  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2235  }
2236  if ($object->type == 2 && !empty($object->fk_facture_source)) {
2237  $objectreplaced = new Facture($this->db);
2238  $objectreplaced->fetch($object->fk_facture_source);
2239 
2240  $posy += 3;
2241  $pdf->SetXY($posx, $posy);
2242  $pdf->SetTextColor(0, 0, 60);
2243  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
2244  }
2245 
2246  $posy += 4;
2247  $pdf->SetXY($posx, $posy);
2248  $pdf->SetTextColor(0, 0, 60);
2249 
2250  $title = $outputlangs->transnoentities("DateInvoice");
2251  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2252  $title .= ' - '.$outputlangsbis->transnoentities("DateInvoice");
2253  }
2254  $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
2255 
2256  if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
2257  $posy += 4;
2258  $pdf->SetXY($posx, $posy);
2259  $pdf->SetTextColor(0, 0, 60);
2260  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : ".dol_print_date($object->date_pointoftax, "day", false, $outputlangs), '', 'R');
2261  }
2262 
2263  if ($object->type != 2) {
2264  $posy += 3;
2265  $pdf->SetXY($posx, $posy);
2266  $pdf->SetTextColor(0, 0, 60);
2267  $title = $outputlangs->transnoentities("DateDue");
2268  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2269  $title .= ' - '.$outputlangsbis->transnoentities("DateDue");
2270  }
2271  $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
2272  }
2273 
2274  if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2275  $posy += 3;
2276  $pdf->SetXY($posx, $posy);
2277  $pdf->SetTextColor(0, 0, 60);
2278  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
2279  }
2280 
2281  // Get contact
2282  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2283  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
2284  if (count($arrayidcontact) > 0) {
2285  $usertmp = new User($this->db);
2286  $usertmp->fetch($arrayidcontact[0]);
2287  $posy += 4;
2288  $pdf->SetXY($posx, $posy);
2289  $pdf->SetTextColor(0, 0, 60);
2290  $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
2291  }
2292  }
2293 
2294  $posy += 1;
2295 
2296  $top_shift = 0;
2297  $shipp_shift = 0;
2298  // Show list of linked objects
2299  $current_y = $pdf->getY();
2300  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
2301  if ($current_y < $pdf->getY()) {
2302  $top_shift = $pdf->getY() - $current_y;
2303  }
2304 
2305  if ($showaddress) {
2306  // Sender properties
2307  $carac_emetteur = '';
2308  // Add internal contact of object if defined
2309  $arrayidcontact = $object->getIdContact('internal', 'BILLING');
2310  if (count($arrayidcontact) > 0) {
2311  $object->fetch_user($arrayidcontact[0]);
2312  $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
2313  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
2314  $carac_emetteur .= "\n";
2315  }
2316 
2317  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
2318 
2319  // Show sender
2320  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2321  $posy += $top_shift;
2322  $posx = $this->marge_gauche;
2323  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2324  $posx = $this->page_largeur - $this->marge_droite - 80;
2325  }
2326 
2327  $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2328  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2329 
2330  // Show sender frame
2331  if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2332  $pdf->SetTextColor(0, 0, 0);
2333  $pdf->SetFont('', '', $default_font_size - 2);
2334  $pdf->SetXY($posx, $posy - 5);
2335  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
2336  $pdf->SetXY($posx, $posy);
2337  $pdf->SetFillColor(230, 230, 230);
2338  $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
2339  $pdf->SetTextColor(0, 0, 60);
2340  }
2341 
2342  // Show sender name
2343  if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2344  $pdf->SetXY($posx + 2, $posy + 3);
2345  $pdf->SetFont('', 'B', $default_font_size);
2346  $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2347  $posy = $pdf->getY();
2348  }
2349 
2350  // Show sender information
2351  $pdf->SetXY($posx + 2, $posy);
2352  $pdf->SetFont('', '', $default_font_size - 1);
2353  $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2354 
2355  // If BILLING contact defined on invoice, we use it
2356  $usecontact = false;
2357  $arrayidcontact = $object->getIdContact('external', 'BILLING');
2358  if (count($arrayidcontact) > 0) {
2359  $usecontact = true;
2360  $result = $object->fetch_contact($arrayidcontact[0]);
2361  }
2362 
2363  // Recipient name
2364  if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
2365  $thirdparty = $object->contact;
2366  } else {
2367  $thirdparty = $object->thirdparty;
2368  }
2369 
2370  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
2371 
2372  $mode = 'target';
2373  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
2374 
2375  // Show recipient
2376  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2377  if ($this->page_largeur < 210) {
2378  $widthrecbox = 84; // To work with US executive format
2379  }
2380  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2381  $posy += $top_shift;
2382  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2383  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2384  $posx = $this->marge_gauche;
2385  }
2386 
2387  // Show recipient frame
2388  if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2389  $pdf->SetTextColor(0, 0, 0);
2390  $pdf->SetFont('', '', $default_font_size - 2);
2391  $pdf->SetXY($posx + 2, $posy - 5);
2392  $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
2393  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2394  }
2395 
2396  // Show recipient name
2397  $pdf->SetXY($posx + 2, $posy + 3);
2398  $pdf->SetFont('', 'B', $default_font_size);
2399  $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2400 
2401  $posy = $pdf->getY();
2402 
2403  // Show recipient information
2404  $pdf->SetFont('', '', $default_font_size - 1);
2405  $pdf->SetXY($posx + 2, $posy);
2406  $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2407 
2408  // Show shipping address
2409  if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS')) {
2410  $idaddressshipping = $object->getIdContact('external', 'SHIPPING');
2411 
2412  if (!empty($idaddressshipping)) {
2413  $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2414  $companystatic = new Societe($this->db);
2415  $companystatic->fetch($object->contact->fk_soc);
2416  $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs);
2417  $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact, 'target', $object);
2418  } else {
2419  $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs);
2420  $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);
2421  }
2422  if (!empty($carac_client_shipping)) {
2423  $posy += $hautcadre;
2424 
2425  // Show shipping frame
2426  $pdf->SetXY($posx + 2, $posy - 5);
2427  $pdf->SetFont('', '', $default_font_size - 2);
2428  $pdf->MultiCell($widthrecbox, '', $outputlangs->transnoentities('ShippingTo'), 0, 'L', 0);
2429  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2430 
2431  // Show shipping name
2432  $pdf->SetXY($posx + 2, $posy + 3);
2433  $pdf->SetFont('', 'B', $default_font_size);
2434  $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L');
2435 
2436  $posy = $pdf->getY();
2437 
2438  // Show shipping information
2439  $pdf->SetXY($posx+2, $posy);
2440  $pdf->SetFont('', '', $default_font_size - 1);
2441  $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L');
2442  $shipp_shift += $hautcadre;
2443  }
2444  }
2445  }
2446 
2447  $pdf->SetTextColor(0, 0, 0);
2448 
2449  $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift);
2450  return $pagehead;
2451  }
2452 
2453  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2464  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0)
2465  {
2466  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2467  return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $heightforqrinvoice + $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
2468  }
2469 
2480  public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
2481  {
2482  global $conf, $hookmanager;
2483 
2484  // Default field style for content
2485  $this->defaultContentsFieldsStyle = array(
2486  'align' => 'R', // R,C,L
2487  'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2488  );
2489 
2490  // Default field style for content
2491  $this->defaultTitlesFieldsStyle = array(
2492  'align' => 'C', // R,C,L
2493  'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2494  );
2495 
2496  /*
2497  * For exemple
2498  $this->cols['theColKey'] = array(
2499  'rank' => $rank, // int : use for ordering columns
2500  'width' => 20, // the column width in mm
2501  'title' => array(
2502  'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2503  'label' => ' ', // the final label : used fore final generated text
2504  'align' => 'L', // text alignement : R,C,L
2505  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2506  ),
2507  'content' => array(
2508  'align' => 'L', // text alignement : R,C,L
2509  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2510  ),
2511  );
2512  */
2513 
2514  $rank = 0; // do not use negative rank
2515  $this->cols['desc'] = array(
2516  'rank' => $rank,
2517  'width' => false, // only for desc
2518  'status' => true,
2519  'title' => array(
2520  'textkey' => 'Designation', // use lang key is usefull in somme case with module
2521  'align' => 'L',
2522  // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
2523  // 'label' => ' ', // the final label
2524  'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2525  ),
2526  'content' => array(
2527  'align' => 'L',
2528  'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2529  ),
2530  );
2531 
2532  // Image of product
2533  $rank = $rank + 10;
2534  $this->cols['photo'] = array(
2535  'rank' => $rank,
2536  'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
2537  'status' => false,
2538  'title' => array(
2539  'textkey' => 'Photo',
2540  'label' => ' '
2541  ),
2542  'content' => array(
2543  'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
2544  ),
2545  'border-left' => false, // remove left line separator
2546  );
2547 
2548  if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
2549  $this->cols['photo']['status'] = true;
2550  }
2551 
2552 
2553  $rank = $rank + 10;
2554  $this->cols['vat'] = array(
2555  'rank' => $rank,
2556  'status' => false,
2557  'width' => 16, // in mm
2558  'title' => array(
2559  'textkey' => 'VAT'
2560  ),
2561  'border-left' => true, // add left line separator
2562  );
2563 
2564  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
2565  $this->cols['vat']['status'] = true;
2566  }
2567 
2568  $rank = $rank + 10;
2569  $this->cols['subprice'] = array(
2570  'rank' => $rank,
2571  'width' => 19, // in mm
2572  'status' => true,
2573  'title' => array(
2574  'textkey' => 'PriceUHT'
2575  ),
2576  'border-left' => true, // add left line separator
2577  );
2578 
2579  // Adapt dynamically the width of subprice, if text is too long.
2580  $tmpwidth = 0;
2581  $nblines = count($object->lines);
2582  for ($i = 0; $i < $nblines; $i++) {
2583  $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
2584  $tmpwidth = max($tmpwidth, $tmpwidth2);
2585  }
2586  if ($tmpwidth > 10) {
2587  $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
2588  }
2589 
2590  $rank = $rank + 10;
2591  $this->cols['qty'] = array(
2592  'rank' => $rank,
2593  'width' => 16, // in mm
2594  'status' => true,
2595  'title' => array(
2596  'textkey' => 'Qty'
2597  ),
2598  'border-left' => true, // add left line separator
2599  );
2600 
2601  $rank = $rank + 10;
2602  $this->cols['progress'] = array(
2603  'rank' => $rank,
2604  'width' => 19, // in mm
2605  'status' => false,
2606  'title' => array(
2607  'textkey' => 'ProgressShort'
2608  ),
2609  'border-left' => true, // add left line separator
2610  );
2611 
2612  if ($this->situationinvoice) {
2613  $this->cols['progress']['status'] = true;
2614  }
2615 
2616  $rank = $rank + 10;
2617  $this->cols['unit'] = array(
2618  'rank' => $rank,
2619  'width' => 11, // in mm
2620  'status' => false,
2621  'title' => array(
2622  'textkey' => 'Unit'
2623  ),
2624  'border-left' => true, // add left line separator
2625  );
2626  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
2627  $this->cols['unit']['status'] = true;
2628  }
2629 
2630  $rank = $rank + 10;
2631  $this->cols['discount'] = array(
2632  'rank' => $rank,
2633  'width' => 13, // in mm
2634  'status' => false,
2635  'title' => array(
2636  'textkey' => 'ReductionShort'
2637  ),
2638  'border-left' => true, // add left line separator
2639  );
2640  if ($this->atleastonediscount) {
2641  $this->cols['discount']['status'] = true;
2642  }
2643 
2644  $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
2645  $this->cols['totalexcltax'] = array(
2646  'rank' => $rank,
2647  'width' => 26, // in mm
2648  'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ? true : false,
2649  'title' => array(
2650  'textkey' => 'TotalHTShort'
2651  ),
2652  'border-left' => true, // add left line separator
2653  );
2654 
2655  $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
2656  $this->cols['totalincltax'] = array(
2657  'rank' => $rank,
2658  'width' => 26, // in mm
2659  'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ? false : true,
2660  'title' => array(
2661  'textkey' => 'TotalTTCShort'
2662  ),
2663  'border-left' => true, // add left line separator
2664  );
2665 
2666  // Add extrafields cols
2667  if (!empty($object->lines)) {
2668  $line = reset($object->lines);
2669  $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
2670  }
2671 
2672  $parameters = array(
2673  'object' => $object,
2674  'outputlangs' => $outputlangs,
2675  'hidedetails' => $hidedetails,
2676  'hidedesc' => $hidedesc,
2677  'hideref' => $hideref
2678  );
2679 
2680  $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
2681  if ($reshook < 0) {
2682  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2683  } elseif (empty($reshook)) {
2684  $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
2685  } else {
2686  $this->cols = $hookmanager->resArray;
2687  }
2688  }
2689 }
Class to manage bank accounts.
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage bank accounts description of third parties.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage hooks.
Parent class of invoice document generators.
addBottomQRInvoice(TCPDF $pdf, Facture $object, Translate $langs)
Add SwissQR invoice at bottom of page 1.
getHeightForQRInvoice(int $pagenbr, Facture $object, Translate $langs)
Get the height for bottom-page QR invoice in mm, depending on the page number.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:48
Class to manage PDF invoice template sponge.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
__construct($db)
Constructor.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
Show payments table.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0, $heightforqrinvoice=0)
Show footer of page.
drawInfoTable(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2520
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2275
pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails=0)
Return line total amount discount.
Definition: pdf.lib.php:2552
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:85
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:314
pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails=0)
Return line total including tax.
Definition: pdf.lib.php:2331
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:1005
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1892
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition: pdf.lib.php:2224
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1830
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2138
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:721
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1333
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:828
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:266
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:435
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:2181
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1977
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:753
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:127
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:387
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123