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()
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 return db_query($sql, "could not get all tax types");
45 function get_all_tax_types_simple()
47 $sql = "SELECT * FROM ".TB_PREF."tax_types";
49 return db_query($sql, "could not get all tax types");
52 function get_tax_type($type_id)
54 $sql = "SELECT ".TB_PREF."tax_types.*,
55 Chart1.account_name AS SalesAccountName,
56 Chart2.account_name AS PurchasingAccountName
57 FROM ".TB_PREF."tax_types, ".TB_PREF."chart_master AS Chart1,
58 ".TB_PREF."chart_master AS Chart2
59 WHERE ".TB_PREF."tax_types.sales_gl_code = Chart1.account_code
60 AND ".TB_PREF."tax_types.purchasing_gl_code = Chart2.account_code AND id=$type_id";
62 $result = db_query($sql, "could not get tax type");
64 return db_fetch($result);
67 function get_tax_type_default_rate($type_id)
69 $sql = "SELECT rate FROM ".TB_PREF."tax_types WHERE id=$type_id";
71 $result = db_query($sql, "could not get tax type rate");
73 $row = db_fetch_row($result);
77 function delete_tax_type($type_id)
81 $sql = "DELETE FROM ".TB_PREF."tax_types WHERE id=$type_id";
83 db_query($sql, "could not delete tax type");
85 // also delete any item tax exemptions associated with this type
86 $sql = "DELETE FROM ".TB_PREF."item_tax_type_exemptions WHERE tax_type_id=$type_id";
88 db_query($sql, "could not delete item tax type exemptions");