The calculations below show how the NationalTax is calculated. Note that rounding can be up or down since the resulting NationalTax value is allowed to fall in a precision tolerance interval based on the number of line items.
Calculation when TransactionDiscount is zero
NationalTax = (sum of (LineItem Total x LineItem TaxRate) / 10000) + (ShippingAmount x ShippingTaxRate) / 10000
Calculation when TransactionDiscount is not zero
The TransactionDiscount is spread across some or all of the line items resulting in an additional discount for these line items.
Let’s call the LineItem Total of the affected line items, reduced LineItem Total. Then,
NationalTax = (sum of (reduced LineItem Total x LineItem TaxRate) / 10000) + (ShippingAmount x ShippingTaxRate) / 10000.
For the above calculation, a maximum and minimum tax amount is obtained by sorting line items in ascending and descending order respectively according to LineItem TaxRate.