| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod ValidateInput ( | 
|   output String feedback_o, | 
|   output String sanitycheckfeedback_o, | 
|   MacroPlan owner, | 
|   String id, | 
|   String name, | 
|   Unit unit, | 
|   Unit parent, | 
|   Boolean hasuserstart, | 
|   Date start, | 
|   Boolean hasuserend, | 
|   Date end, | 
|   String capacitytype, | 
|   UnitOfMeasure_MP unitofmeasure, | 
|   Currency_MP currency, | 
|   Real minimumquantity, | 
|   Boolean hasmaximumquantity, | 
|   Real maximumquantity, | 
|   Real lotsize, | 
|   Boolean hascapacitysmoothing, | 
|   Boolean issmoothcapacityoverallperiods, | 
|   Number usercapacitysmoothinglength, | 
|   Real capacitysmoothingpercentagedelta, | 
|   Boolean checkuniqueid | 
| ) declarative remote as Boolean | 
| { | 
|   Description: 'Check if the input is valid' | 
|   TextBody: | 
|   [* | 
|     feedback_o      := ''; | 
|     maxnamelength   := GlobalParameters_MP::GetLengthOfNames(); | 
|     istransportunit := capacitytype = GlobalParameters_MP::GetCapacityTypeTransportTime() | 
|                        or capacitytype = GlobalParameters_MP::GetCapacityTypeTransportQuantity(); | 
|      | 
|     // Check ID | 
|     if( checkuniqueid | 
|         and exists( owner, Unit, u, u <> unit, u.ID() = id ) ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsIDExists(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|        | 
|     } | 
|     else if ( id.Length() =0 ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidID( 500 ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Invalid unit | 
|     else if( not isnull( unit ) and unit = parent ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsTargetSelf(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Invalid unit | 
|     else if( not isnull( parent ) | 
|              and exists( unit, AllChildren, allchildren, | 
|              allchildren.AsChildren().ID() = parent.ID() ) ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsTargetChild(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Invalid start and end | 
|     else if( hasuserend and hasuserstart and start >= end ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidStartEndDate( end, start ) ; | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Invalid UOM | 
|     else if( isnull( unitofmeasure ) ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsUnitOfMeasureNull(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Invalid Currency | 
|     else if( isnull( currency ) ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsCurrencyNull(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|      | 
|     // Only check for non-transport unit | 
|     else if( not istransportunit ) | 
|     { | 
|       // Invalid lot size | 
|       if( lotsize < 0 ) | 
|       { | 
|         feedback_o := Translations::MP_ValidateInput_IsNegativeLotSize( lotsize ); | 
|         sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|       } | 
|       // Invalid lot size | 
|       else if( hasmaximumquantity | 
|                and lotsize > maximumquantity ) | 
|       { | 
|         feedback_o := Translations::MP_Unit_ValidateInput_IsLotSizeGreaterThanMaximumQuantity( maximumquantity, lotsize ); | 
|         sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|       } | 
|       // Invalid min qty | 
|       else if( minimumquantity < 0 ) | 
|       { | 
|         feedback_o := Translations::MP_Unit_ValidateInput_IsNegativeMinimumQuantity( minimumquantity ); | 
|         sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|       } | 
|       // Invalid max qty | 
|       else if( hasmaximumquantity | 
|                and maximumquantity < 0 ) | 
|       { | 
|         feedback_o := Translations::MP_Unit_ValidateInput_IsNegativeMaximumQuantity( maximumquantity ); | 
|         sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|       } | 
|       // Invalid max qty | 
|       else if( hasmaximumquantity | 
|                and minimumquantity > maximumquantity ) | 
|       { | 
|         feedback_o := Translations::MP_Unit_ValidateInput_IsMinimumQuantityGreaterThanMaximumQuantity( maximumquantity, minimumquantity); | 
|         sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|       } | 
|         // Invalid capacity smoothing length | 
|       else if( hascapacitysmoothing and not issmoothcapacityoverallperiods and usercapacitysmoothinglength < 2 ) | 
|       { | 
|         feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidSmoothingLength( usercapacitysmoothinglength ); | 
|         sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|       } | 
|       // Invalid capacity smoothing percentage delta | 
|       else if( hascapacitysmoothing and capacitysmoothingpercentagedelta < 0.0 ) | 
|       { | 
|         feedback_o := Translations::MP_Unit_ValidateInput_IsNegativeSmoothingDelta( capacitysmoothingpercentagedelta ); | 
|         sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|       } | 
|     } | 
|     // Invalid name | 
|     //else if is removed, because this checking need to happen regardless of the capacity type | 
|     //as we do not want to overwrite any previous feedback, checking will only be done if feedback_o is still empty at this point | 
|     if( ( name = '' or name.Length() > maxnamelength ) and feedback_o = '' ) | 
|     { | 
|       feedback_o := Translations::MP_Unit_ValidateInput_IsInvalidName( maxnamelength ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|     } | 
|      | 
|     // Add instance text | 
|     if( feedback_o <> '' ) | 
|     { | 
|       unitname := MacroPlan::GetSubstituteName( name ); | 
|       feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_Unit_Instance( unitname ), | 
|                                                              feedback_o ); | 
|     } | 
|      | 
|     return feedback_o = ''; | 
|   *] | 
| } |