dolibarr  16.0.5
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 <https://www.gnu.org/licenses/>.
16  * or see https://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 {
41  public $emetteur;
42 
46  public $version = 'development';
47 
53  public function __construct($db)
54  {
55  global $conf, $langs, $mysoc;
56 
57  // Load translation files required by the page
58  $langs->loadLangs(array("main", "bank", "withdrawals", "companies"));
59 
60  $this->db = $db;
61  $this->name = "ban";
62  $this->description = $langs->trans("DocumentModelBan").' (Volunteer wanted to finish)';
63 
64  // Page size for A4 format
65  $this->type = 'pdf';
66  $formatarray = pdf_getFormat();
67  $this->page_largeur = $formatarray['width'];
68  $this->page_hauteur = $formatarray['height'];
69  $this->format = array($this->page_largeur, $this->page_hauteur);
70  $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
71  $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
72  $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
73  $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
74 
75  $this->option_logo = 1; // Display logo FAC_PDF_LOGO
76  $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
77 
78  // Retrieves transmitter
79  $this->emetteur = $mysoc;
80  if (!$this->emetteur->country_code) {
81  $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
82  }
83 
84  // Define column position
85  $this->posxref = $this->marge_gauche + 1;
86  $this->posxlabel = $this->marge_gauche + 25;
87  $this->posxworkload = $this->marge_gauche + 100;
88  $this->posxdatestart = $this->marge_gauche + 150;
89  $this->posxdateend = $this->marge_gauche + 170;
90  }
91 
92 
93  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
101  public function write_file($object, $outputlangs)
102  {
103  // phpcs:enable
104  global $conf, $hookmanager, $langs, $user;
105 
106  if (!is_object($outputlangs)) {
107  $outputlangs = $langs;
108  }
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)) {
111  $outputlangs->charset_output = 'ISO-8859-1';
112  }
113 
114  // Load traductions files required by page
115  $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
116 
117  if ($conf->bank->dir_output) {
118  //$nblines = count($object->lines); // This is set later with array of tasks
119 
120  // Definition of $dir and $file
121  if ($object->specimen) {
122  $dir = $conf->bank->dir_output;
123  $file = $dir."/SPECIMEN.pdf";
124  } else {
125  $objectref = dol_sanitizeFileName($object->ref);
126  $dir = $conf->bank->dir_output."/".$objectref;
127  $file = $dir."/".$objectref.".pdf";
128  }
129 
130  if (!file_exists($dir)) {
131  if (dol_mkdir($dir) < 0) {
132  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
133  return 0;
134  }
135  }
136 
137  if (file_exists($dir)) {
138  // Add pdfgeneration hook
139  if (!is_object($hookmanager)) {
140  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
141  $hookmanager = new HookManager($this->db);
142  }
143  $hookmanager->initHooks(array('pdfgeneration'));
144  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
145  global $action;
146  $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
147 
148  $pdf = pdf_getInstance($this->format);
149  $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
150  $heightforinfotot = 50; // Height reserved to output the info and total part
151  $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
152  $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
153  if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
154  $heightforfooter += 6;
155  }
156  $pdf->SetAutoPageBreak(1, 0);
157 
158  if (class_exists('TCPDF')) {
159  $pdf->setPrintHeader(false);
160  $pdf->setPrintFooter(false);
161  }
162  $pdf->SetFont(pdf_getPDFFont($outputlangs));
163 
164  $pdf->Open();
165  $pagenb = 0;
166  $pdf->SetDrawColor(128, 128, 128);
167 
168  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
169  $pdf->SetSubject($outputlangs->transnoentities("BAN"));
170  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
171  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
172  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("BAN"));
173  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
174  $pdf->SetCompression(false);
175  }
176 
177  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
178 
179  // New page
180  $pdf->AddPage();
181  $pagenb++;
182  $this->_pagehead($pdf, $object, 1, $outputlangs);
183  $pdf->SetFont('', '', $default_font_size - 1);
184  $pdf->MultiCell(0, 3, ''); // Set interline to 3
185  $pdf->SetTextColor(0, 0, 0);
186 
187  $tab_top = 50;
188  $tab_top_newpage = 40;
189 
190  $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
191 
192  // Affiche notes
193  if (!empty($object->note_public)) {
194  $pdf->SetFont('', '', $default_font_size - 1);
195  $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1);
196  $nexY = $pdf->GetY();
197  $height_note = $nexY - ($tab_top - 2);
198 
199  // Rect takes a length in 3rd parameter
200  $pdf->SetDrawColor(192, 192, 192);
201  $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
202 
203  $tab_height = $tab_height - $height_note;
204  $tab_top = $nexY + 6;
205  } else {
206  $height_note = 0;
207  }
208 
209  $iniY = $tab_top + 7;
210  $curY = $tab_top + 7;
211  $nexY = $tab_top + 7;
212 
213  $pdf->SetXY($this->marge_gauche, $curY);
214  $pdf->MultiCell(200, 3, $outputlangs->trans("BAN").' : '.$object->account_number, 0, 'L');
215 
216 
217 
218  // Show square
219  if ($pagenb == 1) {
220  $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
221  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
222  } else {
223  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
224  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
225  }
226 
227  /*
228  * Footer of the page
229  */
230  $this->_pagefoot($pdf, $object, $outputlangs);
231  if (method_exists($pdf, 'AliasNbPages')) {
232  $pdf->AliasNbPages();
233  }
234 
235  $pdf->Close();
236 
237  $pdf->Output($file, 'F');
238 
239  // Add pdfgeneration hook
240  if (!is_object($hookmanager)) {
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  if ($reshook < 0) {
249  $this->error = $hookmanager->error;
250  $this->errors = $hookmanager->errors;
251  }
252 
253  if (!empty($conf->global->MAIN_UMASK)) {
254  @chmod($file, octdec($conf->global->MAIN_UMASK));
255  }
256 
257  $this->result = array('fullpath'=>$file);
258 
259  return 1; // No error
260  } else {
261  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
262  return 0;
263  }
264  }
265 
266  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "DELIVERY_OUTPUTDIR");
267  return 0;
268  }
269 
270 
271  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
284  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
285  {
286  // phpcs:enable
287  global $conf, $mysoc;
288 
289  $default_font_size = pdf_getPDFFontSize($outputlangs);
290  }
291 
292  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
302  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
303  {
304  global $langs, $conf, $mysoc;
305  // phpcs:enable
306 
307  $default_font_size = pdf_getPDFFontSize($outputlangs);
308 
309  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
310 
311  $pdf->SetTextColor(0, 0, 60);
312  $pdf->SetFont('', 'B', $default_font_size + 3);
313 
314  $posx = $this->page_largeur - $this->marge_droite - 100;
315  $posy = $this->marge_haute;
316 
317  $pdf->SetXY($this->marge_gauche, $posy);
318 
319  // Logo
320  $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
321  if ($mysoc->logo) {
322  if (is_readable($logo)) {
323  $height = pdf_getHeightForLogo($logo);
324  $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
325  } else {
326  $pdf->SetTextColor(200, 0, 0);
327  $pdf->SetFont('', 'B', $default_font_size - 2);
328  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
329  $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
330  }
331  } else {
332  $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
333  }
334 
335  $pdf->SetFont('', 'B', $default_font_size + 3);
336  $pdf->SetXY($posx, $posy);
337  $pdf->SetTextColor(0, 0, 60);
338  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("BAN")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
339  $pdf->SetFont('', '', $default_font_size + 2);
340 
341  $posy += 6;
342  $pdf->SetXY($posx, $posy);
343  $pdf->SetTextColor(0, 0, 60);
344  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date(dol_now(), 'day', false, $outputlangs, true), '', 'R');
345  /*$posy+=6;
346  $pdf->SetXY($posx,$posy);
347  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R');
348  */
349 
350  $pdf->SetTextColor(0, 0, 60);
351 
352  // Add list of linked objects
353  /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
354  $object->fetchObjectLinked();
355 
356  foreach($object->linkedObjects as $objecttype => $objects)
357  {
358  //var_dump($objects);exit;
359  if ($objecttype == 'commande')
360  {
361  $outputlangs->load('orders');
362  $num=count($objects);
363  for ($i=0;$i<$num;$i++)
364  {
365  $posy+=4;
366  $pdf->SetXY($posx,$posy);
367  $pdf->SetFont('','', $default_font_size - 1);
368  $text=$objects[$i]->ref;
369  if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
370  $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
371  }
372  }
373  }
374  */
375  }
376 
377  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
387  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
388  {
389  // phpcs:enable
390  global $conf;
391 
392  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
393  //return pdf_pagefoot($pdf,$outputlangs,'BANK_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
394  }
395 }
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
pdf_getFormat
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:84
pdf_getInstance
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition: pdf.lib.php:126
pdf_ban
Classe permettant de generer les projets au modele Ban.
Definition: pdf_ban.modules.php:36
pdf_getPDFFont
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:265
name
$conf db name
Definition: repair.php:122
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
pdf_pagehead
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:711
pdf_ban\write_file
write_file($object, $outputlangs)
Fonction generant le projet sur le disque.
Definition: pdf_ban.modules.php:101
pdf_ban\_tableau
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
Definition: pdf_ban.modules.php:284
pdf_getHeightForLogo
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:313
pdf_ban\_pagefoot
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
Definition: pdf_ban.modules.php:387
pdf_ban\_pagehead
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
Definition: pdf_ban.modules.php:302
pdf_ban\__construct
__construct($db)
Constructor.
Definition: pdf_ban.modules.php:53
ModeleBankAccountDoc
Parent class for bank account models.
Definition: modules_bank.php:32
dol_htmlentitiesbr
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...
Definition: functions.lib.php:6991
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
pdf_getPDFFontSize
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:288
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30