Quintiq file version 2.0
#parent: #root
Method CreateInventorySupply (
  structured[ProductInStockingPointInPeriod] selection,
  internal[GUIComponent] parent
) id:Method_DialogCreateEditInventorySupply_CreateInventorySupply_676
{
  #keys: '[124808.0.458558795]'
  Body:
  [*
    // Create inventory supply from PISPIP
    ValueHolderIsBatchEdit.Value( [String] false );
    Dialog.ShowHideComponentForBatchEdit( false );
    
    data := null( shadow[InventorySupply] );
    
    feedback := '';
    id := MacroPlan.IDHolder().GetInventorySupplyID();
    stockingpoint := null( StockingPoint_MP );
    owner := InventorySupply::GetDefaultOwner( MacroPlan, stockingpoint );
    // directly trying to use StartOfPlanningPeriod.StartDate could give errors
    // if none of the periods are used for planning. Thus, added a guard and a local variable.
    startOfPlanningPeriod := MacroPlan.StartOfPlanningPeriod();
    date := guard( startOfPlanningPeriod.StartDate(), Date::MinDate() );
    min_mfgdate := date;
    
    if( not isnull( selection ) and InventorySupply::CanCreate( feedback, selection ) )
    {
      pispip := selection.Element( 0 );
      owner := pispip.ProductInStockingPoint_MP().Product_MP();
      stockingpoint := pispip.ProductInStockingPoint_MP().StockingPoint_MP();
      date := selection.Element( 0 ).Start().Date();
      min_mfgdate := date;
    }
    
    data := owner.InventorySupply( relshadow,
                                   ID := id,
                                   StockingPoint_MP := stockingpoint,
                                   Date := date,
                                   ManufacturedDate := min_mfgdate );
                                     
    Dialog.Data( data );
    result := this.DoModal( parent );
    
    if ( result > 0 )
    {                                                                                                            
      //if manufactured date is restricted, default it to date of inv supply
      data.ManufacturedDate( this.GetManufacturedDateWithUIRestriction( data.ManufacturedDate(), data.Date() ) );
      data.Commit();
    }
  *]
}
