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