dolibarr  20.0.0-beta
pdf_soleil.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 Cédric Salvador <csalvador@gpcsolutions.fr>
8  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  * or see https://www.gnu.org/
24  */
25 
31 require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36 
37 
42 {
46  public $db;
47 
51  public $name;
52 
56  public $description;
57 
61  public $update_main_doc_field;
62 
66  public $type;
67 
72  public $version = 'dolibarr';
73 
74 
80  public function __construct($db)
81  {
82  global $langs, $mysoc;
83 
84  $this->db = $db;
85  $this->name = 'soleil';
86  $this->description = $langs->trans("DocumentModelStandardPDF");
87  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
88 
89  // Page size for A4 format
90  $this->type = 'pdf';
91  $formatarray = pdf_getFormat();
92  $this->page_largeur = $formatarray['width'];
93  $this->page_hauteur = $formatarray['height'];
94  $this->format = array($this->page_largeur, $this->page_hauteur);
95  $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
96  $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
97  $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
98  $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
99 
100  $this->option_logo = 1; // Display logo
101  $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
102  $this->option_modereg = 0; // Display payment mode
103  $this->option_condreg = 0; // Display payment terms
104  $this->option_multilang = 1; // Available in several languages
105  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
106  $this->watermark = '';
107 
108  // Get source company
109  $this->emetteur = $mysoc;
110  if (empty($this->emetteur->country_code)) {
111  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if not defined
112  }
113 
114  // Define position of columns
115  $this->posxdesc = $this->marge_gauche + 1;
116  }
117 
118  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
130  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
131  {
132  // phpcs:enable
133  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
134 
135  if (!is_object($outputlangs)) {
136  $outputlangs = $langs;
137  }
138  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
139  if (getDolGlobalString('MAIN_USE_FPDF')) {
140  $outputlangs->charset_output = 'ISO-8859-1';
141  }
142 
143  // Load traductions files required by page
144  $outputlangs->loadLangs(array("main", "interventions", "dict", "companies"));
145 
146  // Show Draft Watermark
147  if ($object->statut == $object::STATUS_DRAFT && (getDolGlobalString('FICHINTER_DRAFT_WATERMARK'))) {
148  $this->watermark = getDolGlobalString('FICHINTER_DRAFT_WATERMARK');
149  }
150 
151  if ($conf->ficheinter->dir_output) {
152  $object->fetch_thirdparty();
153 
154  // Definition of $dir and $file
155  if ($object->specimen) {
156  $dir = $conf->ficheinter->dir_output;
157  $file = $dir."/SPECIMEN.pdf";
158  } else {
159  $objectref = dol_sanitizeFileName($object->ref);
160  $dir = $conf->ficheinter->dir_output."/".$objectref;
161  $file = $dir."/".$objectref.".pdf";
162  }
163 
164  if (!file_exists($dir)) {
165  if (dol_mkdir($dir) < 0) {
166  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
167  return 0;
168  }
169  }
170 
171  if (file_exists($dir)) {
172  // Add pdfgeneration hook
173  if (!is_object($hookmanager)) {
174  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
175  $hookmanager = new HookManager($this->db);
176  }
177 
178  $hookmanager->initHooks(array('pdfgeneration'));
179  $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
180  global $action;
181  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
182 
183  $nblines = count($object->lines);
184 
185  // Create pdf instance
186  $pdf = pdf_getInstance($this->format);
187  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
188  $heightforinfotot = 50; // Height reserved to output the info and total part
189  $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
190  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
191  if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
192  $heightforfooter += 6;
193  }
194  $pdf->SetAutoPageBreak(1, 0);
195 
196  if (class_exists('TCPDF')) {
197  $pdf->setPrintHeader(false);
198  $pdf->setPrintFooter(false);
199  }
200  $pdf->SetFont(pdf_getPDFFont($outputlangs));
201  // Set path to the background PDF File
202  if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
203  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
204  $tplidx = $pdf->importPage(1);
205  }
206 
207  $pdf->Open();
208  $pagenb = 0;
209  $pdf->SetDrawColor(128, 128, 128);
210 
211  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
212  $pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
213  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
214  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
215  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard"));
216  if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
217  $pdf->SetCompression(false);
218  }
219 
220  // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
221  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
222 
223  // New page
224  $pdf->AddPage();
225  if (!empty($tplidx)) {
226  $pdf->useTemplate($tplidx);
227  }
228  $pagenb++;
229  $this->_pagehead($pdf, $object, 1, $outputlangs);
230  $pdf->SetFont('', '', $default_font_size - 1);
231  $pdf->SetTextColor(0, 0, 0);
232 
233  $tab_top = 90;
234  $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
235 
236  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
237 
238  // Display notes
239  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
240  if ($notetoshow) {
241  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
242  complete_substitutions_array($substitutionarray, $outputlangs, $object);
243  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
244  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
245 
246  $tab_top = 88;
247 
248  $pdf->SetFont('', '', $default_font_size - 1);
249  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
250  $nexY = $pdf->GetY();
251  $height_note = $nexY - $tab_top;
252 
253  // Rect takes a length in 3rd parameter
254  $pdf->SetDrawColor(192, 192, 192);
255  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
256 
257  $tab_height = $tab_height - $height_note;
258  $tab_top = $nexY + 6;
259  } else {
260  $height_note = 0;
261  }
262 
263  $iniY = $tab_top + 7;
264  $curY = $tab_top + 7;
265  $nexY = $tab_top + 7;
266 
267  $pdf->SetXY($this->marge_gauche, $tab_top);
268  $pdf->MultiCell(190, 5, $outputlangs->transnoentities("Description"), 0, 'L', 0);
269  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
270 
271  $pdf->SetFont('', '', $default_font_size - 1);
272 
273  $pdf->SetXY($this->marge_gauche, $tab_top + 5);
274  $text = $object->description;
275  if ($object->duration > 0) {
276  $totaltime = convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
277  $text .= ($text ? ' - ' : '').$langs->trans("Total").": ".$totaltime;
278  }
279  $desc = dol_htmlentitiesbr($text, 1);
280  //print $outputlangs->convToOutputCharset($desc); exit;
281 
282  $pdf->writeHTMLCell(180, 3, 10, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
283  $nexY = $pdf->GetY();
284 
285  $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
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 = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
294  if ($valide > 0 || $object->specimen) {
295  $curY = $nexY;
296  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
297  $pdf->SetTextColor(0, 0, 0);
298 
299  $pdf->setTopMargin($tab_top_newpage);
300  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
301  $pageposbefore = $pdf->getPage();
302 
303  // Description of product line
304  $curX = $this->posxdesc - 1;
305 
306  // Description of product line
307  if (!getDolGlobalString('FICHINTER_DATE_WITHOUT_HOUR')) {
308  $txt = $outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'dayhour', false, $outputlangs, true);
309  } else {
310  $txt = $outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'day', false, $outputlangs, true);
311  }
312 
313  if ($objectligne->duration > 0) {
314  $txt .= " - ".$outputlangs->transnoentities("Duration")." : ".convertSecondToTime($objectligne->duration);
315  }
316  $txt = '<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).'</strong>';
317  $desc = dol_htmlentitiesbr($objectligne->desc, 1);
318 
319  $pdf->startTransaction();
320  $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt, $desc), 0, 1, 0);
321  $pageposafter = $pdf->getPage();
322  if ($pageposafter > $pageposbefore) { // There is a pagebreak
323  $pdf->rollbackTransaction(true);
324  $pageposafter = $pageposbefore;
325  //print $pageposafter.'-'.$pageposbefore;exit;
326  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
327  $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt, $desc), 0, 1, 0);
328  $pageposafter = $pdf->getPage();
329  $posyafter = $pdf->GetY();
330  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
331  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
332  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
333  $pdf->AddPage('', '', true);
334  if (!empty($tplidx)) {
335  $pdf->useTemplate($tplidx);
336  }
337  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
338  $this->_pagehead($pdf, $object, 0, $outputlangs);
339  }
340  $pdf->setPage($pageposafter + 1);
341  }
342  }
343  } else { // No pagebreak
344  $pdf->commitTransaction();
345  }
346 
347  $nexY = $pdf->GetY();
348  $pageposafter = $pdf->getPage();
349  $pdf->setPage($pageposbefore);
350  $pdf->setTopMargin($this->marge_haute);
351  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
352 
353  // We suppose that a too long description is moved completely on next page
354  if ($pageposafter > $pageposbefore) {
355  $pdf->setPage($pageposafter);
356  $curY = $tab_top_newpage;
357  }
358 
359  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
360 
361  // Detect if some page were added automatically and output _tableau for past pages
362  while ($pagenb < $pageposafter) {
363  $pdf->setPage($pagenb);
364  if ($pagenb == 1) {
365  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
366  } else {
367  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
368  }
369  $this->_pagefoot($pdf, $object, $outputlangs, 1);
370  $pagenb++;
371  $pdf->setPage($pagenb);
372  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
373  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
374  $this->_pagehead($pdf, $object, 0, $outputlangs);
375  }
376  if (!empty($tplidx)) {
377  $pdf->useTemplate($tplidx);
378  }
379  }
380  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
381  if ($pagenb == 1) {
382  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
383  } else {
384  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
385  }
386  $this->_pagefoot($pdf, $object, $outputlangs, 1);
387  // New page
388  $pdf->AddPage();
389  if (!empty($tplidx)) {
390  $pdf->useTemplate($tplidx);
391  }
392  $pagenb++;
393  if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
394  $this->_pagehead($pdf, $object, 0, $outputlangs);
395  }
396  }
397  }
398  }
399 
400  // Show square
401  if ($pagenb == 1) {
402  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object);
403  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
404  } else {
405  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object);
406  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
407  }
408 
409  $this->_pagefoot($pdf, $object, $outputlangs);
410  if (method_exists($pdf, 'AliasNbPages')) {
411  $pdf->AliasNbPages();
412  }
413 
414  $pdf->Close();
415  $pdf->Output($file, 'F');
416 
417  // Add pdfgeneration hook
418  $hookmanager->initHooks(array('pdfgeneration'));
419  $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
420  global $action;
421  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
422  if ($reshook < 0) {
423  $this->error = $hookmanager->error;
424  $this->errors = $hookmanager->errors;
425  }
426 
427  dolChmod($file);
428 
429  $this->result = array('fullpath' => $file);
430 
431  return 1;
432  } else {
433  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
434  return 0;
435  }
436  } else {
437  $this->error = $langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR");
438  return 0;
439  }
440  }
441 
442  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
456  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, FichInter $object = null)
457  {
458  global $conf;
459 
460 
461  $default_font_size = pdf_getPDFFontSize($outputlangs);
462  /*
463  $pdf->SetXY($this->marge_gauche, $tab_top);
464  $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
465  $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
466 
467  $pdf->SetFont('','', $default_font_size - 1);
468 
469  $pdf->MultiCell(0, 3, ''); // Set interline to 3
470  $pdf->SetXY($this->marge_gauche, $tab_top + 8);
471  $text=$object->description;
472  if ($object->duration > 0)
473  {
474  $totaltime=convertSecondToTime($object->duration,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
475  $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
476  }
477  $desc=dol_htmlentitiesbr($text,1);
478  //print $outputlangs->convToOutputCharset($desc); exit;
479 
480  $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
481  $nexY = $pdf->GetY();
482 
483  $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
484 
485  $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
486  */
487 
488  // Output Rect
489  $this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height + 1, 0, 0); // Rect takes a length in 3rd parameter and 4th parameter
490 
491  if (empty($hidebottom)) {
492  $employee_name = '';
493  if (!empty($object)) {
494  $arrayidcontact = $object->getIdContact('internal', 'INTERVENING');
495  if (count($arrayidcontact) > 0) {
496  $object->fetch_user($arrayidcontact[0]);
497  $employee_name = $object->user->getFullName($outputlangs);
498  }
499  }
500 
501  $pdf->SetXY(20, 230);
502  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', 0);
503 
504  $pdf->SetXY(20, 235);
505  $pdf->MultiCell(80, 25, $employee_name, 1, 'L');
506 
507  $pdf->SetXY(110, 230);
508  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', 0);
509 
510  $pdf->SetXY(110, 235);
511  $pdf->MultiCell(80, 25, '', 1);
512  }
513  }
514 
515  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
525  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
526  {
527  global $conf, $langs;
528 
529  $default_font_size = pdf_getPDFFontSize($outputlangs);
530 
531  // Load traductions files required by page
532  $outputlangs->loadLangs(array("main", "dict", "companies", "interventions"));
533 
534  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
535 
536  //Prepare next
537  $pdf->SetTextColor(0, 0, 60);
538  $pdf->SetFont('', 'B', $default_font_size + 3);
539 
540  $posx = $this->page_largeur - $this->marge_droite - 100;
541  $posy = $this->marge_haute;
542 
543  $pdf->SetXY($this->marge_gauche, $posy);
544 
545  // Logo
546  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
547  if ($this->emetteur->logo) {
548  if (is_readable($logo)) {
549  $height = pdf_getHeightForLogo($logo);
550  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
551  } else {
552  $pdf->SetTextColor(200, 0, 0);
553  $pdf->SetFont('', 'B', $default_font_size - 2);
554  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
555  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
556  }
557  } else {
558  $text = $this->emetteur->name;
559  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
560  }
561 
562  $pdf->SetFont('', 'B', $default_font_size + 3);
563  $pdf->SetXY($posx, $posy);
564  $pdf->SetTextColor(0, 0, 60);
565  $title = $outputlangs->transnoentities("InterventionCard");
566  $pdf->MultiCell(100, 4, $title, '', 'R');
567 
568  $pdf->SetFont('', 'B', $default_font_size + 2);
569 
570  $posy += 5;
571  $pdf->SetXY($posx, $posy);
572  $pdf->SetTextColor(0, 0, 60);
573  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
574 
575  $posy += 1;
576  $pdf->SetFont('', '', $default_font_size);
577 
578  $posy += 4;
579  $pdf->SetXY($posx, $posy);
580  $pdf->SetTextColor(0, 0, 60);
581  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->datec, "day", false, $outputlangs, true), '', 'R');
582 
583  if (!empty($object->ref_client)) {
584  $posy += 4;
585  $pdf->SetXY($posx, $posy);
586  $pdf->SetTextColor(0, 0, 60);
587  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer") . " : " . dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
588  }
589 
590 
591  if (!getDolGlobalString('MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
592  $posy += 4;
593  $pdf->SetXY($posx, $posy);
594  $pdf->SetTextColor(0, 0, 60);
595  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
596  }
597 
598  if ($showaddress) {
599  // Sender properties
600  $carac_emetteur = '';
601  // Add internal contact of object if defined
602  $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
603  if (count($arrayidcontact) > 0) {
604  $object->fetch_user($arrayidcontact[0]);
605  $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
606  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname.": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
607  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ' (' : '';
608  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : '';
609  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') && getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ', ' : '';
610  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : '';
611  $carac_emetteur .= (getDolGlobalInt('PDF_SHOW_PHONE_AFTER_USER_CONTACT') || getDolGlobalInt('PDF_SHOW_EMAIL_AFTER_USER_CONTACT')) ? ')' : '';
612  $carac_emetteur .= "\n";
613  }
614 
615  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
616 
617  // Show sender
618  $posy = 42;
619  $posx = $this->marge_gauche;
620  if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
621  $posx = $this->page_largeur - $this->marge_droite - 80;
622  }
623  $hautcadre = 40;
624 
625  // Show sender frame
626  if (!getDolGlobalString('MAIN_PDF_NO_SENDER_FRAME')) {
627  $pdf->SetTextColor(0, 0, 0);
628  $pdf->SetFont('', '', $default_font_size - 2);
629  $pdf->SetXY($posx, $posy - 5);
630  $pdf->SetXY($posx, $posy);
631  $pdf->SetFillColor(230, 230, 230);
632  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
633  }
634 
635  // Show sender name
636  if (!getDolGlobalString('MAIN_PDF_HIDE_SENDER_NAME')) {
637  $pdf->SetXY($posx + 2, $posy + 3);
638  $pdf->SetTextColor(0, 0, 60);
639  $pdf->SetFont('', 'B', $default_font_size);
640  $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
641  $posy = $pdf->getY();
642  }
643 
644  // Show sender information
645  $pdf->SetFont('', '', $default_font_size - 1);
646  $pdf->SetXY($posx + 2, $posy);
647  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
648 
649 
650  // If CUSTOMER contact defined, we use it
651  $usecontact = false;
652  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
653  if (count($arrayidcontact) > 0) {
654  $usecontact = true;
655  $result = $object->fetch_contact($arrayidcontact[0]);
656  }
657 
658  // Recipient name
659  if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || getDolGlobalString('MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
660  $thirdparty = $object->contact;
661  } else {
662  $thirdparty = $object->thirdparty;
663  }
664 
665  $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
666 
667  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), $usecontact, 'target', $object);
668 
669  // Show recipient
670  $widthrecbox = 100;
671  if ($this->page_largeur < 210) {
672  $widthrecbox = 84; // To work with US executive format
673  }
674  $posy = 42;
675  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
676  if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
677  $posx = $this->marge_gauche;
678  }
679 
680  // Show recipient frame
681  if (!getDolGlobalString('MAIN_PDF_NO_RECIPENT_FRAME')) {
682  $pdf->SetTextColor(0, 0, 0);
683  $pdf->SetFont('', '', $default_font_size - 2);
684  $pdf->SetXY($posx + 2, $posy - 5);
685  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
686  $pdf->SetTextColor(0, 0, 0);
687  }
688 
689  // Show recipient name
690  $pdf->SetXY($posx + 2, $posy + 3);
691  $pdf->SetFont('', 'B', $default_font_size);
692  $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
693 
694  $posy = $pdf->getY();
695 
696  // Show recipient information
697  $pdf->SetFont('', '', $default_font_size - 1);
698  $pdf->SetXY($posx + 2, $posy);
699  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
700  }
701 
702  return 0;
703  }
704 
705  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
715  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
716  {
717  $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
718  return pdf_pagefoot($pdf, $outputlangs, 'FICHINTER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
719  }
720 }
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 build interventions documents with model Soleil.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, FichInter $object=null)
Show table for lines.
__construct($db)
Constructor.
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(".$version.") pid 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...
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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_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:123
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:126