-- declarations
DECLARE @pk INT
DECLARE @pk_security_role INT

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Security Roles')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Security Roles', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Administrator', 'string', NULL, 0, '20080101')
	SELECT @pk_security_role = SCOPE_IDENTITY()
	INSERT INTO [dbo].[Security] ([Active], [RoleNo], [Account], [Password], [FirstName], [LastName], [LastModified])
		VALUES (1, @pk_security_role, 'Administrator', '1111', NULL, NULL, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Maintenance', NULL, 0, '20080101')
	SELECT @pk_security_role = SCOPE_IDENTITY()
	INSERT INTO [dbo].[Security] ([Active], [RoleNo], [Account], [Password], [FirstName], [LastName], [LastModified])
		VALUES (1, @pk_security_role, 'Maintenance', '2222', NULL, NULL, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Reports', NULL, 0, '20080101')
	SELECT @pk_security_role = SCOPE_IDENTITY()
	INSERT INTO [dbo].[Security] ([Active], [RoleNo], [Account], [Password], [FirstName], [LastName], [LastModified])
		VALUES (1, @pk_security_role, 'Reports', '3333', NULL, NULL, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Machine Status')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Machine Status', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Offline', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Online', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Busy', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Main Module Bin Max Capacity')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Main Module Bin Max Capacity', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, '24', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Max Chain Modules')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Max Chain Modules', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, '4', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Chain Module Bin Max Capacity')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Chain Module Bin Max Capacity', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, '6', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Listener Port')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Listener Port', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, '40000', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Status Timer')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Status Timer', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, '1800', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Report Timer')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Report Timer', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, '60', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Customer Name')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Customer Name', 1, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Default Customer', 'string', NULL, 1, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Customer Location')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Customer Location', 1, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Customer Department')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Customer Department', 1, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Email Account')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Email Account', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'eric.miles', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Email Password')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Email Password', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'aisPW2007', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Email From Address')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Email From Address', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'donotreply@aisvendors.com', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Report Frequency')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Report Frequency', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Daily', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Weekly', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Bi-weekly', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Monthly', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Quarterly', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Yearly', 'string', NULL, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Products WHERE [PartNum] = 'Empty')
BEGIN
	INSERT INTO [dbo].[Products] ([Active], [IsEditable], [PartNum], [Description], [VendorNo], [PackageQty], [Price], [CurrentQty], [MinQty], [OrderQty], [LastModified])
		VALUES (1, 0, 'Empty', 'Empty', null, 1, 0.0000, 0, 0, 0, '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Usage By Machine')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Usage By Machine', NULL, '20080101 00:00', '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Usage By Product')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Usage By Product', NULL, '20080101 00:00', '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Usage By Employee')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Usage By Employee', NULL, '20080101 00:00', '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Usage By Department')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Usage By Department', NULL, '20080101 00:00', '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Usage By Job')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Usage By Job', NULL, '20080101 00:00', '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Usage By Vendor')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Usage By Vendor', NULL, '20080101 00:00', '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Bin Inventory')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Bin Inventory', NULL, '20080101 00:00', '20080101')
END
/*
IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Low Product Inventory')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Low Product Inventory', NULL, '20080101 00:00', '20080101')
END
*/
IF NOT EXISTS (SELECT * FROM dbo.Reports WHERE [Name] = 'Low Bin Inventory')
BEGIN
	INSERT INTO [dbo].[Reports] ([AutoEnable], [Name], [FrequencyNo], [NextRunDT], [LastModified])
		VALUES (0, 'Low Bin Inventory', NULL, '20080101 00:00', '20080101')
END

IF NOT EXISTS (SELECT * FROM dbo.Attributes WHERE [Name] = 'Machine Setting')
BEGIN
	INSERT INTO [dbo].[Attributes] ([Name], [IsEditable], [LastModified])
		VALUES ('Machine Setting', 0, '20080101')
	SELECT @pk = SCOPE_IDENTITY()
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Keypad ID Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Keypad PIN Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Keypad Job#1 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Keypad Job#2 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Keypad Job#3 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Mag Stripe ID Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Mag Stripe PIN Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Mag Stripe Job#1 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Mag Stripe Job#2 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Mag Stripe Job#3 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Scanner ID Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Scanner PIN Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Scanner Job#1 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Scanner Job#2 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Scanner Job#3 Entry', 'bool', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'PIN Min Length', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'PIN Max Length', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'PIN Entry Prompt', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'PIN Entry Timeout', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Job Min Length', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Job Max Length', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Job#1 Entry Prompt', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Job#2 Entry Prompt', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Job#3 Entry Prompt', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Job Entry Timeout', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Select Entry Prompt', 'string', NULL, 0, '20080101')
	INSERT INTO [dbo].[AttributeValues] ([AttributeNo], [Value], [ValueType], [ParentAttributeValueNo], [ParentEligible], [LastModified])
		VALUES (@pk, 'Select Entry Timeout', 'string', NULL, 0, '20080101')
END
