From: Janusz Dobrowolski Date: Wed, 6 Feb 2008 13:07:59 +0000 (+0000) Subject: Corected inadequate shipping tax calculations. X-Git-Tag: v2.4.2~19^2~2242 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=146f7f65af4a1212c74d5105b1a572104526e852;p=fa-stable.git Corected inadequate shipping tax calculations. --- diff --git a/taxes/db/tax_groups_db.inc b/taxes/db/tax_groups_db.inc index e23ab752..415d0419 100644 --- a/taxes/db/tax_groups_db.inc +++ b/taxes/db/tax_groups_db.inc @@ -106,4 +106,37 @@ function get_tax_group_items_as_array($id) 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 tax_groups.tax_shipping=1 + AND 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]['included_in_price'] = $tax_group_item['included_in_price']; + $ret_tax_array[$index]['Value'] = 0; + } + + return $ret_tax_array; +} ?> \ No newline at end of file diff --git a/taxes/tax_calc.inc b/taxes/tax_calc.inc index 1f00b8a0..146beac4 100644 --- a/taxes/tax_calc.inc +++ b/taxes/tax_calc.inc @@ -130,6 +130,7 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group) for ($i = 0; $i < count($items); $i++) { $item_taxes = get_taxes_for_item($items[$i], $ret_tax_array); + if ($item_taxes != null) { foreach ($item_taxes as $item_tax) @@ -143,12 +144,14 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group) // add the shipping taxes, only if non-zero, and only if tax group taxes shipping if ($shipping_cost != 0) { - $tax_group = get_tax_group($tax_group); - if ($tax_group['tax_shipping']) + $item_taxes = get_shipping_tax_as_array(); + if ($item_taxes != null) { - foreach ($ret_tax_array as $item_tax) + foreach ($item_taxes as $item_tax) { $index = $item_tax['tax_type_id']; + if(!isset($ret_tax_array[$index])) + $ret_tax_array[$index] = $item_tax; $ret_tax_array[$index]['Value'] += $shipping_cost * $item_tax['rate'] / 100; } }