Quintiq file version 2.0
#parent: #root
Method UIEnableDisableComponent (
  Boolean isInit
) id:Method_DialogCreateEditStockingPoint_UIEnableDisableComponent
{
  #keys: '[135040.0.219561692]'
  Body:
  [*
    batchValidityActive := not CheckBoxBatchEditValidity.Visible() 
                           or CheckBoxBatchEditValidity.Checked();
    
    // Enable / disable validity start
    hasValidityStartScrValue  := CheckboxHasStart.Checked();
    hasValidityStartDataValue := guard( DataHolderDialogData.Data().Start().DateTime().IsFinite(), false );
    hasValidityStartValue     := ifexpr( isInit
                                        ,hasValidityStartDataValue
                                        ,hasValidityStartScrValue );
    dsStart.Enabled( hasValidityStartValue
                     and batchValidityActive, "" );
    
    validityStartScrValue  := dsStart.Date();
    validityStartDataValue := guard( DataHolderDialogData.Data().Start(), Date::MinDate() );  //todo!! setting DateTime::MinDateTime() into datetimeSelector return strange value "Jan-1-0001 00:08:39". potential RFC?
    validityStartValue     := ifexpr( isInit
                                     ,validityStartDataValue
                                     ,validityStartScrValue );
    
    if( hasValidityStartValue and not isInit ) //user action check
    {
      defaultStart := MacroPlan.Start().Date();
      
      start := ifexpr( validityStartValue.IsFinite()  //todo!! setting DateTime::MinDateTime() into datetimeSelector return strange value "Jan-1-0001 00:08:39", hence, only get Date. Potential RFC?
                      ,validityStartValue
                      ,defaultStart );
      dsStart.Date( start ); 
    }
    else if( not hasValidityStartValue and not isInit ) //user action uncheck
    {
      dsStart.Date( Date::MinDate() ); 
    }
    
    // Enable / disable validity end
    hasValidityEndScrValue  := CheckboxHasEnd.Checked();
    hasValidityEndDataValue := guard( DataHolderDialogData.Data().End().DateTime().IsFinite(), false );
    hasValidityEndValue     := ifexpr( isInit
                                      ,hasValidityEndDataValue
                                      ,hasValidityEndScrValue );
    dsEnd.Enabled( hasValidityEndValue
                   and batchValidityActive, "" );
    
    validityEndScrValue  := dsEnd.Date();
    validityEndDataValue := guard( DataHolderDialogData.Data().End(), Date::MaxDate() );
    validityEndValue     := ifexpr( isInit
                                     ,validityEndDataValue
                                     ,validityEndScrValue );
    
    if( hasValidityEndValue and not isInit ) //user action check
    {
      defaultEnd := MacroPlan.End().Date();
      
      end := ifexpr( validityEndValue.IsFinite()
                    ,validityEndValue
                    ,defaultEnd );
      dsEnd.Date( end ); 
    }
    else if( not hasValidityEndValue and not isInit ) //user action uncheck
    {
      dsEnd.Date( Date::MaxDate() ); 
    }
  *]
}
