yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
  *]
}