Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method UpdateTargetCampaignsStartEnd ( 
 | 
  DateTime newtargetend, 
 | 
  Campaign_MP_DELETED_Q320 source, 
 | 
  Campaign_MP_DELETED_Q320 target, 
 | 
  Campaign_MP_DELETED_Q320 checktarget 
 | 
) 
 | 
{ 
 | 
  Description: 'Look for the last non overlapping campaign and use it as a starting point to update target campaigns start and end.' 
 | 
  TextBody: 
 | 
  [* 
 | 
    isnonoverlapcampaignfound := false; 
 | 
    hasoverlap := false; 
 | 
    gaptonexttarget := guard( target.Start() - newtargetend, Duration::Zero() ); 
 | 
    transitiondurationtonexttarget := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( guard( source.CampaignType_MP(), null( CampaignType_MP ) ), 
 | 
                                                                             guard( target.CampaignType_MP(), null( CampaignType_MP ) ) ); 
 | 
    while( not isnonoverlapcampaignfound and 
 | 
           not isnull( target ) and 
 | 
           target <> this and 
 | 
           ( newtargetend > target.Start() or 
 | 
             gaptonexttarget < transitiondurationtonexttarget) ) 
 | 
    { 
 | 
      nexttarget := this.GetNextCampaignExcludingSelf( target ); 
 | 
      transitionduration := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( source.CampaignType_MP(), target.CampaignType_MP() ); 
 | 
      targetduration := target.End() - target.Start(); 
 | 
      newtargetend := newtargetend + transitionduration + targetduration; 
 | 
      gaptonexttarget := guard( nexttarget.Start() - newtargetend, Duration::Zero() ); 
 | 
      transitiondurationtonexttarget := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( target.CampaignType_MP(), guard( nexttarget.CampaignType_MP(), null( CampaignType_MP ) ) ); 
 | 
      if(  not isnull( nexttarget ) and  
 | 
           ( newtargetend > nexttarget.Start() or 
 | 
             gaptonexttarget < transitiondurationtonexttarget ) ) 
 | 
      { 
 | 
        source := target; 
 | 
        target := nexttarget;   
 | 
      } 
 | 
      else 
 | 
      { 
 | 
        isnonoverlapcampaignfound := true;   
 | 
      } 
 | 
      hasoverlap := true;  
 | 
    } 
 | 
     
 | 
    while( hasoverlap and not isnull( target ) ) 
 | 
    { 
 | 
      previoustarget := this.GetPreviousCampaignExcludingSelf( target ); 
 | 
      transitionduration := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( guard( previoustarget.CampaignType_MP(), null( CampaignType_MP ) ), target.CampaignType_MP() );  
 | 
      targetduration := target.End() - target.Start(); 
 | 
      newtargetstart := newtargetend - targetduration; 
 | 
       
 | 
      // To prevent type index error, shift current campaign's start to make it not unique before updating target campaign's start/end 
 | 
      if( newtargetstart = this.Start() and newtargetend = this.End() ) 
 | 
      { 
 | 
        this.Update( this.CampaignType_MP(),  
 | 
                     this.Start() + targetduration, 
 | 
                     this.End(), 
 | 
                     this.MinQuantity(), 
 | 
                     this.MaxQuantity(), 
 | 
                     this.Comment(), 
 | 
                     this.IsManuallyConfigured() );     
 | 
      } 
 | 
       
 | 
      target.Update( target.CampaignType_MP(), 
 | 
                     newtargetstart, 
 | 
                     newtargetend, 
 | 
                     target.MinQuantity(), 
 | 
                     target.MaxQuantity(), 
 | 
                     target.Comment(), 
 | 
                     target.IsManuallyConfigured() ); 
 | 
       
 | 
      newtargetend := newtargetstart - transitionduration; 
 | 
                      
 | 
      if( target <> checktarget ) 
 | 
      { 
 | 
        target := previoustarget;   
 | 
      } 
 | 
      else 
 | 
      { 
 | 
        target := null( Campaign_MP_DELETED_Q320 );   
 | 
      }  
 | 
    } 
 | 
  *] 
 | 
} 
 |