dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024 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(1, 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])) {
243 $logodir = $conf->mycompany->multidir_output[$object->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('', 1, $heightforfooter + $heightforfreetext);
349 }
350
351 // back to start
352 $pdf->setPage($pageposbeforenote);
353 $pdf->setPageOrientation('', 1, $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('', 1, $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('', 1, 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('', 1, $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('', 1, $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('', 1, 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 (($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('', 1, 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 if ($reshook < 0) {
699 $this->error = $hookmanager->error;
700 $this->errors = $hookmanager->errors;
701 }
702
703 dolChmod($file);
704
705 $this->result = array('fullpath' => $file);
706
707 return 1; // No error
708 } else {
709 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
710 return 0;
711 }
712 } else {
713 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "ASSET_OUTPUTDIR");
714 return 0;
715 }
716 }
717
718 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
726 public static function liste_modeles($db, $maxfilenamelength = 0)
727 {
728 // phpcs:enable
729 return parent::liste_modeles($db, $maxfilenamelength); // TODO: Change the autogenerated stub
730 }
731
732 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
747 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
748 {
749 global $conf;
750
751 // Force to disable hidetop and hidebottom
752 $hidebottom = 0;
753 if ($hidetop) {
754 $hidetop = -1;
755 }
756
757 $currency = !empty($currency) ? $currency : $conf->currency;
758 $default_font_size = pdf_getPDFFontSize($outputlangs);
759
760 // Amount in (at tab_top - 1)
761 $pdf->SetTextColor(0, 0, 0);
762 $pdf->SetFont('', '', $default_font_size - 2);
763
764 if (empty($hidetop)) {
765 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
766 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
767 $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
768 }
769
770 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
771 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
772
773 //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
774 if (getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
775 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, $this->corner_radius, '1001', 'F', null, explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
776 }
777 }
778
779 $pdf->SetDrawColor(128, 128, 128);
780 $pdf->SetFont('', '', $default_font_size - 1);
781
782 // Output Rect
783 $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
784
785
786 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
787
788 if (empty($hidetop)) {
789 $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
790 }
791 }
792
793 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
804 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
805 {
806 global $conf, $langs;
807
808 // Load traductions files required by page
809 $outputlangs->loadLangs(array("main", "bills", "propal", "companies"));
810
811 $default_font_size = pdf_getPDFFontSize($outputlangs);
812
813 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
814
815 // Show Draft Watermark
816 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) {
817 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
818 }
819
820 $pdf->SetTextColor(0, 0, 60);
821 $pdf->SetFont('', 'B', $default_font_size + 3);
822
823 $w = 110;
824
825 $posy = $this->marge_haute;
826 $posx = $this->page_largeur - $this->marge_droite - $w;
827
828 $pdf->SetXY($this->marge_gauche, $posy);
829
830 // Logo
831 if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) {
832 if ($this->emetteur->logo) {
833 $logodir = $conf->mycompany->dir_output;
834 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
835 $logodir = $conf->mycompany->multidir_output[$object->entity];
836 }
837 if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) {
838 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
839 } else {
840 $logo = $logodir.'/logos/'.$this->emetteur->logo;
841 }
842 if (is_readable($logo)) {
843 $height = pdf_getHeightForLogo($logo);
844 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
845 } else {
846 $pdf->SetTextColor(200, 0, 0);
847 $pdf->SetFont('', 'B', $default_font_size - 2);
848 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
849 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
850 }
851 } else {
852 $text = $this->emetteur->name;
853 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
854 }
855 }
856
857 $pdf->SetFont('', 'B', $default_font_size + 3);
858 $pdf->SetXY($posx, $posy);
859 $pdf->SetTextColor(0, 0, 60);
860 $title = $outputlangs->transnoentities("PdfTitle");
861 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
862 $title .= ' - ';
863 $title .= $outputlangsbis->transnoentities("PdfTitle");
864 }
865 $pdf->MultiCell($w, 3, $title, '', 'R');
866
867 $pdf->SetFont('', 'B', $default_font_size);
868
869 $posy += 5;
870 $pdf->SetXY($posx, $posy);
871 $pdf->SetTextColor(0, 0, 60);
872 $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
873 if ($object->status == $object::STATUS_DRAFT) {
874 $pdf->SetTextColor(128, 0, 0);
875 $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
876 }
877 $pdf->MultiCell($w, 4, $textref, '', 'R');
878
879 $posy += 1;
880 $pdf->SetFont('', '', $default_font_size - 2);
881
882 // if ($object->ref_client) {
883 // $posy += 4;
884 // $pdf->SetXY($posx, $posy);
885 // $pdf->SetTextColor(0, 0, 60);
886 // $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".$outputlangs->convToOutputCharset($object->ref_client), '', 'R');
887 // }
888
889 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
890 $object->fetchProject();
891 if (!empty($object->project->ref)) {
892 $posy += 3;
893 $pdf->SetXY($posx, $posy);
894 $pdf->SetTextColor(0, 0, 60);
895 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->projet->title), '', 'R');
896 }
897 }
898
899 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
900 $object->fetchProject();
901 if (!empty($object->project->ref)) {
902 $outputlangs->load("projects");
903 $posy += 3;
904 $pdf->SetXY($posx, $posy);
905 $pdf->SetTextColor(0, 0, 60);
906 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
907 }
908 }
909
910 $posy += 4;
911 $pdf->SetXY($posx, $posy);
912 $pdf->SetTextColor(0, 0, 60);
913
914 $title = $outputlangs->transnoentities("Date");
915 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
916 $title .= ' - '.$outputlangsbis->transnoentities("Date");
917 }
918 $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->date_acquisition, "day", false, $outputlangs), '', 'R');
919
920 if ($object->thirdparty->code_client) {
921 $posy += 3;
922 $pdf->SetXY($posx, $posy);
923 $pdf->SetTextColor(0, 0, 60);
924 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
925 }
926
927 // Get contact
928 if (getDolGlobalString('DOC_SHOW_FIRST_SALES_REP')) {
929 $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
930 if (count($arrayidcontact) > 0) {
931 $usertmp = new User($this->db);
932 $usertmp->fetch($arrayidcontact[0]);
933 $posy += 4;
934 $pdf->SetXY($posx, $posy);
935 $pdf->SetTextColor(0, 0, 60);
936 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
937 }
938 }
939
940 $posy += 1;
941
942 $top_shift = 0;
943 // Show list of linked objects
944 $current_y = $pdf->getY();
945 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
946 if ($current_y < $pdf->getY()) {
947 $top_shift = $pdf->getY() - $current_y;
948 }
949
950 if ($showaddress) {
951 // Sender properties
952 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
953
954 // Show sender
955 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
956 $posy += $top_shift;
957 $posx = $this->marge_gauche;
958 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
959 $posx = $this->page_largeur - $this->marge_droite - 80;
960 }
961
962 $hautcadre = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 38 : 40;
963 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
964
965
966 // Show sender frame
967 $pdf->SetTextColor(0, 0, 0);
968 $pdf->SetFont('', '', $default_font_size - 2);
969 $pdf->SetXY($posx, $posy - 5);
970 $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
971 $pdf->SetXY($posx, $posy);
972 $pdf->SetFillColor(230, 230, 230);
973 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
974 $pdf->SetTextColor(0, 0, 60);
975
976 // Show sender name
977 $pdf->SetXY($posx + 2, $posy + 3);
978 $pdf->SetFont('', 'B', $default_font_size);
979 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
980 $posy = $pdf->getY();
981
982 // Show sender information
983 $pdf->SetXY($posx + 2, $posy);
984 $pdf->SetFont('', '', $default_font_size - 1);
985 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
986
987 // If BILLING contact defined on invoice, we use it
988 $usecontact = false;
989 $arrayidcontact = $object->getIdContact('external', 'BILLING');
990 if (count($arrayidcontact) > 0) {
991 $usecontact = true;
992 $result = $object->fetch_contact($arrayidcontact[0]);
993 }
994
995 // Recipient name
996 if ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
997 $thirdparty = $object->contact;
998 } else {
999 $thirdparty = $object->thirdparty;
1000 }
1001
1002 if (is_object($thirdparty)) {
1003 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
1004 }
1005
1006 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), ($usecontact ? 1 : 0), 'target', $object);
1007
1008 // Show recipient
1009 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
1010 if ($this->page_largeur < 210) {
1011 $widthrecbox = 84; // To work with US executive format
1012 }
1013 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
1014 $posy += $top_shift;
1015 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1016 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
1017 $posx = $this->marge_gauche;
1018 }
1019
1020 // Show recipient frame
1021 $pdf->SetTextColor(0, 0, 0);
1022 $pdf->SetFont('', '', $default_font_size - 2);
1023 $pdf->SetXY($posx + 2, $posy - 5);
1024 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1025 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
1026
1027 // Show recipient name
1028 $pdf->SetXY($posx + 2, $posy + 3);
1029 $pdf->SetFont('', 'B', $default_font_size);
1030 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1031
1032 $posy = $pdf->getY();
1033
1034 // Show recipient information
1035 $pdf->SetFont('', '', $default_font_size - 1);
1036 $pdf->SetXY($posx + 2, $posy);
1037 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1038 }
1039
1040 $pdf->SetTextColor(0, 0, 0);
1041
1042 return $top_shift;
1043 }
1044
1045 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1055 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1056 {
1057 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1058 return pdf_pagefoot($pdf, $outputlangs, 'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1059 }
1060
1071 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1072 {
1073 global $conf, $hookmanager;
1074
1075 // Default field style for content
1076 $this->defaultContentsFieldsStyle = array(
1077 'align' => 'R', // R,C,L
1078 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1079 );
1080
1081 // Default field style for content
1082 $this->defaultTitlesFieldsStyle = array(
1083 'align' => 'C', // R,C,L
1084 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1085 );
1086
1087 /*
1088 * For example
1089 $this->cols['theColKey'] = array(
1090 'rank' => $rank, // int : use for ordering columns
1091 'width' => 20, // the column width in mm
1092 'title' => array(
1093 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1094 'label' => ' ', // the final label : used fore final generated text
1095 'align' => 'L', // text alignment : R,C,L
1096 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1097 ),
1098 'content' => array(
1099 'align' => 'L', // text alignment : R,C,L
1100 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1101 ),
1102 );
1103 */
1104
1105 $rank = 0; // do not use negative rank
1106 $this->cols['desc'] = array(
1107 'rank' => $rank,
1108 'width' => false, // only for desc
1109 'status' => true,
1110 'title' => array(
1111 'textkey' => 'Designation', // use lang key is useful in somme case with module
1112 'align' => 'L',
1113 // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1114 // 'label' => ' ', // the final label
1115 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1116 ),
1117 'content' => array(
1118 'align' => 'L',
1119 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1120 ),
1121 );
1122
1123 $rank += 10;
1124 $this->cols['vat'] = array(
1125 'rank' => $rank,
1126 'status' => false,
1127 'width' => 16, // in mm
1128 'title' => array(
1129 'textkey' => 'VAT'
1130 ),
1131 'border-left' => true, // add left line separator
1132 );
1133
1134 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) {
1135 $this->cols['vat']['status'] = true;
1136 }
1137
1138 $rank += 10;
1139 $this->cols['subprice'] = array(
1140 'rank' => $rank,
1141 'width' => 19, // in mm
1142 'status' => true,
1143 'title' => array(
1144 'textkey' => 'PriceUHT'
1145 ),
1146 'border-left' => true, // add left line separator
1147 );
1148
1149 $rank += 10;
1150 $this->cols['qty'] = array(
1151 'rank' => $rank,
1152 'width' => 16, // in mm
1153 'status' => true,
1154 'title' => array(
1155 'textkey' => 'Qty'
1156 ),
1157 'border-left' => true, // add left line separator
1158 );
1159
1160 $rank += 10;
1161 $this->cols['progress'] = array(
1162 'rank' => $rank,
1163 'width' => 19, // in mm
1164 'status' => false,
1165 'title' => array(
1166 'textkey' => 'Progress'
1167 ),
1168 'border-left' => true, // add left line separator
1169 );
1170
1171 if ($this->situationinvoice) {
1172 $this->cols['progress']['status'] = true;
1173 }
1174
1175 $rank += 10;
1176 $this->cols['unit'] = array(
1177 'rank' => $rank,
1178 'width' => 11, // in mm
1179 'status' => false,
1180 'title' => array(
1181 'textkey' => 'Unit'
1182 ),
1183 'border-left' => true, // add left line separator
1184 );
1185 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1186 $this->cols['unit']['status'] = true;
1187 }
1188
1189 $rank += 10;
1190 $this->cols['discount'] = array(
1191 'rank' => $rank,
1192 'width' => 13, // in mm
1193 'status' => false,
1194 'title' => array(
1195 'textkey' => 'ReductionShort'
1196 ),
1197 'border-left' => true, // add left line separator
1198 );
1199 if ($this->atleastonediscount) {
1200 $this->cols['discount']['status'] = true;
1201 }
1202
1203 $rank += 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
1204 $this->cols['totalexcltax'] = array(
1205 'rank' => $rank,
1206 'width' => 26, // in mm
1207 'status' => true,
1208 'title' => array(
1209 'textkey' => 'TotalHT'
1210 ),
1211 'border-left' => true, // add left line separator
1212 );
1213
1214 // Add extrafields cols
1215 if (!empty($object->lines)) {
1216 $line = reset($object->lines);
1217 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
1218 }
1219
1220 $parameters = array(
1221 'object' => $object,
1222 'outputlangs' => $outputlangs,
1223 'hidedetails' => $hidedetails,
1224 'hidedesc' => $hidedesc,
1225 'hideref' => $hideref
1226 );
1227
1228 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
1229 if ($reshook < 0) {
1230 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1231 } elseif (empty($reshook)) {
1232 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
1233 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1234 } else {
1235 $this->cols = $hookmanager->resArray;
1236 }
1237 }
1238}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
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.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
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:1031
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:733
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
Definition pdf.lib.php:1409
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
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:2139
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:769
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:390
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:789
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:150
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:153