dolibarr  9.0.0
pdf_aurore.modules.php
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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) 2017 Ferran Marcet <fmarcet@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  * or see http://www.gnu.org/
22  */
23 
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34 
35 
40 {
44  public $db;
45 
49  public $name;
50 
54  public $description;
55 
59  public $type;
60 
65  public $phpmin = array(5, 4);
66 
71  public $version = 'dolibarr';
72 
76  public $page_largeur;
77 
81  public $page_hauteur;
82 
86  public $format;
87 
91  public $marge_gauche;
92 
96  public $marge_droite;
97 
101  public $marge_haute;
102 
106  public $marge_basse;
107 
112  public $emetteur;
113 
114 
120  public function __construct($db)
121  {
122  global $conf, $langs, $mysoc;
123 
124  // Translations
125  $langs->loadLangs(array("main", "bills"));
126 
127  $this->db = $db;
128  $this->name = "aurore";
129  $this->description = $langs->trans('DocModelAuroreDescription');
130 
131  // Dimension page pour format A4
132  $this->type = 'pdf';
133  $formatarray=pdf_getFormat();
134  $this->page_largeur = $formatarray['width'];
135  $this->page_hauteur = $formatarray['height'];
136  $this->format = array($this->page_largeur,$this->page_hauteur);
137  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
138  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
139  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
140  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
141 
142  $this->option_logo = 1; // Affiche logo
143  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
144  $this->option_modereg = 1; // Affiche mode reglement
145  $this->option_condreg = 1; // Affiche conditions reglement
146  $this->option_codeproduitservice = 1; // Affiche code produit-service
147  $this->option_multilang = 1; // Dispo en plusieurs langues
148  $this->option_escompte = 1; // Affiche si il y a eu escompte
149  $this->option_credit_note = 1; // Support credit notes
150  $this->option_freetext = 1; // Support add of a personalised text
151  $this->option_draft_watermark = 1; //Support add of a watermark on drafts
152 
153  $this->franchise=!$mysoc->tva_assuj;
154 
155  // Get source company
156  $this->emetteur=$mysoc;
157  if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
158 
159  // Define position of columns
160  $this->posxdesc=$this->marge_gauche+1;
161  $this->posxdiscount=162;
162  $this->postotalht=174;
163 
164  if ($conf->global->PRODUCT_USE_UNITS)
165  {
166  $this->posxtva=101;
167  $this->posxup=118;
168  $this->posxqty=135;
169  $this->posxunit=151;
170  } else {
171  $this->posxtva=102;
172  $this->posxup=126;
173  $this->posxqty=145;
174  }
175 
176  if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxup=$this->posxtva;
177  $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
178  if ($this->page_largeur < 210) // To work with US executive format
179  {
180  $this->posxpicture-=20;
181  $this->posxtva-=20;
182  $this->posxup-=20;
183  $this->posxqty-=20;
184  $this->posxunit-=20;
185  $this->posxdiscount-=20;
186  $this->postotalht-=20;
187  }
188 
189  $this->tva=array();
190  $this->localtax1=array();
191  $this->localtax2=array();
192  $this->atleastoneratenotnull=0;
193  $this->atleastonediscount=0;
194  }
195 
196  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
208  function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
209  {
210  // phpcs:enable
211  global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
212 
213  if (! is_object($outputlangs)) $outputlangs=$langs;
214  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
215  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
216 
217  // Load traductions files requiredby by page
218  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "supplier_proposal"));
219 
220  $nblignes = count($object->lines);
221 
222  // Loop on each lines to detect if there is at least one image to show
223  $realpatharray=array();
224  if (! empty($conf->global->MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE))
225  {
226  for ($i = 0 ; $i < $nblignes ; $i++)
227  {
228  if (empty($object->lines[$i]->fk_product)) continue;
229 
230  $objphoto = new Product($this->db);
231  $objphoto->fetch($object->lines[$i]->fk_product);
232 
233  if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
234  {
235  $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
236  $dir = $conf->product->dir_output.'/'.$pdir;
237  }
238  else
239  {
240  $pdir = get_exdir(0,2,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
241  $dir = $conf->product->dir_output.'/'.$pdir;
242  }
243 
244  $realpath='';
245  foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
246  {
247  $filename=$obj['photo'];
248  //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
249  $realpath = $dir.$filename;
250  break;
251  }
252 
253  if ($realpath) $realpatharray[$i]=$realpath;
254  }
255  }
256  if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
257 
258  if ($conf->supplier_proposal->dir_output)
259  {
260  $object->fetch_thirdparty();
261 
262  // $deja_regle = 0;
263 
264  // Definition of $dir and $file
265  if ($object->specimen)
266  {
267  $dir = $conf->supplier_proposal->dir_output;
268  $file = $dir . "/SPECIMEN.pdf";
269  }
270  else
271  {
272  $objectref = dol_sanitizeFileName($object->ref);
273  $dir = $conf->supplier_proposal->dir_output . "/" . $objectref;
274  $file = $dir . "/" . $objectref . ".pdf";
275  }
276 
277  if (! file_exists($dir))
278  {
279  if (dol_mkdir($dir) < 0)
280  {
281  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
282  return 0;
283  }
284  }
285 
286  if (file_exists($dir))
287  {
288  // Add pdfgeneration hook
289  if (! is_object($hookmanager))
290  {
291  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
292  $hookmanager=new HookManager($this->db);
293  }
294  $hookmanager->initHooks(array('pdfgeneration'));
295  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
296  global $action;
297  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
298 
299  // Create pdf instance
300  $pdf=pdf_getInstance($this->format);
301  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
302  $heightforinfotot = 50; // Height reserved to output the info and total part
303  $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
304  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
305  if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
306  $pdf->SetAutoPageBreak(1,0);
307 
308  if (class_exists('TCPDF'))
309  {
310  $pdf->setPrintHeader(false);
311  $pdf->setPrintFooter(false);
312  }
313  $pdf->SetFont(pdf_getPDFFont($outputlangs));
314  // Set path to the background PDF File
315  if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
316  {
317  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
318  $tplidx = $pdf->importPage(1);
319  }
320 
321  $pdf->Open();
322  $pagenb=0;
323  $pdf->SetDrawColor(128,128,128);
324 
325  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
326  $pdf->SetSubject($outputlangs->transnoentities("CommercialAsk"));
327  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
328  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
329  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("CommercialAsk")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
330  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
331 
332  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
333 
334  // Positionne $this->atleastonediscount si on a au moins une remise
335  for ($i = 0 ; $i < $nblignes ; $i++)
336  {
337  if ($object->lines[$i]->remise_percent)
338  {
339  $this->atleastonediscount++;
340  }
341  }
342  if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
343  {
344  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
345  $this->posxtva+=($this->postotalht - $this->posxdiscount);
346  $this->posxup+=($this->postotalht - $this->posxdiscount);
347  $this->posxqty+=($this->postotalht - $this->posxdiscount);
348  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
349  //$this->postotalht;
350  }
351 
352  // New page
353  $pdf->AddPage();
354  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
355  $pagenb++;
356  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
357  $pdf->SetFont('','', $default_font_size - 1);
358  $pdf->MultiCell(0, 3, ''); // Set interline to 3
359  $pdf->SetTextColor(0,0,0);
360 
361  $tab_top = 90+$top_shift;
362  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
363 
364  // Affiche notes
365  $notetoshow=empty($object->note_public)?'':$object->note_public;
366  if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
367  {
368  // Get first sale rep
369  if (is_object($object->thirdparty))
370  {
371  $salereparray=$object->thirdparty->getSalesRepresentatives($user);
372  $salerepobj=new User($this->db);
373  $salerepobj->fetch($salereparray[0]['id']);
374  if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
375  }
376  }
377  if ($notetoshow)
378  {
379  $tab_top -= 2;
380 
381  $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
382  complete_substitutions_array($substitutionarray, $outputlangs, $object);
383  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
384 
385  $pdf->SetFont('','', $default_font_size - 1);
386  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($notetoshow), 0, 1);
387  $nexY = $pdf->GetY();
388  $height_note=$nexY-$tab_top;
389 
390  // Rect prend une longueur en 3eme param
391  $pdf->SetDrawColor(192,192,192);
392  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
393 
394  $tab_top = $nexY+6;
395  }
396 
397  $iniY = $tab_top + 7;
398  $curY = $tab_top + 7;
399  $nexY = $tab_top + 7;
400 
401  // Loop on each lines
402  for ($i = 0 ; $i < $nblignes ; $i++)
403  {
404  $curY = $nexY;
405  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
406  $pdf->SetTextColor(0,0,0);
407 
408  // Define size of image if we need it
409  $imglinesize=array();
410  if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
411 
412  $pdf->setTopMargin($tab_top_newpage);
413  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
414  $pageposbefore=$pdf->getPage();
415 
416  $showpricebeforepagebreak=1;
417  $posYAfterImage=0;
418  $posYAfterDescription=0;
419 
420  // We start with Photo of product line
421  if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page
422  {
423  $pdf->AddPage('','',true);
424  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
425  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
426  $pdf->setPage($pageposbefore+1);
427 
428  $curY = $tab_top_newpage;
429  $showpricebeforepagebreak=0;
430  }
431 
432  if (!empty($imglinesize['width']) && !empty($imglinesize['height']))
433  {
434  $curX = $this->posxpicture-1;
435  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
436  // $pdf->Image does not increase value return by getY, so we save it manually
437  $posYAfterImage=$curY+$imglinesize['height'];
438  }
439 
440  // Description of product line
441  $curX = $this->posxdesc-1;
442 
443  $pdf->startTransaction();
444  if ($posYAfterImage > 0)
445  {
446  $descWidth = $this->posxpicture-$curX;
447  }
448  else
449  {
450  $descWidth = $this->posxtva-$curX;
451  }
452  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$descWidth,3,$curX,$curY,$hideref,$hidedesc,1);
453 
454  $pageposafter=$pdf->getPage();
455  if ($pageposafter > $pageposbefore) // There is a pagebreak
456  {
457  $pdf->rollbackTransaction(true);
458  $pageposafter=$pageposbefore;
459  //print $pageposafter.'-'.$pageposbefore;exit;
460  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
461  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$descWidth,3,$curX,$curY,$hideref,$hidedesc);
462 
463  $pageposafter=$pdf->getPage();
464  $posyafter=$pdf->GetY();
465  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
466  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
467  {
468  if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
469  {
470  $pdf->AddPage('','',true);
471  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
472  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
473  $pdf->setPage($pageposafter+1);
474  }
475  }
476  else
477  {
478  // We found a page break
479  $showpricebeforepagebreak=0;
480  }
481  }
482  else // No pagebreak
483  {
484  $pdf->commitTransaction();
485  }
486  $posYAfterDescription=$pdf->GetY();
487 
488  $nexY = $pdf->GetY();
489  $pageposafter=$pdf->getPage();
490 
491  $pdf->setPage($pageposbefore);
492  $pdf->setTopMargin($this->marge_haute);
493  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
494 
495  // We suppose that a too long description or photo were moved completely on next page
496  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
497  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
498  }
499 
500  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
501 
502  // VAT Rate
503  /*
504  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
505  {
506  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
507  $pdf->SetXY($this->posxtva, $curY);
508  $pdf->MultiCell($this->posxup-$this->posxtva-3, 3, $vat_rate, 0, 'R');
509  }
510 
511  // Unit price before discount
512  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
513  $pdf->SetXY($this->posxup, $curY);
514  if ($up_excl_tax > 0)
515  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
516  */
517 
518  // Quantity
519  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
520  $pdf->SetXY($this->posxqty, $curY);
521  // Enough for 6 chars
522  if($conf->global->PRODUCT_USE_UNITS)
523  {
524  $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 3, $qty, 0, 'R');
525  }
526  else
527  {
528  $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R');
529  }
530 
531  // Unit
532  if($conf->global->PRODUCT_USE_UNITS)
533  {
534  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
535  $pdf->SetXY($this->posxunit, $curY);
536  $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
537  }
538 
539  // Discount on line
540  /*
541  if ($object->lines[$i]->remise_percent)
542  {
543  $pdf->SetXY($this->posxdiscount-2, $curY);
544  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
545  $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
546  }
547 
548  // Total HT line
549  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
550  $pdf->SetXY($this->postotalht, $curY);
551  if ($total_excl_tax > 0)
552  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
553  */
554 
555  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
556  if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
557  else $tvaligne=$object->lines[$i]->total_tva;
558 
559  $localtax1ligne=$object->lines[$i]->total_localtax1;
560  $localtax2ligne=$object->lines[$i]->total_localtax2;
561  $localtax1_rate=$object->lines[$i]->localtax1_tx;
562  $localtax2_rate=$object->lines[$i]->localtax2_tx;
563  $localtax1_type=$object->lines[$i]->localtax1_type;
564  $localtax2_type=$object->lines[$i]->localtax2_type;
565 
566  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
567  if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
568  if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
569 
570  $vatrate=(string) $object->lines[$i]->tva_tx;
571 
572  // Retrieve type from database for backward compatibility with old records
573  if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
574  && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
575  {
576  $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
577  $localtax1_type = $localtaxtmp_array[0];
578  $localtax2_type = $localtaxtmp_array[2];
579  }
580 
581  // retrieve global local tax
582  if ($localtax1_type && $localtax1ligne != 0)
583  $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
584  if ($localtax2_type && $localtax2ligne != 0)
585  $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
586 
587  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
588  if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
589  $this->tva[$vatrate] += $tvaligne;
590 
591  if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
592 
593  // Add line
594  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
595  {
596  $pdf->setPage($pageposafter);
597  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
598  //$pdf->SetDrawColor(190,190,200);
599  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
600  $pdf->SetLineStyle(array('dash'=>0));
601  }
602 
603  $nexY+=2; // Passe espace entre les lignes
604 
605  // Detect if some page were added automatically and output _tableau for past pages
606  while ($pagenb < $pageposafter)
607  {
608  $pdf->setPage($pagenb);
609  if ($pagenb == 1)
610  {
611  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
612  }
613  else
614  {
615  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
616  }
617  $this->_pagefoot($pdf,$object,$outputlangs,1);
618  $pagenb++;
619  $pdf->setPage($pagenb);
620  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
621  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
622  }
623  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
624  {
625  if ($pagenb == 1)
626  {
627  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
628  }
629  else
630  {
631  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
632  }
633  $this->_pagefoot($pdf,$object,$outputlangs,1);
634  // New page
635  $pdf->AddPage();
636  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
637  $pagenb++;
638  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
639  }
640  }
641 
642  // Show square
643  if ($pagenb == 1)
644  {
645  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
646  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
647  }
648  else
649  {
650  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
651  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
652  }
653 
654  // Affiche zone infos
655  $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
656 
657  // Affiche zone totaux
658  //$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
659 
660  // Affiche zone versements
661  /*
662  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
663  {
664  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
665  }
666  */
667 
668  // Pied de page
669  $this->_pagefoot($pdf,$object,$outputlangs);
670  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
671 
672  $pdf->Close();
673 
674  $pdf->Output($file,'F');
675 
676  //Add pdfgeneration hook
677  $hookmanager->initHooks(array('pdfgeneration'));
678  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
679  global $action;
680  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
681 
682  if (! empty($conf->global->MAIN_UMASK))
683  @chmod($file, octdec($conf->global->MAIN_UMASK));
684 
685  $this->result = array('fullpath'=>$file);
686 
687  return 1; // Pas d'erreur
688  }
689  else
690  {
691  $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
692  return 0;
693  }
694  }
695  else
696  {
697  $this->error=$langs->trans("ErrorConstantNotDefined","SUPPLIER_PROPOSAL_OUTPUTDIR");
698  return 0;
699  }
700  }
701 
702  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
712  function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
713  {
714  // phpcs:enable
715  }
716 
717 
718  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
728  function _tableau_info(&$pdf, $object, $posy, $outputlangs)
729  {
730  // phpcs:enable
731  global $conf;
732  $default_font_size = pdf_getPDFFontSize($outputlangs);
733 
734  $pdf->SetFont('','', $default_font_size - 1);
735 
736  $posxval=52;
737 
738  // Show shipping date
739  if (! empty($object->date_livraison))
740  {
741  $outputlangs->load("sendings");
742  $pdf->SetFont('','B', $default_font_size - 2);
743  $pdf->SetXY($this->marge_gauche, $posy);
744  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
745  $pdf->MultiCell(80, 4, $titre, 0, 'L');
746  $pdf->SetFont('','', $default_font_size - 2);
747  $pdf->SetXY($posxval, $posy);
748  $dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
749  $pdf->MultiCell(80, 4, $dlp, 0, 'L');
750 
751  $posy=$pdf->GetY()+1;
752  }
753  else {
754  $outputlangs->load("sendings");
755  $pdf->SetFont('','B', $default_font_size - 2);
756  $pdf->SetXY($this->marge_gauche, $posy);
757  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
758  $pdf->MultiCell(80, 4, $titre, 0, 'L');
759  $pdf->SetFont('','', $default_font_size - 2);
760  $pdf->SetXY($posxval, $posy);
761  //$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
762  $pdf->MultiCell(80, 4, $dlp, 0, 'L');
763 
764  $posy=$pdf->GetY()+1;
765  }
766  /* PHFAVRE
767  elseif ($object->availability_code || $object->availability) // Show availability conditions
768  {
769  $pdf->SetFont('','B', $default_font_size - 2);
770  $pdf->SetXY($this->marge_gauche, $posy);
771  $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
772  $pdf->MultiCell(80, 4, $titre, 0, 'L');
773  $pdf->SetTextColor(0,0,0);
774  $pdf->SetFont('','', $default_font_size - 2);
775  $pdf->SetXY($posxval, $posy);
776  $lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
777  $lib_availability=str_replace('\n',"\n",$lib_availability);
778  $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
779 
780  $posy=$pdf->GetY()+1;
781  }*/
782 
783  // Show payments conditions
784  if (empty($conf->global->SUPPLIER_PROPOSAL_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
785  {
786  $pdf->SetFont('','B', $default_font_size - 2);
787  $pdf->SetXY($this->marge_gauche, $posy);
788  $titre = $outputlangs->transnoentities("PaymentConditions").':';
789  $pdf->MultiCell(80, 4, $titre, 0, 'L');
790 
791  $pdf->SetFont('','', $default_font_size - 2);
792  $pdf->SetXY($posxval, $posy);
793  $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);
794  $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
795  $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
796 
797  $posy=$pdf->GetY()+3;
798  }
799 
800  if (! empty($conf->global->SUPPLIER_PROPOSAL_PDF_SHOW_PAYMENTTERMMODE))
801  {
802  // Show payment mode
803  if ($object->mode_reglement_code
804  && $object->mode_reglement_code != 'CHQ'
805  && $object->mode_reglement_code != 'VIR')
806  {
807  $pdf->SetFont('','B', $default_font_size - 2);
808  $pdf->SetXY($this->marge_gauche, $posy-2);
809  $titre = $outputlangs->transnoentities("PaymentMode").':';
810  $pdf->MultiCell(80, 5, $titre, 0, 'L');
811  $pdf->SetFont('','', $default_font_size - 2);
812  $pdf->SetXY($posxval, $posy-2);
813  $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);
814  $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
815 
816  $posy=$pdf->GetY()+2;
817  }
818 
819  // Show payment mode CHQ
820  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
821  {
822  // Si mode reglement non force ou si force a CHQ
823  if (! empty($conf->global->FACTURE_CHQ_NUMBER))
824  {
825  $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
826 
827  if ($conf->global->FACTURE_CHQ_NUMBER > 0)
828  {
829  $account = new Account($this->db);
830  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
831 
832  $pdf->SetXY($this->marge_gauche, $posy);
833  $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
834  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
835  $posy=$pdf->GetY()+1;
836 
837  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
838  {
839  $pdf->SetXY($this->marge_gauche, $posy);
840  $pdf->SetFont('','', $default_font_size - $diffsizetitle);
841  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
842  $posy=$pdf->GetY()+2;
843  }
844  }
845  if ($conf->global->FACTURE_CHQ_NUMBER == -1)
846  {
847  $pdf->SetXY($this->marge_gauche, $posy);
848  $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
849  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
850  $posy=$pdf->GetY()+1;
851 
852  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
853  {
854  $pdf->SetXY($this->marge_gauche, $posy);
855  $pdf->SetFont('','', $default_font_size - $diffsizetitle);
856  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
857  $posy=$pdf->GetY()+2;
858  }
859  }
860  }
861  }
862 
863  // If payment mode not forced or forced to VIR, show payment with BAN
864  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
865  {
866  if (! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
867  {
868  $bankid=(empty($object->fk_bank)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_bank);
869  $account = new Account($this->db);
870  $account->fetch($bankid);
871 
872  $curx=$this->marge_gauche;
873  $cury=$posy;
874 
875  $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
876 
877  $posy+=2;
878  }
879  }
880  }
881 
882  return $posy;
883  }
884 
885 
886  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
897  function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
898  {
899  // phpcs:enable
900  global $conf,$mysoc;
901  $default_font_size = pdf_getPDFFontSize($outputlangs);
902 
903  $tab2_top = $posy;
904  $tab2_hl = 4;
905  $pdf->SetFont('','', $default_font_size - 1);
906 
907  // Tableau total
908  $col1x = 120; $col2x = 170;
909  if ($this->page_largeur < 210) // To work with US executive format
910  {
911  $col2x-=20;
912  }
913  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
914 
915  $useborder=0;
916  $index = 0;
917 
918  // Total HT
919  $pdf->SetFillColor(255,255,255);
920  $pdf->SetXY($col1x, $tab2_top + 0);
921  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
922 
923  $pdf->SetXY($col2x, $tab2_top + 0);
924  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
925 
926  // Show VAT by rates and total
927  $pdf->SetFillColor(248,248,248);
928 
929  $this->atleastoneratenotnull=0;
930  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
931  {
932  $tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
933  if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
934  {
935  // Nothing to do
936  }
937  else
938  {
939  //Local tax 1 before VAT
940  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
941  //{
942  foreach( $this->localtax1 as $localtax_type => $localtax_rate )
943  {
944  if (in_array((string) $localtax_type, array('1','3','5'))) continue;
945 
946  foreach( $localtax_rate as $tvakey => $tvaval )
947  {
948  if ($tvakey!=0) // On affiche pas taux 0
949  {
950  //$this->atleastoneratenotnull++;
951 
952  $index++;
953  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
954 
955  $tvacompl='';
956  if (preg_match('/\*/',$tvakey))
957  {
958  $tvakey=str_replace('*','',$tvakey);
959  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
960  }
961  $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
962  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
963  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
964 
965  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
966  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
967  }
968  }
969  }
970  //}
971  //Local tax 2 before VAT
972  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
973  //{
974  foreach( $this->localtax2 as $localtax_type => $localtax_rate )
975  {
976  if (in_array((string) $localtax_type, array('1','3','5'))) continue;
977 
978  foreach( $localtax_rate as $tvakey => $tvaval )
979  {
980  if ($tvakey!=0) // On affiche pas taux 0
981  {
982  //$this->atleastoneratenotnull++;
983 
984 
985 
986  $index++;
987  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
988 
989  $tvacompl='';
990  if (preg_match('/\*/',$tvakey))
991  {
992  $tvakey=str_replace('*','',$tvakey);
993  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
994  }
995  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
996  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
997  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
998 
999  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1000  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1001  }
1002  }
1003  }
1004  //}
1005  // VAT
1006  foreach($this->tva as $tvakey => $tvaval)
1007  {
1008  if ($tvakey > 0) // On affiche pas taux 0
1009  {
1010  $this->atleastoneratenotnull++;
1011 
1012  $index++;
1013  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1014 
1015  $tvacompl='';
1016  if (preg_match('/\*/',$tvakey))
1017  {
1018  $tvakey=str_replace('*','',$tvakey);
1019  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1020  }
1021  $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
1022  $totalvat.=vatrate($tvakey,1).$tvacompl;
1023  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1024 
1025  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1026  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1027  }
1028  }
1029 
1030  //Local tax 1 after VAT
1031  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1032  //{
1033  foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1034  {
1035  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1036 
1037  foreach( $localtax_rate as $tvakey => $tvaval )
1038  {
1039  if ($tvakey != 0) // On affiche pas taux 0
1040  {
1041  //$this->atleastoneratenotnull++;
1042 
1043  $index++;
1044  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1045 
1046  $tvacompl='';
1047  if (preg_match('/\*/',$tvakey))
1048  {
1049  $tvakey=str_replace('*','',$tvakey);
1050  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1051  }
1052  $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1053 
1054  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1055  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1056  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1057  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1058  }
1059  }
1060  }
1061  //}
1062  //Local tax 2 after VAT
1063  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1064  //{
1065  foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1066  {
1067  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1068 
1069  foreach( $localtax_rate as $tvakey => $tvaval )
1070  {
1071  // retrieve global local tax
1072  if ($tvakey != 0) // On affiche pas taux 0
1073  {
1074  //$this->atleastoneratenotnull++;
1075 
1076  $index++;
1077  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1078 
1079  $tvacompl='';
1080  if (preg_match('/\*/',$tvakey))
1081  {
1082  $tvakey=str_replace('*','',$tvakey);
1083  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1084  }
1085  $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1086 
1087  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1088  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1089 
1090  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1091  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1092  }
1093  }
1094  }
1095  //}
1096 
1097  // Total TTC
1098  $index++;
1099  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1100  $pdf->SetTextColor(0,0,60);
1101  $pdf->SetFillColor(224,224,224);
1102  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1103 
1104  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1105  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1106  }
1107  }
1108 
1109  $pdf->SetTextColor(0,0,0);
1110 
1111  /*
1112  $resteapayer = $object->total_ttc - $deja_regle;
1113  if (! empty($object->paye)) $resteapayer=0;
1114  */
1115 
1116  if ($deja_regle > 0)
1117  {
1118  $index++;
1119 
1120  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1121  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1122 
1123  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1124  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1125 
1126  /*
1127  if ($object->close_code == 'discount_vat')
1128  {
1129  $index++;
1130  $pdf->SetFillColor(255,255,255);
1131 
1132  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1133  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1134 
1135  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1136  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1137 
1138  $resteapayer=0;
1139  }
1140  */
1141 
1142  $index++;
1143  $pdf->SetTextColor(0,0,60);
1144  $pdf->SetFillColor(224,224,224);
1145  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1146  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1147 
1148  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1149  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1150 
1151  $pdf->SetFont('','', $default_font_size - 1);
1152  $pdf->SetTextColor(0,0,0);
1153  }
1154 
1155  $index++;
1156  return ($tab2_top + ($tab2_hl * $index));
1157  }
1158 
1172  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1173  {
1174  global $conf;
1175 
1176  // Force to disable hidetop and hidebottom
1177  $hidebottom=0;
1178  if ($hidetop) $hidetop=-1;
1179 
1180  $currency = !empty($currency) ? $currency : $conf->currency;
1181  $default_font_size = pdf_getPDFFontSize($outputlangs);
1182 
1183  // Amount in (at tab_top - 1)
1184  $pdf->SetTextColor(0,0,0);
1185  $pdf->SetFont('','',$default_font_size - 2);
1186 
1187  if (empty($hidetop))
1188  {
1189  $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1190  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1191  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1192 
1193  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1194  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));
1195  }
1196 
1197  $pdf->SetDrawColor(128,128,128);
1198  $pdf->SetFont('','',$default_font_size - 1);
1199 
1200  // Output Rect
1201  $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
1202 
1203  if (empty($hidetop))
1204  {
1205  $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
1206 
1207  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
1208  $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1209  }
1210 
1211  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1212  {
1213  $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1214  //$pdf->line($this->posxtva-2, $tab_top, $this->posxtva-2, $tab_top + $tab_height);
1215  if (empty($hidetop))
1216  {
1217  $pdf->SetXY($this->posxtva-5, $tab_top+1);
1218  $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1219  }
1220  }
1221 
1222  $pdf->line($this->posxup-3, $tab_top, $this->posxup-3, $tab_top + $tab_height);
1223  if (empty($hidetop))
1224  {
1225  $pdf->SetXY($this->posxup-1, $tab_top+1);
1226  $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1227  }
1228 
1229  $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1230  if (empty($hidetop))
1231  {
1232  $pdf->SetXY($this->posxqty-1, $tab_top+1);
1233  if($conf->global->PRODUCT_USE_UNITS)
1234  {
1235  $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1236  }
1237  else
1238  {
1239  $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1240  }
1241  }
1242 
1243  if($conf->global->PRODUCT_USE_UNITS) {
1244  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1245  if (empty($hidetop)) {
1246  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1247  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
1248  'C');
1249  }
1250  }
1251 
1252  $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1253  if (empty($hidetop))
1254  {
1255  if ($this->atleastonediscount)
1256  {
1257  $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1258  $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1259  }
1260  }
1261  if ($this->atleastonediscount)
1262  {
1263  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1264  }
1265  if (empty($hidetop))
1266  {
1267  $pdf->SetXY($this->postotalht-1, $tab_top+1);
1268  $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1269  }
1270  }
1271 
1281  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1282  {
1283  global $conf, $langs;
1284 
1285  // Load traductions files requiredby by page
1286  $outputlangs->loadLangs(array("main", "bills", "supplier_proposal", "companies"));
1287 
1288  $default_font_size = pdf_getPDFFontSize($outputlangs);
1289 
1290  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1291 
1292  // Show Draft Watermark
1293  if($object->statut==0 && (! empty($conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK)) )
1294  {
1295  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK);
1296  }
1297 
1298  $pdf->SetTextColor(0,0,60);
1299  $pdf->SetFont('','B', $default_font_size + 3);
1300 
1301  $posy=$this->marge_haute;
1302  $posx=$this->page_largeur-$this->marge_droite-100;
1303 
1304  $pdf->SetXY($this->marge_gauche,$posy);
1305 
1306  // Logo
1307  $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1308  if ($this->emetteur->logo)
1309  {
1310  if (is_readable($logo))
1311  {
1312  $height=pdf_getHeightForLogo($logo);
1313  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1314  }
1315  else
1316  {
1317  $pdf->SetTextColor(200,0,0);
1318  $pdf->SetFont('','B',$default_font_size - 2);
1319  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1320  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1321  }
1322  }
1323  else
1324  {
1325  $text=$this->emetteur->name;
1326  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1327  }
1328 
1329  $pdf->SetFont('','B',$default_font_size + 3);
1330  $pdf->SetXY($posx,$posy);
1331  $pdf->SetTextColor(0,0,60);
1332  $title=$outputlangs->transnoentities("CommercialAsk");
1333  $pdf->MultiCell(100, 4, $title, '', 'R');
1334 
1335  $pdf->SetFont('','B',$default_font_size);
1336 
1337  $posy+=5;
1338  $pdf->SetXY($posx,$posy);
1339  $pdf->SetTextColor(0,0,60);
1340  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1341 
1342  $posy+=1;
1343  $pdf->SetFont('','', $default_font_size - 2);
1344 
1345  if ($object->ref_client)
1346  {
1347  $posy+=4;
1348  $pdf->SetXY($posx,$posy);
1349  $pdf->SetTextColor(0,0,60);
1350  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1351  }
1352 /* PHFAVRE
1353  $posy+=4;
1354  $pdf->SetXY($posx,$posy);
1355  $pdf->SetTextColor(0,0,60);
1356  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierProposalDate")." : " . dol_print_date($object->date_livraison,"day",false,$outputlangs,true), '', 'R');
1357 */
1358 
1359  if ($object->thirdparty->code_fournisseur)
1360  {
1361  $posy+=4;
1362  $pdf->SetXY($posx,$posy);
1363  $pdf->SetTextColor(0,0,60);
1364  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1365  }
1366 
1367  // Get contact
1368  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1369  {
1370  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1371  if (count($arrayidcontact) > 0)
1372  {
1373  $usertmp=new User($this->db);
1374  $usertmp->fetch($arrayidcontact[0]);
1375  $posy+=4;
1376  $pdf->SetXY($posx,$posy);
1377  $pdf->SetTextColor(0,0,60);
1378  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1379  }
1380  }
1381 
1382  $posy+=2;
1383 
1384  $top_shift = 0;
1385  // Show list of linked objects
1386  $current_y = $pdf->getY();
1387  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1388  if ($current_y < $pdf->getY())
1389  {
1390  $top_shift = $pdf->getY() - $current_y;
1391  }
1392 
1393  if ($showaddress)
1394  {
1395  // Sender properties
1396  $carac_emetteur='';
1397  // Add internal contact of proposal if defined
1398  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1399  if (count($arrayidcontact) > 0)
1400  {
1401  $object->fetch_user($arrayidcontact[0]);
1402  $labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1403  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1404  }
1405 
1406  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1407 
1408  // Show sender
1409  $posy=42+$top_shift;
1410  $posx=$this->marge_gauche;
1411  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1412  $hautcadre=40;
1413 
1414  // Show sender frame
1415  $pdf->SetTextColor(0,0,0);
1416  $pdf->SetFont('','', $default_font_size - 2);
1417  $pdf->SetXY($posx,$posy-5);
1418  $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1419  $pdf->SetXY($posx,$posy);
1420  $pdf->SetFillColor(230,230,230);
1421  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1422  $pdf->SetTextColor(0,0,60);
1423 
1424  // Show sender name
1425  $pdf->SetXY($posx+2,$posy+3);
1426  $pdf->SetFont('','B', $default_font_size);
1427  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1428  $posy=$pdf->getY();
1429 
1430  // Show sender information
1431  $pdf->SetXY($posx+2,$posy);
1432  $pdf->SetFont('','', $default_font_size - 1);
1433  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1434 
1435 
1436  // If CUSTOMER contact defined, we use it
1437  $usecontact=false;
1438  $arrayidcontact=$object->getIdContact('external','CUSTOMER');
1439  if (count($arrayidcontact) > 0)
1440  {
1441  $usecontact=true;
1442  $result=$object->fetch_contact($arrayidcontact[0]);
1443  }
1444 
1445  // Recipient name
1446  if (! empty($usecontact))
1447  {
1448  // On peut utiliser le nom de la societe du contact
1449  if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname;
1450  else $socname = $object->thirdparty->name;
1451  $carac_client_name=$outputlangs->convToOutputCharset($socname);
1452  }
1453  else
1454  {
1455  $carac_client_name=$outputlangs->convToOutputCharset($object->thirdparty->name);
1456  }
1457 
1458  $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1459 
1460  // Show recipient
1461  $widthrecbox=100;
1462  if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
1463  $posy=42+$top_shift;
1464  $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1465  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1466 
1467  // Show recipient frame
1468  $pdf->SetTextColor(0,0,0);
1469  $pdf->SetFont('','', $default_font_size - 2);
1470  $pdf->SetXY($posx+2,$posy-5);
1471  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1472  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1473 
1474  // Show recipient name
1475  $pdf->SetXY($posx+2,$posy+3);
1476  $pdf->SetFont('','B', $default_font_size);
1477  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1478 
1479  // Show recipient information
1480  $pdf->SetFont('','', $default_font_size - 1);
1481  $pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4));
1482  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1483  }
1484 
1485  $pdf->SetTextColor(0,0,0);
1486  return $top_shift;
1487  }
1488 
1498  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1499  {
1500  global $conf;
1501  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1502  return pdf_pagefoot($pdf,$outputlangs,'SUPPLIER_PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1503  }
1504 }
__construct($db)
Constructor.
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:692
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:600
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:643
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:353
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:224
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:41
_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:201
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Classe mere des modeles de propale.
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
Definition: pdf.lib.php:1798
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Class to manage bank accounts.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
Class to manage hooks.
type
Definition: viewcat.php:284
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1661
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:872
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2170
Class to generate PDF proposal Azur.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:245
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1119
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
$version
Dolibarr version of the loaded document string.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:623
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1158
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formated text with and (WARNING: string must not have mixed and br sepa...
_tableau_versements(&$pdf, $object, $posy, $outputlangs)
Show payments table.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...