dolibarr 21.0.3
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-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024 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 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 * or see https://www.gnu.org/
28 */
29
35require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41
42
47{
51 public $db;
52
56 public $entity;
57
61 public $name;
62
66 public $description;
67
71 public $update_main_doc_field;
72
76 public $type;
77
82 public $version = 'dolibarr';
83
88 public $recipient;
89
95 public function __construct($db)
96 {
97 global $langs, $mysoc;
98
99 $this->db = $db;
100 $this->name = 'strato';
101 $this->description = $langs->trans("StandardContractsTemplate");
102 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
103
104 // Dimension page
105 $this->type = 'pdf';
106 $formatarray = pdf_getFormat();
107
108 $this->page_largeur = $formatarray['width'];
109 $this->page_hauteur = $formatarray['height'];
110 $this->format = array($this->page_largeur, $this->page_hauteur);
111 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
112 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
113 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
114 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
115 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
116 $this->option_logo = 1; // Display logo
117 $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
118 $this->option_modereg = 0; // Display payment mode
119 $this->option_condreg = 0; // Display payment terms
120 $this->option_multilang = 0; // Available in several languages
121 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
122
123 // Define position of columns
124 $this->posxdesc = $this->marge_gauche + 1;
125
126 if ($mysoc === null) {
127 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
128 return;
129 }
130
131 // Get source company
132 $this->emetteur = $mysoc;
133 if (empty($this->emetteur->country_code)) {
134 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
135 }
136 }
137
138 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
150 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
151 {
152 // phpcs:enable
153 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
154
155 if (!is_object($outputlangs)) {
156 $outputlangs = $langs;
157 }
158 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
159 if (getDolGlobalString('MAIN_USE_FPDF')) {
160 $outputlangs->charset_output = 'ISO-8859-1';
161 }
162
163 // Load translation files required by page
164 $outputlangs->loadLangs(array("main", "dict", "companies", "contracts", "compta"));
165
166 // Show Draft Watermark
167 if ($object->status == $object::STATUS_DRAFT && (getDolGlobalString('CONTRACT_DRAFT_WATERMARK'))) {
168 $this->watermark = getDolGlobalString('CONTRACT_DRAFT_WATERMARK');
169 }
170
171 global $outputlangsbis;
172 $outputlangsbis = null;
173 if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) {
174 $outputlangsbis = new Translate('', $conf);
175 $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'));
176 $outputlangsbis->loadLangs(array("main", "dict", "companies", "contracts", "compta"));
177 }
178
179 $nblines = count($object->lines);
180
181 if ($conf->contract->multidir_output[$conf->entity]) {
182 $object->fetch_thirdparty();
183
184 // Definition of $dir and $file
185 if ($object->specimen) {
187 $file = $dir."/SPECIMEN.pdf";
188 } else {
189 $objectref = dol_sanitizeFileName($object->ref);
190 $dir = getMultidirOutput($object)."/".$objectref;
191 $file = $dir."/".$objectref.".pdf";
192 }
193
194 if (!file_exists($dir)) {
195 if (dol_mkdir($dir) < 0) {
196 $this->error = $langs->transnoentitiesnoconv("ErrorCanNotCreateDir", $dir);
197 return 0;
198 }
199 }
200
201 if (file_exists($dir)) {
202 // Add pdfgeneration hook
203 if (!is_object($hookmanager)) {
204 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
205 $hookmanager = new HookManager($this->db);
206 }
207 $hookmanager->initHooks(array('pdfgeneration'));
208 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
209 global $action;
210 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
211
212 // Set nblines with the new lines content after hook
213 $nblines = (is_array($object->lines) ? count($object->lines) : 0);
214
215 // Create pdf instance
216 $pdf = pdf_getInstance($this->format);
217 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
218 $pdf->SetAutoPageBreak(1, 0);
219
220 $heightforinfotot = 50; // Height reserved to output the info and total part
221 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
222 $heightforfooter = $this->marge_basse + 9; // Height reserved to output the footer (value include bottom margin)
223 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
224 $heightforfooter += 6;
225 }
226
227 if (class_exists('TCPDF')) {
228 $pdf->setPrintHeader(false);
229 $pdf->setPrintFooter(false);
230 }
231 $pdf->SetFont(pdf_getPDFFont($outputlangs));
232 // Set path to the background PDF File
233 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
234 $logodir = $conf->mycompany->dir_output;
235 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
236 $logodir = $conf->mycompany->multidir_output[$object->entity];
237 }
238 $pagecount = $pdf->setSourceFile($logodir.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
239 $tplidx = $pdf->importPage(1);
240 }
241
242 $pdf->Open();
243 $pagenb = 0;
244 $pdf->SetDrawColor(128, 128, 128);
245
246 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
247 $pdf->SetSubject($outputlangs->transnoentities("Contract"));
248 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
249 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
250 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Contract")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
251 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
252 $pdf->SetCompression(false);
253 }
254
255 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
256 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
257
258 // New page
259 $pdf->AddPage();
260 if (!empty($tplidx)) {
261 $pdf->useTemplate($tplidx);
262 }
263 $pagenb++;
264 $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis : null));
265 $pdf->SetFont('', '', $default_font_size - 1);
266 $pdf->MultiCell(0, 3, ''); // Set interline to 3
267 $pdf->SetTextColor(0, 0, 0);
268
269 $tab_top = 90;
270 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
271
272 // Display notes
273 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
274
275 // Extrafields in note
276 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
277 if (!empty($extranote)) {
278 $notetoshow = dol_concatdesc($notetoshow, $extranote);
279 }
280
281 if (!empty($notetoshow)) {
282 $tab_top -= 2;
283
284 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
285 complete_substitutions_array($substitutionarray, $outputlangs, $object);
286 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
287 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
288
289 $pdf->SetFont('', '', $default_font_size - 1);
290 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1);
291 $nexY = $pdf->GetY();
292 $height_note = $nexY - $tab_top;
293
294 // Rect takes a length in 3rd parameter
295 $pdf->SetDrawColor(192, 192, 192);
296 $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');
297
298 $tab_top = $nexY + 6;
299 }
300
301 $iniY = $tab_top + 7;
302 $curY = $tab_top + 7;
303 $nexY = $tab_top + 2;
304
305 $pdf->SetXY($this->marge_gauche, $tab_top);
306
307 $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
308
309 $nblines = count($object->lines);
310
311 // Loop on each lines
312 for ($i = 0; $i < $nblines; $i++) {
313 $objectligne = $object->lines[$i];
314
315 $valide = $objectligne->id ? 1 : 0;
316
317 if ($valide > 0 || $object->specimen) {
318 $curX = $this->posxdesc - 1;
319 $curY = $nexY;
320 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
321 $pdf->SetTextColor(0, 0, 0);
322
323 $pdf->setTopMargin($tab_top_newpage);
324 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
325 $pageposbefore = $pdf->getPage();
326
327 // Description of product line
328
329 if (!empty($objectligne->date_start)) {
330 $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
331 } else {
332 $datei = $langs->trans("Unknown");
333 }
334
335 if (!empty($objectligne->date_end)) {
336 $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
337 $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
338 } else {
339 $durationi = $langs->trans("Unknown");
340 $datee = $langs->trans("Unknown");
341 }
342
343 if (!empty($objectligne->date_start_real)) {
344 $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
345 } else {
346 $daters = $langs->trans("Unknown");
347 }
348
349 if (!empty($objectligne->date_end_real)) {
350 $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
351 } else {
352 $datere = $langs->trans("Unknown");
353 }
354
355 $txtpredefinedservice = $objectligne->product_ref;
356 if ($objectligne->product_label) {
357 $txtpredefinedservice .= ' - ';
358 $txtpredefinedservice .= $objectligne->product_label;
359 }
360
361 $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
362 $txt = '';
363 if (!getDolGlobalString('CONTRACT_HIDE_QTY_ON_PDF')) {
364 $txt .= $outputlangs->transnoentities("Quantity") . ' : <strong>' . $objectligne->qty . '</strong>';
365 }
366 if (!getDolGlobalString('CONTRACT_HIDE_PRICE_ON_PDF')) {
367 $txt .= ' - ' . $outputlangs->transnoentities("UnitPrice") . ' : <strong>' . price($objectligne->subprice) . '</strong>';
368 }
369 if (!getDolGlobalString('CONTRACT_HIDE_PLANNED_DATE_ON_PDF')) {
370 $txt .= '<br>';
371 $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
372 }
373 if (!getDolGlobalString('CONTRACT_HIDE_REAL_DATE_ON_PDF')) {
374 $txt .= '<br>';
375 $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
376 if (!empty($objectligne->date_end_real)) {
377 $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : <strong>".$datere.'</strong>';
378 }
379 }
380
381 $pdf->startTransaction();
382 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
383 $pageposafter = $pdf->getPage();
384 if ($pageposafter > $pageposbefore) { // There is a pagebreak
385 $pdf->rollbackTransaction(true);
386 $pageposafter = $pageposbefore;
387 //print $pageposafter.'-'.$pageposbefore;exit;
388 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
389 $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
390 $pageposafter = $pdf->getPage();
391 $posyafter = $pdf->GetY();
392 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
393 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
394 $pdf->AddPage('', '', true);
395 if (!empty($tplidx)) {
396 $pdf->useTemplate($tplidx);
397 }
398 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
399 $this->_pagehead($pdf, $object, 0, $outputlangs);
400 }
401 $pdf->setPage($pageposafter + 1);
402 }
403 } else {
404 // We found a page break
405
406 // Allows data in the first page if description is long enough to break in multiples pages
407 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
408 $showpricebeforepagebreak = 1;
409 } else {
410 $showpricebeforepagebreak = 0;
411 }
412 }
413 } else { // No pagebreak
414 $pdf->commitTransaction();
415 }
416 $posYAfterDescription = $pdf->GetY();
417
418 $nexY = $pdf->GetY() + 2;
419 $pageposafter = $pdf->getPage();
420
421 $pdf->setPage($pageposbefore);
422 $pdf->setTopMargin($this->marge_haute);
423 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
424
425 // We suppose that a too long description is moved completely on next page
426 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
427 $pdf->setPage($pageposafter);
428 $curY = $tab_top_newpage;
429 }
430
431 $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
432
433 // Detect if some page were added automatically and output _tableau for past pages
434 while ($pagenb < $pageposafter) {
435 $pdf->setPage($pagenb);
436 if ($pagenb == 1) {
437 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
438 } else {
439 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
440 }
441 $this->_pagefoot($pdf, $object, $outputlangs, 1);
442 $pagenb++;
443 $pdf->setPage($pagenb);
444 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
445 if (!getDolGlobalString('MAIN_PDF_DONOTREPEAT_HEAD')) {
446 $this->_pagehead($pdf, $object, 0, $outputlangs);
447 }
448 if (!empty($tplidx)) {
449 $pdf->useTemplate($tplidx);
450 }
451 }
452
453 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
454 if ($pagenb == 1) {
455 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
456 } else {
457 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
458 }
459 $this->_pagefoot($pdf, $object, $outputlangs, 1);
460 // New page
461 $pdf->AddPage();
462 if (!empty($tplidx)) {
463 $pdf->useTemplate($tplidx);
464 }
465 $pagenb++;
466 }
467 }
468 }
469
470
471 // Show square
472 if ($pagenb == 1) {
473 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
474 $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
475 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
476 } else {
477 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
478 $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
479 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
480 }
481
482 $this->_pagefoot($pdf, $object, $outputlangs);
483 if (method_exists($pdf, 'AliasNbPages')) {
484 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
485 }
486
487 $pdf->Close();
488
489 $pdf->Output($file, 'F');
490
491 // Add pdfgeneration hook
492 $hookmanager->initHooks(array('pdfgeneration'));
493 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
494 global $action;
495 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
496 if ($reshook < 0) {
497 $this->error = $hookmanager->error;
498 $this->errors = $hookmanager->errors;
499 }
500
501 dolChmod($file);
502
503 $this->result = array('fullpath' => $file);
504
505 return 1; // No error
506 } else {
507 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
508 return 0;
509 }
510 } else {
511 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
512 return 0;
513 }
514 }
515
516 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
529 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
530 {
531 global $conf;
532
533 // Force to disable hidetop and hidebottom
534 $hidebottom = 0;
535 if ($hidetop) {
536 $hidetop = -1;
537 }
538
539 //$default_font_size = pdf_getPDFFontSize($outputlangs);
540
541 /*
542 $pdf->SetXY($this->marge_gauche, $tab_top);
543 $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
544 $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
545
546 $pdf->SetFont('','', $default_font_size - 1);
547
548 $pdf->MultiCell(0, 3, ''); // Set interline to 3
549 $pdf->SetXY($this->marge_gauche, $tab_top + 8);
550 $text=$object->description;
551 if ($object->duree > 0)
552 {
553 $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
554 $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
555 }
556 $desc=dol_htmlentitiesbr($text,1);
557 //print $outputlangs->convToOutputCharset($desc); exit;
558
559 $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
560 $nexY = $pdf->GetY();
561
562 $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
563
564 $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
565 */
566
567 // Output Rect
568 $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
569 }
570
580 protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
581 {
582 $pdf->SetDrawColor(128, 128, 128);
583 $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
584 $posy = $tab_top + $tab_height + 3 + 3;
585
586 if (!getDolGlobalString('CONTRACT_HIDE_MYCOMPANY_SIGNATURE_SECTION_PDF')) {
587 $pdf->SetXY($this->marge_gauche, $posy);
588 $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', 0);
589
590 $pdf->SetXY($this->marge_gauche, $posy + 5);
591 $pdf->RoundedRect($this->marge_gauche, $posy + 5, $posmiddle - $this->marge_gauche - 5, 20, $this->corner_radius, '1234', 'D');
592 }
593
594 if (!getDolGlobalString('CONTRACT_HIDE_THIRPARTY_SIGNATURE_SECTION_PDF')) {
595 $pdf->SetXY($posmiddle + 5, $posy);
596 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->recipient->name), 0, 'L', 0);
597
598 $pdf->SetXY($posmiddle + 5, $posy + 5);
599 $pdf->RoundedRect($posmiddle + 5, $posy + 5, $this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, $this->corner_radius, '1234', 'D');
600 }
601 }
602
603 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
615 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "Contract")
616 {
617 // phpcs:enable
618 global $conf;
619
620 $top_shift = 0;
621
622 $ltrdirection = 'L';
623 if ($outputlangs->trans("DIRECTION") == 'rtl') {
624 $ltrdirection = 'R';
625 }
626
627 // Load traductions files required by page
628 $outputlangs->loadLangs(array("main", "dict", "contract", "companies"));
629
630 $default_font_size = pdf_getPDFFontSize($outputlangs);
631
632 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
633
634 $pdf->SetTextColor(0, 0, 60);
635 $pdf->SetFont('', 'B', $default_font_size + 3);
636
637 $w = 100;
638
639 $posy = $this->marge_haute;
640 $posx = $this->page_largeur - $this->marge_droite - $w;
641
642 $pdf->SetXY($this->marge_gauche, $posy);
643
644 // Logo
645 if (!getDolGlobalString('PDF_DISABLE_MYCOMPANY_LOGO')) {
646 if ($this->emetteur->logo) {
647 $logodir = $conf->mycompany->dir_output;
648 if (getMultidirOutput($object, 'mycompany')) {
649 $logodir = getMultidirOutput($object, 'mycompany');
650 }
651 if (!getDolGlobalString('MAIN_PDF_USE_LARGE_LOGO')) {
652 $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
653 } else {
654 $logo = $logodir.'/logos/'.$this->emetteur->logo;
655 }
656 if (is_readable($logo)) {
657 $height = pdf_getHeightForLogo($logo);
658 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
659 } else {
660 $pdf->SetTextColor(200, 0, 0);
661 $pdf->SetFont('', 'B', $default_font_size - 2);
662 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
663 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
664 }
665 } else {
666 $text = $this->emetteur->name;
667 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
668 }
669 }
670
671 $pdf->SetFont('', 'B', $default_font_size + 3);
672 $pdf->SetXY($posx, $posy);
673 $pdf->SetTextColor(0, 0, 60);
674 $title = $outputlangs->transnoentities($titlekey);
675 $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
676 if ($object->status == $object::STATUS_DRAFT) {
677 $pdf->SetTextColor(128, 0, 0);
678 $title .= ' - '.$outputlangs->transnoentities("NotValidated");
679 }
680 $pdf->MultiCell($w, 3, $title, '', 'R');
681
682 $pdf->SetFont('', 'B', $default_font_size);
683
684 /*
685 $posy += 5;
686 $pdf->SetXY($posx, $posy);
687 $pdf->SetTextColor(0, 0, 60);
688 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
689 */
690
691 $posy += 3;
692 $pdf->SetFont('', '', $default_font_size - 1);
693
694 $posy += 4;
695 $pdf->SetXY($posx, $posy);
696 $pdf->SetTextColor(0, 0, 60);
697 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_contrat, "day", false, $outputlangs, true), '', 'R');
698
699 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
700 $posy += 4;
701 $pdf->SetXY($posx, $posy);
702 $pdf->SetTextColor(0, 0, 60);
703 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
704 }
705
706 if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE') && $object->thirdparty->code_compta_client) {
707 $posy += 4;
708 $pdf->SetXY($posx, $posy);
709 $pdf->SetTextColor(0, 0, 60);
710 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerAccountancyCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_compta_client), '', 'R');
711 }
712
713 if ($showaddress) {
714 // Sender properties
715 $carac_emetteur = '';
716 // Add internal contact of object if defined
717 $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
718 if (count($arrayidcontact) > 0) {
719 $object->fetch_user($arrayidcontact[0]);
720 $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
721 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
722 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
723 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
724 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
725 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
726 $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
727 $carac_emetteur .= "\n";
728 }
729
730 $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
731
732 // Show sender
733 $posy = 42;
734 $posx = $this->marge_gauche;
735 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
736 $posx = $this->page_largeur - $this->marge_droite - 80;
737 }
738 $hautcadre = 40;
739
740 // Show sender frame
741 if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
742 $pdf->SetTextColor(0, 0, 0);
743 $pdf->SetFont('', '', $default_font_size - 2);
744 $pdf->SetXY($posx, $posy - 5);
745 $pdf->SetXY($posx, $posy);
746 $pdf->SetFillColor(230, 230, 230);
747 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
748 $pdf->SetTextColor(0, 0, 60);
749 }
750
751 // Show sender name
752 if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
753 $pdf->SetXY($posx + 2, $posy + 3);
754 $pdf->SetTextColor(0, 0, 60);
755 $pdf->SetFont('', 'B', $default_font_size);
756 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
757 $posy = $pdf->getY();
758 }
759
760 // Show sender information
761 $pdf->SetXY($posx + 2, $posy);
762 $pdf->SetFont('', '', $default_font_size - 1);
763 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
764
765
766 // If CUSTOMER contact defined, we use it
767 $usecontact = false;
768 $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
769 if (count($arrayidcontact) > 0) {
770 $usecontact = true;
771 $result = $object->fetch_contact($arrayidcontact[0]);
772 }
773
774 $this->recipient = $object->thirdparty;
775
776 // Recipient name
777 if ($usecontact && ($object->contact->socid != $object->thirdparty->id) && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT'))) {
778 $thirdparty = $object->contact;
779 } else {
780 $thirdparty = $object->thirdparty;
781 }
782
783 $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
784
785 $mode = 'target';
786 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), ($usecontact ? 1 : 0), $mode, $object);
787
788 // Show recipient
789 $widthrecbox = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
790 if ($this->page_largeur < 210) {
791 $widthrecbox = 84; // To work with US executive format
792 }
793 $posy = getDolGlobalString('MAIN_PDF_USE_ISO_LOCATION') ? 40 : 42;
794 $posy += $top_shift;
795 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
796 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
797 $posx = $this->marge_gauche;
798 }
799
800 // Show recipient frame
801 if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
802 $pdf->SetTextColor(0, 0, 0);
803 $pdf->SetFont('', '', $default_font_size - 2);
804 $pdf->SetXY($posx + 2, $posy - 5);
805 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
806 $pdf->SetTextColor(0, 0, 0);
807 }
808
809 // Show recipient name
810 $pdf->SetXY($posx + 2, $posy + 3);
811 $pdf->SetFont('', 'B', $default_font_size);
812 $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, $ltrdirection);
813
814 $posy = $pdf->getY();
815
816 // Show recipient information
817 $pdf->SetFont('', '', $default_font_size - 1);
818 $pdf->SetXY($posx + 2, $posy);
819 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
820 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
821 }
822
823 $pdf->SetTextColor(0, 0, 0);
824
825 return $top_shift;
826 }
827
828 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
838 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
839 {
840 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
841 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);
842 }
843}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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 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.
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:244
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.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) 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_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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
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:1031
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:733
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
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:438
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:769
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:390
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:150
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:153