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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Quintiq file version 2.0
#parent: #root
Method GenerateCombiExistingTransition (
  Transition_MP transition,
  output OptCampaignUnitSubPeriod lastocuspforcombicreate,
  Boolean usemultiperiodcombi
) as OptCampaignCombi
{
  Description: 'create combi element that reflects an existing transition object'
  TextBody:
  [*
    ocusps := selectsortedset( transition, TransitionPeriod_MP.UnitPeriod.OptCampaignUnitSubPeriod, p, not p.IsFixed() and guard( p.StartTime() > lastocuspforcombicreate.StartTime(), true ), p.StartTime() ); 
    combi := null( OptCampaignCombi ); 
    
    if ( ocusps.Size() > 0 ) 
    {
      firstocusp :=  ocusps.Element( 0 ); 
      if ( guard( firstocusp.PreviousSubPeriod().IsFixed() and not isnull( firstocusp.PreviousSubPeriod().Campaign_MP() ), false ) )
      {
        // we need to start out with a single period combi in order to get the sequence constraint right with previous fixed period at start of plan 
        combi := this.GetCombiForExistingPlan( firstocusp ); 
        combi.AddCombiElementCampaign( firstocusp.PreviousSubPeriod().Campaign_MP().CampaignType_MP(), firstocusp ); 
        combi.AddCombiElementTransition( transition.TransitionType_MP(), firstocusp ); 
        ocusps.Remove( firstocusp ); 
        lastocuspforcombicreate := firstocusp; 
      }
      
      if ( usemultiperiodcombi ) 
      {
        firstloop := true; 
        traverse( ocusps, Elements, ocusp ) 
        {
          if ( firstloop ) // for the 1st period, if we have a previous period we must start with that combi element type
          {
            combi := this.GetCombiForExistingPlan( ocusp); 
        
            startingcombielement := ocusp.GetLastElementPreviousSubPeriod();  
            if ( not isnull( startingcombielement ) ) 
            {
              // start of combi with combi element of previous unit sub period
              type :=  startingcombielement.GetOptCampaignElementType(); 
              combi.AddCombiElement( type, ocusp );
            }
          } // endif firstloop
          
          if ( not firstloop or guard( not combi.LastCombiElement().OptCampaignElementType().Name() = transition.TransitionType_MP().Name(), true ) ) // add transition type ( if not already added because of previous)
          {
            combi.AddCombiElementTransition( transition.TransitionType_MP(), ocusp ); 
          }
        
          lastocuspforcombicreate := ocusp; 
          firstloop := false;       
        }
      }
      else // not usemultiperiodcombi
      {
        traverse( ocusps, Elements, ocusp ) 
        {
          combi := this.GetCombiForExistingPlan( ocusp); 
        
          startingcombielement := ocusp.GetLastElementPreviousSubPeriod();  
          if ( not isnull( startingcombielement ) ) 
          {
            // start of combi with combi element of previous unit sub period
            type :=  startingcombielement.GetOptCampaignElementType(); 
            combi.AddCombiElement( type, ocusp );
          }
          if ( not guard( not combi.LastCombiElement().OptCampaignElementType().Name() = transition.TransitionType_MP().Name(), true ) )
          {
            combi.AddCombiElementTransition( transition.TransitionType_MP(), ocusp ); 
          }
          lastocuspforcombicreate := ocusp; 
        }
      }
    }
    return combi;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}