dolibarr  16.0.5
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@open-dsi.fr>
4  * Copyright (C) 2016-2021 Philippe Grand <philippe.grand@atoo-net.com>
5  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
6  * Copyright (C) 2018 Francis Appels <francis.appels@z-application.com>
7  * Copyright (C) 2019 Markus Welters <markus@welters.de>
8  * Copyright (C) 2019 Rafael Ingenleuf <ingenleuf@welters.de>
9  * Copyright (C) 2020 Marc Guenneugues <marc.guenneugues@simicar.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 
32 require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
33 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
41 
46 {
50  public $db;
51 
55  public $name;
56 
60  public $description;
61 
65  public $update_main_doc_field;
66 
70  public $type;
71 
76  public $phpmin = array(5, 6);
77 
82  public $version = 'dolibarr';
83 
88  public $emetteur;
89 
90  public $posxpiece;
91  public $posxcomment;
92  public $posxtva;
93  public $posxup;
94  public $posxqty;
95  public $postotalht;
96  public $postotalttc;
97 
98 
104  public function __construct($db)
105  {
106  global $conf, $langs, $mysoc, $user;
107 
108  // Translations
109  $langs->loadLangs(array("main", "trips", "projects"));
110 
111  $this->db = $db;
112  $this->name = "";
113  $this->description = $langs->trans('PDFStandardExpenseReports');
114  $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
115 
116  // Page size for A4 format
117  $this->type = 'pdf';
118  $formatarray = pdf_getFormat();
119  $this->page_largeur = $formatarray['width'];
120  $this->page_hauteur = $formatarray['height'];
121  $this->format = array($this->page_largeur, $this->page_hauteur);
122  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
123  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
124  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
125  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
126 
127  $this->option_logo = 1; // Display logo
128  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
129  $this->option_modereg = 1; // Display payment mode
130  $this->option_condreg = 1; // Display payment terms
131  $this->option_multilang = 1; // Available in several languages
132  $this->option_escompte = 0; // Displays if there has been a discount
133  $this->option_credit_note = 0; // Support credit notes
134  $this->option_freetext = 1; // Support add of a personalised text
135  $this->option_draft_watermark = 1; // Support add of a watermark on drafts
136 
137  // Get source company
138  $this->emetteur = $mysoc;
139 
140  if (empty($this->emetteur->country_code)) {
141  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
142  }
143 
144  // Define position of columns
145  $this->posxpiece = $this->marge_gauche + 1;
146  $this->posxcomment = $this->marge_gauche + 10;
147  //$this->posxdate=88;
148  //$this->posxtype=107;
149  //$this->posxprojet=120;
150  $this->posxtva = 112;
151  $this->posxup = 127;
152  $this->posxqty = 150;
153  $this->postotalht = 160;
154  $this->postotalttc = 180;
155  // if (empty($conf->project->enabled)) {
156  // $this->posxtva-=20;
157  // $this->posxup-=20;
158  // $this->posxqty-=20;
159  // $this->postotalttc-=20;
160  // }
161  if ($this->page_largeur < 210) { // To work with US executive format
162  $this->posxdate -= 20;
163  $this->posxtype -= 20;
164  $this->posxprojet -= 20;
165  $this->posxtva -= 20;
166  $this->posxup -= 20;
167  $this->posxqty -= 20;
168  $this->postotalttc -= 20;
169  }
170 
171  $this->tva = array();
172  $this->tva_array = array();
173  $this->localtax1 = array();
174  $this->localtax2 = array();
175  $this->atleastoneratenotnull = 0;
176  $this->atleastonediscount = 0;
177  }
178 
179 
180  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
192  public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
193  {
194  // phpcs:enable
195  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
196 
197  if (!is_object($outputlangs)) {
198  $outputlangs = $langs;
199  }
200  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
201  if (!empty($conf->global->MAIN_USE_FPDF)) {
202  $outputlangs->charset_output = 'ISO-8859-1';
203  }
204 
205  // Load traductions files required by page
206  $outputlangs->loadLangs(array("main", "trips", "projects", "dict", "bills", "banks"));
207 
208  $nblines = count($object->lines);
209 
210  if ($conf->expensereport->dir_output) {
211  // Definition of $dir and $file
212  if ($object->specimen) {
213  $dir = $conf->expensereport->dir_output;
214  $file = $dir."/SPECIMEN.pdf";
215  } else {
216  $objectref = dol_sanitizeFileName($object->ref);
217  $dir = $conf->expensereport->dir_output."/".$objectref;
218  $file = $dir."/".$objectref.".pdf";
219  }
220 
221  if (!file_exists($dir)) {
222  if (dol_mkdir($dir) < 0) {
223  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
224  return 0;
225  }
226  }
227 
228  if (file_exists($dir)) {
229  // Add pdfgeneration hook
230  if (!is_object($hookmanager)) {
231  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
232  $hookmanager = new HookManager($this->db);
233  }
234  $hookmanager->initHooks(array('pdfgeneration'));
235  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
236  global $action;
237  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
238 
239  // Create pdf instance
240  $pdf = pdf_getInstance($this->format);
241  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
242  $heightforinfotot = 40; // Height reserved to output the info and total part
243  $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
244  $heightforfooter = $this->marge_basse + 12; // Height reserved to output the footer (value include bottom margin)
245  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
246  $heightforfooter += 6;
247  }
248 
249  $pdf->SetAutoPageBreak(1, 0);
250 
251  if (class_exists('TCPDF')) {
252  $pdf->setPrintHeader(false);
253  $pdf->setPrintFooter(false);
254  }
255  $pdf->SetFont(pdf_getPDFFont($outputlangs));
256  // Set path to the background PDF File
257  if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
258  $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
259  $tplidx = $pdf->importPage(1);
260  }
261 
262  $pdf->Open();
263  $pagenb = 0;
264  $pdf->SetDrawColor(128, 128, 128);
265 
266  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
267  $pdf->SetSubject($outputlangs->transnoentities("Trips"));
268  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
269  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
270  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Trips"));
271  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
272  $pdf->SetCompression(false);
273  }
274 
275  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
276 
277  // New page
278  $pdf->AddPage();
279  if (!empty($tplidx)) {
280  $pdf->useTemplate($tplidx);
281  }
282  $pagenb++;
283  $this->_pagehead($pdf, $object, 1, $outputlangs);
284  $pdf->SetFont('', '', $default_font_size - 1);
285  $pdf->MultiCell(0, 3, ''); // Set interline to 3
286  $pdf->SetTextColor(0, 0, 0);
287 
288  $tab_top = 95;
289  $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 65 : 10);
290 
291  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
292 
293  // Show notes
294  $notetoshow = empty($object->note_public) ? '' : $object->note_public;
295  if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
296  // Get first sale rep
297  if (is_object($object->thirdparty)) {
298  $salereparray = $object->thirdparty->getSalesRepresentatives($user);
299  $salerepobj = new User($this->db);
300  $salerepobj->fetch($salereparray[0]['id']);
301  if (!empty($salerepobj->signature)) {
302  $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
303  }
304  }
305  }
306  if ($notetoshow) {
307  $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
308  complete_substitutions_array($substitutionarray, $outputlangs, $object);
309  $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
310  $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
311 
312  $tab_top = 95;
313 
314  $pdf->SetFont('', '', $default_font_size - 1);
315  $pdf->writeHTMLCell(190, 3, $this->posxpiece - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
316  $nexY = $pdf->GetY();
317  $height_note = $nexY - $tab_top;
318 
319  // Rect takes a length in 3rd parameter
320  $pdf->SetDrawColor(192, 192, 192);
321  $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
322 
323  $tab_height = $tab_height - $height_note;
324  $tab_top = $nexY + 6;
325  } else {
326  $height_note = 0;
327  }
328 
329  $iniY = $tab_top + 7;
330  $initialY = $tab_top + 7;
331  $nexY = $tab_top + 7;
332 
333  $showpricebeforepagebreak = 1;
334  $pdf->setTopMargin($tab_top_newpage);
335  // Loop on each lines
336  $i = 0;
337  while ($i < $nblines) {
338  $pdf->SetFont('', '', $default_font_size - 2); // Into loop to work with multipage
339  $pdf->SetTextColor(0, 0, 0);
340 
341  $pdf->setTopMargin($tab_top_newpage);
342  if (empty($showpricebeforepagebreak) && ($i !== ($nblines - 1))) {
343  $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
344  } else {
345  $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
346  }
347 
348  $pageposbefore = $pdf->getPage();
349  $curY = $nexY;
350  $pdf->startTransaction();
351  $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
352  $pageposafter = $pdf->getPage();
353  if ($pageposafter > $pageposbefore) {
354  // There is a pagebreak
355  $pdf->rollbackTransaction(true);
356 
357  $pageposafter = $pageposbefore;
358  //print $pageposafter.'-'.$pageposbefore;exit;
359  if (empty($showpricebeforepagebreak)) {
360  $pdf->AddPage('', '', true);
361  if (!empty($tplidx)) {
362  $pdf->useTemplate($tplidx);
363  }
364  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
365  $this->_pagehead($pdf, $object, 0, $outputlangs);
366  }
367  $pdf->setPage($pageposafter + 1);
368  $showpricebeforepagebreak = 1;
369  $nexY = $tab_top_newpage;
370  $nexY += ($pdf->getFontSize() * 1.3); // Add space between lines
371  $pdf->SetFont('', '', $default_font_size - 2); // Into loop to work with multipage
372  $pdf->SetTextColor(0, 0, 0);
373 
374  $pdf->setTopMargin($tab_top_newpage);
375  continue;
376  } else {
377  $pdf->setPageOrientation('', 1, $heightforfooter);
378  $showpricebeforepagebreak = 0;
379  }
380 
381  $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
382  $pageposafter = $pdf->getPage();
383  $posyafter = $pdf->GetY();
384  //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
385  if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
386  // There is no space left for total+free text
387  if ($i == ($nblines - 1)) {
388  // No more lines, and no space left to show total, so we create a new page
389  $pdf->AddPage('', '', true);
390  if (!empty($tplidx)) {
391  $pdf->useTemplate($tplidx);
392  }
393  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
394  $this->_pagehead($pdf, $object, 0, $outputlangs);
395  }
396  $pdf->setPage($pageposafter + 1);
397  }
398  } else {
399  // We found a page break
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  $i++;
412  //nexY
413  $nexY = $pdf->GetY();
414  $pageposafter = $pdf->getPage();
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  //$nblineFollowComment = 1;
420  // Search number of lines coming to know if there is enough room
421  // if ($i < ($nblines - 1)) // If it's not last line
422  // {
423  // //Fetch current description to know on which line the next one should be placed
424  // $follow_comment = $object->lines[$i]->comments;
425  // $follow_type = $object->lines[$i]->type_fees_code;
426 
427  // //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
428  // $nbLineCommentNeed = dol_nboflines_bis($follow_comment,52,$outputlangs->charset_output);
429  // $nbLineTypeNeed = dol_nboflines_bis($follow_type,4,$outputlangs->charset_output);
430 
431  // $nblineFollowComment = max($nbLineCommentNeed, $nbLineTypeNeed);
432  // }
433 
434  //$nexY+=$nblineFollowComment*($pdf->getFontSize()*1.3); // Add space between lines
435  $nexY += ($pdf->getFontSize() * 1.3); // Add space between lines
436 
437  // Detect if some page were added automatically and output _tableau for past pages
438  while ($pagenb < $pageposafter) {
439  $pdf->setPage($pagenb);
440  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
441  if ($pagenb == 1) {
442  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
443  } else {
444  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
445  }
446  $this->_pagefoot($pdf, $object, $outputlangs, 1);
447  $pagenb++;
448  $pdf->setPage($pagenb);
449  $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
450  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
451  $this->_pagehead($pdf, $object, 0, $outputlangs);
452  }
453  if (!empty($tplidx)) {
454  $pdf->useTemplate($tplidx);
455  }
456  }
457  if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
458  if ($pagenb == 1) {
459  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
460  } else {
461  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
462  }
463  $this->_pagefoot($pdf, $object, $outputlangs, 1);
464  // New page
465  $pdf->AddPage();
466  if (!empty($tplidx)) {
467  $pdf->useTemplate($tplidx);
468  }
469  $pagenb++;
470  if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
471  $this->_pagehead($pdf, $object, 0, $outputlangs);
472  }
473  }
474  }
475 
476  // Show square
477  if ($pagenb == 1) {
478  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
479  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
480  } else {
481  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
482  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
483  }
484 
485  $pdf->SetFont('', '', 10);
486 
487  // Show total area box
488  $posy = $bottomlasttab + 5;
489  $posy_start_of_totals = $posy;
490  $pdf->SetXY(130, $posy);
491  $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L');
492  $pdf->SetXY(180, $posy);
493  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ht), 1, 'R');
494  $pdf->SetFillColor(248, 248, 248);
495 
496  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
497  // TODO Show vat amout per tax level
498  $posy += 5;
499  $pdf->SetXY(130, $posy);
500  $pdf->SetTextColor(0, 0, 60);
501  $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalVAT"), 1, 'L');
502  $pdf->SetXY(180, $posy);
503  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_tva), 1, 'R');
504  }
505 
506  $posy += 5;
507  $pdf->SetXY(130, $posy);
508  $pdf->SetFont('', 'B', 10);
509  $pdf->SetTextColor(0, 0, 60);
510  $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalTTC"), 1, 'L');
511  $pdf->SetXY(180, $posy);
512  $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ttc), 1, 'R');
513 
514  // show payments zone
515  $sumPayments = $object->getSumPayments();
516  if ($sumPayments > 0 && empty($conf->global->PDF_EXPENSEREPORT_NO_PAYMENT_DETAILS)) {
517  $posy = $this->tablePayments($pdf, $object, $posy_start_of_totals, $outputlangs);
518  }
519 
520  // Page footer
521  $this->_pagefoot($pdf, $object, $outputlangs);
522  if (method_exists($pdf, 'AliasNbPages')) {
523  $pdf->AliasNbPages();
524  }
525 
526  $pdf->Close();
527 
528  $pdf->Output($file, 'F');
529 
530  // Add pdfgeneration hook
531  $hookmanager->initHooks(array('pdfgeneration'));
532  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
533  global $action;
534  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
535  if ($reshook < 0) {
536  $this->error = $hookmanager->error;
537  $this->errors = $hookmanager->errors;
538  }
539 
540  if (!empty($conf->global->MAIN_UMASK)) {
541  @chmod($file, octdec($conf->global->MAIN_UMASK));
542  }
543 
544  $this->result = array('fullpath'=>$file);
545 
546  return 1; // No error
547  } else {
548  $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
549  return 0;
550  }
551  } else {
552  $this->error = $langs->trans("ErrorConstantNotDefined", "EXPENSEREPORT_OUTPUTDIR");
553  return 0;
554  }
555  }
556 
567  protected function printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails = 0)
568  {
569  global $conf;
570  $pdf->SetFont('', '', $default_font_size - 1);
571  $pdf->SetTextColor(0, 0, 0);
572 
573  // Accountancy piece
574  $pdf->SetXY($this->posxpiece, $curY);
575  $pdf->writeHTMLCell($this->posxcomment - $this->posxpiece - 0.8, 4, $this->posxpiece - 1, $curY, $linenumber + 1, 0, 1);
576 
577  // Date
578  //$pdf->SetXY($this->posxdate -1, $curY);
579  //$pdf->MultiCell($this->posxtype-$this->posxdate-0.8, 4, dol_print_date($object->lines[$linenumber]->date,"day",false,$outputlangs), 0, 'C');
580 
581  // Type
582  $pdf->SetXY($this->posxtype - 1, $curY);
583  $nextColumnPosX = $this->posxup;
584  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
585  $nextColumnPosX = $this->posxtva;
586  }
587  if (!empty($conf->project->enabled)) {
588  $nextColumnPosX = $this->posxprojet;
589  }
590 
591  $expensereporttypecode = $object->lines[$linenumber]->type_fees_code;
592  $expensereporttypecodetoshow = ($outputlangs->trans(($expensereporttypecode)) == $expensereporttypecode ? $object->lines[$linenumber]->type_fees_libelle : $outputlangs->trans($expensereporttypecode));
593 
594 
595  if ($expensereporttypecodetoshow == $expensereporttypecode) {
596  $expensereporttypecodetoshow = preg_replace('/^(EX_|TF_)/', '', $expensereporttypecodetoshow);
597  }
598  //$expensereporttypecodetoshow = dol_trunc($expensereporttypecodetoshow, 9);
599 
600  //$pdf->MultiCell($nextColumnPosX-$this->posxtype-0.8, 4, $expensereporttypecodetoshow, 0, 'C');
601 
602  // Project
603  //if (! empty($conf->project->enabled))
604  //{
605  // $pdf->SetFont('','', $default_font_size - 1);
606  // $pdf->SetXY($this->posxprojet, $curY);
607  // $pdf->MultiCell($this->posxtva-$this->posxprojet-0.8, 4, $object->lines[$linenumber]->projet_ref, 0, 'C');
608  //}
609 
610  // VAT Rate
611  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
612  $vat_rate = pdf_getlinevatrate($object, $linenumber, $outputlangs, $hidedetails);
613  $pdf->SetXY($this->posxtva, $curY);
614  $pdf->MultiCell($this->posxup - $this->posxtva - 0.8, 4, $vat_rate, 0, 'R');
615  }
616 
617  // Unit price
618  $pdf->SetXY($this->posxup, $curY);
619  $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 4, price($object->lines[$linenumber]->value_unit), 0, 'R');
620 
621  // Quantity
622  $pdf->SetXY($this->posxqty, $curY);
623  $pdf->MultiCell($this->postotalht - $this->posxqty - 0.8, 4, $object->lines[$linenumber]->qty, 0, 'R');
624 
625  // Total without taxes
626  $pdf->SetXY($this->postotalht, $curY);
627  $pdf->MultiCell($this->postotalttc - $this->postotalht - 0.8, 4, price($object->lines[$linenumber]->total_ht), 0, 'R');
628 
629  // Total with all taxes
630  $pdf->SetXY($this->postotalttc - 1, $curY);
631  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 4, price($object->lines[$linenumber]->total_ttc), 0, 'R');
632 
633  // Comments
634  $pdf->SetXY($this->posxcomment, $curY);
635  $comment = $outputlangs->trans("Date").':'.dol_print_date($object->lines[$linenumber]->date, "day", false, $outputlangs).' ';
636  $comment .= $outputlangs->trans("Type").':'.$expensereporttypecodetoshow.'<br>';
637  if (!empty($object->lines[$linenumber]->projet_ref)) {
638  $comment .= $outputlangs->trans("Project").':'.$object->lines[$linenumber]->projet_ref.'<br>';
639  }
640  $comment .= $object->lines[$linenumber]->comments;
641  $pdf->writeHTMLCell($this->posxtva - $this->posxcomment - 0.8, 4, $this->posxcomment - 1, $curY, $comment, 0, 1);
642  }
643 
644  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
654  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
655  {
656  // global $conf, $langs, $hookmanager;
657  global $user, $langs, $conf, $mysoc, $db, $hookmanager;
658 
659  // Load traductions files required by page
660  $outputlangs->loadLangs(array("main", "trips", "companies"));
661 
662  $default_font_size = pdf_getPDFFontSize($outputlangs);
663 
664  /*
665  // ajout du fondu vert en bas de page à droite
666  $image_fondue = $conf->mycompany->dir_output.'/fondu_vert_.jpg';
667  $pdf->Image($image_fondue,20,107,200,190);
668 
669  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
670  */
671 
672  // Draft watermark
673  if ($object->fk_statut == 0 && !empty($conf->global->EXPENSEREPORT_DRAFT_WATERMARK)) {
674  pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->EXPENSEREPORT_DRAFT_WATERMARK);
675  }
676 
677  $pdf->SetTextColor(0, 0, 60);
678  $pdf->SetFont('', 'B', $default_font_size + 3);
679 
680  $posy = $this->marge_haute;
681  $posx = $this->page_largeur - $this->marge_droite - 100;
682 
683  $pdf->SetXY($this->marge_gauche, $posy);
684 
685  // Logo
686  $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
687  if ($this->emetteur->logo) {
688  if (is_readable($logo)) {
689  $height = pdf_getHeightForLogo($logo);
690  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
691  } else {
692  $pdf->SetTextColor(200, 0, 0);
693  $pdf->SetFont('', 'B', $default_font_size - 2);
694  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
695  $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
696  }
697  } else {
698  $text = $this->emetteur->name;
699  $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
700  }
701 
702  $pdf->SetFont('', 'B', $default_font_size + 4);
703  $pdf->SetXY($posx, $posy);
704  $pdf->SetTextColor(0, 0, 60);
705  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 6, $langs->trans("ExpenseReport"), 0, 'R');
706 
707  $pdf->SetFont('', '', $default_font_size - 1);
708 
709  // Ref complete
710  $posy += 8;
711  $pdf->SetXY($posx, $posy);
712  $pdf->SetTextColor(0, 0, 60);
713  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R');
714 
715  // Date start period
716  $posy += 5;
717  $pdf->SetXY($posx, $posy);
718  $pdf->SetTextColor(0, 0, 60);
719  $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');
720 
721  // Date end period
722  $posy += 5;
723  $pdf->SetXY($posx, $posy);
724  $pdf->SetTextColor(0, 0, 60);
725  $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');
726 
727  // Status Expense Report
728  $posy += 6;
729  $pdf->SetXY($posx, $posy);
730  $pdf->SetFont('', 'B', $default_font_size + 2);
731  $pdf->SetTextColor(111, 81, 124);
732  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities($object->statuts_short[$object->status]), '', 'R');
733 
734  if ($showaddress) {
735  // Sender properties
736  $carac_emetteur = '';
737  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->address);
738  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->zip).' '.$outputlangs->convToOutputCharset($this->emetteur->town);
739  $carac_emetteur .= "\n";
740  if ($this->emetteur->phone) {
741  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Phone")." : ".$outputlangs->convToOutputCharset($this->emetteur->phone);
742  }
743  if ($this->emetteur->fax) {
744  $carac_emetteur .= ($carac_emetteur ? ($this->emetteur->tel ? " - " : "\n") : '').$outputlangs->transnoentities("Fax")." : ".$outputlangs->convToOutputCharset($this->emetteur->fax);
745  }
746  if ($this->emetteur->email) {
747  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($this->emetteur->email);
748  }
749  if ($this->emetteur->url) {
750  $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Web")." : ".$outputlangs->convToOutputCharset($this->emetteur->url);
751  }
752 
753  // Receiver Properties
754  $receiver = new User($this->db);
755  $receiver->fetch($object->fk_user_author);
756  $receiver_account = new UserBankAccount($this->db);
757  $receiver_account->fetch(0, '', $object->fk_user_author);
758  $expense_receiver = '';
759  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->address);
760  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->zip).' '.$outputlangs->convToOutputCharset($receiver->town);
761  $expense_receiver .= "\n";
762  if ($receiver->email) {
763  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($receiver->email);
764  }
765  if ($receiver_account->iban) {
766  $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("IBAN")." : ".$outputlangs->convToOutputCharset($receiver_account->iban);
767  }
768 
769  // Show sender
770  $posy = 50;
771  $posx = $this->marge_gauche;
772  $hautcadre = 40;
773  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
774  $posx = 118;
775  }
776 
777  // Show sender frame
778  $pdf->SetTextColor(0, 0, 0);
779  $pdf->SetFont('', 'B', $default_font_size - 2);
780  $pdf->SetXY($posx, $posy - 5);
781  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripSociete"), '', 'L');
782  $pdf->SetXY($posx, $posy);
783  $pdf->SetFillColor(224, 224, 224);
784  $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
785  $pdf->SetTextColor(0, 0, 60);
786 
787  // Show sender information
788  if (empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
789  $pdf->SetXY($posx + 2, $posy + 3);
790  $pdf->SetFont('', 'B', $default_font_size);
791  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
792  $pdf->SetXY($posx + 2, $posy + 8);
793  $pdf->SetFont('', '', $default_font_size - 1);
794  $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
795  } else {
796  $pdf->SetXY($posx + 2, $posy + 3);
797  $pdf->SetFont('', 'B', $default_font_size);
798  $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset(dolGetFirstLastname($receiver->firstname, $receiver->lastname)), 0, 'L');
799  $pdf->SetXY($posx + 2, $posy + 8);
800  $pdf->SetFont('', '', $default_font_size - 1);
801  $pdf->MultiCell(80, 4, $expense_receiver, 0, 'L');
802  }
803 
804  // Show recipient
805  $posy = 50;
806  $posx = 100;
807  if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
808  $posx = $this->marge_gauche;
809  }
810 
811  // Show recipient frame
812  $pdf->SetTextColor(0, 0, 0);
813  $pdf->SetFont('', 'B', 8);
814  $pdf->SetXY($posx, $posy - 5);
815  $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripNDF")." :", 0, 'L');
816  $pdf->rect($posx, $posy, $this->page_largeur - $this->marge_gauche - $posx, $hautcadre);
817 
818  // Informations for expense report (dates and users workflow)
819  if ($object->fk_user_author > 0) {
820  $userfee = new User($this->db);
821  $userfee->fetch($object->fk_user_author);
822  $posy += 3;
823  $pdf->SetXY($posx + 2, $posy);
824  $pdf->SetFont('', '', 10);
825  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
826  $posy = $pdf->GetY() + 1;
827  $pdf->SetXY($posx + 2, $posy);
828  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateCreation")." : ".dol_print_date($object->date_create, "day", false, $outputlangs), 0, 'L');
829  }
830 
831  if ($object->fk_statut == 99) {
832  if ($object->fk_user_refuse > 0) {
833  $userfee = new User($this->db);
834  $userfee->fetch($object->fk_user_refuse);
835  $posy += 6;
836  $pdf->SetXY($posx + 2, $posy);
837  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("REFUSEUR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
838  $posy += 5;
839  $pdf->SetXY($posx + 2, $posy);
840  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_REFUS")." : ".$outputlangs->convToOutputCharset($object->detail_refuse), 0, 'L');
841  $posy += 5;
842  $pdf->SetXY($posx + 2, $posy);
843  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_REFUS")." : ".dol_print_date($object->date_refuse, "day", false, $outputlangs), 0, 'L');
844  }
845  } elseif ($object->fk_statut == 4) {
846  if ($object->fk_user_cancel > 0) {
847  $userfee = new User($this->db);
848  $userfee->fetch($object->fk_user_cancel);
849  $posy += 6;
850  $pdf->SetXY($posx + 2, $posy);
851  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("CANCEL_USER")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
852  $posy += 5;
853  $pdf->SetXY($posx + 2, $posy);
854  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_CANCEL")." : ".$outputlangs->convToOutputCharset($object->detail_cancel), 0, 'L');
855  $posy += 5;
856  $pdf->SetXY($posx + 2, $posy);
857  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_CANCEL")." : ".dol_print_date($object->date_cancel, "day", false, $outputlangs), 0, 'L');
858  }
859  } else {
860  if ($object->fk_user_approve > 0) {
861  $userfee = new User($this->db);
862  $userfee->fetch($object->fk_user_approve);
863  $posy += 6;
864  $pdf->SetXY($posx + 2, $posy);
865  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("VALIDOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
866  $posy += 5;
867  $pdf->SetXY($posx + 2, $posy);
868  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateApprove")." : ".dol_print_date($object->date_approve, "day", false, $outputlangs), 0, 'L');
869  }
870  }
871 
872  if ($object->fk_statut == 6) {
873  if ($object->fk_user_paid > 0) {
874  $userfee = new User($this->db);
875  $userfee->fetch($object->fk_user_paid);
876  $posy += 6;
877  $pdf->SetXY($posx + 2, $posy);
878  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHORPAIEMENT")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
879  $posy += 5;
880  $pdf->SetXY($posx + 2, $posy);
881  $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_PAIEMENT")." : ".dol_print_date($object->date_paiement, "day", false, $outputlangs), 0, 'L');
882  }
883  }
884  }
885  }
886 
887  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
901  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
902  {
903  global $conf;
904 
905  // Force to disable hidetop and hidebottom
906  $hidebottom = 0;
907  if ($hidetop) {
908  $hidetop = -1;
909  }
910 
911  $currency = !empty($currency) ? $currency : $conf->currency;
912  $default_font_size = pdf_getPDFFontSize($outputlangs);
913 
914  // Amount in (at tab_top - 1)
915  $pdf->SetTextColor(0, 0, 0);
916  $pdf->SetFont('', '', $default_font_size - 2);
917  $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
918  $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 4), $tab_top - 4);
919  $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
920 
921  $pdf->SetDrawColor(128, 128, 128);
922 
923  // Rect takes a length in 3rd parameter
924  $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height);
925  // line prend une position y en 3eme param
926  if (empty($hidetop)) {
927  $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
928  }
929 
930  $pdf->SetFont('', '', 8);
931 
932  // Accountancy piece
933  if (empty($hidetop)) {
934  $pdf->SetXY($this->posxpiece - 1, $tab_top + 1);
935  $pdf->MultiCell($this->posxcomment - $this->posxpiece - 0.8, 1, '', '', 'R');
936  }
937 
938  // Comments
939  $pdf->line($this->posxcomment - 1, $tab_top, $this->posxcomment - 1, $tab_top + $tab_height);
940  if (empty($hidetop)) {
941  $pdf->SetXY($this->posxcomment - 1, $tab_top + 1);
942  $pdf->MultiCell($this->posxdate - $this->posxcomment - 0.8, 1, $outputlangs->transnoentities("Description"), '', 'L');
943  }
944 
945  // Date
946  //$pdf->line($this->posxdate-1, $tab_top, $this->posxdate-1, $tab_top + $tab_height);
947  //if (empty($hidetop))
948  //{
949  // $pdf->SetXY($this->posxdate-1, $tab_top+1);
950  // $pdf->MultiCell($this->posxtype-$this->posxdate-1,2, $outputlangs->transnoentities("Date"),'','C');
951  //}
952 
953  // Type
954  //$pdf->line($this->posxtype-1, $tab_top, $this->posxtype-1, $tab_top + $tab_height);
955  //if (empty($hidetop))
956  //{
957  // $pdf->SetXY($this->posxtype-1, $tab_top+1);
958  // $pdf->MultiCell($this->posxprojet-$this->posxtype - 1, 2, $outputlangs->transnoentities("Type"), '', 'C');
959  //}
960 
961  //if (!empty($conf->project->enabled))
962  //{
963  // // Project
964  // $pdf->line($this->posxprojet - 1, $tab_top, $this->posxprojet - 1, $tab_top + $tab_height);
965  // if (empty($hidetop)) {
966  // $pdf->SetXY($this->posxprojet - 1, $tab_top + 1);
967  // $pdf->MultiCell($this->posxtva - $this->posxprojet - 1, 2, $outputlangs->transnoentities("Project"), '', 'C');
968  // }
969  //}
970 
971  // VAT
972  if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
973  $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
974  if (empty($hidetop)) {
975  $pdf->SetXY($this->posxtva - 0.8, $tab_top + 1);
976  $pdf->MultiCell($this->posxup - $this->posxtva - 1, 2, $outputlangs->transnoentities("VAT"), '', 'C');
977  }
978  }
979 
980  // Unit price
981  $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
982  if (empty($hidetop)) {
983  $pdf->SetXY($this->posxup - 0.8, $tab_top + 1);
984  $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUTTC"), '', 'C');
985  }
986 
987  // Quantity
988  $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
989  if (empty($hidetop)) {
990  $pdf->SetXY($this->posxqty - 0.8, $tab_top + 1);
991  $pdf->MultiCell($this->postotalht - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
992  }
993 
994  // Total without taxes
995  $pdf->line($this->postotalht - 1, $tab_top, $this->postotalht - 1, $tab_top + $tab_height);
996  if (empty($hidetop)) {
997  $pdf->SetXY($this->postotalht - 0.8, $tab_top + 1);
998  $pdf->MultiCell($this->postotalttc - $this->postotalht + 1, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
999  }
1000 
1001  // Total with all taxes
1002  $pdf->line($this->postotalttc, $tab_top, $this->postotalttc, $tab_top + $tab_height);
1003  if (empty($hidetop)) {
1004  $pdf->SetXY($this->postotalttc - 0.8, $tab_top + 1);
1005  $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 2, $outputlangs->transnoentities("TotalTTC"), '', 'R');
1006  }
1007 
1008  $pdf->SetTextColor(0, 0, 0);
1009  }
1010 
1020  protected function tablePayments(&$pdf, $object, $posy, $outputlangs)
1021  {
1022  global $conf;
1023 
1024  $sign = 1;
1025  $tab3_posx = $this->marge_gauche;
1026  $tab3_top = $posy;
1027  $tab3_width = 88;
1028  $tab3_height = 5;
1029 
1030  $default_font_size = pdf_getPDFFontSize($outputlangs);
1031 
1032  $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1033  $pdf->SetFont('', '', $default_font_size - 2);
1034  $pdf->SetXY($tab3_posx, $tab3_top - 4);
1035  $pdf->SetTextColor(0, 0, 0);
1036  $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1037 
1038  $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width + 2, $tab3_top); // Top border line of table title
1039 
1040  $pdf->SetXY($tab3_posx, $tab3_top + 1);
1041  $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Date"), 0, 'L', 0);
1042  $pdf->SetXY($tab3_posx + 19, $tab3_top + 1); // Old value 17
1043  $pdf->MultiCell(15, 3, $outputlangs->transnoentities("Amount"), 0, 'C', 0);
1044  $pdf->SetXY($tab3_posx + 35, $tab3_top + 1);
1045  $pdf->MultiCell(30, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1046  if (!empty($conf->banque->enabled)) {
1047  $pdf->SetXY($tab3_posx + 65, $tab3_top + 1);
1048  $pdf->MultiCell(25, 3, $outputlangs->transnoentities("BankAccount"), 0, 'L', 0);
1049  }
1050  $pdf->line($tab3_posx, $tab3_top + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $tab3_height); // Bottom border line of table title
1051 
1052  $y = 0;
1053 
1054  // Loop on each payment
1055  // TODO create method on expensereport class to get payments
1056  // Payments already done (from payment on this expensereport)
1057  $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1058  $sql .= "c.code as p_code, c.libelle as payment_type,";
1059  $sql .= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1060  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."payment_expensereport as p";
1061  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1062  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
1063  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
1064  $sql .= " WHERE e.rowid = ".((int) $object->id);
1065  $sql .= " AND p.fk_expensereport = e.rowid";
1066  $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
1067  $sql .= " ORDER BY dp";
1068 
1069  $resql = $this->db->query($sql);
1070  if ($resql) {
1071  $num = $this->db->num_rows($resql);
1072  $totalpaid = 0;
1073  $i = 0;
1074  while ($i < $num) {
1075  $y += $tab3_height;
1076  $row = $this->db->fetch_object($resql);
1077 
1078  $pdf->SetXY($tab3_posx, $tab3_top + $y + 1);
1079  $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->dp), 'day', false, $outputlangs, true), 0, 'L', 0);
1080  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y + 1);
1081  $pdf->MultiCell(15, 3, price($sign * $row->amount, 0, $outputlangs), 0, 'R', 0);
1082  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y + 1);
1083  $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->p_code);
1084 
1085  $pdf->MultiCell(40, 3, $oper, 0, 'L', 0);
1086  if (!empty($conf->banque->enabled)) {
1087  $pdf->SetXY($tab3_posx + 65, $tab3_top + $y + 1);
1088  $pdf->MultiCell(30, 3, $row->baref, 0, 'L', 0);
1089  }
1090 
1091  $pdf->line($tab3_posx, $tab3_top + $y + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $y + $tab3_height); // Bottom line border of table
1092  $totalpaid += $row->amount;
1093  $i++;
1094  }
1095  if ($num > 0 && $object->paid == 0) {
1096  $y += $tab3_height;
1097 
1098  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1099  $pdf->MultiCell(15, 3, price($totalpaid), 0, 'R', 0);
1100  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1101  $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AlreadyPaid"), 0, 'L', 0);
1102  $y += $tab3_height - 2;
1103  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1104  $pdf->MultiCell(15, 3, price($object->total_ttc), 0, 'R', 0);
1105  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1106  $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AmountExpected"), 0, 'L', 0);
1107  $y += $tab3_height - 2;
1108  $remaintopay = $object->total_ttc - $totalpaid;
1109  $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1110  $pdf->MultiCell(15, 3, price($remaintopay), 0, 'R', 0);
1111  $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1112  $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("RemainderToPay"), 0, 'L', 0);
1113  }
1114  } else {
1115  $this->error = $this->db->lasterror();
1116  return -1;
1117  }
1118  }
1119 
1120  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1130  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1131  {
1132  global $conf;
1133  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1134  return pdf_pagefoot($pdf, $outputlangs, 'EXPENSEREPORT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1135  }
1136 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
pdf_getlinevatrate
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition: pdf.lib.php:1784
db
$conf db
API class for accounts.
Definition: inc.php:41
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_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdf_standard\printLine
printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails=0)
Definition: pdf_standard.modules.php:567
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
pdf_standard\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_standard.modules.php:1130
pdf_standard\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_standard.modules.php:654
name
$conf db name
Definition: repair.php:122
UserBankAccount
Class to manage bank accounts description of users.
Definition: userbankaccount.class.php:35
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
pdf_standard\tablePayments
tablePayments(&$pdf, $object, $posy, $outputlangs)
Show payments table.
Definition: pdf_standard.modules.php:1020
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
convertBackOfficeMediasLinksToPublicLinks
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...
Definition: functions2.lib.php:2711
dolGetFirstLastname
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
Definition: functions.lib.php:8062
User
Class to manage Dolibarr users.
Definition: user.class.php:44
pdf_standard\__construct
__construct($db)
Constructor.
Definition: pdf_standard.modules.php:104
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_standard\write_file
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
Definition: pdf_standard.modules.php:192
pdf_standard\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
Definition: pdf_standard.modules.php:901
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
pdf_getSubstitutionArray
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:737
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
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
pdf_standard
Class to generate expense report based on standard model.
Definition: pdf_standard.modules.php:45
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
complete_substitutions_array
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...
Definition: functions.lib.php:7961
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
ModeleExpenseReport
Parent class for trips and expenses templates.
Definition: modules_expensereport.php:24