admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
Quintiq file version 2.0
#parent: #root
Method GetServiceLevel () declarative remote as ServiceLevelBase
{
  Description: 'Selects and returns  the ServiceLevel object'
  TextBody:
  [*
    // edz1 Jul-11-2016 (created)
    
    servicelevel := null( ServiceLevelBase );
    
    setservicelevels := selectset( this, 
                                    ProductInStockingPoint_MP.ServiceLevels, 
                                    sl, 
                                    sl.IsUsedForSafetyStockCalculation() 
                                    and sl.IsEnabled()
                                    and Period_MP::IsInPeriod( this.Start(), this.End(), sl.Start().DateTime(), sl.End().DateTime() ) );
    
    //When no service level is defined on PISP with the matching date, look for service level where the prod / sp is specified.
    if( setservicelevels.Size() = 0 )                                                                                    
    {
      setservicelevels := selectset( this, 
                                     ProductInStockingPoint_MP.Product_MP.MacroPlan.SafetyStockCalculationServiceLevel, 
                                     sl, 
                                     sl.IsUsedForSafetyStockCalculation() 
                                     and sl.IsEnabled(), 
                                     ( isnull( sl.Product_MP() ) or sl.Product_MP() = this.ProductInStockingPoint_MP().Product_MP() )
                                     and ( isnull( sl.StockingPoint_MP() ) or sl.StockingPoint_MP() = this.StockingPointInPeriod().StockingPoint_MP() ) 
                                     and Period_MP::IsInPeriod( this.Start(), this.End(), sl.Start().DateTime(), sl.End().DateTime() ) );
    }
    if( setservicelevels.Size() > 0 )
    {
      servicelevel := maxselect ( setservicelevels, Elements, sl, true,  sl.TargetPercentage() )
    }
    // If no service levels have been found, then check whether a service level has been defined for a parent of this product
    // Martijn: I cannot make it recursive because it is declarative
    // So I have to repeat the method but then while checking if the product of the service level is a parent of this product
    else
    {
      // This will only select the service levels if it is on the direct parent (not a parent of the parent)
      // The next if loop will select the service levels that are on higher level parents
      setservicelevels := selectset( this, 
                                     ParentOfProductDimension.ProductInStockingPoint_MP.ServiceLevels, 
                                     sl, 
                                     sl.IsUsedForSafetyStockCalculation() 
                                     and sl.IsEnabled()
                                     and Period_MP::IsInPeriod( this.Start(), this.End(), sl.Start().DateTime(), sl.End().DateTime() ) );
    
      //When no service level is defined on PISP with the matching date, look for service level where the prod / sp is specified.
      if( setservicelevels.Size() = 0 )                                                                                    
      {
        setservicelevels := selectset( this, 
                                       ProductInStockingPoint_MP.Product_MP.MacroPlan.SafetyStockCalculationServiceLevel, 
                                       sl, 
                                       sl.IsUsedForSafetyStockCalculation() 
                                       and sl.IsEnabled(), 
                                       ( isnull( sl.Product_MP() ) or sl.Product_MP().IsParentOf( this.ProductInStockingPoint_MP().Product_MP() ) )
                                       and ( isnull( sl.StockingPoint_MP() ) or sl.StockingPoint_MP() = this.StockingPointInPeriod().StockingPoint_MP() ) 
                                       and Period_MP::IsInPeriod( this.Start(), this.End(), sl.Start().DateTime(), sl.End().DateTime() ) );
      }
      if( setservicelevels.Size() > 0 )
      {
        servicelevel := maxselect ( setservicelevels, Elements, sl, true,  sl.TargetPercentage() )
      }
    }
    
    return servicelevel;
  *]
}