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