dolibarr  7.0.0-beta
pdf_standard.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@products.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  * or see http://www.gnu.org/
17  */
18 
25 require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
32 
33 
37 class pdf_standard extends ModelePDFProduct
38 {
42  public $db;
43 
47  public $name;
48 
52  public $description;
53 
57  public $type;
58 
63  public $phpmin = array(5, 2);
64 
69  public $version = 'dolibarr';
70 
71  public $page_largeur;
72  public $page_hauteur;
73  public $format;
74  public $marge_gauche;
75  public $marge_droite;
76  public $marge_haute;
77  public $marge_basse;
78 
79  public $emetteur; // Objet societe qui emet
80 
81 
87  public function __construct($db)
88  {
89  global $conf,$langs,$mysoc;
90 
91  $langs->load("main");
92  $langs->load("companies");
93 
94  $this->db = $db;
95  $this->name = "standard";
96  $this->description = $langs->trans("DocumentModelStandardPDF");
97 
98  // Dimension page pour format A4
99  $this->type = 'pdf';
100  $formatarray=pdf_getFormat();
101  $this->page_largeur = $formatarray['width'];
102  $this->page_hauteur = $formatarray['height'];
103  $this->format = array($this->page_largeur,$this->page_hauteur);
104  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
105  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
106  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
107  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
108 
109  $this->option_logo = 1; // Affiche logo
110  $this->option_codeproduitservice = 0; // Affiche code produit-service
111  $this->option_multilang = 1; // Dispo en plusieurs langues
112  $this->option_freetext = 0; // Support add of a personalised text
113 
114  // Recupere emetteur
115  $this->emetteur=$mysoc;
116  if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined
117  }
118 
119 
131  function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
132  {
133  global $user,$langs,$conf,$mysoc,$db,$hookmanager;
134 
135  if (! is_object($outputlangs)) $outputlangs=$langs;
136  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
137  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
138 
139  $outputlangs->load("main");
140  $outputlangs->load("dict");
141  $outputlangs->load("companies");
142  $outputlangs->load("bills");
143  $outputlangs->load("products");
144  $outputlangs->load("orders");
145  $outputlangs->load("deliveries");
146 
147  $nblignes = count($object->lines);
148 
149  if ($conf->produit->dir_output)
150  {
151  // Definition of $dir and $file
152  if ($object->specimen)
153  {
154  $dir = $conf->produit->dir_output;
155  $file = $dir . "/SPECIMEN.pdf";
156  }
157  else
158  {
159  $objectref = dol_sanitizeFileName($object->ref);
160  $dir = $conf->produit->dir_output . "/" . $objectref;
161  $file = $dir . "/" . $objectref . ".pdf";
162  }
163 
164  $productFournisseur = new ProductFournisseur($this->db);
165  $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
166  $object->supplierprices = $supplierprices;
167 
168  if (! file_exists($dir))
169  {
170  if (dol_mkdir($dir) < 0)
171  {
172  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
173  return -1;
174  }
175  }
176 
177  if (file_exists($dir))
178  {
179  // Add pdfgeneration hook
180  if (! is_object($hookmanager))
181  {
182  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
183  $hookmanager=new HookManager($this->db);
184  }
185  $hookmanager->initHooks(array('pdfgeneration'));
186  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
187  global $action;
188  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
189 
190  // Create pdf instance
191  $pdf=pdf_getInstance($this->format);
192  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
193  $pdf->SetAutoPageBreak(1,0);
194 
195  $heightforinfotot = 40; // Height reserved to output the info and total part
196  $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
197  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
198 
199  if (class_exists('TCPDF'))
200  {
201  $pdf->setPrintHeader(false);
202  $pdf->setPrintFooter(false);
203  }
204  $pdf->SetFont(pdf_getPDFFont($outputlangs));
205  // Set path to the background PDF File
206  if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
207  {
208  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
209  $tplidx = $pdf->importPage(1);
210  }
211 
212  $pdf->Open();
213  $pagenb=0;
214  $pdf->SetDrawColor(128,128,128);
215 
216  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
217  $pdf->SetSubject($outputlangs->transnoentities("Order"));
218  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
219  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
220  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
221  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
222 
223  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
224 
225 
226  // New page
227  $pdf->AddPage();
228  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
229  $pagenb++;
230  $this->_pagehead($pdf, $object, 1, $outputlangs);
231  $pdf->SetFont('','', $default_font_size - 1);
232  $pdf->MultiCell(0, 3, ''); // Set interline to 3
233  $pdf->SetTextColor(0,0,0);
234 
235 
236  $tab_top = 42;
237  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
238  $tab_height = 130;
239  $tab_height_newpage = 150;
240 
241  //
242  $pdf->SetFont('','B', $default_font_size);
243  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
244  $nexY = $pdf->GetY();
245 
246  $pdf->SetFont('','', $default_font_size);
247  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
248  $nexY = $pdf->GetY();
249 
250  $nexY+=5;
251 
252  if ($object->weight)
253  {
254  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight), 0, 1);
255  $nexY = $pdf->GetY();
256  }
257  if ($object->weight)
258  {
259  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != ''?$object->length:'?').' x '.($object->width != ''?$object->width:'?').' x '.($object->height != ''?$object->height:'?'), 0, 1);
260  $nexY = $pdf->GetY();
261  }
262  if ($object->surface)
263  {
264  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Area").': '.dol_htmlentitiesbr($object->surface), 0, 1);
265  $nexY = $pdf->GetY();
266  }
267  if ($object->volume)
268  {
269  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Volume").': '.dol_htmlentitiesbr($object->volume), 0, 1);
270  $nexY = $pdf->GetY();
271  }
272 
273 
274  // Affiche notes
275  // TODO There is no public note on product yet
276  $notetoshow=empty($object->note_public)?'':$object->note_public;
277  if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
278  {
279  // Get first sale rep
280  if (is_object($object->thirdparty))
281  {
282  $salereparray=$object->thirdparty->getSalesRepresentatives($user);
283  $salerepobj=new User($this->db);
284  $salerepobj->fetch($salereparray[0]['id']);
285  if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
286  }
287  }
288  if ($notetoshow)
289  {
290  $tab_top = 88;
291 
292  $pdf->SetFont('','', $default_font_size - 1);
293  $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
294  $nexY = $pdf->GetY();
295  $height_note=$nexY-$tab_top;
296 
297  // Rect prend une longueur en 3eme param
298  $pdf->SetDrawColor(192,192,192);
299  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
300 
301  $tab_height = $tab_height - $height_note;
302  $tab_top = $nexY+6;
303  }
304  else
305  {
306  $height_note=0;
307  }
308 
309  $iniY = $tab_top + 7;
310  $curY = $tab_top + 7;
311  $nexY = $tab_top + 7;
312 
313  // Loop on each lines
314  /*
315  for ($i = 0 ; $i < $nblignes ; $i++)
316  {
317  $curY = $nexY;
318  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
319  $pdf->SetTextColor(0,0,0);
320 
321  $pdf->setTopMargin($tab_top_newpage);
322  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
323  $pageposbefore=$pdf->getPage();
324 
325  // Description of product line
326  $curX = $this->posxdesc-1;
327 
328  $showpricebeforepagebreak=1;
329 
330  $pdf->startTransaction();
331  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
332  $pageposafter=$pdf->getPage();
333  if ($pageposafter > $pageposbefore) // There is a pagebreak
334  {
335  $pdf->rollbackTransaction(true);
336  $pageposafter=$pageposbefore;
337  //print $pageposafter.'-'.$pageposbefore;exit;
338  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
339  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
340  $pageposafter=$pdf->getPage();
341  $posyafter=$pdf->GetY();
342  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
343  {
344  if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
345  {
346  $pdf->AddPage('','',true);
347  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
348  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
349  $pdf->setPage($pageposafter+1);
350  }
351  }
352  else
353  {
354  // We found a page break
355  $showpricebeforepagebreak=0;
356  }
357  }
358  else // No pagebreak
359  {
360  $pdf->commitTransaction();
361  }
362 
363  $nexY = $pdf->GetY();
364  $pageposafter=$pdf->getPage();
365  $pdf->setPage($pageposbefore);
366  $pdf->setTopMargin($this->marge_haute);
367  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
368 
369  // We suppose that a too long description is moved completely on next page
370  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
371  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
372  }
373 
374  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
375 
376  // VAT Rate
377  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
378  {
379  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
380  $pdf->SetXY($this->posxtva, $curY);
381  $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R');
382  }
383 
384  // Unit price before discount
385  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
386  $pdf->SetXY($this->posxup, $curY);
387  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
388 
389  // Quantity
390  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
391  $pdf->SetXY($this->posxqty, $curY);
392  // Enough for 6 chars
393  if($conf->global->PRODUCT_USE_UNITS)
394  {
395  $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
396  }
397  else
398  {
399  $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
400  }
401 
402  // Unit
403  if($conf->global->PRODUCT_USE_UNITS)
404  {
405  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
406  $pdf->SetXY($this->posxunit, $curY);
407  $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
408  }
409 
410  // Discount on line
411  $pdf->SetXY($this->posxdiscount, $curY);
412  if ($object->lines[$i]->remise_percent)
413  {
414  $pdf->SetXY($this->posxdiscount-2, $curY);
415  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
416  $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
417  }
418 
419  // Total HT line
420  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
421  $pdf->SetXY($this->postotalht, $curY);
422  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
423 
424  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
425  if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
426  else $tvaligne=$object->lines[$i]->total_tva;
427 
428  $localtax1ligne=$object->lines[$i]->total_localtax1;
429  $localtax2ligne=$object->lines[$i]->total_localtax2;
430  $localtax1_rate=$object->lines[$i]->localtax1_tx;
431  $localtax2_rate=$object->lines[$i]->localtax2_tx;
432  $localtax1_type=$object->lines[$i]->localtax1_type;
433  $localtax2_type=$object->lines[$i]->localtax2_type;
434 
435  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
436  if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
437  if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
438 
439  $vatrate=(string) $object->lines[$i]->tva_tx;
440 
441  // Retrieve type from database for backward compatibility with old records
442  if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
443  && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
444  {
445  $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
446  $localtax1_type = $localtaxtmp_array[0];
447  $localtax2_type = $localtaxtmp_array[2];
448  }
449 
450  // retrieve global local tax
451  if ($localtax1_type && $localtax1ligne != 0)
452  $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
453  if ($localtax2_type && $localtax2ligne != 0)
454  $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
455 
456  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
457  if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
458  $this->tva[$vatrate] += $tvaligne;
459 
460  // Add line
461  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
462  {
463  $pdf->setPage($pageposafter);
464  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
465  //$pdf->SetDrawColor(190,190,200);
466  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
467  $pdf->SetLineStyle(array('dash'=>0));
468  }
469 
470  $nexY+=2; // Passe espace entre les lignes
471 
472  // Detect if some page were added automatically and output _tableau for past pages
473  while ($pagenb < $pageposafter)
474  {
475  $pdf->setPage($pagenb);
476  if ($pagenb == 1)
477  {
478  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
479  }
480  else
481  {
482  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
483  }
484  $this->_pagefoot($pdf,$object,$outputlangs,1);
485  $pagenb++;
486  $pdf->setPage($pagenb);
487  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
488  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
489  }
490  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
491  {
492  if ($pagenb == 1)
493  {
494  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
495  }
496  else
497  {
498  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
499  }
500  $this->_pagefoot($pdf,$object,$outputlangs,1);
501  // New page
502  $pdf->AddPage();
503  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
504  $pagenb++;
505  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
506  }
507  }
508 
509  // Show square
510  if ($pagenb == 1)
511  {
512  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
513  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
514  }
515  else
516  {
517  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
518  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
519  }
520  */
521 
522  // Affiche zone infos
523  //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
524 
525  // Pied de page
526  $this->_pagefoot($pdf,$object,$outputlangs);
527  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
528 
529  $pdf->Close();
530 
531  $pdf->Output($file,'F');
532 
533  // Add pdfgeneration hook
534  $hookmanager->initHooks(array('pdfgeneration'));
535  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
536  global $action;
537  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
538 
539  if (! empty($conf->global->MAIN_UMASK))
540  @chmod($file, octdec($conf->global->MAIN_UMASK));
541 
542  $this->result = array('fullpath'=>$file);
543 
544  return 1; // Pas d'erreur
545  }
546  else
547  {
548  $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
549  return 0;
550  }
551  }
552  else
553  {
554  $this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
555  return 0;
556  }
557  }
558 
559 
573  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
574  {
575  global $conf;
576 
577  // Force to disable hidetop and hidebottom
578  $hidebottom=0;
579  if ($hidetop) $hidetop=-1;
580 
581  $currency = !empty($currency) ? $currency : $conf->currency;
582  $default_font_size = pdf_getPDFFontSize($outputlangs);
583 
584  // Amount in (at tab_top - 1)
585  $pdf->SetTextColor(0,0,0);
586  $pdf->SetFont('','', $default_font_size - 2);
587 
588  if (empty($hidetop))
589  {
590  $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
591  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
592  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
593 
594  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
595  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));
596  }
597 
598  $pdf->SetDrawColor(128,128,128);
599  $pdf->SetFont('','', $default_font_size - 1);
600 
601  // Output Rect
602  $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
603 
604  if (empty($hidetop))
605  {
606  $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
607 
608  $pdf->SetXY($this->posxdesc-1, $tab_top+1);
609  $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
610  }
611 
612  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
613  {
614  $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
615  if (empty($hidetop))
616  {
617  $pdf->SetXY($this->posxtva-3, $tab_top+1);
618  $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
619  }
620  }
621 
622  $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
623  if (empty($hidetop))
624  {
625  $pdf->SetXY($this->posxup-1, $tab_top+1);
626  $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
627  }
628 
629  $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
630  if (empty($hidetop))
631  {
632  $pdf->SetXY($this->posxqty-1, $tab_top+1);
633  if($conf->global->PRODUCT_USE_UNITS)
634  {
635  $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
636  }
637  else
638  {
639  $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
640  }
641  }
642 
643  if($conf->global->PRODUCT_USE_UNITS) {
644  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
645  if (empty($hidetop)) {
646  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
647  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
648  'C');
649  }
650  }
651 
652  $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
653  if (empty($hidetop))
654  {
655  if ($this->atleastonediscount)
656  {
657  $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
658  $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
659  }
660  }
661 
662  if ($this->atleastonediscount)
663  {
664  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
665  }
666  if (empty($hidetop))
667  {
668  $pdf->SetXY($this->postotalht-1, $tab_top+1);
669  $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
670  }
671  }
672 
683  function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
684  {
685  global $conf,$langs,$hookmanager;
686 
687  $outputlangs->load("main");
688  $outputlangs->load("bills");
689  $outputlangs->load("propal");
690  $outputlangs->load("companies");
691  $outputlangs->load("orders");
692  $default_font_size = pdf_getPDFFontSize($outputlangs);
693 
694  if ($object->type == 1) $titlekey='ServiceSheet';
695  else $titlekey='ProductSheet';
696 
697  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
698 
699  // Show Draft Watermark
700  if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
701  {
702  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
703  }
704 
705  $pdf->SetTextColor(0,0,60);
706  $pdf->SetFont('','B', $default_font_size + 3);
707 
708  $posy=$this->marge_haute;
709  $posx=$this->page_largeur-$this->marge_droite-100;
710 
711  $pdf->SetXY($this->marge_gauche,$posy);
712 
713  // Logo
714  $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
715  if ($this->emetteur->logo)
716  {
717  if (is_readable($logo))
718  {
719  $height=pdf_getHeightForLogo($logo);
720  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
721  }
722  else
723  {
724  $pdf->SetTextColor(200,0,0);
725  $pdf->SetFont('','B', $default_font_size -2);
726  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
727  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
728  }
729  }
730  else
731  {
732  $text=$this->emetteur->name;
733  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
734  }
735 
736  $pdf->SetFont('','B', $default_font_size + 3);
737  $pdf->SetXY($posx,$posy);
738  $pdf->SetTextColor(0,0,60);
739  $title=$outputlangs->transnoentities($titlekey);
740  $pdf->MultiCell(100, 3, $title, '', 'R');
741 
742  $pdf->SetFont('','B',$default_font_size);
743 
744  $posy+=5;
745  $pdf->SetXY($posx,$posy);
746  $pdf->SetTextColor(0,0,60);
747  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
748 
749  $posy+=1;
750  $pdf->SetFont('','', $default_font_size - 1);
751 
752  /*if ($object->ref_client)
753  {
754  $posy+=5;
755  $pdf->SetXY($posx,$posy);
756  $pdf->SetTextColor(0,0,60);
757  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
758  }*/
759 
760  /*$posy+=4;
761  $pdf->SetXY($posx,$posy);
762  $pdf->SetTextColor(0,0,60);
763  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
764  */
765 
766  // Get contact
767  /*
768  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
769  {
770  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
771  if (count($arrayidcontact) > 0)
772  {
773  $usertmp=new User($this->db);
774  $usertmp->fetch($arrayidcontact[0]);
775  $posy+=4;
776  $pdf->SetXY($posx,$posy);
777  $pdf->SetTextColor(0,0,60);
778  $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
779  }
780  }*/
781 
782  $posy+=2;
783 
784  // Show list of linked objects
785  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
786 
787  if ($showaddress)
788  {
789  /*
790  // Sender properties
791  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
792 
793  // Show sender
794  $posy=42;
795  $posx=$this->marge_gauche;
796  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
797  $hautcadre=40;
798 
799  // Show sender frame
800  $pdf->SetTextColor(0,0,0);
801  $pdf->SetFont('','', $default_font_size - 2);
802  $pdf->SetXY($posx,$posy-5);
803  $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
804  $pdf->SetXY($posx,$posy);
805  $pdf->SetFillColor(230,230,230);
806  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
807  $pdf->SetTextColor(0,0,60);
808 
809  // Show sender name
810  $pdf->SetXY($posx+2,$posy+3);
811  $pdf->SetFont('','B', $default_font_size);
812  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
813  $posy=$pdf->getY();
814 
815  // Show sender information
816  $pdf->SetXY($posx+2,$posy);
817  $pdf->SetFont('','', $default_font_size - 1);
818  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
819  */
820  }
821 
822  $pdf->SetTextColor(0,0,0);
823  }
824 
834  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
835  {
836  global $conf;
837  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
838  return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
839  }
840 
841 }
842 
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
</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.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:256
Class to manage Dolibarr users.
Definition: user.class.php:39
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...
write_file($object, $outputlangs, $srctemplatepath, $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
Class to generate expense report based on standard model.
Class to manage hooks.
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
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
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
$version
Dolibarr version of the loaded document string.
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
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
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
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...
__construct($db)
Constructor.
Parent class to manage intervention document templates.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
type
Definition: viewcat.php:283
Class to manage predefined suppliers products.