admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
Quintiq file version 2.0
#parent: #root
Method UpdateTargetCampaignsStartEnd (
  DateTime newtargetend,
  Campaign_MP_DELETED_Q320 source,
  Campaign_MP_DELETED_Q320 target,
  Campaign_MP_DELETED_Q320 checktarget
)
{
  Description: 'Look for the last non overlapping campaign and use it as a starting point to update target campaigns start and end.'
  TextBody:
  [*
    isnonoverlapcampaignfound := false;
    hasoverlap := false;
    gaptonexttarget := guard( target.Start() - newtargetend, Duration::Zero() );
    transitiondurationtonexttarget := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( guard( source.CampaignType_MP(), null( CampaignType_MP ) ),
                                                                             guard( target.CampaignType_MP(), null( CampaignType_MP ) ) );
    while( not isnonoverlapcampaignfound and
           not isnull( target ) and
           target <> this and
           ( newtargetend > target.Start() or
             gaptonexttarget < transitiondurationtonexttarget) )
    {
      nexttarget := this.GetNextCampaignExcludingSelf( target );
      transitionduration := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( source.CampaignType_MP(), target.CampaignType_MP() );
      targetduration := target.End() - target.Start();
      newtargetend := newtargetend + transitionduration + targetduration;
      gaptonexttarget := guard( nexttarget.Start() - newtargetend, Duration::Zero() );
      transitiondurationtonexttarget := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( target.CampaignType_MP(), guard( nexttarget.CampaignType_MP(), null( CampaignType_MP ) ) );
      if(  not isnull( nexttarget ) and 
           ( newtargetend > nexttarget.Start() or
             gaptonexttarget < transitiondurationtonexttarget ) )
      {
        source := target;
        target := nexttarget;  
      }
      else
      {
        isnonoverlapcampaignfound := true;  
      }
      hasoverlap := true; 
    }
    
    while( hasoverlap and not isnull( target ) )
    {
      previoustarget := this.GetPreviousCampaignExcludingSelf( target );
      transitionduration := Campaign_MP_DELETED_Q320::GetMinTransitionDuration( guard( previoustarget.CampaignType_MP(), null( CampaignType_MP ) ), target.CampaignType_MP() ); 
      targetduration := target.End() - target.Start();
      newtargetstart := newtargetend - targetduration;
      
      // To prevent type index error, shift current campaign's start to make it not unique before updating target campaign's start/end
      if( newtargetstart = this.Start() and newtargetend = this.End() )
      {
        this.Update( this.CampaignType_MP(), 
                     this.Start() + targetduration,
                     this.End(),
                     this.MinQuantity(),
                     this.MaxQuantity(),
                     this.Comment(),
                     this.IsManuallyConfigured() );    
      }
      
      target.Update( target.CampaignType_MP(),
                     newtargetstart,
                     newtargetend,
                     target.MinQuantity(),
                     target.MaxQuantity(),
                     target.Comment(),
                     target.IsManuallyConfigured() );
      
      newtargetend := newtargetstart - transitionduration;
                     
      if( target <> checktarget )
      {
        target := previoustarget;  
      }
      else
      {
        target := null( Campaign_MP_DELETED_Q320 );  
      } 
    }
  *]
}