dolibarr  9.0.0
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 {
42  public $emetteur;
43 
48  public $version = 'development';
49 
55  function __construct($db)
56  {
57  global $conf,$langs,$mysoc;
58 
59  // Load translation files required by the page
60  $langs->loadLangs(array("main","bank","withdrawals","companies"));
61 
62  $this->db = $db;
63  $this->name = "ban";
64  $this->description = $langs->trans("DocumentModelBan").' (Volunteer wanted to finish)';
65 
66  // Dimension page pour format A4
67  $this->type = 'pdf';
68  $formatarray=pdf_getFormat();
69  $this->page_largeur = $formatarray['width'];
70  $this->page_hauteur = $formatarray['height'];
71  $this->format = array($this->page_largeur,$this->page_hauteur);
72  $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
73  $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
74  $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
75  $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
76 
77  $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
78  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
79  $this->option_codeproduitservice = 1; // Affiche code produit-service
80 
81  // Recupere emmetteur
82  $this->emetteur=$mysoc;
83  if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined
84 
85  // Defini position des colonnes
86  $this->posxref=$this->marge_gauche+1;
87  $this->posxlabel=$this->marge_gauche+25;
88  $this->posxworkload=$this->marge_gauche+100;
89  $this->posxprogress=$this->marge_gauche+130;
90  $this->posxdatestart=$this->marge_gauche+150;
91  $this->posxdateend=$this->marge_gauche+170;
92  }
93 
94 
95  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
103  function write_file($object,$outputlangs)
104  {
105  // phpcs:enable
106  global $conf, $hookmanager, $langs, $user;
107 
108  if (! is_object($outputlangs)) $outputlangs=$langs;
109  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
110  if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
111 
112  // Load traductions files requiredby by page
113  $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
114 
115  if ($conf->bank->dir_output)
116  {
117  //$nblignes = count($object->lines); // This is set later with array of tasks
118 
119  // Definition of $dir and $file
120  if ($object->specimen)
121  {
122  $dir = $conf->bank->dir_output;
123  $file = $dir . "/SPECIMEN.pdf";
124  }
125  else
126  {
127  $objectref = dol_sanitizeFileName($object->ref);
128  $dir = $conf->bank->dir_output . "/" . $objectref;
129  $file = $dir . "/" . $objectref . ".pdf";
130  }
131 
132  if (! file_exists($dir))
133  {
134  if (dol_mkdir($dir) < 0)
135  {
136  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
137  return 0;
138  }
139  }
140 
141  if (file_exists($dir))
142  {
143  // Add pdfgeneration hook
144  if (! is_object($hookmanager))
145  {
146  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
147  $hookmanager=new HookManager($this->db);
148  }
149  $hookmanager->initHooks(array('pdfgeneration'));
150  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
151  global $action;
152  $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
153 
154  $pdf=pdf_getInstance($this->format);
155  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
156  $heightforinfotot = 50; // Height reserved to output the info and total part
157  $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
158  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
159  if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
160  $pdf->SetAutoPageBreak(1,0);
161 
162  if (class_exists('TCPDF'))
163  {
164  $pdf->setPrintHeader(false);
165  $pdf->setPrintFooter(false);
166  }
167  $pdf->SetFont(pdf_getPDFFont($outputlangs));
168 
169  $pdf->Open();
170  $pagenb=0;
171  $pdf->SetDrawColor(128,128,128);
172 
173  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
174  $pdf->SetSubject($outputlangs->transnoentities("BAN"));
175  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
176  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
177  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("BAN"));
178  if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
179 
180  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
181 
182  // New page
183  $pdf->AddPage();
184  $pagenb++;
185  $this->_pagehead($pdf, $object, 1, $outputlangs);
186  $pdf->SetFont('','', $default_font_size - 1);
187  $pdf->MultiCell(0, 3, ''); // Set interline to 3
188  $pdf->SetTextColor(0,0,0);
189 
190  $tab_top = 50;
191  $tab_height = 200;
192  $tab_top_newpage = 40;
193  $tab_height_newpage = 210;
194 
195  // Affiche notes
196  if (! empty($object->note_public))
197  {
198  $pdf->SetFont('','', $default_font_size - 1);
199  $pdf->writeHTMLCell(190, 3, $this->posxref-1, $tab_top-2, dol_htmlentitiesbr($object->note_public), 0, 1);
200  $nexY = $pdf->GetY();
201  $height_note=$nexY-($tab_top-2);
202 
203  // Rect prend une longueur en 3eme param
204  $pdf->SetDrawColor(192,192,192);
205  $pdf->Rect($this->marge_gauche, $tab_top-3, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
206 
207  $tab_height = $tab_height - $height_note;
208  $tab_top = $nexY+6;
209  }
210  else
211  {
212  $height_note=0;
213  }
214 
215  $iniY = $tab_top + 7;
216  $curY = $tab_top + 7;
217  $nexY = $tab_top + 7;
218 
219  $pdf->SetXY($this->marge_gauche, $curY);
220  $pdf->MultiCell(200, 3, $outputlangs->trans("BAN").' : '.$object->account_number, 0, 'L');
221 
222 
223 
224  // Show square
225  if ($pagenb == 1)
226  {
227  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
228  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
229  }
230  else
231  {
232  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
233  $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
234  }
235 
236  /*
237  * Pied de page
238  */
239  $this->_pagefoot($pdf,$object,$outputlangs);
240  if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
241 
242  $pdf->Close();
243 
244  $pdf->Output($file,'F');
245 
246  // Add pdfgeneration hook
247  if (! is_object($hookmanager))
248  {
249  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
250  $hookmanager=new HookManager($this->db);
251  }
252  $hookmanager->initHooks(array('pdfgeneration'));
253  $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
254  global $action;
255  $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
256 
257  if (! empty($conf->global->MAIN_UMASK))
258  @chmod($file, octdec($conf->global->MAIN_UMASK));
259 
260  $this->result = array('fullpath'=>$file);
261 
262  return 1; // Pas d'erreur
263  }
264  else
265  {
266  $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
267  return 0;
268  }
269  }
270 
271  $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
272  return 0;
273  }
274 
275 
288  function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
289  {
290  global $conf,$mysoc;
291 
292  $default_font_size = pdf_getPDFFontSize($outputlangs);
293  }
294 
304  function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
305  {
306  global $langs,$conf,$mysoc;
307 
308  $default_font_size = pdf_getPDFFontSize($outputlangs);
309 
310  pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
311 
312  $pdf->SetTextColor(0,0,60);
313  $pdf->SetFont('','B', $default_font_size + 3);
314 
315  $posx=$this->page_largeur-$this->marge_droite-100;
316  $posy=$this->marge_haute;
317 
318  $pdf->SetXY($this->marge_gauche,$posy);
319 
320  // Logo
321  $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
322  if ($mysoc->logo)
323  {
324  if (is_readable($logo))
325  {
326  $height=pdf_getHeightForLogo($logo);
327  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
328  }
329  else
330  {
331  $pdf->SetTextColor(200,0,0);
332  $pdf->SetFont('','B', $default_font_size - 2);
333  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
334  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
335  }
336  }
337  else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
338 
339  $pdf->SetFont('','B', $default_font_size + 3);
340  $pdf->SetXY($posx,$posy);
341  $pdf->SetTextColor(0,0,60);
342  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("BAN")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
343  $pdf->SetFont('','', $default_font_size + 2);
344 
345  $posy+=6;
346  $pdf->SetXY($posx,$posy);
347  $pdf->SetTextColor(0,0,60);
348  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date(dol_now(),'day',false,$outputlangs,true), '', 'R');
349  /*$posy+=6;
350  $pdf->SetXY($posx,$posy);
351  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R');
352  */
353 
354  $pdf->SetTextColor(0,0,60);
355 
356  // Add list of linked objects
357  /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
358  $object->fetchObjectLinked();
359 
360  foreach($object->linkedObjects as $objecttype => $objects)
361  {
362  var_dump($objects);exit;
363  if ($objecttype == 'commande')
364  {
365  $outputlangs->load('orders');
366  $num=count($objects);
367  for ($i=0;$i<$num;$i++)
368  {
369  $posy+=4;
370  $pdf->SetXY($posx,$posy);
371  $pdf->SetFont('','', $default_font_size - 1);
372  $text=$objects[$i]->ref;
373  if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
374  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
375  }
376  }
377  }
378  */
379  }
380 
390  function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
391  {
392  global $conf;
393  $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
394  //return pdf_pagefoot($pdf,$outputlangs,'BANK_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
395  }
396 }
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:600
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="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< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
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:224
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:201
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Class to manage hooks.
type
Definition: viewcat.php:284
_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:245
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.
$version
Dolibarr version of the loaded document string.