dolibarr 25.0.0-alpha
pdf_soleil.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) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
6 * Copyright (C) 2011 Fabrice CHERRIER
7 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024 Nick Fragoulis
12 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 * or see https://www.gnu.org/
27 */
28
34require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
39
40
45{
49 public $db;
50
54 public $name;
55
59 public $description;
60
64 public $update_main_doc_field;
65
69 public $type;
70
75 public $version = 'dolibarr';
76
80 public $position = 50;
81
82
88 public function __construct($db)
89 {
90 global $langs, $mysoc;
91
92 $this->db = $db;
93 $this->name = 'soleil';
94 $this->description = $langs->trans("DocumentModelStandardPDF");
95 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
96
97 // Page size for A4 format
98 $this->type = 'pdf';
99 $formatarray = pdf_getFormat();
100 $this->page_largeur = $formatarray['width'];
101 $this->page_hauteur = $formatarray['height'];
102 $this->format = array($this->page_largeur, $this->page_hauteur);
103 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
104 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
105 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
106 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
107 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
108 $this->option_logo = 1; // Display logo
109 $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
110 $this->option_modereg = 0; // Display payment mode
111 $this->option_condreg = 0; // Display payment terms
112 $this->option_multilang = 1; // Available in several languages
113 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
114 $this->watermark = '';
115
116 // Define position of columns
117 $this->posxdesc = $this->marge_gauche + 1;
118
119 if ($mysoc === null) {
120 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
121 return;
122 }
123
124 // Get source company
125 $this->emetteur = $mysoc;
126 if (empty($this->emetteur->country_code)) {
127 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if not defined
128 }
129 }
130
131 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
143 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
144 {
145 // phpcs:enable
146 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
147
148 if (!is_object($outputlangs)) {
149 $outputlangs = $langs;
150 }
151 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
152 if (getDolGlobalString('MAIN_USE_FPDF')) {
153 $outputlangs->charset_output = 'ISO-8859-1';
154 }
155
156 // Load traductions files required by page
157 $outputlangs->loadLangs(array("main", "interventions", "dict", "companies", "compta"));
158
159 // Show Draft Watermark
160 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('FICHINTER_DRAFT_WATERMARK'))) {
161 $this->watermark = getDolGlobalString('FICHINTER_DRAFT_WATERMARK');
162 }
163
164 if ($conf->ficheinter->dir_output) {
165 $object->fetch_thirdparty();
166
167 // Definition of $dir and $file
168 if ($object->specimen) {
169 $dir = $conf->ficheinter->dir_output;
170 $file = $dir."/SPECIMEN.pdf";
171 } else {
172 $objectref = dol_sanitizeFileName($object->ref);
173 $dir = $conf->ficheinter->dir_output."/".$objectref;
174 $file = $dir."/".$objectref.".pdf";
175 }
176
177 if (!file_exists($dir)) {
178 if (dol_mkdir($dir) < 0) {
179 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
180 return 0;
181 }
182 }
183
184 if (file_exists($dir)) {
185 // Add pdfgeneration hook
186 if (!is_object($hookmanager)) {
187 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
188 $hookmanager = new HookManager($this->db);
189 }
190
191 $hookmanager->initHooks(array('pdfgeneration'));
192 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
193 global $action;
194 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
195
196 $nblines = count($object->lines);
197
198 // Create pdf instance
199 $pdf = pdf_getInstance($this->format);
200 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
201 $heightforinfotot = 50; // Height reserved to output the info and total part
202 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
203 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
204 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
205 $heightforfooter += 6;
206 }
207 $pdf->setAutoPageBreak(true, 0);
208
209 if (class_exists('TCPDF')) {
210 $pdf->setPrintHeader(false);
211 $pdf->setPrintFooter(false);
212 }
213 $pdf->SetFont(pdf_getPDFFont($outputlangs));
214 // Set path to the background PDF File
215 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
216 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
217 $tplidx = $pdf->importPage(1);
218 }
219
220 $pdf->Open();
221 $pagenb = 0;
222 $pdf->SetDrawColor(128, 128, 128);
223
224 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
225 $pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
226 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
227 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
228 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard"));
229 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
230 $pdf->SetCompression(false);
231 }
232
233 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
234 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
235
236 // New page
237 $pdf->AddPage();
238 if (!empty($tplidx)) {
239 $pdf->useTemplate($tplidx);
240 }
241 $pagenb++;
242 $this->_pagehead($pdf, $object, 1, $outputlangs);
243 $pdf->SetFont('', '', $default_font_size - 1);
244 $pdf->SetTextColor(0, 0, 0);
245
246 $tab_top = 80 + $this->marge_haute;
247 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
248
249 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
250
251 // Display notes
252 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
253 if ($notetoshow) {
254 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
255 complete_substitutions_array($substitutionarray, $outputlangs, $object);
256 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
257 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
258
259 $tab_top = 78 + $this->marge_haute;
260
261 $pdf->SetFont('', '', $default_font_size - 1);
262 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
263 $nexY = $pdf->GetY();
264 $height_note = $nexY - $tab_top;
265
266 // Rect takes a length in 3rd parameter
267 $pdf->SetDrawColor(192, 192, 192);
268 $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');
269
270 $tab_height -= $height_note;
271 $tab_top = $nexY + 6;
272 } else {
273 $height_note = 0;
274 }
275
276 $iniY = $tab_top + 7;
277 $curY = $tab_top + 7;
278 $nexY = $tab_top + 7;
279
280 $pdf->SetXY($this->marge_gauche, $tab_top);
281 $pdf->MultiCell(190, 5, $outputlangs->transnoentities("Description"), 0, 'L', false);
282 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
283
284 $pdf->SetFont('', '', $default_font_size - 1);
285
286 $pdf->SetXY($this->marge_gauche, $tab_top + 5);
287 $text = $object->description;
288 if ($object->duration > 0) {
289 $totaltime = convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
290 $text .= ($text ? ' - ' : '').$langs->trans("Total").": ".$totaltime;
291 }
292 $desc = dol_htmlentitiesbr($text, 1);
293 //print $outputlangs->convToOutputCharset($desc); exit;
294
295 $pdf->writeHTMLCell(180, 3, $this->posxdesc - 1, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
296 $nexY = $pdf->GetY();
297
298 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
299
300 $nblines = count($object->lines);
301
302 // Loop on each lines
303 for ($i = 0; $i < $nblines; $i++) {
304 $objectligne = $object->lines[$i];
305
306 $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
307 if ($valide > 0 || $object->specimen) {
308 $curY = $nexY;
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 product line
317 $curX = $this->posxdesc - 1;
318
319 // Subtotals module: a title / subtotal / free-text line has no date nor duration,
320 // it is shown as a (possibly coloured) section band instead of a standard line.
321 $issubtotalline = (defined('SUBTOTALS_SPECIAL_CODE') && $objectligne->special_code == SUBTOTALS_SPECIAL_CODE);
322 $subtotalbgcolor = null;
323
324 if ($issubtotalline) {
325 $outputlangs->load('subtotals');
326 $level = (int) $objectligne->duration; // For fichinter the subtotal depth is stored in the duree field
327 $linetext = $objectligne->desc;
328 if ($level < 0) {
329 // Closing "subtotal" line: an intervention PDF has no amount to sum, so it is only a section marker
330 $linetext = getDolGlobalString('SUBTOTAL_LINE_TEXT_DOES_NOT_INCLUDE_TITLE_TEXT') ? $outputlangs->transnoentities('SubTotal') : $outputlangs->transnoentities('SubtotalOf', $objectligne->desc);
331 }
332 $indent = str_repeat('&nbsp;', max(0, abs($level) - 1) * 4);
333 $txt = '';
334 $desc = $indent.($level != 0 ? '<strong>' : '').dol_htmlentitiesbr($linetext, 1).($level != 0 ? '</strong>' : '');
335 if ($level != 0) {
336 $subtotalbgcolor = colorStringToArray(getDolGlobalString('SUBTOTAL_BACK_COLOR_LEVEL_'.abs($level), 'ffffff'));
337 }
338 } else {
339 // Description of product line
340 if (!getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR')) {
341 $txt = $outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'dayhour', false, $outputlangs, true);
342 } else {
343 $txt = $outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'day', false, $outputlangs, true);
344 }
345
346 if ($objectligne->duration > 0) {
347 $txt .= " - ".$outputlangs->transnoentities("Duration")." : ".convertSecondToTime($objectligne->duration);
348 }
349 $txt = '<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).'</strong>';
350 $desc = dol_htmlentitiesbr($objectligne->desc, 1);
351 }
352
353 // Paint the coloured band behind a title/subtotal line (measure its height first)
354 if ($issubtotalline && is_array($subtotalbgcolor)) {
355 $pdf->startTransaction();
356 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt, $desc), 0, 1, false);
357 $subtotalh = $pdf->GetY() - $curY;
358 $subtotalpage = $pdf->getPage();
359 $pdf->rollbackTransaction(true);
360 if ($subtotalpage == $pageposbefore) {
361 $pdf->SetFillColor($subtotalbgcolor[0], $subtotalbgcolor[1], $subtotalbgcolor[2]);
362 $pdf->Rect($this->marge_gauche, $curY + 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, max(2, $subtotalh), 'F');
363 if (!colorIsLight(implode(',', $subtotalbgcolor))) {
364 $pdf->SetTextColor(255, 255, 255);
365 }
366 }
367 }
368
369 $pdf->startTransaction();
370 $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt, $desc), 0, 1, false);
371 $pageposafter = $pdf->getPage();
372 if ($pageposafter > $pageposbefore) { // There is a pagebreak
373 $pdf->rollbackTransaction(true);
374 $pageposafter = $pageposbefore;
375 //print $pageposafter.'-'.$pageposbefore;exit;
376 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
377 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt, $desc), 0, 1, false);
378 $pageposafter = $pdf->getPage();
379 $posyafter = $pdf->GetY();
380 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
381 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
382 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
383 $pdf->AddPage('', '', true);
384 if (!empty($tplidx)) {
385 $pdf->useTemplate($tplidx);
386 }
387 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
388 $this->_pagehead($pdf, $object, 0, $outputlangs);
389 }
390 $pdf->setPage($pageposafter + 1);
391 }
392 }
393 } else { // No pagebreak
394 $pdf->commitTransaction();
395 }
396
397 if ($issubtotalline) {
398 $pdf->SetTextColor(0, 0, 0);
399 }
400
401 $nexY = $pdf->GetY();
402 $pageposafter = $pdf->getPage();
403 $pdf->setPage($pageposbefore);
404 $pdf->setTopMargin($this->marge_haute);
405 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
406
407 // We suppose that a too long description is moved completely on next page
408 if ($pageposafter > $pageposbefore) {
409 $pdf->setPage($pageposafter);
410 $curY = $tab_top_newpage;
411 }
412
413 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
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 == 1) {
419 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
420 } else {
421 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
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 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
435 if ($pagenb == 1) {
436 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
437 } else {
438 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
439 }
440 $this->_pagefoot($pdf, $object, $outputlangs, 1);
441 // New page
442 $pdf->AddPage();
443 if (!empty($tplidx)) {
444 $pdf->useTemplate($tplidx);
445 }
446 $pagenb++;
447 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
448 $this->_pagehead($pdf, $object, 0, $outputlangs);
449 }
450 }
451 }
452 }
453
454 // Show square
455 if ($pagenb == 1) {
456 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object);
457 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
458 } else {
459 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object);
460 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
461 }
462
463 $this->_pagefoot($pdf, $object, $outputlangs);
464 if (method_exists($pdf, 'AliasNbPages')) {
465 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
466 }
467
468 $pdf->Close();
469 $pdf->Output($file, 'F');
470
471 // Add pdfgeneration hook
472 $hookmanager->initHooks(array('pdfgeneration'));
473 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
474 global $action;
475 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
476 $this->warnings = $hookmanager->warnings;
477 if ($reshook < 0) {
478 $this->error = $hookmanager->error;
479 $this->errors = $hookmanager->errors;
480 dolChmod($file);
481 return -1;
482 }
483
484 dolChmod($file);
485
486 $this->result = array('fullpath' => $file);
487
488 return 1;
489 } else {
490 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
491 return 0;
492 }
493 } else {
494 $this->error = $langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR");
495 return 0;
496 }
497 }
498
499 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
513 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $object = null)
514 {
515 global $conf;
516
517
518 $default_font_size = pdf_getPDFFontSize($outputlangs);
519 /*
520 $pdf->SetXY($this->marge_gauche, $tab_top);
521 $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
522 $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
523
524 $pdf->SetFont('','', $default_font_size - 1);
525
526 $pdf->MultiCell(0, 3, ''); // Set interline to 3
527 $pdf->SetXY($this->marge_gauche, $tab_top + 8);
528 $text=$object->description;
529 if ($object->duration > 0)
530 {
531 $totaltime=convertSecondToTime($object->duration,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
532 $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
533 }
534 $desc=dol_htmlentitiesbr($text,1);
535 //print $outputlangs->convToOutputCharset($desc); exit;
536
537 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
538 $nexY = $pdf->GetY();
539
540 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
541
542 $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
543 */
544
545 // Output Rect
546 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height + 1, $this->corner_radius, 0, 0, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
547
548 if (empty($hidebottom)) {
549 $employee_name = '';
550 if (!empty($object)) {
551 $arrayidcontact = $object->getIdContact('internal', 'INTERVENING');
552 if (count($arrayidcontact) > 0) {
553 $object->fetch_user($arrayidcontact[0]);
554 $employee_name = $object->user->getFullName($outputlangs);
555 }
556 }
557
558 $pdf->SetXY(20, 230);
559 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', false);
560
561 $pdf->SetXY(20, 235);
562 $pdf->MultiCell(80, 25, $employee_name, 1, 'L');
563
564 $pdf->SetXY(110, 230);
565 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', false);
566
567 $pdf->SetXY(110, 235);
568 $pdf->MultiCell(80, 25, '', 1);
569 }
570 }
571
572 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
582 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
583 {
584 global $conf, $langs;
585
586 $default_font_size = pdf_getPDFFontSize($outputlangs);
587
588 // Load traductions files required by page
589 $outputlangs->loadLangs(array("main", "dict", "companies", "interventions"));
590
591 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
592
593 //Prepare next
594 $pdf->SetTextColor(0, 0, 60);
595 $pdf->SetFont('', 'B', $default_font_size + 3);
596
597 $posx = $this->page_largeur - $this->marge_droite - 100;
598 $posy = $this->marge_haute;
599
600 $pdf->SetXY($this->marge_gauche, $posy);
601
602 // Logo
603 $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
604 if ($this->emetteur->logo) {
605 if (is_readable($logo)) {
606 $height = pdf_getHeightForLogo($logo);
607 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
608 } else {
609 $pdf->SetTextColor(200, 0, 0);
610 $pdf->SetFont('', 'B', $default_font_size - 2);
611 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
612 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
613 }
614 } else {
615 $text = $this->emetteur->name;
616 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
617 }
618
619 $pdf->SetFont('', 'B', $default_font_size + 3);
620 $pdf->SetXY($posx, $posy);
621 $pdf->SetTextColor(0, 0, 60);
622 $title = $outputlangs->transnoentities("InterventionCard");
623 $pdf->MultiCell(100, 4, $title, '', 'R');
624
625 $pdf->SetFont('', 'B', $default_font_size + 2);
626
627 $posy += 5;
628 $pdf->SetXY($posx, $posy);
629 $pdf->SetTextColor(0, 0, 60);
630 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
631
632 $posy += 1;
633 $pdf->SetFont('', '', $default_font_size);
634
635 $posy += 4;
636 $pdf->SetXY($posx, $posy);
637 $pdf->SetTextColor(0, 0, 60);
638 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->datec, "day", false, $outputlangs, true), '', 'R');
639
640 if (!empty($object->ref_client)) {
641 $posy += 4;
642 $pdf->SetXY($posx, $posy);
643 $pdf->SetTextColor(0, 0, 60);
644 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer") . " : " . pdf_truncate_text($pdf, $outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
645 }
646
647
648 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
649 $posy += 4;
650 $pdf->SetXY($posx, $posy);
651 $pdf->SetTextColor(0, 0, 60);
652 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
653 }
654
655 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
656 $posy += 4;
657 $pdf->SetXY($posx, $posy);
658 $pdf->SetTextColor(0, 0, 60);
659 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_compta_client), '', 'R');
660 }
661
662 if ($showaddress) {
663 // Sender properties
664 $carac_emetteur = '';
665 // Add internal contact of object if defined
666 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
667 if (count($arrayidcontact) > 0) {
668 $object->fetch_user($arrayidcontact[0]);
669 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
670 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
671 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
672 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
673 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
674 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
675 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
676 $carac_emetteur .= "\n";
677 }
678
679 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
680
681 // Show sender
682 $posy = 32 + $this->marge_haute;
683 $posx = $this->marge_gauche;
684 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
685 $posx = $this->page_largeur - $this->marge_droite - 80;
686 }
687 $hautcadre = 40;
688
689 // Show sender frame
690 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
691 $pdf->SetTextColor(0, 0, 0);
692 $pdf->SetFont('', '', $default_font_size - 2);
693 $pdf->SetXY($posx, $posy - 5);
694 $pdf->SetXY($posx, $posy);
695 $pdf->SetFillColor(230, 230, 230);
696 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
697 }
698
699 // Show sender name
700 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
701 $pdf->SetXY($posx + 2, $posy + 3);
702 $pdf->SetTextColor(0, 0, 60);
703 $pdf->SetFont('', 'B', $default_font_size);
704 $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
705 $posy = $pdf->getY();
706 }
707
708 // Show sender information
709 $pdf->SetFont('', '', $default_font_size - 1);
710 $pdf->SetXY($posx + 2, $posy);
711 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
712
713
714 // If CUSTOMER contact defined, we use it
715 $usecontact = false;
716 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
717 if (count($arrayidcontact) > 0) {
718 $usecontact = true;
719 $result = $object->fetch_contact($arrayidcontact[0]);
720 }
721
722 // Recipient name
723 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
724 $thirdparty = $object->contact;
725 } else {
726 $thirdparty = $object->thirdparty;
727 }
728
729 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
730
731 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), ($usecontact ? 1 : 0), 'target', $object);
732
733 // Show recipient
734 $widthrecbox = 100;
735 if ($this->page_largeur < 210) {
736 $widthrecbox = 84; // To work with US executive format
737 }
738 $posy = 32 + $this->marge_haute;
739 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
740 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
741 $posx = $this->marge_gauche;
742 }
743
744 // Show recipient frame
745 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
746 $pdf->SetTextColor(0, 0, 0);
747 $pdf->SetFont('', '', $default_font_size - 2);
748 $pdf->SetXY($posx + 2, $posy - 5);
749 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
750 $pdf->SetTextColor(0, 0, 0);
751 }
752
753 // Show recipient name
754 $pdf->SetXY($posx + 2, $posy + 3);
755 $pdf->SetFont('', 'B', $default_font_size);
756 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
757
758 $posy = $pdf->getY();
759
760 // Show recipient information
761 $pdf->SetFont('', '', $default_font_size - 1);
762 $pdf->SetXY($posx + 2, $posy);
763 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
764 }
765
766 return 0;
767 }
768
769 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
779 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
780 {
781 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
782 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);
783 }
784}
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:
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
Class to manage hooks.
Parent class to manage intervention document templates.
Class to build interventions documents with model Soleil.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $object=null)
Show table for lines.
__construct($db)
Constructor.
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...
colorIsLight($stringcolor)
Return true if the color is light.
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_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