| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod ValidateInput ( | 
|   output String feedback_o, | 
|   output String sanitycheckfeedback_o, | 
|   Unit unit, | 
|   DateTime start, | 
|   Real mincapacity, | 
|   Real maxcapacity, | 
|   Real maxloadpercentage, | 
|   Number nrofunitsopen, | 
|   UnitCapacity unitcapacity, | 
|   Boolean checkunique | 
| ) declarative remote as Boolean | 
| { | 
|   Description: 'Check for input obtained from UI.' | 
|   TextBody: | 
|   [* | 
|     // Validate input for UnitCapacity | 
|     feedback_o := ''; | 
|     sanitycheckfeedback_o := ''; | 
|     gp := guard( unit.MacroPlan().GlobalParameters_MP(), null( GlobalParameters_MP ) ); | 
|      | 
|     // Check if the unit is provided | 
|     if( isnull( unit ) ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsNullUnit(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|     } | 
|     // Check if the unit capacity is unique. | 
|     // Check if the primary keys are unique | 
|     else if( checkunique | 
|              and not UnitCapacity::IsPrimaryKeysUnique( unit, start, unitcapacity ) ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsNotUnique(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the min capacity is larger than zero | 
|     else if( mincapacity < 0.0 ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsNegativeMinCapacity( mincapacity ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the min capacity is within the allowed range | 
|     else if( mincapacity <> 0 | 
|              and not GlobalParameters_MP::GetIsValueWithinRange( mincapacity, | 
|                                                                  gp.AbsoluteUpperLimit(), | 
|                                                                  gp.AbsoluteLowerLimit() ) ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_InvalidMinCapacity( mincapacity, | 
|                                                                                     gp.AbsoluteUpperLimit(), | 
|                                                                                     gp.AbsoluteLowerLimit() ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the max capacity is larger than zero | 
|     else if( maxcapacity < 0.0 ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsNegativeMaxCapacity( maxcapacity ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the max capacity is within the allowed range | 
|     else if( maxcapacity <> 0 | 
|              and not GlobalParameters_MP::GetIsValueWithinRange( maxcapacity, | 
|                                                                  gp.AbsoluteUpperLimit(), | 
|                                                                  gp.AbsoluteLowerLimit() ) ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_InvalidMaxCapacity( maxcapacity, | 
|                                                                                     gp.AbsoluteUpperLimit(), | 
|                                                                                     gp.AbsoluteLowerLimit() ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the min capacity is less than or equals to max capacity | 
|     else if( mincapacity > maxcapacity ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsMaxCapacityLessThanMinCapacity( maxcapacity, mincapacity ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the max load percentage is larger than zero | 
|     else if( maxloadpercentage < 0 ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsNegativeMaximumLoadPercentage( maxloadpercentage ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Just to make sure max load percentage is not too large to be consistent with unit availability. | 
|     else if( maxloadpercentage > 1000 ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsMaximumLoadPercentageTooLarge( maxloadpercentage ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the number of units open is larger than zero | 
|     else if( nrofunitsopen < 0 ) | 
|     { | 
|       feedback_o := Translations::MP_UnitCapacity_ValidateInput_IsNegativeNrOfUnitsOpen( nrofunitsopen ); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|      | 
|     // Add instance text if any of the preconditions above are violated | 
|     if( feedback_o <> '' ) | 
|     { | 
|       unitname := MacroPlan::GetSubstituteName( guard( unit.Name(), '' ) ); | 
|       feedback_o :=  SanityCheckMessage::GetFormattedMessage( Translations::MP_UnitCapacity_Instance( unitname, start ), | 
|                                                               feedback_o ); | 
|     } | 
|      | 
|     return feedback_o = ''; | 
|   *] | 
| } |