dolibarr  19.0.0-dev
pdf_einstein.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-2013 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
8  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
10  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  * or see https://www.gnu.org/
25  */
26 
33 require_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
34 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38 
39 
44 {
48  public $db;
49 
53  public $entity;
54 
58  public $name;
59 
63  public $description;
64 
68  public $update_main_doc_field;
69 
73  public $type;
74 
79  public $version = 'dolibarr';
80 
84  public $page_largeur;
85 
89  public $page_hauteur;
90 
94  public $format;
95 
99  public $marge_gauche;
100 
104  public $marge_droite;
105 
109  public $marge_haute;
110 
114  public $marge_basse;
115 
120  public $emetteur;
121 
122 
128  public function __construct($db)
129  {
130  global $conf, $langs, $mysoc;
131 
132  // Translations
133  $langs->loadLangs(array("main", "bills", "products"));
134 
135  $this->db = $db;
136  $this->name = "einstein";
137  $this->description = $langs->trans('PDFEinsteinDescription');
138  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
139 
140  // Dimension page
141  $this->type = 'pdf';
142  $formatarray = pdf_getFormat();
143  $this->page_largeur = $formatarray['width'];
144  $this->page_hauteur = $formatarray['height'];
145  $this->format = array($this->page_largeur, $this->page_hauteur);
146  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
147  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
148  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
149  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
150 
151  $this->option_logo = 1; // Display logo
152  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
153  $this->option_modereg = 1; // Display payment mode
154  $this->option_condreg = 1; // Display payment terms
155  $this->option_multilang = 1; // Available in several languages
156  $this->option_escompte = 0; // Displays if there has been a discount
157  $this->option_credit_note = 0; // Support credit notes
158  $this->option_freetext = 1; // Support add of a personalised text
159  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
160  $this->watermark = '';
161 
162  // Get source company
163  $this->emetteur = $mysoc;
164  if (empty($this->emetteur->country_code)) {
165  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
166  }
167 
168  // Define position of columns
169  $this->posxdesc = $this->marge_gauche + 1;
170  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
171  $this->posxtva = 101;
172  $this->posxup = 118;
173  $this->posxqty = 135;
174  $this->posxunit = 151;
175  } else {
176  $this->posxtva = 106;
177  $this->posxup = 122;
178  $this->posxqty = 145;
179  $this->posxunit = 162;
180  }
181  $this->posxdiscount = 162;
182  $this->postotalht = 174;
183  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
184  $this->posxtva = $this->posxup;
185  }
186  $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
187  if ($this->page_largeur < 210) { // To work with US executive format
188  $this->posxpicture -= 20;
189  $this->posxtva -= 20;
190  $this->posxup -= 20;
191  $this->posxqty -= 20;
192  $this->posxunit -= 20;
193  $this->posxdiscount -= 20;
194  $this->postotalht -= 20;
195  }
196 
197  $this->tva = array();
198  $this->tva_array = array();
199  $this->localtax1 = array();
200  $this->localtax2 = array();
201  $this->atleastoneratenotnull = 0;
202  $this->atleastonediscount = 0;
203  }
204 
205  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
217  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
218  {
219  // phpcs:enable
220  global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
221 
222  if (!is_object($outputlangs)) {
223  $outputlangs = $langs;
224  }
225  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
226  if (!empty($conf->global->MAIN_USE_FPDF)) {
227  $outputlangs->charset_output = 'ISO-8859-1';
228  }
229 
230  // Load translation files required by the page
231  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
232 
233  // Show Draft Watermark
234  if ($object->statut == $object::STATUS_DRAFT && getDolGlobalString('COMMANDE_DRAFT_WATERMARK')) {
235  $this->watermark = getDolGlobalString('COMMANDE_DRAFT_WATERMARK');
236  }
237 
238  global $outputlangsbis;
239  $outputlangsbis = null;
240  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
241  $outputlangsbis = new Translate('', $conf);
242  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
243  $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
244  }
245 
246  $nblines = count($object->lines);
247 
248  if ($conf->commande->multidir_output[$conf->entity]) {
249  $object->fetch_thirdparty();
250 
251  $deja_regle = 0;
252 
253  // Definition of $dir and $file
254  if ($object->specimen) {
255  $dir = $conf->commande->multidir_output[$conf->entity];
256  $file = $dir."/SPECIMEN.pdf";
257  } else {
258  // Possibility to use suffix for proforma
259  $suffix = '';
260  if (!empty($conf->global->PROFORMA_PDF_WITH_SUFFIX)) {
261  $suffix = (GETPOST('model', 2)=='proforma') ? $conf->global->PROFORMA_PDF_WITH_SUFFIX : '';
262  $suffix = dol_sanitizeFileName($suffix);
263  }
264 
265  $objectref = dol_sanitizeFileName($object->ref);
266  $dir = $conf->commande->multidir_output[$object->entity]."/".$objectref;
267  $file = $dir."/".$objectref.$suffix.".pdf";
268  }
269 
270  if (!file_exists($dir)) {
271  if (dol_mkdir($dir) < 0) {
272  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
273  return 0;
274  }
275  }
276 
277  if (file_exists($dir)) {
278  // Add pdfgeneration hook
279  if (!is_object($hookmanager)) {
280  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
281  $hookmanager = new HookManager($this->db);
282  }
283  $hookmanager->initHooks(array('pdfgeneration'));
284  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
285  global $action;
286  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
287 
288  // Set nblines with the new command lines content after hook
289  $nblines = count($object->lines);
290 
291  // Create pdf instance
292  $pdf = pdf_getInstance($this->format);
293  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
294  $pdf->SetAutoPageBreak(1, 0);
295 
296  $heightforinfotot = 40; // Height reserved to output the info and total part
297  $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
298  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
299  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
300  $heightforfooter += 6;
301  }
302 
303  if (class_exists('TCPDF')) {
304  $pdf->setPrintHeader(false);
305  $pdf->setPrintFooter(false);
306  }
307  $pdf->SetFont(pdf_getPDFFont($outputlangs));
308  // Set path to the background PDF File
309  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
310  $logodir = $conf->mycompany->dir_output;
311  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
312  $logodir = $conf->mycompany->multidir_output[$object->entity];
313  }
314  $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
315  $tplidx = $pdf->importPage(1);
316  }
317 
318  $pdf->Open();
319  $pagenb = 0;
320  $pdf->SetDrawColor(128, 128, 128);
321 
322  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
323  $pdf->SetSubject($outputlangs->transnoentities("PdfOrderTitle"));
324  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
325  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
326  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfOrderTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
327  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
328  $pdf->SetCompression(false);
329  }
330 
331  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
332 
333  // Set $this->atleastonediscount if you have at least one discount
334  for ($i = 0; $i < $nblines; $i++) {
335  if ($object->lines[$i]->remise_percent) {
336  $this->atleastonediscount++;
337  }
338  }
339  if (empty($this->atleastonediscount)) {
340  $delta = ($this->postotalht - $this->posxdiscount);
341  $this->posxpicture += $delta;
342  $this->posxtva += $delta;
343  $this->posxup += $delta;
344  $this->posxqty += $delta;
345  $this->posxunit += $delta;
346  $this->posxdiscount += $delta;
347  // post of fields after are not modified, stay at same position
348  }
349 
350  // New page
351  $pdf->AddPage();
352  if (!empty($tplidx)) {
353  $pdf->useTemplate($tplidx);
354  }
355  $pagenb++;
356  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
357  $pdf->SetFont('', '', $default_font_size - 1);
358  $pdf->MultiCell(0, 3, ''); // Set interline to 3
359  $pdf->SetTextColor(0, 0, 0);
360 
361 
362  $tab_top = 90 + $top_shift;
363  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
364 
365  // Incoterm
366  $height_incoterms = 0;
367  if (isModEnabled('incoterm')) {
368  $desc_incoterms = $object->getIncotermsForPDF();
369  if ($desc_incoterms) {
370  $tab_top -= 2;
371 
372  $pdf->SetFont('', '', $default_font_size - 1);
373  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
374  $nexY = $pdf->GetY();
375  $height_incoterms = $nexY - $tab_top;
376 
377  // Rect takes a length in 3rd parameter
378  $pdf->SetDrawColor(192, 192, 192);
379  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
380 
381  $tab_top = $nexY + 6;
382  }
383  }
384 
385  // Displays notes
386  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
387  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
388  // Get first sale rep
389  if (is_object($object->thirdparty)) {
390  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
391  $salerepobj = new User($this->db);
392  $salerepobj->fetch($salereparray[0]['id']);
393  if (!empty($salerepobj->signature)) {
394  $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
395  }
396  }
397  }
398  // Extrafields in note
399  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
400  if (!empty($extranote)) {
401  $notetoshow = dol_concatdesc($notetoshow, $extranote);
402  }
403 
404  if ($notetoshow) {
405  $tab_top -= 2;
406 
407  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
408  complete_substitutions_array($substitutionarray, $outputlangs, $object);
409  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
410  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
411 
412  $pdf->SetFont('', '', $default_font_size - 1);
413  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
414  $nexY = $pdf->GetY();
415  $height_note = $nexY - $tab_top;
416 
417  // Rect takes a length in 3rd parameter
418  $pdf->SetDrawColor(192, 192, 192);
419  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
420 
421  $tab_top = $nexY + 6;
422  }
423 
424  $iniY = $tab_top + 7;
425  $curY = $tab_top + 7;
426  $nexY = $tab_top + 7;
427 
428  // Loop on each lines
429  for ($i = 0; $i < $nblines; $i++) {
430  $curY = $nexY;
431  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
432  $pdf->SetTextColor(0, 0, 0);
433 
434  $pdf->setTopMargin($tab_top_newpage);
435  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
436  $pageposbefore = $pdf->getPage();
437 
438  // Description of product line
439  $curX = $this->posxdesc - 1;
440 
441  $showpricebeforepagebreak = 1;
442 
443  $pdf->startTransaction();
444  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc);
445  $pageposafter = $pdf->getPage();
446  if ($pageposafter > $pageposbefore) { // There is a pagebreak
447  $pdf->rollbackTransaction(true);
448  $pageposafter = $pageposbefore;
449  //print $pageposafter.'-'.$pageposbefore;exit;
450  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
451  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc);
452  $pageposafter = $pdf->getPage();
453  $posyafter = $pdf->GetY();
454  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
455  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
456  $pdf->AddPage('', '', true);
457  if (!empty($tplidx)) {
458  $pdf->useTemplate($tplidx);
459  }
460  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
461  $this->_pagehead($pdf, $object, 0, $outputlangs);
462  }
463  $pdf->setPage($pageposafter + 1);
464  }
465  } else {
466  // We found a page break
467  // Allows data in the first page if description is long enough to break in multiples pages
468  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
469  $showpricebeforepagebreak = 1;
470  } else {
471  $showpricebeforepagebreak = 0;
472  }
473  }
474  } else // No pagebreak
475  {
476  $pdf->commitTransaction();
477  }
478  $posYAfterDescription = $pdf->GetY();
479 
480  $nexY = $pdf->GetY();
481  $pageposafter = $pdf->getPage();
482 
483  $pdf->setPage($pageposbefore);
484  $pdf->setTopMargin($this->marge_haute);
485  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
486 
487  // We suppose that a too long description is moved completely on next page
488  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
489  $pdf->setPage($pageposafter);
490  $curY = $tab_top_newpage;
491  }
492 
493  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
494 
495  // VAT Rate
496  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
497  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
498  $pdf->SetXY($this->posxtva - 5, $curY);
499  $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R');
500  }
501 
502  // Unit price before discount
503  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
504  $pdf->SetXY($this->posxup, $curY);
505  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
506 
507  // Quantity
508  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
509  $pdf->SetXY($this->posxqty, $curY);
510  $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
511 
512  // Unit
513  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
514  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
515  $pdf->SetXY($this->posxunit, $curY);
516  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
517  }
518 
519  // Discount on line
520  $pdf->SetXY($this->posxdiscount, $curY);
521  if ($object->lines[$i]->remise_percent) {
522  $pdf->SetXY($this->posxdiscount - 2, $curY);
523  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
524  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
525  }
526 
527  // Total HT line
528  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
529  $pdf->SetXY($this->postotalht, $curY);
530  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
531 
532  // Collection of totals by value of vat in $this->vat["rate"] = total_tva
533  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
534  $tvaligne = $object->lines[$i]->multicurrency_total_tva;
535  } else {
536  $tvaligne = $object->lines[$i]->total_tva;
537  }
538 
539  $localtax1ligne = $object->lines[$i]->total_localtax1;
540  $localtax2ligne = $object->lines[$i]->total_localtax2;
541  $localtax1_rate = $object->lines[$i]->localtax1_tx;
542  $localtax2_rate = $object->lines[$i]->localtax2_tx;
543  $localtax1_type = $object->lines[$i]->localtax1_type;
544  $localtax2_type = $object->lines[$i]->localtax2_type;
545 
546  // TODO remise_percent is an obsolete field for object parent
547  /*if ($object->remise_percent) {
548  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
549  }
550  if ($object->remise_percent) {
551  $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
552  }
553  if ($object->remise_percent) {
554  $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
555  }*/
556 
557  $vatrate = (string) $object->lines[$i]->tva_tx;
558 
559  // Retrieve type from database for backward compatibility with old records
560  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
561  && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
562  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
563  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
564  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
565  }
566 
567  // retrieve global local tax
568  if ($localtax1_type && $localtax1ligne != 0) {
569  if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
570  $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
571  } else {
572  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
573  }
574  }
575  if ($localtax2_type && $localtax2ligne != 0) {
576  if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
577  $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
578  } else {
579  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
580  }
581  }
582 
583  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
584  $vatrate .= '*';
585  }
586 
587  // Fill $this->tva and $this->tva_array
588  if (!isset($this->tva[$vatrate])) {
589  $this->tva[$vatrate] = 0;
590  }
591  $this->tva[$vatrate] += $tvaligne;
592  $vatcode = $object->lines[$i]->vat_src_code;
593  if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
594  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
595  }
596  $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
597 
598  // Add line
599  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
600  $pdf->setPage($pageposafter);
601  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
602  //$pdf->SetDrawColor(190,190,200);
603  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
604  $pdf->SetLineStyle(array('dash'=>0));
605  }
606 
607  $nexY += 2; // Add space between lines
608 
609  // Detect if some page were added automatically and output _tableau for past pages
610  while ($pagenb < $pageposafter) {
611  $pdf->setPage($pagenb);
612  if ($pagenb == 1) {
613  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
614  } else {
615  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
616  }
617  $this->_pagefoot($pdf, $object, $outputlangs, 1);
618  $pagenb++;
619  $pdf->setPage($pagenb);
620  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
621  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
622  $this->_pagehead($pdf, $object, 0, $outputlangs);
623  }
624  if (!empty($tplidx)) {
625  $pdf->useTemplate($tplidx);
626  }
627  }
628  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
629  if ($pagenb == 1) {
630  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
631  } else {
632  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
633  }
634  $this->_pagefoot($pdf, $object, $outputlangs, 1);
635  // New page
636  $pdf->AddPage();
637  if (!empty($tplidx)) {
638  $pdf->useTemplate($tplidx);
639  }
640  $pagenb++;
641  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
642  $this->_pagehead($pdf, $object, 0, $outputlangs);
643  }
644  }
645  }
646 
647  // Show square
648  if ($pagenb == 1) {
649  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
650  } else {
651  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
652  }
653  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
654 
655  // Display infos area
656  $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
657 
658  // Display total zone
659  $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
660 
661  // Affiche zone versements
662  /*
663  if ($deja_regle)
664  {
665  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
666  }
667  */
668 
669  // Pied de page
670  $this->_pagefoot($pdf, $object, $outputlangs);
671  if (method_exists($pdf, 'AliasNbPages')) {
672  $pdf->AliasNbPages();
673  }
674 
675  $pdf->Close();
676 
677  $pdf->Output($file, 'F');
678 
679  // Add pdfgeneration hook
680  $hookmanager->initHooks(array('pdfgeneration'));
681  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
682  global $action;
683  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
684  if ($reshook < 0) {
685  $this->error = $hookmanager->error;
686  $this->errors = $hookmanager->errors;
687  }
688 
689  dolChmod($file);
690 
691  $this->result = array('fullpath'=>$file);
692 
693  return 1; // No error
694  } else {
695  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
696  return 0;
697  }
698  } else {
699  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR");
700  return 0;
701  }
702  }
703 
704  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
705  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
715  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
716  {
717  // phpcs:enable
718  return 1;
719  }
720 
721  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
722  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
732  protected function _tableau_info(&$pdf, $object, $posy, $outputlangs)
733  {
734  // phpcs:enable
735  global $conf, $mysoc;
736  $default_font_size = pdf_getPDFFontSize($outputlangs);
737 
738  $pdf->SetFont('', '', $default_font_size - 1);
739 
740  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
741 
742  // If France, show VAT mention if not applicable
743  if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) {
744  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
745  $pdf->SetXY($this->marge_gauche, $posy);
746  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
747 
748  $posy = $pdf->GetY() + 4;
749  }
750 
751  $posxval = 52;
752 
753  $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
754 
755  // Show payments conditions
756  if ($object->cond_reglement_code || $object->cond_reglement) {
757  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
758  $pdf->SetXY($this->marge_gauche, $posy);
759  $titre = $outputlangs->transnoentities("PaymentConditions").':';
760  $pdf->MultiCell(43, 4, $titre, 0, 'L');
761 
762  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
763  $pdf->SetXY($posxval, $posy);
764  $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);
765  $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
766  if ($object->deposit_percent > 0) {
767  $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
768  }
769  $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
770 
771  $posy = $pdf->GetY() + 3;
772  }
773 
774  // Check a payment mode is defined
775  /* Not used with orders
776  if (empty($object->mode_reglement_code)
777  && ! $conf->global->FACTURE_CHQ_NUMBER
778  && ! $conf->global->FACTURE_RIB_NUMBER)
779  {
780  $pdf->SetXY($this->marge_gauche, $posy);
781  $pdf->SetTextColor(200,0,0);
782  $pdf->SetFont('','B', $default_font_size - 2);
783  $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
784  $pdf->SetTextColor(0,0,0);
785 
786  $posy=$pdf->GetY()+1;
787  }
788  */
789  /* TODO
790  else if (!empty($object->availability_code))
791  {
792  $pdf->SetXY($this->marge_gauche, $posy);
793  $pdf->SetTextColor(200,0,0);
794  $pdf->SetFont('','B', $default_font_size - 2);
795  $pdf->MultiCell(80, 3, $outputlangs->transnoentities("AvailabilityPeriod").': '.,0,'L',0);
796  $pdf->SetTextColor(0,0,0);
797 
798  $posy=$pdf->GetY()+1;
799  }*/
800 
801  // Show planed date of delivery
802  if (!empty($object->delivery_date)) {
803  $outputlangs->load("sendings");
804  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
805  $pdf->SetXY($this->marge_gauche, $posy);
806  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
807  $pdf->MultiCell(80, 4, $titre, 0, 'L');
808  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
809  $pdf->SetXY($posxval, $posy);
810  $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true);
811  $pdf->MultiCell(80, 4, $dlp, 0, 'L');
812 
813  $posy = $pdf->GetY() + 1;
814  } elseif ($object->availability_code || $object->availability) {
815  // Show availability conditions
816  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
817  $pdf->SetXY($this->marge_gauche, $posy);
818  $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
819  $pdf->MultiCell(80, 4, $titre, 0, 'L');
820  $pdf->SetTextColor(0, 0, 0);
821  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
822  $pdf->SetXY($posxval, $posy);
823  $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset(isset($object->availability) ? $object->availability : '');
824  $lib_availability = str_replace('\n', "\n", $lib_availability);
825  $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
826 
827  $posy = $pdf->GetY() + 1;
828  }
829 
830  // Show payment mode
831  if ($object->mode_reglement_code
832  && $object->mode_reglement_code != 'CHQ'
833  && $object->mode_reglement_code != 'VIR') {
834  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
835  $pdf->SetXY($this->marge_gauche, $posy);
836  $titre = $outputlangs->transnoentities("PaymentMode").':';
837  $pdf->MultiCell(80, 5, $titre, 0, 'L');
838 
839  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
840  $pdf->SetXY($posxval, $posy);
841  $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);
842  $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
843 
844  $posy = $pdf->GetY() + 2;
845  }
846 
847  // Show payment mode CHQ
848  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
849  // Si mode reglement non force ou si force a CHQ
850  if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
851  if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
852  $account = new Account($this->db);
853  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
854 
855  $pdf->SetXY($this->marge_gauche, $posy);
856  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
857  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
858  $posy = $pdf->GetY() + 1;
859 
860  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
861  $pdf->SetXY($this->marge_gauche, $posy);
862  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
863  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
864  $posy = $pdf->GetY() + 2;
865  }
866  }
867  if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
868  $pdf->SetXY($this->marge_gauche, $posy);
869  $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
870  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
871  $posy = $pdf->GetY() + 1;
872 
873  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
874  $pdf->SetXY($this->marge_gauche, $posy);
875  $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
876  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
877  $posy = $pdf->GetY() + 2;
878  }
879  }
880  }
881  }
882 
883  // If payment mode not forced or forced to VIR, show payment with BAN
884  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
885  if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
886  $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
887  if ($object->fk_bank > 0) {
888  $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
889  }
890  $account = new Account($this->db);
891  $account->fetch($bankid);
892 
893  $curx = $this->marge_gauche;
894  $cury = $posy;
895 
896  $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
897 
898  $posy += 2;
899  }
900  }
901 
902  return $posy;
903  }
904 
905  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
906  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
918  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
919  {
920  // phpcs:enable
921  global $conf, $mysoc, $hookmanager;
922 
923  $default_font_size = pdf_getPDFFontSize($outputlangs);
924 
925  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
926  $outputlangsbis = new Translate('', $conf);
927  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
928  $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
929  $default_font_size--;
930  }
931 
932  $tab2_top = $posy;
933  $tab2_hl = 4;
934  $pdf->SetFont('', '', $default_font_size - 1);
935 
936  // Total table
937  $col1x = 120;
938  $col2x = 170;
939  if ($this->page_largeur < 210) { // To work with US executive format
940  $col2x -= 20;
941  }
942  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
943 
944  $useborder = 0;
945  $index = 0;
946 
947  // Total HT
948  $pdf->SetFillColor(255, 255, 255);
949  $pdf->SetXY($col1x, $tab2_top);
950  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
951 
952  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
953  $pdf->SetXY($col2x, $tab2_top);
954  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
955 
956  // Show VAT by rates and total
957  $pdf->SetFillColor(248, 248, 248);
958 
959  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
960 
961  $this->atleastoneratenotnull = 0;
962  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
963  $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
964  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
965  // Nothing to do
966  } else {
967  //Local tax 1 before VAT
968  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
969  //{
970  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
971  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
972  continue;
973  }
974  foreach ($localtax_rate as $tvakey => $tvaval) {
975  if ($tvakey != 0) { // On affiche pas taux 0
976  //$this->atleastoneratenotnull++;
977 
978  $index++;
979  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
980 
981  $tvacompl = '';
982  if (preg_match('/\*/', $tvakey)) {
983  $tvakey = str_replace('*', '', $tvakey);
984  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
985  }
986  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
987  $totalvat .= ' ';
988  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
989  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
990 
991  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
992  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
993  }
994  }
995  }
996  //}
997  //Local tax 2 before VAT
998  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
999  //{
1000  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1001  if (in_array((string) $localtax_type, array('1', '3', '5'))) {
1002  continue;
1003  }
1004  foreach ($localtax_rate as $tvakey => $tvaval) {
1005  if ($tvakey != 0) { // On affiche pas taux 0
1006  //$this->atleastoneratenotnull++;
1007 
1008  $index++;
1009  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1010 
1011  $tvacompl = '';
1012  if (preg_match('/\*/', $tvakey)) {
1013  $tvakey = str_replace('*', '', $tvakey);
1014  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1015  }
1016  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1017  $totalvat .= ' ';
1018  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1019  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1020 
1021  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1022  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1023  }
1024  }
1025  }
1026  //}
1027 
1028  // VAT
1029  foreach ($this->tva_array as $tvakey => $tvaval) {
1030  if ($tvakey != 0) { // On affiche pas taux 0
1031  $this->atleastoneratenotnull++;
1032 
1033  $index++;
1034  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1035 
1036  $tvacompl = '';
1037  if (preg_match('/\*/', $tvakey)) {
1038  $tvakey = str_replace('*', '', $tvakey);
1039  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1040  }
1041  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
1042  $totalvat .= ' ';
1043  if (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'rateonly') {
1044  $totalvat .= vatrate($tvaval['vatrate'], 1).$tvacompl;
1045  } elseif (getDolGlobalString('PDF_VAT_LABEL_IS_CODE_OR_RATE') == 'codeonly') {
1046  $totalvat .= $tvaval['vatcode'].$tvacompl;
1047  } else {
1048  $totalvat .= vatrate($tvaval['vatrate'], 1).($tvaval['vatcode'] ? ' ('.$tvaval['vatcode'].')' : '').$tvacompl;
1049  }
1050  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1051 
1052  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1053  $pdf->MultiCell($largcol2, $tab2_hl, price(price2num($tvaval['amount'], 'MT'), 0, $outputlangs), 0, 'R', 1);
1054  }
1055  }
1056 
1057  //Local tax 1 after VAT
1058  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1059  //{
1060  foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1061  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1062  continue;
1063  }
1064 
1065  foreach ($localtax_rate as $tvakey => $tvaval) {
1066  if ($tvakey != 0) { // On affiche pas taux 0
1067  //$this->atleastoneratenotnull++;
1068 
1069  $index++;
1070  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1071 
1072  $tvacompl = '';
1073  if (preg_match('/\*/', $tvakey)) {
1074  $tvakey = str_replace('*', '', $tvakey);
1075  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1076  }
1077  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
1078  $totalvat .= ' ';
1079 
1080  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1081  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1082  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1083  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1084  }
1085  }
1086  }
1087  //}
1088  //Local tax 2 after VAT
1089  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1090  //{
1091  foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1092  if (in_array((string) $localtax_type, array('2', '4', '6'))) {
1093  continue;
1094  }
1095 
1096  foreach ($localtax_rate as $tvakey => $tvaval) {
1097  // retrieve global local tax
1098  if ($tvakey != 0) { // On affiche pas taux 0
1099  //$this->atleastoneratenotnull++;
1100 
1101  $index++;
1102  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1103 
1104  $tvacompl = '';
1105  if (preg_match('/\*/', $tvakey)) {
1106  $tvakey = str_replace('*', '', $tvakey);
1107  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1108  }
1109  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
1110  $totalvat .= ' ';
1111 
1112  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
1113  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1114 
1115  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1116  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1117  }
1118  }
1119  }
1120  //}
1121 
1122  // Total TTC
1123  $index++;
1124  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1125  $pdf->SetTextColor(0, 0, 60);
1126  $pdf->SetFillColor(224, 224, 224);
1127  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalTTC", $mysoc->country_code) : ''), $useborder, 'L', 1);
1128 
1129  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1130  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1131  }
1132  }
1133 
1134  $pdf->SetTextColor(0, 0, 0);
1135 
1136  $creditnoteamount = 0;
1137  $depositsamount = 0;
1138  //$creditnoteamount=$object->getSumCreditNotesUsed();
1139  //$depositsamount=$object->getSumDepositsUsed();
1140  //print "x".$creditnoteamount."-".$depositsamount;exit;
1141  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1142  if (!empty($object->paye)) {
1143  $resteapayer = 0;
1144  }
1145 
1146  if ($deja_regle > 0) {
1147  // Already paid + Deposits
1148  $index++;
1149 
1150  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1151  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
1152  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1153  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1154 
1155  $index++;
1156  $pdf->SetTextColor(0, 0, 60);
1157  $pdf->SetFillColor(224, 224, 224);
1158  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1159  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), $useborder, 'L', 1);
1160 
1161  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1162  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1163 
1164  $pdf->SetFont('', '', $default_font_size - 1);
1165  $pdf->SetTextColor(0, 0, 0);
1166  }
1167 
1168  $index++;
1169  return ($tab2_top + ($tab2_hl * $index));
1170  }
1171 
1172  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1187  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
1188  {
1189  global $conf;
1190 
1191  // Force to disable hidetop and hidebottom
1192  $hidebottom = 0;
1193  if ($hidetop) {
1194  $hidetop = -1;
1195  }
1196 
1197  $currency = !empty($currency) ? $currency : $conf->currency;
1198  $default_font_size = pdf_getPDFFontSize($outputlangs);
1199 
1200  // Amount in (at tab_top - 1)
1201  $pdf->SetTextColor(0, 0, 0);
1202  $pdf->SetFont('', '', $default_font_size - 2);
1203 
1204  if (empty($hidetop)) {
1205  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1206  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1207  $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
1208  }
1209 
1210  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1211  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1212 
1213  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1214  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1215  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1216  }
1217  }
1218 
1219  $pdf->SetDrawColor(128, 128, 128);
1220  $pdf->SetFont('', '', $default_font_size - 1);
1221 
1222  // Output Rect
1223  $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
1224 
1225  if (empty($hidetop)) {
1226  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
1227 
1228  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1229  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1230  }
1231 
1232  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1233  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1234  if (empty($hidetop)) {
1235  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1236  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1237  }
1238  }
1239 
1240  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1241  if (empty($hidetop)) {
1242  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1243  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1244  }
1245 
1246  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1247  if (empty($hidetop)) {
1248  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1249  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1250  }
1251 
1252  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1253  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1254  if (empty($hidetop)) {
1255  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1256  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1257  }
1258  }
1259 
1260  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1261  if (empty($hidetop)) {
1262  if ($this->atleastonediscount) {
1263  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1264  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1265  }
1266  }
1267 
1268  if ($this->atleastonediscount) {
1269  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1270  }
1271  if (empty($hidetop)) {
1272  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1273  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1274  }
1275  }
1276 
1277  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1278  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1290  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle")
1291  {
1292  // phpcs:enable
1293  global $conf, $langs, $hookmanager;
1294 
1295  $ltrdirection = 'L';
1296  if ($outputlangs->trans("DIRECTION") == 'rtl') {
1297  $ltrdirection = 'R';
1298  }
1299 
1300  // Load traductions files required by page
1301  $outputlangs->loadLangs(array("main", "bills", "propal", "orders", "companies"));
1302 
1303  $default_font_size = pdf_getPDFFontSize($outputlangs);
1304 
1305  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
1306 
1307  $pdf->SetTextColor(0, 0, 60);
1308  $pdf->SetFont('', 'B', $default_font_size + 3);
1309 
1310  $w = 100;
1311 
1312  $posy = $this->marge_haute;
1313  $posx = $this->page_largeur - $this->marge_droite - $w;
1314 
1315  $pdf->SetXY($this->marge_gauche, $posy);
1316 
1317  // Logo
1318  if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
1319  if ($this->emetteur->logo) {
1320  $logodir = $conf->mycompany->dir_output;
1321  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1322  $logodir = $conf->mycompany->multidir_output[$object->entity];
1323  }
1324  if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
1325  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
1326  } else {
1327  $logo = $logodir.'/logos/'.$this->emetteur->logo;
1328  }
1329  if (is_readable($logo)) {
1330  $height = pdf_getHeightForLogo($logo);
1331  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1332  } else {
1333  $pdf->SetTextColor(200, 0, 0);
1334  $pdf->SetFont('', 'B', $default_font_size - 2);
1335  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1336  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1337  }
1338  } else {
1339  $text = $this->emetteur->name;
1340  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1341  }
1342  }
1343 
1344  $pdf->SetFont('', 'B', $default_font_size + 3);
1345  $pdf->SetXY($posx, $posy);
1346  $pdf->SetTextColor(0, 0, 60);
1347  $title = $outputlangs->transnoentities($titlekey);
1348  $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
1349  if ($object->statut == $object::STATUS_DRAFT) {
1350  $pdf->SetTextColor(128, 0, 0);
1351  $title .= ' - '.$outputlangs->transnoentities("NotValidated");
1352  }
1353  $pdf->MultiCell($w, 3, $title, '', 'R');
1354 
1355  $pdf->SetFont('', 'B', $default_font_size);
1356 
1357  /*
1358  $posy += 5;
1359  $pdf->SetXY($posx, $posy);
1360  $pdf->SetTextColor(0, 0, 60);
1361  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1362  */
1363 
1364  $posy += 3;
1365  $pdf->SetFont('', '', $default_font_size - 1);
1366 
1367  if ($object->ref_client) {
1368  $posy += 5;
1369  $pdf->SetXY($posx, $posy);
1370  $pdf->SetTextColor(0, 0, 60);
1371  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1372  }
1373 
1374  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1375  $object->fetch_projet();
1376  if (!empty($object->project->ref)) {
1377  $posy += 3;
1378  $pdf->SetXY($posx, $posy);
1379  $pdf->SetTextColor(0, 0, 60);
1380  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1381  }
1382  }
1383 
1384  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1385  $object->fetch_projet();
1386  if (!empty($object->project->ref)) {
1387  $outputlangs->load("projects");
1388  $posy += 3;
1389  $pdf->SetXY($posx, $posy);
1390  $pdf->SetTextColor(0, 0, 60);
1391  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1392  }
1393  }
1394 
1395  $posy += 4;
1396  $pdf->SetXY($posx, $posy);
1397  $pdf->SetTextColor(0, 0, 60);
1398  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1399 
1400  if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && !empty($object->thirdparty->code_client)) {
1401  $posy += 4;
1402  $pdf->SetXY($posx, $posy);
1403  $pdf->SetTextColor(0, 0, 60);
1404  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1405  }
1406 
1407  // Get contact
1408  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1409  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1410  if (count($arrayidcontact) > 0) {
1411  $usertmp = new User($this->db);
1412  $usertmp->fetch($arrayidcontact[0]);
1413  $posy += 4;
1414  $pdf->SetXY($posx, $posy);
1415  $pdf->SetTextColor(0, 0, 60);
1416  $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1417  }
1418  }
1419 
1420  $posy += 2;
1421 
1422  $top_shift = 0;
1423  // Show list of linked objects
1424  $current_y = $pdf->getY();
1425  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1426  if ($current_y < $pdf->getY()) {
1427  $top_shift = $pdf->getY() - $current_y;
1428  }
1429 
1430  if ($showaddress) {
1431  // Sender properties
1432  $carac_emetteur = '';
1433  // Add internal contact of object if defined
1434  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1435  if (count($arrayidcontact) > 0) {
1436  $object->fetch_user($arrayidcontact[0]);
1437  $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
1438  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1439  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
1440  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
1441  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
1442  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
1443  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
1444  $carac_emetteur .= "\n";
1445  }
1446 
1447  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1448 
1449  // Show sender
1450  $posy = 42 + $top_shift;
1451  $posx = $this->marge_gauche;
1452  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1453  $posx = $this->page_largeur - $this->marge_droite - 80;
1454  }
1455  $hautcadre = 40;
1456 
1457  // Show sender frame
1458  if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
1459  $pdf->SetTextColor(0, 0, 0);
1460  $pdf->SetFont('', '', $default_font_size - 2);
1461  $pdf->SetXY($posx, $posy - 5);
1462  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
1463  $pdf->SetXY($posx, $posy);
1464  $pdf->SetFillColor(230, 230, 230);
1465  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1466  $pdf->SetTextColor(0, 0, 60);
1467  }
1468 
1469  // Show sender name
1470  if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
1471  $pdf->SetXY($posx + 2, $posy + 3);
1472  $pdf->SetFont('', 'B', $default_font_size);
1473  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1474  $posy = $pdf->getY();
1475  }
1476 
1477  // Show sender information
1478  $pdf->SetXY($posx + 2, $posy);
1479  $pdf->SetFont('', '', $default_font_size - 1);
1480  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1481 
1482 
1483  // If CUSTOMER contact defined, we use it
1484  $usecontact = false;
1485  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
1486  if (count($arrayidcontact) > 0) {
1487  $usecontact = true;
1488  $result = $object->fetch_contact($arrayidcontact[0]);
1489  }
1490 
1491  // Recipient name
1492  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)))) {
1493  $thirdparty = $object->contact;
1494  } else {
1495  $thirdparty = $object->thirdparty;
1496  }
1497 
1498  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1499 
1500  $mode = 'target';
1501  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
1502 
1503  // Show recipient
1504  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1505  if ($this->page_largeur < 210) {
1506  $widthrecbox = 84; // To work with US executive format
1507  }
1508  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1509  $posy += $top_shift;
1510  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1511  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1512  $posx = $this->marge_gauche;
1513  }
1514 
1515  // Show recipient frame
1516  if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
1517  $pdf->SetTextColor(0, 0, 0);
1518  $pdf->SetFont('', '', $default_font_size - 2);
1519  $pdf->SetXY($posx + 2, $posy - 5);
1520  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
1521  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1522  }
1523 
1524  // Show recipient name
1525  $pdf->SetXY($posx + 2, $posy + 3);
1526  $pdf->SetFont('', 'B', $default_font_size);
1527  $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1528 
1529  $posy = $pdf->getY();
1530 
1531  // Show recipient information
1532  $pdf->SetFont('', '', $default_font_size - 1);
1533  $pdf->SetXY($posx + 2, $posy);
1534  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1535  }
1536 
1537  $pdf->SetTextColor(0, 0, 0);
1538  return $top_shift;
1539  }
1540 
1541  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1542  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1552  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1553  {
1554  // phpcs:enable
1555  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1556  return pdf_pagefoot($pdf, $outputlangs, 'ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
1557  }
1558 }
Class to manage bank accounts.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage hooks.
Parent class for orders models.
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:48
Class to generate PDF orders with template Einstein.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null, $titlekey="PdfOrderTitle")
Show top header of page.
__construct($db)
Constructor.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis=null)
Show total to pay.
_tableau_versements(&$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.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2275
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:85
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1369
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:314
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:1005
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1892
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1830
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2138
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:721
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1333
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:828
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:266
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:435
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:2181
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1977
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:753
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:127
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:387
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123