Historical Data

This utility calculates historical data in a price list for each line.

The included data:

  • Weighted averages of a List Price per unit

  • Margin per unit

  • Cost per unit

  • Margin %

  • Total value of volume for last X months

(information) The calculated data is cached using api.global, so you need to set api.retainGlobal = true in your calculation logic. 

Usage

This code checks if the data is cached or not using 'isCachedHistoricalData()'. 

def lib = libs.PriceListManagement.HistoricalPrice
if(!lib.isCachedHistoricalData()){
    //calculate 
}


This code calculates the historical data.

api.retainGlobal = true
def lib = libs.PriceListManagement.HistoricalPrice
lib.calculateHistoriCalData(12) // calculate historical data for last 12 months


This code gets the historical data for a specific SKU.

def lib = libs.PriceListManagement.HistoricalPrice

return lib.getHistoricalData(api.product("sku"))


In addition, you can get a specific piece of data for a product.

def lib = libs.PriceListManagement.HistoricalPrice

def pid = api.product("sku")

def weightedAvgListPrice = lib.getHistoricalWeightdAvgListPrice(pid)

def listPrice = lib.getHistoricalListPrice(pid)

def cost = lib.getHistoricalCost(pid)

def margin = getHistoricalMargin(pid)

def marginPercentage = lib.getHistoricalMarginPercentage(pid)

def volume = lib.getHistoricalVolume(pid)


Settings are read from the application advanced properties, however you can overwrite it and calculate data manually.

def lib = libs.PriceListManagement.HistoricalPrice

def skus = api.getBatchInfo()?.collect{it[0]}
def builder = lib.getConfiguredHistoricalQueryBuilder(skus,12)

builder.setDataMart("Datamart_Name")
builder.setProductIdColumn("ProductIdColumn")
builder.setListPriceColumn("ListPriceColumn")
builder.setCostColumn("CostColumn")
builder.setInvoiceDateColumn("InvoiceDateColumn")
builder.setQuantityColumn("QuantityColumn")
builder.setMarginColumn("marginColumn")

builder.processHistoricalData()