haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Quintiq file version 2.0
#parent: #root
Method ShelfLifeExtendHistoricalPeriods (
  Boolean restore,
  owning ProductInStockingPoint_MPs pisps
)
{
  TextBody:
  [*
    this.MacroPlan().IsPeriodUpdateForShelfLife( true ); // limit how much PlanningSpecification.Update will do
    if ( isnull( pisps  ) ) 
    {
      pisps := selectset( this, MacroPlan.Product_MP.ProductInStockingPoint_MP, pisp, true, pisp.IsOptMaturation() or pisp.IsOptShelfLife() ); 
    }
    
    if ( pisps.Size() > 0 ) 
    {
      maxshelflifematuration := maxvalue(  max( this, MacroPlan.Product_MP, p, p.HasShelfLife(), p.ShelfLife() ), 
                                           max( this, MacroPlan.Product_MP, p, p.HasMaturation(), p.MaturationDays() ) );
      periodspecs := selectset( this, MacroPlan.PeriodSpecification_MP, pspec, true, pspec.IsUsedForPlanning() ); 
      
      planningspec := minselect(  periodspecs, 
                                  Elements, 
                                  p, 
                                  true, 
                                  guard(p.FirstInPeriodSpecification().DurationInDays(), Real::MaxReal() ) ) ; 
      
      
      
      if ( not isnull( planningspec ) ) 
      {
        firstperiodinrun := min( planningspec, Period_MP, p, true, p.Start() );
        offsetdays := [Number] ( firstperiodinrun - this.MacroPlan().StartOfPlanning() ).DaysAsReal(); 
        perioddurationdays := min( planningspec, Period_MP, p, not p.IsGapPlanning(), p.DurationInDays() );  // ignore gap planning period to avoid an over-estimate
        neededperiodhistory := ifexpr( restore, planningspec.OptimizerShelfLifePreviousHistoricalPeriods(), ceil( maxvalue( 0, maxshelflifematuration - offsetdays) / perioddurationdays ) ); 
        
        if ( neededperiodhistory > planningspec.NrOfHistoricalPeriod() or restore ) 
        {
          debuginfo(  'Changing period', planningspec.ID(), planningspec.NrOfHistoricalPeriod(), '->', neededperiodhistory ); 
          planningspec.Update(  planningspec.ID(), 
                                planningspec.TimeUnit(), 
                                planningspec.NrOfTimeUnit(), 
                                planningspec.PeriodAlignment(), 
                                neededperiodhistory, 
                                planningspec.NrOfFuturePeriod(), 
                                true, // sync
                                planningspec.IsManuallyConfigured(), 
                                planningspec.IsUsedForPlanning(), 
                                false // is cleanup actuals
                              )
        }
        else
        {
          debuginfo( 'nr of historical periods for shelf life optimizer - not changing' ); 
        }
      }
    }
    
    this.MacroPlan().IsPeriodUpdateForShelfLife( false ); // limit how much PlanningSpecification.Update will do
  *]
  InterfaceProperties { Accessibility: 'Module' }
}