admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  output String sanitycheckfeedback_o,
  MacroPlan macroplan,
  CampaignType_MP campaigntype,
  Campaign_MP campaign,
  DateTime earlieststart,
  Duration duration,
  String inputType,
  Real minqty,
  Real maxqty,
  Duration mindur,
  Duration maxdur,
  String comment,
  Boolean checkunique,
  Boolean checkmaxqty,
  Boolean checkmaxdur,
  Boolean iscampaignaddlast
) declarative remote as Boolean
{
  Description: 'Checks the correctness of input data from Create/Edit dialog.'
  TextBody:
  [*
    // Precondition to validate the input for creating/editing Campaign_MP
    feedback_o := '';
    sanitycheckfeedback_o := '';
    start := guard( Campaign_MP::GetAvailableStart( earlieststart, campaign ), DateTime::MinDateTime() );
    startofplanning := macroplan.StartOfPlanning();
    
    // Calculate possible campaign duration based on inputs
    duration := Campaign_MP::GetDerivedDuration( campaigntype, minqty, maxqty, checkmaxqty, mindur, maxdur, checkmaxdur );
    
    // Calculate End possible end time for campaign
    earliestend := earlieststart + duration;
    end := ifexpr( start.IsFinite(), start + duration, DateTime::MinDateTime() );
    
    isQuantity := inputType = GlobalParameters_MP::GetCampaignTransitionsTypeQuantity();
    isDuration := inputType = GlobalParameters_MP::GetCampaignTransitionsTypeDuration();
        
    // Check if campaign type is null
    if( isnull( campaigntype ) )
    {
      feedback_o := Translations::MP_Campaign_ValidateInput_IsNullCampaignType();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if there is TransitionType defined (only applies to New Campaign added to last)
    else if( iscampaignaddlast
             and isnull( campaign )
             and not isnull( campaigntype )
             and not isnull( campaigntype.Unit().LastCampaign() )
             and campaigntype.Unit().LastCampaign().CampaignType_MP() <> campaigntype
             and not CampaignType_MP::CheckHasTransitionType( campaigntype.Unit().LastCampaign().CampaignType_MP(), campaigntype ) )
    {
      feedback_o := Translations::MP_Campaign_CanResequence_CampaignTypeForbiddenTransition( campaigntype.Unit().LastCampaign().CampaignTypeName(),
                                                                                             campaigntype.Name() );
    }
    // Check if there is TransitionType defined for Next Campaign
    else if( not isnull( campaign )
             and not isnull( campaign.NextCampaign() )
             and campaign.NextCampaign().CampaignType_MP() <> campaign.CampaignType_MP()
             and not Campaign_MP::CheckHasTransitionType( campaign, campaign.NextCampaign() ) )
    {
      feedback_o := Translations::MP_Campaign_CanResequence_CampaignTypeForbiddenTransition( campaign.CampaignTypeName(),
                                                                                             campaign.NextCampaign().CampaignTypeName() );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();                                                                                       
    }
    //Check if earliest start is valid
    else if( guard( not campaign.IsHistorical(), true ) 
             and earlieststart < startofplanning )
    {
      feedback_o := Translations::MP_Campaign_ValidateInput_InvalidEarliestStart( earlieststart, startofplanning );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if campaign type has any operations with zero throughput
    else if( min( campaigntype, OperationInCampaignType.Operation, opr, opr.Throughput() ) = 0 )
    {
      feedback_o := Translations::MP_CampaignType_IsOperationThroughputZero();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if campaign could ends before start of planning
    else if( earliestend < startofplanning
             and ( end.IsInfinite() or end < startofplanning )
             and guard( not( duration = campaign.Duration() ), true ) )         
    {
      enddate := ifexpr( end.IsFinite(), end, earliestend );
      feedback_o := Translations::MP_CampaignType_IsEndBeforeStartOfPlanning( duration, enddate, startofplanning );
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    else if( not isDuration and not isQuantity )
    {
      feedback_o := Translations::MP_Campaign_ValidateInput_DurationAndQuantitySelected();
      sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    else if( isDuration )
    {
      // Check if duration is valid
      if( mindur <= Duration::Zero() )
      {
        feedback_o := Translations::MP_Campaign_ValidateInput_IsNegativeMinDuration( mindur );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();  
      }
      else if( checkmaxdur and maxdur <= Duration::Zero() )
      {
        feedback_o := Translations::MP_Campaign_ValidateInput_IsNegativeMaxDuration( maxdur );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();  
      }
      // Check if maximum duration is larger than minimum duration
      else if( checkmaxdur and maxdur < mindur )
      {
        feedback_o := Translations::MP_Campaign_ValidateInput_IsMaxDurationLessThanMaxDuration( mindur, maxdur ); 
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
    }
    else if( isQuantity )
    {
      // Check if minimum quantity is valid
      if( minqty <= 0 )
      {
        feedback_o := Translations::MP_Campaign_ValidateInput_IsNegativeMinQuantity( minqty );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      // Check if maximum quantity is valid
      else if( checkmaxqty and maxqty <= 0 )
      {
        feedback_o := Translations::MP_Campaign_ValidateInput_IsNegativeMaxQuantity( maxqty );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      // Check if maximum quantity is larger than minimum quantity
      else if( checkmaxqty and maxqty < minqty )
      {
        feedback_o := Translations::MP_Campaign_ValidateInput_IsMaxQuantityLessThanMaxQuantity( minqty, maxqty );
        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
    }  
    
    
    // Format feedback text if any of the precondition above is violated
    if( feedback_o <> '' )
    {
      instance := Campaign_MP::GetInstanceText( campaigntype, start );
      feedback_o := SanityCheckMessage::GetFormattedMessage( instance, feedback_o );
    }
        
    return feedback_o.Length() = 0;
  *]
}