dolibarr  7.0.0-beta
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 <http://www.gnu.org/licenses/>.
18  * or see http://www.gnu.org/
19  */
20 
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
30 
31 
36 {
37  var $emetteur; // Objet societe qui emet
38 
44  function __construct($db)
45  {
46  global $conf,$langs,$mysoc;
47 
48  $langs->load("main");
49  $langs->load("bills");
50 
51  $this->db = $db;
52  $this->name = "blochet";
53 
54  $this->tab_top = 60;
55 
56  // Dimension page pour format A4
57  $this->type = 'pdf';
58  $formatarray=pdf_getFormat();
59  $this->page_largeur = $formatarray['width'];
60  $this->page_hauteur = $formatarray['height'];
61  $this->format = array($this->page_largeur,$this->page_hauteur);
62  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
63  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
64  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
65  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
66 
67  // Recupere emmetteur
68  $this->emetteur=$mysoc;
69  if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined
70 
71  // Defini position des colonnes
72  $this->line_height = 5;
73  $this->line_per_page = 40;
74  $this->tab_height = 200; //$this->line_height * $this->line_per_page;
75  }
76 
86  function write_file($object, $_dir, $number, $outputlangs)
87  {
88  global $user,$conf,$langs,$hookmanager;
89 
90  if (! is_object($outputlangs)) $outputlangs=$langs;
91  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
92  $sav_charset_output=$outputlangs->charset_output;
93  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
94 
95  $outputlangs->load("main");
96  $outputlangs->load("companies");
97  $outputlangs->load("bills");
98  $outputlangs->load("products");
99  $outputlangs->load("compta");
100 
101  $dir = $_dir . "/".get_exdir($number,0,1,0,$object,'cheque').$number;
102 
103  if (! is_dir($dir))
104  {
105  $result=dol_mkdir($dir);
106 
107  if ($result < 0)
108  {
109  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
110  return -1;
111  }
112  }
113 
114  $file = $dir . "/bordereau-".$number.".pdf";
115 
116  // Add pdfgeneration hook
117  if (! is_object($hookmanager))
118  {
119  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
120  $hookmanager=new HookManager($this->db);
121  }
122  $hookmanager->initHooks(array('pdfgeneration'));
123  $parameters=array('file'=>$file, 'outputlangs'=>$outputlangs);
124  global $action;
125  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
126 
127  // Create PDF instance
128  $pdf=pdf_getInstance($this->format);
129  $heightforinfotot = 50; // Height reserved to output the info and total part
130  $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
131  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
132  $pdf->SetAutoPageBreak(1,0);
133 
134  if (class_exists('TCPDF'))
135  {
136  $pdf->setPrintHeader(false);
137  $pdf->setPrintFooter(false);
138  }
139  $pdf->SetFont(pdf_getPDFFont($outputlangs));
140 
141  $pdf->Open();
142  $pagenb=0;
143  $pdf->SetDrawColor(128,128,128);
144 
145  $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
146  $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
147  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
148  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
149  $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
150  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
151 
152  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
153 
154  $nboflines=count($this->lines);
155 
156  // Define nb of page
157  $pages = intval($nboflines / $this->line_per_page);
158  if (($nboflines % $this->line_per_page)>0)
159  {
160  $pages++;
161  }
162  if ($pages == 0)
163  {
164  // force to build at least one page if report has no lines
165  $pages = 1;
166  }
167 
168  $pdf->AddPage();
169  $pagenb++;
170  $this->Header($pdf, $pagenb, $pages, $outputlangs);
171 
172  $this->Body($pdf, $pagenb, $pages, $outputlangs);
173 
174  // Pied de page
175  $this->_pagefoot($pdf,'',$outputlangs);
176  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
177 
178  $pdf->Close();
179 
180  $pdf->Output($file,'F');
181 
182  // Add pdfgeneration hook
183  if (! is_object($hookmanager))
184  {
185  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
186  $hookmanager=new HookManager($this->db);
187  }
188  $hookmanager->initHooks(array('pdfgeneration'));
189  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
190  global $action;
191  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
192 
193  if (! empty($conf->global->MAIN_UMASK))
194  @chmod($file, octdec($conf->global->MAIN_UMASK));
195 
196  $this->result = array('fullpath'=>$file);
197 
198  $outputlangs->charset_output=$sav_charset_output;
199  return 1; // Pas d'erreur
200  }
201 
202 
212  function Header(&$pdf, $page, $pages, $outputlangs)
213  {
214  global $langs;
215  $default_font_size = pdf_getPDFFontSize($outputlangs);
216 
217  $outputlangs->load("compta");
218  $outputlangs->load("banks");
219 
220  $title = $outputlangs->transnoentities("CheckReceipt");
221  $pdf->SetFont('','B', $default_font_size);
222  $pdf->SetXY(10,8);
223  $pdf->MultiCell(0,2,$title,0,'L');
224 
225  $pdf->SetFont('','', $default_font_size);
226  $pdf->SetXY(10,15);
227  $pdf->MultiCell(22,2,$outputlangs->transnoentities("Ref"),0,'L');
228  $pdf->SetXY(32,15);
229  $pdf->SetFont('','', $default_font_size);
230  $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
231 
232  $pdf->SetFont('','', $default_font_size);
233  $pdf->SetXY(10,20);
234  $pdf->MultiCell(22,2,$outputlangs->transnoentities("Date"),0,'L');
235  $pdf->SetXY(32,20);
236  $pdf->SetFont('','', $default_font_size);
237  $pdf->MultiCell(60, 2, dol_print_date($this->date,"day",false,$outputlangs));
238 
239  $pdf->SetFont('','', $default_font_size);
240  $pdf->SetXY(10,26);
241  $pdf->MultiCell(22,2,$outputlangs->transnoentities("Owner"),0,'L');
242  $pdf->SetFont('','', $default_font_size);
243  $pdf->SetXY(32,26);
244  $pdf->MultiCell(60,2,$outputlangs->convToOutputCharset($this->account->proprio),0,'L');
245 
246  $pdf->SetFont('','', $default_font_size);
247  $pdf->SetXY(10,32);
248  $pdf->MultiCell(0,2,$outputlangs->transnoentities("Account"),0,'L');
249  pdf_bank($pdf,$outputlangs,32,32,$this->account,1);
250 
251  $pdf->SetFont('','', $default_font_size);
252  $pdf->SetXY(114,15);
253  $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
254 
255  $pdf->Rect(9, 14, 192, 35);
256  $pdf->line(9, 19, 112, 19);
257  $pdf->line(9, 25, 112, 25);
258  //$pdf->line(9, 31, 201, 31);
259  $pdf->line(9, 31, 112, 31);
260 
261  $pdf->line(30, 14, 30, 49);
262  $pdf->line(112, 14, 112, 49);
263 
264  // Number of cheques
265  $posy=51;
266  $pdf->Rect(9, $posy, 192, 6);
267  $pdf->line(55, $posy, 55, $posy+6);
268  $pdf->line(140, $posy, 140, $posy+6);
269  $pdf->line(170, $posy, 170, $posy+6);
270 
271  $pdf->SetFont('','', $default_font_size);
272  $pdf->SetXY(10,$posy+1);
273  $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
274 
275  $pdf->SetFont('','B', $default_font_size);
276  $pdf->SetXY(57,$posy+1);
277  $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
278 
279  $pdf->SetFont('','', $default_font_size);
280  $pdf->SetXY(148,$posy+1);
281  $pdf->MultiCell(40, 2, $langs->trans("Total"));
282 
283  $pdf->SetFont('','B', $default_font_size);
284  $pdf->SetXY(170, $posy+1);
285  $pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
286 
287  // Tableau
288  $pdf->SetFont('','', $default_font_size - 2);
289  $pdf->SetXY(11, $this->tab_top+2);
290  $pdf->MultiCell(40,2,$outputlangs->transnoentities("Num"), 0, 'L');
291  $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
292 
293  $pdf->SetXY(41, $this->tab_top+2);
294  $pdf->MultiCell(40,2,$outputlangs->transnoentities("Bank"), 0, 'L');
295  $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
296 
297  $pdf->SetXY(101, $this->tab_top+2);
298  $pdf->MultiCell(40,2,$outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
299  $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
300 
301  $pdf->SetXY(180, $this->tab_top+2);
302  $pdf->MultiCell(20,2,$outputlangs->transnoentities("Amount"), 0, 'R');
303  $pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
304 
305  $pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
306  }
307 
308 
318  function Body(&$pdf, $pagenb, $pages, $outputlangs)
319  {
320  // x=10 - Num
321  // x=30 - Banque
322  // x=100 - Emetteur
323  $default_font_size = pdf_getPDFFontSize($outputlangs);
324  $pdf->SetFont('','', $default_font_size - 1);
325  $oldprowid = 0;
326  $pdf->SetFillColor(220,220,220);
327  $yp = 0;
328  $lineinpage=0;
329  $num=count($this->lines);
330  for ($j = 0; $j < $num; $j++)
331  {
332  $lineinpage++;
333 
334  $pdf->SetXY(1, $this->tab_top + 10 + $yp);
335  $pdf->MultiCell(8, $this->line_height, $j+1, 0, 'R', 0);
336 
337  $pdf->SetXY(10, $this->tab_top + 10 + $yp);
338  $pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq?$this->lines[$j]->num_chq:'', 0, 'L', 0);
339 
340  $pdf->SetXY(40, $this->tab_top + 10 + $yp);
341  $pdf->MultiCell(70, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->bank_chq),44), 0, 'L', 0);
342 
343  $pdf->SetXY(100, $this->tab_top + 10 + $yp);
344  $pdf->MultiCell(80, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq),50), 0, 'L', 0);
345 
346  $pdf->SetXY(180, $this->tab_top + 10 + $yp);
347  $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
348 
349  $yp = $yp + $this->line_height;
350 
351  if ($lineinpage >= $this->line_per_page && $j < (count($this->lines)-1))
352  {
353  $lineinpage=0; $yp=0;
354 
355  // New page
356  $pdf->AddPage();
357  $pagenb++;
358  $this->Header($pdf, $pagenb, $pages, $outputlangs);
359  $pdf->SetFont('','', $default_font_size - 1);
360  $pdf->MultiCell(0, 3, ''); // Set interline to 3
361  $pdf->SetTextColor(0,0,0);
362  }
363  }
364  }
365 
366 
376  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
377  {
378  global $conf;
379  $default_font_size = pdf_getPDFFontSize($outputlangs);
380 
381  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
382 
383  // Line of free text
384  $newfreetext='';
385  $paramfreetext='BANK_CHEQUERECEIPT_FREE_TEXT';
386  if (! empty($conf->global->$paramfreetext))
387  {
388  $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
389  }
390 
391  return pdf_pagefoot($pdf,$outputlangs,$newfreetext,$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
392  }
393 }
394 
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:672
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:256
Header(&$pdf, $page, $pages, $outputlangs)
Generate Header.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:233
Body(&$pdf, $pagenb, $pages, $outputlangs)
Output array.
Classe mere des modeles de.
Class to manage hooks.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0)
Show footer of page for PDF generation.
Definition: pdf.lib.php:852
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
__construct($db)
Constructor.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval)...
type
Definition: viewcat.php:283
Class of file to build cheque deposit receipts.
write_file($object, $_dir, $number, $outputlangs)
Fonction to generate document on disk.