chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
53
54
55
56
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
        }
      }
    }
  *]
}