Hello @sturgulster
Thank you very much for using our plugin. The equation code will depend on your business logic.
I’ll try to describe the process with a hypothetical example.
Assuming you plan to sell tiles and want to enable users to input the room’s length and width, each box of tiles covers 2 square meters and is priced at $25. Based on the dimensions provided by the user, you will calculate the number of tile boxes needed for their project, as well as the total cost. Additionally, if the project requires more than five boxes, a 10% discount will be applied to the final price.
First, insert two number fields for width and length. I’ll call them fieldname1, and fieldname2.
Second, insert a calculated field to calculate the number of boxers (fieldname3). In this case, the equation needs to calculate the area to cover, and divide it by the area covered by the tile box:
CEIL(fieldname1*fieldname2/2)
Finally, insert the calculated field that calculates the project’s cost. It will use the quantity calculated by the previous field and apply the discount if proceeds:
PREC(fieldname3*25*IF(5<fieldname3, 0.9, 1), 2)
The PREC(X, Y) rounds the number X with Y decimals. Since the result is a currency, we want to round it with two decimals.
I used two calculated fields to give the users additional information like the number of boxes required for their projects. However, if you want to calculate the price only, you can implement the process with a unique calculated field, and the equation could be implemented as follows:
(function(){
let quantity = CEIL(fieldname1*fieldname2/2);
return PREC(quantity*25*IF(5<quantity, 0.9, 1), 2);
})()
Best regards.