+
+//----------------------------------------------------------------------------------
+// Check if given account is used by any bank_account.
+// Returns id of first bank_account using account_code, null otherwise.
+//
+// Keep in mind that direct posting to bank account is depreciated
+// because we have no way to select right bank account if
+// there is more than one using given gl account.
+//
+function is_bank_account($account_code)
+{
+ $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code=".db_escape($account_code);
+ $result = db_query($sql, "checking account is bank account");
+ if (db_num_rows($result) > 0) {
+ $acct = db_fetch($result);
+ return $acct['id'];
+ } else
+ return false;
+}
+
+function get_chart_accounts_search($like, $skip=false)
+{
+ global $SysPrefs;
+
+ if (isset($SysPrefs->max_rows_in_search))
+ $limit = $SysPrefs->max_rows_in_search;
+ else
+ $limit = 10;
+
+ if ($skip)
+ $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
+ FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
+ ."LEFT JOIN ".TB_PREF."bank_accounts acc "
+ ."ON chart.account_code=acc.account_code
+ WHERE acc.account_code IS NULL
+ AND chart.account_type=type.id ";
+ else
+ $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
+ FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type WHERE chart.account_type=type.id ";
+ $sql .= "AND (
+ chart.account_name LIKE " . db_escape("%" . $like. "%") . " OR
+ chart.account_code LIKE " . db_escape("%" . $like. "%") . "
+ )
+ ORDER BY chart.account_code LIMIT 0,".(int)($limit); // We only display 10 items.
+ return db_query($sql, "Failed in retreiving GL account list.");
+}