3 function clear_shipping_tax_group() {
4 $sql = "UPDATE ".TB_PREF."tax_groups SET tax_shipping=0 WHERE 1";
5 db_query($sql, "could not update tax_shipping fields");
8 function add_tax_group($name, $tax_shipping, $taxes, $rates)
12 if($tax_shipping) // only one tax group for shipping
13 clear_shipping_tax_group();
15 $sql = "INSERT INTO ".TB_PREF."tax_groups (name, tax_shipping) VALUES ('$name', $tax_shipping)";
16 db_query($sql, "could not add tax group");
20 add_tax_group_items($id, $taxes, $rates);
25 function update_tax_group($id, $name, $tax_shipping, $taxes, $rates)
29 if($tax_shipping) // only one tax group for shipping
30 clear_shipping_tax_group();
32 $sql = "UPDATE ".TB_PREF."tax_groups SET name='$name',tax_shipping=$tax_shipping WHERE id=$id";
33 db_query($sql, "could not update tax group");
35 delete_tax_group_items($id);
36 add_tax_group_items($id, $taxes, $rates);
41 function get_all_tax_groups()
43 $sql = "SELECT * FROM ".TB_PREF."tax_groups";
45 return db_query($sql, "could not get all tax group");
48 function get_tax_group($type_id)
50 $sql = "SELECT * FROM ".TB_PREF."tax_groups WHERE id=$type_id";
52 $result = db_query($sql, "could not get tax group");
54 return db_fetch($result);
57 function delete_tax_group($id)
61 $sql = "DELETE FROM ".TB_PREF."tax_groups WHERE id=$id";
63 db_query($sql, "could not delete tax group");
65 delete_tax_group_items($id);
70 function add_tax_group_items($id, $items, $rates)
72 for ($i=0; $i < count($items); $i++)
74 $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate)
75 VALUES ($id, " . $items[$i] . ", " . $rates[$i] .")";
76 db_query($sql, "could not add item tax group item");
80 function delete_tax_group_items($id)
82 $sql = "DELETE FROM ".TB_PREF."tax_group_items WHERE tax_group_id=$id";
84 db_query($sql, "could not delete item tax group items");
87 function get_tax_group_items($id)
89 $sql = "SELECT ".TB_PREF."tax_group_items.*, ".TB_PREF."tax_types.name AS tax_type_name,
90 ".TB_PREF."tax_types.sales_gl_code, ".TB_PREF."tax_types.purchasing_gl_code
91 FROM ".TB_PREF."tax_group_items, ".TB_PREF."tax_types
92 WHERE tax_group_id=$id
93 AND ".TB_PREF."tax_types.id=tax_type_id";
95 return db_query($sql, "could not get item tax type group items");
98 function get_tax_group_items_as_array($id)
100 $ret_tax_array = array();
102 $tax_group_items = get_tax_group_items($id);
104 while ($tax_group_item = db_fetch($tax_group_items))
106 $index = $tax_group_item['tax_type_id'];
107 $ret_tax_array[$index]['tax_type_id'] = $tax_group_item['tax_type_id'];
108 $ret_tax_array[$index]['tax_type_name'] = $tax_group_item['tax_type_name'];
109 $ret_tax_array[$index]['sales_gl_code'] = $tax_group_item['sales_gl_code'];
110 $ret_tax_array[$index]['purchasing_gl_code'] = $tax_group_item['purchasing_gl_code'];
111 $ret_tax_array[$index]['rate'] = $tax_group_item['rate'];
112 $ret_tax_array[$index]['Value'] = 0;
115 return $ret_tax_array;
118 function get_shipping_tax_group_items()
121 $sql = "SELECT ".TB_PREF."tax_group_items.*, ".TB_PREF."tax_types.name AS tax_type_name,
122 ".TB_PREF."tax_types.sales_gl_code, ".TB_PREF."tax_types.purchasing_gl_code
123 FROM " .TB_PREF."tax_group_items, ".TB_PREF."tax_types, ".TB_PREF."tax_groups
124 WHERE " .TB_PREF."tax_groups.tax_shipping=1
125 AND " .TB_PREF."tax_groups.id=tax_group_id
126 AND ".TB_PREF."tax_types.id=tax_type_id";
127 return db_query($sql, "could not get shipping tax group items");
130 function get_shipping_tax_as_array()
132 $ret_tax_array = array();
135 $tax_group_items = get_shipping_tax_group_items();
137 while ($tax_group_item = db_fetch($tax_group_items))
139 $index = $tax_group_item['tax_type_id'];
140 $ret_tax_array[$index]['tax_type_id'] = $tax_group_item['tax_type_id'];
141 $ret_tax_array[$index]['tax_type_name'] = $tax_group_item['tax_type_name'];
142 $ret_tax_array[$index]['sales_gl_code'] = $tax_group_item['sales_gl_code'];
143 $ret_tax_array[$index]['purchasing_gl_code'] = $tax_group_item['purchasing_gl_code'];
144 $ret_tax_array[$index]['rate'] = $tax_group_item['rate'];
145 $ret_tax_array[$index]['Value'] = 0;
148 return $ret_tax_array;