If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Bug Reports / [Done v1.3.9] Discount groups and tax calc problem with tax-included pricing

[Done v1.3.9] Discount groups and tax calc problem with tax-included pricing

Locked

Started by srt9969 on 16 Feb 2009, 2:16 PM · Views: 13,309

Results 1 to 20 of 29
This thread is locked. New replies are disabled.
16 Feb 2009, 2:16 PM
#1
srt9969 avatar

srt9969

New Zenner

Join Date:
Jan 2009
Posts:
62
Plugin Contributions:
0

Post #1 by srt9969

Hi all,

Really sorry to post this again from e/where on the forum. http://www.zen-cart.com/forum/showthread.php?t=119602
It strikes me as an issue with the way tax is handled, but I need a view from a proper coder, as this facility is vital to my business. I'm sure it only requires a small alteration, but I'm struggling to find an answer:

I have a problem with group pricing and shipping (I think).
No Coupons
ZC1.3.8a
I set up a dummy product priced £100
I added it to the cart and checked out.
The cart shows:

Sub-Total: £100 (inc. VAT)

Shipping:£10.00 (inc. VAT)

Group Discount:-£5.00 (this is application of a group discount of 5%)

VAT 15%:£13.63

Total:£105.00

ot_group_pricing is set Include Shipping & Include Tax both False.

The VAT figure should be 105 * 15% = 13.70
What's actually happening is that the VAT is being calced thus:

104.50 * 15% = 13.63

The 104.50 is coming from:

100 less 5% = 95.00
10 less 5% = 9.50

The 5% is the group discount.

How do I stop the Group Discount being applied to shipping for VAT purposes? I guess it's in the tax module, but that code is a bit scary to a noob. Any help very much appreciated.

Thanks,

Sean

19 Feb 2009, 8:56 AM
#2
srt9969 avatar

srt9969

New Zenner

Join Date:
Jan 2009
Posts:
62
Plugin Contributions:
0

Post #2 by srt9969

Hi,

Does anyone have a view on this issue?
I'm assuming that, since it is (for me) a fairly prominent bug, no-one else has experienced the same problem. Either that, or it has been comprehensively covered elsewhere. I did see a list of 'known issues' somewhere, but lost it again. Perhaps it is covered already in there? Can someone redirect me please?

Regards

Sean

19 Feb 2009, 10:49 AM
#3
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #3 by wilt

Hi,

This is a bug, and has been addressed in the upcoming v139 release.

There are a couple of files that need to be edited to fix this.

First is includes/classes/order.php

circa line 347 - you should see

                 'subtotal' => 0,
                        'tax' => 0,
                        'total' => 0,

which should be changed to

                 'subtotal' => 0,
                       'shipping_tax'=>0,
                        'tax' => 0,
                        'total' => 0,

next you need to edit includes/modules.order_total/ot_shipping.php

circa line 67 change

          $order->info['tax'] += $shipping_tax_amount;
          $order->info['tax_groups']["$shipping_tax_description"] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);

to

    $order->info['tax'] += $shipping_tax_amount;
             $order->info['shipping_tax'] += $shipping_tax_amount;
          $order->info['tax_groups']["$shipping_tax_description"] += zen_calculate_tax($order->info['shipping_cost'], $shipping_tax);

and finally includes/modules/order_total/ot_group_pricing.php

circa line 60
change

    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];

to

    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];
    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_tax'];

Remember to backup any files you edit, in case of disasters.

20 Feb 2009, 12:06 AM
#4
srt9969 avatar

srt9969

New Zenner

Join Date:
Jan 2009
Posts:
62
Plugin Contributions:
0

Post #4 by srt9969

Hi Wilt,

Thanks for the reply. Unfortunately, it didn't work. It added 6 pence to my cart total, and subtracted the same from the group discount.
More to the point, it didn't affect the tax figure at all: I went on to try the same cart (product 100 in tax 15%, shipping 10 inc tax 15%) with a range of group discounts from 5 through 100%. The only one to figure right was (da-daaaa....) 100% discount. On some, the rounding was abominable, but that's a different issue...
Each conformed to the pattern: calculating the total tax on a figure derived from (Subtotal + Shipping)-((Subtotal + Shipping)*groupDiscount%), with no regard to how group pricing module switches were set.

It looks like I have to artificially raise my shipping prices, and set Include Shipping=true, in order to have the shipping discounted to the right price in the cart.
This is unsatisfactory as hell, as it misrepresents actual prices.
I love the functionality and adaptability of ZenCart, but I hate that it can't add up, or round out correctly.
I know this ain't your fault, or anyones, really, I'm just stunned that it hasn't been addressed long ago....

Here's hoping,

Sean

21 Feb 2009, 11:26 AM
#5
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #5 by wilt

Hi,

My apologies, but it seems my fingers failed me.

Where I said to change includes/modules/order_total/ot_group_pricing.php to

    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];
    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_tax'];  

the second line should have been

if ($this->include_shipping != 'true') $order_total_tax -= $order->info['shipping_tax']; 
21 Feb 2009, 11:59 AM
#6
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #6 by wilt

Note. The above is partly plagued by the rounding error mentioned in your other thread.

However I think I have a solution for that as well. Will post to other thread

22 Feb 2009, 10:16 AM
#7
srt9969 avatar

srt9969

New Zenner

Join Date:
Jan 2009
Posts:
62
Plugin Contributions:
0

Post #7 by srt9969

Aha!
And my apologies for not spotting the obvious and sorting it out myself...still on a heck of a learning curve :lookaroun

Sean

22 Feb 2009, 11:20 AM
#8
srt9969 avatar

srt9969

New Zenner

Join Date:
Jan 2009
Posts:
62
Plugin Contributions:
0

Post #8 by srt9969

...except this is not yet quite fixed.
with this mod, totals are as follows:

Sub-Total:£100.00
Flat Rate (Best Way):£10.00
Group Discount:-£4.93
VAT 15%:£13.69
Total:£105.06

Include Tax & Shipping both=False, Re-calculate Tax=Standard.

The Tax is now calculating close enough, but discount is down 7p and total is up only 6p (this is without rounding mod from other thread, just trying to do one thing at a time...)

I'm going to leave this for the moment, and concentrate on other things for a while, maybe it'll look better when I come back to it...

:frusty:

Thanks for your help, so far...
Cheers,

Sean

22 Feb 2009, 5:13 PM
#9
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #9 by wilt

k, have removed my previous post, as i had not quite thought things through .

There is still a piece missing.

If both include_tax and include-shipping are FALSE then the calculations are being done on an order_total that has in effect had the shipping tax removed twice, hence the 6p discrepancy.

22 Feb 2009, 5:58 PM
#10
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #10 by wilt

The fix is to add this line

    if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total += $order->info['shipping_tax'];

This should be added after the similar lines we changed earlier to adjuts the shipping tax.

I now get

Sub-Total:£100.00
Flat Rate (Best Way):£10.00
Group Discount:-£5.00
VAT 15%:£13.70
Total:£105.00

23 Feb 2009, 10:20 AM
#11
srt9969 avatar

srt9969

New Zenner

Join Date:
Jan 2009
Posts:
62
Plugin Contributions:
0

Post #11 by srt9969

...and now my numbers agree with yours. Thank you very much for this, it lifts a weight from my shoulders, for sure.

Presumably this, together with the rounding issue, will be addressed in a future update? Is there a mechanism for ensuring that it gets in? I'm sure that it's easy for important mods to escape being included.

Thanks again for your help,

Regards,

Sean

23 Feb 2009, 10:24 AM
#12
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #12 by wilt

not to worry,

I have already committed the changes to the 1.3.9 branch.

28 Feb 2009, 12:43 AM
#13
evan70 avatar

evan70

New Zenner

Join Date:
Aug 2008
Posts:
13
Plugin Contributions:
0

Post #13 by evan70

function get_order_total() {

    global  $order;

    $order_total_tax = $order->info['tax'];

    $order_total = $order->info['total'];

    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];

	 if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];     
    if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
    if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total += $order->info['shipping_tax']; 

    $orderTotalFull = $order_total;

    $order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);

    return $order_total;

  }
```:clap:
12 Jul 2009, 6:07 AM
#14
shartlesville avatar

shartlesville

New Zenner

Join Date:
Jul 2009
Location:
Roswell, NM, USA
Posts:
103
Plugin Contributions:
0

Post #14 by shartlesville

evan70:

function get_order_total() {

global  $order;
$order_total_tax = $order->info['tax'];
$order_total = $order->info['total'];
if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];
if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];     
if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total += $order->info['shipping_tax']; 
$orderTotalFull = $order_total;
$order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);
return $order_total;

}


Shouldn't the second instance of:

if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];     

actually be:

if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_tax']; 

So instead it would be:

```php
function get_order_total() {
    global  $order;
    $order_total_tax = $order->info['tax'];
    $order_total = $order->info['total'];
    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost']; 
    if ($this->include_shipping != 'true') $order_total_tax -= $order->info['shipping_tax'];
    if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total += $order->info['shipping_tax'];    
    if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
    $orderTotalFull = $order_total;
    $order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);

    return $order_total;
  }

Or is it supposed to have the shipping_cost in both rows?

BTW this is for the includes/modules/order_total/ot_group_pricing.php for anyone reading who isn't sure. :wink:

Blessings,
Krisann

I donate to the Zen Team do you?
My current project: BestSewingDeals.com;

15 Aug 2009, 12:15 PM
#16
smiloen avatar

smiloen

New Zenner

Join Date:
Aug 2009
Posts:
1
Plugin Contributions:
0

Post #16 by smiloen

shartlesville:

Shouldn't the second instance of:
#snip#
Or is it supposed to have the shipping_cost in both rows?

I'd like to verify this as well, does shartlesville have the correct code listed?

Best regards :smile:

27 Aug 2009, 5:19 PM
#17
jazznuts699 avatar

jazznuts699

New Zenner

Join Date:
Jul 2009
Posts:
72
Plugin Contributions:
0

Post #17 by jazznuts699

SMiloen:

I'd like to verify this as well, does shartlesville have the correct code listed?

Best regards :smile:

in order for group discount to correctly function i had to comment out the one of the new lines of code plus substitute shipping_tax for shipping_cost:

Here is the code as recommended:

function get_order_total() {
    global  $order;
    $order_total_tax = $order->info['tax'];
    $order_total = $order->info['total'];
    if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost']; 
    if ($this->include_shipping != 'true') $order_total_tax -= $order->info['shipping_tax'];
    if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total += $order->info['shipping_tax'];    
    if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
    $orderTotalFull = $order_total;
    $order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);

    return $order_total;
  }  

and here is what i have -- sorry about all the comments in the code, it helps me to look back and see what came from where

  function get_order_total() {
    global  $order;
    $order_total_tax = $order->info['tax'];
    $order_total = $order->info['total'];
	if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost']; 
	//if ($this->include_shipping != 'true') $order_total_tax -= $order->info['shipping_cost']; //removed see new code below
	if ($this->include_shipping != 'true') $order_total_tax -= $order->info['shipping_tax']; //changed to shipping_tax per http://www.zen-cart.com/forum/showthread.php?t=120341
	//if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total += $order->info['shipping_tax'];  //removed due to incorrect discount computation 
	if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
	
    $orderTotalFull = $order_total;
    $order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax);

    return $order_total;
  }
14 Sep 2009, 7:41 AM
#18
pupsandpets avatar

pupsandpets

New Zenner

Join Date:
Mar 2008
Posts:
30
Plugin Contributions:
0

Post #18 by pupsandpets

Hi all

I'm having a similar problem I wonder if you can help me with.

I offer free shipping on sales of £100 and over but recently had a few sales around the £88 mark with VAT around £13.20 which makes the overall sale £101 and therefore my cart doesn't charge shipping.

In effect it is therefore giving free shipping on sales under £100 due to the VAT being added.

Can anyone advise how to change this so the free shipping is only on sales of £100 excluding vat?

Sorry to crash on here but I've posted several times elsewhere and had no response!

Thanks
Tori

3 Oct 2009, 11:52 AM
#19
pupsandpets avatar

pupsandpets

New Zenner

Join Date:
Mar 2008
Posts:
30
Plugin Contributions:
0

Post #19 by pupsandpets

pupsandpets:

Hi all

I'm having a similar problem I wonder if you can help me with.

I offer free shipping on sales of £100 and over but recently had a few sales around the £88 mark with VAT around £13.20 which makes the overall sale £101 and therefore my cart doesn't charge shipping.

In effect it is therefore giving free shipping on sales under £100 due to the VAT being added.

Can anyone advise how to change this so the free shipping is only on sales of £100 excluding vat?

Sorry to crash on here but I've posted several times elsewhere and had no response!

Thanks
Tori

**Still haven't solved this if anyone can help?

Thanks**

3 Oct 2009, 3:52 PM
#20
brent avatar

brent

Totally Zenned

Join Date:
Mar 2005
Location:
United Kingdom
Posts:
606
Plugin Contributions:
0

Post #20 by brent

What are your settings for Order Totals Modules >> Discount Coupon?