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