Formulas
Fieldpine allows you to enter formulas in several places to control operation. This goes beyond simply using formulas for pricing and monetary use, to also using formulas as control expressions. For example, you can specify a "formula" to control if products are visible at specific POS terminals.
The expression engine is originally based on Blake Madden's tinyexpr++, which itself is based on Lewis Van Winkle's TinyExpr
Syntax
Formulas are specified as text strings, without the leading Y= concept. For example the expression Y=A+B is simply entered as "A+B".
Examples
The function fdl$date() is used to load various dates and times, see below
Runtime Execution Notes
Formulas are typically used to decide if something should happen or not. This is a true/false type decision. However, you may need to use variables that aren't defined, which would cause the expression to be invalid. Therefore in most places, a value of zero will be added for unknown variables. This means you can define a formula such as
= or(Perth,SydneyB,activecustomer.female)The variable "activecustomer.female" will only have a value if the current sale has a customer attached. If no customer is attached, then the result of this formula would be FALSE, even if the variable "Perth" is true. However, by forcing the variable "activecustomer.female" to zero, the formula can and will return TRUE for Perth users.
Function fdl$date()
This function converts a date/time to a numeric value that can be used for comparisons. It can convert either literal dates or selected keywords
Keyword | Result |
fdl$date(today) | Current Date without time. Or to be more precise, time is set to 00:00 (beginning of the day) |
fdl$date(now) | Current date and time |
fdl$date(todayutc) | Current UTC Date without time |
fdl$date(nowutc) | Current UTC date and time |
fdl$date(yesterday) | Equivalent to today - 1day |
fdl$date(tomorrow) | Equivalent to today + 1day |
fdl$date(month) |
Date at first of the current month, without time. If the keyword month has a -N or +N after it, the date is moved back/forward
N months.
For example if fdl$date(today) is 23 August, then fdl$date(month) is 1 August, and fdl$date(month-2) is 1 June |
fdl$date(year) | Date at the beginning of the year. If the keyword year has a -N or +N after it, the date is moved back/forward N years. |
All others |
Interpret the value as a literal date/time. The prefered format is DD-MMM-YYYY HH:MM
( 23-Aug-2017 14:54 )
Do not use the formats DD-MM-YYYY or MM-DD-YYYY (where month is a two digit number) as it is ambiguous as to which format is being used. The function will decode this format, but you should consider this translation as luck and subject to change. Contact support about this and you will be told to use a different format. You can use the format YYYY-MM-DD |
The numeric value of the date/time is not intended to be used to calculate time differences. You can use Dx > Dy to compare two dates. You cannot add/subtract two dates to try and get a time difference. The value of Dx - Dy does not generally contain a useable value. If the result of Dx - Dy is more than 24 hours though, the value will be >= 1