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
Quintiq file version 2.0
#parent: #root
Method SetDefaultDisplayIndexForUnit
{
  Description: 'Set default display index for unit'
  TextBody:
  [*
    // Level-order traversal of Unit hierarchy
    // Start with root units, sorted by name
    queue := selectsortedset( this, Unit, unit, isnull( unit.Parent() ), unit.Name() );
    i := 0;
    while( queue.Size() > 0 )
    {
      // Get leading unit
      unit := queue.Element( 0 );
      unit.DisplayIndexForExcel( i );
      i++;
    
      // Add child units to the queue, sorted by name
      childunits := selectsortedset( unit, Child, child, true, child.Name() );
      traverse( childunits, Elements, child )
      {
        queue.Add( child );
      }
      // Remove leading unit from queue
      queue.Remove( unit );
    }
  *]
}