Changed balance_sheet field in account class to ctype and fixed class editing.
[fa-stable.git] / gl / includes / db / gl_db_account_types.inc
1 <?php
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)
13 {
14         $sql = "INSERT INTO ".TB_PREF."chart_types (id, name, class_id, parent)
15                 VALUES ($id, ".db_escape($name).", $class_id, $parent)";
16
17         db_query($sql, "could not add account type");
18 }
19
20 function update_account_type($id, $name, $class_id, $parent)
21 {
22     $sql = "UPDATE ".TB_PREF."chart_types SET name=".db_escape($name).",
23                 class_id=$class_id,     parent=$parent WHERE id = $id";
24
25         db_query($sql, "could not update account type");
26 }
27
28 function get_account_types($all=false)
29 {
30         $sql = "SELECT * FROM ".TB_PREF."chart_types";
31
32         if (!$all) $sql .= " WHERE !inactive";
33         $sql .= " ORDER BY class_id, id";
34
35         return db_query($sql, "could not get account types");
36 }
37
38 function get_account_type($id)
39 {
40         $sql = "SELECT * FROM ".TB_PREF."chart_types WHERE id = $id";
41
42         $result = db_query($sql, "could not get account type");
43
44         return db_fetch($result);
45 }
46
47 function get_account_type_name($id)
48 {
49         $sql = "SELECT name FROM ".TB_PREF."chart_types WHERE id = $id";
50
51         $result = db_query($sql, "could not get account type");
52
53         $row = db_fetch_row($result);
54         return $row[0];
55 }
56
57 function delete_account_type($id)
58 {
59         $sql = "DELETE FROM ".TB_PREF."chart_types WHERE id = $id";
60
61         db_query($sql, "could not delete account type");
62 }
63
64 function add_account_class($id, $name, $ctype)
65 {
66         $sql = "INSERT INTO ".TB_PREF."chart_class (cid, class_name, ctype)
67                 VALUES ($id, ".db_escape($name).", $ctype)";
68
69         db_query($sql, "could not add account type");
70 }
71
72 function update_account_class($id, $name, $ctype)
73 {
74     $sql = "UPDATE ".TB_PREF."chart_class SET class_name=".db_escape($name).",
75                 ctype=$ctype WHERE cid = $id";
76
77         db_query($sql, "could not update account type");
78 }
79
80 function get_account_classes($all=false)
81 {
82         $sql = "SELECT * FROM ".TB_PREF."chart_class";
83         if (!$all) $sql .= " WHERE !inactive";
84         $sql .= " ORDER BY cid";
85
86         return db_query($sql, "could not get account types");
87 }
88
89 function get_account_class($id)
90 {
91         $sql = "SELECT * FROM ".TB_PREF."chart_class WHERE cid = $id";
92
93         $result = db_query($sql, "could not get account type");
94
95         return db_fetch($result);
96 }
97
98 function get_account_class_name($id)
99 {
100         $sql = "SELECT class_name FROM ".TB_PREF."chart_class WHERE cid = $id";
101
102         $result = db_query($sql, "could not get account type");
103
104         $row = db_fetch_row($result);
105         return $row[0];
106 }
107
108 function delete_account_class($id)
109 {
110         $sql = "DELETE FROM ".TB_PREF."chart_class WHERE cid = $id";
111
112         db_query($sql, "could not delete account type");
113 }
114
115 ?>