dolibarr  13.0.2
pdf_standard.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@stocks.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/stock/modules_stock.php';
26 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.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 ModelePDFStock
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 
74  public $page_largeur;
75 
79  public $page_hauteur;
80 
84  public $format;
85 
89  public $marge_gauche;
90 
94  public $marge_droite;
95 
99  public $marge_haute;
100 
104  public $marge_basse;
105 
110  public $emetteur;
111 
112 
118  public function __construct($db)
119  {
120  global $conf, $langs, $mysoc;
121 
122  // Load traductions files required by page
123  $langs->loadLangs(array("main", "companies"));
124 
125  $this->db = $db;
126  $this->name = "standard";
127  $this->description = $langs->trans("DocumentModelStandardPDF");
128 
129  // Page size for A4 format
130  $this->type = 'pdf';
131  $formatarray = pdf_getFormat();
132  $this->page_largeur = $formatarray['width'];
133  $this->page_hauteur = $formatarray['height'];
134  $this->format = array($this->page_largeur, $this->page_hauteur);
135  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
136  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
137  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
138  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
139 
140  $this->option_logo = 1; // Affiche logo
141  $this->option_codestockservice = 0; // Affiche code stock-service
142  $this->option_multilang = 1; // Dispo en plusieurs langues
143  $this->option_freetext = 0; // Support add of a personalised text
144 
145  // Recupere emetteur
146  $this->emetteur = $mysoc;
147  if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
148 
149  // Define position of columns
150  $this->wref = 35;
151  $this->posxdesc = $this->marge_gauche + 1;
152  $this->posxlabel = $this->posxdesc + $this->wref;
153  $this->posxtva = 80;
154  $this->posxqty = 95;
155  $this->posxup = 115;
156  $this->posxunit = 135;
157  $this->posxdiscount = 155;
158  $this->postotalht = 175;
159 
160  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva = $this->posxup;
161  $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
162  if ($this->page_largeur < 210) // To work with US executive format
163  {
164  $this->posxpicture -= 20;
165  $this->posxtva -= 20;
166  $this->posxup -= 20;
167  $this->posxqty -= 20;
168  $this->posxunit -= 20;
169  $this->posxdiscount -= 20;
170  $this->postotalht -= 20;
171  }
172  $this->tva = array();
173  $this->localtax1 = array();
174  $this->localtax2 = array();
175  $this->atleastoneratenotnull = 0;
176  $this->atleastonediscount = 0;
177  }
178 
179 
180  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
192  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
193  {
194  // phpcs:enable
195  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
196 
197  if (!is_object($outputlangs)) $outputlangs = $langs;
198  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
199  if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
200 
201  // Load traductions files required by page
202  $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
203 
204  $nblines = count($object->lines);
205 
206  if ($conf->stock->dir_output)
207  {
208  // Definition of $dir and $file
209  if ($object->specimen)
210  {
211  $dir = $conf->stock->dir_output;
212  $file = $dir."/SPECIMEN.pdf";
213  } else {
214  $objectref = dol_sanitizeFileName($object->ref);
215  $dir = $conf->stock->dir_output."/".$objectref;
216  $file = $dir."/".$objectref.".pdf";
217  }
218 
219  $stockFournisseur = new ProductFournisseur($this->db);
220  $supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
221  $object->supplierprices = $supplierprices;
222 
223  $productstatic = new Product($this->db);
224 
225  if (!file_exists($dir))
226  {
227  if (dol_mkdir($dir) < 0)
228  {
229  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
230  return -1;
231  }
232  }
233 
234  if (file_exists($dir))
235  {
236  // Add pdfgeneration hook
237  if (!is_object($hookmanager))
238  {
239  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
240  $hookmanager = new HookManager($this->db);
241  }
242  $hookmanager->initHooks(array('pdfgeneration'));
243  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
244  global $action;
245  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
246 
247  // Create pdf instance
248  $pdf = pdf_getInstance($this->format);
249  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
250  $pdf->SetAutoPageBreak(1, 0);
251 
252  $heightforinfotot = 40; // Height reserved to output the info and total part
253  $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
254  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
255 
256  if (class_exists('TCPDF'))
257  {
258  $pdf->setPrintHeader(false);
259  $pdf->setPrintFooter(false);
260  }
261  $pdf->SetFont(pdf_getPDFFont($outputlangs));
262  // Set path to the background PDF File
263  if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
264  {
265  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
266  $tplidx = $pdf->importPage(1);
267  }
268 
269  $pdf->Open();
270  $pagenb = 0;
271  $pdf->SetDrawColor(128, 128, 128);
272 
273  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
274  $pdf->SetSubject($outputlangs->transnoentities("Stock"));
275  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
276  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
277  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Stock")." ".$outputlangs->convToOutputCharset($object->label));
278  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
279 
280  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
281 
282 
283  // New page
284  $pdf->AddPage();
285  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
286  $pagenb++;
287  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
288  $pdf->SetFont('', '', $default_font_size - 1);
289  $pdf->MultiCell(0, 3, ''); // Set interline to 3
290  $pdf->SetTextColor(0, 0, 0);
291 
292  $tab_top = 80 + $top_shift;
293  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
294 
295  $tab_height = 130;
296 
297 
298  /* ************************************************************************** */
299  /* */
300  /* Show list of product in warehouse */
301  /* */
302  /* ************************************************************************** */
303 
304  $totalunit = 0;
305  $totalvalue = $totalvaluesell = 0;
306 
307  $sortfield = 'p.ref';
308  $sortorder = 'ASC';
309 
310  $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc, p.entity,";
311  $sql .= " ps.reel as value";
312  $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
313  $sql .= " WHERE ps.fk_product = p.rowid";
314  $sql .= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
315  $sql .= " AND ps.fk_entrepot = ".$object->id;
316  $sql .= $this->db->order($sortfield, $sortorder);
317 
318  //dol_syslog('List products', LOG_DEBUG);
319  $resql = $this->db->query($sql);
320  if ($resql)
321  {
322  $num = $this->db->num_rows($resql);
323  $i = 0;
324  $nblines = $num;
325 
326  $this->tabTitleHeight = 0;
327  $nexY = $tab_top + $this->tabTitleHeight;
328 
329  for ($i = 0; $i < $nblines; $i++)
330  {
331  $curY = $nexY;
332 
333  $objp = $this->db->fetch_object($resql);
334 
335  // Multilangs
336  if (!empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
337  {
338  $sql = "SELECT label";
339  $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
340  $sql .= " WHERE fk_product=".$objp->rowid;
341  $sql .= " AND lang='".$this->db->escape($langs->getDefaultLang())."'";
342  $sql .= " LIMIT 1";
343 
344  $result = $this->db->query($sql);
345  if ($result)
346  {
347  $objtp = $this->db->fetch_object($result);
348  if ($objtp->label != '') $objp->produit = $objtp->label;
349  }
350  }
351 
352  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
353  $pdf->SetTextColor(0, 0, 0);
354 
355  $pdf->setTopMargin($tab_top_newpage);
356  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
357  $pageposbefore = $pdf->getPage();
358 
359  // Description of product line
360  $curX = $this->posxdesc - 1;
361 
362  $showpricebeforepagebreak = 1;
363 
364  $pdf->startTransaction();
365  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc);
366  $pageposafter = $pdf->getPage();
367  if ($pageposafter > $pageposbefore) // There is a pagebreak
368  {
369  $pdf->rollbackTransaction(true);
370  $pageposafter = $pageposbefore;
371  //print $pageposafter.'-'.$pageposbefore;exit;
372  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
373  pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc);
374  $pageposafter = $pdf->getPage();
375  $posyafter = $pdf->GetY();
376  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text
377  {
378  if ($i == ($nblines - 1)) // No more lines, and no space left to show total, so we create a new page
379  {
380  $pdf->AddPage('', '', true);
381  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
382  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
383  $pdf->setPage($pageposafter + 1);
384  }
385  } else {
386  // We found a page break
387 
388  // Allows data in the first page if description is long enough to break in multiples pages
389  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
390  $showpricebeforepagebreak = 1;
391  else $showpricebeforepagebreak = 0;
392  }
393  } else // No pagebreak
394  {
395  $pdf->commitTransaction();
396  }
397  $posYAfterDescription = $pdf->GetY();
398 
399  $nexY = $pdf->GetY();
400  $pageposafter = $pdf->getPage();
401 
402  $pdf->setPage($pageposbefore);
403  $pdf->setTopMargin($this->marge_haute);
404  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
405 
406  // We suppose that a too long description is moved completely on next page
407  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
408  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
409  }
410 
411  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
412 
413  $productstatic->id = $objp->rowid;
414  $productstatic->ref = $objp->ref;
415  $productstatic->label = $objp->produit;
416  $productstatic->type = $objp->type;
417  $productstatic->entity = $objp->entity;
418  $productstatic->status_batch = $objp->tobatch;
419 
420  // Ref.
421  $pdf->SetXY($this->posxdesc, $curY);
422  $pdf->MultiCell($this->wref, 3, $productstatic->ref, 0, 'L');
423 
424  // Label
425  $pdf->SetXY($this->posxlabel + 0.8, $curY);
426  $pdf->MultiCell($this->posxqty - $this->posxlabel - 0.8, 3, dol_trunc($objp->produit, 24), 0, 'L');
427 
428  // Quantity
429  $valtoshow = price2num($objp->value, 'MS');
430  $towrite = (empty($valtoshow) ? '0' : $valtoshow);
431 
432  $pdf->SetXY($this->posxqty, $curY);
433  $pdf->MultiCell($this->posxup - $this->posxqty - 0.8, 3, $towrite, 0, 'R');
434 
435  // AWP
436  $totalunit += $objp->value;
437 
438  $pdf->SetXY($this->posxup, $curY);
439  $pdf->MultiCell($this->posxunit - $this->posxup - 0.8, 3, price(price2num($objp->ppmp, 'MU'), 0, $outputlangs), 0, 'R');
440 
441  // Total PMP
442  $pdf->SetXY($this->posxunit, $curY);
443  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 3, price(price2num($objp->ppmp * $objp->value, 'MT'), 0, $outputlangs), 0, 'R');
444  $totalvalue += price2num($objp->ppmp * $objp->value, 'MT');
445 
446  // Price sell min
447  if (empty($conf->global->PRODUIT_MULTIPRICES))
448  {
449  $pricemin = $objp->price;
450  $pdf->SetXY($this->posxdiscount, $curY);
451  $pdf->MultiCell($this->postotalht - $this->posxdiscount, 3, price(price2num($pricemin, 'MU'), 0, $outputlangs), 0, 'R', 0);
452 
453  // Total sell min
454  $pdf->SetXY($this->postotalht, $curY);
455  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, price(price2num($pricemin * $objp->value, 'MT'), 0, $outputlangs), 0, 'R', 0);
456  }
457  $totalvaluesell += price2num($pricemin * $objp->value, 'MT');
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  } else {
479  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
480  }
481  $this->_pagefoot($pdf, $object, $outputlangs, 1);
482  $pagenb++;
483  $pdf->setPage($pagenb);
484  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
485  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
486  }
487  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak)
488  {
489  if ($pagenb == 1)
490  {
491  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
492  } else {
493  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
494  }
495  $this->_pagefoot($pdf, $object, $outputlangs, 1);
496  // New page
497  $pdf->AddPage();
498  if (!empty($tplidx)) $pdf->useTemplate($tplidx);
499  $pagenb++;
500  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
501  }
502  }
503 
504  $this->db->free($resql);
505 
509  $nexY = $pdf->GetY();
510  $nexY += 2;
511  $curY = $nexY;
512 
513  if ($nblines > 0) {
514  $pdf->SetLineStyle(array('dash'=>'0', 'color'=>array(200, 200, 200)));
515  $pdf->line($this->marge_gauche, $curY - 1, $this->page_largeur - $this->marge_droite, $curY - 1);
516  $pdf->SetLineStyle(array('dash'=>0));
517 
518  $pdf->SetFont('', 'B', $default_font_size - 1);
519  $pdf->SetTextColor(0, 0, 120);
520 
521  // Ref.
522  $pdf->SetXY($this->posxdesc, $curY);
523  $pdf->MultiCell($this->wref, 3, $langs->trans("Total"), 0, 'L');
524 
525  // Quantity
526  $valtoshow = price2num($totalunit, 'MS');
527  $towrite = empty($valtoshow) ? '0' : $valtoshow;
528 
529  $pdf->SetXY($this->posxqty, $curY);
530  $pdf->MultiCell($this->posxup - $this->posxqty - 0.8, 3, $towrite, 0, 'R');
531 
532  // Total PMP
533  $pdf->SetXY($this->posxunit, $curY);
534  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 3, price(price2num($totalvalue, 'MT'), 0, $outputlangs), 0, 'R');
535 
536  // Price sell min
537  if (empty($conf->global->PRODUIT_MULTIPRICES))
538  {
539  // Total sell min
540  $pdf->SetXY($this->postotalht, $curY);
541  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, price(price2num($totalvaluesell, 'MT'), 0, $outputlangs), 0, 'R', 0);
542  }
543  }
544  } else {
545  dol_print_error($this->db);
546  }
547 
548  // Displays notes
549  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
550 
551  if ($notetoshow)
552  {
553  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
554  complete_substitutions_array($substitutionarray, $outputlangs, $object);
555  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
556  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
557 
558  $tab_top = 88;
559 
560  $pdf->SetFont('', '', $default_font_size - 1);
561  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
562  $nexY = $pdf->GetY();
563  $height_note = $nexY - $tab_top;
564 
565  // Rect takes a length in 3rd parameter
566  $pdf->SetDrawColor(192, 192, 192);
567  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
568 
569  $tab_height = $tab_height - $height_note;
570  $tab_top = $nexY + 6;
571  } else {
572  $height_note = 0;
573  }
574 
575  $iniY = $tab_top + 7;
576  $curY = $tab_top + 7;
577  $nexY = $tab_top + 7;
578 
579  $tab_top = $tab_top_newpage + 25 + $top_shift;
580 
581  // Show square
582  if ($pagenb == 1)
583  {
584  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
585  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
586  } else {
587  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
588  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
589  }
590 
591  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
592 
593  // Affiche zone infos
594  //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
595 
596  // Affiche zone totaux
597  //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
598 
599  // Pied de page
600  $this->_pagefoot($pdf, $object, $outputlangs);
601  if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
602 
603  $pdf->Close();
604 
605  $pdf->Output($file, 'F');
606 
607  // Add pdfgeneration hook
608  $hookmanager->initHooks(array('pdfgeneration'));
609  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
610  global $action;
611  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
612  if ($reshook < 0)
613  {
614  $this->error = $hookmanager->error;
615  $this->errors = $hookmanager->errors;
616  }
617 
618  if (!empty($conf->global->MAIN_UMASK))
619  @chmod($file, octdec($conf->global->MAIN_UMASK));
620 
621  $this->result = array('fullpath'=>$file);
622 
623  return 1; // No error
624  } else {
625  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
626  return 0;
627  }
628  } else {
629  $this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR");
630  return 0;
631  }
632  }
633 
634  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
648  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
649  {
650  global $conf;
651 
652  // Force to disable hidetop and hidebottom
653  $hidebottom = 0;
654  if ($hidetop) $hidetop = -1;
655 
656  $currency = !empty($currency) ? $currency : $conf->currency;
657  $default_font_size = pdf_getPDFFontSize($outputlangs);
658 
659  // Amount in (at tab_top - 1)
660  $pdf->SetTextColor(0, 0, 0);
661  $pdf->SetFont('', '', $default_font_size - 2);
662 
663  if (empty($hidetop))
664  {
665  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
666  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
667  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
668 
669  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
670  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
671  }
672 
673  $pdf->SetDrawColor(128, 128, 128);
674  $pdf->SetFont('', 'B', $default_font_size - 3);
675 
676  // Output Rect
677  //$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
678 
679  $pdf->SetLineStyle(array('dash'=>'0', 'color'=>array(200, 200, 200)));
680  $pdf->SetDrawColor(200, 200, 200);
681  $pdf->line($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite, $tab_top);
682  $pdf->SetLineStyle(array('dash'=>0));
683  $pdf->SetDrawColor(128, 128, 128);
684  $pdf->SetTextColor(0, 0, 120);
685 
686  if (empty($hidetop))
687  {
688  //$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
689  $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
690  $pdf->MultiCell($this->wref, 3, $outputlangs->transnoentities("Ref"), '', 'L');
691  }
692 
693  //$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
694  if (empty($hidetop))
695  {
696  $pdf->SetXY($this->posxlabel - 1, $tab_top + 1);
697  $pdf->MultiCell($this->posxqty - $this->posxlabel - 1, 2, $outputlangs->transnoentities("Label"), '', 'L');
698  }
699 
700  //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
701  if (empty($hidetop))
702  {
703  $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
704  $pdf->MultiCell($this->posxup - $this->posxqty - 1, 2, $outputlangs->transnoentities("Units"), '', 'R');
705  }
706 
707  //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
708  if (empty($hidetop))
709  {
710  $pdf->SetXY($this->posxup - 1, $tab_top + 1);
711  $pdf->MultiCell($this->posxunit - $this->posxup - 1, 2, $outputlangs->transnoentities("AverageUnitPricePMPShort"), '', 'R');
712  }
713 
714  //$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
715  if (empty($hidetop))
716  {
717  $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
718  $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("EstimatedStockValueShort"), '', 'R');
719  }
720 
721  //$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
722  if (empty($hidetop))
723  {
724  $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
725  $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities("SellPriceMin"), '', 'R');
726  }
727 
728  //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
729  if (empty($hidetop))
730  {
731  $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
732  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 2, $outputlangs->transnoentities("EstimatedStockValueSellShort"), '', 'R');
733  }
734 
735  $pdf->SetDrawColor(200, 200, 200);
736  $pdf->SetLineStyle(array('dash'=>'0', 'color'=>array(200, 200, 200)));
737  $pdf->line($this->marge_gauche, $tab_top + 11, $this->page_largeur - $this->marge_droite, $tab_top + 11);
738  $pdf->SetLineStyle(array('dash'=>0));
739  }
740 
741  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
752  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "")
753  {
754  global $conf, $langs, $db, $hookmanager;
755 
756  // Load traductions files required by page
757  $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
758 
759  $default_font_size = pdf_getPDFFontSize($outputlangs);
760 
761  if ($object->type == 1) $titlekey = 'ServiceSheet';
762  else $titlekey = 'StockSheet';
763 
764  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
765 
766  // Show Draft Watermark
767  if ($object->statut == 0 && (!empty($conf->global->COMMANDE_DRAFT_WATERMARK)))
768  {
769  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
770  }
771 
772  $pdf->SetTextColor(0, 0, 60);
773  $pdf->SetFont('', 'B', $default_font_size + 3);
774 
775  $posy = $this->marge_haute;
776  $posx = $this->page_largeur - $this->marge_droite - 100;
777 
778  $pdf->SetXY($this->marge_gauche, $posy);
779 
780  // Logo
781  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
782  if ($this->emetteur->logo)
783  {
784  if (is_readable($logo))
785  {
786  $height = pdf_getHeightForLogo($logo);
787  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
788  } else {
789  $pdf->SetTextColor(200, 0, 0);
790  $pdf->SetFont('', 'B', $default_font_size - 2);
791  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
792  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
793  }
794  } else {
795  $text = $this->emetteur->name;
796  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
797  }
798 
799  $pdf->SetFont('', 'B', $default_font_size + 3);
800  $pdf->SetXY($posx, $posy);
801  $pdf->SetTextColor(0, 0, 60);
802  $title = $outputlangs->transnoentities("Warehouse");
803  $pdf->MultiCell(100, 3, $title, '', 'R');
804 
805  $pdf->SetFont('', 'B', $default_font_size);
806 
807  $posy += 5;
808  $pdf->SetXY($posx, $posy);
809  $pdf->SetTextColor(0, 0, 60);
810 
811  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->label), '', 'R');
812 
813  $posy += 5;
814  $pdf->SetFont('', '', $default_font_size - 1);
815  $pdf->SetXY($posx, $posy);
816  $pdf->SetTextColor(0, 0, 60);
817  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
818 
819  $posy += 4;
820  $pdf->SetXY($posx - 50, $posy);
821  $pdf->MultiCell(150, 3, $object->lieu, '', 'R');
822 
823  $posy += 4;
824  $pdf->SetXY($posx, $posy);
825  $pdf->SetTextColor(0, 0, 60);
826 
827  // Parent entrepot
828  $e = new Entrepot($this->db);
829  $hasparent = (!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0);
830 
831  if ($hasparent) {
832  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
833 
834  $posy += 4;
835  $pdf->SetXY($posx - 50, $posy);
836  $pdf->MultiCell(150, 3, $e->label, '', 'R');
837  }
838 
839  // Description
840  $nexY = $pdf->GetY();
841  $nexY += 5;
842  $pdf->SetXY($posx, $posy);
843  $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
844  $nexY = $pdf->GetY();
845 
846  $calcproductsunique = $object->nb_different_products();
847  $calcproducts = $object->nb_products();
848 
849  // Total nb of different products
850  $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb']), 0, 1);
851  $nexY = $pdf->GetY();
852 
853  // Nb of products
854  $valtoshow = price2num($calcproducts['nb'], 'MS');
855  $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfProducts").' : </b>'.(empty($valtoshow) ? '0' : $valtoshow), 0, 1);
856  $nexY = $pdf->GetY();
857 
858  // Value
859  $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("EstimatedStockValueShort").' : </b>'.price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1);
860  $nexY = $pdf->GetY();
861 
862 
863  // Last movement
864  $sql = "SELECT max(m.datem) as datem";
865  $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
866  $sql .= " WHERE m.fk_entrepot = ".((int) $object->id);
867  $resqlbis = $this->db->query($sql);
868  if ($resqlbis)
869  {
870  $obj = $this->db->fetch_object($resqlbis);
871  $lastmovementdate = $this->db->jdate($obj->datem);
872  } else {
873  dol_print_error($this->db);
874  }
875 
876  if ($lastmovementdate)
877  {
878  $toWrite = dol_print_date($lastmovementdate, 'dayhour').' ';
879  } else {
880  $toWrite = $outputlangs->transnoentities("None");
881  }
882 
883  $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("LastMovement").' : </b>'.$toWrite, 0, 1);
884  $nexY = $pdf->GetY();
885 
886  $posy += 2;
887 
888  $top_shift = 0;
889  // Show list of linked objects
890  $current_y = $pdf->getY();
891  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
892  if ($current_y < $pdf->getY())
893  {
894  $top_shift = $pdf->getY() - $current_y;
895  }
896 
897  $pdf->SetTextColor(0, 0, 0);
898 
899  return $top_shift;
900  }
901 
902  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
912  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
913  {
914  global $conf;
915  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
916  return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
917  }
918 }
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:45
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:620
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:663
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency= '')
Show table for lines.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:245
Class to manage products or services.
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...
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:222
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
Class to generate expense report based on standard model.
Class to manage hooks.
write_file($object, $outputlangs, $srctemplatepath= '', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build a document on disk using the generic odt module.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:887
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:270
convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1135
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:643
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
Definition: pdf.lib.php:88
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
Definition: pdf.lib.php:1174
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
__construct($db)
Constructor.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
Show top header of page.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Parent class for stock models of doc generators.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
Class to manage predefined suppliers products.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
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 &quot;subst...
Class to manage warehouses.