陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
Quintiq file version 2.0
#parent: #root
Method WriteOptCampaignPeriodTaskQuantities (
  LibOpt_Task task,
  OptCampaignCombiElementCampaign elt
)
{
  Description: 'Write out combi world quantities to period task in campaign objects'
  TextBody:
  [*
    ocusp := elt.OptCampaignUnitSubPeriod(); 
    
    Transaction::Transaction().Propagate( relation( Campaign_MP, CampaignPeriod_MP ) ); // we increase the campaign duration so now we want to make sure campaign periods are ok
    Transaction::Transaction().Propagate( relation( CampaignPeriod_MP, UnitPeriod ) ); // we use this relation below to look-up the campaign period
    Transaction::Transaction().Propagate( relation( PeriodTaskInCampaign, CampaignPeriod_MP ) );  // writing to period tasks in this method, set relations right
                                          
    campaignperiod := select( this, CampaignPeriod_MP, cp, true, cp.UnitPeriod() = ocusp.UnitPeriod() ); 
    
    if ( isnull( campaignperiod ) ) // 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. 
    {
      campaignperiod := select( this, CampaignPeriod_MP, cp, true, guard( cp.UnitPeriod() = ocusp.PreviousSubPeriod().UnitPeriod(), false ) ); 
    }
    
    if ( isnull( campaignperiod ) ) // similar idea, but adding on to the next period
    {
      campaignperiod := select( this, CampaignPeriod_MP, cp, true, guard( cp.UnitPeriod() = ocusp.NextSubPeriod().UnitPeriod(), false ) ); 
    }
    
    if ( isnull( campaignperiod ) ) 
    {
      ptoquantity := sum(  elt, OptCampaignPeriodTaskInCombiElement, p, true, p.Quantity() ); 
      if ( ptoquantity > 0.0 ) 
      {
        task.Log( 'campaign' + this.CampaignType_MP().Name() + [String] this.Start() + [String] this.End() ); 
        traverse( this, CampaignPeriod_MP, cp ) 
        {
          task.Log(  '   I have campaign periods' +[String] cp.Start() + [String] cp.End() +  'with up' + [String] cp.UnitPeriod().Start() + [String] cp.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( campaignperiod ); // find period task in campaign corresponding to opt periodtask and write back
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Extensible' }
}