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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  output String sanitycheckfeedback_o,
  MacroPlan owner,
  String id,
  String name,
  Unit unit,
  Unit parent,
  Boolean hasuserstart,
  Date start,
  Boolean hasuserend,
  Date end,
  String capacitytype,
  UnitOfMeasure_MP unitofmeasure,
  Currency_MP currency,
  Real minimumquantity,
  Boolean hasmaximumquantity,
  Real maximumquantity,
  Real lotsize,
  Boolean hascapacitysmoothing,
  Boolean issmoothcapacityoverallperiods,
  Number usercapacitysmoothinglength,
  Real capacitysmoothingpercentagedelta,
  Boolean checkuniqueid
) declarative remote as Boolean
{
  Description: 'Check if the input is valid'
  TextBody:
  [*
    feedback_o      := '';
    maxnamelength   := GlobalParameters_MP::GetLengthOfNames();
    istransportunit := capacitytype = GlobalParameters_MP::GetCapacityTypeTransportTime()
                       or capacitytype = GlobalParameters_MP::GetCapacityTypeTransportQuantity();
    
    // Check ID
    if( checkuniqueid
        and exists( owner, Unit, u, u <> unit, u.ID() = id ) )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsIDExists();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      
    }
    else if ( id.Length() =0 )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidID( 500 );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Invalid unit
    else if( not isnull( unit ) and unit = parent )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsTargetSelf();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Invalid unit
    else if( not isnull( parent )
             and exists( unit, AllChildren, allchildren,
             allchildren.AsChildren().ID() = parent.ID() ) )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsTargetChild();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Invalid start and end
    else if( hasuserend and hasuserstart and start >= end )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidStartEndDate( end, start ) ;
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Invalid UOM
    else if( isnull( unitofmeasure ) )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsUnitOfMeasureNull();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Invalid Currency
    else if( isnull( currency ) )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsCurrencyNull();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    
    // Only check for non-transport unit
    else if( not istransportunit )
    {
      // Invalid lot size
      if( lotsize < 0 )
      {
        feedback_o := Translations::MP_ValidateInput_IsNegativeLotSize( lotsize );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      // Invalid lot size
      else if( hasmaximumquantity
               and lotsize > maximumquantity )
      {
        feedback_o := Translations::MP_Unit_ValidateInput_IsLotSizeGreaterThanMaximumQuantity( maximumquantity, lotsize );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      // Invalid min qty
      else if( minimumquantity < 0 )
      {
        feedback_o := Translations::MP_Unit_ValidateInput_IsNegativeMinimumQuantity( minimumquantity );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      // Invalid max qty
      else if( hasmaximumquantity
               and maximumquantity < 0 )
      {
        feedback_o := Translations::MP_Unit_ValidateInput_IsNegativeMaximumQuantity( maximumquantity );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      // Invalid max qty
      else if( hasmaximumquantity
               and minimumquantity > maximumquantity )
      {
        feedback_o := Translations::MP_Unit_ValidateInput_IsMinimumQuantityGreaterThanMaximumQuantity( maximumquantity, minimumquantity);
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
        // Invalid capacity smoothing length
      else if( hascapacitysmoothing and not issmoothcapacityoverallperiods and usercapacitysmoothinglength < 2 )
      {
        feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidSmoothingLength( usercapacitysmoothinglength );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      // Invalid capacity smoothing percentage delta
      else if( hascapacitysmoothing and capacitysmoothingpercentagedelta < 0.0 )
      {
        feedback_o := Translations::MP_Unit_ValidateInput_IsNegativeSmoothingDelta( capacitysmoothingpercentagedelta );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
    }
    // Invalid name
    //else if is removed, because this checking need to happen regardless of the capacity type
    //as we do not want to overwrite any previous feedback, checking will only be done if feedback_o is still empty at this point
    if( ( name = '' or name.Length() > maxnamelength ) and feedback_o = '' )
    {
      feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidName( maxnamelength );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    
    // Add instance text
    if( feedback_o <> '' )
    {
      unitname := MacroPlan::GetSubstituteName( name );
      feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_Unit_Instance( unitname ),
                                                             feedback_o );
    }
    
    return feedback_o = '';
  *]
}