Optimizing the F2, F3 and F4 keys in sales/purchase forms.
[fa-stable.git] / gl / includes / db / gl_db_accounts.inc
index 3244b176cfd701340d2838118dd3f5a626c12c50..6bc73abd9d03234c437d1f6932a85885f83015dc 100644 (file)
@@ -111,7 +111,7 @@ function gl_account_in_company_defaults($acc)
                OR name='default_cogs_act'
                OR name='default_adj_act'
                OR name='default_inv_sales_act'
-               OR name='default_assembly_act') AND value=".db_escape($acc);
+               OR name='default_wip_act') AND value=".db_escape($acc);
        $result = db_query($sql,"Couldn't test for default company GL codes");
 
        $myrow = db_fetch_row($result);
@@ -289,7 +289,7 @@ function is_bank_account($account_code)
                return false;
 }
 
-function get_chart_accounts_search($like)
+function get_chart_accounts_search($like, $skip=false)
 {
        global $SysPrefs;
 
@@ -298,14 +298,20 @@ function get_chart_accounts_search($like)
        else
                $limit = 10;
 
-
-       $sql = "SELECT chart.account_code, chart.account_name, type.name
-                       FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
-                       WHERE chart.account_type=type.id
-        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.
+       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.");
 }