dolibarr 21.0.0-alpha
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
60 public $ref_ext;
61
62
68 public function __construct($db)
69 {
70 global $langs, $mysoc;
71
72 // Load traductions files required by page
73 $langs->loadLangs(array("main", "bills"));
74
75 $this->db = $db;
76 $this->name = "blochet";
77
78 $this->tab_top = 60;
79
80 // Page size for A4 format
81 $this->type = 'pdf';
82 $formatarray = pdf_getFormat();
83 $this->page_largeur = $formatarray['width'];
84 $this->page_hauteur = $formatarray['height'];
85 $this->format = array($this->page_largeur, $this->page_hauteur);
86 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
87 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
88 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
89 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
90 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
91
92 // Define column position
93 $this->line_height = 5;
94 $this->line_per_page = 40;
95 $this->tab_height = 200; //$this->line_height * $this->line_per_page;
96
97 if ($mysoc === null) {
98 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
99 return;
100 }
101 // Retrieves issuer
102 $this->emetteur = $mysoc;
103 if (!$this->emetteur->country_code) {
104 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
105 }
106 }
107
108 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
118 public function write_file($object, $_dir, $number, $outputlangs)
119 {
120 // phpcs:enable
121 global $user, $conf, $langs, $hookmanager;
122
123 if (!is_object($outputlangs)) {
124 $outputlangs = $langs;
125 }
126 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
127 $sav_charset_output = $outputlangs->charset_output;
128 if (getDolGlobalString('MAIN_USE_FPDF')) {
129 $outputlangs->charset_output = 'ISO-8859-1';
130 }
131
132 // Load traductions files required by page
133 $outputlangs->loadLangs(array("main", "companies", "bills", "products", "compta"));
134
135 $dir = $_dir."/".get_exdir($number, 0, 1, 0, $object, 'checkdeposits');
136
137 if (!is_dir($dir)) {
138 $result = dol_mkdir($dir);
139
140 if ($result < 0) {
141 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
142 return -1;
143 }
144 }
145
146 $file = $dir."/bordereau-".$number.".pdf";
147
148 // Add pdfgeneration hook
149 if (!is_object($hookmanager)) {
150 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
151 $hookmanager = new HookManager($this->db);
152 }
153 $hookmanager->initHooks(array('pdfgeneration'));
154 $parameters = array('file' => $file, 'outputlangs' => $outputlangs);
155 global $action;
156 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
157
158 // Create PDF instance
159 $pdf = pdf_getInstance($this->format);
160 $heightforinfotot = 50; // Height reserved to output the info and total part
161 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
162 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
163 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
164 $heightforfooter += 6;
165 }
166 $pdf->SetAutoPageBreak(1, 0);
167
168 if (class_exists('TCPDF')) {
169 $pdf->setPrintHeader(false);
170 $pdf->setPrintFooter(false);
171 }
172 $pdf->SetFont(pdf_getPDFFont($outputlangs));
173
174 $pdf->Open();
175 $pagenb = 0;
176 $pdf->SetDrawColor(128, 128, 128);
177
178 $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
179 $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
180 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
181 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
182 $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
183 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
184 $pdf->SetCompression(false);
185 }
186
187 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
188 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
189
190 $nboflines = count($this->lines);
191
192 // Define nb of page
193 $pages = intval($nboflines / $this->line_per_page);
194 if (($nboflines % $this->line_per_page) > 0) {
195 $pages++;
196 }
197 if ($pages == 0) {
198 // force to build at least one page if report has no lines
199 $pages = 1;
200 }
201
202 $pdf->AddPage();
203 $pagenb++;
204 $this->Header($pdf, $pagenb, $pages, $outputlangs);
205
206 $this->Body($pdf, $pagenb, $pages, $outputlangs);
207
208 // Pied de page
209 $this->_pagefoot($pdf, '', $outputlangs);
210 if (method_exists($pdf, 'AliasNbPages')) {
211 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
212 }
213
214 $pdf->Close();
215
216 $pdf->Output($file, 'F');
217
218 // Add pdfgeneration hook
219 if (!is_object($hookmanager)) {
220 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
221 $hookmanager = new HookManager($this->db);
222 }
223 $hookmanager->initHooks(array('pdfgeneration'));
224 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
225 global $action;
226 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
227 if ($reshook < 0) {
228 $this->error = $hookmanager->error;
229 $this->errors = $hookmanager->errors;
230 }
231
232 dolChmod($file);
233
234 $this->result = array('fullpath' => $file);
235
236 $outputlangs->charset_output = $sav_charset_output;
237 return 1; // No error
238 }
239
240
241 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
251 public function Header(&$pdf, $page, $pages, $outputlangs)
252 {
253 // phpcs:enable
254 global $langs;
255 $default_font_size = pdf_getPDFFontSize($outputlangs);
256
257 // Load traductions files required by page
258 $outputlangs->loadLangs(array("compta", "banks"));
259
260 $title = $outputlangs->transnoentities("CheckReceipt");
261 $pdf->SetFont('', 'B', $default_font_size);
262 $pdf->SetXY(10, 8);
263 $pdf->MultiCell(0, 2, $title, 0, 'L');
264
265 $pdf->SetFont('', '', $default_font_size);
266 $pdf->SetXY(10, 15);
267 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Ref"), 0, 'L');
268 $pdf->SetXY(32, 15);
269 $pdf->SetFont('', '', $default_font_size);
270 $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext ? " - ".$this->ref_ext : '')), 0, 'L');
271
272 $pdf->SetFont('', '', $default_font_size);
273 $pdf->SetXY(10, 20);
274 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Date"), 0, 'L');
275 $pdf->SetXY(32, 20);
276 $pdf->SetFont('', '', $default_font_size);
277 $pdf->MultiCell(60, 2, dol_print_date($this->date, "day", false, $outputlangs));
278
279 $pdf->SetFont('', '', $default_font_size);
280 $pdf->SetXY(10, 26);
281 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Owner"), 0, 'L');
282 $pdf->SetFont('', '', $default_font_size);
283 $pdf->SetXY(32, 26);
284 $pdf->MultiCell(80, 2, $outputlangs->convToOutputCharset($this->account->owner_name), 0, 'L');
285
286 $pdf->SetFont('', '', $default_font_size);
287 $pdf->SetXY(10, 32);
288 $pdf->MultiCell(22, 2, $outputlangs->transnoentities("BankAccount"), 0, 'L');
289 pdf_bank($pdf, $outputlangs, 32, 32, $this->account, 1);
290
291 $pdf->SetFont('', '', $default_font_size);
292 $pdf->SetXY(114, 15);
293 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
294
295 $pdf->RoundedRect(9, 14, 192, 35, $this->corner_radius, '1234', 'D');
296 $pdf->line(9, 19, 112, 19);
297 $pdf->line(9, 25, 112, 25);
298 //$pdf->line(9, 31, 201, 31);
299 $pdf->line(9, 31, 112, 31);
300
301 $pdf->line(30, 14, 30, 49);
302 $pdf->line(112, 14, 112, 49);
303
304 // Number of cheques
305 $posy = 51;
306 $pdf->RoundedRect(9, $posy, 192, 6, $this->corner_radius, '1234', 'D');
307 $pdf->line(55, $posy, 55, $posy + 6);
308 $pdf->line(140, $posy, 140, $posy + 6);
309 $pdf->line(170, $posy, 170, $posy + 6);
310
311 $pdf->SetFont('', '', $default_font_size);
312 $pdf->SetXY(10, $posy + 1);
313 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
314
315 $pdf->SetFont('', 'B', $default_font_size);
316 $pdf->SetXY(57, $posy + 1);
317 $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
318
319 $pdf->SetFont('', '', $default_font_size);
320 $pdf->SetXY(148, $posy + 1);
321 $pdf->MultiCell(40, 2, $langs->trans("Total"));
322
323 $pdf->SetFont('', 'B', $default_font_size);
324 $pdf->SetXY(170, $posy + 1);
325 $pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
326
327 // Tableau
328 $pdf->SetFont('', '', $default_font_size - 2);
329 $pdf->SetXY(11, $this->tab_top + 2);
330 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Num"), 0, 'L');
331 $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
332
333 $pdf->SetXY(41, $this->tab_top + 2);
334 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Bank"), 0, 'L');
335 $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
336
337 $pdf->SetXY(101, $this->tab_top + 2);
338 $pdf->MultiCell(40, 2, $outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
339 $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
340
341 $pdf->SetXY(180, $this->tab_top + 2);
342 $pdf->MultiCell(20, 2, $outputlangs->transnoentities("Amount"), 0, 'R');
343 $pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
344
345 $pdf->RoundedRect(9, $this->tab_top, 192, $this->tab_height + 10, $this->corner_radius, '1234', 'D');
346 }
347
348
349 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
359 public function Body(&$pdf, $pagenb, $pages, $outputlangs)
360 {
361 // phpcs:enable
362 // x=10 - Num
363 // x=30 - Banque
364 // x=100 - Emetteur
365 $default_font_size = pdf_getPDFFontSize($outputlangs);
366 $pdf->SetFont('', '', $default_font_size - 1);
367 $oldprowid = 0;
368 $pdf->SetFillColor(220, 220, 220);
369 $yp = 0;
370 $lineinpage = 0;
371 $num = count($this->lines);
372 for ($j = 0; $j < $num; $j++) {
373 // Dynamic max line height calculation
374 $dynamic_line_height = array();
375 $dynamic_line_height[] = $pdf->getStringHeight(60, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq));
376 $dynamic_line_height[] = $pdf->getStringHeight(80, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq));
377 $max_line_height = max($dynamic_line_height);
378 // Calculate number of line used function of estimated line size
379 if ($max_line_height > $this->line_height) {
380 $nb_lines = floor($max_line_height / $this->line_height) + 1;
381 } else {
382 $nb_lines = 1;
383 }
384
385 // Add page break if we do not have space to add current line
386 if ($lineinpage >= ($this->line_per_page - 1)) {
387 $lineinpage = 0;
388 $yp = 0;
389
390 // New page
391 $pdf->AddPage();
392 $pagenb++;
393 $this->Header($pdf, $pagenb, $pages, $outputlangs);
394 $pdf->SetFont('', '', $default_font_size - 1);
395 $pdf->MultiCell(0, 3, ''); // Set interline to 3
396 $pdf->SetTextColor(0, 0, 0);
397 }
398
399 $lineinpage += $nb_lines;
400
401 $pdf->SetXY(1, $this->tab_top + 10 + $yp);
402 $pdf->MultiCell(8, $this->line_height, $j + 1, 0, 'R', 0);
403
404 $pdf->SetXY(10, $this->tab_top + 10 + $yp);
405 $pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq ? $this->lines[$j]->num_chq : '', 0, 'L', 0);
406
407 $pdf->SetXY(40, $this->tab_top + 10 + $yp);
408 $pdf->MultiCell(60, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq, 44), 0, 'L', 0);
409
410 $pdf->SetXY(100, $this->tab_top + 10 + $yp);
411 $pdf->MultiCell(80, $this->line_height, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq, 50), 0, 'L', 0);
412
413 $pdf->SetXY(180, $this->tab_top + 10 + $yp);
414 $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
415
416 $yp += ($this->line_height * $nb_lines);
417 }
418 }
419
420 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
430 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
431 {
432 global $conf;
433
434 $showdetails = getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
435
436 // Line of free text
437 $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
438 complete_substitutions_array($substitutionarray, $outputlangs, $object);
439 $newfreetext = '';
440 $paramfreetext = 'BANK_CHEQUERECEIPT_FREE_TEXT';
441 if (getDolGlobalString($paramfreetext)) {
442 $newfreetext = make_substitutions(getDolGlobalString($paramfreetext), $substitutionarray);
443 }
444
445 return pdf_pagefoot($pdf, $outputlangs, $newfreetext, $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
446 }
447}
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.
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)
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:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140