This article explains how to show changes between current and previous revisions of a Contract in PromotionManager. an Agreement/Promotion. In this particular case we had created two different contract term typesCondition Types: By Bulletin and By Product. So a Contract an Agreement/Promotion can have line items of the Bulletin or Product type. In order to configure the Change History tool, we need to define the Change History element in Configuration in Administration > Promotion Manager > Contract Logics > Agreements & Promotions Header Logics. Here is the Groovy code that will display the Contract History element in Contract in Agreement/Promotion header output results.
Code Block |
---|
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" ] ) |
...