PORTOS Developers
  • 👋Introduction
  • 📖Glossary
  • HTTP Status codes
  • Error models
  • Error codes
  • Validation constraints
  • Resource names
  • 🔒User rights
  • Device environments
  • 🌍Localization
  • 🔍NData query syntax
  • OpenAPI specification
  • Data models
  • Authentication
    • 🔐Authentication schemes
      • JWT Bearer Authentication
      • HMAC Authentication
  • ⚡Notifications
    • SignalR
    • Webhooks
  • API reference
    • 🔑API keys
    • 🛍️Article categories
    • 💼Companies
    • 💱Currencies
    • 👫Customers
    • 📈Daily sales reports
    • 🖥️Devices
    • 🖨️Fiscals
    • ❤️Health check
    • 📃License
    • 🎚️Modifiers
    • 👨‍🍳Order endpoints
    • 🛎️Orders
    • 🪙Payment types
    • ☕Plus
    • 🔏Roles
    • 🔐Sessions
    • ⚙️Settings
    • 🔎Stock takings
    • 🔢Stock transfer numbering
    • 🚚Stock transfers
    • 📦Stocks
    • 🧾Tickets
      • Ticket Model States
      • Ticket Operations and User Rights
      • Ticket Model Mathematics
    • 👨‍💼Users
    • ⚖️Vats
    • 🪑Zones
  • 3rd Party Integrations
    • Introduction
    • Online orders API
    • Rewards API
    • PDA Files
  • Previous versions
    • Migration to V4.1
    • Migration to V4
    • Legacy documentation
Powered by GitBook
On this page
  • Ticket Item Mathematics
  • Unit Price Including VAT
  • Effective Discount Rate
  • Unit Price After Discount
  • Unit Price After Discount Including VAT
  • Total Price Including VAT
  • Total Price After Discount Including VAT
  • Discount Price Including VAT
  • Ticket Mathematics
  • Payments amount of Ticket
  • Total Price of Ticket Including VAT
  • Total Price After Discount of Ticket Including VAT
  • Total Price after Discount of Ticket Including VAT and Rounding
  • Examples
  • Example 1

Was this helpful?

  1. API reference
  2. Tickets

Ticket Model Mathematics

Exploring calculations and logic within Tickets and Ticket Items

PreviousTicket Operations and User RightsNextUsers

Last updated 1 year ago

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 .

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 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)vat=unitPrice∗(vatRate/100)

Effective Discount Rate

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.

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:

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:

Total Price Including VAT

Total Price After Discount Including VAT

Discount Price Including VAT

Ticket Mathematics

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

  • roundingAmount: the rounding amount.

Payments amount of Ticket

Total amount of payments.

Total Price of Ticket Including VAT

Total Price After Discount of Ticket Including VAT

Total Price after Discount of Ticket Including VAT and Rounding

Examples

Example 1

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

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

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.

de=1−(1−dt)∗(1−dti)d_{e}= 1- (1 - d_{t}) * (1 - d_{ti})de​=1−(1−dt​)∗(1−dti​)
unitPriceIncludingDiscount=unitPrice−unitPrice∗deunitPriceIncludingDiscount = unitPrice - unitPrice * d_{e}unitPriceIncludingDiscount=unitPrice−unitPrice∗de​

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

unitPriceAfterDiscountIncludingVat=up−up∗deunitPriceAfterDiscountIncludingVat = up - up * d_{e}unitPriceAfterDiscountIncludingVat=up−up∗de​

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:

totalPriceIncludingVat=unitPriceIncludingVat∗quantitytotalPriceIncludingVat = unitPriceIncludingVat * quantity totalPriceIncludingVat=unitPriceIncludingVat∗quantity

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:

totalPriceAfterDiscountIncludingVat=up∗quantitytotalPriceAfterDiscountIncludingVat = up * quantitytotalPriceAfterDiscountIncludingVat=up∗quantity

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:

discountPriceIncludingVat=tp−tpddiscountPriceIncludingVat = tp - tp_{d}discountPriceIncludingVat=tp−tpd​

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.

paymentsAmount=Σ(p∈payments)p.amount.amountpaymentsAmount = Σ (p ∈ payments) p.amount.amountpaymentsAmount=Σ(p∈payments)p.amount.amount

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:

totalPriceIncludingVat=Σ(i∈items)i.totalPriceIncludingVattotalPriceIncludingVat = Σ (i ∈ items) i.totalPriceIncludingVattotalPriceIncludingVat=Σ(i∈items)i.totalPriceIncludingVat

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:

tinvoice=paymentsAmount−roundingAmountt_{invoice} = paymentsAmount - roundingAmounttinvoice​=paymentsAmount−roundingAmount

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:

tcashRegister=Σ(i∈items)i.totalPriceAfterDiscountIncludingVatt_{cashRegister} = Σ (i ∈ items) i.totalPriceAfterDiscountIncludingVattcashRegister​=Σ(i∈items)i.totalPriceAfterDiscountIncludingVat

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:

totalPriceAfterDiscountIncludingVat+roundingAmounttotalPriceAfterDiscountIncludingVat + roundingAmounttotalPriceAfterDiscountIncludingVat+roundingAmount

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:

vat=unitPrice∗(vatRate/100)=5.363636∗(10/100)=0.5363636vat = unitPrice * ( vatRate / 100) = 5.363636 * (10 / 100) = 0.5363636vat=unitPrice∗(vatRate/100)=5.363636∗(10/100)=0.5363636
0.5363636≈0.5363640.5363636 ≈ 0.5363640.5363636≈0.536364
unitPriceIncludingVat=unitPrice+vatrounded=5.363636+0.536364=5.90unitPriceIncludingVat = unitPrice + vat_{rounded} = 5.363636 + 0.536364 = 5.90unitPriceIncludingVat=unitPrice+vatrounded​=5.363636+0.536364=5.90
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.2de​=1−(1−dt​)∗(1−dti​)=1−(1−0)∗(1−0.2)=1−(1∗0.8)=0.2
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.72up−up∗de​=5.90−5.90∗0.2=5.90−1.18=4.72
totalPriceIncludingVat=unitPriceIncludingVat∗quantity=5.90∗1.234≈7.28totalPriceIncludingVat = unitPriceIncludingVat * quantity = 5.90 * 1.234 ≈ 7.28totalPriceIncludingVat=unitPriceIncludingVat∗quantity=5.90∗1.234≈7.28
totalPriceAfterDiscountIncludingVat=up∗quantity=4.72∗1.234≈5.82totalPriceAfterDiscountIncludingVat = up * quantity = 4.72 * 1.234 ≈ 5.82totalPriceAfterDiscountIncludingVat=up∗quantity=4.72∗1.234≈5.82
🧾
effective discount rate
unit price including VAT
effective discount rate
unit price after discount including VAT
total price including VAT
total price after discount including VAT
payments amount
payments amount of ticket
total price after discount including VAT
payments amount of ticket
total price after discount of Ticket including VAT
Ticket
Ticket
TicketItem
ticketItem
UnitPrice
ticket item
UnitPrice
ticket
ticket item
ticket item
UnitPrice
UnitPrice
ticket item
Price
ticket item
Price
ticket item
Price
ticket
ticket items
ticket payments
ticket type
type
ticket payment
Price
ticket
type
ticket item
Price
ticket
type
ticket
Price
type
ticket item
Price
ticket
type
type
ticket
Price
ticket item