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