Quintiq file version 2.0
#parent: #root
Method EditTransportAvailabilityFromListUnitPeriodTransportTime (
  internal[GUIComponent] parent,
  structured[UnitPeriodTransportTime] selection
) id:Method_DialogCreateEditTransportAvailability_EditTransportAvailabilityFromListUnitPeriodTransportTime
{
  #keys: '[121458.0.772017541]'
  Body:
  [*
    // Edit the capacity of the selection unit period times from periods list
    
    isbatchedit := selection.Size() > 1;
    Dialog.ShowHideComponentForBatchEdit( isbatchedit, false, true );
    
    uptt := selection.Element( 0 );
    // Need this for excluding itself in pre-condition primary keys checking.
    data := shadow( uptt.TransportAvailability() );
    
    // In case selection.Element( 0 ) doesn't bind to any unit availability, calling SetDefaultValue method will return null error.
    // Check start in case of editing from UPT later than the existing TC, the Start date will be off if we pass in existing TC
    if( isnull( data )
        or data.Start() <> uptt.Start() )
    {
      data := uptt.Unit().TransportAvailability( relshadow, UnitID := uptt.Unit().ID(), Start := uptt.Start() );
    }
     
    Dialog.Data( data );
    
    // Need this so that when the upt doesn't not have a unit availability, the fields in this Dialog will not be blank.
    Dialog.SetDefaultValue( uptt );
    
    result := this.DoModal( parent );
    
    if( result > 0 )
    {
      TransportAvailability::CreateOrUpdateForUnitPeriodTransports( selection, 
                                                                    not isbatchedit or CheckBoxBatchEditMaintenance.Checked(),
                                                                    data.TimeUnit(),
                                                                    data.Maintenance(),
                                                                    not isbatchedit or CheckBoxBatchEditNumberOfUnit.Checked(),
                                                                    data.NumberOfUnit(),
                                                                    not isbatchedit or CheckBoxBatchEditLotSize.Checked(),
                                                                    data.LotSize(),
                                                                    data.MinimumPerLot(),
                                                                    not isbatchedit or CheckBoxBatchEditCapacity.Checked(),
                                                                    data.MaximumQuantity(), 
                                                                    not isbatchedit or CheckBoxBatchEditShiftPattern.Checked(),
                                                                    data.ShiftPattern(),
                                                                    CheckBoxThisPeriodOnwards.Checked() );
    }
  *]
}
