| 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; | 
|         } | 
|       } | 
|     } | 
|   *] | 
| } |