DiscountCalc
Back to ListDescription: Calculate Discount Amount
FileMaker Prototype:
Set Variable [$res; ACF_Run("DiscountCalc"; float_qty; float_price; string_disc)]
Category: FINANCE
Function source:
Function DiscountCalc ( float qty, float price, string disc)
disc = trimboth (disc);
float discAm, discper;
if ( right( disc,1) == "%") then
discper = float(substring(disc,0, length(disc)-1))/100.0;
discAm = qty*price*discper;
else
discAm = float(disc);
end if
return discAm;
end
The DiscountCalc function calculates the discount amount from a discount field that can contain either a discount amount or a percentage discount, making the discount field on an order line more versatile.
If the discount field contains a number followed by a percent sign (%), the function calculates the line price and then applies the discount as a percentage. If there is no percent sign, the field is interpreted as a fixed discount amount.
The goal is to have a single input text field for the discount, with a calculated field for the discount amount, which this function determines.
Example
Set Field [Orderline::DiscountAm;
ACF_Run("DiscountCalc"; Orderline::qty; Orderline::price; Orderline::Discount)]
For an order line with the following values:
Orderline::qty= 10Orderline::price= 200Orderline::Discount= "25%" (This is a text field)
The Orderline::DiscountAm will be calculated as 500.
The line total can then be calculated as:
Set Field [Orderline::LineTotal;
Orderline::qty * Orderline::price - Orderline::DiscountAm]
Example 2
For an order line with the following values:
Orderline::qty= 10Orderline::price= 200Orderline::Discount= "175" (This is a text field)
The Orderline::DiscountAm will be set to 175.
