yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Quintiq file version 2.0
#parent: #root
Method EditUnitAvailabilityFromListUnitPeriodTime (
  internal[GUIComponent] parent,
  structured[UnitPeriodTime] selection
) id:Method_DialogCreateEditUnitAvailability_EditUnitAvailabilityFromListUnitPeriodTime
{
  #keys: '[105706.0.2071122933]'
  Body:
  [*
    // Edit the capacity of the selection unit period times from periods list
    
    isbatchedit := selection.Size() > 1;
    Dialog.ShowHideComponentForBatchEdit( isbatchedit, false, true );
    
    upt := selection.Element( 0 );
    // Need this for excluding itself in pre-condition primary keys checking.
    data := shadow( upt.UnitAvailability() );
    
    // 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 UA, the Start date will be off if we pass in existing UA
    if( isnull( data )
        or data.Start() <> upt.Start() )
    {
      data := selection.Element( 0 ).Unit().UnitAvailability( relshadow, UnitID := upt.Unit().ID(), Start := upt.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( selection.Element( 0 ) );
    
    result := this.DoModal( parent );
    
    if( result > 0 )
    {
      UnitAvailability::CreateOrUpdateForUnitPeriodTimes( selection,
                                                          not isbatchedit or CheckBoxBatchEditMaintenance.Checked(),
                                                          data.TimeUnit(),
                                                          data.Maintenance(),
                                                          not isbatchedit or CheckBoxBatchEditEfficiency.Checked(),
                                                          data.Efficiency(),
                                                          not isbatchedit or CheckBoxBatchEditAllocation.Checked(),
                                                          data.Allocation(),
                                                          not isbatchedit or CheckBoxBatchEditShiftPattern.Checked(),
                                                          data.ShiftPattern(),
                                                          not isbatchedit or CheckBoxBatchEditMaxLoadPercentage.Checked(),
                                                          data.MaximumLoadPercentage(),
                                                          not isbatchedit or CheckBoxBatchEditNrOfUnitsOpen.Checked(),
                                                          data.NrOfUnitsOpen(),
                                                          CheckBoxThisPeriodOnwards.Checked(),
                                                          not isbatchedit or CheckBoxBatchEditMinimumLoadThreshold.Checked(),
                                                          data.MinimumLoadThreshold()
                                                          );
    }
  *]
}