Quintiq file version 2.0
#parent: #root
Method GenerateMatrixData () id:Method_FormCostManagement_GenerateMatrixData
{
  #keys: '[127710.1.439019647]'
  Body:
  [*
    // Generate account cost in period shadow instances
    // Clear data holder
    DataHolderShadowGlobalParameters.Data( null( shadow[GlobalParameters_MP], owning ) );
    
    //Ownership on GP so that it is possible to show multi rows when multiple accounts are selected.
    owner := shadow( MacroPlan.GlobalParameters_MP() );
    
    DataHolderShadowGlobalParameters.Data( &owner );
    
    traverse( DataHolderMatrixEditorRows.Data(), Elements, rowheadercost ) // For each ROW
    {
      traverse ( DataHolderMatrixEditorColumns.Data(), Elements, p )
      {
        maxcost := maxselect( rowheadercost, AccountAssignment.AccountCost, ac,
                              ac.OwnerID() = rowheadercost.OwnerID()
                              and ac.Account_MP() = rowheadercost.Account_MP()
                              and ac.CostDriver() = rowheadercost.CostDriver()
                              and ac.Start() <= p.StartDate(),
                              ac.Start() );
    
        if( rowheadercost.istype( ProductValueAndCost ) )
        {
          maxcost := maxselect( rowheadercost.astype( ProductValueAndCost ),
                                Product_MP.ProductValueAndCost,
                                pc,
                                pc.OwnerID() = rowheadercost.OwnerID()
                                and pc.Account_MP() = rowheadercost.Account_MP()
                                and pc.CostDriver() = rowheadercost.CostDriver()
                                and pc.Start() <= p.StartDate(),
                                pc.Start() );
        }
    
        if( not isnull( maxcost ) )
        {
          this.CreateShadowAccountCostInPeriod( p,
                                                maxcost,
                                                rowheadercost );
        }
      }
    }
  *]
}
