Ticket Model Mathematics

Exploring calculations and logic within Tickets and Ticket Items

The Ticket 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 Ticket model and related models like TicketItem.

Understanding Property Naming Conventions

When a financial property doesn't have the "IncludingVat" postfix, its value is indicated without including VAT. For instance, unitPrice refers to the value excluding VAT, while unitPriceIncludingVat specifies the value including VAT.

Ticket Item Mathematics

The ticketItem 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

Unit Price Including VAT

Initially, we must calculate VAT from the base amount, using the following formula:

vat=unitPriceโˆ—(vatRate/100)vat = unitPrice * ( vatRate / 100)

The "vatRate" stands for plu.vatInfo.rate. The outcome of vat is expressed as a UnitPrice, rounded mathematically to six decimal places, refered as "vat rounded". The unit price including VAT of ticket item is then calculated using following formula:

unitPriceIncludingVat=unitPrice+vatroundedunitPriceIncludingVat = unitPrice + vat_{rounded}

The outcome of second formula is expressed as a UnitPrice, rounded mathematically to six decimal places as well.

Effective Discount Rate

The discount can be placed on ticket item based on two properties:

  • The discount rate of the ticket in which the ticket item 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 ticket item 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 effective discount rate (referred to as "de") is calculated using the following formula:

de=1โˆ’(1โˆ’dt)โˆ—(1โˆ’dti)d_{e}= 1- (1 - d_{t}) * (1 - d_{ti})

The outcome is value within an interval between 0 and 1, with the value rounded mathematically to four decimal places.

Unit Price After Discount

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:

unitPriceIncludingDiscount=unitPriceโˆ’unitPriceโˆ—deunitPriceIncludingDiscount = unitPrice - unitPrice * d_{e}

The "de" stands for effective discount rate. The outcome is expressed as a UnitPrice, rounded mathematically to six decimal places.

Unit Price After Discount Including VAT

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:

unitPriceAfterDiscountIncludingVat=upโˆ’upโˆ—deunitPriceAfterDiscountIncludingVat = up - up * d_{e}

The "up" stands for unit price including VAT. The "de" stands for effective discount rate. The outcome is expressed as a UnitPrice, rounded mathematically to six decimal places.

Total Price Including VAT

The following formula is used to calculate the total price of a ticket item, including VAT:

totalPriceIncludingVat=unitPriceIncludingVatโˆ—quantitytotalPriceIncludingVat = unitPriceIncludingVat * quantity

The "quantity" stands for quantity.amount. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Total Price After Discount Including VAT

The following formula is used to calculate the total price of a ticket item after applying a discount, including VAT:

totalPriceAfterDiscountIncludingVat=upโˆ—quantitytotalPriceAfterDiscountIncludingVat = up * quantity

The "up" stands for unit price after discount including VAT. The "quantity" stands for quantity.amount. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Discount Price Including VAT

The following formula is used to calculate the total discount of a ticket item including VAT:

discountPriceIncludingVat=tpโˆ’tpddiscountPriceIncludingVat = tp - tp_{d}

The "tp" stands for total price including VAT. The "tpd" stands for total price after discount including VAT. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Ticket Mathematics

The ticket model contains following properties, relevant for mathematics:

  • discountRate: the discount rate (numeric value between 0 and 100).

  • items: collection of ticket items.

  • payments: collection of ticket payments.

  • roundingAmount: the rounding amount.

  • type: certain formulas might differ depending on the ticket type. For instance, if the ticket is of the invoice type, it won't have any elements in the `items` collection.

Payments amount of Ticket

Total amount of payments.

paymentsAmount=ฮฃ(pโˆˆpayments)p.amount.amountpaymentsAmount = ฮฃ (p โˆˆ payments) p.amount.amount

The notation represents the summation of the amount.amount property for each ticket payment within the payments collection. The expression p โˆˆ payments indicates the iteration over each element in the payments collection. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Total Price of Ticket Including VAT

Total ticket amount, including VAT, before any discounts are applied.

If ticket is of the invoice type, total price including VAT is equal to payments amount. Othewise, total price including VAT is calculated using the following formula:

totalPriceIncludingVat=ฮฃ(iโˆˆitems)i.totalPriceIncludingVattotalPriceIncludingVat = ฮฃ (i โˆˆ items) i.totalPriceIncludingVat

The notation represents the summation of the totalPriceIncludingVat property for each ticket item within the items collection. The expression i โˆˆ items indicates the iteration over each element in the items collection. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Total Price After Discount of Ticket Including VAT

Total ticket amount, including VAT, after discounts are applied.

If ticket is of the invoice type, total price after discount including VAT is calculated using the following formula:

tinvoice=paymentsAmountโˆ’roundingAmountt_{invoice} = paymentsAmount - roundingAmount

The "paymentsAmount" stands for payments amount of ticket. The "roundingAmount" stands for roundingAmount property of ticket. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Otherwise, if ticket is not of invoice type, total price after discount including VAT is calculated using the following formula:

tcashRegister=ฮฃ(iโˆˆitems)i.totalPriceAfterDiscountIncludingVatt_{cashRegister} = ฮฃ (i โˆˆ items) i.totalPriceAfterDiscountIncludingVat

The notation represents the summation of the total price after discount including VAT for each ticket item within the items collection. The expression i โˆˆ items indicates the iteration over each element in the items collection. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Total Price after Discount of Ticket Including VAT and Rounding

Total ticket amount, including VAT and rounding, after discounts are applied.

If ticket is of the invoice type, total price after discount including VAT and rounding equal to payments amount of ticket. Otherwise, if ticket is not of invoice type, total price after discount including VAT and rounding is calculated using the following formula:

totalPriceAfterDiscountIncludingVat+roundingAmounttotalPriceAfterDiscountIncludingVat + roundingAmount

The "totalPriceAfterDiscountIncludingVat" stands for total price after discount of Ticket including VAT. The "roundingAmount" stands for roundingAmount property of ticket. The outcome is expressed as a Price, rounded mathematically to two decimal places.

Examples

Example 1

Assume ticket item with the following properties:

  • 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:

vat=unitPriceโˆ—(vatRate/100)=5.363636โˆ—(10/100)=0.5363636vat = unitPrice * ( vatRate / 100) = 5.363636 * (10 / 100) = 0.5363636

To get rounded VAT, result must be rounded to 6 decimal places:

0.5363636โ‰ˆ0.5363640.5363636 โ‰ˆ 0.536364

To calculate unit price including VAT, we use formula:

unitPriceIncludingVat=unitPrice+vatrounded=5.363636+0.536364=5.90unitPriceIncludingVat = unitPrice + vat_{rounded} = 5.363636 + 0.536364 = 5.90

To calculate effective discount rate, we use formula:

de=1โˆ’(1โˆ’dt)โˆ—(1โˆ’dti)=1โˆ’(1โˆ’0)โˆ—(1โˆ’0.2)=1โˆ’(1โˆ—0.8)=0.2d_{e}= 1 - (1 - d_{t}) * (1 - d_{ti}) = 1-(1-0)*(1-0.2) = 1-(1*0.8)=0.2

To calculate unit price after discount including VAT, we use formula:

upโˆ’upโˆ—de=5.90โˆ’5.90โˆ—0.2=5.90โˆ’1.18=4.72up - up * d_{e} = 5.90 - 5.90 * 0.2 = 5.90 - 1.18 = 4.72

To calculate total price including VAT, we use formula:

totalPriceIncludingVat=unitPriceIncludingVatโˆ—quantity=5.90โˆ—1.234โ‰ˆ7.28totalPriceIncludingVat = unitPriceIncludingVat * quantity = 5.90 * 1.234 โ‰ˆ 7.28

To calculate total price after discount including VAT, we use formula:

totalPriceAfterDiscountIncludingVat=upโˆ—quantity=4.72โˆ—1.234โ‰ˆ5.82totalPriceAfterDiscountIncludingVat = up * quantity = 4.72 * 1.234 โ‰ˆ 5.82

Last updated