2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 function add_gl_account($account_code, $account_name, $account_type, $account_code2, $tax_code)
14 $account_name = db_escape($account_name);
15 $sql = "INSERT INTO ".TB_PREF."chart_master (account_code, account_code2, account_name, account_type,
17 VALUES (".db_escape($account_code).", ".db_escape($account_code2).", $account_name, $account_type, $tax_code)";
19 db_query($sql, "could not add gl account");
22 function update_gl_account($account_code, $account_name, $account_type, $account_code2, $tax_code)
24 $account_name = db_escape($account_name);
25 $sql = "UPDATE ".TB_PREF."chart_master SET account_name=$account_name,
26 account_type=$account_type, account_code2=".db_escape($account_code2).",
27 tax_code=$tax_code WHERE account_code = '$account_code'";
29 db_query($sql, "could not update gl account");
32 function delete_gl_account($code)
34 $sql = "DELETE FROM ".TB_PREF."chart_master WHERE account_code='$code'";
36 db_query($sql, "could not delete gl account");
39 function get_gl_accounts($from=null, $to=null)
41 $sql = "SELECT ".TB_PREF."chart_master.*,".TB_PREF."chart_types.name AS AccountTypeName
42 FROM ".TB_PREF."chart_master,".TB_PREF."chart_types
43 WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id";
45 $sql .= " AND ".TB_PREF."chart_master.account_code >= '$from'";
47 $sql .= " AND ".TB_PREF."chart_master.account_code <= '$to'";
48 $sql .= " ORDER BY account_code";
50 return db_query($sql, "could not get gl accounts");
53 function get_gl_accounts_all($balance=-1)
55 $sql = "SELECT ".TB_PREF."chart_master.*,".TB_PREF."chart_types.name AS AccountTypeName,".TB_PREF."chart_class.class_name AS AccountClassName
56 FROM ".TB_PREF."chart_master,".TB_PREF."chart_types, ".TB_PREF."chart_class
57 WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id AND
58 ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid";
60 $sql .= " AND ".TB_PREF."chart_class.balance_sheet=$balance";
61 $sql .= " ORDER BY ".TB_PREF."chart_class.cid, ".TB_PREF."chart_types.id, ".TB_PREF."chart_master.account_code";
63 return db_query($sql, "could not get gl accounts");
66 function get_gl_account($code)
68 $sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_code='$code'";
70 $result = db_query($sql, "could not get gl account");
71 return db_fetch($result);
74 function is_account_balancesheet($code)
76 $sql = "SELECT ".TB_PREF."chart_class.balance_sheet FROM ".TB_PREF."chart_class, ".TB_PREF."chart_types, ".TB_PREF."chart_master
77 WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id AND
78 ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid
79 AND ".TB_PREF."chart_master.account_code='$code'";
81 $result = db_query($sql,"could not retreive the account class for $code");
82 $row = db_fetch_row($result);
86 function get_gl_account_name($code)
88 $sql = "SELECT account_name from ".TB_PREF."chart_master WHERE account_code='$code'";
90 $result = db_query($sql,"could not retreive the account name for $code");
92 if (db_num_rows($result) == 1)
94 $row = db_fetch_row($result);
98 display_db_error("could not retreive the account name for $code", $sql, true);