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
Quintiq file version 2.0
#parent: #root
Method CleanUpTransportAvailability
{
  TextBody:
  [*
    // Clean up transport availability
    // Get a sorted set of all transport availabilities of this unit
    sortedtas := selectsortedset( this, TransportAvailability, ta, 
                                  true, 
                                  ta.Start() );
                                  
    head := null( TransportAvailability );
    
    // Traverse the sorted set of transport availabilities
    traverse( sortedtas, Elements, ta )
    {
      // Check if there's any transport availability is selected, if there's none, set the current transport availability as selected
      if( isnull( head ) )
      {
        head := ta;
      }
    
      // Get the index of the selected transport availability in the sorted set
      headpos := sortedtas.Find( head );
      // Get the next transport availability after the selected transport availability in the sorted set
      nextta := guard( sortedtas.Element( headpos + 1 ), null( TransportAvailability ) );
    
      // Check if there's any next transport availability
      if( not isnull( nextta ) )
      {
        // Check if the next transport availability has the same data as the selected one
        // If the data is the same, remove the next transport availability from the sorted set and dataset
        if( head.HasSameData( nextta ) )
        {
          sortedtas.Remove( nextta );
          nextta.Delete();
        }
        // Else, set the next transport availability as the selected one
        else
        {
          head := nextta;
        }
      }
    }
  *]
}