
-- Ordering_UseProcessingTimes = 80518

DECLARE @ConfigEnum INT = 80518;

-- Create Mobile 'Ordering' subgroup if it doesn't exist.
IF NOT EXISTS (SELECT 1 FROM [dbo].[tbConfigurationSubGroup] CSG INNER JOIN [dbo].[tbConfigurationGroup] CG ON CG.[ConfigurationGroupID] = CSG.[ConfigurationGroupID]
	WHERE CG.[Name] = 'Mobile' AND CSG.[Name] = 'Ordering')
BEGIN

	INSERT INTO [dbo].[tbConfigurationSubGroup] (ConfigurationGroupID, [Name], SortOrder)
	SELECT ConfigurationGroupID, 'Ordering', 0
	FROM [dbo].[tbConfigurationGroup]
	WHERE [Name] = 'Mobile'
END

IF NOT EXISTS (SELECT 1 FROM [dbo].[tbConfigurationSetting] WHERE [ConfigurationEnum] = @ConfigEnum)
BEGIN

    INSERT INTO [dbo].[tbConfigurationSetting] ([ConfigurationSubGroupID], [ConfigurationEnum], [Type], [Value], [AllowedValues], [Name], [HelpText], [AllowChange], [RelatedPages], [Status])
    SELECT
        csg.[ConfigurationSubGroupId],
        @ConfigEnum,
        50, -- 10: text, 20: numeric, 30: ?,40: select list, 50: bool
        'False',
        '',
        'Create Order - Use Processing Times',
        'When set to true, and the user is creating an order, the system will check for Processing Times, by item, and adjust the forecast usage and safety stock to reflect the updated times.',
        1,
        NULL,
        NULL
    FROM [dbo].[tbConfigurationGroup] CG WITH(NOLOCK)
    INNER JOIN [dbo].[tbConfigurationSubGroup] CSG WITH(NOLOCK) ON ( CG.[ConfigurationGroupID] = CSG.[ConfigurationGroupID] )
    WHERE
        CG.[Name] = 'Mobile'
    AND CSG.[Name] = 'Ordering'

END
GO
