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