2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 function add_account_type($id, $name, $class_id, $parent)
14 $sql = "INSERT INTO ".TB_PREF."chart_types (id, name, class_id, parent)
15 VALUES ($id, ".db_escape($name).", $class_id, $parent)";
17 db_query($sql, "could not add account type");
20 function update_account_type($id, $name, $class_id, $parent)
22 $sql = "UPDATE ".TB_PREF."chart_types SET name=".db_escape($name).",
23 class_id=$class_id, parent=$parent WHERE id = $id";
25 db_query($sql, "could not update account type");
28 function get_account_types()
30 $sql = "SELECT * FROM ".TB_PREF."chart_types ORDER BY class_id, id";
32 return db_query($sql, "could not get account types");
35 function get_account_type($id)
37 $sql = "SELECT * FROM ".TB_PREF."chart_types WHERE id = $id";
39 $result = db_query($sql, "could not get account type");
41 return db_fetch($result);
44 function get_account_type_name($id)
46 $sql = "SELECT name FROM ".TB_PREF."chart_types WHERE id = $id";
48 $result = db_query($sql, "could not get account type");
50 $row = db_fetch_row($result);
55 function get_account_types_all($balance=-1)
57 $sql = "SELECT ".TB_PREF."chart_types.name AS AccountTypeName,".TB_PREF."chart_types.parent,".TB_PREF."chart_types.id AS AccountType,
58 ".TB_PREF."chart_class.class_name AS AccountClassName
59 FROM ".TB_PREF."chart_types, ".TB_PREF."chart_class
60 WHERE ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid";
62 $sql .= " AND ".TB_PREF."chart_class.balance_sheet=$balance";
63 $sql .= " ORDER BY ".TB_PREF."chart_class.cid, IF(parent > -1,parent,".TB_PREF."chart_types.id), parent";
65 return db_query($sql, "could not get gl types");
68 function delete_account_type($id)
70 $sql = "DELETE FROM ".TB_PREF."chart_types WHERE id = $id";
72 db_query($sql, "could not delete account type");
75 function add_account_class($id, $name, $balance)
77 $sql = "INSERT INTO ".TB_PREF."chart_class (cid, class_name, balance_sheet)
78 VALUES ($id, ".db_escape($name).", $balance)";
80 db_query($sql, "could not add account type");
83 function update_account_class($id, $name, $balance)
85 $sql = "UPDATE ".TB_PREF."chart_class SET class_name=".db_escape($name).",
86 balance_sheet=$balance WHERE cid = $id";
88 db_query($sql, "could not update account type");
91 function get_account_classes()
93 $sql = "SELECT * FROM ".TB_PREF."chart_class ORDER BY cid";
95 return db_query($sql, "could not get account types");
98 function get_account_class($id)
100 $sql = "SELECT * FROM ".TB_PREF."chart_class WHERE cid = $id";
102 $result = db_query($sql, "could not get account type");
104 return db_fetch($result);
107 function get_account_class_name($id)
109 $sql = "SELECT class_name FROM ".TB_PREF."chart_class WHERE cid = $id";
111 $result = db_query($sql, "could not get account type");
113 $row = db_fetch_row($result);
118 function delete_account_class($id)
120 $sql = "DELETE FROM ".TB_PREF."chart_class WHERE cid = $id";
122 db_query($sql, "could not delete account type");