dolibarr  7.0.0-beta
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@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) 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 {
41  var $db;
42  var $name;
43  var $description;
44  var $type;
45 
46  var $phpmin = array(4,3,0); // Minimum version of PHP required by module
47  var $version = 'dolibarr';
48 
49  var $page_largeur;
50  var $page_hauteur;
51  var $format;
52  var $marge_gauche;
53  var $marge_droite;
54  var $marge_haute;
55  var $marge_basse;
56 
57  var $emetteur; // Objet societe qui emet
58 
59 
65  function __construct($db)
66  {
67  global $conf,$langs,$mysoc;
68 
69  $langs->load("main");
70  $langs->load("bills");
71 
72  $this->db = $db;
73  $this->name = "aurore";
74  $this->description = $langs->trans('DocModelAuroreDescription');
75 
76  // Dimension page pour format A4
77  $this->type = 'pdf';
78  $formatarray=pdf_getFormat();
79  $this->page_largeur = $formatarray['width'];
80  $this->page_hauteur = $formatarray['height'];
81  $this->format = array($this->page_largeur,$this->page_hauteur);
82  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
83  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
84  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
85  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
86 
87  $this->option_logo = 1; // Affiche logo
88  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
89  $this->option_modereg = 1; // Affiche mode reglement
90  $this->option_condreg = 1; // Affiche conditions reglement
91  $this->option_codeproduitservice = 1; // Affiche code produit-service
92  $this->option_multilang = 1; // Dispo en plusieurs langues
93  $this->option_escompte = 1; // Affiche si il y a eu escompte
94  $this->option_credit_note = 1; // Support credit notes
95  $this->option_freetext = 1; // Support add of a personalised text
96  $this->option_draft_watermark = 1; //Support add of a watermark on drafts
97 
98  $this->franchise=!$mysoc->tva_assuj;
99 
100  // Get source company
101  $this->emetteur=$mysoc;
102  if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
103 
104  // Define position of columns
105  $this->posxdesc=$this->marge_gauche+1;
106  $this->posxtva=102;
107  $this->posxup=126;
108  $this->posxqty=145;
109  $this->posxdiscount=162;
110  $this->postotalht=174;
111  if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxup=$this->posxtva;
112  $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
113  if ($this->page_largeur < 210) // To work with US executive format
114  {
115  $this->posxpicture-=20;
116  $this->posxtva-=20;
117  $this->posxup-=20;
118  $this->posxqty-=20;
119  $this->posxunit-=20;
120  $this->posxdiscount-=20;
121  $this->postotalht-=20;
122  }
123 
124  $this->tva=array();
125  $this->localtax1=array();
126  $this->localtax2=array();
127  $this->atleastoneratenotnull=0;
128  $this->atleastonediscount=0;
129  }
130 
142  function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
143  {
144  global $user,$langs,$conf,$mysoc,$db,$hookmanager;
145 
146  if (! is_object($outputlangs)) $outputlangs=$langs;
147  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
148  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
149 
150  $outputlangs->load("main");
151  $outputlangs->load("dict");
152  $outputlangs->load("companies");
153  $outputlangs->load("bills");
154  $outputlangs->load("supplier_proposal");
155  $outputlangs->load("products");
156 
157  $nblignes = count($object->lines);
158 
159  // Loop on each lines to detect if there is at least one image to show
160  $realpatharray=array();
161  if (! empty($conf->global->MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE))
162  {
163  for ($i = 0 ; $i < $nblignes ; $i++)
164  {
165  if (empty($object->lines[$i]->fk_product)) continue;
166 
167  $objphoto = new Product($this->db);
168  $objphoto->fetch($object->lines[$i]->fk_product);
169 
170  if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
171  {
172  $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
173  $dir = $conf->product->dir_output.'/'.$pdir;
174  }
175  else
176  {
177  $pdir = get_exdir(0,2,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/';
178  $dir = $conf->product->dir_output.'/'.$pdir;
179  }
180 
181  $realpath='';
182  foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
183  {
184  $filename=$obj['photo'];
185  //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
186  $realpath = $dir.$filename;
187  break;
188  }
189 
190  if ($realpath) $realpatharray[$i]=$realpath;
191  }
192  }
193  if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
194 
195  if ($conf->supplier_proposal->dir_output)
196  {
197  $object->fetch_thirdparty();
198 
199  // $deja_regle = 0;
200 
201  // Definition of $dir and $file
202  if ($object->specimen)
203  {
204  $dir = $conf->supplier_proposal->dir_output;
205  $file = $dir . "/SPECIMEN.pdf";
206  }
207  else
208  {
209  $objectref = dol_sanitizeFileName($object->ref);
210  $dir = $conf->supplier_proposal->dir_output . "/" . $objectref;
211  $file = $dir . "/" . $objectref . ".pdf";
212  }
213 
214  if (! file_exists($dir))
215  {
216  if (dol_mkdir($dir) < 0)
217  {
218  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
219  return 0;
220  }
221  }
222 
223  if (file_exists($dir))
224  {
225  // Add pdfgeneration hook
226  if (! is_object($hookmanager))
227  {
228  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
229  $hookmanager=new HookManager($this->db);
230  }
231  $hookmanager->initHooks(array('pdfgeneration'));
232  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
233  global $action;
234  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
235 
236  // Create pdf instance
237  $pdf=pdf_getInstance($this->format);
238  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
239  $heightforinfotot = 50; // Height reserved to output the info and total part
240  $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
241  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
242  $pdf->SetAutoPageBreak(1,0);
243 
244  if (class_exists('TCPDF'))
245  {
246  $pdf->setPrintHeader(false);
247  $pdf->setPrintFooter(false);
248  }
249  $pdf->SetFont(pdf_getPDFFont($outputlangs));
250  // Set path to the background PDF File
251  if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
252  {
253  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
254  $tplidx = $pdf->importPage(1);
255  }
256 
257  $pdf->Open();
258  $pagenb=0;
259  $pdf->SetDrawColor(128,128,128);
260 
261  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
262  $pdf->SetSubject($outputlangs->transnoentities("CommercialAsk"));
263  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
264  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
265  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("CommercialAsk")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
266  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
267 
268  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
269 
270  // Positionne $this->atleastonediscount si on a au moins une remise
271  for ($i = 0 ; $i < $nblignes ; $i++)
272  {
273  if ($object->lines[$i]->remise_percent)
274  {
275  $this->atleastonediscount++;
276  }
277  }
278  if (empty($this->atleastonediscount))
279  {
280  $this->posxpicture+=($this->postotalht - $this->posxdiscount);
281  $this->posxtva+=($this->postotalht - $this->posxdiscount);
282  $this->posxup+=($this->postotalht - $this->posxdiscount);
283  $this->posxqty+=($this->postotalht - $this->posxdiscount);
284  $this->posxdiscount+=($this->postotalht - $this->posxdiscount);
285  //$this->postotalht;
286  }
287 
288  // New page
289  $pdf->AddPage();
290  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
291  $pagenb++;
292  $this->_pagehead($pdf, $object, 1, $outputlangs);
293  $pdf->SetFont('','', $default_font_size - 1);
294  $pdf->MultiCell(0, 3, ''); // Set interline to 3
295  $pdf->SetTextColor(0,0,0);
296 
297  $tab_top = 90;
298  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
299  $tab_height = 130;
300  $tab_height_newpage = 150;
301 
302  // Affiche notes
303  $notetoshow=empty($object->note_public)?'':$object->note_public;
304  if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
305  {
306  // Get first sale rep
307  if (is_object($object->thirdparty))
308  {
309  $salereparray=$object->thirdparty->getSalesRepresentatives($user);
310  $salerepobj=new User($this->db);
311  $salerepobj->fetch($salereparray[0]['id']);
312  if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
313  }
314  }
315  if ($notetoshow)
316  {
317  $tab_top = 88;
318 
319  $pdf->SetFont('','', $default_font_size - 1);
320  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
321  $nexY = $pdf->GetY();
322  $height_note=$nexY-$tab_top;
323 
324  // Rect prend une longueur en 3eme param
325  $pdf->SetDrawColor(192,192,192);
326  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
327 
328  $tab_height = $tab_height - $height_note;
329  $tab_top = $nexY+6;
330  }
331  else
332  {
333  $height_note=0;
334  }
335 
336  $iniY = $tab_top + 7;
337  $curY = $tab_top + 7;
338  $nexY = $tab_top + 7;
339 
340  // Loop on each lines
341  for ($i = 0 ; $i < $nblignes ; $i++)
342  {
343  $curY = $nexY;
344  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
345  $pdf->SetTextColor(0,0,0);
346 
347  // Define size of image if we need it
348  $imglinesize=array();
349  if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
350 
351  $pdf->setTopMargin($tab_top_newpage);
352  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
353  $pageposbefore=$pdf->getPage();
354 
355  $showpricebeforepagebreak=1;
356  $posYAfterImage=0;
357  $posYAfterDescription=0;
358 
359  // We start with Photo of product line
360  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
361  {
362  $pdf->AddPage('','',true);
363  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
364  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
365  $pdf->setPage($pageposbefore+1);
366 
367  $curY = $tab_top_newpage;
368  $showpricebeforepagebreak=0;
369  }
370 
371  if (!empty($imglinesize['width']) && !empty($imglinesize['height']))
372  {
373  $curX = $this->posxpicture-1;
374  $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
375  // $pdf->Image does not increase value return by getY, so we save it manually
376  $posYAfterImage=$curY+$imglinesize['height'];
377  }
378 
379  // Description of product line
380  $curX = $this->posxdesc-1;
381 
382  $pdf->startTransaction();
383  if ($posYAfterImage > 0)
384  {
385  $descWidth = $this->posxpicture-$curX;
386  }
387  else
388  {
389  $descWidth = $this->posxtva-$curX;
390  }
391  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$descWidth,3,$curX,$curY,$hideref,$hidedesc,1);
392 
393  $pageposafter=$pdf->getPage();
394  if ($pageposafter > $pageposbefore) // There is a pagebreak
395  {
396  $pdf->rollbackTransaction(true);
397  $pageposafter=$pageposbefore;
398  //print $pageposafter.'-'.$pageposbefore;exit;
399  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
400  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$descWidth,3,$curX,$curY,$hideref,$hidedesc);
401 
402  $pageposafter=$pdf->getPage();
403  $posyafter=$pdf->GetY();
404  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
405  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
406  {
407  if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
408  {
409  $pdf->AddPage('','',true);
410  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
411  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
412  $pdf->setPage($pageposafter+1);
413  }
414  }
415  else
416  {
417  // We found a page break
418  $showpricebeforepagebreak=0;
419  }
420  }
421  else // No pagebreak
422  {
423  $pdf->commitTransaction();
424  }
425  $posYAfterDescription=$pdf->GetY();
426 
427  $nexY = $pdf->GetY();
428  $pageposafter=$pdf->getPage();
429 
430  $pdf->setPage($pageposbefore);
431  $pdf->setTopMargin($this->marge_haute);
432  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
433 
434  // We suppose that a too long description or photo were moved completely on next page
435  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
436  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
437  }
438 
439  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
440 
441  // VAT Rate
442  /*
443  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
444  {
445  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
446  $pdf->SetXY($this->posxtva, $curY);
447  $pdf->MultiCell($this->posxup-$this->posxtva-3, 3, $vat_rate, 0, 'R');
448  }
449 
450  // Unit price before discount
451  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
452  $pdf->SetXY($this->posxup, $curY);
453  if ($up_excl_tax > 0)
454  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
455  */
456 
457  // Quantity
458  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
459  $pdf->SetXY($this->posxqty, $curY);
460  $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars
461 
462  // Discount on line
463  /*
464  if ($object->lines[$i]->remise_percent)
465  {
466  $pdf->SetXY($this->posxdiscount-2, $curY);
467  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
468  $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
469  }
470 
471  // Total HT line
472  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
473  $pdf->SetXY($this->postotalht, $curY);
474  if ($total_excl_tax > 0)
475  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
476  */
477 
478  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
479  if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
480  else $tvaligne=$object->lines[$i]->total_tva;
481 
482  $localtax1ligne=$object->lines[$i]->total_localtax1;
483  $localtax2ligne=$object->lines[$i]->total_localtax2;
484  $localtax1_rate=$object->lines[$i]->localtax1_tx;
485  $localtax2_rate=$object->lines[$i]->localtax2_tx;
486  $localtax1_type=$object->lines[$i]->localtax1_type;
487  $localtax2_type=$object->lines[$i]->localtax2_type;
488 
489  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
490  if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
491  if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
492 
493  $vatrate=(string) $object->lines[$i]->tva_tx;
494 
495  // Retrieve type from database for backward compatibility with old records
496  if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
497  && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
498  {
499  $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
500  $localtax1_type = $localtaxtmp_array[0];
501  $localtax2_type = $localtaxtmp_array[2];
502  }
503 
504  // retrieve global local tax
505  if ($localtax1_type && $localtax1ligne != 0)
506  $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
507  if ($localtax2_type && $localtax2ligne != 0)
508  $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
509 
510  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
511  if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
512  $this->tva[$vatrate] += $tvaligne;
513 
514  if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
515 
516  // Add line
517  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
518  {
519  $pdf->setPage($pageposafter);
520  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
521  //$pdf->SetDrawColor(190,190,200);
522  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
523  $pdf->SetLineStyle(array('dash'=>0));
524  }
525 
526  $nexY+=2; // Passe espace entre les lignes
527 
528  // Detect if some page were added automatically and output _tableau for past pages
529  while ($pagenb < $pageposafter)
530  {
531  $pdf->setPage($pagenb);
532  if ($pagenb == 1)
533  {
534  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
535  }
536  else
537  {
538  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
539  }
540  $this->_pagefoot($pdf,$object,$outputlangs,1);
541  $pagenb++;
542  $pdf->setPage($pagenb);
543  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
544  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
545  }
546  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
547  {
548  if ($pagenb == 1)
549  {
550  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
551  }
552  else
553  {
554  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
555  }
556  $this->_pagefoot($pdf,$object,$outputlangs,1);
557  // New page
558  $pdf->AddPage();
559  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
560  $pagenb++;
561  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
562  }
563  }
564 
565  // Show square
566  if ($pagenb == 1)
567  {
568  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
569  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
570  }
571  else
572  {
573  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
574  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
575  }
576 
577  // Affiche zone infos
578  $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
579 
580  // Affiche zone totaux
581  //$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
582 
583  // Affiche zone versements
584  /*
585  if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
586  {
587  $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
588  }
589  */
590 
591  // Pied de page
592  $this->_pagefoot($pdf,$object,$outputlangs);
593  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
594 
595  $pdf->Close();
596 
597  $pdf->Output($file,'F');
598 
599  //Add pdfgeneration hook
600  $hookmanager->initHooks(array('pdfgeneration'));
601  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
602  global $action;
603  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
604 
605  if (! empty($conf->global->MAIN_UMASK))
606  @chmod($file, octdec($conf->global->MAIN_UMASK));
607 
608  $this->result = array('fullpath'=>$file);
609 
610  return 1; // Pas d'erreur
611  }
612  else
613  {
614  $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
615  return 0;
616  }
617  }
618  else
619  {
620  $this->error=$langs->trans("ErrorConstantNotDefined","SUPPLIER_PROPOSAL_OUTPUTDIR");
621  return 0;
622  }
623  }
624 
634  function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
635  {
636 
637  }
638 
639 
649  function _tableau_info(&$pdf, $object, $posy, $outputlangs)
650  {
651  global $conf;
652  $default_font_size = pdf_getPDFFontSize($outputlangs);
653 
654  $pdf->SetFont('','', $default_font_size - 1);
655 
656  $posxval=52;
657 
658  // Show shipping date
659  if (! empty($object->date_livraison))
660  {
661  $outputlangs->load("sendings");
662  $pdf->SetFont('','B', $default_font_size - 2);
663  $pdf->SetXY($this->marge_gauche, $posy);
664  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
665  $pdf->MultiCell(80, 4, $titre, 0, 'L');
666  $pdf->SetFont('','', $default_font_size - 2);
667  $pdf->SetXY($posxval, $posy);
668  $dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
669  $pdf->MultiCell(80, 4, $dlp, 0, 'L');
670 
671  $posy=$pdf->GetY()+1;
672  }
673  else {
674  $outputlangs->load("sendings");
675  $pdf->SetFont('','B', $default_font_size - 2);
676  $pdf->SetXY($this->marge_gauche, $posy);
677  $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
678  $pdf->MultiCell(80, 4, $titre, 0, 'L');
679  $pdf->SetFont('','', $default_font_size - 2);
680  $pdf->SetXY($posxval, $posy);
681  //$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
682  $pdf->MultiCell(80, 4, $dlp, 0, 'L');
683 
684  $posy=$pdf->GetY()+1;
685  }
686  /* PHFAVRE
687  elseif ($object->availability_code || $object->availability) // Show availability conditions
688  {
689  $pdf->SetFont('','B', $default_font_size - 2);
690  $pdf->SetXY($this->marge_gauche, $posy);
691  $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
692  $pdf->MultiCell(80, 4, $titre, 0, 'L');
693  $pdf->SetTextColor(0,0,0);
694  $pdf->SetFont('','', $default_font_size - 2);
695  $pdf->SetXY($posxval, $posy);
696  $lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
697  $lib_availability=str_replace('\n',"\n",$lib_availability);
698  $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
699 
700  $posy=$pdf->GetY()+1;
701  }*/
702 
703  // Show payments conditions
704  if (empty($conf->global->SUPPLIER_PROPOSAL_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
705  {
706  $pdf->SetFont('','B', $default_font_size - 2);
707  $pdf->SetXY($this->marge_gauche, $posy);
708  $titre = $outputlangs->transnoentities("PaymentConditions").':';
709  $pdf->MultiCell(80, 4, $titre, 0, 'L');
710 
711  $pdf->SetFont('','', $default_font_size - 2);
712  $pdf->SetXY($posxval, $posy);
713  $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);
714  $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
715  $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
716 
717  $posy=$pdf->GetY()+3;
718  }
719 
720  if (! empty($conf->global->SUPPLIER_PROPOSAL_PDF_SHOW_PAYMENTTERMMODE))
721  {
722  // Show payment mode
723  if ($object->mode_reglement_code
724  && $object->mode_reglement_code != 'CHQ'
725  && $object->mode_reglement_code != 'VIR')
726  {
727  $pdf->SetFont('','B', $default_font_size - 2);
728  $pdf->SetXY($this->marge_gauche, $posy-2);
729  $titre = $outputlangs->transnoentities("PaymentMode").':';
730  $pdf->MultiCell(80, 5, $titre, 0, 'L');
731  $pdf->SetFont('','', $default_font_size - 2);
732  $pdf->SetXY($posxval, $posy-2);
733  $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);
734  $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
735 
736  $posy=$pdf->GetY()+2;
737  }
738 
739  // Show payment mode CHQ
740  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
741  {
742  // Si mode reglement non force ou si force a CHQ
743  if (! empty($conf->global->FACTURE_CHQ_NUMBER))
744  {
745  $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
746 
747  if ($conf->global->FACTURE_CHQ_NUMBER > 0)
748  {
749  $account = new Account($this->db);
750  $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
751 
752  $pdf->SetXY($this->marge_gauche, $posy);
753  $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
754  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
755  $posy=$pdf->GetY()+1;
756 
757  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
758  {
759  $pdf->SetXY($this->marge_gauche, $posy);
760  $pdf->SetFont('','', $default_font_size - $diffsizetitle);
761  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
762  $posy=$pdf->GetY()+2;
763  }
764  }
765  if ($conf->global->FACTURE_CHQ_NUMBER == -1)
766  {
767  $pdf->SetXY($this->marge_gauche, $posy);
768  $pdf->SetFont('','B', $default_font_size - $diffsizetitle);
769  $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
770  $posy=$pdf->GetY()+1;
771 
772  if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
773  {
774  $pdf->SetXY($this->marge_gauche, $posy);
775  $pdf->SetFont('','', $default_font_size - $diffsizetitle);
776  $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
777  $posy=$pdf->GetY()+2;
778  }
779  }
780  }
781  }
782 
783  // If payment mode not forced or forced to VIR, show payment with BAN
784  if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
785  {
786  if (! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
787  {
788  $bankid=(empty($object->fk_bank)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_bank);
789  $account = new Account($this->db);
790  $account->fetch($bankid);
791 
792  $curx=$this->marge_gauche;
793  $cury=$posy;
794 
795  $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
796 
797  $posy+=2;
798  }
799  }
800  }
801 
802  return $posy;
803  }
804 
805 
816  function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
817  {
818  global $conf,$mysoc;
819  $default_font_size = pdf_getPDFFontSize($outputlangs);
820 
821  $tab2_top = $posy;
822  $tab2_hl = 4;
823  $pdf->SetFont('','', $default_font_size - 1);
824 
825  // Tableau total
826  $col1x = 120; $col2x = 170;
827  if ($this->page_largeur < 210) // To work with US executive format
828  {
829  $col2x-=20;
830  }
831  $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
832 
833  $useborder=0;
834  $index = 0;
835 
836  // Total HT
837  $pdf->SetFillColor(255,255,255);
838  $pdf->SetXY($col1x, $tab2_top + 0);
839  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
840 
841  $pdf->SetXY($col2x, $tab2_top + 0);
842  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
843 
844  // Show VAT by rates and total
845  $pdf->SetFillColor(248,248,248);
846 
847  $this->atleastoneratenotnull=0;
848  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
849  {
850  $tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
851  if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull)
852  {
853  // Nothing to do
854  }
855  else
856  {
857  //Local tax 1 before VAT
858  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
859  //{
860  foreach( $this->localtax1 as $localtax_type => $localtax_rate )
861  {
862  if (in_array((string) $localtax_type, array('1','3','5'))) continue;
863 
864  foreach( $localtax_rate as $tvakey => $tvaval )
865  {
866  if ($tvakey!=0) // On affiche pas taux 0
867  {
868  //$this->atleastoneratenotnull++;
869 
870  $index++;
871  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
872 
873  $tvacompl='';
874  if (preg_match('/\*/',$tvakey))
875  {
876  $tvakey=str_replace('*','',$tvakey);
877  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
878  }
879  $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
880  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
881  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
882 
883  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
884  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
885  }
886  }
887  }
888  //}
889  //Local tax 2 before VAT
890  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
891  //{
892  foreach( $this->localtax2 as $localtax_type => $localtax_rate )
893  {
894  if (in_array((string) $localtax_type, array('1','3','5'))) continue;
895 
896  foreach( $localtax_rate as $tvakey => $tvaval )
897  {
898  if ($tvakey!=0) // On affiche pas taux 0
899  {
900  //$this->atleastoneratenotnull++;
901 
902 
903 
904  $index++;
905  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
906 
907  $tvacompl='';
908  if (preg_match('/\*/',$tvakey))
909  {
910  $tvakey=str_replace('*','',$tvakey);
911  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
912  }
913  $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
914  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
915  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
916 
917  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
918  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
919 
920  }
921  }
922  }
923  //}
924  // VAT
925  foreach($this->tva as $tvakey => $tvaval)
926  {
927  if ($tvakey > 0) // On affiche pas taux 0
928  {
929  $this->atleastoneratenotnull++;
930 
931  $index++;
932  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
933 
934  $tvacompl='';
935  if (preg_match('/\*/',$tvakey))
936  {
937  $tvakey=str_replace('*','',$tvakey);
938  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
939  }
940  $totalvat =$outputlangs->transcountrynoentities("TotalVAT",$mysoc->country_code).' ';
941  $totalvat.=vatrate($tvakey,1).$tvacompl;
942  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
943 
944  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
945  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
946  }
947  }
948 
949  //Local tax 1 after VAT
950  //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
951  //{
952  foreach( $this->localtax1 as $localtax_type => $localtax_rate )
953  {
954  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
955 
956  foreach( $localtax_rate as $tvakey => $tvaval )
957  {
958  if ($tvakey != 0) // On affiche pas taux 0
959  {
960  //$this->atleastoneratenotnull++;
961 
962  $index++;
963  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
964 
965  $tvacompl='';
966  if (preg_match('/\*/',$tvakey))
967  {
968  $tvakey=str_replace('*','',$tvakey);
969  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
970  }
971  $totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
972 
973  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
974  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
975  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
976  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
977  }
978  }
979  }
980  //}
981  //Local tax 2 after VAT
982  //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
983  //{
984  foreach( $this->localtax2 as $localtax_type => $localtax_rate )
985  {
986  if (in_array((string) $localtax_type, array('2','4','6'))) continue;
987 
988  foreach( $localtax_rate as $tvakey => $tvaval )
989  {
990  // retrieve global local tax
991  if ($tvakey != 0) // On affiche pas taux 0
992  {
993  //$this->atleastoneratenotnull++;
994 
995  $index++;
996  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
997 
998  $tvacompl='';
999  if (preg_match('/\*/',$tvakey))
1000  {
1001  $tvakey=str_replace('*','',$tvakey);
1002  $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1003  }
1004  $totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1005 
1006  $totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1007  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1008 
1009  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1010  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1011  }
1012  }
1013  }
1014  //}
1015 
1016  // Total TTC
1017  $index++;
1018  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1019  $pdf->SetTextColor(0,0,60);
1020  $pdf->SetFillColor(224,224,224);
1021  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1022 
1023  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1024  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1025  }
1026  }
1027 
1028  $pdf->SetTextColor(0,0,0);
1029 
1030  /*
1031  $resteapayer = $object->total_ttc - $deja_regle;
1032  if (! empty($object->paye)) $resteapayer=0;
1033  */
1034 
1035  if ($deja_regle > 0)
1036  {
1037  $index++;
1038 
1039  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1040  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1041 
1042  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1043  $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1044 
1045  /*
1046  if ($object->close_code == 'discount_vat')
1047  {
1048  $index++;
1049  $pdf->SetFillColor(255,255,255);
1050 
1051  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1052  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
1053 
1054  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1055  $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1056 
1057  $resteapayer=0;
1058  }
1059  */
1060 
1061  $index++;
1062  $pdf->SetTextColor(0,0,60);
1063  $pdf->SetFillColor(224,224,224);
1064  $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1065  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1066 
1067  $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1068  $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
1069 
1070  $pdf->SetFont('','', $default_font_size - 1);
1071  $pdf->SetTextColor(0,0,0);
1072  }
1073 
1074  $index++;
1075  return ($tab2_top + ($tab2_hl * $index));
1076  }
1077 
1091  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1092  {
1093  global $conf;
1094 
1095  // Force to disable hidetop and hidebottom
1096  $hidebottom=0;
1097  if ($hidetop) $hidetop=-1;
1098 
1099  $currency = !empty($currency) ? $currency : $conf->currency;
1100  $default_font_size = pdf_getPDFFontSize($outputlangs);
1101 
1102  // Amount in (at tab_top - 1)
1103  $pdf->SetTextColor(0,0,0);
1104  $pdf->SetFont('','',$default_font_size - 2);
1105 
1106  if (empty($hidetop))
1107  {
1108  $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1109  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1110  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1111 
1112  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1113  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));
1114  }
1115 
1116  $pdf->SetDrawColor(128,128,128);
1117  $pdf->SetFont('','',$default_font_size - 1);
1118 
1119  // Output Rect
1120  $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
1121 
1122  if (empty($hidetop))
1123  {
1124  $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
1125 
1126  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
1127  $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1128  }
1129 
1130  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1131  {
1132  $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1133  //$pdf->line($this->posxtva-2, $tab_top, $this->posxtva-2, $tab_top + $tab_height);
1134  if (empty($hidetop))
1135  {
1136  $pdf->SetXY($this->posxtva-5, $tab_top+1);
1137  $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1138  }
1139  }
1140 
1141  $pdf->line($this->posxup-3, $tab_top, $this->posxup-3, $tab_top + $tab_height);
1142  if (empty($hidetop))
1143  {
1144  $pdf->SetXY($this->posxup-1, $tab_top+1);
1145  $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1146  }
1147 
1148  $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1149  if (empty($hidetop))
1150  {
1151  $pdf->SetXY($this->posxqty-1, $tab_top+1);
1152  $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1153  }
1154 
1155  $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1156  if (empty($hidetop))
1157  {
1158  if ($this->atleastonediscount)
1159  {
1160  $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1161  $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1162  }
1163  }
1164  if ($this->atleastonediscount)
1165  {
1166  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1167  }
1168  if (empty($hidetop))
1169  {
1170  $pdf->SetXY($this->postotalht-1, $tab_top+1);
1171  $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1172  }
1173  }
1174 
1184  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1185  {
1186  global $conf,$langs;
1187 
1188  $outputlangs->load("main");
1189  $outputlangs->load("bills");
1190  $outputlangs->load("supplier_proposal");
1191  $outputlangs->load("companies");
1192 
1193  $default_font_size = pdf_getPDFFontSize($outputlangs);
1194 
1195  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1196 
1197  // Show Draft Watermark
1198  if($object->statut==0 && (! empty($conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK)) )
1199  {
1200  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK);
1201  }
1202 
1203  $pdf->SetTextColor(0,0,60);
1204  $pdf->SetFont('','B', $default_font_size + 3);
1205 
1206  $posy=$this->marge_haute;
1207  $posx=$this->page_largeur-$this->marge_droite-100;
1208 
1209  $pdf->SetXY($this->marge_gauche,$posy);
1210 
1211  // Logo
1212  $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1213  if ($this->emetteur->logo)
1214  {
1215  if (is_readable($logo))
1216  {
1217  $height=pdf_getHeightForLogo($logo);
1218  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
1219  }
1220  else
1221  {
1222  $pdf->SetTextColor(200,0,0);
1223  $pdf->SetFont('','B',$default_font_size - 2);
1224  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1225  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1226  }
1227  }
1228  else
1229  {
1230  $text=$this->emetteur->name;
1231  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1232  }
1233 
1234  $pdf->SetFont('','B',$default_font_size + 3);
1235  $pdf->SetXY($posx,$posy);
1236  $pdf->SetTextColor(0,0,60);
1237  $title=$outputlangs->transnoentities("CommercialAsk");
1238  $pdf->MultiCell(100, 4, $title, '', 'R');
1239 
1240  $pdf->SetFont('','B',$default_font_size);
1241 
1242  $posy+=5;
1243  $pdf->SetXY($posx,$posy);
1244  $pdf->SetTextColor(0,0,60);
1245  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1246 
1247  $posy+=1;
1248  $pdf->SetFont('','', $default_font_size - 2);
1249 
1250  if ($object->ref_client)
1251  {
1252  $posy+=4;
1253  $pdf->SetXY($posx,$posy);
1254  $pdf->SetTextColor(0,0,60);
1255  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1256  }
1257 /* PHFAVRE
1258  $posy+=4;
1259  $pdf->SetXY($posx,$posy);
1260  $pdf->SetTextColor(0,0,60);
1261  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierProposalDate")." : " . dol_print_date($object->date_livraison,"day",false,$outputlangs,true), '', 'R');
1262 */
1263 
1264  if ($object->thirdparty->code_fournisseur)
1265  {
1266  $posy+=4;
1267  $pdf->SetXY($posx,$posy);
1268  $pdf->SetTextColor(0,0,60);
1269  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1270  }
1271 
1272  // Get contact
1273  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1274  {
1275  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1276  if (count($arrayidcontact) > 0)
1277  {
1278  $usertmp=new User($this->db);
1279  $usertmp->fetch($arrayidcontact[0]);
1280  $posy+=4;
1281  $pdf->SetXY($posx,$posy);
1282  $pdf->SetTextColor(0,0,60);
1283  $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1284  }
1285  }
1286 
1287  $posy+=2;
1288 
1289  // Show list of linked objects
1290  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1291 
1292  if ($showaddress)
1293  {
1294  // Sender properties
1295  $carac_emetteur='';
1296  // Add internal contact of proposal if defined
1297  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1298  if (count($arrayidcontact) > 0)
1299  {
1300  $object->fetch_user($arrayidcontact[0]);
1301  $labelbeforecontactname=($outputlangs->transnoentities("FromContactName")!='FromContactName'?$outputlangs->transnoentities("FromContactName"):$outputlangs->transnoentities("Name"));
1302  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1303  }
1304 
1305  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
1306 
1307  // Show sender
1308  $posy=42;
1309  $posx=$this->marge_gauche;
1310  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1311  $hautcadre=40;
1312 
1313  // Show sender frame
1314  $pdf->SetTextColor(0,0,0);
1315  $pdf->SetFont('','', $default_font_size - 2);
1316  $pdf->SetXY($posx,$posy-5);
1317  $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1318  $pdf->SetXY($posx,$posy);
1319  $pdf->SetFillColor(230,230,230);
1320  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1321  $pdf->SetTextColor(0,0,60);
1322 
1323  // Show sender name
1324  $pdf->SetXY($posx+2,$posy+3);
1325  $pdf->SetFont('','B', $default_font_size);
1326  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1327  $posy=$pdf->getY();
1328 
1329  // Show sender information
1330  $pdf->SetXY($posx+2,$posy);
1331  $pdf->SetFont('','', $default_font_size - 1);
1332  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1333 
1334 
1335  // If CUSTOMER contact defined, we use it
1336  $usecontact=false;
1337  $arrayidcontact=$object->getIdContact('external','CUSTOMER');
1338  if (count($arrayidcontact) > 0)
1339  {
1340  $usecontact=true;
1341  $result=$object->fetch_contact($arrayidcontact[0]);
1342  }
1343 
1344  // Recipient name
1345  if (! empty($usecontact))
1346  {
1347  // On peut utiliser le nom de la societe du contact
1348  if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname;
1349  else $socname = $object->thirdparty->name;
1350  $carac_client_name=$outputlangs->convToOutputCharset($socname);
1351  }
1352  else
1353  {
1354  $carac_client_name=$outputlangs->convToOutputCharset($object->thirdparty->name);
1355  }
1356 
1357  $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target',$object);
1358 
1359  // Show recipient
1360  $widthrecbox=100;
1361  if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
1362  $posy=42;
1363  $posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1364  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1365 
1366  // Show recipient frame
1367  $pdf->SetTextColor(0,0,0);
1368  $pdf->SetFont('','', $default_font_size - 2);
1369  $pdf->SetXY($posx+2,$posy-5);
1370  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1371  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1372 
1373  // Show recipient name
1374  $pdf->SetXY($posx+2,$posy+3);
1375  $pdf->SetFont('','B', $default_font_size);
1376  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1377 
1378  // Show recipient information
1379  $pdf->SetFont('','', $default_font_size - 1);
1380  $pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4));
1381  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1382  }
1383 
1384  $pdf->SetTextColor(0,0,0);
1385  }
1386 
1396  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1397  {
1398  global $conf;
1399  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1400  return pdf_pagefoot($pdf,$outputlangs,'SUPPLIER_PROPOSAL_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1401  }
1402 
1403 }
1404 
__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:672
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:580
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...
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Classe mere des modeles de propale.
Class to manage bank accounts.
_tableau_info(&$pdf, $object, $posy, $outputlangs)
Show miscellaneous information (payment mode, payment term, ...)
Class to manage hooks.
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
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
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
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:2115
Class to generate PDF proposal Azur.
_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:277
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1100
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1139
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
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.
type
Definition: viewcat.php:283