admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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 SynchronizeBasePeriods
{
  Description: 'Synchronize base periods that will be used for planning'
  TextBody:
  [*
    // DWE2 May-17-2016 (created)
    // Reset all periods to none base and assume as deleted, we will flush the useless period at the end of this method
    traverse( this, Period_MP, period )
    {
      period.IsBase( false );
    }
    
    sortedperiods := selectsortedset( this, Period_MP, period,
                                      not period.IsDeleted()
                                      and not period.GetIsSystemCreated(),
                                      period.Start() );
    if( sortedperiods.Size() > 0 )
    {
      starts := selectvalues( sortedperiods, Elements, period, true, period.Start() );
      starts.Add( this.PeriodParameter_MP().StartOfPlanning() ); // Include start of planning as a chop off for period spans across it
    
      ends := selectvalues( sortedperiods, Elements, period, true, period.End() );
    
      periods := starts.Union( ends ).Unique();
      periods.Sort();
    
      i := 0;
      while( i < periods.Size() - 1 )
      {
        start := periods.Element( i );
        end := periods.Element( i + 1 );
        
        // Use select instead of typeindex 
        systemperiod := select( this, Period_MP, period, period.Start() = start, period.End() = end );
        
                                                                                    
        // If there is no period, create new and mark as system created. (null period spec)
        if( isnull( systemperiod ) )
        {
          systemperiod := Period_MP::Create( this, null( PeriodSpecification_MP ), start, end, true, false );
        }
        // If there is existing one which is marked as deleted, make it a system period
        else if( systemperiod.IsDeleted() )
        {                
          systemperiod.PeriodSpecification_MP( relflush );
          Period_MP::ChangeKeyPeriodTypeIndex( systemperiod, "", systemperiod.Start(), systemperiod.End() );
        }
    
        systemperiod.IsBase( true );
        systemperiod.IsDeleted( false ); 
        i++;
      }
    }
    
    if( not this.IsRollingPeriod() )
    {
      this.DeleteObsoleteBasePeriod();
    }
  *]
}