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 380d5b442e1cca62585f39c0566c975ddb365da6..bcecad749aba6f546f97e4c7ba22f27bd3e6ab64 100644 (file)
@@ -49,22 +49,24 @@ function get_gl_accounts($from=null, $to=null)
        return db_query($sql, "could not get gl accounts");
 }
 
-function get_gl_accounts_in_type($type)
+function get_gl_accounts_all($balance=-1)
 {
-       $sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_type=$type ORDER BY account_code";
+       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;                                 
+        $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");
 }
 
-function num_accounts_in_type($type, $parent)
-{
-       $sql = "SELECT COUNT(*) FROM ".TB_PREF."chart_master WHERE account_type=$type OR account_type=$parent";
-
-       $result = db_query($sql, "could not get gl accounts");
-       $row = db_fetch_row($result);
-       return $row[0];
-}
-
 function get_gl_account($code)
 {
        $sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_code='$code'";
@@ -82,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)