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
Quintiq file version 2.0
#parent: #root
Method GetSupplyChain (
  GraphProgramGraph tree
) as String
{
  Description: 'Construct the CSV string of the product specific supply chain. Input is tree from Treeify algorithm'
  TextBody:
  [*
    // Construct of strings, each element correspond to one line in CSV string
    pisps_string := construct( Strings );
    
    // Header in CSV string
    pisps_string.Add( "product;upstream;downstream;leadtime")
    
    // Select root node of tree
    root := select( tree, Nodes, node, node.Name() = MEIO_Treeify::GetArtificialRootName() );
    
    // Traverse through all non-root nodes to create CSV rows
    traverse( tree, Nodes, node, node <> root )
    {
      downstream := node.Object1().astype( ProductInStockingPoint_MP );
      upstream_node := select( node, Input, n, true );
      if( not isnull( upstream_node ) )
      {
        // Collect leadtime, upstream PISP name, downstream PISP name, and leadtime between the two
        leadtime := [String]downstream.MEIO_Leadtime();
        upstream := upstream_node.Input().Object1().astype( ProductInStockingPoint_MP );
        upstreamName := guard( upstream.Name(), MEIO_Treeify::GetArtificialRootName() );
        
        // Create a row for the CSV on the header-format
        pisp_string := downstream.Product_MP().Name() + this.Separator() + upstreamName + this.Separator() + downstream.Name() + this.Separator() + leadtime;
        pisps_string.Add( pisp_string );
      }
    }
    
    value := pisps_string.ToString( String::NewLine() );
    Transaction::Transaction().Propagate( attribute( ProductInStockingPointInPeriodPlanningLeaf, IsActiveInMEIO ) ); 
    
    return value;
  *]
}