From 0e64cd1cf3fe3e0c27627641e67f2fbb0c4723c5 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Wed, 24 Feb 2010 09:34:32 +0000 Subject: [PATCH] Tax included calculation problem when more than 1 tax type in a group Small layout fixes --- CHANGELOG.txt | 8 ++++++++ admin/backups.php | 2 +- reporting/rep107.php | 2 +- reporting/rep110.php | 2 +- taxes/tax_calc.inc | 29 +++++++++++++++++------------ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 26b8882a..408d9cf8 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,14 @@ Legend: ! -> Note $ -> Affected files +24-Feb-2010 Joe Hunt +# Tax included calculation problem when more than 1 tax type in a group +$ /taxes/tax_calc.inc +! Small layout fixes +$ /admin/backups.php + /reporting/rep107.php + /reporting/rep110.php + 21-Feb-2010 Joe Hunt # Exchange rate doesn't update table immediately when adding new rate and no exchange rates there before. diff --git a/admin/backups.php b/admin/backups.php index 4bf99a42..9f6efa55 100644 --- a/admin/backups.php +++ b/admin/backups.php @@ -99,7 +99,7 @@ function compress_list_row($label, $name, $value=null) if (function_exists("gzopen")) $ar_comps['gzip'] = "gzip"; - echo "$label"; + echo "$label"; echo array_selector('comp', $value, $ar_comps); echo ""; } diff --git a/reporting/rep107.php b/reporting/rep107.php index e3bd2065..e9df284d 100644 --- a/reporting/rep107.php +++ b/reporting/rep107.php @@ -179,7 +179,7 @@ function print_invoices() if ($tax_item['included_in_price']) { $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] . - " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2); + " (" . $tax_item['rate'] . "%) " . $doc_Amount . ": " . $DisplayTax, -2); } else { diff --git a/reporting/rep110.php b/reporting/rep110.php index 31169780..9f418f7c 100644 --- a/reporting/rep110.php +++ b/reporting/rep110.php @@ -174,7 +174,7 @@ function print_deliveries() if ($tax_item['included_in_price']) { $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] . - " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2); + " (" . $tax_item['rate'] . "%) " . $doc_Amount . ": " . $DisplayTax, -2); } else { diff --git a/taxes/tax_calc.inc b/taxes/tax_calc.inc index db985408..f0be7323 100644 --- a/taxes/tax_calc.inc +++ b/taxes/tax_calc.inc @@ -162,13 +162,10 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc { $index = $item_tax['tax_type_id']; if($tax_included==1) {// 2008-11-26 Joe Hunt Taxes are stored without roundings - //$ret_tax_array[$index]['Value'] += round($prices[$i] * $item_tax['rate'] - // / ($item_tax['rate'] + 100), user_price_dec()); - $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / ($item_tax['rate'] + 100)); - $ret_tax_array[$index]['Net'] += ($prices[$i] * 100 / ($item_tax['rate'] + 100)); + $nprice = get_tax_free_price_for_item($items[$i], $prices[$i], $tax_group, $tax_included); + $ret_tax_array[$index]['Value'] += ($nprice * $item_tax['rate'] / 100); + $ret_tax_array[$index]['Net'] += $nprice; } else { - //$ret_tax_array[$index]['Value'] += - // round($prices[$i] * $item_tax['rate'] / 100, user_price_dec()); $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / 100); $ret_tax_array[$index]['Net'] += $prices[$i]; } @@ -182,18 +179,26 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc $item_taxes = get_shipping_tax_as_array(); if ($item_taxes != null) { + if ($tax_included == 1) + { + $tax_rate = 0; + foreach ($item_taxes as $item_tax) + { + $index = $item_tax['tax_type_id']; + if(isset($ret_tax_array[$index])) { + $tax_rate += $item_tax['rate']; + } + } + $shipping_net = round2($shipping_cost / (1 + ($tax_rate / 100)), user_price_dec()); + } foreach ($item_taxes as $item_tax) { $index = $item_tax['tax_type_id']; if(isset($ret_tax_array[$index])) { if($tax_included==1) {// 2008-11-26 Joe Hunt Taxes are stored without roundings - //$ret_tax_array[$index]['Value'] += round($shipping_cost * $item_tax['rate'] - // / ($item_tax['rate'] + 100), user_price_dec()); - $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / ($item_tax['rate'] + 100)); - $ret_tax_array[$index]['Net'] += ($shipping_cost * 100 / ($item_tax['rate'] + 100)); + $ret_tax_array[$index]['Value'] += ($shipping_net * $item_tax['rate'] / 100); + $ret_tax_array[$index]['Net'] += $shipping_net; } else { - //$ret_tax_array[$index]['Value'] += - // round($shipping_cost * $item_tax['rate'] / 100, user_price_dec()); $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / 100); $ret_tax_array[$index]['Net'] += $shipping_cost; } -- 2.30.2