Jump to content

Wrong Tax Calculation In Payment Module


Recommended Posts

PaymentModule.php

 

The PDF invoice shows wrong Tax=>Tax calculated for only ONE product in the Cart instead of sum of products.

 

Recommended changes for validateOrder() function:

1)use intval() for the rate

2) sum up tax += instead of =

 

CODE CHANGES:

 

1. original code:

if (!$nTax++)

$storeAllTaxes[$res->id]['amount'] = ($price * (1 + ($res->rate * 0.01))) - $price;

else{ $priceTmp = $price_wt / (1 + ($res->rate * 0.01)); $storeAllTaxes[$res->id]['amount'] = $price_wt - $priceTmp; }

1. fixed code:

if (!$nTax++)

$storeAllTaxes[$res->id]['amount'] += ($price * (intval($res->rate) * 0.01))* $quantityInStock;

else{ $priceTmp = $price_wt / (1 + (intval($res->rate) * 0.01)); $storeAllTaxes[$res->id]['amount'] += ($price_wt - $priceTmp)* $quantityInStock; }

 

2. original code:

if (!$nTax++)

$storeAllTaxes[$res->id]['amount'] += ($shippingCostTaxExcl * (1 + ($res->rate * 0.01))) - $shippingCostTaxExcl;

else{ $priceTmp = $order->total_shipping / (1 + ($res->rate * 0.01)); $storeAllTaxes[$res->id]['amount'] += $order->total_shipping - $priceTmp; }

2. fixed code:

if (!$nTax++)

$storeAllTaxes[$res->id]['amount'] += $shippingCostTaxExcl * (intval($res->rate) * 0.01);

else{ $priceTmp = $order->total_shipping / (1 + (intval($res->rate) * 0.01)); $storeAllTaxes[$res->id]['amount'] += $order->total_shipping - $priceTmp; }

 

3. original code:

Db::getInstance()->Execute('

INSERT INTO '.DB_PREFIX.'order_tax (id_order, tax_name, tax_rate, amount)

VALUES ('.(int)$order->id.', \''.pSQL($t['name']).'\', '.(float)($t['rate']).', '.(float)$t['amount'].')');

3. fixed code:

Db::getInstance()->Execute('

INSERT INTO '.DB_PREFIX.'order_tax (id_order, tax_name, tax_rate, amount)

VALUES ('.(int)$order->id.', \''.pSQL($t['name']).'\', \''.(float)($t['rate']).'\', '.(float)Tools::ps_round($t['amount'],2).')');

Link to comment
Share on other sites

  • 1 year later...
  • 3 months later...

In 1.4.7.3 it's not a rounding issue - its an actual logic issue when calculating provincial tax. There are 2 different if/else blocks that deal with the $nTax variable. I removed both blocks and only use the calculation under the original if() statement to properly calculate taxes on products/shipping in Canada/US.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...