dolibarr  17.0.4
pdf_standard_asset.modules.php
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
5  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
8  * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
11  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  * or see https://www.gnu.org/
26  */
27 
34 dol_include_once('/asset/core/modules/asset/modules_asset.php');
35 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
39 
40 
45 {
49  public $db;
50 
54  public $name;
55 
59  public $description;
60 
64  public $update_main_doc_field;
65 
69  public $type;
70 
75  public $phpmin = array(7, 0);
76 
81  public $version = 'dolibarr';
82 
86  public $page_largeur;
87 
91  public $page_hauteur;
92 
96  public $format;
97 
101  public $marge_gauche;
102 
106  public $marge_droite;
107 
111  public $marge_haute;
112 
116  public $marge_basse;
117 
122  public $emetteur;
123 
127  public $situationinvoice;
128 
129 
133  public $cols;
134 
135 
141  public function __construct($db)
142  {
143  global $conf, $langs, $mysoc;
144 
145  // Translations
146  $langs->loadLangs(array("main", "bills"));
147 
148  $this->db = $db;
149  $this->name = "standard";
150  $this->description = $langs->trans('DocumentModelStandardPDF');
151  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
152 
153  // Dimension page
154  $this->type = 'pdf';
155  $formatarray = pdf_getFormat();
156  $this->page_largeur = $formatarray['width'];
157  $this->page_hauteur = $formatarray['height'];
158  $this->format = array($this->page_largeur, $this->page_hauteur);
159  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
160  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
161  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
162  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
163 
164  // Get source company
165  $this->emetteur = $mysoc;
166  if (empty($this->emetteur->country_code)) {
167  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
168  }
169 
170  // Define position of columns
171  $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
172 
173 
174  $this->tabTitleHeight = 5; // default height
175 
176  // Use new system for position of columns, view $this->defineColumnField()
177 
178  $this->tva = array();
179  $this->localtax1 = array();
180  $this->localtax2 = array();
181  $this->atleastoneratenotnull = 0;
182  $this->atleastonediscount = 0;
183  $this->situationinvoice = false;
184  }
185 
186 
187  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
199  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
200  {
201  // phpcs:enable
202  global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
203 
204  dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
205 
206  if (!is_object($outputlangs)) {
207  $outputlangs = $langs;
208  }
209  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
210  if (!empty($conf->global->MAIN_USE_FPDF)) {
211  $outputlangs->charset_output = 'ISO-8859-1';
212  }
213 
214  // Load translation files required by the page
215  $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
216 
217  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
218  global $outputlangsbis;
219  $outputlangsbis = new Translate('', $conf);
220  $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
221  $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
222  }
223 
224  $nblines = (is_array($object->lines) ? count($object->lines) : 0);
225 
226  $hidetop = 0;
227  if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
228  $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
229  }
230 
231  // Loop on each lines to detect if there is at least one image to show
232  $realpatharray = array();
233  $this->atleastonephoto = false;
234  /*
235  if (!empty($conf->global->MAIN_GENERATE_ASSET_WITH_PICTURE))
236  {
237  $objphoto = new Product($this->db);
238 
239  for ($i = 0; $i < $nblines; $i++)
240  {
241  if (empty($object->lines[$i]->fk_product)) continue;
242 
243  //var_dump($objphoto->ref);exit;
244  if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
245  $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
246  $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
247  } else {
248  $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
249  $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
250  }
251 
252  $arephoto = false;
253  foreach ($pdir as $midir)
254  {
255  if (!$arephoto)
256  {
257  $dir = $conf->product->dir_output.'/'.$midir;
258 
259  foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
260  {
261  if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
262  {
263  if ($obj['photo_vignette'])
264  {
265  $filename = $obj['photo_vignette'];
266  } else {
267  $filename = $obj['photo'];
268  }
269  } else {
270  $filename = $obj['photo'];
271  }
272 
273  $realpath = $dir.$filename;
274  $arephoto = true;
275  $this->atleastonephoto = true;
276  }
277  }
278  }
279 
280  if ($realpath && $arephoto) $realpatharray[$i] = $realpath;
281  }
282  }
283  */
284 
285  //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
286 
287  if ($conf->asset->dir_output.'/asset') {
288  $object->fetch_thirdparty();
289 
290  // Definition of $dir and $file
291  if ($object->specimen) {
292  $dir = $conf->asset->dir_output.'/asset';
293  $file = $dir."/SPECIMEN.pdf";
294  } else {
295  $objectref = dol_sanitizeFileName($object->ref);
296  $dir = $conf->asset->dir_output.'/asset/'.$objectref;
297  $file = $dir."/".$objectref.".pdf";
298  }
299  if (!file_exists($dir)) {
300  if (dol_mkdir($dir) < 0) {
301  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
302  return 0;
303  }
304  }
305 
306  if (file_exists($dir)) {
307  // Add pdfgeneration hook
308  if (!is_object($hookmanager)) {
309  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
310  $hookmanager = new HookManager($this->db);
311  }
312  $hookmanager->initHooks(array('pdfgeneration'));
313  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
314  global $action;
315  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
316 
317  // Set nblines with the new facture lines content after hook
318  $nblines = (is_array($object->lines) ? count($object->lines) : 0);
319 
320  // Create pdf instance
321  $pdf = pdf_getInstance($this->format);
322  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
323  $pdf->SetAutoPageBreak(1, 0);
324 
325  $heightforinfotot = 50; // Height reserved to output the info and total part and payment part
326  $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
327  $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
328 
329  if (class_exists('TCPDF')) {
330  $pdf->setPrintHeader(false);
331  $pdf->setPrintFooter(false);
332  }
333  $pdf->SetFont(pdf_getPDFFont($outputlangs));
334 
335  // Set path to the background PDF File
336  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
337  $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
338  $tplidx = $pdf->importPage(1);
339  }
340 
341  $pdf->Open();
342  $pagenb = 0;
343  $pdf->SetDrawColor(128, 128, 128);
344 
345  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
346  $pdf->SetSubject($outputlangs->transnoentities("PdfTitle"));
347  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
348  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
349  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
350  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
351  $pdf->SetCompression(false);
352  }
353 
354  // Set certificate
355  $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
356  // If user has no certificate, we try to take the company one
357  if (!$cert) {
358  $cert = empty($conf->global->CERTIFICATE_CRT) ? '' : $conf->global->CERTIFICATE_CRT;
359  }
360  // If a certificate is found
361  if ($cert) {
362  $info = array(
363  'Name' => $this->emetteur->name,
364  'Location' => getCountry($this->emetteur->country_code, 0),
365  'Reason' => 'ASSET',
366  'ContactInfo' => $this->emetteur->email
367  );
368  $pdf->setSignature($cert, $cert, $this->emetteur->name, '', 2, $info);
369  }
370 
371  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
372 
373  // New page
374  $pdf->AddPage();
375  if (!empty($tplidx)) {
376  $pdf->useTemplate($tplidx);
377  }
378  $pagenb++;
379 
380  $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
381  $pdf->SetFont('', '', $default_font_size - 1);
382  $pdf->MultiCell(0, 3, ''); // Set interline to 3
383  $pdf->SetTextColor(0, 0, 0);
384 
385  $tab_top = 90 + $top_shift;
386  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
387  $tab_height = 130 - $top_shift;
388  $tab_height_newpage = 150;
389  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
390  $tab_height_newpage -= $top_shift;
391  }
392 
393  $nexY = $tab_top - 1;
394 
395  // Display notes
396  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
397  // Extrafields in note
398  $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
399  if (!empty($extranote)) {
400  $notetoshow = dol_concatdesc($notetoshow, $extranote);
401  }
402 
403  $pagenb = $pdf->getPage();
404  if ($notetoshow) {
405  $tab_top -= 2;
406 
407  $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
408  $pageposbeforenote = $pagenb;
409 
410  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
411  complete_substitutions_array($substitutionarray, $outputlangs, $object);
412  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
413  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
414 
415  $pdf->startTransaction();
416 
417  $pdf->SetFont('', '', $default_font_size - 1);
418  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
419  // Description
420  $pageposafternote = $pdf->getPage();
421  $posyafter = $pdf->GetY();
422 
423  if ($pageposafternote > $pageposbeforenote) {
424  $pdf->rollbackTransaction(true);
425 
426  // prepare pages to receive notes
427  while ($pagenb < $pageposafternote) {
428  $pdf->AddPage();
429  $pagenb++;
430  if (!empty($tplidx)) {
431  $pdf->useTemplate($tplidx);
432  }
433  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
434  $this->_pagehead($pdf, $object, 0, $outputlangs);
435  }
436  // $this->_pagefoot($pdf,$object,$outputlangs,1);
437  $pdf->setTopMargin($tab_top_newpage);
438  // The only function to edit the bottom margin of current page to set it.
439  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
440  }
441 
442  // back to start
443  $pdf->setPage($pageposbeforenote);
444  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
445  $pdf->SetFont('', '', $default_font_size - 1);
446  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
447  $pageposafternote = $pdf->getPage();
448 
449  $posyafter = $pdf->GetY();
450 
451  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
452  $pdf->AddPage('', '', true);
453  $pagenb++;
454  $pageposafternote++;
455  $pdf->setPage($pageposafternote);
456  $pdf->setTopMargin($tab_top_newpage);
457  // The only function to edit the bottom margin of current page to set it.
458  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
459  //$posyafter = $tab_top_newpage;
460  }
461 
462 
463  // apply note frame to previous pages
464  $i = $pageposbeforenote;
465  while ($i < $pageposafternote) {
466  $pdf->setPage($i);
467 
468 
469  $pdf->SetDrawColor(128, 128, 128);
470  // Draw note frame
471  if ($i > $pageposbeforenote) {
472  $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
473  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
474  } else {
475  $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
476  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
477  }
478 
479  // Add footer
480  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
481  $this->_pagefoot($pdf, $object, $outputlangs, 1);
482 
483  $i++;
484  }
485 
486  // apply note frame to last page
487  $pdf->setPage($pageposafternote);
488  if (!empty($tplidx)) {
489  $pdf->useTemplate($tplidx);
490  }
491  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
492  $this->_pagehead($pdf, $object, 0, $outputlangs);
493  }
494  $height_note = $posyafter - $tab_top_newpage;
495  $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
496  } else // No pagebreak
497  {
498  $pdf->commitTransaction();
499  $posyafter = $pdf->GetY();
500  $height_note = $posyafter - $tab_top;
501  $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
502 
503 
504  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
505  // not enough space, need to add page
506  $pdf->AddPage('', '', true);
507  $pagenb++;
508  $pageposafternote++;
509  $pdf->setPage($pageposafternote);
510  if (!empty($tplidx)) {
511  $pdf->useTemplate($tplidx);
512  }
513  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
514  $this->_pagehead($pdf, $object, 0, $outputlangs);
515  }
516 
517  $posyafter = $tab_top_newpage;
518  }
519  }
520 
521  $tab_height = $tab_height - $height_note;
522  $tab_top = $posyafter + 6;
523  } else {
524  $height_note = 0;
525  }
526 
527  // Use new auto column system
528  $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
529 
530  // Table simulation to know the height of the title line
531  $pdf->startTransaction();
532  $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
533  $pdf->rollbackTransaction(true);
534 
535  $nexY = $tab_top + $this->tabTitleHeight;
536 
537  // Loop on each lines
538  $pageposbeforeprintlines = $pdf->getPage();
539  $pagenb = $pageposbeforeprintlines;
540  for ($i = 0; $i < $nblines; $i++) {
541  $curY = $nexY;
542  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
543  $pdf->SetTextColor(0, 0, 0);
544 
545  // Define size of image if we need it
546  $imglinesize = array();
547  if (!empty($realpatharray[$i])) {
548  $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
549  }
550 
551  $pdf->setTopMargin($tab_top_newpage);
552  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
553  $pageposbefore = $pdf->getPage();
554 
555  $showpricebeforepagebreak = 1;
556  $posYAfterImage = 0;
557 
558  if ($this->getColumnStatus('photo')) {
559  // We start with Photo of product line
560  if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
561  $pdf->AddPage('', '', true);
562  if (!empty($tplidx)) {
563  $pdf->useTemplate($tplidx);
564  }
565  $pdf->setPage($pageposbefore + 1);
566 
567  $curY = $tab_top_newpage;
568 
569  // Allows data in the first page if description is long enough to break in multiples pages
570  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
571  $showpricebeforepagebreak = 1;
572  } else {
573  $showpricebeforepagebreak = 0;
574  }
575  }
576 
577  if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
578  $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
579  // $pdf->Image does not increase value return by getY, so we save it manually
580  $posYAfterImage = $curY + $imglinesize['height'];
581  }
582  }
583 
584  // Description of product line
585  if ($this->getColumnStatus('desc')) {
586  $pdf->startTransaction();
587 
588  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
589  $pageposafter = $pdf->getPage();
590 
591  if ($pageposafter > $pageposbefore) { // There is a pagebreak
592  $pdf->rollbackTransaction(true);
593  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
594 
595  $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
596 
597  $pageposafter = $pdf->getPage();
598  $posyafter = $pdf->GetY();
599  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
600  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
601  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
602  $pdf->AddPage('', '', true);
603  if (!empty($tplidx)) {
604  $pdf->useTemplate($tplidx);
605  }
606  $pdf->setPage($pageposafter + 1);
607  }
608  } else {
609  // We found a page break
610  // Allows data in the first page if description is long enough to break in multiples pages
611  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
612  $showpricebeforepagebreak = 1;
613  } else {
614  $showpricebeforepagebreak = 0;
615  }
616  }
617  } else // No pagebreak
618  {
619  $pdf->commitTransaction();
620  }
621  }
622 
623  $nexY = $pdf->GetY();
624  $pageposafter = $pdf->getPage();
625  $pdf->setPage($pageposbefore);
626  $pdf->setTopMargin($this->marge_haute);
627  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
628 
629  // We suppose that a too long description or photo were moved completely on next page
630  if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
631  $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
632  }
633 
634  $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut
635 
636  // Quantity
637  // Enough for 6 chars
638  if ($this->getColumnStatus('qty')) {
639  $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
640  $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
641  $nexY = max($pdf->GetY(), $nexY);
642  }
643 
644  // Extrafields
645  if (!empty($object->lines[$i]->array_options)) {
646  foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
647  if ($this->getColumnStatus($extrafieldColKey)) {
648  $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
649  $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
650  $nexY = max($pdf->GetY(), $nexY);
651  }
652  }
653  }
654 
655 
656  $parameters = array(
657  'object' => $object,
658  'i' => $i,
659  'pdf' =>& $pdf,
660  'curY' =>& $curY,
661  'nexY' =>& $nexY,
662  'outputlangs' => $outputlangs,
663  'hidedetails' => $hidedetails
664  );
665  $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
666 
667 
668  $sign = 1;
669  // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
670  $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
671  if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
672  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
673  $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
674  } else {
675  $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
676  }
677  } else {
678  if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
679  $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
680  } else {
681  $tvaligne = $sign * $object->lines[$i]->total_tva;
682  }
683  }
684 
685  $localtax1ligne = $object->lines[$i]->total_localtax1;
686  $localtax2ligne = $object->lines[$i]->total_localtax2;
687  $localtax1_rate = $object->lines[$i]->localtax1_tx;
688  $localtax2_rate = $object->lines[$i]->localtax2_tx;
689  $localtax1_type = $object->lines[$i]->localtax1_type;
690  $localtax2_type = $object->lines[$i]->localtax2_type;
691 
692  if ($object->remise_percent) {
693  $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
694  }
695  if ($object->remise_percent) {
696  $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
697  }
698  if ($object->remise_percent) {
699  $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
700  }
701 
702  $vatrate = (string) $object->lines[$i]->tva_tx;
703 
704  // Retrieve type from database for backward compatibility with old records
705  if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
706  && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
707  $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
708  $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
709  $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
710  }
711 
712  // retrieve global local tax
713  if ($localtax1_type && $localtax1ligne != 0) {
714  $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
715  }
716  if ($localtax2_type && $localtax2ligne != 0) {
717  $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
718  }
719 
720  if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
721  $vatrate .= '*';
722  }
723  if (!isset($this->tva[$vatrate])) {
724  $this->tva[$vatrate] = 0;
725  }
726  $this->tva[$vatrate] += $tvaligne;
727 
728  $nexY = max($nexY, $posYAfterImage);
729 
730  // Add line
731  if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
732  $pdf->setPage($pageposafter);
733  $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
734  //$pdf->SetDrawColor(190,190,200);
735  $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
736  $pdf->SetLineStyle(array('dash'=>0));
737  }
738 
739  // Detect if some page were added automatically and output _tableau for past pages
740  while ($pagenb < $pageposafter) {
741  $pdf->setPage($pagenb);
742  if ($pagenb == $pageposbeforeprintlines) {
743  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
744  } else {
745  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
746  }
747  $this->_pagefoot($pdf, $object, $outputlangs, 1);
748  $pagenb++;
749  $pdf->setPage($pagenb);
750  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
751  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
752  $this->_pagehead($pdf, $object, 0, $outputlangs);
753  }
754  }
755 
756  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
757  if ($pagenb == $pageposafter) {
758  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
759  } else {
760  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
761  }
762  $this->_pagefoot($pdf, $object, $outputlangs, 1);
763  // New page
764  $pdf->AddPage();
765  if (!empty($tplidx)) {
766  $pdf->useTemplate($tplidx);
767  }
768  $pagenb++;
769  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
770  $this->_pagehead($pdf, $object, 0, $outputlangs);
771  }
772  }
773  }
774 
775  // Show square
776  if ($pagenb == $pageposbeforeprintlines) {
777  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
778  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
779  } else {
780  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
781  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
782  }
783 
784  // Display infos area
785  //$posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
786 
787  // Display total zone
788  //$posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
789 
790  // Display payment area
791  /*
792  if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
793  {
794  $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
795  }
796  */
797 
798  // Pagefoot
799  $this->_pagefoot($pdf, $object, $outputlangs);
800  if (method_exists($pdf, 'AliasNbPages')) {
801  $pdf->AliasNbPages();
802  }
803 
804  $pdf->Close();
805 
806  $pdf->Output($file, 'F');
807 
808  // Add pdfgeneration hook
809  $hookmanager->initHooks(array('pdfgeneration'));
810  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
811  global $action;
812  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
813  if ($reshook < 0) {
814  $this->error = $hookmanager->error;
815  $this->errors = $hookmanager->errors;
816  }
817 
818  if (!empty($conf->global->MAIN_UMASK)) {
819  @chmod($file, octdec($conf->global->MAIN_UMASK));
820  }
821 
822  $this->result = array('fullpath'=>$file);
823 
824  return 1; // No error
825  } else {
826  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
827  return 0;
828  }
829  } else {
830  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
831  return 0;
832  }
833  }
834 
835  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
843  public static function liste_modeles($db, $maxfilenamelength = 0)
844  {
845  // phpcs:enable
846  return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
847  }
848 
849  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
864  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
865  {
866  global $conf;
867 
868  // Force to disable hidetop and hidebottom
869  $hidebottom = 0;
870  if ($hidetop) {
871  $hidetop = -1;
872  }
873 
874  $currency = !empty($currency) ? $currency : $conf->currency;
875  $default_font_size = pdf_getPDFFontSize($outputlangs);
876 
877  // Amount in (at tab_top - 1)
878  $pdf->SetTextColor(0, 0, 0);
879  $pdf->SetFont('', '', $default_font_size - 2);
880 
881  if (empty($hidetop)) {
882  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
883  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
884  $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
885  }
886 
887  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
888  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
889 
890  //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
891  if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
892  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
893  }
894  }
895 
896  $pdf->SetDrawColor(128, 128, 128);
897  $pdf->SetFont('', '', $default_font_size - 1);
898 
899  // Output Rect
900  $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
901 
902 
903  $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
904 
905  if (empty($hidetop)) {
906  $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
907  }
908  }
909 
910  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
921  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
922  {
923  global $conf, $langs;
924 
925  // Load traductions files required by page
926  $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
927 
928  $default_font_size = pdf_getPDFFontSize($outputlangs);
929 
930  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
931 
932  // Show Draft Watermark
933  if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
934  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
935  }
936 
937  $pdf->SetTextColor(0, 0, 60);
938  $pdf->SetFont('', 'B', $default_font_size + 3);
939 
940  $w = 110;
941 
942  $posy = $this->marge_haute;
943  $posx = $this->page_largeur - $this->marge_droite - $w;
944 
945  $pdf->SetXY($this->marge_gauche, $posy);
946 
947  // Logo
948  if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
949  if ($this->emetteur->logo) {
950  $logodir = $conf->mycompany->dir_output;
951  if (!empty($conf->mycompany->multidir_output[$object->entity])) {
952  $logodir = $conf->mycompany->multidir_output[$object->entity];
953  }
954  if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
955  $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
956  } else {
957  $logo = $logodir.'/logos/'.$this->emetteur->logo;
958  }
959  if (is_readable($logo)) {
960  $height = pdf_getHeightForLogo($logo);
961  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
962  } else {
963  $pdf->SetTextColor(200, 0, 0);
964  $pdf->SetFont('', 'B', $default_font_size - 2);
965  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
966  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
967  }
968  } else {
969  $text = $this->emetteur->name;
970  $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
971  }
972  }
973 
974  $pdf->SetFont('', 'B', $default_font_size + 3);
975  $pdf->SetXY($posx, $posy);
976  $pdf->SetTextColor(0, 0, 60);
977  $title = $outputlangs->transnoentities("PdfTitle");
978  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
979  $title .= ' - ';
980  $title .= $outputlangsbis->transnoentities("PdfTitle");
981  }
982  $pdf->MultiCell($w, 3, $title, '', 'R');
983 
984  $pdf->SetFont('', 'B', $default_font_size);
985 
986  $posy += 5;
987  $pdf->SetXY($posx, $posy);
988  $pdf->SetTextColor(0, 0, 60);
989  $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
990  if ($object->statut == $object::STATUS_DRAFT) {
991  $pdf->SetTextColor(128, 0, 0);
992  $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
993  }
994  $pdf->MultiCell($w, 4, $textref, '', 'R');
995 
996  $posy += 1;
997  $pdf->SetFont('', '', $default_font_size - 2);
998 
999  if ($object->ref_client) {
1000  $posy += 4;
1001  $pdf->SetXY($posx, $posy);
1002  $pdf->SetTextColor(0, 0, 60);
1003  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1004  }
1005 
1006  if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1007  $object->fetch_projet();
1008  if (!empty($object->project->ref)) {
1009  $posy += 3;
1010  $pdf->SetXY($posx, $posy);
1011  $pdf->SetTextColor(0, 0, 60);
1012  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
1013  }
1014  }
1015 
1016  if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1017  $object->fetch_projet();
1018  if (!empty($object->project->ref)) {
1019  $outputlangs->load("projects");
1020  $posy += 3;
1021  $pdf->SetXY($posx, $posy);
1022  $pdf->SetTextColor(0, 0, 60);
1023  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1024  }
1025  }
1026 
1027  $posy += 4;
1028  $pdf->SetXY($posx, $posy);
1029  $pdf->SetTextColor(0, 0, 60);
1030 
1031  $title = $outputlangs->transnoentities("Date");
1032  if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1033  $title .= ' - '.$outputlangsbis->transnoentities("Date");
1034  }
1035  $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date, "day", false, $outputlangs), '', 'R');
1036 
1037  if ($object->thirdparty->code_client) {
1038  $posy += 3;
1039  $pdf->SetXY($posx, $posy);
1040  $pdf->SetTextColor(0, 0, 60);
1041  $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1042  }
1043 
1044  // Get contact
1045  if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1046  $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1047  if (count($arrayidcontact) > 0) {
1048  $usertmp = new User($this->db);
1049  $usertmp->fetch($arrayidcontact[0]);
1050  $posy += 4;
1051  $pdf->SetXY($posx, $posy);
1052  $pdf->SetTextColor(0, 0, 60);
1053  $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1054  }
1055  }
1056 
1057  $posy += 1;
1058 
1059  $top_shift = 0;
1060  // Show list of linked objects
1061  $current_y = $pdf->getY();
1062  $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1063  if ($current_y < $pdf->getY()) {
1064  $top_shift = $pdf->getY() - $current_y;
1065  }
1066 
1067  if ($showaddress) {
1068  // Sender properties
1069  $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1070 
1071  // Show sender
1072  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1073  $posy += $top_shift;
1074  $posx = $this->marge_gauche;
1075  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1076  $posx = $this->page_largeur - $this->marge_droite - 80;
1077  }
1078 
1079  $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1080  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1081 
1082 
1083  // Show sender frame
1084  $pdf->SetTextColor(0, 0, 0);
1085  $pdf->SetFont('', '', $default_font_size - 2);
1086  $pdf->SetXY($posx, $posy - 5);
1087  $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1088  $pdf->SetXY($posx, $posy);
1089  $pdf->SetFillColor(230, 230, 230);
1090  $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1091  $pdf->SetTextColor(0, 0, 60);
1092 
1093  // Show sender name
1094  $pdf->SetXY($posx + 2, $posy + 3);
1095  $pdf->SetFont('', 'B', $default_font_size);
1096  $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1097  $posy = $pdf->getY();
1098 
1099  // Show sender information
1100  $pdf->SetXY($posx + 2, $posy);
1101  $pdf->SetFont('', '', $default_font_size - 1);
1102  $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
1103 
1104  // If BILLING contact defined on invoice, we use it
1105  $usecontact = false;
1106  $arrayidcontact = $object->getIdContact('external', 'BILLING');
1107  if (count($arrayidcontact) > 0) {
1108  $usecontact = true;
1109  $result = $object->fetch_contact($arrayidcontact[0]);
1110  }
1111 
1112  // Recipient name
1113  if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))) {
1114  $thirdparty = $object->contact;
1115  } else {
1116  $thirdparty = $object->thirdparty;
1117  }
1118 
1119  if (is_object($thirdparty)) {
1120  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1121  }
1122 
1123  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, 'target', $object);
1124 
1125  // Show recipient
1126  $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1127  if ($this->page_largeur < 210) {
1128  $widthrecbox = 84; // To work with US executive format
1129  }
1130  $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1131  $posy += $top_shift;
1132  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1133  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1134  $posx = $this->marge_gauche;
1135  }
1136 
1137  // Show recipient frame
1138  $pdf->SetTextColor(0, 0, 0);
1139  $pdf->SetFont('', '', $default_font_size - 2);
1140  $pdf->SetXY($posx + 2, $posy - 5);
1141  $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1142  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1143 
1144  // Show recipient name
1145  $pdf->SetXY($posx + 2, $posy + 3);
1146  $pdf->SetFont('', 'B', $default_font_size);
1147  $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1148 
1149  $posy = $pdf->getY();
1150 
1151  // Show recipient information
1152  $pdf->SetFont('', '', $default_font_size - 1);
1153  $pdf->SetXY($posx + 2, $posy);
1154  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1155  }
1156 
1157  $pdf->SetTextColor(0, 0, 0);
1158  return $top_shift;
1159  }
1160 
1161  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1171  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1172  {
1173  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1174  return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1175  }
1176 
1187  public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1188  {
1189  global $conf, $hookmanager;
1190 
1191  // Default field style for content
1192  $this->defaultContentsFieldsStyle = array(
1193  'align' => 'R', // R,C,L
1194  'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1195  );
1196 
1197  // Default field style for content
1198  $this->defaultTitlesFieldsStyle = array(
1199  'align' => 'C', // R,C,L
1200  'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1201  );
1202 
1203  /*
1204  * For exemple
1205  $this->cols['theColKey'] = array(
1206  'rank' => $rank, // int : use for ordering columns
1207  'width' => 20, // the column width in mm
1208  'title' => array(
1209  'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1210  'label' => ' ', // the final label : used fore final generated text
1211  'align' => 'L', // text alignement : R,C,L
1212  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1213  ),
1214  'content' => array(
1215  'align' => 'L', // text alignement : R,C,L
1216  'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1217  ),
1218  );
1219  */
1220 
1221  $rank = 0; // do not use negative rank
1222  $this->cols['desc'] = array(
1223  'rank' => $rank,
1224  'width' => false, // only for desc
1225  'status' => true,
1226  'title' => array(
1227  'textkey' => 'Designation', // use lang key is usefull in somme case with module
1228  'align' => 'L',
1229  // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1230  // 'label' => ' ', // the final label
1231  'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1232  ),
1233  'content' => array(
1234  'align' => 'L',
1235  'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1236  ),
1237  );
1238 
1239  // PHOTO
1240  $rank = $rank + 10;
1241  $this->cols['photo'] = array(
1242  'rank' => $rank,
1243  'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1244  'status' => false,
1245  'title' => array(
1246  'textkey' => 'Photo',
1247  'label' => ' '
1248  ),
1249  'content' => array(
1250  'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1251  ),
1252  'border-left' => false, // remove left line separator
1253  );
1254 
1255  if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE) && !empty($this->atleastonephoto)) {
1256  $this->cols['photo']['status'] = true;
1257  }
1258 
1259 
1260  $rank = $rank + 10;
1261  $this->cols['vat'] = array(
1262  'rank' => $rank,
1263  'status' => false,
1264  'width' => 16, // in mm
1265  'title' => array(
1266  'textkey' => 'VAT'
1267  ),
1268  'border-left' => true, // add left line separator
1269  );
1270 
1271  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1272  $this->cols['vat']['status'] = true;
1273  }
1274 
1275  $rank = $rank + 10;
1276  $this->cols['subprice'] = array(
1277  'rank' => $rank,
1278  'width' => 19, // in mm
1279  'status' => true,
1280  'title' => array(
1281  'textkey' => 'PriceUHT'
1282  ),
1283  'border-left' => true, // add left line separator
1284  );
1285 
1286  $rank = $rank + 10;
1287  $this->cols['qty'] = array(
1288  'rank' => $rank,
1289  'width' => 16, // in mm
1290  'status' => true,
1291  'title' => array(
1292  'textkey' => 'Qty'
1293  ),
1294  'border-left' => true, // add left line separator
1295  );
1296 
1297  $rank = $rank + 10;
1298  $this->cols['progress'] = array(
1299  'rank' => $rank,
1300  'width' => 19, // in mm
1301  'status' => false,
1302  'title' => array(
1303  'textkey' => 'Progress'
1304  ),
1305  'border-left' => true, // add left line separator
1306  );
1307 
1308  if ($this->situationinvoice) {
1309  $this->cols['progress']['status'] = true;
1310  }
1311 
1312  $rank = $rank + 10;
1313  $this->cols['unit'] = array(
1314  'rank' => $rank,
1315  'width' => 11, // in mm
1316  'status' => false,
1317  'title' => array(
1318  'textkey' => 'Unit'
1319  ),
1320  'border-left' => true, // add left line separator
1321  );
1322  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1323  $this->cols['unit']['status'] = true;
1324  }
1325 
1326  $rank = $rank + 10;
1327  $this->cols['discount'] = array(
1328  'rank' => $rank,
1329  'width' => 13, // in mm
1330  'status' => false,
1331  'title' => array(
1332  'textkey' => 'ReductionShort'
1333  ),
1334  'border-left' => true, // add left line separator
1335  );
1336  if ($this->atleastonediscount) {
1337  $this->cols['discount']['status'] = true;
1338  }
1339 
1340  $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1341  $this->cols['totalexcltax'] = array(
1342  'rank' => $rank,
1343  'width' => 26, // in mm
1344  'status' => true,
1345  'title' => array(
1346  'textkey' => 'TotalHT'
1347  ),
1348  'border-left' => true, // add left line separator
1349  );
1350 
1351  // Add extrafields cols
1352  if (!empty($object->lines)) {
1353  $line = reset($object->lines);
1354  $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1355  }
1356 
1357  $parameters = array(
1358  'object' => $object,
1359  'outputlangs' => $outputlangs,
1360  'hidedetails' => $hidedetails,
1361  'hidedesc' => $hidedesc,
1362  'hideref' => $hideref
1363  );
1364 
1365  $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1366  if ($reshook < 0) {
1367  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1368  } elseif (empty($reshook)) {
1369  $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1370  } else {
1371  $this->cols = $hookmanager->resArray;
1372  }
1373  }
1374 }
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getColumnContentXStart($colKey)
get column content X (abscissa) left position from column key
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage hooks.
Parent class for documents models.
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:47
Class to manage PDF template standard_asset.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
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...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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...
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
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:2514
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
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:1001
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:749
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:723
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition: pdf.lib.php:1323
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
Definition: pdf.lib.php:434
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition: pdf.lib.php:1971
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:769
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41