haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
Method GetNewStartAndEndAfterResequence (
  Campaign_MP_DELETED_Q320 targetcampaign,
  output DateTime newcampaignstart,
  output DateTime newcampaignend,
  output DateTime newtargetcampaignstart,
  output DateTime newtargetcampaignend
) declarative remote
{
  Description: 'Return the new start and end for selected campaign and target campaign.'
  TextBody:
  [*
    if( not isnull( targetcampaign ) )
    {
      campaignduration := this.End() -  this.Start();
      previoustarget := guard( targetcampaign.Previous(), null(  Campaign_MP_DELETED_Q320 ) );
      previoustargetcampaigntype := guard( previoustarget.CampaignType_MP(), null( CampaignType_MP ) );
      targetcampaigntype := guard( targetcampaign.CampaignType_MP(), null( CampaignType_MP ) );
      sourcecampaigntype := this.CampaignType_MP();
      transitionduration := ifexpr( not isnull( previoustarget ) and 
                                    previoustarget <> this and
                                    targetcampaign.Start() - previoustarget.End() <= Campaign_MP_DELETED_Q320::GetMinTransitionDuration( previoustargetcampaigntype, targetcampaigntype ),
                                    Campaign_MP_DELETED_Q320::GetTransitionDurationDifference( previoustargetcampaigntype,
                                                                                  targetcampaigntype,
                                                                                  previoustargetcampaigntype,
                                                                                  sourcecampaigntype ),
                                    Duration::Zero() );
      
      newcampaignstart := targetcampaign.Start() + transitionduration; 
      
      newcampaignend := newcampaignstart + campaignduration;
      
      targetcampaignduration := targetcampaign.End() - targetcampaign.Start();
      newtargetcampaignstart := newcampaignend + Campaign_MP_DELETED_Q320::GetMinTransitionDuration( sourcecampaigntype, targetcampaigntype );
      newtargetcampaignend := newtargetcampaignstart + targetcampaignduration;  
    }
  *]
}