Quintiq file version 2.0
#parent: #root
Method SetDefaultValue (
  UnitPeriodTransportQuantity unitperiodtransportquantity
) id:Method_DialogCreateEditTransportCapacity_SetDefaultValue
{
  #keys: '[113694.0.1526783783]'
  Body:
  [*
    // Set the default value for the fields in the dialog
    
    data := Dialog.Data();
    
    start := MacroPlan.Start();
    timeunit := MacroPlan.StartOfPlanningPeriod().TimeUnit();
    lotsize := 0.0;
    mincapacity := MacroPlan.GlobalParameters_MP().DefaultMinCapacityPerDayForUnit();
    maxcapacity := MacroPlan.GlobalParameters_MP().DefaultMaxCapacityPerDayForUnit();
    
    if( not isnull( unitperiodtransportquantity ) )
    {
      // To inherit the value from the last transport capacity while creating a new one.
      transportcapacity := unitperiodtransportquantity.TransportCapacity();
      start := unitperiodtransportquantity.Start();
    
      if( not isnull( transportcapacity ) )
      {
        timeunit := transportcapacity.TimeUnit();
        mincapacity := transportcapacity.MinimumCapacity();
        maxcapacity := transportcapacity.MaximumCapacity();
        lotsize := transportcapacity.LotSize();
      }
      else
      {
        timeunit := unitperiodtransportquantity.Period_MP().TimeUnit();
        mincapacity := unitperiodtransportquantity.MinimumQuantity();
        maxcapacity := unitperiodtransportquantity.MaximumQuantity();
        lotsize := unitperiodtransportquantity.LotSize();
      }
    }
    
    // Assigning value to Read-Only attribute will result in runtime error.
    if( isnull( data.WrappedInstance() ) )
    {
      data.Start( start );
    }
    
    data.TimeUnit( timeunit );
    data.MinimumCapacity( mincapacity );
    data.MaximumCapacity( maxcapacity );
    data.LotSize( lotsize );
  *]
}
