Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Function CalcEnd 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    tt := this.TransitionType_MP(); 
 | 
    value := tt.Unit().MacroPlan().StartOfPlanning(); 
 | 
    gapduration := Duration::Zero(); 
 | 
     
 | 
    if ( not isnull( this.FromCampaign() )  
 | 
         and this.FromCampaign().HasNextTransitionDurationByOpt() and this.FromCampaign().NextTransitionDurationByOpt() > Duration::Zero() )  
 | 
    { 
 | 
      // case: end of transition determined by campaign sequence optimizer 
 | 
      value := this.Start() + this.FromCampaign().NextTransitionDurationByOpt();  
 | 
    } 
 | 
    else 
 | 
    { 
 | 
      // case: end of transition determined by decision support system 
 | 
      if( not isnull( this.ToCampaign() ) 
 | 
          and not isnull( this.FromCampaign() ) and this.ToCampaign().Start().IsFinite() and this.FromCampaign().End().IsFinite() ) 
 | 
      { 
 | 
        value := this.ToCampaign().Start(); 
 | 
        gapduration := this.ToCampaign().Start() - this.FromCampaign().End(); 
 | 
      } 
 | 
       
 | 
      if( gapduration > tt.DefaultDuration() ) 
 | 
      { 
 | 
        duration := minvalue( gapduration, tt.DefaultDuration() ); 
 | 
        value := this.Start() + duration;   
 | 
      } 
 | 
       
 | 
      if( not tt.IsDuration() and this.OperationInTransition( relsize ) > 0 ) 
 | 
      { 
 | 
        duration := tt.DefaultDuration(); 
 | 
        value := this.Start() + duration 
 | 
      } 
 | 
       
 | 
      if( not isnull( this.FromCampaign() ) 
 | 
          and this.FromCampaign().HistoricalTransitionDuration() > Duration::Zero() ) 
 | 
      { 
 | 
        duration := this.FromCampaign().HistoricalTransitionDuration(); 
 | 
        value := this.Start() + duration;  
 | 
      } 
 | 
       
 | 
      
 | 
    } 
 | 
     
 | 
    this.End( value ); 
 | 
  *] 
 | 
} 
 |