Changed balance_sheet operation in class table to class type for sign convert in...
[fa-stable.git] / gl / includes / db / gl_db_accounts.inc
index b544094e325551c51f0afd1fb79f308ff349513e..bcecad749aba6f546f97e4c7ba22f27bd3e6ab64 100644 (file)
@@ -51,13 +51,17 @@ function get_gl_accounts($from=null, $to=null)
 
 function get_gl_accounts_all($balance=-1)
 {
-        $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name AS AccountTypeName,".TB_PREF."chart_types.id AS AccountType,
-               ".TB_PREF."chart_types.parent, ".TB_PREF."chart_class.class_name AS AccountClassName
+       if ($balance == 1)
+               $where ="WHERE balance_sheet>0 AND balance_sheet<".CL_INCOME;
+       elseif ($balance == 0)  
+               $where ="WHERE balance_sheet>".CL_EQUITY." OR balance_sheet=0"; // backwards compatibility
+       $sql = "SELECT ".TB_PREF."chart_master.account_code, ".TB_PREF."chart_master.account_name, ".TB_PREF."chart_types.name AS AccountTypeName,".TB_PREF."chart_types.id AS AccountType,
+               ".TB_PREF."chart_types.parent, ".TB_PREF."chart_class.class_name AS AccountClassName, ".TB_PREF."chart_class.cid AS ClassID 
                FROM ".TB_PREF."chart_types INNER JOIN ".TB_PREF."chart_class ON ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid
                LEFT JOIN ".TB_PREF."chart_master ON ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id ";
        if ($balance != -1)
-               $sql .= "WHERE ".TB_PREF."chart_class.balance_sheet=$balance ";                                 
-        $sql .= "ORDER BY ".TB_PREF."chart_class.cid, IF(parent > 0,parent,".TB_PREF."chart_types.id), 
+               $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";
 
        return db_query($sql, "could not get gl accounts");
@@ -80,7 +84,7 @@ function is_account_balancesheet($code)
 
        $result = db_query($sql,"could not retreive the account class for $code");
        $row = db_fetch_row($result);
-       return $row[0];
+       return $row[0] > 0 && $row[0] < CL_INCOME;
 }
 
 function get_gl_account_name($code)