yypsybs
2023-09-09 3cb5a54def670d97301f07170fcaad213bfc54f2
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
Quintiq file version 2.0
#parent: #root
Method SynchronizePeriods
{
  Description: 'This will create periods based on this period definition'
  TextBody:
  [*
    // DWE2 Apr-25-2016 (modified)
    traverse( this, Period_MP, period )
    {
      period.IsDeleted( true );
    }
    
    // To create from historical period
    start := PeriodSpecification_MP::GetStartOfPreviousPeriod( this.PeriodAlignment().Date(),
                                                               this.TimeUnit(),
                                                               this.NrOfTimeUnit() * this.NrOfHistoricalPeriod() ); // Multiply to get the earlist start
    
    totalofperiods := this.NrOfFuturePeriod() + this.NrOfHistoricalPeriod(); // Sum for total period needs to be created
    
    for( i:= 0; i < totalofperiods ; i++ )
    {
      end := PeriodSpecification_MP::GetStartOfNextPeriod( start, this.TimeUnit(), this.NrOfTimeUnit() );
      period := Period_MP::FindPeriodTypeIndex( this.ID(), start , end );
      if( isnull( period ) )
      {
        //Check if there's already a gap planning period with the same start and end
        period := select( this, MacroPlan.Period_MP, p,
                          p.IsSystemCreated(),
                          p.Start() = start
                          and p.End() = end );
        if( isnull( period ) )
        {
          Period_MP::Create( this.MacroPlan(), this, start, end, false, false );
        }
        else
        {
          //Change redundant gap planning period to planning period
          period.LinkGapPlanningToPeriodSpecification( this );
        }
      }
      else
      {
        period.Update( this );      // It may created by system as a base period previously
        period.IsDeleted( false );
      }
      start := end;
    }
    
    if( not this.MacroPlan().IsRollingPeriod() )
    {
      periods := selectset( this, Period_MP, period, period.IsDeleted() )
      Period_MP::Delete( periods );
    }
  *]
}