Quintiq file version 2.0
#parent: #root
Method OnOK () id:Method_DialogCreateEditInventoryTarget_OnOK
{
  #keys: '[139394.1.939163035]'
  Body:
  [*
    // On ok
    this.ApplyChanges();
    
    data := DataHolderDialogData.Data();
    
    if( isnull( data.WrappedInstance() ) )
    {
      newinvspec := InventorySpecification::Create( data.Product_MP(),
                                      data.StockingPoint_MP(),
                                      data.Start(),
                                      false,
                                      0.0,
                                      0.0,
                                      data.HasMinLevelInDays(),
                                      ApplicationMacroPlanner.FormatStringToReal( efMinInventoryLevel.Text() ),
                                      ApplicationMacroPlanner.FormatStringToReal( efMinInventoryLevel.Text() ),
                                      data.HasMaxLevel(),
                                      data.HasMaxLevelInDays(),
                                      ApplicationMacroPlanner.FormatStringToReal( efMaxInventoryLevel.Text() ),
                                      ApplicationMacroPlanner.FormatStringToReal( efMaxInventoryLevel.Text() ),
                                      false /*iscalculated*/,
                                      false /*isfromdb*/ );
      // Access the form, select the new inventory spec
      DataHolderForm.Data().ListInventoryTargets().SelectByKey( newinvspec.Key() );
       
    }
    else
    {
      InventorySpecification::Update( DataHolderDialogDatas.Data(),
                                      data.Product_MP(),
                                      data.StockingPoint_MP(),
                                      dsStart.Date(), // Read-only, apply changes to shadow is not taking place for read-only attribute when editing.
                                      false /*batchedittarget*/, // Target is now handled in object Safety Stock
                                      false /*hastragetindays*/,
                                      0.0 /*TargetInDays*/,
                                      0.0 /*TargetInQuantity*/,
                                      cbBatchEditMinInventory.Checked(),
                                      data.HasMinLevelInDays(),
                                      ApplicationMacroPlanner.FormatStringToReal( efMinInventoryLevel.Text() ),
                                      ApplicationMacroPlanner.FormatStringToReal( efMinInventoryLevel.Text() ),
                                      cbBatchEditMaxInventory.Checked(),
                                      data.HasMaxLevel(),
                                      data.HasMaxLevelInDays(),
                                      ApplicationMacroPlanner.FormatStringToReal( efMaxInventoryLevel.Text() ),
                                      ApplicationMacroPlanner.FormatStringToReal( efMaxInventoryLevel.Text() ),
                                      false /*isfromdb*/ );  
    }
    
    this.Close();
  *]
}
