dolibarr  9.0.0
bank.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
6  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
31 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
32 require_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 
37 if (!$user->admin)
39 
40 $action = GETPOST('action', 'alpha');
41 $value = GETPOST('value', 'alpha');
42 $label = GETPOST('label', 'alpha');
43 $scandir = GETPOST('scan_dir', 'alpha');
44 $type = 'bankaccount';
45 
46 
47 /*
48  * Actions
49  */
50 
51 //Order display of bank account
52 if ($action == 'setbankorder') {
53  if (dolibarr_set_const($db, "BANK_SHOW_ORDER_OPTION",
54  GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity) > 0) {
55  header("Location: " . $_SERVER["PHP_SELF"]);
56  exit;
57  }
58  else {
59  dol_print_error($db);
60  }
61 }
62 
63 //Auto report last num releve on conciliate
64 if ($action == 'setreportlastnumreleve') {
65  if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 1, 'chaine', 0,
66  '', $conf->entity) > 0) {
67  header("Location: " . $_SERVER["PHP_SELF"]);
68  exit;
69  }
70  else {
71  dol_print_error($db);
72  }
73 }
74 elseif ($action == 'unsetreportlastnumreleve') {
75  if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 0, 'chaine', 0,
76  '', $conf->entity) > 0) {
77  header("Location: " . $_SERVER["PHP_SELF"]);
78  exit;
79  }
80  else {
81  dol_print_error($db);
82  }
83 }
84 
85 
86 if ($action == 'specimen') {
87  $modele = GETPOST('module', 'alpha');
88 
89  if ($modele == 'sepamandate') {
90  $object = new CompanyBankAccount($db);
91  }
92  else {
93  $object = new Account($db);
94  }
95  $object->initAsSpecimen();
96 
97  // Search template files
98  $file = '';
99  $classname = '';
100  $filefound = 0;
101  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
102  foreach ($dirmodels as $reldir) {
103  $file = dol_buildpath($reldir . "core/modules/bank/doc/pdf_" . $modele . ".modules.php",
104  0);
105  if (file_exists($file)) {
106  $filefound = 1;
107  $classname = "pdf_" . $modele;
108  break;
109  }
110  }
111 
112  if ($filefound) {
113  require_once $file;
114 
115  $module = new $classname($db);
116 
117  if ($module->write_file($object, $langs) > 0) {
118  header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=bank&file=SPECIMEN.pdf");
119  return;
120  }
121  else {
122  setEventMessages($module->error, null, 'errors');
123  dol_syslog($module->error, LOG_ERR);
124  }
125  }
126  else {
127  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
128  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
129  }
130 }
131 
132 // Activate a model
133 if ($action == 'set') {
134  $ret = addDocumentModel($value, $type, $label, $scandir);
135 }
136 else if ($action == 'del') {
137  $ret = delDocumentModel($value, $type);
138  if ($ret > 0) {
139  if ($conf->global->BANKADDON_PDF == "$value")
140  dolibarr_del_const($db, 'BANKADDON_PDF', $conf->entity);
141  }
142 }
143 // Set default model
144 else if ($action == 'setdoc') {
145  if (dolibarr_set_const($db, "BANKADDON_PDF", $value, 'chaine', 0, '',
146  $conf->entity)) {
147  // The constant that was read before the new set
148  // We therefore requires a variable to have a coherent view
149  $conf->global->BANKADDON_PDF = $value;
150  }
151 
152  // On active le modele
153  $ret = delDocumentModel($value, $type);
154  if ($ret > 0) {
155  $ret = addDocumentModel($value, $type, $label, $scandir);
156  }
157 }
158 
159 
160 
161 /*
162  * view
163  */
164 
165 $form = new Form($db);
166 
167 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
168 
169 llxHeader("", $langs->trans("BankSetupModule"));
170 
171 $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
172 print load_fiche_titre($langs->trans("BankSetupModule"), $linkback,
173  'title_setup');
174 
175 $head = bank_admin_prepare_head(null);
176 dol_fiche_head($head, 'general', $langs->trans("BankSetupModule"), -1, 'account');
177 
178 //Show bank account order
179 print load_fiche_titre($langs->trans("BankOrderShow"), '', '');
180 
181 print '<table class="noborder" width="100%">';
182 print '<tr class="liste_titre">';
183 print '<td width="140">' . $langs->trans("Name") . '</td>';
184 print '<td>' . $langs->trans("Description") . '</td>';
185 print '<td>' . $langs->trans("Example") . '</td>';
186 print '<td align="center">' . $langs->trans("Status") . '</td>';
187 print '<td align="center" width="60">&nbsp;</td>';
188 print "</tr>\n";
189 
190 $bankorder[0][0] = $langs->trans("BankOrderGlobal");
191 $bankorder[0][1] = $langs->trans("BankOrderGlobalDesc");
192 $bankorder[0][2] = 'BankCode DeskCode BankAccountNumber BankAccountNumberKey';
193 $bankorder[1][0] = $langs->trans("BankOrderES");
194 $bankorder[1][1] = $langs->trans("BankOrderESDesc");
195 $bankorder[1][2] = 'BankCode DeskCode BankAccountNumberKey BankAccountNumber';
196 
197 $i = 0;
198 
199 $nbofbank = count($bankorder);
200 while ($i < $nbofbank) {
201 
202  print '<tr class="oddeven">';
203  print '<td>' . $bankorder[$i][0] . "</td><td>\n";
204  print $bankorder[$i][1];
205  print '</td>';
206  print '<td class="nowrap">';
207  $tmparray = explode(' ', $bankorder[$i][2]);
208  foreach ($tmparray as $key => $val) {
209  if ($key > 0)
210  print ', ';
211  print $langs->trans($val);
212  }
213  print "</td>\n";
214 
215  if ($conf->global->BANK_SHOW_ORDER_OPTION == $i) {
216  print '<td align="center">';
217  print img_picto($langs->trans("Activated"), 'on');
218  print '</td>';
219  }
220  else {
221  print '<td align="center"><a href="' . $_SERVER['PHP_SELF'] . '?action=setbankorder&amp;value=' . $i . '">';
222  print img_picto($langs->trans("Disabled"), 'off');
223  print '</a></td>';
224  }
225  print '<td>&nbsp;</td>';
226  print '</tr>' . "\n";
227  $i++;
228 }
229 
230 print '</table>' . "\n";
231 
232 print '<br><br>';
233 
234 
235 /*
236  * Document templates generators
237  */
238 //if (! empty($conf->global->MAIN_FEATURES_LEVEL))
239 //{
240 print load_fiche_titre($langs->trans("BankAccountModelModule"), '', '');
241 
242 // Load array def with activated templates
243 $def = array();
244 $sql = "SELECT nom";
245 $sql .= " FROM " . MAIN_DB_PREFIX . "document_model";
246 $sql .= " WHERE type = '" . $type . "'";
247 $sql .= " AND entity = " . $conf->entity;
248 $resql = $db->query($sql);
249 if ($resql) {
250  $i = 0;
251  $num_rows = $db->num_rows($resql);
252  while ($i < $num_rows) {
253  $array = $db->fetch_array($resql);
254  array_push($def, $array[0]);
255  $i ++;
256  }
257 }
258 else {
259  dol_print_error($db);
260 }
261 
262 print "<table class=\"noborder\" width=\"100%\">\n";
263 print "<tr class=\"liste_titre\">\n";
264 print '<td>' . $langs->trans("Name") . '</td>';
265 print '<td>' . $langs->trans("Description") . '</td>';
266 print '<td align="center" width="60">' . $langs->trans("Status") . "</td>\n";
267 print '<td align="center" width="60">' . $langs->trans("Default") . "</td>\n";
268 print '<td align="center" width="38">' . $langs->trans("ShortInfo") . '</td>';
269 print '<td align="center" width="38">' . $langs->trans("Preview") . '</td>';
270 print "</tr>\n";
271 
272 clearstatcache();
273 
274 foreach ($dirmodels as $reldir) {
275  foreach (array('', '/doc') as $valdir) {
276  $dir = dol_buildpath($reldir . "core/modules/bank" . $valdir);
277 
278  if (is_dir($dir)) {
279  $handle = opendir($dir);
280  if (is_resource($handle)) {
281  while (($file = readdir($handle)) !== false) {
282  $filelist[] = $file;
283  }
284  closedir($handle);
285  arsort($filelist);
286 
287  foreach ($filelist as $file) {
288  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/',
289  $file)) {
290 
291  if (file_exists($dir . '/' . $file)) {
292  $name = substr($file, 4, dol_strlen($file) - 16);
293  $classname = substr($file, 0, dol_strlen($file) - 12);
294 
295  require_once $dir . '/' . $file;
296  $module = new $classname($db);
297 
298  $modulequalified = 1;
299  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL
300  < 2)
301  $modulequalified = 0;
302  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL
303  < 1)
304  $modulequalified = 0;
305 
306  if ($modulequalified) {
307  print '<tr class="oddeven"><td width="100">';
308  print(empty($module->name) ? $name : $module->name);
309  print "</td><td>\n";
310  if (method_exists($module, 'info'))
311  print $module->info($langs);
312  else
313  print $module->description;
314  print '</td>';
315 
316  // Active
317  if (in_array($name, $def)) {
318  print '<td align="center">' . "\n";
319  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=del&value=' . $name . '">';
320  print img_picto($langs->trans("Enabled"),
321  'switch_on');
322  print '</a>';
323  print '</td>';
324  }
325  else {
326  print '<td align="center">' . "\n";
327  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=set&value=' . $name . '&amp;scan_dir=' . $module->scandir . '&amp;label=' . urlencode($module->name) . '">' . img_picto($langs->trans("Disabled"),
328  'switch_off') . '</a>';
329  print "</td>";
330  }
331 
332  // Default
333  print '<td align="center">';
334  if ($conf->global->BANKADDON_PDF == $name) {
335  print img_picto($langs->trans("Default"),
336  'on');
337  }
338  else {
339  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=setdoc&value=' . $name . '&amp;scan_dir=' . $module->scandir . '&amp;label=' . urlencode($module->name) . '" alt="' . $langs->trans("Default") . '">' . img_picto($langs->trans("Disabled"),
340  'off') . '</a>';
341  }
342  print '</td>';
343 
344  // Info
345  $htmltooltip = '' . $langs->trans("Name") . ': ' . $module->name;
346  $htmltooltip .= '<br>' . $langs->trans("Type") . ': ' . ($module->type ? $module->type : $langs->trans("Unknown"));
347  if ($module->type == 'pdf') {
348  $htmltooltip .= '<br>' . $langs->trans("Width") . '/' . $langs->trans("Height") . ': ' . $module->page_largeur . '/' . $module->page_hauteur;
349  }
350  $htmltooltip .= '<br><br><u>' . $langs->trans("FeaturesSupported") . ':</u>';
351  $htmltooltip .= '<br>' . $langs->trans("Logo") . ': ' . yn($module->option_logo,
352  1, 1);
353  //$htmltooltip .= '<br>' . $langs->trans("PaymentMode") . ': ' . yn($module->option_modereg, 1, 1);
354  //$htmltooltip .= '<br>' . $langs->trans("PaymentConditions") . ': ' . yn($module->option_condreg, 1, 1);
355  $htmltooltip .= '<br>' . $langs->trans("MultiLanguage") . ': ' . yn($module->option_multilang,
356  1, 1);
357  // $htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
358  // $htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
359  //$htmltooltip .= '<br>' . $langs->trans("WatermarkOnDraftOrders") . ': ' . yn($module->option_draft_watermark, 1, 1);
360 
361  print '<td align="center">';
362  print $form->textwithpicto('', $htmltooltip, 1,
363  0);
364  print '</td>';
365 
366  // Preview
367  print '<td align="center">';
368  if ($module->type == 'pdf') {
369  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=specimen&module=' . $name . '">' . img_object($langs->trans("Preview"),
370  'bill') . '</a>';
371  }
372  else {
373  print img_object($langs->trans("PreviewNotAvailable"),
374  'generic');
375  }
376  print '</td>';
377 
378  print "</tr>\n";
379  }
380  }
381  }
382  }
383  }
384  }
385  }
386 }
387 print '</table>';
388 //}
389 
390 
391 
392 print '<br><br>';
393 
394 
395 /*
396  * Document templates generators
397  */
398 //if (! empty($conf->global->MAIN_FEATURES_LEVEL))
399 //{
400 print load_fiche_titre($langs->trans("Other"), '', '');
401 
402 
403 print "<table class=\"noborder\" width=\"100%\">\n";
404 print "<tr class=\"liste_titre\">\n";
405 print '<td>' . $langs->trans("Name") . '</td>';
406 print '<td>' . $langs->trans("Description") . '</td>';
407 print '<td align="center" width="60">' . $langs->trans("Status") . "</td>\n";
408 print "</tr>\n";
409 
410 print '<tr class="oddeven"><td width="100">';
411 print $langs->trans('AccountStatement');
412 print "</td><td>\n";
413 print $langs->trans('AutoReportLastAccountStatement');
414 print '</td>';
415 // Active
416 if ($conf->global->BANK_REPORT_LAST_NUM_RELEVE) {
417  print '<td align="center">' . "\n";
418  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=unsetreportlastnumreleve">';
419  print img_picto($langs->trans("Enabled"), 'switch_on');
420  print '</a>';
421  print '</td>';
422 }
423 else
424 {
425  print '<td align="center">' . "\n";
426  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=setreportlastnumreleve">' . img_picto($langs->trans("Disabled"),
427  'switch_off') . '</a>';
428  print "</td>";
429 }
430 
431 print "</tr>\n";
432 print '</table>';
433 dol_fiche_end();
434 
435 // End of page
436 llxFooter();
437 $db->close();
bank_admin_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:125
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1643
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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).
Definition: admin.lib.php:510
Class to manage bank accounts description of third parties.
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1609
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to manage bank accounts.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)