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