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
Quintiq file version 2.0
#parent: #root
Function CalcAge
{
  TextBody:
  [*
    value := 0.0;
    pispip := this.ProductInStockingPointInPeriodPlanningLeaf();
    
    /* Start age of inventory supply is the duration between manufactured date to period start date
       rounded up to the multiple of period's duration.
      e.g. inv supply in W2, manufactured on 3-Jan, assuming W1: 1 Jan to 8 Jan, W2: 8 Jan to 15 Jan
      age = 8-3 rounded up to multiple of 7 = 7
    */
    
    if ( not isnull( pispip ) and this.Product_MP().HasShelfLifeOrMaturation() )
    {
      
      period := pispip.Period_MP();
      date := pispip.Start();
      manufacturedate := this.ManufacturedDate();
      
      value := ifexpr( manufacturedate.IsFinite() and date.IsFinite(),
                       ShelfLife::GetSupplyAge( manufacturedate, date.Date(), period ), 0.0 );
    }                
    
    this.Age( value );
  *]
}