Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method ResequenceOnGap ( 
 | 
  DateTime droptime, 
 | 
  output DateTime newcampaignstart, 
 | 
  output DateTime newcampaignend 
 | 
) 
 | 
{ 
 | 
  Description: 'Resequence source campaign on an empty gap of gantt chart row,, push following campaigns back if resequencing will cause overlap.' 
 | 
  TextBody: 
 | 
  [* 
 | 
    newcampaignstart := this.Start(); 
 | 
    newcampaignend := this.End(); 
 | 
    sourceduration := this.End() - this.Start(); 
 | 
    previoustarget := maxselect( this, Unit.Campaign_MP_DELETED_Q320, cpg, cpg.End() <= droptime, cpg.End() ); 
 | 
    firsttarget := this.GetNextCampaignExcludingSelf( previoustarget ); 
 | 
    target := firsttarget; 
 | 
    source := this; 
 | 
                     
 | 
    if( not isnull( previoustarget ) and previoustarget <> this ) 
 | 
    { 
 | 
      newcampaignstart := previoustarget.End() + Campaign_MP_DELETED_Q320::GetMinTransitionDuration( guard( previoustarget.CampaignType_MP(), null( CampaignType_MP ) ), this.CampaignType_MP() ); 
 | 
      newcampaignend := newcampaignstart + sourceduration; 
 | 
    } 
 | 
    else if( isnull( previoustarget ) ) 
 | 
    { 
 | 
      newcampaignstart := this.MacroPlan().StartOfPlanning(); 
 | 
      newcampaignend := newcampaignstart + sourceduration; 
 | 
      firsttarget := this.Unit().FirstCampaign_Old(); 
 | 
      target := firsttarget; 
 | 
    } 
 | 
     
 | 
    this.UpdateTargetCampaignsStartEnd( newcampaignend, 
 | 
                                        source, 
 | 
                                        target, 
 | 
                                        firsttarget ); 
 | 
  *] 
 | 
} 
 |