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