Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sales tax rounds incorrectly?


Chris Dunning

Recommended Posts

Yes, I've searched the forums for this. I came up with this thread:

http://www.oscommerce.com/forums/index.php?sho...=0entry130452

This discusses MS1, and the fix mentioned there has apparently been implemented in MS2. However, I'm still having a problem.

 

A client of mine is having issues with the sales tax rounding incorrectly. Some (but not all) of his orders are off by 1c. While 1c is not a big issue monetarily, it's a headache for accounting. What I've gathered is that the sales tax is being rounded up regardless of whether it should be or not. Example:

 

An order on 3/7 - subtotal plus shipping was $72.38

with a tax rate of 8.75% totaling $78.71325. This should be rounded to

$78.71 but it was charged at $78.72.

 

Another order on 3/5 with subtotal plus shipping of $36.03 with a

tax rate of 8.625% totaling $39.13758 which was rounded correctly to $39.14.

 

Has anyone else seen this? Is there a fix posted somewhere that I was unable to find?

Chris Dunning

osCommerce, Contributions Moderator Team

 

Please do not send me PM! I do not read or answer these often. Use the email button instead!

 

I do NOT support contributions other than my own. Emails asking for support on other people's contributions will be ignored. Ask in the forum or contact the contribution author directly.

Link to comment
Share on other sites

orders.php in the admin screen.

 

I don't know what shows up in checkout_confirmation.php - I haven't done much testing on that. The amount being passed to the payment module, however, is the same (occasionally incorrect) amount that's being shown on the admin screen.

Chris Dunning

osCommerce, Contributions Moderator Team

 

Please do not send me PM! I do not read or answer these often. Use the email button instead!

 

I do NOT support contributions other than my own. Emails asking for support on other people's contributions will be ignored. Ask in the forum or contact the contribution author directly.

Link to comment
Share on other sites

maybe look at(in admin/catagories):

 

function updateGross() {

var taxRate = getTaxRate();

var grossValue = document.forms["new_product"].products_price.value;

 

if (taxRate > 0) {

grossValue = grossValue * ((taxRate / 100) + 1);

}

 

document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);

}

 

function updateNet() {

var taxRate = getTaxRate();

var netValue = document.forms["new_product"].products_price_gross.value;

 

if (taxRate > 0) {

netValue = netValue / ((taxRate / 100) + 1);

}

 

document.forms["new_product"].products_price.value = doRound(netValue, 4);

}

Your online success is Paramount.

Link to comment
Share on other sites

Yesudo - I think that function only has to do with calculating the price after tax when you are inputting your products.

 

 

Maybe this information could help.

There are 17 orders in record that needed sales tax calculated. Of these seventeen, only four were rounded incorrectly. Of those four, two were in the same tax zone - the other two were in two different tax zones. The percentages for the three zones are all different. Three of the orders were rounded down when they should have been rounded up, one was rounded up instead of down. One order used a coupon (which was calculated after taxes) and one had a "low order fee" - a taxable item. There were other orders with coupons that were rounded correctly, and other orders with low order fees that were rounded correctly. I can't find a pattern here anywhere.

 

 

 

Here are my calculations of what the taxes should have been with the calculations made by osCommerce:

 

2.1153 - osC rounded to 2.11

12.397575 - osC rounded to 12.39

4.815125 - osC rounded to 4.81

6.33325 - osC rounded to 6.34

 

Can anyone offer a suggestion of where to turn next for debugging this?

Chris Dunning

osCommerce, Contributions Moderator Team

 

Please do not send me PM! I do not read or answer these often. Use the email button instead!

 

I do NOT support contributions other than my own. Emails asking for support on other people's contributions will be ignored. Ask in the forum or contact the contribution author directly.

Link to comment
Share on other sites

Round function as PHP defines it

 

Example 1. round() examples

 

<?php

echo round(3.4); // 3

echo round(3.5); // 4

echo round(3.6); // 4

echo round(3.6, 0); // 4

echo round(1.95583, 2); // 1.96

echo round(1241757, -3); // 1242000

echo round(5.045, 2); // 5.04

echo round(5.055, 2); // 5.06

?>

Caution

When rounding on exact halves round() rounds down on evens and up on odds. If you want to always force it in one direction on a .5 (or .05 in your case) add or substract a tiny fuzz factor. The reason behind rounding half the values down and the other half up is to avoid the classical banking problem where if you always rounded down you would be stealing money from your customers, or if you always rounded up you would end up over time losing money. By averaging it out through evens and odds you statistically break even.

 

 

As you can see you can set the precision in the round function. I would assume if this doesn't exist it uses the system precision instead..

Link to comment
Share on other sites

Tax padding is set to 0. I assume this means 0 decimal places beyond the standard for that currency? ie, for US dollars now it should round to xx.xx, but if I set that padding to 1 it would round to xx.xxx?

 

The information on the round() function is interesting! I didn't know about the up on evens/down on odds thing. However, osCommerce uses tep_round() instead of round(). tep_round() always rounds up on .05.

Chris Dunning

osCommerce, Contributions Moderator Team

 

Please do not send me PM! I do not read or answer these often. Use the email button instead!

 

I do NOT support contributions other than my own. Emails asking for support on other people's contributions will be ignored. Ask in the forum or contact the contribution author directly.

Link to comment
Share on other sites

I think the problem is this:

 

Right now the order total module "subtotal" is sorted to be directly below the products ordered - but before shipping and extra fees which are all taxable. I believe tax is calculated on the subtotal, then rounded. Tax is then calculated on each of the other modules, and each of those numbers rounded. All of those rounded numbers are then added together to get the total sales tax.

 

I believe I can fix the problem by changing the subtotal to come after all of the taxable items (including shipping, low order fees etc.) which should then cause the tax to be calculated only once, on that subtotal.

 

Does this sound logical?

Chris Dunning

osCommerce, Contributions Moderator Team

 

Please do not send me PM! I do not read or answer these often. Use the email button instead!

 

I do NOT support contributions other than my own. Emails asking for support on other people's contributions will be ignored. Ask in the forum or contact the contribution author directly.

Link to comment
Share on other sites

  • 7 months later...
I think the problem is this:

 

Right now the order total module "subtotal" is sorted to be directly below the products ordered - but before shipping and extra fees which are all taxable.  I believe tax is calculated on the subtotal, then rounded.  Tax is then calculated on each of the other modules, and each of those numbers rounded.  All of those rounded numbers are then added together to get the total sales tax.

 

I believe I can fix the problem by changing the subtotal to come after all of the taxable items (including shipping, low order fees etc.) which should then cause the tax to be calculated only once, on that subtotal.

 

Does this sound logical?

 

Bumping this topic: BlueNoteMKVI, did you solve this problem? Was it indeed the order of your sort?

 

And about the tax padding, should it indeed be set to zero if your currency decimal place is set to 2?

Link to comment
Share on other sites

I haven't solved the problem, no. I've just stopped worrying about it. :)

Chris Dunning

osCommerce, Contributions Moderator Team

 

Please do not send me PM! I do not read or answer these often. Use the email button instead!

 

I do NOT support contributions other than my own. Emails asking for support on other people's contributions will be ignored. Ask in the forum or contact the contribution author directly.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...