Merged changes from main trunk up to 2.2.3
[fa-stable.git] / gl / includes / db / gl_db_accounts.inc
index 3c29cd3ab6efccce205d3932231b1c6acf738052..685619736746e6bffbd9b152d5adf4ed95f8c3d0 100644 (file)
@@ -50,6 +50,8 @@ function get_gl_accounts($from=null, $to=null)
 
 function get_gl_accounts_all($balance=-1)
 {
+       global $use_new_account_types;
+       
        if ($balance == 1)
                $where ="WHERE ctype>0 AND ctype<".CL_INCOME;
        elseif ($balance == 0)  
@@ -62,8 +64,11 @@ function get_gl_accounts_all($balance=-1)
                LEFT JOIN ".TB_PREF."chart_master ON ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id ";
        if ($balance != -1)
                $sql .= $where;                                 
-        $sql .= " ORDER BY ".TB_PREF."chart_class.cid, IF(parent > 0,parent,".TB_PREF."chart_types.id), 
-               IF(parent > 0,".TB_PREF."chart_types.id, parent), ".TB_PREF."chart_master.account_code";
+       if (isset($use_new_account_types) && $use_new_account_types == 1)
+               $sql .= " ORDER BY ".TB_PREF."chart_class.cid, ".TB_PREF."chart_types.id, parent, ".TB_PREF."chart_master.account_code";
+       else
+               $sql .= " ORDER BY ".TB_PREF."chart_class.cid, IF(parent > 0,parent,".TB_PREF."chart_types.id), 
+                       IF(parent > 0,".TB_PREF."chart_types.id, parent), ".TB_PREF."chart_master.account_code";
 
        return db_query($sql, "could not get gl accounts");
 }
@@ -104,15 +109,6 @@ function get_gl_account_name($code)
        display_db_error("could not retreive the account name for $code", $sql, true);
 }
 
-function gl_account_in_transactions($acc)
-{
-       $sql= "SELECT COUNT(*) FROM ".TB_PREF."gl_trans WHERE account=$acc";
-       $result = db_query($sql,"Couldn't test for existing transactions");
-
-       $myrow = db_fetch_row($result);
-       return ($myrow[0] > 0); 
-}
-
 function gl_account_in_company_defaults($acc)
 {
        $sql= "SELECT COUNT(*) FROM ".TB_PREF."company WHERE debtors_act=$acc 
@@ -137,15 +133,6 @@ function gl_account_in_company_defaults($acc)
        return ($myrow[0] > 0); 
 }
 
-function gl_account_in_bank_accounts($acc)
-{
-       $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_accounts WHERE account_code=$acc";
-       $result = db_query($sql,"Couldn't test for bank accounts");
-
-       $myrow = db_fetch_row($result);
-       return ($myrow[0] > 0); 
-}
-
 function gl_account_in_stock_category($acc)
 {
        $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_category WHERE