dolibarr 21.0.0-alpha
pdf_ban.modules.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 Nick Fragoulis
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * or see https://www.gnu.org/
20 */
21
28require_once DOL_DOCUMENT_ROOT.'/core/modules/bank/modules_bank.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33
34
40{
44 public $version = 'development';
45
49 public $posxdatestart;
50
54 public $posxdateend;
55
61 public function __construct($db)
62 {
63 global $langs, $mysoc;
64
65 // Load translation files required by the page
66 $langs->loadLangs(array("main", "bank", "withdrawals", "companies"));
67
68 $this->db = $db;
69 $this->name = "ban";
70 $this->description = $langs->trans("DocumentModelBan").' (Volunteer wanted to finish)';
71
72 // Page size for A4 format
73 $this->type = 'pdf';
74 $formatarray = pdf_getFormat();
75 $this->page_largeur = $formatarray['width'];
76 $this->page_hauteur = $formatarray['height'];
77 $this->format = array($this->page_largeur, $this->page_hauteur);
78 $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10);
79 $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10);
80 $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10);
81 $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10);
82 $this->corner_radius = getDolGlobalInt('MAIN_PDF_FRAME_CORNER_RADIUS', 0);
83 $this->option_logo = 1; // Display logo FAC_PDF_LOGO
84 $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
85
86 // Define column position
87 $this->posxref = $this->marge_gauche + 1;
88 $this->posxlabel = $this->marge_gauche + 25;
89 $this->posxworkload = $this->marge_gauche + 100;
90 $this->posxdatestart = $this->marge_gauche + 150;
91 $this->posxdateend = $this->marge_gauche + 170;
92
93 if ($mysoc === null) {
94 dol_syslog(get_class($this).'::__construct() Global $mysoc should not be null.'. getCallerInfoString(), LOG_ERR);
95 return;
96 }
97 // Retrieves issuer
98 $this->emetteur = $mysoc;
99 if (!$this->emetteur->country_code) {
100 $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
101 }
102 }
103
104
105 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
113 public function write_file($object, $outputlangs)
114 {
115 // phpcs:enable
116 global $conf, $hookmanager, $langs, $user;
117
118 if (!is_object($outputlangs)) {
119 $outputlangs = $langs;
120 }
121 // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
122 if (getDolGlobalString('MAIN_USE_FPDF')) {
123 $outputlangs->charset_output = 'ISO-8859-1';
124 }
125
126 // Load traductions files required by page
127 $outputlangs->loadLangs(array("main", "dict", "companies", "projects"));
128
129 if ($conf->bank->dir_output) {
130 //$nblines = count($object->lines); // This is set later with array of tasks
131
132 // Definition of $dir and $file
133 if ($object->specimen) {
134 $dir = $conf->bank->dir_output;
135 $file = $dir."/SPECIMEN.pdf";
136 } else {
137 $objectref = dol_sanitizeFileName($object->ref);
138 $dir = $conf->bank->dir_output."/".$objectref;
139 $file = $dir."/".$objectref.".pdf";
140 }
141
142 if (!file_exists($dir)) {
143 if (dol_mkdir($dir) < 0) {
144 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
145 return 0;
146 }
147 }
148
149 if (file_exists($dir)) {
150 // Add pdfgeneration hook
151 if (!is_object($hookmanager)) {
152 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
153 $hookmanager = new HookManager($this->db);
154 }
155 $hookmanager->initHooks(array('pdfgeneration'));
156 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
157 global $action;
158 $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
159
160 $pdf = pdf_getInstance($this->format);
161 $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
162 $heightforinfotot = 50; // Height reserved to output the info and total part
163 $heightforfreetext = getDolGlobalInt('MAIN_PDF_FREETEXT_HEIGHT', 5); // Height reserved to output the free text on last page
164 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
165 if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) {
166 $heightforfooter += 6;
167 }
168 $pdf->SetAutoPageBreak(1, 0);
169
170 if (class_exists('TCPDF')) {
171 $pdf->setPrintHeader(false);
172 $pdf->setPrintFooter(false);
173 }
174 $pdf->SetFont(pdf_getPDFFont($outputlangs));
175
176 $pdf->Open();
177 $pagenb = 0;
178 $pdf->SetDrawColor(128, 128, 128);
179
180 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
181 $pdf->SetSubject($outputlangs->transnoentities("BAN"));
182 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
183 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
184 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("BAN"));
185 if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
186 $pdf->SetCompression(false);
187 }
188
189 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
190 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
191
192 // New page
193 $pdf->AddPage();
194 $pagenb++;
195 $this->_pagehead($pdf, $object, 1, $outputlangs);
196 $pdf->SetFont('', '', $default_font_size - 1);
197 $pdf->MultiCell(0, 3, ''); // Set interline to 3
198 $pdf->SetTextColor(0, 0, 0);
199
200 $tab_top = 50;
201 $tab_top_newpage = 40;
202
203 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
204
205 // Affiche notes
206 if (!empty($object->note_public)) {
207 $pdf->SetFont('', '', $default_font_size - 1);
208 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1);
209 $nexY = $pdf->GetY();
210 $height_note = $nexY - ($tab_top - 2);
211
212 // Rect takes a length in 3rd parameter
213 $pdf->SetDrawColor(192, 192, 192);
214 $pdf->RoundedRect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius, '1234', 'D');
215
216 $tab_height -= $height_note;
217 $tab_top = $nexY + 6;
218 } else {
219 $height_note = 0;
220 }
221
222 $iniY = $tab_top + 7;
223 $curY = $tab_top + 7;
224 $nexY = $tab_top + 7;
225
226 $pdf->SetXY($this->marge_gauche, $curY);
227 $pdf->MultiCell(200, 3, $outputlangs->trans("BAN").' : '.$object->account_number, 0, 'L');
228
229
230
231 // Show square
232 if ($pagenb == 1) {
233 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
234 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
235 } else {
236 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
237 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
238 }
239
240 /*
241 * Footer of the page
242 */
243 $this->_pagefoot($pdf, $object, $outputlangs);
244 if (method_exists($pdf, 'AliasNbPages')) {
245 $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
246 }
247
248 $pdf->Close();
249
250 $pdf->Output($file, 'F');
251
252 // Add pdfgeneration hook
253 if (!is_object($hookmanager)) {
254 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
255 $hookmanager = new HookManager($this->db);
256 }
257 $hookmanager->initHooks(array('pdfgeneration'));
258 $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
259 global $action;
260 $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
261 if ($reshook < 0) {
262 $this->error = $hookmanager->error;
263 $this->errors = $hookmanager->errors;
264 }
265
266 dolChmod($file);
267
268 $this->result = array('fullpath' => $file);
269
270 return 1; // No error
271 } else {
272 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
273 return 0;
274 }
275 }
276
277 $this->error = $langs->transnoentities("ErrorConstantNotDefined", "DELIVERY_OUTPUTDIR");
278 return 0;
279 }
280
281
282 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
295 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
296 {
297 // phpcs:enable
298 global $conf, $mysoc;
299
300 $default_font_size = pdf_getPDFFontSize($outputlangs);
301 }
302
303 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
313 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
314 {
315 global $langs, $conf, $mysoc;
316 // phpcs:enable
317
318 $default_font_size = pdf_getPDFFontSize($outputlangs);
319
320 pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
321
322 $pdf->SetTextColor(0, 0, 60);
323 $pdf->SetFont('', 'B', $default_font_size + 3);
324
325 $posx = $this->page_largeur - $this->marge_droite - 100;
326 $posy = $this->marge_haute;
327
328 $pdf->SetXY($this->marge_gauche, $posy);
329
330 // Logo
331 $logo = $conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
332 if ($mysoc->logo) {
333 if (is_readable($logo)) {
334 $height = pdf_getHeightForLogo($logo);
335 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
336 } else {
337 $pdf->SetTextColor(200, 0, 0);
338 $pdf->SetFont('', 'B', $default_font_size - 2);
339 $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
340 $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
341 }
342 } else {
343 $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L');
344 }
345
346 $pdf->SetFont('', 'B', $default_font_size + 3);
347 $pdf->SetXY($posx, $posy);
348 $pdf->SetTextColor(0, 0, 60);
349 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("BAN")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
350 $pdf->SetFont('', '', $default_font_size + 2);
351
352 $posy += 6;
353 $pdf->SetXY($posx, $posy);
354 $pdf->SetTextColor(0, 0, 60);
355 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date(dol_now(), 'day', false, $outputlangs, true), '', 'R');
356 /*$posy+=6;
357 $pdf->SetXY($posx,$posy);
358 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd")." : " . dol_print_date($object->date_end,'day',false,$outputlangs,true), '', 'R');
359 */
360
361 $pdf->SetTextColor(0, 0, 60);
362
363 // Add list of linked objects
364 /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc....
365 $object->fetchObjectLinked();
366
367 foreach($object->linkedObjects as $objecttype => $objects) {
368 if ($objecttype == 'commande') {
369 $outputlangs->load('orders');
370 $num=count($objects);
371 for ($i=0;$i<$num;$i++) {
372 $posy+=4;
373 $pdf->SetXY($posx,$posy);
374 $pdf->SetFont('','', $default_font_size - 1);
375 $text=$objects[$i]->ref;
376 if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
377 $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
378 }
379 }
380 }
381 */
382
383 return 0;
384 }
385
386 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
396 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
397 {
398 // phpcs:enable
399 global $conf;
400
401 $showdetails = !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
402 return 1;
403 }
404}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage hooks.
Parent class for bank account models.
Class permettant de generer les projects 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.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
Definition pdf.lib.php:86
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
Definition pdf.lib.php:288
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
Definition pdf.lib.php:313
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
Definition pdf.lib.php:729
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Definition pdf.lib.php:265
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
Definition pdf.lib.php:128
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140