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