dolibarr 24.0.0-beta
pdf_standard_supplierpayment.modules.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2022 Ferran Marcet <fmarcet@2byte.es>
7 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 Nick Fragoulis
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/supplier_payment/modules_supplier_payment.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functionsnumtoword.lib.php';
40
41
46{
51 protected function getDefaultThirdpartyIban($socid)
52 {
53 $iban = '';
54 if ((int) $socid <= 0) {
55 return '';
56 }
57
58 $sql = "SELECT iban_prefix as iban";
59 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as rib";
60 $sql .= " WHERE fk_soc = ".((int) $socid);
61 $sql .= " AND rib.default_rib = 1";
62 $sql .= " AND rib.type = 'ban'";
63 $sql .= " LIMIT 1";
64 $resql = $this->db->query($sql);
65 if ($resql) {
66 $obj = $this->db->fetch_object($resql);
67 if ($obj) {
68 $iban = dolDecrypt($obj->iban);
69 }
70 }
71
72 return (string) $iban;
73 }
74
79 protected function getSupplierRefsFromLines($lines)
80 {
81 $out = array();
82 if (!is_array($lines)) {
83 return $out;
84 }
85 foreach ($lines as $l) {
86 if (is_object($l) && !empty($l->ref_supplier)) {
87 $out[(string) $l->ref_supplier] = true;
88 }
89 }
90 return array_keys($out);
91 }
92
96 public $db;
97
101 public $name;
102
106 public $description;
107
111 public $update_main_doc_field;
112
116 public $type;
117
122 public $version = 'dolibarr';
123
127 public $posxdate;
131 public $posxreffacturefourn;
135 public $posxreffacture;
139 public $posxtype;
143 public $posxtotalht;
147 public $posxtva;
151 public $posxtotalttc;
152
153
159 public function __construct($db)
160 {
161 global $langs, $mysoc;
162
163 // Load translation files required by the page
164 $langs->loadLangs(array("main", "bills"));
165
166 $this->db = $db;
167 $this->name = "standard";
168 $this->description = $langs->trans('DocumentModelStandardPDF');
169 $this->update_main_doc_field = 0; // Save the name of generated file as the main doc when generating a doc with this template
170
171 // Page size for A4 format
172 $this->type = 'pdf';
173 $formatarray = pdf_getFormat();
174 $this->page_largeur = $formatarray['width'];
175 $this->page_hauteur = $formatarray['height'];
176 $this->format = array($this->page_largeur, $this->page_hauteur);
177 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
178 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
179 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
180 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
181 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
182 $this->option_logo = 1; // Display logo
183 $this->option_multilang = 1; // Available in several languages
184
185 // Define column position
186 $this->posxdate = $this->marge_gauche + 1;
187 $this->posxreffacturefourn = 30;
188 $this->posxreffacture = 65;
189 $this->posxtype = 100;
190 $this->posxtotalht = 80;
191 $this->posxtva = 90;
192 $this->posxtotalttc = 180;
193
194 if ($this->page_largeur < 210) { // To work with US executive format
195 $this->posxreffacturefourn -= 20;
196 $this->posxreffacture -= 20;
197 $this->posxtype -= 20;
198 $this->posxtotalht -= 20;
199 $this->posxtva -= 20;
200 $this->posxtotalttc -= 20;
201 }
202
203 $this->tva = array();
204 $this->tva_array = array();
205 $this->localtax1 = array();
206 $this->localtax2 = array();
207 $this->atleastoneratenotnull = 0;
208 $this->atleastonediscount = 0;
209
210 if ($mysoc === null) {
211 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
212 return;
213 }
214
215 // Get source company
216 $this->emetteur = $mysoc;
217 if (!$this->emetteur->country_code) {
218 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
219 }
220 }
221
222
223 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
235 public function write_file($object, $outputlangs = null, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
236 {
237 // phpcs:enable
238 global $user, $langs, $conf, $mysoc, $hookmanager;
239
240 if (!is_object($outputlangs)) {
241 $outputlangs = $langs;
242 }
243 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
244 if (getDolGlobalString('MAIN_USE_FPDF')) {
245 $outputlangs->charset_output = 'ISO-8859-1';
246 }
247
248 // Load translation files required by the page
249 $outputlangs->loadLangs(array("main", "suppliers", "companies", "bills", "dict", "products"));
250
251 $object->factures = array();
252
253 if ($conf->fournisseur->payment->dir_output) {
254 $object->fetch_thirdparty();
258 $sql = 'SELECT f.rowid, f.ref, f.datef, f.ref_supplier, f.total_ht, f.total_tva, f.total_ttc, pf.amount, f.rowid as facid, f.paye';
259 $sql .= ', f.fk_statut, s.nom as name, s.rowid as socid';
260 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
261 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
262 $sql .= ' AND pf.fk_paiementfourn = '.((int) $object->id);
263 $resql = $this->db->query($sql);
264 if ($resql) {
265 if ($this->db->num_rows($resql) > 0) {
266 while ($objp = $this->db->fetch_object($resql)) {
267 $objp->type = $outputlangs->trans('SupplierInvoice');
268 $object->lines[] = $objp;
269 }
270 }
271 }
272
273 $total = $object->amount;
274
275 // Definition of $dir and $file
276 if ($object->specimen) {
277 $dir = $conf->fournisseur->payment->dir_output;
278 $file = $dir."/SPECIMEN.pdf";
279 } else {
280 $objectref = dol_sanitizeFileName($object->ref);
281 //$objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
282 $dir = $conf->fournisseur->payment->dir_output.'/'.$objectref;
283 $file = $dir."/".$objectref.".pdf";
284 //if (getDolGlobalString('SUPPLIER_REF_IN_NAME')) {
285 // $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
286 //}
287 }
288
289 if (!file_exists($dir)) {
290 if (dol_mkdir($dir) < 0) {
291 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
292 return 0;
293 }
294 }
295
296 if (file_exists($dir)) {
297 // Add pdfgeneration hook
298 if (!is_object($hookmanager)) {
299 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
300 $hookmanager = new HookManager($this->db);
301 }
302 $hookmanager->initHooks(array('pdfgeneration'));
303 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
304 global $action;
305 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
306
307 $nblines = (empty($object->lines) ? 0 : count($object->lines));
308
309 $pdf = pdf_getInstance($this->format);
310 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
311 $heightforinfotot = 50; // Height reserved to output the info and total part
312 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
313 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
314 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
315 $heightforfooter += 6;
316 }
317 $pdf->setAutoPageBreak(true, 0);
318
319 if (class_exists('TCPDF')) {
320 $pdf->setPrintHeader(false);
321 $pdf->setPrintFooter(false);
322 }
323 $pdf->SetFont(pdf_getPDFFont($outputlangs));
324 // Set path to the background PDF File
325 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
326 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
327 $tplidx = $pdf->importPage(1);
328 }
329
330 $pdf->Open();
331 $pagenb = 0;
332 $pdf->SetDrawColor(128, 128, 128);
333
334 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
335 $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
336 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
337 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getAnonymisableFullName($outputlangs)));
338 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
339 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
340 $pdf->SetCompression(false);
341 }
342
343 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
344 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
345
346
347 // New page
348 $pdf->AddPage();
349 if (!empty($tplidx)) {
350 $pdf->useTemplate($tplidx);
351 }
352 $pagenb++;
353 $this->_pagehead($pdf, $object, 1, $outputlangs);
354 $pdf->SetFont('', '', $default_font_size - 1);
355 $pdf->MultiCell(0, 3, ''); // Set interline to 3
356 $pdf->SetTextColor(0, 0, 0);
357
358 $tab_top = 90;
359 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
360
361 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
362
363 // Incoterm
364 $height_incoterms = 0;
365
366 $height_note = 0;
367
368 $iniY = $tab_top + 7;
369 $curY = $tab_top + 7;
370 $nexY = $tab_top + 7;
371
372 // Loop on each lines
373 for ($i = 0; $i < $nblines; $i++) {
374 $curY = $nexY;
375 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
376 $pdf->SetTextColor(0, 0, 0);
377
378 $pdf->setTopMargin($tab_top_newpage);
379 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
380 $pageposbefore = $pdf->getPage();
381
382 // Description of product line
383 $curX = $this->posxdate - 1;
384 $showpricebeforepagebreak = 1;
385
386 $pdf->startTransaction();
387 //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,1);
388 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
389 $pageposafter = $pdf->getPage();
390 if ($pageposafter > $pageposbefore) { // There is a pagebreak
391 $pdf->rollbackTransaction(true);
392 $pageposafter = $pageposbefore;
393 //print $pageposafter.'-'.$pageposbefore;exit;
394 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
395 //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,1);
396 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
397 $posyafter = $pdf->GetY();
398 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
399 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
400 $pdf->AddPage('', '', true);
401 if (!empty($tplidx)) {
402 $pdf->useTemplate($tplidx);
403 }
404 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
405 $this->_pagehead($pdf, $object, 0, $outputlangs);
406 }
407 $pdf->setPage($pageposafter + 1);
408 }
409 } else {
410 // We found a page break
411 // Allows data in the first page if description is long enough to break in multiples pages
412 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
413 $showpricebeforepagebreak = 1;
414 } else {
415 $showpricebeforepagebreak = 0;
416 }
417 }
418 } else { // No pagebreak
419 $pdf->commitTransaction();
420 }
421
422 $nexY = $pdf->GetY();
423 $pageposafter = $pdf->getPage();
424 $pdf->setPage($pageposbefore);
425 $pdf->setTopMargin($this->marge_haute);
426 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
427
428 // We suppose that a too long description is moved completely on next page
429 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
430 $pdf->setPage($pageposafter);
431 $curY = $tab_top_newpage;
432 }
433
434 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default
435
436 // ref fourn
437 $pdf->SetXY($this->posxreffacturefourn, $curY);
438 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3, $object->lines[$i]->ref_supplier, 0, 'L', false);
439
440 // ref facture fourn
441 $pdf->SetXY($this->posxreffacture, $curY);
442 $pdf->MultiCell($this->posxreffacture - 0.8, 3, (string) $object->lines[$i]->ref, 0, 'L', false);
443
444 // type
445 $pdf->SetXY($this->posxtype, $curY);
446 $pdf->MultiCell($this->posxtype - 0.8, 3, $object->lines[$i]->type, 0, 'L', false);
447
448 // Total ht
449 $pdf->SetXY($this->posxtotalht, $curY);
450 $pdf->MultiCell($this->posxtotalht - 0.8, 3, price($object->lines[$i]->total_ht), 0, 'R', false);
451
452 // Total tva
453 $pdf->SetXY($this->posxtva, $curY);
454 $pdf->MultiCell($this->posxtva - 0.8, 3, price($object->lines[$i]->total_tva), 0, 'R', false);
455
456 // Total TTC line
457 $pdf->SetXY($this->posxtotalttc, $curY);
458 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3, price($object->lines[$i]->total_ttc), 0, 'R', false);
459
460
461 // Add line
462 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
463 $pdf->setPage($pageposafter);
464 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
465 //$pdf->SetDrawColor(190,190,200);
466 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
467 $pdf->SetLineStyle(array('dash' => 0));
468 }
469
470 $nexY += 2; // Add space between lines
471
472 // Detect if some page were added automatically and output _tableau for past pages
473 while ($pagenb < $pageposafter) {
474 $pdf->setPage($pagenb);
475 if ($pagenb == 1) {
476 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
477 } else {
478 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
479 }
480 $this->_pagefoot($pdf, $object, $outputlangs, 1);
481 $pagenb++;
482 $pdf->setPage($pagenb);
483 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
484 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
485 $this->_pagehead($pdf, $object, 0, $outputlangs);
486 }
487 if (!empty($tplidx)) {
488 $pdf->useTemplate($tplidx);
489 }
490 }
491 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
492 if ($pagenb == 1) {
493 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
494 } else {
495 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
496 }
497 $this->_pagefoot($pdf, $object, $outputlangs, 1);
498 // New page
499 $pdf->AddPage();
500 if (!empty($tplidx)) {
501 $pdf->useTemplate($tplidx);
502 }
503 $pagenb++;
504 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
505 $this->_pagehead($pdf, $object, 0, $outputlangs);
506 }
507 }
508 }
509
510 // Show square
511 if ($pagenb == 1) {
512 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
513 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
514 } else {
515 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
516 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
517 }
518
519 // Display check zone
520 $posy = $this->_tableau_cheque($pdf, $object, $bottomlasttab, $outputlangs);
521
522 // Affiche zone totaux
523 //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
524
525 // Footer page
526 $this->_pagefoot($pdf, $object, $outputlangs);
527 if (method_exists($pdf, 'AliasNbPages')) {
528 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
529 }
530
531 $pdf->Close();
532
533 $pdf->Output($file, 'F');
534
535 // Add pdfgeneration hook
536 $hookmanager->initHooks(array('pdfgeneration'));
537 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
538 global $action;
539 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
540 $this->warnings = $hookmanager->warnings;
541 if ($reshook < 0) {
542 $this->error = $hookmanager->error;
543 $this->errors = $hookmanager->errors;
544 dolChmod($file);
545 return -1;
546 }
547
548 dolChmod($file);
549
550 $this->result = array('fullpath' => $file);
551
552 return 1; // No error
553 } else {
554 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
555 return 0;
556 }
557 } else {
558 $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
559 return 0;
560 }
561 }
562
563 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
564 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
574 protected function _tableau_cheque(&$pdf, $object, $posy, $outputlangs)
575 {
576 // phpcs:enable
577 global $conf, $mysoc;
578
579 $default_font_size = pdf_getPDFFontSize($outputlangs);
580
581 $pdf->SetFont('', '', $default_font_size - 1);
582 $pdf->SetFillColor(255, 255, 255);
583
584 // N° payment
585 $pdf->SetXY($this->marge_gauche, $posy);
586 $pdf->MultiCell(30, 4, 'N° '.$outputlangs->transnoentities("Payment"), 0, 'L', true);
587
588 // Ref payment
589 $pdf->SetXY($this->marge_gauche + 30, $posy);
590 $pdf->MultiCell(50, 4, (string) $object->ref, 0, 'L', true);
591
592 // Total payments
593 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
594 $pdf->MultiCell(50, 4, price($object->amount), 0, 'R', true);
595 $posy += 20;
596
597 // translate amount
598 $currency = $conf->currency;
599 $translateinletter = strtoupper(dol_convertToWord((float) price2num($object->amount, 'MT'), $outputlangs, $currency));
600 $pdf->SetXY($this->marge_gauche + 50, $posy);
601 $pdf->SetFont('', '', $default_font_size - 3);
602 $pdf->MultiCell(90, 8, $translateinletter, 0, 'L', true);
603 $pdf->SetFont('', '', $default_font_size - 1);
604 $posy += 8;
605
606 // To
607 $pdf->SetXY($this->marge_gauche + 50, $posy);
608 $pdf->MultiCell(150, 4, $object->thirdparty->name, 0, 'L', true);
609
610 $LENGTHAMOUNT = 35;
611 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
612 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(price($object->amount).' '.$currency, 18, '*', STR_PAD_LEFT), 0, 'R', true);
613 $posy += 10;
614
615 // City
616 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
617 $pdf->MultiCell(150, 4, (string) $mysoc->town, 0, 'L', true);
618 $posy += 4;
619
620 // Date
621 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
622 $pdf->MultiCell(150, 4, date("d").' '.$outputlangs->transnoentitiesnoconv(date("F")).' '.date("Y"), 0, 'L', true);
623 return $posy;
624 }
625
626 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
640 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
641 {
642 global $conf, $mysoc;
643
644 // Force to disable hidetop and hidebottom
645 $hidebottom = 0;
646 if ($hidetop) {
647 $hidetop = -1;
648 }
649
650 $currency = !empty($currency) ? $currency : $conf->currency;
651 $default_font_size = pdf_getPDFFontSize($outputlangs);
652
653 // Amount in (at tab_top - 1)
654 $pdf->SetTextColor(0, 0, 0);
655 $pdf->SetFont('', '', $default_font_size - 2);
656
657 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
658 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top);
659 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
660
661
662 $pdf->SetDrawColor(128, 128, 128);
663 $pdf->SetFont('', '', $default_font_size - 1);
664
665 // Output Rect
666 //$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect takes a length in 3rd parameter and 4th parameter
667 }
668
669 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
679 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
680 {
681 global $langs, $conf, $mysoc;
682
683 // Load translation files required by the page
684 $outputlangs->loadLangs(array("main", "orders", "companies", "bills", "banks", "suppliers"));
685
686 $default_font_size = pdf_getPDFFontSize($outputlangs);
687
688 // Do not add the BACKGROUND as this is for suppliers
689 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
690
691 $pdf->SetTextColor(0, 0, 60);
692 $pdf->SetFont('', 'B', $default_font_size + 3);
693
694 $posy = $this->marge_haute;
695 $posx = $this->page_largeur - $this->marge_droite - 100;
696
697 $pdf->SetXY($this->marge_gauche, $posy);
698
699 // Logo
700 $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
701 if ($mysoc->logo) {
702 if (is_readable($logo)) {
703 $height = pdf_getHeightForLogo($logo);
704 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
705 } else {
706 $pdf->SetTextColor(200, 0, 0);
707 $pdf->SetFont('', 'B', $default_font_size - 2);
708 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
709 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
710 }
711 } else {
712 $text = $this->emetteur->name;
713 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
714 }
715
716 // Title (right)
717 $pdf->SetFont('', 'B', $default_font_size + 3);
718 $pdf->SetXY($posx, $posy);
719 $pdf->SetTextColor(0, 0, 60);
720 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("SupplierPayment")." ".$outputlangs->convToOutputCharset($object->ref), 0, 'R');
721
722 $pdf->SetFont('', '', $default_font_size - 1);
723 $posy += 6;
724 if (!empty($object->date)) {
725 $pdf->SetXY($posx, $posy);
726 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), 0, 'R');
727 $posy += 4;
728 }
729
730 $supplierRefs = $this->getSupplierRefsFromLines($object->lines);
731 if (!empty($supplierRefs)) {
732 $pdf->SetXY($posx, $posy);
733 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : ".implode(', ', $supplierRefs), 0, 'R');
734 $posy += 4;
735 }
736
737 $ibanDest = $this->getDefaultThirdpartyIban((int) $object->thirdparty->id);
738 if (!empty($ibanDest)) {
739 $pdf->SetXY($posx, $posy);
740 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("IBAN")." : ".$ibanDest, 0, 'R');
741 $posy += 4;
742 }
743 /*
744 $pdf->SetFont('','B', $default_font_size + 3);
745 $pdf->SetXY($posx,$posy);
746 $pdf->SetTextColor(0,0,60);
747 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierInvoice")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
748 $posy+=1;
749
750 if ($object->ref_supplier)
751 {
752 $posy+=4;
753 $pdf->SetFont('','B', $default_font_size);
754 $pdf->SetXY($posx,$posy);
755 $pdf->SetTextColor(0,0,60);
756 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : " . $object->ref_supplier, '', 'R');
757 $posy+=1;
758 }
759
760 $pdf->SetFont('','', $default_font_size - 1);
761
762 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
763 $object->fetchProject();
764 if (!empty($object->project->ref)) {
765 $posy += 3;
766 $pdf->SetXY($posx, $posy);
767 $pdf->SetTextColor(0, 0, 60);
768 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
769 }
770 }
771
772 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
773 $object->fetchProject();
774 if (!empty($object->project->ref))
775 {
776 $outputlangs->load("projects");
777 $posy+=4;
778 $pdf->SetXY($posx,$posy);
779 $langs->load("projects");
780 $pdf->SetTextColor(0,0,60);
781 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->project->ref), '', 'R');
782 }
783 }
784
785 if ($object->date)
786 {
787 $posy+=4;
788 $pdf->SetXY($posx,$posy);
789 $pdf->SetTextColor(0,0,60);
790 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
791 }
792 else
793 {
794 $posy+=4;
795 $pdf->SetXY($posx,$posy);
796 $pdf->SetTextColor(255,0,0);
797 $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
798 }
799
800 if ($object->thirdparty->code_fournisseur)
801 {
802 $posy+=4;
803 $pdf->SetXY($posx,$posy);
804 $pdf->SetTextColor(0,0,60);
805 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities((string) $object->thirdparty->code_fournisseur), '', 'R');
806 }
807
808 $posy+=1;
809 $pdf->SetTextColor(0,0,60);
810
811 // Show list of linked objects
812 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
813 */
814 if ($showaddress) {
815 // Sender properties
816 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
817
818 // Show payer
819 $posy = 42;
820 $posx = $this->marge_gauche;
821 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
822 $posx = $this->page_largeur - $this->marge_droite - 80;
823 }
824 $hautcadre = 40;
825
826 // Show sender frame
827 $pdf->SetTextColor(0, 0, 0);
828 $pdf->SetFont('', '', $default_font_size - 2);
829 $pdf->SetXY($posx, $posy - 5);
830 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("PayedBy"), 0, 'L');
831 $pdf->SetXY($posx, $posy);
832 $pdf->SetFillColor(230, 230, 230);
833 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
834 $pdf->SetTextColor(0, 0, 60);
835
836 // Show sender name
837 $pdf->SetXY($posx + 2, $posy + 3);
838 $pdf->SetFont('', 'B', $default_font_size);
839 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
840 $posy = $pdf->getY();
841
842 // Show sender information
843 $pdf->SetXY($posx + 2, $posy);
844 $pdf->SetFont('', '', $default_font_size - 1);
845 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
846
847 // Paid
848 $thirdparty = $object->thirdparty;
849
850 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
851
852 $usecontact = 0;
853
854 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
855
856 // Show recipient
857 $widthrecbox = 90;
858 if ($this->page_largeur < 210) {
859 $widthrecbox = 84; // To work with US executive format
860 }
861 $posy = 42;
862 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
863 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
864 $posx = $this->marge_gauche;
865 }
866
867 // Show recipient frame
868 $pdf->SetTextColor(0, 0, 0);
869 $pdf->SetFont('', '', $default_font_size - 2);
870 $pdf->SetXY($posx + 2, $posy - 5);
871 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("PayedTo"), 0, 'L');
872 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
873
874 // Show recipient name
875 $pdf->SetXY($posx + 2, $posy + 3);
876 $pdf->SetFont('', 'B', $default_font_size);
877 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
878
879 $posy = $pdf->getY();
880
881 // Show recipient information
882 $pdf->SetFont('', '', $default_font_size - 1);
883 $pdf->SetXY($posx + 2, $posy);
884 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
885
886 // Show default IBAN account (destination account)
887 $iban = $this->getDefaultThirdpartyIban((int) $object->thirdparty->id);
888 if (!empty($iban)) {
889 $pdf->SetFont('', '', $default_font_size - 1);
890 $pdf->SetXY($posx + 2, $posy + 15);
891 $pdf->MultiCell($widthrecbox, 4, $langs->trans("IBAN").': '.$iban, 0, 'L');
892 }
893
894 // Show origin bank account used for the payment (our bank account)
895 if (!empty($object->fk_account) && (int) $object->fk_account > 0) {
896 $bankaccount = new Account($this->db);
897 if ($bankaccount->fetch((int) $object->fk_account) > 0) {
898 $ibanOrigin = dolDecrypt((string) $bankaccount->iban);
899 if ($ibanOrigin === '' && !empty($bankaccount->iban)) {
900 $ibanOrigin = (string) $bankaccount->iban;
901 }
902 $label = (string) $bankaccount->label;
903 $line = $outputlangs->transnoentities("BankAccount").': '.$label;
904 if ($ibanOrigin !== '') {
905 $line .= ' - '.$langs->trans("IBAN").': '.$ibanOrigin;
906 } elseif (!empty($bankaccount->number)) {
907 $line .= ' - '.$outputlangs->transnoentities("Account").': '.$bankaccount->number;
908 }
909
910 $pdf->SetFont('', '', $default_font_size - 2);
911 $pdf->SetTextColor(0, 0, 0);
912 $pdf->SetXY($this->marge_gauche, 82);
913 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - $this->marge_droite, 4, $line, 0, 'L');
914 $pdf->SetTextColor(0, 0, 60);
915 }
916 }
917 }
918
919 return 0;
920 }
921
922 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
932 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
933 {
934 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
935 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
936 }
937}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage bank accounts.
Class to manage hooks.
Parent class for supplier invoices models.
Class to generate the supplier invoices payment file with the standard model.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_cheque(&$pdf, $object, $posy, $outputlangs)
Show total to pay.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
write_file($object, $outputlangs=null, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
global $mysoc
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(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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)
dol_convertToWord($num, $langs, $currency='', $centimes=false)
Function to return a number into a text.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:87
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:294
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:317
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:1421
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:273
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
Definition pdf.lib.php:438
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:129
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
Definition pdf.lib.php:393
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:487
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.