dolibarr  18.0.0-alpha
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  $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 (getDolGlobalInt('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((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
236  $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
237  $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $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 (getDolGlobalString('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 = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
346 
347  // Incoterm
348  if (isModEnabled('incoterm')) {
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 (!getDolGlobalInt('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 (getDolGlobalInt('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 (isModEnabled("multicurrency") && $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 (!getDolGlobalInt('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 (!getDolGlobalInt('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  dolChmod($file);
626 
627  $this->result = array('fullpath'=>$file);
628 
629  return 1; // No error
630  } else {
631  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
632  return 0;
633  }
634  } else {
635  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
636  return 0;
637  }
638  }
639 
640  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
641  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
652  protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
653  {
654  // phpcs:enable
655  global $conf, $mysoc;
656 
657  $sign = 1;
658  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
659  $sign = -1;
660  }
661 
662  $default_font_size = pdf_getPDFFontSize($outputlangs);
663 
664  $tab2_top = $posy;
665  $tab2_hl = 4;
666  $pdf->SetFont('', '', $default_font_size - 1);
667 
668  // Total table
669  $col1x = 120;
670  $col2x = 170;
671  if ($this->page_largeur < 210) { // To work with US executive format
672  $col2x -= 20;
673  }
674  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
675 
676  $useborder = 0;
677  $index = 0;
678 
679  // Total HT
680  $pdf->SetFillColor(255, 255, 255);
681  $pdf->SetXY($col1x, $tab2_top);
682  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
683 
684  $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
685  $pdf->SetXY($col2x, $tab2_top);
686  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
687 
688  // Show VAT by rates and total
689  $pdf->SetFillColor(248, 248, 248);
690 
691  $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
692 
693  $this->atleastoneratenotnull = 0;
694  foreach ($this->tva as $tvakey => $tvaval) {
695  if ($tvakey > 0) { // We do not display rate 0
696  $this->atleastoneratenotnull++;
697 
698  $index++;
699  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
700 
701  $tvacompl = '';
702 
703  if (preg_match('/\*/', $tvakey)) {
704  $tvakey = str_replace('*', '', $tvakey);
705  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
706  }
707 
708  $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
709  $totalvat .= vatrate($tvakey, 1).$tvacompl;
710  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
711 
712  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
713  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
714  }
715  }
716  if (!$this->atleastoneratenotnull) { // If no vat at all
717  $index++;
718  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
719  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
720  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
721  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva, 0, $outputlangs), 0, 'R', 1);
722 
723  // Total LocalTax1
724  if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on' && $object->total_localtax1 > 0) {
725  $index++;
726  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
727  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
728  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
729  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1, 0, $outputlangs), 0, 'R', 1);
730  }
731 
732  // Total LocalTax2
733  if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on' && $object->total_localtax2 > 0) {
734  $index++;
735  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
736  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
737  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
738  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2, 0, $outputlangs), 0, 'R', 1);
739  }
740  } else {
741  //if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
742  //{
743  //Local tax 1
744  foreach ($this->localtax1 as $tvakey => $tvaval) {
745  if ($tvakey != 0) { // On affiche pas taux 0
746  //$this->atleastoneratenotnull++;
747 
748  $index++;
749  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
750 
751  $tvacompl = '';
752  if (preg_match('/\*/', $tvakey)) {
753  $tvakey = str_replace('*', '', $tvakey);
754  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
755  }
756  $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
757  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
758  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
759 
760  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
761  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
762  }
763  }
764  //}
765 
766  //if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
767  //{
768  //Local tax 2
769  foreach ($this->localtax2 as $tvakey => $tvaval) {
770  if ($tvakey != 0) { // On affiche pas taux 0
771  //$this->atleastoneratenotnull++;
772 
773  $index++;
774  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
775 
776  $tvacompl = '';
777  if (preg_match('/\*/', $tvakey)) {
778  $tvakey = str_replace('*', '', $tvakey);
779  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
780  }
781  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
782  $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
783  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
784 
785  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
786  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
787  }
788  }
789  //}
790  }
791 
792  // Total TTC
793  $index++;
794  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
795  $pdf->SetTextColor(0, 0, 60);
796  $pdf->SetFillColor(224, 224, 224);
797  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
798 
799  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
800  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
801 
802  $pdf->SetTextColor(0, 0, 0);
803  $creditnoteamount = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
804  $depositsamount = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
805  //print "x".$creditnoteamount."-".$depositsamount;exit;
806  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
807  if (!empty($object->paye)) {
808  $resteapayer = 0;
809  }
810 
811  if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
812  // Already paid + Deposits
813  $index++;
814  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
815  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
816  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
817  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
818 
819  // Credit note
820  if ($creditnoteamount) {
821  $labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
822  $index++;
823  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
824  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
825  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
826  $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
827  }
828 
829  // Escompte
830  if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
831  $index++;
832  $pdf->SetFillColor(255, 255, 255);
833 
834  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
835  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
836  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
837  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
838 
839  $resteapayer = 0;
840  }
841 
842  $index++;
843  $pdf->SetTextColor(0, 0, 60);
844  $pdf->SetFillColor(224, 224, 224);
845  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
846  $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
847 
848  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
849  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
850  $pdf->SetFont('', '', $default_font_size - 1);
851  $pdf->SetTextColor(0, 0, 0);
852  }
853 
854  $index++;
855  return ($tab2_top + ($tab2_hl * $index));
856  }
857 
858  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
872  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
873  {
874  global $conf;
875 
876  // Force to disable hidetop and hidebottom
877  $hidebottom = 0;
878  if ($hidetop) {
879  $hidetop = -1;
880  }
881 
882  $currency = !empty($currency) ? $currency : $conf->currency;
883  $default_font_size = pdf_getPDFFontSize($outputlangs);
884 
885  // Amount in (at tab_top - 1)
886  $pdf->SetTextColor(0, 0, 0);
887  $pdf->SetFont('', '', $default_font_size - 2);
888 
889  if (empty($hidetop)) {
890  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
891  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
892  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
893 
894  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
895  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
896  $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));
897  }
898  }
899 
900  $pdf->SetDrawColor(128, 128, 128);
901  $pdf->SetFont('', '', $default_font_size - 1);
902 
903  // Output Rect
904  $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
905 
906  if (empty($hidetop)) {
907  $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
908 
909  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
910  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
911  }
912 
913  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
914  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
915  if (empty($hidetop)) {
916  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
917  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
918  }
919  }
920 
921  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
922  if (empty($hidetop)) {
923  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
924  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
925  }
926 
927  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
928  if (empty($hidetop)) {
929  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
930  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
931  }
932 
933  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
934  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
935  if (empty($hidetop)) {
936  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
937  $pdf->MultiCell(
938  $this->posxdiscount - $this->posxunit - 1,
939  2,
940  $outputlangs->transnoentities("Unit"),
941  '',
942  'C'
943  );
944  }
945  }
946 
947  if ($this->atleastonediscount) {
948  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
949  if (empty($hidetop)) {
950  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
951  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
952  }
953  }
954 
955  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
956  if (empty($hidetop)) {
957  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
958  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
959  }
960  }
961 
962  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
963  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
974  protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0)
975  {
976  // phpcs:enable
977  global $conf;
978 
979  $sign = 1;
980  if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
981  $sign = -1;
982  }
983 
984  $tab3_posx = 120;
985  $tab3_top = $posy + 8;
986  $tab3_width = 80;
987  $tab3_height = 4;
988  if ($this->page_largeur < 210) { // To work with US executive format
989  $tab3_posx -= 20;
990  }
991 
992  $default_font_size = pdf_getPDFFontSize($outputlangs);
993 
994  $pdf->SetFont('', '', $default_font_size - 3);
995  $pdf->SetXY($tab3_posx, $tab3_top - 4);
996  $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0);
997 
998  $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
999 
1000  $pdf->SetFont('', '', $default_font_size - 4);
1001  $pdf->SetXY($tab3_posx, $tab3_top);
1002  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
1003  $pdf->SetXY($tab3_posx + 21, $tab3_top);
1004  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
1005  $pdf->SetXY($tab3_posx + 40, $tab3_top);
1006  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1007  $pdf->SetXY($tab3_posx + 58, $tab3_top);
1008  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
1009 
1010  $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1011 
1012  $y = 0;
1013 
1014  $pdf->SetFont('', '', $default_font_size - 4);
1015 
1016  // Loop on each deposits and credit notes included
1017  //
1018 
1019  // Loop on each payment
1020  $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1021  $sql .= " cp.code";
1022  $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
1023  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
1024  $sql .= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
1025  $sql .= " ORDER BY p.datep";
1026  $resql = $this->db->query($sql);
1027  if ($resql) {
1028  $num = $this->db->num_rows($resql);
1029  $i = 0;
1030  while ($i < $num) {
1031  $y += 3;
1032  $row = $this->db->fetch_object($resql);
1033 
1034  $pdf->SetXY($tab3_posx, $tab3_top + $y);
1035  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0);
1036  $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1037  $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0, 'L', 0);
1038  $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1039  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->code);
1040 
1041  $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1042  $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1043  $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1044 
1045  $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1046 
1047  $i++;
1048  }
1049  } else {
1050  $this->error = $this->db->lasterror();
1051  return -1;
1052  }
1053  }
1054 
1055  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1065  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1066  {
1067  global $langs, $conf, $mysoc;
1068 
1069  // Load translation files required by the page
1070  $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
1071 
1072  $default_font_size = pdf_getPDFFontSize($outputlangs);
1073 
1074  // Do not add the BACKGROUND as this is for suppliers
1075  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1076 
1077  $pdf->SetTextColor(0, 0, 60);
1078  $pdf->SetFont('', 'B', $default_font_size + 3);
1079 
1080  $posy = $this->marge_haute;
1081  $posx = $this->page_largeur - $this->marge_droite - 100;
1082 
1083  $pdf->SetXY($this->marge_gauche, $posy);
1084 
1085  // Logo
1086  /*
1087  $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1088  if ($mysoc->logo)
1089  {
1090  if (is_readable($logo))
1091  {
1092  $height=pdf_getHeightForLogo($logo);
1093  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1094  }
1095  else
1096  {
1097  $pdf->SetTextColor(200,0,0);
1098  $pdf->SetFont('','B', $default_font_size - 2);
1099  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1100  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1101  }
1102  }
1103  else
1104  {*/
1105  $text = $this->emetteur->name;
1106  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1107  //}
1108 
1109  $pdf->SetFont('', 'B', $default_font_size + 3);
1110  $pdf->SetXY($posx, $posy);
1111  $pdf->SetTextColor(0, 0, 60);
1112  $title = $outputlangs->transnoentities("PdfInvoiceTitle");
1113  if ($object->type == 1) {
1114  $title = $outputlangs->transnoentities("InvoiceReplacement");
1115  }
1116  if ($object->type == 2) {
1117  $title = $outputlangs->transnoentities("InvoiceAvoir");
1118  }
1119  if ($object->type == 3) {
1120  $title = $outputlangs->transnoentities("InvoiceDeposit");
1121  }
1122  $pdf->MultiCell(100, 3, $title." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1123  $posy += 1;
1124 
1125  if ($object->ref_supplier) {
1126  $posy += 4;
1127  $pdf->SetFont('', 'B', $default_font_size);
1128  $pdf->SetXY($posx, $posy);
1129  $pdf->SetTextColor(0, 0, 60);
1130  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : ".$object->ref_supplier, '', 'R');
1131  $posy += 1;
1132  }
1133 
1134  $pdf->SetFont('', '', $default_font_size - 1);
1135 
1136  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1137  $object->fetch_projet();
1138  if (!empty($object->project->ref)) {
1139  $posy += 3;
1140  $pdf->SetXY($posx, $posy);
1141  $pdf->SetTextColor(0, 0, 60);
1142  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1143  }
1144  }
1145 
1146  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1147  $object->fetch_projet();
1148  if (!empty($object->project->ref)) {
1149  $outputlangs->load("projects");
1150  $posy += 4;
1151  $pdf->SetXY($posx, $posy);
1152  $langs->load("projects");
1153  $pdf->SetTextColor(0, 0, 60);
1154  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1155  }
1156  }
1157 
1158  if ($object->date) {
1159  $posy += 4;
1160  $pdf->SetXY($posx, $posy);
1161  $pdf->SetTextColor(0, 0, 60);
1162  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
1163  } else {
1164  $posy += 4;
1165  $pdf->SetXY($posx, $posy);
1166  $pdf->SetTextColor(255, 0, 0);
1167  $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
1168  }
1169 
1170  if ($object->thirdparty->code_fournisseur) {
1171  $posy += 4;
1172  $pdf->SetXY($posx, $posy);
1173  $pdf->SetTextColor(0, 0, 60);
1174  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1175  }
1176 
1177  $posy += 1;
1178  $pdf->SetTextColor(0, 0, 60);
1179 
1180  $top_shift = 0;
1181  // Show list of linked objects
1182  $current_y = $pdf->getY();
1183  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1184  if ($current_y < $pdf->getY()) {
1185  $top_shift = $pdf->getY() - $current_y;
1186  }
1187 
1188  if ($showaddress) {
1189  // Sender properties
1190  $carac_emetteur = '';
1191  // Add internal contact of proposal if defined
1192  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1193  if (count($arrayidcontact) > 0) {
1194  $object->fetch_user($arrayidcontact[0]);
1195  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1196  }
1197 
1198  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1199 
1200  // Show sender
1201  $posy = 42 + $top_shift;
1202  $posx = $this->marge_gauche;
1203  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1204  $posx = $this->page_largeur - $this->marge_droite - 80;
1205  }
1206  $hautcadre = 40;
1207 
1208  // Show sender frame
1209  $pdf->SetTextColor(0, 0, 0);
1210  $pdf->SetFont('', '', $default_font_size - 2);
1211  $pdf->SetXY($posx, $posy - 5);
1212  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
1213  $pdf->SetXY($posx, $posy);
1214  $pdf->SetFillColor(230, 230, 230);
1215  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1216  $pdf->SetTextColor(0, 0, 60);
1217 
1218  // Show sender name
1219  $pdf->SetXY($posx + 2, $posy + 3);
1220  $pdf->SetFont('', 'B', $default_font_size);
1221  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1222  $posy = $pdf->getY();
1223 
1224  // Show sender information
1225  $pdf->SetXY($posx + 2, $posy);
1226  $pdf->SetFont('', '', $default_font_size - 1);
1227  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1228 
1229 
1230 
1231  // If BILLING contact defined on invoice, we use it
1232  $usecontact = false;
1233  $arrayidcontact = $object->getIdContact('internal', 'BILLING');
1234  if (count($arrayidcontact) > 0) {
1235  $usecontact = true;
1236  $result = $object->fetch_contact($arrayidcontact[0]);
1237  }
1238 
1239  // Recipient name
1240  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)))) {
1241  $thirdparty = $object->contact;
1242  } else {
1243  $thirdparty = $mysoc;
1244  }
1245 
1246  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1247 
1248  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
1249 
1250  // Show recipient
1251  $widthrecbox = 100;
1252  if ($this->page_largeur < 210) {
1253  $widthrecbox = 84; // To work with US executive format
1254  }
1255  $posy = 42 + $top_shift;
1256  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1257  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1258  $posx = $this->marge_gauche;
1259  }
1260 
1261  // Show recipient frame
1262  $pdf->SetTextColor(0, 0, 0);
1263  $pdf->SetFont('', '', $default_font_size - 2);
1264  $pdf->SetXY($posx + 2, $posy - 5);
1265  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, 'L');
1266  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1267 
1268  // Show recipient name
1269  $pdf->SetXY($posx + 2, $posy + 3);
1270  $pdf->SetFont('', 'B', $default_font_size);
1271  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1272 
1273  $posy = $pdf->getY();
1274 
1275  // Show recipient information
1276  $pdf->SetFont('', '', $default_font_size - 1);
1277  $pdf->SetXY($posx + 2, $posy);
1278  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1279  }
1280 
1281  return $top_shift;
1282  }
1283 
1284  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1294  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1295  {
1296  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1297  return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1298  }
1299 }
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:8210
pdf_getlinevatrate
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1815
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:2505
pdf_getlineqty
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1962
pdf_getlineupexcltax
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1877
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:1354
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1236
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:2166
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:652
pdf_canelle\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_canelle.modules.php:1065
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
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:2123
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:872
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
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:2566
pdf_canelle\_tableau_versements
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
Definition: pdf_canelle.modules.php:974
dolChmod
dolChmod($filepath, $newmask='')
Change mod of a file.
Definition: functions.lib.php:6882
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:6757
pdf_canelle\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_canelle.modules.php:1294
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:1010
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:1318
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:2723
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:147
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:7325
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:744
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:5708
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6811
pdf_getlinetotalexcltax
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:2260
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:8333
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:5659
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:996
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