Ticket Model Mathematics
Exploring calculations and logic within Tickets and Ticket Items
Last updated
Was this helpful?
Exploring calculations and logic within Tickets and Ticket Items
Last updated
Was this helpful?
The model is defined without supplementary financial properties. Instead, these additional properties can be calculated on the client's side. This article explains how the math works in the model and related models like .
The model contains following properties, relevant for mathematics:
unitPrice
: price per single quantity unit, excluding VAT.
quantity.amount
: the amount of product or service
discountRate
: the discount rate (numeric value between 0 and 100).
plu.vatInfo.Rate
: VAT rate percentage
plu.isDiscountAllowed
: indicates whether discount can be applied to ticket item
Initially, we must calculate VAT from the base amount, using the following formula:
The discount can be placed on ticket item based on two properties:
The effective discount rate (referred to as "de") is calculated using the following formula:
The outcome is value within an interval between 0 and 1, with the value rounded mathematically to four decimal places.
The plu.isDiscountAllowed
specifies, whether discount can be applied to ticket item. When value is false
, unit price after discount is equal to unit price. However, when plu.isDiscountAllowed
is set to true
, the following formula is used to calculate the unit price after applying a discount:
The plu.isDiscountAllowed
specifies, whether discount can be applied to ticket item. When value is false
, unit price after discount including VAT is equal to unit price including VAT. However, when plu.isDiscountAllowed
is set to true
, the following formula is used to calculate the unit price after applying a discount, including VAT:
discountRate
: the discount rate (numeric value between 0 and 100).
roundingAmount
: the rounding amount.
Total amount of payments.
unit price = 5.363636
quantity = 1.234
discount rate = 20%
vat rate = 10%
is discount allowed = yes
Unit price including VAT, VAT must be is calculated first, using following formula:
To get rounded VAT, result must be rounded to 6 decimal places:
To calculate unit price including VAT, we use formula:
To calculate effective discount rate, we use formula:
To calculate unit price after discount including VAT, we use formula:
To calculate total price including VAT, we use formula:
To calculate total price after discount including VAT, we use formula:
The "vatRate" stands for plu.vatInfo.rate
. The outcome of vat is expressed as a , rounded mathematically to six decimal places, refered as "vat rounded". The unit price including VAT of is then calculated using following formula:
The outcome of second formula is expressed as a , rounded mathematically to six decimal places as well.
The discount rate of the in which the is located (the ticket.discountRate
property, referred to as "dt" in the formula below). The value is normalized within an interval between 0 and 1, with the value rounded mathematically to four decimal places.
The discount rate of the itself (the ticketItem.discountRate
property, referred to as "di" in the formula below). The value is normalized within an interval between 0 and 1, with the value rounded mathematically to four decimal places.
The "de" stands for . The outcome is expressed as a , rounded mathematically to six decimal places.
The "up" stands for . The "de" stands for . The outcome is expressed as a , rounded mathematically to six decimal places.
The following formula is used to calculate the total price of a , including VAT:
The "quantity" stands for quantity.amount
. The outcome is expressed as a , rounded mathematically to two decimal places.
The following formula is used to calculate the total price of a after applying a discount, including VAT:
The "up" stands for . The "quantity" stands for quantity.amount
. The outcome is expressed as a , rounded mathematically to two decimal places.
The following formula is used to calculate the total discount of a including VAT:
The "tp" stands for . The "tpd" stands for . The outcome is expressed as a , rounded mathematically to two decimal places.
The model contains following properties, relevant for mathematics:
items
: collection of .
payments
: collection of .
type
: certain formulas might differ depending on the . For instance, if the ticket is of the invoice
, it won't have any elements in the `items` collection.
The notation represents the summation of the amount.amount
property for each within the payments
collection. The expression p ∈ payments
indicates the iteration over each element in the payments collection. The outcome is expressed as a , rounded mathematically to two decimal places.
Total amount, including VAT, before any discounts are applied.
If ticket is of the invoice
, total price including VAT is equal to . Othewise, total price including VAT is calculated using the following formula:
The notation represents the summation of the totalPriceIncludingVat
property for each within the items
collection. The expression i ∈ items
indicates the iteration over each element in the items collection. The outcome is expressed as a , rounded mathematically to two decimal places.
Total amount, including VAT, after discounts are applied.
If ticket is of the invoice
, total price after discount including VAT is calculated using the following formula:
The "paymentsAmount" stands for . The "roundingAmount" stands for roundingAmount
property of . The outcome is expressed as a , rounded mathematically to two decimal places.
Otherwise, if ticket is not of invoice
, total price after discount including VAT is calculated using the following formula:
The notation represents the summation of the for each within the items
collection. The expression i ∈ items
indicates the iteration over each element in the items collection. The outcome is expressed as a , rounded mathematically to two decimal places.
Total amount, including VAT and rounding, after discounts are applied.
If ticket is of the invoice
, total price after discount including VAT and rounding equal to . Otherwise, if ticket is not of invoice
, total price after discount including VAT and rounding is calculated using the following formula:
The "totalPriceAfterDiscountIncludingVat" stands for . The "roundingAmount" stands for roundingAmount
property of . The outcome is expressed as a , rounded mathematically to two decimal places.
Assume with the following properties: