dolibarr  16.0.5
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-2020 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  *
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/contract/modules_contract.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.'/product/class/product.class.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 $phpmin = array(5, 6);
73 
78  public $version = 'dolibarr';
79 
83  public $page_largeur;
84 
88  public $page_hauteur;
89 
93  public $format;
94 
98  public $marge_gauche;
99 
103  public $marge_droite;
104 
108  public $marge_haute;
109 
113  public $marge_basse;
114 
119  public $emetteur;
120 
125  public $recipient;
126 
132  public function __construct($db)
133  {
134  global $conf, $langs, $mysoc;
135 
136  $this->db = $db;
137  $this->name = 'strato';
138  $this->description = $langs->trans("StandardContractsTemplate");
139  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
140 
141  // Page size for A4 format
142  $this->type = 'pdf';
143  $formatarray = pdf_getFormat();
144 
145  $this->page_largeur = $formatarray['width'];
146  $this->page_hauteur = $formatarray['height'];
147  $this->format = array($this->page_largeur, $this->page_hauteur);
148  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
149  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
150  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
151  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
152 
153  $this->option_logo = 1; // Display logo
154  $this->option_tva = 0; // Manage the vat option FACTURE_TVAOPTION
155  $this->option_modereg = 0; // Display payment mode
156  $this->option_condreg = 0; // Display payment terms
157  $this->option_multilang = 0; // Available in several languages
158  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
159 
160  // Get source company
161  $this->emetteur = $mysoc;
162  if (empty($this->emetteur->country_code)) {
163  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if not defined
164  }
165 
166  // Define position of columns
167  $this->posxdesc = $this->marge_gauche + 1;
168  }
169 
170  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
182  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
183  {
184  // phpcs:enable
185  global $user, $langs, $conf, $hookmanager, $mysoc;
186 
187  if (!is_object($outputlangs)) {
188  $outputlangs = $langs;
189  }
190  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
191  if (!empty($conf->global->MAIN_USE_FPDF)) {
192  $outputlangs->charset_output = 'ISO-8859-1';
193  }
194 
195  // Load traductions files required by page
196  $outputlangs->loadLangs(array("main", "dict", "companies", "contracts"));
197 
198  if ($conf->contrat->dir_output) {
199  $object->fetch_thirdparty();
200 
201  // Definition of $dir and $file
202  if ($object->specimen) {
203  $dir = $conf->contrat->dir_output;
204  $file = $dir."/SPECIMEN.pdf";
205  } else {
206  $objectref = dol_sanitizeFileName($object->ref);
207  $dir = $conf->contrat->multidir_output[$object->entity]."/".$objectref;
208  $file = $dir."/".$objectref.".pdf";
209  }
210 
211  if (!file_exists($dir)) {
212  if (dol_mkdir($dir) < 0) {
213  $this->error = $outputlangs->trans("ErrorCanNotCreateDir", $dir);
214  return 0;
215  }
216  }
217 
218  if (file_exists($dir)) {
219  // Add pdfgeneration hook
220  if (!is_object($hookmanager)) {
221  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
222  $hookmanager = new HookManager($this->db);
223  }
224  $hookmanager->initHooks(array('pdfgeneration'));
225  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
226  global $action;
227  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
228 
229  $pdf = pdf_getInstance($this->format);
230  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
231  $heightforinfotot = 50; // Height reserved to output the info and total part
232  $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
233  $heightforfooter = $this->marge_basse + 9; // Height reserved to output the footer (value include bottom margin)
234  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
235  $heightforfooter += 6;
236  }
237  $pdf->SetAutoPageBreak(1, 0);
238 
239  if (class_exists('TCPDF')) {
240  $pdf->setPrintHeader(false);
241  $pdf->setPrintFooter(false);
242  }
243  $pdf->SetFont(pdf_getPDFFont($outputlangs));
244  // Set path to the background PDF File
245  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
246  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
247  $tplidx = $pdf->importPage(1);
248  }
249 
250  $pdf->Open();
251  $pagenb = 0;
252  $pdf->SetDrawColor(128, 128, 128);
253 
254  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
255  $pdf->SetSubject($outputlangs->transnoentities("ContractCard"));
256  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
257  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
258  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("ContractCard")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
259  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
260  $pdf->SetCompression(false);
261  }
262 
263  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
264 
265  // New page
266  $pdf->AddPage();
267  if (!empty($tplidx)) {
268  $pdf->useTemplate($tplidx);
269  }
270  $pagenb++;
271  $this->_pagehead($pdf, $object, 1, $outputlangs);
272  $pdf->SetFont('', '', $default_font_size - 1);
273  $pdf->MultiCell(0, 3, ''); // Set interline to 3
274  $pdf->SetTextColor(0, 0, 0);
275 
276  $tab_top = 90;
277  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10);
278 
279  // Display notes
280  if (!empty($object->note_public)) {
281  $tab_top -= 2;
282 
283  $pdf->SetFont('', '', $default_font_size - 1);
284  $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($object->note_public), 0, 1);
285  $nexY = $pdf->GetY();
286  $height_note = $nexY - $tab_top;
287 
288  // Rect takes a length in 3rd parameter
289  $pdf->SetDrawColor(192, 192, 192);
290  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
291 
292  $tab_top = $nexY + 6;
293  }
294 
295  $iniY = $tab_top + 7;
296  $curY = $tab_top + 7;
297  $nexY = $tab_top + 2;
298 
299  $pdf->SetXY($this->marge_gauche, $tab_top);
300 
301  $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
302 
303  $nblines = count($object->lines);
304 
305  // Loop on each lines
306  for ($i = 0; $i < $nblines; $i++) {
307  $objectligne = $object->lines[$i];
308 
309  $valide = $objectligne->id ? 1 : 0;
310 
311  if ($valide > 0 || $object->specimen) {
312  $curX = $this->posxdesc - 1;
313  $curY = $nexY;
314  $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
315  $pdf->SetTextColor(0, 0, 0);
316 
317  $pdf->setTopMargin($tab_top_newpage);
318  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
319  $pageposbefore = $pdf->getPage();
320 
321  // Description of product line
322 
323  if (!empty($objectligne->date_start)) {
324  $datei = dol_print_date((int) $objectligne->date_start, 'day', false, $outputlangs, true);
325  } else {
326  $datei = $langs->trans("Unknown");
327  }
328 
329  if (!empty($objectligne->date_end)) {
330  $durationi = convertSecondToTime((int) $objectligne->date_end - (int) $objectligne->date_start, 'allwithouthour');
331  $datee = dol_print_date($objectligne->date_end, 'day', false, $outputlangs, true);
332  } else {
333  $durationi = $langs->trans("Unknown");
334  $datee = $langs->trans("Unknown");
335  }
336 
337  if (!empty($objectligne->date_start_real)) {
338  $daters = dol_print_date((int) $objectligne->date_start_real, 'day', false, $outputlangs, true);
339  } else {
340  $daters = $langs->trans("Unknown");
341  }
342 
343  if (!empty($objectligne->date_end_real)) {
344  $datere = dol_print_date((int) $objectligne->date_end_real, 'day', false, $outputlangs, true);
345  } else {
346  $datere = $langs->trans("Unknown");
347  }
348 
349  $txtpredefinedservice = $objectligne->product_ref;
350  if ($objectligne->product_label) {
351  $txtpredefinedservice .= ' - ';
352  $txtpredefinedservice .= $objectligne->product_label;
353  }
354 
355  $desc = dol_htmlentitiesbr($objectligne->desc, 1); // Desc (not empty for free lines)
356  $txt = '';
357  if (empty($conf->global->CONTRACT_HIDE_QTY_ON_PDF)) {
358  $txt .= $outputlangs->transnoentities("Quantity") . ' : <strong>' . $objectligne->qty . '</strong>';
359  }
360  if (empty($conf->global->CONTRACT_HIDE_PRICE_ON_PDF)) {
361  $txt .= ' - ' . $outputlangs->transnoentities("UnitPrice") . ' : <strong>' . price($objectligne->subprice) . '</strong>';
362  }
363  if (empty($conf->global->CONTRACT_HIDE_PLANNED_DATE_ON_PDF)) {
364  $txt .= '<br>';
365  $txt .= $outputlangs->transnoentities("DateStartPlannedShort")." : <strong>".$datei."</strong> - ".$outputlangs->transnoentities("DateEndPlanned")." : <strong>".$datee.'</strong>';
366  }
367  if (empty($conf->global->CONTRACT_HIDE_REAL_DATE_ON_PDF)) {
368  $txt .= '<br>';
369  $txt .= $outputlangs->transnoentities("DateStartRealShort")." : <strong>".$daters.'</strong>';
370  if (!empty($objectligne->date_end_real)) {
371  $txt .= " - ".$outputlangs->transnoentities("DateEndRealShort")." : '<strong>'".$datere.'</strong>';
372  }
373  }
374 
375  $pdf->startTransaction();
376  $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
377  $pageposafter = $pdf->getPage();
378  if ($pageposafter > $pageposbefore) { // There is a pagebreak
379  $pdf->rollbackTransaction(true);
380  $pageposafter = $pageposbefore;
381  //print $pageposafter.'-'.$pageposbefore;exit;
382  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
383  $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txtpredefinedservice, dol_concatdesc($txt, $desc)), 0, 1, 0);
384  $pageposafter = $pdf->getPage();
385  $posyafter = $pdf->GetY();
386  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
387  if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
388  $pdf->AddPage('', '', true);
389  if (!empty($tplidx)) {
390  $pdf->useTemplate($tplidx);
391  }
392  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
393  $this->_pagehead($pdf, $object, 0, $outputlangs);
394  }
395  $pdf->setPage($pageposafter + 1);
396  }
397  } else {
398  // We found a page break
399 
400  // Allows data in the first page if description is long enough to break in multiples pages
401  if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
402  $showpricebeforepagebreak = 1;
403  } else {
404  $showpricebeforepagebreak = 0;
405  }
406  }
407  } else // No pagebreak
408  {
409  $pdf->commitTransaction();
410  }
411 
412  $nexY = $pdf->GetY() + 2;
413  $pageposafter = $pdf->getPage();
414 
415  $pdf->setPage($pageposbefore);
416  $pdf->setTopMargin($this->marge_haute);
417  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
418 
419  // We suppose that a too long description is moved completely on next page
420  if ($pageposafter > $pageposbefore) {
421  $pdf->setPage($pageposafter);
422  $curY = $tab_top_newpage;
423  }
424 
425  $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
426 
427  // Detect if some page were added automatically and output _tableau for past pages
428  while ($pagenb < $pageposafter) {
429  $pdf->setPage($pagenb);
430  if ($pagenb == 1) {
431  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
432  } else {
433  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
434  }
435  $this->_pagefoot($pdf, $object, $outputlangs, 1);
436  $pagenb++;
437  $pdf->setPage($pagenb);
438  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
439  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
440  $this->_pagehead($pdf, $object, 0, $outputlangs);
441  }
442  if (!empty($tplidx)) {
443  $pdf->useTemplate($tplidx);
444  }
445  }
446 
447  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
448  if ($pagenb == 1) {
449  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext, 0, $outputlangs, 0, 1);
450  } else {
451  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1, 1);
452  }
453  $this->_pagefoot($pdf, $object, $outputlangs, 1);
454  // New page
455  $pdf->AddPage();
456  if (!empty($tplidx)) {
457  $pdf->useTemplate($tplidx);
458  }
459  $pagenb++;
460  }
461  }
462  }
463 
464 
465  // Show square
466  if ($pagenb == 1) {
467  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
468  $this->tabSignature($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
469  $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
470  } else {
471  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
472  $this->tabSignature($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, $outputlangs);
473  $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
474  }
475 
476  $this->_pagefoot($pdf, $object, $outputlangs);
477  if (method_exists($pdf, 'AliasNbPages')) {
478  $pdf->AliasNbPages();
479  }
480 
481  $pdf->Close();
482 
483  $pdf->Output($file, 'F');
484 
485  // Add pdfgeneration hook
486  if (!is_object($hookmanager)) {
487  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
488  $hookmanager = new HookManager($this->db);
489  }
490  $hookmanager->initHooks(array('pdfgeneration'));
491  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
492  global $action;
493  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
494  if ($reshook < 0) {
495  $this->error = $hookmanager->error;
496  $this->errors = $hookmanager->errors;
497  }
498 
499  if (!empty($conf->global->MAIN_UMASK)) {
500  @chmod($file, octdec($conf->global->MAIN_UMASK));
501  }
502 
503  $this->result = array('fullpath'=>$file);
504 
505  return 1;
506  } else {
507  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
508  return 0;
509  }
510  } else {
511  $this->error = $langs->trans("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
512  return 0;
513  }
514  }
515 
516  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
529  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
530  {
531  global $conf;
532 
533  // Force to disable hidetop and hidebottom
534  $hidebottom = 0;
535  if ($hidetop) {
536  $hidetop = -1;
537  }
538 
539  $default_font_size = pdf_getPDFFontSize($outputlangs);
540  /*
541  $pdf->SetXY($this->marge_gauche, $tab_top);
542  $pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
543  $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
544 
545  $pdf->SetFont('','', $default_font_size - 1);
546 
547  $pdf->MultiCell(0, 3, ''); // Set interline to 3
548  $pdf->SetXY($this->marge_gauche, $tab_top + 8);
549  $text=$object->description;
550  if ($object->duree > 0)
551  {
552  $totaltime=convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
553  $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
554  }
555  $desc=dol_htmlentitiesbr($text,1);
556  //print $outputlangs->convToOutputCharset($desc); exit;
557 
558  $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
559  $nexY = $pdf->GetY();
560 
561  $pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
562 
563  $pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
564  */
565 
566  // Output Rect
567  $this->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
568  }
569 
578  protected function tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
579  {
580  $pdf->SetDrawColor(128, 128, 128);
581  $posmiddle = $this->marge_gauche + round(($this->page_largeur - $this->marge_gauche - $this->marge_droite) / 2);
582  $posy = $tab_top + $tab_height + 3 + 3;
583 
584  $pdf->SetXY($this->marge_gauche, $posy);
585  $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->emetteur->name), 0, 'L', 0);
586 
587  $pdf->SetXY($this->marge_gauche, $posy + 5);
588  $pdf->MultiCell($posmiddle - $this->marge_gauche - 5, 20, '', 1);
589 
590  $pdf->SetXY($posmiddle + 5, $posy);
591  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 5, $outputlangs->transnoentities("ContactNameAndSignature", $this->recipient->name), 0, 'L', 0);
592 
593  $pdf->SetXY($posmiddle + 5, $posy + 5);
594  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posmiddle - 5, 20, '', 1);
595  }
596 
597  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
607  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
608  {
609  global $conf, $langs;
610 
611  $default_font_size = pdf_getPDFFontSize($outputlangs);
612 
613  // Load traductions files required by page
614  $outputlangs->loadLangs(array("main", "dict", "contract", "companies"));
615 
616  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
617 
618  //Affiche le filigrane brouillon - Print Draft Watermark
619  if ($object->statut == 0 && (!empty($conf->global->CONTRACT_DRAFT_WATERMARK))) {
620  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->CONTRACT_DRAFT_WATERMARK);
621  }
622 
623  //Prepare next
624  $pdf->SetTextColor(0, 0, 60);
625  $pdf->SetFont('', 'B', $default_font_size + 3);
626 
627  $posx = $this->page_largeur - $this->marge_droite - 100;
628  $posy = $this->marge_haute;
629 
630  $pdf->SetXY($this->marge_gauche, $posy);
631 
632  // Logo
633  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
634  if ($this->emetteur->logo) {
635  if (is_readable($logo)) {
636  $height = pdf_getHeightForLogo($logo);
637  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
638  } else {
639  $pdf->SetTextColor(200, 0, 0);
640  $pdf->SetFont('', 'B', $default_font_size - 2);
641  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
642  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
643  }
644  } else {
645  $text = $this->emetteur->name;
646  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
647  }
648 
649  $pdf->SetFont('', 'B', $default_font_size + 3);
650  $pdf->SetXY($posx, $posy);
651  $pdf->SetTextColor(0, 0, 60);
652  $title = $outputlangs->transnoentities("ContractCard");
653  $pdf->MultiCell(100, 4, $title, '', 'R');
654 
655  $pdf->SetFont('', 'B', $default_font_size + 2);
656 
657  $posy += 5;
658  $pdf->SetXY($posx, $posy);
659  $pdf->SetTextColor(0, 0, 60);
660  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
661 
662  $posy += 1;
663  $pdf->SetFont('', '', $default_font_size);
664 
665  $posy += 4;
666  $pdf->SetXY($posx, $posy);
667  $pdf->SetTextColor(0, 0, 60);
668  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_contrat, "day", false, $outputlangs, true), '', 'R');
669 
670  if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
671  $posy += 4;
672  $pdf->SetXY($posx, $posy);
673  $pdf->SetTextColor(0, 0, 60);
674  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
675  }
676 
677  if ($showaddress) {
678  // Sender properties
679  $carac_emetteur = '';
680  // Add internal contact of proposal if defined
681  $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
682  if (count($arrayidcontact) > 0) {
683  $object->fetch_user($arrayidcontact[0]);
684  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
685  }
686 
687  $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
688 
689  // Show sender
690  $posy = 42;
691  $posx = $this->marge_gauche;
692  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
693  $posx = $this->page_largeur - $this->marge_droite - 80;
694  }
695  $hautcadre = 40;
696 
697  // Show sender frame
698  if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
699  $pdf->SetTextColor(0, 0, 0);
700  $pdf->SetFont('', '', $default_font_size - 2);
701  $pdf->SetXY($posx, $posy - 5);
702  $pdf->SetXY($posx, $posy);
703  $pdf->SetFillColor(230, 230, 230);
704  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
705  }
706 
707  // Show sender name
708  if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
709  $pdf->SetXY($posx + 2, $posy + 3);
710  $pdf->SetTextColor(0, 0, 60);
711  $pdf->SetFont('', 'B', $default_font_size);
712  $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
713  $posy = $pdf->getY();
714  }
715 
716  // Show sender information
717  $pdf->SetFont('', '', $default_font_size - 1);
718  $pdf->SetXY($posx + 2, $posy);
719  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
720 
721 
722  // If CUSTOMER contact defined, we use it
723  $usecontact = false;
724  $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
725  if (count($arrayidcontact) > 0) {
726  $usecontact = true;
727  $result = $object->fetch_contact($arrayidcontact[0]);
728  }
729 
730  $this->recipient = $object->thirdparty;
731 
732  // Recipient name
733  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)))) {
734  $thirdparty = $object->contact;
735  } else {
736  $thirdparty = $object->thirdparty;
737  }
738 
739  $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
740 
741  $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : ''), $usecontact, 'target', $object);
742 
743  // Show recipient
744  $widthrecbox = 100;
745  if ($this->page_largeur < 210) {
746  $widthrecbox = 84; // To work with US executive format
747  }
748  $posy = 42;
749  $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
750  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
751  $posx = $this->marge_gauche;
752  }
753 
754  // Show recipient frame
755  if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
756  $pdf->SetTextColor(0, 0, 0);
757  $pdf->SetFont('', '', $default_font_size - 2);
758  $pdf->SetXY($posx + 2, $posy - 5);
759  $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
760  $pdf->SetTextColor(0, 0, 0);
761  }
762 
763  // Show recipient name
764  $pdf->SetXY($posx + 2, $posy + 3);
765  $pdf->SetFont('', 'B', $default_font_size);
766  $pdf->MultiCell($widthrecbox, 4, $this->recipient->name, 0, 'L');
767 
768  $posy = $pdf->getY();
769 
770  // Show recipient information
771  $pdf->SetFont('', '', $default_font_size - 1);
772  $pdf->SetXY($posx + 2, $posy);
773  $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
774  }
775  }
776 
777  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
787  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
788  {
789  global $conf;
790  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
791  return pdf_pagefoot($pdf, $outputlangs, 'CONTRACT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
792  }
793 }
db
$conf db
API class for accounts.
Definition: inc.php:41
pdf_strato\write_file
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Definition: pdf_strato.modules.php:182
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_strato\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
Definition: pdf_strato.modules.php:529
pdf_strato\__construct
__construct($db)
Constructor.
Definition: pdf_strato.modules.php:132
pdf_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_strato
Class to build contracts documents with model Strato.
Definition: pdf_strato.modules.php:41
name
$conf db name
Definition: repair.php:122
convertSecondToTime
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:236
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_concatdesc
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...
Definition: functions.lib.php:7248
pdfBuildThirdpartyName
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition: pdf.lib.php:386
pdf_pagehead
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:711
pdf_strato\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_strato.modules.php:787
pdf_watermark
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:757
pdf_getHeightForLogo
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
CommonDocGenerator\printRect
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Definition: commondocgenerator.class.php:977
pdf_build_address
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:427
ModelePDFContract
Parent class to manage intervention document templates.
Definition: modules_contract.php:38
pdf_strato\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_strato.modules.php:607
dol_htmlentitiesbr
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...
Definition: functions.lib.php:6991
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
price
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.
Definition: functions.lib.php:5541
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
pdf_strato\tabSignature
tabSignature(&$pdf, $tab_top, $tab_height, $outputlangs)
Show footer signature of page.
Definition: pdf_strato.modules.php:578
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
pdf_pagefoot
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:989