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