dolibarr  16.0.5
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(5, 6);
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 = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
145  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
146  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
147  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->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  $this->posxtva = 112;
158  $this->posxup = 126;
159  $this->posxqty = 145;
160  $this->posxunit = 162;
161  $this->posxdiscount = 162;
162  $this->postotalht = 174;
163 
164  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
165  $this->posxtva = 99;
166  $this->posxup = 114;
167  $this->posxqty = 130;
168  $this->posxunit = 147;
169  }
170  //if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
171  $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
172  if ($this->page_largeur < 210) { // To work with US executive format
173  $this->posxpicture -= 20;
174  $this->posxtva -= 20;
175  $this->posxup -= 20;
176  $this->posxqty -= 20;
177  $this->posxunit -= 20;
178  $this->posxdiscount -= 20;
179  $this->postotalht -= 20;
180  }
181 
182  $this->tva = array();
183  $this->tva_array = array();
184  $this->localtax1 = array();
185  $this->localtax2 = array();
186  $this->atleastoneratenotnull = 0;
187  $this->atleastonediscount = 0;
188  }
189 
190 
191  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
203  public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
204  {
205  // phpcs:enable
206  global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
207 
208  // Get source company
209  if (!is_object($object->thirdparty)) {
210  $object->fetch_thirdparty();
211  }
212  if (!is_object($object->thirdparty)) {
213  $object->thirdparty = $mysoc; // If fetch_thirdparty fails, object has no socid (specimen)
214  }
215 
216  $this->emetteur = $object->thirdparty;
217  if (!$this->emetteur->country_code) {
218  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
219  }
220 
221  if (!is_object($outputlangs)) {
222  $outputlangs = $langs;
223  }
224  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
225  if (!empty($conf->global->MAIN_USE_FPDF)) {
226  $outputlangs->charset_output = 'ISO-8859-1';
227  }
228 
229  // Load translation files required by the page
230  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products"));
231 
232  $nblines = count($object->lines);
233 
234  if ($conf->fournisseur->facture->dir_output) {
235  $deja_regle = $object->getSommePaiement((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
236  $amount_credit_notes_included = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
237  $amount_deposits_included = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
238 
239  // Definition of $dir and $file
240  if ($object->specimen) {
241  $dir = $conf->fournisseur->facture->dir_output;
242  $file = $dir."/SPECIMEN.pdf";
243  } else {
244  $objectref = dol_sanitizeFileName($object->ref);
245  $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
246  $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$objectref;
247  $file = $dir."/".$objectref.".pdf";
248  if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
249  $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
250  }
251  }
252 
253  if (!file_exists($dir)) {
254  if (dol_mkdir($dir) < 0) {
255  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
256  return 0;
257  }
258  }
259 
260  if (file_exists($dir)) {
261  // Add pdfgeneration hook
262  if (!is_object($hookmanager)) {
263  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
264  $hookmanager = new HookManager($this->db);
265  }
266  $hookmanager->initHooks(array('pdfgeneration'));
267  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
268  global $action;
269  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
270 
271  // Set nblines with the new facture lines content after hook
272  $nblines = count($object->lines);
273  $nbpayments = count($object->getListOfPayments());
274 
275  // Create pdf instance
276  $pdf = pdf_getInstance($this->format);
277  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
278  $pdf->SetAutoPageBreak(1, 0);
279 
280  $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part
281  if ($heightforinfotot > 220) {
282  $heightforinfotot = 220;
283  }
284  $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
285  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
286  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
287  $heightforfooter += 6;
288  }
289 
290  if (class_exists('TCPDF')) {
291  $pdf->setPrintHeader(false);
292  $pdf->setPrintFooter(false);
293  }
294  $pdf->SetFont(pdf_getPDFFont($outputlangs));
295  // Set path to the background PDF File
296  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
297  $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
298  $tplidx = $pdf->importPage(1);
299  }
300 
301  $pdf->Open();
302  $pagenb = 0;
303  $pdf->SetDrawColor(128, 128, 128);
304 
305  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
306  $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
307  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
308  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
309  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
310  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
311  $pdf->SetCompression(false);
312  }
313 
314  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
315 
316  // Set $this->atleastonediscount if you have at least one discount
317  for ($i = 0; $i < $nblines; $i++) {
318  if ($object->lines[$i]->remise_percent) {
319  $this->atleastonediscount++;
320  }
321  }
322  if (empty($this->atleastonediscount)) {
323  $delta = ($this->postotalht - $this->posxdiscount);
324  $this->posxpicture += $delta;
325  $this->posxtva += $delta;
326  $this->posxup += $delta;
327  $this->posxqty += $delta;
328  $this->posxunit += $delta;
329  $this->posxdiscount += $delta;
330  // post of fields after are not modified, stay at same position
331  }
332 
333  // New page
334  $pdf->AddPage();
335  if (!empty($tplidx)) {
336  $pdf->useTemplate($tplidx);
337  }
338  $pagenb++;
339  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
340  $pdf->SetFont('', '', $default_font_size - 1);
341  $pdf->MultiCell(0, 3, ''); // Set interline to 3
342  $pdf->SetTextColor(0, 0, 0);
343 
344  $tab_top = 90 + $top_shift;
345  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
346 
347  // Incoterm
348  if (!empty($conf->incoterm->enabled)) {
349  $desc_incoterms = $object->getIncotermsForPDF();
350  if ($desc_incoterms) {
351  $tab_top -= 2;
352 
353  $pdf->SetFont('', '', $default_font_size - 1);
354  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
355  $nexY = $pdf->GetY();
356  $height_incoterms = $nexY - $tab_top;
357 
358  // Rect takes a length in 3rd parameter
359  $pdf->SetDrawColor(192, 192, 192);
360  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
361 
362  $tab_top = $nexY + 6;
363  }
364  }
365 
366  // Displays notes
367  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
368 
369  if ($notetoshow) {
370  $tab_top -= 2;
371 
372  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
373  complete_substitutions_array($substitutionarray, $outputlangs, $object);
374  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
375  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
376 
377  $pdf->SetFont('', '', $default_font_size - 1);
378  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
379  $nexY = $pdf->GetY();
380  $height_note = $nexY - $tab_top;
381 
382  // Rect takes a length in 3rd parameter
383  $pdf->SetDrawColor(192, 192, 192);
384  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
385 
386  $tab_top = $nexY + 6;
387  }
388 
389  $iniY = $tab_top + 7;
390  $curY = $tab_top + 7;
391  $nexY = $tab_top + 7;
392 
393  // Loop on each lines
394  for ($i = 0; $i < $nblines; $i++) {
395  $curY = $nexY;
396  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
397  $pdf->SetTextColor(0, 0, 0);
398 
399  // Define size of image if we need it
400  $imglinesize = array();
401  if (!empty($realpatharray[$i])) {
402  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
403  }
404 
405  $pdf->setTopMargin($tab_top_newpage);
406  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
407  $pageposbefore = $pdf->getPage();
408 
409  $showpricebeforepagebreak = 1;
410  $posYAfterImage = 0;
411 
412  // Description of product line
413  $curX = $this->posxdesc - 1;
414 
415  $pdf->startTransaction();
416  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
417  $pageposafter = $pdf->getPage();
418  if ($pageposafter > $pageposbefore) { // There is a pagebreak
419  $pdf->rollbackTransaction(true);
420  $pageposafter = $pageposbefore;
421  //print $pageposafter.'-'.$pageposbefore;exit;
422  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
423  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
424  $posyafter = $pdf->GetY();
425  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
426  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
427  $pdf->AddPage('', '', true);
428  if (!empty($tplidx)) {
429  $pdf->useTemplate($tplidx);
430  }
431  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
432  $this->_pagehead($pdf, $object, 0, $outputlangs);
433  }
434  $pdf->setPage($pageposafter + 1);
435  }
436  } else {
437  // We found a page break
438  // Allows data in the first page if description is long enough to break in multiples pages
439  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
440  $showpricebeforepagebreak = 1;
441  } else {
442  $showpricebeforepagebreak = 0;
443  }
444  }
445  } else // No pagebreak
446  {
447  $pdf->commitTransaction();
448  }
449  $posYAfterDescription = $pdf->GetY();
450 
451  $nexY = $pdf->GetY();
452  $pageposafter = $pdf->getPage();
453  $pdf->setPage($pageposbefore);
454  $pdf->setTopMargin($this->marge_haute);
455  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
456 
457  // We suppose that a too long description or photo were moved completely on next page
458  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
459  $pdf->setPage($pageposafter);
460  $curY = $tab_top_newpage;
461  }
462 
463  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
464 
465  // VAT Rate
466  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
467  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
468  $pdf->SetXY($this->posxtva, $curY);
469  $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
470  }
471 
472  // Unit price before discount
473  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
474  $pdf->SetXY($this->posxup, $curY);
475  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
476 
477  // Quantity
478  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
479  $pdf->SetXY($this->posxqty, $curY);
480  $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
481 
482  // Unit
483  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
484  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
485  $pdf->SetXY($this->posxunit, $curY);
486  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
487  }
488 
489  // Discount on line
490  if ($object->lines[$i]->remise_percent) {
491  $pdf->SetXY($this->posxdiscount - 2, $curY);
492  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
493  $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0, 'R');
494  }
495 
496  // Total HT line
497  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
498  $pdf->SetXY($this->postotalht, $curY);
499  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
500 
501  // Collection of totals by VAT value in $this->tva["taux"]=total_tva
502  if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
503  $tvaligne = $object->lines[$i]->multicurrency_total_tva;
504  } else {
505  $tvaligne = $object->lines[$i]->total_tva;
506  }
507 
508  $localtax1ligne = $object->lines[$i]->total_localtax1;
509  $localtax2ligne = $object->lines[$i]->total_localtax2;
510 
511  if (!empty($object->remise_percent)) {
512  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
513  }
514 
515  $vatrate = (string) $object->lines[$i]->tva_tx;
516  $localtax1rate = (string) $object->lines[$i]->localtax1_tx;
517  $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
518 
519  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
520  $vatrate .= '*';
521  }
522  if (empty($this->tva[$vatrate])) {
523  $this->tva[$vatrate] = 0;
524  }
525  if (empty($this->localtax1[$localtax1rate])) {
526  $this->localtax1[$localtax1rate] = 0;
527  }
528  if (empty($this->localtax2[$localtax2rate])) {
529  $this->localtax2[$localtax2rate] = 0;
530  }
531  $this->tva[$vatrate] += $tvaligne;
532  $this->localtax1[$localtax1rate] += $localtax1ligne;
533  $this->localtax2[$localtax2rate] += $localtax2ligne;
534 
535  if ($posYAfterImage > $posYAfterDescription) {
536  $nexY = $posYAfterImage;
537  }
538 
539  // Add line
540  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
541  $pdf->setPage($pageposafter);
542  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
543  //$pdf->SetDrawColor(190,190,200);
544  $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
545  $pdf->SetLineStyle(array('dash'=>0));
546  }
547 
548  $nexY += 2; // Add space between lines
549 
550  // Detect if some page were added automatically and output _tableau for past pages
551  while ($pagenb < $pageposafter) {
552  $pdf->setPage($pagenb);
553  if ($pagenb == 1) {
554  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
555  } else {
556  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
557  }
558  $this->_pagefoot($pdf, $object, $outputlangs, 1);
559  $pagenb++;
560  $pdf->setPage($pagenb);
561  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
562  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
563  $this->_pagehead($pdf, $object, 0, $outputlangs);
564  }
565  }
566  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
567  if ($pagenb == 1) {
568  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
569  } else {
570  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
571  }
572  $this->_pagefoot($pdf, $object, $outputlangs, 1);
573  // New page
574  $pdf->AddPage();
575  if (!empty($tplidx)) {
576  $pdf->useTemplate($tplidx);
577  }
578  $pagenb++;
579  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
580  $this->_pagehead($pdf, $object, 0, $outputlangs);
581  }
582  }
583  }
584 
585  // Show square
586  if ($pagenb == 1) {
587  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
588  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
589  } else {
590  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
591  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
592  }
593 
594  // Display total area
595  $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
596 
597  $amount_credit_notes_included = 0;
598  $amount_deposits_included = 0;
599 
600  // Display Payments area
601  if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->SUPPLIER_INVOICE_NO_PAYMENT_DETAILS)) {
602  $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
603  }
604 
605  // Pagefoot
606  $this->_pagefoot($pdf, $object, $outputlangs);
607  if (method_exists($pdf, 'AliasNbPages')) {
608  $pdf->AliasNbPages();
609  }
610 
611  $pdf->Close();
612 
613  $pdf->Output($file, 'F');
614 
615  // Add pdfgeneration hook
616  $hookmanager->initHooks(array('pdfgeneration'));
617  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
618  global $action;
619  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
620  if ($reshook < 0) {
621  $this->error = $hookmanager->error;
622  $this->errors = $hookmanager->errors;
623  }
624 
625  if (!empty($conf->global->MAIN_UMASK)) {
626  @chmod($file, octdec($conf->global->MAIN_UMASK));
627  }
628 
629  $this->result = array('fullpath'=>$file);
630 
631  return 1; // No error
632  } else {
633  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
634  return 0;
635  }
636  } else {
637  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
638  return 0;
639  }
640  }
641 
642  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
643  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
654  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
655  {
656  // phpcs:enable
657  global $conf, $mysoc;
658 
659  $sign = 1;
660  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
661  $sign = -1;
662  }
663 
664  $default_font_size = pdf_getPDFFontSize($outputlangs);
665 
666  $tab2_top = $posy;
667  $tab2_hl = 4;
668  $pdf->SetFont('', '', $default_font_size - 1);
669 
670  // Total table
671  $col1x = 120;
672  $col2x = 170;
673  if ($this->page_largeur < 210) { // To work with US executive format
674  $col2x -= 20;
675  }
676  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
677 
678  $useborder = 0;
679  $index = 0;
680 
681  // Total HT
682  $pdf->SetFillColor(255, 255, 255);
683  $pdf->SetXY($col1x, $tab2_top + 0);
684  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
685 
686  $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
687  $pdf->SetXY($col2x, $tab2_top + 0);
688  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
689 
690  // Show VAT by rates and total
691  $pdf->SetFillColor(248, 248, 248);
692 
693  $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
694 
695  $this->atleastoneratenotnull = 0;
696  foreach ($this->tva as $tvakey => $tvaval) {
697  if ($tvakey > 0) { // We do not display rate 0
698  $this->atleastoneratenotnull++;
699 
700  $index++;
701  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
702 
703  $tvacompl = '';
704 
705  if (preg_match('/\*/', $tvakey)) {
706  $tvakey = str_replace('*', '', $tvakey);
707  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
708  }
709 
710  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
711  $totalvat .= vatrate($tvakey, 1).$tvacompl;
712  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
713 
714  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
715  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
716  }
717  }
718  if (!$this->atleastoneratenotnull) { // If no vat at all
719  $index++;
720  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
721  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
722  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
723  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva, 0, $outputlangs), 0, 'R', 1);
724 
725  // Total LocalTax1
726  if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
727  $index++;
728  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
729  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
730  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
731  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1, 0, $outputlangs), 0, 'R', 1);
732  }
733 
734  // Total LocalTax2
735  if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
736  $index++;
737  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
738  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
739  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
740  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2, 0, $outputlangs), 0, 'R', 1);
741  }
742  } else {
743  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
744  //{
745  //Local tax 1
746  foreach ($this->localtax1 as $tvakey => $tvaval) {
747  if ($tvakey != 0) { // On affiche pas taux 0
748  //$this->atleastoneratenotnull++;
749 
750  $index++;
751  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
752 
753  $tvacompl = '';
754  if (preg_match('/\*/', $tvakey)) {
755  $tvakey = str_replace('*', '', $tvakey);
756  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
757  }
758  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
759  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
760  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
761 
762  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
763  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
764  }
765  }
766  //}
767 
768  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
769  //{
770  //Local tax 2
771  foreach ($this->localtax2 as $tvakey => $tvaval) {
772  if ($tvakey != 0) { // On affiche pas taux 0
773  //$this->atleastoneratenotnull++;
774 
775  $index++;
776  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
777 
778  $tvacompl = '';
779  if (preg_match('/\*/', $tvakey)) {
780  $tvakey = str_replace('*', '', $tvakey);
781  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
782  }
783  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
784  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
785  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
786 
787  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
788  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
789  }
790  }
791  //}
792  }
793 
794  // Total TTC
795  $index++;
796  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
797  $pdf->SetTextColor(0, 0, 60);
798  $pdf->SetFillColor(224, 224, 224);
799  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
800 
801  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
802  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
803 
804  $pdf->SetTextColor(0, 0, 0);
805  $creditnoteamount = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
806  $depositsamount = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
807  //print "x".$creditnoteamount."-".$depositsamount;exit;
808  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
809  if (!empty($object->paye)) {
810  $resteapayer = 0;
811  }
812 
813  if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
814  // Already paid + Deposits
815  $index++;
816  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
817  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
818  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
819  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
820 
821  // Credit note
822  if ($creditnoteamount) {
823  $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
824  $index++;
825  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
826  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
827  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
828  $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
829  }
830 
831  // Escompte
832  if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
833  $index++;
834  $pdf->SetFillColor(255, 255, 255);
835 
836  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
837  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
838  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
839  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
840 
841  $resteapayer = 0;
842  }
843 
844  $index++;
845  $pdf->SetTextColor(0, 0, 60);
846  $pdf->SetFillColor(224, 224, 224);
847  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
848  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
849 
850  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
851  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
852  $pdf->SetFont('', '', $default_font_size - 1);
853  $pdf->SetTextColor(0, 0, 0);
854  }
855 
856  $index++;
857  return ($tab2_top + ($tab2_hl * $index));
858  }
859 
860  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
874  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
875  {
876  global $conf;
877 
878  // Force to disable hidetop and hidebottom
879  $hidebottom = 0;
880  if ($hidetop) {
881  $hidetop = -1;
882  }
883 
884  $currency = !empty($currency) ? $currency : $conf->currency;
885  $default_font_size = pdf_getPDFFontSize($outputlangs);
886 
887  // Amount in (at tab_top - 1)
888  $pdf->SetTextColor(0, 0, 0);
889  $pdf->SetFont('', '', $default_font_size - 2);
890 
891  if (empty($hidetop)) {
892  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
893  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
894  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
895 
896  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
897  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
898  $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));
899  }
900  }
901 
902  $pdf->SetDrawColor(128, 128, 128);
903  $pdf->SetFont('', '', $default_font_size - 1);
904 
905  // Output Rect
906  $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
907 
908  if (empty($hidetop)) {
909  $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
910 
911  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
912  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
913  }
914 
915  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
916  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
917  if (empty($hidetop)) {
918  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
919  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
920  }
921  }
922 
923  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
924  if (empty($hidetop)) {
925  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
926  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
927  }
928 
929  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
930  if (empty($hidetop)) {
931  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
932  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
933  }
934 
935  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
936  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
937  if (empty($hidetop)) {
938  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
939  $pdf->MultiCell(
940  $this->posxdiscount - $this->posxunit - 1,
941  2,
942  $outputlangs->transnoentities("Unit"),
943  '',
944  'C'
945  );
946  }
947  }
948 
949  if ($this->atleastonediscount) {
950  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
951  if (empty($hidetop)) {
952  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
953  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
954  }
955  }
956 
957  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
958  if (empty($hidetop)) {
959  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
960  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
961  }
962  }
963 
964  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
965  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
976  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
977  {
978  // phpcs:enable
979  global $conf;
980 
981  $sign = 1;
982  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
983  $sign = -1;
984  }
985 
986  $tab3_posx = 120;
987  $tab3_top = $posy + 8;
988  $tab3_width = 80;
989  $tab3_height = 4;
990  if ($this->page_largeur < 210) { // To work with US executive format
991  $tab3_posx -= 20;
992  }
993 
994  $default_font_size = pdf_getPDFFontSize($outputlangs);
995 
996  $pdf->SetFont('', '', $default_font_size - 3);
997  $pdf->SetXY($tab3_posx, $tab3_top - 4);
998  $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0);
999 
1000  $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1001 
1002  $pdf->SetFont('', '', $default_font_size - 4);
1003  $pdf->SetXY($tab3_posx, $tab3_top);
1004  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1005  $pdf->SetXY($tab3_posx + 21, $tab3_top);
1006  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1007  $pdf->SetXY($tab3_posx + 40, $tab3_top);
1008  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1009  $pdf->SetXY($tab3_posx + 58, $tab3_top);
1010  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1011 
1012  $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1013 
1014  $y = 0;
1015 
1016  $pdf->SetFont('', '', $default_font_size - 4);
1017 
1018  // Loop on each deposits and credit notes included
1019  //
1020 
1021  // Loop on each payment
1022  $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1023  $sql .= " cp.code";
1024  $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
1025  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1026  $sql .= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
1027  $sql .= " ORDER BY p.datep";
1028  $resql = $this->db->query($sql);
1029  if ($resql) {
1030  $num = $this->db->num_rows($resql);
1031  $i = 0;
1032  while ($i < $num) {
1033  $y += 3;
1034  $row = $this->db->fetch_object($resql);
1035 
1036  $pdf->SetXY($tab3_posx, $tab3_top + $y);
1037  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1038  $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1039  $pdf->MultiCell(20, 3, price($sign * ((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0, 'L', 0);
1040  $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1041  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1042 
1043  $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1044  $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1045  $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1046 
1047  $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1048 
1049  $i++;
1050  }
1051  } else {
1052  $this->error = $this->db->lasterror();
1053  return -1;
1054  }
1055  }
1056 
1057  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1067  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1068  {
1069  global $langs, $conf, $mysoc;
1070 
1071  // Load translation files required by the page
1072  $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
1073 
1074  $default_font_size = pdf_getPDFFontSize($outputlangs);
1075 
1076  // Do not add the BACKGROUND as this is for suppliers
1077  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1078 
1079  $pdf->SetTextColor(0, 0, 60);
1080  $pdf->SetFont('', 'B', $default_font_size + 3);
1081 
1082  $posy = $this->marge_haute;
1083  $posx = $this->page_largeur - $this->marge_droite - 100;
1084 
1085  $pdf->SetXY($this->marge_gauche, $posy);
1086 
1087  // Logo
1088  /*
1089  $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1090  if ($mysoc->logo)
1091  {
1092  if (is_readable($logo))
1093  {
1094  $height=pdf_getHeightForLogo($logo);
1095  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1096  }
1097  else
1098  {
1099  $pdf->SetTextColor(200,0,0);
1100  $pdf->SetFont('','B', $default_font_size - 2);
1101  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1102  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1103  }
1104  }
1105  else
1106  {*/
1107  $text = $this->emetteur->name;
1108  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1109  //}
1110 
1111  $pdf->SetFont('', 'B', $default_font_size + 3);
1112  $pdf->SetXY($posx, $posy);
1113  $pdf->SetTextColor(0, 0, 60);
1114  $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1115  if ($object->type == 1) {
1116  $title = $outputlangs->transnoentities("InvoiceReplacement");
1117  }
1118  if ($object->type == 2) {
1119  $title = $outputlangs->transnoentities("InvoiceAvoir");
1120  }
1121  if ($object->type == 3) {
1122  $title = $outputlangs->transnoentities("InvoiceDeposit");
1123  }
1124  $pdf->MultiCell(100, 3, $title." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1125  $posy += 1;
1126 
1127  if ($object->ref_supplier) {
1128  $posy += 4;
1129  $pdf->SetFont('', 'B', $default_font_size);
1130  $pdf->SetXY($posx, $posy);
1131  $pdf->SetTextColor(0, 0, 60);
1132  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : ".$object->ref_supplier, '', 'R');
1133  $posy += 1;
1134  }
1135 
1136  $pdf->SetFont('', '', $default_font_size - 1);
1137 
1138  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1139  $object->fetch_projet();
1140  if (!empty($object->project->ref)) {
1141  $posy += 3;
1142  $pdf->SetXY($posx, $posy);
1143  $pdf->SetTextColor(0, 0, 60);
1144  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1145  }
1146  }
1147 
1148  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1149  $object->fetch_projet();
1150  if (!empty($object->project->ref)) {
1151  $outputlangs->load("projects");
1152  $posy += 4;
1153  $pdf->SetXY($posx, $posy);
1154  $langs->load("projects");
1155  $pdf->SetTextColor(0, 0, 60);
1156  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1157  }
1158  }
1159 
1160  if ($object->date) {
1161  $posy += 4;
1162  $pdf->SetXY($posx, $posy);
1163  $pdf->SetTextColor(0, 0, 60);
1164  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1165  } else {
1166  $posy += 4;
1167  $pdf->SetXY($posx, $posy);
1168  $pdf->SetTextColor(255, 0, 0);
1169  $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
1170  }
1171 
1172  if ($object->thirdparty->code_fournisseur) {
1173  $posy += 4;
1174  $pdf->SetXY($posx, $posy);
1175  $pdf->SetTextColor(0, 0, 60);
1176  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1177  }
1178 
1179  $posy += 1;
1180  $pdf->SetTextColor(0, 0, 60);
1181 
1182  $top_shift = 0;
1183  // Show list of linked objects
1184  $current_y = $pdf->getY();
1185  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1186  if ($current_y < $pdf->getY()) {
1187  $top_shift = $pdf->getY() - $current_y;
1188  }
1189 
1190  if ($showaddress) {
1191  // Sender properties
1192  $carac_emetteur = '';
1193  // Add internal contact of proposal if defined
1194  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1195  if (count($arrayidcontact) > 0) {
1196  $object->fetch_user($arrayidcontact[0]);
1197  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1198  }
1199 
1200  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1201 
1202  // Show sender
1203  $posy = 42 + $top_shift;
1204  $posx = $this->marge_gauche;
1205  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1206  $posx = $this->page_largeur - $this->marge_droite - 80;
1207  }
1208  $hautcadre = 40;
1209 
1210  // Show sender frame
1211  $pdf->SetTextColor(0, 0, 0);
1212  $pdf->SetFont('', '', $default_font_size - 2);
1213  $pdf->SetXY($posx, $posy - 5);
1214  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
1215  $pdf->SetXY($posx, $posy);
1216  $pdf->SetFillColor(230, 230, 230);
1217  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1218  $pdf->SetTextColor(0, 0, 60);
1219 
1220  // Show sender name
1221  $pdf->SetXY($posx + 2, $posy + 3);
1222  $pdf->SetFont('', 'B', $default_font_size);
1223  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1224  $posy = $pdf->getY();
1225 
1226  // Show sender information
1227  $pdf->SetXY($posx + 2, $posy);
1228  $pdf->SetFont('', '', $default_font_size - 1);
1229  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1230 
1231 
1232 
1233  // If BILLING contact defined on invoice, we use it
1234  $usecontact = false;
1235  $arrayidcontact = $object->getIdContact('internal', 'BILLING');
1236  if (count($arrayidcontact) > 0) {
1237  $usecontact = true;
1238  $result = $object->fetch_contact($arrayidcontact[0]);
1239  }
1240 
1241  // Recipient name
1242  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)))) {
1243  $thirdparty = $object->contact;
1244  } else {
1245  $thirdparty = $mysoc;
1246  }
1247 
1248  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1249 
1250  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
1251 
1252  // Show recipient
1253  $widthrecbox = 100;
1254  if ($this->page_largeur < 210) {
1255  $widthrecbox = 84; // To work with US executive format
1256  }
1257  $posy = 42 + $top_shift;
1258  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1259  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1260  $posx = $this->marge_gauche;
1261  }
1262 
1263  // Show recipient frame
1264  $pdf->SetTextColor(0, 0, 0);
1265  $pdf->SetFont('', '', $default_font_size - 2);
1266  $pdf->SetXY($posx + 2, $posy - 5);
1267  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, 'L');
1268  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1269 
1270  // Show recipient name
1271  $pdf->SetXY($posx + 2, $posy + 3);
1272  $pdf->SetFont('', 'B', $default_font_size);
1273  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1274 
1275  $posy = $pdf->getY();
1276 
1277  // Show recipient information
1278  $pdf->SetFont('', '', $default_font_size - 1);
1279  $pdf->SetXY($posx + 2, $posy);
1280  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1281  }
1282 
1283  return $top_shift;
1284  }
1285 
1286  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1296  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1297  {
1298  global $conf;
1299  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1300  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1301  }
1302 }
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:7839
pdf_getlinevatrate
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1784
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:2474
pdf_getlineqty
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1931
pdf_getlineupexcltax
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1846
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:1345
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
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:2135
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:654
pdf_canelle\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_canelle.modules.php:1067
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:2092
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:874
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
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:2514
pdf_canelle\_tableau_versements
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
Definition: pdf_canelle.modules.php:976
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:6549
pdf_canelle\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_canelle.modules.php:1296
pdf_canelle\__construct
__construct($db)
Constructor.
Definition: pdf_canelle.modules.php:126
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:977
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:1309
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:427
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:2711
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:6991
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
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:737
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:5541
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
pdf_getlinetotalexcltax
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2229
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:7961
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:5492
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:989
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:203
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25