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