Quintiq file version 2.0
#parent: #root
Method OnOK () id:Method_DialogCreateEditSafetyStock_OnOK
{
  #keys: '[136682.1.2144769365]'
  Body:
  [*
    //OnOK
    Form.ApplyChanges();
    
    istargetinday := [Boolean]rbgSafetyStock.BoundValue()
    targetindays := ifexpr( istargetinday, ApplicationMacroPlanner.FormatStringToReal( efSafetyStockInDays.Text(),0.0), 0.0 );
    targetinqty := ifexpr( not istargetinday, ApplicationMacroPlanner.FormatStringToReal( efSafetyStockInQuantity.Text(),0.0 ), 0.0 );
    
    if ( isnull( DataHolderDialogData.Data().WrappedInstance() ) )
    {
        newsafetystock := SafetyStock::Create( ddlProduct.Data(),
                             ddlStockingPoint.Data(),
                             dsStart.Date(),
                             istargetinday, targetindays, targetinqty,            // Does not have a target in days, the initial targets are 0
                             false, cbOverrideCalculatedSafetyStock.Checked(), false );
        // Access the form, select the new safety stock
        DataHolderForm.Data().ListSafetyStocks().SelectByKey( newsafetystock.Key() );
    }
    else
    {
       
       SafetyStock::Update( DataHolderDialogDatas.Data(),
                           ddlProduct.Data(),
                           ddlStockingPoint.Data(),
                           dsStart.Date(),
                           istargetinday, targetindays, targetinqty,            // Does not have a target in days, the initial targets are 0
                           false, cbOverrideCalculatedSafetyStock.Checked(), false );     
      
    }
    
    Form.Close();
  *]
}
