X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=taxes%2Fdb%2Ftax_groups_db.inc;h=5abe4333b969de031c5e3a95cec103c302387b61;hb=c4eae7a18f0eb824e6eda7be2ba6fa820e9e58c9;hp=e23ab75234a5d571e32e4e847d9fe7a2215ec93a;hpb=da8311619dd73feae101d246a1957b972e00cbd2;p=fa-stable.git diff --git a/taxes/db/tax_groups_db.inc b/taxes/db/tax_groups_db.inc index e23ab752..5abe4333 100644 --- a/taxes/db/tax_groups_db.inc +++ b/taxes/db/tax_groups_db.inc @@ -1,29 +1,48 @@ . +***********************************************************************/ +function clear_shipping_tax_group() { + $sql = "UPDATE ".TB_PREF."tax_groups SET tax_shipping=0 WHERE 1"; + db_query($sql, "could not update tax_shipping fields"); +} -function add_tax_group($name, $tax_shipping, $taxes, $rates, $included) +function add_tax_group($name, $tax_shipping, $taxes, $rates) { begin_transaction(); + + if($tax_shipping) // only one tax group for shipping + clear_shipping_tax_group(); - $sql = "INSERT INTO ".TB_PREF."tax_groups (name, tax_shipping) VALUES ('$name', $tax_shipping)"; + $sql = "INSERT INTO ".TB_PREF."tax_groups (name, tax_shipping) VALUES (".db_escape($name).", $tax_shipping)"; db_query($sql, "could not add tax group"); $id = db_insert_id(); - add_tax_group_items($id, $taxes, $rates, $included); + add_tax_group_items($id, $taxes, $rates); commit_transaction(); } -function update_tax_group($id, $name, $tax_shipping, $taxes, $rates, $included) +function update_tax_group($id, $name, $tax_shipping, $taxes, $rates) { begin_transaction(); - - $sql = "UPDATE ".TB_PREF."tax_groups SET name='$name',tax_shipping=$tax_shipping WHERE id=$id"; + + if($tax_shipping) // only one tax group for shipping + clear_shipping_tax_group(); + $sql = "UPDATE ".TB_PREF."tax_groups SET name=".db_escape($name).",tax_shipping=$tax_shipping WHERE id=$id"; db_query($sql, "could not update tax group"); delete_tax_group_items($id); - add_tax_group_items($id, $taxes, $rates, $included); + add_tax_group_items($id, $taxes, $rates); commit_transaction(); } @@ -57,12 +76,12 @@ function delete_tax_group($id) commit_transaction(); } -function add_tax_group_items($id, $items, $rates, $included) +function add_tax_group_items($id, $items, $rates) { for ($i=0; $i < count($items); $i++) { - $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate, included_in_price) - VALUES ($id, " . $items[$i] . ", " . $rates[$i] . ", " . $included[$i] .")"; + $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate) + VALUES ($id, " . $items[$i] . ", " . $rates[$i] .")"; db_query($sql, "could not add item tax group item"); } } @@ -99,11 +118,42 @@ function get_tax_group_items_as_array($id) $ret_tax_array[$index]['sales_gl_code'] = $tax_group_item['sales_gl_code']; $ret_tax_array[$index]['purchasing_gl_code'] = $tax_group_item['purchasing_gl_code']; $ret_tax_array[$index]['rate'] = $tax_group_item['rate']; - $ret_tax_array[$index]['included_in_price'] = $tax_group_item['included_in_price']; $ret_tax_array[$index]['Value'] = 0; } return $ret_tax_array; } +function get_shipping_tax_group_items() +{ + + $sql = "SELECT ".TB_PREF."tax_group_items.*, ".TB_PREF."tax_types.name AS tax_type_name, + ".TB_PREF."tax_types.sales_gl_code, ".TB_PREF."tax_types.purchasing_gl_code + FROM " .TB_PREF."tax_group_items, ".TB_PREF."tax_types, ".TB_PREF."tax_groups + WHERE " .TB_PREF."tax_groups.tax_shipping=1 + AND " .TB_PREF."tax_groups.id=tax_group_id + AND ".TB_PREF."tax_types.id=tax_type_id"; + return db_query($sql, "could not get shipping tax group items"); +} + +function get_shipping_tax_as_array() +{ + $ret_tax_array = array(); + + + $tax_group_items = get_shipping_tax_group_items(); + + while ($tax_group_item = db_fetch($tax_group_items)) + { + $index = $tax_group_item['tax_type_id']; + $ret_tax_array[$index]['tax_type_id'] = $tax_group_item['tax_type_id']; + $ret_tax_array[$index]['tax_type_name'] = $tax_group_item['tax_type_name']; + $ret_tax_array[$index]['sales_gl_code'] = $tax_group_item['sales_gl_code']; + $ret_tax_array[$index]['purchasing_gl_code'] = $tax_group_item['purchasing_gl_code']; + $ret_tax_array[$index]['rate'] = $tax_group_item['rate']; + $ret_tax_array[$index]['Value'] = 0; + } + + return $ret_tax_array; +} ?> \ No newline at end of file