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