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
45
46
47
48
49
50
51
52
53
54
55
Quintiq file version 2.0
#parent: #root
Method SynchronizeGapPlanningPeriods
{
  Description: 'Generates non-base, gap planning periods to fill the gap between planning period specifications.'
  TextBody:
  [*
    // ODE2 May-11-2017 (created)
    
    // Reset period status
    traverse( this, Period_MP, period )
    {
      period.IsIncludedInGapPlanningPeriod( false );
      // Clean non planning base periods
      if( period.IsGapPlanning() )
      {
        period.IsGapPlanning( false );
      }
    }
    
    // Requires propagation to update, amongst others, BasePeriod relation & PS End computation
    Transaction::Transaction().Propagate();
    
    // Create gap planning periods
    traverse( this, BasePeriod_MP, baseperiod,  
              not baseperiod.IsIncludedInGapPlanningPeriod()                                            // Do not create a gap planning period if period was included in a previous iteration
              and this.GetHasPlanningPeriodSpecification( baseperiod.Start(), baseperiod.End() )        // Gap periods only get created on horizons for which planning periods are defined
              and not exists( this, PeriodSpecification_MP, ps, 
                              ps.HasInclusivePlanningPeriod( baseperiod.Start(), baseperiod.End() ) ) ) // No planning period on the considered horizon
    {
      this.CreateGapPlanningFromPeriod( baseperiod );
    }
    
    // Handle specific case in which a planning period spans across planning start
    period := select( this, PeriodSpecification_MP.Period_MP, p,
                      p.PeriodSpecification_MP().GetIsLowestLevelPlanning( p.Start(), p.End() )
                      and p.IsAcrossStartOfPlanningHorizon() );
    if( not isnull( period ) )
    {
      startofplanning := this.PeriodParameter_MP().StartOfPlanning();
      // Create gap planning period for historical & future periods
      this.CreateUpdateGapPlanningPeriod( period.Start(), startofplanning );
      this.CreateUpdateGapPlanningPeriod( startofplanning, period.End() );
    }
    
    // Flush obsolete gap planning periods
    if( not this.IsRollingPeriod() )
    {
      this.DeleteObsoletePeriodAndCleanObsoletePeriodTasks();
    }
    
    // Propagation of IsPlanning required for proper generation of sales demand in periods 
    Transaction::Transaction().Propagate( attribute( Period_MP, IsPlanning ) );
  *]
}