Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
import net.pricefx.common.api.FieldFormatType

import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType
import static net.pricefx.server.dto.calculation.ResultMatrixGrouping.AggregateFunctionType.SUM

def filter = [
        Filter.equal("name", "ListPrice"),
]

List<String> fields = ["ProductId", "ListPrice", "Currency"]

def listPriceItems = api.find("PX3", 0, api.getMaxFindResultsLimit(), "ProductId", fields, *filter)

def rows = listPriceItems

def columnFormats = [
        "ProductId": FieldFormatType.TEXT,
        "ListPrice": FieldFormatType.MONEY,
        "Currency" : FieldFormatType.MONEY,
]

def resultMatrix = api.newMatrix()
        .withEnableClientFilter(true)
        .withColumnFormats(columnFormats)
        .withRows(rows)
        .withGroupBy(['Currency'])
        .withColumnAggregation('ListPrice', SUM)
        .calculateGroupByData()

return resultMatrix

Result

...