Conditional Logic How to calculate commission amount with minimum and maximum?

Conditional Logic How to calculate commission amount with minimum and maximum?

We expect different commission structure for different Accounts. And each Account may or may not have floor and/or ceiling commission. What is the best way to find the commission for each deal?

Preface
Each "Lender (Account module)" has following fields that dictates "Compensation Rule."
  • Commission Percentage
  • Minimum Amount (If the commission amount is lower than this number, the commission will default to this number)
  • Maximum Amount (If the commission amount is higher than this number, the commission will default to this number)
Each "Transaction (Deal module)" has "Loan Amount" field and a "Lender" lookup field.

Desired Result
"Loan Amount," and based on the "Lender's" "Compensation Rule," it will calculate the "Commission Amount."

What is the best approach?
What is the best module/app to utilize this custom formula?
Custom scripting for a fields "Commission Amount" in Zoho CRM
Custom Module in Zoho CRM
or Invoice in Zoho CRM

Automation is to execute whenever "Lender (lookup field)" has "Loan Amount (currency field)," in the "Transaction" module is not empty. Then, it will use the values in the "Lender" for the Commission Percentage, Maximum Amount, and Minimum Amount fields, to calculate the following:

Min(Max(${Lender.Commission Rate}*${Transactions.Loan Amount},${Lender.Minimum Amount}),${Lender.Maximum Amount})