yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
FunctionOverride CalcExpiredInPeriodShelfLifeSupplyQuantity
{
  TextBody:
  [*
    value := 0.0;
    
    product := this.ProductInStockingPoint_MP().Product_MP();
    shelflife := this.ShelfLife();
    
    // Check if product has shelf-life
    if( product.HasShelfLife() and not isnull( shelflife) )
    {
      // Get the age and quantity vector of remaining product stock after consumption
      agevector := RealVector::Construct( shelflife.ShelfLifeSupplyAgeVectorAsBinaryValue() );
      quantityvector := RealVector::Construct( shelflife.ShelfLifeSupplyQuantityVectorAsBinaryValue() );
      
      isexpiredinperiodvector := BooleanVector::Construct();
      traverse( agevector.AsValues(), Elements, age )
      {
        isexpiredinperiod := not product.GetIsUsableInTargetPeriod( [Real] age, this.Start(), this.Period_MP() );
        isexpiredinperiodvector.Append( isexpiredinperiod );
      } 
      
      // Sum of all elements in the quantity vector that corresponds to element = true in the boolean vector
      value := quantityvector.GetSelection( isexpiredinperiodvector ).Sum();
    }
    
    this.ExpiredInPeriodShelfLifeSupplyQuantity( value );
  *]
}