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' } 
 | 
} 
 |