June 15, 2010

Fix for ASPDotNetStorefront Order Receipt VAT calculation issues

Filed under: Tips — Tags: , — Webopius @ 9:38 am

This article resolves a potential issue for UK (and possibly other European) websites running ASPDotNetStorefront MLv9 (up to at the time of writing).

It helps solve the problem where an order receipt sent to the Customer and displayed within the Admin pages calculates and displays the product prices and discounts incorrectly due to VAT.

VAT Calculations in ASPDNSF

In version 9 of ASPDotNetStorefront (and some earlier releases), products that have their prices stored excluding VAT/Tax store the price to 4 decimal places, as an example:

4.2574 plus 17.5% VAT (probably increasing soon!) = 5.002445 = £5.00 on screen rounded to 2 decimal places.

Unfortunately, the order receipt XSLT extension (ReceiptXsltExtension) doesn’t get this quite right and calculates to 2 decimal places before adding the VAT like this:

4.26 plus 17.5% VAT = 5.005 = £5.01 on screen which of course is not ideal.
In addition, any discount amounts in the order receipt are shown excluding VAT.

Fix for VAT rounding in ASPDotNetStorefront

To resolve this, you need to edit /App_Code/ReceiptXsltExtension.cs (make a backup first!). Within the ‘PreComputeLineItemIntrinsics’ method at about line 613, change the price calculation to 4 decimal places:

price = Math.Round(price, 4, MidpointRounding.AwayFromZero);

This will resolve the VAT problem. Then, to fix the discount issue, add the following code after the ‘displayExtPrice’ block at about line 630:

if (!isAKit && !isAPack) {
discount = (( Math.Round(displayPrice, 2, MidpointRounding.AwayFromZero)*quantity) - displayExtPrice);
discount = Math.Round(discount, 2, MidpointRounding.AwayFromZero);

That’s it. Give your site a few seconds to rebuild the new code and now, your order receipts should be correctly calculated.

Note: No warranty or support can be provided with this code. Make the change at your own risk!

  • Tags