dolibarr 25.0.0-alpha
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-2025 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
13 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
14 * Copyright (C) ---Replace with your own copyright and developer email---
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 * or see https://www.gnu.org/
29 */
30
37dol_include_once('/mymodule/core/modules/mymodule/modules_myobject.php');
38require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
41require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
44
45
50{
54 public $db;
55
59 public $entity;
60
64 public $name;
65
69 public $description;
70
74 public $update_main_doc_field;
75
79 public $type;
80
85 public $phpmin = array(7, 0);
86
91 public $version = 'dolibarr';
92
96 public $position = 50;
97
98
103 public $emetteur;
104
108 public $cols;
109
110
116 public function __construct($db)
117 {
118 global $langs, $mysoc;
119
120 // Translations
121 $langs->loadLangs(array("main", "bills"));
122
123 $this->db = $db;
124 $this->name = "standard";
125 $this->description = $langs->trans('DocumentModelStandardPDF');
126 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
127
128 // Dimension page
129 $this->type = 'pdf';
130 $formatarray = pdf_getFormat();
131 $this->page_largeur = $formatarray['width'];
132 $this->page_hauteur = $formatarray['height'];
133 $this->format = array($this->page_largeur, $this->page_hauteur);
134 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
135 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
136 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
137 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
138
139 // Define position of columns
140 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
141
142 $this->tabTitleHeight = 5; // default height
143
144 // Use new system for position of columns, view $this->defineColumnField()
145
146 $this->tva = array();
147 $this->tva_array = array();
148 $this->localtax1 = array();
149 $this->localtax2 = array();
150 $this->atleastoneratenotnull = 0;
151 $this->atleastonediscount = 0;
152
153 if ($mysoc === null) {
154 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
155 return;
156 }
157
158 // Get source company
159 $this->emetteur = $mysoc;
160 if (empty($this->emetteur->country_code)) {
161 $this->emetteur->country_code = dol_substr($langs->defaultlang, -2); // By default, if was not defined
162 }
163 }
164
165
166 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
178 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
179 {
180 // phpcs:enable
181 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
182
183 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
184
185 if (!is_object($outputlangs)) {
186 $outputlangs = $langs;
187 }
188 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
189 if (getDolGlobalInt('MAIN_USE_FPDF')) {
190 $outputlangs->charset_output = 'ISO-8859-1';
191 }
192
193 // Load translation files required by the page
194 $langfiles = array("main", "bills", "products", "dict", "companies", "compta");
195 $outputlangs->loadLangs($langfiles);
196
197 // Show Draft Watermark
198 if (getDolGlobalString('MYOBJECT_DRAFT_WATERMARK') && $object->status == $object::STATUS_DRAFT) {
199 $this->watermark = getDolGlobalString('MYOBJECT_DRAFT_WATERMARK');
200 }
201
202 global $outputlangsbis;
203 $outputlangsbis = null;
204 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
205 $outputlangsbis = new Translate('', $conf);
206 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
207 $outputlangsbis->loadLangs($langfiles);
208 }
209
210 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
211
212 $hidetop = 0;
213 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
214 $hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
215 }
216
217 // Loop on each lines to detect if there is at least one image to show
218 $realpatharray = array();
219 $this->atleastonephoto = false;
220 /*
221 if (getDolGlobalInt('MAIN_GENERATE_MYOBJECT_WITH_PICTURE'))) {
222 $objphoto = new Product($this->db);
223
224 for ($i = 0; $i < $nblines; $i++) {
225 if (empty($object->lines[$i]->fk_product)) {
226 continue;
227 }
228
229 $objphoto->fetch($object->lines[$i]->fk_product);
230 //var_dump($objphoto->ref);exit;
231 if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
232 $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
233 $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
234 } else {
235 $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
236 $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
237 }
238
239 $arephoto = false;
240 foreach ($pdir as $midir) {
241 if (!$arephoto) {
242 if ($conf->entity != $objphoto->entity) {
243 $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
244 } else {
245 $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
246 }
247
248 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
249 if (!getDolGlobalInt('CAT_HIGH_QUALITY_IMAGES')) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
250 if ($obj['photo_vignette']) {
251 $filename = $obj['photo_vignette'];
252 } else {
253 $filename = $obj['photo'];
254 }
255 } else {
256 $filename = $obj['photo'];
257 }
258
259 $realpath = $dir.$filename;
260 $arephoto = true;
261 $this->atleastonephoto = true;
262 }
263 }
264 }
265
266 if ($realpath && $arephoto) {
267 $realpatharray[$i] = $realpath;
268 }
269 }
270 }
271 */
272
273 //if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
274 $dir_output = getMultidirOutput($object, $object->module);
275 if (!empty($dir_output)) {
276 $dir_output .= '/' . $object->element;
277
278 $object->fetch_thirdparty();
279
280 $dir = null;
281 // Definition of $dir and $file
282 if ($object->specimen) {
283 $dir = $dir_output;
284 $file = $dir."/SPECIMEN.pdf"; // When building a SPECIMEN Pdf file, the name must always be "SPECIMEN.pdf"
285 } else {
286 $objectref = dol_sanitizeFileName($object->ref);
287 $dir = $dir_output."/".$objectref;
288 $file = $dir."/".$objectref.".pdf";
289 }
290 // if ($dir === null) {
291 // return 0;
292 // }
293 if (!file_exists($dir)) {
294 if (dol_mkdir($dir) < 0) {
295 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
296 return 0;
297 }
298 }
299
300 if (file_exists($dir)) {
301 // Add pdfgeneration hook
302 if (!is_object($hookmanager)) {
303 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
304 $hookmanager = new HookManager($this->db);
305 }
306 $hookmanager->initHooks(array('pdfgeneration'));
307 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
308 global $action;
309 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
310
311 // Set nblines with the new lines content after hook
312 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
313
314 // Create pdf instance
315 $pdf = pdf_getInstance($this->format);
316 '@phan-var-force TCPDI|TCPDF $pdf';
317 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
318 $pdf->setAutoPageBreak(true, 0);
319
320 $heightforinfotot = 50; // Height reserved to output the info and total part and payment part
321 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
322 $heightforfooter = $this->marge_basse + (getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
323
324 if (class_exists('TCPDF')) {
325 $pdf->setPrintHeader(false);
326 $pdf->setPrintFooter(false);
327 }
328 $pdf->SetFont(pdf_getPDFFont($outputlangs));
329
330 // Set path to the background PDF File
331 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
332 $logodir = $conf->mycompany->dir_output;
333 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
334 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
335 }
336 $pagecount = $pdf->setSourceFile($logodir.'/'.getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
337 $tplidx = $pdf->importPage(1);
338 }
339
340 $pdf->Open();
341 $pagenb = 0;
342 $pdf->SetDrawColor(128, 128, 128);
343
344 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
345 $pdf->SetSubject($outputlangs->transnoentities("PdfTitle"));
346 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
347 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
348 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
349 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
350 $pdf->SetCompression(false);
351 }
352
353 // Set certificate
354 $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT;
355 // If user has no certificate, we try to take the company one
356 if (!$cert) {
357 $cert = getDolGlobalString('CERTIFICATE_CRT');
358 }
359 // If a certificate is found
360 if ($cert) {
361 $info = array(
362 'Name' => $this->emetteur->name,
363 'Location' => getCountry($this->emetteur->country_code, ''),
364 'Reason' => 'MYOBJECT',
365 'ContactInfo' => $this->emetteur->email
366 );
367 $pdf->setSignature($cert, $cert, $this->emetteur->name, '', 2, $info);
368 }
369
370 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
371 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
372
373
374 // New page
375 $pdf->AddPage();
376 if (!empty($tplidx)) {
377 $pdf->useTemplate($tplidx);
378 }
379 $pagenb++;
380
381 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
382 $pdf->SetFont('', '', $default_font_size - 1);
383 $pdf->MultiCell(0, 3, ''); // Set interline to 3
384 $pdf->SetTextColor(0, 0, 0);
385
386 $tab_top = 90 + $top_shift;
387 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
388
389 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
390
391 $tab_height_newpage = 150;
392 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
393 $tab_height_newpage -= $top_shift;
394 }
395
396 $nexY = $tab_top - 1;
397
398 // Display notes
399 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
400 // Extrafields in note
401 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
402 if (!empty($extranote)) {
403 $notetoshow = dol_concatdesc($notetoshow, $extranote);
404 }
405
406 $pagenb = $pdf->getPage();
407 if ($notetoshow) {
408 $tab_top -= 2;
409
410 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
411 $pageposbeforenote = $pagenb;
412
413 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
414 complete_substitutions_array($substitutionarray, $outputlangs, $object);
415 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
416 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
417
418 $pdf->startTransaction();
419
420 $pdf->SetFont('', '', $default_font_size - 1);
421 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
422 // Description
423 $pageposafternote = $pdf->getPage();
424 $posyafter = $pdf->GetY();
425
426 if ($pageposafternote > $pageposbeforenote) {
427 $pdf->rollbackTransaction(true);
428
429 // prepare pages to receive notes
430 while ($pagenb < $pageposafternote) {
431 $pdf->AddPage();
432 $pagenb++;
433 if (!empty($tplidx)) {
434 $pdf->useTemplate($tplidx);
435 }
436 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
437 $this->_pagehead($pdf, $object, 0, $outputlangs);
438 }
439 // $this->_pagefoot($pdf,$object,$outputlangs,1);
440 $pdf->setTopMargin($tab_top_newpage);
441 // The only function to edit the bottom margin of current page to set it.
442 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
443 }
444
445 // back to start
446 $pdf->setPage($pageposbeforenote);
447 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
448 $pdf->SetFont('', '', $default_font_size - 1);
449 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
450 $pageposafternote = $pdf->getPage();
451
452 $posyafter = $pdf->GetY();
453
454 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
455 $pdf->AddPage('', '', true);
456 $pagenb++;
457 $pageposafternote++;
458 $pdf->setPage($pageposafternote);
459 $pdf->setTopMargin($tab_top_newpage);
460 // The only function to edit the bottom margin of current page to set it.
461 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
462 //$posyafter = $tab_top_newpage;
463 }
464
465
466 // apply note frame to previous pages
467 $i = $pageposbeforenote;
468 while ($i < $pageposafternote) {
469 $pdf->setPage($i);
470
471
472 $pdf->SetDrawColor(128, 128, 128);
473 // Draw note frame
474 if ($i > $pageposbeforenote) {
475 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
476 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
477 } else {
478 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
479 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
480 }
481
482 // Add footer
483 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
484 $this->_pagefoot($pdf, $object, $outputlangs, 1);
485
486 $i++;
487 }
488
489 // apply note frame to last page
490 $pdf->setPage($pageposafternote);
491 if (!empty($tplidx)) {
492 $pdf->useTemplate($tplidx);
493 }
494 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
495 $this->_pagehead($pdf, $object, 0, $outputlangs);
496 }
497 $height_note = $posyafter - $tab_top_newpage;
498 $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
499 } else {
500 // No pagebreak
501 $pdf->commitTransaction();
502 $posyafter = $pdf->GetY();
503 $height_note = $posyafter - $tab_top;
504 $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
505
506
507 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
508 // not enough space, need to add page
509 $pdf->AddPage('', '', true);
510 $pagenb++;
511 $pageposafternote++;
512 $pdf->setPage($pageposafternote);
513 if (!empty($tplidx)) {
514 $pdf->useTemplate($tplidx);
515 }
516 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
517 $this->_pagehead($pdf, $object, 0, $outputlangs);
518 }
519
520 $posyafter = $tab_top_newpage;
521 }
522 }
523
524 $tab_height -= $height_note;
525 $tab_top = $posyafter + 6;
526 } else {
527 $height_note = 0;
528 }
529
530 // Use new auto column system
531 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
532
533 // Table simulation to know the height of the title line
534 $pdf->startTransaction();
535 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
536 $pdf->rollbackTransaction(true);
537
538 $nexY = $tab_top + $this->tabTitleHeight;
539
540 // Loop on each lines
541 $pageposbeforeprintlines = $pdf->getPage();
542 $pagenb = $pageposbeforeprintlines;
543 for ($i = 0; $i < $nblines; $i++) {
544 $curY = $nexY;
545 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
546 $pdf->SetTextColor(0, 0, 0);
547
548 // Define size of image if we need it
549 // $imglinesize = array();
550 // if (!empty($realpatharray[$i])) {
551 // $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
552 // }
553
554 $pdf->setTopMargin($tab_top_newpage);
555 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
556 $pageposbefore = $pdf->getPage();
557
558 $showpricebeforepagebreak = 1;
559 $posYAfterImage = 0;
560 $posYAfterDescription = 0;
561
562 // if ($this->getColumnStatus('photo')) {
563 // // We start with Photo of product line
564 // 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
565 // $pdf->AddPage('', '', true);
566 // if (!empty($tplidx)) {
567 // $pdf->useTemplate($tplidx);
568 // }
569 // $pdf->setPage($pageposbefore + 1);
570
571 // $curY = $tab_top_newpage;
572
573 // // Allows data in the first page if description is long enough to break in multiples pages
574 // if (getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
575 // $showpricebeforepagebreak = 1;
576 // } else {
577 // $showpricebeforepagebreak = 0;
578 // }
579 // }
580
581 // if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
582 // $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
583 // // $pdf->Image does not increase value return by getY, so we save it manually
584 // $posYAfterImage = $curY + $imglinesize['height'];
585 // }
586 // }
587
588 // Description of product line
589 if ($this->getColumnStatus('desc')) {
590 $pdf->startTransaction();
591
592 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
593 $pageposafter = $pdf->getPage();
594
595 if ($pageposafter > $pageposbefore) { // There is a pagebreak
596 $pdf->rollbackTransaction(true);
597 $pageposafter = $pageposbefore;
598 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
599
600 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
601
602 $pageposafter = $pdf->getPage();
603 $posyafter = $pdf->GetY();
604
605 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
606 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
607 $pdf->AddPage('', '', true);
608 if (!empty($tplidx)) {
609 $pdf->useTemplate($tplidx);
610 }
611 $pdf->setPage($pageposafter + 1);
612 }
613 } else {
614 // We found a page break
615 // Allows data in the first page if description is long enough to break in multiples pages
616 if (getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
617 $showpricebeforepagebreak = 1;
618 } else {
619 $showpricebeforepagebreak = 0;
620 }
621 }
622 } else { // No pagebreak
623 $pdf->commitTransaction();
624 }
625 $posYAfterDescription = $pdf->GetY();
626 }
627
628 $nexY = max($pdf->GetY(), $posYAfterImage);
629
630
631 $pageposafter = $pdf->getPage();
632 $pdf->setPage($pageposbefore);
633 $pdf->setTopMargin($this->marge_haute);
634 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
635
636 // We suppose that a too long description or photo were moved completely on next page
637 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
638 $pdf->setPage($pageposafter);
639 $curY = $tab_top_newpage;
640 }
641
642 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
643
644 // Quantity
645 // Enough for 6 chars
646 if ($this->getColumnStatus('qty')) {
647 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
648 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
649 $nexY = max($pdf->GetY(), $nexY);
650 }
651
652 // Extrafields
653 if (!empty($object->lines[$i]->array_options)) {
654 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
655 if ($this->getColumnStatus($extrafieldColKey)) {
656 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
657 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
658 $nexY = max($pdf->GetY(), $nexY);
659 }
660 }
661 }
662
663
664 $parameters = array(
665 'object' => $object,
666 'i' => $i,
667 'pdf' => & $pdf,
668 'curY' => & $curY,
669 'nexY' => & $nexY,
670 'outputlangs' => $outputlangs,
671 'hidedetails' => $hidedetails
672 );
673 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
674
675
676 $sign = 1;
677 // Collection of totals by value of VAT in $this->tva["taux"]=total_tva
678 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
679 if ($prev_progress > 0 && $object->lines[$i] instanceof CommonInvoiceLine && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
680 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
681 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; // @phan-suppress-current-line PhanUndeclaredProperty
682 } else {
683 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; // @phan-suppress-current-line PhanUndeclaredProperty
684 }
685 } else {
686 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
687 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
688 } else {
689 $tvaligne = $sign * $object->lines[$i]->total_tva;
690 }
691 }
692
693 $localtax1ligne = $object->lines[$i]->total_localtax1;
694 $localtax2ligne = $object->lines[$i]->total_localtax2;
695 // @phan-suppress-next-line PhanUndeclaredProperty
696 $localtax1_rate = $object->lines[$i]->localtax1_tx;
697 $localtax2_rate = $object->lines[$i]->localtax2_tx; // @phan-suppress-current-line PhanUndeclaredProperty
698 $localtax1_type = $object->lines[$i]->localtax1_type; // @phan-suppress-current-line PhanUndeclaredProperty
699 $localtax2_type = $object->lines[$i]->localtax2_type; // @phan-suppress-current-line PhanUndeclaredProperty
700
701 $vatrate = (string) $object->lines[$i]->tva_tx;
702
703 // Retrieve type from database for backward compatibility with old records
704 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
705 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
706 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
707 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
708 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
709 }
710
711 // retrieve global local tax
712 if ($localtax1_type && $localtax1ligne != 0) {
713 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
714 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
715 } else {
716 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
717 }
718 }
719 if ($localtax2_type && $localtax2ligne != 0) {
720 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
721 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
722 } else {
723 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
724 }
725 }
726
727 if (((int) $object->lines[$i]->info_bits & 0x01) == 0x01) {
728 $vatrate .= '*';
729 }
730
731 // Fill $this->tva and $this->tva_array
732 if (!isset($this->tva[$vatrate])) {
733 $this->tva[$vatrate] = 0;
734 }
735 $this->tva[$vatrate] += $tvaligne;
736 $vatcode = $object->lines[$i]->vat_src_code; // @phan-suppress-current-line PhanUndeclaredProperty
737 if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
738 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
739 }
740 $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
741
742 $nexY = max($nexY, $posYAfterImage);
743
744 // Add line
745 if (getDolGlobalInt('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
746 $pdf->setPage($pageposafter);
747 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
748 //$pdf->SetDrawColor(190,190,200);
749 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
750 $pdf->SetLineStyle(array('dash' => 0));
751 }
752
753 // Detect if some page were added automatically and output _tableau for past pages
754 while ($pagenb < $pageposafter) {
755 $pdf->setPage($pagenb);
756 if ($pagenb == $pageposbeforeprintlines) {
757 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
758 } else {
759 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
760 }
761 $this->_pagefoot($pdf, $object, $outputlangs, 1);
762 $pagenb++;
763 $pdf->setPage($pagenb);
764 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
765 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
766 $this->_pagehead($pdf, $object, 0, $outputlangs);
767 }
768 if (!empty($tplidx)) {
769 $pdf->useTemplate($tplidx);
770 }
771 }
772
773 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
774 if ($pagenb == $pageposafter) {
775 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
776 } else {
777 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
778 }
779 $this->_pagefoot($pdf, $object, $outputlangs, 1);
780 // New page
781 $pdf->AddPage();
782 if (!empty($tplidx)) {
783 $pdf->useTemplate($tplidx);
784 }
785 $pagenb++;
786 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
787 $this->_pagehead($pdf, $object, 0, $outputlangs);
788 }
789 }
790 }
791
792 // Show square
793 if ($pagenb == $pageposbeforeprintlines) {
794 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
795 } else {
796 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
797 }
798 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
799
800 // Display infos area
801 //$posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
802
803 // Display total zone
804 //$posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
805
806 // Display payment area
807 /*
808 if ($deja_regle)
809 {
810 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
811 }
812 */
813
814 // Pagefoot
815 $this->_pagefoot($pdf, $object, $outputlangs);
816 if (method_exists($pdf, 'AliasNbPages')) {
817 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
818 }
819
820 $pdf->Close();
821
822 $pdf->Output($file, 'F');
823
824 // Add pdfgeneration hook
825 $hookmanager->initHooks(array('pdfgeneration'));
826 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
827 global $action;
828 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
829 $this->warnings = $hookmanager->warnings;
830 if ($reshook < 0) {
831 $this->error = $hookmanager->error;
832 $this->errors = $hookmanager->errors;
833 dolChmod($file);
834 return -1;
835 }
836
837 dolChmod($file);
838
839 $this->result = array('fullpath' => $file);
840
841 return 1; // No error
842 } else {
843 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
844 return 0;
845 }
846 } else {
847 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
848 return 0;
849 }
850 }
851
852 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
860 public static function liste_modeles($db, $maxfilenamelength = 0)
861 {
862 // phpcs:enable
863 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
864 }
865
866 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
881 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
882 {
883 global $conf;
884
885 // Force to disable hidetop and hidebottom
886 $hidebottom = 0;
887 if ($hidetop) {
888 $hidetop = -1;
889 }
890
891 $currency = !empty($currency) ? $currency : $conf->currency;
892 $default_font_size = pdf_getPDFFontSize($outputlangs);
893
894 // Amount in (at tab_top - 1)
895 $pdf->SetTextColor(0, 0, 0);
896 $pdf->SetFont('', '', $default_font_size - 2);
897
898 if (empty($hidetop)) {
899 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
900 if (getDolGlobalInt('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
901 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
902 }
903
904 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
905 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
906
907 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
908 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
909 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
910 }
911 }
912
913 $pdf->SetDrawColor(128, 128, 128);
914 $pdf->SetFont('', '', $default_font_size - 1);
915
916 // Output Rect
917 $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
918
919
920 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
921
922 if (empty($hidetop)) {
923 $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
924 }
925 }
926
927 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
938 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
939 {
940 // phpcs:enable
941 global $conf, $langs;
942
943 $ltrdirection = 'L';
944 if ($outputlangs->trans("DIRECTION") == 'rtl') {
945 $ltrdirection = 'R';
946 }
947
948 // Load traductions files required by page
949 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
950
951 $default_font_size = pdf_getPDFFontSize($outputlangs);
952
953 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
954
955 // Show Draft Watermark
956 if (getDolGlobalString('MYMODULE_DRAFT_WATERMARK') && $object->status == $object::STATUS_DRAFT) {
957 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', dol_escape_htmltag(getDolGlobalString('MYMODULE_DRAFT_WATERMARK')));
958 }
959
960 $pdf->SetTextColor(0, 0, 60);
961 $pdf->SetFont('', 'B', $default_font_size + 3);
962
963 $w = 110;
964
965 $posy = $this->marge_haute;
966 $posx = $this->page_largeur - $this->marge_droite - $w;
967
968 $pdf->SetXY($this->marge_gauche, $posy);
969
970 // Logo
971 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
972 if ($this->emetteur->logo) {
973 $logodir = $conf->mycompany->dir_output;
974 if (!empty(getMultidirOutput($object, 'mycompany'))) {
975 $logodir = getMultidirOutput($object, 'mycompany');
976 }
977 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
978 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
979 } else {
980 $logo = $logodir.'/logos/'.$this->emetteur->logo;
981 }
982 if (is_readable($logo)) {
983 $height = pdf_getHeightForLogo($logo);
984 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
985 } else {
986 $pdf->SetTextColor(200, 0, 0);
987 $pdf->SetFont('', 'B', $default_font_size - 2);
988 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
989 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
990 }
991 } else {
992 $text = $this->emetteur->name;
993 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
994 }
995 }
996
997 $pdf->SetFont('', 'B', $default_font_size + 3);
998 $pdf->SetXY($posx, $posy);
999 $pdf->SetTextColor(0, 0, 60);
1000 $title = $outputlangs->transnoentities("PdfTitle");
1001 if (getDolGlobalInt('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1002 $title .= ' - ';
1003 $title .= $outputlangsbis->transnoentities("PdfTitle");
1004 }
1005 $pdf->MultiCell($w, 3, $title, '', 'R');
1006
1007 $pdf->SetFont('', 'B', $default_font_size);
1008
1009 $posy += 5;
1010 $pdf->SetXY($posx, $posy);
1011 $pdf->SetTextColor(0, 0, 60);
1012 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
1013 if ($object->status == $object::STATUS_DRAFT) {
1014 $pdf->SetTextColor(128, 0, 0);
1015 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
1016 }
1017 $pdf->MultiCell($w, 4, $textref, '', 'R');
1018
1019 $posy += 1;
1020 $pdf->SetFont('', '', $default_font_size - 2);
1021
1022 // @phan-suppress-next-line PhanUndeclaredProperty
1023 if (property_exists($object, 'ref_client') && $object->ref_client) {
1024 $posy += 4;
1025 $pdf->SetXY($posx, $posy);
1026 $pdf->SetTextColor(0, 0, 60);
1027 // @phan-suppress-next-line PhanUndeclaredProperty
1028 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".pdf_truncate_text($pdf, $outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
1029 }
1030
1031 if (getDolGlobalInt('PDF_SHOW_PROJECT_TITLE')) {
1032 $object->fetchProject();
1033 if (!empty($object->project->ref)) {
1034 $posy += 3;
1035 $pdf->SetXY($posx, $posy);
1036 $pdf->SetTextColor(0, 0, 60);
1037 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
1038 }
1039 }
1040
1041 if (getDolGlobalInt('PDF_SHOW_PROJECT')) {
1042 $object->fetchProject();
1043 if (!empty($object->project->ref)) {
1044 $outputlangs->load("projects");
1045 $posy += 3;
1046 $pdf->SetXY($posx, $posy);
1047 $pdf->SetTextColor(0, 0, 60);
1048 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
1049 }
1050 }
1051
1052 $posy += 4;
1053 $pdf->SetXY($posx, $posy);
1054 $pdf->SetTextColor(0, 0, 60);
1055
1056 $title = $outputlangs->transnoentities("Date");
1057 if (getDolGlobalInt('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1058 $title .= ' - '.$outputlangsbis->transnoentities("Date");
1059 }
1060 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_creation, "day", false, $outputlangs, true), '', 'R');
1061
1062 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
1063 $posy += 3;
1064 $pdf->SetXY($posx, $posy);
1065 $pdf->SetTextColor(0, 0, 60);
1066 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
1067 }
1068
1069 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && !empty($object->thirdparty->code_compta_client)) {
1070 $posy += 3;
1071 $pdf->SetXY($posx, $posy);
1072 $pdf->SetTextColor(0, 0, 60);
1073 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_compta_client), '', 'R');
1074 }
1075
1076 // Get contact
1077 if (getDolGlobalInt('DOC_SHOW_FIRST_SALES_REP')) {
1078 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
1079 if (count($arrayidcontact) > 0) {
1080 $usertmp = new User($this->db);
1081 $usertmp->fetch($arrayidcontact[0]);
1082 $posy += 4;
1083 $pdf->SetXY($posx, $posy);
1084 $pdf->SetTextColor(0, 0, 60);
1085 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
1086 }
1087 }
1088
1089 $posy += 1;
1090
1091 $top_shift = 0;
1092 // Show list of linked objects
1093 $current_y = $pdf->getY();
1094 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
1095 if ($current_y < $pdf->getY()) {
1096 $top_shift = $pdf->getY() - $current_y;
1097 }
1098
1099 if ($showaddress) {
1100 // Sender properties
1101 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1102
1103 // Show sender
1104 $posy = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1105 $posy += $top_shift;
1106 $posx = $this->marge_gauche;
1107 if (getDolGlobalInt('MAIN_INVERT_SENDER_RECIPIENT')) {
1108 $posx = $this->page_largeur - $this->marge_droite - 80;
1109 }
1110
1111 $hautcadre = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
1112 $widthrecbox = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
1113
1114
1115 // Show sender frame
1116 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
1117 $pdf->SetTextColor(0, 0, 0);
1118 $pdf->SetFont('', '', $default_font_size - 2);
1119 $pdf->SetXY($posx, $posy - 5);
1120 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom").":", 0, $ltrdirection);
1121 $pdf->SetXY($posx, $posy);
1122 $pdf->SetFillColor(230, 230, 230);
1123 $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', true);
1124 $pdf->SetTextColor(0, 0, 60);
1125 }
1126
1127 // Show sender name
1128 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
1129 $pdf->SetXY($posx + 2, $posy + 3);
1130 $pdf->SetFont('', 'B', $default_font_size);
1131 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1132 $posy = $pdf->getY();
1133 }
1134
1135 // Show sender information
1136 $pdf->SetXY($posx + 2, $posy);
1137 $pdf->SetFont('', '', $default_font_size - 1);
1138 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
1139
1140 // If BILLING contact defined, we use it
1141 $usecontact = false;
1142 $arrayidcontact = $object->getIdContact('external', 'BILLING');
1143 if (count($arrayidcontact) > 0) {
1144 $usecontact = true;
1145 $result = $object->fetch_contact($arrayidcontact[0]);
1146 }
1147
1148 // Recipient name
1149 if ($usecontact && $object->contact->socid != $object->thirdparty->id && getDolGlobalInt('MAIN_USE_COMPANY_NAME_OF_CONTACT')) {
1150 $thirdparty = $object->contact;
1151 } else {
1152 $thirdparty = $object->thirdparty;
1153 }
1154
1155 if (is_object($thirdparty)) {
1156 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1157 } else {
1158 $carac_client_name = null;
1159 }
1160
1161 $mode = 'target';
1162 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
1163
1164 // Show recipient
1165 $widthrecbox = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1166 if ($this->page_largeur < 210) {
1167 $widthrecbox = 84; // To work with US executive format
1168 }
1169 $posy = getDolGlobalInt('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1170 $posy += $top_shift;
1171 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1172 if (getDolGlobalInt('MAIN_INVERT_SENDER_RECIPIENT')) {
1173 $posx = $this->marge_gauche;
1174 }
1175
1176 // Show recipient frame
1177 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
1178 $pdf->SetTextColor(0, 0, 0);
1179 $pdf->SetFont('', '', $default_font_size - 2);
1180 $pdf->SetXY($posx + 2, $posy - 5);
1181 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("To").":", 0, $ltrdirection);
1182 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1183 }
1184
1185 // Show recipient name
1186 $pdf->SetXY($posx + 2, $posy + 3);
1187 $pdf->SetFont('', 'B', $default_font_size);
1188 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1189 $pdf->MultiCell($widthrecbox, 2, (string) $carac_client_name, 0, $ltrdirection);
1190
1191 $posy = $pdf->getY();
1192
1193 // Show recipient information
1194 $pdf->SetFont('', '', $default_font_size - 1);
1195 $pdf->SetXY($posx + 2, $posy);
1196 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1197 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1198 }
1199
1200 $pdf->SetTextColor(0, 0, 0);
1201 return $top_shift;
1202 }
1203
1204 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1214 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1215 {
1216 global $conf;
1217 $showdetails = !getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 0 : getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS');
1218 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1219 }
1220
1231 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1232 {
1233 global $hookmanager;
1234
1235 // Default field style for content
1236 $this->defaultContentsFieldsStyle = array(
1237 'align' => 'R', // R,C,L
1238 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1239 );
1240
1241 // Default field style for content
1242 $this->defaultTitlesFieldsStyle = array(
1243 'align' => 'C', // R,C,L
1244 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1245 );
1246
1247 /*
1248 * For example
1249 $this->cols['theColKey'] = array(
1250 'rank' => $rank, // int : use for ordering columns
1251 'width' => 20, // the column width in mm
1252 'title' => array(
1253 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1254 'label' => ' ', // the final label : used fore final generated text
1255 'align' => 'L', // text alignment : R,C,L
1256 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1257 ),
1258 'content' => array(
1259 'align' => 'L', // text alignment : R,C,L
1260 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1261 ),
1262 );
1263 */
1264
1265 $rank = 0; // do not use negative rank
1266 $this->cols['desc'] = array(
1267 'rank' => $rank,
1268 'width' => false, // only for desc
1269 'status' => true,
1270 'title' => array(
1271 'textkey' => 'Designation', // use lang key is useful in some case with module
1272 'align' => 'L',
1273 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1274 // 'label' => ' ', // the final label
1275 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1276 ),
1277 'content' => array(
1278 'align' => 'L',
1279 'padding' => array(1.0, 0.5, 1.0, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1280 ),
1281 );
1282
1283 // PHOTO
1284 // $rank += 10;
1285 // $this->cols['photo'] = array(
1286 // 'rank' => $rank,
1287 // 'width' => (!getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH') ? 20 : getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH')), // in mm
1288 // 'status' => false,
1289 // 'title' => array(
1290 // 'textkey' => 'Photo',
1291 // 'label' => ' '
1292 // ),
1293 // 'content' => array(
1294 // 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1295 // ),
1296 // 'border-left' => false, // remove left line separator
1297 // );
1298
1299 // if (getDolGlobalInt('MAIN_GENERATE_INVOICES_WITH_PICTURE') && !empty($this->atleastonephoto)) {
1300 // $this->cols['photo']['status'] = true;
1301 // }
1302
1303
1304 $rank += 10;
1305 $this->cols['vat'] = array(
1306 'rank' => $rank,
1307 'status' => false,
1308 'width' => 16.0, // in mm
1309 'title' => array(
1310 'textkey' => 'VAT'
1311 ),
1312 'border-left' => true, // add left line separator
1313 );
1314
1315 if (!getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
1316 $this->cols['vat']['status'] = true;
1317 }
1318
1319 $rank += 10;
1320 $this->cols['subprice'] = array(
1321 'rank' => $rank,
1322 'width' => 19.0, // in mm
1323 'status' => true,
1324 'title' => array(
1325 'textkey' => 'PriceUHT'
1326 ),
1327 'border-left' => true, // add left line separator
1328 );
1329
1330 $rank += 10;
1331 $this->cols['qty'] = array(
1332 'rank' => $rank,
1333 'width' => 16.0, // in mm
1334 'status' => true,
1335 'title' => array(
1336 'textkey' => 'Qty'
1337 ),
1338 'border-left' => true, // add left line separator
1339 );
1340
1341 $rank += 10;
1342 $this->cols['unit'] = array(
1343 'rank' => $rank,
1344 'width' => 11.0, // in mm
1345 'status' => false,
1346 'title' => array(
1347 'textkey' => 'Unit'
1348 ),
1349 'border-left' => true, // add left line separator
1350 );
1351 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1352 $this->cols['unit']['status'] = true;
1353 }
1354
1355 $rank += 10;
1356 $this->cols['discount'] = array(
1357 'rank' => $rank,
1358 'width' => 13.0, // in mm
1359 'status' => false,
1360 'title' => array(
1361 'textkey' => 'ReductionShort'
1362 ),
1363 'border-left' => true, // add left line separator
1364 );
1365 if ($this->atleastonediscount) {
1366 $this->cols['discount']['status'] = true;
1367 }
1368
1369 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1370 $this->cols['totalexcltax'] = array(
1371 'rank' => $rank,
1372 'width' => 26.0, // in mm
1373 'status' => true,
1374 'title' => array(
1375 'textkey' => 'TotalHTShort'
1376 ),
1377 'border-left' => true, // add left line separator
1378 );
1379
1380 // Add extrafields cols
1381 if (!empty($object->lines)) {
1382 $line = reset($object->lines);
1383 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1384 }
1385
1386 $parameters = array(
1387 'object' => $object,
1388 'outputlangs' => $outputlangs,
1389 'hidedetails' => $hidedetails,
1390 'hidedesc' => $hidedesc,
1391 'hideref' => $hideref
1392 );
1393
1394 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1395 if ($reshook < 0) {
1396 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1397 } elseif (empty($reshook)) {
1398 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
1399 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1400 } else {
1401 $this->cols = $hookmanager->resArray;
1402 }
1403 }
1404}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Parent class of all other business classes for details of elements (invoices, contracts,...
Class to manage hooks.
Parent class for document models.
Class to manage translations.
Class to manage Dolibarr users.
Class to manage PDF template standard_myobject.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build and write pdf to disk.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
pdf_watermark($pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:1200
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation The hook 'pdf_writeLinkedObjects' can replace this block (retu...
Definition pdf.lib.php:1870
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:296
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:319
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:792
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:1479
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:275
pdf_truncate_text($pdf, $text, $max_width, $ellipsis_pos=1, $ellipsis="\u{2026}")
Truncates text to fit a specified width in TCPDF, with configurable ellipsis position.
Definition pdf.lib.php:3483
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:481
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2638
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1180
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:436
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165