Step-by-step guide to creating a calculating sales form
Note: These features are part of the Visforms Subscription and are not included in the free Visforms version.
For a better understanding, we recommend reading the documentation completely and using the
Section Introduction
to start.
Relationships explained in earlier sections of the documentation are not repeated here.
The example form
A user can buy apples with this sample form: Form with calculations.
The user selects the delivery quantity for the apples he would like to purchase from a list box. If the user buys 10 kg of apples or more, they are granted a volume discount of 2.5%. 7% tax is calculated on the discounted price, if any, and a grand total is returned. Of course, you would also add fields for various contact data in a fully productive form.
The fields
The example form consists of the following fields:
Name | Type | Function |
---|---|---|
Quantity | Select | Selection of desired quantity |
Total (Euro) | Calculation | Calculates the net price from the kilogram price and the selected quantity |
Discount (Euro) | Calculation | Calculates the discount |
7% tax (euro) | Calculation | Calculates the tax on the possibly discounted price |
Total (Euro) | Calculation | Calculates total price from net price, discount and tax |
The Quantity field
The “Quantity” field is a list box type field. This has a total of 6 options. See also the screenshot for this.
Note: Please note that all values in the options list are numbers.
The standard Visforms field functionality “Custom Text” was used to insert an item image and a description.
The Total field
A simple multiplication.
The Sum field calculates the sum of the user-selected amount of apples and a set price, so it’s a simple multiplication.
Note: Please note that all numbers in the calculations must have a period as a decimal separator.
Therefore, the price is entered in the format 1.79. Irrespective of the fact that the numbers used in a calculation must always have a point as the decimal separator, you can determine the display format of the result yourself. Since a comma is usually used as the decimal separator in German-speaking countries, we have selected the value “comma” in the “Decimal separator” option. The result of the calculation is then displayed in the appropriate format and saved as such.
The “Precision” option determines to how many decimal places the calculation should be rounded to. All numerical values that are included in the calculation are rounded to this set accuracy.
The “fixed decimal places” option is used to format the result. If this option is activated, the calculated value is filled with zeros up to the selected number of decimal places. The number ‘9.9’ is then displayed as ‘9.90’ if the precision is set to 2 decimal places. If the option is disabled, zeros are not displayed at the end of the value. The number ‘9.9’ is then displayed as ‘9.9’ even if the precision of the calculation is 2 decimal places.
Since the Sum field itself can only contain a numerical value, the currency was integrated as text in the field label.
The Discount field
Using a condition in the calculation formula.
In the example form, a discount should only be given if 10 kg of apples or more are purchased. Such a condition can also be implemented with the field type Calculation. To do this, use the following syntax in general.
(Condition) ? Alternative if condition is met : Alternative if condition is not met
In our example form it looks like this:
The concrete formula in the example form is therefore:
([QUANTITY] >= 10) ?(-(([TOTAL]*2.5)/100)) : 0
If the condition ([QUANTITY] >= 10) is met, i.e. if 10 kg of apples or more have been selected, the calculation (-(([SUMME]*2.5)/100)) is performed.
This returns a negative value, namely the discount amount.
Otherwise 0 is returned.
The “Tax” field
The use of parentheses ensures that when calculating the tax, the sum and discount values are added together first.
Then 7% of this is calculated and returned as the result of the formula.
The “Total” field
The total amount is calculated in the same way as the tax is calculated.
Alternatively, it would also have been possible to simply add the three fields “Total”, “Discount” and “Tax” here.