dolibarr 23.0.3
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-2025 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.'/core/lib/company.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/functionsnumtoword.lib.php';
39
40
45{
49 public $db;
50
54 public $name;
55
59 public $description;
60
64 public $update_main_doc_field;
65
69 public $type;
70
75 public $version = 'dolibarr';
76
80 public $posxdate;
84 public $posxreffacturefourn;
88 public $posxreffacture;
92 public $posxtype;
96 public $posxtotalht;
100 public $posxtva;
104 public $posxtotalttc;
105
106
112 public function __construct($db)
113 {
114 global $langs, $mysoc;
115
116 // Load translation files required by the page
117 $langs->loadLangs(array("main", "bills"));
118
119 $this->db = $db;
120 $this->name = "standard";
121 $this->description = $langs->trans('DocumentModelStandardPDF');
122 $this->update_main_doc_field = 0; // Save the name of generated file as the main doc when generating a doc with this template
123
124 // Page size for A4 format
125 $this->type = 'pdf';
126 $formatarray = pdf_getFormat();
127 $this->page_largeur = $formatarray['width'];
128 $this->page_hauteur = $formatarray['height'];
129 $this->format = array($this->page_largeur, $this->page_hauteur);
130 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
131 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
132 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
133 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
134 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
135 $this->option_logo = 1; // Display logo
136 $this->option_multilang = 1; // Available in several languages
137
138 // Define column position
139 $this->posxdate = $this->marge_gauche + 1;
140 $this->posxreffacturefourn = 30;
141 $this->posxreffacture = 65;
142 $this->posxtype = 100;
143 $this->posxtotalht = 80;
144 $this->posxtva = 90;
145 $this->posxtotalttc = 180;
146
147 if ($this->page_largeur < 210) { // To work with US executive format
148 $this->posxreffacturefourn -= 20;
149 $this->posxreffacture -= 20;
150 $this->posxtype -= 20;
151 $this->posxtotalht -= 20;
152 $this->posxtva -= 20;
153 $this->posxtotalttc -= 20;
154 }
155
156 $this->tva = array();
157 $this->tva_array = array();
158 $this->localtax1 = array();
159 $this->localtax2 = array();
160 $this->atleastoneratenotnull = 0;
161 $this->atleastonediscount = 0;
162
163 if ($mysoc === null) {
164 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
165 return;
166 }
167
168 // Get source company
169 $this->emetteur = $mysoc;
170 if (!$this->emetteur->country_code) {
171 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
172 }
173 }
174
175
176 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
188 public function write_file($object, $outputlangs = null, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
189 {
190 // phpcs:enable
191 global $user, $langs, $conf, $mysoc, $hookmanager;
192
193 if (!is_object($outputlangs)) {
194 $outputlangs = $langs;
195 }
196 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
197 if (getDolGlobalString('MAIN_USE_FPDF')) {
198 $outputlangs->charset_output = 'ISO-8859-1';
199 }
200
201 // Load translation files required by the page
202 $outputlangs->loadLangs(array("main", "suppliers", "companies", "bills", "dict", "products"));
203
204 $object->factures = array();
205
206 if ($conf->fournisseur->payment->dir_output) {
207 $object->fetch_thirdparty();
211 $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';
212 $sql .= ', f.fk_statut, s.nom as name, s.rowid as socid';
213 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
214 $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
215 $sql .= ' AND pf.fk_paiementfourn = '.((int) $object->id);
216 $resql = $this->db->query($sql);
217 if ($resql) {
218 if ($this->db->num_rows($resql) > 0) {
219 while ($objp = $this->db->fetch_object($resql)) {
220 $objp->type = $outputlangs->trans('SupplierInvoice');
221 $object->lines[] = $objp;
222 }
223 }
224 }
225
226 $total = $object->amount;
227
228 // Definition of $dir and $file
229 if ($object->specimen) {
230 $dir = $conf->fournisseur->payment->dir_output;
231 $file = $dir."/SPECIMEN.pdf";
232 } else {
233 $objectref = dol_sanitizeFileName($object->ref);
234 //$objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
235 $dir = $conf->fournisseur->payment->dir_output.'/'.$objectref;
236 $file = $dir."/".$objectref.".pdf";
237 //if (getDolGlobalString('SUPPLIER_REF_IN_NAME')) {
238 // $file = $dir."/".$objectref.($objectrefsupplier ? "_".$objectrefsupplier : "").".pdf";
239 //}
240 }
241
242 if (!file_exists($dir)) {
243 if (dol_mkdir($dir) < 0) {
244 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
245 return 0;
246 }
247 }
248
249 if (file_exists($dir)) {
250 // Add pdfgeneration hook
251 if (!is_object($hookmanager)) {
252 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
253 $hookmanager = new HookManager($this->db);
254 }
255 $hookmanager->initHooks(array('pdfgeneration'));
256 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
257 global $action;
258 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
259
260 $nblines = (empty($object->lines) ? 0 : count($object->lines));
261
262 $pdf = pdf_getInstance($this->format);
263 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
264 $heightforinfotot = 50; // Height reserved to output the info and total part
265 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
266 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
267 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
268 $heightforfooter += 6;
269 }
270 $pdf->setAutoPageBreak(true, 0);
271
272 if (class_exists('TCPDF')) {
273 $pdf->setPrintHeader(false);
274 $pdf->setPrintFooter(false);
275 }
276 $pdf->SetFont(pdf_getPDFFont($outputlangs));
277 // Set path to the background PDF File
278 if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) {
279 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND'));
280 $tplidx = $pdf->importPage(1);
281 }
282
283 $pdf->Open();
284 $pagenb = 0;
285 $pdf->SetDrawColor(128, 128, 128);
286
287 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
288 $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
289 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
290 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
291 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
292 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
293 $pdf->SetCompression(false);
294 }
295
296 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
297 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
298
299
300 // New page
301 $pdf->AddPage();
302 if (!empty($tplidx)) {
303 $pdf->useTemplate($tplidx);
304 }
305 $pagenb++;
306 $this->_pagehead($pdf, $object, 1, $outputlangs);
307 $pdf->SetFont('', '', $default_font_size - 1);
308 $pdf->MultiCell(0, 3, ''); // Set interline to 3
309 $pdf->SetTextColor(0, 0, 0);
310
311 $tab_top = 90;
312 $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
313
314 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
315
316 // Incoterm
317 $height_incoterms = 0;
318
319 $height_note = 0;
320
321 $iniY = $tab_top + 7;
322 $curY = $tab_top + 7;
323 $nexY = $tab_top + 7;
324
325 // Loop on each lines
326 for ($i = 0; $i < $nblines; $i++) {
327 $curY = $nexY;
328 $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
329 $pdf->SetTextColor(0, 0, 0);
330
331 $pdf->setTopMargin($tab_top_newpage);
332 $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
333 $pageposbefore = $pdf->getPage();
334
335 // Description of product line
336 $curX = $this->posxdate - 1;
337 $showpricebeforepagebreak = 1;
338
339 $pdf->startTransaction();
340 //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,1);
341 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
342 $pageposafter = $pdf->getPage();
343 if ($pageposafter > $pageposbefore) { // There is a pagebreak
344 $pdf->rollbackTransaction(true);
345 $pageposafter = $pageposbefore;
346 //print $pageposafter.'-'.$pageposbefore;exit;
347 $pdf->setPageOrientation('', true, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
348 //pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,1);
349 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY, $object->lines[$i]->datef, 0, 1, false, true, 'J', true);
350 $posyafter = $pdf->GetY();
351 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
352 if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
353 $pdf->AddPage('', '', true);
354 if (!empty($tplidx)) {
355 $pdf->useTemplate($tplidx);
356 }
357 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
358 $this->_pagehead($pdf, $object, 0, $outputlangs);
359 }
360 $pdf->setPage($pageposafter + 1);
361 }
362 } else {
363 // We found a page break
364 // Allows data in the first page if description is long enough to break in multiples pages
365 if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
366 $showpricebeforepagebreak = 1;
367 } else {
368 $showpricebeforepagebreak = 0;
369 }
370 }
371 } else { // No pagebreak
372 $pdf->commitTransaction();
373 }
374
375 $nexY = $pdf->GetY();
376 $pageposafter = $pdf->getPage();
377 $pdf->setPage($pageposbefore);
378 $pdf->setTopMargin($this->marge_haute);
379 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
380
381 // We suppose that a too long description is moved completely on next page
382 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
383 $pdf->setPage($pageposafter);
384 $curY = $tab_top_newpage;
385 }
386
387 $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default
388
389 // ref fourn
390 $pdf->SetXY($this->posxreffacturefourn, $curY);
391 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3, $object->lines[$i]->ref_supplier, 0, 'L', false);
392
393 // ref facture fourn
394 $pdf->SetXY($this->posxreffacture, $curY);
395 $pdf->MultiCell($this->posxreffacture - 0.8, 3, $object->lines[$i]->ref, 0, 'L', false);
396
397 // type
398 $pdf->SetXY($this->posxtype, $curY);
399 $pdf->MultiCell($this->posxtype - 0.8, 3, $object->lines[$i]->type, 0, 'L', false);
400
401 // Total ht
402 $pdf->SetXY($this->posxtotalht, $curY);
403 $pdf->MultiCell($this->posxtotalht - 0.8, 3, price($object->lines[$i]->total_ht), 0, 'R', false);
404
405 // Total tva
406 $pdf->SetXY($this->posxtva, $curY);
407 $pdf->MultiCell($this->posxtva - 0.8, 3, price($object->lines[$i]->total_tva), 0, 'R', false);
408
409 // Total TTC line
410 $pdf->SetXY($this->posxtotalttc, $curY);
411 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3, price($object->lines[$i]->total_ttc), 0, 'R', false);
412
413
414 // Add line
415 if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
416 $pdf->setPage($pageposafter);
417 $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
418 //$pdf->SetDrawColor(190,190,200);
419 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
420 $pdf->SetLineStyle(array('dash' => 0));
421 }
422
423 $nexY += 2; // Add space between lines
424
425 // Detect if some page were added automatically and output _tableau for past pages
426 while ($pagenb < $pageposafter) {
427 $pdf->setPage($pagenb);
428 if ($pagenb == 1) {
429 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
430 } else {
431 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
432 }
433 $this->_pagefoot($pdf, $object, $outputlangs, 1);
434 $pagenb++;
435 $pdf->setPage($pagenb);
436 $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it.
437 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
438 $this->_pagehead($pdf, $object, 0, $outputlangs);
439 }
440 if (!empty($tplidx)) {
441 $pdf->useTemplate($tplidx);
442 }
443 }
444 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
445 if ($pagenb == 1) {
446 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
447 } else {
448 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
449 }
450 $this->_pagefoot($pdf, $object, $outputlangs, 1);
451 // New page
452 $pdf->AddPage();
453 if (!empty($tplidx)) {
454 $pdf->useTemplate($tplidx);
455 }
456 $pagenb++;
457 if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
458 $this->_pagehead($pdf, $object, 0, $outputlangs);
459 }
460 }
461 }
462
463 // Show square
464 if ($pagenb == 1) {
465 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
466 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
467 } else {
468 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
469 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
470 }
471
472 // Display check zone
473 $posy = $this->_tableau_cheque($pdf, $object, $bottomlasttab, $outputlangs);
474
475 // Affiche zone totaux
476 //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
477
478 // Footer page
479 $this->_pagefoot($pdf, $object, $outputlangs);
480 if (method_exists($pdf, 'AliasNbPages')) {
481 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
482 }
483
484 $pdf->Close();
485
486 $pdf->Output($file, 'F');
487
488 // Add pdfgeneration hook
489 $hookmanager->initHooks(array('pdfgeneration'));
490 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
491 global $action;
492 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
493 $this->warnings = $hookmanager->warnings;
494 if ($reshook < 0) {
495 $this->error = $hookmanager->error;
496 $this->errors = $hookmanager->errors;
497 dolChmod($file);
498 return -1;
499 }
500
501 dolChmod($file);
502
503 $this->result = array('fullpath' => $file);
504
505 return 1; // No error
506 } else {
507 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
508 return 0;
509 }
510 } else {
511 $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
512 return 0;
513 }
514 }
515
516 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
517 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
527 protected function _tableau_cheque(&$pdf, $object, $posy, $outputlangs)
528 {
529 // phpcs:enable
530 global $conf, $mysoc;
531
532 $default_font_size = pdf_getPDFFontSize($outputlangs);
533
534 $pdf->SetFont('', '', $default_font_size - 1);
535 $pdf->SetFillColor(255, 255, 255);
536
537 // N° payment
538 $pdf->SetXY($this->marge_gauche, $posy);
539 $pdf->MultiCell(30, 4, 'N° '.$outputlangs->transnoentities("Payment"), 0, 'L', true);
540
541 // Ref payment
542 $pdf->SetXY($this->marge_gauche + 30, $posy);
543 $pdf->MultiCell(50, 4, $object->ref, 0, 'L', true);
544
545 // Total payments
546 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
547 $pdf->MultiCell(50, 4, price($object->amount), 0, 'R', true);
548 $posy += 20;
549
550 // translate amount
551 $currency = $conf->currency;
552 $translateinletter = strtoupper(dol_convertToWord((float) price2num($object->amount, 'MT'), $outputlangs, $currency));
553 $pdf->SetXY($this->marge_gauche + 50, $posy);
554 $pdf->SetFont('', '', $default_font_size - 3);
555 $pdf->MultiCell(90, 8, $translateinletter, 0, 'L', true);
556 $pdf->SetFont('', '', $default_font_size - 1);
557 $posy += 8;
558
559 // To
560 $pdf->SetXY($this->marge_gauche + 50, $posy);
561 $pdf->MultiCell(150, 4, $object->thirdparty->name, 0, 'L', true);
562
563 $LENGTHAMOUNT = 35;
564 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
565 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(price($object->amount).' '.$currency, 18, '*', STR_PAD_LEFT), 0, 'R', true);
566 $posy += 10;
567
568 // City
569 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
570 $pdf->MultiCell(150, 4, $mysoc->town, 0, 'L', true);
571 $posy += 4;
572
573 // Date
574 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
575 $pdf->MultiCell(150, 4, date("d").' '.$outputlangs->transnoentitiesnoconv(date("F")).' '.date("Y"), 0, 'L', true);
576 return $posy;
577 }
578
579 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
593 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
594 {
595 global $conf, $mysoc;
596
597 // Force to disable hidetop and hidebottom
598 $hidebottom = 0;
599 if ($hidetop) {
600 $hidetop = -1;
601 }
602
603 $currency = !empty($currency) ? $currency : $conf->currency;
604 $default_font_size = pdf_getPDFFontSize($outputlangs);
605
606 // Amount in (at tab_top - 1)
607 $pdf->SetTextColor(0, 0, 0);
608 $pdf->SetFont('', '', $default_font_size - 2);
609
610 /*$titre = strtoupper($mysoc->town).' - '.dol_print_date(dol_now(), 'day', 'tzserver', $outputlangs);
611 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3) - 60, $tab_top - 6);
612 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);*/
613
614 $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
615 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top);
616 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
617
618
619 $pdf->SetDrawColor(128, 128, 128);
620 $pdf->SetFont('', '', $default_font_size - 1);
621
622 // Output Rect
623 //$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
624 }
625
626 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
636 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
637 {
638 global $langs, $conf, $mysoc;
639
640 // Load translation files required by the page
641 $outputlangs->loadLangs(array("main", "orders", "companies", "bills"));
642
643 $default_font_size = pdf_getPDFFontSize($outputlangs);
644
645 // Do not add the BACKGROUND as this is for suppliers
646 //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
647
648 $pdf->SetTextColor(0, 0, 60);
649 $pdf->SetFont('', 'B', $default_font_size + 3);
650
651 $posy = $this->marge_haute;
652 $posx = $this->page_largeur - $this->marge_droite - 100;
653
654 $pdf->SetXY($this->marge_gauche, $posy);
655
656 // Logo
657 $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
658 if ($mysoc->logo) {
659 if (is_readable($logo)) {
660 $height = pdf_getHeightForLogo($logo);
661 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
662 } else {
663 $pdf->SetTextColor(200, 0, 0);
664 $pdf->SetFont('', 'B', $default_font_size - 2);
665 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
666 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
667 }
668 } else {
669 $text = $this->emetteur->name;
670 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
671 }
672 /*
673 $pdf->SetFont('','B', $default_font_size + 3);
674 $pdf->SetXY($posx,$posy);
675 $pdf->SetTextColor(0,0,60);
676 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierInvoice")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
677 $posy+=1;
678
679 if ($object->ref_supplier)
680 {
681 $posy+=4;
682 $pdf->SetFont('','B', $default_font_size);
683 $pdf->SetXY($posx,$posy);
684 $pdf->SetTextColor(0,0,60);
685 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier")." : " . $object->ref_supplier, '', 'R');
686 $posy+=1;
687 }
688
689 $pdf->SetFont('','', $default_font_size - 1);
690
691 if (getDolGlobalString('PDF_SHOW_PROJECT_TITLE')) {
692 $object->fetchProject();
693 if (!empty($object->project->ref)) {
694 $posy += 3;
695 $pdf->SetXY($posx, $posy);
696 $pdf->SetTextColor(0, 0, 60);
697 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
698 }
699 }
700
701 if (getDolGlobalString('PDF_SHOW_PROJECT')) {
702 $object->fetchProject();
703 if (!empty($object->project->ref))
704 {
705 $outputlangs->load("projects");
706 $posy+=4;
707 $pdf->SetXY($posx,$posy);
708 $langs->load("projects");
709 $pdf->SetTextColor(0,0,60);
710 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->project->ref), '', 'R');
711 }
712 }
713
714 if ($object->date)
715 {
716 $posy+=4;
717 $pdf->SetXY($posx,$posy);
718 $pdf->SetTextColor(0,0,60);
719 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
720 }
721 else
722 {
723 $posy+=4;
724 $pdf->SetXY($posx,$posy);
725 $pdf->SetTextColor(255,0,0);
726 $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
727 }
728
729 if ($object->thirdparty->code_fournisseur)
730 {
731 $posy+=4;
732 $pdf->SetXY($posx,$posy);
733 $pdf->SetTextColor(0,0,60);
734 $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
735 }
736
737 $posy+=1;
738 $pdf->SetTextColor(0,0,60);
739
740 // Show list of linked objects
741 $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
742 */
743 if ($showaddress) {
744 // Sender properties
745 $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
746
747 // Show payer
748 $posy = 42;
749 $posx = $this->marge_gauche;
750 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
751 $posx = $this->page_largeur - $this->marge_droite - 80;
752 }
753 $hautcadre = 40;
754
755 // Show sender frame
756 $pdf->SetTextColor(0, 0, 0);
757 $pdf->SetFont('', '', $default_font_size - 2);
758 $pdf->SetXY($posx, $posy - 5);
759 $pdf->MultiCell(80, 5, $outputlangs->transnoentities("PayedBy"), 0, 'L');
760 $pdf->SetXY($posx, $posy);
761 $pdf->SetFillColor(230, 230, 230);
762 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius, '1234', 'F');
763 $pdf->SetTextColor(0, 0, 60);
764
765 // Show sender name
766 $pdf->SetXY($posx + 2, $posy + 3);
767 $pdf->SetFont('', 'B', $default_font_size);
768 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
769 $posy = $pdf->getY();
770
771 // Show sender information
772 $pdf->SetXY($posx + 2, $posy);
773 $pdf->SetFont('', '', $default_font_size - 1);
774 $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
775
776 // Paid
777 $thirdparty = $object->thirdparty;
778
779 $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
780
781 $usecontact = 0;
782
783 $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ((!empty($object->contact)) ? $object->contact : null), $usecontact, 'target', $object);
784
785 // Show recipient
786 $widthrecbox = 90;
787 if ($this->page_largeur < 210) {
788 $widthrecbox = 84; // To work with US executive format
789 }
790 $posy = 42;
791 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
792 if (getDolGlobalString('MAIN_INVERT_SENDER_RECIPIENT')) {
793 $posx = $this->marge_gauche;
794 }
795
796 // Show recipient frame
797 $pdf->SetTextColor(0, 0, 0);
798 $pdf->SetFont('', '', $default_font_size - 2);
799 $pdf->SetXY($posx + 2, $posy - 5);
800 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("PayedTo"), 0, 'L');
801 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1234', 'D');
802
803 // Show recipient name
804 $pdf->SetXY($posx + 2, $posy + 3);
805 $pdf->SetFont('', 'B', $default_font_size);
806 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
807
808 $posy = $pdf->getY();
809
810 // Show recipient information
811 $pdf->SetFont('', '', $default_font_size - 1);
812 $pdf->SetXY($posx + 2, $posy);
813 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
814
815 // Show default IBAN account
816 $iban = '';
817 $sql = "SELECT iban_prefix as iban";
818 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as rib";
819 $sql .= " WHERE fk_soc = ".($object->thirdparty->id);
820 $sql .= " AND rib.default_rib = 1";
821 $sql .= " AND rib.type = 'ban'";
822 $sql .= " LIMIT 1";
823 $resql = $this->db->query($sql);
824 if ($resql) {
825 $obj = $this->db->fetch_object($resql);
826 if ($obj) {
827 $iban = dolDecrypt($obj->iban);
828 }
829 }
830
831 if (!empty($iban)) {
832 $pdf->SetFont('', '', $default_font_size - 1);
833 $pdf->SetXY($posx + 2, $posy + 15);
834 $pdf->MultiCell($widthrecbox, 4, $langs->trans("IBAN").': '.$iban, 0, 'L');
835 }
836 }
837
838 return 0;
839 }
840
841 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
851 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
852 {
853 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
854 return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
855 }
856}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
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.
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.
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:289
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:312
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:1110
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:268
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:433
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:388
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:464
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:125
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.