dolibarr 21.0.0-beta
pdf_blochet.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2009-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Nick Fragoulis
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/lib/pdf.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
33
34
39{
43 public $tab_top;
44
48 public $tab_height;
49
53 public $line_height;
54
58 public $line_per_page;
59
63 public $ref_ext;
64
65
71 public function __construct($db)
72 {
73 global $langs, $mysoc;
74
75 // Load traductions files required by page
76 $langs->loadLangs(array("main", "bills"));
77
78 $this->db = $db;
79 $this->name = "blochet";
80
81 $this->tab_top = 60;
82
83 // Page size for A4 format
84 $this->type = 'pdf';
85 $formatarray = pdf_getFormat();
86 $this->page_largeur = $formatarray['width'];
87 $this->page_hauteur = $formatarray['height'];
88 $this->format = array($this->page_largeur, $this->page_hauteur);
89 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
90 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
91 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
92 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
93 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
94
95 // Define column position
96 $this->line_height = 5;
97 $this->line_per_page = 40;
98 $this->tab_height = 200; //$this->line_height * $this->line_per_page;
99
100 if ($mysoc === null) {
101 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
102 return;
103 }
104 // Retrieves issuer
105 $this->emetteur = $mysoc;
106 if (!$this->emetteur->country_code) {
107 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
108 }
109 }
110
111 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
121 public function write_file($object, $_dir, $number, $outputlangs)
122 {
123 // phpcs:enable
124 global $user, $conf, $langs, $hookmanager;
125
126 if (!is_object($outputlangs)) {
127 $outputlangs = $langs;
128 }
129 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
130 $sav_charset_output = $outputlangs->charset_output;
131 if (getDolGlobalString('MAIN_USE_FPDF')) {
132 $outputlangs->charset_output = 'ISO-8859-1';
133 }
134
135 // Load traductions files required by page
136 $outputlangs->loadLangs(array("main", "companies", "bills", "products", "compta"));
137
138 $dir = $_dir."/".get_exdir($number, 0, 1, 0, $object, 'checkdeposits');
139
140 if (!is_dir($dir)) {
141 $result = dol_mkdir($dir);
142
143 if ($result < 0) {
144 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
145 return -1;
146 }
147 }
148
149 $file = $dir."/bordereau-".$number.".pdf";
150
151 // Add pdfgeneration hook
152 if (!is_object($hookmanager)) {
153 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
154 $hookmanager = new HookManager($this->db);
155 }
156 $hookmanager->initHooks(array('pdfgeneration'));
157 $parameters = array('file' => $file, 'outputlangs' => $outputlangs);
158 global $action;
159 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
160
161 // Create PDF instance
162 $pdf = pdf_getInstance($this->format);
163 $heightforinfotot = 50; // Height reserved to output the info and total part
164 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
165 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
166 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
167 $heightforfooter += 6;
168 }
169 $pdf->SetAutoPageBreak(1, 0);
170
171 if (class_exists('TCPDF')) {
172 $pdf->setPrintHeader(false);
173 $pdf->setPrintFooter(false);
174 }
175 $pdf->SetFont(pdf_getPDFFont($outputlangs));
176
177 $pdf->Open();
178 $pagenb = 0;
179 $pdf->SetDrawColor(128, 128, 128);
180
181 $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
182 $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
183 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
184 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
185 $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
186 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
187 $pdf->SetCompression(false);
188 }
189
190 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
191 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
192
193 $nboflines = count($this->lines);
194
195 // Define nb of page
196 $pages = intval($nboflines / $this->line_per_page);
197 if (($nboflines % $this->line_per_page) > 0) {
198 $pages++;
199 }
200 if ($pages == 0) {
201 // force to build at least one page if report has no lines
202 $pages = 1;
203 }
204
205 $pdf->AddPage();
206 $pagenb++;
207 $this->Header($pdf, $pagenb, $pages, $outputlangs);
208
209 $this->Body($pdf, $pagenb, $pages, $outputlangs);
210
211 // Pied de page
212 $this->_pagefoot($pdf, null, $outputlangs);
213 if (method_exists($pdf, 'AliasNbPages')) {
214 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
215 }
216
217 $pdf->Close();
218
219 $pdf->Output($file, 'F');
220
221 // Add pdfgeneration hook
222 if (!is_object($hookmanager)) {
223 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
224 $hookmanager = new HookManager($this->db);
225 }
226 $hookmanager->initHooks(array('pdfgeneration'));
227 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
228 global $action;
229 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
230 if ($reshook < 0) {
231 $this->error = $hookmanager->error;
232 $this->errors = $hookmanager->errors;
233 }
234
235 dolChmod($file);
236
237 $this->result = array('fullpath' => $file);
238
239 $outputlangs->charset_output = $sav_charset_output;
240 return 1; // No error
241 }
242
243
244 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
254 public function Header(&$pdf, $page, $pages, $outputlangs)
255 {
256 // phpcs:enable
257 global $langs;
258 $default_font_size = pdf_getPDFFontSize($outputlangs);
259
260 // Load traductions files required by page
261 $outputlangs->loadLangs(array("compta", "banks"));
262
263 $title = $outputlangs->transnoentities("CheckReceipt");
264 $pdf->SetFont('', 'B', $default_font_size);
265 $pdf->SetXY(10, 8);
266 $pdf->MultiCell(0, 2, $title, 0, 'L');
267
268 $pdf->SetFont('', '', $default_font_size);
269 $pdf->SetXY(10, 15);
270 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Ref"), 0, 'L');
271 $pdf->SetXY(32, 15);
272 $pdf->SetFont('', '', $default_font_size);
273 $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext ? " - ".$this->ref_ext : '')), 0, 'L');
274
275 $pdf->SetFont('', '', $default_font_size);
276 $pdf->SetXY(10, 20);
277 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Date"), 0, 'L');
278 $pdf->SetXY(32, 20);
279 $pdf->SetFont('', '', $default_font_size);
280 $pdf->MultiCell(60, 2, dol_print_date($this->date, "day", false, $outputlangs));
281
282 $pdf->SetFont('', '', $default_font_size);
283 $pdf->SetXY(10, 26);
284 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Owner"), 0, 'L');
285 $pdf->SetFont('', '', $default_font_size);
286 $pdf->SetXY(32, 26);
287 $pdf->MultiCell(80, 2, $outputlangs->convToOutputCharset($this->account->owner_name), 0, 'L');
288
289 $pdf->SetFont('', '', $default_font_size);
290 $pdf->SetXY(10, 32);
291 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("BankAccount"), 0, 'L');
292 pdf_bank($pdf, $outputlangs, 32, 32, $this->account, 1);
293
294 $pdf->SetFont('', '', $default_font_size);
295 $pdf->SetXY(114, 15);
296 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
297
298 $pdf->RoundedRect(9, 14, 192, 35, $this->corner_radius, '1234', 'D');
299 $pdf->line(9, 19, 112, 19);
300 $pdf->line(9, 25, 112, 25);
301 //$pdf->line(9, 31, 201, 31);
302 $pdf->line(9, 31, 112, 31);
303
304 $pdf->line(30, 14, 30, 49);
305 $pdf->line(112, 14, 112, 49);
306
307 // Number of cheques
308 $posy = 51;
309 $pdf->RoundedRect(9, $posy, 192, 6, $this->corner_radius, '1234', 'D');
310 $pdf->line(55, $posy, 55, $posy + 6);
311 $pdf->line(140, $posy, 140, $posy + 6);
312 $pdf->line(170, $posy, 170, $posy + 6);
313
314 $pdf->SetFont('', '', $default_font_size);
315 $pdf->SetXY(10, $posy + 1);
316 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
317
318 $pdf->SetFont('', 'B', $default_font_size);
319 $pdf->SetXY(57, $posy + 1);
320 $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
321
322 $pdf->SetFont('', '', $default_font_size);
323 $pdf->SetXY(148, $posy + 1);
324 $pdf->MultiCell(40, 2, $langs->trans("Total"));
325
326 $pdf->SetFont('', 'B', $default_font_size);
327 $pdf->SetXY(170, $posy + 1);
328 $pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
329
330 // Tableau
331 $pdf->SetFont('', '', $default_font_size - 2);
332 $pdf->SetXY(11, $this->tab_top + 2);
333 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Num"), 0, 'L');
334 $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
335
336 $pdf->SetXY(41, $this->tab_top + 2);
337 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Bank"), 0, 'L');
338 $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
339
340 $pdf->SetXY(101, $this->tab_top + 2);
341 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
342 $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
343
344 $pdf->SetXY(180, $this->tab_top + 2);
345 $pdf->MultiCell(20, 2, $outputlangs->transnoentities("Amount"), 0, 'R');
346 $pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
347
348 $pdf->RoundedRect(9, $this->tab_top, 192, $this->tab_height + 10, $this->corner_radius, '1234', 'D');
349 }
350
351
352 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
362 public function Body(&$pdf, $pagenb, $pages, $outputlangs)
363 {
364 // phpcs:enable
365 // x=10 - Num
366 // x=30 - Banque
367 // x=100 - Emetteur
368 $default_font_size = pdf_getPDFFontSize($outputlangs);
369 $pdf->SetFont('', '', $default_font_size - 1);
370 $oldprowid = 0;
371 $pdf->SetFillColor(220, 220, 220);
372 $yp = 0;
373 $lineinpage = 0;
374 $num = count($this->lines);
375 for ($j = 0; $j < $num; $j++) {
376 // Dynamic max line height calculation
377 $dynamic_line_height = array();
378 $dynamic_line_height[] = $pdf->getStringHeight(60, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq));
379 $dynamic_line_height[] = $pdf->getStringHeight(80, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq));
380 $max_line_height = max($dynamic_line_height);
381 // Calculate number of line used function of estimated line size
382 if ($max_line_height > $this->line_height) {
383 $nb_lines = floor($max_line_height / $this->line_height) + 1;
384 } else {
385 $nb_lines = 1;
386 }
387
388 // Add page break if we do not have space to add current line
389 if ($lineinpage >= ($this->line_per_page - 1)) {
390 $lineinpage = 0;
391 $yp = 0;
392
393 // New page
394 $pdf->AddPage();
395 $pagenb++;
396 $this->Header($pdf, $pagenb, $pages, $outputlangs);
397 $pdf->SetFont('', '', $default_font_size - 1);
398 $pdf->MultiCell(0, 3, ''); // Set interline to 3
399 $pdf->SetTextColor(0, 0, 0);
400 }
401
402 $lineinpage += $nb_lines;
403
404 $pdf->SetXY(1, $this->tab_top + 10 + $yp);
405 $pdf->MultiCell(8, $this->line_height, $j + 1, 0, 'R', 0);
406
407 $pdf->SetXY(10, $this->tab_top + 10 + $yp);
408 $pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq ? $this->lines[$j]->num_chq : '', 0, 'L', 0);
409
410 $pdf->SetXY(40, $this->tab_top + 10 + $yp);
411 $pdf->MultiCell(60, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq, 44), 0, 'L', 0);
412
413 $pdf->SetXY(100, $this->tab_top + 10 + $yp);
414 $pdf->MultiCell(80, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq, 50), 0, 'L', 0);
415
416 $pdf->SetXY(180, $this->tab_top + 10 + $yp);
417 $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
418
419 $yp += ($this->line_height * $nb_lines);
420 }
421 }
422
423 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
433 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
434 {
435 global $conf;
436
437 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
438
439 // Line of free text
440 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
441 complete_substitutions_array($substitutionarray, $outputlangs, $object);
442 $newfreetext = '';
443 $paramfreetext = 'BANK_CHEQUERECEIPT_FREE_TEXT';
444 if (getDolGlobalString($paramfreetext)) {
445 $newfreetext = make_substitutions(getDolGlobalString($paramfreetext), $substitutionarray);
446 }
447
448 return pdf_pagefoot($pdf, $outputlangs, $newfreetext, $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
449 }
450}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class of file to build cheque deposit receipts.
__construct($db)
Constructor.
Body(&$pdf, $pagenb, $pages, $outputlangs)
Output array.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Header(&$pdf, $page, $pages, $outputlangs)
Generate Header.
write_file($object, $_dir, $number, $outputlangs)
Fonction to generate document on disk.
Class to manage hooks.
Class parent for templates of document generation.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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_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_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:850
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:765
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152