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