VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Virtuemart 1.1 Development (Archiv) => Quality & Testing VirtueMart 1.1.x => Topic started by: aravot on October 13, 2010, 08:44:14 am

Title: One penny tax difference issue on every subsequent product that is added to cart
Post by: aravot on October 13, 2010, 08:44:14 am
1 penny tax difference issue on every subsequent product that is added to cart.
Example if 10 of the same product is added than the difference is 5 cent and not penny, the more the product the more the difference.

In shopper group 'Show Prices including tax' is checked.
There is a one penny difference in tax calculation when there are more than two products in shopping cart, the reason instead of tax being calculated on total price of the products it is calculated for individual product rounded and added to total, for better explanation see example below.

In this example tax is 9.75% (0.0975) and product cost $10.

$10 + 9.75%Tax = $10.975 which VirtueMart rounds it to $10.98

When 2 quantity or more is ordered VirtueMart adds the total so it is $10.98 + 10.98 = $21.96 which is Wrong should be

$10 + $10 = $20 + 9.75% = $21.95
However adding this way is wrong too, because what if one of the products doesn’t have tax so best solution would be not to round the tax until it is added to the cart.
$10.975 + $10.975 = $21.95 instead of $10.98 + $10.98 = $21.96

This needs to be fixed, you might think 1penny is nothing but if more quantity is added than the difference adds up and if customer notices this, than store owner has to issue a refund, which result to more fee (credit card refund fees)

(http://www.protechsystems.us/stuff/joomla/vm/vm-tax-penny-1.png)

(http://www.protechsystems.us/stuff/joomla/vm/vm-tax-penny-2.png)

Some information about tax calculation http://docs.phpcoin.com/index.php/Tax_Calculations
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: zanardi on November 01, 2010, 23:48:45 pm
This has already been included in Redmine: http://dev.virtuemart.net/redmine/issues/139.

I spent some time on it, and, believe me, this is not easy to fix. It is not "a bug" in the meaning of "a wrong line of code" or a "miscalculation". It requires that we first decide a sensible way of rounding numbers, and then apply it to every VM page that deals with prices. It will require some analysis and surely a solution will not be included in 1.1.6.
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: AH on November 10, 2010, 22:38:49 pm
aarovot

in the UK the tax is taken from the final price including tax

As each product is displayed rounded then this IS the product price including tax.

The rounding should then be forgotten when calculating the tax element in the final price including tax.

To calculate the tax element you use the total line item price and mutliply by the tax rate/100.


I had to solve this issue for my UK client on 1.1.4 and ran my thoughts by Zanardi at that time.
You cannot start from the the base price before tax

Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: leetodd1986 on September 26, 2011, 15:31:03 pm
aarovot

in the UK the tax is taken from the final price including tax

As each product is displayed rounded then this IS the product price including tax.

The rounding should then be forgotten when calculating the tax element in the final price including tax.

To calculate the tax element you use the total line item price and mutliply by the tax rate/100.


I had to solve this issue for my UK client on 1.1.4 and ran my thoughts by Zanardi at that time.
You cannot start from the the base price before tax

Hutson, I know this post is really old. but i am having this issue with virtuemart not calculating the tax properly and rounding the tax wrong by 1p. You say you solved this issue? i am just wondering how you did it? there is so much code in virtuemart that it is taking me way too long to find the specific files and lines in which to change the way tax is calculated. Just wondering if you could shed some light on this for me? I've been looking through ps_checkout and basket.php to find the calcs... am i in the right area? :)
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: stinga on September 27, 2011, 15:53:47 pm
<quote>
in the UK the tax is taken from the final price including tax
<quote>
Not sure that is quite correct....

Anyway.. The issue the tax is calculated in the item price not the item price * quantity, so it is wrong.
The other place you might see this is the currency calculation, worse case is add a product of the value of 1cent, then show it in another currency.
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: leetodd1986 on September 29, 2011, 12:48:02 pm
Im not sure if this will help anyone but it helped me...

The issue i was having is that i needed to find the tax of 1 item, say 5.99... the tax at 20% would be 1.198 or rounded to 2 (1.20)... to make the total plus tax 7.19. i then needed this total to be multiplied and the tax extracted from the total... instead of multiplying the untaxed item by the quantity then adding the tax. There were 3 files i needed to edit, ps_checkout, basket and ro_basket. If anyone needs the code i would be happy to help. but i spent weeks searching forums looking for the same issue... to no avail.. so maybe it was just be who had the issue... if there is anyone else.. i will go to the trouble of writing out instructions on how to do this.... untill then...
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: AH on October 01, 2011, 19:36:07 pm
ps_checkout.php is where the issues are.

Here is my posts to Zanardi, I have implemented VAt changes in a very busy site and it is working fine!

http://forum.virtuemart.net/index.php?topic=75346.msg250755#msg250755 (http://forum.virtuemart.net/index.php?topic=75346.msg250755#msg250755)

These are the coding lines that cause the issues!

$order_tax_details[$my_taxrate] += $product_price_tmp*$my_taxrate*$cart[$i]["quantity"];

$order_tax += $price["product_price"] * $tax_rate * $cart[$i]["quantity"];



also ps_order_change.php
//            $my_taxrate = strval(round(($product_final_price / $product_item_price) - 1,2)."00");

            $my_taxrate = strval(round(($product_final_price / $product_item_price) - 1,3)."0");



Also in these two files the rounding is out so make ro_basket round to 2

basket.php line 112         $product_price = round( $product_price, 2 );
ro_basket.php line 99       $product_price = round( $product_price, 5 );
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: stinga on October 02, 2011, 11:24:10 am
I think the correct calc should be...

tax_line = round(product_price * vat%, 2)
total_tax = tax_line * quantity

10.98 * 20% = 2.196 rounded = 2.20

2.20 * 10 = 22.00

22.00 + (10.98 * 10) = 131.80

I think for the UK the tax/vat can be calc on the total line not the individual line item (but I am no expert)

Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: hepcom on November 24, 2011, 17:23:25 pm
I recently purchased Virtuemart Canadian Taxes extension for Virtue Mart and am having issues with the default Virtuemart "total tax".  http://www.daycounts.com/en/help/virtuemart-canadian-taxes

It is rounding by one cent.  The problem is that it is calculating the total tax not the breakdown of taxes which is a difference of 1 cent.  Do you have a solution for this?  I have spent a good few hours searching and can't seem to find a solution.
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: clivemax on January 12, 2012, 21:46:17 pm
ps_checkout.php is where the issues are.

Here is my posts to Zanardi, I have implemented VAt changes in a very busy site and it is working fine!

http://forum.virtuemart.net/index.php?topic=75346.msg250755#msg250755 (http://forum.virtuemart.net/index.php?topic=75346.msg250755#msg250755)

These are the coding lines that cause the issues!

$order_tax_details[$my_taxrate] += $product_price_tmp*$my_taxrate*$cart[$i]["quantity"];

$order_tax += $price["product_price"] * $tax_rate * $cart[$i]["quantity"];



also ps_order_change.php
//            $my_taxrate = strval(round(($product_final_price / $product_item_price) - 1,2)."00");

            $my_taxrate = strval(round(($product_final_price / $product_item_price) - 1,3)."0");



Also in these two files the rounding is out so make ro_basket round to 2

basket.php line 112         $product_price = round( $product_price, 2 );
ro_basket.php line 99       $product_price = round( $product_price, 5 );


Hi folks, on vm 1.1.9 and I get the occasional 1p extra added to the tax (VAT) and therefore the total with the IPN errors rasied by Paypal - has anyone really fixed this? The solution above identifies problem lines in ps_checkout, but not what the fixes are - the link to the referred to post gives an error. Really could use some help. Many thanks in advance, Cheers

My problem is as follows:

I create a product with a gross price of £9.99, tax is 20% which calculates out as £8.326 as the net price. When a purchase goes through the shipping is added as £2.26.

The order looks like this:

Subtotal: £9.99
Shiiping: £2.26
VAT: £2.05
total: £12.26

The VAT should be £2.04!

Help!!!
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: AH on January 16, 2012, 16:49:29 pm
Yes I fixed this based on my post prior to this.
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: stinga on January 18, 2012, 00:01:18 am
Because we had the problem with currency conversion, I altered notify.php to allow 1p discrepancy in the price, nobody has complained.
Title: Re: One penny tax difference issue on every subsequent product that is added to cart
Post by: arbgor on May 27, 2012, 18:19:46 pm
I've solved the one step of this issue.

In these two files where are located in administrator/components/com_virtuemart/html the rounding is out so change value from:

basket.php line 112         $product_price = round( $product_price, 2 );
ro_basket.php line 99       $product_price = round( $product_price, 5 );

to:

basket.php line 112         $product_price = round( $product_price, 3 );
ro_basket.php line 99       $product_price = round( $product_price, 3 );

I hope that will be usefull.

Now in every step of ordering product a pirce will be rounded fine.

But in summation wchich is send to owner's e-mail prices are wrong... :(