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_gl_account($account_code, $account_name, $account_type, $account_code2)
14 $account_name = db_escape($account_name);
15 $sql = "INSERT INTO ".TB_PREF."chart_master (account_code, account_code2, account_name, account_type)
16 VALUES (".db_escape($account_code).", ".db_escape($account_code2).", $account_name, $account_type)";
18 db_query($sql, "could not add gl account");
21 function update_gl_account($account_code, $account_name, $account_type, $account_code2)
23 $account_name = db_escape($account_name);
24 $sql = "UPDATE ".TB_PREF."chart_master SET account_name=$account_name,
25 account_type=$account_type, account_code2=".db_escape($account_code2)
26 ." WHERE account_code = '$account_code'";
28 db_query($sql, "could not update gl account");
31 function delete_gl_account($code)
33 $sql = "DELETE FROM ".TB_PREF."chart_master WHERE account_code='$code'";
35 db_query($sql, "could not delete gl account");
38 function get_gl_accounts($from=null, $to=null)
40 $sql = "SELECT ".TB_PREF."chart_master.*,".TB_PREF."chart_types.name AS AccountTypeName
41 FROM ".TB_PREF."chart_master,".TB_PREF."chart_types
42 WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id";
44 $sql .= " AND ".TB_PREF."chart_master.account_code >= '$from'";
46 $sql .= " AND ".TB_PREF."chart_master.account_code <= '$to'";
47 $sql .= " ORDER BY account_code";
49 return db_query($sql, "could not get gl accounts");
52 function get_gl_accounts_in_type($type)
54 $sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_type=$type ORDER BY account_code";
56 return db_query($sql, "could not get gl accounts");
59 function num_accounts_in_type($type, $parent)
61 $sql = "SELECT COUNT(*) FROM ".TB_PREF."chart_master WHERE account_type=$type OR account_type=$parent";
63 $result = db_query($sql, "could not get gl accounts");
64 $row = db_fetch_row($result);
68 function get_gl_account($code)
70 $sql = "SELECT * FROM ".TB_PREF."chart_master WHERE account_code='$code'";
72 $result = db_query($sql, "could not get gl account");
73 return db_fetch($result);
76 function is_account_balancesheet($code)
78 $sql = "SELECT ".TB_PREF."chart_class.balance_sheet FROM ".TB_PREF."chart_class, ".TB_PREF."chart_types, ".TB_PREF."chart_master
79 WHERE ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id AND
80 ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid
81 AND ".TB_PREF."chart_master.account_code='$code'";
83 $result = db_query($sql,"could not retreive the account class for $code");
84 $row = db_fetch_row($result);
88 function get_gl_account_name($code)
90 $sql = "SELECT account_name from ".TB_PREF."chart_master WHERE account_code='$code'";
92 $result = db_query($sql,"could not retreive the account name for $code");
94 if (db_num_rows($result) == 1)
96 $row = db_fetch_row($result);
100 display_db_error("could not retreive the account name for $code", $sql, true);