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