42 global $db, $langs,
$conf, $user;
47 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/card.php', [
'id' =>
$object->id]);
48 $head[$h][1] = $langs->trans(
"BankAccount");
49 $head[$h][2] =
'bankname';
52 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/bankentries_list.php', [
'id' =>
$object->id]);
53 $head[$h][1] = $langs->trans(
"BankTransactions");
54 $head[$h][2] =
'journal';
57 if (
$object->canBeConciliated() > 0) {
58 $allowautomaticconciliation =
getDolGlobalBool(
'MAIN_ALLOW_AUTOMATIC_CONCILIATION');
59 $titletoconciliatemanual = $langs->trans(
"Conciliate");
60 $titletoconciliateauto = $langs->trans(
"Conciliate");
61 if ($allowautomaticconciliation) {
62 $titletoconciliatemanual .=
' ('.$langs->trans(
"Manual").
')';
63 $titletoconciliateauto .=
' ('.$langs->trans(
"Auto").
')';
69 if ($user->hasRight(
'banque',
'consolidate')) {
72 'action' =>
'reconcile',
73 'sortfield' =>
'b.datev,b.dateo,b.rowid',
74 'sortorder' =>
'asc,asc,asc',
75 'search_conciliated' => 0,
76 'search_account' =>
$object->id,
78 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/bankentries_list.php', $query).$param;
79 $head[$h][1] = $titletoconciliatemanual;
80 $head[$h][2] =
'reconcile';
86 if ($allowautomaticconciliation) {
88 if ($user->hasRight(
'banque',
'consolidate')) {
90 $newparam = preg_replace(
'/search_conciliated=\d+/i',
'', $newparam);
92 $head[$h][0] = DOL_URL_ROOT.
"/compta/bank/bankentries_list.php?id=".
$object->id.
'&action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0&search_account='.
$object->id.$newparam;
93 $head[$h][1] = $titletoconciliateauto;
94 $head[$h][2] =
'reconcileauto';
108 $sql =
"SELECT COUNT(DISTINCT(b.num_releve)) as nb";
109 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
110 $sql .=
" WHERE b.fk_account = ".((int)
$object->id);
112 $resql = $db->query($sql);
114 $obj = $db->fetch_object($resql);
116 $nbReceipts = $obj->nb;
121 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/releve.php', [
'account' =>
$object->id]);
122 $head[$h][1] = $langs->trans(
"AccountStatements");
123 if (($nbReceipts) > 0) {
124 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.($nbReceipts).
'</span>';
126 $head[$h][2] =
'statement';
131 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
132 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
134 $nbFiles = count(
dol_dir_list($upload_dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$'));
136 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/document.php', [
'account' =>
$object->id]);
137 $head[$h][1] = $langs->trans(
"Documents");
138 if (($nbFiles + $nbLinks) > 0) {
139 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).
'</span>';
141 $head[$h][2] =
'document';
144 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/annuel.php', [
'account' =>
$object->id]);
145 $head[$h][1] = $langs->trans(
"Reports");
146 $head[$h][2] =
'annual';
149 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/treso.php', [
'account' =>
$object->id]);
150 $head[$h][1] = $langs->trans(
"PlannedTransactions");
151 $head[$h][2] =
'cash';
178 global $db, $langs,
$conf, $user;
183 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/annuel.php', [
'account' =>
$object->id]);
184 $head[$h][1] = $langs->trans(
"IOMonthlyReporting");
185 $head[$h][2] =
'annual';
188 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/graph.php', [
'account' =>
$object->id]);
189 $head[$h][1] = $langs->trans(
"Graph");
190 $head[$h][2] =
'graph';
203 global $langs,
$conf, $extrafields;
205 $langs->loadLangs(array(
"compta"));
207 $extrafields->fetch_name_optionals_label(
'bank_account');
208 $extrafields->fetch_name_optionals_label(
'bank');
209 $extrafields->fetch_name_optionals_label(
'paiement');
210 $extrafields->fetch_name_optionals_label(
'payment_various');
215 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/admin/bank.php');
216 $head[$h][1] = $langs->trans(
"Miscellaneous");
217 $head[$h][2] =
'general';
220 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/admin/chequereceipts.php');
221 $head[$h][1] = $langs->trans(
"CheckReceiptShort");
222 $head[$h][2] =
'checkreceipts';
232 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/admin/extrafields.php', array(
'elementtype' =>
'bank_account'));
233 $head[$h][1] = $langs->trans(
"ExtraFields").
' ('.$langs->trans(
"BankAccounts").
')';
234 $nbExtrafields = $extrafields->attributes[
'bank_account'][
'count'];
235 if ($nbExtrafields > 0) {
236 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.$nbExtrafields.
'</span>';
238 $head[$h][2] =
'attributes';
241 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/admin/extrafields.php', array(
'elementtype' =>
'bank'));
242 $head[$h][1] = $langs->trans(
"ExtraFields").
' ('.$langs->trans(
"BankTransactions").
')';
243 $nbExtrafields = $extrafields->attributes[
'bank'][
'count'];
244 if ($nbExtrafields > 0) {
245 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.$nbExtrafields.
'</span>';
247 $head[$h][2] =
'bankline_extrafields';
250 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/admin/extrafields.php', array(
'elementtype' =>
'paiement'));
251 $head[$h][1] = $langs->trans(
"ExtraFields").
' ('.$langs->trans(
"Payments").
')';
252 $nbExtrafields = $extrafields->attributes[
'paiement'][
'count'];
253 if ($nbExtrafields > 0) {
254 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.$nbExtrafields.
'</span>';
256 $head[$h][2] =
'bank_payments_extrafields';
259 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/admin/extrafields.php', array(
'elementtype' =>
'payment_various'));
260 $head[$h][1] = $langs->trans(
"ExtraFields").
' ('.$langs->trans(
"VariousPayments").
')';
261 $nbExtrafields = $extrafields->attributes[
'payment_various'][
'count'];
262 if ($nbExtrafields > 0) {
263 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.$nbExtrafields.
'</span>';
265 $head[$h][2] =
'bank_various_payment_extrafields';
283 global $langs,
$conf, $db;
287 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/releve.php', [
'account' =>
$object->id,
'num' => $num]);
288 $head[$h][1] = $langs->trans(
"AccountStatement");
289 $head[$h][2] =
'statement';
293 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
294 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
296 $nbFiles = count(
dol_dir_list($upload_dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$'));
299 $head[$h][0] =
dolBuildUrl(DOL_URL_ROOT.
'/compta/bank/account_statement_document.php', [
'account' =>
$object->id,
'num' => $num]);
300 $head[$h][1] = $langs->trans(
"Documents");
301 if (($nbFiles + $nbLinks) > 0) {
302 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).
'</span>';
304 $head[$h][2] =
'document';
323 global $db, $langs,
$conf;
328 $head[$h][0] = DOL_URL_ROOT.
'/compta/bank/various_payment/card.php?id='.
$object->id;
329 $head[$h][1] = $langs->trans(
"VariousPayment");
330 $head[$h][2] =
'card';
339 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
340 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
343 $nbFiles = count(
dol_dir_list($upload_dir,
'files', 0,
'',
'(\.meta|_preview.*\.png)$'));
344 if (!empty($upload_dirold) &&
dol_is_dir($upload_dirold)) {
345 $nbFiles += count(
dol_dir_list($upload_dirold,
'files', 0,
'',
'(\.meta|_preview.*\.png)$'));
348 $head[$h][0] = DOL_URL_ROOT.
'/compta/bank/various_payment/document.php?id='.
$object->id;
349 $head[$h][1] = $langs->trans(
'Documents');
350 if (($nbFiles + $nbLinks) > 0) {
351 $head[$h][1] .=
'<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).
'</span>';
353 $head[$h][2] =
'documents';
356 $head[$h][0] = DOL_URL_ROOT.
'/compta/bank/various_payment/info.php?id='.
$object->id;
357 $head[$h][1] = $langs->trans(
"Info");
358 $head[$h][2] =
'info';
375 if ($account ==
null && $swift ==
null) {
377 } elseif ($swift ==
null) {
378 $swift = $account->bic;
380 if (preg_match(
"/^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$/", $swift)) {
396 if ($account ==
null && $ibantocheck ==
null) {
398 } elseif ($ibantocheck ==
null) {
399 $ibantocheck = ($account->iban ? $account->iban : $account->iban_prefix);
401 require_once DOL_DOCUMENT_ROOT.
'/includes/php-iban/oophp-iban.php';
403 $iban =
new PHP_IBAN\IBAN($ibantocheck);
404 $check = $iban->Verify();
421 if ($account->getCountryCode() ==
'FR') {
422 require_once DOL_DOCUMENT_ROOT.
'/includes/php-iban/oophp-iban.php';
423 $ibantoprint = preg_replace(
'/[^a-zA-Z0-9]/',
'', empty($account->iban) ?
'' : $account->iban);
424 $iban =
new PHP_IBAN\IBAN($ibantoprint);
425 return $iban->HumanFormat();
428 return $account->iban;
439 $country_code = $account->getCountryCode();
444 if (empty($account->number)) {
445 $account->number = $account->num_compte;
447 if (empty($account->cle)) {
448 $account->cle = $account->cle_rib;
451 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);
453 if ($country_code ==
'FR') {
454 $coef = array(62, 34, 3);
456 $rib = strtolower(trim($account->code_banque).trim($account->code_guichet).trim($account->number).trim($account->cle));
459 $rib = strtr($rib,
"abcdefghijklmnopqrstuvwxyz",
"12345678912345678923456789");
464 for ($i = 0; $i < 3; $i++) {
465 $code = substr($rib, 7 * $i, 7);
466 $s += ((int) $code) * $coef[$i];
469 $cle_rib = 97 - ($s % 97);
470 if ($cle_rib == $account->cle) {
481 if ($country_code ==
'DZ') {
482 $code_banque = trim((
string) $account->code_banque);
483 $code_guichet = trim((
string) $account->code_guichet);
484 $number = trim((
string) $account->number);
485 $cle = trim((
string) $account->cle);
488 if (empty($code_banque) && empty($code_guichet) && empty($cle) && preg_match(
'/^[0-9]{20}$/', $number)) {
489 $code_banque = substr($number, 0, 3);
490 $code_guichet = substr($number, 3, 5);
491 $cle = substr($number, 18, 2);
492 $number = substr($number, 8, 10);
496 if (is_numeric($code_banque) && strlen($code_banque) < 3) {
497 $code_banque = sprintf(
'%03s', $code_banque);
499 if (is_numeric($code_guichet) && strlen($code_guichet) < 5) {
500 $code_guichet = sprintf(
'%05s', $code_guichet);
502 if (is_numeric($number) && strlen($number) < 10) {
503 $number = sprintf(
'%010s', $number);
505 if (is_numeric($cle) && strlen($cle) < 2) {
506 $cle = sprintf(
'%02s', $cle);
509 $rib18 = $code_banque.$code_guichet.$number;
511 if (!preg_match(
'/^[0-9]{18}$/', $rib18) || !preg_match(
'/^[0-9]{2}$/', $cle)) {
517 $rib20 = $rib18.
'00';
518 $len = strlen($rib20);
519 for ($i = 0; $i < $len; $i++) {
520 $remainder = ($remainder * 10 + (int) $rib20[$i]) % 97;
522 $calculated_key = sprintf(
'%02d', 97 - $remainder);
524 return ($calculated_key === $cle);
527 if ($country_code ==
'ES') {
528 $CCC = strtolower(trim($account->number));
529 $rib = strtolower(trim($account->code_banque).trim($account->code_guichet));
530 $cle_rib = strtolower(
checkES($rib, $CCC));
531 if ($cle_rib == strtolower($account->cle)) {
536 if ($country_code ==
'AU') {
537 if (strlen($account->code_banque) > 7) {
539 } elseif (strlen($account->code_banque) < 6) {
549 if (empty($account->number)) {
567 if (empty($IentOfi) || empty($InumCta) || strlen($IentOfi) != 8 || strlen($InumCta) != 10) {
572 $ccc = $IentOfi.$InumCta;
573 $numbers =
"1234567890";
577 while ($i <= strlen($ccc) - 1) {
578 if (strpos($numbers, substr($ccc, $i, 1)) ===
false) {
585 $values = array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
588 for ($i = 2; $i < 10; $i++) {
589 $sum += $values[$i] * (int) substr($IentOfi, $i - 2, 1);
592 $key = 11 - $sum % 11;
605 for ($i = 0; $i < 10; $i++) {
606 $sum += $values[$i] * (int) substr($InumCta, $i, 1);
609 $key = 11 - $sum % 11;
if(! $sortfield) if(! $sortorder) $object
checkIbanForAccount($account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
checkES($IentOfi, $InumCta)
Returns the key for Spanish Banks Accounts.
bank_report_prepare_head(Account $object)
Prepare array with list of tabs for bank report.
account_statement_prepare_head($object, $num)
Prepare array with list of tabs.
checkBanForAccount($account)
Check account number information for a bank account.
getIbanHumanReadable(Account $account)
Returns the iban human readable.
bank_prepare_head(Account $object)
Prepare array with list of tabs.
bank_admin_prepare_head($object=null)
Prepare array with list of tabs.
various_payment_prepare_head($object)
Prepare array with list of tabs.
checkSwiftForAccount($account=null, $swift=null)
Check SWIFT information for a bank account.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
const TYPE_CASH
Cash account.
static count($dbs, $objecttype, $objectid)
Return nb of links.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.