lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  output String sanitychkfeedback_o,
  MacroPlan macroplan,
  Unit unit,
  String name,
  Boolean hasstart,
  Date start,
  Boolean hasend,
  Date end,
  Boolean hasuserlotsize,
  Real userminimumquantity,
  Boolean hasusermaximumquantity,
  Real usermaximumquantity,
  Real userlotsize,
  Real co2Emission,
  String processtype
) declarative remote as Boolean
{
  Description: 'Validate input, triggered when user create operation from the UI or edit it.'
  TextBody:
  [*
    feedback_o := '';
    sanitychkfeedback_o := '';
    lengthlimit := GlobalParameters_MP::GetLengthOfNames();
    
    // Check if unit is valid
    if( isnull( unit ) )
    {
      feedback_o := Translations::MP_Process_ValidateInput_IsNullUnit( processtype );
      sanitychkfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if start and end window is valid
    else if( hasend and hasstart and ( start >= end ) )
    {
      feedback_o := Translations::MP_Process_ValidateInput_IsStartDateAfterEndDate( end, start );
      sanitychkfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Transport unit cannot be used for operation
    else if( processtype = Operation::GetDefinitionName()
             and unit.HasCapacityTypeTransportBase() )
    {
      feedback_o := Translations::MP_Process_ValidateInput_IsNotTransportUnit();
      sanitychkfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // if has user lot size, check the remaining
    else if( not Process_MP::ValidateInputLotSize( feedback_o, sanitychkfeedback_o, hasuserlotsize, userminimumquantity, hasusermaximumquantity, usermaximumquantity, userlotsize ) )
    {
    }
    // name should not be blank and name length should not be more than length limit
    else if( name = '' or name.Length() > lengthlimit )
    {
      feedback_o := Translations::MP_Process_ValidateInput_IsNameEmpty( lengthlimit, processtype );
      sanitychkfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    // co2 emission should >= 0
    else if( not Process_MP::HasValidCO2( co2Emission, feedback_o ) )
    {
      sanitychkfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    
    
    // Add feedback text is any of the preconditions above are violated
    if( feedback_o <> '' )
    {
      processname := MacroPlan::GetSubstituteName( name );
      // add instance text
      msg := SanityCheckMessage::GetFormattedMessage( Translations::MP_Process_Instance( processtype, processname ),
                                                      feedback_o );
      feedback_o := msg;                                                   
    }
    
    return feedback_o = '';
  *]
}