dolibarr 19.0.3
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 *
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 */
20
21
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
34
35// Load translation files required by the page
36$langs->loadLangs(array("admin", "companies", "bills", "other", "banks"));
37
38if (!$user->admin) {
40}
41
42$action = GETPOST('action', 'aZ09');
43$actionsave = GETPOST('save', 'alpha');
44$value = GETPOST('value', 'alpha');
45$label = GETPOST('label', 'alpha');
46$scandir = GETPOST('scan_dir', 'alpha');
47$type = 'bankaccount';
48
49
50/*
51 * Actions
52 */
53
54// Order display of bank account
55if ($action == 'setbankorder') {
56 if (dolibarr_set_const($db, "BANK_SHOW_ORDER_OPTION", GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity) > 0) {
57 } else {
58 dol_print_error($db);
59 }
60}
61
62// Auto report last num releve on conciliate
63if ($action == 'setreportlastnumreleve') {
64 if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 1, 'chaine', 0, '', $conf->entity) > 0) {
65 } else {
66 dol_print_error($db);
67 }
68} elseif ($action == 'unsetreportlastnumreleve') {
69 if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 0, 'chaine', 0, '', $conf->entity) > 0) {
70 } else {
71 dol_print_error($db);
72 }
73}
74
75// Colorize movements
76if ($action == 'setbankcolorizemovement') {
77 if (dolibarr_set_const($db, "BANK_COLORIZE_MOVEMENT", 1, 'chaine', 0, '', $conf->entity) > 0) {
78 } else {
79 dol_print_error($db);
80 }
81} elseif ($action == 'unsetbankcolorizemovement') {
82 if (dolibarr_set_const($db, "BANK_COLORIZE_MOVEMENT", 0, 'chaine', 0, '', $conf->entity) > 0) {
83 } else {
84 dol_print_error($db);
85 }
86}
87
88if ($actionsave) {
89 $db->begin();
90
91 $i = 1;
92 $errorsaved = 0;
93 $error = 0;
94
95 // Save colors
96 while ($i <= 2) {
97 $color = GETPOST('BANK_COLORIZE_MOVEMENT_COLOR'.$i, 'alpha');
98 if ($color == '-1') {
99 $color = '';
100 }
101
102 $res = dolibarr_set_const($db, 'BANK_COLORIZE_MOVEMENT_COLOR'.$i, $color, 'chaine', 0, '', $conf->entity);
103 if (!($res > 0)) {
104 $error++;
105 }
106 $i++;
107 }
108
109 if (!$error) {
110 $db->commit();
111 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
112 } else {
113 $db->rollback();
114 if (empty($errorsaved)) {
115 setEventMessages($langs->trans("Error"), null, 'errors');
116 }
117 }
118}
119
120
121if ($action == 'specimen') {
122 $modele = GETPOST('module', 'alpha');
123
124 if ($modele == 'sepamandate') {
125 $object = new CompanyBankAccount($db);
126 } else {
127 $object = new Account($db);
128 }
129 $object->initAsSpecimen();
130
131 // Search template files
132 $file = '';
133 $classname = '';
134 $filefound = 0;
135 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
136 foreach ($dirmodels as $reldir) {
137 $file = dol_buildpath($reldir."core/modules/bank/doc/pdf_".$modele.".modules.php", 0);
138 if (file_exists($file)) {
139 $filefound = 1;
140 $classname = "pdf_".$modele;
141 break;
142 }
143 }
144
145 if ($filefound) {
146 require_once $file;
147
148 $module = new $classname($db);
149
150 if ($module->write_file($object, $langs) > 0) {
151 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bank&file=SPECIMEN.pdf");
152 return;
153 } else {
154 setEventMessages($module->error, null, 'errors');
155 dol_syslog($module->error, LOG_ERR);
156 }
157 } else {
158 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
159 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
160 }
161}
162
163// Activate a model
164if ($action == 'set') {
165 $ret = addDocumentModel($value, $type, $label, $scandir);
166} elseif ($action == 'del') {
167 $ret = delDocumentModel($value, $type);
168 if ($ret > 0) {
169 if ($conf->global->BANKADDON_PDF == "$value") {
170 dolibarr_del_const($db, 'BANKADDON_PDF', $conf->entity);
171 }
172 }
173} elseif ($action == 'setdoc') {
174 // Set default model
175 if (dolibarr_set_const($db, "BANKADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
176 // The constant that was read before the new set
177 // We therefore requires a variable to have a coherent view
178 $conf->global->BANKADDON_PDF = $value;
179 }
180
181 // On active le modele
182 $ret = delDocumentModel($value, $type);
183 if ($ret > 0) {
184 $ret = addDocumentModel($value, $type, $label, $scandir);
185 }
186}
187
188
189
190/*
191 * View
192 */
193
194$form = new Form($db);
195$formother = new FormOther($db);
196
197$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
198
199llxHeader("", $langs->trans("BankSetupModule"));
200
201$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
202print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup');
203
204print '<form name="bankmovementcolorconfig" action="'.$_SERVER["PHP_SELF"].'" method="post">';
205print '<input type="hidden" name="token" value="'.newToken().'">';
206print '<input type="hidden" name="action" value="save">';
207
208$head = bank_admin_prepare_head(null);
209print dol_get_fiche_head($head, 'general', $langs->trans("BankSetupModule"), -1, 'account');
210
211//Show bank account order
212print load_fiche_titre($langs->trans("BankOrderShow"), '', '');
213
214print '<div class="div-table-responsive-no-min">';
215print '<table class="noborder centpercent">';
216print '<tr class="liste_titre">';
217print '<td>'.$langs->trans("Name").'</td>';
218print '<td class="minwidth100">'.$langs->trans("Description").'</td>';
219print '<td>'.$langs->trans("Example").'</td>';
220print '<td class="center">'.$langs->trans("Status").'</td>';
221print "</tr>\n";
222
223$bankorder[0][0] = $langs->trans("BankOrderGlobal");
224$bankorder[0][1] = $langs->trans("BankOrderGlobalDesc");
225$bankorder[0][2] = 'BankCode DeskCode BankAccountNumber BankAccountNumberKey';
226$bankorder[1][0] = $langs->trans("BankOrderES");
227$bankorder[1][1] = $langs->trans("BankOrderESDesc");
228$bankorder[1][2] = 'BankCode DeskCode BankAccountNumberKey BankAccountNumber';
229
230$i = 0;
231
232$nbofbank = count($bankorder);
233while ($i < $nbofbank) {
234 print '<tr class="oddeven">';
235 print '<td>'.$bankorder[$i][0]."</td><td>\n";
236 print $bankorder[$i][1];
237 print '</td>';
238 print '<td class="nowrap">';
239 $tmparray = explode(' ', $bankorder[$i][2]);
240 foreach ($tmparray as $key => $val) {
241 if ($key > 0) {
242 print ', ';
243 }
244 print $langs->trans($val);
245 }
246 print "</td>\n";
247
248 if (getDolGlobalInt('BANK_SHOW_ORDER_OPTION') == $i) {
249 print '<td class="center">';
250 print img_picto($langs->trans("Activated"), 'on');
251 print '</td>';
252 } else {
253 print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setbankorder&token='.newToken().'&value='.((int) $i).'">';
254 print img_picto($langs->trans("Disabled"), 'off');
255 print '</a></td>';
256 }
257 print '</tr>'."\n";
258 $i++;
259}
260
261print '</table>'."\n";
262print "</div>";
263
264print '<br><br>';
265
266
267/*
268 * Document templates generators
269 */
270
271print load_fiche_titre($langs->trans("BankAccountModelModule"), '', '');
272
273// Load array def with activated templates
274$def = array();
275$sql = "SELECT nom";
276$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
277$sql .= " WHERE type = '".$db->escape($type)."'";
278$sql .= " AND entity = ".$conf->entity;
279$resql = $db->query($sql);
280if ($resql) {
281 $i = 0;
282 $num_rows = $db->num_rows($resql);
283 while ($i < $num_rows) {
284 $array = $db->fetch_array($resql);
285 array_push($def, $array[0]);
286 $i++;
287 }
288} else {
289 dol_print_error($db);
290}
291
292print '<div class="div-table-responsive-no-min">';
293print '<table class="noborder centpercent">'."\n";
294print '<tr class="liste_titre">'."\n";
295print '<td>'.$langs->trans("Name").'</td>';
296print '<td class="minwidth100">'.$langs->trans("Description").'</td>';
297print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
298print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
299print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
300print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
301print '</tr>'."\n";
302
303clearstatcache();
304
305foreach ($dirmodels as $reldir) {
306 foreach (array('', '/doc') as $valdir) {
307 $dir = dol_buildpath($reldir."core/modules/bank".$valdir);
308
309 if (is_dir($dir)) {
310 $handle = opendir($dir);
311 if (is_resource($handle)) {
312 while (($file = readdir($handle)) !== false) {
313 $filelist[] = $file;
314 }
315 closedir($handle);
316 arsort($filelist);
317
318 foreach ($filelist as $file) {
319 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
320 if (file_exists($dir.'/'.$file)) {
321 $name = substr($file, 4, dol_strlen($file) - 16);
322 $classname = substr($file, 0, dol_strlen($file) - 12);
323
324 require_once $dir.'/'.$file;
325 $module = new $classname($db);
326
327 $modulequalified = 1;
328 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
329 $modulequalified = 0;
330 }
331 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
332 $modulequalified = 0;
333 }
334
335 if ($modulequalified) {
336 print '<tr class="oddeven"><td width="100">';
337 print(empty($module->name) ? $name : $module->name);
338 print "</td><td>\n";
339 if (method_exists($module, 'info')) {
340 print $module->info($langs);
341 } else {
342 print $module->description;
343 }
344 print '</td>';
345
346 // Active
347 if (in_array($name, $def)) {
348 print '<td class="center">'."\n";
349 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.$name.'">';
350 print img_picto($langs->trans("Enabled"), 'switch_on');
351 print '</a>';
352 print '</td>';
353 } else {
354 print '<td class="center">'."\n";
355 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&token='.newToken().'&can_dir='.$module->scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
356 print "</td>";
357 }
358
359 // Default
360 print '<td class="center">';
361 if ($conf->global->BANKADDON_PDF == $name) {
362 print img_picto($langs->trans("Default"), 'on');
363 } else {
364 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.$name.'&scan_dir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
365 }
366 print '</td>';
367
368 // Info
369 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
370 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
371 if ($module->type == 'pdf') {
372 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
373 }
374 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
375 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
376 //$htmltooltip .= '<br>' . $langs->trans("PaymentMode") . ': ' . yn($module->option_modereg, 1, 1);
377 //$htmltooltip .= '<br>' . $langs->trans("PaymentConditions") . ': ' . yn($module->option_condreg, 1, 1);
378 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
379 // $htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
380 // $htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
381 //$htmltooltip .= '<br>' . $langs->trans("WatermarkOnDraftOrders") . ': ' . yn($module->option_draft_watermark, 1, 1);
382
383 print '<td class="center">';
384 print $form->textwithpicto('', $htmltooltip, 1, 0);
385 print '</td>';
386
387 // Preview
388 print '<td class="center">';
389 if ($module->type == 'pdf') {
390 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
391 } else {
392 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
393 }
394 print '</td>';
395
396 print "</tr>\n";
397 }
398 }
399 }
400 }
401 }
402 }
403 }
404}
405print '</table>';
406print '</div>';
407
408print '<br><br>';
409
410print load_fiche_titre($langs->trans("BankColorizeMovement"), '', '');
411
412print '<div class="div-table-responsive-no-min">';
413print '<table class="noborder centpercent">'."\n";
414print '<tr class="liste_titre">'."\n";
415print '<td colspan="4">'.$langs->trans("Name").'</td>';
416print '<td align="center" width="75">'.$langs->trans("Value").'</td>'."\n";
417print "</tr>\n";
418
419print '<tr class="oddeven"><td colspan="4">';
420print $langs->trans('BankColorizeMovementDesc');
421print "</td>";
422// Active
423if (getDolGlobalInt('BANK_COLORIZE_MOVEMENT')) {
424 print '<td class="center">'."\n";
425 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetbankcolorizemovement&token='.newToken().'">';
426 print img_picto($langs->trans("Enabled"), 'switch_on');
427 print '</a>';
428 print '</td>';
429} else {
430 print '<td class="center">'."\n";
431 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setbankcolorizemovement&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
432 print "</td>";
433}
434
435print "</tr>\n";
436
437if (getDolGlobalInt('BANK_COLORIZE_MOVEMENT')) {
438 $i = 1;
439 while ($i <= 2) {
440 $key = $i;
441 $color = 'BANK_COLORIZE_MOVEMENT_COLOR'.$key;
442
443 print '<tr class="oddeven">';
444
445 // Label
446 print '<td colspan="4" width="180" class="nowrap">'.$langs->trans("BankColorizeMovementName".$key)."</td>";
447 // Color
448 print '<td class="nowrap right">';
449 print $formother->selectColor((GETPOST("BANK_COLORIZE_MOVEMENT_COLOR".$key) ? GETPOST("BANK_COLORIZE_MOVEMENT_COLOR".$key) : $conf->global->$color), "BANK_COLORIZE_MOVEMENT_COLOR".$key, 'bankmovementcolorconfig', 1, '', 'right hideifnotset');
450 print '</td>';
451 print "</tr>";
452 $i++;
453 }
454}
455print '</table>';
456print '</div>';
457
458print '<br><br>';
459
460
461/*
462 * Document templates generators
463 */
464
465print load_fiche_titre($langs->trans("Other"), '', '');
466
467print '<div class="div-table-responsive-no-min">';
468print '<table class="noborder centpercent">'."\n";
469print '<tr class="liste_titre">'."\n";
470print '<td>'.$langs->trans("Name").'</td>';
471print '<td>'.$langs->trans("Description").'</td>';
472print '<td class="center width75">'.$langs->trans("Status")."</td>\n";
473print "</tr>\n";
474
475print '<tr class="oddeven"><td>';
476print $langs->trans('AccountStatement');
477print "</td><td>\n";
478print $langs->trans('AutoReportLastAccountStatement');
479print '</td>';
480// Active
481if (getDolGlobalString('BANK_REPORT_LAST_NUM_RELEVE')) {
482 print '<td class="center">'."\n";
483 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unsetreportlastnumreleve&token='.newToken().'">';
484 print img_picto($langs->trans("Enabled"), 'switch_on');
485 print '</a>';
486 print '</td>';
487} else {
488 print '<td class="center">'."\n";
489 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setreportlastnumreleve&token='.newToken().'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
490 print "</td>";
491}
492print "</tr>\n";
493
494// Allow SEPA Mandate OnLine Sign
495if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
496 print '<tr class="oddeven">';
497 print '<td>'.$langs->trans("AllowOnLineSign").'</td>';
498 print '<td>'.$langs->trans("BankAccountModelModule").'</td>';
499 print '<td class="center">';
500 print ajax_constantonoff('SOCIETE_RIB_ALLOW_ONLINESIGN', array(), null, 0, 0, 0, 2, 0, 1);
501 print '</td></tr>';
502}
503
504print '</table>';
505print '</div>';
506
507print dol_get_fiche_end();
508
509print $form->buttonsSaveCancel("Save", '');
510
511print "</form>\n";
512
513// End of page
514llxFooter();
515$db->close();
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.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
bank_admin_prepare_head($object)
Prepare array with list of tabs.
Definition bank.lib.php:132
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.
Classe permettant la generation de composants html autre Only common components are here.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.