yypsybs
2023-09-09 3cb5a54def670d97301f07170fcaad213bfc54f2
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
Quintiq file version 2.0
#parent: #root
Method LimitSuggestedQuantityToAvailableCapacity (
  Real quantity,
  Boolean usecurrentcapacity
) declarative remote as Real
{
  Description: 'Only limit the suggested quantity to remaining available capacity'
  TextBody:
  [*
    // soh yee Jun-25-2013 (created)
    
    up := this.UnitPeriod();
    value := quantity;
    
    // Passed in quantity, convert to quantity to process as unit capacity is calculated based on quantity to process setting.
    // Only limit the suggested quantity to remaining capacity.
    if( not up.IsPlannedInfinite() )
    {
      ontype( up )
      {
        UnitPeriodTimeBase as upt:
        {
          freecapacity := ifexpr( usecurrentcapacity, upt.FreeCapacity() , upt.TotalAvailableCapacity() ) * this.RequiredCapacity();
          value := freecapacity.HoursAsReal();
        }
        UnitPeriodQuantityBase as upq:
        {
          value := ifexpr( usecurrentcapacity, upq.FreeCapacity(), upq.TotalAvailableCapacity() );
        }
      }
    
      // Find the max quantity allowed by taking lot size into consideration.
      // E.g., if available capacity = 1000, lot size = 30, process max quantity = 3000, the actual max quantity is 990. If we pass in 1000 to the next method,
      // it will round to 1020 instead of 990.
      if( this.Process_MP().HasLotSize() )
      {
        lotsize := this.Process_MP().LotSize();
        value := floor( value / lotsize ) * lotsize;
      }
      quantityout := guard( value / this.Process_MP().QuantityToProcessFactor(), value );    // Convert the quantity to process back to quantity out again.
      value := minvalue( quantity, quantityout );                       // Take the min value between available capacity and unfulfilled quantity, in quantity out.
    }
    
    return value;
  *]
}