Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  Unit unit,
  Product_MP product,
  DateTime start,
  DateTime end,
  Real minquantity,
  Real targetquantity,
  Boolean hasmaxquantity,
  Real maxquantity,
  SupplySpecification supplyspec,
  Boolean checkunique,
  output String sanitycheckfb
) declarative remote as Boolean
{
  Description: 'Check for input obtained from UI'
  TextBody:
  [*
    // Validate input for SupplySpecifications
    feedback_o := '';
    
    // Check if the supply specification can be created.
    // Check if the unit and product are null
    if( isnull( unit ) )
    { 
      feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsNullUnit();
      sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    else if( isnull( product ) )
    {
      feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsNullProduct();
      sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataWarning();
    }
    // Check if the primary keys are unique
    else if( checkunique
             and not SupplySpecification::IsPrimaryKeysUnique( unit, product, start, end, supplyspec ) )
    {
      feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsSupplySpecificationExists();
      sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    else if ( not exists( unit, AllChildren.AsChildren.Process_MP.ProcessOutput.ProductInStockingPoint_MP.Product_MP.AllParent.AsParent, p, p = product ))
    {
      feedback_o := Translations::MP_SupplySpecification_ValidateInput_NoOutputProduct( unit.Name(), product.Name());
      sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    
    // Check if start is larger than equals to end
    else if( start >= end )
    {
      feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsStartAfterEnd( end, start );
      sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    
    // Check if min quantity is less than zero
    else if( minquantity < 0 )
    {
      feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsNegativeMinQuantity( minquantity );
      sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if target quantity is less than zero
    else if( targetquantity < 0 )
    {
      feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsNegativeTargetQuantity( targetquantity );
      sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
    }
    // Check if has max quantity
    else if( hasmaxquantity )
    {
      // Check if max quantity is valid
      if( maxquantity < minquantity )
      {
        feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsMaxQuantityLessThanMinQuantity( maxquantity, minquantity );
        sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
      else if( maxquantity < targetquantity )
      {
        feedback_o := Translations::MP_SupplySpecification_ValidateInput_IsMaxQuantityLessThanTargetQuantity( maxquantity, targetquantity );
        sanitycheckfb := SanityCheckCategoryLevel::GetSanityCheckCategoryDataIssue();
      }
     
    }
    
    // Add instance text if any of the preconditions above are violated
    if( feedback_o <> '' )
    {
      unitname := MacroPlan::GetSubstituteName( guard( unit.Name(), '' ) );
      productname := MacroPlan::GetSubstituteName( guard( product.Name(), '' ) );
      feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_SupplySpecification_Instance( productname, unitname, start, end ),
                                                             feedback_o );
    }
    
    return feedback_o = '';
  *]
}