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