[0001174] Adding bank account tnumber to customer branch record.
[fa-stable.git] / gl / includes / db / gl_db_bank_accounts.inc
index 1669d20005656ccff82c445f0f24dd4881870ea7..c4318279a033840c769c8293e132c06b1a78aa4e 100644 (file)
@@ -347,5 +347,20 @@ function get_bank_account_limit($account, $date, $user=null)
                return null;
        return max(0, get_balance_before_for_bank_account($account, add_days($date,1))); // in case of manco made before the check was implemented
 }
+function identify_bank_account($account_number)
+{
+       $number = db_escape($account_number);
+       $sql = "(SELECT id AS id, ".BO_COMPANY." AS type FROM ".TB_PREF."bank_accounts WHERE REPLACE(bank_account_number,' ', '')=$number)";
+       $sql .= " UNION (SELECT supplier_id AS id, ".BO_SUPPLIER." AS type FROM ".TB_PREF."suppliers WHERE REPLACE(bank_account,' ', '')=$number)";
+       $sql .= " UNION (SELECT branch_code AS id, ".BO_CUSTBRANCH." AS type FROM ".TB_PREF."cust_branch WHERE REPLACE(bank_account,' ', '')=$number)";
+
+       $result = db_query($sql, 'bank account identification failed');
+
+       if (db_num_rows($result))
+               return db_fetch($result);
+       else
+               return null;
+}
 
 ?>
\ No newline at end of file