dolibarr  18.0.0-alpha
pdf_standard.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@products.sourceforge.net>
3  * Copyright (C) 2023 Anthony Berton <anthony.berton@bb2a.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  * or see https://www.gnu.org/
18  */
19 
26 require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
33 
34 
38 class pdf_standard extends ModelePDFProduct
39 {
43  public $db;
44 
48  public $name;
49 
53  public $description;
54 
58  public $type;
59 
64  public $phpmin = array(7, 0);
65 
70  public $version = 'dolibarr';
71 
76  public $emetteur;
77 
78 
84  public function __construct($db)
85  {
86  global $conf, $langs, $mysoc;
87 
88  // Load traductions files required by page
89  $langs->loadLangs(array("main", "companies"));
90 
91  $this->db = $db;
92  $this->name = "standard";
93  $this->description = $langs->trans("DocumentModelStandardPDF");
94 
95  // Page size for A4 format
96  $this->type = 'pdf';
97  $formatarray = pdf_getFormat();
98  $this->page_largeur = $formatarray['width'];
99  $this->page_hauteur = $formatarray['height'];
100  $this->format = array($this->page_largeur, $this->page_hauteur);
101  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
102  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
103  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
104  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
105 
106  $this->option_logo = 1; // Display logo
107  $this->option_multilang = 1; // Available in several languages
108  $this->option_freetext = 0; // Support add of a personalised text
109 
110  // Get source company
111  $this->emetteur = $mysoc;
112  if (!$this->emetteur->country_code) {
113  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
114  }
115  }
116 
117 
118  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
130  public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
131  {
132  // phpcs:enable
133  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
134 
135  if (!is_object($outputlangs)) {
136  $outputlangs = $langs;
137  }
138  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
139  if (!empty($conf->global->MAIN_USE_FPDF)) {
140  $outputlangs->charset_output = 'ISO-8859-1';
141  }
142 
143  // Load traductions files required by page
144  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "orders", "deliveries"));
145 
146  if (is_array($object->lines)) {
147  $nblines = count($object->lines);
148  } else {
149  $nblines = 0;
150  }
151 
152  if ($conf->product->dir_output) {
153  // Definition of $dir and $file
154  if ($object->specimen) {
155  $dir = $conf->product->dir_output;
156  $file = $dir."/SPECIMEN.pdf";
157  } else {
158  $objectref = dol_sanitizeFileName($object->ref);
159  $dir = $conf->product->dir_output."/".$objectref;
160  $file = $dir."/".$objectref.".pdf";
161  }
162 
163  $productFournisseur = new ProductFournisseur($this->db);
164  $supplierprices = $productFournisseur->list_product_fournisseur_price($object->id);
165  $object->supplierprices = $supplierprices;
166 
167  if (!file_exists($dir)) {
168  if (dol_mkdir($dir) < 0) {
169  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
170  return -1;
171  }
172  }
173 
174  if (file_exists($dir)) {
175  // Add pdfgeneration hook
176  if (!is_object($hookmanager)) {
177  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
178  $hookmanager = new HookManager($this->db);
179  }
180  $hookmanager->initHooks(array('pdfgeneration'));
181  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
182  global $action;
183  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
184 
185  // Create pdf instance
186  $pdf = pdf_getInstance($this->format);
187  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
188  $pdf->SetAutoPageBreak(1, 0);
189 
190  $heightforinfotot = 40; // Height reserved to output the info and total part
191  $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
192  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
193  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
194  $heightforfooter += 6;
195  }
196 
197  if (class_exists('TCPDF')) {
198  $pdf->setPrintHeader(false);
199  $pdf->setPrintFooter(false);
200  }
201  $pdf->SetFont(pdf_getPDFFont($outputlangs));
202  // Set path to the background PDF File
203  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
204  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
205  $tplidx = $pdf->importPage(1);
206  }
207 
208  $pdf->Open();
209  $pagenb = 0;
210  $pdf->SetDrawColor(128, 128, 128);
211 
212  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
213  $pdf->SetSubject($outputlangs->transnoentities("Product"));
214  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
215  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
216  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Product"));
217  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
218  $pdf->SetCompression(false);
219  }
220 
221  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
222 
223 
224  // New page
225  $pdf->AddPage();
226  if (!empty($tplidx)) {
227  $pdf->useTemplate($tplidx);
228  }
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 = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
238 
239  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
240 
241  // Label of product
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  // Show photo
247  if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
248  $pdir[0] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/";
249  $pdir[1] = get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref).'/';
250  } else {
251  $pdir[0] = get_exdir(0, 0, 0, 0, $object, 'product'); // default
252  $pdir[1] = get_exdir($object->id, 2, 0, 0, $object, 'product').$object->id."/photos/"; // alternative
253  }
254 
255  $arephoto = false;
256  foreach ($pdir as $midir) {
257  if (!$arephoto) {
258  if ($conf->entity != $object->entity) {
259  $dir = $conf->product->multidir_output[$object->entity].'/'.$midir; //Check repertories of current entities
260  } else {
261  $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
262  }
263  foreach ($object->liste_photos($dir, 1) as $key => $obj) {
264  if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
265  if ($obj['photo_vignette']) {
266  $filename = $obj['photo_vignette'];
267  } else {
268  $filename = $obj['photo'];
269  }
270  } else {
271  $filename = $obj['photo'];
272  }
273  $realpath = $dir.$filename;
274  $arephoto = true;
275  }
276  }
277  }
278  // Define size of image if we need it
279  $imglinesize = array();
280  if (!empty($realpath) && $arephoto) {
281  $imgsize = pdf_getSizeForImage($realpath);
282  $imgsizewidth = $imgsize['width'] + 20;
283  $imgsizeheight = $imgsize['height'] + 20;
284 
285  $midelpage = ($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2;
286  $posxphoto = $midelpage + ($midelpage / 2) - ($imgsizewidth / 2);
287  $posyphoto = $tab_top - 1;
288  $pdf->Image($realpath, $posxphoto, $posyphoto, $imgsizewidth, $imgsizeheight, '', '', '', 2, 300); // Use 300 dpi
289  $nexyafterphoto = $tab_top + $imgsizeheight;
290  }
291 
292  // Description
293  $pdf->SetFont('', '', $default_font_size);
294  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, dol_htmlentitiesbr($object->description), 0, 1);
295  $nexY = $pdf->GetY();
296 
297  $nexY += 5;
298 
299  $outputlangs->load("other");
300  if ($object->weight) {
301  $texttoshow = $langs->trans("Weight").': '.dol_htmlentitiesbr($object->weight);
302  if (isset($object->weight_units)) {
303  $texttoshow .= ' '.measuring_units_string($object->weight_units, 'weight', 0, 0, $outputlangs);
304  }
305  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
306  $nexY = $pdf->GetY();
307  }
308  if ($object->length) {
309  $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 : '?');
310  $texttoshow .= ' ' . measuringUnitString(0, "size", $object->length_units);
311  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
312  $nexY = $pdf->GetY();
313  }
314  if ($object->surface) {
315  $texttoshow = $langs->trans("Surface") . ': ' . dol_htmlentitiesbr($object->surface);
316  $texttoshow .= ' ' . measuringUnitString(0, "surface", $object->surface_units);
317  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
318  $nexY = $pdf->GetY();
319  }
320  if ($object->volume) {
321  $texttoshow = $langs->trans("Volume") . ': ' . dol_htmlentitiesbr($object->volume);
322  $texttoshow .= ' ' . measuringUnitString(0, "volume", $object->volume_units);
323  $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $texttoshow, 0, 1);
324  $nexY = $pdf->GetY();
325  }
326 
327  $tab_top = 88;
328  if (!empty($nexyafterphoto) && $nexyafterphoto > $tab_top) {
329  $tab_top = $nexyafterphoto;
330  }
331 
332  // Show notes
333  // TODO There is no public note on product yet
334  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
335  if ($notetoshow) {
336  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
337  complete_substitutions_array($substitutionarray, $outputlangs, $object);
338  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
339  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
340 
341  $pdf->SetFont('', '', $default_font_size - 1);
342  $pdf->writeHTMLCell(190, 3, $this->marge_gauche - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
343  $nexY = $pdf->GetY();
344  $height_note = $nexY - $tab_top;
345 
346  // Rect takes a length in 3rd parameter
347  $pdf->SetDrawColor(192, 192, 192);
348  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
349 
350  $tab_height = $tab_height - $height_note;
351  $tab_top = $nexY + 6;
352  } else {
353  $height_note = 0;
354  }
355 
356  $iniY = $tab_top + 7;
357  $curY = $tab_top + 7;
358  $nexY = $tab_top + 7;
359 
360  // Loop on each lines
361  /*
362  for ($i = 0 ; $i < $nblines ; $i++)
363  {
364  $curY = $nexY;
365  $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
366  $pdf->SetTextColor(0,0,0);
367 
368  $pdf->setTopMargin($tab_top_newpage);
369  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
370  $pageposbefore=$pdf->getPage();
371 
372  // Description of product line
373  $curX = $this->posxdesc-1;
374 
375  $showpricebeforepagebreak=1;
376 
377  $pdf->startTransaction();
378  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
379  $pageposafter=$pdf->getPage();
380  if ($pageposafter > $pageposbefore) // There is a pagebreak
381  {
382  $pdf->rollbackTransaction(true);
383  $pageposafter=$pageposbefore;
384  //print $pageposafter.'-'.$pageposbefore;exit;
385  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
386  pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
387  $pageposafter=$pdf->getPage();
388  $posyafter=$pdf->GetY();
389  if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
390  {
391  if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page
392  {
393  $pdf->AddPage('','',true);
394  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
395  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
396  $pdf->setPage($pageposafter+1);
397  }
398  }
399  else
400  {
401  // We found a page break
402  $showpricebeforepagebreak=0;
403  }
404  }
405  else // No pagebreak
406  {
407  $pdf->commitTransaction();
408  }
409 
410  $nexY = $pdf->GetY();
411  $pageposafter=$pdf->getPage();
412  $pdf->setPage($pageposbefore);
413  $pdf->setTopMargin($this->marge_haute);
414  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
415 
416  // We suppose that a too long description is moved completely on next page
417  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
418  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
419  }
420 
421  $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
422 
423  // VAT Rate
424  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
425  {
426  $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
427  $pdf->SetXY($this->posxtva, $curY);
428  $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R');
429  }
430 
431  // Unit price before discount
432  $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
433  $pdf->SetXY($this->posxup, $curY);
434  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
435 
436  // Quantity
437  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
438  $pdf->SetXY($this->posxqty, $curY);
439  $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
440 
441  // Unit
442  if($conf->global->PRODUCT_USE_UNITS)
443  {
444  $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
445  $pdf->SetXY($this->posxunit, $curY);
446  $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
447  }
448 
449  // Discount on line
450  $pdf->SetXY($this->posxdiscount, $curY);
451  if ($object->lines[$i]->remise_percent)
452  {
453  $pdf->SetXY($this->posxdiscount-2, $curY);
454  $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
455  $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
456  }
457 
458  // Total HT line
459  $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
460  $pdf->SetXY($this->postotalht, $curY);
461  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
462 
463  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
464  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
465  else $tvaligne=$object->lines[$i]->total_tva;
466 
467  $localtax1ligne=$object->lines[$i]->total_localtax1;
468  $localtax2ligne=$object->lines[$i]->total_localtax2;
469  $localtax1_rate=$object->lines[$i]->localtax1_tx;
470  $localtax2_rate=$object->lines[$i]->localtax2_tx;
471  $localtax1_type=$object->lines[$i]->localtax1_type;
472  $localtax2_type=$object->lines[$i]->localtax2_type;
473 
474  if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
475  if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
476  if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
477 
478  $vatrate=(string) $object->lines[$i]->tva_tx;
479 
480  // Retrieve type from database for backward compatibility with old records
481  if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
482  && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax
483  {
484  $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
485  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
486  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
487  }
488 
489  // retrieve global local tax
490  if ($localtax1_type && $localtax1ligne != 0)
491  $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
492  if ($localtax2_type && $localtax2ligne != 0)
493  $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
494 
495  if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
496  if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
497  $this->tva[$vatrate] += $tvaligne;
498 
499  // Add line
500  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
501  {
502  $pdf->setPage($pageposafter);
503  $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
504  //$pdf->SetDrawColor(190,190,200);
505  $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
506  $pdf->SetLineStyle(array('dash'=>0));
507  }
508 
509  $nexY+=2; // Add space between lines
510 
511  // Detect if some page were added automatically and output _tableau for past pages
512  while ($pagenb < $pageposafter)
513  {
514  $pdf->setPage($pagenb);
515  if ($pagenb == 1)
516  {
517  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
518  }
519  else
520  {
521  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
522  }
523  $this->_pagefoot($pdf,$object,$outputlangs,1);
524  $pagenb++;
525  $pdf->setPage($pagenb);
526  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
527  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
528  }
529  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
530  {
531  if ($pagenb == 1)
532  {
533  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
534  }
535  else
536  {
537  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
538  }
539  $this->_pagefoot($pdf,$object,$outputlangs,1);
540  // New page
541  $pdf->AddPage();
542  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
543  $pagenb++;
544  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) $this->_pagehead($pdf, $object, 0, $outputlangs);
545  }
546  }
547 
548  // Show square
549  if ($pagenb == 1)
550  {
551  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
552  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
553  }
554  else
555  {
556  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
557  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
558  }
559  */
560 
561  // Affiche zone infos
562  //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
563 
564  // Pied de page
565  $this->_pagefoot($pdf, $object, $outputlangs);
566  if (method_exists($pdf, 'AliasNbPages')) {
567  $pdf->AliasNbPages();
568  }
569 
570  $pdf->Close();
571 
572  $pdf->Output($file, 'F');
573 
574  // Add pdfgeneration hook
575  $hookmanager->initHooks(array('pdfgeneration'));
576  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
577  global $action;
578  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
579  if ($reshook < 0) {
580  $this->error = $hookmanager->error;
581  $this->errors = $hookmanager->errors;
582  }
583 
584  dolChmod($file);
585 
586  $this->result = array('fullpath'=>$file);
587 
588  return 1; // No error
589  } else {
590  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
591  return 0;
592  }
593  } else {
594  $this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR");
595  return 0;
596  }
597  }
598 
599  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
613  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
614  {
615  global $conf;
616 
617  // Force to disable hidetop and hidebottom
618  $hidebottom = 0;
619  if ($hidetop) {
620  $hidetop = -1;
621  }
622 
623  $currency = !empty($currency) ? $currency : $conf->currency;
624  $default_font_size = pdf_getPDFFontSize($outputlangs);
625 
626  // Amount in (at tab_top - 1)
627  $pdf->SetTextColor(0, 0, 0);
628  $pdf->SetFont('', '', $default_font_size - 2);
629 
630  if (empty($hidetop)) {
631  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
632  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
633  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
634 
635  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
636  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
637  $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));
638  }
639  }
640 
641  $pdf->SetDrawColor(128, 128, 128);
642  $pdf->SetFont('', '', $default_font_size - 1);
643 
644  // Output Rect
645  $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
646 
647  if (empty($hidetop)) {
648  $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
649 
650  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
651  $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
652  }
653 
654  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
655  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
656  if (empty($hidetop)) {
657  $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
658  $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
659  }
660  }
661 
662  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
663  if (empty($hidetop)) {
664  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
665  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
666  }
667 
668  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
669  if (empty($hidetop)) {
670  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
671  $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
672  }
673 
674  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
675  $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
676  if (empty($hidetop)) {
677  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
678  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
679  }
680  }
681 
682  $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
683  if (empty($hidetop)) {
684  if ($this->atleastonediscount) {
685  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
686  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
687  }
688  }
689 
690  if ($this->atleastonediscount) {
691  $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
692  }
693  if (empty($hidetop)) {
694  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
695  $pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
696  }
697  }
698 
699  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
710  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "")
711  {
712  global $conf, $langs, $hookmanager;
713 
714  $ltrdirection = 'L';
715  if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
716 
717  // Load traductions files required by page
718  $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders"));
719 
720  $default_font_size = pdf_getPDFFontSize($outputlangs);
721 
722  if ($object->type == 1) {
723  $titlekey = 'ServiceSheet';
724  } else {
725  $titlekey = 'ProductSheet';
726  }
727 
728  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
729 
730  // Show Draft Watermark
731  if ($object->statut == 0 && getDolGlobalString('PRODUCT_DRAFT_WATERMARK')) {
732  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
733  }
734 
735  $pdf->SetTextColor(0, 0, 60);
736  $pdf->SetFont('', 'B', $default_font_size + 3);
737 
738  $w = 100;
739 
740  $posy = $this->marge_haute;
741  $posx = $this->page_largeur - $this->marge_droite - 100;
742 
743  $pdf->SetXY($this->marge_gauche, $posy);
744 
745  // Logo
746  if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
747  if ($this->emetteur->logo) {
748  $logodir = $conf->mycompany->dir_output;
749  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
750  $logodir = $conf->mycompany->multidir_output[$object->entity];
751  }
752  if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
753  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
754  } else {
755  $logo = $logodir.'/logos/'.$this->emetteur->logo;
756  }
757  if (is_readable($logo)) {
758  $height = pdf_getHeightForLogo($logo);
759  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
760  } else {
761  $pdf->SetTextColor(200, 0, 0);
762  $pdf->SetFont('', 'B', $default_font_size - 2);
763  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
764  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
765  }
766  } else {
767  $text = $this->emetteur->name;
768  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
769  }
770  }
771 
772 
773  $pdf->SetFont('', 'B', $default_font_size + 3);
774  $pdf->SetXY($posx, $posy);
775  $pdf->SetTextColor(0, 0, 60);
776  $title = $outputlangs->transnoentities($titlekey);
777  $pdf->MultiCell(100, 3, $title, '', 'R');
778 
779  $pdf->SetFont('', 'B', $default_font_size);
780 
781  $posy += 5;
782  $pdf->SetXY($posx, $posy);
783  $pdf->SetTextColor(0, 0, 60);
784  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
785 
786  $posy += 1;
787  $pdf->SetFont('', '', $default_font_size - 1);
788 
789  /*if ($object->ref_client)
790  {
791  $posy+=5;
792  $pdf->SetXY($posx,$posy);
793  $pdf->SetTextColor(0,0,60);
794  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
795  }*/
796 
797  /*$posy+=4;
798  $pdf->SetXY($posx,$posy);
799  $pdf->SetTextColor(0,0,60);
800  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
801  */
802 
803  // Get contact
804  /*
805  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
806  {
807  $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
808  if (count($arrayidcontact) > 0)
809  {
810  $usertmp=new User($this->db);
811  $usertmp->fetch($arrayidcontact[0]);
812  $posy+=4;
813  $pdf->SetXY($posx,$posy);
814  $pdf->SetTextColor(0,0,60);
815  $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
816  }
817  }*/
818 
819  $posy += 2;
820 
821  // Show list of linked objects
822  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
823 
824  if ($showaddress) {
825  /*
826  // Sender properties
827  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
828 
829  // Show sender
830  $posy=42;
831  $posx=$this->marge_gauche;
832  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
833  $hautcadre=40;
834 
835  // Show sender frame
836  $pdf->SetTextColor(0,0,0);
837  $pdf->SetFont('','', $default_font_size - 2);
838  $pdf->SetXY($posx,$posy-5);
839  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillFrom"), 0, 'L');
840  $pdf->SetXY($posx,$posy);
841  $pdf->SetFillColor(230,230,230);
842  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
843  $pdf->SetTextColor(0,0,60);
844 
845  // Show sender name
846  $pdf->SetXY($posx+2,$posy+3);
847  $pdf->SetFont('','B', $default_font_size);
848  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
849  $posy=$pdf->getY();
850 
851  // Show sender information
852  $pdf->SetXY($posx+2,$posy);
853  $pdf->SetFont('','', $default_font_size - 1);
854  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
855  */
856  }
857 
858  $pdf->SetTextColor(0, 0, 0);
859  }
860 
861  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
871  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
872  {
873  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
874  return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
875  }
876 }
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:8210
db
$conf db
API class for accounts.
Definition: inc.php:41
pdf_getSizeForImage
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
Definition: pdf.lib.php:2505
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1236
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:40
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:805
dolChmod
dolChmod($filepath, $newmask='')
Change mod of a file.
Definition: functions.lib.php:6882
pdf_pagehead
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:718
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6757
pdf_standard\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
Show top header of page.
Definition: pdf_standard.modules.php:710
pdf_watermark
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:764
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:1010
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:1318
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:2723
ModelePDFProduct
Parent class to manage intervention document templates.
Definition: modules_product.class.php:34
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
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:130
pdf_standard\__construct
__construct($db)
Constructor.
Definition: pdf_standard.modules.php:84
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:7325
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:613
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:744
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6811
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
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:8333
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:996