Add new Sale

Sale.sale_items attributes explanaion

A sale contains an array named sale_items, that contains the items (and its discount/surcharges) you want to sell.

Each item has the following important attributes:

  • department_id: The integer id of department (see /departments endpoint) related to this item, it is very important because the italian fiscal printers want to know exactly which is the department for each item sold, because for each department there is a VAT percentage ( see /vat endpoint ) that the printer know for its internal fiscal aggregates.

  • department_name: The name of related department.

  • vat_perc: The VAT percentage for this related department.

  • item_id: The integer id of item sold (not necessary but useful).

  • name: The name of the item sold,

  • price: Unit price of this item (before surcharge and discount).

  • quantity: Sold quantity of this item, can be decimal and negative in refund case.

  • type: Can be 'Sale' (quantity > 0), 'refund' (quantity < 0) or 'gift' (price = 0)

  • uuid: That identifies univocally the sale item (in UUID standard format).

  • price_changes: Each sale item can have an array of discount/surcharges that is called price_changes, and is applied to price in the order specified by each index.Each price_change is composed by:

  1. description: A textual description of this discount/surcharge.

  2. index: An integer number that is used for order apply.

  3. type: Can be:

  • discount_fix: Is if a fixed value discount, for example a discount of 1.00 €.

  • discount_perc: If is a percentage discount, for example 10 % discount.

  • surcharge_fix: If is a fixed value surcharge, for example a surcharge of 1.00 €.

  • surcharge_perc: If is a percentage value surchage, for example a surcharge of 10 %.

  1. value: Value of this discount/surcharge.

Example:

  • Case of 1.00 € discount/surcharge (discount_fix/surcharge_fix), 'value':1.00

  • Case of 10 % discount/surcharge (discount_perc/surcharge_perc), 'value':10.00

  • final_price: Unit price, with applied its surcharge and discounts and a quota of global discount/surcharges (in sale document), VAT included Example.

If a sale item has quantity 2, a price and 2 price_changes: 1st element discount_perc (index = 1) and 2nd element surcharge_fix (index = 0), and 1 global discount_fix and 1 global discount_perc

var partial_final_price = sale_item.price * sale_item.quantity

[ sale_item.price_changes[1].index = 0 ] partial_final_price = partial_final_price + sale_item.price_changes[1].value

[ sale_item.price_changes[1].index = 1 ] partial_final_price = partial_final_price ( 1 - sale_item.price_changes[0].value/100 ) Partial final price with global discount/surcharge quota:var total_discounted = sale.amount - sale.price_changes[0].value

total_discounted += sale.amount - (sale.amount * sale.price_changes[1].value/100)

var total_discount = sale.amount - total_discounted

partial_final_price = partial_final_price - (total_discount * partial_final_price / sale.amount)sale_item.final_price = partial_final_price / sale_item.quantity

  • final_net_price: Unit price, with applied surcharge and discounts, VAT excluded sale_item.final_net_price = sale_item.final_price / ( 1 + sale_item.vat_perc)

Sale attributes explanation

A sale is composed by a group of general attributes, in particular we must put attention on sale amounts, global discounts and surcharges:

  • price_changes: Each sale can have an array of discount/surcharges that is called price_changes, and is applied to amount in the order specified by each index.

Each price_change is composed by:

  1. description: A textual description of this discount/surcharge.

  2. index: An integer number that is used for order apply.

    1. type: can be:

discount_fix: Is if a fixed value discount, for example a discount of 1.00 €

discount_perc: If is a percentage discount, for example 10 % discount

surcharge_fix: If is a fixed value surcharge, for example a surcharge of 1.00 €.

surcharge_perc: If is a percentage value surchage, for example a surcharge of 10 %

  1. value: Value of this discount/surcharge. Example:

  2. Case of 1.00 € discount/surcharge (discount_fix/surcharge_fix), 'value':1.00

2.Case of 10 % discount/surcharge (discount_perc/surcharge_perc), 'value':10.00

amount: Sum of price quantity + discount/surcharges of all sale_items, global discount/surcharges (that is applied on amount*) is excluded.

Example 1: If a sale has 3 items sale_items in sale items array, each with 1 discount_fix:

sale.amount = sale.sale_items[0].quantity * sale.sale_items[0].price - sale.sale_items[0].price_changes[0].value + sale.sale_items[1].quantity * sale.sale_items[1].price - sale.sale_items[1].price_changes[0].value +sale.sale_items[2].quantity * sale.sale_items[2].price - sale.sale_items[0].price_changes[0].value

Example 2:If a sale has 2 items sale_items in sale items array, each with 1 discount_perc (index = 0) and 1 surcharge_fix (index = 1):

var partial_item_1 = sale.sale_items[0].quantity * sale.sale_items[0].price partial_item_1 = partial_item_1 - sale.sale_items[0].price_changes[0].value partial_item_1 = partial_item_1 * ( 1 + sale.sale_items[0].price_changes[1].value/10 )

var partial_item_2 = sale.sale_items[1].quantity * sale.sale_items[1].price partial_item_2 = partial_item_2 - sale.sale_items[1].price_changes[0].value partial_item_2 = partial_item_2 * ( 1 + sale.sale_items[1].price_changes[1].value/100 )

sale.amount = partial_item_1 + partial_item_2

  • final_amount: Sum of (price quantity) + discount/surcharges of all sale_items, global discount/surcharges (that is applied on amount*) is included.

Example 1A) If a sale has 3 items sale_items in sale items array, each with 1 discount_fix (like example 1), and 3 global price_changes (first with type = discount_perc and index = 0, second with type = surcharge_fix and index = 1, third with type = surcharge_perc and index = 2):

sale.final_amount = sale.amount * ( 1 - sale.price_changes[0].value/100)

sale.final_amount = sale.final_amount + sale.price_change[1].value

sale.final_amount = sale.final_amount * ( 1 + sale.price_change[1].value/100 )

final_net_amount: Is the sum of each sale_item_net_price.

Body Params
string
required
string
required
length between 3 and 30
date-time
required
integer
required
string
required
integer
string
boolean
boolean
number
string
integer
string
boolean
string
length between 0 and 16
date-time

Delivering date

string
string
e_invoice
object
string

this param can be used by external integration that needs to save a unique id associated with the sale

boolean
string | null
string
string
string
string
price_changes
array of objects
price_changes
integer
Defaults to 0
number
string
sale_customer
object
integer

used by Tilby's app to know the sales count and order

integer

it is used if this sales come from another sale. Can happen in payment split for example

string

it is used if this sales come from another sale. Can happen in payment split for example

string
number
number
sent_exits
object
string
number
string
length ≤ 25
number

Sum of price * quantity + discount/surcharges of all sale_items

number

Payment change (also known as 'resto'). This will be set by the app when the sale will be closed. It's calculated if the sum of payments is greater than final_amount of the sale

string
enum

It is "cash" when there are cash payments in the array of payments.
it is "ticket" when there are tickets and no cash payments in the array of payments.
it is "other" when there are no cash or tickets in the payments.

Allowed:
date-time

Closing (or Storing) date

number

Sum of price * quantity + discount/surcharges of all sale_items + discount/surcharges on amount

number

Sum of final_price * quantity of all sale_items

date-time
integer
integer

it is used if the order is sent to cash registry

string
enum
Defaults to normal

it is used if the order is sent to cash registry

Allowed:
string

it is used if the order is sent to cash registry

payments
array of objects
payments
sale_documents
array of objects
sale_documents
sale_items
array of objects
sale_items
string

Tilby Pass Shop ID

string
enum
required

Sale status, can be open, closed or stored

Allowed:
string

must be unique

Responses

422

Error: Unprocessable Entity

Language
Credentials
Bearer
JWT
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json