Forums / Bug Reports / Sales tax calculations incorrect.

Sales tax calculations incorrect.

Locked

Views: 13,051

Results 1 to 20 of 40
This thread is locked. New replies are disabled.
29 Apr 2008, 7:15 PM
#1
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Sales tax calculations incorrect.

I am using ZenCart 1.3.7 and am not seeing any error messages. This is an issue with calculations of sales tax.

ZenCart's method of calculating tax appears to be to this (based on my experiments):

  • Take each line item in an order
  • Calculate the tax on that line, truncating to 2 significant figures
  • Add all the calculated subtaxes together to produce the total tax on the order

On my web site, it's possible to order up to 10 different items, all of which cost $6. The sales tax rate I use (for California) is 8.75%. 8.75% of $6 is $0.5250, which should produce a tax of $5.25 on this $60 order. However, because ZenCart truncates the individual tax figures instead of rounding them, or instead of calculating the tax once on the full order amount, when it adds up 10 instances of $0.52, it produces a tax of $5.20. On orders with a large number of small items, this process will unpredictably underestimate the sales tax. I can submit spreadsheets demonstrating the calculations if desired. When I order 3 copies of a $20 item, the sales tax is correctly calculated.

I respectfully request a fix in which more than 2 significant figures are used to calculate sales tax, and rounding rather than truncation is used for display. Undercollecting the sales tax could subject our site to penalties from the CA State Board of Equalization.

hedera

Nature bats last.

5 May 2008, 10:08 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Sales tax calculations incorrect.

Just adding a link to related discussion: http://www.zen-cart.com/forum/showthread.php?p=549200#post549200

By way of comment, the problem is worse when tax rates are of a .5 or .75 percentage instead of just a plain integer value.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

6 May 2008, 4:08 AM
#3
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

Yes, the related discussion was my original thread on the subject, detailing how I've worked this out.

Unfortunately, a .75 tax rate is what I have to deal with. I don't want to encourage the state of California to raise it to 9% just to make the calculations easier!

hedera

Nature bats last.

6 May 2008, 6:46 AM
#4
dreamz avatar

dreamz

New Zenner

Join Date:
Oct 2007
Posts:
52
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

As I've posted on the other thread that you (hedera) began and which DrByte referenced - I am having this exact problem. Using Quickbooks the numbers do not match up. Tax on an order should be computed by totaling the items - not on a line item basis as that can return an under valued number. I have not found a solution for this - is there one?

15 May 2008, 3:16 PM
#5
shiatsuguy avatar

shiatsuguy

New Zenner

Join Date:
Nov 2007
Posts:
3
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

I've noticed the same problem in a few of my sales when there is a discount and the sales tax is then calculated incorrectly. I haven't been able to find any postings where this has been fixed. Are we all stuck with this or did anyone find a solution?

15 May 2008, 5:25 PM
#6
dreamz avatar

dreamz

New Zenner

Join Date:
Oct 2007
Posts:
52
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

Dr Byte - Is there a way to have zen cart compute tax on the order sub total before shipping instead of on each item and then adding the tax for each item up? This seems to be a bug that should be corrected. Am I mistaken?

16 May 2008, 6:57 AM
#7
dreamz avatar

dreamz

New Zenner

Join Date:
Oct 2007
Posts:
52
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

Should I be posting this in the bug area?

18 May 2008, 1:24 PM
#8
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

You can set the number of decimal places to 3 instead of two -- see Admin / Localization / Currencies. This causes Zen Cart to use 3 decimal places instead of 2 for calculations, but has the unfortunate side effect of showing 3 digits after the decimal everywhere on the site.

So Zen Cart can do the right thing, but may display wrongly. The issue then is to have separate settings in Admin for the decimal places used in calculations and the decimal places displayed. I have no doubt this is on the To Do list displayed prominently in the lobby of Zen Cart's vast and palatial headquarters. :smartalec:

HTH

Rob

Breakfast: the most important donut of the day.

22 May 2008, 8:24 AM
#9
dreamz avatar

dreamz

New Zenner

Join Date:
Oct 2007
Posts:
52
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

thanks for the info rstevenson. Will this actually solve the problem even though it might not look too good?

23 May 2008, 2:03 PM
#10
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

Well, it's a simple change to make in Admin, so make the change then run some test orders to see.

It will cause the item costs to be truncated at 3 digits instead of 2 (they still won't be rounded properly) so that will make the addition correct(er), though the fundamental problem -- adding tax to each item rather than to the total -- remains unchanged. At least with 3 digits you'll end up with the right number of cents (if you mentally round the third digit yourself.)

This works fine for those of us who use a disconnected accounting system, but would still cause a small problem -- never more than 1 cent, I think -- for anyone who is using an accounting system directly connected to ZC.

Rob

Breakfast: the most important donut of the day.

24 May 2008, 1:00 PM
#11
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Sales tax calculations incorrect.

As far as I know it's allowed to round the tax per item and use the rounded tax amounts to calculate the total. I am sure it's NOT allowed to always round it down per item though (in the Netherlands).

And if you calculate tax on the totals you will have another problem: if you show in and ex price per item rounded on 2 decimals, the totals inc minus the totals ex won't be equal to the total tax anymore (depending on the rounding differences of course).

So if you display 2 decimals and want all the prices ex tax and inc tax per item to be correct and match the totals, it's impossible to guarantee that total tax will always be 100% accurate.

27 May 2008, 10:44 PM
#12
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

Thanks many times to rstevenson for thinking of the useful if ugly solution of setting decimal places to 3. It mainly works (I'll be doing some more checking); and it looks really funky. Still, since some of my tax calculations were off as much as a nickel per order, it may be worth it; I'll try to persuade my business partner.

I did actually file a bug report, on which I've gotten zero response.

paulm is quite right that rounding and even calculating tax on the total order won't help you if you want, or have, to show per-item costs including tax. But since we don't plan to do that, I'd be extremely happy if someone would come up with a patch that calculates the tax on the entire order total, since that's what the State of California expects.

hedera

Nature bats last.

31 May 2008, 7:12 AM
#13
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Sales tax calculations incorrect.

Maybe it should be optional:

  • display the tax calculated on the totals

or

  • the sum of taxes calculated per order line

?

6 Jun 2008, 6:41 PM
#14
dreamz avatar

dreamz

New Zenner

Join Date:
Oct 2007
Posts:
52
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

I changed the tax calculation rounding to keep 1 extra digit ( +1 ) in /includes/classes/order.php line 512:

        $tax_add = zen_round(($products_tax / 100) * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places'] +1);
2 Jul 2008, 10:17 PM
#15
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

Dreamz, I just got back from vacation and saw your last post, about changing the tax calculation rounding: did that work?? I'll certainly give it a try and retest. I don't see any other comments (maybe I'm not the only person who was on vacation!).

hedera

Nature bats last.

2 Jul 2008, 10:28 PM
#16
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

I should have looked at my code before posting. Was that correction you made to 1.3.8?? I'm still running 1.3.7 and line 512 in /includes/classes/order.php is entirely different. In fact, I don't even see a line beginning with:

 $tax_add = zen_round ....

Can you give me some guidance on doing this in 1.3.7?? Here's the line I think I need to modify (line 501 in the 1.3.7 version of order.php):

$current_row_tax_exc = zen_round(($products_tax / 100) * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']);

hedera

Nature bats last.

2 Jul 2008, 11:46 PM
#17
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

It worked, it worked! I made the change in my orders.php and my problem test case calculated out perfectly, even with the currency display set to 2 characters. Boy, is THAT a relief.

And MANY MANY thanks to dreamz who came up with this simple solution.

hedera

Nature bats last.

7 Jul 2008, 9:43 PM
#18
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

I can't win. The tax calculation is now correct but it isn't carried over to the order total! On a single item order with a cost of $2, California tax rate of 8.75%, the modified tax calculation correctly shows $ 0.18, but the order total is $2.17!

Where do we have to add that extra decimal place to correct the final order total??

hedera

Nature bats last.

7 Jul 2008, 10:03 PM
#19
hedera avatar

hedera

Zen Follower

Join Date:
Nov 2007
Posts:
128
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

Furthermore, on a $1.00 order, the tax should be $0.09 and it comes out as $0.08 in both the tax calculation and the order total.

Can we actually ROUND the tax calculation instead of just truncating it at 2 decimal places? Adding the 3rd digit to the tax calculation has made it much better than it was BUT - it's still wrong for $1 orders. We aren't going to get a lot of them, so this probably isn't a show-stopper, but it's stupid. And the mismatch between tax calculation and order total is a show-stopper.

hedera

Nature bats last.

8 Jul 2008, 4:39 AM
#20
tick avatar

tick

New Zenner

Join Date:
Jun 2007
Location:
Phoenix, AZ
Posts:
66
Plugin Contributions:
0

Re: Sales tax calculations incorrect.

hedera:

Furthermore, on a $1.00 order, the tax should be $0.09 and it comes out as $0.08 in both the tax calculation and the order total.

Can we actually ROUND the tax calculation instead of just truncating it at 2 decimal places? Adding the 3rd digit to the tax calculation has made it much better than it was BUT - it's still wrong for $1 orders. We aren't going to get a lot of them, so this probably isn't a show-stopper, but it's stupid. And the mismatch between tax calculation and order total is a show-stopper.

I can't reproduce your error on a stock 1.3.8 cart. I've added a product worth $1.00 and setup one tax zone at 8.75%. If I put two of the items in my cart and proceed to checkout, my order total is $2.18. Your issue may be a bug in 1.3.7 that has been fixed. Have you tried setting up your tax zones on a stock 1.3.8 cart and running your test again?

Also, I just did a quick diff of functions_taxes.php between 1.3.7 and 1.3.8. It looks like they changed the code for handling multiple tax rates. Do you have more than one tax rate (or zone) defined?

Generations Crafting (Our Zen-Cart storefront)
"
And that's just it, Doc - my mind has always been my Achilles' heel!" -- The Tick