dolibarr  13.0.2
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; // Affiche logo FAC_PDF_LOGO
76  $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
77  $this->option_codeproduitservice = 1; // Affiche code produit-service
78 
79  // Retrieves transmitter
80  $this->emetteur = $mysoc;
81  if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
82 
83  // Define column position
84  $this->posxref = $this->marge_gauche + 1;
85  $this->posxlabel = $this->marge_gauche + 25;
86  $this->posxworkload = $this->marge_gauche + 100;
87  $this->posxdatestart = $this->marge_gauche + 150;
88  $this->posxdateend = $this->marge_gauche + 170;
89  }
90 
91 
92  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
100  public function write_file($object, $outputlangs)
101  {
102  // phpcs:enable
103  global $conf, $hookmanager, $langs, $user;
104 
105  if (!is_object($outputlangs)) $outputlangs = $langs;
106  // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
107  if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1';
108 
109  // Load traductions files required by page
110  $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
111 
112  if ($conf->bank->dir_output)
113  {
114  //$nblines = count($object->lines); // This is set later with array of tasks
115 
116  // Definition of $dir and $file
117  if ($object->specimen) {
118  $dir = $conf->bank->dir_output;
119  $file = $dir."/SPECIMEN.pdf";
120  } else {
121  $objectref = dol_sanitizeFileName($object->ref);
122  $dir = $conf->bank->dir_output."/".$objectref;
123  $file = $dir."/".$objectref.".pdf";
124  }
125 
126  if (!file_exists($dir))
127  {
128  if (dol_mkdir($dir) < 0)
129  {
130  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
131  return 0;
132  }
133  }
134 
135  if (file_exists($dir))
136  {
137  // Add pdfgeneration hook
138  if (!is_object($hookmanager))
139  {
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)) $heightforfooter += 6;
154  $pdf->SetAutoPageBreak(1, 0);
155 
156  if (class_exists('TCPDF'))
157  {
158  $pdf->setPrintHeader(false);
159  $pdf->setPrintFooter(false);
160  }
161  $pdf->SetFont(pdf_getPDFFont($outputlangs));
162 
163  $pdf->Open();
164  $pagenb = 0;
165  $pdf->SetDrawColor(128, 128, 128);
166 
167  $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
168  $pdf->SetSubject($outputlangs->transnoentities("BAN"));
169  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
170  $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
171  $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("BAN"));
172  if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
173 
174  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
175 
176  // New page
177  $pdf->AddPage();
178  $pagenb++;
179  $this->_pagehead($pdf, $object, 1, $outputlangs);
180  $pdf->SetFont('', '', $default_font_size - 1);
181  $pdf->MultiCell(0, 3, ''); // Set interline to 3
182  $pdf->SetTextColor(0, 0, 0);
183 
184  $tab_top = 50;
185  $tab_height = 200;
186  $tab_top_newpage = 40;
187  $tab_height_newpage = 210;
188 
189  // Affiche notes
190  if (!empty($object->note_public))
191  {
192  $pdf->SetFont('', '', $default_font_size - 1);
193  $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1);
194  $nexY = $pdf->GetY();
195  $height_note = $nexY - ($tab_top - 2);
196 
197  // Rect takes a length in 3rd parameter
198  $pdf->SetDrawColor(192, 192, 192);
199  $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
200 
201  $tab_height = $tab_height - $height_note;
202  $tab_top = $nexY + 6;
203  } else {
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  } else {
222  $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
223  $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
224  }
225 
226  /*
227  * Footer of the page
228  */
229  $this->_pagefoot($pdf, $object, $outputlangs);
230  if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
231 
232  $pdf->Close();
233 
234  $pdf->Output($file, 'F');
235 
236  // Add pdfgeneration hook
237  if (!is_object($hookmanager))
238  {
239  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
240  $hookmanager = new HookManager($this->db);
241  }
242  $hookmanager->initHooks(array('pdfgeneration'));
243  $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
244  global $action;
245  $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
246  if ($reshook < 0)
247  {
248  $this->error = $hookmanager->error;
249  $this->errors = $hookmanager->errors;
250  }
251 
252  if (!empty($conf->global->MAIN_UMASK))
253  @chmod($file, octdec($conf->global->MAIN_UMASK));
254 
255  $this->result = array('fullpath'=>$file);
256 
257  return 1; // No error
258  } else {
259  $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
260  return 0;
261  }
262  }
263 
264  $this->error = $langs->transnoentities("ErrorConstantNotDefined", "DELIVERY_OUTPUTDIR");
265  return 0;
266  }
267 
268 
269  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
282  protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
283  {
284  // phpcs:enable
285  global $conf, $mysoc;
286 
287  $default_font_size = pdf_getPDFFontSize($outputlangs);
288  }
289 
290  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
300  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
301  {
302  global $langs, $conf, $mysoc;
303  // phpcs:enable
304 
305  $default_font_size = pdf_getPDFFontSize($outputlangs);
306 
307  pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
308 
309  $pdf->SetTextColor(0, 0, 60);
310  $pdf->SetFont('', 'B', $default_font_size + 3);
311 
312  $posx = $this->page_largeur - $this->marge_droite - 100;
313  $posy = $this->marge_haute;
314 
315  $pdf->SetXY($this->marge_gauche, $posy);
316 
317  // Logo
318  $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
319  if ($mysoc->logo)
320  {
321  if (is_readable($logo))
322  {
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 $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  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
385  protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
386  {
387  // phpcs:enable
388  global $conf;
389 
390  $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
391  //return pdf_pagefoot($pdf,$outputlangs,'BANK_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
392  }
393 }
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
Definition: pdf.lib.php:45
Parent class for bank account models.
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition: pdf.lib.php:620
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</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:750
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition: pdf.lib.php:245
dol_now($mode= 'auto')
Return date for now.
write_file($object, $outputlangs)
Fonction generant le projet sur le disque.
__construct($db)
Constructor.
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...
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition: pdf.lib.php:222
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
_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_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition: pdf.lib.php:270
Classe permettant de generer les projets au modele Ban.
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
Definition: pdf.lib.php:88
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)