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_tax_type($name, $sales_gl_code, $purchasing_gl_code, $rate)
14 $sql = "INSERT INTO ".TB_PREF."tax_types (name, sales_gl_code, purchasing_gl_code, rate)
15 VALUES (".db_escape($name).", ".db_escape($sales_gl_code)
16 .", ".db_escape($purchasing_gl_code).", $rate)";
18 db_query($sql, "could not add tax type");
21 function update_tax_type($type_id, $name, $sales_gl_code, $purchasing_gl_code, $rate)
23 $sql = "UPDATE ".TB_PREF."tax_types SET name=".db_escape($name).",
24 sales_gl_code=".db_escape($sales_gl_code).",
25 purchasing_gl_code=".db_escape($purchasing_gl_code).",
29 db_query($sql, "could not update tax type");
32 function get_all_tax_types($all=false)
34 $sql = "SELECT ".TB_PREF."tax_types.*,
35 Chart1.account_name AS SalesAccountName,
36 Chart2.account_name AS PurchasingAccountName
37 FROM ".TB_PREF."tax_types, ".TB_PREF."chart_master AS Chart1,
38 ".TB_PREF."chart_master AS Chart2
39 WHERE ".TB_PREF."tax_types.sales_gl_code = Chart1.account_code
40 AND ".TB_PREF."tax_types.purchasing_gl_code = Chart2.account_code";
42 if (!$all) $sql .= " AND !".TB_PREF."tax_types.inactive";
43 return db_query($sql, "could not get all tax types");
46 function get_all_tax_types_simple()
48 $sql = "SELECT * FROM ".TB_PREF."tax_types";
50 return db_query($sql, "could not get all tax types");
53 function get_tax_type($type_id)
55 $sql = "SELECT ".TB_PREF."tax_types.*,
56 Chart1.account_name AS SalesAccountName,
57 Chart2.account_name AS PurchasingAccountName
58 FROM ".TB_PREF."tax_types, ".TB_PREF."chart_master AS Chart1,
59 ".TB_PREF."chart_master AS Chart2
60 WHERE ".TB_PREF."tax_types.sales_gl_code = Chart1.account_code
61 AND ".TB_PREF."tax_types.purchasing_gl_code = Chart2.account_code AND id=$type_id";
63 $result = db_query($sql, "could not get tax type");
65 return db_fetch($result);
68 function get_tax_type_default_rate($type_id)
70 $sql = "SELECT rate FROM ".TB_PREF."tax_types WHERE id=$type_id";
72 $result = db_query($sql, "could not get tax type rate");
74 $row = db_fetch_row($result);
78 function delete_tax_type($type_id)
82 $sql = "DELETE FROM ".TB_PREF."tax_types WHERE id=$type_id";
84 db_query($sql, "could not delete tax type");
86 // also delete any item tax exemptions associated with this type
87 $sql = "DELETE FROM ".TB_PREF."item_tax_type_exemptions WHERE tax_type_id=$type_id";
89 db_query($sql, "could not delete item tax type exemptions");