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
40
41
42
43
44
45
46
47
48
49
50
51
52
Quintiq file version 2.0
#parent: #root
Method WriteOptCampaignPeriodTaskQuantities (
  LibOpt_Task task,
  OptCampaignCombiElementTransition elt
)
{
  Description: 'Write out combi world quantities to period task in transition objects'
  TextBody:
  [*
    ocusp := elt.OptCampaignUnitSubPeriod(); 
                                          
    transperiod := select( this, TransitionPeriod_MP, tp, true, tp.UnitPeriod() = ocusp.UnitPeriod() ); 
    
    addedtocurrent := not isnull( transperiod ); 
    addedtoprevious := false; 
    addedtonext := false;  
    if ( isnull( transperiod ) ) // possiblly we are at start of combi ( and period) and duration of elt is 0 but still some qty added to campaign we are building. Look for previous period. 
    {
      transperiod := select( this, TransitionPeriod_MP, tp, true, guard( tp.UnitPeriod() = ocusp.PreviousSubPeriod().UnitPeriod(), false ) ); 
    }
    addedtoprevious := not addedtocurrent and not isnull( transperiod ); 
    
    if ( isnull( transperiod ) ) // similar idea, but adding on to the next period
    {
      transperiod := select( this, TransitionPeriod_MP, tp, true, guard( tp.UnitPeriod() = ocusp.NextSubPeriod().UnitPeriod(), false ) ); 
    }
    addedtonext := not addedtoprevious and not addedtocurrent and not isnull( transperiod ); 
    
    if ( isnull( transperiod ) ) 
    {
      ptoquantity := sum(  elt, OptCampaignPeriodTaskInCombiElement, p, true, p.Quantity() ); 
      if ( ptoquantity > 0.0 ) 
      {
        task.Log( 'trans' + this.TransitionType_MP().Name() + [String] this.Start() + [String] this.End() ); 
        traverse( this, TransitionPeriod_MP, tp ) 
        {
          task.Log(  '   I have trans periods' +[String] tp.Start() + [String] tp.End() +  'with up' + [String] tp.UnitPeriod().Start() + [String] tp.Key() )
        }
        task.Log(  'Looking for:' + elt.Name() +  elt.OptCampaignCombi().Name() +  'qty to write= ' + [String] ptoquantity + 'ocusp' +[String] ocusp.StartTime() + [String] ocusp.EndTime() +  'with up = ' + [String] ocusp.UnitPeriod().Start() + [String] ocusp.UnitPeriod().End() ); 
      }
    }
    else
    {
      traverse( elt, OptCampaignPeriodTaskInCombiElement, pto ) 
      {
        pto.WriteQuantity( transperiod ); // find period task in campaign corresponding to opt periodtask and write back
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}