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_group($name, $taxes, $rates, $tax_shippings)
16 $sql = "INSERT INTO ".TB_PREF."tax_groups (name) VALUES (".db_escape($name).")";
17 db_query($sql, "could not add tax group");
21 add_tax_group_items($id, $taxes, $rates, $tax_shippings);
26 function update_tax_group($id, $name, $taxes, $rates, $tax_shippings)
30 $sql = "UPDATE ".TB_PREF."tax_groups SET name=".db_escape($name)." WHERE id=".db_escape($id);
31 db_query($sql, "could not update tax group");
33 delete_tax_group_items($id);
34 add_tax_group_items($id, $taxes, $rates, $tax_shippings);
39 function get_all_tax_groups($all=false)
41 $sql = "SELECT * FROM ".TB_PREF."tax_groups";
42 if (!$all) $sql .= " WHERE !inactive";
44 return db_query($sql, "could not get all tax group");
47 function get_tax_group($type_id)
49 $sql = "SELECT * FROM ".TB_PREF."tax_groups WHERE id=".db_escape($type_id);
51 $result = db_query($sql, "could not get tax group");
53 return db_fetch($result);
56 function delete_tax_group($id)
60 $sql = "DELETE FROM ".TB_PREF."tax_groups WHERE id=".db_escape($id);
62 db_query($sql, "could not delete tax group");
64 delete_tax_group_items($id);
69 function add_tax_group_items($id, $items, $rates, $tax_shippings)
71 for ($i=0; $i < count($items); $i++)
73 $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate, tax_shipping)
74 VALUES (".db_escape($id).", ".db_escape($items[$i]).", " . $rates[$i] .", " . $tax_shippings[$i] .")";
75 db_query($sql, "could not add item tax group item");
79 function delete_tax_group_items($id)
81 $sql = "DELETE FROM ".TB_PREF."tax_group_items WHERE tax_group_id=".db_escape($id);
83 db_query($sql, "could not delete item tax group items");
86 function get_tax_group_items($id)
88 $sql = "SELECT ".TB_PREF."tax_group_items.*, ".TB_PREF."tax_types.name AS tax_type_name, ".TB_PREF."tax_types.rate,
89 ".TB_PREF."tax_types.sales_gl_code, ".TB_PREF."tax_types.purchasing_gl_code
90 FROM ".TB_PREF."tax_group_items, ".TB_PREF."tax_types
91 WHERE tax_group_id=".db_escape($id)."
92 AND ".TB_PREF."tax_types.id=tax_type_id";
94 return db_query($sql, "could not get item tax type group items");
97 function get_tax_group_items_as_array($id)
99 $ret_tax_array = array();
101 $tax_group_items = get_tax_group_items($id);
103 while ($tax_group_item = db_fetch($tax_group_items))
105 $index = $tax_group_item['tax_type_id'];
106 $ret_tax_array[$index]['tax_type_id'] = $tax_group_item['tax_type_id'];
107 $ret_tax_array[$index]['tax_type_name'] = $tax_group_item['tax_type_name'];
108 $ret_tax_array[$index]['sales_gl_code'] = $tax_group_item['sales_gl_code'];
109 $ret_tax_array[$index]['purchasing_gl_code'] = $tax_group_item['purchasing_gl_code'];
110 $ret_tax_array[$index]['rate'] = $tax_group_item['rate'];
111 $ret_tax_array[$index]['Value'] = 0;
114 return $ret_tax_array;
117 function get_shipping_tax_group_items($tax_group)
120 $sql = "SELECT ".TB_PREF."tax_group_items.*, ".TB_PREF."tax_types.name AS tax_type_name, ".TB_PREF."tax_types.rate,
121 ".TB_PREF."tax_types.sales_gl_code, ".TB_PREF."tax_types.purchasing_gl_code
122 FROM " .TB_PREF."tax_group_items, ".TB_PREF."tax_types
123 WHERE " .TB_PREF."tax_group_items.tax_shipping=1
124 AND tax_group_id=$tax_group
125 AND ".TB_PREF."tax_types.id=tax_type_id";
126 return db_query($sql, "could not get shipping tax group items");
129 function get_shipping_tax_as_array($tax_group)
131 $ret_tax_array = array();
134 $tax_group_items = get_shipping_tax_group_items($tax_group);
136 while ($tax_group_item = db_fetch($tax_group_items))
138 $index = $tax_group_item['tax_type_id'];
139 $ret_tax_array[$index]['tax_type_id'] = $tax_group_item['tax_type_id'];
140 $ret_tax_array[$index]['tax_type_name'] = $tax_group_item['tax_type_name'];
141 $ret_tax_array[$index]['sales_gl_code'] = $tax_group_item['sales_gl_code'];
142 $ret_tax_array[$index]['purchasing_gl_code'] = $tax_group_item['purchasing_gl_code'];
143 $ret_tax_array[$index]['rate'] = $tax_group_item['rate'];
144 $ret_tax_array[$index]['Value'] = 0;
147 return $ret_tax_array;