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_item_tax_type($name, $exempt, $exempt_from)
16 $sql = "INSERT INTO ".TB_PREF."item_tax_types (name, exempt)
17 VALUES (".db_escape($name).",$exempt)";
19 db_query($sql, "could not add item tax type");
24 add_item_tax_type_exemptions($id, $exempt_from);
29 function update_item_tax_type($id, $name, $exempt, $exempt_from)
33 $sql = "UPDATE ".TB_PREF."item_tax_types SET name=".db_escape($name).
34 ", exempt=$exempt WHERE id=$id";
36 db_query($sql, "could not update item tax type");
38 // readd the exemptions
39 delete_item_tax_type_exemptions($id);
40 add_item_tax_type_exemptions($id, $exempt_from);
45 function get_all_item_tax_types()
47 $sql = "SELECT * FROM ".TB_PREF."item_tax_types";
49 return db_query($sql, "could not get all item tax type");
52 function get_item_tax_type($id)
54 $sql = "SELECT * FROM ".TB_PREF."item_tax_types WHERE id=$id";
56 $result = db_query($sql, "could not get item tax type");
58 return db_fetch($result);
61 function get_item_tax_type_for_item($stock_id)
63 $sql = "SELECT ".TB_PREF."item_tax_types.* FROM ".TB_PREF."item_tax_types,".TB_PREF."stock_master WHERE ".TB_PREF."stock_master.stock_id='$stock_id'
64 AND ".TB_PREF."item_tax_types.id=".TB_PREF."stock_master.tax_type_id";
66 $result = db_query($sql, "could not get item tax type");
68 return db_fetch($result);
71 function delete_item_tax_type($id)
75 $sql = "DELETE FROM ".TB_PREF."item_tax_types WHERE id=$id";
77 db_query($sql, "could not delete item tax type");
78 // also delete all exemptions
79 delete_item_tax_type_exemptions($id);
84 function add_item_tax_type_exemptions($id, $exemptions)
86 for ($i = 0; $i < count($exemptions); $i++)
88 $sql = "INSERT INTO ".TB_PREF."item_tax_type_exemptions (item_tax_type_id, tax_type_id)
89 VALUES ($id, " . $exemptions[$i] . ")";
90 db_query($sql, "could not add item tax type exemptions");
94 function delete_item_tax_type_exemptions($id)
96 $sql = "DELETE FROM ".TB_PREF."item_tax_type_exemptions WHERE item_tax_type_id=$id";
98 db_query($sql, "could not delete item tax type exemptions");
101 function get_item_tax_type_exemptions($id)
103 $sql = "SELECT * FROM ".TB_PREF."item_tax_type_exemptions WHERE item_tax_type_id=$id";
105 return db_query($sql, "could not get item tax type exemptions");