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