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