dolibarr  17.0.3
pdf_canelle.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
3  * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
5  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  * or see https://www.gnu.org/
20  */
21 
28 require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
29 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34 
35 
40 {
44  public $db;
45 
49  public $name;
50 
54  public $description;
55 
59  public $update_main_doc_field;
60 
64  public $type;
65 
70  public $phpmin = array(7, 0);
71 
76  public $version = 'dolibarr';
77 
81  public $page_largeur;
82 
86  public $page_hauteur;
87 
91  public $format;
92 
96  public $marge_gauche;
97 
101  public $marge_droite;
102 
106  public $marge_haute;
107 
111  public $marge_basse;
112 
117  public $emetteur;
118 
119 
120 
126  public function __construct($db)
127  {
128  global $conf, $langs, $mysoc;
129 
130  // Translations
131  $langs->loadLangs(array("main", "bills"));
132 
133  $this->db = $db;
134  $this->name = "canelle";
135  $this->description = $langs->trans('SuppliersInvoiceModel');
136  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
137 
138  // Page dimensions
139  $this->type = 'pdf';
140  $formatarray = pdf_getFormat();
141  $this->page_largeur = $formatarray['width'];
142  $this->page_hauteur = $formatarray['height'];
143  $this->format = array($this->page_largeur, $this->page_hauteur);
144  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
145  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
146  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
147  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
148 
149  $this->option_logo = 1; // Display logo
150  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
151  $this->option_modereg = 1; // Display payment mode
152  $this->option_condreg = 1; // Display payment terms
153  $this->option_multilang = 1; // Available in several languages
154 
155  // Define column position
156  $this->posxdesc = $this->marge_gauche + 1;
157 
158  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
159  $this->posxtva = 99;
160  $this->posxup = 114;
161  $this->posxqty = 130;
162  $this->posxunit = 147;
163  } else {
164  $this->posxtva = 106;
165  $this->posxup = 122;
166  $this->posxqty = 145;
167  $this->posxunit = 162;
168  }
169  $this->posxdiscount = 162;
170  $this->postotalht = 174;
171 
172  /* if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
173  $this->posxtva = $this->posxup;
174  } */
175  $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
176  if ($this->page_largeur < 210) { // To work with US executive format
177  $this->posxpicture -= 20;
178  $this->posxtva -= 20;
179  $this->posxup -= 20;
180  $this->posxqty -= 20;
181  $this->posxunit -= 20;
182  $this->posxdiscount -= 20;
183  $this->postotalht -= 20;
184  }
185 
186  $this->tva = array();
187  $this->tva_array = array();
188  $this->localtax1 = array();
189  $this->localtax2 = array();
190  $this->atleastoneratenotnull = 0;
191  $this->atleastonediscount = 0;
192  }
193 
194 
195  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
207  public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
208  {
209  // phpcs:enable
210  global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
211 
212  // Get source company
213  if (!is_object($object->thirdparty)) {
214  $object->fetch_thirdparty();
215  }
216  if (!is_object($object->thirdparty)) {
217  $object->thirdparty = $mysoc; // If fetch_thirdparty fails, object has no socid (specimen)
218  }
219 
220  $this->emetteur = $object->thirdparty;
221  if (!$this->emetteur->country_code) {
222  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
223  }
224 
225  if (!is_object($outputlangs)) {
226  $outputlangs = $langs;
227  }
228  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
229  if (!empty($conf->global->MAIN_USE_FPDF)) {
230  $outputlangs->charset_output = 'ISO-8859-1';
231  }
232 
233  // Load translation files required by the page
234  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products"));
235 
236  $nblines = count($object->lines);
237 
238  if ($conf->fournisseur->facture->dir_output) {
239  $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
240  $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
241  $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
242 
243  // Definition of $dir and $file
244  if ($object->specimen) {
245  $dir = $conf->fournisseur->facture->dir_output;
246  $file = $dir."/SPECIMEN.pdf";
247  } else {
248  $objectref = dol_sanitizeFileName($object->ref);
249  $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
250  $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$objectref;
251  $file = $dir."/".$objectref.".pdf";
252  if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
253  $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
254  }
255  }
256 
257  if (!file_exists($dir)) {
258  if (dol_mkdir($dir) < 0) {
259  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
260  return 0;
261  }
262  }
263 
264  if (file_exists($dir)) {
265  // Add pdfgeneration hook
266  if (!is_object($hookmanager)) {
267  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
268  $hookmanager = new HookManager($this->db);
269  }
270  $hookmanager->initHooks(array('pdfgeneration'));
271  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
272  global $action;
273  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
274 
275  // Set nblines with the new facture lines content after hook
276  $nblines = count($object->lines);
277  $nbpayments = count($object->getListOfPayments());
278 
279  // Create pdf instance
280  $pdf = pdf_getInstance($this->format);
281  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
282  $pdf->SetAutoPageBreak(1, 0);
283 
284  $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
285  if ($heightforinfotot > 220) {
286  $heightforinfotot = 220;
287  }
288  $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
289  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
290  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
291  $heightforfooter += 6;
292  }
293 
294  if (class_exists('TCPDF')) {
295  $pdf->setPrintHeader(false);
296  $pdf->setPrintFooter(false);
297  }
298  $pdf->SetFont(pdf_getPDFFont($outputlangs));
299  // Set path to the background PDF File
300  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
301  $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
302  $tplidx = $pdf->importPage(1);
303  }
304 
305  $pdf->Open();
306  $pagenb = 0;
307  $pdf->SetDrawColor(128, 128, 128);
308 
309  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
310  $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
311  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
312  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
313  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
314  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
315  $pdf->SetCompression(false);
316  }
317 
318  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
319 
320  // Set $this->atleastonediscount if you have at least one discount
321  for ($i = 0; $i < $nblines; $i++) {
322  if ($object->lines[$i]->remise_percent) {
323  $this->atleastonediscount++;
324  }
325  }
326  if (empty($this->atleastonediscount)) {
327  $delta = ($this->postotalht - $this->posxdiscount);
328  $this->posxpicture += $delta;
329  $this->posxtva += $delta;
330  $this->posxup += $delta;
331  $this->posxqty += $delta;
332  $this->posxunit += $delta;
333  $this->posxdiscount += $delta;
334  // post of fields after are not modified, stay at same position
335  }
336 
337  // New page
338  $pdf->AddPage();
339  if (!empty($tplidx)) {
340  $pdf->useTemplate($tplidx);
341  }
342  $pagenb++;
343  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
344  $pdf->SetFont('', '', $default_font_size - 1);
345  $pdf->MultiCell(0, 3, ''); // Set interline to 3
346  $pdf->SetTextColor(0, 0, 0);
347 
348  $tab_top = 90 + $top_shift;
349  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
350 
351  // Incoterm
352  if (isModEnabled('incoterm')) {
353  $desc_incoterms = $object->getIncotermsForPDF();
354  if ($desc_incoterms) {
355  $tab_top -= 2;
356 
357  $pdf->SetFont('', '', $default_font_size - 1);
358  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
359  $nexY = $pdf->GetY();
360  $height_incoterms = $nexY - $tab_top;
361 
362  // Rect takes a length in 3rd parameter
363  $pdf->SetDrawColor(192, 192, 192);
364  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
365 
366  $tab_top = $nexY + 6;
367  }
368  }
369 
370  // Displays notes
371  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
372 
373  // Extrafields in note
374  if (!empty($conf->global->INVOICE_ADD_EXTRAFIELD_IN_NOTE)) {
375  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
376  if (!empty($extranote)) {
377  $notetoshow = dol_concatdesc($notetoshow, $extranote);
378  }
379  }
380 
381  if ($notetoshow) {
382  $tab_top -= 2;
383 
384  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
385  complete_substitutions_array($substitutionarray, $outputlangs, $object);
386  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
387  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
388 
389  $pdf->SetFont('', '', $default_font_size - 1);
390  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
391  $nexY = $pdf->GetY();
392  $height_note = $nexY - $tab_top;
393 
394  // Rect takes a length in 3rd parameter
395  $pdf->SetDrawColor(192, 192, 192);
396  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
397 
398  $tab_top = $nexY + 6;
399  }
400 
401  $iniY = $tab_top + 7;
402  $curY = $tab_top + 7;
403  $nexY = $tab_top + 7;
404 
405  // Loop on each lines
406  for ($i = 0; $i < $nblines; $i++) {
407  $curY = $nexY;
408  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
409  $pdf->SetTextColor(0, 0, 0);
410 
411  // Define size of image if we need it
412  $imglinesize = array();
413  if (!empty($realpatharray[$i])) {
414  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
415  }
416 
417  $pdf->setTopMargin($tab_top_newpage);
418  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
419  $pageposbefore = $pdf->getPage();
420 
421  $showpricebeforepagebreak = 1;
422  $posYAfterImage = 0;
423 
424  // Description of product line
425  $curX = $this->posxdesc - 1;
426 
427  $pdf->startTransaction();
428  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
429  $pageposafter = $pdf->getPage();
430  if ($pageposafter > $pageposbefore) { // There is a pagebreak
431  $pdf->rollbackTransaction(true);
432  $pageposafter = $pageposbefore;
433  //print $pageposafter.'-'.$pageposbefore;exit;
434  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
435  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
436  $posyafter = $pdf->GetY();
437  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
438  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
439  $pdf->AddPage('', '', true);
440  if (!empty($tplidx)) {
441  $pdf->useTemplate($tplidx);
442  }
443  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
444  $this->_pagehead($pdf, $object, 0, $outputlangs);
445  }
446  $pdf->setPage($pageposafter + 1);
447  }
448  } else {
449  // We found a page break
450  // Allows data in the first page if description is long enough to break in multiples pages
451  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
452  $showpricebeforepagebreak = 1;
453  } else {
454  $showpricebeforepagebreak = 0;
455  }
456  }
457  } else // No pagebreak
458  {
459  $pdf->commitTransaction();
460  }
461  $posYAfterDescription = $pdf->GetY();
462 
463  $nexY = $pdf->GetY();
464  $pageposafter = $pdf->getPage();
465  $pdf->setPage($pageposbefore);
466  $pdf->setTopMargin($this->marge_haute);
467  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
468 
469  // We suppose that a too long description or photo were moved completely on next page
470  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
471  $pdf->setPage($pageposafter);
472  $curY = $tab_top_newpage;
473  }
474 
475  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
476 
477  // VAT Rate
478  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
479  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
480  $pdf->SetXY($this->posxtva, $curY);
481  $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
482  }
483 
484  // Unit price before discount
485  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
486  $pdf->SetXY($this->posxup, $curY);
487  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
488 
489  // Quantity
490  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
491  $pdf->SetXY($this->posxqty, $curY);
492  $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
493 
494  // Unit
495  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
496  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
497  $pdf->SetXY($this->posxunit, $curY);
498  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
499  }
500 
501  // Discount on line
502  if ($object->lines[$i]->remise_percent) {
503  $pdf->SetXY($this->posxdiscount - 2, $curY);
504  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
505  $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0, 'R');
506  }
507 
508  // Total HT line
509  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
510  $pdf->SetXY($this->postotalht, $curY);
511  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
512 
513  // Collection of totals by VAT value in $this->tva["taux"]=total_tva
514  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
515  $tvaligne = $object->lines[$i]->multicurrency_total_tva;
516  } else {
517  $tvaligne = $object->lines[$i]->total_tva;
518  }
519 
520  $localtax1ligne = $object->lines[$i]->total_localtax1;
521  $localtax2ligne = $object->lines[$i]->total_localtax2;
522 
523  if (!empty($object->remise_percent)) {
524  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
525  }
526 
527  $vatrate = (string) $object->lines[$i]->tva_tx;
528  $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
529  $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
530 
531  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
532  $vatrate .= '*';
533  }
534  if (empty($this->tva[$vatrate])) {
535  $this->tva[$vatrate] = 0;
536  }
537  if (empty($this->localtax1[$localtax1rate])) {
538  $this->localtax1[$localtax1rate] = 0;
539  }
540  if (empty($this->localtax2[$localtax2rate])) {
541  $this->localtax2[$localtax2rate] = 0;
542  }
543  $this->tva[$vatrate] += $tvaligne;
544  $this->localtax1[$localtax1rate] += $localtax1ligne;
545  $this->localtax2[$localtax2rate] += $localtax2ligne;
546 
547  if ($posYAfterImage > $posYAfterDescription) {
548  $nexY = $posYAfterImage;
549  }
550 
551  // Add line
552  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
553  $pdf->setPage($pageposafter);
554  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
555  //$pdf->SetDrawColor(190,190,200);
556  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
557  $pdf->SetLineStyle(array('dash'=>0));
558  }
559 
560  $nexY += 2; // Add space between lines
561 
562  // Detect if some page were added automatically and output _tableau for past pages
563  while ($pagenb < $pageposafter) {
564  $pdf->setPage($pagenb);
565  if ($pagenb == 1) {
566  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
567  } else {
568  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
569  }
570  $this->_pagefoot($pdf, $object, $outputlangs, 1);
571  $pagenb++;
572  $pdf->setPage($pagenb);
573  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
574  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
575  $this->_pagehead($pdf, $object, 0, $outputlangs);
576  }
577  }
578  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
579  if ($pagenb == 1) {
580  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
581  } else {
582  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
583  }
584  $this->_pagefoot($pdf, $object, $outputlangs, 1);
585  // New page
586  $pdf->AddPage();
587  if (!empty($tplidx)) {
588  $pdf->useTemplate($tplidx);
589  }
590  $pagenb++;
591  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
592  $this->_pagehead($pdf, $object, 0, $outputlangs);
593  }
594  }
595  }
596 
597  // Show square
598  if ($pagenb == 1) {
599  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
600  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
601  } else {
602  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
603  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
604  }
605 
606  // Display total area
607  $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
608 
609  $amount_credit_notes_included = 0;
610  $amount_deposits_included = 0;
611 
612  // Display Payments area
613  if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->SUPPLIER_INVOICE_NO_PAYMENT_DETAILS)) {
614  $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
615  }
616 
617  // Pagefoot
618  $this->_pagefoot($pdf, $object, $outputlangs);
619  if (method_exists($pdf, 'AliasNbPages')) {
620  $pdf->AliasNbPages();
621  }
622 
623  $pdf->Close();
624 
625  $pdf->Output($file, 'F');
626 
627  // Add pdfgeneration hook
628  $hookmanager->initHooks(array('pdfgeneration'));
629  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
630  global $action;
631  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
632  if ($reshook < 0) {
633  $this->error = $hookmanager->error;
634  $this->errors = $hookmanager->errors;
635  }
636 
637  if (!empty($conf->global->MAIN_UMASK)) {
638  @chmod($file, octdec($conf->global->MAIN_UMASK));
639  }
640 
641  $this->result = array('fullpath'=>$file);
642 
643  return 1; // No error
644  } else {
645  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
646  return 0;
647  }
648  } else {
649  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
650  return 0;
651  }
652  }
653 
654  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
655  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
666  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
667  {
668  // phpcs:enable
669  global $conf, $mysoc;
670 
671  $sign = 1;
672  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
673  $sign = -1;
674  }
675 
676  $default_font_size = pdf_getPDFFontSize($outputlangs);
677 
678  $tab2_top = $posy;
679  $tab2_hl = 4;
680  $pdf->SetFont('', '', $default_font_size - 1);
681 
682  // Total table
683  $col1x = 120;
684  $col2x = 170;
685  if ($this->page_largeur < 210) { // To work with US executive format
686  $col2x -= 20;
687  }
688  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
689 
690  $useborder = 0;
691  $index = 0;
692 
693  // Total HT
694  $pdf->SetFillColor(255, 255, 255);
695  $pdf->SetXY($col1x, $tab2_top + 0);
696  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
697 
698  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
699  $pdf->SetXY($col2x, $tab2_top + 0);
700  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
701 
702  // Show VAT by rates and total
703  $pdf->SetFillColor(248, 248, 248);
704 
705  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
706 
707  $this->atleastoneratenotnull = 0;
708  foreach ($this->tva as $tvakey => $tvaval) {
709  if ($tvakey > 0) { // We do not display rate 0
710  $this->atleastoneratenotnull++;
711 
712  $index++;
713  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
714 
715  $tvacompl = '';
716 
717  if (preg_match('/\*/', $tvakey)) {
718  $tvakey = str_replace('*', '', $tvakey);
719  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
720  }
721 
722  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
723  $totalvat .= vatrate($tvakey, 1).$tvacompl;
724  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
725 
726  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
727  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
728  }
729  }
730  if (!$this->atleastoneratenotnull) { // If no vat at all
731  $index++;
732  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
733  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
734  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
735  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva, 0, $outputlangs), 0, 'R', 1);
736 
737  // Total LocalTax1
738  if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
739  $index++;
740  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
741  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
742  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
743  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1, 0, $outputlangs), 0, 'R', 1);
744  }
745 
746  // Total LocalTax2
747  if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
748  $index++;
749  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
750  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
751  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
752  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2, 0, $outputlangs), 0, 'R', 1);
753  }
754  } else {
755  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
756  //{
757  //Local tax 1
758  foreach ($this->localtax1 as $tvakey => $tvaval) {
759  if ($tvakey != 0) { // On affiche pas taux 0
760  //$this->atleastoneratenotnull++;
761 
762  $index++;
763  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
764 
765  $tvacompl = '';
766  if (preg_match('/\*/', $tvakey)) {
767  $tvakey = str_replace('*', '', $tvakey);
768  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
769  }
770  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
771  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
772  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
773 
774  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
775  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
776  }
777  }
778  //}
779 
780  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
781  //{
782  //Local tax 2
783  foreach ($this->localtax2 as $tvakey => $tvaval) {
784  if ($tvakey != 0) { // On affiche pas taux 0
785  //$this->atleastoneratenotnull++;
786 
787  $index++;
788  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
789 
790  $tvacompl = '';
791  if (preg_match('/\*/', $tvakey)) {
792  $tvakey = str_replace('*', '', $tvakey);
793  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
794  }
795  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
796  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
797  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
798 
799  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
800  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
801  }
802  }
803  //}
804  }
805 
806  // Total TTC
807  $index++;
808  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
809  $pdf->SetTextColor(0, 0, 60);
810  $pdf->SetFillColor(224, 224, 224);
811  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
812 
813  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
814  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
815 
816  $pdf->SetTextColor(0, 0, 0);
817  $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
818  $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
819  //print "x".$creditnoteamount."-".$depositsamount;exit;
820  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
821  if (!empty($object->paye)) {
822  $resteapayer = 0;
823  }
824 
825  if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
826  // Already paid + Deposits
827  $index++;
828  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
829  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
830  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
831  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
832 
833  // Credit note
834  if ($creditnoteamount) {
835  $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
836  $index++;
837  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
838  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
839  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
840  $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
841  }
842 
843  // Escompte
844  if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
845  $index++;
846  $pdf->SetFillColor(255, 255, 255);
847 
848  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
849  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
850  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
851  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
852 
853  $resteapayer = 0;
854  }
855 
856  $index++;
857  $pdf->SetTextColor(0, 0, 60);
858  $pdf->SetFillColor(224, 224, 224);
859  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
860  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
861 
862  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
863  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
864  $pdf->SetFont('', '', $default_font_size - 1);
865  $pdf->SetTextColor(0, 0, 0);
866  }
867 
868  $index++;
869  return ($tab2_top + ($tab2_hl * $index));
870  }
871 
872  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
886  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
887  {
888  global $conf;
889 
890  // Force to disable hidetop and hidebottom
891  $hidebottom = 0;
892  if ($hidetop) {
893  $hidetop = -1;
894  }
895 
896  $currency = !empty($currency) ? $currency : $conf->currency;
897  $default_font_size = pdf_getPDFFontSize($outputlangs);
898 
899  // Amount in (at tab_top - 1)
900  $pdf->SetTextColor(0, 0, 0);
901  $pdf->SetFont('', '', $default_font_size - 2);
902 
903  if (empty($hidetop)) {
904  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
905  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
906  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
907 
908  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
909  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
910  $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));
911  }
912  }
913 
914  $pdf->SetDrawColor(128, 128, 128);
915  $pdf->SetFont('', '', $default_font_size - 1);
916 
917  // Output Rect
918  $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
919 
920  if (empty($hidetop)) {
921  $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
922 
923  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
924  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
925  }
926 
927  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
928  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
929  if (empty($hidetop)) {
930  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
931  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
932  }
933  }
934 
935  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
936  if (empty($hidetop)) {
937  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
938  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
939  }
940 
941  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
942  if (empty($hidetop)) {
943  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
944  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
945  }
946 
947  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
948  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
949  if (empty($hidetop)) {
950  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
951  $pdf->MultiCell(
952  $this->posxdiscount - $this->posxunit - 1,
953  2,
954  $outputlangs->transnoentities("Unit"),
955  '',
956  'C'
957  );
958  }
959  }
960 
961  if ($this->atleastonediscount) {
962  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
963  if (empty($hidetop)) {
964  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
965  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
966  }
967  }
968 
969  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
970  if (empty($hidetop)) {
971  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
972  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
973  }
974  }
975 
976  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
977  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
988  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
989  {
990  // phpcs:enable
991  global $conf;
992 
993  $sign = 1;
994  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
995  $sign = -1;
996  }
997 
998  $tab3_posx = 120;
999  $tab3_top = $posy + 8;
1000  $tab3_width = 80;
1001  $tab3_height = 4;
1002  if ($this->page_largeur < 210) { // To work with US executive format
1003  $tab3_posx -= 20;
1004  }
1005 
1006  $default_font_size = pdf_getPDFFontSize($outputlangs);
1007 
1008  $pdf->SetFont('', '', $default_font_size - 3);
1009  $pdf->SetXY($tab3_posx, $tab3_top - 4);
1010  $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0);
1011 
1012  $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1013 
1014  $pdf->SetFont('', '', $default_font_size - 4);
1015  $pdf->SetXY($tab3_posx, $tab3_top);
1016  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1017  $pdf->SetXY($tab3_posx + 21, $tab3_top);
1018  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1019  $pdf->SetXY($tab3_posx + 40, $tab3_top);
1020  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1021  $pdf->SetXY($tab3_posx + 58, $tab3_top);
1022  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1023 
1024  $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1025 
1026  $y = 0;
1027 
1028  $pdf->SetFont('', '', $default_font_size - 4);
1029 
1030  // Loop on each deposits and credit notes included
1031  //
1032 
1033  // Loop on each payment
1034  $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1035  $sql .= " cp.code";
1036  $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
1037  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1038  $sql .= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
1039  $sql .= " ORDER BY p.datep";
1040  $resql = $this->db->query($sql);
1041  if ($resql) {
1042  $num = $this->db->num_rows($resql);
1043  $i = 0;
1044  while ($i < $num) {
1045  $y += 3;
1046  $row = $this->db->fetch_object($resql);
1047 
1048  $pdf->SetXY($tab3_posx, $tab3_top + $y);
1049  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1050  $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1051  $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0, 'L', 0);
1052  $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1053  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1054 
1055  $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1056  $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1057  $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1058 
1059  $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1060 
1061  $i++;
1062  }
1063  } else {
1064  $this->error = $this->db->lasterror();
1065  return -1;
1066  }
1067  }
1068 
1069  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1079  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1080  {
1081  global $langs, $conf, $mysoc;
1082 
1083  // Load translation files required by the page
1084  $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
1085 
1086  $default_font_size = pdf_getPDFFontSize($outputlangs);
1087 
1088  // Do not add the BACKGROUND as this is for suppliers
1089  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1090 
1091  $pdf->SetTextColor(0, 0, 60);
1092  $pdf->SetFont('', 'B', $default_font_size + 3);
1093 
1094  $posy = $this->marge_haute;
1095  $posx = $this->page_largeur - $this->marge_droite - 100;
1096 
1097  $pdf->SetXY($this->marge_gauche, $posy);
1098 
1099  // Logo
1100  /*
1101  $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1102  if ($mysoc->logo)
1103  {
1104  if (is_readable($logo))
1105  {
1106  $height=pdf_getHeightForLogo($logo);
1107  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1108  }
1109  else
1110  {
1111  $pdf->SetTextColor(200,0,0);
1112  $pdf->SetFont('','B', $default_font_size - 2);
1113  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1114  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1115  }
1116  }
1117  else
1118  {*/
1119  $text = $this->emetteur->name;
1120  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1121  //}
1122 
1123  $pdf->SetFont('', 'B', $default_font_size + 3);
1124  $pdf->SetXY($posx, $posy);
1125  $pdf->SetTextColor(0, 0, 60);
1126  $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1127  if ($object->type == 1) {
1128  $title = $outputlangs->transnoentities("InvoiceReplacement");
1129  }
1130  if ($object->type == 2) {
1131  $title = $outputlangs->transnoentities("InvoiceAvoir");
1132  }
1133  if ($object->type == 3) {
1134  $title = $outputlangs->transnoentities("InvoiceDeposit");
1135  }
1136  $pdf->MultiCell(100, 3, $title." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1137  $posy += 1;
1138 
1139  if ($object->ref_supplier) {
1140  $posy += 4;
1141  $pdf->SetFont('', 'B', $default_font_size);
1142  $pdf->SetXY($posx, $posy);
1143  $pdf->SetTextColor(0, 0, 60);
1144  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : ".$object->ref_supplier, '', 'R');
1145  $posy += 1;
1146  }
1147 
1148  $pdf->SetFont('', '', $default_font_size - 1);
1149 
1150  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1151  $object->fetch_projet();
1152  if (!empty($object->project->ref)) {
1153  $posy += 3;
1154  $pdf->SetXY($posx, $posy);
1155  $pdf->SetTextColor(0, 0, 60);
1156  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1157  }
1158  }
1159 
1160  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1161  $object->fetch_projet();
1162  if (!empty($object->project->ref)) {
1163  $outputlangs->load("projects");
1164  $posy += 4;
1165  $pdf->SetXY($posx, $posy);
1166  $langs->load("projects");
1167  $pdf->SetTextColor(0, 0, 60);
1168  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1169  }
1170  }
1171 
1172  if ($object->date) {
1173  $posy += 4;
1174  $pdf->SetXY($posx, $posy);
1175  $pdf->SetTextColor(0, 0, 60);
1176  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1177  } else {
1178  $posy += 4;
1179  $pdf->SetXY($posx, $posy);
1180  $pdf->SetTextColor(255, 0, 0);
1181  $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
1182  }
1183 
1184  if ($object->thirdparty->code_fournisseur) {
1185  $posy += 4;
1186  $pdf->SetXY($posx, $posy);
1187  $pdf->SetTextColor(0, 0, 60);
1188  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1189  }
1190 
1191  $posy += 1;
1192  $pdf->SetTextColor(0, 0, 60);
1193 
1194  $top_shift = 0;
1195  // Show list of linked objects
1196  $current_y = $pdf->getY();
1197  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1198  if ($current_y < $pdf->getY()) {
1199  $top_shift = $pdf->getY() - $current_y;
1200  }
1201 
1202  if ($showaddress) {
1203  // Sender properties
1204  $carac_emetteur = '';
1205  // Add internal contact of proposal if defined
1206  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1207  if (count($arrayidcontact) > 0) {
1208  $object->fetch_user($arrayidcontact[0]);
1209  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1210  }
1211 
1212  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1213 
1214  // Show sender
1215  $posy = 42 + $top_shift;
1216  $posx = $this->marge_gauche;
1217  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1218  $posx = $this->page_largeur - $this->marge_droite - 80;
1219  }
1220  $hautcadre = 40;
1221 
1222  // Show sender frame
1223  $pdf->SetTextColor(0, 0, 0);
1224  $pdf->SetFont('', '', $default_font_size - 2);
1225  $pdf->SetXY($posx, $posy - 5);
1226  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
1227  $pdf->SetXY($posx, $posy);
1228  $pdf->SetFillColor(230, 230, 230);
1229  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1230  $pdf->SetTextColor(0, 0, 60);
1231 
1232  // Show sender name
1233  $pdf->SetXY($posx + 2, $posy + 3);
1234  $pdf->SetFont('', 'B', $default_font_size);
1235  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1236  $posy = $pdf->getY();
1237 
1238  // Show sender information
1239  $pdf->SetXY($posx + 2, $posy);
1240  $pdf->SetFont('', '', $default_font_size - 1);
1241  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1242 
1243 
1244 
1245  // If BILLING contact defined on invoice, we use it
1246  $usecontact = false;
1247  $arrayidcontact = $object->getIdContact('internal', 'BILLING');
1248  if (count($arrayidcontact) > 0) {
1249  $usecontact = true;
1250  $result = $object->fetch_contact($arrayidcontact[0]);
1251  }
1252 
1253  // Recipient name
1254  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)))) {
1255  $thirdparty = $object->contact;
1256  } else {
1257  $thirdparty = $mysoc;
1258  }
1259 
1260  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1261 
1262  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
1263 
1264  // Show recipient
1265  $widthrecbox = 100;
1266  if ($this->page_largeur < 210) {
1267  $widthrecbox = 84; // To work with US executive format
1268  }
1269  $posy = 42 + $top_shift;
1270  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1271  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1272  $posx = $this->marge_gauche;
1273  }
1274 
1275  // Show recipient frame
1276  $pdf->SetTextColor(0, 0, 0);
1277  $pdf->SetFont('', '', $default_font_size - 2);
1278  $pdf->SetXY($posx + 2, $posy - 5);
1279  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, 'L');
1280  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1281 
1282  // Show recipient name
1283  $pdf->SetXY($posx + 2, $posy + 3);
1284  $pdf->SetFont('', 'B', $default_font_size);
1285  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1286 
1287  $posy = $pdf->getY();
1288 
1289  // Show recipient information
1290  $pdf->SetFont('', '', $default_font_size - 1);
1291  $pdf->SetXY($posx + 2, $posy);
1292  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1293  }
1294 
1295  return $top_shift;
1296  }
1297 
1298  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1308  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1309  {
1310  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1311  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1312  }
1313 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:8167
pdf_getlinevatrate
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1824
db
$conf db
API class for accounts.
Definition: inc.php:41
pdf_getSizeForImage
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2514
pdf_getlineqty
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1971
pdf_getlineupexcltax
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1886
pdf_writelinedesc
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1359
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
pdf_getlineremisepercent
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:2175
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_canelle\_tableau_tot
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
Definition: pdf_canelle.modules.php:666
pdf_canelle\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_canelle.modules.php:1079
pdf_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
ModelePDFSuppliersInvoices
Parent class for supplier invoices models.
Definition: modules_facturefournisseur.php:35
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_getlineunit
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:2132
name
$conf db name
Definition: repair.php:122
pdf_canelle\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
Definition: pdf_canelle.modules.php:886
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5823
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7542
pdf_canelle\_tableau_versements
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
Definition: pdf_canelle.modules.php:988
pdfBuildThirdpartyName
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6735
pdf_canelle\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_canelle.modules.php:1308
pdf_canelle\__construct
__construct($db)
Constructor.
Definition: pdf_canelle.modules.php:126
$resql
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
pdf_canelle
Class to generate the supplier invoices PDF with the template canelle.
Definition: pdf_canelle.modules.php:39
CommonDocGenerator\printRect
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Definition: commondocgenerator.class.php:982
pdf_writeLinkedObjects
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1323
pdf_build_address
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:434
convertBackOfficeMediasLinksToPublicLinks
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
Definition: functions2.lib.php:2721
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
dol_htmlentitiesbr
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Definition: functions.lib.php:7277
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getSubstitutionArray
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:749
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5697
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6789
pdf_getlinetotalexcltax
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2269
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
complete_substitutions_array
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
Definition: functions.lib.php:8290
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5648
pdf_pagefoot
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:1001
pdf_canelle\write_file
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Definition: pdf_canelle.modules.php:207
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25