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).",".db_escape($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=".db_escape($exempt)." WHERE id=".db_escape($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($also_inactive=false)
47 $sql = "SELECT * FROM ".TB_PREF."item_tax_types";
49 $sql .= " WHERE !inactive";
51 return db_query($sql, "could not get all item tax type");
54 function get_item_tax_type($id)
56 $sql = "SELECT * FROM ".TB_PREF."item_tax_types WHERE id=".db_escape($id);
58 $result = db_query($sql, "could not get item tax type");
60 return db_fetch($result);
63 function get_item_tax_type_for_item($stock_id)
65 $sql = "SELECT item_tax_type.*
66 FROM ".TB_PREF."item_tax_types item_tax_type,"
67 .TB_PREF."stock_master item
68 WHERE item.stock_id=".db_escape($stock_id)."
69 AND item_tax_type.id=item.tax_type_id";
71 $result = db_query($sql, "could not get item tax type");
73 return db_fetch($result);
76 function delete_item_tax_type($id)
80 $sql = "DELETE FROM ".TB_PREF."item_tax_types WHERE id=".db_escape($id);
82 db_query($sql, "could not delete item tax type");
83 // also delete all exemptions
84 delete_item_tax_type_exemptions($id);
89 function add_item_tax_type_exemptions($id, $exemptions)
91 for ($i = 0; $i < count($exemptions); $i++)
93 $sql = "INSERT INTO ".TB_PREF."item_tax_type_exemptions (item_tax_type_id, tax_type_id)
94 VALUES (".db_escape($id).", ".db_escape($exemptions[$i]).")";
95 db_query($sql, "could not add item tax type exemptions");
99 function delete_item_tax_type_exemptions($id)
101 $sql = "DELETE FROM ".TB_PREF."item_tax_type_exemptions WHERE item_tax_type_id=".db_escape($id);
103 db_query($sql, "could not delete item tax type exemptions");
106 function get_item_tax_type_exemptions($id)
108 $sql = "SELECT * FROM ".TB_PREF."item_tax_type_exemptions WHERE item_tax_type_id=".db_escape($id);
110 return db_query($sql, "could not get item tax type exemptions");
113 function item_type_inactive($id)
115 $type = get_item_tax_type($id);
116 return @$type['inactive'];