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