Quintiq file version 2.0
#parent: #root
Method New () id:Method_DialogCreateEditExternalSupply_New
{
  #keys: '[136682.1.2082707088]'
  Body:
  [*
    //Create New Inventory Supply
    
    id := MacroPlan.IDHolder().GetInventorySupplyID();
    stockingpoint := select( DataHolderStockingPoint.Data(), Elements, e, not e.IsSystem() );
    owner := select( DataHolderProduct.Data(), Elements, product, not product.IsSystem() and product.IsLeaf() );
    // 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;
    
    
    data := owner.InventorySupply( relshadow,
                                   ID := id,
                                   StockingPoint_MP := stockingpoint,
                                   Date := date,
                                   ManufacturedDate := min_mfgdate );
                                     
    
    DataHolderExternalSupply.Data( &data );
    pnlContent.OnUserUpdateUI( owner, stockingpoint, Form.IsBatchEdit() );
    ApplicationMacroPlanner.ShowFormModal( Form );
  *]
}
