dolibarr 20.0.0
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
28require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
31
32
37{
41 public $tab_top;
42
46 public $tab_height;
47
51 public $line_height;
52
56 public $line_per_page;
57
61 public $account;
62
63 public $amount;
64 public $date;
65 public $nbcheque;
66 public $ref;
67 public $ref_ext;
68
69
73 public $lines;
74
80 public function __construct($db)
81 {
82 global $langs, $mysoc;
83
84 // Load traductions files required by page
85 $langs->loadLangs(array("main", "bills"));
86
87 $this->db = $db;
88 $this->name = "blochet";
89
90 $this->tab_top = 60;
91
92 // Page size for A4 format
93 $this->type = 'pdf';
94 $formatarray = pdf_getFormat();
95 $this->page_largeur = $formatarray['width'];
96 $this->page_hauteur = $formatarray['height'];
97 $this->format = array($this->page_largeur, $this->page_hauteur);
98 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
99 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
100 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
101 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
102
103 // Retrieves transmitter
104 $this->emetteur = $mysoc;
105 if (!$this->emetteur->country_code) {
106 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
107 }
108
109 // Define column position
110 $this->line_height = 5;
111 $this->line_per_page = 40;
112 $this->tab_height = 200; //$this->line_height * $this->line_per_page;
113 }
114
115 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
125 public function write_file($object, $_dir, $number, $outputlangs)
126 {
127 // phpcs:enable
128 global $user, $conf, $langs, $hookmanager;
129
130 if (!is_object($outputlangs)) {
131 $outputlangs = $langs;
132 }
133 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
134 $sav_charset_output = $outputlangs->charset_output;
135 if (getDolGlobalString('MAIN_USE_FPDF')) {
136 $outputlangs->charset_output = 'ISO-8859-1';
137 }
138
139 // Load traductions files required by page
140 $outputlangs->loadLangs(array("main", "companies", "bills", "products", "compta"));
141
142 $dir = $_dir."/".get_exdir($number, 0, 1, 0, $object, 'checkdeposits');
143
144 if (!is_dir($dir)) {
145 $result = dol_mkdir($dir);
146
147 if ($result < 0) {
148 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
149 return -1;
150 }
151 }
152
153 $file = $dir."/bordereau-".$number.".pdf";
154
155 // Add pdfgeneration hook
156 if (!is_object($hookmanager)) {
157 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
158 $hookmanager = new HookManager($this->db);
159 }
160 $hookmanager->initHooks(array('pdfgeneration'));
161 $parameters = array('file' => $file, 'outputlangs' => $outputlangs);
162 global $action;
163 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
164
165 // Create PDF instance
166 $pdf = pdf_getInstance($this->format);
167 $heightforinfotot = 50; // Height reserved to output the info and total part
168 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page
169 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
170 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
171 $heightforfooter += 6;
172 }
173 $pdf->SetAutoPageBreak(1, 0);
174
175 if (class_exists('TCPDF')) {
176 $pdf->setPrintHeader(false);
177 $pdf->setPrintFooter(false);
178 }
179 $pdf->SetFont(pdf_getPDFFont($outputlangs));
180
181 $pdf->Open();
182 $pagenb = 0;
183 $pdf->SetDrawColor(128, 128, 128);
184
185 $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
186 $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
187 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
188 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
189 $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
190 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
191 $pdf->SetCompression(false);
192 }
193
194 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
195 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
196
197 $nboflines = count($this->lines);
198
199 // Define nb of page
200 $pages = intval($nboflines / $this->line_per_page);
201 if (($nboflines % $this->line_per_page) > 0) {
202 $pages++;
203 }
204 if ($pages == 0) {
205 // force to build at least one page if report has no lines
206 $pages = 1;
207 }
208
209 $pdf->AddPage();
210 $pagenb++;
211 $this->Header($pdf, $pagenb, $pages, $outputlangs);
212
213 $this->Body($pdf, $pagenb, $pages, $outputlangs);
214
215 // Pied de page
216 $this->_pagefoot($pdf, '', $outputlangs);
217 if (method_exists($pdf, 'AliasNbPages')) {
218 $pdf->AliasNbPages();
219 }
220
221 $pdf->Close();
222
223 $pdf->Output($file, 'F');
224
225 // Add pdfgeneration hook
226 if (!is_object($hookmanager)) {
227 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
228 $hookmanager = new HookManager($this->db);
229 }
230 $hookmanager->initHooks(array('pdfgeneration'));
231 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
232 global $action;
233 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
234 if ($reshook < 0) {
235 $this->error = $hookmanager->error;
236 $this->errors = $hookmanager->errors;
237 }
238
239 dolChmod($file);
240
241 $this->result = array('fullpath' => $file);
242
243 $outputlangs->charset_output = $sav_charset_output;
244 return 1; // No error
245 }
246
247
248 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
258 public function Header(&$pdf, $page, $pages, $outputlangs)
259 {
260 // phpcs:enable
261 global $langs;
262 $default_font_size = pdf_getPDFFontSize($outputlangs);
263
264 // Load traductions files required by page
265 $outputlangs->loadLangs(array("compta", "banks"));
266
267 $title = $outputlangs->transnoentities("CheckReceipt");
268 $pdf->SetFont('', 'B', $default_font_size);
269 $pdf->SetXY(10, 8);
270 $pdf->MultiCell(0, 2, $title, 0, 'L');
271
272 $pdf->SetFont('', '', $default_font_size);
273 $pdf->SetXY(10, 15);
274 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Ref"), 0, 'L');
275 $pdf->SetXY(32, 15);
276 $pdf->SetFont('', '', $default_font_size);
277 $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext ? " - ".$this->ref_ext : '')), 0, 'L');
278
279 $pdf->SetFont('', '', $default_font_size);
280 $pdf->SetXY(10, 20);
281 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Date"), 0, 'L');
282 $pdf->SetXY(32, 20);
283 $pdf->SetFont('', '', $default_font_size);
284 $pdf->MultiCell(60, 2, dol_print_date($this->date, "day", false, $outputlangs));
285
286 $pdf->SetFont('', '', $default_font_size);
287 $pdf->SetXY(10, 26);
288 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Owner"), 0, 'L');
289 $pdf->SetFont('', '', $default_font_size);
290 $pdf->SetXY(32, 26);
291 $pdf->MultiCell(80, 2, $outputlangs->convToOutputCharset($this->account->owner_name), 0, 'L');
292
293 $pdf->SetFont('', '', $default_font_size);
294 $pdf->SetXY(10, 32);
295 $pdf->MultiCell(0, 2, $outputlangs->transnoentities("BankAccount"), 0, 'L');
296 pdf_bank($pdf, $outputlangs, 32, 32, $this->account, 1);
297
298 $pdf->SetFont('', '', $default_font_size);
299 $pdf->SetXY(114, 15);
300 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
301
302 $pdf->Rect(9, 14, 192, 35);
303 $pdf->line(9, 19, 112, 19);
304 $pdf->line(9, 25, 112, 25);
305 //$pdf->line(9, 31, 201, 31);
306 $pdf->line(9, 31, 112, 31);
307
308 $pdf->line(30, 14, 30, 49);
309 $pdf->line(112, 14, 112, 49);
310
311 // Number of cheques
312 $posy = 51;
313 $pdf->Rect(9, $posy, 192, 6);
314 $pdf->line(55, $posy, 55, $posy + 6);
315 $pdf->line(140, $posy, 140, $posy + 6);
316 $pdf->line(170, $posy, 170, $posy + 6);
317
318 $pdf->SetFont('', '', $default_font_size);
319 $pdf->SetXY(10, $posy + 1);
320 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
321
322 $pdf->SetFont('', 'B', $default_font_size);
323 $pdf->SetXY(57, $posy + 1);
324 $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
325
326 $pdf->SetFont('', '', $default_font_size);
327 $pdf->SetXY(148, $posy + 1);
328 $pdf->MultiCell(40, 2, $langs->trans("Total"));
329
330 $pdf->SetFont('', 'B', $default_font_size);
331 $pdf->SetXY(170, $posy + 1);
332 $pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
333
334 // Tableau
335 $pdf->SetFont('', '', $default_font_size - 2);
336 $pdf->SetXY(11, $this->tab_top + 2);
337 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Num"), 0, 'L');
338 $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
339
340 $pdf->SetXY(41, $this->tab_top + 2);
341 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Bank"), 0, 'L');
342 $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
343
344 $pdf->SetXY(101, $this->tab_top + 2);
345 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
346 $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
347
348 $pdf->SetXY(180, $this->tab_top + 2);
349 $pdf->MultiCell(20, 2, $outputlangs->transnoentities("Amount"), 0, 'R');
350 $pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
351
352 $pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
353 }
354
355
356 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
366 public function Body(&$pdf, $pagenb, $pages, $outputlangs)
367 {
368 // phpcs:enable
369 // x=10 - Num
370 // x=30 - Banque
371 // x=100 - Emetteur
372 $default_font_size = pdf_getPDFFontSize($outputlangs);
373 $pdf->SetFont('', '', $default_font_size - 1);
374 $oldprowid = 0;
375 $pdf->SetFillColor(220, 220, 220);
376 $yp = 0;
377 $lineinpage = 0;
378 $num = count($this->lines);
379 for ($j = 0; $j < $num; $j++) {
380 // Dynamic max line height calculation
381 $dynamic_line_height = array();
382 $dynamic_line_height[] = $pdf->getStringHeight(60, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq));
383 $dynamic_line_height[] = $pdf->getStringHeight(80, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq));
384 $max_line_height = max($dynamic_line_height);
385 // Calculate number of line used function of estimated line size
386 if ($max_line_height > $this->line_height) {
387 $nb_lines = floor($max_line_height / $this->line_height) + 1;
388 } else {
389 $nb_lines = 1;
390 }
391
392 // Add page break if we do not have space to add current line
393 if ($lineinpage >= ($this->line_per_page - 1)) {
394 $lineinpage = 0;
395 $yp = 0;
396
397 // New page
398 $pdf->AddPage();
399 $pagenb++;
400 $this->Header($pdf, $pagenb, $pages, $outputlangs);
401 $pdf->SetFont('', '', $default_font_size - 1);
402 $pdf->MultiCell(0, 3, ''); // Set interline to 3
403 $pdf->SetTextColor(0, 0, 0);
404 }
405
406 $lineinpage += $nb_lines;
407
408 $pdf->SetXY(1, $this->tab_top + 10 + $yp);
409 $pdf->MultiCell(8, $this->line_height, $j + 1, 0, 'R', 0);
410
411 $pdf->SetXY(10, $this->tab_top + 10 + $yp);
412 $pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq ? $this->lines[$j]->num_chq : '', 0, 'L', 0);
413
414 $pdf->SetXY(40, $this->tab_top + 10 + $yp);
415 $pdf->MultiCell(60, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq, 44), 0, 'L', 0);
416
417 $pdf->SetXY(100, $this->tab_top + 10 + $yp);
418 $pdf->MultiCell(80, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq, 50), 0, 'L', 0);
419
420 $pdf->SetXY(180, $this->tab_top + 10 + $yp);
421 $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
422
423 $yp = $yp + ($this->line_height * $nb_lines);
424 }
425 }
426
427 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
437 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
438 {
439 global $conf;
440
441 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
442
443 // Line of free text
444 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
445 complete_substitutions_array($substitutionarray, $outputlangs, $object);
446 $newfreetext = '';
447 $paramfreetext = 'BANK_CHEQUERECEIPT_FREE_TEXT';
448 if (!empty($conf->global->$paramfreetext)) {
449 $newfreetext = make_substitutions(getDolGlobalString($paramfreetext), $substitutionarray);
450 }
451
452 return pdf_pagefoot($pdf, $outputlangs, $newfreetext, $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
453 }
454}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.
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 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_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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_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:1020
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank information for PDF generation.
Definition pdf.lib.php:843
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:267
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:769
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:139
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142