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
74
80 public function __construct($db)
81 {
82 global $langs, $mysoc;
83
84 $this->db = $db;
85 $this->name = 'helios';
86 $this->description = $langs->trans("DocumentModelStandardPDF");
87 $this->update_main_doc_field = 1;
88
89 // Page size for A4 format
90 $this->type = 'pdf';
91 $formatarray = pdf_getFormat();
92 $this->page_largeur = $formatarray['width'];
93 $this->page_hauteur = $formatarray['height'];
94 $this->format = array($this->page_largeur, $this->page_hauteur);
95 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
96 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
97 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
98 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
99 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
100 $this->option_logo = 1; // Display logo
101 $this->option_tva = 0;
102 $this->option_modereg = 0;
103 $this->option_condreg = 0;
104 $this->option_multilang = 1; // Available in several languages
105 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
106 $this->watermark = '';
107
108 $this->tabTitleHeight = 5; // default height
109
110 // Define position of columns
111 $this->posxdesc = $this->marge_gauche + 1;
112
113 if ($mysoc === null) {
114 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'.getCallerInfoString(), LOG_ERR);
115 return;
116 }
117
118 // Get source company
119 $this->emetteur = $mysoc;
120 if (empty($this->emetteur->country_code)) {
121 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if not defined
122 }
123 }
124
125 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
137 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
138 {
139 // phpcs:enable
140 global $user, $langs, $conf, $mysoc, $hookmanager;
141
142 if (!is_object($outputlangs)) {
143 $outputlangs = $langs;
144 }
145 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
146 if (getDolGlobalString('MAIN_USE_FPDF')) {
147 $outputlangs->charset_output = 'ISO-8859-1';
148 }
149
150 // Load traductions files required by page
151 $outputlangs->loadLangs(array("main", "interventions", "dict", "companies", "compta"));
152
153 // Show Draft Watermark
154 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FICHINTER_DRAFT_WATERMARK'))) {
155 $this->watermark = getDolGlobalString('FICHINTER_DRAFT_WATERMARK');
156 }
157
158 if ($conf->ficheinter->dir_output) {
159 $object->fetch_thirdparty();
160
161 // Definition of $dir and $file
162 if ($object->specimen) {
163 $dir = $conf->ficheinter->dir_output;
164 $file = $dir."/SPECIMEN.pdf";
165 } else {
166 $objectref = dol_sanitizeFileName($object->ref);
167 $dir = $conf->ficheinter->dir_output."/".$objectref;
168 $file = $dir."/".$objectref.".pdf";
169 }
170
171 if (!file_exists($dir)) {
172 if (dol_mkdir($dir) < 0) {
173 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
174 return 0;
175 }
176 }
177
178 if (file_exists($dir)) {
179 // Add pdfgeneration hook
180 if (!is_object($hookmanager)) {
181 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
182 $hookmanager = new HookManager($this->db);
183 }
184 $hookmanager->initHooks(array('pdfgeneration'));
185 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
186 global $action;
187 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
188
189 $nblines = is_array($object->lines) ? count($object->lines) : 0;
190
191 // Create pdf instance
192 $pdf = pdf_getInstance($this->format);
193 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
194 $heightforinfotot = 40; // Height reserved to output the total line + the name/signature boxes
195 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
196 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
197 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
198 $heightforfooter += 6;
199 }
200 $pdf->setAutoPageBreak(true, 0);
201
202 if (class_exists('TCPDF')) {
203 $pdf->setPrintHeader(false);
204 $pdf->setPrintFooter(false);
205 }
206 $pdf->SetFont(pdf_getPDFFont($outputlangs));
207 // Set path to the background PDF File
208 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
209 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
210 $tplidx = $pdf->importPage(1);
211 }
212
213 $pdf->Open();
214 $pagenb = 0;
215 $pdf->SetDrawColor(128, 128, 128);
216
217 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
218 $pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
219 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
220 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
221 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard"));
222 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
223 $pdf->SetCompression(false);
224 }
225
226 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
227 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
228
229 // New page
230 $pdf->AddPage();
231 if (!empty($tplidx)) {
232 $pdf->useTemplate($tplidx);
233 }
234 $pagenb++;
235 $this->_pagehead($pdf, $object, 1, $outputlangs);
236 $pdf->SetFont('', '', $default_font_size - 1);
237 $pdf->SetTextColor(0, 0, 0);
238
239 $tab_top = 80 + $this->marge_haute;
240 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
241
242 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
243
244 // Display notes
245 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
246 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
247 if (!empty($extranote)) {
248 $notetoshow = dol_concatdesc($notetoshow, $extranote);
249 }
250 if ($notetoshow) {
251 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
252 complete_substitutions_array($substitutionarray, $outputlangs, $object);
253 $notetoshow = make_substitutions((string) $notetoshow, $substitutionarray, $outputlangs);
254 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
255
256 $tab_top -= 2;
257
258 $pdf->SetFont('', '', $default_font_size - 1);
259 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
260 $nexY = $pdf->GetY();
261 $height_note = $nexY - $tab_top;
262
263 // Rect takes a length in 3rd parameter
264 $pdf->SetDrawColor(192, 192, 192);
265 $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');
266
267 $tab_height -= $height_note;
268 $tab_top = $nexY + 6;
269 } else {
270 $height_note = 0;
271 }
272
273 // Use new auto column system
274 $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
275
276 // Table simulation to know the height of the title line
277 $pdf->startTransaction();
278 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs);
279 $pdf->rollbackTransaction(true);
280
281 $nexY = $tab_top + $this->tabTitleHeight;
282
283 // Loop on each lines
284 $pageposbeforeprintlines = $pdf->getPage();
285 $pagenb = $pageposbeforeprintlines;
286 for ($i = 0; $i < $nblines; $i++) {
287 $objectligne = $object->lines[$i];
288
289 $curY = $nexY;
290
291 $issubtotalline = (defined('SUBTOTALS_SPECIAL_CODE') && $objectligne->special_code == SUBTOTALS_SPECIAL_CODE);
292 $sub_options = is_array($objectligne->extraparams) ? ($objectligne->extraparams["subtotal"] ?? array()) : array();
293
294 // Fichinter::fetch_lines() already stores the subtotal depth in ->qty, but be defensive if the
295 // line was built elsewhere: for fichinter the depth lives in the duree/duration field.
296 if ($issubtotalline && empty($objectligne->qty)) {
297 $objectligne->qty = (int) $objectligne->duration;
298 }
299
300 if (($curY + 6) > ($this->page_hauteur - $heightforfooter)
301 || (isset($sub_options['titleforcepagebreak']) && !($pdf->getNumPages() == 1 && $curY == $tab_top + $this->tabTitleHeight))) {
302 $pdf->AddPage();
303 if (!empty($tplidx)) {
304 $pdf->useTemplate($tplidx);
305 }
306 $pdf->setPage($pdf->getNumPages());
307 $nexY = $curY = $tab_top_newpage;
308 }
309
310 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
311 $pdf->SetTextColor(0, 0, 0);
312
313 $pdf->setTopMargin($tab_top_newpage);
314 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
315 $pageposbefore = $pdf->getPage();
316
317 // Description of line
318 if ($this->getColumnStatus('desc')) {
319 if ($issubtotalline) {
320 $bg_color = colorStringToArray(getDolGlobalString("SUBTOTAL_BACK_COLOR_LEVEL_".abs((int) $objectligne->qty), 'ffffff'));
321 pdf_render_subtotals($pdf, $this, $curY, $object, $i, $outputlangs, $hideref, $hidedesc, $bg_color, true, true);
322 } else {
323 $pdf->startTransaction();
324
325 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
326
327 $pageposafter = $pdf->getPage();
328 if ($pageposafter > $pageposbefore) { // There is a pagebreak
329 $pdf->rollbackTransaction(true);
330
331 $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
332
333 $pageposafter = $pdf->getPage();
334 $posyafter = $pdf->GetY();
335 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
336 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
337 $pdf->AddPage('', '', true);
338 if (!empty($tplidx)) {
339 $pdf->useTemplate($tplidx);
340 }
341 $pdf->setPage($pageposafter + 1);
342 }
343 }
344 } else { // No pagebreak
345 $pdf->commitTransaction();
346 }
347 }
348 }
349
350 $nexY = $pdf->GetY();
351 $pageposafter = $pdf->getPage();
352
353 $pdf->setPage($pageposbefore);
354 $pdf->setTopMargin($this->marge_haute);
355 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
356
357 // We suppose that a too long description is moved completely on next page
358 if ($pageposafter > $pageposbefore) {
359 $pdf->setPage($pageposafter);
360 $curY = $tab_top_newpage;
361 }
362
363 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
364
365 // # of line
366 if ($this->getColumnStatus('position')) {
367 $this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
368 }
369
370 // Date and duration are not printed for the subtotals module lines
371 if (!$issubtotalline) {
372 if ($this->getColumnStatus('date')) {
373 $dateformat = getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR') ? 'day' : 'dayhour';
374 $this->printStdColumnContent($pdf, $curY, 'date', dol_print_date($objectligne->datei, $dateformat, false, $outputlangs, true));
375 }
376 if ($this->getColumnStatus('duration') && $objectligne->duration > 0) {
377 $this->printStdColumnContent($pdf, $curY, 'duration', convertSecondToTime((int) $objectligne->duration));
378 }
379
380 // Extrafields
381 if (!empty($objectligne->array_options)) {
382 foreach ($objectligne->array_options as $extrafieldColKey => $extrafieldValue) {
383 if ($this->getColumnStatus($extrafieldColKey)) {
384 $extrafieldValue = $this->getExtrafieldContent($objectligne, $extrafieldColKey, $outputlangs);
385 $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
386 }
387 }
388 }
389 }
390
391 $parameters = array(
392 'object' => $object,
393 'i' => $i,
394 'pdf' => & $pdf,
395 'curY' => & $curY,
396 'nexY' => & $nexY,
397 'outputlangs' => $outputlangs,
398 'hidedetails' => $hidedetails
399 );
400 $hookmanager->executeHooks('printPDFline', $parameters, $this);
401
402 // Add a line separator between lines
403 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
404 $pdf->setPage($pageposafter);
405 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
406 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
407 $pdf->SetLineStyle(array('dash' => 0));
408 }
409
410 // Detect if some page were added automatically and output _tableau for past pages
411 while ($pagenb < $pageposafter) {
412 $pdf->setPage($pagenb);
413 if ($pagenb == $pageposbeforeprintlines) {
414 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
415 } else {
416 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
417 }
418 $this->_pagefoot($pdf, $object, $outputlangs, 1);
419 $pagenb++;
420 $pdf->setPage($pagenb);
421 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
422 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
423 $this->_pagehead($pdf, $object, 0, $outputlangs);
424 }
425 if (!empty($tplidx)) {
426 $pdf->useTemplate($tplidx);
427 }
428 }
429 }
430
431 // Show square
432 if ($pagenb == $pageposbeforeprintlines) {
433 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
434 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
435 } else {
436 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
437 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
438 }
439
440 // Display total area (total duration of the intervention)
441 $this->_tableau_tot($pdf, $object, $bottomlasttab, $outputlangs);
442
443 // Signatures + Pagefoot
444 $this->_tableau_signature($pdf, $object, $bottomlasttab + 6, $outputlangs);
445
446 $this->_pagefoot($pdf, $object, $outputlangs);
447 if (method_exists($pdf, 'AliasNbPages')) {
448 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
449 }
450
451 $pdf->Close();
452 $pdf->Output($file, 'F');
453
454 // Add pdfgeneration hook
455 $hookmanager->initHooks(array('pdfgeneration'));
456 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
457 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
458 $this->warnings = $hookmanager->warnings;
459 if ($reshook < 0) {
460 $this->error = $hookmanager->error;
461 $this->errors = $hookmanager->errors;
462 dolChmod($file);
463 return -1;
464 }
465
466 dolChmod($file);
467
468 $this->result = array('fullpath' => $file);
469
470 return 1;
471 } else {
472 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
473 return 0;
474 }
475 } else {
476 $this->error = $langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR");
477 return 0;
478 }
479 }
480
481 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
482 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
492 protected function _tableau_tot(&$pdf, $object, $posy, $outputlangs)
493 {
494 // phpcs:enable
495 global $conf;
496
497 $default_font_size = pdf_getPDFFontSize($outputlangs);
498 $pdf->SetFont('', 'B', $default_font_size - 1);
499 $pdf->SetTextColor(0, 0, 0);
500
501 if ($this->getColumnStatus('desc')) {
502 $this->printStdColumnContent($pdf, $posy, 'desc', $outputlangs->transnoentities("TotalDuration"));
503 }
504 if ($this->getColumnStatus('duration') && !empty($object->duration)) {
505 $totaltime = convertSecondToTime((int) $object->duration, 'all', getDolGlobalInt('MAIN_DURATION_OF_WORKDAY', 28800));
506 $this->printStdColumnContent($pdf, $posy, 'duration', $totaltime);
507 }
508
509 $pdf->SetFont('', '', $default_font_size - 1);
510
511 return $posy + 4;
512 }
513
514 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
515 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
525 protected function _tableau_signature(&$pdf, $object, $posy, $outputlangs)
526 {
527 // phpcs:enable
528 $default_font_size = pdf_getPDFFontSize($outputlangs);
529 $pdf->SetFont('', '', $default_font_size - 1);
530 $pdf->SetTextColor(0, 0, 0);
531
532 $employee_name = '';
533 $arrayidcontact = $object->getIdContact('internal', 'INTERVENING');
534 if (count($arrayidcontact) > 0) {
535 $object->fetch_user($arrayidcontact[0]);
536 $employee_name = $object->user->getFullName($outputlangs);
537 }
538
539 $boxwidth = ($this->page_largeur - $this->marge_gauche - $this->marge_droite - 10) / 2;
540
541 $pdf->SetXY($this->marge_gauche, $posy);
542 $pdf->MultiCell($boxwidth, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', false);
543 $pdf->SetXY($this->marge_gauche, $posy + 5);
544 $pdf->MultiCell($boxwidth, 20, $employee_name, 1, 'L');
545
546 $pdf->SetXY($this->marge_gauche + $boxwidth + 10, $posy);
547 $pdf->MultiCell($boxwidth, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', false);
548 $pdf->SetXY($this->marge_gauche + $boxwidth + 10, $posy + 5);
549 $pdf->MultiCell($boxwidth, 20, '', 1);
550 }
551
552 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
565 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
566 {
567 global $conf;
568
569 // Force to disable hidetop and hidebottom
570 $hidebottom = 0;
571 if ($hidetop) {
572 $hidetop = -1;
573 }
574
575 $default_font_size = pdf_getPDFFontSize($outputlangs);
576
577 $pdf->SetTextColor(0, 0, 0);
578 $pdf->SetFont('', '', $default_font_size - 2);
579
580 if (empty($hidetop) && getDolGlobalString('MAIN_PDF_TITLE_BACKGROUND_COLOR')) {
581 $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')));
582 }
583
584 $pdf->SetDrawColor(128, 128, 128);
585 $pdf->SetFont('', '', $default_font_size - 1);
586
587 // Output Rect
588 $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');
589
590 $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
591
592 if (empty($hidetop)) {
593 $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight);
594 }
595 }
596
597 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
607 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
608 {
609 global $conf, $langs;
610
611 $default_font_size = pdf_getPDFFontSize($outputlangs);
612
613 // Load traductions files required by page
614 $outputlangs->loadLangs(array("main", "dict", "companies", "interventions"));
615
616 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
617
618 $pdf->SetTextColor(0, 0, 60);
619 $pdf->SetFont('', 'B', $default_font_size + 3);
620
621 $posx = $this->page_largeur - $this->marge_droite - 100;
622 $posy = $this->marge_haute;
623
624 $pdf->SetXY($this->marge_gauche, $posy);
625
626 // Logo
627 $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
628 if ($this->emetteur->logo) {
629 if (is_readable($logo)) {
630 $height = pdf_getHeightForLogo($logo);
631 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
632 } else {
633 $pdf->SetTextColor(200, 0, 0);
634 $pdf->SetFont('', 'B', $default_font_size - 2);
635 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
636 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
637 }
638 } else {
639 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
640 }
641
642 $pdf->SetFont('', 'B', $default_font_size + 3);
643 $pdf->SetXY($posx, $posy);
644 $pdf->SetTextColor(0, 0, 60);
645 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("InterventionCard"), '', 'R');
646
647 $pdf->SetFont('', 'B', $default_font_size + 2);
648
649 $posy += 5;
650 $pdf->SetXY($posx, $posy);
651 $pdf->SetTextColor(0, 0, 60);
652 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
653
654 $posy += 1;
655 $pdf->SetFont('', '', $default_font_size);
656
657 $posy += 4;
658 $pdf->SetXY($posx, $posy);
659 $pdf->SetTextColor(0, 0, 60);
660 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->datec, "day", false, $outputlangs, true), '', 'R');
661
662 if (!empty($object->ref_client)) {
663 $posy += 4;
664 $pdf->SetXY($posx, $posy);
665 $pdf->SetTextColor(0, 0, 60);
666 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : ".pdf_truncate_text($pdf, $outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
667 }
668
669 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
670 $posy += 4;
671 $pdf->SetXY($posx, $posy);
672 $pdf->SetTextColor(0, 0, 60);
673 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
674 }
675
676 if ($showaddress) {
677 // Sender properties
678 $carac_emetteur = '';
679 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
680 if (count($arrayidcontact) > 0) {
681 $object->fetch_user($arrayidcontact[0]);
682 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
683 $carac_emetteur .= $labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
684 }
685
686 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
687
688 // Show sender
689 $posy = 32 + $this->marge_haute;
690 $posx = $this->marge_gauche;
691 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
692 $posx = $this->page_largeur - $this->marge_droite - 80;
693 }
694 $hautcadre = 40;
695
696 // Show sender frame
697 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
698 $pdf->SetTextColor(0, 0, 0);
699 $pdf->SetFont('', '', $default_font_size - 2);
700 $pdf->SetXY($posx, $posy);
701 $pdf->SetFillColor(230, 230, 230);
702 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
703 }
704
705 // Show sender name
706 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
707 $pdf->SetXY($posx + 2, $posy + 3);
708 $pdf->SetTextColor(0, 0, 60);
709 $pdf->SetFont('', 'B', $default_font_size);
710 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
711 $posy = $pdf->getY();
712 }
713
714 // Show sender information
715 $pdf->SetFont('', '', $default_font_size - 1);
716 $pdf->SetXY($posx + 2, $posy);
717 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
718
719 // If CUSTOMER contact defined, we use it
720 $usecontact = false;
721 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
722 if (count($arrayidcontact) > 0) {
723 $usecontact = true;
724 $result = $object->fetch_contact($arrayidcontact[0]);
725 }
726
727 // Recipient name
728 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
729 $thirdparty = $object->contact;
730 } else {
731 $thirdparty = $object->thirdparty;
732 }
733
734 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
735
736 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), ($usecontact ? 1 : 0), 'target', $object);
737
738 // Show recipient
739 $widthrecbox = 100;
740 if ($this->page_largeur < 210) {
741 $widthrecbox = 84; // To work with US executive format
742 }
743 $posy = 32 + $this->marge_haute;
744 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
745 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
746 $posx = $this->marge_gauche;
747 }
748
749 // Show recipient frame
750 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
751 $pdf->SetTextColor(0, 0, 0);
752 $pdf->SetFont('', '', $default_font_size - 2);
753 $pdf->SetXY($posx + 2, $posy - 5);
754 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
755 $pdf->SetTextColor(0, 0, 0);
756 }
757
758 // Show recipient name
759 $pdf->SetXY($posx + 2, $posy + 3);
760 $pdf->SetFont('', 'B', $default_font_size);
761 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
762
763 $posy = $pdf->getY();
764
765 // Show recipient information
766 $pdf->SetFont('', '', $default_font_size - 1);
767 $pdf->SetXY($posx + 2, $posy);
768 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
769 }
770
771 return 0;
772 }
773
774 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
784 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
785 {
786 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
787 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);
788 }
789
790 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
801 public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
802 {
803 // phpcs:enable
804 global $hookmanager;
805
806 // Default field style for content
807 $this->defaultContentsFieldsStyle = array(
808 'align' => 'R', // R,C,L
809 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
810 );
811
812 // Default field style for title
813 $this->defaultTitlesFieldsStyle = array(
814 'align' => 'C', // R,C,L
815 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
816 );
817
818 $rank = 0; // do not use negative rank
819 $this->cols['position'] = array(
820 'rank' => $rank,
821 'width' => 10,
822 'status' => getDolGlobalInt('PDF_ADD_POSITION') ? true : false,
823 'title' => array(
824 'textkey' => '#',
825 'align' => 'C',
826 'padding' => array(0.5, 0.5, 0.5, 0.5),
827 ),
828 'content' => array(
829 'align' => 'C',
830 'padding' => array(1, 0.5, 1, 1.5),
831 ),
832 );
833
834 $rank += 10;
835 $this->cols['desc'] = array(
836 'rank' => $rank,
837 'width' => false, // only for desc
838 'status' => true,
839 'title' => array(
840 'textkey' => 'Designation',
841 'align' => 'L',
842 'padding' => array(0.5, 0.5, 0.5, 0.5),
843 ),
844 'content' => array(
845 'align' => 'L',
846 'padding' => array(1, 0.5, 1, 1.5),
847 ),
848 );
849
850 $rank += 10;
851 $this->cols['date'] = array(
852 'rank' => $rank,
853 'width' => 40, // in mm
854 'status' => true,
855 'title' => array(
856 'textkey' => 'Date',
857 ),
858 'border-left' => true,
859 'content' => array(
860 'align' => 'C',
861 ),
862 );
863
864 $rank += 10;
865 $this->cols['duration'] = array(
866 'rank' => $rank,
867 'width' => 25, // in mm
868 'status' => true,
869 'title' => array(
870 'textkey' => 'Duration',
871 ),
872 'border-left' => true,
873 'content' => array(
874 'align' => 'C',
875 ),
876 );
877
878 // Add extrafields cols
879 if (!empty($object->lines)) {
880 $line = reset($object->lines);
881 $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
882 }
883
884 $parameters = array(
885 'object' => $object,
886 'outputlangs' => $outputlangs,
887 'hidedetails' => $hidedetails,
888 'hidedesc' => $hidedesc,
889 'hideref' => $hideref
890 );
891
892 $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
893 if ($reshook < 0) {
894 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
895 } elseif (empty($reshook)) {
896 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
897 $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
898 } else {
899 $this->cols = $hookmanager->resArray;
900 }
901 }
902}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:280
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:253
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
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:1466
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:3365
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:3437
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:140