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
Quintiq file version 2.0
#parent: #root
Method MPSyncDetailedSchedule (
  Boolean isoverwitemanualconfig,
  IODetailedSchedules iodetailedschedule_mps
)
{
  Description: 'Synchronization of Detailed Schedules to Feedback for MPSync'
  TextBody:
  [*
    // Select a set of existing Feedbacks, only get frozen 
    existing := selectset( this, Feedback.astype( FeedbackPeriodTaskOperation ), feedback, feedback.IsLocked() );
    updates := construct( FeedbackPeriodTaskOperations );
    
    // The synchronization is as follow
    // 1. We group scheduled work orders according to operationID and datetime
    // 2. Then group planning periods by datetime
    // We then loop through sorted scheduled work orders
    // for each detailed scheule, we populate all 
    // planning operation period tasks associated to it
    if( iodetailedschedule_mps.Size() > 0 )
    {
      iodetailedschedule_mps.Sort( attribute( IODetailedSchedule, RoutingID ), true /*ascending*/,
                                   attribute( IODetailedSchedule, RoutingStepSeqNr ), true /*ascending*/,
                                   attribute( IODetailedSchedule, ResourceID ), true /*ascending*/,
                                   attribute( IODetailedSchedule, ScheduledStart ), true /*ascending*/,
                                   attribute( IODetailedSchedule, ScheduledEnd ), true /*ascending*/ );
       
      traverse( iodetailedschedule_mps, Elements, ioschwo )
      {
        FeedbackPeriodTaskOperation::CreateUpdate( this,
                                                   ioschwo.ScheduledStart(), ioschwo.ScheduledEnd(), ioschwo.ResourceID(), 
                                                   ioschwo.RoutingID(), ioschwo.RoutingStepSeqNr(), ioschwo.Quantity(), 
                                                   updates /* output structured FeedbackPTO */ );
      }
    }
    
    this.PostProcessDetailScheduleFeedback( true, updates, existing );//set to false if not creating zero feedback
    // Get the set of old Feedback to be deleted
    tobedeleteset := existing.Difference( updates );
    // Traverse the set of Feedback to be deleted
    // Only delete Feedback that is not manually configured or the imported instance should overwrite manual configuration
    traverse( tobedeleteset, Elements, ele, not ele.IsManuallyConfigured() or isoverwitemanualconfig)
    {
      ele.Delete();
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}