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