Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CanResequence ( 
 | 
  Campaign_MP targetcampaign, 
 | 
  Unit targetunit, 
 | 
  DateTime droptime, 
 | 
  output String feedback_o 
 | 
) declarative remote as Boolean 
 | 
{ 
 | 
  Description: 'Check if source campaign and target campaign are the same.' 
 | 
  TextBody: 
 | 
  [* 
 | 
    isvalid := true; 
 | 
     
 | 
    //workaround to fix the webclient precondition issue when the ondroptarget is Transition 
 | 
    if( isnull( targetcampaign ) ) 
 | 
    { 
 | 
      targetcampaign := minselect( targetunit, Campaign_MP, campaign, 
 | 
                                   campaign.End() > droptime, 
 | 
                                   campaign.Start() ); 
 | 
    } 
 | 
     
 | 
    if( not isnull( targetcampaign ) 
 | 
        and this.CampaignType_MP() <> targetcampaign.CampaignType_MP() 
 | 
        and not Campaign_MP::CheckHasTransitionType( this, targetcampaign ) ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_CampaignTypeForbiddenTransition( this.CampaignTypeName(),  
 | 
                                                                                             targetcampaign.CampaignTypeName() ); 
 | 
    } 
 | 
     
 | 
    if( not isnull( targetcampaign ) 
 | 
        and not isnull( targetcampaign.PreviousCampaign() ) 
 | 
        and targetcampaign.PreviousCampaign().CampaignType_MP() <> this.CampaignType_MP() 
 | 
        and not Campaign_MP::CheckHasTransitionType( targetcampaign.PreviousCampaign(), this ) ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_CampaignTypeForbiddenTransition( targetcampaign.PreviousCampaign().CampaignTypeName(),  
 | 
                                                                                             this.CampaignTypeName() ); 
 | 
    } 
 | 
     
 | 
    //target campaign is only null if it is dropped at the empty space after last campaign 
 | 
    //check if there is transition between the last campaign's campaign type and the source campaign type 
 | 
    if( isnull( targetcampaign ) 
 | 
        and not isnull( targetunit.LastCampaign() ) 
 | 
        and targetunit.LastCampaign().CampaignType_MP() <> this.CampaignType_MP() 
 | 
        and not Campaign_MP::CheckHasTransitionType( targetunit.LastCampaign(), this ) ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_CampaignTypeForbiddenTransition( targetunit.LastCampaign().CampaignTypeName(), 
 | 
                                                                                             this.CampaignTypeName() ); 
 | 
    } 
 | 
     
 | 
    if( this.Unit() <> targetunit ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_SourceUnitAndTargetUnitAreDifferent( this.UnitID(), targetunit.ID() );  
 | 
    } 
 | 
    if( targetcampaign = this ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_SourceAndTargetAreTheSame(); 
 | 
    } 
 | 
    if( droptime < this.MacroPlan().StartOfPlanning()  
 | 
        or ( not isnull( targetcampaign ) and targetcampaign.IsHistorical() ) ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_DroptimeBeforePlanningHorizon();     
 | 
    } 
 | 
     
 | 
    if( droptime < this.EarliestStart() ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_DroptimeBeforeEarliestStart( this.EarliestStart() ); 
 | 
    } 
 | 
     
 | 
    if( not isnull( this.NextCampaign() ) and this.NextCampaign() = targetcampaign ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_TargetCampaignIsAlreadyNextInSequence();  
 | 
    } 
 | 
     
 | 
    if( this.IsHistorical() ) 
 | 
    { 
 | 
      isvalid := false; 
 | 
      feedback_o := Translations::MP_Campaign_CanResequence_IsHistoricalCampaign( this.MacroPlan().StartOfPlanning() ); 
 | 
    } 
 | 
     
 | 
    return isvalid; 
 | 
  *] 
 | 
} 
 |