Tuesday, October 22, 2013

Magento Correcting the default taxing module for calculating tax based on discounted price

Hello,

Lets assume your client has a requirement of calculating tax based only on the discounted price.

Like,
The price of the item with tax is 100
Discount on this item with tax is 25
The remaining amount with tax is 75

If I consider 14% as tax then the tax should be shown as 9.21 and this is already part of 75. So if I subtract 9.21 from 75 then I will get 65.78, if I calculate 14% of 65.78 then I will get 9.21 to be exact.

In Magento this seems to be difficult to achieve by default configurations as if you enter item price without tax and discount is entered or calculated with tax.

I have checked it is not possible without a custom module.

Unfortunately cannot paste the entire module here but here are few pointers for resolving such issue.

  1. Main change we need to make is in the Quote Taxing module which is responsible for all the configuration based tax calculations, like in my case I was using unit based taxing so we have switch case which needed to be edited. This is the module which will return the actual tax amount so by changing it we are making the core change for recalculating the tax.
  2. Because of the above change we have our grand total all messed up, which needed to be corrected in Quote/address/grand file.
  3. Above 2 file will ensure that the new way of calculating tax has been enforced on frontend, but back end still needed to be changed
  4. The way Magento calculates row totals is, it adds the base price with the tax amount and hence we get row totals, but if the tax is based on the discounted price then adding it to the product price will give an incorrect result, fortunately this happens only at adminhtml template level, so as it being cosmetic change only we need to change the order, invoice view and create templates.
  5. Also we need to change the invoice subtotal calculation file as the final calculations is effected as I explained earlier.
If all the above changes are in place properly then the desired change will be achieved, I have tested and developed this module.

Thanx
Anshumaan Bakshi

No comments:

Post a Comment