How to Calculate the VAT Amount and Produce the Invoice Trailer

Up to this point, the extended rule you have defined instructs Sterling Gentran:Server® to calculate the totals for the invoice for each of the different VAT rates. Now you will define a rule that calculates the total VAT amount and produces the invoice trailer.

First, the system will initialize the lines total amount (TLR LVLT element) and the total VAT amount payable (TLR TVAT element) to zero. Next, the system will perform the following calculations for every STL segment:

  • Set the VAT amount payable (STL VATA element) equal to the product of the lines subtotal (STL LVLA element) and the VAT rate percentage (STL VATP:2 element), divided by one hundred (to calculate the VAT payable).
  • Set the extended subtotal amount (STL EVLA element) equal to the lines subtotal (STL LVLA element), because you are not using settlement discounts in this tutorial.
  • Set the extended subtotal amount (STL ASDA element) equal to the lines subtotal (STL LVLA element), because you are not using settlement discounts in this tutorial.
  • Set the payable subtotal amount (STL APSI element) equal to the sum of the lines subtotal (STL LVLA element) and the VAT amount payable (STL VATA element).
  • Set the lines total amount (TLR LVLT element) equal to the sum of the lines total amount (TLR LVLT element) and the extended subtotal amount (STL EVLA element).
  • Set the total VAT amount payable (TLR TVAT element) equal to the sum of the total VAT amount payable (TLR VATA element) and the VAT amount payable (STL VATA element).

Finally, you want the system to repeat the calculations described above until all STL segments have been processed.