X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=gl%2Fincludes%2Fdb%2Fgl_db_account_types.inc;h=03a3abeb293b826c78e2f7d915f055a2ef4309f9;hb=9a98bb3bc7a94f1a8e47f8dab45a87c8b4212080;hp=94d27fccffb0028e25c2149a56a6b3f9c2d02208;hpb=02dd4aefa3e3babb64d61140bb7f7de14e37f755;p=fa-stable.git diff --git a/gl/includes/db/gl_db_account_types.inc b/gl/includes/db/gl_db_account_types.inc index 94d27fcc..03a3abeb 100644 --- a/gl/includes/db/gl_db_account_types.inc +++ b/gl/includes/db/gl_db_account_types.inc @@ -20,7 +20,7 @@ function add_account_type($id, $name, $class_id, $parent) function update_account_type($id, $name, $class_id, $parent, $old_id) { begin_transaction(); - if ($old_id != $id) + if ($old_id !== $id) { $sql = "SELECT id FROM ".TB_PREF."chart_types WHERE parent = ".db_escape($old_id); @@ -52,11 +52,25 @@ function update_account_type($id, $name, $class_id, $parent, $old_id) return $ret; } -function get_account_types($all=false) +function get_account_types($all=false, $class_id=false, $parent=false) { $sql = "SELECT * FROM ".TB_PREF."chart_types"; - if (!$all) $sql .= " WHERE !inactive"; + $where = array(); + + if (!$all) + $where[] = "!inactive"; + + if ($class_id != false) + $where[] = "class_id=".db_escape($class_id); + + if ($parent == -1) + $where[] ="(parent = '' OR parent = '-1')"; + elseif ($parent !== false) + $where[] = "parent=".db_escape($parent); + + if (count($where)) + $sql .= ' WHERE '.implode(' AND ', $where); $sql .= " ORDER BY class_id, id, parent"; return db_query($sql, "could not get account types"); @@ -104,13 +118,19 @@ function update_account_class($id, $name, $ctype) return db_query($sql); } -function get_account_classes($all=false) +function get_account_classes($all=false, $balance=-1) { $sql = "SELECT * FROM ".TB_PREF."chart_class"; - if (!$all) $sql .= " WHERE !inactive"; + + if (!$all) + $sql .= " WHERE !inactive"; + if ($balance == 0) + $sql .= " AND ctype>".CL_EQUITY." OR ctype=0"; + elseif ($balance == 1) + $sql .= " AND ctype>0 AND ctype<".CL_INCOME; $sql .= " ORDER BY ctype, cid"; - return db_query($sql, "could not get account types"); + return db_query($sql, "could not get account classes"); } function get_account_class($id)