dolibarr  7.0.0-beta
pdf_crabe.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
4  * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
8  * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  * or see http://www.gnu.org/
25  */
26 
33 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
34 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38 
39 
44 {
45  var $db;
46  var $name;
47  var $description;
48  var $update_main_doc_field; // Save the name of generated file as the main doc when generating a doc with this template
49  var $type;
50 
51  var $phpmin = array(4,3,0); // Minimum version of PHP required by module
52  var $version = 'dolibarr';
53 
54  var $page_largeur;
55  var $page_hauteur;
56  var $format;
57  var $marge_gauche;
58  var $marge_droite;
59  var $marge_haute;
60  var $marge_basse;
61 
62  var $emetteur; // Objet societe qui emet
63 
67  public $situationinvoice;
68 
72  public $posxprogress;
73 
74 
80  function __construct($db)
81  {
82  global $conf,$langs,$mysoc;
83 
84  $langs->load("main");
85  $langs->load("bills");
86 
87  $this->db = $db;
88  $this->name = "crabe";
89  $this->description = $langs->trans('PDFCrabeDescription');
90  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
91 
92  // Dimensiont page
93  $this->type = 'pdf';
94  $formatarray=pdf_getFormat();
95  $this->page_largeur = $formatarray['width'];
96  $this->page_hauteur = $formatarray['height'];
97  $this->format = array($this->page_largeur,$this->page_hauteur);
98  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
99  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
100  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
101  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
102 
103  $this->option_logo = 1; // Affiche logo
104  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
105  $this->option_modereg = 1; // Affiche mode reglement
106  $this->option_condreg = 1; // Affiche conditions reglement
107  $this->option_codeproduitservice = 1; // Affiche code produit-service
108  $this->option_multilang = 1; // Dispo en plusieurs langues
109  $this->option_escompte = 1; // Affiche si il y a eu escompte
110  $this->option_credit_note = 1; // Support credit notes
111  $this->option_freetext = 1; // Support add of a personalised text
112  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
113 
114  $this->franchise=!$mysoc->tva_assuj;
115 
116  // Get source company
117  $this->emetteur=$mysoc;
118  if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
119 
120  // Define position of columns
121  $this->posxdesc=$this->marge_gauche+1;
122  if($conf->global->PRODUCT_USE_UNITS)
123  {
124  $this->posxtva=99;
125  $this->posxup=114;
126  $this->posxqty=130;
127  $this->posxunit=147;
128  }
129  else
130  {
131  $this->posxtva=110;
132  $this->posxup=126;
133  $this->posxqty=145;
134  }
135  $this->posxdiscount=162;
136  $this->posxprogress=126; // Only displayed for situation invoices
137  $this->postotalht=174;
138  if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
139  $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
140  if ($this->page_largeur < 210) // To work with US executive format
141  {
142  $this->posxpicture-=20;
143  $this->posxtva-=20;
144  $this->posxup-=20;
145  $this->posxqty-=20;
146  $this->posxunit-=20;
147  $this->posxdiscount-=20;
148  $this->posxprogress-=20;
149  $this->postotalht-=20;
150  }
151 
152  $this->tva=array();
153  $this->localtax1=array();
154  $this->localtax2=array();
155  $this->atleastoneratenotnull=0;
156  $this->atleastonediscount=0;
157  $this->situationinvoice=False;
158  }
159 
160 
172  function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
173  {
174  global $user,$langs,$conf,$mysoc,$db,$hookmanager;
175 
176  if (! is_object($outputlangs)) $outputlangs=$langs;
177  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
178  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
179 
180  $outputlangs->load("main");
181  $outputlangs->load("dict");
182  $outputlangs->load("companies");
183  $outputlangs->load("bills");
184  $outputlangs->load("products");
185 
186  $nblignes = count($object->lines);
187 
188  // Loop on each lines to detect if there is at least one image to show
189  $realpatharray=array();
190  if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
191  {
192  for ($i = 0 ; $i < $nblignes ; $i++)
193  {
194  if (empty($object->lines[$i]->fk_product)) continue;
195 
196  $objphoto = new Product($this->db);
197  $objphoto->fetch($object->lines[$i]->fk_product);
198 
199  $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
200  $dir = $conf->product->dir_output.'/'.$pdir;
201 
202  $realpath='';
203  foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
204  {
205  $filename=$obj['photo'];
206  //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
207  $realpath = $dir.$filename;
208  break;
209  }
210 
211  if ($realpath) $realpatharray[$i]=$realpath;
212  }
213  }
214  if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
215 
216  if ($conf->facture->dir_output)
217  {
218  $object->fetch_thirdparty();
219 
220  $deja_regle = $object->getSommePaiement(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
221  $amount_credit_notes_included = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
222  $amount_deposits_included = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
223 
224  // Definition of $dir and $file
225  if ($object->specimen)
226  {
227  $dir = $conf->facture->dir_output;
228  $file = $dir . "/SPECIMEN.pdf";
229  }
230  else
231  {
232  $objectref = dol_sanitizeFileName($object->ref);
233  $dir = $conf->facture->dir_output . "/" . $objectref;
234  $file = $dir . "/" . $objectref . ".pdf";
235  }
236  if (! file_exists($dir))
237  {
238  if (dol_mkdir($dir) < 0)
239  {
240  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
241  return 0;
242  }
243  }
244 
245  if (file_exists($dir))
246  {
247  // Add pdfgeneration hook
248  if (! is_object($hookmanager))
249  {
250  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
251  $hookmanager=new HookManager($this->db);
252  }
253  $hookmanager->initHooks(array('pdfgeneration'));
254  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
255  global $action;
256  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
257 
258  // Set nblignes with the new facture lines content after hook
259  $nblignes = count($object->lines);
260  $nbpayments = count($object->getListOfPayments());
261 
262  // Create pdf instance
263  $pdf=pdf_getInstance($this->format);
264  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
265  $pdf->SetAutoPageBreak(1,0);
266 
267  $heightforinfotot = 50+(4*$nbpayments); // Height reserved to output the info and total part and payment part
268  $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
269  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
270 
271  if (class_exists('TCPDF'))
272  {
273  $pdf->setPrintHeader(false);
274  $pdf->setPrintFooter(false);
275  }
276  $pdf->SetFont(pdf_getPDFFont($outputlangs));
277 
278  // Set path to the background PDF File
279  if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
280  {
281  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
282  $tplidx = $pdf->importPage(1);
283  }
284 
285  $pdf->Open();
286  $pagenb=0;
287  $pdf->SetDrawColor(128,128,128);
288 
289  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
290  $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
291  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
292  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
293  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
294  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
295 
296  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
297 
298  // Positionne $this->atleastonediscount si on a au moins une remise
299  for ($i = 0 ; $i < $nblignes ; $i++)
300  {
301  if ($object->lines[$i]->remise_percent)
302  {
303  $this->atleastonediscount++;
304  }
305  }
306  if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS)) // retreive space not used by discount
307  {
308  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
309  $this->posxtva+=($this->postotalht - $this->posxdiscount);
310  $this->posxup+=($this->postotalht - $this->posxdiscount);
311  $this->posxqty+=($this->postotalht - $this->posxdiscount);
312  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
313  //$this->postotalht;
314  }
315 
316  $progress_width = 0;
317  // Situation invoice handling
318  if ($object->situation_cycle_ref)
319  {
320  $this->situationinvoice = True;
321  $progress_width = 18;
322  $this->posxtva -= $progress_width;
323  $this->posxup -= $progress_width;
324  $this->posxqty -= $progress_width;
325  if(empty($conf->global->PRODUCT_USE_UNITS)) {
326  $this->posxprogress += $progress_width;
327  }
328  /*$this->posxdiscount -= $progress_width;
329  $this->posxprogress -= $progress_width;*/
330  }
331 
332  // New page
333  $pdf->AddPage();
334  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
335  $pagenb++;
336 
337  $this->_pagehead($pdf, $object, 1, $outputlangs);
338  $pdf->SetFont('','', $default_font_size - 1);
339  $pdf->MultiCell(0, 3, ''); // Set interline to 3
340  $pdf->SetTextColor(0,0,0);
341 
342  $tab_top = 90;
343  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
344  $tab_height = 130;
345  $tab_height_newpage = 150;
346 
347  // Incoterm
348  $height_incoterms = 0;
349  if ($conf->incoterm->enabled)
350  {
351  $desc_incoterms = $object->getIncotermsForPDF();
352  if ($desc_incoterms)
353  {
354  $tab_top = 88;
355 
356  $pdf->SetFont('','', $default_font_size - 1);
357  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
358  $nexY = $pdf->GetY();
359  $height_incoterms=$nexY-$tab_top;
360 
361  // Rect prend une longueur en 3eme param
362  $pdf->SetDrawColor(192,192,192);
363  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
364 
365  $tab_top = $nexY+6;
366  $height_incoterms += 4;
367  }
368  }
369 
370  // Affiche notes
371  $notetoshow=empty($object->note_public)?'':$object->note_public;
372  if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
373  {
374  // Get first sale rep
375  if (is_object($object->thirdparty))
376  {
377  $salereparray=$object->thirdparty->getSalesRepresentatives($user);
378  $salerepobj=new User($this->db);
379  $salerepobj->fetch($salereparray[0]['id']);
380  if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
381  }
382  }
383  if ($notetoshow)
384  {
385  $tab_top = 88 + $height_incoterms;
386 
387  $pdf->SetFont('','', $default_font_size - 1);
388  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
389  $nexY = $pdf->GetY();
390  $height_note=$nexY-$tab_top;
391 
392  // Rect prend une longueur en 3eme param
393  $pdf->SetDrawColor(192,192,192);
394  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
395 
396  $tab_height = $tab_height - $height_note;
397  $tab_top = $nexY+6;
398  }
399  else
400  {
401  $height_note=0;
402  }
403 
404  $iniY = $tab_top + 7;
405  $curY = $tab_top + 7;
406  $nexY = $tab_top + 7;
407 
408  // Loop on each lines
409  for ($i = 0; $i < $nblignes; $i++)
410  {
411  $curY = $nexY;
412  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
413  $pdf->SetTextColor(0,0,0);
414 
415  // Define size of image if we need it
416  $imglinesize=array();
417  if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
418 
419  $pdf->setTopMargin($tab_top_newpage);
420  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
421  $pageposbefore=$pdf->getPage();
422 
423  $showpricebeforepagebreak=1;
424  $posYAfterImage=0;
425  $posYAfterDescription=0;
426 
427  // We start with Photo of product line
428  if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page
429  {
430  $pdf->AddPage('','',true);
431  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
432  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
433  $pdf->setPage($pageposbefore+1);
434 
435  $curY = $tab_top_newpage;
436  $showpricebeforepagebreak=0;
437  }
438 
439  if (isset($imglinesize['width']) && isset($imglinesize['height']))
440  {
441  $curX = $this->posxpicture-1;
442  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
443  // $pdf->Image does not increase value return by getY, so we save it manually
444  $posYAfterImage=$curY+$imglinesize['height'];
445  }
446 
447  // Description of product line
448  $curX = $this->posxdesc-1;
449 
450  $pdf->startTransaction();
451  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
452  $pageposafter=$pdf->getPage();
453  if ($pageposafter > $pageposbefore) // There is a pagebreak
454  {
455  $pdf->rollbackTransaction(true);
456  $pageposafter=$pageposbefore;
457  //print $pageposafter.'-'.$pageposbefore;exit;
458  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
459  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX-$progress_width,3,$curX,$curY,$hideref,$hidedesc);
460  $pageposafter=$pdf->getPage();
461  $posyafter=$pdf->GetY();
462  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
463  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
464  {
465  if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
466  {
467  $pdf->AddPage('','',true);
468  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
469  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
470  $pdf->setPage($pageposafter+1);
471  }
472  }
473  else
474  {
475  // We found a page break
476  $showpricebeforepagebreak=0;
477  }
478  }
479  else // No pagebreak
480  {
481  $pdf->commitTransaction();
482  }
483  $posYAfterDescription=$pdf->GetY();
484 
485  $nexY = $pdf->GetY();
486  $pageposafter=$pdf->getPage();
487  $pdf->setPage($pageposbefore);
488  $pdf->setTopMargin($this->marge_haute);
489  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
490 
491  // We suppose that a too long description or photo were moved completely on next page
492  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
493  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
494  }
495 
496  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
497 
498  // VAT Rate
499  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
500  {
501  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
502  $pdf->SetXY($this->posxtva-5, $curY);
503  $pdf->MultiCell($this->posxup-$this->posxtva+4, 3, $vat_rate, 0, 'R');
504  }
505 
506  // Unit price before discount
507  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
508  $pdf->SetXY($this->posxup, $curY);
509  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
510 
511  // Quantity
512  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
513  $pdf->SetXY($this->posxqty, $curY);
514  // Enough for 6 chars
515 
516  if ($this->situationinvoice)
517  {
518  $pdf->MultiCell($this->posxprogress-$this->posxqty-0.8, 4, $qty, 0, 'R');
519  }
520  else if($conf->global->PRODUCT_USE_UNITS)
521  {
522  $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
523  }
524  else
525  {
526  $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
527  }
528 
529  // Situation progress
530  if ($this->situationinvoice)
531  {
532  $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
533  $pdf->SetXY($this->posxprogress, $curY);
534  if($conf->global->PRODUCT_USE_UNITS)
535  {
536  $pdf->MultiCell($this->posxunit-$this->posxprogress-1, 3, $progress, 0, 'R');
537  }
538  else if ($this->atleastonediscount)
539  {
540  $pdf->MultiCell($this->posxdiscount-$this->posxprogress-1, 3, $progress, 0, 'R');
541  }
542  else
543  {
544  $pdf->MultiCell($this->postotalht-$this->posxprogress-1, 3, $progress, 0, 'R');
545  }
546  }
547 
548  // Unit
549  if($conf->global->PRODUCT_USE_UNITS)
550  {
551  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
552  $pdf->SetXY($this->posxunit, $curY);
553  $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
554  }
555 
556  // Discount on line
557  if ($object->lines[$i]->remise_percent)
558  {
559  $pdf->SetXY($this->posxdiscount-2, $curY);
560  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
561  $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
562  }
563 
564  // Total HT line
565  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
566  $pdf->SetXY($this->postotalht, $curY);
567  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
568 
569 
570  $sign=1;
571  if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
572  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
573  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
574  if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) // Compute progress from previous situation
575  {
576  if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
577  else $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
578  } else {
579  if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne= $sign * $object->lines[$i]->multicurrency_total_tva;
580  else $tvaligne= $sign * $object->lines[$i]->total_tva;
581  }
582 
583  $localtax1ligne=$object->lines[$i]->total_localtax1;
584  $localtax2ligne=$object->lines[$i]->total_localtax2;
585  $localtax1_rate=$object->lines[$i]->localtax1_tx;
586  $localtax2_rate=$object->lines[$i]->localtax2_tx;
587  $localtax1_type=$object->lines[$i]->localtax1_type;
588  $localtax2_type=$object->lines[$i]->localtax2_type;
589 
590  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
591  if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
592  if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
593 
594  $vatrate=(string) $object->lines[$i]->tva_tx;
595 
596  // Retrieve type from database for backward compatibility with old records
597  if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
598  && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
599  {
600  $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc);
601  $localtax1_type = $localtaxtmp_array[0];
602  $localtax2_type = $localtaxtmp_array[2];
603  }
604 
605  // retrieve global local tax
606  if ($localtax1_type && $localtax1ligne != 0)
607  $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
608  if ($localtax2_type && $localtax2ligne != 0)
609  $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
610 
611  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
612  if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
613  $this->tva[$vatrate] += $tvaligne;
614 
615  if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
616 
617  // Add line
618  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
619  {
620  $pdf->setPage($pageposafter);
621  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
622  //$pdf->SetDrawColor(190,190,200);
623  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
624  $pdf->SetLineStyle(array('dash'=>0));
625  }
626 
627  $nexY+=2; // Passe espace entre les lignes
628 
629  // Detect if some page were added automatically and output _tableau for past pages
630  while ($pagenb < $pageposafter)
631  {
632  $pdf->setPage($pagenb);
633  if ($pagenb == 1)
634  {
635  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
636  }
637  else
638  {
639  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
640  }
641  $this->_pagefoot($pdf,$object,$outputlangs,1);
642  $pagenb++;
643  $pdf->setPage($pagenb);
644  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
645  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
646  }
647  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
648  {
649  if ($pagenb == 1)
650  {
651  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
652  }
653  else
654  {
655  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
656  }
657  $this->_pagefoot($pdf,$object,$outputlangs,1);
658  // New page
659  $pdf->AddPage();
660  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
661  $pagenb++;
662  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
663  }
664  }
665 
666  // Show square
667  if ($pagenb == 1)
668  {
669  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
670  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
671  }
672  else
673  {
674  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
675  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
676  }
677 
678  // Affiche zone infos
679  $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
680 
681  // Affiche zone totaux
682  $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
683 
684  // Affiche zone versements
685  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
686  {
687  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
688  }
689 
690  // Pied de page
691  $this->_pagefoot($pdf,$object,$outputlangs);
692  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
693 
694  $pdf->Close();
695 
696  $pdf->Output($file,'F');
697 
698  // Add pdfgeneration hook
699  $hookmanager->initHooks(array('pdfgeneration'));
700  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
701  global $action;
702  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
703 
704  if (! empty($conf->global->MAIN_UMASK))
705  @chmod($file, octdec($conf->global->MAIN_UMASK));
706 
707  $this->result = array('fullpath'=>$file);
708 
709  return 1; // No error
710  }
711  else
712  {
713  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
714  return 0;
715  }
716  }
717  else
718  {
719  $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
720  return 0;
721  }
722  }
723 
724 
734  function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
735  {
736  global $conf;
737 
738  $sign=1;
739  if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
740 
741  $tab3_posx = 120;
742  $tab3_top = $posy + 8;
743  $tab3_width = 80;
744  $tab3_height = 4;
745  if ($this->page_largeur < 210) // To work with US executive format
746  {
747  $tab3_posx -= 20;
748  }
749 
750  $default_font_size = pdf_getPDFFontSize($outputlangs);
751 
752  $title=$outputlangs->transnoentities("PaymentsAlreadyDone");
753  if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone");
754 
755  $pdf->SetFont('','', $default_font_size - 3);
756  $pdf->SetXY($tab3_posx, $tab3_top - 4);
757  $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
758 
759  $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top);
760 
761  $pdf->SetFont('','', $default_font_size - 4);
762  $pdf->SetXY($tab3_posx, $tab3_top);
763  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
764  $pdf->SetXY($tab3_posx+21, $tab3_top);
765  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
766  $pdf->SetXY($tab3_posx+40, $tab3_top);
767  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
768  $pdf->SetXY($tab3_posx+58, $tab3_top);
769  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
770 
771  $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
772 
773  $y=0;
774 
775  $pdf->SetFont('','', $default_font_size - 4);
776 
777 
778  // Loop on each deposits and credit notes included
779  $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
780  $sql.= " re.description, re.fk_facture_source,";
781  $sql.= " f.type, f.datef";
782  $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
783  $sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
784  $resql=$this->db->query($sql);
785  if ($resql)
786  {
787  $num = $this->db->num_rows($resql);
788  $i=0;
789  $invoice=new Facture($this->db);
790  while ($i < $num)
791  {
792  $y+=3;
793  $obj = $this->db->fetch_object($resql);
794 
795  if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
796  elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
797  else $text=$outputlangs->trans("UnknownType");
798 
799  $invoice->fetch($obj->fk_facture_source);
800 
801  $pdf->SetXY($tab3_posx, $tab3_top+$y);
802  $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
803  $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
804  $pdf->MultiCell(20, 3, price(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0);
805  $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
806  $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
807  $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
808  $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
809 
810  $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
811 
812  $i++;
813  }
814  }
815  else
816  {
817  $this->error=$this->db->lasterror();
818  return -1;
819  }
820 
821  // Loop on each payment
822  // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql
823  $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
824  $sql.= " cp.code";
825  $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
826  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id AND cp.entity IN (".getEntity('c_paiement').")";
827  $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id;
828  //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1";
829  $sql.= " ORDER BY p.datep";
830 
831  $resql=$this->db->query($sql);
832  if ($resql)
833  {
834  $num = $this->db->num_rows($resql);
835  $i=0;
836  while ($i < $num) {
837  $y+=3;
838  $row = $this->db->fetch_object($resql);
839 
840  $pdf->SetXY($tab3_posx, $tab3_top+$y);
841  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
842  $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
843  $pdf->MultiCell(20, 3, price($sign * (($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0);
844  $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
845  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code);
846 
847  $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
848  $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
849  $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
850 
851  $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3);
852 
853  $i++;
854  }
855  }
856  else
857  {
858  $this->error=$this->db->lasterror();
859  return -1;
860  }
861 
862  }
863 
864 
874  function _tableau_info(&$pdf, $object, $posy, $outputlangs)
875  {
876  global $conf;
877 
878  $default_font_size = pdf_getPDFFontSize($outputlangs);
879 
880  $pdf->SetFont('','', $default_font_size - 1);
881 
882  // If France, show VAT mention if not applicable
883  if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
884  {
885  $pdf->SetFont('','B', $default_font_size - 2);
886  $pdf->SetXY($this->marge_gauche, $posy);
887  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
888 
889  $posy=$pdf->GetY()+4;
890  }
891 
892  $posxval=52;
893 
894  // Show payments conditions
895  if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
896  {
897  $pdf->SetFont('','B', $default_font_size - 2);
898  $pdf->SetXY($this->marge_gauche, $posy);
899  $titre = $outputlangs->transnoentities("PaymentConditions").':';
900  $pdf->MultiCell(43, 4, $titre, 0, 'L');
901 
902  $pdf->SetFont('','', $default_font_size - 2);
903  $pdf->SetXY($posxval, $posy);
904  $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
905  $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
906  $pdf->MultiCell(67, 4, $lib_condition_paiement,0,'L');
907 
908  $posy=$pdf->GetY()+3;
909  }
910 
911  if ($object->type != 2)
912  {
913  // Check a payment mode is defined
914  if (empty($object->mode_reglement_code)
915  && empty($conf->global->FACTURE_CHQ_NUMBER)
916  && empty($conf->global->FACTURE_RIB_NUMBER))
917  {
918  $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured");
919  }
920  // Avoid having any valid PDF with setup that is not complete
921  elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
922  || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER) && empty($object->fk_account) && empty($object->fk_bank)))
923  {
924  $outputlangs->load("errors");
925 
926  $pdf->SetXY($this->marge_gauche, $posy);
927  $pdf->SetTextColor(200,0,0);
928  $pdf->SetFont('','B', $default_font_size - 2);
929  $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code);
930  $pdf->MultiCell(80, 3, $this->error,0,'L',0);
931  $pdf->SetTextColor(0,0,0);
932 
933  $posy=$pdf->GetY()+1;
934  }
935 
936  // Show payment mode
937  if ($object->mode_reglement_code
938  && $object->mode_reglement_code != 'CHQ'
939  && $object->mode_reglement_code != 'VIR')
940  {
941  $pdf->SetFont('','B', $default_font_size - 2);
942  $pdf->SetXY($this->marge_gauche, $posy);
943  $titre = $outputlangs->transnoentities("PaymentMode").':';
944  $pdf->MultiCell(80, 5, $titre, 0, 'L');
945 
946  $pdf->SetFont('','', $default_font_size - 2);
947  $pdf->SetXY($posxval, $posy);
948  $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);
949  $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
950 
951  $posy=$pdf->GetY()+2;
952  }
953 
954  // Show payment mode CHQ
955  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
956  {
957  // Si mode reglement non force ou si force a CHQ
958  if (! empty($conf->global->FACTURE_CHQ_NUMBER))
959  {
960  $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
961 
962  if ($conf->global->FACTURE_CHQ_NUMBER > 0)
963  {
964  $account = new Account($this->db);
965  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
966 
967  $pdf->SetXY($this->marge_gauche, $posy);
968  $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
969  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
970  $posy=$pdf->GetY()+1;
971 
972  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
973  {
974  $pdf->SetXY($this->marge_gauche, $posy);
975  $pdf->SetFont('','', $default_font_size - $diffsizetitle);
976  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
977  $posy=$pdf->GetY()+2;
978  }
979  }
980  if ($conf->global->FACTURE_CHQ_NUMBER == -1)
981  {
982  $pdf->SetXY($this->marge_gauche, $posy);
983  $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
984  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
985  $posy=$pdf->GetY()+1;
986 
987  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
988  {
989  $pdf->SetXY($this->marge_gauche, $posy);
990  $pdf->SetFont('','', $default_font_size - $diffsizetitle);
991  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
992  $posy=$pdf->GetY()+2;
993  }
994  }
995  }
996  }
997 
998  // If payment mode not forced or forced to VIR, show payment with BAN
999  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
1000  {
1001  if (! empty($object->fk_account) || ! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
1002  {
1003  $bankid=(empty($object->fk_account)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_account);
1004  if (! empty($object->fk_bank)) $bankid=$object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
1005  $account = new Account($this->db);
1006  $account->fetch($bankid);
1007 
1008  $curx=$this->marge_gauche;
1009  $cury=$posy;
1010 
1011  $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
1012 
1013  $posy+=2;
1014  }
1015  }
1016  }
1017 
1018  return $posy;
1019  }
1020 
1021 
1032  function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
1033  {
1034  global $conf,$mysoc;
1035 
1036  $sign=1;
1037  if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1038 
1039  $default_font_size = pdf_getPDFFontSize($outputlangs);
1040 
1041  $tab2_top = $posy;
1042  $tab2_hl = 4;
1043  $pdf->SetFont('','', $default_font_size - 1);
1044 
1045  // Tableau total
1046  $col1x = 120; $col2x = 170;
1047  if ($this->page_largeur < 210) // To work with US executive format
1048  {
1049  $col2x-=20;
1050  }
1051  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1052 
1053  $useborder=0;
1054  $index = 0;
1055 
1056  // Total HT
1057  $pdf->SetFillColor(255,255,255);
1058  $pdf->SetXY($col1x, $tab2_top + 0);
1059  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1060 
1061  $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
1062  $pdf->SetXY($col2x, $tab2_top + 0);
1063  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
1064 
1065  // Show VAT by rates and total
1066  $pdf->SetFillColor(248,248,248);
1067 
1068  $total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1069 
1070  $this->atleastoneratenotnull=0;
1071  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1072  {
1073  $tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
1074  if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
1075  {
1076  // Nothing to do
1077  }
1078  else
1079  {
1080  // FIXME amount of vat not supported with multicurrency
1081 
1082  //Local tax 1 before VAT
1083  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1084  //{
1085  foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1086  {
1087  if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1088 
1089  foreach( $localtax_rate as $tvakey => $tvaval )
1090  {
1091  if ($tvakey!=0) // On affiche pas taux 0
1092  {
1093  //$this->atleastoneratenotnull++;
1094 
1095  $index++;
1096  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1097 
1098  $tvacompl='';
1099  if (preg_match('/\*/',$tvakey))
1100  {
1101  $tvakey=str_replace('*','',$tvakey);
1102  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1103  }
1104 
1105  $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1106  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1107  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1108 
1109  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1110  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1111  }
1112  }
1113  }
1114  //}
1115  //Local tax 2 before VAT
1116  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1117  //{
1118  foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1119  {
1120  if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1121 
1122  foreach( $localtax_rate as $tvakey => $tvaval )
1123  {
1124  if ($tvakey!=0) // On affiche pas taux 0
1125  {
1126  //$this->atleastoneratenotnull++;
1127 
1128 
1129 
1130  $index++;
1131  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1132 
1133  $tvacompl='';
1134  if (preg_match('/\*/',$tvakey))
1135  {
1136  $tvakey=str_replace('*','',$tvakey);
1137  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1138  }
1139  $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1140  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1141  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1142 
1143  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1144  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1145 
1146  }
1147  }
1148  }
1149 
1150  //}
1151 
1152  // VAT
1153  // Situations totals migth be wrong on huge amounts
1154  if ($object->situation_cycle_ref && $object->situation_counter > 1) {
1155 
1156  $sum_pdf_tva = 0;
1157  foreach($this->tva as $tvakey => $tvaval){
1158  $sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
1159  }
1160 
1161  if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
1162  $coef_fix_tva = $object->total_tva / $sum_pdf_tva;
1163 
1164  foreach($this->tva as $tvakey => $tvaval) {
1165  $this->tva[$tvakey]=$tvaval * $coef_fix_tva;
1166  }
1167  }
1168 
1169  }
1170 
1171  foreach($this->tva as $tvakey => $tvaval)
1172  {
1173  if ($tvakey != 0) // On affiche pas taux 0
1174  {
1175  $this->atleastoneratenotnull++;
1176 
1177  $index++;
1178  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1179 
1180  $tvacompl='';
1181  if (preg_match('/\*/',$tvakey))
1182  {
1183  $tvakey=str_replace('*','',$tvakey);
1184  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1185  }
1186  $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1187  $totalvat.=vatrate($tvakey,1).$tvacompl;
1188  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1189 
1190  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1191  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1192  }
1193  }
1194 
1195  //Local tax 1 after VAT
1196  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1197  //{
1198  foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1199  {
1200  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1201 
1202  foreach( $localtax_rate as $tvakey => $tvaval )
1203  {
1204  if ($tvakey != 0) // On affiche pas taux 0
1205  {
1206  //$this->atleastoneratenotnull++;
1207 
1208  $index++;
1209  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1210 
1211  $tvacompl='';
1212  if (preg_match('/\*/',$tvakey))
1213  {
1214  $tvakey=str_replace('*','',$tvakey);
1215  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1216  }
1217  $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1218  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1219 
1220  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1221  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1222  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1223  }
1224  }
1225  }
1226  //}
1227  //Local tax 2 after VAT
1228  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1229  //{
1230  foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1231  {
1232  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1233 
1234  foreach( $localtax_rate as $tvakey => $tvaval )
1235  {
1236  // retrieve global local tax
1237  if ($tvakey != 0) // On affiche pas taux 0
1238  {
1239  //$this->atleastoneratenotnull++;
1240 
1241  $index++;
1242  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1243 
1244  $tvacompl='';
1245  if (preg_match('/\*/',$tvakey))
1246  {
1247  $tvakey=str_replace('*','',$tvakey);
1248  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1249  }
1250  $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1251 
1252  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1253  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1254 
1255  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1256  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1257  }
1258  }
1259  //}
1260  }
1261 
1262  // Revenue stamp
1263  if (price2num($object->revenuestamp) != 0)
1264  {
1265  $index++;
1266  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1267  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
1268 
1269  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1270  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
1271  }
1272 
1273  // Total TTC
1274  $index++;
1275  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1276  $pdf->SetTextColor(0,0,60);
1277  $pdf->SetFillColor(224,224,224);
1278  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1279 
1280  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1281  $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1282  }
1283  }
1284 
1285  $pdf->SetTextColor(0,0,0);
1286 
1287  $creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1288  $depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
1289  //print "x".$creditnoteamount."-".$depositsamount;exit;
1290  $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
1291  if ($object->paye) $resteapayer=0;
1292 
1293  if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0)
1294  {
1295  // Already paid + Deposits
1296  $index++;
1297  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1298  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
1299  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1300  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
1301 
1302  // Credit note
1303  if ($creditnoteamount)
1304  {
1305  $index++;
1306  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1307  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
1308  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1309  $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
1310  }
1311 
1312  // Escompte
1313  if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
1314  {
1315  $index++;
1316  $pdf->SetFillColor(255,255,255);
1317 
1318  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1319  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1320  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1321  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
1322 
1323  $resteapayer=0;
1324  }
1325 
1326  $index++;
1327  $pdf->SetTextColor(0,0,60);
1328  $pdf->SetFillColor(224,224,224);
1329  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1330  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1331  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1332  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1333 
1334  $pdf->SetFont('','', $default_font_size - 1);
1335  $pdf->SetTextColor(0,0,0);
1336  }
1337 
1338  $index++;
1339  return ($tab2_top + ($tab2_hl * $index));
1340  }
1341 
1355  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1356  {
1357  global $conf;
1358 
1359  // Force to disable hidetop and hidebottom
1360  $hidebottom=0;
1361  if ($hidetop) $hidetop=-1;
1362 
1363  $currency = !empty($currency) ? $currency : $conf->currency;
1364  $default_font_size = pdf_getPDFFontSize($outputlangs);
1365 
1366  // Amount in (at tab_top - 1)
1367  $pdf->SetTextColor(0,0,0);
1368  $pdf->SetFont('','', $default_font_size - 2);
1369 
1370  if (empty($hidetop))
1371  {
1372  $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1373  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1374  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1375 
1376  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1377  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));
1378  }
1379 
1380  $pdf->SetDrawColor(128,128,128);
1381  $pdf->SetFont('','', $default_font_size - 1);
1382 
1383  // Output Rect
1384  $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
1385 
1386  if (empty($hidetop))
1387  {
1388  $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
1389 
1390  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
1391  $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1392  }
1393 
1394  if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE))
1395  {
1396  $pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1397  if (empty($hidetop))
1398  {
1399  //$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1400  //$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1401  }
1402  }
1403 
1404  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
1405  {
1406  $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1407  if (empty($hidetop))
1408  {
1409  $pdf->SetXY($this->posxtva-3, $tab_top+1);
1410  $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1411  }
1412  }
1413 
1414  $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1415  if (empty($hidetop))
1416  {
1417  $pdf->SetXY($this->posxup-1, $tab_top+1);
1418  $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1419  }
1420 
1421  $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1422  if (empty($hidetop))
1423  {
1424  $pdf->SetXY($this->posxqty-1, $tab_top+1);
1425 
1426  if($this->situationinvoice)
1427  {
1428  $pdf->MultiCell($this->posxprogress-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1429  }
1430  else if($conf->global->PRODUCT_USE_UNITS)
1431  {
1432  $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1433  }
1434  else
1435  {
1436  $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1437  }
1438  }
1439 
1440  if ($this->situationinvoice) {
1441  $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1442 
1443  if (empty($hidetop)) {
1444 
1445  $pdf->SetXY($this->posxprogress, $tab_top+1);
1446 
1447  if($conf->global->PRODUCT_USE_UNITS)
1448  {
1449  $pdf->MultiCell($this->posxunit-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1450  }
1451  else if ($this->atleastonediscount)
1452  {
1453  $pdf->MultiCell($this->posxdiscount-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1454  }
1455  else
1456  {
1457  $pdf->MultiCell($this->postotalht-$this->posxprogress,2, $outputlangs->transnoentities("Progress"),'','C');
1458  }
1459 
1460  }
1461 
1462  }
1463 
1464  if($conf->global->PRODUCT_USE_UNITS) {
1465  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1466  if (empty($hidetop)) {
1467  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1468  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1469  'C');
1470  }
1471  }
1472 
1473  $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1474  if (empty($hidetop))
1475  {
1476  if ($this->atleastonediscount)
1477  {
1478  $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1479  $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1480  }
1481  }
1482 
1483  if ($this->situationinvoice)
1484  {
1485  $pdf->line($this->postotalht+4, $tab_top, $this->postotalht+4, $tab_top + $tab_height);
1486  if (empty($hidetop))
1487  {
1488  $pdf->SetXY($this->postotalht-19, $tab_top+1);
1489  $pdf->MultiCell(30,2, $outputlangs->transnoentities("Situation"),'','C');
1490  }
1491  }
1492 
1493  if ($this->atleastonediscount)
1494  {
1495  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1496  }
1497  if (empty($hidetop))
1498  {
1499  $pdf->SetXY($this->postotalht-1, $tab_top+1);
1500  $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1501  }
1502  }
1503 
1513  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1514  {
1515  global $conf,$langs;
1516 
1517  $outputlangs->load("main");
1518  $outputlangs->load("bills");
1519  $outputlangs->load("propal");
1520  $outputlangs->load("companies");
1521 
1522  $default_font_size = pdf_getPDFFontSize($outputlangs);
1523 
1524  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1525 
1526  // Show Draft Watermark
1527  if($object->statut==Facture::STATUS_DRAFT && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
1528  {
1529  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
1530  }
1531 
1532  $pdf->SetTextColor(0,0,60);
1533  $pdf->SetFont('','B', $default_font_size + 3);
1534 
1535  $w = 110;
1536 
1537  $posy=$this->marge_haute;
1538  $posx=$this->page_largeur-$this->marge_droite-$w;
1539 
1540  $pdf->SetXY($this->marge_gauche,$posy);
1541 
1542  // Logo
1543  $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1544  if ($this->emetteur->logo)
1545  {
1546  if (is_readable($logo))
1547  {
1548  $height=pdf_getHeightForLogo($logo);
1549  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1550  }
1551  else
1552  {
1553  $pdf->SetTextColor(200,0,0);
1554  $pdf->SetFont('','B',$default_font_size - 2);
1555  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1556  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1557  }
1558  }
1559  else
1560  {
1561  $text=$this->emetteur->name;
1562  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1563  }
1564 
1565  $pdf->SetFont('','B', $default_font_size + 3);
1566  $pdf->SetXY($posx,$posy);
1567  $pdf->SetTextColor(0,0,60);
1568  $title=$outputlangs->transnoentities("PdfInvoiceTitle");
1569  if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
1570  if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
1571  if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
1572  if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
1573  if ($this->situationinvoice) $title=$outputlangs->transnoentities("InvoiceSituation");
1574  $pdf->MultiCell($w, 3, $title, '', 'R');
1575 
1576  $pdf->SetFont('','B',$default_font_size);
1577 
1578  $posy+=5;
1579  $pdf->SetXY($posx,$posy);
1580  $pdf->SetTextColor(0,0,60);
1581  $textref=$outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref);
1582  if ($object->statut == Facture::STATUS_DRAFT)
1583  {
1584  $pdf->SetTextColor(128,0,0);
1585  $textref.=' - '.$outputlangs->transnoentities("NotValidated");
1586  }
1587  $pdf->MultiCell($w, 4, $textref, '', 'R');
1588 
1589  $posy+=1;
1590  $pdf->SetFont('','', $default_font_size - 2);
1591 
1592  if ($object->ref_client)
1593  {
1594  $posy+=4;
1595  $pdf->SetXY($posx,$posy);
1596  $pdf->SetTextColor(0,0,60);
1597  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1598  }
1599 
1600  $objectidnext=$object->getIdReplacingInvoice('validated');
1601  if ($object->type == 0 && $objectidnext)
1602  {
1603  $objectreplacing=new Facture($this->db);
1604  $objectreplacing->fetch($objectidnext);
1605 
1606  $posy+=3;
1607  $pdf->SetXY($posx,$posy);
1608  $pdf->SetTextColor(0,0,60);
1609  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
1610  }
1611  if ($object->type == 1)
1612  {
1613  $objectreplaced=new Facture($this->db);
1614  $objectreplaced->fetch($object->fk_facture_source);
1615 
1616  $posy+=4;
1617  $pdf->SetXY($posx,$posy);
1618  $pdf->SetTextColor(0,0,60);
1619  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1620  }
1621  if ($object->type == 2 && !empty($object->fk_facture_source))
1622  {
1623  $objectreplaced=new Facture($this->db);
1624  $objectreplaced->fetch($object->fk_facture_source);
1625 
1626  $posy+=3;
1627  $pdf->SetXY($posx,$posy);
1628  $pdf->SetTextColor(0,0,60);
1629  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
1630  }
1631 
1632  $posy+=4;
1633  $pdf->SetXY($posx,$posy);
1634  $pdf->SetTextColor(0,0,60);
1635  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
1636 
1637  if (! empty($conf->global->INVOICE_POINTOFTAX_DATE))
1638  {
1639  $posy+=4;
1640  $pdf->SetXY($posx,$posy);
1641  $pdf->SetTextColor(0,0,60);
1642  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R');
1643  }
1644 
1645  if ($object->type != 2)
1646  {
1647  $posy+=3;
1648  $pdf->SetXY($posx,$posy);
1649  $pdf->SetTextColor(0,0,60);
1650  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateDue")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
1651  }
1652 
1653  if ($object->thirdparty->code_client)
1654  {
1655  $posy+=3;
1656  $pdf->SetXY($posx,$posy);
1657  $pdf->SetTextColor(0,0,60);
1658  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1659  }
1660 
1661  // Get contact
1662  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1663  {
1664  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1665  if (count($arrayidcontact) > 0)
1666  {
1667  $usertmp=new User($this->db);
1668  $usertmp->fetch($arrayidcontact[0]);
1669  $posy+=4;
1670  $pdf->SetXY($posx,$posy);
1671  $pdf->SetTextColor(0,0,60);
1672  $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1673  }
1674  }
1675 
1676  $posy+=1;
1677 
1678  // Show list of linked objects
1679  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1680 
1681  if ($showaddress)
1682  {
1683  // Sender properties
1684  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
1685 
1686  // Show sender
1687  $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1688  $posx=$this->marge_gauche;
1689  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1690 
1691  $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1692  $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1693 
1694 
1695  // Show sender frame
1696  $pdf->SetTextColor(0,0,0);
1697  $pdf->SetFont('','', $default_font_size - 2);
1698  $pdf->SetXY($posx,$posy-5);
1699  $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1700  $pdf->SetXY($posx,$posy);
1701  $pdf->SetFillColor(230,230,230);
1702  $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1703  $pdf->SetTextColor(0,0,60);
1704 
1705  // Show sender name
1706  $pdf->SetXY($posx+2,$posy+3);
1707  $pdf->SetFont('','B', $default_font_size);
1708  $pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1709  $posy=$pdf->getY();
1710 
1711  // Show sender information
1712  $pdf->SetXY($posx+2,$posy);
1713  $pdf->SetFont('','', $default_font_size - 1);
1714  $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1715 
1716 
1717 
1718  // If BILLING contact defined on invoice, we use it
1719  $usecontact=false;
1720  $arrayidcontact=$object->getIdContact('external','BILLING');
1721  if (count($arrayidcontact) > 0)
1722  {
1723  $usecontact=true;
1724  $result=$object->fetch_contact($arrayidcontact[0]);
1725  }
1726 
1727  //Recipient name
1728  // On peut utiliser le nom de la societe du contact
1729  if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1730  $thirdparty = $object->contact;
1731  } else {
1732  $thirdparty = $object->thirdparty;
1733  }
1734 
1735  $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1736 
1737  $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1738 
1739  // Show recipient
1740  $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1741  if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
1742  $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1743  $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1744  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1745 
1746  // Show recipient frame
1747  $pdf->SetTextColor(0,0,0);
1748  $pdf->SetFont('','', $default_font_size - 2);
1749  $pdf->SetXY($posx+2,$posy-5);
1750  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":",0,'L');
1751  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1752 
1753  // Show recipient name
1754  $pdf->SetXY($posx+2,$posy+3);
1755  $pdf->SetFont('','B', $default_font_size);
1756  $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1757 
1758  $posy = $pdf->getY();
1759 
1760  // Show recipient information
1761  $pdf->SetFont('','', $default_font_size - 1);
1762  $pdf->SetXY($posx+2,$posy);
1763  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1764  }
1765 
1766  $pdf->SetTextColor(0,0,0);
1767  }
1768 
1778  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1779  {
1780  global $conf;
1781  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1782  return pdf_pagefoot($pdf,$outputlangs,'INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1783  }
1784 
1785 }
1786 
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:672
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:350
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:580
Class to manage PDF invoice template Crabe.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:623
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:384
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
Show total to pay.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:233
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:1744
Class to manage bank accounts.
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
Definition: pdf.lib.php:1870
Class to manage hooks.
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1472
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1607
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
Parent class of invoice document generators.
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
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
const STATUS_DRAFT
Draft.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
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
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
Definition: pdf.lib.php:1786
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
Definition: pdf.lib.php:1823
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...
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
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).
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
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)
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...
Class to manage invoices.
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
__construct($db)
Constructor.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...