Contract Calculation Logic Details

The Contract Calculation logic has two parts:

  1. Header logic.
  2. "Term Type" logic – the logic which is defined for Contract Term Types, but is calculated in context of the line items.

Flow of Execution

After you click the Recalculate button, items are executed in this order:

  1. Header logic (so called pre-phase execution).
  2. Term Type (line item) logic – executed for every line of the contract.
  3. Header logic (so called post-phase execution).

Usage of Header Information on Line Items

Term Type (line item) logic cannot access information available in Header, so if you need to take some information from the header and place it to the line item, you must do it in the Header Logic and pass the information to the line items via its inputs.

Header Logic

As the header logic needs to be able to:

  • Iterate through all line items.
  • Create input boxes for the folders (usually for the Root folder).
  • Create output/results for the folders.
  • Set value of various fields on the header or line items level.

it has a special variable cProcessor which you can use to do all those actions.

cProcessor Variable

In the header logic you can use the automatic variable cProcessor. This variable is NOT available in the Term Type (line item) logic.

It exposes an object of the type ContractBuilder which has the following functions specifically for Contracts:

  • getContractView() – Map of the whole Contract, including all its inputs, outputs, line items etc.
  • getHelper() – Returns a ContractHelper object which can make working with the map returned by getContractView() easier.

In addition to this, it has many other functions (which can also be found in Quote and Rebate header processors). For details see the CalculableLineItemCollectionBuilder functions.

Example of cProcessor Variable Usage

if (cProcessor.isPostPhase()) {
  return
}

def c = cProcessor.getContractView()

//get the customer and product group from lower level
def customerGroupValue = null
def productGroupValue = null

for (lineItemMap in c.lineItems) {
  if (lineItemMap.folder) continue//skip folders
  
  for (input in lineItemMap.inputs) {
        
    if ("CustomerGroup".equals(input.name)) {
      customerGroupValue = input.value
    } else if ("ProductGroup".equals(input.name)) {
      productGroupValue = input.value

Found an issue in documentation? Write to us.

Â