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
Quintiq file version 2.0
#parent: #root
Method GenerateCombisforExistingCampaignPlan
{
  TextBody:
  [*
    this.PreprocessExistingTransitionsToSpanGaps(); 
    
    Transaction::Transaction().Propagate(); // above method has changed durations of transitions possibly, ensure all declarative objects ( transition periods, etc.) are good
    
    campaigns := selectsortedset( this, OptCampaignUnitSubPeriod.UnitPeriod.CampaignPeriod_MP.Campaign_MP, c, c.End() > c.Unit().EndOfFrozen(), c.Start() ); 
    transitions := selectsortedset(  this, OptCampaignUnitSubPeriod.UnitPeriod.TransitionPeriod_MP.Transition_MP, t, t.End() > t.Unit().EndOfFrozen(), t.Start() ); 
    
    lastocuspforcombicreate := null(  OptCampaignUnitSubPeriod ); // used to keep track of where we will be adding the new combi
    
    done := false; 
    
    while ( campaigns.Size() + transitions.Size() > 0 and not done ) 
    {
      firstcampaign := guard( campaigns.Element( 0 ), null( Campaign_MP ) );
      firsttransition := guard( transitions.Element( 0 ), null( Transition_MP ) );  
     
      if ( isnull( firstcampaign ) ) 
      {
        // only transition left (expected to be 1)
        this.GenerateCombiExistingTransition( firsttransition, lastocuspforcombicreate, false ); // false means do not create multi period combi 
        done := true; 
      }
      else
      {
        if ( isnull( firsttransition ) ) 
        {
          // only a campaign left (expected to be 1)
          this.GenerateCombiExistingCampaign( firstcampaign, lastocuspforcombicreate, false ); // false means do not create multi period combi 
          done := true; 
          
        }
        else 
        {
          // we still have both campaigns and transitions
          if ( firstcampaign.Start() < firsttransition.Start() ) 
          {
            combi := this.GenerateCombiExistingCampaign( firstcampaign, lastocuspforcombicreate, true ); // true means create multi period combi 
            campaigns.Remove( firstcampaign ); 
            this.CompleteCombiForLastPeriod( combi, campaigns, transitions ); 
          }
          else
          {
            combi := this.GenerateCombiExistingTransition( firsttransition, lastocuspforcombicreate, true ); // true means create multi period combi 
            transitions.Remove( firsttransition );
            this.CompleteCombiForLastPeriod( combi, campaigns, transitions ); 
          }
        }  
      }   
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}