chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  output String sanitycheckfeedback_o,
  String id,
  MacroPlan macroplan,
  PeriodSpecification_MP periodspecification,
  String timeunit,
  Number nroftimeunit,
  DateTime periodalignment,
  Number nrofhistoricalperiod,
  Number nroffutureperiod,
  Boolean checkunique
) declarative remote as Boolean
{
  Description: 'Validate input entered by user at period definition'
  TextBody:
  [*
    feedback_o := '';
    sanitycheckfeedback_o := '';
    instance := Translations::MP_PeriodSpecification_MP_Instance( id );
    // Get all time units and tokenize them into a set of structured string
    timeunits := PeriodSpecification_MP::GetAllTimeUnit().Tokenize( ';' );
    
    // Check if ID is entered
    if( id = '' )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_IsIDEmpty();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if time unit is valid
    else if( timeunits.Find( timeunit ) < 0  )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_InvalidTimeUnit();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if number of time unit is valid
    else if( nroftimeunit <= 0 )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_IsInvalidNrOfTimeUnit( nroftimeunit );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if numbero f future period is valid
    else if( nroffutureperiod < 0 )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_IsInvalidNrOfFuturePeriod( nroffutureperiod );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if number of historical period is valid
    else if( nrofhistoricalperiod < 0 )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_IsInvalidNrOfHistoricalPeriod( nrofhistoricalperiod );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // For period specification of time unit Month, Quarter, and Year, the start of current period is not allowed to be on 29th, 30th or 31st of the month
    // To prevent unclear specification due to variable duration of these periods. For example for monthly period with start of period 30 January, it's not clear where period should end.
    else if( timeunit <> Translations::MP_GlobalParameters_Hour()
             and timeunit <> Translations::MP_GlobalParameters_Day()
             and timeunit <> Translations::MP_GlobalParameters_Week()
             and periodalignment.Day() > 28 )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_IsInvalidPeriodAlignment_LimitOfMonth( periodalignment, timeunit );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if ID is unique
    else if( checkunique
             and exists( macroplan, PeriodSpecification_MP, pdef,
                         pdef <> periodspecification,
                         pdef.ID() = id ) )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_IsNotUnique();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    else if( checkunique 
             and exists( macroplan, 
                         PeriodSpecification_MP, pdef, 
                         pdef <> periodspecification,
                         pdef.ID() <> id
                         and pdef.TimeUnit() = timeunit 
                         and pdef.NrOfTimeUnit() = nroftimeunit ) )
    {
      feedback_o := Translations::MP_PeriodSpecification_MP_ValidateInput_DuplicateGranularity();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    
    // Add feedback text if any of the precondition above is violated
    if( feedback_o <> '' )
    {
      feedback_o := SanityCheckMessage::GetFormattedMessage( instance, feedback_o );
    }
    
    return feedback_o = '';
  *]
}