1418pxAs per the requirement from prospect nVent for the POC, we need to be able to show the changes between current and previous revisions of SPA (i.e. Contract) in Promotion Manager. For nVent POC, we had created two different contract term types: By Bulletin and By Product. So a SPA can have line items at the Bulletin type or Product type. In order to configure the Change History tool, we need to define the Change History element in the Contract Header Logic under Configuration → Promotion Manager → Contract Header Formulas. Here is the Groovy code that for the Contract History element that will display the Contract History element in Contract header output results.
Code for Change History element:
def roundUp(numberToRound,roundTo)
{
return Math.ceil(numberToRound/roundTo)*roundTo
}
def changeHistoryMatrix = api.newMatrix("Bulletin", "Product", "Previous Quantity", "Current Quantity", "Previous Into Stock Multiplier", "Current Into Stock Multiplier", "Previous Requested Multiplier", "Current Requested Multiplier", "Previous Gross Margin %", "Current Gross Margin %" )
def view = cProcessor.getContractView()
def prevRevUniqueName = view.prevRev
def prevRevision = api.find("CT", Filter.equal("uniqueName", prevRevUniqueName))
if (!prevRevision) {
return
}
def prevLineItemsCollection = api.getCalculableLineItemCollection(prevRevision[0].typedId)
def prevLineItems = prevLineItemsCollection?.lineItems
for (line in view.lineItems) {
if (line.folder) continue
def currentBulletin = line.outputs?.find { it.resultName == "Bulletin" }?.result
def currentProduct = line.outputs?.find { it.resultName == "Product" }?.result
def currentQuantity = line.outputs?.find { it.resultName == "Quantity" }?.result
def currentIntoStockMultiplier = line.outputs?.find { it.resultName == "IntoStockMultiplier" }?.result
def currentRequestedMultiplier = line.outputs?.find { it.resultName == "RequestedMultiplier" }?.result
def currentGrossMargin = line.outputs?.find { it.resultName == "GrossMarginPercent" }?.result
def currentGrossMarginPercent = roundUp((currentGrossMargin * 100),2) + " %"
for (prevLine in prevLineItems) {
if (prevLine.folder) continue
def prevBulletin = prevLine.outputs?.find { it.resultName == "Bulletin" }?.result
def prevProduct = prevLine.outputs?.find { it.resultName == "Product" }?.result
def prevQuantity = prevLine.outputs?.find { it.resultName == "Quantity" }?.result
def prevIntoStockMultiplier = prevLine.outputs?.find { it.resultName == "IntoStockMultiplier" }?.result
def prevRequestedMultiplier = prevLine.outputs?.find { it.resultName == "RequestedMultiplier" }?.result
def prevGrossMargin = prevLine.outputs?.find { it.resultName == "GrossMarginPercent" }?.result
def prevGrossMarginPercent = roundUp((prevGrossMargin * 100),2) + " %"
if (prevBulletin == currentBulletin && prevProduct == currentProduct) {
changeHistoryMatrix.addRow([
"Bulletin" : currentBulletin,
"Product" : currentProduct,
"Previous Quantity" : prevQuantity,
"Current Quantity" : currentQuantity,
"Previous Into Stock Multiplier" : prevIntoStockMultiplier,
"Current Into Stock Multiplier" : currentIntoStockMultiplier,
"Previous Requested Multiplier" : prevRequestedMultiplier,
"Current Requested Multiplier" : currentRequestedMultiplier,
"Previous Gross Margin %" : prevGrossMarginPercent,
"Current Gross Margin %" : currentGrossMarginPercent
])
}
}
}
cProcessor.addOrUpdateOutput (
"ROOT",
[ "resultName" : "ChangeHistory",
"resultLabel": "Change History",
"result" : changeHistoryMatrix,
"resultType" : "MATRIX"
]
)
Contract Calculation Results (Unity UI):
Change History (Unity UI):