/
pdf_blochet.class.php
430 lines (351 loc) · 14.4 KB
/
pdf_blochet.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<?php
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/modules/cheque/pdf/pdf_blochet.class.php
* \ingroup banque
* \brief File to build cheque deposit receipts
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/pdf/modules_chequereceipts.php';
/**
* Class of file to build cheque deposit receipts
*/
class BordereauChequeBlochet extends ModeleChequeReceipts
{
var $error='';
var $emetteur; // Objet societe qui emet
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
global $conf,$langs,$mysoc;
$langs->load("main");
$langs->load("bills");
$this->db = $db;
$this->name = "blochet";
$this->tab_top = 60;
// Dimension page pour format A4
$this->type = 'pdf';
$formatarray=pdf_getFormat();
$this->page_largeur = $formatarray['width'];
$this->page_hauteur = $formatarray['height'];
$this->format = array($this->page_largeur,$this->page_hauteur);
$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
// Recupere emmetteur
$this->emetteur=$mysoc;
if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined
// Defini position des colonnes
$this->line_height = 5;
$this->line_per_page = 40;
$this->tab_height = 200; //$this->line_height * $this->line_per_page;
}
/**
* Fonction generant le rapport sur le disque
*
* @param string $_dir Directory
* @param string $number Number
* @param Translate $outputlangs Lang output object
* @return int 1=ok, 0=ko
*/
function write_file($_dir, $number, $outputlangs)
{
global $user,$conf,$langs,$hookmanager;
if (! is_object($outputlangs)) $outputlangs=$langs;
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
$sav_charset_output=$outputlangs->charset_output;
if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
$outputlangs->load("main");
$outputlangs->load("companies");
$outputlangs->load("bills");
$outputlangs->load("products");
$outputlangs->load("compta");
$dir = $_dir . "/".get_exdir($number,2,1,0,null,'cheque').$number;
if (! is_dir($dir))
{
$result=dol_mkdir($dir);
if ($result < 0)
{
$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
return -1;
}
}
$file = $dir . "/bordereau-".$number.".pdf";
// Add pdfgeneration hook
if (! is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($this->db);
}
$hookmanager->initHooks(array('pdfgeneration'));
$parameters=array('file'=>$file, 'outputlangs'=>$outputlangs);
global $action;
$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
// Create PDF instance
$pdf=pdf_getInstance($this->format);
$heightforinfotot = 50; // Height reserved to output the info and total part
$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
$heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
$pdf->SetAutoPageBreak(1,0);
if (class_exists('TCPDF'))
{
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
}
$pdf->SetFont(pdf_getPDFFont($outputlangs));
$pdf->Open();
$pagenb=0;
$pdf->SetDrawColor(128,128,128);
$pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
$pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
$pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
$pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
$nboflines=count($this->lines);
// Define nb of page
$pages = intval($nboflines / $this->line_per_page);
if (($nboflines % $this->line_per_page)>0)
{
$pages++;
}
if ($pages == 0)
{
// force to build at least one page if report has no lines
$pages = 1;
}
$pdf->AddPage();
$pagenb++;
$this->Header($pdf, $pagenb, $pages, $outputlangs);
$this->Body($pdf, $pagenb, $pages, $outputlangs);
// Pied de page
$this->_pagefoot($pdf,'',$outputlangs);
if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
$pdf->Close();
$pdf->Output($file,'F');
// Add pdfgeneration hook
if (! is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($this->db);
}
$hookmanager->initHooks(array('pdfgeneration'));
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
global $action;
$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (! empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));
$outputlangs->charset_output=$sav_charset_output;
return 1; // Pas d'erreur
}
/**
* Generate Header
*
* @param PDF $pdf Pdf object
* @param int $page Current page number
* @param int $pages Total number of pages
* @param Translate $outputlangs Object language for output
* @return void
*/
function Header(&$pdf, $page, $pages, $outputlangs)
{
global $langs;
$default_font_size = pdf_getPDFFontSize($outputlangs);
$outputlangs->load("compta");
$outputlangs->load("banks");
$title = $outputlangs->transnoentities("CheckReceipt");
$pdf->SetFont('','B', $default_font_size);
$pdf->SetXY(10,8);
$pdf->MultiCell(0,2,$title,0,'L');
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(10,15);
$pdf->MultiCell(22,2,$outputlangs->transnoentities("Ref"),0,'L');
$pdf->SetXY(32,15);
$pdf->SetFont('','', $default_font_size);
$pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->number.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(10,20);
$pdf->MultiCell(22,2,$outputlangs->transnoentities("Date"),0,'L');
$pdf->SetXY(32,20);
$pdf->SetFont('','', $default_font_size);
$pdf->MultiCell(60, 2, dol_print_date($this->date,"day",false,$outputlangs));
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(10,26);
$pdf->MultiCell(22,2,$outputlangs->transnoentities("Owner"),0,'L');
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(32,26);
$pdf->MultiCell(60,2,$outputlangs->convToOutputCharset($this->account->proprio),0,'L');
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(10,32);
$pdf->MultiCell(0,2,$outputlangs->transnoentities("Account"),0,'L');
pdf_bank($pdf,$outputlangs,32,32,$this->account,1);
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(114,15);
$pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
$pdf->Rect(9, 14, 192, 35);
$pdf->line(9, 19, 112, 19);
$pdf->line(9, 25, 112, 25);
//$pdf->line(9, 31, 201, 31);
$pdf->line(9, 31, 112, 31);
$pdf->line(30, 14, 30, 49);
$pdf->line(112, 14, 112, 49);
// Number of cheques
$posy=51;
$pdf->Rect(9, $posy, 192, 6);
$pdf->line(55, $posy, 55, $posy+6);
$pdf->line(140, $posy, 140, $posy+6);
$pdf->line(170, $posy, 170, $posy+6);
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(10,$posy+1);
$pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
$pdf->SetFont('','B', $default_font_size);
$pdf->SetXY(57,$posy+1);
$pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
$pdf->SetFont('','', $default_font_size);
$pdf->SetXY(148,$posy+1);
$pdf->MultiCell(40, 2, $langs->trans("Total"));
$pdf->SetFont('','B', $default_font_size);
$pdf->SetXY(170, $posy+1);
$pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
// Tableau
$pdf->SetFont('','', $default_font_size - 2);
$pdf->SetXY(11, $this->tab_top+2);
$pdf->MultiCell(40,2,$outputlangs->transnoentities("Num"), 0, 'L');
$pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
$pdf->SetXY(41, $this->tab_top+2);
$pdf->MultiCell(40,2,$outputlangs->transnoentities("Bank"), 0, 'L');
$pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
$pdf->SetXY(101, $this->tab_top+2);
$pdf->MultiCell(40,2,$outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
$pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
$pdf->SetXY(180, $this->tab_top+2);
$pdf->MultiCell(20,2,$outputlangs->transnoentities("Amount"), 0, 'R');
$pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
$pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
}
/**
* Output array
*
* @param PDF $pdf PDF object
* @param int $pagenb Page nb
* @param int $pages Pages
* @param Translate $outputlangs Object lang
* @return void
*/
function Body(&$pdf, $pagenb, $pages, $outputlangs)
{
// x=10 - Num
// x=30 - Banque
// x=100 - Emetteur
$default_font_size = pdf_getPDFFontSize($outputlangs);
$pdf->SetFont('','', $default_font_size - 1);
$oldprowid = 0;
$pdf->SetFillColor(220,220,220);
$yp = 0;
$lineinpage=0;
$num=count($this->lines);
for ($j = 0; $j < $num; $j++)
{
$lineinpage++;
$pdf->SetXY(1, $this->tab_top + 10 + $yp);
$pdf->MultiCell(8, $this->line_height, $j+1, 0, 'R', 0);
$pdf->SetXY(10, $this->tab_top + 10 + $yp);
$pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq?$this->lines[$j]->num_chq:'', 0, 'L', 0);
$pdf->SetXY(40, $this->tab_top + 10 + $yp);
$pdf->MultiCell(70, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->bank_chq),44), 0, 'L', 0);
$pdf->SetXY(100, $this->tab_top + 10 + $yp);
$pdf->MultiCell(80, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq),50), 0, 'L', 0);
$pdf->SetXY(180, $this->tab_top + 10 + $yp);
$pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
$yp = $yp + $this->line_height;
if ($lineinpage >= $this->line_per_page && $j < (count($this->lines)-1))
{
$lineinpage=0; $yp=0;
// New page
$pdf->AddPage();
$pagenb++;
$this->Header($pdf, $pagenb, $pages, $outputlangs);
$pdf->SetFont('','', $default_font_size - 1);
$pdf->MultiCell(0, 3, ''); // Set interline to 3
$pdf->SetTextColor(0,0,0);
}
}
}
/**
* Show footer of page. Need this->emetteur object
*
* @param PDF $pdf PDF
* @param Object $object Object to show
* @param Translate $outputlangs Object lang for output
* @param int $hidefreetext 1=Hide free text
* @return void
*/
function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
{
global $conf;
$default_font_size = pdf_getPDFFontSize($outputlangs);
//$showdetails=0;
//return pdf_pagefoot($pdf,$outputlangs,'BANK_CHEQUERECEIPT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
$paramfreetext='BANK_CHEQUERECEIPT_FREE_TEXT';
$marge_basse=$this->marge_basse;
$marge_gauche=$this->marge_gauche;
$page_hauteur=$this->page_hauteur;
// Line of free text
$line=(! empty($conf->global->$paramfreetext))?$outputlangs->convToOutputCharset($conf->global->$paramfreetext):"";
$pdf->SetFont('','', $default_font_size - 3);
$pdf->SetDrawColor(224,224,224);
// On positionne le debut du bas de page selon nbre de lignes de ce bas de page
$nbofline=dol_nboflines_bis($line,0,$outputlangs->charset_output);
//print 'e'.$line.'t'.dol_nboflines($line);exit;
$posy=$marge_basse + ($nbofline*3);
if ($line) // Free text
{
$pdf->SetXY($marge_gauche,-$posy);
$pdf->MultiCell(20000, 3, $line, 0, 'L', 0); // Use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
$posy-=($nbofline*3); // 6 of ligne + 3 of MultiCell
}
$pdf->SetY(-$posy);
$pdf->line($marge_gauche, $page_hauteur-$posy, 200, $page_hauteur-$posy);
$posy--;
/*if ($line1)
{
$pdf->SetXY($marge_gauche,-$posy);
$pdf->MultiCell(200, 2, $line1, 0, 'C', 0);
}
if ($line2)
{
$posy-=3;
$pdf->SetXY($marge_gauche,-$posy);
$pdf->MultiCell(200, 2, $line2, 0, 'C', 0);
}*/
// Show page nb only on iso languages (so default Helvetica font)
if (pdf_getPDFFont($outputlangs) == 'Helvetica')
{
$pdf->SetXY(-20,-$posy);
$pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
}
}
}