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