Share via


ProjEmplTrans::costAmountDisplayCache Method

Calculates the cost amounts for multiple transactions and returns a map of the transaction IDs to cost amounts in a container.

Syntax

server public static container costAmountDisplayCache(
    container _conProjEmplTrans, 
    container _conProjEmplTransSalesAmount, 
    TransDate _ledgerFromDate, 
    TransDate _ledgerToDate)

Run On

Server

Parameters

  • _conProjEmplTrans
    Type: container
    A packed set of transaction IDs.
  • _conProjEmplTransSalesAmount
    Type: container
    A packed map of String to Real. It can be empty or can already contain elements.

Return Value

Type: container
A packed map of transaction IDs to cost amounts.

Remarks

The ProjEmplTrans.costAmount method is used to calculate the amounts.

If _conProjEmplTrans contains transaction IDs that are already in _conProjEmplTransSalesAmount, the cost amount will be recalculated and updated in the map.

Set _ledgerFromDate to the dateNull method and _ledgerToDate to the dateMax method to include all postings for the transactions in the cost calculation.

Examples

This example creates and loads two maps with cost and sales amounts for hours transactions for a specific project. For the purposes of this example the maps used to cache the data are declared and initialized locally, but typically they would be declared in the class declaration of a form and initialized in the form's init method.

public void loadEmplTramsAmountCache() 
{ 
    ProjEmplTrans    projEmplTrans; 
    Set              projEmplTransSet; 
    Map              salesAmountCache; 
    Map              costAmountCache; 
    TransDate        ledgerFromDate; 
    TransDate        ledgerToDate; 
  
        // Initialize sets and maps 
    projEmplTransSet    = new Set(Types::String); 
    salesAmountCache    = new Map(Types::String, Types::Real); 
    costAmountCache     = new Map(Types::String, Types::Real); 
    // Get the hours transactions for a project and add to the  set. 
    while select projEmplTrans 
        where projEmplTrans.ProjId == "9004" 
    { 
        // In this example this check is unnecessary, because we know the 
        // cache is empty, but in the typical case where the cache is global 
        // this should be done to avoid needlessly recalculating the amounts 
        // for transactions already in the cache. 
        // Assumes saleAmountCache and costAmountCache are always in sync. 
        if (! salesAmountCache.exists(projEmplTrans.TransId)) 
        { 
            projEmplTransSet.add(projEmplTrans.TransId); 
        } 
    } 
 
    if (! projEmplTransSet.empty()) 
    { 
        // Set dates to include all ledger postings for each transaction 
        ledgerFromDate  = dateNull(); 
        ledgerToDate    = dateMax(); 
         // Load the maps 
        salesAmountCache = Map::create(ProjEmplTrans::salesAmountDisplayCache(projEmplTransSet.pack(),salesAmountCache.pack(),ledgerFromDate,ledgerToDate)); 
        costAmountCache  = Map::create(ProjEmplTrans::costAmountDisplayCache(projEmplTransSet.pack(),costAmountCache.pack(),ledgerFromDate,ledgerToDate)); 
    } 
}

See Also

Reference

ProjEmplTrans Table