| 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 ) ); | 
|   *] | 
| } |