dolibarr  9.0.0
pdf_standard.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
4  * Copyright (C) 2016-2018 Philippe Grand <philippe.grand@atoo-net.com>
5  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  * or see http://www.gnu.org/
20  */
21 
28 require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
29 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 
35 
36 
41 {
45  public $db;
46 
50  public $name;
51 
55  public $description;
56 
60  public $type;
61 
66  public $phpmin = array(5, 4);
67 
72  public $version = 'dolibarr';
73 
77  public $page_largeur;
78 
82  public $page_hauteur;
83 
87  public $format;
88 
92  public $marge_gauche;
93 
97  public $marge_droite;
98 
102  public $marge_haute;
103 
107  public $marge_basse;
108 
113  public $emetteur;
114 
115 
121  function __construct($db)
122  {
123  global $conf, $langs, $mysoc;
124 
125  // Translations
126  $langs->loadLangs(array("main", "trips", "projects"));
127 
128  $this->db = $db;
129  $this->name = "";
130  $this->description = $langs->trans('PDFStandardExpenseReports');
131 
132  // Dimension page pour format A4
133  $this->type = 'pdf';
134  $formatarray=pdf_getFormat();
135  $this->page_largeur = $formatarray['width'];
136  $this->page_hauteur = $formatarray['height'];
137  $this->format = array($this->page_largeur,$this->page_hauteur);
138  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
139  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
140  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
141  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
142 
143  $this->option_logo = 1; // Affiche logo
144  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
145  $this->option_modereg = 1; // Affiche mode reglement
146  $this->option_condreg = 1; // Affiche conditions reglement
147  $this->option_codeproduitservice = 1; // Affiche code produit-service
148  $this->option_multilang = 1; // Dispo en plusieurs langues
149  $this->option_escompte = 0; // Affiche si il y a eu escompte
150  $this->option_credit_note = 0; // Support credit notes
151  $this->option_freetext = 1; // Support add of a personalised text
152  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
153 
154  $this->franchise = !$mysoc->tva_assuj;
155 
156  // Get source company
157  $this->emetteur=$mysoc;
158  if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
159 
160  // Define position of columns
161  $this->posxpiece=$this->marge_gauche+1;
162  $this->posxcomment=$this->marge_gauche+10;
163  //$this->posxdate=88;
164  //$this->posxtype=107;
165  //$this->posxprojet=120;
166  $this->posxtva=130;
167  $this->posxup=145;
168  $this->posxqty=168;
169  $this->postotalttc=178;
170  // if (empty($conf->projet->enabled)) {
171  // $this->posxtva-=20;
172  // $this->posxup-=20;
173  // $this->posxqty-=20;
174  // $this->postotalttc-=20;
175  // }
176  if ($this->page_largeur < 210) // To work with US executive format
177  {
178  $this->posxdate-=20;
179  $this->posxtype-=20;
180  $this->posxprojet-=20;
181  $this->posxtva-=20;
182  $this->posxup-=20;
183  $this->posxqty-=20;
184  $this->postotalttc-=20;
185  }
186 
187  $this->tva=array();
188  $this->localtax1=array();
189  $this->localtax2=array();
190  $this->atleastoneratenotnull=0;
191  }
192 
193 
194  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
206  function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
207  {
208  // phpcs:enable
209  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
210 
211  if (! is_object($outputlangs)) $outputlangs=$langs;
212  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
213  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
214 
215  // Load traductions files requiredby by page
216  $outputlangs->loadLangs(array("main", "trips", "projects", "dict"));
217 
218  $nblignes = count($object->lines);
219 
220  if ($conf->expensereport->dir_output) {
221  // Definition of $dir and $file
222  if ($object->specimen) {
223  $dir = $conf->expensereport->dir_output;
224  $file = $dir . "/SPECIMEN.pdf";
225  }
226  else
227  {
228  $objectref = dol_sanitizeFileName($object->ref);
229  $dir = $conf->expensereport->dir_output . "/" . $objectref;
230  $file = $dir . "/" . $objectref . ".pdf";
231  }
232 
233  if (! file_exists($dir))
234  {
235  if (dol_mkdir($dir) < 0)
236  {
237  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
238  return 0;
239  }
240  }
241 
242  if (file_exists($dir))
243  {
244  // Add pdfgeneration hook
245  if (! is_object($hookmanager))
246  {
247  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
248  $hookmanager=new HookManager($this->db);
249  }
250  $hookmanager->initHooks(array('pdfgeneration'));
251  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
252  global $action;
253  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
254 
255  // Create pdf instance
256  $pdf=pdf_getInstance($this->format);
257  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
258  $heightforinfotot = 40; // Height reserved to output the info and total part
259  $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
260  $heightforfooter = $this->marge_basse + 12; // Height reserved to output the footer (value include bottom margin)
261  if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
262 
263  $pdf->SetAutoPageBreak(1,0);
264 
265  if (class_exists('TCPDF'))
266  {
267  $pdf->setPrintHeader(false);
268  $pdf->setPrintFooter(false);
269  }
270  $pdf->SetFont(pdf_getPDFFont($outputlangs));
271  // Set path to the background PDF File
272  if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
273  {
274  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
275  $tplidx = $pdf->importPage(1);
276  }
277 
278  $pdf->Open();
279  $pagenb=0;
280  $pdf->SetDrawColor(128,128,128);
281 
282  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
283  $pdf->SetSubject($outputlangs->transnoentities("Trips"));
284  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
285  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
286  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Trips"));
287  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
288 
289  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
290 
291  // New page
292  $pdf->AddPage();
293  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
294  $pagenb++;
295  $this->_pagehead($pdf, $object, 1, $outputlangs);
296  $pdf->SetFont('','', $default_font_size - 1);
297  $pdf->MultiCell(0, 3, ''); // Set interline to 3
298  $pdf->SetTextColor(0,0,0);
299 
300  $tab_top = 95;
301  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?65:10);
302  $tab_height = 130;
303  $tab_height_newpage = 150;
304 
305  // Show notes
306  $notetoshow=empty($object->note_public)?'':$object->note_public;
307  if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
308  {
309  // Get first sale rep
310  if (is_object($object->thirdparty))
311  {
312  $salereparray=$object->thirdparty->getSalesRepresentatives($user);
313  $salerepobj=new User($this->db);
314  $salerepobj->fetch($salereparray[0]['id']);
315  if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
316  }
317  }
318  if ($notetoshow)
319  {
320  $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
321  complete_substitutions_array($substitutionarray, $outputlangs, $object);
322  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
323 
324  $tab_top = 95;
325 
326  $pdf->SetFont('','', $default_font_size - 1);
327  $pdf->writeHTMLCell(190, 3, $this->posxpiece-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
328  $nexY = $pdf->GetY();
329  $height_note=$nexY-$tab_top;
330 
331  // Rect prend une longueur en 3eme param
332  $pdf->SetDrawColor(192,192,192);
333  $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
334 
335  $tab_height = $tab_height - $height_note;
336  $tab_top = $nexY+6;
337  }
338  else
339  {
340  $height_note=0;
341  }
342 
343  $iniY = $tab_top + 7;
344  $initialY = $tab_top + 7;
345  $nexY = $tab_top + 7;
346 
347  // Loop on each lines
348  for ($i = 0 ; $i < $nblignes ; $i++) {
349  $pdf->SetFont('','', $default_font_size - 2); // Into loop to work with multipage
350  $pdf->SetTextColor(0,0,0);
351 
352  $pdf->setTopMargin($tab_top_newpage);
353  $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
354  $pageposbefore = $pdf->getPage();
355  $curY = $nexY;
356  $pdf->startTransaction();
357  $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
358  $pageposafter=$pdf->getPage();
359  if ($pageposafter > $pageposbefore) {
360  // 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  $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
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))) {
370  // There is no space left for total+free text
371  if ($i == ($nblignes-1)) {
372  // No more lines, and no space left to show total, so we create a new page
373  $pdf->AddPage('', '', true);
374  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
375  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
376  $pdf->setPage($pageposafter+1);
377  }
378  }
379  else
380  {
381  // We found a page break
382  $showpricebeforepagebreak=0;
383  }
384  }
385  else // No pagebreak
386  {
387  $pdf->commitTransaction();
388  }
389  //nexY
390  $nexY = $pdf->GetY();
391  $pageposafter=$pdf->getPage();
392  $pdf->setPage($pageposbefore);
393  $pdf->setTopMargin($this->marge_haute);
394  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
395 
396  //$nblineFollowComment = 1;
397  // Cherche nombre de lignes a venir pour savoir si place suffisante
398  // if ($i < ($nblignes - 1)) // If it's not last line
399  // {
400  // //Fetch current description to know on which line the next one should be placed
401  // $follow_comment = $object->lines[$i]->comments;
402  // $follow_type = $object->lines[$i]->type_fees_code;
403 
404  // //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
405  // $nbLineCommentNeed = dol_nboflines_bis($follow_comment,52,$outputlangs->charset_output);
406  // $nbLineTypeNeed = dol_nboflines_bis($follow_type,4,$outputlangs->charset_output);
407 
408  // $nblineFollowComment = max($nbLineCommentNeed, $nbLineTypeNeed);
409  // }
410 
411  //$nexY+=$nblineFollowComment*($pdf->getFontSize()*1.3); // Passe espace entre les lignes
412  $nexY += ($pdf->getFontSize()*1.3); // Passe espace entre les lignes
413 
414  // Detect if some page were added automatically and output _tableau for past pages
415  while ($pagenb < $pageposafter)
416  {
417  $pdf->setPage($pagenb);
418  if ($pagenb == 1)
419  {
420  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
421  }
422  else
423  {
424  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
425  }
426  $this->_pagefoot($pdf,$object,$outputlangs,1);
427  $pagenb++;
428  $pdf->setPage($pagenb);
429  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
430  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
431  }
432  if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
433  {
434  if ($pagenb == 1)
435  {
436  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
437  }
438  else
439  {
440  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
441  }
442  $this->_pagefoot($pdf,$object,$outputlangs,1);
443  // New page
444  $pdf->AddPage();
445  if (! empty($tplidx)) $pdf->useTemplate($tplidx);
446  $pagenb++;
447  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
448  }
449  }
450 
451  // Show square
452  if ($pagenb == 1)
453  {
454  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
455  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
456  }
457  else
458  {
459  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
460  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
461  }
462 
463  $pdf->SetFont('','', 10);
464 
465  // Show total area box
466  $posy=$bottomlasttab+5;
467  $pdf->SetXY(100, $posy);
468  $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L');
469  $pdf->SetXY(160, $posy);
470  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_ht), 1, 'R');
471  $pdf->SetFillColor(248,248,248);
472 
473  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
474  {
475  // TODO Show vat amout per tax level
476  $posy+=5;
477  $pdf->SetXY(100, $posy);
478  $pdf->SetTextColor(0,0,60);
479  $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalVAT"), 1,'L');
480  $pdf->SetXY(160, $posy);
481  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_tva),1, 'R');
482  }
483 
484  $posy+=5;
485  $pdf->SetXY(100, $posy);
486  $pdf->SetFont('','B', 10);
487  $pdf->SetTextColor(0,0,60);
488  $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalTTC"), 1,'L');
489  $pdf->SetXY(160, $posy);
490  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_ttc),1, 'R');
491 
492  // Pied de page
493  $this->_pagefoot($pdf,$object,$outputlangs);
494  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPage();
495 
496  $pdf->Close();
497 
498  $pdf->Output($file,'F');
499 
500  // Add pdfgeneration hook
501  $hookmanager->initHooks(array('pdfgeneration'));
502  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
503  global $action;
504  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
505 
506  if (! empty($conf->global->MAIN_UMASK))
507  @chmod($file, octdec($conf->global->MAIN_UMASK));
508 
509  $this->result = array('fullpath'=>$file);
510 
511  return 1; // Pas d'erreur
512  }
513  else
514  {
515  $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
516  return 0;
517  }
518  }
519  else
520  {
521  $this->error=$langs->trans("ErrorConstantNotDefined","EXPENSEREPORT_OUTPUTDIR");
522  return 0;
523  }
524  }
525 
536  private function printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails=0)
537  {
538  global $conf;
539  $pdf->SetFont('','', $default_font_size - 1);
540 
541  // Accountancy piece
542  $pdf->SetXY($this->posxpiece, $curY);
543  $pdf->writeHTMLCell($this->posxcomment-$this->posxpiece-0.8, 4, $this->posxpiece-1, $curY, $linenumber + 1, 0, 1);
544 
545  // Date
546  //$pdf->SetXY($this->posxdate -1, $curY);
547  //$pdf->MultiCell($this->posxtype-$this->posxdate-0.8, 4, dol_print_date($object->lines[$linenumber]->date,"day",false,$outputlangs), 0, 'C');
548 
549  // Type
550  $pdf->SetXY($this->posxtype -1, $curY);
551  $nextColumnPosX = $this->posxup;
552  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
553  $nextColumnPosX = $this->posxtva;
554  }
555  if (!empty($conf->projet->enabled)) {
556  $nextColumnPosX = $this->posxprojet;
557  }
558 
559  $expensereporttypecode = $object->lines[$linenumber]->type_fees_code;
560  $expensereporttypecodetoshow = $outputlangs->trans($expensereporttypecode);
561  if ($expensereporttypecodetoshow == $expensereporttypecode) {
562  $expensereporttypecodetoshow = preg_replace('/^(EX_|TF_)/', '', $expensereporttypecodetoshow);
563  }
564  //$expensereporttypecodetoshow = dol_trunc($expensereporttypecodetoshow, 9);
565 
566  //$pdf->MultiCell($nextColumnPosX-$this->posxtype-0.8, 4, $expensereporttypecodetoshow, 0, 'C');
567 
568  // Project
569  //if (! empty($conf->projet->enabled))
570  //{
571  // $pdf->SetFont('','', $default_font_size - 1);
572  // $pdf->SetXY($this->posxprojet, $curY);
573  // $pdf->MultiCell($this->posxtva-$this->posxprojet-0.8, 4, $object->lines[$linenumber]->projet_ref, 0, 'C');
574  //}
575 
576  // VAT Rate
577  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
578  $vat_rate = pdf_getlinevatrate($object, $linenumber, $outputlangs, $hidedetails);
579  $pdf->SetXY($this->posxtva, $curY);
580  $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 4,$vat_rate, 0, 'R');
581  }
582 
583  // Unit price
584  $pdf->SetXY($this->posxup, $curY);
585  $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 4,price($object->lines[$linenumber]->value_unit), 0, 'R');
586 
587  // Quantity
588  $pdf->SetXY($this->posxqty, $curY);
589  $pdf->MultiCell($this->postotalttc-$this->posxqty-0.8, 4,$object->lines[$linenumber]->qty, 0, 'R');
590 
591  // Total with all taxes
592  $pdf->SetXY($this->postotalttc-1, $curY);
593  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalttc, 4, price($object->lines[$linenumber]->total_ttc), 0, 'R');
594 
595  // Comments
596  $pdf->SetXY($this->posxcomment, $curY );
597  $comment = $outputlangs->trans("Date").':'. dol_print_date($object->lines[$linenumber]->date,"day",false,$outputlangs).' ';
598  $comment .= $outputlangs->trans("Type").':'. $expensereporttypecodetoshow.'<br>';
599  if (! empty($object->lines[$linenumber]->projet_ref)) {
600  $comment .= $outputlangs->trans("Project").':'. $object->lines[$linenumber]->projet_ref.'<br>';
601  }
602  $comment .= $object->lines[$linenumber]->comments;
603  $pdf->writeHTMLCell($this->posxtva-$this->posxcomment-0.8, 4, $this->posxcomment-1, $curY, $comment, 0, 1);
604  }
605 
615  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
616  {
617  global $conf, $langs, $hookmanager;
618 
619  // Load traductions files requiredby by page
620  $outputlangs->loadLangs(array("main", "trips", "companies"));
621 
622  $default_font_size = pdf_getPDFFontSize($outputlangs);
623 
624  /*
625  // ajout du fondu vert en bas de page à droite
626  $image_fondue = $conf->mycompany->dir_output.'/fondu_vert_.jpg';
627  $pdf->Image($image_fondue,20,107,200,190);
628 
629  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
630  */
631 
632  // Draft watermark
633  if ($object->fk_statut == 0 && ! empty($conf->global->EXPENSEREPORT_DRAFT_WATERMARK)) {
634  pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->EXPENSEREPORT_DRAFT_WATERMARK);
635  }
636 
637  $pdf->SetTextColor(0, 0, 60);
638  $pdf->SetFont('', 'B', $default_font_size + 3);
639 
640  $posy=$this->marge_haute;
641  $posx=$this->page_largeur-$this->marge_droite-100;
642 
643  $pdf->SetXY($this->marge_gauche,$posy);
644 
645  // Logo
646  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
647  if ($this->emetteur->logo) {
648  if (is_readable($logo)) {
649  $height=pdf_getHeightForLogo($logo);
650  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
651  } else {
652  $pdf->SetTextColor(200,0,0);
653  $pdf->SetFont('','B', $default_font_size -2);
654  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
655  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
656  }
657  }
658  else
659  {
660  $text=$this->emetteur->name;
661  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
662  }
663 
664  $pdf->SetFont('','B', $default_font_size + 4);
665  $pdf->SetXY($posx,$posy);
666  $pdf->SetTextColor(0,0,60);
667  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx,6,$langs->trans("ExpenseReport"), 0, 'R');
668 
669  $pdf->SetFont('','', $default_font_size -1);
670 
671  // Ref complete
672  $posy+=8;
673  $pdf->SetXY($posx,$posy);
674  $pdf->SetTextColor(0,0,60);
675  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $outputlangs->transnoentities("Ref")." : " . $object->ref, '', 'R');
676 
677  // Date start period
678  $posy+=5;
679  $pdf->SetXY($posx,$posy);
680  $pdf->SetTextColor(0,0,60);
681  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $outputlangs->transnoentities("DateStart")." : " . ($object->date_debut>0?dol_print_date($object->date_debut,"day",false,$outputlangs):''), '', 'R');
682 
683  // Date end period
684  $posy+=5;
685  $pdf->SetXY($posx,$posy);
686  $pdf->SetTextColor(0,0,60);
687  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $outputlangs->transnoentities("DateEnd")." : " . ($object->date_fin>0?dol_print_date($object->date_fin,"day",false,$outputlangs):''), '', 'R');
688 
689  // Status Expense Report
690  $posy+=6;
691  $pdf->SetXY($posx,$posy);
692  $pdf->SetFont('','B', $default_font_size + 2);
693  $pdf->SetTextColor(111,81,124);
694  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $object->getLibStatut(0), '', 'R');
695 
696  if ($showaddress) {
697  // Sender properties
698  $carac_emetteur = '';
699  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->convToOutputCharset($this->emetteur->address);
700  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->convToOutputCharset($this->emetteur->zip).' '.$outputlangs->convToOutputCharset($this->emetteur->town);
701  $carac_emetteur .= "\n";
702  // Phone
703  if ($this->emetteur->phone) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Phone")." : ".$outputlangs->convToOutputCharset($this->emetteur->phone);
704  // Fax
705  if ($this->emetteur->fax) $carac_emetteur .= ($carac_emetteur ? ($this->emetteur->tel ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax")." : ".$outputlangs->convToOutputCharset($this->emetteur->fax);
706  // EMail
707  if ($this->emetteur->email) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($this->emetteur->email);
708  // Web
709  if ($this->emetteur->url) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Web")." : ".$outputlangs->convToOutputCharset($this->emetteur->url);
710 
711  // Show sender
712  $posy=50;
713  $posx=$this->marge_gauche;
714  $hautcadre=40;
715  if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=118;
716 
717  // Show sender frame
718  $pdf->SetTextColor(0, 0, 0);
719  $pdf->SetFont('','B', $default_font_size - 2);
720  $pdf->SetXY($posx,$posy-5);
721  $pdf->MultiCell(66,5, $outputlangs->transnoentities("TripSociete")." :",'','L');
722  $pdf->SetXY($posx,$posy);
723  $pdf->SetFillColor(224,224,224);
724  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
725  $pdf->SetTextColor(0, 0, 60);
726 
727  // Show sender name
728  $pdf->SetXY($posx+2,$posy+3);
729  $pdf->SetFont('','B', $default_font_size);
730  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
731 
732  // Show sender information
733  $pdf->SetXY($posx+2,$posy+8);
734  $pdf->SetFont('', '', $default_font_size - 1);
735  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
736 
737  // Show recipient
738  $posy=50;
739  $posx=100;
740 
741  // Show recipient frame
742  $pdf->SetTextColor(0, 0, 0);
743  $pdf->SetFont('', 'B', 8);
744  $pdf->SetXY($posx,$posy-5);
745  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripNDF")." :", 0, 'L');
746  $pdf->rect($posx, $posy, $this->page_largeur - $this->marge_gauche - $posx, $hautcadre);
747 
748  // Informations for trip (dates and users workflow)
749  if ($object->fk_user_author > 0) {
750  $userfee=new User($this->db);
751  $userfee->fetch($object->fk_user_author); $posy+=3;
752  $pdf->SetXY($posx+2,$posy);
753  $pdf->SetFont('','',10);
754  $pdf->MultiCell(96,4,$outputlangs->transnoentities("AUTHOR")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L');
755  $posy+=5;
756  $pdf->SetXY($posx+2,$posy);
757  $pdf->MultiCell(96,4,$outputlangs->transnoentities("DateCreation")." : ".dol_print_date($object->date_create,"day",false,$outputlangs),0,'L');
758  }
759 
760  if ($object->fk_statut==99)
761  {
762  if ($object->fk_user_refuse > 0) {
763  $userfee=new User($this->db);
764  $userfee->fetch($object->fk_user_refuse); $posy+=6;
765  $pdf->SetXY($posx+2,$posy);
766  $pdf->MultiCell(96,4,$outputlangs->transnoentities("REFUSEUR")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L');
767  $posy+=5;
768  $pdf->SetXY($posx+2,$posy);
769  $pdf->MultiCell(96,4,$outputlangs->transnoentities("MOTIF_REFUS")." : ".$outputlangs->convToOutputCharset($object->detail_refuse),0,'L');
770  $posy+=5;
771  $pdf->SetXY($posx+2,$posy);
772  $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_REFUS")." : ".dol_print_date($object->date_refuse,"day",false,$outputlangs),0,'L');
773  }
774  }
775  else if($object->fk_statut==4)
776  {
777  if ($object->fk_user_cancel > 0) {
778  $userfee=new User($this->db);
779  $userfee->fetch($object->fk_user_cancel); $posy+=6;
780  $pdf->SetXY($posx+2,$posy);
781  $pdf->MultiCell(96,4,$outputlangs->transnoentities("CANCEL_USER")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L');
782  $posy+=5;
783  $pdf->SetXY($posx+2,$posy);
784  $pdf->MultiCell(96,4,$outputlangs->transnoentities("MOTIF_CANCEL")." : ".$outputlangs->convToOutputCharset($object->detail_cancel),0,'L');
785  $posy+=5;
786  $pdf->SetXY($posx+2,$posy);
787  $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_CANCEL")." : ".dol_print_date($object->date_cancel,"day",false,$outputlangs),0,'L');
788  }
789  }
790  else
791  {
792  if ($object->fk_user_approve > 0) {
793  $userfee=new User($this->db);
794  $userfee->fetch($object->fk_user_approve); $posy+=6;
795  $pdf->SetXY($posx+2,$posy);
796  $pdf->MultiCell(96,4,$outputlangs->transnoentities("VALIDOR")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L');
797  $posy+=5;
798  $pdf->SetXY($posx+2,$posy);
799  $pdf->MultiCell(96,4,$outputlangs->transnoentities("DateApprove")." : ".dol_print_date($object->date_approve,"day",false,$outputlangs),0,'L');
800  }
801  }
802 
803  if($object->fk_statut==6) {
804  if ($object->fk_user_paid > 0) {
805  $userfee=new User($this->db);
806  $userfee->fetch($object->fk_user_paid); $posy+=6;
807  $pdf->SetXY($posx+2,$posy);
808  $pdf->MultiCell(96,4,$outputlangs->transnoentities("AUTHORPAIEMENT")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L');
809  $posy+=5;
810  $pdf->SetXY($posx+2,$posy);
811  $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_PAIEMENT")." : ".dol_print_date($object->date_paiement,"day",false,$outputlangs),0,'L');
812  }
813  }
814  }
815  }
816 
830  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
831  {
832  global $conf;
833 
834  // Force to disable hidetop and hidebottom
835  $hidebottom=0;
836  if ($hidetop) $hidetop=-1;
837 
838  $currency = !empty($currency) ? $currency : $conf->currency;
839  $default_font_size = pdf_getPDFFontSize($outputlangs);
840 
841  // Amount in (at tab_top - 1)
842  $pdf->SetTextColor(0,0,0);
843  $pdf->SetFont('', '', $default_font_size - 2);
844  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
845  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 4), $tab_top -4);
846  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
847 
848  $pdf->SetDrawColor(128,128,128);
849 
850  // Rect prend une longueur en 3eme param
851  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
852  // line prend une position y en 3eme param
853  if (empty($hidetop)) {
854  $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
855  }
856 
857  $pdf->SetFont('','',8);
858 
859  // Accountancy piece
860  if (empty($hidetop)) {
861  $pdf->SetXY($this->posxpiece-1, $tab_top+1);
862  $pdf->MultiCell($this->posxcomment-$this->posxpiece-1, 1, '', '', 'R');
863  }
864 
865  // Comments
866  $pdf->line($this->posxcomment-1, $tab_top, $this->posxcomment-1, $tab_top + $tab_height);
867  if (empty($hidetop)) {
868  $pdf->SetXY($this->posxcomment-1, $tab_top+1);
869  $pdf->MultiCell($this->posxdate-$this->posxcomment-1, 1, $outputlangs->transnoentities("Description"),'','L');
870  }
871 
872  // Date
873  //$pdf->line($this->posxdate-1, $tab_top, $this->posxdate-1, $tab_top + $tab_height);
874  //if (empty($hidetop))
875  //{
876  // $pdf->SetXY($this->posxdate-1, $tab_top+1);
877  // $pdf->MultiCell($this->posxtype-$this->posxdate-1,2, $outputlangs->transnoentities("Date"),'','C');
878  //}
879 
880  // Type
881  //$pdf->line($this->posxtype-1, $tab_top, $this->posxtype-1, $tab_top + $tab_height);
882  //if (empty($hidetop))
883  //{
884  // $pdf->SetXY($this->posxtype-1, $tab_top+1);
885  // $pdf->MultiCell($this->posxprojet-$this->posxtype - 1, 2, $outputlangs->transnoentities("Type"), '', 'C');
886  //}
887 
888  //if (!empty($conf->projet->enabled))
889  //{
890  // // Project
891  // $pdf->line($this->posxprojet - 1, $tab_top, $this->posxprojet - 1, $tab_top + $tab_height);
892  // if (empty($hidetop)) {
893  // $pdf->SetXY($this->posxprojet - 1, $tab_top + 1);
894  // $pdf->MultiCell($this->posxtva - $this->posxprojet - 1, 2, $outputlangs->transnoentities("Project"), '', 'C');
895  // }
896  //}
897 
898  // VAT
899  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
900  $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
901  if (empty($hidetop)) {
902  $pdf->SetXY($this->posxtva-1, $tab_top+1);
903  $pdf->MultiCell($this->posxup-$this->posxtva - 1, 2, $outputlangs->transnoentities("VAT"), '', 'C');
904  }
905  }
906 
907  // Unit price
908  $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
909  if (empty($hidetop)) {
910  $pdf->SetXY($this->posxup-1, $tab_top+1);
911  $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceU"),'','C');
912  }
913 
914  // Quantity
915  $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
916  if (empty($hidetop)) {
917  $pdf->SetXY($this->posxqty-1, $tab_top+1);
918  $pdf->MultiCell($this->postotalttc-$this->posxqty - 1,2, $outputlangs->transnoentities("Qty"),'','R');
919  }
920 
921  // Total with all taxes
922  $pdf->line($this->postotalttc, $tab_top, $this->postotalttc, $tab_top + $tab_height);
923  if (empty($hidetop)) {
924  $pdf->SetXY($this->postotalttc-1, $tab_top+1);
925  $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalttc, 2, $outputlangs->transnoentities("TotalTTC"),'','R');
926  }
927 
928  $pdf->SetTextColor(0,0,0);
929  }
930 
940  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
941  {
942  global $conf;
943  $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
944  return pdf_pagefoot($pdf, $outputlangs, 'EXPENSEREPORT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
945  }
946 }
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition: pdf.lib.php:643
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:224
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Class to manage Dolibarr users.
Definition: user.class.php:41
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:201
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Parent class for trips and expenses templates.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Class to generate expense report based on standard model.
Class to manage hooks.
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1526
type
Definition: viewcat.php:284
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:872
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
$version
Dolibarr version of the loaded document string.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:245
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:623
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
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...
__construct($db)
Constructor.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails=0)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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...