dolibarr  9.0.0
pdf_muscadet.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-2011 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
5  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  * or see http://www.gnu.org/
23  */
24 
31 require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.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 $type;
63 
68  public $phpmin = array(5, 4);
69 
74  public $version = 'dolibarr';
75 
79  public $page_largeur;
80 
84  public $page_hauteur;
85 
89  public $format;
90 
94  public $marge_gauche;
95 
99  public $marge_droite;
100 
104  public $marge_haute;
105 
109  public $marge_basse;
110 
115  public $emetteur;
116 
117 
123  function __construct($db)
124  {
125  global $conf, $langs, $mysoc;
126 
127  // Load translation files required by the page
128  $langs->loadLangs(array("main", "bills"));
129 
130  $this->db = $db;
131  $this->name = "muscadet";
132  $this->description = $langs->trans('SuppliersCommandModel');
133 
134  // Dimension page pour format A4
135  $this->type = 'pdf';
136  $formatarray=pdf_getFormat();
137  $this->page_largeur = $formatarray['width'];
138  $this->page_hauteur = $formatarray['height'];
139  $this->format = array($this->page_largeur,$this->page_hauteur);
140  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
141  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
142  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
143  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
144 
145  $this->option_logo = 1; // Affiche logo
146  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
147  $this->option_modereg = 1; // Affiche mode reglement
148  $this->option_condreg = 1; // Affiche conditions reglement
149  $this->option_codeproduitservice = 1; // Affiche code produit-service
150  $this->option_multilang = 1; // Dispo en plusieurs langues
151  $this->option_escompte = 0; // Affiche si il y a eu escompte
152  $this->option_credit_note = 0; // Support credit notes
153  $this->option_freetext = 1; // Support add of a personalised text
154  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
155 
156  $this->franchise=!$mysoc->tva_assuj;
157 
158  // Get source company
159  $this->emetteur=$mysoc;
160  if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
161 
162  // Defini position des colonnes
163  $this->posxdesc=$this->marge_gauche+1;
164  $this->posxdiscount=162;
165  $this->postotalht=174;
166 
167  if ($conf->global->PRODUCT_USE_UNITS)
168  {
169  $this->posxtva=95;
170  $this->posxup=114;
171  $this->posxqty=132;
172  $this->posxunit=147;
173  } else {
174  $this->posxtva=110;
175  $this->posxup=126;
176  $this->posxqty=145;
177  }
178 
179  if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxup = $this->posxtva; // posxtva is picture position reference
180  $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
181  if ($this->page_largeur < 210) // To work with US executive format
182  {
183  $this->posxpicture-=20;
184  $this->posxtva-=20;
185  $this->posxup-=20;
186  $this->posxqty-=20;
187  $this->posxunit-=20;
188  $this->posxdiscount-=20;
189  $this->postotalht-=20;
190  }
191 
192  $this->tva=array();
193  $this->localtax1=array();
194  $this->localtax2=array();
195  $this->atleastoneratenotnull=0;
196  $this->atleastonediscount=0;
197  }
198 
199 
200  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
212  function write_file($object,$outputlangs='',$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
213  {
214  // phpcs:enable
215  global $user,$langs,$conf,$hookmanager,$mysoc,$nblignes;
216 
217  if (! is_object($outputlangs)) $outputlangs=$langs;
218  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
219  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
220 
221  // Load translation files required by the page
222  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
223 
224  $nblignes = count($object->lines);
225 
226  // Loop on each lines to detect if there is at least one image to show
227  $realpatharray=array();
228  if (! empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE))
229  {
230  for ($i = 0 ; $i < $nblignes ; $i++)
231  {
232  if (empty($object->lines[$i]->fk_product)) continue;
233 
234  $objphoto = new Product($this->db);
235  $objphoto->fetch($object->lines[$i]->fk_product);
236 
237  if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
238  {
239  $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
240  $dir = $conf->product->dir_output.'/'.$pdir;
241  }
242  else
243  {
244  $pdir = get_exdir(0,2,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
245  $dir = $conf->product->dir_output.'/'.$pdir;
246  }
247 
248  $realpath='';
249  foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
250  {
251  $filename=$obj['photo'];
252  //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
253  $realpath = $dir.$filename;
254  break;
255  }
256 
257  if ($realpath) $realpatharray[$i]=$realpath;
258  }
259  }
260  if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
261 
262  if ($conf->fournisseur->commande->dir_output)
263  {
264  $object->fetch_thirdparty();
265 
266  $deja_regle = 0;
267  $amount_credit_notes_included = 0;
268  $amount_deposits_included = 0;
269  //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
270  //$amount_deposits_included = $object->getSumDepositsUsed();
271 
272  // Definition of $dir and $file
273  if ($object->specimen)
274  {
275  $dir = $conf->fournisseur->commande->dir_output;
276  $file = $dir . "/SPECIMEN.pdf";
277  }
278  else
279  {
280  $objectref = dol_sanitizeFileName($object->ref);
281  $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
282  $dir = $conf->fournisseur->commande->dir_output . '/'. $objectref;
283  $file = $dir . "/" . $objectref . ".pdf";
284  if (! empty($conf->global->SUPPLIER_REF_IN_NAME)) $file = $dir . "/" . $objectref . ($objectrefsupplier?"_".$objectrefsupplier:"").".pdf";
285  }
286 
287  if (! file_exists($dir))
288  {
289  if (dol_mkdir($dir) < 0)
290  {
291  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
292  return 0;
293  }
294  }
295 
296  if (file_exists($dir))
297  {
298  // Add pdfgeneration hook
299  if (! is_object($hookmanager))
300  {
301  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
302  $hookmanager=new HookManager($this->db);
303  }
304  $hookmanager->initHooks(array('pdfgeneration'));
305  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
306  global $action;
307  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
308 
309  $nblignes = count($object->lines);
310 
311  $pdf=pdf_getInstance($this->format);
312  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
313  $heightforinfotot = 50; // Height reserved to output the info and total part
314  $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
315  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
316  if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
317  $pdf->SetAutoPageBreak(1,0);
318 
319  if (class_exists('TCPDF'))
320  {
321  $pdf->setPrintHeader(false);
322  $pdf->setPrintFooter(false);
323  }
324  $pdf->SetFont(pdf_getPDFFont($outputlangs));
325  // Set path to the background PDF File
326  if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
327  {
328  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
329  $tplidx = $pdf->importPage(1);
330  }
331 
332  $pdf->Open();
333  $pagenb=0;
334  $pdf->SetDrawColor(128,128,128);
335 
336  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
337  $pdf->SetSubject($outputlangs->transnoentities("Order"));
338  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
339  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
340  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
341  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
342 
343  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
344 
345  // Positionne $this->atleastonediscount si on a au moins une remise
346  for ($i = 0 ; $i < $nblignes ; $i++)
347  {
348  if ($object->lines[$i]->remise_percent)
349  {
350  $this->atleastonediscount++;
351  }
352  }
353  if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
354  {
355  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
356  $this->posxtva+=($this->postotalht - $this->posxdiscount);
357  $this->posxup+=($this->postotalht - $this->posxdiscount);
358  $this->posxqty+=($this->postotalht - $this->posxdiscount);
359  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
360  //$this->postotalht;
361  }
362 
363  // New page
364  $pdf->AddPage();
365  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
366  $pagenb++;
367  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
368  $pdf->SetFont('','', $default_font_size - 1);
369  $pdf->MultiCell(0, 3, ''); // Set interline to 3
370  $pdf->SetTextColor(0,0,0);
371 
372  $tab_top = 90+$top_shift;
373  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
374 
375  // Incoterm
376  if ($conf->incoterm->enabled)
377  {
378  $desc_incoterms = $object->getIncotermsForPDF();
379  if ($desc_incoterms)
380  {
381  $tab_top -= 2;
382 
383  $pdf->SetFont('','', $default_font_size - 1);
384  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
385  $nexY = $pdf->GetY();
386  $height_incoterms=$nexY-$tab_top;
387 
388  // Rect prend une longueur en 3eme param
389  $pdf->SetDrawColor(192,192,192);
390  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
391 
392  $tab_top = $nexY+6;
393  }
394  }
395 
396  // Affiche notes
397  if (! empty($object->note_public))
398  {
399  $tab_top -= 2;
400 
401  $pdf->SetFont('','', $default_font_size - 1);
402  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($object->note_public), 0, 1);
403  $nexY = $pdf->GetY();
404  $height_note=$nexY-$tab_top;
405 
406  // Rect prend une longueur en 3eme param
407  $pdf->SetDrawColor(192,192,192);
408  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
409 
410  $tab_top = $nexY+6;
411  }
412 
413  $iniY = $tab_top + 7;
414  $curY = $tab_top + 7;
415  $nexY = $tab_top + 7;
416 
417  // Loop on each lines
418  for ($i = 0 ; $i < $nblignes ; $i++)
419  {
420  $curY = $nexY;
421  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
422  $pdf->SetTextColor(0,0,0);
423 
424  // Define size of image if we need it
425  $imglinesize=array();
426  if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
427 
428  $pdf->setTopMargin($tab_top_newpage);
429  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
430  $pageposbefore=$pdf->getPage();
431 
432  $showpricebeforepagebreak=1;
433  $posYAfterImage=0;
434  $posYAfterDescription=0;
435 
436  // We start with Photo of product line
437  if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page
438  {
439  $pdf->AddPage('','',true);
440  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
441  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
442  $pdf->setPage($pageposbefore+1);
443 
444  $curY = $tab_top_newpage;
445  $showpricebeforepagebreak=0;
446  }
447 
448  if (!empty($imglinesize['width']) && !empty($imglinesize['height']))
449  {
450  $curX = $this->posxpicture-1;
451  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
452  // $pdf->Image does not increase value return by getY, so we save it manually
453  $posYAfterImage=$curY+$imglinesize['height'];
454  }
455  // Description of product line
456  $curX = $this->posxdesc-1;
457  $showpricebeforepagebreak=1;
458 
459  $pdf->startTransaction();
460  if ($posYAfterImage > 0)
461  {
462  $descWidth = $this->posxpicture-$curX;
463  }
464  else
465  {
466  $descWidth = $this->posxtva-$curX;
467  }
468  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$descWidth,3,$curX,$curY,$hideref,$hidedesc,1);
469 
470  $pageposafter=$pdf->getPage();
471  if ($pageposafter > $pageposbefore) // There is a pagebreak
472  {
473  $pdf->rollbackTransaction(true);
474  $pageposafter=$pageposbefore;
475  //print $pageposafter.'-'.$pageposbefore;exit;
476  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
477  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$descWidth,3,$curX,$curY,$hideref,$hidedesc,1);
478  $posyafter=$pdf->GetY();
479  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
480  {
481  if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
482  {
483  $pdf->AddPage('','',true);
484  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
485  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
486  $pdf->setPage($pageposafter+1);
487  }
488  }
489  else
490  {
491  // We found a page break
492  $showpricebeforepagebreak=0;
493  }
494  }
495  else // No pagebreak
496  {
497  $pdf->commitTransaction();
498  }
499 
500  $nexY = $pdf->GetY();
501  $pageposafter=$pdf->getPage();
502  $pdf->setPage($pageposbefore);
503  $pdf->setTopMargin($this->marge_haute);
504  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
505 
506  // We suppose that a too long description is moved completely on next page
507  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
508  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
509  }
510 
511  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
512 
513  // VAT Rate
514  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
515  {
516  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
517  $pdf->SetXY($this->posxtva, $curY);
518  $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
519  }
520 
521  // Unit price before discount
522  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
523  $pdf->SetXY($this->posxup, $curY);
524  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
525 
526  // Quantity
527  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
528  $pdf->SetXY($this->posxqty, $curY);
529  // Enough for 6 chars
530  if($conf->global->PRODUCT_USE_UNITS)
531  {
532  $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
533  }
534  else
535  {
536  $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
537  }
538 
539  // Unit
540  if($conf->global->PRODUCT_USE_UNITS)
541  {
542  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
543  $pdf->SetXY($this->posxunit, $curY);
544  $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
545  }
546 
547  // Discount on line
548  $pdf->SetXY($this->posxdiscount, $curY);
549  if ($object->lines[$i]->remise_percent)
550  {
551  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
552  $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $remise_percent, 0, 'R');
553  }
554 
555  // Total HT line
556  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs);
557  $pdf->SetXY($this->postotalht, $curY);
558  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
559 
560  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
561  if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
562  else $tvaligne=$object->lines[$i]->total_tva;
563 
564  $localtax1ligne=$object->lines[$i]->total_localtax1;
565  $localtax2ligne=$object->lines[$i]->total_localtax2;
566  $localtax1_rate=$object->lines[$i]->localtax1_tx;
567  $localtax2_rate=$object->lines[$i]->localtax2_tx;
568  $localtax1_type=$object->lines[$i]->localtax1_type;
569  $localtax2_type=$object->lines[$i]->localtax2_type;
570 
571  if (! empty($object->remise_percent)) $tvaligne-=($tvaligne*$object->remise_percent)/100;
572  if (! empty($object->remise_percent)) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
573  if (! empty($object->remise_percent)) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
574 
575  $vatrate=(string) $object->lines[$i]->tva_tx;
576 
577  // Retrieve type from database for backward compatibility with old records
578  if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
579  && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
580  {
581  $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$mysoc,$object->thirdparty);
582  $localtax1_type = $localtaxtmp_array[0];
583  $localtax2_type = $localtaxtmp_array[2];
584  }
585 
586  // retrieve global local tax
587  if ($localtax1_type && $localtax1ligne != 0)
588  $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
589  if ($localtax2_type && $localtax2ligne != 0)
590  $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
591 
592  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
593  if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
594  $this->tva[$vatrate] += $tvaligne;
595 
596  if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
597 
598  // Add line
599  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
600  {
601  $pdf->setPage($pageposafter);
602  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
603  //$pdf->SetDrawColor(190,190,200);
604  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
605  $pdf->SetLineStyle(array('dash'=>0));
606  }
607 
608  $nexY+=2; // Passe espace entre les lignes
609 
610  // Detect if some page were added automatically and output _tableau for past pages
611  while ($pagenb < $pageposafter)
612  {
613  $pdf->setPage($pagenb);
614  if ($pagenb == 1)
615  {
616  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
617  }
618  else
619  {
620  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
621  }
622  $this->_pagefoot($pdf,$object,$outputlangs,1);
623  $pagenb++;
624  $pdf->setPage($pagenb);
625  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
626  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
627  }
628  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
629  {
630  if ($pagenb == 1)
631  {
632  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
633  }
634  else
635  {
636  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
637  }
638  $this->_pagefoot($pdf,$object,$outputlangs,1);
639  // New page
640  $pdf->AddPage();
641  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
642  $pagenb++;
643  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
644  }
645  }
646 
647  // Show square
648  if ($pagenb == 1)
649  {
650  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
651  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
652  }
653  else
654  {
655  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
656  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
657  }
658 
659  // Affiche zone infos
660  $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
661 
662  // Affiche zone totaux
663  $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
664 
665  // Affiche zone versements
666  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
667  {
668  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
669  }
670 
671  // Pied de page
672  $this->_pagefoot($pdf, $object, $outputlangs);
673  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
674 
675  $pdf->Close();
676 
677  $pdf->Output($file,'F');
678 
679  // Add pdfgeneration hook
680  $hookmanager->initHooks(array('pdfgeneration'));
681  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
682  global $action;
683  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
684 
685  if (! empty($conf->global->MAIN_UMASK))
686  @chmod($file, octdec($conf->global->MAIN_UMASK));
687 
688  $this->result = array('fullpath'=>$file);
689 
690  return 1; // Pas d'erreur
691  }
692  else
693  {
694  $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
695  return 0;
696  }
697  }
698  else
699  {
700  $this->error=$langs->trans("ErrorConstantNotDefined","SUPPLIER_OUTPUTDIR");
701  return 0;
702  }
703  }
704 
705 
706  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
716  function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
717  {
718  // phpcs:enable
719  }
720 
721 
722  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
732  function _tableau_info(&$pdf, $object, $posy, $outputlangs)
733  {
734  // phpcs:enable
735  global $conf;
736  $default_font_size = pdf_getPDFFontSize($outputlangs);
737 
738  // If France, show VAT mention if not applicable
739  if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
740  {
741  $pdf->SetFont('','B', $default_font_size - 2);
742  $pdf->SetXY($this->marge_gauche, $posy);
743  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
744 
745  $posy=$pdf->GetY()+4;
746  }
747 
748  $posxval=52;
749 
750  // Show payments conditions
751  if (!empty($object->cond_reglement_code) || $object->cond_reglement)
752  {
753  $pdf->SetFont('','B', $default_font_size - 2);
754  $pdf->SetXY($this->marge_gauche, $posy);
755  $titre = $outputlangs->transnoentities("PaymentConditions").':';
756  $pdf->MultiCell(80, 4, $titre, 0, 'L');
757 
758  $pdf->SetFont('','', $default_font_size - 2);
759  $pdf->SetXY($posxval, $posy);
760  $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);
761  $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
762  $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
763 
764  $posy=$pdf->GetY()+3;
765  }
766 
767  // Show payment mode
768  if (!empty($object->mode_reglement_code))
769  {
770  $pdf->SetFont('','B', $default_font_size - 2);
771  $pdf->SetXY($this->marge_gauche, $posy);
772  $titre = $outputlangs->transnoentities("PaymentMode").':';
773  $pdf->MultiCell(80, 5, $titre, 0, 'L');
774 
775  $pdf->SetFont('','', $default_font_size - 2);
776  $pdf->SetXY($posxval, $posy);
777  $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);
778  $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
779 
780  $posy=$pdf->GetY()+2;
781  }
782 
783 
784  return $posy;
785  }
786 
787  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
798  function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
799  {
800  // phpcs:enable
801  global $conf,$mysoc;
802 
803  $default_font_size = pdf_getPDFFontSize($outputlangs);
804 
805  $tab2_top = $posy;
806  $tab2_hl = 4;
807  $pdf->SetFont('','', $default_font_size - 1);
808 
809  // Tableau total
810  $col1x = 120; $col2x = 170;
811  if ($this->page_largeur < 210) // To work with US executive format
812  {
813  $col2x-=20;
814  }
815  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
816 
817  $useborder=0;
818  $index = 0;
819 
820  // Total HT
821  $pdf->SetFillColor(255,255,255);
822  $pdf->SetXY($col1x, $tab2_top + 0);
823  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
824 
825  $total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
826  $pdf->SetXY($col2x, $tab2_top + 0);
827  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0)), 0, 'R', 1);
828 
829  // Show VAT by rates and total
830  $pdf->SetFillColor(248,248,248);
831 
832  $this->atleastoneratenotnull=0;
833  foreach( $this->tva as $tvakey => $tvaval )
834  {
835  if ($tvakey > 0) // On affiche pas taux 0
836  {
837  $this->atleastoneratenotnull++;
838 
839  $index++;
840  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
841 
842  $tvacompl='';
843 
844  if (preg_match('/\*/',$tvakey))
845  {
846  $tvakey=str_replace('*','',$tvakey);
847  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
848  }
849 
850  $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
851  $totalvat.=vatrate($tvakey,1).$tvacompl;
852  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
853 
854  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
855  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
856  }
857  }
858  if (! $this->atleastoneratenotnull) // If no vat at all
859  {
860  $index++;
861  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
862  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
863 
864  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
865  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
866 
867  // Total LocalTax1
868  if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
869  {
870  $index++;
871  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
872  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code), 0, 'L', 1);
873  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
874  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
875  }
876 
877  // Total LocalTax2
878  if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
879  {
880  $index++;
881  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
882  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code), 0, 'L', 1);
883  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
884  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
885  }
886  }
887  else
888  {
889  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
890  //{
891  //Local tax 1
892  foreach( $this->localtax1 as $localtax_type => $localtax_rate )
893  {
894  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
895 
896  foreach( $localtax_rate as $tvakey => $tvaval )
897  {
898  if ($tvakey != 0) // On affiche pas taux 0
899  {
900  //$this->atleastoneratenotnull++;
901 
902  $index++;
903  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
904 
905  $tvacompl='';
906  if (preg_match('/\*/',$tvakey))
907  {
908  $tvakey=str_replace('*','',$tvakey);
909  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
910  }
911  $totalvat =$outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
912  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
913  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
914 
915  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
916  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
917  }
918  }
919  }
920 
921  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
922  //{
923  //Local tax 2
924  foreach( $this->localtax2 as $localtax_type => $localtax_rate )
925  {
926  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
927 
928  foreach( $localtax_rate as $tvakey => $tvaval )
929  {
930  if ($tvakey != 0) // On affiche pas taux 0
931  {
932  //$this->atleastoneratenotnull++;
933 
934  $index++;
935  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
936 
937  $tvacompl='';
938  if (preg_match('/\*/',$tvakey))
939  {
940  $tvakey=str_replace('*','',$tvakey);
941  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
942  }
943  $totalvat =$outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
944  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
945  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
946 
947  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
948  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
949  }
950  }
951  }
952  }
953 
954  // Total TTC
955  $index++;
956  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
957  $pdf->SetTextColor(0,0,60);
958  $pdf->SetFillColor(224,224,224);
959  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
960 
961  $total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
962  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
963  $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
964  $pdf->SetFont('','', $default_font_size - 1);
965  $pdf->SetTextColor(0,0,0);
966 
967  $creditnoteamount=0;
968  $depositsamount=0;
969  //$creditnoteamount=$object->getSumCreditNotesUsed();
970  //$depositsamount=$object->getSumDepositsUsed();
971  //print "x".$creditnoteamount."-".$depositsamount;exit;
972  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
973  if (! empty($object->paye)) $resteapayer=0;
974 
975  if ($deja_regle > 0)
976  {
977  // Already paid + Deposits
978  $index++;
979 
980  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
981  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
982  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
983  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
984 
985  $index++;
986  $pdf->SetTextColor(0,0,60);
987  $pdf->SetFillColor(224,224,224);
988  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
989  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
990 
991  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
992  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
993 
994  $pdf->SetFont('','', $default_font_size - 1);
995  $pdf->SetTextColor(0,0,0);
996  }
997 
998  $index++;
999  return ($tab2_top + ($tab2_hl * $index));
1000  }
1001 
1015  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1016  {
1017  global $conf;
1018 
1019  // Force to disable hidetop and hidebottom
1020  $hidebottom=0;
1021  if ($hidetop) $hidetop=-1;
1022 
1023  $currency = !empty($currency) ? $currency : $conf->currency;
1024  $default_font_size = pdf_getPDFFontSize($outputlangs);
1025 
1026  // Amount in (at tab_top - 1)
1027  $pdf->SetTextColor(0,0,0);
1028  $pdf->SetFont('','', $default_font_size - 2);
1029 
1030  if (empty($hidetop))
1031  {
1032  $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1033  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1034  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1035 
1036  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1037  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));
1038  }
1039 
1040  $pdf->SetDrawColor(128,128,128);
1041  $pdf->SetFont('','', $default_font_size - 1);
1042 
1043  // Output Rect
1044  $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
1045 
1046  if (empty($hidetop))
1047  {
1048  $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
1049 
1050  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
1051  $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1052  }
1053 
1054  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1055  {
1056  $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1057  if (empty($hidetop))
1058  {
1059  $pdf->SetXY($this->posxtva-3, $tab_top+1);
1060  $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1061  }
1062  }
1063 
1064  $pdf->line($this->posxup, $tab_top, $this->posxup, $tab_top + $tab_height);
1065  if (empty($hidetop))
1066  {
1067  $pdf->SetXY($this->posxup-1, $tab_top+1);
1068  $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1069  }
1070 
1071  $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1072  if (empty($hidetop))
1073  {
1074  $pdf->SetXY($this->posxqty-1, $tab_top+1);
1075  if($conf->global->PRODUCT_USE_UNITS)
1076  {
1077  $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1078  }
1079  else
1080  {
1081  $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1082  }
1083  }
1084 
1085  if($conf->global->PRODUCT_USE_UNITS) {
1086  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1087  if (empty($hidetop)) {
1088  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1089  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1090  'C');
1091  }
1092  }
1093 
1094  $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1095  if (empty($hidetop))
1096  {
1097  if ($this->atleastonediscount)
1098  {
1099  $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1100  $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1101  }
1102  }
1103 
1104  if ($this->atleastonediscount)
1105  {
1106  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1107  }
1108  if (empty($hidetop))
1109  {
1110  $pdf->SetXY($this->postotalht-1, $tab_top+1);
1111  $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHTShort"),'','C');
1112  }
1113  }
1114 
1124  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1125  {
1126  global $langs, $conf, $mysoc;
1127 
1128  // Load translation files required by the page
1129  $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
1130 
1131  $default_font_size = pdf_getPDFFontSize($outputlangs);
1132 
1133  // Do not add the BACKGROUND as this is for suppliers
1134  //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1135 
1136  //Affiche le filigrane brouillon - Print Draft Watermark
1137  /*if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
1138  {
1139  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
1140  }*/
1141  //Print content
1142 
1143  $pdf->SetTextColor(0,0,60);
1144  $pdf->SetFont('','B',$default_font_size + 3);
1145 
1146  $posx=$this->page_largeur-$this->marge_droite-100;
1147  $posy=$this->marge_haute;
1148 
1149  $pdf->SetXY($this->marge_gauche,$posy);
1150 
1151  // Logo
1152  $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1153  if ($this->emetteur->logo)
1154  {
1155  if (is_readable($logo))
1156  {
1157  $height=pdf_getHeightForLogo($logo);
1158  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1159  }
1160  else
1161  {
1162  $pdf->SetTextColor(200,0,0);
1163  $pdf->SetFont('','B', $default_font_size - 2);
1164  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1165  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1166  }
1167  }
1168  else
1169  {
1170  $text=$this->emetteur->name;
1171  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1172  }
1173 
1174  $pdf->SetFont('', 'B', $default_font_size + 3);
1175  $pdf->SetXY($posx,$posy);
1176  $pdf->SetTextColor(0,0,60);
1177  $title=$outputlangs->transnoentities("SupplierOrder")." ".$outputlangs->convToOutputCharset($object->ref);
1178  $pdf->MultiCell(100, 3, $title, '', 'R');
1179  $posy+=1;
1180 
1181  if ($object->ref_supplier)
1182  {
1183  $posy+=4;
1184  $pdf->SetFont('','B', $default_font_size);
1185  $pdf->SetXY($posx,$posy);
1186  $pdf->SetTextColor(0,0,60);
1187  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : " . $outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1188  $posy+=1;
1189  }
1190 
1191  $pdf->SetFont('','', $default_font_size -1);
1192 
1193  if (! empty($conf->global->PDF_SHOW_PROJECT))
1194  {
1195  $object->fetch_projet();
1196  if (! empty($object->project->ref))
1197  {
1198  $posy+=4;
1199  $pdf->SetXY($posx,$posy);
1200  $langs->load("projects");
1201  $pdf->SetTextColor(0,0,60);
1202  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->projet->ref), '', 'R');
1203  }
1204  }
1205 
1206  if (! empty($object->date_commande))
1207  {
1208  $posy+=5;
1209  $pdf->SetXY($posx,$posy);
1210  $pdf->SetTextColor(0,0,60);
1211  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date_commande,"day",false,$outputlangs,true), '', 'R');
1212  }
1213  else
1214  {
1215  $posy+=5;
1216  $pdf->SetXY($posx,$posy);
1217  $pdf->SetTextColor(255,0,0);
1218  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R');
1219  }
1220 
1221  $pdf->SetTextColor(0,0,60);
1222  $usehourmin='day';
1223  if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin='dayhour';
1224  if (! empty($object->date_livraison))
1225  {
1226  $posy+=4;
1227  $pdf->SetXY($posx-90,$posy);
1228  $pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : " . dol_print_date($object->date_livraison,$usehourmin,false,$outputlangs,true), '', 'R');
1229  }
1230 
1231  if ($object->thirdparty->code_fournisseur)
1232  {
1233  $posy+=4;
1234  $pdf->SetXY($posx,$posy);
1235  $pdf->SetTextColor(0,0,60);
1236  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1237  }
1238 
1239  // Get contact
1240  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1241  {
1242  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1243  if (count($arrayidcontact) > 0)
1244  {
1245  $usertmp=new User($this->db);
1246  $usertmp->fetch($arrayidcontact[0]);
1247  $posy+=4;
1248  $pdf->SetXY($posx,$posy);
1249  $pdf->SetTextColor(0,0,60);
1250  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1251  }
1252  }
1253 
1254  $posy+=1;
1255  $pdf->SetTextColor(0,0,60);
1256 
1257  $top_shift = 0;
1258  // Show list of linked objects
1259  $current_y = $pdf->getY();
1260  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1261  if ($current_y < $pdf->getY())
1262  {
1263  $top_shift = $pdf->getY() - $current_y;
1264  }
1265 
1266  if ($showaddress)
1267  {
1268  // Sender properties
1269  $carac_emetteur='';
1270  // Add internal contact of proposal if defined
1271  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1272  if (count($arrayidcontact) > 0)
1273  {
1274  $object->fetch_user($arrayidcontact[0]);
1275  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1276  }
1277 
1278  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1279 
1280  // Show sender
1281  $posy=42+$top_shift;
1282  $posx=$this->marge_gauche;
1283  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1284  $hautcadre=40;
1285 
1286  // Show sender frame
1287  $pdf->SetTextColor(0,0,0);
1288  $pdf->SetFont('','', $default_font_size - 2);
1289  $pdf->SetXY($posx,$posy-5);
1290  $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1291  $pdf->SetXY($posx,$posy);
1292  $pdf->SetFillColor(230,230,230);
1293  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1294  $pdf->SetTextColor(0,0,60);
1295 
1296  // Show sender name
1297  $pdf->SetXY($posx+2,$posy+3);
1298  $pdf->SetFont('','B', $default_font_size);
1299  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1300  $posy=$pdf->getY();
1301 
1302  // Show sender information
1303  $pdf->SetXY($posx+2,$posy);
1304  $pdf->SetFont('','', $default_font_size - 1);
1305  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1306 
1307 
1308 
1309  // If BILLING contact defined on order, we use it
1310  $usecontact=false;
1311  $arrayidcontact=$object->getIdContact('external','BILLING');
1312  if (count($arrayidcontact) > 0)
1313  {
1314  $usecontact=true;
1315  $result=$object->fetch_contact($arrayidcontact[0]);
1316  }
1317 
1318  //Recipient name
1319  // On peut utiliser le nom de la societe du contact
1320  if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1321  $thirdparty = $object->contact;
1322  } else {
1323  $thirdparty = $object->thirdparty;
1324  }
1325 
1326  $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1327 
1328  $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1329 
1330  // Show recipient
1331  $widthrecbox=100;
1332  if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
1333  $posy=42+$top_shift;
1334  $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1335  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1336 
1337  // Show recipient frame
1338  $pdf->SetTextColor(0,0,0);
1339  $pdf->SetFont('','', $default_font_size - 2);
1340  $pdf->SetXY($posx+2,$posy-5);
1341  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1342  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1343 
1344  // Show recipient name
1345  $pdf->SetXY($posx+2,$posy+3);
1346  $pdf->SetFont('','B', $default_font_size);
1347  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1348 
1349  $posy = $pdf->getY();
1350 
1351  // Show recipient information
1352  $pdf->SetFont('','', $default_font_size - 1);
1353  $pdf->SetXY($posx+2,$posy);
1354  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1355  }
1356 
1357  return $top_shift;
1358  }
1359 
1369  function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
1370  {
1371  global $conf;
1372  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1373  return pdf_pagefoot($pdf,$outputlangs,'SUPPLIER_ORDER_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1374  }
1375 }
Parent class for supplier orders models.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
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
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
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
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:224
Class to manage products or services.
$version
Dolibarr version of the loaded document string.
Class to manage Dolibarr users.
Definition: user.class.php:41
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
__construct($db)
Constructor.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:201
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:1798
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Class to generate the supplier orders with the muscadet model.
write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
type
Definition: viewcat.php:284
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1661
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:872
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
Definition: pdf.lib.php:1585
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2170
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.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
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_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...
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...