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