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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Quintiq file version 2.0
#parent: #root
Method ResetPeriodTasksAndResetKPI (
  Boolean resetmanual,
  Boolean resetoptimizer,
  OptimizerPuzzle optimizerpuzzle,
  Date unplanafterstart
)
{
  Description: 'Reset period tasks and update KPI'
  TextBody:
  [*
    // FrozenPeriod moves to Unit level
    // During reset, to traverse all active LeadingPeriod, then only filter out frozen PT
    
    // Handleing case null( OptimizerPuzzle )
    if( isnull( optimizerpuzzle ) )
    {
      optimizerpuzzle := this.OptimizerPuzzleWorld();  
    }
    
    // Use the logic used by the dialog to create all subsets
    // Populate the IsInclduedFinal
    // We get the 100% correct result for unit, product, stocking point
    
    // Getting list of included units / included products / included stockingpoint 
    // Prevent from calling GetIncludedUnits multiple times
    includedUnits := optimizerpuzzle.GetIncludedUnits();
    includedProducts := optimizerpuzzle.GetIncludedProducts();
    includedStockingPoint := optimizerpuzzle.GetIncludedStockingPoints( includedUnits );
    includedPISP := optimizerpuzzle.GetIncludedPISP( includedProducts, includedStockingPoint );
    
    // Reset PeriodTasks
    // Get routings with Operations and pisps included in the optimizer puzzle scope
    routings := optimizerpuzzle.GetIncludedRoutings( includedUnits, includedPISP ); 
    
    // Traverse in scope routings in order to reset PeriodTask operation not frozen
    traverse( routings, Elements, routing )
    {
       routing.ResetRouting( resetmanual, resetoptimizer, unplanafterstart );
    }
    
    // Reset Trips
    // Get process Laneleg in optimizer puzzle scope ( Unit, destination StockingPoint_MP in scope )
    processesLaneleg := optimizerpuzzle.GetIncludedLaneLegs( includedUnits, includedPISP );
    
    // Reset products in trips only if the product in trip is in scope ( Product_MP in scope )
    traverse( processesLaneleg, Elements.Trip.ProductInTrip, pit, optimizerpuzzle.IsProductIncluded( pit.Product_MP(), includedProducts ) and pit.Trip().Departure().Date() >= unplanafterstart )
    {
      pit.ResetProductInTrip( resetmanual, resetoptimizer );
    }
    
    
    // Some pispips do not have new supply and period task due to pre & post-processing time.
    traverse( this, Unit.Process_MP.ProcessOutput.ProductInStockingPoint_MP, pisp, pisp.IsLeaf() )
    {
      traverse( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), p, not p.IsPeriodFrozen() and p.Start().Date() >= unplanafterstart )
      {  
        if(  p.NewSupply( relsize ) = 0 )
        {
          p.ResetQuantitySetByOptimizer(); 
        }
        
        p.MergeSalesDemand( resetmanual )
      }
    }
    
    if( resetmanual )
    {
      traverse( this, Period_MP.ProductInStockingPointInPeriod, pispip, pispip.Start().Date() >= unplanafterstart )
      {
        pispip.UpdateTotalSupplyUser( false, 0.0 );
        pispip.UpdateTotalAvailableSupplyUser( false, 0.0 );
      }
    }
    
    // Remove pegging
    this.RemovePegging( resetmanual, resetoptimizer );
    
    // Calculate KPI Score
    this.CalculateKPIScore( false );
    
    this.UpdateLastPlanningAction( true, false, false, false ); // isReset, isPlan, isRoll, isLockUnlock
    
    // Change lastUsedReset OptimizerPuzzle
    if( not isnull( optimizerpuzzle ) )
    { 
      optimizerpuzzle.ChangeLastUsedResetPuzzle();
    }
  *]
  InterfaceProperties { Accessibility: 'Extensible' }
}