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