dolibarr  7.0.0-beta
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-2014 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 $langs->load("admin");
35 $langs->load("companies");
36 $langs->load("bills");
37 $langs->load("other");
38 $langs->load("banks");
39 
40 if (!$user->admin)
42 
43 $action = GETPOST('action', '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
55 if ($action == 'setbankorder') {
56  if (dolibarr_set_const($db, "BANK_SHOW_ORDER_OPTION",
57  GETPOST('value', 'alpha'), 'chaine', 0, '', $conf->entity) > 0) {
58  header("Location: " . $_SERVER["PHP_SELF"]);
59  exit;
60  }
61  else {
62  dol_print_error($db);
63  }
64 }
65 
66 //Auto report last num releve on conciliate
67 if ($action == 'setreportlastnumreleve') {
68  if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 1, 'chaine', 0,
69  '', $conf->entity) > 0) {
70  header("Location: " . $_SERVER["PHP_SELF"]);
71  exit;
72  }
73  else {
74  dol_print_error($db);
75  }
76 }
77 elseif ($action == 'unsetreportlastnumreleve') {
78  if (dolibarr_set_const($db, "BANK_REPORT_LAST_NUM_RELEVE", 0, 'chaine', 0,
79  '', $conf->entity) > 0) {
80  header("Location: " . $_SERVER["PHP_SELF"]);
81  exit;
82  }
83  else {
84  dol_print_error($db);
85  }
86 }
87 
88 
89 if ($action == 'specimen') {
90  $modele = GETPOST('module', 'alpha');
91 
92  if ($modele == 'sepamandate') {
93  $object = new CompanyBankAccount($db);
94  }
95  else {
96  $object = new Account($db);
97  }
98  $object->initAsSpecimen();
99 
100  // Search template files
101  $file = '';
102  $classname = '';
103  $filefound = 0;
104  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
105  foreach ($dirmodels as $reldir) {
106  $file = dol_buildpath($reldir . "core/modules/bank/doc/pdf_" . $modele . ".modules.php",
107  0);
108  if (file_exists($file)) {
109  $filefound = 1;
110  $classname = "pdf_" . $modele;
111  break;
112  }
113  }
114 
115  if ($filefound) {
116  require_once $file;
117 
118  $module = new $classname($db);
119 
120  if ($module->write_file($object, $langs) > 0) {
121  header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=bank&file=SPECIMEN.pdf");
122  return;
123  }
124  else {
125  setEventMessages($module->error, null, 'errors');
126  dol_syslog($module->error, LOG_ERR);
127  }
128  }
129  else {
130  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
131  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
132  }
133 }
134 
135 // Activate a model
136 if ($action == 'set') {
137  $ret = addDocumentModel($value, $type, $label, $scandir);
138 }
139 else if ($action == 'del') {
140  $ret = delDocumentModel($value, $type);
141  if ($ret > 0) {
142  if ($conf->global->BANKADDON_PDF == "$value")
143  dolibarr_del_const($db, 'BANKADDON_PDF', $conf->entity);
144  }
145 }
146 // Set default model
147 else if ($action == 'setdoc') {
148  if (dolibarr_set_const($db, "BANKADDON_PDF", $value, 'chaine', 0, '',
149  $conf->entity)) {
150  // The constant that was read before the new set
151  // We therefore requires a variable to have a coherent view
152  $conf->global->BANKADDON_PDF = $value;
153  }
154 
155  // On active le modele
156  $ret = delDocumentModel($value, $type);
157  if ($ret > 0) {
158  $ret = addDocumentModel($value, $type, $label, $scandir);
159  }
160 }
161 
162 
163 
164 /*
165  * view
166  */
167 
168 $form = new Form($db);
169 
170 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
171 
172 llxHeader("", $langs->trans("BankSetupModule"));
173 
174 $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
175 print load_fiche_titre($langs->trans("BankSetupModule"), $linkback,
176  'title_setup');
177 
178 $head = bank_admin_prepare_head(null);
179 dol_fiche_head($head, 'general', $langs->trans("BankSetupModule"), -1, 'account');
180 
181 $var = true;
182 
183 $var = !$var;
184 
185 //Show bank account order
186 print load_fiche_titre($langs->trans("BankOrderShow"), '', '');
187 
188 print '<table class="noborder" width="100%">';
189 print '<tr class="liste_titre">';
190 print '<td width="140">' . $langs->trans("Name") . '</td>';
191 print '<td>' . $langs->trans("Description") . '</td>';
192 print '<td>' . $langs->trans("Example") . '</td>';
193 print '<td align="center">' . $langs->trans("Status") . '</td>';
194 print '<td align="center" width="60">&nbsp;</td>';
195 print "</tr>\n";
196 
197 $bankorder[0][0] = $langs->trans("BankOrderGlobal");
198 $bankorder[0][1] = $langs->trans("BankOrderGlobalDesc");
199 $bankorder[0][2] = 'BankCode DeskCode BankAccountNumber BankAccountNumberKey';
200 $bankorder[1][0] = $langs->trans("BankOrderES");
201 $bankorder[1][1] = $langs->trans("BankOrderESDesc");
202 $bankorder[1][2] = 'BankCode DeskCode BankAccountNumberKey BankAccountNumber';
203 
204 $var = true;
205 $i = 0;
206 
207 $nbofbank = count($bankorder);
208 while ($i < $nbofbank) {
209  $var = !$var;
210 
211  print '<tr class="oddeven">';
212  print '<td>' . $bankorder[$i][0] . "</td><td>\n";
213  print $bankorder[$i][1];
214  print '</td>';
215  print '<td class="nowrap">';
216  $tmparray = explode(' ', $bankorder[$i][2]);
217  foreach ($tmparray as $key => $val) {
218  if ($key > 0)
219  print ', ';
220  print $langs->trans($val);
221  }
222  print "</td>\n";
223 
224  if ($conf->global->BANK_SHOW_ORDER_OPTION == $i) {
225  print '<td align="center">';
226  print img_picto($langs->trans("Activated"), 'on');
227  print '</td>';
228  }
229  else {
230  print '<td align="center"><a href="' . $_SERVER['PHP_SELF'] . '?action=setbankorder&amp;value=' . $i . '">';
231  print img_picto($langs->trans("Disabled"), 'off');
232  print '</a></td>';
233  }
234  print '<td>&nbsp;</td>';
235  print '</tr>' . "\n";
236  $i++;
237 }
238 
239 print '</table>' . "\n";
240 
241 
242 print '<br><br>';
243 
244 
245 /*
246  * Document templates generators
247  */
248 //if (! empty($conf->global->MAIN_FEATURES_LEVEL))
249 //{
250 print load_fiche_titre($langs->trans("BankAccountModelModule"), '', '');
251 
252 // Load array def with activated templates
253 $def = array();
254 $sql = "SELECT nom";
255 $sql .= " FROM " . MAIN_DB_PREFIX . "document_model";
256 $sql .= " WHERE type = '" . $type . "'";
257 $sql .= " AND entity = " . $conf->entity;
258 $resql = $db->query($sql);
259 if ($resql) {
260  $i = 0;
261  $num_rows = $db->num_rows($resql);
262  while ($i < $num_rows) {
263  $array = $db->fetch_array($resql);
264  array_push($def, $array[0]);
265  $i ++;
266  }
267 }
268 else {
269  dol_print_error($db);
270 }
271 
272 print "<table class=\"noborder\" width=\"100%\">\n";
273 print "<tr class=\"liste_titre\">\n";
274 print '<td>' . $langs->trans("Name") . '</td>';
275 print '<td>' . $langs->trans("Description") . '</td>';
276 print '<td align="center" width="60">' . $langs->trans("Status") . "</td>\n";
277 print '<td align="center" width="60">' . $langs->trans("Default") . "</td>\n";
278 print '<td align="center" width="38">' . $langs->trans("ShortInfo") . '</td>';
279 print '<td align="center" width="38">' . $langs->trans("Preview") . '</td>';
280 print "</tr>\n";
281 
282 clearstatcache();
283 
284 foreach ($dirmodels as $reldir) {
285  foreach (array('', '/doc') as $valdir) {
286  $dir = dol_buildpath($reldir . "core/modules/bank" . $valdir);
287 
288  if (is_dir($dir)) {
289  $handle = opendir($dir);
290  if (is_resource($handle)) {
291  while (($file = readdir($handle)) !== false) {
292  $filelist[] = $file;
293  }
294  closedir($handle);
295  arsort($filelist);
296 
297  foreach ($filelist as $file) {
298  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/',
299  $file)) {
300 
301  if (file_exists($dir . '/' . $file)) {
302  $name = substr($file, 4, dol_strlen($file) - 16);
303  $classname = substr($file, 0, dol_strlen($file) - 12);
304 
305  require_once $dir . '/' . $file;
306  $module = new $classname($db);
307 
308  $modulequalified = 1;
309  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL
310  < 2)
311  $modulequalified = 0;
312  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL
313  < 1)
314  $modulequalified = 0;
315 
316  if ($modulequalified) {
317  print '<tr class="oddeven"><td width="100">';
318  print(empty($module->name) ? $name : $module->name);
319  print "</td><td>\n";
320  if (method_exists($module, 'info'))
321  print $module->info($langs);
322  else
323  print $module->description;
324  print '</td>';
325 
326  // Active
327  if (in_array($name, $def)) {
328  print '<td align="center">' . "\n";
329  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=del&value=' . $name . '">';
330  print img_picto($langs->trans("Enabled"),
331  'switch_on');
332  print '</a>';
333  print '</td>';
334  }
335  else {
336  print '<td align="center">' . "\n";
337  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"),
338  'switch_off') . '</a>';
339  print "</td>";
340  }
341 
342  // Default
343  print '<td align="center">';
344  if ($conf->global->BANKADDON_PDF == $name) {
345  print img_picto($langs->trans("Default"),
346  'on');
347  }
348  else {
349  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"),
350  'off') . '</a>';
351  }
352  print '</td>';
353 
354  // Info
355  $htmltooltip = '' . $langs->trans("Name") . ': ' . $module->name;
356  $htmltooltip .= '<br>' . $langs->trans("Type") . ': ' . ($module->type ? $module->type : $langs->trans("Unknown"));
357  if ($module->type == 'pdf') {
358  $htmltooltip .= '<br>' . $langs->trans("Width") . '/' . $langs->trans("Height") . ': ' . $module->page_largeur . '/' . $module->page_hauteur;
359  }
360  $htmltooltip .= '<br><br><u>' . $langs->trans("FeaturesSupported") . ':</u>';
361  $htmltooltip .= '<br>' . $langs->trans("Logo") . ': ' . yn($module->option_logo,
362  1, 1);
363  //$htmltooltip .= '<br>' . $langs->trans("PaymentMode") . ': ' . yn($module->option_modereg, 1, 1);
364  //$htmltooltip .= '<br>' . $langs->trans("PaymentConditions") . ': ' . yn($module->option_condreg, 1, 1);
365  $htmltooltip .= '<br>' . $langs->trans("MultiLanguage") . ': ' . yn($module->option_multilang,
366  1, 1);
367  // $htmltooltip.='<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
368  // $htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
369  //$htmltooltip .= '<br>' . $langs->trans("WatermarkOnDraftOrders") . ': ' . yn($module->option_draft_watermark, 1, 1);
370 
371  print '<td align="center">';
372  print $form->textwithpicto('', $htmltooltip, 1,
373  0);
374  print '</td>';
375 
376  // Preview
377  print '<td align="center">';
378  if ($module->type == 'pdf') {
379  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=specimen&module=' . $name . '">' . img_object($langs->trans("Preview"),
380  'bill') . '</a>';
381  }
382  else {
383  print img_object($langs->trans("PreviewNotAvailable"),
384  'generic');
385  }
386  print '</td>';
387 
388  print "</tr>\n";
389  }
390  }
391  }
392  }
393  }
394  }
395  }
396 }
397 print '</table>';
398 //}
399 
400 
401 
402 print '<br><br>';
403 
404 
405 /*
406  * Document templates generators
407  */
408 //if (! empty($conf->global->MAIN_FEATURES_LEVEL))
409 //{
410 print load_fiche_titre($langs->trans("BankAccountReleveModule"), '', '');
411 
412 
413 print "<table class=\"noborder\" width=\"100%\">\n";
414 print "<tr class=\"liste_titre\">\n";
415 print '<td>' . $langs->trans("Name") . '</td>';
416 print '<td>' . $langs->trans("Description") . '</td>';
417 print '<td align="center" width="60">' . $langs->trans("Status") . "</td>\n";
418 print "</tr>\n";
419 
420 print '<tr class="oddeven"><td width="100">';
421 print $langs->trans('AccountStatement');
422 print "</td><td>\n";
423 print $langs->trans('AutoReportLastAccountStatement');
424 print '</td>';
425 // Active
426 if ($conf->global->BANK_REPORT_LAST_NUM_RELEVE) {
427  print '<td align="center">' . "\n";
428  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=unsetreportlastnumreleve">';
429  print img_picto($langs->trans("Enabled"), 'switch_on');
430  print '</a>';
431  print '</td>';
432 }
433 else {
434  print '<td align="center">' . "\n";
435  print '<a href="' . $_SERVER["PHP_SELF"] . '?action=setreportlastnumreleve">' . img_picto($langs->trans("Disabled"),
436  'switch_off') . '</a>';
437  print "</td>";
438 }
439 
440 print "</tr>\n";
441 print '</table>';
442 dol_fiche_end();
443 
444 llxFooter();
445 
446 $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:1540
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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:485
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:1506
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to manage bank accounts.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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'une constante dans la base de donnees.
Definition: admin.lib.php:410
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print
Draft customers invoices.
Definition: index.php:91
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:1013
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.