| 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; | 
|   *] | 
| } |