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
Quintiq file version 2.0
#parent: #root
StaticMethod ConvertToFulfillmentGoal (
  MacroPlan macroplan,
  Boolean isimportservicelevel
)
{
  Description: 'This method mainly to convert data from 2016 Q4 to 2017 Q1 service level that with isusedForPlanningFulfillment, once the data converted the method can be removed'
  TextBody:
  [*
    // This method mainly to convert data from 2016 Q4 to 2017 Q1 service level that with isusedForPlanningFulfillment, once the data converted the method can be removed
    if( isimportservicelevel)
    {
      // Traverse all ServiceLevels of the passed in MacroPlan that has IsUsedForPlanningFulfillment = TRUE
      traverse( macroplan, ServiceLevel, servicelevel, servicelevel.IsUsedForPlanningFulfillment() )
      {
        // Find Product_MP, StockingPoint_MP, & SalesSegment_MP with the IDs from the current ServiceLevel
        product := Product_MP::FindProductTypeIndex( servicelevel.ProductID() );
        stockingpoint := StockingPoint_MP::FindStockingPointTypeIndex( servicelevel.StockingPointID() );
        salessegment := SalesSegment_MP::FindSalesSegmentTypeIndex( servicelevel.SalesSegmentName() );
    
        // Try to find a FulfillmentTarget that matches the data from the current ServiceLevel
        fulfillmenttarget := select ( macroplan, 
                                      FulfillmentTarget,
                                      f,
                                      f.StockingPointID() = servicelevel.StockingPointID()
                                      and f.ProductID()= servicelevel.ProductID()
                                      and f.SalesSegmentName()= servicelevel.SalesSegmentName()
                                      and f.Start() = servicelevel.Start()
                                      and f.End() = servicelevel.End()
                                      and f.TargetPercentage() = servicelevel.TargetPercentage() );
                                      
        // Create the FulfillmentTarget with data from the current ServiceLevel if no existing FulfillmentTarget is found
        if( isnull( fulfillmenttarget ) )
        {
          FulfillmentTarget::Create( macroplan, 
                                     servicelevel.ID(),
                                     servicelevel.IsEnabled(),
                                     servicelevel.Name(),
                                     product,
                                     stockingpoint,
                                     salessegment,
                                     servicelevel.TargetPercentage(),
                                     servicelevel.Start(),
                                     servicelevel.End(),
                                     false,
                                     true,
                                     servicelevel.IsManuallyConfigured());
                                     
        }
        
        // Delete the current ServiceLevel
        servicelevel.Delete();
      }
    }
  *]
}