hongji.li
2023-11-03 aefafd2142478d4fb07d6b8b45c3047e247389e0
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
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  output String sanitycheckfeedback_o,
  MacroPlan owner,
  String name,
  Number numberofdays,
  ShiftPattern oldshiftpattern,
  Boolean checkunique
) declarative remote as Boolean
{
  Description: 'Validate input for creating/editing ShiftPattern'
  TextBody:
  [*
    // Validate input for creating/editing ShiftPattern
    feedback_o := '';
    sanitycheckfeedback_o := '';
    
    // Set the maximum allowed number of days
    maxnumberofdays := 999;
    // Get the maximum allowed length for names
    lengthlimit := GlobalParameters_MP::GetLengthOfNames();
    
    // Check if name is entered or is within the allowed length
    if( name = '' or name.Length() > lengthlimit  )
    {
      feedback_o := Translations::MP_ShiftPattern_ValidateInput_IsInvalidName( lengthlimit );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if the entered name is unique
    else if( checkunique
             and exists( owner, ShiftPattern, s,
                         s <> oldshiftpattern,
                         s.Name() = name ) )
    {
      feedback_o := Translations::MP_ShiftPattern_ValidateInput_IsNameExists();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if the number of days is within the allowed range
    else if( numberofdays <= 0
             or numberofdays > maxnumberofdays )
    {
      feedback_o := Translations::MP_ShiftPattern_ValidateInput_IsInvalidNrOfDays( numberofdays, maxnumberofdays );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    
    // Add instance text
    if( feedback_o <> '' )
    {
      shiftpatternname := MacroPlan::GetSubstituteName( name );
      feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_ShiftPattern_Instance( shiftpatternname ),
                                                             feedback_o );
    }
    
    return feedback_o = '';
  *]
}