Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Quintiq file version 2.0
#parent: #root
Method PostProcessDetailScheduleFeedback (
  Boolean isgeneratezerofeedback,
  output FeedbackPeriodTaskOperations updates,
  output FeedbackPeriodTaskOperations existings
)
{
  Description: 'Only generate zero feedback for operation without feedback within the mp sc schedule horizon'
  TextBody:
  [*
    if( isgeneratezerofeedback )
    {
      operations := selectset( this, Unit.Operation, operation, not isnull( operation.AsOperationForOptimization() ) );
      feedbacks := selectsortedset( updates, Elements, f, true, f.DateTime() );
      
      schorizonstart := guard( feedbacks.First().DateTime(), DateTime::MaxDateTime() );
      schorizonend := guard( feedbacks.Last().DateTime(), DateTime::MinDateTime() );
      
      planningperiods := selectsortedset( this, PlanningPeriod, pp, pp.Start()>= schorizonstart and pp.Start()<= schorizonend , pp.Start() );                       
      
      if ( planningperiods.Size() > 0 )
      {
        canbedeleted := existings.Difference( updates );
        
        traverse( operations, Elements, op )
        {
            traverse( planningperiods, Elements, pp )
            {
                //check on newly updated or created feedback
                feedback := select( feedbacks, 
                                    Elements, 
                                    updatedfeedback, 
                                    pp.IsInPeriod( updatedfeedback.DateTime(), updatedfeedback.DateTime() ) and updatedfeedback.OperationID() = op.ID() );
                
                //  only check on old feedback if cannot found
                if ( isnull( feedback ) ) 
                {
                  feedback := select( canbedeleted, 
                                      Elements, 
                                      oldfeedback, 
                                      pp.IsInPeriod( oldfeedback.DateTime(), oldfeedback.DateTime() ) and oldfeedback.OperationID() = op.ID() );
                  
                  //create if not found                                          
                  if ( isnull( feedback ) )
                  {
                       feedback := FeedbackPeriodTaskOperation::Create( this,
                                                            this.IDHolder().GetFeedbackID(),
                                                            guard( op.ID(), '' ),
                                                            pp.Start(),
                                                            0.0,
                                                            '',
                                                            true /*isplannedexact*/,
                                                            false ); /*isfromdb*/
                                                            
                  }
                  else // update feedbackquantity if found 1
                  {
                      feedback.FeedbackQuantity( 0.0 );
                  }
                  
                  updates.Add( feedback );
                }
                                                              
            }
        
        }                       
      
      }                       
                               
    }
  *]
}