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