To configure the Rebates module, so that you can create new Rebate Agreements, take the following steps:
...
Element Name | Calculation Context | Groovy | Note |
---|
ProductGroup |
| api.productGroupEntry() | The conditions are typically negotiated for a group of products. |
CustomerGroup |
| api.customerGroupEntry() | The conditions are typically negotiated for a group of customers. |
RebateDiscount |
| api.userEntry("RebateDiscount") / 100.0
| The negotiated condition – in this case the discount in percentage. |
AbortOnInputGeneration |
| if (api.isInputGenerationExecution()) api.abortCalculation() | isInputGenerationExecution is supported from version 10.0, in older versions use isSyntaxCheck . |
Today |
| return api.targetDate() | This is to be able to simulate different "today". |
StartDate |
| return (api.currentItem()?.startDate) ? api.parseDate("yyyy-MM-dd",api.currentItem().startDate) : new Date() |
|
EndDate |
| return (api.currentItem()?.endDate) ? api.parseDate("yyyy-MM-dd",api.currentItem().endDate) : new Date() |
|
EndDateOrToday |
| return (api.getElement("Today") < api.getElement("EndDate")) ? api.getElement("Today") : api.getElement("EndDate") |
|
ActualSales |
| def dmCtx = api.getDatamartContext()
def salesDM = dmCtx.getDatamart("Transactions")
def datamartQuery = dmCtx.newQuery(salesDM,true)
datamartQuery.select("SUM(Invoice_Price)", "IP")
datamartQuery.where(
Filter.greaterOrEqual("Invoice_Date",api.getElement("StartDate")),
Filter.lessOrEqual("Invoice_Date",api.getElement("EndDateOrToday"))
)
datamartQuery.where(api.getElement("CustomerGroup"))
datamartQuery.where(api.getElement("ProductGroup"))
def result = dmCtx.executeQuery(datamartQuery)
return (result?.getData()?.getValue(0,0)?:0.0)
| How much money were actually spent in the time frame. The number comes from Datamart for the specified period. |
Rebate |
| def sales = api.getElement("ActualSales")
def rebatePct = api.getElement("RebateDiscount")
return (sales != null && rebatePct != null) ? (sales * rebatePct) : null
| SimpleRebate calculation – we will pay back the customer the negotiated percentage of the spendings on the given group of products. |
ForecastSales |
| def sales = api.getElement("ActualSales")
if (sales<=0) sales=0
if (sales > 0) {
def from = api.getElement("StartDate")
def to = api.getElement("EndDate")
def today = api.targetDate()
if (today > to ) return sales
else if (today < from) return 0.0
else {
int totalDays = to - from + 1
def daysofTransactions = today - from + 1
def perDaySales = sales / daysofTransactions
//api.trace("validity", from as String, to as String)
//api.trace("totalDays", totalDays)
//api.trace("daysofTransactions",daysofTransactions)
return perDaySales * totalDays
}
}
|
|
ForecastRebate |
| def sales = api.getElement("ForecastSales")
def rebatePct = api.getElement("Rebate")
return (sales != null && rebatePct != null) ? (sales * rebatePct) : null
|
|
RebateRecordCreate | Agreement | rebateRecords.add()
/*
rebateRecords.add([
"attribute1":api.getElement("Rebate"),
"attribute2":api.getElement("TotalSales"),
"attribute3":api.getElement("RebateDiscount")
])
*/
| Every agreement line will generate one Rebate Record (i.e., there will be only one payout at the end of the year). |
RRInput | RebateRecord | api.userEntry("RRInput") | This is an example of how to make an input specific for the Rebate Record. |
CalculationBase | RebateRecord | calculationBase.clear()
calculationBase.include(api.getElement("CustomerGroup"))
calculationBase.include(api.getElement("ProductGroup"))
calculationBase.include( new TimePeriod(api.getElement("StartDate"), api.getElement("EndDateOrToday"), TimeUnit.DAY) )
calculationBase.setDateFieldName("InvoiceDate")
| Calculation base specifies a filter which finds the sales transactions related to this Rebate Record. |
...