Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  output String sanitycheckfeedback_o,
  Unit unit,
  DateTime start,
  String timeunit,
  Real efficiency,
  Real allocation,
  ShiftPattern shiftpattern,
  Real minloadpercentage,
  Real maxloadpercentage,
  Number nrofunitsopen,
  UnitAvailability unitavailability,
  Boolean checkunique
) declarative remote as Boolean
{
  Description: 'Check for input obtained from UI'
  TextBody:
  [*
    // Validate input for UnitAvailability
    feedback_o := '';
    sanitycheckfeedback_o := '';
    
    // Check if the unit availability can be created.
    // Check if the primary keys are unique
    if( checkunique
        and not UnitAvailability::IsPrimaryKeysUnique( unit, start, unitavailability ) )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_IsNotUnique();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if efficiency is larger than zero
    else if( efficiency < 0.0 )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_InvalidEfficiency( efficiency );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if allocation is larger than zero
    else if( allocation < 0.0 )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_InvalidAllocation( allocation );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if shiftpattern is provided
    else if( isnull( shiftpattern ) )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_IsNullShiftPattern();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if max load percentage is larger than zero
    else if( maxloadpercentage < 0 )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_IsNegativeMaximumLoadPercentage( maxloadpercentage );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Just to make sure max load percentage is not too large, which will cause the total available duration to be max duration.
    else if( maxloadpercentage > 1000 )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_IsMaximumLoadPercentageTooLarge( maxloadpercentage );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if number of unts open is larger than zero
    else if( nrofunitsopen < 0 )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_IsNegativeNrOfUnitsOpen( nrofunitsopen );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Verify min load percentage is larger or equal zero
    else if( minloadpercentage < 0 )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_MinimumLoadPercentageMustGreaterOrEqualToZero( minloadpercentage );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    // Verify min load percentage is less or equal to max load percentage
    else if( minloadpercentage > maxloadpercentage )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_MinimumLoadPercentageMustBeLowerThanMaximumPercentage( minloadpercentage, maxloadpercentage );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    // Check if unit is provided
    else if( isnull( unit ) )
    {
      feedback_o := Translations::MP_UnitAvailability_ValidateInput_IsNullUnit();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    
    // Add instance text if any of the preconditions above are violated
    if( feedback_o <> '' )
    {
      unitname := MacroPlan::GetSubstituteName( guard( unit.Name(), '' ) );
      feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_UnitAvailability_Instance( unitname, start ),
                                                             feedback_o );
    }
    
    return feedback_o = '';
  *]
}