| Quintiq file version 2.0 | 
| #parent: #root | 
| Method PreProcessCampaigns | 
| { | 
|   Description: 'If the optimizer horizon starts in the middle of a campaign, we want to separate this campaign in two' | 
|   TextBody: | 
|   [* | 
|     startpuzzle := this.GetPuzzleStart();  | 
|     unit := this.Unit() | 
|     startcampaign := null( Campaign_MP ) | 
|     starttransition := null(  Transition_MP ) | 
|      | 
|     startcampaign := select( unit, Campaign_MP, c, c.Start() < startpuzzle and c.End() >= startpuzzle ) | 
|     starttransition := select( unit, Transition_MP, t, t.Start() < startpuzzle and t.End() >= startpuzzle ) | 
|     //update the campaign to keep only the part before puzzle start | 
|     if( not isnull( startcampaign ) and not startcampaign.End() = startpuzzle ) | 
|     { | 
|       newduration := startcampaign.Duration() - ( startcampaign.End() - startpuzzle ) | 
|       startcampaign.Update( unit, | 
|                             startcampaign.EarliestStart(), | 
|                             newduration, | 
|                             startcampaign.SequenceNumberForExcel(), | 
|                             startcampaign.MinQuantity(), | 
|                             startcampaign.MaxQuantity(), | 
|                             startcampaign.MinDuration(), | 
|                             startcampaign.MaxDuration(), | 
|                             startcampaign.CampaignTypeName(), | 
|                             startcampaign.CampaignID(), | 
|                             startcampaign.Comment(), | 
|                             startcampaign.HasInputMaxQuantity(), | 
|                             startcampaign.HasInputMaxDuration(), | 
|                             not startcampaign.IsManuallyConfigured() | 
|                            ) | 
|       startcampaign.SynchronizePeriodTaskInCampaignQuantities(); | 
|       startcampaign.CampaignOptimizerPreProcessDuration( newduration ); // for use in meta optimizer because we need to be able to initialize back to this state, but also need to add to the duration | 
|     } | 
|     this.LastCampaignBeforeOptHorizon( relset, startcampaign ) | 
|     this.LastTransitionBeforeOptHorizon( relset, starttransition ) | 
|   *] | 
| } |