dolibarr 21.0.0-alpha
pdf_standard_expensereport.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-2023 Philippe Grand <philippe.grand@atoo-net.com>
5 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Nick Fragoulis
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 * or see https://www.gnu.org/
26 */
27
34require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
42require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php';
43
48{
52 public $db;
53
57 public $name;
58
62 public $description;
63
67 public $update_main_doc_field;
68
72 public $type;
73
78 public $version = 'dolibarr';
79
80 public $posxpiece;
81 public $posxcomment;
82 public $posxtva;
83 public $posxup;
84 public $posxqty;
85 public $posxtype;
86
90 public $posxdate;
91 public $posxprojet;
92 public $postotalht;
93 public $postotalttc;
94
95
101 public function __construct($db)
102 {
103 global $conf, $langs, $mysoc, $user;
104
105 // Translations
106 $langs->loadLangs(array("main", "trips", "projects"));
107
108 $this->db = $db;
109 $this->name = "";
110 $this->description = $langs->trans('PDFStandardExpenseReports');
111 $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
112
113 // Page size for A4 format
114 $this->type = 'pdf';
115 $formatarray = pdf_getFormat();
116 $this->page_largeur = $formatarray['width'];
117 $this->page_hauteur = $formatarray['height'];
118 $this->format = array($this->page_largeur, $this->page_hauteur);
119 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
120 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
121 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
122 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
123 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
124 $this->option_logo = 1; // Display logo
125 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
126 $this->option_modereg = 1; // Display payment mode
127 $this->option_condreg = 1; // Display payment terms
128 $this->option_multilang = 1; // Available in several languages
129 $this->option_escompte = 0; // Displays if there has been a discount
130 $this->option_credit_note = 0; // Support credit notes
131 $this->option_freetext = 1; // Support add of a personalised text
132 $this->option_draft_watermark = 1; // Support add of a watermark on drafts
133
134 // Define position of columns
135 $this->posxpiece = $this->marge_gauche + 1;
136 $this->posxcomment = $this->marge_gauche + 10;
137 //$this->posxdate=88;
138 //$this->posxtype=107;
139 //$this->posxprojet=120;
140 $this->posxtva = 112;
141 $this->posxup = 127;
142 $this->posxqty = 150;
143 $this->postotalht = 160;
144 $this->postotalttc = 180;
145 // if (!isModEnabled('project')) {
146 // $this->posxtva-=20;
147 // $this->posxup-=20;
148 // $this->posxqty-=20;
149 // $this->postotalttc-=20;
150 // }
151 if ($this->page_largeur < 210) { // To work with US executive format
152 $this->posxdate -= 20;
153 $this->posxtype -= 20;
154 $this->posxprojet -= 20;
155 $this->posxtva -= 20;
156 $this->posxup -= 20;
157 $this->posxqty -= 20;
158 $this->postotalttc -= 20;
159 }
160
161 $this->tva = array();
162 $this->tva_array = array();
163 $this->localtax1 = array();
164 $this->localtax2 = array();
165 $this->atleastoneratenotnull = 0;
166 $this->atleastonediscount = 0;
167
168 if ($mysoc === null) {
169 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
170 return;
171 }
172
173 // Get source company
174 $this->emetteur = $mysoc;
175
176 if (empty($this->emetteur->country_code)) {
177 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
178 }
179 }
180
181
182 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
194 public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
195 {
196 // phpcs:enable
197 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
198
199 if (!is_object($outputlangs)) {
200 $outputlangs = $langs;
201 }
202 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
203 if (getDolGlobalString('MAIN_USE_FPDF')) {
204 $outputlangs->charset_output = 'ISO-8859-1';
205 }
206
207 // Load traductions files required by page
208 $outputlangs->loadLangs(array("main", "trips", "projects", "dict", "bills", "banks"));
209
210 $nblines = count($object->lines);
211
212 if ($conf->expensereport->dir_output) {
213 // Definition of $dir and $file
214 if ($object->specimen) {
215 $dir = $conf->expensereport->dir_output;
216 $file = $dir."/SPECIMEN.pdf";
217 } else {
218 $objectref = dol_sanitizeFileName($object->ref);
219 $dir = $conf->expensereport->dir_output."/".$objectref;
220 $file = $dir."/".$objectref.".pdf";
221 }
222
223 if (!file_exists($dir)) {
224 if (dol_mkdir($dir) < 0) {
225 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
226 return 0;
227 }
228 }
229
230 if (file_exists($dir)) {
231 // Add pdfgeneration hook
232 if (!is_object($hookmanager)) {
233 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
234 $hookmanager = new HookManager($this->db);
235 }
236 $hookmanager->initHooks(array('pdfgeneration'));
237 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
238 global $action;
239 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
240
241 // Create pdf instance
242 $pdf = pdf_getInstance($this->format);
243 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
244 $heightforinfotot = 40; // Height reserved to output the info and total part
245 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
246 $heightforfooter = $this->marge_basse + 12; // Height reserved to output the footer (value include bottom margin)
247 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
248 $heightforfooter += 6;
249 }
250
251 $pdf->SetAutoPageBreak(1, 0);
252
253 if (class_exists('TCPDF')) {
254 $pdf->setPrintHeader(false);
255 $pdf->setPrintFooter(false);
256 }
257 $pdf->SetFont(pdf_getPDFFont($outputlangs));
258 // Set path to the background PDF File
259 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
260 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
261 $tplidx = $pdf->importPage(1);
262 }
263
264 $pdf->Open();
265 $pagenb = 0;
266 $pdf->SetDrawColor(128, 128, 128);
267
268 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
269 $pdf->SetSubject($outputlangs->transnoentities("Trips"));
270 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
271 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
272 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Trips"));
273 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
274 $pdf->SetCompression(false);
275 }
276
277 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
278 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
279
280 // New page
281 $pdf->AddPage();
282 if (!empty($tplidx)) {
283 $pdf->useTemplate($tplidx);
284 }
285 $pagenb++;
286 $this->_pagehead($pdf, $object, 1, $outputlangs);
287 $pdf->SetFont('', '', $default_font_size - 1);
288 $pdf->MultiCell(0, 3, ''); // Set interline to 3
289 $pdf->SetTextColor(0, 0, 0);
290
291 $tab_top = 95;
292 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 65 : 10);
293
294 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
295
296 // Show notes
297 $notetoshow = empty($object->note_public) ? '' : $object->note_public;
298 if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) {
299 // Get first sale rep
300 if (is_object($object->thirdparty)) {
301 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
302 $salerepobj = new User($this->db);
303 $salerepobj->fetch($salereparray[0]['id']);
304 if (!empty($salerepobj->signature)) {
305 $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
306 }
307 }
308 }
309 if ($notetoshow) {
310 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
311 complete_substitutions_array($substitutionarray, $outputlangs, $object);
312 $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
313 $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
314
315 $tab_top = 95;
316
317 $pdf->SetFont('', '', $default_font_size - 1);
318 $pdf->writeHTMLCell(190, 3, $this->posxpiece - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
319 $nexY = $pdf->GetY();
320 $height_note = $nexY - $tab_top;
321
322 // Rect takes a length in 3rd parameter
323 $pdf->SetDrawColor(192, 192, 192);
324 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1, $this->corner_radius, '1234', 'D');
325
326 $tab_height -= $height_note;
327 $tab_top = $nexY + 6;
328 } else {
329 $height_note = 0;
330 }
331
332 $iniY = $tab_top + 7;
333 $nexY = $tab_top + 7;
334
335 $showpricebeforepagebreak = 1;
336 $pdf->setTopMargin($tab_top_newpage);
337 // Loop on each lines
338 $i = 0;
339 while ($i < $nblines) {
340 $pdf->SetFont('', '', $default_font_size - 2); // Into loop to work with multipage
341 $pdf->SetTextColor(0, 0, 0);
342
343 $pdf->setTopMargin($tab_top_newpage);
344 if (empty($showpricebeforepagebreak) && ($i !== ($nblines - 1))) {
345 $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
346 } else {
347 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
348 }
349
350 $pageposbefore = $pdf->getPage();
351 $curY = $nexY;
352 $pdf->startTransaction();
353 $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
354 $pageposafter = $pdf->getPage();
355 if ($pageposafter > $pageposbefore) {
356 // There is a pagebreak
357 $pdf->rollbackTransaction(true);
358
359 $pageposafter = $pageposbefore;
360 //print $pageposafter.'-'.$pageposbefore;exit;
361 if (empty($showpricebeforepagebreak)) {
362 $pdf->AddPage('', '', true);
363 if (!empty($tplidx)) {
364 $pdf->useTemplate($tplidx);
365 }
366 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
367 $this->_pagehead($pdf, $object, 0, $outputlangs);
368 }
369 $pdf->setPage($pageposafter + 1);
370 $showpricebeforepagebreak = 1;
371 $nexY = $tab_top_newpage;
372 $nexY += ($pdf->getFontSize() * 1.3); // Add space between lines
373 $pdf->SetFont('', '', $default_font_size - 2); // Into loop to work with multipage
374 $pdf->SetTextColor(0, 0, 0);
375
376 $pdf->setTopMargin($tab_top_newpage);
377 continue;
378 } else {
379 $pdf->setPageOrientation('', 1, $heightforfooter);
380 $showpricebeforepagebreak = 0;
381 }
382
383 $this->printLine($pdf, $object, $i, $curY, $default_font_size, $outputlangs, $hidedetails);
384 $pageposafter = $pdf->getPage();
385 $posyafter = $pdf->GetY();
386 //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
387 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
388 // There is no space left for total+free text
389 if ($i == ($nblines - 1)) {
390 // No more lines, and no space left to show total, so we create a new page
391 $pdf->AddPage('', '', true);
392 if (!empty($tplidx)) {
393 $pdf->useTemplate($tplidx);
394 }
395 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
396 $this->_pagehead($pdf, $object, 0, $outputlangs);
397 }
398 $pdf->setPage($pageposafter + 1);
399 }
400 } else {
401 // We found a page break
402 // Allows data in the first page if description is long enough to break in multiples pages
403 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
404 $showpricebeforepagebreak = 1;
405 } else {
406 $showpricebeforepagebreak = 0;
407 }
408 }
409 } else { // No pagebreak
410 $pdf->commitTransaction();
411 }
412 $i++;
413 //nexY
414 $nexY = $pdf->GetY();
415 $pageposafter = $pdf->getPage();
416 $pdf->setPage($pageposbefore);
417 $pdf->setTopMargin($this->marge_haute);
418 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
419
420 //$nexY+=$nblineFollowComment*($pdf->getFontSize()*1.3); // Add space between lines
421 $nexY += ($pdf->getFontSize() * 1.3); // Add space between lines
422
423 // Detect if some page were added automatically and output _tableau for past pages
424 while ($pagenb < $pageposafter) {
425 $pdf->setPage($pagenb);
426 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
427 if ($pagenb == 1) {
428 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
429 } else {
430 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
431 }
432 $this->_pagefoot($pdf, $object, $outputlangs, 1);
433 $pagenb++;
434 $pdf->setPage($pagenb);
435 $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
436 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
437 $this->_pagehead($pdf, $object, 0, $outputlangs);
438 }
439 if (!empty($tplidx)) {
440 $pdf->useTemplate($tplidx);
441 }
442 }
443 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
444 if ($pagenb == 1) {
445 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
446 } else {
447 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
448 }
449 $this->_pagefoot($pdf, $object, $outputlangs, 1);
450 // New page
451 $pdf->AddPage();
452 if (!empty($tplidx)) {
453 $pdf->useTemplate($tplidx);
454 }
455 $pagenb++;
456 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
457 $this->_pagehead($pdf, $object, 0, $outputlangs);
458 }
459 }
460 }
461
462 // Show square
463 if ($pagenb == 1) {
464 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
465 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
466 } else {
467 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
468 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
469 }
470
471 $pdf->SetFont('', '', 10);
472
473 // Show total area box
474 $posy = $bottomlasttab + 5;
475 $posy_start_of_totals = $posy;
476 $pdf->SetXY(130, $posy);
477 $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L');
478 $pdf->SetXY(180, $posy);
479 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ht), 1, 'R');
480 $pdf->SetFillColor(248, 248, 248);
481
482 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
483 // TODO Show vat amount per tax level
484 $posy += 5;
485 $pdf->SetXY(130, $posy);
486 $pdf->SetTextColor(0, 0, 60);
487 $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalVAT"), 1, 'L');
488 $pdf->SetXY(180, $posy);
489 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_tva), 1, 'R');
490 }
491
492 $posy += 5;
493 $pdf->SetXY(130, $posy);
494 $pdf->SetFont('', 'B', 10);
495 $pdf->SetTextColor(0, 0, 60);
496 $pdf->MultiCell(70, 5, $outputlangs->transnoentities("TotalTTC"), 1, 'L');
497 $pdf->SetXY(180, $posy);
498 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 180, 5, price($object->total_ttc), 1, 'R');
499
500 // show payments zone
501 $sumPayments = $object->getSumPayments();
502 if ($sumPayments > 0 && !getDolGlobalString('PDF_EXPENSEREPORT_NO_PAYMENT_DETAILS')) {
503 $posy = $this->tablePayments($pdf, $object, $posy_start_of_totals, $outputlangs);
504 }
505
506 // Page footer
507 $this->_pagefoot($pdf, $object, $outputlangs);
508 if (method_exists($pdf, 'AliasNbPages')) {
509 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
510 }
511
512 $pdf->Close();
513
514 $pdf->Output($file, 'F');
515
516 // Add pdfgeneration hook
517 $hookmanager->initHooks(array('pdfgeneration'));
518 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
519 global $action;
520 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
521 if ($reshook < 0) {
522 $this->error = $hookmanager->error;
523 $this->errors = $hookmanager->errors;
524 }
525
526 dolChmod($file);
527
528 $this->result = array('fullpath' => $file);
529
530 return 1; // No error
531 } else {
532 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
533 return 0;
534 }
535 } else {
536 $this->error = $langs->trans("ErrorConstantNotDefined", "EXPENSEREPORT_OUTPUTDIR");
537 return 0;
538 }
539 }
540
551 protected function printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails = 0)
552 {
553 global $conf;
554 $pdf->SetFont('', '', $default_font_size - 1);
555 $pdf->SetTextColor(0, 0, 0);
556
557 // Accountancy piece
558 $pdf->SetXY($this->posxpiece, $curY);
559 $pdf->writeHTMLCell($this->posxcomment - $this->posxpiece - 0.8, 4, $this->posxpiece - 1, $curY, $linenumber + 1, 0, 1);
560
561 // Date
562 //$pdf->SetXY($this->posxdate -1, $curY);
563 //$pdf->MultiCell($this->posxtype-$this->posxdate-0.8, 4, dol_print_date($object->lines[$linenumber]->date,"day",false,$outputlangs), 0, 'C');
564
565 // Type
566 $pdf->SetXY($this->posxtype - 1, $curY);
567 $nextColumnPosX = $this->posxup;
568 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
569 $nextColumnPosX = $this->posxtva;
570 }
571 if (isModEnabled('project')) {
572 $nextColumnPosX = $this->posxprojet;
573 }
574
575 $expensereporttypecode = $object->lines[$linenumber]->type_fees_code;
576 $expensereporttypecodetoshow = ($outputlangs->trans(($expensereporttypecode)) == $expensereporttypecode ? $object->lines[$linenumber]->type_fees_libelle : $outputlangs->trans($expensereporttypecode));
577
578
579 if ($expensereporttypecodetoshow == $expensereporttypecode) {
580 $expensereporttypecodetoshow = preg_replace('/^(EX_|TF_)/', '', $expensereporttypecodetoshow);
581 }
582 //$expensereporttypecodetoshow = dol_trunc($expensereporttypecodetoshow, 9);
583
584 //$pdf->MultiCell($nextColumnPosX-$this->posxtype-0.8, 4, $expensereporttypecodetoshow, 0, 'C');
585
586 // Project
587 //if (isModEnabled('project'))
588 //{
589 // $pdf->SetFont('','', $default_font_size - 1);
590 // $pdf->SetXY($this->posxprojet, $curY);
591 // $pdf->MultiCell($this->posxtva-$this->posxprojet-0.8, 4, $object->lines[$linenumber]->projet_ref, 0, 'C');
592 //}
593
594 // VAT Rate
595 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
596 $vat_rate = pdf_getlinevatrate($object, $linenumber, $outputlangs, $hidedetails);
597 $pdf->SetXY($this->posxtva, $curY);
598 $pdf->MultiCell($this->posxup - $this->posxtva - 0.8, 4, $vat_rate, 0, 'R');
599 }
600
601 // Unit price
602 $pdf->SetXY($this->posxup, $curY);
603 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 4, price($object->lines[$linenumber]->value_unit), 0, 'R');
604
605 // Quantity
606 $pdf->SetXY($this->posxqty, $curY);
607 $pdf->MultiCell($this->postotalht - $this->posxqty - 0.8, 4, $object->lines[$linenumber]->qty, 0, 'R');
608
609 // Total without taxes
610 $pdf->SetXY($this->postotalht, $curY);
611 $pdf->MultiCell($this->postotalttc - $this->postotalht - 0.8, 4, price($object->lines[$linenumber]->total_ht), 0, 'R');
612
613 // Total with all taxes
614 $pdf->SetXY($this->postotalttc - 1, $curY);
615 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 4, price($object->lines[$linenumber]->total_ttc), 0, 'R');
616
617 // Comments
618 $pdf->SetXY($this->posxcomment, $curY);
619 $comment = $outputlangs->trans("Date").':'.dol_print_date($object->lines[$linenumber]->date, "day", false, $outputlangs).' ';
620 $comment .= $outputlangs->trans("Type").':'.$expensereporttypecodetoshow.'<br>';
621 if (!empty($object->lines[$linenumber]->projet_ref)) {
622 $comment .= $outputlangs->trans("Project").':'.$object->lines[$linenumber]->projet_ref.'<br>';
623 }
624 $comment .= $object->lines[$linenumber]->comments;
625 $pdf->writeHTMLCell($this->posxtva - $this->posxcomment - 0.8, 4, $this->posxcomment - 1, $curY, $comment, 0, 1);
626 }
627
628 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
638 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
639 {
640 // global $conf, $langs, $hookmanager;
641 global $user, $langs, $conf, $mysoc, $db, $hookmanager;
642
643 // Load traductions files required by page
644 $outputlangs->loadLangs(array("main", "trips", "companies"));
645
646 $default_font_size = pdf_getPDFFontSize($outputlangs);
647
648 /*
649 // ajout du fondu vert en bas de page à droite
650 $image_fondue = $conf->mycompany->dir_output.'/fondu_vert_.jpg';
651 $pdf->Image($image_fondue,20,107,200,190);
652
653 pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
654 */
655
656 // Draft watermark
657 if ($object->fk_statut == 0 && getDolGlobalString('EXPENSEREPORT_DRAFT_WATERMARK')) {
658 pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->EXPENSEREPORT_DRAFT_WATERMARK);
659 }
660
661 $pdf->SetTextColor(0, 0, 60);
662 $pdf->SetFont('', 'B', $default_font_size + 3);
663
664 $posy = $this->marge_haute;
665 $posx = $this->page_largeur - $this->marge_droite - 100;
666
667 $pdf->SetXY($this->marge_gauche, $posy);
668
669 // Logo
670 $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
671 if ($this->emetteur->logo) {
672 if (is_readable($logo)) {
673 $height = pdf_getHeightForLogo($logo);
674 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
675 } else {
676 $pdf->SetTextColor(200, 0, 0);
677 $pdf->SetFont('', 'B', $default_font_size - 2);
678 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
679 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
680 }
681 } else {
682 $text = $this->emetteur->name;
683 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
684 }
685
686 $pdf->SetFont('', 'B', $default_font_size + 4);
687 $pdf->SetXY($posx, $posy);
688 $pdf->SetTextColor(0, 0, 60);
689 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 6, $langs->trans("ExpenseReport"), 0, 'R');
690
691 $pdf->SetFont('', '', $default_font_size - 1);
692
693 // Ref complete
694 $posy += 8;
695 $pdf->SetXY($posx, $posy);
696 $pdf->SetTextColor(0, 0, 60);
697 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R');
698
699 // Date start period
700 $posy += 5;
701 $pdf->SetXY($posx, $posy);
702 $pdf->SetTextColor(0, 0, 60);
703 $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');
704
705 // Date end period
706 $posy += 5;
707 $pdf->SetXY($posx, $posy);
708 $pdf->SetTextColor(0, 0, 60);
709 $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');
710
711 // Status Expense Report
712 $posy += 6;
713 $pdf->SetXY($posx, $posy);
714 $pdf->SetFont('', 'B', $default_font_size + 2);
715 $pdf->SetTextColor(111, 81, 124);
716 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities($object->labelStatusShort[$object->status]), '', 'R');
717
718 if ($showaddress) {
719 // Sender properties
720 $carac_emetteur = '';
721 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->address);
722 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->convToOutputCharset($this->emetteur->zip).' '.$outputlangs->convToOutputCharset($this->emetteur->town);
723 $carac_emetteur .= "\n";
724 if ($this->emetteur->phone) {
725 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Phone")." : ".$outputlangs->convToOutputCharset($this->emetteur->phone);
726 }
727 if ($this->emetteur->fax) {
728 $carac_emetteur .= ($carac_emetteur ? ($this->emetteur->tel ? " - " : "\n") : '').$outputlangs->transnoentities("Fax")." : ".$outputlangs->convToOutputCharset($this->emetteur->fax);
729 }
730 if ($this->emetteur->email) {
731 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($this->emetteur->email);
732 }
733 if ($this->emetteur->url) {
734 $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Web")." : ".$outputlangs->convToOutputCharset($this->emetteur->url);
735 }
736
737 // Receiver Properties
738 $receiver = new User($this->db);
739 $receiver->fetch($object->fk_user_author);
740 $receiver_account = new UserBankAccount($this->db);
741 $receiver_account->fetch(0, '', $object->fk_user_author);
742 $expense_receiver = '';
743 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->address);
744 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->convToOutputCharset($receiver->zip).' '.$outputlangs->convToOutputCharset($receiver->town);
745 $expense_receiver .= "\n";
746 if ($receiver->email) {
747 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("Email")." : ".$outputlangs->convToOutputCharset($receiver->email);
748 }
749 if ($receiver_account->iban) {
750 $expense_receiver .= ($expense_receiver ? "\n" : '').$outputlangs->transnoentities("IBAN")." : ".$outputlangs->convToOutputCharset($receiver_account->iban);
751 }
752
753 // Show sender
754 $posy = 50;
755 $posx = $this->marge_gauche;
756 $hautcadre = 40;
757 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
758 $posx = 118;
759 }
760
761 // Show sender frame
762 $pdf->SetTextColor(0, 0, 0);
763 $pdf->SetFont('', 'B', $default_font_size - 2);
764 $pdf->SetXY($posx, $posy - 5);
765 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripSociete"), '', 'L');
766 $pdf->SetXY($posx, $posy);
767 $pdf->SetFillColor(224, 224, 224);
768 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
769 $pdf->SetTextColor(0, 0, 60);
770
771 // Show sender information
772 if (!getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
773 $pdf->SetXY($posx + 2, $posy + 3);
774 $pdf->SetFont('', 'B', $default_font_size);
775 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
776 $pdf->SetXY($posx + 2, $posy + 8);
777 $pdf->SetFont('', '', $default_font_size - 1);
778 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
779 } else {
780 $pdf->SetXY($posx + 2, $posy + 3);
781 $pdf->SetFont('', 'B', $default_font_size);
782 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset(dolGetFirstLastname($receiver->firstname, $receiver->lastname)), 0, 'L');
783 $pdf->SetXY($posx + 2, $posy + 8);
784 $pdf->SetFont('', '', $default_font_size - 1);
785 $pdf->MultiCell(80, 4, $expense_receiver, 0, 'L');
786 }
787
788 // Show recipient
789 $posy = 50;
790 $posx = 100;
791 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
792 $posx = $this->marge_gauche;
793 }
794
795 // Show recipient frame
796 $pdf->SetTextColor(0, 0, 0);
797 $pdf->SetFont('', 'B', 8);
798 $pdf->SetXY($posx, $posy - 5);
799 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripNDF")." :", 0, 'L');
800 $pdf->RoundedRect($posx, $posy, $this->page_largeur - $this->marge_gauche - $posx, $hautcadre, $this->corner_radius, '1234', 'D');
801
802 // Information for expense report (dates and users workflow)
803 if ($object->fk_user_author > 0) {
804 $userfee = new User($this->db);
805 $userfee->fetch($object->fk_user_author);
806 $posy += 3;
807 $pdf->SetXY($posx + 2, $posy);
808 $pdf->SetFont('', '', 10);
809 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
810 $posy = $pdf->GetY() + 1;
811 $pdf->SetXY($posx + 2, $posy);
812 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateCreation")." : ".dol_print_date($object->date_create, "day", false, $outputlangs), 0, 'L');
813 }
814
815 if ($object->fk_statut == 99) {
816 if ($object->fk_user_refuse > 0) {
817 $userfee = new User($this->db);
818 $userfee->fetch($object->fk_user_refuse);
819 $posy += 6;
820 $pdf->SetXY($posx + 2, $posy);
821 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("REFUSEUR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
822 $posy += 5;
823 $pdf->SetXY($posx + 2, $posy);
824 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_REFUS")." : ".$outputlangs->convToOutputCharset($object->detail_refuse), 0, 'L');
825 $posy += 5;
826 $pdf->SetXY($posx + 2, $posy);
827 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_REFUS")." : ".dol_print_date($object->date_refuse, "day", false, $outputlangs), 0, 'L');
828 }
829 } elseif ($object->fk_statut == 4) {
830 if ($object->fk_user_cancel > 0) {
831 $userfee = new User($this->db);
832 $userfee->fetch($object->fk_user_cancel);
833 $posy += 6;
834 $pdf->SetXY($posx + 2, $posy);
835 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("CANCEL_USER")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
836 $posy += 5;
837 $pdf->SetXY($posx + 2, $posy);
838 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_CANCEL")." : ".$outputlangs->convToOutputCharset($object->detail_cancel), 0, 'L');
839 $posy += 5;
840 $pdf->SetXY($posx + 2, $posy);
841 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_CANCEL")." : ".dol_print_date($object->date_cancel, "day", false, $outputlangs), 0, 'L');
842 }
843 } else {
844 if ($object->fk_user_approve > 0) {
845 $userfee = new User($this->db);
846 $userfee->fetch($object->fk_user_approve);
847 $posy += 6;
848 $pdf->SetXY($posx + 2, $posy);
849 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("VALIDOR")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
850 $posy += 5;
851 $pdf->SetXY($posx + 2, $posy);
852 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateApprove")." : ".dol_print_date($object->date_approve, "day", false, $outputlangs), 0, 'L');
853 }
854 }
855
856 if ($object->fk_statut == 6) {
857 if ($object->fk_user_paid > 0) {
858 $userfee = new User($this->db);
859 $userfee->fetch($object->fk_user_paid);
860 $posy += 6;
861 $pdf->SetXY($posx + 2, $posy);
862 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHORPAIEMENT")." : ".dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
863 $posy += 5;
864 $pdf->SetXY($posx + 2, $posy);
865 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_PAIEMENT")." : ".dol_print_date($object->date_paiement, "day", false, $outputlangs), 0, 'L');
866 }
867 }
868 }
869
870 return 0;
871 }
872
873 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
887 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
888 {
889 global $conf;
890
891 // Force to disable hidetop and hidebottom
892 $hidebottom = 0;
893 if ($hidetop) {
894 $hidetop = -1;
895 }
896
897 $currency = !empty($currency) ? $currency : $conf->currency;
898 $default_font_size = pdf_getPDFFontSize($outputlangs);
899
900 // Amount in (at tab_top - 1)
901 $pdf->SetTextColor(0, 0, 0);
902 $pdf->SetFont('', '', $default_font_size - 2);
903 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
904 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 4), $tab_top - 4);
905 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
906
907 $pdf->SetDrawColor(128, 128, 128);
908
909 // Rect takes a length in 3rd parameter
910 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, '1234', 'D');
911 if (empty($hidetop)) {
912 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
913 }
914
915 $pdf->SetFont('', '', 8);
916
917 // Accountancy piece
918 if (empty($hidetop)) {
919 $pdf->SetXY($this->posxpiece - 1, $tab_top + 1);
920 $pdf->MultiCell($this->posxcomment - $this->posxpiece - 0.8, 1, '', '', 'R');
921 }
922
923 // Comments
924 $pdf->line($this->posxcomment - 1, $tab_top, $this->posxcomment - 1, $tab_top + $tab_height);
925 if (empty($hidetop)) {
926 $pdf->SetXY($this->posxcomment - 1, $tab_top + 1);
927 $pdf->MultiCell($this->posxdate - $this->posxcomment - 0.8, 1, $outputlangs->transnoentities("Description"), '', 'L');
928 }
929
930 // Date
931 //$pdf->line($this->posxdate-1, $tab_top, $this->posxdate-1, $tab_top + $tab_height);
932 //if (empty($hidetop))
933 //{
934 // $pdf->SetXY($this->posxdate-1, $tab_top+1);
935 // $pdf->MultiCell($this->posxtype-$this->posxdate-1,2, $outputlangs->transnoentities("Date"),'','C');
936 //}
937
938 // Type
939 //$pdf->line($this->posxtype-1, $tab_top, $this->posxtype-1, $tab_top + $tab_height);
940 //if (empty($hidetop))
941 //{
942 // $pdf->SetXY($this->posxtype-1, $tab_top+1);
943 // $pdf->MultiCell($this->posxprojet-$this->posxtype - 1, 2, $outputlangs->transnoentities("Type"), '', 'C');
944 //}
945
946 //if (isModEnabled('project'))
947 //{
948 // // Project
949 // $pdf->line($this->posxprojet - 1, $tab_top, $this->posxprojet - 1, $tab_top + $tab_height);
950 // if (empty($hidetop)) {
951 // $pdf->SetXY($this->posxprojet - 1, $tab_top + 1);
952 // $pdf->MultiCell($this->posxtva - $this->posxprojet - 1, 2, $outputlangs->transnoentities("Project"), '', 'C');
953 // }
954 //}
955
956 // VAT
957 if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) {
958 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
959 if (empty($hidetop)) {
960 $pdf->SetXY($this->posxtva - 0.8, $tab_top + 1);
961 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 2, $outputlangs->transnoentities("VAT"), '', 'C');
962 }
963 }
964
965 // Unit price
966 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
967 if (empty($hidetop)) {
968 $pdf->SetXY($this->posxup - 0.8, $tab_top + 1);
969 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUTTC"), '', 'C');
970 }
971
972 // Quantity
973 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
974 if (empty($hidetop)) {
975 $pdf->SetXY($this->posxqty - 0.8, $tab_top + 1);
976 $pdf->MultiCell($this->postotalht - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
977 }
978
979 // Total without taxes
980 $pdf->line($this->postotalht - 1, $tab_top, $this->postotalht - 1, $tab_top + $tab_height);
981 if (empty($hidetop)) {
982 $pdf->SetXY($this->postotalht - 0.8, $tab_top + 1);
983 $pdf->MultiCell($this->postotalttc - $this->postotalht + 1, 2, $outputlangs->transnoentities("TotalHT"), '', 'C');
984 }
985
986 // Total with all taxes
987 $pdf->line($this->postotalttc, $tab_top, $this->postotalttc, $tab_top + $tab_height);
988 if (empty($hidetop)) {
989 $pdf->SetXY($this->postotalttc - 0.8, $tab_top + 1);
990 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 2, $outputlangs->transnoentities("TotalTTC"), '', 'R');
991 }
992
993 $pdf->SetTextColor(0, 0, 0);
994 }
995
1005 protected function tablePayments(&$pdf, $object, $posy, $outputlangs)
1006 {
1007 global $conf;
1008
1009 $sign = 1;
1010 $tab3_posx = $this->marge_gauche;
1011 $tab3_top = $posy;
1012 $tab3_width = 88;
1013 $tab3_height = 5;
1014
1015 $default_font_size = pdf_getPDFFontSize($outputlangs);
1016
1017 $title = $outputlangs->transnoentities("PaymentsAlreadyDone");
1018 $pdf->SetFont('', '', $default_font_size - 2);
1019 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1020 $pdf->SetTextColor(0, 0, 0);
1021 $pdf->MultiCell(60, 3, $title, 0, 'L', 0);
1022
1023 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width + 2, $tab3_top); // Top border line of table title
1024
1025 $pdf->SetXY($tab3_posx, $tab3_top + 1);
1026 $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Date"), 0, 'L', 0);
1027 $pdf->SetXY($tab3_posx + 19, $tab3_top + 1); // Old value 17
1028 $pdf->MultiCell(15, 3, $outputlangs->transnoentities("Amount"), 0, 'C', 0);
1029 $pdf->SetXY($tab3_posx + 35, $tab3_top + 1);
1030 $pdf->MultiCell(30, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
1031 if (isModEnabled("bank")) {
1032 $pdf->SetXY($tab3_posx + 65, $tab3_top + 1);
1033 $pdf->MultiCell(25, 3, $outputlangs->transnoentities("BankAccount"), 0, 'L', 0);
1034 }
1035 $pdf->line($tab3_posx, $tab3_top + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $tab3_height); // Bottom border line of table title
1036
1037 $y = 0;
1038
1039 // Loop on each payment
1040 // TODO create method on expensereport class to get payments
1041 // Payments already done (from payment on this expensereport)
1042 $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1043 $sql .= "c.code as p_code, c.libelle as payment_type,";
1044 $sql .= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1045 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."payment_expensereport as p";
1046 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
1047 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
1048 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
1049 $sql .= " WHERE e.rowid = ".((int) $object->id);
1050 $sql .= " AND p.fk_expensereport = e.rowid";
1051 $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
1052 $sql .= " ORDER BY dp";
1053
1054 $resql = $this->db->query($sql);
1055 if ($resql) {
1056 $num = $this->db->num_rows($resql);
1057 $totalpaid = 0;
1058 $i = 0;
1059 while ($i < $num) {
1060 $y += $tab3_height;
1061 $row = $this->db->fetch_object($resql);
1062
1063 $pdf->SetXY($tab3_posx, $tab3_top + $y + 1);
1064 $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->dp), 'day', false, $outputlangs, true), 0, 'L', 0);
1065 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y + 1);
1066 $pdf->MultiCell(15, 3, price($sign * $row->amount, 0, $outputlangs), 0, 'R', 0);
1067 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y + 1);
1068 $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort".$row->p_code);
1069
1070 $pdf->MultiCell(40, 3, $oper, 0, 'L', 0);
1071 if (isModEnabled("bank")) {
1072 $pdf->SetXY($tab3_posx + 65, $tab3_top + $y + 1);
1073 $pdf->MultiCell(30, 3, $row->baref, 0, 'L', 0);
1074 }
1075
1076 $pdf->line($tab3_posx, $tab3_top + $y + $tab3_height, $tab3_posx + $tab3_width + 2, $tab3_top + $y + $tab3_height); // Bottom line border of table
1077 $totalpaid += $row->amount;
1078 $i++;
1079 }
1080 if ($num > 0 && $object->paid == 0) {
1081 $y += $tab3_height;
1082
1083 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1084 $pdf->MultiCell(15, 3, price($totalpaid), 0, 'R', 0);
1085 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1086 $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AlreadyPaid"), 0, 'L', 0);
1087 $y += $tab3_height - 2;
1088 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1089 $pdf->MultiCell(15, 3, price($object->total_ttc), 0, 'R', 0);
1090 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1091 $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("AmountExpected"), 0, 'L', 0);
1092 $y += $tab3_height - 2;
1093 $remaintopay = $object->total_ttc - $totalpaid;
1094 $pdf->SetXY($tab3_posx + 17, $tab3_top + $y);
1095 $pdf->MultiCell(15, 3, price($remaintopay), 0, 'R', 0);
1096 $pdf->SetXY($tab3_posx + 35, $tab3_top + $y);
1097 $pdf->MultiCell(30, 4, $outputlangs->transnoentitiesnoconv("RemainderToPay"), 0, 'L', 0);
1098 }
1099 } else {
1100 $this->error = $this->db->lasterror();
1101 return -1;
1102 }
1103 return -1;
1104 }
1105
1106 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1116 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1117 {
1118 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1119 return pdf_pagefoot($pdf, $outputlangs, 'EXPENSEREPORT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1120 }
1121}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage hooks.
Parent class for trips and expenses templates.
Class to manage bank accounts description of users.
Class to manage Dolibarr users.
Class to generate expense report based on standard model.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
printLine(&$pdf, $object, $linenumber, $curY, $default_font_size, $outputlangs, $hidedetails=0)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
tablePayments(&$pdf, $object, $posy, $outputlangs)
Show payments table.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists( 'dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
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.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
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:1027
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
Definition pdf.lib.php:1938
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:765
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
Add a draft watermark on PDF files.
Definition pdf.lib.php:785
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140