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