dolibarr  9.0.0
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 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 <http://www.gnu.org/licenses/>.
19  * or see http://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/pdf.lib.php';
33 
34 
39 {
43  public $db;
44 
48  public $name;
49 
53  public $description;
54 
58  public $type;
59 
64  public $phpmin = array(5, 4);
65 
70  public $version = 'dolibarr';
71 
75  public $page_largeur;
76 
80  public $page_hauteur;
81 
85  public $format;
86 
90  public $marge_gauche;
91 
95  public $marge_droite;
96 
100  public $marge_haute;
101 
105  public $marge_basse;
106 
111  public $emetteur;
112 
113 
114 
120  function __construct($db)
121  {
122  global $conf, $langs, $mysoc;
123 
124  // Load translation files required by the page
125  $langs->loadLangs(array("main", "bills"));
126 
127  $this->db = $db;
128  $this->name = "canelle";
129  $this->description = $langs->trans('SuppliersInvoiceModel');
130 
131  // Dimension page pour format A4
132  $this->type = 'pdf';
133  $formatarray=pdf_getFormat();
134  $this->page_largeur = $formatarray['width'];
135  $this->page_hauteur = $formatarray['height'];
136  $this->format = array($this->page_largeur,$this->page_hauteur);
137  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
138  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
139  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
140  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
141 
142  $this->option_logo = 1; // Affiche logo
143  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
144  $this->option_modereg = 1; // Affiche mode reglement
145  $this->option_condreg = 1; // Affiche conditions reglement
146  $this->option_codeproduitservice = 1; // Affiche code produit-service
147  $this->option_multilang = 1; // Dispo en plusieurs langues
148 
149  $this->franchise=!$mysoc->tva_assuj;
150 
151  // Defini position des colonnes
152  $this->posxdesc=$this->marge_gauche+1;
153  $this->posxtva=112;
154  $this->posxup=126;
155  $this->posxqty=145;
156  $this->posxdiscount=162;
157  $this->postotalht=174;
158 
159  if($conf->global->PRODUCT_USE_UNITS) {
160  $this->posxtva=99;
161  $this->posxup=114;
162  $this->posxqty=130;
163  $this->posxunit=147;
164  }
165  //if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
166  $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
167  if ($this->page_largeur < 210) // To work with US executive format
168  {
169  $this->posxpicture-=20;
170  $this->posxtva-=20;
171  $this->posxup-=20;
172  $this->posxqty-=20;
173  $this->posxunit-=20;
174  $this->posxdiscount-=20;
175  $this->postotalht-=20;
176  }
177 
178  $this->tva=array();
179  $this->localtax1=array();
180  $this->localtax2=array();
181  $this->atleastoneratenotnull=0;
182  $this->atleastonediscount=0;
183  }
184 
185 
186  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
198  function write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
199  {
200  // phpcs:enable
201  global $user,$langs,$conf,$mysoc,$hookmanager,$nblignes;
202 
203  // Get source company
204  if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
205  if (! is_object($object->thirdparty)) $object->thirdparty=$mysoc; // If fetch_thirdparty fails, object has no socid (specimen)
206  $this->emetteur=$object->thirdparty;
207  if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
208 
209  if (! is_object($outputlangs)) $outputlangs=$langs;
210  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
211  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
212 
213  // Load translation files required by the page
214  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products"));
215 
216  if ($conf->fournisseur->facture->dir_output)
217  {
218  $object->fetch_thirdparty();
219 
220  $deja_regle = $object->getSommePaiement();
221  //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
222  //$amount_deposits_included = $object->getSumDepositsUsed();
223 
224  // Definition of $dir and $file
225  if ($object->specimen)
226  {
227  $dir = $conf->fournisseur->facture->dir_output;
228  $file = $dir . "/SPECIMEN.pdf";
229  }
230  else
231  {
232  $objectref = dol_sanitizeFileName($object->ref);
233  $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
234  $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$objectref;
235  $file = $dir . "/" . $objectref . ".pdf";
236  if (! empty($conf->global->SUPPLIER_REF_IN_NAME)) $file = $dir . "/" . $objectref . ($objectrefsupplier?"_".$objectrefsupplier:"").".pdf";
237  }
238 
239  if (! file_exists($dir))
240  {
241  if (dol_mkdir($dir) < 0)
242  {
243  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
244  return 0;
245  }
246  }
247 
248  if (file_exists($dir))
249  {
250  // Add pdfgeneration hook
251  if (! is_object($hookmanager))
252  {
253  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
254  $hookmanager=new HookManager($this->db);
255  }
256  $hookmanager->initHooks(array('pdfgeneration'));
257  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
258  global $action;
259  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
260 
261  $nblignes = count($object->lines);
262 
263  $pdf=pdf_getInstance($this->format);
264  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
265  $heightforinfotot = 50; // Height reserved to output the info and total part
266  $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
267  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
268  if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
269  $pdf->SetAutoPageBreak(1,0);
270 
271  if (class_exists('TCPDF'))
272  {
273  $pdf->setPrintHeader(false);
274  $pdf->setPrintFooter(false);
275  }
276  $pdf->SetFont(pdf_getPDFFont($outputlangs));
277  // Set path to the background PDF File
278  if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
279  {
280  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
281  $tplidx = $pdf->importPage(1);
282  }
283 
284  $pdf->Open();
285  $pagenb=0;
286  $pdf->SetDrawColor(128,128,128);
287 
288  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
289  $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
290  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
291  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
292  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
293  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
294 
295  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
296 
297  // Positionne $this->atleastonediscount si on a au moins une remise
298  for ($i = 0 ; $i < $nblignes ; $i++)
299  {
300  if ($object->lines[$i]->remise_percent)
301  {
302  $this->atleastonediscount++;
303  }
304  }
305  if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
306  {
307  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
308  $this->posxtva+=($this->postotalht - $this->posxdiscount);
309  $this->posxup+=($this->postotalht - $this->posxdiscount);
310  $this->posxqty+=($this->postotalht - $this->posxdiscount);
311  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
312  //$this->postotalht;
313  }
314 
315  // New page
316  $pdf->AddPage();
317  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
318  $pagenb++;
319  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
320  $pdf->SetFont('','', $default_font_size - 1);
321  $pdf->MultiCell(0, 3, ''); // Set interline to 3
322  $pdf->SetTextColor(0,0,0);
323 
324  $tab_top = 90+$top_shift;
325  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
326 
327  // Incoterm
328  if ($conf->incoterm->enabled)
329  {
330  $desc_incoterms = $object->getIncotermsForPDF();
331  if ($desc_incoterms)
332  {
333  $tab_top -= 2;
334 
335  $pdf->SetFont('','', $default_font_size - 1);
336  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
337  $nexY = $pdf->GetY();
338  $height_incoterms=$nexY-$tab_top;
339 
340  // Rect prend une longueur en 3eme param
341  $pdf->SetDrawColor(192,192,192);
342  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
343 
344  $tab_top = $nexY+6;
345  }
346  }
347 
348  // Affiche notes
349  if (! empty($object->note_public))
350  {
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($object->note_public), 0, 1);
355  $nexY = $pdf->GetY();
356  $height_note=$nexY-$tab_top;
357 
358  // Rect prend une longueur en 3eme param
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_note+1);
361 
362  $tab_top = $nexY+6;
363  }
364 
365  $iniY = $tab_top + 7;
366  $curY = $tab_top + 7;
367  $nexY = $tab_top + 7;
368 
369  // Loop on each lines
370  for ($i = 0 ; $i < $nblignes ; $i++)
371  {
372  $curY = $nexY;
373  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
374  $pdf->SetTextColor(0,0,0);
375 
376  $pdf->setTopMargin($tab_top_newpage);
377  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
378  $pageposbefore=$pdf->getPage();
379 
380  // Description of product line
381  $curX = $this->posxdesc-1;
382  $showpricebeforepagebreak=1;
383 
384  $pdf->startTransaction();
385  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,1);
386  $pageposafter=$pdf->getPage();
387  if ($pageposafter > $pageposbefore) // There is a pagebreak
388  {
389  $pdf->rollbackTransaction(true);
390  $pageposafter=$pageposbefore;
391  //print $pageposafter.'-'.$pageposbefore;exit;
392  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
393  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,1);
394  $posyafter=$pdf->GetY();
395  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
396  {
397  if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
398  {
399  $pdf->AddPage('','',true);
400  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
401  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
402  $pdf->setPage($pageposafter+1);
403  }
404  }
405  else
406  {
407  // We found a page break
408  $showpricebeforepagebreak=0;
409  }
410  }
411  else // No pagebreak
412  {
413  $pdf->commitTransaction();
414  }
415 
416  $nexY = $pdf->GetY();
417  $pageposafter=$pdf->getPage();
418  $pdf->setPage($pageposbefore);
419  $pdf->setTopMargin($this->marge_haute);
420  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
421 
422  // We suppose that a too long description is moved completely on next page
423  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
424  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
425  }
426 
427  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
428 
429  // VAT Rate
430  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
431  {
432  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
433  $pdf->SetXY($this->posxtva, $curY);
434  $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
435  }
436 
437  // Unit price before discount
438  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
439  $pdf->SetXY($this->posxup, $curY);
440  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
441 
442  // Unit price before discount
443  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
444  $pdf->SetXY($this->posxup, $curY);
445  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
446 
447  // Quantity
448  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
449  $pdf->SetXY($this->posxqty, $curY);
450  // Enough for 6 chars
451  if($conf->global->PRODUCT_USE_UNITS)
452  {
453  $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
454  }
455  else
456  {
457  $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
458  }
459 
460  // Unit
461  if($conf->global->PRODUCT_USE_UNITS)
462  {
463  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
464  $pdf->SetXY($this->posxunit, $curY);
465  $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
466  }
467 
468  // Discount on line
469  $pdf->SetXY($this->posxdiscount, $curY);
470  if ($object->lines[$i]->remise_percent)
471  {
472  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
473  $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $remise_percent."%", 0, 'R');
474  }
475 
476  // Total HT line
477  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs);
478  $pdf->SetXY($this->postotalht, $curY);
479  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
480 
481  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
482  if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
483  else $tvaligne=$object->lines[$i]->total_tva;
484 
485  $localtax1ligne=$object->lines[$i]->total_localtax1;
486  $localtax2ligne=$object->lines[$i]->total_localtax2;
487 
488  if (! empty($object->remise_percent)) $tvaligne-=($tvaligne*$object->remise_percent)/100;
489 
490  $vatrate=(string) $object->lines[$i]->tva_tx;
491  $localtax1rate=(string) $object->lines[$i]->localtax1_tx;
492  $localtax2rate=(string) $object->lines[$i]->localtax2_tx;
493 
494  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
495  if (empty($this->tva[$vatrate])) $this->tva[$vatrate]=0;
496  if (empty($this->localtax1[$localtax1rate])) $this->localtax1[$localtax1rate]=0;
497  if (empty($this->localtax2[$localtax2rate])) $this->localtax2[$localtax2rate]=0;
498  $this->tva[$vatrate] += $tvaligne;
499  $this->localtax1[$localtax1rate]+=$localtax1ligne;
500  $this->localtax2[$localtax2rate]+=$localtax2ligne;
501 
502  // Add line
503  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
504  {
505  $pdf->setPage($pageposafter);
506  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
507  //$pdf->SetDrawColor(190,190,200);
508  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
509  $pdf->SetLineStyle(array('dash'=>0));
510  }
511 
512  $nexY+=2; // Passe espace entre les lignes
513 
514  // Detect if some page were added automatically and output _tableau for past pages
515  while ($pagenb < $pageposafter)
516  {
517  $pdf->setPage($pagenb);
518  if ($pagenb == 1)
519  {
520  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
521  }
522  else
523  {
524  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
525  }
526  $this->_pagefoot($pdf,$object,$outputlangs,1);
527  $pagenb++;
528  $pdf->setPage($pagenb);
529  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
530  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
531  }
532  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
533  {
534  if ($pagenb == 1)
535  {
536  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
537  }
538  else
539  {
540  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
541  }
542  $this->_pagefoot($pdf,$object,$outputlangs,1);
543  // New page
544  $pdf->AddPage();
545  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
546  $pagenb++;
547  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
548  }
549  }
550 
551  // Show square
552  if ($pagenb == 1)
553  {
554  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
555  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
556  }
557  else
558  {
559  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
560  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
561  }
562 
563  // Affiche zone totaux
564  $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
565 
566  $amount_credit_notes_included=0;
567  $amount_deposits_included=0;
568 
569  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
570  {
571  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
572  }
573 
574  // Pied de page
575  $this->_pagefoot($pdf, $object, $outputlangs);
576  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
577 
578  $pdf->Close();
579 
580  $pdf->Output($file,'F');
581 
582  // Add pdfgeneration hook
583  $hookmanager->initHooks(array('pdfgeneration'));
584  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
585  global $action;
586  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
587 
588  if (! empty($conf->global->MAIN_UMASK))
589  @chmod($file, octdec($conf->global->MAIN_UMASK));
590 
591  $this->result = array('fullpath'=>$file);
592 
593  return 1; // Pas d'erreur
594  }
595  else
596  {
597  $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
598  return 0;
599  }
600  }
601  else
602  {
603  $this->error=$langs->trans("ErrorConstantNotDefined","SUPPLIER_OUTPUTDIR");
604  return 0;
605  }
606  }
607 
608  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
619  function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
620  {
621  // phpcs:enable
622  global $conf,$mysoc;
623 
624  $default_font_size = pdf_getPDFFontSize($outputlangs);
625 
626  $tab2_top = $posy;
627  $tab2_hl = 4;
628  $pdf->SetFont('','', $default_font_size - 1);
629 
630  $pdf->SetXY($this->marge_gauche, $tab2_top + 0);
631  // If France, show VAT mention if not applicable
632  if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
633  {
634  $pdf->MultiCell(100, $tab2_hl, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
635  }
636 
637  // Tableau total
638  $col1x = 120; $col2x = 170;
639  if ($this->page_largeur < 210) // To work with US executive format
640  {
641  $col2x-=20;
642  }
643  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
644 
645  $index=0;
646 
647  // Total HT
648  $pdf->SetFillColor(255,255,255);
649  $pdf->SetXY($col1x, $tab2_top + 0);
650  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
651 
652  $total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
653  $pdf->SetXY($col2x, $tab2_top + 0);
654  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + $object->remise), 0, 'R', 1);
655 
656  // Show VAT by rates and total
657  $pdf->SetFillColor(248,248,248);
658 
659  foreach( $this->tva as $tvakey => $tvaval )
660  {
661  if ($tvakey > 0) // On affiche pas taux 0
662  {
663  $this->atleastoneratenotnull++;
664 
665  $index++;
666  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
667 
668  $tvacompl='';
669 
670  if (preg_match('/\*/',$tvakey))
671  {
672  $tvakey=str_replace('*','',$tvakey);
673  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
674  }
675 
676  $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
677  $totalvat.=vatrate($tvakey,1).$tvacompl;
678  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
679 
680  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
681  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
682  }
683  }
684  if (! $this->atleastoneratenotnull) // If no vat at all
685  {
686  $index++;
687  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
688  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
689  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
690  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
691 
692  // Total LocalTax1
693  if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
694  {
695  $index++;
696  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
697  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code), 0, 'L', 1);
698  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
699  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), 0, 'R', 1);
700  }
701 
702  // Total LocalTax2
703  if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
704  {
705  $index++;
706  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
707  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code), 0, 'L', 1);
708  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
709  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), 0, 'R', 1);
710  }
711  }
712  else
713  {
714  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
715  //{
716  //Local tax 1
717  foreach( $this->localtax1 as $tvakey => $tvaval )
718  {
719  if ($tvakey != 0) // On affiche pas taux 0
720  {
721  //$this->atleastoneratenotnull++;
722 
723  $index++;
724  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
725 
726  $tvacompl='';
727  if (preg_match('/\*/',$tvakey))
728  {
729  $tvakey=str_replace('*','',$tvakey);
730  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
731  }
732  $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
733  $totalvat.= vatrate(abs($tvakey),1).$tvacompl;
734  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
735 
736  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
737  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
738  }
739  }
740  //}
741 
742  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
743  //{
744  //Local tax 2
745  foreach( $this->localtax2 as $tvakey => $tvaval )
746  {
747  if ($tvakey != 0) // On affiche pas taux 0
748  {
749  //$this->atleastoneratenotnull++;
750 
751  $index++;
752  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
753 
754  $tvacompl='';
755  if (preg_match('/\*/',$tvakey))
756  {
757  $tvakey=str_replace('*','',$tvakey);
758  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
759  }
760  $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
761  $totalvat.= vatrate(abs($tvakey),1).$tvacompl;
762  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
763 
764  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
765  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
766  }
767  }
768  //}
769  }
770 
771  $useborder=0;
772 
773  // Total TTC
774  $index++;
775  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
776  $pdf->SetTextColor(0,0,60);
777  $pdf->SetFillColor(224,224,224);
778  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
779 
780  $total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
781  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
782  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
783 
784  $creditnoteamount=0;
785  $depositsamount=0;
786  //$creditnoteamount=$object->getSumCreditNotesUsed();
787  //$depositsamount=$object->getSumDepositsUsed();
788  //print "x".$creditnoteamount."-".$depositsamount;exit;
789  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
790  if (! empty($object->paye)) $resteapayer=0;
791 
792  if ($deja_regle > 0)
793  {
794  $index++;
795 
796  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
797  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
798 
799  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
800  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
801 
802  $index++;
803  $pdf->SetTextColor(0,0,60);
804  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
805  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
806 
807  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
808  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
809  $pdf->SetFont('','', $default_font_size - 1);
810  $pdf->SetTextColor(0,0,0);
811  }
812 
813  $index++;
814  return ($tab2_top + ($tab2_hl * $index));
815  }
816 
830  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
831  {
832  global $conf;
833 
834  // Force to disable hidetop and hidebottom
835  $hidebottom=0;
836  if ($hidetop) $hidetop=-1;
837 
838  $currency = !empty($currency) ? $currency : $conf->currency;
839  $default_font_size = pdf_getPDFFontSize($outputlangs);
840 
841  // Amount in (at tab_top - 1)
842  $pdf->SetTextColor(0,0,0);
843  $pdf->SetFont('','',$default_font_size - 2);
844 
845  if (empty($hidetop))
846  {
847  $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
848  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
849  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
850 
851  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
852  if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $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));
853  }
854 
855  $pdf->SetDrawColor(128,128,128);
856  $pdf->SetFont('','', $default_font_size - 1);
857 
858  // Output Rect
859  $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param
860 
861  if (empty($hidetop))
862  {
863  $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); // line prend une position y en 2eme param et 4eme param
864 
865  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
866  $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
867  }
868 
869  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
870  {
871  $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
872  if (empty($hidetop))
873  {
874  $pdf->SetXY($this->posxtva-3, $tab_top+1);
875  $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
876  }
877  }
878 
879  $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
880  if (empty($hidetop))
881  {
882  $pdf->SetXY($this->posxup-1, $tab_top+1);
883  $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
884  }
885 
886  $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
887  if (empty($hidetop))
888  {
889  $pdf->SetXY($this->posxqty-1, $tab_top+1);
890  if($conf->global->PRODUCT_USE_UNITS)
891  {
892  $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
893  }
894  else
895  {
896  $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
897  }
898  }
899 
900  if($conf->global->PRODUCT_USE_UNITS) {
901  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
902  if (empty($hidetop)) {
903  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
904  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
905  'C');
906  }
907  }
908 
909  $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
910  if (empty($hidetop))
911  {
912  if ($this->atleastonediscount)
913  {
914  $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
915  $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
916  }
917  }
918 
919  if ($this->atleastonediscount)
920  {
921  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
922  }
923  if (empty($hidetop))
924  {
925  $pdf->SetXY($this->postotalht-1, $tab_top+1);
926  $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHTShort"),'','C');
927  }
928  }
929 
930  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
940  function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
941  {
942  // phpcs:enable
943  global $conf;
944 
945  $sign=1;
946  if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
947 
948  $tab3_posx = 120;
949  $tab3_top = $posy + 8;
950  $tab3_width = 80;
951  $tab3_height = 4;
952  if ($this->page_largeur < 210) // To work with US executive format
953  {
954  $tab3_posx -= 20;
955  }
956 
957  $default_font_size = pdf_getPDFFontSize($outputlangs);
958 
959  $pdf->SetFont('','', $default_font_size - 3);
960  $pdf->SetXY($tab3_posx, $tab3_top - 4);
961  $pdf->MultiCell(60, 3, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0);
962 
963  $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
964 
965  $pdf->SetFont('','', $default_font_size - 4);
966  $pdf->SetXY($tab3_posx, $tab3_top);
967  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
968  $pdf->SetXY($tab3_posx+21, $tab3_top);
969  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
970  $pdf->SetXY($tab3_posx+40, $tab3_top);
971  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
972  $pdf->SetXY($tab3_posx+58, $tab3_top);
973  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
974 
975  $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
976 
977  $y=0;
978 
979  $pdf->SetFont('','', $default_font_size - 4);
980 
981  // Loop on each deposits and credit notes included
982  //
983 
984  // Loop on each payment
985  $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
986  $sql.= " cp.code";
987  $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
988  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
989  $sql.= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".$object->id;
990  $sql.= " ORDER BY p.datep";
991  $resql=$this->db->query($sql);
992  if ($resql)
993  {
994  $num = $this->db->num_rows($resql);
995  $i=0;
996  while ($i < $num) {
997  $y+=3;
998  $row = $this->db->fetch_object($resql);
999 
1000  $pdf->SetXY($tab3_posx, $tab3_top+$y);
1001  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
1002  $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
1003  $pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0, 'L', 0);
1004  $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
1005  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
1006 
1007  $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
1008  $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
1009  $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
1010 
1011  $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
1012 
1013  $i++;
1014  }
1015  }
1016  else
1017  {
1018  $this->error=$this->db->lasterror();
1019  return -1;
1020  }
1021  }
1022 
1032  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1033  {
1034  global $langs, $conf, $mysoc;
1035 
1036  // Load translation files required by the page
1037  $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
1038 
1039  $default_font_size = pdf_getPDFFontSize($outputlangs);
1040 
1041  // Do not add the BACKGROUND as this is for suppliers
1042  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1043 
1044  $pdf->SetTextColor(0,0,60);
1045  $pdf->SetFont('','B', $default_font_size + 3);
1046 
1047  $posy=$this->marge_haute;
1048  $posx=$this->page_largeur-$this->marge_droite-100;
1049 
1050  $pdf->SetXY($this->marge_gauche,$posy);
1051 
1052  // Logo
1053  /*
1054  $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1055  if ($mysoc->logo)
1056  {
1057  if (is_readable($logo))
1058  {
1059  $height=pdf_getHeightForLogo($logo);
1060  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1061  }
1062  else
1063  {
1064  $pdf->SetTextColor(200,0,0);
1065  $pdf->SetFont('','B', $default_font_size - 2);
1066  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1067  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1068  }
1069  }
1070  else
1071  {*/
1072  $text=$this->emetteur->name;
1073  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1074  //}
1075 
1076  $pdf->SetFont('','B', $default_font_size + 3);
1077  $pdf->SetXY($posx,$posy);
1078  $pdf->SetTextColor(0,0,60);
1079  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierInvoice")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
1080  $posy+=1;
1081 
1082  if ($object->ref_supplier)
1083  {
1084  $posy+=4;
1085  $pdf->SetFont('','B', $default_font_size);
1086  $pdf->SetXY($posx,$posy);
1087  $pdf->SetTextColor(0,0,60);
1088  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : " . $object->ref_supplier, '', 'R');
1089  $posy+=1;
1090  }
1091 
1092  $pdf->SetFont('','', $default_font_size - 1);
1093 
1094  if (! empty($conf->global->PDF_SHOW_PROJECT))
1095  {
1096  $object->fetch_projet();
1097  if (! empty($object->project->ref))
1098  {
1099  $posy+=4;
1100  $pdf->SetXY($posx,$posy);
1101  $langs->load("projects");
1102  $pdf->SetTextColor(0,0,60);
1103  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->projet->ref), '', 'R');
1104  }
1105  }
1106 
1107  if ($object->date)
1108  {
1109  $posy+=4;
1110  $pdf->SetXY($posx,$posy);
1111  $pdf->SetTextColor(0,0,60);
1112  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
1113  }
1114  else
1115  {
1116  $posy+=4;
1117  $pdf->SetXY($posx,$posy);
1118  $pdf->SetTextColor(255,0,0);
1119  $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
1120  }
1121 
1122  if ($object->thirdparty->code_fournisseur)
1123  {
1124  $posy+=4;
1125  $pdf->SetXY($posx,$posy);
1126  $pdf->SetTextColor(0,0,60);
1127  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1128  }
1129 
1130  $posy+=1;
1131  $pdf->SetTextColor(0,0,60);
1132 
1133  $top_shift = 0;
1134  // Show list of linked objects
1135  $current_y = $pdf->getY();
1136  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1137  if ($current_y < $pdf->getY())
1138  {
1139  $top_shift = $pdf->getY() - $current_y;
1140  }
1141 
1142  if ($showaddress)
1143  {
1144  // Sender properties
1145  $carac_emetteur='';
1146  // Add internal contact of proposal if defined
1147  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1148  if (count($arrayidcontact) > 0)
1149  {
1150  $object->fetch_user($arrayidcontact[0]);
1151  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1152  }
1153 
1154  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1155 
1156  // Show sender
1157  $posy=42+$top_shift;
1158  $posx=$this->marge_gauche;
1159  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1160  $hautcadre=40;
1161 
1162  // Show sender frame
1163  $pdf->SetTextColor(0,0,0);
1164  $pdf->SetFont('','', $default_font_size - 2);
1165  $pdf->SetXY($posx,$posy-5);
1166  $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1167  $pdf->SetXY($posx,$posy);
1168  $pdf->SetFillColor(230,230,230);
1169  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1170  $pdf->SetTextColor(0,0,60);
1171 
1172  // Show sender name
1173  $pdf->SetXY($posx+2,$posy+3);
1174  $pdf->SetFont('','B', $default_font_size);
1175  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1176  $posy=$pdf->getY();
1177 
1178  // Show sender information
1179  $pdf->SetXY($posx+2,$posy);
1180  $pdf->SetFont('','', $default_font_size - 1);
1181  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1182 
1183 
1184 
1185  // If BILLING contact defined on invoice, we use it
1186  $usecontact=false;
1187  $arrayidcontact=$object->getIdContact('internal','BILLING');
1188  if (count($arrayidcontact) > 0)
1189  {
1190  $usecontact=true;
1191  $result=$object->fetch_contact($arrayidcontact[0]);
1192  }
1193 
1194  //Recipient name
1195  // On peut utiliser le nom de la societe du contact
1196  if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1197  $thirdparty = $object->contact;
1198  } else {
1199  $thirdparty = $mysoc;
1200  }
1201 
1202  $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1203 
1204  $carac_client=pdf_build_address($outputlangs,$this->emetteur,$mysoc,((!empty($object->contact))?$object->contact:null),$usecontact,'target',$object);
1205 
1206  // Show recipient
1207  $widthrecbox=100;
1208  if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
1209  $posy=42+$top_shift;
1210  $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1211  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1212 
1213  // Show recipient frame
1214  $pdf->SetTextColor(0,0,0);
1215  $pdf->SetFont('','', $default_font_size - 2);
1216  $pdf->SetXY($posx+2,$posy-5);
1217  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1218  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1219 
1220  // Show recipient name
1221  $pdf->SetXY($posx+2,$posy+3);
1222  $pdf->SetFont('','B', $default_font_size);
1223  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1224 
1225  $posy = $pdf->getY();
1226 
1227  // Show recipient information
1228  $pdf->SetFont('','', $default_font_size - 1);
1229  $pdf->SetXY($posx+2,$posy);
1230  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1231  }
1232 
1233  return $top_shift;
1234  }
1235 
1245  function _pagefoot(&$pdf, $object, $outputlangs,$hidefreetext=0)
1246  {
1247  global $conf;
1248  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1249  return pdf_pagefoot($pdf,$outputlangs,'SUPPLIER_INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1250  }
1251 }
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:319
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
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:353
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:224
__construct($db)
Constructor.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:201
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:1798
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Parent class for supplier invoices models.
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:1925
Class to manage hooks.
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1526
type
Definition: viewcat.php:284
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1661
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:872
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1585
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
$version
Dolibarr version of the loaded document string.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:1840
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1119
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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:1158
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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...
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
Class to generate the supplier invoices with the canelle model.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...