Quintiq file version 2.0
#parent: #root
Method SetDefaultValue (
  UnitPeriodTransportTime unitperiodtransport
) id:Method_DialogCreateEditTransportAvailability_SetDefaultValue
{
  #keys: '[135040.0.3056409]'
  Body:
  [*
    // Set the default value for the fields in the dialog
    
    data := Dialog.Data();
    
    start := MacroPlan.Start();
    timeunit := MacroPlan.StartOfPlanningPeriod().TimeUnit(); 
    maintenance := Duration::Zero();
    lotsize := 0.0;
    minperlot := 0.0;
    minquantity := MacroPlan.GlobalParameters_MP().DefaultMinCapacityPerDayForUnit();
    maxquantity := MacroPlan.GlobalParameters_MP().DefaultMaxCapacityPerDayForUnit();
    shiftpattern := data.Unit().MacroPlan().DefaultShiftPattern();
    numberofunit := 1;
    
    if( not isnull( unitperiodtransport ) )
    {
      // To inherit the value from the last transport capacity while creating a new one.
      transportcapacity := unitperiodtransport.TransportAvailability();
      start := unitperiodtransport.Start();
    
      if( not isnull( transportcapacity ) )
      {
        timeunit := transportcapacity.TimeUnit();
        maintenance := transportcapacity.Maintenance();
        lotsize := transportcapacity.LotSize();
        minperlot := transportcapacity.MinimumPerLot();
        minquantity := transportcapacity.MinimumQuantity();
        maxquantity := transportcapacity.MaximumQuantity();
        shiftpattern := transportcapacity.ShiftPattern();
        numberofunit := transportcapacity.NumberOfUnit();
      }
      else
      {
        timeunit := unitperiodtransport.Period_MP().TimeUnit();
        maintenance := unitperiodtransport.Maintenance();
        lotsize := unitperiodtransport.LotSize();
        minperlot := unitperiodtransport.MinimumPerLot();
        minquantity := unitperiodtransport.MinimumQuantity();
        maxquantity := unitperiodtransport.MaximumQuantity();
        shiftpattern := unitperiodtransport.ShiftPattern();
        numberofunit := unitperiodtransport.NrOfOpen();
      }
    }
    
    // Assigning value to Read-Only attribute will result in runtime error.
    if( isnull( data.WrappedInstance() ) )
    {
      data.Start( start );
    }
    
    data.TimeUnit( timeunit );
    data.NrOfTimeUnit( 1 );
    data.Maintenance( maintenance );
    data.LotSize( lotsize );
    data.MinimumPerLot( minperlot );
    data.MinimumQuantity( minquantity );
    data.MaximumQuantity( maxquantity );
    data.ShiftPattern( relset, shiftpattern );
    data.NumberOfUnit( numberofunit);
  *]
}
