For NC160
Description:
A better (correct) way to calculate taxes over the order and discounts. Particularly (Dutch, European) way of tax calculation. Code base and changes are for reference usage.
Algorithm perfected to calculate tax percentage over discount when assigned to whole order or order level discount has been added. (see function GetDiscountAmount() in price helper) This calculation can work on shopping cart or on order (reverse calculation proof).
When we have the tax component over discount amount ( as there is no tax category for discount on order level), this should be deducted from OrderTotal. Based on user selection for Incl. or Excl tax display GetDiscount amount can be called to get discount amout incl or excl tax.
In the Order table we always store discount amount incl tax. So if a user selection was incl. tax, then this amount is displayed as is, otherwise recalculation can be done using function GetDiscountAmount() function on order level.
Details tax calculation table displays this on the OrderTotal page and on the PDF invoice. The table is not required and can be removed if needed, it is placed there for testing purposes for checking if the algorithm works consistently on shopping cart and on saved order.
Files affected:
/Libraries/Nop.BusinessLogic/OrderManager.cs
/Libraries/Nop.BusinessLogic/ShoppingCartManager.cs
/Libraries/Nop.BusinessLogic/TaxManager.cs
/Libraries/Nop.BusinessLogic/PDFHelper.cs
/Libraries/Nop.BusinessLogic/PriceHelper.cs
/NopCommerceStore/Modules/OrderDetails.ascx (cs)
/NopCommerceStore/Modules/Ordersummary.ascx (cs)
/NopCommerceStore/Modules/OrderTotals.ascx (cs)
changes:
1. Function GetDiscountAmount(…) is added to calculate discount with tax in PriceHelper.cs file (Line 327) as
public static decimal GetDiscountAmount(ShoppingCart Cart, Customer customer, bool includesTax)
2. Function GetOrderDiscount(..) in ShoppingCartManager.cs line 1284. has been overloaded with extra parameter includeTax to get order discount with or without tax.
3. Function GetDiscountAmount(Order order, Customer customer, bool includingTax) in PriceHelper.cs, its same as function added in point 1 above except it works on order instead of shopping cart reverse engineering (for re-calculation). Line number 474.
4. Function GetOrderBTWCalculation(Order order) has been added in PriceHelper.cs at line number 588, it gives a datatable to describe how the calculation is done. (Placed on invoice for tax administration).
5. Function BindData() in OrderDetails.cs adjusted to get discountStr with or without tax line number 176.
6. OrderControl.ascx and OrderTotals.ascx.cs has been changed to display tax calculation detail box on page and calculation is done in .cs file.
7. Function GetTaxTotal (..) has been changed (line number 276) to call PriceHelper.GetDiscountAmount() function to get discount amount incl. and excl. tax.
8. Some other cosmetic changes has been made in OrderSummary.ascx, OrderDetails.ascx and respective .cs file to show tax suffix string at relevant places and also show vat % in form of article.
9. After all these changes order can be saved as incl. and excl tax and displayed accordingly on PDF invoice.
10. For displaying tax calculation detail box some new resource strings have been added(should be added accordingly in new source).
11. Changes in above changed source files can be searched with “Archifact SSA” text.
12. Function PlaceOrder(..) in OrderManager has been changed (line number 2837)to call ShoppingCartManager.GetShoppingCartSubTotal() with including tax (true), in order to get discout amout incl tax (we always store discount amount incl tax in order).
13. ShoppingCartManager.GetShoppingCartSubTotal() has been changed(line number 563)to return discount amount incl or excl tax.
Screen Prints (cosmatic changes)
Shopping cart order totals:
http://www.archifact.nl/fotos/416_37.png
Customer order details page:
http://www.archifact.nl/fotos/417_37.png
PDF invoice:
http://www.archifact.nl/fotos/418_37.png
You can download the whole package here.