| 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' } | 
| } |