| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod ValidateInput ( | 
|   output String feedback_o, | 
|   output String sanitycheckfeedback_o, | 
|   ConversionFactor conversionfactor, | 
|   UnitOfMeasure_MP sourceuom, | 
|   UnitOfMeasure_MP targetuom, | 
|   Real factor, | 
|   Boolean isproductdependent, | 
|   Product_MP product, | 
|   Boolean checkunique | 
| ) declarative remote as Boolean | 
| { | 
|   Description: 'Validate input from user for conversion factor' | 
|   TextBody: | 
|   [* | 
|     feedback_o := ''; | 
|     sanitycheckfeedback_o := ''; | 
|      | 
|     // Check if target unit of measure is null | 
|     if( isnull( targetuom ) ) | 
|     { | 
|       feedback_o := Translations::MP_ConversionFactor_ValidateInput_IsNullUOM(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if factor is not valid | 
|     else if( factor = 0 | 
|              or factor = Real::MinReal() ) | 
|     { | 
|       feedback_o := Translations::MP_ConversionFactor_ValidateInput_IsZeroFactor(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if the source unit of measure conversion to target unit of measure combination is unique | 
|     else if( checkunique | 
|              and exists( sourceuom, AsSourceUnitOfMeasure, cf, | 
|                          cf <> conversionfactor, | 
|                          cf.TargetUnitOfMeasure() = targetuom | 
|                          and ifexpr( isproductdependent, | 
|                                      cf.Product_MP() = product, | 
|                                      isnull( cf.Product_MP() ) ) ) ) // Only allow one pair of conversion and pair with different product | 
|     { | 
|       feedback_o := Translations::MP_ConversionFactor_ValidateInput_IsNotUnique(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue(); | 
|     } | 
|     // Check if a product is inserted while conversion factor is set to be product dependent | 
|     else if( isproductdependent | 
|              and isnull( product ) ) | 
|     { | 
|       feedback_o := Translations::MP_ConversionFactor_ValidateInput_IsNullProduct(); | 
|       sanitycheckfeedback_o := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning(); | 
|     } | 
|      | 
|     // Format the feedback text if any of the precondition above is violated | 
|     if( feedback_o <> '' ) | 
|     { | 
|       instance := ConversionFactor::GetInstanceText( sourceuom, targetuom, null( Product_MP) ); | 
|        | 
|       if( isproductdependent ) | 
|       { | 
|         instance := ConversionFactor::GetInstanceText( sourceuom, targetuom, product ); | 
|       } | 
|        | 
|       feedback_o := SanityCheckMessage::GetFormattedMessage( instance, feedback_o ); | 
|     } | 
|        | 
|     return feedback_o = ''; | 
|   *] | 
| } |