0000710: Shipping tax on all tax groups. And marking with tax type(s) it shall have.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 12 Jul 2011 14:50:51 +0000 (16:50 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 12 Jul 2011 14:50:51 +0000 (16:50 +0200)
sales/includes/cart_class.inc
sql/alter2.4.sql
taxes/db/tax_groups_db.inc
taxes/tax_calc.inc
taxes/tax_groups.php

index 286f9f373dcd89642d3f9f8ffe2e1eb8849177a1..46f8d5009436fa31661a8b86d8b42655aed4b96b 100644 (file)
@@ -492,7 +492,7 @@ class cart
        function get_shipping_tax()
        {
 
-               $tax_items = get_shipping_tax_as_array();
+               $tax_items = get_shipping_tax_as_array($this->tax_group_id);
                $tax_rate = 0;
                if ($tax_items != null) {
                        foreach ($tax_items as $item_tax) {
index d84441ac7577469e24ff7b975ea1fd082b94dfba..d944173746f9c8100c03c49e3a4559c91b95534c 100644 (file)
@@ -27,3 +27,9 @@ UPDATE `0_gl_trans` gl
  SET `person_id` = IF(br.receivables_account, br.debtor_no, IF(sup.payable_account, sup.supplier_id, NULL)), 
        `person_type_id` = IF(br.receivables_account, 2, IF(sup.payable_account, 3, NULL));
 
+ALTER TABLE `0_tax_group_items` ADD COLUMN `tax_shipping` tinyint(1) NOT NULL default '0' AFTER `rate`;
+UPDATE `0_tax_group_items` tgi
+       SET tgi.tax_shipping=1
+       WHERE tgi.rate=(SELECT 0_tax_types.rate FROM 0_tax_types, 0_tax_groups 
+               WHERE tax_shipping=1 AND tgi.tax_group_id=0_tax_groups.id AND tgi.tax_type_id=0_tax_types.id);
+ALTER TABLE `0_tax_groups` DROP COLUMN `tax_shipping`;
index 5c217aa275bb0457c67a8285b57bf0ff4f509fca..05e36f9235de5b367a16f8763d63e50f00790c91 100644 (file)
@@ -9,40 +9,29 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-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)
+function add_tax_group($name, $taxes, $rates, $tax_shippings)
 {
        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 (".db_escape($name).", ".db_escape($tax_shipping).")";
+       $sql = "INSERT INTO ".TB_PREF."tax_groups (name) VALUES (".db_escape($name).")";
        db_query($sql, "could not add tax group");
        
        $id = db_insert_id();
        
-       add_tax_group_items($id, $taxes, $rates);       
+       add_tax_group_items($id, $taxes, $rates, $tax_shippings);       
        
        commit_transaction();   
 }
 
-function update_tax_group($id, $name, $tax_shipping, $taxes, $rates)
+function update_tax_group($id, $name, $taxes, $rates, $tax_shippings)
 {
        begin_transaction();    
 
-       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=".db_escape($tax_shipping)." WHERE id=".db_escape($id);
+    $sql = "UPDATE ".TB_PREF."tax_groups SET name=".db_escape($name)." WHERE id=".db_escape($id);
        db_query($sql, "could not update tax group");
        
        delete_tax_group_items($id);
-       add_tax_group_items($id, $taxes, $rates);       
+       add_tax_group_items($id, $taxes, $rates, $tax_shippings);       
        
        commit_transaction();                   
 }
@@ -77,12 +66,12 @@ function delete_tax_group($id)
        commit_transaction();
 }
 
-function add_tax_group_items($id, $items, $rates)
+function add_tax_group_items($id, $items, $rates, $tax_shippings)
 {
        for ($i=0; $i < count($items); $i++) 
        {
-               $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate)
-                       VALUES (".db_escape($id).",  ".db_escape($items[$i]).", " . $rates[$i] .")";
+               $sql = "INSERT INTO ".TB_PREF."tax_group_items (tax_group_id, tax_type_id, rate, tax_shipping)
+                       VALUES (".db_escape($id).",  ".db_escape($items[$i]).", " . $rates[$i] .", " . $tax_shippings[$i] .")";
                db_query($sql, "could not add item tax group item");                                    
        }               
 }
@@ -125,24 +114,24 @@ function get_tax_group_items_as_array($id)
        return $ret_tax_array;
 }
 
-function get_shipping_tax_group_items()
+function get_shipping_tax_group_items($tax_group)
 {
 
        $sql = "SELECT ".TB_PREF."tax_group_items.*, ".TB_PREF."tax_types.name AS tax_type_name, ".TB_PREF."tax_types.rate,
                ".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
+               FROM " .TB_PREF."tax_group_items, ".TB_PREF."tax_types
+               WHERE " .TB_PREF."tax_group_items.tax_shipping=1
+               AND tax_group_id=$tax_group
                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()
+function get_shipping_tax_as_array($tax_group)
 {
        $ret_tax_array = array();
 
        
-       $tax_group_items = get_shipping_tax_group_items();
+       $tax_group_items = get_shipping_tax_group_items($tax_group);
 
        while ($tax_group_item = db_fetch($tax_group_items)) 
        {
index 6e721da7e53f13ca839626d08676beaeefe773b4..f9906e0fca11f24b623d50ca25a75ab3785e9aa2 100644 (file)
@@ -179,7 +179,7 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc
        // add the shipping taxes, only if non-zero, and only if tax group taxes shipping
        if ($shipping_cost != 0) 
        {
-               $item_taxes = get_shipping_tax_as_array();
+               $item_taxes = get_shipping_tax_as_array($tax_group);
                if ($item_taxes != null) 
                {
                        if ($tax_included == 1)
index bf888159043376a45cfdcb14c72bec0f5d09707f..2f300e7ee71b2377a199391f8c57be2634ee4a03 100644 (file)
@@ -64,6 +64,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                // create an array of the taxes and array of rates
        $taxes = array();
        $rates = array();
+       $tax_shippings = array();
 
        for ($i = 0; $i < 5; $i++) 
        {
@@ -72,6 +73,7 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                        {
                        $taxes[] = $_POST['tax_type_id' . $i];
                                $rates[] = get_tax_type_default_rate($_POST['tax_type_id' . $i]);
+                       $tax_shippings[] = check_value('tax_shipping' . $i);
                                //Editable rate has been removed 090920 Joe Hunt
                        //$rates[] = input_num('rate' . $i);
                }
@@ -79,13 +81,12 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
 
        if ($selected_id != -1) 
        {
-                       update_tax_group($selected_id, $_POST['name'], $_POST['tax_shipping'], $taxes, 
-                       $rates);
+                       update_tax_group($selected_id, $_POST['name'], $taxes, $rates, $tax_shippings);
                        display_notification(_('Selected tax group has been updated'));
        } 
        else 
        {
-                       add_tax_group($_POST['name'], $_POST['tax_shipping'], $taxes, $rates);
+                       add_tax_group($_POST['name'], $taxes, $rates, $tax_shippings);
                        display_notification(_('New tax group has been added'));
        }
 
@@ -143,7 +144,7 @@ $result = get_all_tax_groups(check_value('show_inactive'));
 start_form();
 
 start_table(TABLESTYLE);
-$th = array(_("Description"), _("Shipping Tax"), "", "");
+$th = array(_("Description"), "", "");
 inactive_control_column($th);
 
 table_header($th);
@@ -155,10 +156,6 @@ while ($myrow = db_fetch($result))
        alt_table_row_color($k);
 
        label_cell($myrow["name"]);
-       if ($myrow["tax_shipping"])
-               label_cell(_("Yes"));
-       else
-               label_cell(_("No"));
 
        /*for ($i=0; $i< 5; $i++)
                if ($myrow["type" . $i] != ALL_NUMERIC)
@@ -185,7 +182,6 @@ if ($selected_id != -1)
        $group = get_tax_group($selected_id);
 
        $_POST['name']  = $group["name"];
-       $_POST['tax_shipping'] = $group["tax_shipping"];
 
        $items = get_tax_group_items($selected_id);
 
@@ -194,6 +190,7 @@ if ($selected_id != -1)
        {
                $_POST['tax_type_id' . $i]  = $tax_item["tax_type_id"];
                $_POST['rate' . $i]  = percent_format($tax_item["rate"]);
+               $_POST['tax_shipping' . $i]  = $tax_item["tax_shipping"];
                $i ++;
        }
        while($i<5) unset($_POST['tax_type_id'.$i++]);
@@ -202,7 +199,6 @@ if ($selected_id != -1)
        hidden('selected_id', $selected_id);
 }
 text_row_ex(_("Description:"), 'name', 40);
-yesno_list_row(_("Tax applied to Shipping:"), 'tax_shipping', null, "", "", true);
 
 end_table();
 
@@ -211,20 +207,23 @@ display_note(_("Select the taxes that are included in this group."), 1, 1);
 start_table(TABLESTYLE2);
 //$th = array(_("Tax"), _("Default Rate (%)"), _("Rate (%)"));
 //Editable rate has been removed 090920 Joe Hunt
-$th = array(_("Tax"), _("Rate (%)"));
+$th = array(_("Tax"), _("Rate (%)"), _("Shipping Tax"));
 table_header($th);
 for ($i = 0; $i < 5; $i++) 
 {
        start_row();
        if (!isset($_POST['tax_type_id' . $i]))
                $_POST['tax_type_id' . $i] = 0;
+       if (!isset($_POST['tax_shipping' . $i]))
+               $_POST['tax_shipping' . $i] = 0;
        tax_types_list_cells(null, 'tax_type_id' . $i, $_POST['tax_type_id' . $i], _("None"), true);
 
        if ($_POST['tax_type_id' . $i] != 0 && $_POST['tax_type_id' . $i] != ALL_NUMERIC) 
        {
                $default_rate = get_tax_type_default_rate($_POST['tax_type_id' . $i]);
                label_cell(percent_format($default_rate), "nowrap align=right");
-
+               
+               check_cells(null, 'tax_shipping' . $i);
                //Editable rate has been removed 090920 Joe Hunt
                //if (!isset($_POST['rate' . $i]) || $_POST['rate' . $i] == "")
                //      $_POST['rate' . $i] = percent_format($default_rate);