Zen Cart Logo
Forums / Bug Reports / [Done v1.3.9] Sales Tax Calculation Incorrect

[Done v1.3.9] Sales Tax Calculation Incorrect

Locked

Views: 6,543

Results 1 to 20 of 29
This thread is locked. New replies are disabled.
10 Apr 2009, 4:18 PM
#1
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

[Done v1.3.9] Sales Tax Calculation Incorrect

I've just posted a comment on the Quantity Discounts support thread regarding a tax calculation error:

http://www.zen-cart.com/forum/showpost.php?p=713621&postcount=389

However, i've realised that this error occurs when any discount module is used, including the inbuilt Discount coupons.

The tax appears to be calculated on the subtotal rather than as a percentage of the total. There are a number of other threads with similar problems:
http://www.zen-cart.com/forum/showthread.php?t=94942
https://www.zen-cart.com/forum/showthread.php?p=706968

I'm not a coder so cannot say how this is calculated but it would appear that when a discount coupon is used, tax should be calculated based on the order total (excluding the shipping amount if there is no tax on shipping).

Any help on this problem would be much appreciated.

10 Apr 2009, 4:52 PM
#2
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

see

http://www.zen-cart.com/forum/showthread.php?p=713626#post713626

this should address the problem of Tax calculations where display_price_with_tax = true

10 Apr 2009, 9:03 PM
#3
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Hey

Thanks for replying. I've just tried that bug fix and it appeared to make no difference.

Tax is still calculating incorrectly for both quantity discounts and coupons.

I need the coupon to include tax so that the discount includes tax.

Regards.

10 Apr 2009, 9:29 PM
#4
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

with

include_tax = false
include_shipping = false
recalculate_tax = standard

what totals are you now getting

(BTW I am also assuming that you do have DISPLAY_PRICE_WITH_TAX = true)

10 Apr 2009, 9:51 PM
#5
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Hey,

Yes, display_prices_with_tax=true

and
Include Shipping
false

Include Tax
false

Re-calculate Tax
Standard

Without bugfix applied:

Sub-Total: £10.00
Free shipping (Free shipping): £0.00
Discount Coupon: 10% : -£0.85
Included VAT @ 15%: £1.19
Total: £9.15

Totals are the same after bugfix is applied.

The problem is when i turn on tax (as i want the 10% discount to be applied to the inc tax price (ie the £10):

Include Shipping
false

Include Tax
true

Re-calculate Tax
None

Sub-Total:£10.00
Free shipping (Free shipping):£0.00
Discount Coupon: 10%:-£0.96 (incorrect)
Included VAT @ 15%:£1.19
Total:£9.15

Include Shipping
false

Include Tax
true

Re-calculate Tax
Standard

Sub-Total:£10.00
Free shipping (Free shipping):£0.00
Discount Coupon: 10%:-£0.96 (incorrect)
Included VAT @ 15%:£1.19 (incorrect)
Total:£9.04

10 Apr 2009, 10:40 PM
#6
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

k,

And you are sure you implemented the fixes from page 1 of the thread I posted earlier.

includes/modules/order_totals/ot_coupon.php

line 73

replace

if (DISPLAY_PRICE_WITH_TAX == 'true') { 

with

if (DISPLAY_PRICE_WITH_TAX == 'true' && $od_amount['type'] == 'P') { 

Line 76

replace

if ($this->calculate_tax == "Standard") $order->info['total'] -= $tax;

with

if ($this->calculate_tax == "Standard"  && $od_amount['type'] == 'P') $order->info['total'] -= $tax;

line 347

replace

$ratio = $od_amount['total']/$order_total; 

with

$ratio = $od_amount['total']/($order_total+ ( (DISPLAY_PRICE_WITH_TAX == 'true') ? $orderTotalTax : 0 ));

remember to back files up before editing

14 Apr 2009, 1:36 PM
#7
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Hi,

Sorry for the slow reply - holiday weekend.

Yes, as said before, after applying the fix (all 4 lines) the totals are exactly the same for the discount coupon.

This error was noticed on the Quantity Discount module, not the Discount Coupon module so would appear to affect the tax calculation for all discount modules, not just the Discount Coupon one.

Thanks.

22 Apr 2009, 10:43 AM
#8
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Any insights as to what might be causing this problem?

Any help would be much appreciated.

22 Apr 2009, 8:37 PM
#9
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Hi,

I've tested some new code for Discount coupons et al and so far it fixes all the known tax calculation problems that these modules used to have.

I have not however tested it with Quantity discounts. I'll do that asap (tomorrow)
and let you know what I find.

22 Apr 2009, 9:40 PM
#10
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

wilt:

Hi,

I've tested some new code for Discount coupons et al and so far it fixes all the known tax calculation problems that these modules used to have.

I have not however tested it with Quantity discounts. I'll do that asap (tomorrow)
and let you know what I find.

Fantastic - i look forward to trying it out. Please let me know if i can help in any way.

25 Apr 2009, 12:06 AM
#11
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

k,

On the tests I have done so far, it does seem that if a product has associated Quantity Discounts there are problems with the calculation of taxes.

In fact my tests seem to suggest that this problem exists even without any discounts being applied.

I'll work thru the code to see if I can find the exact problem.

Just a note. We now have an semi - automated test system. This allows us to define test situations (ie what products, what discounts, what tax rates)

makes it so much easier to find problems.

29 Apr 2009, 1:59 PM
#12
andy4pop avatar

andy4pop

New Zenner

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

I found Tax to ba calculated incorrectaly when tax is shown in shop or not, the version is 1.3.8.
This only happens when using discount,
If I have shop set to include tax, the invoice value is correct but the tax is always less.

29 Apr 2009, 2:03 PM
#13
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

wilt:

k,

On the tests I have done so far, it does seem that if a product has associated Quantity Discounts there are problems with the calculation of taxes.

In fact my tests seem to suggest that this problem exists even without any discounts being applied.

I'll work thru the code to see if I can find the exact problem.

Just a note. We now have an semi - automated test system. This allows us to define test situations (ie what products, what discounts, what tax rates)

makes it so much easier to find problems.

Hi Wilt,

Any progress on fixing this issue?

Thanks.

12 May 2009, 5:34 PM
#14
batterygenie avatar

batterygenie

New Zenner

Join Date:
May 2008
Location:
Thousand Oaks, CA
Posts:
30
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Just throwing my hat in the ring here. There's definitely a bug in how Zen Cart processes the tax in combination with Coupon discounts. It'd be great if someone could shed some light on this problem.

12 May 2009, 6:07 PM
#15
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Any progress on fixing this issue?

Yes,

The problem was in includes/classes/order.php circa line 499

Replace

$shown_price = (zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'])

with

  $shown_price = (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']))
13 May 2009, 1:11 PM
#16
fergusmacdonald avatar

fergusmacdonald

Zen Follower

Join Date:
Oct 2007
Location:
Edinburgh, Scotland
Posts:
243
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

wilt:

Yes,

The problem was in includes/classes/order.php circa line 499

Replace

$shown_price = (zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'])

> 
> with 
> 
> ```php
  $shown_price = (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']))

Fantastic, thanks. Will try it out and let you know if i get any problems.

Much appreciated.

13 May 2009, 9:26 PM
#17
batterygenie avatar

batterygenie

New Zenner

Join Date:
May 2008
Location:
Thousand Oaks, CA
Posts:
30
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

I don't believe this fix is addressing the issue I was finding with the sales tax.

Maybe it's a settings issue I'm missing but I've checked all the same attributes as listed previously but I still get a slight miscalculation in the sales tax code that appears like this whenever a coupon is used:

From Sample Order:
Sub-Total: $27.98
Standard: $9.98
Discount Coupon: JUNSAVE20 : -$5.60
Tax (CA residents only) + + : $2.07
Reward Points earned: 28
Total: $34.43
Amount Applied: $34.43

But when you look at the MySQL database in the orders_total table the value that is passed through is 2.0716, whereas it should be 2.07015 based on a tax rate of 9.25. It seems that every time a coupon is applied and tax is involved it throws the calculation off, sometimes higher and sometimes lower than what it should be. I don't understand how Zen Cart is achieving this result. Not sure if it's relevant but the coupon is for 20% off.

13 May 2009, 10:07 PM
#18
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

Batterygenie,

Do you have tax applied to your shipping costs or not ??

13 May 2009, 10:17 PM
#19
batterygenie avatar

batterygenie

New Zenner

Join Date:
May 2008
Location:
Thousand Oaks, CA
Posts:
30
Plugin Contributions:
0

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

No, taxing shipping is not required in California.

Other pertinent settings in Order Total if you're curious:
Order Total Modules > Discount Coupon
Default Sort of 280
Include shipping: False
Include Tax: False
Re-calculate Tax: Standard
Tax Class: None

Thanks for taking the time to reply...it would be great to stop having to juggle our taxes every month...

13 May 2009, 10:38 PM
#20
wilt avatar

wilt

Oji-san

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

Re: [Done v1.3.9] Sales Tax Calculation Incorrect

ok,

In that case I am unsure as to where you think the problems is.

According to my calculations

Sub - Total 27.98
Discount -5.60

Taxable Total 22.38
Tax @9.25% 2.07

Sub - Total 24.45
Shipping 9.98

Grand Total 34.43

which seems to match the figures you have ?
Not sure why you are concerned too much with the figures stored in the table, as these would need to be rounded to 2 significant figures, and still would give you 2.07