dolibarr  13.0.2
bank.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
5  * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
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 <https://www.gnu.org/licenses/>.
20  * or see https://www.gnu.org/
21  */
22 
35 function bank_prepare_head(Account $object)
36 {
37  global $db, $langs, $conf, $user;
38  $h = 0;
39  $head = array();
40 
41  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/card.php?id='.$object->id;
42  $head[$h][1] = $langs->trans("BankAccount");
43  $head[$h][2] = 'bankname';
44  $h++;
45 
46  $head[$h][0] = DOL_URL_ROOT."/compta/bank/bankentries_list.php?id=".$object->id;
47  $head[$h][1] = $langs->trans("BankTransactions");
48  $head[$h][2] = 'journal';
49  $h++;
50 
51  // if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
52  // {
53  $head[$h][0] = DOL_URL_ROOT."/compta/bank/treso.php?account=".$object->id;
54  $head[$h][1] = $langs->trans("PlannedTransactions");
55  $head[$h][2] = 'cash';
56  $h++;
57  // }
58 
59  $head[$h][0] = DOL_URL_ROOT."/compta/bank/annuel.php?account=".$object->id;
60  $head[$h][1] = $langs->trans("IOMonthlyReporting");
61  $head[$h][2] = 'annual';
62  $h++;
63 
64  $head[$h][0] = DOL_URL_ROOT."/compta/bank/graph.php?account=".$object->id;
65  $head[$h][1] = $langs->trans("Graph");
66  $head[$h][2] = 'graph';
67  $h++;
68 
69  if ($object->courant != Account::TYPE_CASH)
70  {
71  $nbReceipts = 0;
72 
73  // List of all standing receipts
74  $sql = "SELECT COUNT(DISTINCT(b.num_releve)) as nb";
75  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
76  $sql .= " WHERE b.fk_account = ".$object->id;
77 
78  $resql = $db->query($sql);
79  if ($resql)
80  {
81  $obj = $db->fetch_object($resql);
82  if ($obj) $nbReceipts = $obj->nb;
83  $db->free($resql);
84  }
85 
86  $head[$h][0] = DOL_URL_ROOT."/compta/bank/releve.php?account=".$object->id;
87  $head[$h][1] = $langs->trans("AccountStatements");
88  if (($nbReceipts) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbReceipts).'</span>';
89  $head[$h][2] = 'statement';
90  $h++;
91  }
92 
93  // Attached files
94  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
95  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
96  $upload_dir = $conf->bank->dir_output."/".dol_sanitizeFileName($object->ref);
97  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
98  $nbLinks = Link::count($db, $object->element, $object->id);
99  $head[$h][0] = DOL_URL_ROOT."/compta/bank/document.php?account=".$object->id;
100  $head[$h][1] = $langs->trans("Documents");
101  if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
102  $head[$h][2] = 'document';
103  $h++;
104 
105  // Show more tabs from modules
106  // Entries must be declared in modules descriptor with line
107  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
108  // $this->tabs = array('entity:-tabname); to remove a tab
109  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank');
110 
111  /*$head[$h][0] = DOL_URL_ROOT . "/compta/bank/info.php?id=" . $object->id;
112  $head[$h][1] = $langs->trans("Info");
113  $head[$h][2] = 'info';
114  $h++;*/
115 
116  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank', 'remove');
117 
118  return $head;
119 }
126 function bank_admin_prepare_head($object)
127 {
128  global $langs, $conf, $user;
129  $h = 0;
130  $head = array();
131 
132  $head[$h][0] = DOL_URL_ROOT.'/admin/bank.php';
133  $head[$h][1] = $langs->trans("Miscellaneous");
134  $head[$h][2] = 'general';
135  $h++;
136 
137  $head[$h][0] = DOL_URL_ROOT.'/admin/chequereceipts.php';
138  $head[$h][1] = $langs->trans("CheckReceiptShort");
139  $head[$h][2] = 'checkreceipts';
140  $h++;
141 
142 
143  // Show more tabs from modules
144  // Entries must be declared in modules descriptor with line
145  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
146  // $this->tabs = array('entity:-tabname); to remove a tab
147  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank_admin');
148 
149  $head[$h][0] = DOL_URL_ROOT.'/admin/bank_extrafields.php';
150  $head[$h][1] = $langs->trans("ExtraFields");
151  $head[$h][2] = 'attributes';
152  $h++;
153 
154  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank_admin', 'remove');
155 
156 
157  return $head;
158 }
159 
160 
168 function account_statement_prepare_head($object, $num)
169 {
170  global $langs, $conf, $user, $db;
171  $h = 0;
172  $head = array();
173 
174  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/releve.php?account='.$object->id.'&num='.$num;
175  $head[$h][1] = $langs->trans("AccountStatement");
176  $head[$h][2] = 'statement';
177  $h++;
178 
179  // Attached files
180  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
181  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
182  $upload_dir = $conf->bank->dir_output."/".$object->id.'/statement/'.dol_sanitizeFileName($num);
183  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
184  $nbLinks = Link::count($db, $object->element, $object->id);
185 
186  $head[$h][0] = DOL_URL_ROOT."/compta/bank/account_statement_document.php?account=".$object->id."&num=".$num;
187  $head[$h][1] = $langs->trans("Documents");
188  if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
189  $head[$h][2] = 'document';
190  $h++;
191 
192  complete_head_from_modules($conf, $langs, $object, $head, $h, 'account_statement');
193 
194  complete_head_from_modules($conf, $langs, $object, $head, $h, 'account_statement', 'remove');
195 
196  return $head;
197 }
198 
199 
207 {
208  global $db, $langs, $conf;
209 
210  $h = 0;
211  $head = array();
212 
213  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$object->id;
214  $head[$h][1] = $langs->trans("VariousPayment");
215  $head[$h][2] = 'card';
216  $h++;
217 
218  // Show more tabs from modules
219  // Entries must be declared in modules descriptor with line
220  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
221  // $this->tabs = array('entity:-tabname); to remove a tab
222  complete_head_from_modules($conf, $langs, $object, $head, $h, 'various_payment');
223 
224  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
225  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
226  $upload_dir = $conf->bank->dir_output."/".dol_sanitizeFileName($object->ref);
227  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
228  $nbLinks = Link::count($db, $object->element, $object->id);
229  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/document.php?id='.$object->id;
230  $head[$h][1] = $langs->trans('Documents');
231  if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
232  $head[$h][2] = 'documents';
233  $h++;
234 
235  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/info.php?id='.$object->id;
236  $head[$h][1] = $langs->trans("Info");
237  $head[$h][2] = 'info';
238  $h++;
239 
240  complete_head_from_modules($conf, $langs, $object, $head, $h, 'various_payment', 'remove');
241 
242  return $head;
243 }
244 
251 function checkSwiftForAccount($account)
252 {
253  $swift = $account->bic;
254  if (preg_match("/^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$/", $swift)) {
255  return true;
256  } else {
257  return false;
258  }
259 }
260 
267 function checkIbanForAccount($account)
268 {
269  require_once DOL_DOCUMENT_ROOT.'/includes/php-iban/oophp-iban.php';
270 
271  $iban = new IBAN($account->iban);
272  $check = $iban->Verify();
273 
274  if ($check) return true;
275  else return false;
276 }
277 
284 function checkBanForAccount($account)
285 {
286  $country_code = $account->getCountryCode();
287 
288  // For compatibility between
289  // account of type CompanyBankAccount class (we use number, cle_rib)
290  // account of type Account class (we use num_compte, cle)
291  if (empty($account->number))
292  $account->number = $account->num_compte;
293  if (empty($account->cle))
294  $account->cle = $account->cle_rib;
295 
296  dol_syslog("bank.lib::checkBanForAccount account->code_banque=".$account->code_banque." account->code_guichet=".$account->code_guichet." account->number=".$account->number." account->cle=".$account->cle." account->iban=".$account->iban." country_code=".$country_code, LOG_DEBUG);
297 
298  if ($country_code == 'FR') { // France rules
299  $coef = array(62, 34, 3);
300  // Concatenation des differents codes.
301  $rib = strtolower(trim($account->code_banque).trim($account->code_guichet).trim($account->number).trim($account->cle));
302  // On remplace les eventuelles lettres par des chiffres.
303  //$rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz","12345678912345678912345678"); //Ne marche pas
304  $rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz", "12345678912345678923456789");
305  // Separation du rib en 3 groupes de 7 + 1 groupe de 2.
306  // Multiplication de chaque groupe par les coef du tableau
307 
308  for ($i = 0, $s = 0; $i < 3; $i++) {
309  $code = substr($rib, 7 * $i, 7);
310  $s += (0 + (int) $code) * $coef[$i];
311  }
312  // Soustraction du modulo 97 de $s a 97 pour obtenir la cle
313  $cle_rib = 97 - ($s % 97);
314  if ($cle_rib == $account->cle) {
315  return true;
316  }
317  return false;
318  }
319 
320  if ($country_code == 'BE') { // Belgium rules
321  }
322 
323  if ($country_code == 'ES') { // Spanish rules
324  $CCC = strtolower(trim($account->number));
325  $rib = strtolower(trim($account->code_banque).trim($account->code_guichet));
326  $cle_rib = strtolower(checkES($rib, $CCC));
327  if ($cle_rib == strtolower($account->cle)) {
328  return true;
329  }
330  return false;
331  }
332  if ($country_code == 'AU') { // Australian
333  if (strlen($account->code_banque) > 7)
334  return false; // Sould be 6 but can be 123-456
335  elseif (strlen($account->code_banque) < 6)
336  return false; // Sould be 6
337  else return true;
338  }
339 
340  // No particular rule
341  // If account is CompanyBankAccount class, we use number
342  // If account is Account class, we use num_compte
343  if (empty($account->number)) {
344  return false;
345  }
346 
347  return true;
348 }
349 
350 
351 
359 function checkES($IentOfi, $InumCta)
360 {
361  if (empty($IentOfi) || empty($InumCta) || strlen($IentOfi) != 8 || strlen($InumCta) != 10) {
362  $keycontrol = "";
363  return $keycontrol;
364  }
365 
366  $ccc = $IentOfi.$InumCta;
367  $numbers = "1234567890";
368 
369  $i = 0;
370 
371  while ($i <= strlen($ccc) - 1) {
372  if (strpos($numbers, substr($ccc, $i, 1)) === false) {
373  $keycontrol = "";
374  return $keycontrol;
375  }
376  $i++;
377  }
378 
379  $values = array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
380  $sum = 0;
381 
382  for ($i = 2; $i < 10; $i++) {
383  $sum += $values[$i] * substr($IentOfi, $i - 2, 1);
384  }
385 
386  $key = 11 - $sum % 11;
387 
388  if ($key == 10)
389  $key = 1;
390  if ($key == 11)
391  $key = 0;
392 
393  $keycontrol = $key;
394 
395  $sum = 0;
396 
397  for ($i = 0; $i < 11; $i++) {
398  $sum += $values[$i] * (int) substr($InumCta, $i, 1); //int to cast result of substr to a number
399  }
400 
401  $key = 11 - $sum % 11;
402 
403  if ($key == 10)
404  $key = 1;
405  if ($key == 11)
406  $key = 0;
407 
408  $keycontrol .= $key;
409  return $keycontrol;
410 }
checkES($IentOfi, $InumCta)
Returns the key for Spanish Banks Accounts.
Definition: bank.lib.php:359
bank_admin_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:126
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:35
account_statement_prepare_head($object, $num)
Prepare array with list of tabs.
Definition: bank.lib.php:168
various_payment_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:206
checkSwiftForAccount($account)
Check SWIFT informations for a bank account.
Definition: bank.lib.php:251
Class to manage bank accounts.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
const TYPE_CASH
Cash account.
checkBanForAccount($account)
Check account number informations for a bank account.
Definition: bank.lib.php:284
checkIbanForAccount($account)
Check IBAN number informations for a bank account.
Definition: bank.lib.php:267
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).