dolibarr  9.0.0
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 {
41  public $emetteur;
42 
48  function __construct($db)
49  {
50  global $conf,$langs,$mysoc;
51 
52  // Load traductions files requiredby 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  // Dimension page pour format A4
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=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
67  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
68  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
69  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
70 
71  // Recupere emmetteur
72  $this->emetteur=$mysoc;
73  if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined
74 
75  // Defini position des colonnes
76  $this->line_height = 5;
77  $this->line_per_page = 40;
78  $this->tab_height = 200; //$this->line_height * $this->line_per_page;
79  }
80 
81  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
91  function write_file($object, $_dir, $number, $outputlangs)
92  {
93  // phpcs:enable
94  global $user,$conf,$langs,$hookmanager;
95 
96  if (! is_object($outputlangs)) $outputlangs=$langs;
97  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
98  $sav_charset_output=$outputlangs->charset_output;
99  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
100 
101  // Load traductions files requiredby by page
102  $outputlangs->loadLangs(array("main", "companies", "bills", "products", "compta"));
103 
104  $dir = $_dir . "/".get_exdir($number,0,1,0,$object,'cheque').$number;
105 
106  if (! is_dir($dir))
107  {
108  $result=dol_mkdir($dir);
109 
110  if ($result < 0)
111  {
112  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
113  return -1;
114  }
115  }
116 
117  $file = $dir . "/bordereau-".$number.".pdf";
118 
119  // Add pdfgeneration hook
120  if (! is_object($hookmanager))
121  {
122  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
123  $hookmanager=new HookManager($this->db);
124  }
125  $hookmanager->initHooks(array('pdfgeneration'));
126  $parameters=array('file'=>$file, 'outputlangs'=>$outputlangs);
127  global $action;
128  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
129 
130  // Create PDF instance
131  $pdf=pdf_getInstance($this->format);
132  $heightforinfotot = 50; // Height reserved to output the info and total part
133  $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
134  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
135  if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
136  $pdf->SetAutoPageBreak(1,0);
137 
138  if (class_exists('TCPDF'))
139  {
140  $pdf->setPrintHeader(false);
141  $pdf->setPrintFooter(false);
142  }
143  $pdf->SetFont(pdf_getPDFFont($outputlangs));
144 
145  $pdf->Open();
146  $pagenb=0;
147  $pdf->SetDrawColor(128,128,128);
148 
149  $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt")." ".$number);
150  $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
151  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
152  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
153  $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt")." ".$number);
154  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
155 
156  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
157 
158  $nboflines=count($this->lines);
159 
160  // Define nb of page
161  $pages = intval($nboflines / $this->line_per_page);
162  if (($nboflines % $this->line_per_page)>0)
163  {
164  $pages++;
165  }
166  if ($pages == 0)
167  {
168  // force to build at least one page if report has no lines
169  $pages = 1;
170  }
171 
172  $pdf->AddPage();
173  $pagenb++;
174  $this->Header($pdf, $pagenb, $pages, $outputlangs);
175 
176  $this->Body($pdf, $pagenb, $pages, $outputlangs);
177 
178  // Pied de page
179  $this->_pagefoot($pdf,'',$outputlangs);
180  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
181 
182  $pdf->Close();
183 
184  $pdf->Output($file,'F');
185 
186  // Add pdfgeneration hook
187  if (! is_object($hookmanager))
188  {
189  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
190  $hookmanager=new HookManager($this->db);
191  }
192  $hookmanager->initHooks(array('pdfgeneration'));
193  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
194  global $action;
195  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
196 
197  if (! empty($conf->global->MAIN_UMASK))
198  @chmod($file, octdec($conf->global->MAIN_UMASK));
199 
200  $this->result = array('fullpath'=>$file);
201 
202  $outputlangs->charset_output=$sav_charset_output;
203  return 1; // Pas d'erreur
204  }
205 
206 
207  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
217  function Header(&$pdf, $page, $pages, $outputlangs)
218  {
219  // phpcs:enable
220  global $langs;
221  $default_font_size = pdf_getPDFFontSize($outputlangs);
222 
223  // Load traductions files requiredby by page
224  $outputlangs->loadLangs(array("compta", "banks"));
225 
226  $title = $outputlangs->transnoentities("CheckReceipt");
227  $pdf->SetFont('','B', $default_font_size);
228  $pdf->SetXY(10,8);
229  $pdf->MultiCell(0,2,$title,0,'L');
230 
231  $pdf->SetFont('','', $default_font_size);
232  $pdf->SetXY(10,15);
233  $pdf->MultiCell(22,2,$outputlangs->transnoentities("Ref"),0,'L');
234  $pdf->SetXY(32,15);
235  $pdf->SetFont('','', $default_font_size);
236  $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
237 
238  $pdf->SetFont('','', $default_font_size);
239  $pdf->SetXY(10,20);
240  $pdf->MultiCell(22,2,$outputlangs->transnoentities("Date"),0,'L');
241  $pdf->SetXY(32,20);
242  $pdf->SetFont('','', $default_font_size);
243  $pdf->MultiCell(60, 2, dol_print_date($this->date,"day",false,$outputlangs));
244 
245  $pdf->SetFont('','', $default_font_size);
246  $pdf->SetXY(10,26);
247  $pdf->MultiCell(22,2,$outputlangs->transnoentities("Owner"),0,'L');
248  $pdf->SetFont('','', $default_font_size);
249  $pdf->SetXY(32,26);
250  $pdf->MultiCell(60,2,$outputlangs->convToOutputCharset($this->account->proprio),0,'L');
251 
252  $pdf->SetFont('','', $default_font_size);
253  $pdf->SetXY(10,32);
254  $pdf->MultiCell(0,2,$outputlangs->transnoentities("Account"),0,'L');
255  pdf_bank($pdf,$outputlangs,32,32,$this->account,1);
256 
257  $pdf->SetFont('','', $default_font_size);
258  $pdf->SetXY(114,15);
259  $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L');
260 
261  $pdf->Rect(9, 14, 192, 35);
262  $pdf->line(9, 19, 112, 19);
263  $pdf->line(9, 25, 112, 25);
264  //$pdf->line(9, 31, 201, 31);
265  $pdf->line(9, 31, 112, 31);
266 
267  $pdf->line(30, 14, 30, 49);
268  $pdf->line(112, 14, 112, 49);
269 
270  // Number of cheques
271  $posy=51;
272  $pdf->Rect(9, $posy, 192, 6);
273  $pdf->line(55, $posy, 55, $posy+6);
274  $pdf->line(140, $posy, 140, $posy+6);
275  $pdf->line(170, $posy, 170, $posy+6);
276 
277  $pdf->SetFont('','', $default_font_size);
278  $pdf->SetXY(10,$posy+1);
279  $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L');
280 
281  $pdf->SetFont('','B', $default_font_size);
282  $pdf->SetXY(57,$posy+1);
283  $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L');
284 
285  $pdf->SetFont('','', $default_font_size);
286  $pdf->SetXY(148,$posy+1);
287  $pdf->MultiCell(40, 2, $langs->trans("Total"));
288 
289  $pdf->SetFont('','B', $default_font_size);
290  $pdf->SetXY(170, $posy+1);
291  $pdf->MultiCell(31, 2, price($this->amount), 0, 'C', 0);
292 
293  // Tableau
294  $pdf->SetFont('','', $default_font_size - 2);
295  $pdf->SetXY(11, $this->tab_top+2);
296  $pdf->MultiCell(40,2,$outputlangs->transnoentities("Num"), 0, 'L');
297  $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10);
298 
299  $pdf->SetXY(41, $this->tab_top+2);
300  $pdf->MultiCell(40,2,$outputlangs->transnoentities("Bank"), 0, 'L');
301  $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10);
302 
303  $pdf->SetXY(101, $this->tab_top+2);
304  $pdf->MultiCell(40,2,$outputlangs->transnoentities("CheckTransmitter"), 0, 'L');
305  $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10);
306 
307  $pdf->SetXY(180, $this->tab_top+2);
308  $pdf->MultiCell(20,2,$outputlangs->transnoentities("Amount"), 0, 'R');
309  $pdf->line(9, $this->tab_top + 8, 201, $this->tab_top + 8);
310 
311  $pdf->Rect(9, $this->tab_top, 192, $this->tab_height + 10);
312  }
313 
314 
315  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
325  function Body(&$pdf, $pagenb, $pages, $outputlangs)
326  {
327  // phpcs:enable
328  // x=10 - Num
329  // x=30 - Banque
330  // x=100 - Emetteur
331  $default_font_size = pdf_getPDFFontSize($outputlangs);
332  $pdf->SetFont('','', $default_font_size - 1);
333  $oldprowid = 0;
334  $pdf->SetFillColor(220,220,220);
335  $yp = 0;
336  $lineinpage=0;
337  $num=count($this->lines);
338  for ($j = 0; $j < $num; $j++)
339  {
340  $lineinpage++;
341 
342  $pdf->SetXY(1, $this->tab_top + 10 + $yp);
343  $pdf->MultiCell(8, $this->line_height, $j+1, 0, 'R', 0);
344 
345  $pdf->SetXY(10, $this->tab_top + 10 + $yp);
346  $pdf->MultiCell(30, $this->line_height, $this->lines[$j]->num_chq?$this->lines[$j]->num_chq:'', 0, 'L', 0);
347 
348  $pdf->SetXY(40, $this->tab_top + 10 + $yp);
349  $pdf->MultiCell(70, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->bank_chq),44), 0, 'L', 0);
350 
351  $pdf->SetXY(100, $this->tab_top + 10 + $yp);
352  $pdf->MultiCell(80, $this->line_height, dol_trunc($outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq),50), 0, 'L', 0);
353 
354  $pdf->SetXY(180, $this->tab_top + 10 + $yp);
355  $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0);
356 
357  $yp = $yp + $this->line_height;
358 
359  if ($lineinpage >= $this->line_per_page && $j < (count($this->lines)-1))
360  {
361  $lineinpage=0; $yp=0;
362 
363  // New page
364  $pdf->AddPage();
365  $pagenb++;
366  $this->Header($pdf, $pagenb, $pages, $outputlangs);
367  $pdf->SetFont('','', $default_font_size - 1);
368  $pdf->MultiCell(0, 3, ''); // Set interline to 3
369  $pdf->SetTextColor(0,0,0);
370  }
371  }
372  }
373 
374 
384  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
385  {
386  global $conf;
387  $default_font_size = pdf_getPDFFontSize($outputlangs);
388 
389  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
390 
391  // Line of free text
392  $newfreetext='';
393  $paramfreetext='BANK_CHEQUERECEIPT_FREE_TEXT';
394  if (! empty($conf->global->$paramfreetext))
395  {
396  $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
397  }
398 
399  return pdf_pagefoot($pdf,$outputlangs,$newfreetext,$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
400  }
401 }
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
Definition: pdf.lib.php:692
_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 &#39;...&#39; 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:224
Header(&$pdf, $page, $pages, $outputlangs)
Generate Header.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:201
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Body(&$pdf, $pagenb, $pages, $outputlangs)
Output array.
Classe mere des modeles de.
Class to manage hooks.
type
Definition: viewcat.php:284
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:872
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 substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Class of file to build cheque deposit receipts.
write_file($object, $_dir, $number, $outputlangs)
Fonction to generate document on disk.