Let’s Calculate the Total Amount Automatically

I’m wondering whether you would like to add an automatic money calculation function to the workflow App for goods purchasing requests. You have to calculate not only the totals and subtotals, but you also have to change the formula depending on the conditions.

In this post, I would like to illustrate how to implement a system that not only calculates the total amount based on the purchase list but also does a discount calculation which deducts 50% from payments exceeding $1000 of the total amount using a split in the workflow diagram. A Table-type Data Item and a Service Task (Data Assignment) are vital elements for the design of the App.

Calculation of the Total Amount with a Table Data Item

First of all, we’d like you to create an App, setting a Table-type Data Item for listing the purchased items and make it calculate the total automatically.

Workflow Diagram

Please create a new App and set up the workflow diagram as follows:

Data Items

Let’s prepare the following data items.

Name Data Type Field Name Remarks
Title String-type / Text Box single line
Purchase list Table q_purchase_list Set 4 sections, Description (String)/ Unit Price (Numeric)/ Quantity (Numeric)/ Subtotal (Numeric)
Total Numeric-type q_total Automatically input total value of: Purchase list–Subtotal

Settings of “Purchase List”

In “Purchase List” (Table-type Data Item) you should add 4 table columns, which are labeled respectively “Description”, “Unit Price”, “Quantity”, and “Subtotal”.

In the Subtotal column, the subtotal of each row in the table is calculated and saved. Please remember to check the box “Show total value at the bottom of list” as well.

Then, you should set up the Data Item of Total so that it saves the total value of the Table-type Data Item using the arithmetic expression property. The expression is automatically inserted into the text box.

Settings of Data editing permission

Please set up as in the following figure.

Enter Confirm
Title Editable Only display
Purchase list Editable Only display
Total No display Only display

You’ve created an app that calculates the total amount from the Purchase list using a Table Data Item. Please save and release it now and see how it works.

When you finish the Task after entering the unit price and quantity of an item in the Purchase list, the total amount will be saved in the Total section.

Discount Calculations Using Service Task (Data Assignment)

Now, let’s implement the workflow that performs automatic calculations under the condition of a 50% discount for payments where the total is over $1000.

Workflow Diagram

Let’s add changes to the initial workflow diagram which you made as follows:

Set a Service Task (Data Assignment) in each split flow where the condition of the Task is set to more than $1000 and less than $1000 in the total amount. That enables the token to advance to the Task and set the condition of a 50% discount for payments exceeding $1000 in the total amount.

Settings in Exclusive Gateway (XOR)

You use an Exclusive Gateway (XOR) to control the flow based on whether the total amount is over $1000.

You have to add a flow for cases of over $1000 and set its destination to “Discount”, whereas you set the destination of the Default Flow to “No Discount”.

For the condition of the “Total” which is set over $1000, the Conditional Expression Setting is set as follows.

This setting enables the token to advance to the “Discount Processing” Task if the “Total” is over $1000, whereas the token advances to the “No Discount” Task if the total is less than $1000.

Settings of Data Item

Please add a Numeric-type Data Item of “Total Discounted Amount” to save the discounted total.

Name Data Type Field Name Remarks
Total Discounted Amount Numeric-type q_discounted_total
Enter Confirm
Total Discounted Amount No display Only display

Settings in “Service Task (Data Assignment)”

Let’s set up two Service Tasks (Data Assignment) respectively for “No Discount” and “Discount”.

No Discount

Set up the expression for the “Total” which is less than $1000. Since it will not apply any discount, the value of Total should be saved in the Total Discounted Amount data item.

Discount

Set up the expression for the “Total” which is over $1000. A 50% discount is given to the amount over $1000 so the expression is set as follows:

1000 + (#q_total – 1000) * 0.5
* For the Numeric-type, numbers below the range of decimal digits specified in the settings of the Data item are removed (e.g. if the range of decimal digits is 0, then the result of 1.5 (3 * 0.5) becomes 1 due to removing the first decimal place). The same thing will perform in the Numeric- type of table columns.

The settings of the App are now complete. You have to save and release and see how it works. In particular, I would like you to check that splitting by the “Total” is working and for any mistakes in discount calculations.

Use of an Arithmetic Expression Property (Numeric-type Data Item)

This time, I used a “Service Task (Data Assignment)” for the discount calculations to cope with the splitting process. However, the arithmetic expression property in a Numeric-type Data Item can be used for arithmetic operations, as well. For example, you can achieve a 50% discount by setting the same expression as the “Discount” Task as in the figure below. However, you should remember that the arithmetic expression property can’t set a split condition for a 50% discount for payments over $1000.

You cannot embed data with field name (e.g. # q _ total) in the arithmetic expression property of a Numeric- type Data Item. Please write data [‘ 1 ’] using the data item number, which is located in the modeler’s “Data Item” tab and the right of the subject text box of each data item.

Although within the properties of a Numeric-type Data Item it is not possible to change expressions according to any conditions, it may not be necessary if the App doesn’t require a splitting process. Please use the property according to the implementation you want.

As explained above, the use of a Table- type Data Item and Service Task (Data Assignment) will make it possible to perform various calculations. Questetra BPM Suite will help with troublesome monetary calculations that can change the formula according to the conditions faster without bothering any staff members.

3 thoughts on “Let’s Calculate the Total Amount Automatically”

  1. Pingback: Numeric-Type – Questetra Support

  2. Pingback: Table-Type – Questetra Support

  3. Pingback: Service Task (Data Assignment) – Questetra Support

Comments are closed.

%d bloggers like this: