Tax Calculation Bugs

Tax Calculation Bugs

Postby chris.tikkos@.....com » Thu Sep 01, 2011 4:48 pm

There are a few calculation bugs that need to be repaired; basically they are Virtuemart bugs but they still exist in OPC unfortunately:

BUG 1: After placing an order and checking out, the invoice emailed to the customer and store admin doesn't add the shipping tax to the Tax Total , however the Grand total shows the correctly calculated amount. (When NOT using “Show prices including tax”)

In /administrator/components/com_virtuemart/classes/ps_onepage.php

Look for this code:

if ($auth["show_price_including_tax"] == 1) {

$order_shipping = $db->f("order_shipping");
$order_shipping += $db->f("order_shipping_tax");
$order_shipping_tax = 0;
$order_tax = $db->f("order_tax") + $db->f("order_shipping_tax");
}
else {

$order_shipping = $db->f("order_shipping");
$order_shipping_tax = $db->f("order_shipping_tax");
$order_tax = $db->f("order_tax");

}

and replace with this:

if ($auth["show_price_including_tax"] == 1) {

$order_shipping = $db->f("order_shipping");
$order_shipping += $db->f("order_shipping_tax");
$order_shipping_tax = 0;
$order_tax = $db->f("order_tax") + $db->f("order_shipping_tax");
}
else {

$order_shipping = $db->f("order_shipping");
$order_shipping_tax = $db->f("order_shipping_tax");
// $order_tax = $db->f("order_tax");
$order_tax = $db->f("order_tax") + $db->f("order_shipping_tax");

}

BUG 2: with the Sub Total including the item tax in the Purchase Order email sent to the shopper and vendor (in case you are using “Show prices including tax”)

In /administrator/components/com_virtuemart/classes/ps_onepage.php

Look for this code:

if ($auth["show_price_including_tax"] == 1) {
$sub_total += ($dboi->f("product_quantity") * $dboi->f("product_final_price"));
$shopper_message .= $CURRENCY_DISPLAY->getFullValue($dboi->f("product_final_price"), '', $db->f('order_currency'));

and change to:

if ($auth["show_price_including_tax"] == 1) {
$sub_total += ($dboi->f("product_quantity") * $dboi->f("product_item_price"));
$shopper_message .= $CURRENCY_DISPLAY->getFullValue($dboi->f("product_final_price"), '', $db->f('order_currency'));

(The product_final_price is changed to product_item_price)
chris.tikkos@.....com
 
Posts: 22
Joined: Fri Aug 05, 2011 12:07 pm

Re: Tax Calculation Bugs

Postby admin » Sun Sep 04, 2011 1:15 pm

Hello Chris,
thank you for the report. The situation with the tax counting and tax issues is that most of my customers have a custom modification of the tax and therefore my component shows the taxes as they come out from original virtuemart functions. I also added couple of checkboxes which modify how the tax is displayed but actual tax calculation is always done by virtuemart. For example tax counting is a large issue when using paypal new api because virtuemart counts tax on order subtotal and also shipping (unfortunately it does not count tax on payment fee which is another nightmare). The problem with tax is that by counting the tax twice (subtotal+shipping) it can lead to 2 cents rounding issue which leads for paypal payment not to be accepted. Virtuemart does not take into considaration rounding to 50 cents as several countries do. Also tax rounding in most countries is not rounded mathemetically but by a rule set in a law: for exmple here in Slovakia we round tax to the floor of hundreds (1.009 = 1.00). Also if you are selling items which have the VAT included in the price and you round them to 2 decimals, the tax should be counted from this rounded price and not from the actual product price without VAT which is usually a 6 decimal number.

This all leads to modifications of ps_checkout tax counting functions and this is the main reason why our component does not alter tax counting functions.

Tax Calculation Bugs

chris.tikkos@gmail.com » Štv Sep 01, 2011 3:48 pm
There are a few calculation bugs that need to be repaired; basically they are Virtuemart bugs but they still exist in OPC unfortunately:

BUG 1: After placing an order and checking out, the invoice emailed to the customer and store admin doesn't add the shipping tax to the Tax Total , however the Grand total shows the correctly calculated amount. (When NOT using “Show prices including tax”)

Please check get_tax_rate() function in your shipping module and search for $taxrate in list_rates($d) if it takes into consideration your $auth['show_price_including_tax']. There was several changes in the latest virtuemart releases. Especially the state field did many problems with the actuall tax rate when not using it.
In /administrator/components/com_virtuemart/classes/ps_onepage.php

Look for this code:

if ($auth["show_price_including_tax"] == 1) {

$order_shipping = $db->f("order_shipping");
$order_shipping += $db->f("order_shipping_tax");
$order_shipping_tax = 0;
$order_tax = $db->f("order_tax") + $db->f("order_shipping_tax");
}
else {

$order_shipping = $db->f("order_shipping");
$order_shipping_tax = $db->f("order_shipping_tax");
$order_tax = $db->f("order_tax");

}

and replace with this:

if ($auth["show_price_including_tax"] == 1) {

$order_shipping = $db->f("order_shipping");
$order_shipping += $db->f("order_shipping_tax");
$order_shipping_tax = 0;
$order_tax = $db->f("order_tax") + $db->f("order_shipping_tax");
}
else {

$order_shipping = $db->f("order_shipping");
$order_shipping_tax = $db->f("order_shipping_tax");
// $order_tax = $db->f("order_tax");
$order_tax = $db->f("order_tax") + $db->f("order_shipping_tax");

}

This will only alter the view of the order receipt if the checkbox is not checked at the email tab [NOT RECOMMENDED checkbox]. The reason why i included my own email function was that VM < 1.1.6 sent emails from customer's email address which lead to marking the email server as SPAM server. Nowadays many hosting providers don't allow sending email in the name of email address which is not registered within the server.

I rather recommend to modify your email template than this code as this code is 95 percent original ps_checkout->email_receipt function. By modifying email template you can also change the table layout.

Also summing of $db->f('... without checking it's type (number, null, string) can lead to a fatal error.

BUG 2: with the Sub Total including the item tax in the Purchase Order email sent to the shopper and vendor (in case you are using “Show prices including tax”)

In /administrator/components/com_virtuemart/classes/ps_onepage.php

Look for this code:

if ($auth["show_price_including_tax"] == 1) {
$sub_total += ($dboi->f("product_quantity") * $dboi->f("product_final_price"));
$shopper_message .= $CURRENCY_DISPLAY->getFullValue($dboi->f("product_final_price"), '', $db->f('order_currency'));

and change to:

if ($auth["show_price_including_tax"] == 1) {
$sub_total += ($dboi->f("product_quantity") * $dboi->f("product_item_price"));
$shopper_message .= $CURRENCY_DISPLAY->getFullValue($dboi->f("product_final_price"), '', $db->f('order_currency'));

(The product_final_price is changed to product_item_price)


This was fixed in the latest release when comparing ps_onepage to ps_checkout in VM 1.1.9. In the next release we might not include our own email receipt function as it seems that most VM bugs were fixed by now.
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm


Return to One Page Checkout for Virtuemart 1.1.x