Quintiq file version 2.0
#parent: #root
Method SetDefaultValue (
  UnitPeriodTime unitperiodtime
) id:Method_DialogCreateEditUnitAvailability_SetDefaultValue
{
  #keys: '[136682.1.1068361498]'
  Body:
  [*
    // Set the default value for the fields in the dialog
    
    data := DataHolderDialogData.Data();
    
    start := MacroPlan.Start();
    timeunit := MacroPlan.StartOfPlanningPeriod().TimeUnit();
    maintenance := Duration::Zero();
    efficiency := 1.0;
    allocation := 1.0;
    shiftpattern := MacroPlan.DefaultShiftPattern();
    maxloadpercentage := MacroPlan.GlobalParameters_MP().DefaultMaxLoadPercentage();
    nrofunitopen := 1;
    minloadthreshold := 0.0;
    
    if( not isnull( unitperiodtime ) )
    {
      // To inherit the value from last unit availability while creating a new unit availability
      unitavailability := unitperiodtime.UnitAvailability();
      start := unitperiodtime.Start();
    
      if( not isnull( unitavailability ) )
      {
        timeunit := unitavailability.TimeUnit();
        maintenance := unitavailability.Maintenance();
        efficiency := unitavailability.Efficiency();
        allocation := unitavailability.Allocation();
        shiftpattern := unitavailability.ShiftPattern();
        maxloadpercentage := unitavailability.MaximumLoadPercentage();
        nrofunitopen := unitavailability.NrOfUnitsOpen();
        minloadthreshold := unitavailability.MinimumLoadThreshold();
      }
      else
      {
        timeunit := unitperiodtime.Period_MP().TimeUnit();
        maintenance := unitperiodtime.Maintenance();
        efficiency := unitperiodtime.Efficiency();
        allocation := unitperiodtime.Allocation();
        shiftpattern := unitperiodtime.ShiftPattern();
        maxloadpercentage := unitperiodtime.MaximumLoadPercentage();
        nrofunitopen := unitperiodtime.NrOfOpen();
        minloadthreshold := unitperiodtime.MinimumLoadThreshold();
      }
    }
    
    // Assigning value to Read-Only attribute will result in runtime error.
    if( isnull( data.WrappedInstance() ) )
    {
      data.Start( start );
    }
    
    data.TimeUnit( timeunit );
    data.Maintenance( maintenance );
    
    data.Efficiency( efficiency );
    data.Allocation( allocation );
    
    data.ShiftPattern( relset, shiftpattern );
    data.MaximumLoadPercentage( maxloadpercentage );
    
    data.NrOfUnitsOpen( nrofunitopen );
    
    data.MinimumLoadThreshold( minloadthreshold );
  *]
}
