dolibarr  16.0.5
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 <https://www.gnu.org/licenses/>.
16  * or see https://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, 6);
64 
69  public $version = 'dolibarr';
70 
75  public $emetteur;
76 
77 
83  public function __construct($db)
84  {
85  global $conf, $langs, $mysoc;
86 
87  // Load traductions files required by page
88  $langs->loadLangs(array("main", "companies"));
89 
90  $this->db = $db;
91  $this->name = "standard";
92  $this->description = $langs->trans("DocumentModelStandardPDF");
93 
94  // Page size for A4 format
95  $this->type = 'pdf';
96  $formatarray = pdf_getFormat();
97  $this->page_largeur = $formatarray['width'];
98  $this->page_hauteur = $formatarray['height'];
99  $this->format = array($this->page_largeur, $this->page_hauteur);
100  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
101  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
102  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
103  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
104 
105  $this->option_logo = 1; // Display logo
106  $this->option_multilang = 1; // Available in several languages
107  $this->option_freetext = 0; // Support add of a personalised text
108 
109  // Get source company
110  $this->emetteur = $mysoc;
111  if (!$this->emetteur->country_code) {
112  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
113  }
114  }
115 
116 
117  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
129  public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
130  {
131  // phpcs:enable
132  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
133 
134  if (!is_object($outputlangs)) {
135  $outputlangs = $langs;
136  }
137  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
138  if (!empty($conf->global->MAIN_USE_FPDF)) {
139  $outputlangs->charset_output = 'ISO-8859-1';
140  }
141 
142  // Load traductions files required by page
143  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
144 
145  if (is_array($object->lines)) {
146  $nblines = count($object->lines);
147  } else {
148  $nblines = 0;
149  }
150 
151  if ($conf->product->dir_output) {
152  // Definition of $dir and $file
153  if ($object->specimen) {
154  $dir = $conf->product->dir_output;
155  $file = $dir."/SPECIMEN.pdf";
156  } else {
157  $objectref = dol_sanitizeFileName($object->ref);
158  $dir = $conf->product->dir_output."/".$objectref;
159  $file = $dir."/".$objectref.".pdf";
160  }
161 
162  $productFournisseur = new ProductFournisseur($this->db);
163  $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
164  $object->supplierprices = $supplierprices;
165 
166  if (!file_exists($dir)) {
167  if (dol_mkdir($dir) < 0) {
168  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
169  return -1;
170  }
171  }
172 
173  if (file_exists($dir)) {
174  // Add pdfgeneration hook
175  if (!is_object($hookmanager)) {
176  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
177  $hookmanager = new HookManager($this->db);
178  }
179  $hookmanager->initHooks(array('pdfgeneration'));
180  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
181  global $action;
182  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
183 
184  // Create pdf instance
185  $pdf = pdf_getInstance($this->format);
186  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
187  $pdf->SetAutoPageBreak(1, 0);
188 
189  $heightforinfotot = 40; // Height reserved to output the info and total part
190  $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
191  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
192  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
193  $heightforfooter += 6;
194  }
195 
196  if (class_exists('TCPDF')) {
197  $pdf->setPrintHeader(false);
198  $pdf->setPrintFooter(false);
199  }
200  $pdf->SetFont(pdf_getPDFFont($outputlangs));
201  // Set path to the background PDF File
202  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
203  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
204  $tplidx = $pdf->importPage(1);
205  }
206 
207  $pdf->Open();
208  $pagenb = 0;
209  $pdf->SetDrawColor(128, 128, 128);
210 
211  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
212  $pdf->SetSubject($outputlangs->transnoentities("Order"));
213  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
214  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
215  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
216  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
217  $pdf->SetCompression(false);
218  }
219 
220  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
221 
222 
223  // New page
224  $pdf->AddPage();
225  if (!empty($tplidx)) {
226  $pdf->useTemplate($tplidx);
227  }
228  $pagenb++;
229  $this->_pagehead($pdf, $object, 1, $outputlangs);
230  $pdf->SetFont('', '', $default_font_size - 1);
231  $pdf->MultiCell(0, 3, ''); // Set interline to 3
232  $pdf->SetTextColor(0, 0, 0);
233 
234 
235  $tab_top = 42;
236  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
237 
238  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
239 
240  // Label of product
241  $pdf->SetFont('', 'B', $default_font_size);
242  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->label), 0, 1);
243  $nexY = $pdf->GetY();
244 
245  $pdf->SetFont('', '', $default_font_size);
246  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
247  $nexY = $pdf->GetY();
248 
249  $nexY += 5;
250 
251  $outputlangs->load("other");
252  if ($object->weight) {
253  $texttoshow = $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight);
254  if (isset($object->weight_units)) {
255  $texttoshow .= ' '.measuring_units_string($object->weight_units, 'weight', 0, 0, $outputlangs);
256  }
257  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
258  $nexY = $pdf->GetY();
259  }
260  if ($object->length) {
261  $texttoshow = $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 : '?');
262  $texttoshow .= ' ' . measuringUnitString(0, "size", $object->length_units);
263  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
264  $nexY = $pdf->GetY();
265  }
266  if ($object->surface) {
267  $texttoshow = $langs->trans("Surface") . ': ' . dol_htmlentitiesbr($object->surface);
268  $texttoshow .= ' ' . measuringUnitString(0, "surface", $object->surface_units);
269  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
270  $nexY = $pdf->GetY();
271  }
272  if ($object->volume) {
273  $texttoshow = $langs->trans("Volume") . ': ' . dol_htmlentitiesbr($object->volume);
274  $texttoshow .= ' ' . measuringUnitString(0, "volume", $object->volume_units);
275  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
276  $nexY = $pdf->GetY();
277  }
278 
279  // Show notes
280  // TODO There is no public note on product yet
281  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
282  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
283  // Get first sale rep
284  if (is_object($object->thirdparty)) {
285  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
286  $salerepobj = new User($this->db);
287  $salerepobj->fetch($salereparray[0]['id']);
288  if (!empty($salerepobj->signature)) {
289  $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
290  }
291  }
292  }
293  if ($notetoshow) {
294  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
295  complete_substitutions_array($substitutionarray, $outputlangs, $object);
296  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
297  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
298 
299  $tab_top = 88;
300 
301  $pdf->SetFont('', '', $default_font_size - 1);
302  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
303  $nexY = $pdf->GetY();
304  $height_note = $nexY - $tab_top;
305 
306  // Rect takes a length in 3rd parameter
307  $pdf->SetDrawColor(192, 192, 192);
308  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
309 
310  $tab_height = $tab_height - $height_note;
311  $tab_top = $nexY + 6;
312  } else {
313  $height_note = 0;
314  }
315 
316  $iniY = $tab_top + 7;
317  $curY = $tab_top + 7;
318  $nexY = $tab_top + 7;
319 
320  // Loop on each lines
321  /*
322  for ($i = 0 ; $i < $nblines ; $i++)
323  {
324  $curY = $nexY;
325  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
326  $pdf->SetTextColor(0,0,0);
327 
328  $pdf->setTopMargin($tab_top_newpage);
329  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
330  $pageposbefore=$pdf->getPage();
331 
332  // Description of product line
333  $curX = $this->posxdesc-1;
334 
335  $showpricebeforepagebreak=1;
336 
337  $pdf->startTransaction();
338  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
339  $pageposafter=$pdf->getPage();
340  if ($pageposafter > $pageposbefore) // There is a pagebreak
341  {
342  $pdf->rollbackTransaction(true);
343  $pageposafter=$pageposbefore;
344  //print $pageposafter.'-'.$pageposbefore;exit;
345  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
346  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
347  $pageposafter=$pdf->getPage();
348  $posyafter=$pdf->GetY();
349  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
350  {
351  if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
352  {
353  $pdf->AddPage('','',true);
354  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
355  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
356  $pdf->setPage($pageposafter+1);
357  }
358  }
359  else
360  {
361  // We found a page break
362  $showpricebeforepagebreak=0;
363  }
364  }
365  else // No pagebreak
366  {
367  $pdf->commitTransaction();
368  }
369 
370  $nexY = $pdf->GetY();
371  $pageposafter=$pdf->getPage();
372  $pdf->setPage($pageposbefore);
373  $pdf->setTopMargin($this->marge_haute);
374  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
375 
376  // We suppose that a too long description is moved completely on next page
377  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
378  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
379  }
380 
381  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
382 
383  // VAT Rate
384  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
385  {
386  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
387  $pdf->SetXY($this->posxtva, $curY);
388  $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R');
389  }
390 
391  // Unit price before discount
392  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
393  $pdf->SetXY($this->posxup, $curY);
394  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
395 
396  // Quantity
397  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
398  $pdf->SetXY($this->posxqty, $curY);
399  $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
400 
401  // Unit
402  if($conf->global->PRODUCT_USE_UNITS)
403  {
404  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
405  $pdf->SetXY($this->posxunit, $curY);
406  $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
407  }
408 
409  // Discount on line
410  $pdf->SetXY($this->posxdiscount, $curY);
411  if ($object->lines[$i]->remise_percent)
412  {
413  $pdf->SetXY($this->posxdiscount-2, $curY);
414  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
415  $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
416  }
417 
418  // Total HT line
419  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
420  $pdf->SetXY($this->postotalht, $curY);
421  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
422 
423  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
424  if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
425  else $tvaligne=$object->lines[$i]->total_tva;
426 
427  $localtax1ligne=$object->lines[$i]->total_localtax1;
428  $localtax2ligne=$object->lines[$i]->total_localtax2;
429  $localtax1_rate=$object->lines[$i]->localtax1_tx;
430  $localtax2_rate=$object->lines[$i]->localtax2_tx;
431  $localtax1_type=$object->lines[$i]->localtax1_type;
432  $localtax2_type=$object->lines[$i]->localtax2_type;
433 
434  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
435  if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
436  if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
437 
438  $vatrate=(string) $object->lines[$i]->tva_tx;
439 
440  // Retrieve type from database for backward compatibility with old records
441  if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
442  && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
443  {
444  $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
445  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
446  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
447  }
448 
449  // retrieve global local tax
450  if ($localtax1_type && $localtax1ligne != 0)
451  $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
452  if ($localtax2_type && $localtax2ligne != 0)
453  $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
454 
455  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
456  if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
457  $this->tva[$vatrate] += $tvaligne;
458 
459  // Add line
460  if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
461  {
462  $pdf->setPage($pageposafter);
463  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
464  //$pdf->SetDrawColor(190,190,200);
465  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
466  $pdf->SetLineStyle(array('dash'=>0));
467  }
468 
469  $nexY+=2; // Add space between lines
470 
471  // Detect if some page were added automatically and output _tableau for past pages
472  while ($pagenb < $pageposafter)
473  {
474  $pdf->setPage($pagenb);
475  if ($pagenb == 1)
476  {
477  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
478  }
479  else
480  {
481  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
482  }
483  $this->_pagefoot($pdf,$object,$outputlangs,1);
484  $pagenb++;
485  $pdf->setPage($pagenb);
486  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
487  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
488  }
489  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
490  {
491  if ($pagenb == 1)
492  {
493  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
494  }
495  else
496  {
497  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
498  }
499  $this->_pagefoot($pdf,$object,$outputlangs,1);
500  // New page
501  $pdf->AddPage();
502  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
503  $pagenb++;
504  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
505  }
506  }
507 
508  // Show square
509  if ($pagenb == 1)
510  {
511  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
512  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
513  }
514  else
515  {
516  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
517  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
518  }
519  */
520 
521  // Affiche zone infos
522  //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
523 
524  // Pied de page
525  $this->_pagefoot($pdf, $object, $outputlangs);
526  if (method_exists($pdf, 'AliasNbPages')) {
527  $pdf->AliasNbPages();
528  }
529 
530  $pdf->Close();
531 
532  $pdf->Output($file, 'F');
533 
534  // Add pdfgeneration hook
535  $hookmanager->initHooks(array('pdfgeneration'));
536  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
537  global $action;
538  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
539  if ($reshook < 0) {
540  $this->error = $hookmanager->error;
541  $this->errors = $hookmanager->errors;
542  }
543 
544  if (!empty($conf->global->MAIN_UMASK)) {
545  @chmod($file, octdec($conf->global->MAIN_UMASK));
546  }
547 
548  $this->result = array('fullpath'=>$file);
549 
550  return 1; // No error
551  } else {
552  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
553  return 0;
554  }
555  } else {
556  $this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR");
557  return 0;
558  }
559  }
560 
561  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
575  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
576  {
577  global $conf;
578 
579  // Force to disable hidetop and hidebottom
580  $hidebottom = 0;
581  if ($hidetop) {
582  $hidetop = -1;
583  }
584 
585  $currency = !empty($currency) ? $currency : $conf->currency;
586  $default_font_size = pdf_getPDFFontSize($outputlangs);
587 
588  // Amount in (at tab_top - 1)
589  $pdf->SetTextColor(0, 0, 0);
590  $pdf->SetFont('', '', $default_font_size - 2);
591 
592  if (empty($hidetop)) {
593  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
594  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
595  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
596 
597  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
598  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
599  $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));
600  }
601  }
602 
603  $pdf->SetDrawColor(128, 128, 128);
604  $pdf->SetFont('', '', $default_font_size - 1);
605 
606  // Output Rect
607  $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
608 
609  if (empty($hidetop)) {
610  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); // line takes a position y in 2nd parameter and 4th parameter
611 
612  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
613  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
614  }
615 
616  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
617  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
618  if (empty($hidetop)) {
619  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
620  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
621  }
622  }
623 
624  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
625  if (empty($hidetop)) {
626  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
627  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
628  }
629 
630  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
631  if (empty($hidetop)) {
632  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
633  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
634  }
635 
636  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
637  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
638  if (empty($hidetop)) {
639  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
640  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
641  }
642  }
643 
644  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
645  if (empty($hidetop)) {
646  if ($this->atleastonediscount) {
647  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
648  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
649  }
650  }
651 
652  if ($this->atleastonediscount) {
653  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
654  }
655  if (empty($hidetop)) {
656  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
657  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
658  }
659  }
660 
661  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
672  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "")
673  {
674  global $conf, $langs, $hookmanager;
675 
676  // Load traductions files required by page
677  $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders"));
678 
679  $default_font_size = pdf_getPDFFontSize($outputlangs);
680 
681  if ($object->type == 1) {
682  $titlekey = 'ServiceSheet';
683  } else {
684  $titlekey = 'ProductSheet';
685  }
686 
687  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
688 
689  // Show Draft Watermark
690  if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK))) {
691  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
692  }
693 
694  $pdf->SetTextColor(0, 0, 60);
695  $pdf->SetFont('', 'B', $default_font_size + 3);
696 
697  $posy = $this->marge_haute;
698  $posx = $this->page_largeur - $this->marge_droite - 100;
699 
700  $pdf->SetXY($this->marge_gauche, $posy);
701 
702  // Logo
703  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
704  if ($this->emetteur->logo) {
705  if (is_readable($logo)) {
706  $height = pdf_getHeightForLogo($logo);
707  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
708  } else {
709  $pdf->SetTextColor(200, 0, 0);
710  $pdf->SetFont('', 'B', $default_font_size - 2);
711  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
712  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
713  }
714  } else {
715  $text = $this->emetteur->name;
716  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
717  }
718 
719  $pdf->SetFont('', 'B', $default_font_size + 3);
720  $pdf->SetXY($posx, $posy);
721  $pdf->SetTextColor(0, 0, 60);
722  $title = $outputlangs->transnoentities($titlekey);
723  $pdf->MultiCell(100, 3, $title, '', 'R');
724 
725  $pdf->SetFont('', 'B', $default_font_size);
726 
727  $posy += 5;
728  $pdf->SetXY($posx, $posy);
729  $pdf->SetTextColor(0, 0, 60);
730  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
731 
732  $posy += 1;
733  $pdf->SetFont('', '', $default_font_size - 1);
734 
735  /*if ($object->ref_client)
736  {
737  $posy+=5;
738  $pdf->SetXY($posx,$posy);
739  $pdf->SetTextColor(0,0,60);
740  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
741  }*/
742 
743  /*$posy+=4;
744  $pdf->SetXY($posx,$posy);
745  $pdf->SetTextColor(0,0,60);
746  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
747  */
748 
749  // Get contact
750  /*
751  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
752  {
753  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
754  if (count($arrayidcontact) > 0)
755  {
756  $usertmp=new User($this->db);
757  $usertmp->fetch($arrayidcontact[0]);
758  $posy+=4;
759  $pdf->SetXY($posx,$posy);
760  $pdf->SetTextColor(0,0,60);
761  $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
762  }
763  }*/
764 
765  $posy += 2;
766 
767  // Show list of linked objects
768  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
769 
770  if ($showaddress) {
771  /*
772  // Sender properties
773  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
774 
775  // Show sender
776  $posy=42;
777  $posx=$this->marge_gauche;
778  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
779  $hautcadre=40;
780 
781  // Show sender frame
782  $pdf->SetTextColor(0,0,0);
783  $pdf->SetFont('','', $default_font_size - 2);
784  $pdf->SetXY($posx,$posy-5);
785  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
786  $pdf->SetXY($posx,$posy);
787  $pdf->SetFillColor(230,230,230);
788  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
789  $pdf->SetTextColor(0,0,60);
790 
791  // Show sender name
792  $pdf->SetXY($posx+2,$posy+3);
793  $pdf->SetFont('','B', $default_font_size);
794  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
795  $posy=$pdf->getY();
796 
797  // Show sender information
798  $pdf->SetXY($posx+2,$posy);
799  $pdf->SetFont('','', $default_font_size - 1);
800  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
801  */
802  }
803 
804  $pdf->SetTextColor(0, 0, 0);
805  }
806 
807  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
817  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
818  {
819  global $conf;
820  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
821  return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
822  }
823 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
ProductFournisseur
Class to manage predefined suppliers products.
Definition: fournisseur.product.class.php:41
pdf_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_standard\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_standard.modules.php:1130
pdf_standard\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_standard.modules.php:654
name
$conf db name
Definition: repair.php:122
measuringUnitString
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
Definition: product.lib.php:619
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7248
pdf_pagehead
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:711
pdf_standard\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
Show top header of page.
Definition: pdf_standard.modules.php:672
pdf_watermark
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:757
pdf_getHeightForLogo
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
CommonDocGenerator\printRect
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Definition: commondocgenerator.class.php:977
pdf_writeLinkedObjects
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1309
convertBackOfficeMediasLinksToPublicLinks
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
Definition: functions2.lib.php:2711
ModelePDFProduct
Parent class to manage intervention document templates.
Definition: modules_product.class.php:34
pdf_standard\write_file
write_file($object, $outputlangs, $srctemplatepath, $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
Definition: pdf_standard.modules.php:129
User
Class to manage Dolibarr users.
Definition: user.class.php:44
pdf_standard\__construct
__construct($db)
Constructor.
Definition: pdf_standard.modules.php:83
dol_htmlentitiesbr
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...
Definition: functions.lib.php:6991
pdf_standard\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
Definition: pdf_standard.modules.php:575
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getSubstitutionArray
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:737
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
pdf_standard
Class to generate expense report based on standard model.
Definition: pdf_standard.modules.php:45
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
complete_substitutions_array
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...
Definition: functions.lib.php:7961
pdf_pagefoot
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition: pdf.lib.php:989