yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
Method GenerateCombiExistingCampaign (
  Campaign_MP campaign,
  output OptCampaignUnitSubPeriod lastocuspforcombicreate,
  Boolean usemultiperiodcombi
) as OptCampaignCombi
{
  Description: 'create combi element that reflects an existing campaign object'
  TextBody:
  [*
    ocusps := selectsortedset( campaign, CampaignPeriod_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().Transition_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.AddCombiElementTransition( firstocusp.PreviousSubPeriod().Transition_MP().TransitionType_MP(), firstocusp ); 
        combi.AddCombiElementCampaign( campaign.CampaignType_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() = campaign.CampaignTypeName(), true ) )   // add campaign type to combi ( if not already added because of previous period )
          {  
            combi.AddCombiElementCampaign( campaign.CampaignType_MP(), ocusp ); 
          }
          firstloop := false; 
          lastocuspforcombicreate := ocusp; 
        }
      }
      else // not usemultiperiod combi 
      {
        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 ( guard( not combi.LastCombiElement().OptCampaignElementType().Name() = campaign.CampaignTypeName(), true ) ) // if not added already add campaign type
          {
            combi.AddCombiElementCampaign( campaign.CampaignType_MP(), ocusp ); 
          }
          lastocuspforcombicreate := ocusp; 
        }
      }
    }
    return combi;
  *]
  InterfaceProperties { Accessibility: 'Module' }
}