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