dolibarr 25.0.0-alpha
pdf_helios.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * or see https://www.gnu.org/
21 */
22
28require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33
34
43{
47 public $db;
48
52 public $name;
53
57 public $description;
58
62 public $update_main_doc_field;
63
67 public $type;
68
72 public $version = 'dolibarr';
73
77 public $position = 60;
78
79
85 public function __construct($db)
86 {
87 global $langs, $mysoc;
88
89 $this->db = $db;
90 $this->name = 'helios';
91 $this->description = $langs->trans("DocumentModelStandardPDF");
92 $this->update_main_doc_field = 1;
93
94 // Page size for A4 format
95 $this->type = 'pdf';
96 $formatarray = pdf_getFormat();
97 $this->page_largeur = $formatarray['width'];
98 $this->page_hauteur = $formatarray['height'];
99 $this->format = array($this->page_largeur, $this->page_hauteur);
100 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
101 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
102 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
103 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
104 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
105 $this->option_logo = 1; // Display logo
106 $this->option_tva = 0;
107 $this->option_modereg = 0;
108 $this->option_condreg = 0;
109 $this->option_multilang = 1; // Available in several languages
110 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
111 $this->watermark = '';
112
113 $this->tabTitleHeight = 5; // default height
114
115 // Define position of columns
116 $this->posxdesc = $this->marge_gauche + 1;
117
118 if ($mysoc === null) {
119 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'.getCallerInfoString(), LOG_ERR);
120 return;
121 }
122
123 // Get source company
124 $this->emetteur = $mysoc;
125 if (empty($this->emetteur->country_code)) {
126 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if not defined
127 }
128 }
129
130 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
142 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
143 {
144 // phpcs:enable
145 global $user, $langs, $conf, $mysoc, $hookmanager;
146
147 if (!is_object($outputlangs)) {
148 $outputlangs = $langs;
149 }
150 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
151 if (getDolGlobalString('MAIN_USE_FPDF')) {
152 $outputlangs->charset_output = 'ISO-8859-1';
153 }
154
155 // Load traductions files required by page
156 $outputlangs->loadLangs(array("main", "interventions", "dict", "companies", "compta"));
157
158 // Show Draft Watermark
159 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FICHINTER_DRAFT_WATERMARK'))) {
160 $this->watermark = getDolGlobalString('FICHINTER_DRAFT_WATERMARK');
161 }
162
163 if ($conf->ficheinter->dir_output) {
164 $object->fetch_thirdparty();
165
166 // Definition of $dir and $file
167 if ($object->specimen) {
168 $dir = $conf->ficheinter->dir_output;
169 $file = $dir."/SPECIMEN.pdf";
170 } else {
171 $objectref = dol_sanitizeFileName($object->ref);
172 $dir = $conf->ficheinter->dir_output."/".$objectref;
173 $file = $dir."/".$objectref.".pdf";
174 }
175
176 if (!file_exists($dir)) {
177 if (dol_mkdir($dir) < 0) {
178 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
179 return 0;
180 }
181 }
182
183 if (file_exists($dir)) {
184 // Add pdfgeneration hook
185 if (!is_object($hookmanager)) {
186 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
187 $hookmanager = new HookManager($this->db);
188 }
189 $hookmanager->initHooks(array('pdfgeneration'));
190 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
191 global $action;
192 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
193
194 $nblines = is_array($object->lines) ? count($object->lines) : 0;
195
196 // Create pdf instance
197 $pdf = pdf_getInstance($this->format);
198 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
199 $heightforinfotot = 40; // Height reserved to output the total line + the name/signature boxes
200 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
201 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
202 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
203 $heightforfooter += 6;
204 }
205 $pdf->setAutoPageBreak(true, 0);
206
207 if (class_exists('TCPDF')) {
208 $pdf->setPrintHeader(false);
209 $pdf->setPrintFooter(false);
210 }
211 $pdf->SetFont(pdf_getPDFFont($outputlangs));
212 // Set path to the background PDF File
213 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
214 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
215 $tplidx = $pdf->importPage(1);
216 }
217
218 $pdf->Open();
219 $pagenb = 0;
220 $pdf->SetDrawColor(128, 128, 128);
221
222 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
223 $pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
224 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
225 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
226 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard"));
227 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
228 $pdf->SetCompression(false);
229 }
230
231 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
232 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
233
234 // New page
235 $pdf->AddPage();
236 if (!empty($tplidx)) {
237 $pdf->useTemplate($tplidx);
238 }
239 $pagenb++;
240 $this->_pagehead($pdf, $object, 1, $outputlangs);
241 $pdf->SetFont('', '', $default_font_size - 1);
242 $pdf->SetTextColor(0, 0, 0);
243
244 $tab_top = 80 + $this->marge_haute;
245 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
246
247 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
248
249 // Display notes
250 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
251 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
252 if (!empty($extranote)) {
253 $notetoshow = dol_concatdesc($notetoshow, $extranote);
254 }
255 if ($notetoshow) {
256 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
257 complete_substitutions_array($substitutionarray, $outputlangs, $object);
258 $notetoshow = make_substitutions((string) $notetoshow, $substitutionarray, $outputlangs);
259 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
260
261 $tab_top -= 2;
262
263 $pdf->SetFont('', '', $default_font_size - 1);
264 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
265 $nexY = $pdf->GetY();
266 $height_note = $nexY - $tab_top;
267
268 // Rect takes a length in 3rd parameter
269 $pdf->SetDrawColor(192, 192, 192);
270 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius, '1234', 'D');
271
272 $tab_height -= $height_note;
273 $tab_top = $nexY + 6;
274 } else {
275 $height_note = 0;
276 }
277
278 // Use new auto column system
279 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
280
281 // Table simulation to know the height of the title line
282 $pdf->startTransaction();
283 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
284 $pdf->rollbackTransaction(true);
285
286 $nexY = $tab_top + $this->tabTitleHeight;
287
288 // Loop on each lines
289 $pageposbeforeprintlines = $pdf->getPage();
290 $pagenb = $pageposbeforeprintlines;
291 for ($i = 0; $i < $nblines; $i++) {
292 $objectligne = $object->lines[$i];
293
294 $curY = $nexY;
295
296 $issubtotalline = (defined('SUBTOTALS_SPECIAL_CODE') && $objectligne->special_code == SUBTOTALS_SPECIAL_CODE);
297 $sub_options = is_array($objectligne->extraparams) ? ($objectligne->extraparams["subtotal"] ?? array()) : array();
298
299 // Fichinter::fetch_lines() already stores the subtotal depth in ->qty, but be defensive if the
300 // line was built elsewhere: for fichinter the depth lives in the duree/duration field.
301 if ($issubtotalline && empty($objectligne->qty)) {
302 $objectligne->qty = (int) $objectligne->duration;
303 }
304
305 if (($curY + 6) > ($this->page_hauteur - $heightforfooter)
306 || (isset($sub_options['titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight))) {
307 $pdf->AddPage();
308 if (!empty($tplidx)) {
309 $pdf->useTemplate($tplidx);
310 }
311 $pdf->setPage($pdf->getNumPages());
312 $nexY = $curY = $tab_top_newpage;
313 }
314
315 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
316 $pdf->SetTextColor(0, 0, 0);
317
318 $pdf->setTopMargin($tab_top_newpage);
319 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
320 $pageposbefore = $pdf->getPage();
321
322 // Description of line
323 if ($this->getColumnStatus('desc')) {
324 if ($issubtotalline) {
325 $bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs((int) $objectligne->qty), 'ffffff'));
326 pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
327 } else {
328 $pdf->startTransaction();
329
330 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
331
332 $pageposafter = $pdf->getPage();
333 if ($pageposafter > $pageposbefore) { // There is a pagebreak
334 $pdf->rollbackTransaction(true);
335
336 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
337
338 $pageposafter = $pdf->getPage();
339 $posyafter = $pdf->GetY();
340 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
341 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
342 $pdf->AddPage('', '', true);
343 if (!empty($tplidx)) {
344 $pdf->useTemplate($tplidx);
345 }
346 $pdf->setPage($pageposafter + 1);
347 }
348 }
349 } else { // No pagebreak
350 $pdf->commitTransaction();
351 }
352 }
353 }
354
355 $nexY = $pdf->GetY();
356 $pageposafter = $pdf->getPage();
357
358 $pdf->setPage($pageposbefore);
359 $pdf->setTopMargin($this->marge_haute);
360 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
361
362 // We suppose that a too long description is moved completely on next page
363 if ($pageposafter > $pageposbefore) {
364 $pdf->setPage($pageposafter);
365 $curY = $tab_top_newpage;
366 }
367
368 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
369
370 // # of line
371 if ($this->getColumnStatus('position')) {
372 $this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
373 }
374
375 // Date and duration are not printed for the subtotals module lines
376 if (!$issubtotalline) {
377 if ($this->getColumnStatus('date')) {
378 $dateformat = getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR') ? 'day' : 'dayhour';
379 $this->printStdColumnContent($pdf, $curY, 'date', dol_print_date($objectligne->datei, $dateformat, false, $outputlangs, true));
380 }
381 if ($this->getColumnStatus('duration') && $objectligne->duration > 0) {
382 $this->printStdColumnContent($pdf, $curY, 'duration', convertSecondToTime((int) $objectligne->duration));
383 }
384
385 // Extrafields
386 if (!empty($objectligne->array_options)) {
387 foreach ($objectligne->array_options as $extrafieldColKey => $extrafieldValue) {
388 if ($this->getColumnStatus($extrafieldColKey)) {
389 $extrafieldValue = $this->getExtrafieldContent($objectligne, $extrafieldColKey, $outputlangs);
390 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
391 }
392 }
393 }
394 }
395
396 $parameters = array(
397 'object' => $object,
398 'i' => $i,
399 'pdf' => & $pdf,
400 'curY' => & $curY,
401 'nexY' => & $nexY,
402 'outputlangs' => $outputlangs,
403 'hidedetails' => $hidedetails
404 );
405 $hookmanager->executeHooks('printPDFline', $parameters, $this);
406
407 // Add a line separator between lines
408 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
409 $pdf->setPage($pageposafter);
410 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
411 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
412 $pdf->SetLineStyle(array('dash' => 0));
413 }
414
415 // Detect if some page were added automatically and output _tableau for past pages
416 while ($pagenb < $pageposafter) {
417 $pdf->setPage($pagenb);
418 if ($pagenb == $pageposbeforeprintlines) {
419 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
420 } else {
421 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
422 }
423 $this->_pagefoot($pdf, $object, $outputlangs, 1);
424 $pagenb++;
425 $pdf->setPage($pagenb);
426 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
427 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
428 $this->_pagehead($pdf, $object, 0, $outputlangs);
429 }
430 if (!empty($tplidx)) {
431 $pdf->useTemplate($tplidx);
432 }
433 }
434 }
435
436 // Show square
437 if ($pagenb == $pageposbeforeprintlines) {
438 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
439 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
440 } else {
441 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
442 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
443 }
444
445 // Display total area (total duration of the intervention)
446 $this->_tableau_tot($pdf, $object, $bottomlasttab, $outputlangs);
447
448 // Signatures + Pagefoot
449 $this->_tableau_signature($pdf, $object, $bottomlasttab + 6, $outputlangs);
450
451 $this->_pagefoot($pdf, $object, $outputlangs);
452 if (method_exists($pdf, 'AliasNbPages')) {
453 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
454 }
455
456 $pdf->Close();
457 $pdf->Output($file, 'F');
458
459 // Add pdfgeneration hook
460 $hookmanager->initHooks(array('pdfgeneration'));
461 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
462 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
463 $this->warnings = $hookmanager->warnings;
464 if ($reshook < 0) {
465 $this->error = $hookmanager->error;
466 $this->errors = $hookmanager->errors;
467 dolChmod($file);
468 return -1;
469 }
470
471 dolChmod($file);
472
473 $this->result = array('fullpath' => $file);
474
475 return 1;
476 } else {
477 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
478 return 0;
479 }
480 } else {
481 $this->error = $langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR");
482 return 0;
483 }
484 }
485
486 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
487 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
497 protected function _tableau_tot(&$pdf, $object, $posy, $outputlangs)
498 {
499 // phpcs:enable
500 global $conf;
501
502 $default_font_size = pdf_getPDFFontSize($outputlangs);
503 $pdf->SetFont('', 'B', $default_font_size - 1);
504 $pdf->SetTextColor(0, 0, 0);
505
506 if ($this->getColumnStatus('desc')) {
507 $this->printStdColumnContent($pdf, $posy, 'desc', $outputlangs->transnoentities("TotalDuration"));
508 }
509 if ($this->getColumnStatus('duration') && !empty($object->duration)) {
510 $totaltime = convertSecondToTime((int) $object->duration, 'all', getDolGlobalInt('MAIN_DURATION_OF_WORKDAY', 28800));
511 $this->printStdColumnContent($pdf, $posy, 'duration', $totaltime);
512 }
513
514 $pdf->SetFont('', '', $default_font_size - 1);
515
516 return $posy + 4;
517 }
518
519 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
520 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
530 protected function _tableau_signature(&$pdf, $object, $posy, $outputlangs)
531 {
532 // phpcs:enable
533 $default_font_size = pdf_getPDFFontSize($outputlangs);
534 $pdf->SetFont('', '', $default_font_size - 1);
535 $pdf->SetTextColor(0, 0, 0);
536
537 $employee_name = '';
538 $arrayidcontact = $object->getIdContact('internal', 'INTERVENING');
539 if (count($arrayidcontact) > 0) {
540 $object->fetch_user($arrayidcontact[0]);
541 $employee_name = $object->user->getFullName($outputlangs);
542 }
543
544 $boxwidth = ($this->page_largeur - $this->marge_gauche - $this->marge_droite - 10) / 2;
545
546 $pdf->SetXY($this->marge_gauche, $posy);
547 $pdf->MultiCell($boxwidth, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', false);
548 $pdf->SetXY($this->marge_gauche, $posy + 5);
549 $pdf->MultiCell($boxwidth, 20, $employee_name, 1, 'L');
550
551 $pdf->SetXY($this->marge_gauche + $boxwidth + 10, $posy);
552 $pdf->MultiCell($boxwidth, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', false);
553 $pdf->SetXY($this->marge_gauche + $boxwidth + 10, $posy + 5);
554 $pdf->MultiCell($boxwidth, 20, '', 1);
555 }
556
557 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
570 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
571 {
572 global $conf;
573
574 // Force to disable hidetop and hidebottom
575 $hidebottom = 0;
576 if ($hidetop) {
577 $hidetop = -1;
578 }
579
580 $default_font_size = pdf_getPDFFontSize($outputlangs);
581
582 $pdf->SetTextColor(0, 0, 0);
583 $pdf->SetFont('', '', $default_font_size - 2);
584
585 if (empty($hidetop) && getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
586 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, $this->corner_radius, '1001', 'F', array(), explode(',', getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')));
587 }
588
589 $pdf->SetDrawColor(128, 128, 128);
590 $pdf->SetFont('', '', $default_font_size - 1);
591
592 // Output Rect
593 $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');
594
595 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
596
597 if (empty($hidetop)) {
598 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
599 }
600 }
601
602 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
612 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
613 {
614 global $conf, $langs;
615
616 $default_font_size = pdf_getPDFFontSize($outputlangs);
617
618 // Load traductions files required by page
619 $outputlangs->loadLangs(array("main", "dict", "companies", "interventions"));
620
621 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
622
623 $pdf->SetTextColor(0, 0, 60);
624 $pdf->SetFont('', 'B', $default_font_size + 3);
625
626 $posx = $this->page_largeur - $this->marge_droite - 100;
627 $posy = $this->marge_haute;
628
629 $pdf->SetXY($this->marge_gauche, $posy);
630
631 // Logo
632 $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
633 if ($this->emetteur->logo) {
634 if (is_readable($logo)) {
635 $height = pdf_getHeightForLogo($logo);
636 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
637 } else {
638 $pdf->SetTextColor(200, 0, 0);
639 $pdf->SetFont('', 'B', $default_font_size - 2);
640 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
641 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
642 }
643 } else {
644 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
645 }
646
647 $pdf->SetFont('', 'B', $default_font_size + 3);
648 $pdf->SetXY($posx, $posy);
649 $pdf->SetTextColor(0, 0, 60);
650 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("InterventionCard"), '', 'R');
651
652 $pdf->SetFont('', 'B', $default_font_size + 2);
653
654 $posy += 5;
655 $pdf->SetXY($posx, $posy);
656 $pdf->SetTextColor(0, 0, 60);
657 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
658
659 $posy += 1;
660 $pdf->SetFont('', '', $default_font_size);
661
662 $posy += 4;
663 $pdf->SetXY($posx, $posy);
664 $pdf->SetTextColor(0, 0, 60);
665 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->datec, "day", false, $outputlangs, true), '', 'R');
666
667 if (!empty($object->ref_client)) {
668 $posy += 4;
669 $pdf->SetXY($posx, $posy);
670 $pdf->SetTextColor(0, 0, 60);
671 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : ".pdf_truncate_text($pdf, $outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
672 }
673
674 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
675 $posy += 4;
676 $pdf->SetXY($posx, $posy);
677 $pdf->SetTextColor(0, 0, 60);
678 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
679 }
680
681 if ($showaddress) {
682 // Sender properties
683 $carac_emetteur = '';
684 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
685 if (count($arrayidcontact) > 0) {
686 $object->fetch_user($arrayidcontact[0]);
687 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
688 $carac_emetteur .= $labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
689 }
690
691 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
692
693 // Show sender
694 $posy = 32 + $this->marge_haute;
695 $posx = $this->marge_gauche;
696 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
697 $posx = $this->page_largeur - $this->marge_droite - 80;
698 }
699 $hautcadre = 40;
700
701 // Show sender frame
702 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
703 $pdf->SetTextColor(0, 0, 0);
704 $pdf->SetFont('', '', $default_font_size - 2);
705 $pdf->SetXY($posx, $posy);
706 $pdf->SetFillColor(230, 230, 230);
707 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
708 }
709
710 // Show sender name
711 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
712 $pdf->SetXY($posx + 2, $posy + 3);
713 $pdf->SetTextColor(0, 0, 60);
714 $pdf->SetFont('', 'B', $default_font_size);
715 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
716 $posy = $pdf->getY();
717 }
718
719 // Show sender information
720 $pdf->SetFont('', '', $default_font_size - 1);
721 $pdf->SetXY($posx + 2, $posy);
722 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
723
724 // If CUSTOMER contact defined, we use it
725 $usecontact = false;
726 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
727 if (count($arrayidcontact) > 0) {
728 $usecontact = true;
729 $result = $object->fetch_contact($arrayidcontact[0]);
730 }
731
732 // Recipient name
733 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
734 $thirdparty = $object->contact;
735 } else {
736 $thirdparty = $object->thirdparty;
737 }
738
739 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
740
741 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), ($usecontact ? 1 : 0), 'target', $object);
742
743 // Show recipient
744 $widthrecbox = 100;
745 if ($this->page_largeur < 210) {
746 $widthrecbox = 84; // To work with US executive format
747 }
748 $posy = 32 + $this->marge_haute;
749 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
750 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
751 $posx = $this->marge_gauche;
752 }
753
754 // Show recipient frame
755 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
756 $pdf->SetTextColor(0, 0, 0);
757 $pdf->SetFont('', '', $default_font_size - 2);
758 $pdf->SetXY($posx + 2, $posy - 5);
759 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
760 $pdf->SetTextColor(0, 0, 0);
761 }
762
763 // Show recipient name
764 $pdf->SetXY($posx + 2, $posy + 3);
765 $pdf->SetFont('', 'B', $default_font_size);
766 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
767
768 $posy = $pdf->getY();
769
770 // Show recipient information
771 $pdf->SetFont('', '', $default_font_size - 1);
772 $pdf->SetXY($posx + 2, $posy);
773 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
774 }
775
776 return 0;
777 }
778
779 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
789 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
790 {
791 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
792 return pdf_pagefoot($pdf, $outputlangs, 'FICHINTER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
793 }
794
795 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
806 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
807 {
808 // phpcs:enable
809 global $hookmanager;
810
811 // Default field style for content
812 $this->defaultContentsFieldsStyle = array(
813 'align' => 'R', // R,C,L
814 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
815 );
816
817 // Default field style for title
818 $this->defaultTitlesFieldsStyle = array(
819 'align' => 'C', // R,C,L
820 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
821 );
822
823 $rank = 0; // do not use negative rank
824 $this->cols['position'] = array(
825 'rank' => $rank,
826 'width' => 10,
827 'status' => getDolGlobalInt('PDF_ADD_POSITION') ? true : false,
828 'title' => array(
829 'textkey' => '#',
830 'align' => 'C',
831 'padding' => array(0.5, 0.5, 0.5, 0.5),
832 ),
833 'content' => array(
834 'align' => 'C',
835 'padding' => array(1, 0.5, 1, 1.5),
836 ),
837 );
838
839 $rank += 10;
840 $this->cols['desc'] = array(
841 'rank' => $rank,
842 'width' => false, // only for desc
843 'status' => true,
844 'title' => array(
845 'textkey' => 'Designation',
846 'align' => 'L',
847 'padding' => array(0.5, 0.5, 0.5, 0.5),
848 ),
849 'content' => array(
850 'align' => 'L',
851 'padding' => array(1, 0.5, 1, 1.5),
852 ),
853 );
854
855 $rank += 10;
856 $this->cols['date'] = array(
857 'rank' => $rank,
858 'width' => 40, // in mm
859 'status' => true,
860 'title' => array(
861 'textkey' => 'Date',
862 ),
863 'border-left' => true,
864 'content' => array(
865 'align' => 'C',
866 ),
867 );
868
869 $rank += 10;
870 $this->cols['duration'] = array(
871 'rank' => $rank,
872 'width' => 25, // in mm
873 'status' => true,
874 'title' => array(
875 'textkey' => 'Duration',
876 ),
877 'border-left' => true,
878 'content' => array(
879 'align' => 'C',
880 ),
881 );
882
883 // Add extrafields cols
884 if (!empty($object->lines)) {
885 $line = reset($object->lines);
886 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
887 }
888
889 $parameters = array(
890 'object' => $object,
891 'outputlangs' => $outputlangs,
892 'hidedetails' => $hidedetails,
893 'hidedesc' => $hidedesc,
894 'hideref' => $hideref
895 );
896
897 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
898 if ($reshook < 0) {
899 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
900 } elseif (empty($reshook)) {
901 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
902 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
903 } else {
904 $this->cols = $hookmanager->resArray;
905 }
906 }
907}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
prepareArrayColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Prepare Array Column Field.
getColumnStatus($colKey)
get column status from column key
printStdColumnContent($pdf, &$curY, $colKey, $columnText='')
print standard column content
printColDescContent($pdf, &$curY, $colKey, $object, $i, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
print description column content
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 to manage intervention document templates.
Class to build intervention documents with model Helios.
_tableau_tot(&$pdf, $object, $posy, $outputlangs)
Show total line (total duration of the intervention)
__construct($db)
Constructor.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
defineColumnField($object, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Define Array Column Field.
_tableau_signature(&$pdf, $object, $posy, $outputlangs)
Show name / signature boxes for the internal and external contacts.
global $mysoc
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:263
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...
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:296
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:319
pdf_pagehead($pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:792
pdf_pagefoot($pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
Definition pdf.lib.php:1479
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:275
pdf_render_subtotals(TCPDF $pdf, CommonDocGenerator $generator, float $curY, CommonObject $object, int $i, Translate $outputlangs, int $hideref, int $hidedesc, array $bgColor, bool $isSubtotal=false, bool $applySubtotalLogic=true)
Render subtotals line with a colored background and adapted text color .
Definition pdf.lib.php:3395
pdf_truncate_text($pdf, $text, $max_width, $ellipsis_pos=1, $ellipsis="\u{2026}")
Truncates text to fit a specified width in TCPDF, with configurable ellipsis position.
Definition pdf.lib.php:3483
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:481
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1180
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:436
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165