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