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