admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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 = '';
  *]
}