Quintiq file version 2.0
#parent: #root
Method SetDefaultValue (
  UnitPeriodQuantity unitperiodquantity
) id:Method_DialogCreateEditUnitCapacity_SetDefaultValue
{
  #keys: '[107528.0.125617753]'
  Body:
  [*
    // Set the default value for the fields in the dialog
    data := Dialog.Data();
    
    start := MacroPlan.Start();
    timeunit := MacroPlan.StartOfPlanningPeriod().TimeUnit();
    mincapacity := MacroPlan.GlobalParameters_MP().DefaultMinCapacityPerDayForUnit();
    maxcapacity := MacroPlan.GlobalParameters_MP().DefaultMaxCapacityPerDayForUnit();
    maxload := MacroPlan.GlobalParameters_MP().DefaultMaxLoadPercentage();
    nrofunitopen := 1;
    
    if( not isnull( unitperiodquantity ) )
    {
      // To inherit the value from last unit capacity while creating a new unit capacity
      unitcapacity := unitperiodquantity.UnitCapacity();
      start := unitperiodquantity.Start();
    
      if( not isnull( unitcapacity ) )
      {
        timeunit := unitcapacity.TimeUnit();
        mincapacity := unitcapacity.MinCapacity();
        maxcapacity := unitcapacity.MaxCapacity();
        maxload := unitcapacity.MaximumLoadPercentage();
        nrofunitopen := unitcapacity.NrOfUnitsOpen();
      }
      else
      {
        timeunit := unitperiodquantity.Period_MP().TimeUnit();
        mincapacity := unitperiodquantity.MinCapacity();
        maxcapacity := unitperiodquantity.MaxCapacity();
        maxload := unitperiodquantity.MaximumLoadPercentage();
        nrofunitopen := unitperiodquantity.NrOfOpen();
      }
    }
    
    // Assigning value to Read-Only attribute will result in runtime error.
    if( isnull( data.WrappedInstance() ) )
    {
      data.Start( start );
    }
    
    data.TimeUnit( timeunit );
    data.MinCapacity( mincapacity );
    data.MaxCapacity( maxcapacity );
    
    data.MaximumLoadPercentage( maxload );
    
    data.NrOfUnitsOpen( nrofunitopen );
  *]
}
