| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod ValidateInput ( | 
|   output String feedback_o, | 
|   output String sanitycheckfeedback_o, | 
|   Unit unit, | 
|   String name, | 
|   Real minquantity, | 
|   Real maxquantity, | 
|   Duration minduration, | 
|   Duration maxduration, | 
|   CampaignType_MP campaigntype, | 
|   Boolean checkunique, | 
|   String inputType, | 
|   Boolean checkmaxqty, | 
|   Boolean checkmaxdur | 
| ) 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 := ''; | 
|     isDurationInput := inputType = GlobalParameters_MP::GetCampaignTransitionsTypeDuration(); | 
|      | 
|     // Get the maximum length for names | 
|     lengthlimit := GlobalParameters_MP::GetLengthOfNames(); | 
|      | 
|     // Check if unit is null | 
|     if( isnull( unit ) ) | 
|     { | 
|       feedback_o := Translations::MP_CampaignType_ValidateInput_IsNullUnit() ; | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if campaign name is unique | 
|     else if( checkunique | 
|              and exists( unit, MacroPlan.Unit.CampaignType_MP, ct, | 
|                          ct <> campaigntype, | 
|                          ct.Name() = name ) ) | 
|     { | 
|       feedback_o := Translations::MP_CampaignType_ViolateHasUniqueName(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the provided name is valid | 
|     else if( name = '' or  name.Length() > lengthlimit ) | 
|     { | 
|       feedback_o := Translations::MP_CampaignType_ValidateInput_IsNameEmptyOrExceedLengthLimit( lengthlimit ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|     } | 
|     else if( not isDurationInput ) | 
|     { | 
|      // Check if minimum quantity is valid | 
|      if( minquantity <= 0 ) | 
|      { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsNegativeMinQuantity( minquantity ); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|      } | 
|      // Check if the maximum quantity is valid | 
|      else if( checkmaxqty and maxquantity <= 0 ) | 
|      { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsNegativeMaxQuantity( maxquantity ); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|      } | 
|      // Check if min vs max quantity is valid | 
|      else if( checkmaxqty and maxquantity < minquantity ) | 
|      { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsMinQuantityLessThanMaxQuantity( minquantity, maxquantity ); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();  | 
|      } | 
|      //Check if quantity is greater than zero when duration checkbox is not checked | 
|       else if( not checkmaxdur and minquantity <= 0 and maxquantity <= 0 ) | 
|       { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsQuantityGreaterThanZero(); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|       } | 
|     } | 
|     else if( isDurationInput ) | 
|     { | 
|      // Check if min duration is greater than zero | 
|      if( minduration <= Duration::Zero() ) | 
|      { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsMinDurationZeroOrNegative( minduration ); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|      } | 
|      // Check if max duration is greater than zero | 
|      else if( checkmaxdur and maxduration <= Duration::Zero() ) | 
|      { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsMaxDurationZeroOrNegative( maxduration ); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|      } | 
|      // Check if min vs max duration is valid | 
|      else if( checkmaxdur and maxduration < minduration ) | 
|      { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsMinDurationLessThanMaxDuration( minduration, maxduration ); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|      } | 
|      //Check if duration is greater than zero when quantity checkbox is not checked | 
|       else if( not checkmaxqty and minduration <= Duration::Zero() and maxduration <= Duration::Zero() ) | 
|       { | 
|        feedback_o := Translations::MP_CampaignType_ValidateInput_IsDurationGreaterThanZero(); | 
|        sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|       } | 
|     } | 
|     // Format feedback text if any of the precondition above is violated | 
|     if( feedback_o <> '' ) | 
|     { | 
|       subname := MacroPlan::GetSubstituteName( name ); | 
|       feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_CampaignType_Instance( subname ), | 
|                                                              feedback_o ); | 
|     } | 
|      | 
|     return feedback_o.Length() = 0; | 
|   *] | 
| } |