dolibarr 25.0.0-alpha
bank.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
5 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
6 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array("admin", "companies", "bills", "other", "banks"));
47
48$action = GETPOST('action', 'aZ09');
49$actionsave = GETPOST('save', 'alpha');
50$value = GETPOST('value', 'alpha');
51$label = GETPOST('label', 'alpha');
52$scandir = GETPOST('scan_dir', 'alpha');
53$type = 'bankaccount';
54
55if (!$user->admin) {
57}
58
59$error = 0;
60
61
62/*
63 * Actions
64 */
65
66if (in_array($action, array('setBANK_DISABLE_DIRECT_INPUT'))) {
67 $constname = preg_replace('/^set/', '', $action);
68 $constvalue = GETPOSTINT('value');
69 $res = dolibarr_set_const($db, $constname, $constvalue, 'yesno', 0, '', $conf->entity);
70 if (!($res > 0)) {
71 $error++;
72 }
73
74 if (!$error) {
75 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
76 } else {
77 setEventMessages($langs->trans("Error"), null, 'mesgs');
78 }
79}
80
81// Order display of bank account
82if ($action == 'setbankorder') {
83 if (dolibarr_set_const($db, "BANK_SHOW_ORDER_OPTION", GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity) > 0) {
84 } else {
85 dol_print_error($db);
86 }
87}
88
89// Auto report last num releve on conciliate
90if ($action == 'setreportlastnumreleve') {
91 if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 1, 'chaine', 0, '', $conf->entity) > 0) {
92 } else {
93 dol_print_error($db);
94 }
95} elseif ($action == 'unsetreportlastnumreleve') {
96 if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 0, 'chaine', 0, '', $conf->entity) > 0) {
97 } else {
98 dol_print_error($db);
99 }
100}
101
102// Colorize movements
103if ($action == 'setbankcolorizemovement') {
104 if (dolibarr_set_const($db, "BANK_COLORIZE_MOVEMENT", 1, 'chaine', 0, '', $conf->entity) > 0) {
105 } else {
106 dol_print_error($db);
107 }
108} elseif ($action == 'unsetbankcolorizemovement') {
109 if (dolibarr_set_const($db, "BANK_COLORIZE_MOVEMENT", 0, 'chaine', 0, '', $conf->entity) > 0) {
110 } else {
111 dol_print_error($db);
112 }
113}
114
115if ($actionsave) {
116 $db->begin();
117
118 $i = 1;
119 $errorsaved = 0;
120 $error = 0;
121
122 // Save colors
123 while ($i <= 2) {
124 $color = GETPOST('BANK_COLORIZE_MOVEMENT_COLOR'.$i, 'alpha');
125 if ($color == '-1') {
126 $color = '';
127 }
128
129 $res = dolibarr_set_const($db, 'BANK_COLORIZE_MOVEMENT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
130 if (!($res > 0)) {
131 $error++;
132 }
133 $i++;
134 }
135
136 if (!$error) {
137 $db->commit();
138 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
139 } else {
140 $db->rollback();
141 if (empty($errorsaved)) {
142 setEventMessages($langs->trans("Error"), null, 'errors');
143 }
144 }
145}
146
147
148if ($action == 'specimen') {
149 $modele = GETPOST('module', 'alpha');
150
151 if ($modele == 'sepamandate') {
152 $object = new CompanyBankAccount($db);
153 } else {
154 $object = new Account($db);
155 }
156 $object->initAsSpecimen();
157
158 // Search template files
159 $file = '';
160 $classname = '';
161 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
162 foreach ($dirmodels as $reldir) {
163 $file = dol_buildpath($reldir."core/modules/bank/doc/pdf_".$modele.".modules.php", 0);
164 if (file_exists($file)) {
165 $classname = "pdf_".$modele;
166 break;
167 }
168 }
169
170 if ($classname !== '') {
171 require_once $file;
172
173 $module = new $classname($db);
174 '@phan-var-force ModeleBankAccountDoc $module';
175
176 if ($module->write_file($object, $langs) > 0) {
177 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bank&file=SPECIMEN.pdf");
178 exit();
179 } else {
180 setEventMessages($module->error, null, 'errors');
181 dol_syslog($module->error, LOG_ERR);
182 }
183 } else {
184 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
185 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
186 }
187}
188
189// Activate a model
190if ($action == 'set') {
191 $ret = addDocumentModel($value, $type, $label, $scandir);
192} elseif ($action == 'del') {
193 $ret = delDocumentModel($value, $type);
194 if ($ret > 0) {
195 if (getDolGlobalString('BANKADDON_PDF') == "$value") {
196 dolibarr_del_const($db, 'BANKADDON_PDF', $conf->entity);
197 }
198 }
199} elseif ($action == 'setdoc') {
200 // Set default model
201 if (dolibarr_set_const($db, "BANKADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
202 // The constant that was read before the new set
203 // We therefore requires a variable to have a coherent view
204 $conf->global->BANKADDON_PDF = $value;
205 }
206
207 // On active le modele
208 $ret = delDocumentModel($value, $type);
209 if ($ret > 0) {
210 $ret = addDocumentModel($value, $type, $label, $scandir);
211 }
212}
213
214
215
216/*
217 * View
218 */
219
220$form = new Form($db);
221$formother = new FormOther($db);
222
223$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
224
225llxHeader("", $langs->trans("BankSetupModule"), '', '', 0, 0, '', '', '', 'mod-admin page-bank');
226
227$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
228
229print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup');
230
231print '<form name="bankmovementcolorconfig" action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
232print '<input type="hidden" name="token" value="'.newToken().'">';
233print '<input type="hidden" name="action" value="save">';
234
235$head = bank_admin_prepare_head(null);
236print dol_get_fiche_head($head, 'general', $langs->trans("BankSetupModule"), -1, 'account');
237
238//Show bank account order
239print load_fiche_titre($langs->trans("BankOrderShow"), '', '');
240
241print '<div class="div-table-responsive-no-min">';
242print '<table class="noborder centpercent">';
243print '<tr class="liste_titre">';
244print '<td>'.$langs->trans("Name").'</td>';
245print '<td class="minwidth100">'.$langs->trans("Description").'</td>';
246print '<td>'.$langs->trans("Example").'</td>';
247print '<td class="center">'.$langs->trans("Status").'</td>';
248print "</tr>\n";
249
250$bankorder = array();
251$bankorder[0][0] = $langs->trans("BankOrderGlobal");
252$bankorder[0][1] = $langs->trans("BankOrderGlobalDesc");
253$bankorder[0][2] = 'BankCode DeskCode BankAccountNumber BankAccountNumberKey';
254$bankorder[1][0] = $langs->trans("BankOrderES");
255$bankorder[1][1] = $langs->trans("BankOrderESDesc");
256$bankorder[1][2] = 'BankCode DeskCode BankAccountNumberKey BankAccountNumber';
257
258$i = 0;
259
260$nbofbank = count($bankorder);
261while ($i < $nbofbank) {
262 print '<tr class="oddeven">';
263 print '<td>'.$bankorder[$i][0]."</td><td>\n";
264 print $bankorder[$i][1];
265 print '</td>';
266 print '<td class="nowrap">';
267 $tmparray = explode(' ', $bankorder[$i][2]);
268 foreach ($tmparray as $key => $val) {
269 if ($key > 0) {
270 print ', ';
271 }
272 print $langs->trans($val);
273 }
274 print "</td>\n";
275
276 if (getDolGlobalInt('BANK_SHOW_ORDER_OPTION') == $i) {
277 print '<td class="center">';
278 print img_picto($langs->trans("Activated"), 'on');
279 print '</td>';
280 } else {
281 print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbankorder&token='.newToken().'&value='.((int) $i).'">';
282 print img_picto($langs->trans("Disabled"), 'off');
283 print '</a></td>';
284 }
285 print '</tr>'."\n";
286 $i++;
287}
288
289print '</table>'."\n";
290print "</div>";
291
292print '<br><br>';
293
294
295/*
296 * Document templates generators
297 */
298
299printDocumentModelList($type, 'bank', 'BANKADDON_PDF', $langs->trans("BankAccountModelModule"), array(
300 'Logo' => 'option_logo',
301 'MultiLanguage' => 'option_multilang',
302));
303
304print '<br><br>';
305
306print load_fiche_titre($langs->trans("BankColorizeMovement"), '', '');
307
308print '<div class="div-table-responsive-no-min">';
309print '<table class="noborder centpercent">'."\n";
310print '<tr class="liste_titre">'."\n";
311print '<td colspan="4">'.$langs->trans("Parameter").'</td>';
312print '<td align="center" width="75"></td>'."\n";
313print "</tr>\n";
314
315print '<tr class="oddeven"><td colspan="4">';
316print $langs->trans('BankColorizeMovementDesc');
317print "</td>";
318// Active
319if (getDolGlobalInt('BANK_COLORIZE_MOVEMENT')) {
320 print '<td class="center">'."\n";
321 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetbankcolorizemovement&token='.newToken().'">';
322 print img_picto($langs->trans("Enabled"), 'switch_on');
323 print '</a>';
324 print '</td>';
325} else {
326 print '<td class="center">'."\n";
327 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setbankcolorizemovement&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
328 print "</td>";
329}
330
331print "</tr>\n";
332
333if (getDolGlobalInt('BANK_COLORIZE_MOVEMENT')) {
334 $i = 1;
335 while ($i <= 2) {
336 $key = $i;
337 $color = 'BANK_COLORIZE_MOVEMENT_COLOR'.$key;
338
339 print '<tr class="oddeven">';
340
341 // Label
342 print '<td colspan="4" width="180" class="nowrap">'.$langs->trans("BankColorizeMovementName".$key)."</td>";
343 // Color
344 print '<td class="nowrap right">';
345 print $formother->selectColor((GETPOST("BANK_COLORIZE_MOVEMENT_COLOR".$key) ? GETPOST("BANK_COLORIZE_MOVEMENT_COLOR".$key) : getDolGlobalString($color)), "BANK_COLORIZE_MOVEMENT_COLOR".$key, '', 1, array(), 'right hideifnotset');
346 print '</td>';
347 print "</tr>";
348 $i++;
349 }
350}
351print '</table>';
352print '</div>';
353
354print '<br><br>';
355
356
357/*
358 * Document templates generators
359 */
360
361print load_fiche_titre($langs->trans("Other"), '', '');
362
363print '<div class="div-table-responsive-no-min">';
364print '<table class="noborder centpercent">'."\n";
365print '<tr class="liste_titre">'."\n";
366print '<td>'.$langs->trans("Parameter").'</td>';
367print "<td></td>\n";
368print "</tr>\n";
369
370// Disable direct input
371print '<tr class="oddeven">';
372print '<td>'.$langs->trans("BANK_DISABLE_DIRECT_INPUT").'</td>';
373if (getDolGlobalString('BANK_DISABLE_DIRECT_INPUT')) {
374 print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&action=setBANK_DISABLE_DIRECT_INPUT&value=0">';
375 print img_picto($langs->trans("Activated"), 'switch_on');
376 print '</a></td>';
377} else {
378 print '<td class="center"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&action=setBANK_DISABLE_DIRECT_INPUT&value=1">';
379 print img_picto($langs->trans("Disabled"), 'switch_off');
380 print '</a></td>';
381}
382print '</tr>';
383
384// Autofill bank statement
385print '<tr class="oddeven"><td>'."\n";
386print $langs->trans('AutoReportLastAccountStatement');
387print '</td>';
388// Active
389if (getDolGlobalString('BANK_REPORT_LAST_NUM_RELEVE')) {
390 print '<td class="center">'."\n";
391 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetreportlastnumreleve&token='.newToken().'">';
392 print img_picto($langs->trans("Enabled"), 'switch_on');
393 print '</a>';
394 print '</td>';
395} else {
396 print '<td class="center">'."\n";
397 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setreportlastnumreleve&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
398 print "</td>";
399}
400print "</tr>\n";
401
402// Allow SEPA Mandate OnLine Sign
403if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
404 print '<tr class="oddeven">';
405 print '<td>'.$form->textwithpicto($langs->trans("AllowOnLineSign"), $langs->trans("AllowOnLineSignDesc")).'</td>';
406 print '<td class="center">';
407 print ajax_constantonoff('SOCIETE_RIB_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1, '', '', 'inline-block', 0, $langs->transnoentitiesnoconv("WarningOnlineSignature", "https://www.dolistore.com"));
408 print '</td></tr>';
409}
410
411print '</table>';
412print '</div>';
413
414print dol_get_fiche_end();
415
416print $form->buttonsSaveCancel("Save", '');
417
418print "</form>\n";
419
420// End of page
421llxFooter();
422$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
bank_admin_prepare_head($object=null)
Prepare array with list of tabs.
Definition bank.lib.php:201
Class to manage bank accounts.
Class to manage bank accounts description of third parties.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.