dolibarr  7.0.0-beta
pdf_ban.modules.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  * or see http://www.gnu.org/
17  */
18 
25 require_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
26 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 
31 
37 {
38  var $emetteur; // Objet societe qui emet
39  var $version = 'development';
40 
46  function __construct($db)
47  {
48  global $conf,$langs,$mysoc;
49 
50  $langs->load("main");
51  $langs->load("bank");
52  $langs->load("withdrawals");
53  $langs->load("companies");
54 
55  $this->db = $db;
56  $this->name = "ban";
57  $this->description = $langs->trans("DocumentModelBan").' (Volunteer wanted to finish)';
58 
59  // Dimension page pour format A4
60  $this->type = 'pdf';
61  $formatarray=pdf_getFormat();
62  $this->page_largeur = $formatarray['width'];
63  $this->page_hauteur = $formatarray['height'];
64  $this->format = array($this->page_largeur,$this->page_hauteur);
65  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
66  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
67  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
68  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
69 
70  $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
71  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
72  $this->option_codeproduitservice = 1; // Affiche code produit-service
73 
74  // Recupere emmetteur
75  $this->emetteur=$mysoc;
76  if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined
77 
78  // Defini position des colonnes
79  $this->posxref=$this->marge_gauche+1;
80  $this->posxlabel=$this->marge_gauche+25;
81  $this->posxworkload=$this->marge_gauche+100;
82  $this->posxprogress=$this->marge_gauche+130;
83  $this->posxdatestart=$this->marge_gauche+150;
84  $this->posxdateend=$this->marge_gauche+170;
85  }
86 
87 
95  function write_file($object,$outputlangs)
96  {
97  global $conf, $hookmanager, $langs, $user;
98 
99  if (! is_object($outputlangs)) $outputlangs=$langs;
100  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
101  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
102 
103  $outputlangs->load("main");
104  $outputlangs->load("dict");
105  $outputlangs->load("companies");
106  $outputlangs->load("projects");
107 
108  if ($conf->bank->dir_output)
109  {
110  //$nblignes = count($object->lines); // This is set later with array of tasks
111 
112  // Definition of $dir and $file
113  if ($object->specimen)
114  {
115  $dir = $conf->bank->dir_output;
116  $file = $dir . "/SPECIMEN.pdf";
117  }
118  else
119  {
120  $objectref = dol_sanitizeFileName($object->ref);
121  $dir = $conf->bank->dir_output . "/" . $objectref;
122  $file = $dir . "/" . $objectref . ".pdf";
123  }
124 
125  if (! file_exists($dir))
126  {
127  if (dol_mkdir($dir) < 0)
128  {
129  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
130  return 0;
131  }
132  }
133 
134  if (file_exists($dir))
135  {
136  // Add pdfgeneration hook
137  if (! is_object($hookmanager))
138  {
139  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
140  $hookmanager=new HookManager($this->db);
141  }
142  $hookmanager->initHooks(array('pdfgeneration'));
143  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
144  global $action;
145  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
146 
147  $pdf=pdf_getInstance($this->format);
148  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
149  $heightforinfotot = 50; // Height reserved to output the info and total part
150  $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
151  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
152  $pdf->SetAutoPageBreak(1,0);
153 
154  if (class_exists('TCPDF'))
155  {
156  $pdf->setPrintHeader(false);
157  $pdf->setPrintFooter(false);
158  }
159  $pdf->SetFont(pdf_getPDFFont($outputlangs));
160 
161  $pdf->Open();
162  $pagenb=0;
163  $pdf->SetDrawColor(128,128,128);
164 
165  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
166  $pdf->SetSubject($outputlangs->transnoentities("BAN"));
167  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
168  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
169  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("BAN"));
170  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
171 
172  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
173 
174  // New page
175  $pdf->AddPage();
176  $pagenb++;
177  $this->_pagehead($pdf, $object, 1, $outputlangs);
178  $pdf->SetFont('','', $default_font_size - 1);
179  $pdf->MultiCell(0, 3, ''); // Set interline to 3
180  $pdf->SetTextColor(0,0,0);
181 
182  $tab_top = 50;
183  $tab_height = 200;
184  $tab_top_newpage = 40;
185  $tab_height_newpage = 210;
186 
187  // Affiche notes
188  if (! empty($object->note_public))
189  {
190  $pdf->SetFont('','', $default_font_size - 1);
191  $pdf->writeHTMLCell(190, 3, $this->posxref-1, $tab_top-2, dol_htmlentitiesbr($object->note_public), 0, 1);
192  $nexY = $pdf->GetY();
193  $height_note=$nexY-($tab_top-2);
194 
195  // Rect prend une longueur en 3eme param
196  $pdf->SetDrawColor(192,192,192);
197  $pdf->Rect($this->marge_gauche, $tab_top-3, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
198 
199  $tab_height = $tab_height - $height_note;
200  $tab_top = $nexY+6;
201  }
202  else
203  {
204  $height_note=0;
205  }
206 
207  $iniY = $tab_top + 7;
208  $curY = $tab_top + 7;
209  $nexY = $tab_top + 7;
210 
211  $pdf->SetXY($this->marge_gauche, $curY);
212  $pdf->MultiCell(200, 3, $outputlangs->trans("BAN").' : '.$object->account_number, 0, 'L');
213 
214 
215 
216  // Show square
217  if ($pagenb == 1)
218  {
219  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
220  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
221  }
222  else
223  {
224  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
225  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
226  }
227 
228  /*
229  * Pied de page
230  */
231  $this->_pagefoot($pdf,$object,$outputlangs);
232  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
233 
234  $pdf->Close();
235 
236  $pdf->Output($file,'F');
237 
238  // Add pdfgeneration hook
239  if (! is_object($hookmanager))
240  {
241  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
242  $hookmanager=new HookManager($this->db);
243  }
244  $hookmanager->initHooks(array('pdfgeneration'));
245  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
246  global $action;
247  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
248 
249  if (! empty($conf->global->MAIN_UMASK))
250  @chmod($file, octdec($conf->global->MAIN_UMASK));
251 
252  $this->result = array('fullpath'=>$file);
253 
254  return 1; // Pas d'erreur
255  }
256  else
257  {
258  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
259  return 0;
260  }
261  }
262 
263  $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
264  return 0;
265  }
266 
267 
280  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
281  {
282  global $conf,$mysoc;
283 
284  $default_font_size = pdf_getPDFFontSize($outputlangs);
285 
286 
287  }
288 
298  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
299  {
300  global $langs,$conf,$mysoc;
301 
302  $default_font_size = pdf_getPDFFontSize($outputlangs);
303 
304  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
305 
306  $pdf->SetTextColor(0,0,60);
307  $pdf->SetFont('','B', $default_font_size + 3);
308 
309  $posx=$this->page_largeur-$this->marge_droite-100;
310  $posy=$this->marge_haute;
311 
312  $pdf->SetXY($this->marge_gauche,$posy);
313 
314  // Logo
315  $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
316  if ($mysoc->logo)
317  {
318  if (is_readable($logo))
319  {
320  $height=pdf_getHeightForLogo($logo);
321  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
322  }
323  else
324  {
325  $pdf->SetTextColor(200,0,0);
326  $pdf->SetFont('','B', $default_font_size - 2);
327  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
328  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
329  }
330  }
331  else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
332 
333  $pdf->SetFont('','B', $default_font_size + 3);
334  $pdf->SetXY($posx,$posy);
335  $pdf->SetTextColor(0,0,60);
336  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("BAN")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
337  $pdf->SetFont('','', $default_font_size + 2);
338 
339  $posy+=6;
340  $pdf->SetXY($posx,$posy);
341  $pdf->SetTextColor(0,0,60);
342  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date(dol_now(),'day',false,$outputlangs,true), '', 'R');
343  /*$posy+=6;
344  $pdf->SetXY($posx,$posy);
345  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R');
346  */
347 
348  $pdf->SetTextColor(0,0,60);
349 
350  // Add list of linked objects
351  /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
352  $object->fetchObjectLinked();
353 
354  foreach($object->linkedObjects as $objecttype => $objects)
355  {
356  var_dump($objects);exit;
357  if ($objecttype == 'commande')
358  {
359  $outputlangs->load('orders');
360  $num=count($objects);
361  for ($i=0;$i<$num;$i++)
362  {
363  $posy+=4;
364  $pdf->SetXY($posx,$posy);
365  $pdf->SetFont('','', $default_font_size - 1);
366  $text=$objects[$i]->ref;
367  if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
368  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
369  }
370  }
371  }
372  */
373 
374  }
375 
385  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
386  {
387  global $conf;
388  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
389  //return pdf_pagefoot($pdf,$outputlangs,'BANK_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
390  }
391 
392 }
393 
Parent class for bank account models.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:82
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:580
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
pdf_getFormat(Translate $outputlangs=null)
Return array with format properties of default PDF format.
Definition: pdf.lib.php:42
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:256
write_file($object, $outputlangs)
Fonction generant le projet sur le disque.
__construct($db)
Constructor.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:233
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Class to manage hooks.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
dol_now($mode='gmt')
Return date for now.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:277
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Classe permettant de generer les projets au modele Ban.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
type
Definition: viewcat.php:283