Here's an example of a function contained in a file named CalculateCommission.PRG. This function determines the commission for a sale based on a complex formula: if the sale amount is over $1,000, the commission is 12%; between $500 and $1,000, it's 10%; between $100 and $500, it's 8%; and there's no commission for sales less than $100.

lparameters SaleAmount
do case
  case SaleAmount >= 1000
    Commission = SaleAmount * 0.12
  case SaleAmount >= 500 and SaleAmount < 1000
    Commission = SaleAmount * 0.10
  case SaleAmount >= 100 and SaleAmount < 500
    Commission = SaleAmount * 0.08
  otherwise
    Commission = 0
endcase
return Commission

To use this function in a commission report, create a new report and add the desired fields, including the sale amount field. Then, turn on the "Advanced layout" option and click Edit to bring up the Advanced Report Designer. Create a new field and enter the following for the field's expression:

CalculateCommission(VRP_CONTACT_OPPORTUNITY.OPPORTUNITY_TOTAL)

(VRP_CONTACT_OPPORTUNITY.OPPORTUNITY_TOTAL is the name of the field in this example that contains the sale amount).

Turn on the Show 1000 separator and Display $ settings, and set Decimals to 2. Click OK to close the Formula Editor. The formula appears in the Available Fields list. Add it to the Selected list. When you run the report, it shows the commission calculation for each sale.


© Keystroke.ca, 2018 • Updated: 11/14/18
Comment or report problem with topic