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
Quintiq file version 2.0
#parent: #root
Method CleanUpStockingPointCapacity
{
  Description: 'Find sets of equivalent stocking point capacities in consecutive periods and remove all but the first one'
  TextBody:
  [*
    // Find sets of equivalent stocking point capacities in consecutive periods and remove all but the first one
    sortedspcs := selectsortedset( this, StockingPointCapacity, spc, 
                                   true, 
                                   spc.Start() );
    
    head := null( StockingPointCapacity );
    
    // Traverse the sorted set of StockingPointCapacities
    traverse( sortedspcs, Elements, spc )
    {
      // Check if there are any selected StockingPointCapacity, if none, set the current StockingPointCapacity as selected
      if( isnull( head ) )
      {
        head := spc;
      }
    
      // Get the index of the selected StockingPointCapacity in the sorted set
      headpos := sortedspcs.Find( head );
      // Get the next StockingPointCapacity after the selected StockingPointCapacity in the sorted set
      nextspc := guard( sortedspcs.Element( headpos + 1 ), null( StockingPointCapacity ) );
    
      // Check if next StockingPointCapacity is found
      if( not isnull( nextspc ) )
      {
        // Check if next StockingPointCapacity has the same data as the selected StockingPointCapacity
        if( head.HasSameData( nextspc ) )
        {
          // If next StockingPointCapacity has the same data as the selected StockingPointCapacity,
          // remove it from the sorted set and delete from the dataset
          sortedspcs.Remove( nextspc );
          nextspc.Delete();
        }
        else
        {
          // If the next StockingPointCapacity doesn't has the same data as the selected StockingPointCapacity,
          // set it as the selected StockingPointCapacity
          head := nextspc;
        }
      }
    }
  *]
}