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