dolibarr 25.0.0-alpha
pdf_strato.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-2024 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Nick Fragoulis
12 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 * Copyright (C) 2024 Éric Seigne <eric.seigne@cap-rel.fr>
14 * Copyright (C) 2025 William Mead <william@m34d.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 * or see https://www.gnu.org/
29 */
30
36require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
42
43
48{
52 public $db;
53
57 public $entity;
58
62 public $name;
63
67 public $description;
68
72 public $update_main_doc_field;
73
77 public $type;
78
83 public $version = 'dolibarr';
84
88 public $position = 50;
89
90
94 public $recipient;
95
101 public function __construct($db)
102 {
103 global $langs, $mysoc;
104
105 $this->db = $db;
106 $this->name = 'strato';
107 $this->description = $langs->trans("StandardContractsTemplate");
108 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
109
110 // Dimension page
111 $this->type = 'pdf';
112 $formatarray = pdf_getFormat();
113
114 $this->page_largeur = $formatarray['width'];
115 $this->page_hauteur = $formatarray['height'];
116 $this->format = array($this->page_largeur, $this->page_hauteur);
117 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
118 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
119 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
120 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
121 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
122 $this->option_logo = 1; // Display logo
123 $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
124 $this->option_modereg = 0; // Display payment mode
125 $this->option_condreg = 0; // Display payment terms
126 $this->option_multilang = 0; // Available in several languages
127 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
128
129 // Define position of columns
130 $this->posxdesc = $this->marge_gauche + 1;
131
132 if ($mysoc === null) {
133 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
134 return;
135 }
136
137 // Get source company
138 $this->emetteur = $mysoc;
139 if (empty($this->emetteur->country_code)) {
140 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
141 }
142 }
143
144 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
156 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
157 {
158 // phpcs:enable
159 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
160
161 if (!is_object($outputlangs)) {
162 $outputlangs = $langs;
163 }
164 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
165 if (getDolGlobalString('MAIN_USE_FPDF')) {
166 $outputlangs->charset_output = 'ISO-8859-1';
167 }
168
169 // Load translation files required by page
170 $outputlangs->loadLangs(array("main", "dict", "companies", "contracts", "compta"));
171
172 // Show Draft Watermark
173 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('CONTRACT_DRAFT_WATERMARK'))) {
174 $this->watermark = getDolGlobalString('CONTRACT_DRAFT_WATERMARK');
175 }
176
177 global $outputlangsbis;
178 $outputlangsbis = null;
179 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
180 $outputlangsbis = new Translate('', $conf);
181 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
182 $outputlangsbis->loadLangs(array("main", "dict", "companies", "contracts", "compta"));
183 }
184
185 $nblines = count($object->lines);
186
187 if ($conf->contract->multidir_output[$conf->entity]) {
188 $object->fetch_thirdparty();
189
190 // Definition of $dir and $file
191 if ($object->specimen) {
193 $file = $dir."/SPECIMEN.pdf";
194 } else {
195 $objectref = dol_sanitizeFileName($object->ref);
196 $dir = getMultidirOutput($object)."/".$objectref;
197 $file = $dir."/".$objectref.".pdf";
198 }
199
200 if ($dir === null) {
201 dol_syslog(get_class($this).'::'.__METHOD__."Target directory should not be null.". getCallerInfoString(), LOG_ERR);
202 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", "Null dir");
203 return 0;
204 }
205
206 if (!file_exists($dir)) {
207 if (dol_mkdir($dir) < 0) {
208 $this->error = $langs->transnoentitiesnoconv("ErrorCanNotCreateDir", $dir);
209 return 0;
210 }
211 }
212
213 if (file_exists($dir)) {
214 // Add pdfgeneration hook
215 if (!is_object($hookmanager)) {
216 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
217 $hookmanager = new HookManager($this->db);
218 }
219 $hookmanager->initHooks(array('pdfgeneration'));
220 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
221 global $action;
222 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
223
224 // Set nblines with the new lines content after hook
225 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
226
227 // Create pdf instance
228 $pdf = pdf_getInstance($this->format);
229 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
230 $pdf->setAutoPageBreak(true, 0);
231
232 $heightforinfotot = 50; // Height reserved to output the info and total part
233 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
234 $heightforfooter = $this->marge_basse + 9; // Height reserved to output the footer (value include bottom margin)
235 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
236 $heightforfooter += 6;
237 }
238
239 if (class_exists('TCPDF')) {
240 $pdf->setPrintHeader(false);
241 $pdf->setPrintFooter(false);
242 }
243 $pdf->SetFont(pdf_getPDFFont($outputlangs));
244 // Set path to the background PDF File
245 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
246 $logodir = $conf->mycompany->dir_output;
247 if (!empty($conf->mycompany->multidir_output[$object->entity ?? $conf->entity])) {
248 $logodir = $conf->mycompany->multidir_output[$object->entity ?? $conf->entity];
249 }
250 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
251 $tplidx = $pdf->importPage(1);
252 }
253
254 $pdf->Open();
255 $pagenb = 0;
256 $pdf->SetDrawColor(128, 128, 128);
257
258 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
259 $pdf->SetSubject($outputlangs->transnoentities("Contract"));
260 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
261 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
262 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Contract")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
263 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
264 $pdf->SetCompression(false);
265 }
266
267 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
268 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
269
270 // New page
271 $pdf->AddPage();
272 if (!empty($tplidx)) {
273 $pdf->useTemplate($tplidx);
274 }
275 $pagenb++;
276 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
277 $pdf->SetFont('', '', $default_font_size - 1);
278 $pdf->MultiCell(0, 3, ''); // Set interline to 3
279 $pdf->SetTextColor(0, 0, 0);
280
281 $tab_top = 80 + $this->marge_haute;
282 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 32 + $this->marge_haute : $this->marge_haute);
283
284 // Display notes
285 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
286
287 // Extrafields in note
288 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
289 if (!empty($extranote)) {
290 $notetoshow = dol_concatdesc($notetoshow, $extranote);
291 }
292
293 if (!empty($notetoshow)) {
294 $tab_top -= 2;
295
296 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
297 complete_substitutions_array($substitutionarray, $outputlangs, $object);
298 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
299 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
300
301 $pdf->SetFont('', '', $default_font_size - 1);
302 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
303 $nexY = $pdf->GetY();
304 $height_note = $nexY - $tab_top;
305
306 // Rect takes a length in 3rd parameter
307 $pdf->SetDrawColor(192, 192, 192);
308 $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');
309
310 $tab_top = $nexY + 6;
311 }
312
313 $iniY = $tab_top + 7;
314 $curY = $tab_top + 7;
315 $nexY = $tab_top + 2;
316
317 $pdf->SetXY($this->marge_gauche, $tab_top);
318
319 $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
320
321 $nblines = count($object->lines);
322
323 // Loop on each lines
324 for ($i = 0; $i < $nblines; $i++) {
325 $objectligne = $object->lines[$i];
326
327 $valide = $objectligne->id ? 1 : 0;
328
329 if ($valide > 0 || $object->specimen) {
330 $curX = $this->posxdesc - 1;
331 $curY = $nexY;
332 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
333 $pdf->SetTextColor(0, 0, 0);
334
335 $pdf->setTopMargin($tab_top_newpage);
336 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
337 $pageposbefore = $pdf->getPage();
338
339 // Description of product line
340
341 if (!empty($objectligne->date_start)) {
342 $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
343 } else {
344 $datei = $langs->trans("Unknown");
345 }
346
347 if (!empty($objectligne->date_end)) {
348 $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
349 $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
350 } else {
351 $durationi = $langs->trans("Unknown");
352 $datee = $langs->trans("Unknown");
353 }
354
355 if (!empty($objectligne->date_start_real)) {
356 $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
357 } else {
358 $daters = $langs->trans("Unknown");
359 }
360
361 if (!empty($objectligne->date_end_real)) {
362 $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
363 } else {
364 $datere = $langs->trans("Unknown");
365 }
366
367 $txtpredefinedservice = $objectligne->product_ref;
368 if ($objectligne->product_label) {
369 $txtpredefinedservice .= ' - ';
370 $txtpredefinedservice .= $objectligne->product_label;
371 }
372
373 $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
374 $txt = '';
375 if (!getDolGlobalString('CONTRACT_HIDE_QTY_ON_PDF')) {
376 $txt .= $outputlangs->transnoentities("Quantity") . ' : <strong>' . $objectligne->qty . '</strong>';
377 }
378 if (!getDolGlobalString('CONTRACT_HIDE_PRICE_ON_PDF')) {
379 $txt .= ' - ' . $outputlangs->transnoentities("UnitPrice") . ' : <strong>' . price($objectligne->subprice) . '</strong>';
380 }
381 if (!getDolGlobalString('CONTRACT_HIDE_PLANNED_DATE_ON_PDF')) {
382 $txt .= '<br>';
383 $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
384 }
385 if (!getDolGlobalString('CONTRACT_HIDE_REAL_DATE_ON_PDF')) {
386 $txt .= '<br>';
387 $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
388 if (!empty($objectligne->date_end_real)) {
389 $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : <strong>".$datere.'</strong>';
390 }
391 }
392
393 $pdf->startTransaction();
394 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), false, 1, false);
395 $pageposafter = $pdf->getPage();
396 if ($pageposafter > $pageposbefore) { // There is a pagebreak
397 $pdf->rollbackTransaction(true);
398 $pageposafter = $pageposbefore;
399 //print $pageposafter.'-'.$pageposbefore;exit;
400 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
401 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), false, 1, false);
402 $pageposafter = $pdf->getPage();
403 $posyafter = $pdf->GetY();
404 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
405 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
406 $pdf->AddPage('', '', true);
407 if (!empty($tplidx)) {
408 $pdf->useTemplate($tplidx);
409 }
410 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
411 $this->_pagehead($pdf, $object, 0, $outputlangs);
412 }
413 $pdf->setPage($pageposafter + 1);
414 }
415 } else {
416 // We found a page break
417
418 // Allows data in the first page if description is long enough to break in multiples pages
419 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
420 $showpricebeforepagebreak = 1;
421 } else {
422 $showpricebeforepagebreak = 0;
423 }
424 }
425 } else { // No pagebreak
426 $pdf->commitTransaction();
427 }
428 $posYAfterDescription = $pdf->GetY();
429
430 $nexY = $pdf->GetY() + 2;
431 $pageposafter = $pdf->getPage();
432
433 $pdf->setPage($pageposbefore);
434 $pdf->setTopMargin($this->marge_haute);
435 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
436
437 // We suppose that a too long description is moved completely on next page
438 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
439 $pdf->setPage($pageposafter);
440 $curY = $tab_top_newpage;
441 }
442
443 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
444
445 // Detect if some page were added automatically and output _tableau for past pages
446 while ($pagenb < $pageposafter) {
447 $pdf->setPage($pagenb);
448 if ($pagenb == 1) {
449 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
450 } else {
451 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
452 }
453 $this->_pagefoot($pdf, $object, $outputlangs, 1);
454 $pagenb++;
455 $pdf->setPage($pagenb);
456 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
457 if (!getDolGlobalString('MAIN_PDF_DONOTREPEAT_HEAD')) {
458 $this->_pagehead($pdf, $object, 0, $outputlangs);
459 }
460 if (!empty($tplidx)) {
461 $pdf->useTemplate($tplidx);
462 }
463 }
464
465 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
466 if ($pagenb == 1) {
467 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
468 } else {
469 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
470 }
471 $this->_pagefoot($pdf, $object, $outputlangs, 1);
472 // New page
473 $pdf->AddPage();
474 if (!empty($tplidx)) {
475 $pdf->useTemplate($tplidx);
476 }
477 $pagenb++;
478 }
479 }
480 }
481
482
483 // Show square
484 if ($pagenb == 1) {
485 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
486 $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
487 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
488 } else {
489 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
490 $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
491 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
492 }
493
494 $this->_pagefoot($pdf, $object, $outputlangs);
495 if (method_exists($pdf, 'AliasNbPages')) {
496 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
497 }
498
499 // Add terms of sale
500 if (getDolGlobalString('MAIN_INFO_CONTRACT_TERMSOFSALE') && $this->mustAddTermsOfSale($object, 'CONTRACT')) {
501 $termsofsalefilename = getDolGlobalString('MAIN_INFO_CONTRACT_TERMSOFSALE');
502 $termsofsale = $conf->contract->dir_output.'/'.$termsofsalefilename;
503 if (!empty($conf->contract->multidir_output[$object->entity ?? $conf->entity])) {
504 $termsofsale = $conf->contract->multidir_output[$object->entity ?? $conf->entity].'/'.$termsofsalefilename;
505 }
506 if (file_exists($termsofsale) && is_readable($termsofsale)) {
507 $pagecount = $pdf->setSourceFile($termsofsale);
508 for ($i = 1; $i <= $pagecount; $i++) {
509 $tplIdx = $pdf->importPage($i);
510 if ($tplIdx !== false) {
511 $s = $pdf->getTemplatesize($tplIdx);
512 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
513 $pdf->useTemplate($tplIdx);
514 } else {
515 setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings');
516 }
517 }
518 }
519 }
520
521 $pdf->Close();
522
523 $pdf->Output($file, 'F');
524
525 // Add pdfgeneration hook
526 $hookmanager->initHooks(array('pdfgeneration'));
527 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
528 global $action;
529 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
530 $this->warnings = $hookmanager->warnings;
531 if ($reshook < 0) {
532 $this->error = $hookmanager->error;
533 $this->errors = $hookmanager->errors;
534 dolChmod($file);
535 return -1;
536 }
537
538 dolChmod($file);
539
540 $this->result = array('fullpath' => $file);
541
542 return 1; // No error
543 } else {
544 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
545 return 0;
546 }
547 } else {
548 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
549 return 0;
550 }
551 }
552
553 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
566 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
567 {
568 global $conf;
569
570 // Force to disable hidetop and hidebottom
571 $hidebottom = 0;
572 if ($hidetop) {
573 $hidetop = -1;
574 }
575
576 //$default_font_size = pdf_getPDFFontSize($outputlangs);
577
578 /*
579 $pdf->SetXY($this->marge_gauche, $tab_top);
580 $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
581 $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
582
583 $pdf->SetFont('','', $default_font_size - 1);
584
585 $pdf->MultiCell(0, 3, ''); // Set interline to 3
586 $pdf->SetXY($this->marge_gauche, $tab_top + 8);
587 $text=$object->description;
588 if ($object->duree > 0)
589 {
590 $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
591 $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
592 }
593 $desc=dol_htmlentitiesbr($text,1);
594 //print $outputlangs->convToOutputCharset($desc); exit;
595
596 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
597 $nexY = $pdf->GetY();
598
599 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
600
601 $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
602 */
603
604 // Output Rect
605 $this->printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height + 3, $this->corner_radius, $hidetop, $hidebottom, 'D'); // Rect takes a length in 3rd parameter and 4th parameter
606 }
607
617 protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
618 {
619 $pdf->SetDrawColor(128, 128, 128);
620 $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
621 $posy = $tab_top + $tab_height + 3 + 3;
622
623 if (!getDolGlobalString('CONTRACT_HIDE_MYCOMPANY_SIGNATURE_SECTION_PDF')) {
624 $pdf->SetXY($this->marge_gauche, $posy);
625 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', false);
626
627 $pdf->SetXY($this->marge_gauche, $posy + 5);
628 $pdf->RoundedRect($this->marge_gauche, $posy + 5, $posmiddle - $this->marge_gauche - 5, 20, $this->corner_radius, '1234', 'D');
629 }
630
631 if (!getDolGlobalString('CONTRACT_HIDE_THIRPARTY_SIGNATURE_SECTION_PDF') && is_object($this->recipient)) {
632 $pdf->SetXY($posmiddle + 5, $posy);
633 $recipientname = pdfBuildThirdpartyName($this->recipient, $outputlangs);
634 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $recipientname), 0, 'L', false);
635
636 $pdf->SetXY($posmiddle + 5, $posy + 5);
637 $pdf->RoundedRect($posmiddle + 5, $posy + 5, $this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, $this->corner_radius, '1234', 'D');
638 }
639 }
640
641 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
653 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "Contract")
654 {
655 // phpcs:enable
656 global $conf;
657
658 $top_shift = 0;
659
660 $ltrdirection = 'L';
661 if ($outputlangs->trans("DIRECTION") == 'rtl') {
662 $ltrdirection = 'R';
663 }
664
665 // Load traductions files required by page
666 $outputlangs->loadLangs(array("main", "dict", "contract", "companies"));
667
668 $default_font_size = pdf_getPDFFontSize($outputlangs);
669
670 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
671
672 $pdf->SetTextColor(0, 0, 60);
673 $pdf->SetFont('', 'B', $default_font_size + 3);
674
675 $w = 100;
676
677 $posy = $this->marge_haute;
678 $posx = $this->page_largeur - $this->marge_droite - $w;
679
680 $pdf->SetXY($this->marge_gauche, $posy);
681
682 // Logo
683 $logodir = $conf->mycompany->dir_output;
684 $multidiroutput = getMultidirOutput($object, 'mycompany');
685 if (!empty($multidiroutput)) {
686 $logodir = $multidiroutput;
687 }
688 pdf_writeLogoOrCompanyName($pdf, $outputlangs, $this->emetteur, $logodir, $this->marge_gauche, $posy, $w, $default_font_size, $ltrdirection);
689
690 $pdf->SetFont('', 'B', $default_font_size + 3);
691 $pdf->SetXY($posx, $posy);
692 $pdf->SetTextColor(0, 0, 60);
693 $title = $outputlangs->transnoentities($titlekey);
694 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
695 if ($object->status == $object::STATUS_DRAFT) {
696 $pdf->SetTextColor(128, 0, 0);
697 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
698 }
699 $pdf->MultiCell($w, 3, $title, '', 'R');
700
701 $pdf->SetFont('', 'B', $default_font_size);
702
703 /*
704 $posy += 5;
705 $pdf->SetXY($posx, $posy);
706 $pdf->SetTextColor(0, 0, 60);
707 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
708 */
709
710 $posy += 3;
711 $pdf->SetFont('', '', $default_font_size - 1);
712
713 $posy += 4;
714 $pdf->SetXY($posx, $posy);
715 $pdf->SetTextColor(0, 0, 60);
716 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_contrat, "day", false, $outputlangs, true), '', 'R');
717
718 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
719 $posy += 4;
720 $pdf->SetXY($posx, $posy);
721 $pdf->SetTextColor(0, 0, 60);
722 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_client), '', 'R');
723 }
724
725 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
726 $posy += 4;
727 $pdf->SetXY($posx, $posy);
728 $pdf->SetTextColor(0, 0, 60);
729 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities((string) $object->thirdparty->code_compta_client), '', 'R');
730 }
731
732 if ($showaddress) {
733 // Sender properties
734 $carac_emetteur = '';
735 // Add internal contact of object if defined
736 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
737 if (count($arrayidcontact) > 0) {
738 $object->fetch_user($arrayidcontact[0]);
739 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
740 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
741 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
742 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
743 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
744 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
745 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
746 $carac_emetteur .= "\n";
747 }
748
749 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
750
751 // Show sender
752 $posy = 32 + $this->marge_haute;
753 $posx = $this->marge_gauche;
754 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
755 $posx = $this->page_largeur - $this->marge_droite - 80;
756 }
757 $hautcadre = 40;
758
759 // Show sender frame
760 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
761 $pdf->SetTextColor(0, 0, 0);
762 $pdf->SetFont('', '', $default_font_size - 2);
763 $pdf->SetXY($posx, $posy - 5);
764 $pdf->SetXY($posx, $posy);
765 $pdf->SetFillColor(230, 230, 230);
766 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
767 $pdf->SetTextColor(0, 0, 60);
768 }
769
770 // Show sender name
771 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
772 $pdf->SetXY($posx + 2, $posy + 3);
773 $pdf->SetTextColor(0, 0, 60);
774 $pdf->SetFont('', 'B', $default_font_size);
775 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
776 $posy = $pdf->getY();
777 }
778
779 // Show sender information
780 $pdf->SetXY($posx + 2, $posy);
781 $pdf->SetFont('', '', $default_font_size - 1);
782 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
783
784
785 // If CUSTOMER contact defined, we use it
786 $usecontact = false;
787 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
788 if (count($arrayidcontact) > 0) {
789 $usecontact = true;
790 $result = $object->fetch_contact($arrayidcontact[0]);
791 }
792
793 // Recipient name
794 if ($usecontact && ($object->contact->socid != $object->thirdparty->id) && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
795 $this->recipient = $object->contact;
796 } else {
797 $this->recipient = $object->thirdparty;
798 }
799
800 $recipientname = '';
801 if ($this->recipient instanceof Contact || $this->recipient instanceof Societe) {
802 $recipientname = pdfBuildThirdpartyName($this->recipient, $outputlangs);
803 }
804
805 $mode = 'target';
806 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
807
808 // Show recipient
809 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
810 if ($this->page_largeur < 210) {
811 $widthrecbox = 84; // To work with US executive format
812 }
813 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 30 : 32;
814 $posy += $top_shift + $this->marge_haute;
815 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
816 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
817 $posx = $this->marge_gauche;
818 }
819
820 // Show recipient frame
821 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
822 $pdf->SetTextColor(0, 0, 0);
823 $pdf->SetFont('', '', $default_font_size - 2);
824 $pdf->SetXY($posx + 2, $posy - 5);
825 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
826 $pdf->SetTextColor(0, 0, 0);
827 }
828
829 // Show recipient name
830 $pdf->SetXY($posx + 2, $posy + 3);
831 $pdf->SetFont('', 'B', $default_font_size);
832 $pdf->MultiCell($widthrecbox, 4, $recipientname, 0, $ltrdirection);
833
834 $posy = $pdf->getY();
835
836 // Show recipient information
837 $pdf->SetFont('', '', $default_font_size - 1);
838 $pdf->SetXY($posx + 2, $posy);
839 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
840 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
841 }
842
843 $pdf->SetTextColor(0, 0, 0);
844
845 return $top_shift;
846 }
847
848 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
858 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
859 {
860 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
861 return pdf_pagefoot($pdf, $outputlangs, 'CONTRACT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
862 }
863}
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:
mustAddTermsOfSale($object, $type)
Return if the terms of sale file must be concatenated to the generated document.
printRoundedRect($pdf, $x, $y, $w, $h, $r, $hidetop=0, $hidebottom=0, $style='D')
Print a rounded rectangle on the PDF.
Class to manage contact/addresses.
Class to manage hooks.
Parent class to manage intervention document templates.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to build contracts documents with model Strato.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf on disk.
tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
Show footer signature of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null, $titlekey="Contract")
Show top header of page.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
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...
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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:296
pdf_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_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_writeLogoOrCompanyName($pdf, $outputlangs, $emetteur, $logodir, $posx, $posy, $w, $default_font_size, $align)
Output company logo on top-left of a PDF page header, or the company name as fallback text if no logo...
Definition pdf.lib.php:351
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