Quintiq file version 2.0
#parent: #root
Method SetDefaultValue (
  ProductInStockingPointInPeriod pispip
) id:Method_DialogCreateEditInventorySpecification_SetDefaultValue
{
  #keys: '[105706.0.1326635825]'
  Body:
  [*
    // Set the default value for the fields in the dialog
    
    data := Dialog.Data();
    
    start := MacroPlan.Start().Date();
    hasmininday := false;
    mininday := 0.0;
    mininquantity := 0.0;
    hasmax := false;
    hasmaxinday := false;
    maxinday := 0.0;
    maxinquantity := 0.0;
    
    if( not isnull( pispip ) )
    {
      // To inherit the value from last inventory spec while creating a new inventory spec
      inventoryspec := pispip.InventorySpecification();
      start := pispip.Start().Date();
    
      if( not isnull( inventoryspec  ) )
      {
        hasmininday := inventoryspec.HasMinLevelInDays();
        mininday := inventoryspec.MinLevelInDays();
        mininquantity := inventoryspec.MinLevelInQuantity();
        hasmax := inventoryspec.HasMaxLevel();
        hasmaxinday := inventoryspec.HasMaxLevelInDays();
        maxinday := inventoryspec.MaxLevelInDays();
        maxinquantity := inventoryspec.MaxLevelInQuantity();
      }
      else
      {
        hasmininday := pispip.GetHasMinLevelInDays(); 
        mininday := pispip.MinLevelInDays();
        mininquantity := pispip.MinLevelInQuantity();
        hasmax := pispip.GetHasMaxLevel();
        hasmaxinday := pispip.GetHasMaxLevelInDays();
        maxinday := pispip.MaxLevelInDays();
        maxinquantity := pispip.MaxLevelInQuantity();
      }
    }
    
    // Assigning value to Read-Only attribute will result in runtime error.
    if( isnull( data.WrappedInstance() ) )
    {
      data.Start( start );
    }
    
    
    data.HasMinLevelInDays( hasmininday )
    data.MinLevelInDays( mininday );
    data.MinLevelInQuantity( mininquantity );
    
    data.HasMaxLevel( hasmax );
    data.HasMaxLevelInDays( hasmaxinday );
    data.MaxLevelInDays( maxinday );
    data.MaxLevelInQuantity( maxinquantity );
  *]
}
