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
33
34
35
36
37
38
39
40
41
42
43
44
Quintiq file version 2.0
#parent: #root
FunctionOverride CalcImmatureShelfLifeSupplyQuantity
{
  TextBody:
  [*
    // Calculate the quantity of immature product stocks
    value := 0.0;
    
    product := this.ProductInStockingPoint_MP().Product_MP();
    // Calculate only if the product has maturation period
    if( product.HasMaturation() and not isnull( this.ShelfLife() ) )
    {
      // Retrieve the shelf-life and maturation vectors
      shelflife := this.ShelfLife();
      agevector := RealVector::Construct( shelflife.ShelfLifeSupplyAgeVectorAsBinaryValue() );
      quantityvector := RealVector::Construct( shelflife.ShelfLifeSupplyQuantityVectorAsBinaryValue() );
      
      /*maturationdays := product.MaturationDays();
      // Get the boolean vector of matured product stocks:
      // - Product is consider matured if its age is > maturation days
      // - Example of maturation days = 5.2, product stock age vector = 1, 3.3, 4.9, 5.1, 6, 9.1:
      //   - Boolean vector of matured product will be: false, false, false, false, true, true
      ismaturedvector := agevector.GreaterThan( maturationdays );
      // Apply NOT to the boolean vector
      // Example boolean vector of matured product = false, false, false, false, true, true
      // After applying NOT = true, true, true, true, false, false
      isimmaturevector := ismaturedvector.NOT();
      */
      
      isimmaturevector := BooleanVector::Construct();
      traverse( agevector.AsValues(), Elements, age )
      { 
        isimmature := not product.GetIsMaturedInTargetPeriod( [Real] age, this.Start(), this.Period_MP() );     
        isimmaturevector.Append( isimmature );
      }
      
      // Get the sum of immature product stocks
      value := quantityvector.GetSelection( isimmaturevector ).Sum();
    }
    
    this.ImmatureShelfLifeSupplyQuantity( value );
  *]
}