dolibarr 24.0.0-beta
pdf_standard_asset.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-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
13 * Copyright (C) 2024 Nick Fragoulis
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 * or see https://www.gnu.org/
28 */
29
36require_once DOL_DOCUMENT_ROOT . '/core/modules/asset/modules_asset.php';
37require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
41
42
47{
51 public $db;
52
56 public $name;
57
61 public $description;
62
66 public $update_main_doc_field;
67
71 public $type;
72
77 public $version = 'dolibarr';
78
82 public $situationinvoice;
83
87 public $cols;
88
89
95 public function __construct($db)
96 {
97 global $conf, $langs, $mysoc;
98
99 // Translations
100 $langs->loadLangs(array("main", "bills"));
101
102 $this->db = $db;
103 $this->name = "standard";
104 $this->description = $langs->trans('DocumentModelStandardPDF');
105 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
106
107 // Dimension page
108 $this->type = 'pdf';
109 $formatarray = pdf_getFormat();
110 $this->page_largeur = $formatarray['width'];
111 $this->page_hauteur = $formatarray['height'];
112 $this->format = array($this->page_largeur, $this->page_hauteur);
113 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
114 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
115 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
116 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
117 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
118
119 // Define position of columns
120 $this->posxdesc = $this->marge_gauche + 1; // used for notes and other stuff
121
122
123 $this->tabTitleHeight = 5; // default height
124
125 // Use new system for position of columns, view $this->defineColumnField()
126
127 $this->tva = array();
128 $this->localtax1 = array();
129 $this->localtax2 = array();
130 $this->atleastoneratenotnull = 0;
131 $this->atleastonediscount = 0;
132 $this->situationinvoice = false;
133
134 if ($mysoc === null) {
135 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
136 return;
137 }
138 // Get source company
139 $this->emetteur = $mysoc;
140 if (empty($this->emetteur->country_code)) {
141 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
142 }
143 }
144
145
146 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
158 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
159 {
160 // phpcs:enable
161 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
162
163 dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
164
165 if (!is_object($outputlangs)) {
166 $outputlangs = $langs;
167 }
168 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
169 if (getDolGlobalString('MAIN_USE_FPDF')) {
170 $outputlangs->charset_output = 'ISO-8859-1';
171 }
172
173 // Load translation files required by the page
174 $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
175
176 global $outputlangsbis;
177 $outputlangsbis = null;
178 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
179 $outputlangsbis = new Translate('', $conf);
180 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
181 $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies"));
182 }
183
184 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
185
186 $hidetop = 0;
187 if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
188 $hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
189 }
190
191 if ($conf->asset->dir_output.'/asset') {
192 $object->fetch_thirdparty();
193
194 // Definition of $dir and $file
195 if ($object->specimen) {
196 $dir = $conf->asset->dir_output.'/asset';
197 $file = $dir."/SPECIMEN.pdf";
198 } else {
199 $objectref = dol_sanitizeFileName($object->ref);
200 $dir = $conf->asset->dir_output.'/asset/'.$objectref;
201 $file = $dir."/".$objectref.".pdf";
202 }
203 if (!file_exists($dir)) {
204 if (dol_mkdir($dir) < 0) {
205 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
206 return 0;
207 }
208 }
209
210 if (file_exists($dir)) {
211 // Add pdfgeneration hook
212 if (!is_object($hookmanager)) {
213 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
214 $hookmanager = new HookManager($this->db);
215 }
216 $hookmanager->initHooks(array('pdfgeneration'));
217 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
218 global $action;
219 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
220
221 // Set nblines with the new facture lines content after hook
222 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
223
224 // Create pdf instance
225 $pdf = pdf_getInstance($this->format);
226 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
227 $pdf->setAutoPageBreak(true, 0);
228
229 $heightforinfotot = 50; // Height reserved to output the info and total part and payment part
230 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
231 $heightforfooter = $this->marge_basse + (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
232
233 if (class_exists('TCPDF')) {
234 $pdf->setPrintHeader(false);
235 $pdf->setPrintFooter(false);
236 }
237 $pdf->SetFont(pdf_getPDFFont($outputlangs));
238
239 // Set path to the background PDF File
240 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
241 $logodir = $conf->mycompany->dir_output;
242 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
243 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
244 }
245 $pagecount = $pdf->setSourceFile($logodir .'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
246 $tplidx = $pdf->importPage(1);
247 }
248
249 $pdf->Open();
250 $pagenb = 0;
251 $pdf->SetDrawColor(128, 128, 128);
252
253 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
254 $pdf->SetSubject($outputlangs->transnoentities("PdfTitle"));
255 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
256 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
257 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfTitle")." ".$outputlangs->convToOutputCharset((string) $object->thirdparty->name));
258 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
259 $pdf->SetCompression(false);
260 }
261
262 // Set certificate
263 $cert = getDolUserString('CERTIFICATE_CRT', getDolGlobalString('CERTIFICATE_CRT'));
264 $certprivate = getDolUserString('CERTIFICATE_CRT_PRIVATE', getDolGlobalString('CERTIFICATE_CRT_PRIVATE'));
265
266 // If a certificate is found
267 if ($cert) {
268 $info = array(
269 'Name' => $this->emetteur->name,
270 'Location' => getCountry($this->emetteur->country_code, ''),
271 'Reason' => 'ASSET',
272 'ContactInfo' => $this->emetteur->email
273 );
274 $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info);
275 }
276
277 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
278 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
279
280 // New page
281 $pdf->AddPage();
282 if (!empty($tplidx)) {
283 $pdf->useTemplate($tplidx);
284 }
285 $pagenb++;
286
287 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
288 $pdf->SetFont('', '', $default_font_size - 1);
289 $pdf->MultiCell(0, 3, ''); // Set interline to 3
290 $pdf->SetTextColor(0, 0, 0);
291
292 $tab_top = 90 + $top_shift;
293 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
294 $tab_height = 130 - $top_shift;
295 $tab_height_newpage = 150;
296 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
297 $tab_height_newpage -= $top_shift;
298 }
299
300 $nexY = $tab_top - 1;
301
302 // Display notes
303 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
304 // Extrafields in note
305 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
306 if (!empty($extranote)) {
307 $notetoshow = dol_concatdesc($notetoshow, $extranote);
308 }
309
310 $pagenb = $pdf->getPage();
311 if ($notetoshow) {
312 $tab_top -= 2;
313
314 $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
315 $pageposbeforenote = $pagenb;
316
317 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
318 complete_substitutions_array($substitutionarray, $outputlangs, $object);
319 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
320 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
321
322 $pdf->startTransaction();
323
324 $pdf->SetFont('', '', $default_font_size - 1);
325 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
326 // Description
327 $pageposafternote = $pdf->getPage();
328 $posyafter = $pdf->GetY();
329
330 if ($pageposafternote > $pageposbeforenote) {
331 $pdf->rollbackTransaction(true);
332
333 // prepare pages to receive notes
334 while ($pagenb < $pageposafternote) {
335 $pdf->AddPage();
336 $pagenb++;
337 if (!empty($tplidx)) {
338 $pdf->useTemplate($tplidx);
339 }
340 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
341 $this->_pagehead($pdf, $object, 0, $outputlangs);
342 }
343 // $this->_pagefoot($pdf,$object,$outputlangs,1);
344 $pdf->setTopMargin($tab_top_newpage);
345 // The only function to edit the bottom margin of current page to set it.
346 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
347 }
348
349 // back to start
350 $pdf->setPage($pageposbeforenote);
351 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
352 $pdf->SetFont('', '', $default_font_size - 1);
353 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
354 $pageposafternote = $pdf->getPage();
355
356 $posyafter = $pdf->GetY();
357
358 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
359 $pdf->AddPage('', '', true);
360 $pagenb++;
361 $pageposafternote++;
362 $pdf->setPage($pageposafternote);
363 $pdf->setTopMargin($tab_top_newpage);
364 // The only function to edit the bottom margin of current page to set it.
365 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext);
366 //$posyafter = $tab_top_newpage;
367 }
368
369
370 // apply note frame to previous pages
371 $i = $pageposbeforenote;
372 while ($i < $pageposafternote) {
373 $pdf->setPage($i);
374
375
376 $pdf->SetDrawColor(128, 128, 128);
377 // Draw note frame
378 if ($i > $pageposbeforenote) {
379 $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
380 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
381 } else {
382 $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
383 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
384 }
385
386 // Add footer
387 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
388 $this->_pagefoot($pdf, $object, $outputlangs, 1);
389
390 $i++;
391 }
392
393 // apply note frame to last page
394 $pdf->setPage($pageposafternote);
395 if (!empty($tplidx)) {
396 $pdf->useTemplate($tplidx);
397 }
398 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
399 $this->_pagehead($pdf, $object, 0, $outputlangs);
400 }
401 $height_note = $posyafter - $tab_top_newpage;
402 $pdf->RoundedRect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
403 } else { // No pagebreak
404 $pdf->commitTransaction();
405 $posyafter = $pdf->GetY();
406 $height_note = $posyafter - $tab_top;
407 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1, $this->corner_radius, '1234', 'D');
408
409
410 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
411 // not enough space, need to add page
412 $pdf->AddPage('', '', true);
413 $pagenb++;
414 $pageposafternote++;
415 $pdf->setPage($pageposafternote);
416 if (!empty($tplidx)) {
417 $pdf->useTemplate($tplidx);
418 }
419 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
420 $this->_pagehead($pdf, $object, 0, $outputlangs);
421 }
422
423 $posyafter = $tab_top_newpage;
424 }
425 }
426
427 $tab_height -= $height_note;
428 $tab_top = $posyafter + 6;
429 } else {
430 $height_note = 0;
431 }
432
433 // Use new auto column system
434 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
435
436 // Table simulation to know the height of the title line
437 $pdf->startTransaction();
438 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
439 $pdf->rollbackTransaction(true);
440
441 $nexY = $tab_top + $this->tabTitleHeight;
442
443 // Loop on each lines
444 $pageposbeforeprintlines = $pdf->getPage();
445 $pagenb = $pageposbeforeprintlines;
446 for ($i = 0; $i < $nblines; $i++) {
447 $curY = $nexY;
448 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
449 $pdf->SetTextColor(0, 0, 0);
450
451 $pdf->setTopMargin($tab_top_newpage);
452 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
453 $pageposbefore = $pdf->getPage();
454
455 $showpricebeforepagebreak = 1;
456 $posYAfterImage = 0;
457
458 // Description of product line
459 if ($this->getColumnStatus('desc')) {
460 $pdf->startTransaction();
461
462 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
463 $pageposafter = $pdf->getPage();
464
465 if ($pageposafter > $pageposbefore) { // There is a pagebreak
466 $pdf->rollbackTransaction(true);
467 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
468
469 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
470
471 $pageposafter = $pdf->getPage();
472 $posyafter = $pdf->GetY();
473 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
474 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
475 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
476 $pdf->AddPage('', '', true);
477 if (!empty($tplidx)) {
478 $pdf->useTemplate($tplidx);
479 }
480 $pdf->setPage($pageposafter + 1);
481 }
482 } else {
483 // We found a page break
484 // Allows data in the first page if description is long enough to break in multiples pages
485 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
486 $showpricebeforepagebreak = 1;
487 } else {
488 $showpricebeforepagebreak = 0;
489 }
490 }
491 } else { // No pagebreak
492 $pdf->commitTransaction();
493 }
494 }
495
496 $nexY = $pdf->GetY();
497 $pageposafter = $pdf->getPage();
498 $pdf->setPage($pageposbefore);
499 $pdf->setTopMargin($this->marge_haute);
500 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
501
502 // We suppose that a too long description were moved completely on next page
503 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
504 $pdf->setPage($pageposafter);
505 $curY = $tab_top_newpage;
506 }
507
508 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default
509
510 // Quantity
511 // Enough for 6 chars
512 if ($this->getColumnStatus('qty')) {
513 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
514 $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
515 $nexY = max($pdf->GetY(), $nexY);
516 }
517
518 // Extrafields
519 if (!empty($object->lines[$i]->array_options)) {
520 foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
521 if ($this->getColumnStatus($extrafieldColKey)) {
522 $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
523 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
524 $nexY = max($pdf->GetY(), $nexY);
525 }
526 }
527 }
528
529
530 $parameters = array(
531 'object' => $object,
532 'i' => $i,
533 'pdf' => & $pdf,
534 'curY' => & $curY,
535 'nexY' => & $nexY,
536 'outputlangs' => $outputlangs,
537 'hidedetails' => $hidedetails
538 );
539 $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
540
541
542 $sign = 1;
543 // Collect total by value of vat rate into $this->tva["taux"]=total_tva
544 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
545 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation
546 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
547 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
548 } else {
549 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
550 }
551 } else {
552 if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) {
553 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
554 } else {
555 $tvaligne = $sign * $object->lines[$i]->total_tva;
556 }
557 }
558
559 $localtax1ligne = $object->lines[$i]->total_localtax1;
560 $localtax2ligne = $object->lines[$i]->total_localtax2;
561 $localtax1_rate = $object->lines[$i]->localtax1_tx;
562 $localtax2_rate = $object->lines[$i]->localtax2_tx;
563 $localtax1_type = $object->lines[$i]->localtax1_type;
564 $localtax2_type = $object->lines[$i]->localtax2_type;
565
566 // TODO remise_percent is an obsolete field for object parent
567 /*if ($object->remise_percent) {
568 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
569 }
570 if ($object->remise_percent) {
571 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
572 }
573 if ($object->remise_percent) {
574 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
575 }*/
576
577 $vatrate = (string) $object->lines[$i]->tva_tx;
578
579 // Retrieve type from database for backward compatibility with old records
580 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
581 && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
582 $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
583 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
584 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
585 }
586
587 // retrieve global local tax
588 if ($localtax1_type && $localtax1ligne != 0) {
589 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
590 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
591 } else {
592 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
593 }
594 }
595 if ($localtax2_type && $localtax2ligne != 0) {
596 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
597 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
598 } else {
599 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
600 }
601 }
602
603 if (((int) $object->lines[$i]->info_bits & 0x01) == 0x01) {
604 $vatrate .= '*';
605 }
606 if (!isset($this->tva[$vatrate])) {
607 $this->tva[$vatrate] = 0;
608 }
609 $this->tva[$vatrate] += $tvaligne;
610
611 $nexY = max($nexY, $posYAfterImage);
612
613 // Add line
614 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
615 $pdf->setPage($pageposafter);
616 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
617 //$pdf->SetDrawColor(190,190,200);
618 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
619 $pdf->SetLineStyle(array('dash' => 0));
620 }
621
622 // Detect if some page were added automatically and output _tableau for past pages
623 while ($pagenb < $pageposafter) {
624 $pdf->setPage($pagenb);
625 if ($pagenb == $pageposbeforeprintlines) {
626 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
627 } else {
628 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
629 }
630 $this->_pagefoot($pdf, $object, $outputlangs, 1);
631 $pagenb++;
632 $pdf->setPage($pagenb);
633 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
634 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
635 $this->_pagehead($pdf, $object, 0, $outputlangs);
636 }
637 }
638
639 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
640 if ($pagenb == $pageposafter) {
641 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
642 } else {
643 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
644 }
645 $this->_pagefoot($pdf, $object, $outputlangs, 1);
646 // New page
647 $pdf->AddPage();
648 if (!empty($tplidx)) {
649 $pdf->useTemplate($tplidx);
650 }
651 $pagenb++;
652 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
653 $this->_pagehead($pdf, $object, 0, $outputlangs);
654 }
655 }
656 }
657
658 // Show square
659 if ($pagenb == $pageposbeforeprintlines) {
660 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
661 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
662 } else {
663 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
664 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
665 }
666
667 // Display infos area
668 //$posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
669
670 // Display total zone
671 //$posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
672
673 // Display payment area
674 /*
675 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
676 {
677 $posy = $this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
678 }
679 */
680
681 // Pagefoot
682 $this->_pagefoot($pdf, $object, $outputlangs);
683 if (method_exists($pdf, 'AliasNbPages')) {
684 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
685 }
686
687 $pdf->Close();
688
689 $pdf->Output($file, 'F');
690
691 // Add pdfgeneration hook
692 $hookmanager->initHooks(array('pdfgeneration'));
693 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
694 global $action;
695 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
696 $this->warnings = $hookmanager->warnings;
697 if ($reshook < 0) {
698 $this->error = $hookmanager->error;
699 $this->errors = $hookmanager->errors;
700 dolChmod($file);
701 return -1;
702 }
703
704 dolChmod($file);
705
706 $this->result = array('fullpath' => $file);
707
708 return 1; // No error
709 } else {
710 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
711 return 0;
712 }
713 } else {
714 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "ASSET_OUTPUTDIR");
715 return 0;
716 }
717 }
718
719 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
727 public static function liste_modeles($db, $maxfilenamelength = 0)
728 {
729 // phpcs:enable
730 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
731 }
732
733 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
748 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
749 {
750 global $conf;
751
752 // Force to disable hidetop and hidebottom
753 $hidebottom = 0;
754 if ($hidetop) {
755 $hidetop = -1;
756 }
757
758 $currency = !empty($currency) ? $currency : getDolCurrency();
759 $default_font_size = pdf_getPDFFontSize($outputlangs);
760
761 // Amount in (at tab_top - 1)
762 $pdf->SetTextColor(0, 0, 0);
763 $pdf->SetFont('', '', $default_font_size - 2);
764
765 if (empty($hidetop)) {
766 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
767 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
768 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
769 }
770
771 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
772 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
773
774 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
775 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
776 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
777 }
778 }
779
780 $pdf->SetDrawColor(128, 128, 128);
781 $pdf->SetFont('', '', $default_font_size - 1);
782
783 // Output Rect
784 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
785
786
787 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
788
789 if (empty($hidetop)) {
790 $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
791 }
792 }
793
794 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
805 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
806 {
807 global $conf, $langs;
808
809 // Load traductions files required by page
810 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
811
812 $default_font_size = pdf_getPDFFontSize($outputlangs);
813
814 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
815
816 // Show Draft Watermark
817 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) {
818 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
819 }
820
821 $pdf->SetTextColor(0, 0, 60);
822 $pdf->SetFont('', 'B', $default_font_size + 3);
823
824 $w = 110;
825
826 $posy = $this->marge_haute;
827 $posx = $this->page_largeur - $this->marge_droite - $w;
828
829 $pdf->SetXY($this->marge_gauche, $posy);
830
831 // Logo
832 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
833 if ($this->emetteur->logo) {
834 $logodir = $conf->mycompany->dir_output;
835 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
836 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
837 }
838 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
839 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
840 } else {
841 $logo = $logodir.'/logos/'.$this->emetteur->logo;
842 }
843 if (is_readable($logo)) {
844 $height = pdf_getHeightForLogo($logo);
845 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
846 } else {
847 $pdf->SetTextColor(200, 0, 0);
848 $pdf->SetFont('', 'B', $default_font_size - 2);
849 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
850 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
851 }
852 } else {
853 $text = (string) $this->emetteur->name;
854 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
855 }
856 }
857
858 $pdf->SetFont('', 'B', $default_font_size + 3);
859 $pdf->SetXY($posx, $posy);
860 $pdf->SetTextColor(0, 0, 60);
861 $title = $outputlangs->transnoentities("PdfTitle");
862 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
863 $title .= ' - ';
864 $title .= $outputlangsbis->transnoentities("PdfTitle");
865 }
866 $pdf->MultiCell($w, 3, $title, '', 'R');
867
868 $pdf->SetFont('', 'B', $default_font_size);
869
870 $posy += 5;
871 $pdf->SetXY($posx, $posy);
872 $pdf->SetTextColor(0, 0, 60);
873 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
874 if ($object->status == $object::STATUS_DRAFT) {
875 $pdf->SetTextColor(128, 0, 0);
876 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
877 }
878 $pdf->MultiCell($w, 4, $textref, '', 'R');
879
880 $posy += 1;
881 $pdf->SetFont('', '', $default_font_size - 2);
882
883 // if ($object->ref_client) {
884 // $posy += 4;
885 // $pdf->SetXY($posx, $posy);
886 // $pdf->SetTextColor(0, 0, 60);
887 // $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
888 // }
889
890 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
891 $object->fetchProject();
892 if (!empty($object->project->ref)) {
893 $posy += 3;
894 $pdf->SetXY($posx, $posy);
895 $pdf->SetTextColor(0, 0, 60);
896 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
897 }
898 }
899
900 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
901 $object->fetchProject();
902 if (!empty($object->project->ref)) {
903 $outputlangs->load("projects");
904 $posy += 3;
905 $pdf->SetXY($posx, $posy);
906 $pdf->SetTextColor(0, 0, 60);
907 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
908 }
909 }
910
911 $posy += 4;
912 $pdf->SetXY($posx, $posy);
913 $pdf->SetTextColor(0, 0, 60);
914
915 $title = $outputlangs->transnoentities("Date");
916 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
917 $title .= ' - '.$outputlangsbis->transnoentities("Date");
918 }
919 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_acquisition, "day", false, $outputlangs), '', 'R');
920
921 if ($object->thirdparty->code_client) {
922 $posy += 3;
923 $pdf->SetXY($posx, $posy);
924 $pdf->SetTextColor(0, 0, 60);
925 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
926 }
927
928 // Get contact
929 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
930 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
931 if (count($arrayidcontact) > 0) {
932 $usertmp = new User($this->db);
933 $usertmp->fetch($arrayidcontact[0]);
934 $posy += 4;
935 $pdf->SetXY($posx, $posy);
936 $pdf->SetTextColor(0, 0, 60);
937 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
938 }
939 }
940
941 $posy += 1;
942
943 $top_shift = 0;
944 // Show list of linked objects
945 $current_y = $pdf->getY();
946 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
947 if ($current_y < $pdf->getY()) {
948 $top_shift = $pdf->getY() - $current_y;
949 }
950
951 if ($showaddress) {
952 // Sender properties
953 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
954
955 // Show sender
956 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
957 $posy += $top_shift;
958 $posx = $this->marge_gauche;
959 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
960 $posx = $this->page_largeur - $this->marge_droite - 80;
961 }
962
963 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
964 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
965
966
967 // Show sender frame
968 $pdf->SetTextColor(0, 0, 0);
969 $pdf->SetFont('', '', $default_font_size - 2);
970 $pdf->SetXY($posx, $posy - 5);
971 $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
972 $pdf->SetXY($posx, $posy);
973 $pdf->SetFillColor(230, 230, 230);
974 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
975 $pdf->SetTextColor(0, 0, 60);
976
977 // Show sender name
978 $pdf->SetXY($posx + 2, $posy + 3);
979 $pdf->SetFont('', 'B', $default_font_size);
980 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset((string) $this->emetteur->name), 0, 'L');
981 $posy = $pdf->getY();
982
983 // Show sender information
984 $pdf->SetXY($posx + 2, $posy);
985 $pdf->SetFont('', '', $default_font_size - 1);
986 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
987
988 // If BILLING contact defined on invoice, we use it
989 $usecontact = false;
990 $arrayidcontact = $object->getIdContact('external', 'BILLING');
991 if (count($arrayidcontact) > 0) {
992 $usecontact = true;
993 $result = $object->fetch_contact($arrayidcontact[0]);
994 }
995
996 // Recipient name
997 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
998 $thirdparty = $object->contact;
999 } else {
1000 $thirdparty = $object->thirdparty;
1001 }
1002
1003 if (is_object($thirdparty)) {
1004 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1005 } else {
1006 $carac_client_name = '';
1007 }
1008
1009 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), 'target', $object);
1010
1011 // Show recipient
1012 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1013 if ($this->page_largeur < 210) {
1014 $widthrecbox = 84; // To work with US executive format
1015 }
1016 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1017 $posy += $top_shift;
1018 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1019 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1020 $posx = $this->marge_gauche;
1021 }
1022
1023 // Show recipient frame
1024 $pdf->SetTextColor(0, 0, 0);
1025 $pdf->SetFont('', '', $default_font_size - 2);
1026 $pdf->SetXY($posx + 2, $posy - 5);
1027 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1028 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1029
1030 // Show recipient name
1031 $pdf->SetXY($posx + 2, $posy + 3);
1032 $pdf->SetFont('', 'B', $default_font_size);
1033 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1034
1035 $posy = $pdf->getY();
1036
1037 // Show recipient information
1038 $pdf->SetFont('', '', $default_font_size - 1);
1039 $pdf->SetXY($posx + 2, $posy);
1040 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1041 }
1042
1043 $pdf->SetTextColor(0, 0, 0);
1044
1045 return $top_shift;
1046 }
1047
1048 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1058 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1059 {
1060 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1061 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1062 }
1063
1074 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1075 {
1076 global $conf, $hookmanager;
1077
1078 // Default field style for content
1079 $this->defaultContentsFieldsStyle = array(
1080 'align' => 'R', // R,C,L
1081 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1082 );
1083
1084 // Default field style for content
1085 $this->defaultTitlesFieldsStyle = array(
1086 'align' => 'C', // R,C,L
1087 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1088 );
1089
1090 /*
1091 * For example
1092 $this->cols['theColKey'] = array(
1093 'rank' => $rank, // int : use for ordering columns
1094 'width' => 20, // the column width in mm
1095 'title' => array(
1096 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1097 'label' => ' ', // the final label : used fore final generated text
1098 'align' => 'L', // text alignment : R,C,L
1099 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1100 ),
1101 'content' => array(
1102 'align' => 'L', // text alignment : R,C,L
1103 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1104 ),
1105 );
1106 */
1107
1108 $rank = 0; // do not use negative rank
1109 $this->cols['desc'] = array(
1110 'rank' => $rank,
1111 'width' => false, // only for desc
1112 'status' => true,
1113 'title' => array(
1114 'textkey' => 'Designation', // use lang key is useful in some case with module
1115 'align' => 'L',
1116 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1117 // 'label' => ' ', // the final label
1118 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1119 ),
1120 'content' => array(
1121 'align' => 'L',
1122 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1123 ),
1124 );
1125
1126 $rank += 10;
1127 $this->cols['vat'] = array(
1128 'rank' => $rank,
1129 'status' => false,
1130 'width' => 16, // in mm
1131 'title' => array(
1132 'textkey' => 'VAT'
1133 ),
1134 'border-left' => true, // add left line separator
1135 );
1136
1137 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
1138 $this->cols['vat']['status'] = true;
1139 }
1140
1141 $rank += 10;
1142 $this->cols['subprice'] = array(
1143 'rank' => $rank,
1144 'width' => 19, // in mm
1145 'status' => true,
1146 'title' => array(
1147 'textkey' => 'PriceUHT'
1148 ),
1149 'border-left' => true, // add left line separator
1150 );
1151
1152 $rank += 10;
1153 $this->cols['qty'] = array(
1154 'rank' => $rank,
1155 'width' => 16, // in mm
1156 'status' => true,
1157 'title' => array(
1158 'textkey' => 'Qty'
1159 ),
1160 'border-left' => true, // add left line separator
1161 );
1162
1163 $rank += 10;
1164 $this->cols['progress'] = array(
1165 'rank' => $rank,
1166 'width' => 19, // in mm
1167 'status' => false,
1168 'title' => array(
1169 'textkey' => 'Progress'
1170 ),
1171 'border-left' => true, // add left line separator
1172 );
1173
1174 if ($this->situationinvoice) {
1175 $this->cols['progress']['status'] = true;
1176 }
1177
1178 $rank += 10;
1179 $this->cols['unit'] = array(
1180 'rank' => $rank,
1181 'width' => 11, // in mm
1182 'status' => false,
1183 'title' => array(
1184 'textkey' => 'Unit'
1185 ),
1186 'border-left' => true, // add left line separator
1187 );
1188 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1189 $this->cols['unit']['status'] = true;
1190 }
1191
1192 $rank += 10;
1193 $this->cols['discount'] = array(
1194 'rank' => $rank,
1195 'width' => 13, // in mm
1196 'status' => false,
1197 'title' => array(
1198 'textkey' => 'ReductionShort'
1199 ),
1200 'border-left' => true, // add left line separator
1201 );
1202 if ($this->atleastonediscount) {
1203 $this->cols['discount']['status'] = true;
1204 }
1205
1206 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1207 $this->cols['totalexcltax'] = array(
1208 'rank' => $rank,
1209 'width' => 26, // in mm
1210 'status' => true,
1211 'title' => array(
1212 'textkey' => 'TotalHT'
1213 ),
1214 'border-left' => true, // add left line separator
1215 );
1216
1217 // Add extrafields cols
1218 if (!empty($object->lines)) {
1219 $line = reset($object->lines);
1220 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1221 }
1222
1223 $parameters = array(
1224 'object' => $object,
1225 'outputlangs' => $outputlangs,
1226 'hidedetails' => $hidedetails,
1227 'hidedesc' => $hidedesc,
1228 'hideref' => $hideref
1229 );
1230
1231 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1232 if ($reshook < 0) {
1233 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1234 } elseif (empty($reshook)) {
1235 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
1236 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1237 } else {
1238 $this->cols = $hookmanager->resArray;
1239 }
1240 }
1241}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
pdfTabTitles(&$pdf, $tab_top, $tab_height, $outputlangs, $hidetop=0)
Print standard column content.
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
getExtrafieldContent($object, $extrafieldKey, $outputlangs=null)
get extrafield content for pdf writeHtmlCell compatibility usage for PDF line columns and object note...
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
defineColumnExtrafield($object, $outputlangs, $hidedetails=0)
Define Array Column Field for extrafields.
Class to manage hooks.
Parent class for documents models.
Class to manage translations.
Class to manage Dolibarr users.
Class to manage PDF template standard_asset.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='', $outputlangsbis=null)
Show table for lines.
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(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
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.
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...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
pdf_watermark($pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:1155
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.
Definition pdf.lib.php:1808
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:294
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:317
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:747
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:1421
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:273
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:438
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
Definition pdf.lib.php:2549
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:1135
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:393
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133