dolibarr  7.0.0-beta
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@capnetworks.com>
4  * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
5  * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
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 <http://www.gnu.org/licenses/>.
19  * or see http://www.gnu.org/
20  */
21 
34 function bank_prepare_head(Account $object)
35 {
36  global $db, $langs, $conf, $user;
37  $h = 0;
38  $head = array();
39 
40  $head[$h][0] = DOL_URL_ROOT . '/compta/bank/card.php?id=' . $object->id;
41  $head[$h][1] = $langs->trans("Card");
42  $head[$h][2] = 'bankname';
43  $h++;
44 
45  $head[$h][0] = DOL_URL_ROOT . "/compta/bank/bankentries_list.php?id=" . $object->id;
46  $head[$h][1] = $langs->trans("BankTransactions");
47  $head[$h][2] = 'journal';
48  $h++;
49 
50 // if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
51 // {
52  $head[$h][0] = DOL_URL_ROOT . "/compta/bank/treso.php?account=" . $object->id;
53  $head[$h][1] = $langs->trans("PlannedTransactions");
54  $head[$h][2] = 'cash';
55  $h++;
56 // }
57 
58  $head[$h][0] = DOL_URL_ROOT . "/compta/bank/annuel.php?account=" . $object->id;
59  $head[$h][1] = $langs->trans("IOMonthlyReporting");
60  $head[$h][2] = 'annual';
61  $h++;
62 
63  $head[$h][0] = DOL_URL_ROOT . "/compta/bank/graph.php?account=" . $object->id;
64  $head[$h][1] = $langs->trans("Graph");
65  $head[$h][2] = 'graph';
66  $h++;
67 
68  if ($object->courant != Account::TYPE_CASH)
69  {
70  $nbReceipts=0;
71 
72  // List of all standing receipts
73  $sql = "SELECT COUNT(DISTINCT(b.num_releve)) as nb";
74  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
75  $sql.= " WHERE b.fk_account = ".$object->id;
76 
77  $resql = $db->query($sql);
78  if ($resql)
79  {
80  $obj = $db->fetch_object($resql);
81  if ($obj) $nbReceipts = $obj->nb;
82  $db->free($resql);
83  }
84 
85  $head[$h][0] = DOL_URL_ROOT."/compta/bank/releve.php?account=".$object->id;
86  $head[$h][1] = $langs->trans("AccountStatements");
87  if (($nbReceipts) > 0) $head[$h][1].= ' <span class="badge">'.($nbReceipts).'</span>';
88  $head[$h][2] = 'statement';
89  $h++;
90  }
91 
92  // Attached files
93  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
94  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
95  $upload_dir = $conf->bank->dir_output . "/" . dol_sanitizeFileName($object->ref);
96  $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
97  $nbLinks=Link::count($db, $object->element, $object->id);
98  $head[$h][0] = DOL_URL_ROOT . "/compta/bank/document.php?account=" . $object->id;
99  $head[$h][1] = $langs->trans("Documents");
100  if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
101  $head[$h][2] = 'document';
102  $h++;
103 
104  // Show more tabs from modules
105  // Entries must be declared in modules descriptor with line
106  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
107  // $this->tabs = array('entity:-tabname); to remove a tab
108  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank');
109 
110  /*$head[$h][0] = DOL_URL_ROOT . "/compta/bank/info.php?id=" . $object->id;
111  $head[$h][1] = $langs->trans("Info");
112  $head[$h][2] = 'info';
113  $h++;*/
114 
115  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank', 'remove');
116 
117  return $head;
118 }
125 function bank_admin_prepare_head($object)
126 {
127  global $langs, $conf, $user;
128  $h = 0;
129  $head = array();
130 
131  $head[$h][0] = DOL_URL_ROOT . '/admin/bank.php';
132  $head[$h][1] = $langs->trans("Miscellaneous");
133  $head[$h][2] = 'general';
134  $h++;
135 
136  $head[$h][0] = DOL_URL_ROOT . '/admin/chequereceipts.php';
137  $head[$h][1] = $langs->trans("CheckReceiptShort");
138  $head[$h][2] = 'checkreceipts';
139  $h++;
140 
141 
142  // Show more tabs from modules
143  // Entries must be declared in modules descriptor with line
144  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
145  // $this->tabs = array('entity:-tabname); to remove a tab
146  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank_admin');
147 
148  $head[$h][0] = DOL_URL_ROOT.'/admin/bank_extrafields.php';
149  $head[$h][1] = $langs->trans("ExtraFields");
150  $head[$h][2] = 'attributes';
151  $h++;
152 
153  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank_admin', 'remove');
154 
155  return $head;
156 }
157 
164 function various_payment_prepare_head($object) {
165 
166  global $db, $langs, $conf;
167 
168  $h = 0;
169  $head = array();
170 
171  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$object->id;
172  $head[$h][1] = $langs->trans("Card");
173  $head[$h][2] = 'card';
174  $h++;
175 
176  // Show more tabs from modules
177  // Entries must be declared in modules descriptor with line
178  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
179  // $this->tabs = array('entity:-tabname); to remove a tab
180  complete_head_from_modules($conf,$langs,$object,$head,$h,'various_payment');
181 
182  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
183  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
184  $upload_dir = $conf->banque->dir_output . "/" . dol_sanitizeFileName($object->ref);
185  $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
186  $nbLinks=Link::count($db, $object->element, $object->id);
187  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/document.php?id='.$object->id;
188  $head[$h][1] = $langs->trans('Documents');
189  if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
190  $head[$h][2] = 'documents';
191  $h++;
192 
193  $head[$h][0] = DOL_URL_ROOT.'/compta/bank/various_payment/info.php?id='.$object->id;
194  $head[$h][1] = $langs->trans("Info");
195  $head[$h][2] = 'info';
196  $h++;
197 
198  complete_head_from_modules($conf,$langs,$object,$head,$h,'various_payment', 'remove');
199 
200  return $head;
201 }
202 
209 function checkSwiftForAccount($account)
210 {
211  $swift = $account->bic;
212  if (preg_match("/^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$/", $swift)) {
213  return true;
214  } else {
215  return false;
216  }
217 
218 }
219 
226 function checkIbanForAccount($account)
227 {
228  require_once DOL_DOCUMENT_ROOT.'/includes/php-iban/oophp-iban.php';
229 
230  $iban = new IBAN($account->iban);
231  $check = $iban->Verify();
232 
233  if ($check) return true;
234  else return false;
235 }
236 
243 function checkBanForAccount($account)
244 {
245  $country_code = $account->getCountryCode();
246 
247  // For compatibility between
248  // account of type CompanyBankAccount class (we use number, cle_rib)
249  // account of type Account class (we use num_compte, cle)
250  if (empty($account->number))
251  $account->number = $account->num_compte;
252  if (empty($account->cle))
253  $account->cle = $account->cle_rib;
254 
255  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);
256 
257  if ($country_code == 'FR') { // France rules
258  $coef = array(62, 34, 3);
259  // Concatenation des differents codes.
260  $rib = strtolower(trim($account->code_banque) . trim($account->code_guichet) . trim($account->number) . trim($account->cle));
261  // On remplace les eventuelles lettres par des chiffres.
262  //$rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz","12345678912345678912345678"); //Ne marche pas
263  $rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz", "12345678912345678923456789");
264  // Separation du rib en 3 groupes de 7 + 1 groupe de 2.
265  // Multiplication de chaque groupe par les coef du tableau
266 
267  for ($i = 0, $s = 0; $i < 3; $i++) {
268  $code = substr($rib, 7 * $i, 7);
269  $s += (0 + (int) $code) * $coef[$i];
270  }
271  // Soustraction du modulo 97 de $s a 97 pour obtenir la cle
272  $cle_rib = 97 - ($s % 97);
273  if ($cle_rib == $account->cle) {
274  return true;
275  }
276  return false;
277  }
278 
279  if ($country_code == 'BE') { // Belgium rules
280 
281  }
282 
283  if ($country_code == 'ES') { // Spanish rules
284  $CCC = strtolower(trim($account->number));
285  $rib = strtolower(trim($account->code_banque) . trim($account->code_guichet));
286  $cle_rib = strtolower(checkES($rib, $CCC));
287  if ($cle_rib == strtolower($account->cle)) {
288  return true;
289  }
290  return false;
291  }
292  if ($country_code == 'AU') { // Australian
293  if (strlen($account->code_banque) > 7)
294  return false; // Sould be 6 but can be 123-456
295  else if (strlen($account->code_banque) < 6)
296  return false; // Sould be 6
297  else
298  return true;
299  }
300 
301  // No particular rule
302  // If account is CompanyBankAccount class, we use number
303  // If account is Account class, we use num_compte
304  if (empty($account->number)) {
305  return false;
306  }
307 
308  return true;
309 }
310 
311 
312 
320 function checkES($IentOfi, $InumCta)
321 {
322  if (empty($IentOfi) || empty($InumCta) || strlen($IentOfi) != 8 || strlen($InumCta) != 10) {
323  $keycontrol = "";
324  return $keycontrol;
325  }
326 
327  $ccc = $IentOfi . $InumCta;
328  $numbers = "1234567890";
329 
330  $i = 0;
331 
332  while ($i <= strlen($ccc) - 1) {
333  if (strpos($numbers, substr($ccc, $i, 1)) === false) {
334  $keycontrol = "";
335  return $keycontrol;
336  }
337  $i++;
338  }
339 
340  $values = array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
341  $sum = 0;
342 
343  for ($i = 2; $i < 10; $i++) {
344  $sum += $values[$i] * substr($IentOfi, $i - 2, 1);
345  }
346 
347  $key = 11 - $sum % 11;
348 
349  if ($key == 10)
350  $key = 1;
351  if ($key == 11)
352  $key = 0;
353 
354  $keycontrol = $key;
355 
356  $sum = 0;
357 
358  for ($i = 0; $i < 11; $i++) {
359  $sum += $values[$i] * substr($InumCta, $i, 1);
360  }
361 
362  $key = 11 - $sum % 11;
363 
364  if ($key == 10)
365  $key = 1;
366  if ($key == 11)
367  $key = 0;
368 
369  $keycontrol .= $key;
370  return $keycontrol;
371 }
372 
checkES($IentOfi, $InumCta)
Returns the key for Spanish Banks Accounts.
Definition: bank.lib.php:320
bank_admin_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:125
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition: bank.lib.php:34
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
various_payment_prepare_head($object)
Prepare array with list of tabs.
Definition: bank.lib.php:164
checkSwiftForAccount($account)
Check SWIFT informations for a bank account.
Definition: bank.lib.php:209
Class to manage bank accounts.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="")
Scan a directory and return a list of files/directories.
Definition: files.lib.php:58
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
const TYPE_CASH
Cash account.
checkBanForAccount($account)
Check account number informations for a bank account.
Definition: bank.lib.php:243
checkIbanForAccount($account)
Check IBAN number informations for a bank account.
Definition: bank.lib.php:226
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