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