CRE Loaded Community

Banner


Board index » CRE Loaded Support » CRE Loaded 6.4

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Global Quantity Discount - Tax Problem
PostPosted: Thu Sep 02, 2010 9:23 am 
Offline
CRE Newbie

Joined: Fri Apr 23, 2010 10:36 am
Posts: 22
I have set a 10% discount in Global quantity discount & it seems to give a discount on the total including tax then another discount on the tax amount:

Sub-Total: $4,268.00
Tax: $388.00
Quantity Discount (10%): -$426.80
Free Shipping: $0.00
Total: $3,802.40

The total of $4268 minus 10% should be: $3841.20
It has removed an additional 10% of the tax.

The sub total is wrong too, it says it should display the amount before tax but it displays the amount after tax???

anyone know how to fix this?


Top
 Profile  
 
 Post subject: Re: Global Quantity Discount - Tax Problem
PostPosted: Thu Sep 02, 2010 1:21 pm 
Offline
CRE Legend
User avatar

Joined: Thu Jun 12, 2008 6:39 am
Posts: 2211
Location: New Zealand
sammael wrote:
I have set a 10% discount in Global quantity discount & it seems to give a discount on the total including tax then another discount on the tax amount:

Sub-Total: $4,268.00
Tax: $388.00
Quantity Discount (10%): -$426.80
Free Shipping: $0.00
Total: $3,802.40

The total of $4268 minus 10% should be: $3841.20
It has removed an additional 10% of the tax.

The sub total is wrong too, it says it should display the amount before tax but it displays the amount after tax???

anyone know how to fix this?

In Admin/Modules/Order Totals switch the sort order of the Tax and the Quantity Discount. The QD can appear before or after the Subtotal, depending on whether you want the ST to reflect the discount (ie QD before ST) or not (QD after ST.)

The Subtotal figure will also depend on whether you have Display Price including tax or not in the Admin/Configuration - ie if the display price with tax is true, then the subtotal is the sum of the displayed products prices which include tax (gross) and the tax field is a report only field. If display price with tax is false, then the subtotal is the sum of the products in the cart (net) and the tax is the amount calculated based on it.

Hope this helps,
Simon

_________________
www.codemehappy.com
For Cre Loaded tips, how-to articles and more


Top
 Profile  
 
 Post subject: Re: Global Quantity Discount - Tax Problem
PostPosted: Fri Sep 03, 2010 3:17 am 
Offline
CRE Newbie

Joined: Fri Apr 23, 2010 10:36 am
Posts: 22
Hi Simon,

Is this what you mean?
Sub-Total: $4,268.00
Quantity Discount (10%): -$426.80
Tax: $349.20
Free Shipping: $0.00
Total: $3,802.40

The tax looks correct now but the order total is still wrong. I seem to end up with the same figure no matter what, I have tried changing the sort order in numerous combinations and removing the tax total alltogether.

It seems like the calculation is wrong somewhere internally. Unless I have set up something wrongly but I dont think so. :(

Regarding the subtotal I guess I'll leave that because I want the prices displayed on the site to be inclusive of tax.


Top
 Profile  
 
 Post subject: Re: Global Quantity Discount - Tax Problem
PostPosted: Fri Sep 03, 2010 6:58 am 
Offline
CRE Legend
User avatar

Joined: Thu Jun 12, 2008 6:39 am
Posts: 2211
Location: New Zealand
Yeah the problem is in the file /includes/modules/order_totals/ot_qty_discount.php.
It seems to halve the difference between the qty_discount - tax and deduct this from the order total
... so 4268 - 426.80 = right answer 3841.20 but it goes on to then subtract ((426.80-349.20)/2) = 3802.40

(It also seems to ignore the Calculate Tax, Include Tax and Include Shipping settings in the qty_discount module itself...)

So, howabout backing up the file above (change extension to .bak) and trying this version:

Code:
<?php
/*
  $Id: ot_qty_discount.php,v 1.41 2004-09-14 dreamscape Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2004 Josh Dechant
  Protions Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class ot_qty_discount {
    var $title, $output;

    function ot_qty_discount() {
      $this->code = 'ot_qty_discount';
      $this->title = MODULE_QTY_DISCOUNT_TITLE;
      $this->description = MODULE_QTY_DISCOUNT_DESCRIPTION;
      $this->enabled = MODULE_QTY_DISCOUNT_STATUS;
      $this->sort_order = MODULE_QTY_DISCOUNT_SORT_ORDER;
      $this->include_shipping = MODULE_QTY_DISCOUNT_INC_SHIPPING;
      $this->include_tax = MODULE_QTY_DISCOUNT_INC_TAX;
      $this->calculate_tax = MODULE_QTY_DISCOUNT_CALC_TAX;
      $this->output = array();
    }

    function process() {
      global $order, $currencies, $ot_subtotal;

      $od_amount = $this->calculate_discount($this->get_order_total());
      if ($this->calculate_tax == 'true') $tod_amount = $this->calculate_tax_effect($od_amount);

      if ($od_amount > 0) {
        if (MODULE_QTY_DISCOUNT_RATE_TYPE == 'percentage') $title_ext = sprintf(MODULE_QTY_DISCOUNT_PERCENTAGE_TEXT_EXTENSION ,$this->calculate_rate($_SESSION['cart']->count_contents()));
        $this->deduction = $od_amount+$tod_amount;
        $this->output[] = array('title' => sprintf(MODULE_QTY_DISCOUNT_FORMATED_TITLE, $title_ext),
                                'text' => sprintf(MODULE_QTY_DISCOUNT_FORMATED_TEXT, $currencies->format($od_amount)),
                                'value' => $od_amount);
        $order->info['total'] -= $this->deduction;
        $order->info['tax'] -= $tod_amount;
        if ($this->sort_order < $ot_subtotal->sort_order) $order->info['subtotal'] -= $this->deduction;
      }
    }

    function calculate_discount($amount) {
      global $qty_discount, $order_total_array;

      $od_amount = 0;
      if ((MODULE_QTY_DISCOUNT_DISABLE_WITH_COUPON == 'true') && (isset($_SESSION['cc_id']))) return $od_amount;

      $qty_discount = $this->calculate_rate($_SESSION['cart']->count_contents());
      if ($qty_discount > 0) {
        if (MODULE_QTY_DISCOUNT_RATE_TYPE == 'percentage') {
          $od_amount = tep_round((($amount*10)/10)*($qty_discount/100), 2);
        } else {
          $od_amount = tep_round((($qty_discount*10)/10), 2);
        }
      }

      return $od_amount;
    }

    function calculate_rate($order_qty) {
      $discount_rate = split("[:,]" , MODULE_QTY_DISCOUNT_RATES);
      $size = sizeof($discount_rate);
      for ($i=0, $n=$size; $i<$n; $i+=2) {
        if ($order_qty >= $discount_rate[$i]) {
          $qty_discount = $discount_rate[$i+1];
        }
      }

      return $qty_discount;
    }

    function calculate_tax_effect($od_amount) {
      global $order;

      if (MODULE_QTY_DISCOUNT_RATE_TYPE == 'percentage') {
        $tod_amount = 0;
        reset($order->info['tax_groups']);
        while (list($key, $value) = each($order->info['tax_groups'])) {
          $god_amount = 0;
          $tax_rate = tep_get_tax_rate_from_desc($key);
          $net = ($tax_rate * $order->info['tax_groups'][$key]);
          if ($net > 0) {
            $god_amount = $this->calculate_discount($order->info['tax_groups'][$key]);
            $tod_amount += $god_amount;
            $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
          }
        }
      } else {
        $tod_amount = 0;
        reset($order->info['tax_groups']);
        while (list($key, $value) = each($order->info['tax_groups'])) {
          $god_amount = 0;
          $tax_rate = tep_get_tax_rate_from_desc($key);
          $net = ($tax_rate * $order->info['tax_groups'][$key]);
          if ($net>0) {
            $god_amount = ($tax_rate/100)*$od_amount;
            $tod_amount += $god_amount;
            $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
          }
        }
      }

      return $tod_amount;
    }

    function get_order_total() {
      global $order;

      $order_total = $order->info['total'];
      if ($this->include_tax == 'false') $order_total = ($order_total - $order->info['tax']);
      if ($this->include_shipping == 'false') $order_total = ($order_total - $order->info['shipping_cost']);
      return $order_total;
    }

    function check() {
      if (!isset($this->check)) {
        $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_QTY_DISCOUNT_STATUS'");
        $this->check = tep_db_num_rows($check_query);
      }

      return $this->check;
    }

    function keys() {
      return array('MODULE_QTY_DISCOUNT_STATUS', 'MODULE_QTY_DISCOUNT_SORT_ORDER', 'MODULE_QTY_DISCOUNT_DISABLE_WITH_COUPON', 'MODULE_QTY_DISCOUNT_RATE_TYPE', 'MODULE_QTY_DISCOUNT_RATES', 'MODULE_QTY_DISCOUNT_INC_SHIPPING', 'MODULE_QTY_DISCOUNT_INC_TAX', 'MODULE_QTY_DISCOUNT_CALC_TAX');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Quantity Discount', 'MODULE_QTY_DISCOUNT_STATUS', 'true', 'Do you want to enable the quantity discount module?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_QTY_DISCOUNT_SORT_ORDER', '2', 'Sort order of display.', '6', '2', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Disable If Coupon Used', 'MODULE_QTY_DISCOUNT_DISABLE_WITH_COUPON', 'true', 'Do you want to disable the quantity discount module if a discount coupon is being used by the user?', '6', '3','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Discount Rate Type', 'MODULE_QTY_DISCOUNT_RATE_TYPE', 'percentage', 'Choose the type of discount rate - percentage or flat rate', '6', '4','tep_cfg_select_option(array(\'percentage\', \'flat rate\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Discount Rates', 'MODULE_QTY_DISCOUNT_RATES', '10:5,20:10', 'The discount is based on the total number of items.  Example: 10:5,20:10.. 10 or more items get a 5% or $5 discount; 20 or more items receive a 10% or $10 disount; depending on the rate type.', '6', '5', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_QTY_DISCOUNT_INC_SHIPPING', 'false', 'Include Shipping in calculation', '6', '6', 'tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_QTY_DISCOUNT_INC_TAX', 'false', 'Include Tax in calculation.', '6', '7','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Calculate Tax', 'MODULE_QTY_DISCOUNT_CALC_TAX', 'true', 'Re-calculate Tax on discounted amount.', '6', '8','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
  }

////
// Get tax rate from tax description
  if (!function_exists(tep_get_tax_rate_from_desc)) {
    function tep_get_tax_rate_from_desc($tax_desc) {
      $tax_query = tep_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_description = '" . $tax_desc . "'");
      $tax = mysql_fetch_assoc($tax_query);
      return $tax['tax_rate'];
    }
  }
?>


You'll need to remove and install the qty_discount module in OT again.
I'd also use a simplier example in the cart - maybe just one taxable item at $10 net - so it's easier to figure the total out.

Simon

_________________
www.codemehappy.com
For Cre Loaded tips, how-to articles and more


Top
 Profile  
 
 Post subject: Re: Global Quantity Discount - Tax Problem
PostPosted: Fri Sep 03, 2010 9:59 am 
Offline
CRE Newbie

Joined: Fri Apr 23, 2010 10:36 am
Posts: 22
Hi Simon,
Thanks again for your reply.
I tried installing the code you provided but I get the error:
Fatal error: Call to a member function count_contents() on a non-object in /home/ins21845/public_html/shop/includes/modules/order_total/ot_qty_discount.php on line 53

I'm using pro v6.4a if that makes a difference.

I notice this oscommerce module gives the correct calculation http://addons.oscommerce.com/info/6751 but it only works if I install it when the cart is already at the 'payment information' stage. Trying to check out from the start causes errors. The module seems to have other issues with CRE but it calculates correctly, I cant make heads or tails of the code though.


Top
 Profile  
 
 Post subject: Re: Global Quantity Discount - Tax Problem
PostPosted: Fri Sep 03, 2010 9:23 pm 
Offline
CRE Legend
User avatar

Joined: Thu Jun 12, 2008 6:39 am
Posts: 2211
Location: New Zealand
sammael wrote:
Hi Simon,
Thanks again for your reply.
I tried installing the code you provided but I get the error:
Fatal error: Call to a member function count_contents() on a non-object in /home/ins21845/public_html/shop/includes/modules/order_total/ot_qty_discount.php on line 53

I'm using pro v6.4a if that makes a difference.

I notice this oscommerce module gives the correct calculation http://addons.oscommerce.com/info/6751 but it only works if I install it when the cart is already at the 'payment information' stage. Trying to check out from the start causes errors. The module seems to have other issues with CRE but it calculates correctly, I cant make heads or tails of the code though.

Yeah it was a long shot (the ot_qty_discount.php file from version 6.2.). The osc version is a lot more advanced than the Cre one so it'd take recoding - and I'm not going into that for free! I'd submit the global qty discount module as a bug to http://creloaded.org/issue-tracker.html
Simon

_________________
www.codemehappy.com
For Cre Loaded tips, how-to articles and more


Top
 Profile  
 
 Post subject: Re: Global Quantity Discount - Tax Problem
PostPosted: Sat Sep 04, 2010 12:12 am 
Offline
CRE Newbie

Joined: Fri Apr 23, 2010 10:36 am
Posts: 22
Thanks Simon,
I have submitted the bug to admin. Hopefully they will fix it since it should work in the first place.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

Board index » CRE Loaded Support » CRE Loaded 6.4

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
It is currently Tue Feb 07, 2012 10:58 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Login

Top Listing

1. Cart2Cart - Shopping...
    Category: Shopping Cart Database Conversion Scripts
    
2. Points & Rewards PLUS!...
    Category: Add-Ons
    
3. Configuration Server...
    Category: Fixes
    
4. Credit Card with CCV
    Category: Payment Modules
    
5. CC7333_ATS
    Category: Templates
    
Show more...

Follow Us on Twitter

An error occurred

Oops, an error seems to have occurred. We're sorry for any inconvenience this might have caused. If the error persists, feel free to tell us about it.

CRE Loaded Community Chat hosted by CRE Loaded.

Join now


Chat about what's on your mind. More about public chats.


© CRE Loaded is a product of Chain Reaction Ecommerce, Inc. Usage & Privacy Policy