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