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
Function CalcShelfLifeAgeAndQuantityVectorAsBinaryValue
{
  TextBody:
  [*
    // Get the destination PISPIPPL and Product
    destination_pispippl := this.ProductInStockingPointInPeriodPlanningLeaf();
    destination_product_mp := destination_pispippl.ProductInStockingPoint_MP().Product_MP();
    
    // Check if destination product has shelf life or maturation
    if( guard( destination_product_mp.HasShelfLifeOrMaturation(),
               false ) )
    {
      quantityvector := RealVector::Construct();
      agevector := RealVector::Construct();
    
    
      // Check if this supply is created due to laneleg or routing operation
      if( this.PeriodTask_MP().istype( PeriodTaskLaneLeg ) )
      { 
        // If this new supply is being transported with trip,
        // We will not track the age of product at the origin stocking point. E.g out of 100 NS, 20 is 1 day old, 80 is 2 days old.
        // So it's sufficient to just set all of their age to the leadtime. E.g. all 100 NS are 3 days old when leadtime is 3 days.
        age := this.PeriodTask_MP().astype( PeriodTaskLaneLeg ).Trip().GetShelfLifeAgeToAdd();
        quantityvector.Append( this.Quantity() );
        agevector.Append( age );
      }
      else
      {
        // If this new supply is created using routing operation
        // We assume that the output is a different product altogether
        // therefore, the age of the product is 0
        quantityvector.Append( this.Quantity() );
        agevector.Append( 0.0 );
      }
      
      // Merge the vectors
      ShelfLife::MergeVectorAccordingToAgeAndExpiration( quantityvector, agevector,
                                                         destination_pispippl,
                                                         destination_pispippl.Start() );
    
      this.ShelfLifeQuantityVectorAsBinaryValue( quantityvector.AsBinaryValue() );
      this.ShelfLifeAgeVectorAsBinaryValue( agevector.AsBinaryValue() );
    }
  *]
}