dolibarr 18.0.6
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
25require_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
26require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
29require_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 = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
71 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
72 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
73 $this->marge_basse = getDolGlobalInt('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 (getDolGlobalString('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 dolChmod($file);
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 if (is_readable($logo)) {
321 $height = pdf_getHeightForLogo($logo);
322 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
323 } else {
324 $pdf->SetTextColor(200, 0, 0);
325 $pdf->SetFont('', 'B', $default_font_size - 2);
326 $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
327 $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
328 }
329 } else {
330 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
331 }
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 1;
392 }
393}
Class to manage hooks.
Parent class for bank account models.
Classe permettant de generer les projets au modele Ban.
__construct($db)
Constructor.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
Show table for lines.
write_file($object, $outputlangs)
Fonction generant le projet sur le disque.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:289
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:85
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:314
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:726
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:266
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:127
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123