yanyuan
2023-11-10 143ef74e2eeee697ac8fda3d9032a790fbb4e146
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
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  MacroPlan macroplan,
  SalesSegment_MP salessegment,
  StockingPoint_MP stockingpoint,
  ProductInStockingPoint_MP product,
  Date start,
  Date end,
  Currency_MP currency,
  Real quantity,
  Real adjustment,
  Real price,
  Priority priority,
  String type
) declarative remote as Boolean
{
  Description: 'Validate user input from dialog'
  TextBody:
  [*
    feedback_o := ''
    gp := macroplan.GlobalParameters_MP();
    
    // CHeck if sales segment is null
    if( isnull( salessegment ) )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNullSalesSegment( type );
    }
    // Check if stocking point is null
    else if( isnull( stockingpoint ) )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNullStockingPoint( type );
    }
    // Check if product is null
    else if( isnull( product ) )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNullProduct( type );
    }
    // Check if adjustment is valid
    else if( adjustment < -100.0 )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNegativeAdjustment( adjustment );
    }
    // Check if quantity is valid
    else if( quantity < 0.0 )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNegativeQuantity( quantity );
    }
    // Check if quantity is within range
    else if( quantity <> 0
             and not GlobalParameters_MP::GetIsValueWithinRange( quantity, gp.AbsoluteUpperLimit(), gp.AbsoluteLowerLimit() ) )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_InvalidQuantity( quantity,
                                                                                gp.AbsoluteUpperLimit(),
                                                                                gp.AbsoluteLowerLimit() );
    }
    // Check if currency is null
    else if( isnull( currency ) )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNullCurrency( type );
    }
    // Check if price is valid
    else if( price < 0.0 )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNegativePrice( price );
    }
    // Check if priority is null
    else if( isnull( priority ) )
    {
      feedback_o := Translations::MP_SalesDemand_ValidateInput_IsNullPriority( type );
    }
    
    // Add feedback text if any of the preconditions above are violated
    if( feedback_o <> '' )
    {
      pispname := guard( product.Name(), '' );
      pispname := MacroPlan::GetSubstituteName( pispname );
    
      ssname := guard( salessegment.Name(), '' );
      ssname := MacroPlan::GetSubstituteName( ssname );
    
      feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_SalesDemand_Instance( pispname, ssname, start, end, type ),
                                                             feedback_o );
    }
    
    return feedback_o = '';
  *]
}