News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

VM 3.0.14 - Tax calculation is wrong

Started by siristru, April 05, 2016, 18:44:12 PM

Previous topic - Next topic

siristru

How to replicate?

1. Create tax rule +5%
2. Create new product with price $66,67 net
3. Set tax for that product to 5%, this will give us $70 gross
4. Create another product with price $66,67 net
5. Set tax for that product to 5%, this will give us $70 gross
6. Browse to frontend and add both products to cart

Result:

Summarized gross price is $140,01

Expected result:

Summarized gross price should be $140

Issue apply to both cart and cart module: http://i.imgur.com/XXz9xdN.png
I reported this issue previously here: http://forum.virtuemart.net/index.php?topic=132965.0

Apply to:

Joomla! 3.5
VirtueMart 3.0.14 and 3.1
Само слога Славjанa спашава - Свуда пођи, својој кући дођи.

jenkinhill

The calculation in the cart is 66.67+66.67=133.34 without tax.
Then with 5% tax,  133.34*105/100=144.007  which when rounded to 2 decimal places is 140.01
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

siristru

Yes, mathematic calculation is fine - as you showed it.
But in cart I show price with tax which is 70 zł.
So customer see that 70 zł + 70 zł = 140.01 zł.
Customer is interested in final price, that is gross price.

So rounding  is the case here... 140.007 should be rounded to 140.

I could fix it myself using overrides... but this apply to many places like invoices, emails and so on...
Само слога Славjанa спашава - Свуда пођи, својој кући дођи.

lindapowers

#3
Well the initial problem is that 66,67 is not the correct base price to achieve 70 as gross price with 5% tax but rather: 66,666666666666667

Try adding more decimals like: 66.66667 to the base price of the product.

We had to do this in some prices were we were getting a cent up or down like you but is difficult to avoid it for every case and quantity.
This is not a VM calculation error, this is just rounding which is never perfect.

The 70 zl you are seeing is just a rounding in screen so is not 70.0 zl and the real value youll have it in your backend so if its adding that cent play with the base price as mentioned.

siristru

That shed a bit of light on the issue.
The problem is that net price is showed on the invoice so I can't just add more decimals like 66.66667 as this will be displayed.

Currently the tax for particular product is shown correctly. Eg. if net 66.67 zł, then tax is 3,33 zł = 70 zł

So maybe we could just sum particular tax from products?
VM counts tax separately for each product... why just not sum them up?

66,67 zł + 66,67 zł = 133,34 zł Net
3,33 zł + 3,33 zł = 6,66 zł of tax

133,34 zł + 6,66 zł = 140 zł gross.

So not

66,67 zł + 66,67 zł = 133,34 zł Net and now 5% from it = 6,667 zł
133,34 zł + 6,667 zł = 140,007 zł ~ 140,1 zł gross.

I understand that issue is related with calculation (it also apply to accounting desktop programs).

Possible solutions are (I guess):

- changing rounding so in case of 140,007 it will be just 140.
- adding particular tax value not counting it again from sum of product net prices.

IMHO second solution is better as rounding will be never perfect.

Could you guys set me on a right track to do this? I've tried myself but I'm still learning php and not sure how to add values of the same index in array...
Само слога Славjанa спашава - Свуда пођи, својој кући дођи.

Milbo

Quote from: siristru on April 14, 2016, 01:44:20 AM
So maybe we could just sum particular tax from products?
VM counts tax separately for each product... why just not sum them up?

There are two options and the normal option is "round only display". So VM works already that way
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

lindapowers

As Milbo says in VM configuration/pricing/ check "Round only display" on the price configuration in the left.

You should see only values with 2 decimal places in the invoice with that setting if you use "2" in final sales price on same config screen. Both in the net and gross price.

However as I recommended you, use 4 or 5 decimals in the product cost price to avoid the issue you mentioned of getting a cent up or down.

Regards