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