Quintiq file version 2.0 
 | 
#parent: #root 
 | 
StaticMethod CreateUpdate ( 
 | 
  MacroPlan owner, 
 | 
  DateTime scheduleStart, 
 | 
  DateTime scheduleEnd, 
 | 
  String scheduleResourceID, 
 | 
  String scheduleRoutingID, 
 | 
  Number scheduleRoutingStepSeqNr, 
 | 
  Real scheduleQuantity, 
 | 
  output FeedbackPeriodTaskOperations feedbackPTOs_o 
 | 
) 
 | 
{ 
 | 
  Description: 'Create one or more FeedbackPeriodTaskOperation (depending if span multiple periods)' 
 | 
  TextBody: 
 | 
  [* 
 | 
    planningperiods := selectsortedset( owner, PlanningPeriod, pp, pp.IsInPeriod( scheduleStart, scheduleEnd ), scheduleStart ); 
 | 
     
 | 
    traverse( planningperiods, Elements, planningPeriod ) 
 | 
    { 
 | 
      ratio := guard( ( minvalue( planningPeriod.End(), scheduleEnd ) - maxvalue( planningPeriod.Start(), scheduleStart ) ) / ( scheduleEnd - scheduleStart ), 0 ); 
 | 
      qty := scheduleQuantity * ratio; 
 | 
       
 | 
      unit := Unit::FindUnitTypeIndex( scheduleResourceID ); 
 | 
      operation := select( unit, Operation, op, op.RoutingID() = scheduleRoutingID and op.RoutingStepSeqNr() = scheduleRoutingStepSeqNr ); 
 | 
                                                                       
 | 
      existingFeedback := select( operation, FeedbackPeriodTaskOperation, fpto, fpto.IsLocked() and fpto.DateTime() = planningPeriod.Start() ); 
 | 
      if( isnull( existingFeedback ) ) 
 | 
      { 
 | 
        existingFeedback := FeedbackPeriodTaskOperation::Create( owner, 
 | 
                                                                 owner.IDHolder().GetFeedbackID(), 
 | 
                                                                 guard( operation.ID(), '' ), 
 | 
                                                                 planningPeriod.Start(), 
 | 
                                                                 qty, 
 | 
                                                                 '', 
 | 
                                                                 true /*isplannedexact*/, 
 | 
                                                                 false ); /*isfromdb*/ 
 | 
        // For above select to work (if multiple feedback for operation to able find the newly created feedback)                                                                  
 | 
        Transaction::Transaction().Propagate( relation( Operation, FeedbackPeriodTaskOperation ) ); 
 | 
        feedbackPTOs_o.Add( existingFeedback );                                                           
 | 
      } 
 | 
      else 
 | 
      { 
 | 
        if( feedbackPTOs_o.Find( existingFeedback ) >= 0 ) // Add-on the quantity instead of replace 
 | 
        { 
 | 
          existingFeedback.UpdateQtyDelta( qty );  
 | 
        } 
 | 
        else // Replaces the quantity 
 | 
        { 
 | 
          existingFeedback.Update( qty, existingFeedback.Description(), not existingFeedback.IsManuallyConfigured() ); 
 | 
          feedbackPTOs_o.Add( existingFeedback ); // Only add to structured if not already in it 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |