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