...
Calculating Rebate Agreements
During the negotiation of a Rebate Agreement, the end user can click on the Recalculate button on the Rebate Agreement detail page.
When this button is clicked, then:
The Rebate Header Logic is executed in PrePhase mode.
For each Line Item, the system will execute that Rebate Calculation Logic, which is associated with the Rebate Type of the Line Item.
The Rebate Header Logic is executed in PostPhase mode.
The results/outputs are returned back to the UI and displayed to the user.
When submitted, the Rebate Agreement is locked for editing, recalculated and saved, the approval workflow steps are generated and workflow steps are executed.
Once the Rebate Agreement is locked for editing, it cannot be recalculated manually. It will only be recalculated each time you open it on the screen, but only within the "agreement read-only" context of the calculation logic. Note that in the read-only mode, the header logic is not run, only line items are recalculated. Such result is not saved, only displayed in the UI.
Because the Logics are executed during the negotiation of the Rebate Agreement, i.e., before any transactions have taken place, the rebate amount cannot be calculated yet. Therefore, this calculation typically results in forecasts and estimations of what the final rebate amount may be.
In order for the rebate amount to be calculable, the Logic needs to produce at least one object of the type Rebate Record (RR). This is achieved with the Groovy API method rebateRecords.add()
. The Rebate Record holds a reference to the Line Item’s Rebate Type, and the copies of all the Line Item input and output values. How the Rebate Record is used to calculate the rebate amounts is described in the next chapter.
...