Corected inadequate shipping tax calculations.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 6 Feb 2008 13:07:59 +0000 (13:07 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 6 Feb 2008 13:07:59 +0000 (13:07 +0000)
taxes/db/tax_groups_db.inc
taxes/tax_calc.inc

index e23ab75234a5d571e32e4e847d9fe7a2215ec93a..415d041915fe7db2c3b9d57fe31ba0da47eef841 100644 (file)
@@ -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
index 1f00b8a095d93cf4fe765ddecd69de62d6917650..146beac41aeb89cde91867eb425e4b777a40ba06 100644 (file)
@@ -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;
                        }
                }