Expression examples

Ready-made expressions for the most common cases: a price the cashier types in, an extra charge for a container, prices by size or weight, a special price for one customer, a free item in a set menu, and how much material to write off for each portion. Copy an expression, change the parameter number to yours, and it works in the POS, in orders and in order proposals.

For the basics of expressions, see Expressions.

Which example do I need?

I want to…Example
let the cashier type the pricePrice typed in by the cashier
add a deposit or a take-away container to the priceExtra charge by choice
sell one product in two or three sizesTwo or three prices
sell by weight, with a price per kilogramPrice by weight
sell by grams, with a price per kilogramPrice by grams
give one customer a different pricePrice for one customer
include an item for free in a set menuFree item in a set menu
write off a different amount of material for each portionMaterial write-off by portion

Before you start

Most examples need three things: a parameter (the question the POS asks, such as the price or the size), that parameter on the article, and the expression on the article.

1. Create the parameter

Open Technology → Parameters and click +.

New parameter

#FieldWhat to enter
1NameWhat the cashier will see, for example Price with VAT or Size.
2Field of useProduct.
3TypeThe type the example asks for: Number, Dropdown, Weight or Category.
4CreateCreates the parameter and opens it.

On the parameter page, tick Required (1). Then the POS always asks for the value when the article is added. For a Dropdown, add the choices with + on the right.

Required

Each parameter has a number, shown in the Id column of the list (1). In an expression you write it as p(46), which means "the value of parameter 46". Replace the numbers in the examples with your own.

Parameter Id

2. Add the parameter to the article

Open the article (Technology → Articles), open the Parameters tab (1) and Product parameters (2), click + and choose the parameter (3). The list shows the number and the name, for example #46 - Price with VAT.

Product parameters

3. Enter the expression

On the article's Options tab, click the pencil next to Price expression. Paste the expression (1) and click Confirm (3). Under the text the editor shows the expression with parameter names instead of numbers (2), so you can check that the number is right.

Expression editor

If you don't see Price expression, tick Extended information in your user settings (your picture → User account).

4. Prices and VAT on the article

The article has five price rows. In expressions they are called getPrice() (first row), getPrice1() (second), getPrice2() (third), getPrice3() and getPrice4().

Price rows

  • Price (1) is without VAT. Expressions work with these amounts.
  • Total price (2) is with VAT. You can type the price with VAT here and Smarton fills in the price without VAT.
  • VAT (3) must be set. The POS adds it to the result of the expression.
  • Price expression (4) shows the expression in short.

5. In the POS

When the cashier adds the article, the POS asks for the parameter (1) and adds the line after Add (2). The chosen value is shown under the line, and the price is calculated with the expression. To change the value, the cashier taps i on the line.

The POS asks for the price

The examples below in one test order:

Test order with all examples

Good to know

  • The examples use orderProposalProduct and orderProposal. The same expression also works in orders and the POS; Smarton translates these words there.
  • A dropdown choice is compared by its name, in quotes, written exactly as in the parameter: p(47) == "32".
  • If the expression gives no result, for example because of a typo or an empty value, the line price is 0. Try a new expression on a test order first.
  • After you change an expression, open orders with that article get the new price the next time the order changes.
  • If the POS shows prices on the menu buttons, a button shows the article's first price, not the result of the expression.

Price typed in by the cashier

For products whose price changes every time. The cashier types the price with VAT, and Smarton saves it without VAT.

Set up: a required Number parameter, for example Price with VAT, in the article's product parameters. The article must have VAT.

(p(46) * 100) / (100 + orderProposalProduct.getArticle().getVat().getPercentage())

How it works: p(46) is the price the cashier typed. Multiplying by 100 and dividing by 100 + the VAT rate removes VAT. With 21 % VAT, 3.50 becomes 2.89 without VAT, and the POS shows 3.50 € again. See the POS window in Before you start.

Extra charge by choice

For a deposit or a take-away container that is added to the price, depending on what the cashier chooses.

Set up: a required Dropdown parameter, for example Container, with the choices IndasBOLT, Indas 0.60€, Indai WOLT and No container.

(p(48) == 'IndasBOLT'
    ? orderProposalProduct.getProduct().getArticle().getPrice() + 0.7851
  : p(48) == 'Indas 0.60€'
    ? orderProposalProduct.getProduct().getArticle().getPrice() + 0.4959
  : p(48) == 'Indai WOLT'
    ? orderProposalProduct.getProduct().getArticle().getPrice() + 0.7851
  : orderProposalProduct.getProduct().getArticle().getPrice())

How it works: each p(48) == '…' ? A : B checks one choice: if it matches, the price is A, otherwise the next check runs. The last part is the price when nothing matches, here the article price.

The added amounts are without VAT: 0.7851 + 21 % = 0.95 € and 0.4959 + 21 % = 0.60 €. To add an amount with VAT, divide it by 1.21 (for 21 % VAT). In the test order, a 5.00 € soup with IndasBOLT costs 5.95 €.

Choosing a container

Two or three prices

For one product in several sizes, each with its own price, for example a 32 cm and a 42 cm pizza.

Set up: a required Dropdown parameter, for example Size, with the choices 32, 42 and 52. Enter the prices in the article's first, second and third price rows.

Three prices:

p(47) == "32"
    ? orderProposalProduct.getProduct().getArticle().getPrice()
  : p(47) == "42"
    ? orderProposalProduct.getProduct().getArticle().getPrice1()
  : orderProposalProduct.getProduct().getArticle().getPrice2()

Size 32 gets the first price row, 42 the second, and any other size the third.

Two prices:

p(47) == "32"
    ? orderProposalProduct.getProduct().getArticle().getPrice()
  : orderProposalProduct.getProduct().getArticle().getPrice1()

Size 32 gets the first price row, any other size the second. Keep the last part (after the last colon): without it, a size that is not listed gets the price 0.

Price by weight

For goods sold by weight. Enter the price of one kilogram in the first price row.

Set up: a required Weight parameter, for example Weight. In the POS the cashier types the weight in kilograms, or reads it from a connected scale with the scale button (1).

orderProposalProduct.getProduct().getArticle().getPrice() * p(49)

In the test order, 20 €/kg × 0.35 kg = 7.00 €.

Weight in the POS

Price by grams

For goods with a price per kilogram, when the cashier enters grams.

Set up: a required Number parameter, for example Grams. Enter the price of one kilogram in the first price row.

(orderProposalProduct.getArticle().getPrice() * p(50)) / 1000

In the test order, 30 €/kg and 150 g = 4.50 €.

Price for one customer

For a customer who gets a different price, for example under a contract. No parameter is needed.

Set up: enter that customer's price in the second price row and the usual price in the third. Find the customer's number: open Sales → Customers and the customer; the number at the end of the address, for example …/customers/36, is the customer's ID. You can also show the ID column in the customer list's column settings.

(orderProposal.getCustomer().getId() == '36'
    ? orderProposalProduct.getProduct().getArticle().getPrice1()
  : orderProposalProduct.getProduct().getArticle().getPrice2())

Customer 36 gets the second price row, everyone else the third. In the POS the order's customer is the table's customer or the default customer. When the cashier changes the customer of the order, the prices are calculated again (see Change an order).

Free item in a set menu

For a set menu where the guest chooses, for example, a drink. The drink is included in the set for free, but costs its usual price when ordered on its own.

Set up:

  1. Put the drinks in their own article category, for example Menu drinks.
  2. Create a Category parameter, for example Drink, and tick Required. In its Filter, click the filter button, click +, choose the key Categories.name, type the category name as the value and click Confirm. The POS then offers only the articles of that category.
  3. Add the parameter to the set menu article as a product parameter.
  4. On each drink, enter this price expression:
(orderProduct.getParentOrderProduct() != null
    ? 0.0
  : orderProposalProduct.getProduct().getArticle().getPrice())

How it works: when the cashier adds the set menu, the POS asks for the drink and adds it as a sub-line of the set. A sub-line belongs to another line, so the drink costs 0. Ordered on its own, the drink has its usual price. A sub-line that costs 0 is not shown in the POS order or on the receipt.

Choosing a drink for the set

Material write-off by portion

For one material sold in different portions, for example a drink sold by the 40 ml shot or as a 0.7 l bottle. The expression tells Smarton how much of the material to write off. It is a Quantity expression of the material, not a price expression.

Set up: a required Dropdown parameter, for example Portion, with the choices 40ml and 0.7l, in the article's product parameters. On the article's Materials tab, add the material and click the pencil next to Quantity expression (2).

Three choices:

p(51) == "40ml" ? 0.04 : p(51) == "0.7l" ? 0.7 : 0

Two choices:

p(51) == "40ml" ? 0.04 : 0.7

Quantity expression of a material

  • The result is the amount of material for one item, in the material's unit (here litres). A result of 0 means the Standard quantity (1) is used.
  • The quantity is calculated when the order's production is created. In the POS this happens when the order is confirmed, if the article has Uses production and Auto production creation ticked on its Options tab.
  • Stock changes only if Auto reserve or Auto move to production (3) is on for the material.

The price of the portions can come from the same parameter, as in Two or three prices.

Parts of an expression

PartMeaning
p(46)The value of parameter 46.
==, !=Equal, not equal. Text goes in quotes: p(47) == "32".
A ? B : CIf A is true, then B, otherwise C. Chain several for more choices.
+ - * /Add, subtract, multiply, divide. Use a dot for decimals: 0.7851.
orderProposalProduct.getProduct().getArticle().getPrice()The article's first price, without VAT. getPrice1() … getPrice4() are the next rows.
orderProposalProduct.getArticle().getVat().getPercentage()The article's VAT rate, for example 21.
orderProposal.getCustomer().getId()The ID of the order's customer.
orderProduct.getParentOrderProduct()The line this line belongs to, if it is a sub-line; otherwise empty (null).