yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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 SyncPlannedOrdersFromMacroPlan (
  MacroPlan macroplan,
  String mpsplanid
)
{
  Description: 'Create planned orders from period tasks from macroplan.'
  TextBody:
  [*
    existing := this.IOMPSPlannedOrder( relget );
    updates := construct( IOMPSPlannedOrders );
    
    // Get periods within the planning horizon
    end := macroplan.LastPlanningPeriod().End();
    if( macroplan.GlobalParameters_MP().ExportHorizon().IsFinite() )
    {
      end := macroplan.StartOfPlanning() + macroplan.GlobalParameters_MP().ExportHorizon();
    }
    
    periods := selectset( macroplan, PlanningPeriod, pp, pp.IsInPeriod( macroplan.StartOfPlanning(), end ) );
    routings := selectset( macroplan, Routing, r, r.IsEnabled() );
    
    // Group by Period, RoutingID
    traverse( periods, Elements, p )
    {
      traverse( routings, Elements.LastStep, ls )
      {
        qty := sum( ls, Operation.PeriodTaskOperation, pto, pto.Quantity() > 0.0 and pto.UnitPeriod().Period_MP() = p, pto.Quantity() );
        
        if( qty > 0.0 )
        {
          ioplannedorder := IOMPSPlannedOrder::Create( this, ls.RoutingID(), p.End(), mpsplanid, qty, p.Start(), p.End() );
        
          updates.Add( ioplannedorder );
        }
      }
    }
    
    // Get the set of old PlannedOrder to be deleted
    tobedeleteset := existing.Difference( updates );
    
    traverse( tobedeleteset, Elements, ele )
    {
      ele.Delete();
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}