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