Quintiq file version 2.0
#parent: #root
Method CreateSCVSDNode (
  output owning shadow[SCVConfiguration] scvConfig,
  shadow[SCVNode] ownernode,
  ProductInStockingPointInPeriod pispip,
  Boolean isupstream
) as shadow[SCVNode] id:Method_FormSupplyChainVisualization_CreateSCVSDNode
{
  #keys: '[134266.1.1611597158]'
  Body:
  [*
    // Create inventory supply node and edge
    scvNode := null( shadow[SCVSDNode] );
    
    if( pispip.SalesDemandInPeriodBase( relsize ) > 0 )
    {
      // Make sure we are still within the limit                          
      if( ownernode.Depth() < scvConfig.DownstreamDepthLimit() )
      { 
        // Retrive sales segment names
        // if we get only one, means this 
        // node is linked to only 1 sales segment
        salesSegments := selectuniquevalues( pispip, SalesDemandInPeriodBase, sdipbase,
                                             true,
                                             sdipbase.SalesSegmentName() )
        
        isLinkedToMultipleSalesSegments := salesSegments.Size() > 1;
        
        scvNode := scvConfig.SCVNode( relnew,
                                      SCVSDNode,
                                      ProductInStockingPointInPeriod := pispip, 
                                      IsLinkedToMultipleSalesSegments := isLinkedToMultipleSalesSegments,
                                      Name := ifexpr( isLinkedToMultipleSalesSegments, 
                                                      Translations::MP_SCV_Label_MultipleSalesSegments(), 
                                                      salesSegments.Element( 0 ) ) );
        
        this.CreateSCVEdge( &scvConfig, ownernode, scvNode, isupstream, null( Process_MP ) );
      }
      else
      {
        ownernode.IsDepthLimitMet( true );
      }
    }
    
    return scvNode;
  *]
}
