Customize Amounts
iDynamics Commissions includes several events that let customers customize how the different sales amounts are calculated.
Sales Amount
For iDynamics Commissions, the amount of any sales lines is the line amount before taxes, and before any payment discounts, in local currency. This amount will be used in statistics, when the amounts sold by each salesperson are shown, and as the commission base, if commissions have been configured to use this value.
If you want to customize it, the IDPCOS_OnBeforeGetSalesAmountLCY event, raised by the Sales Line, Sales Invoice Line and Sales Cr.Memo Line tables, will let you alter the way it is calculated.
local procedure IDPCOS_OnBeforeGetSalesAmountLCY(var SalesInvoiceLine: Record "Sales Invoice Line"; var SalesAmountLCY: Decimal; var Handled: Boolean)
The event receives the (sales, sales invoice or sales credit memo) line for which we want to calculate its sales amount, a SalesAmountLCY that lets you specify a custom amount, and a Handled variable, that will tell iDynamics Commissions that this value has been already calculated if set to true.
You can also subscribe to the IDPCOS_OnAfterGetSalesAmountLCY event, on the same tables, if you just want to make adjustments to amount calculated by the app.
Line Cost
The cost will be used to calculate the profit margin of the line. By default, iDynamics Commissions uses the costs calculated by Business Central (including the adjusted cost, if it has changed since the sales invoice was posted), but you can override this by subscribing to the IDPCOS_OnBeforeGetTotalCostLCY event, raised by the tables Sales Line, Sales Invoice Line and Sales Cr.Memo Line (if you reference iDynamics Commissions in your app):
local procedure IDPCOS_OnBeforeGetTotalCostLCY(var SalesCrMemoLine: Record "Sales Invoice Line"; var TotalCostLCY: Decimal; var Handled: Boolean)
The event receives the (sales, sales invoice or sales credit memo) line for which the commissions are going to be calculated, a TotalCostLCY that lets you specify a custom cost in local currency, and a Handled variable, that will tell iDynamics Commissions that this value has been already calculated if set to true.
Profit Margin
This amount is the result of subtracting the total cost for the line (unit cost x quantity) from the value returned by the previous method. It can be customized using the IDPCOS_OnBeforeGetProfitMarginAmountLCY event, also raised by tables Sales Line, Sales Invoice Line and Sales Cr.Memo Line:
local procedure IDPCOS_OnBeforeGetProfitMarginAmountLCY(var SalesInvoiceLine: Record "Sales Invoice Line"; var ProfitMarginAmountLCY: Decimal; var Handled: Boolean)
The event receives the (sales, sales invoice or sales credit memo) line for which we want to calculate its profit margin, a ProfitMarginAmountLCY that lets you specify a custom amount, and a Handled variable, that will tell iDynamics Commissions that this value has already been calculated if set to true.
For direct commissions, this method will be called each time a sales invoice or a sales credit memo is posted. For commissions based on sales targets, though, this method will be called when the commission period is posted.
Base Amount
Both direct commissions and sales targets can be configured to use sales amounts or profit margins. The app uses a GetBaseAmountLCY method that will call one of the two previous methods, depending on the configured value. This can also be customized using the OnBeforeGetBaseAmountLCY event, raised by the table IDPCOS Commiss. Sales Line:
local procedure OnBeforeGetBaseAmountLCY(var TempCommissSalesLine: Record "IDPCOS Commiss. Sales Line"; BaseAmountCalcType: Enum "IDPCOS Base Amount Calc. Type"; var BaseAmountLCY: Decimal; var Handled: Boolean)
This method receives as a parameter the type of amount to use (base or margin) and invokes one of the two methods mentioned previously in this document.
Line Discount
If you want to customize the effective line discount for a sales line or learn how the app calculates it by default:
- The app first calculates the Actual price applied to the line, which is the amount obtained after applying the Line Discount % to the (Unit Price * Quantity) and, to the result, applies the Invoice Discount %. The result is divided by the amount. The Payment Discount is not taken into account. That is, it is the "VAT Base Amount" field of the line divided by the quantity + "Pmt. Discount Amount" divided by the quantity.
- This price is compared with the default sales price that Business Central would have applied by default to the line.
In summary, the effective discount % is: (default sales price - actual price applied) / default sales price.
This means that iDynamics Commissions will treat any of these as discounts:
- Manually changing the unit price.
- Assigning a discount % to the line.
- Applying a document discount (except payment discounts).
Finally, if you want to customize this calculation, you can subscribe to the OnAfterCalculateProfitabilityAndRealLineDiscount in the temporal table IDPCOS Commiss. Sales Line. When commissions are generated, the app creates a copy of the source sales line in this table and raises the event after calculating the profit margin and the line discount. You can update the Real Line Discount % field, in order to set a different discount % that will be used when checking commission rates and generating commissions.