-------------------------------------------------------------------------------------------------------------------------------
--- 82404_ONETIME_SCRIPT_TO_ATTRIBUTE.SQL was last modified on 12/10/2018 04:42:18 PM ---
-------------------------------------------------------------------------------------------------------------------------------

DECLARE
		@A       VARCHAR(MAX)
	   ,@DB_Name VARCHAR(100) = DB_NAME()
	   ,@TODAY   DATETIME     = GETDATE()

SET @A = N'SELECT * INTO SCRATCHDB..Product_Group_Attribute_' + @DB_Name + '_' +  CONVERT(VARCHAR(10), @TODAY, 112) + ' FROM Product_Group_Attribute' +
		 ' SELECT * INTO SCRATCHDB..Product_Group_Level_'     + @DB_Name + '_' +  CONVERT(VARCHAR(10), @TODAY, 112) + ' FROM Product_Group_Level'

EXEC (@A)

IF OBJECT_ID ('TEMPDB..#Attribute')  IS NOT NULL DROP TABLE #Attribute

CREATE TABLE #Attribute (Number VARCHAR(100), Label VARCHAR(100), ID VARCHAR(100), Des VARCHAR(100))

INSERT INTO  #Attribute VALUES ('Prod_Var_F','Prod Var F','Prod_Var_F_ID','Prod_Var_F_Desc')
INSERT INTO  #Attribute VALUES ('Prod_Var_G','Prod Var G','Prod_Var_G_ID','Prod_Var_G_Desc')
INSERT INTO  #Attribute VALUES ('Prod_Var_H','Prod Var H','Prod_Var_H_ID','Prod_Var_H_Desc')
INSERT INTO  #Attribute VALUES ('Prod_Var_J','Prod Var J','Prod_Var_J_ID','Prod_Var_J_Desc')
INSERT INTO  #Attribute VALUES ('Prod_Var_K','Prod Var K','Prod_Var_K_ID','Prod_Var_K_Desc')
INSERT INTO  #Attribute VALUES ('Prod_Var_M','Prod Var M','Prod_Var_M_ID','Prod_Var_M_Desc')

--SELECT * FROM #Attribute

DECLARE 
        @Number VARCHAR(100)
	   ,@Label  VARCHAR(100)
       ,@ID     VARCHAR(100)
       ,@Desc   VARCHAR(100)
	   ,@ID1    INT

SELECT @ID1 = MAX(Product_Group_Level_ID) + 1 FROM Product_Group_Level WHERE Product_Group_Level_ID < 2000

DECLARE CUR CURSOR LOCAL FOR
SELECT  Number, Label, ID, Des FROM #Attribute

OPEN CUR
FETCH NEXT FROM CUR INTO @Number, @Label, @ID, @Desc

WHILE @@FETCH_STATUS = 0 
BEGIN

	IF NOT EXISTS (SELECT * FROM Product_Group_Level WHERE Group_Internal_Label = @Label)
	BEGIN
		INSERT INTO Product_Group_Level 
					(Product_Group_Level_ID, Group_Level_Desc, Deleted, Created_Date, Product_Group_Level_Type, Active,
					 List_Order, Group_Internal_Label, Approval_Group_Type, Is_Group_Combination, Search_Filter_On, Is_PG)
			 VALUES (@ID1, @Label, 0, @TODAY, @ID1, 0,
					 @ID1, @Label, 0, 0, 0, 0)
	
		IF EXISTS (SELECT * FROM Product_Group_Attribute WHERE Product_Group_Attribute_Table = @Number)
			UPDATE Product_Group_Attribute
			SET    Product_Group_Level_ID = @ID1
			WHERE  Product_Group_Attribute_Table = @Number
	END

	IF NOT EXISTS (SELECT * FROM Product_Group_Attribute WHERE Product_Group_Attribute_Table = @Number)
	BEGIN
		INSERT INTO Product_Group_Attribute
					(Product_Group_Level_ID,Product_Group_Attribute_Table,Product_Group_Attribute_ID_Field,Product_Group_Attribute_Name_Field, Program_View_Name,
					 Active,Deleted,Created_Date,Product_Group_Attribute_Search_Sequence_Field,Product_Group_Attribute_Master_ID_Field, Product_Group_Attribute_Number_Field)
			 VALUES (@ID1, @Number, @ID, @Desc, '',
					 0, 0, @TODAY, @Number, @ID, @Number)
	END

	SET @ID1 = @ID1 + 1

	FETCH NEXT FROM CUR INTO @Number, @Label, @ID, @Desc
END

CLOSE CUR
DEALLOCATE CUR

-- REVIEW AFTER ABOVE INSERTS/UPDATES DONE
SELECT* FROM dbo.Product_Group_Attribute WHERE Created_Date = @TODAY
SELECT* FROM dbo.Product_Group_Level     WHERE Created_Date = @TODAY

-------------------------------------------------------------------------------------------------------------------------------
--- AUTO_APPROVER_SETTINGS.SQL was last modified on 03/11/2019 07:46:42 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****   Auto_Approver_Settings   ****/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE ID = OBJECT_ID(N'[dbo].[Auto_Approver_Settings]') AND type in (N'U'))
BEGIN
	CREATE TABLE [dbo].[Auto_Approver_Settings](
		[Auto_Approver_Settings_ID] [int] IDENTITY(1,1) NOT NULL,
		[UserName] [nvarchar](50) NULL,
		[Password] [nvarchar](50) NULL,
		[Mail_Server] [nvarchar](100) NULL,
		[Domain_Server] [nvarchar](100) NULL,
		[Mail_Folder] [nvarchar](50) NULL,		
		[Auto_Approve_Email] [nvarchar](50) NULL,
		[BB_Mail_Folder] [nvarchar](50) NULL,		
		[BB_Auto_Approve_Email] [nvarchar](50) NULL,
		[Mail_SSL] [bit] NOT NULL CONSTRAINT [DF_Auto_Approver_Settings_Mail_SSL]  DEFAULT (0),
		[Deleted] [bit] NOT NULL CONSTRAINT [DF_Auto_Approver_Settings_Deleted]  DEFAULT (0),
		[Deleted_Date] [datetime] NULL,
		[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Auto_Approver_Settings_Created_Date]  DEFAULT (getDate())
	 CONSTRAINT [PK_Auto_Approver_Settings] PRIMARY KEY CLUSTERED 
	(
		[Auto_Approver_Settings_ID] ASC
	)WITH (FILLFACTOR = 90) ON [PRIMARY]
	) ON [PRIMARY]
END
GO

IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Auto_Approver_Settings' AND COLUMN_NAME = 'Domain_Server')
BEGIN
	ALTER TABLE Auto_Approver_Settings ADD Domain_Server nvarchar(100) NULL
END
GO

IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Auto_Approver_Settings' AND COLUMN_NAME = 'Mail_SSL')
BEGIN
	ALTER TABLE Auto_Approver_Settings ADD Mail_SSL [bit] NOT NULL CONSTRAINT [DF_Auto_Approver_Settings_Mail_SSL]  DEFAULT (0)
END
GO


-- D78742 - Remote Approval for billbacks
IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Auto_Approver_Settings' AND COLUMN_NAME = 'BB_Mail_Folder')
BEGIN
	ALTER TABLE Auto_Approver_Settings ADD BB_Mail_Folder nvarchar(50) NULL
END
GO


IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Auto_Approver_Settings' AND COLUMN_NAME = 'BB_Auto_Approve_Email')
BEGIN
	ALTER TABLE Auto_Approver_Settings ADD BB_Auto_Approve_Email nvarchar(50) NULL	
END
GO



IF NOT EXISTS (SELECT * FROM Auto_Approver_Settings WHERE Deleted = 0)
BEGIN
	INSERT INTO Auto_Approver_Settings
		(
		 UserName,
		 Password,
		 Mail_Server,
		 Domain_Server,
		 Mail_Folder,
		 Auto_Approve_Email,
		 BB_Mail_Folder,
		 BB_Auto_Approve_Email,
		 Mail_SSL
		)
	VALUES
		(
		'intra\AutoApprove',
		'6705J05E7E5C88525C989E564E7880441',
		'10.2.4.5',
		'intra.awayx.com',
		'Folders/Dev',
		'DevAutoApprove@bigredflame.com',
		'Billbacks/Dev',
		'DevBBAutoApprove@bigredflame.com',
		'0'
		)
END
GO

-- D34144 - Remote Program Approval for Exchange 2010
-- D61738 - Remote Approval for Exchange Online / Office 365
IF EXISTS (SELECT * FROM Auto_Approver_Settings WHERE Deleted = 0)
BEGIN
	-- Update Auto_Approver_Settings SET UserName = 'TestAutoApprove', Mail_Server = 'mail.bigredflame.com', Domain_Server ='intra.awayx.com', Mail_SSL = 0
	UPDATE Auto_Approver_Settings
	SET
		UserName = 'AutoApprove@bigredflame.com',
		Password = '6705J05E7E5C88525C989E564E7880441',
		Mail_Server = 'outlook.office365.com',
		Domain_Server = '',
		Mail_SSL = 1	
END
GO


IF EXISTS (SELECT * FROM Auto_Approver_Settings WHERE Deleted = 0)
BEGIN
	UPDATE Auto_Approver_Settings SET Password = '6705J05E7E5C88525C989E564E7880441'
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- AWAYX_OPERATOR_LOCATION_TYPE.SQL was last modified on 12/21/2018 08:21:46 PM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS ( SELECT *
                FROM Information_Schema.Tables
                WHERE Table_Name = 'AwayX_Operator_Location_Type' )
CREATE TABLE [dbo].[awayX_Operator_Location_Type](
	[BSA_Operator_Location_Type_ID] [int] IDENTITY(1,1) NOT NULL,
	[Operator_Location_Type] [nvarchar](255) NULL,
	[Business_Segment_ID] [int] NOT NULL CONSTRAINT [DF_awayX_Operator_Location_Type_Business_Segment_ID]  DEFAULT (1)
) ON [PRIMARY]

GO
-- 82739 - Upload - Tibersoft Operator Location
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'AwayX_Operator_Location_Type'
	AND		COLUMN_NAME = 'Operator_Location_Type_ID'
)
ALTER TABLE AwayX_Operator_Location_Type ADD [Operator_Location_Type_ID] [varchar](255) NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BB_CLAIM_OPERATOR_XREF.SQL was last modified on 06/03/2019 06:35:41 AM ---
-------------------------------------------------------------------------------------------------------------------------------

IF NOT EXISTS (SELECT name FROM sysobjects WHERE name = 'BB_Claim_Operator_XREF' AND type = 'U')
CREATE TABLE [dbo].[BB_Claim_Operator_XREF](
	[BB_Claim_Operator_XREF_ID] [int] IDENTITY(1,1) NOT NULL,
	[BB_Claim_Source_XREF_ID] [int] NULL,
	[Source_Code] [varchar](255) NULL,
	[External_Code] [varchar](255) NULL,
	[External_Description] [varchar](255) NULL,
	[Operator_Number] [varchar](255) NULL,
	[Operator_Name] [varchar](255) NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_BB_Claim_Operator_XREF_Created_Date]  DEFAULT (getdate()),
	[Created_By] [varchar](50) NULL,
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_BB_Claim_Operator_XREF_Deleted]  DEFAULT ((0)),
 CONSTRAINT [PK_BB_Claim_Operator_XREF] PRIMARY KEY NONCLUSTERED 
(
	[BB_Claim_Operator_XREF_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[BB_Claim_Operator_XREF]') AND name = N'PK_BB_Claim_Operator_XREF')
ALTER TABLE [dbo].[BB_Claim_Operator_XREF] DROP CONSTRAINT [PK_BB_Claim_Operator_XREF]

ALTER TABLE [dbo].[BB_Claim_Operator_XREF] ADD  CONSTRAINT [PK_BB_Claim_Operator_XREF] PRIMARY KEY NONCLUSTERED 
(
	[BB_Claim_Operator_XREF_ID] ASC
)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80, ONLINE = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[BB_Claim_Operator_XREF]') AND name = N'IDX_BB_Claim_Operator_XREF_C')

CREATE CLUSTERED INDEX IDX_BB_Claim_Operator_XREF_C ON [BB_Claim_Operator_XREF] 
(
	[BB_Claim_Source_XREF_ID] ASC,
	[Source_Code] ASC,
	[External_Code] ASC,
	[Operator_Number]  ASC
)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Updated_date'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [Updated_date] [datetime] NULL
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Address'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [Address] [VarChar](50) NULL
GO
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'City'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [City] [VarChar](50) NULL
GO
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'State'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [State] [VarChar](50) NULL
GO
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Zip'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [Zip] [VarChar](15) NULL
GO
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Updated_By'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [Updated_By] [varchar](50) NULL
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'BSA_Operator_ID'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [BSA_Operator_ID] [int] NULL
GO
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Eshark_RecordID'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [Eshark_RecordID] [VarChar](50) NULL
GO
/* 45073 -  Kraft EDI - Holding Pen processing - Phase 2 (update to Alias tables) */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Hold_Invoice_Count'
)
ALTER TABLE BB_Claim_Operator_XREF ADD [Hold_Invoice_Count] [int] NULL
GO

IF NOT EXISTS ( SELECT	*
				FROM	INFORMATION_SCHEMA.COLUMNS
				WHERE	TABLE_NAME = 'BB_claim_Operator_Xref'
						AND COLUMN_NAME = 'Ignore' 
			  ) 
ALTER TABLE BB_claim_Operator_Xref ADD Ignore BIT NOT NULL CONSTRAINT [DF_BB_claim_Operator_Xref_Ignore] DEFAULT ((0))
GO

--WR75811
IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Address'
)
ALTER TABLE BB_Claim_Operator_XREF 
ALTER COLUMN [Address] [VARCHAR](255) NULL

-- WR 82368
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Claim_Operator_XREF'
	AND		COLUMN_NAME = 'Address_2'
)
ALTER TABLE BB_Claim_Operator_XREF ADD Address_2 [varchar](255) NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BB_CUSTOM_EXPECTED_RATE_CALC_DETAIL.SQL was last modified on 11/11/2019 02:16:44 PM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'BB_Custom_Expected_Rate_Calc_Detail'
)
CREATE TABLE [dbo].[BB_Custom_Expected_Rate_Calc_Detail](
	[Billback_ID] [uniqueidentifier] NOT NULL,
	[BB_item_invoice_level_ID] [int] NOT NULL,
	[Billback_Program_ID] [uniqueidentifier] NOT NULL,
	[Billback_Product_ID] [uniqueidentifier] NOT NULL,
	[Record_Eligible] [bit] NOT NULL,

	[Program_Acute] [varchar] (100) NULL,
	[Operator_Rebate_Account_Type] [varchar] (100) NULL,
	[Price_List_Type] [varchar] (100) NULL,
	[Price_Bracket] [int] NULL,
	[Price_List_Header_ID] [uniqueidentifier] NULL,
	[Location_Tier] [int] NULL,

	[Product_Price_CS] [decimal](20, 4) NULL,
	[Program_Price_Rate] [decimal](20, 4) NULL,
	[Unit_Of_Measure_ID] [int] NULL,
	[Expected_Rate_CS] [decimal](24, 9) NULL,
	[Expected_Rate_LB] [decimal](24, 9) NULL,

	[Zero_Expected_Rate] [bit] NOT NULL,
	[Zero_Expected_Rate_Message] [varchar] (100) NULL,
	[Family_Strategic] [bit] NOT NULL,
	[Family_Network] [bit] NOT NULL,

	[Created_Date] [datetime] NULL CONSTRAINT [DF_BB_Custom_Expected_Rate_Calc_Detail_Created_Date]  DEFAULT (getdate()),	
 CONSTRAINT [PK_BB_Custom_Expected_Rate_Calc_Detail] PRIMARY KEY CLUSTERED 
(
	[Billback_ID] ASC,
	[BB_item_invoice_level_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]



if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Custom_Expected_Rate_Calc_Detail'
	AND		COLUMN_NAME = 'Expected_Rate_CS'
	AND		NUMERIC_SCALE = 4
)
ALTER TABLE BB_Custom_Expected_Rate_Calc_Detail ALTER COLUMN [Expected_Rate_CS] [decimal](24, 9) NULL
GO

if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Custom_Expected_Rate_Calc_Detail'
	AND		COLUMN_NAME = 'Expected_Rate_LB'
	AND		NUMERIC_SCALE = 4
)
ALTER TABLE BB_Custom_Expected_Rate_Calc_Detail ALTER COLUMN [Expected_Rate_LB] [decimal](24, 9) NULL
GO

-------------------------------------------------------------------------------------------------------------------------------
--- BB_ITEM_INVOICE_LEVEL.SQL was last modified on 06/03/2019 06:35:41 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT name FROM sysobjects WHERE name = 'BB_Item_Invoice_Level')

CREATE TABLE [dbo].[BB_Item_Invoice_Level](
	[BB_Item_Invoice_Level_ID] [int] IDENTITY(1,1) NOT NULL,
	[Billback_ID] [uniqueidentifier] NULL,
	[Program_ID] [int] NULL,
	[Billback_Program_ID] [uniqueidentifier] NULL,
	[Distributor_ID] [uniqueidentifier] NULL,
	[Product_ID] [uniqueidentifier] NULL,
	[Item] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Count_Flag] [bit] NULL CONSTRAINT [DF_BB_Item_Invoice_Level_Count_Flag]  DEFAULT ((0)),
	[UOM] [int] NULL CONSTRAINT [DF_BB_Item_Invoice_Level_UOM]  DEFAULT ((1)),
	[Billback_Product_ID] [uniqueidentifier] NULL,
	[Discount_Type_ID] [int] NULL,
	[Claimed_CS] [decimal](20, 4) NULL,
	[Claimed_LB] [decimal](20, 4) NULL,
	[Invoice_Price_CS] [decimal](24, 9) NULL,
	[Invoice_Price_LB] [decimal](24, 9) NULL,
	[Program_Price_CS] [decimal](24, 9) NULL,
	[Program_Price_LB] [decimal](24, 9) NULL,
	[Claimed_Rate_CS] [decimal](24, 9) NULL,
	[Claimed_Rate_LB] [decimal](24, 9) NULL,
	[Claimed_Amt] [decimal](24, 2) NULL,
	[Expected_CS] [decimal](20, 4) NULL,
	[Expected_LB] [decimal](20, 4) NULL,
	[Allocated_Expected_CS] [decimal](20, 4) NULL,
	[Allocated_Expected_LB] [decimal](20, 4) NULL,
	[BB_Item_Final_ID] [uniqueidentifier] NULL,
	[Expected_Rate_CS] [decimal](24, 9) NULL,
	[Expected_Rate_LB] [decimal](24, 9) NULL,
	[Expected_Invoice_Price_CS] [decimal](24, 9) NULL,
	[Manual_Invoice_Price_CS] [decimal](24, 9) NULL,
	[Manual_Invoice_Price_LB] [decimal](24, 9) NULL,
	[Expected_Program_Price_CS] [decimal](24, 9) NULL,
	[Net_Weight] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Rate_Deviation] [bit] NOT NULL CONSTRAINT [DF_BB_Item_Invoice_Level_Rate_Deviation]  DEFAULT ((0)),
	[Volume_Deviation] [bit] NOT NULL CONSTRAINT [DF_BB_Item_Invoice_Level_Volume_Deviation]  DEFAULT ((0)),
	[Selected_Vol_Type] [int] NULL,
	[Selected_Vol_CS] [decimal](20, 4) NULL,
	[Selected_Vol_LB] [decimal](20, 4) NULL,
	[Selected_Rate_Type] [int] NULL,
	[Selected_Rate_CS] [decimal](24, 9) NULL,
	[Selected_Rate_LB] [decimal](24, 9) NULL,
	[Selected_Invoice_Price_Type] [int] NULL,
	[Selected_Program_Price_Type] [int] NULL,
	[Final_Payment] [decimal](20, 2) NULL,
	[Uploaded_Billback] [int] NOT NULL CONSTRAINT [DF_BB_Item_Invoice_Level_Uploaded_Billback]  DEFAULT ((0)),
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_BB_Item_Invoice_Level_Created_Date]  DEFAULT (getdate()),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_BB_Item_Invoice_Level_Deleted]  DEFAULT ((0)),
	[iDone] [int] NOT NULL CONSTRAINT [DF__BB_Item_Invoice_Level_iDone]  DEFAULT ((0)),
	[Volume_Override] [bit] NOT NULL CONSTRAINT [DF__BB_Item_Invoice_Level_Volume_Override]  DEFAULT ((0)),
	[Rate_Override] [bit] NOT NULL CONSTRAINT [DF__BB_Item_Invoice_Level_Rate_Override]  DEFAULT ((0)),
	[Operator_ID] [int] NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


IF EXISTS 
(	SELECT name FROM sysindexes
	WHERE name = 'IDX_BB_Item_Invoice_Level_BBID')
DROP INDEX BB_Item_Invoice_Level.IDX_BB_Item_Invoice_Level_BBID
CREATE INDEX IDX_BB_Item_Invoice_Level_BBID ON BB_Item_Invoice_Level(Billback_ID) 
GO

IF EXISTS 
(	SELECT name FROM sysindexes
	WHERE name = 'IDX_BB_Item_Invoice_Level_ID')
DROP INDEX BB_Item_Invoice_Level.IDX_BB_Item_Invoice_Level_ID
CREATE CLUSTERED INDEX IDX_BB_Item_Invoice_Level_ID ON BB_Item_Invoice_Level(BB_Item_Invoice_Level_ID) 
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Item_Invoice_Level'
		AND
		COLUMN_NAME = 'iDone'
)
ALTER TABLE dbo.BB_Item_Invoice_Level ADD iDone INT NOT NULL CONSTRAINT DF__BB_Item_Invoice_Level_iDone DEFAULT 0
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Item_Invoice_Level'
		AND
		COLUMN_NAME = 'Volume_Override'
)
ALTER TABLE dbo.BB_Item_Invoice_Level ADD Volume_Override BIT NOT NULL CONSTRAINT DF__BB_Item_Invoice_Level_Volume_Override DEFAULT 0
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Item_Invoice_Level'
		AND
		COLUMN_NAME = 'Rate_Override'
)
ALTER TABLE dbo.BB_Item_Invoice_Level ADD Rate_Override BIT NOT NULL CONSTRAINT DF__BB_Item_Invoice_Level_Rate_Override DEFAULT 0
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_Item_Invoice_Level' AND
                        COLUMN_NAME = 'Unknown_Product'
)
ALTER TABLE BB_Item_Invoice_Level ADD [Unknown_Product] [bit] NOT NULL 
CONSTRAINT [DF_BB_Item_Invoice_Level_Unknown_Product] DEFAULT (0)
GO


if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_Item_Invoice_Level' AND
                        COLUMN_NAME = 'Updated_By'
)
ALTER TABLE BB_Item_Invoice_Level ADD [Updated_By] [varchar] (50)
GO


if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_Item_Invoice_Level' AND
                        COLUMN_NAME = 'Updated_Date'
)
ALTER TABLE BB_Item_Invoice_Level ADD [Updated_Date] [DateTime]
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Manual_Rate_CS'
)
ALTER TABLE BB_Item_invoice_level ADD [Manual_Rate_CS] DECIMAL(24,9) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Manual_Rate_LB'
)
ALTER TABLE BB_Item_invoice_level ADD [Manual_Rate_LB] DECIMAL(24,9) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Expected_Rate_LT_CS'
)
ALTER TABLE BB_Item_invoice_level ADD [Expected_Rate_LT_CS] DECIMAL(24,9) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Expected_Rate_LT_LB'
)
ALTER TABLE BB_Item_invoice_level ADD [Expected_Rate_LT_LB] DECIMAL(24,9) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Manual_Vol_LB'
)
ALTER TABLE BB_Item_invoice_level ADD [Manual_Vol_LB] DECIMAL(24,9) NULL 
GO


if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Manual_Vol_CS'
)
ALTER TABLE BB_Item_invoice_level ADD [Manual_Vol_CS] DECIMAL(24,9) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Operator_ID'
)
ALTER TABLE BB_Item_invoice_level ADD [Operator_ID] INT NULL 
GO
/*
	D39421: Deviations Grid - Allow Manual values greater than Claimed
	Anand Rao/24-Sep-2013
*/
if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Manual_Program_Price_CS'
)
ALTER TABLE BB_Item_invoice_level ADD [Manual_Program_Price_CS] DECIMAL(24,9) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Manual_Program_Price_LB'
)
ALTER TABLE BB_Item_invoice_level ADD [Manual_Program_Price_LB] DECIMAL(24,9) NULL 
GO

-- WR 82368
if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'Location_Operator_ID'
)
ALTER TABLE BB_Item_invoice_level ADD Location_Operator_ID INT 
GO

if not exists 
(
            SELECT            *
            FROM   	INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'BB_Item_invoice_level' AND
                        COLUMN_NAME = 'TIER'
)
ALTER TABLE BB_Item_invoice_level ADD TIER TINYINT NOT NULL CONSTRAINT [DF_BB_item_Invoice_Level_Tier]  DEFAULT (0) 
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BB_PROGRAM_REPROCESS_LOG.SQL was last modified on 11/04/2019 10:56:36 AM ---
-------------------------------------------------------------------------------------------------------------------------------
-- 43711 Billbacks with issues like Itemized Amount and Grid Amount are not equal - Issue 1, 3

IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.BB_Program_Reprocess_Log') AND type in (N'U'))
CREATE TABLE dbo.BB_Program_Reprocess_Log(
	BB_Program_Reprocess_Log_ID [int] IDENTITY (1, 1) NOT NULL ,
	Billback_ID uniqueidentifier NOT NULL,
	Reprocess_Date datetime NULL,
	Created_Date [datetime] NOT NULL CONSTRAINT [DF_BB_Program_Reprocess_Log_Created_Date] DEFAULT (getdate())
) ON [PRIMARY]

GO



IF NOT EXISTS ( SELECT	*
				FROM	INFORMATION_SCHEMA.COLUMNS
				WHERE	TABLE_NAME = 'BB_Program_Reprocess_Log'
						AND COLUMN_NAME = 'Reprocess_Status' 
			  ) 
ALTER TABLE BB_Program_Reprocess_Log ADD Reprocess_Status VARCHAR(255)
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BB_SEARCH_GRID_COLUMN_SIZE.SQL was last modified on 07/09/2019 07:32:44 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'BB_Search_Grid_Column_Size'
)
CREATE TABLE [dbo].[BB_Search_Grid_Column_Size](
	[User_Id] [varchar] (50) NOT NULL,
	[Status] [smallint] NULL,
	[Payable_Number] [smallint] NULL,
	[Billback_Number] [smallint] NULL,
	[Title] [smallint] NULL,
	[BB_Date] [smallint] NULL,
	[Payee] [smallint] NULL,
	[Start_Date] [smallint] NULL,
	[End_Date] [smallint] NULL,
	[Claimed_Amount] [smallint] NULL,
	[Approved_Amount] [smallint] NULL,
	[Closing_Method] [smallint] NULL,
	[More_Info] [smallint] NULL
 CONSTRAINT [PK_BB_Search_Grid_Column_Size] PRIMARY KEY CLUSTERED 
(
	[User_Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO


IF NOT EXISTS
(
 SELECT COUNT(*)
 FROM BB_Search_Grid_Column_Size
 HAVING COUNT(*) > 0
)
INSERT INTO BB_Search_Grid_Column_Size(User_Id,Status,Payable_Number,Billback_Number,Title,BB_Date,Payee,Start_Date,End_Date,Claimed_Amount,Approved_Amount,Closing_Method,More_Info)
VALUES('00000000-9999-9999-0000000000000000',75,85,85,100,75,100,100,100,75,75,100,175)


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Search_Grid_Column_Size'
	AND COLUMN_NAME = 'Vendor'
)
ALTER TABLE BB_Search_Grid_Column_Size ADD [Vendor] [smallint] NULL
GO

IF EXISTS
(
 SELECT COUNT(*)
 FROM BB_Search_Grid_Column_Size
 HAVING COUNT(*) > 0
)
UPDATE BB_Search_Grid_Column_Size
SET Vendor = 75,
Closing_Method = 100,
Payee= 75,
Title = 75
WHERE User_ID = '00000000-9999-9999-0000000000000000' OR Vendor IS NULL



IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BB_Search_Grid_Column_Size'
	AND COLUMN_NAME = 'BB_Received_Date'
)
ALTER TABLE BB_Search_Grid_Column_Size ADD [BB_Received_Date] [smallint] NULL
GO

UPDATE BB_Search_Grid_Column_Size SET BB_Received_Date = BB_Date
-- select * from BB_Search_Grid_Column_Size 
-------------------------------------------------------------------------------------------------------------------------------
--- BB_UPLOAD_DIVESTED_ITEMS.SQL was last modified on 06/26/2019 01:09:24 PM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'BB_Upload_Divested_Items'
)
	CREATE TABLE BB_Upload_Divested_Items(
		BB_Upload_Divested_Items_ID [int] IDENTITY (1, 1) NOT NULL ,
		BSA_Foodservice_Items_Master_ID [uniqueidentifier] NOT NULL ,
		GTIN VARCHAR(100),
		Item VARCHAR(100),
		Description VARCHAR(500),
		UPC  VARCHAR(100), 
		Deleted [bit] NOT NULL CONSTRAINT [DF_BB_upload_Divested_items_Deleted] DEFAULT (0), 
		Active_Code VARCHAR(1),
		Created_Date  [datetime] NOT NULL CONSTRAINT [DF_BB_upload_Divested_items_Created_Date] DEFAULT (getdate()),
		Updated_Date [datetime] , 
		Business_Segment_Required [bit] NOT NULL CONSTRAINT [DF_BB_upload_Divested_items_Business_Segment_Required] DEFAULT (0), 
		Business_Segment_ID INT
	)
-------------------------------------------------------------------------------------------------------------------------------
--- BB_UPLOAD_LOG.SQL was last modified on 11/26/2018 07:40:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'BB_upload_log'
)
CREATE TABLE [dbo].[BB_upload_log](
	[upload_id] [int] IDENTITY(1,1) NOT NULL,
	[user_id] [varchar](50) NULL,
	[total_header_count] [int] NULL,
	[total_header_count_failed] [int] NULL,
	[total_header_count_loaded] [int] NULL,
	[total_detail_count] [int] NULL,
	[total_detail_count_failed] [int] NULL,
	[total_detail_count_loaded] [int] NULL,
	[upload_date] [datetime] NULL,
	[upload_status] [varchar](50) NULL,
	[deleted] [bit] NULL CONSTRAINT [DF_BB_upload_log_deleted]  DEFAULT ((0)),
	[header_file_name] [varchar](2000) NULL,
	[detail_file_name] [varchar](2000) NULL,
	[deleted_by] [nvarchar](50) NULL,
	[deleted_date] [datetime] NULL,
	[upload_type] [tinyint] NOT NULL CONSTRAINT [DF_BB_upload_log_upload_type]  DEFAULT ((2))
) ON [PRIMARY]

GO


-- ***** Fix upload_type default - start

IF EXISTS (SELECT NAME FROM sysobjects WHERE name = 'DF_BB_upload_log_upload_type')
ALTER TABLE BB_upload_log DROP CONSTRAINT DF_BB_upload_log_upload_type
GO


IF NOT EXISTS (SELECT NAME FROM sysobjects WHERE name = 'DF_BB_upload_log_upload_type')
ALTER TABLE BB_upload_log ADD CONSTRAINT DF_BB_upload_log_upload_type DEFAULT ((2)) FOR upload_type
GO

update BB_upload_log set upload_type = 2 where upload_type = 1

-- ***** Fix upload_type default - end

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_log' AND
                        COLUMN_NAME = 'Upload_Type_Desc'
)
ALTER TABLE BB_upload_log ADD Upload_Type_Desc INT
GO

if exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_log' AND
                        COLUMN_NAME = 'Upload_Type_Desc'
)
ALTER TABLE BB_upload_log ALTER COLUMN Upload_Type_Desc TINYINT
GO


if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_log' AND
                        COLUMN_NAME = 'Source_Code'
)
ALTER TABLE BB_upload_log ADD  Source_Code varchar(255)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_log' AND
                        COLUMN_NAME = 'Source_Type_Description'
)
ALTER TABLE BB_upload_log ADD  Source_Type_Description varchar(50)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_log' AND
                        COLUMN_NAME = 'Source_Type'
)
ALTER TABLE BB_upload_log ADD  Source_Type TINYINT  NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_log' AND
                        COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE BB_upload_log ADD Business_Segment_ID INT NULL
GO


if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_Log' AND
                        COLUMN_NAME = 'Upload_Complete_Date'
)

BEGIN 
	DECLARE @upload_ID1 int, @upload_ID2 int, @upload_ID3 int

	set		@upload_ID1 = 0 
	set		@upload_ID2 = 0
	set		@upload_ID3 = 0

	select @upload_ID1 = MAX(Billback_Upload_III_P_ID) from Billback_Upload_III_P
	select @upload_ID2 = MAX(upload_ID) from BB_upload_log

	set		@upload_ID3 = CASE WHEN @upload_ID1 >= @upload_ID2 THEN  @upload_ID1
							   ELSE @upload_ID2
						  END
	SELECT		@upload_ID1,@upload_ID2,@upload_ID3			  

	IF @upload_ID3 is not null 
	Begin 
	DBCC CHECKIDENT ('BB_upload_Log', RESEED, @upload_ID3 )
	END
	ELSE
	BEGIN
		  Print 'NO billback uploads'
	END

END

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_upload_Log' AND
                        COLUMN_NAME = 'Upload_Complete_Date'
)
ALTER TABLE BB_upload_log ADD  Upload_Complete_Date DATETIME
GO

IF EXISTS 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_Upload_Log' AND
                        COLUMN_NAME = 'Upload_Status'
)
ALTER TABLE BB_Upload_Log ALTER COLUMN Upload_Status varchar(4000)
GO


IF NOT  EXISTS 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_Upload_Log' AND
                        COLUMN_NAME = 'III_party_job_Process_type'
)
ALTER TABLE BB_Upload_Log ADD III_party_job_Process_type varchar(255)
GO

IF NOT  EXISTS 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BB_Upload_Log' AND
                        COLUMN_NAME = 'Auto_Approve'
)
ALTER TABLE BB_Upload_Log ADD Auto_Approve BIT NOT NULL CONSTRAINT [DF_BB_Upload_Log_Auto_Approve] DEFAULT ((0))
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK.SQL was last modified on 07/09/2019 07:32:44 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
)
CREATE TABLE [dbo].[Billback](
	[Billback_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_BillBack_BillBack_ID]  DEFAULT (newid()),
	[BB_Title] [nvarchar](100) NULL,
	[BB_Date] [datetime] NULL,
	[BB_Start_Date] [datetime] NULL,
	[BB_End_Date] [datetime] NULL,
	[BB_Amount] [float] NULL,
	[BB_Reference] [nvarchar](100) NULL,
	[BB_Creator_ID] [nvarchar](50) NULL,
	[BB_Creator_Notes] [nvarchar](4000) NULL,
	[BB_Code] [nvarchar](50) NULL,
	[BB_Creator_User_Position_ID] [nvarchar](50) NULL,
	[Billback_Status_ID] [int] NULL CONSTRAINT [DF_BillBack_Billback_Status_ID]  DEFAULT (1),
	[Billback_Payee_Type_ID] [int] NULL,
	[BB_UP] [bit] NULL CONSTRAINT [DF_Billback_BB_UP]  DEFAULT (1),
	[BB_PNF] [bit] NULL CONSTRAINT [DF_Billback_BB_PNF]  DEFAULT ((0)),
	[Created_Date] [datetime] NULL CONSTRAINT [DF_BillBack_Created_Date]  DEFAULT (getdate()),
	[BB_Request_Approval_User_ID] [nvarchar](50) NULL,
	[BB_Request_Approval_Date] [datetime] NULL,
	[Deleted] [bit] NULL CONSTRAINT [DF_BillBack_Deleted]  DEFAULT (0),
	[Comments] [nvarchar](4000) NULL,
	[Age_Email_Sent] [bit] NOT NULL CONSTRAINT [DF_Billback_Age_Email_Sent]  DEFAULT (0),
	[Deleted_By_User_id] [nvarchar](50) NULL,
	[Deleted_Date] [datetime] NULL,
	[BB_Received_Date] [datetime] NULL,
	[Auto_Billback] [bit] NULL CONSTRAINT [DF_Billback_Auto_Billback]  DEFAULT (0),
	[CopiedBB] [uniqueidentifier] NULL,
	[VolumeRateSaved] [bit] NULL CONSTRAINT [DF_Billback_VolumeRateSaved]  DEFAULT (0),
	[FYDisabled] [bit] NULL CONSTRAINT [DF_Billback_FYDisabled]  DEFAULT (0),
	[Postmark_Date] [datetime] NULL,
	[Uploaded_Billback] [tinyint] NOT NULL CONSTRAINT [DF_Billback_Uploaded_Billback]  DEFAULT ((0)),
	[Flag_Auto_Billback] [bit] NULL CONSTRAINT [DF_Billback_Flag_Auto_Billback]  DEFAULT (0),
	[BB_Volume] [float] NOT NULL CONSTRAINT [DF_Billback_BB_Volume]  DEFAULT (0),
	[BB_Volume_UOM] [int] NOT NULL CONSTRAINT [DF_Billback_BB_Volume_UOM]  DEFAULT (1),
	[Scheduled_Auto_BB] [bit] NULL CONSTRAINT [DF_Billback_Scheduled_Auto_BB]  DEFAULT (0),
	[check_number] [nvarchar](50) NOT NULL CONSTRAINT [DF_Billback_check_number]  DEFAULT (''),
	[BB_Payment_Request_Sent] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Payment_Request_Sent]  DEFAULT (0),
	[BB_Reset_User_ID] [nvarchar](50) NULL,
	[BB_Reset_Date] [datetime] NULL,
	[BB_Payment_Header_Sent] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Payment_Header_Sent]  DEFAULT (0),
	[BB_Payment_Detail_Sent] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Payment_Detail_Sent]  DEFAULT (0),
	[BB_Payment_User_Sent] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Payment_User_Sent]  DEFAULT (0),
	[BB_Analysis_Sent] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Analysis_Sent]  DEFAULT (0),
	[BB_Is_Child] [bit] NULL CONSTRAINT [DF_Billback_BB_Is_Child]  DEFAULT (0),
	[BB_Parent_ID] [uniqueidentifier] NULL,
	[BB_Split_Number] [nvarchar](50) NULL,
	[BB_Split_Reason] [nvarchar](250) NULL,
	[BB_Split_Date] [datetime] NULL,
	[BB_Closing_Method] [int] NULL CONSTRAINT [DF_Billback_BB_Closing_Method]  DEFAULT (1),
	[BB_Associated_To_DD] [bit] NULL CONSTRAINT [DF_Billback_BB_Associated_To_DD]  DEFAULT (0),
	[Original_BB_Code] [nvarchar](50) NULL,
	[BB_Void_Multiplier] [int] NOT NULL DEFAULT (1),
	[BB_Void_Date] [datetime] NULL,
	[BB_Inactive_Vendor_Indicator] [bit] NOT NULL DEFAULT (0),
	[BB_Inactive_Vendor_Date] [datetime] NULL,
	[BB_Rejected_Indicator] [bit] NOT NULL DEFAULT (0),
	[BB_Rejected_Date] [datetime] NULL,
	[Rejected_Date] [datetime] NULL,
	[BB_Rejected_Notification_Sent] [bit] NULL CONSTRAINT [DF_Billback_BB_Rejected_Notification_Sent]  DEFAULT (0),
	[BB_Inactive_Vendor_Notification_Sent] [bit] NULL CONSTRAINT [DF_Billback_BB_Inactive_Vendor_Notification_Sent]  DEFAULT (0),
	[Previous_BB_Code] [nvarchar](50) NULL,
	[New_BB_Created_Date] [datetime] NULL,
	[Void_Reset_User_ID] [nvarchar](50) NULL,
	[Viod_Reset_User_Position_ID] [nvarchar](50) NULL,
	[Void_Count] [bit] NULL CONSTRAINT [DF_Billback_Void_Count]  DEFAULT (0),
	[BB_Void_Notification_Sent] [bit] NULL CONSTRAINT [DF_Billback_BB_Void_Notification_Sent]  DEFAULT (0),
	[BB_Reopened_Multiplier] [int] NOT NULL CONSTRAINT [DF_Billback_BB_Reopened_Multiplier]  DEFAULT (1),
	[BB_Split_Claimed_Volume] [nvarchar](50) NULL,
	[BB_Disagree] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Disagree]  DEFAULT (0),
	[TotalTaxAmount] [decimal](18, 2) NULL,
	[BB_Payment_Request_Approved] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Payment_Request_Approved]  DEFAULT (0),
	[BB_Payment_Request_Approved_By] [nvarchar](50) NULL,
	[BB_Payment_Request_Approved_Date] [datetime] NULL,
	[BB_Payment_Request_Prepared] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Payment_Request_Prepared]  DEFAULT (0),
	[BB_Payment_Request_Prepared_By] [nvarchar](50) NULL,
	[BB_Payment_Request_Prepared_Date] [datetime] NULL,
	[ClaimMechanics] [int] NULL,
	[Sent_Create_Auto_Billback_Email] [bit] NOT NULL CONSTRAINT [DF_Billback_Sent_Create_Auto_Billback_Email]  DEFAULT (0),
	[Scheduled_Operator_Auto_BB] [bit] NOT NULL CONSTRAINT [DF_Billback_Scheduled_Operator_Auto_BB]  DEFAULT (0),
	[BB_Received_Ack_Type] [int] NOT NULL CONSTRAINT [DF_Billback_BB_Received_Ack_Type]  DEFAULT (0),
	[BB_Payment_Request_Sent_On] [datetime] NULL,
	[BB_Approved_Void_Sent_On] [datetime] NULL,
	[BB_Approved_Void_Ack_Type] [int] NOT NULL CONSTRAINT [DF_Billback_BB_Approved_Void_Ack_Type]  DEFAULT (0),
	[BB_Received_Ack_Date] [datetime] NULL,
	[BB_Approved_Void_Ack_Date] [datetime] NULL,
	[Analyst_User_ID] [nvarchar](50) NULL,
	[BB_Disagree_By] [nvarchar](50) NULL,
	[BB_Disagree_Date] [datetime] NULL,
	[Customer_Claim_Id] [nvarchar](50) NULL,
	[CLAIM_CASES] [float] NOT NULL CONSTRAINT [DF_Billback_CLAIM_CASES]  DEFAULT (0.00),
	[CLAIM_POUNDS] [float] NOT NULL CONSTRAINT [DF_Billback_CLAIM_POUNDS]  DEFAULT (0.00),
	[Payment_Type] [int] NOT NULL CONSTRAINT [DF_Billback_Payment_Type]  DEFAULT (1),
	[Negative_Billback] [bit] NOT NULL CONSTRAINT [DF_Billback_Negative_Billback]  DEFAULT ((0)),
	[deviated] [bit] NOT NULL CONSTRAINT [DF_billback_deviated]  DEFAULT ((0)),
	[BB_Modify_Agree] [bit] NOT NULL CONSTRAINT [DF__Billback_Modify_Agree]  DEFAULT ((0)),
	[BB_Modify_Agree_User] [nvarchar](50) NULL,
	[IS_BB_VCC] [bit] NOT NULL CONSTRAINT [DF_Billback_IS_BB_VCC]  DEFAULT ((0)),
	[referenceNum] [varchar](100) NULL,
	[Auto_Approved] [bit] NOT NULL CONSTRAINT [DF_Billback_Auto_Approved]  DEFAULT ((0)),
	[BB_Line_Item_Number] [nvarchar](50) NULL,
	[Log_Processing] [bit] NOT NULL CONSTRAINT [DF_Billback_Log_Processing]  DEFAULT ((0)),
	[DD_Closure_Sent_on] [datetime] NULL,
	[Auto_Deviation_On] [datetime] NULL,
	[Cannot_Exceed_Percent] [decimal](18, 2) NULL,
	[Cannot_Exceed_Dollar] [decimal](18, 2) NULL,
	[Auto_Deviated_Percent] [decimal](18, 2) NULL,
	[Auto_Deviated_Amt] [decimal](18, 2) NULL,
	[Invalid_Upload] [bit] NOT NULL CONSTRAINT [DF_Billback_Invalid_Upload]  DEFAULT ((0)),
	[Deviation_Ran_Date] [datetime] NULL
) ON [PRIMARY]


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Deviation_Ran_By'
)
ALTER TABLE [dbo].[Billback] ADD [Deviation_Ran_By] [varchar](50) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Auto_Dev_Max_Dollar_Amount'
)
ALTER TABLE [dbo].[Billback] ADD [Auto_Dev_Max_Dollar_Amount] [decimal](18, 0) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Auto_Dev_Claimed_Amt'
)
ALTER TABLE [dbo].[Billback] ADD [Auto_Dev_Claimed_Amt] [decimal](18, 0) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Create_Invoice_FromBB'
)
ALTER TABLE [dbo].[Billback] ADD [Create_Invoice_FromBB] [bit] NULL CONSTRAINT [DF_Create_Invoice_FromBB]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Invoice_Created_Date'
)
ALTER TABLE [dbo].[Billback] ADD [Invoice_Created_Date] [datetime] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Created_Invoice_On_800_Ack'
)
ALTER TABLE [dbo].[Billback] ADD [Created_Invoice_On_800_Ack] [bit] NOT NULL CONSTRAINT [DF_Billback_Created_Invoice_On_800_Ack]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'BB_Approve_Data_Validation_Success'
)
ALTER TABLE [dbo].[Billback] ADD [BB_Approve_Data_Validation_Success] [int] NOT NULL CONSTRAINT [DF_Billback_BB_Approve_Data_Validation_Success]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'BB_Approve_Data_Validation_Date'
)
ALTER TABLE [dbo].[Billback] ADD [BB_Approve_Data_Validation_Date] [datetime] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Paid_Date'
)
ALTER TABLE [dbo].[Billback] ADD [Paid_Date] [datetime] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'BB_Upd_InProgress'
)
ALTER TABLE [dbo].[Billback] ADD [BB_Upd_InProgress] [int] NOT NULL CONSTRAINT [DF_Billback_BB_Upd_InProgress]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Deviation_InProgress'
)
ALTER TABLE [dbo].[Billback] ADD [Deviation_InProgress] [int] NOT NULL CONSTRAINT [DF_Billback_Deviation_InProgress]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Approved_By_Process'
)
ALTER TABLE [dbo].[Billback] ADD [Approved_By_Process] [tinyint] NOT NULL CONSTRAINT [DF__Billback_Approved_By_Process]  DEFAULT ((1))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'billback'
	AND COLUMN_NAME = 'Billback_ID_Int'
)
ALTER TABLE billback ADD [Billback_ID_Int] [int] IDENTITY(1,1) NOT NULL
GO


IF NOT EXISTS
(
SELECT * FROM dbo.sysobjects where id = object_id(N'PK_BillBack') and OBJECTPROPERTY(id, N'IsConstraint') = 1
AND parent_obj = object_id(N'Billback')
)

ALTER TABLE [dbo].[Billback] ADD  CONSTRAINT [PK_BillBack] PRIMARY KEY CLUSTERED 
(
	[Billback_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
GO

IF NOT EXISTS
(
	select name from sysindexes where name = 'IDX_Billback_ID_Int' and id = object_id('Billback')
)
CREATE NONCLUSTERED INDEX [IDX_Billback_ID_Int] ON [dbo].[Billback] 
(
	[Billback_ID_Int] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'billback'
	AND COLUMN_NAME = 'BB_Adjusted'
)
ALTER TABLE billback ADD [BB_Adjusted] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Adjusted]  DEFAULT (0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'billback'
	AND COLUMN_NAME = 'BB_Adjusted_By'
)
ALTER TABLE billback ADD [BB_Adjusted_By] [nvarchar](50) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'billback'
	AND COLUMN_NAME = 'BB_Adjusted_Date'
)
ALTER TABLE billback ADD [BB_Adjusted_Date] [datetime] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'billback'
	AND COLUMN_NAME = 'BB_Reversed'
)
ALTER TABLE billback ADD [BB_Reversed] [bit] NOT NULL CONSTRAINT [DF__Billback_BB_Reversed]  DEFAULT (0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'billback'
	AND COLUMN_NAME = 'BB_Reversed_By'
)
ALTER TABLE billback ADD [BB_Reversed_By] [nvarchar](50) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'billback'
	AND COLUMN_NAME = 'BB_Reversed_Date'
)
ALTER TABLE billback ADD [BB_Reversed_Date] [datetime] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND 		COLUMN_NAME = 'BB_Expected_Amount'
)
ALTER TABLE [dbo].[Billback] ADD [BB_Expected_Amount] [decimal](20, 2) NULL
GO		

ALTER TABLE [dbo].[Billback] ALTER COLUMN [BB_Expected_Amount] [decimal](20, 2) NULL
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND 		COLUMN_NAME = 'Special_Handling'
)
ALTER TABLE [dbo].[Billback] Add [Special_Handling] [bit] NOT NULL CONSTRAINT [DF_Billback_Special_Handling]  DEFAULT ((0))
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND 		COLUMN_NAME = 'Payment_Notes'
)
ALTER TABLE [dbo].[Billback] ADD [Payment_Notes] [nvarchar](255) NULL
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND 		COLUMN_NAME = 'Distributor_Bill_To_ID'
)
ALTER TABLE [dbo].[Billback] ADD [Distributor_Bill_To_ID] [uniqueidentifier] NULL
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND 		COLUMN_NAME = 'Reversal_Sent'
)
ALTER TABLE Billback ADD [Reversal_Sent] [bit] NOT NULL CONSTRAINT [DF_Billback_Reversal_Sent]  DEFAULT (0)
GO


-- D35606 UPDATE:  NEW 3RD PRTY PROCESS TO HARDCODE ”BB_DEVIATIONS_OVERRIDE_PRICE” ON
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND 		COLUMN_NAME = 'BB_Deviations_Override_Price'
)
ALTER TABLE Billback ADD [BB_Deviations_Override_Price] [bit] NOT NULL CONSTRAINT [DF_Billback_BB_Deviations_Override_Price]  DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Hold' )
  ALTER TABLE [dbo].[BillBack]
    ADD [Hold] [BIT] NOT NULL CONSTRAINT [DF_Vendor_Master_Hold] DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Hold_Date' )
  ALTER TABLE [dbo].[BillBack]
    ADD [Hold_Date] [datetime] NULL 
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Released_Date' )
  ALTER TABLE [dbo].[BillBack]
    ADD [Released_Date] [datetime] NULL 
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Released_By' )
  ALTER TABLE [dbo].[BillBack]
    ADD [Released_By] [varchar](50) NULL 
GO

-- D38359 GM - Model out auto approval and auto match for BB
IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Auto_Match_Process_On' )
  ALTER TABLE [dbo].[BillBack] ADD [Auto_Match_Process_On] [datetime] NULL
GO
---D40664 :: Settings page to show Deleted Billbacks
IF NOT EXISTS ( SELECT 1
				FROM Information_Schema.Columns
				WHERE Table_Name = 'BillBack'
				AND Column_Name = 'Un_Deleted_By_User_id')
ALTER TABLE [dbo].[BillBack] ADD [Un_Deleted_By_User_id] [nvarchar](50) NULL
GO
---D40664 :: Settings page to show Deleted Billbacks
IF NOT EXISTS ( SELECT 1
				FROM Information_Schema.Columns
				WHERE Table_Name = 'BillBack'
				AND Column_Name = 'Un_Deleted_Date')
ALTER TABLE [dbo].[BillBack] ADD [Un_Deleted_Date] [datetime] NULL
GO

IF NOT EXISTS ( SELECT	*
			FROM	INFORMATION_SCHEMA.COLUMNS
			WHERE	TABLE_NAME = 'BillBack'
					AND COLUMN_NAME = 'BB_Upload_Dup_Group_ID' ) 
	ALTER TABLE BillBack ADD BB_Upload_Dup_Group_ID INT NULL 
GO

-- D46812 Update interface flags for historical billbacks created in label 46142(US) & 46144(CA)
IF NOT EXISTS ( SELECT	*
			FROM	INFORMATION_SCHEMA.COLUMNS
			WHERE	TABLE_NAME = 'BillBack'
					AND COLUMN_NAME = 'Do_Not_Interface' ) 
	ALTER TABLE BillBack ADD Do_Not_Interface [bit] NOT NULL CONSTRAINT [DF_Billback_Do_Not_Interface]  DEFAULT ((0))
GO
-- 50616 - New Duplicate BB Logic
IF NOT EXISTS ( SELECT	*
			FROM	INFORMATION_SCHEMA.COLUMNS
			WHERE	TABLE_NAME = 'BillBack'
					AND COLUMN_NAME = 'BB_All_Dup_Group_ID' ) 
	ALTER TABLE BillBack ADD BB_All_Dup_Group_ID INT NULL CONSTRAINT [DF_Billback_BB_All_Dup_Group_ID]  DEFAULT ((NULL))
GO

-- 65595 - CBS upload
IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Trade_Indicator' )
  ALTER TABLE [dbo].[BillBack] ADD [Trade_Indicator] [varchar](50) NULL 
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Quick_Pay' )
  ALTER TABLE [dbo].[BillBack]  
    ADD [Quick_Pay] [BIT] NOT NULL CONSTRAINT [DF_BillBack_Quick_Pay] DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT	*
		FROM	INFORMATION_SCHEMA.COLUMNS
		WHERE	TABLE_NAME = 'BillBack'
		AND COLUMN_NAME = 'Vendor_Only_Billback' ) 
	ALTER TABLE [dbo].[Billback] ADD [Vendor_Only_Billback] [bit] NOT NULL CONSTRAINT [DF_Billback_Vendor_Only_Billback]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'BB_Loc_Duplicate'
)
ALTER TABLE [dbo].[Billback] ADD BB_Loc_Duplicate BIT NOT NULL CONSTRAINT [DF_Billback_BB_Loc_Duplicate]  DEFAULT (0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'BB_Loc_Dup_Check_Verified'
)
ALTER TABLE [dbo].[Billback] ADD BB_Loc_Dup_Check_Verified BIT NOT NULL CONSTRAINT [DF_Billback_BB_Loc_Dup_Check_Verified]  DEFAULT (0)
GO

-- 81938 Update logic to pick default vendor on billback
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Distribution_Channel'
)
ALTER TABLE [dbo].[Billback] ADD Distribution_Channel [varchar](50) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback'
	AND COLUMN_NAME = 'Division'
)
ALTER TABLE [dbo].[Billback] ADD Division [varchar](50) NULL
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'BillBack'
                       AND Column_Name = 'Divested_Items' )
  ALTER TABLE [dbo].[BillBack]  
    ADD [Divested_Items] [BIT] NOT NULL CONSTRAINT [DF_BillBack_Divested_Items] DEFAULT ((0))
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_ALLIED.SQL was last modified on 06/03/2019 06:35:41 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Billback_Allied'
)
CREATE TABLE [dbo].[Billback_Allied](
	[Billback_Allied_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Billback_Allied_Billback_Allied_ID]  DEFAULT (newid()),
	[Billback_id] [uniqueidentifier] NOT NULL,
	[BB_Is_Locked] [bit] NULL CONSTRAINT [DF_Billback_Allied_BB_Is_Locked]  DEFAULT (0),
	[BB_Locked_By_User_ID] [nvarchar](50) NULL,
	[BB_Lock_Date] [datetime] NULL CONSTRAINT [DF_Billback_Allied_BB_Lock_Date]  DEFAULT (getdate()),
	[Pay_Print_Over] [bit] NOT NULL CONSTRAINT [DF_Billback_Allied_Approve_Print_Over]  DEFAULT (0),
	[Pay_Print_Date] [datetime] NULL,
	[BB_Locked_By_Match_Central] [bit] NOT NULL DEFAULT ((0)),
	[BB_Locked_By_Deviation_Grid] [bit] NOT NULL DEFAULT ((0))
 CONSTRAINT [PK_Billback_Allied] PRIMARY KEY NONCLUSTERED 
(
	[Billback_Allied_ID] ASC
)
) ON [PRIMARY]
GO

/*XXXXXXXXXXXXXXXXXXXXXXXXXXX		DROP FIRST	XXXXXXXXXXXXXXXXXXXXXXXXXXX*/
	/****** Object:  Index [PK_Billback_Allied]    Script Date: 04/22/2009 15:15:39 ******/
	IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Billback_Allied]') AND name = N'PK_Billback_Allied')
	ALTER TABLE [dbo].[Billback_Allied] DROP CONSTRAINT [PK_Billback_Allied]
	GO

	/****** Object:  Index [IX_Billback_Allied_Billback_id]    Script Date: 04/22/2009 15:17:40 ******/
	IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Billback_Allied]') AND name = N'IX_Billback_Allied_Billback_id')
	DROP INDEX [IX_Billback_Allied_Billback_id] ON [dbo].[Billback_Allied] WITH ( ONLINE = OFF )
	GO

	
/*XXXXXXXXXXXXXXXXXXXXXXXXXXX		NOW CREATE		XXXXXXXXXXXXXXXXXXXXXXXXXXX*/

	/****** Changed to Clustered ******/
	CREATE CLUSTERED INDEX [IX_Billback_Allied_Billback_id] ON [dbo].[Billback_Allied] 
	(
		[Billback_id] ASC
	)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80, ONLINE = OFF) ON [PRIMARY]
	GO


	/****** Changed to Non-clustered ******/
	ALTER TABLE [dbo].[Billback_Allied] ADD  CONSTRAINT [PK_Billback_Allied] PRIMARY KEY NONCLUSTERED 
	(
		[Billback_Allied_ID] ASC
	)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80, ONLINE = OFF) ON [PRIMARY]
	GO

	
	if not exists 
	(
		SELECT	*
		FROM	INFORMATION_SCHEMA.COLUMNS
		WHERE	TABLE_NAME = 'Billback_Allied'
			AND
			COLUMN_NAME = 'Approval_Button'
	)
	ALTER TABLE Billback_Allied ADD [Approval_Button] [varchar](30) NULL
	GO

	if not exists
	(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Allied'
	AND	COLUMN_NAME = 'Set_Program_Won_On_BB_Paid'
	)
	ALTER TABLE Billback_Allied ADD [Set_Program_Won_On_BB_Paid] [bit] NOT NULL CONSTRAINT [DF_Billback_Allied_Set_Program_Won_On_BB_Paid]  DEFAULT ((0))
	GO
	
	-- WR 82368
	if not exists
	(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Allied'
	AND	COLUMN_NAME = 'TIER'
	)
	ALTER TABLE Billback_Allied ADD TIER TINYINT NOT NULL CONSTRAINT [DF_Billback_Allied_Tier]  DEFAULT (0)
	GO

-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_CLOSING_METHODS.SQL was last modified on 06/13/2019 07:34:00 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS
(
	SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[Billback_Closing_Methods]')
	and OBJECTPROPERTY(id, N'IsUserTable') = 1
)
BEGIN

CREATE TABLE [dbo].[Billback_Closing_Methods](
	[iBillback_Closing_Method_ID] [int] NOT NULL,
	[vchBillback_Closing_Method_Desc] [varchar](50) NULL,
	[bEnabled] [bit] NOT NULL CONSTRAINT [DF_Billback_Closing_Methods_bEnabled]  DEFAULT ((0)),
	[tiAutoPay_BB_Status] [tinyint] NOT NULL CONSTRAINT [DF_tiAutoPay_BB_Status]  DEFAULT ((4)),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Billback_Closing_Methods_Deleted]  DEFAULT ((0)),
	[Abbreviation][varchar](50) NULL
) ON [PRIMARY]
END


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Closing_Methods'
	AND		COLUMN_NAME = 'Auto_Dev_BB_Status_Below'
)

ALTER TABLE Billback_Closing_Methods ADD [Auto_Dev_BB_Status_Below] [INT] NOT NULL  DEFAULT(2)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Closing_Methods'
	AND		COLUMN_NAME = 'Auto_Dev_BB_Status_Exceed'
)

ALTER TABLE Billback_Closing_Methods ADD [Auto_Dev_BB_Status_Exceed] [INT] NOT NULL  DEFAULT(2)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Closing_Methods'
	AND		COLUMN_NAME = 'Exclude_From_Payment_History'
)

ALTER TABLE Billback_Closing_Methods ADD [Exclude_From_Payment_History] [BIT] NOT NULL  DEFAULT(0)
GO

IF NOT EXISTS
(
	SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 6
)
	BEGIN
		INSERT INTO Billback_Closing_Methods
		(iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation)
		VALUES
		(6,'Debit Memo',0,3,1,'DM')
	END

IF NOT EXISTS
(
	SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 7
)
	BEGIN
		INSERT INTO Billback_Closing_Methods
		(iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation)
		VALUES
		(7,'Budget Entry Only',0,3,1,'BUD')
	END

IF NOT EXISTS
(
	SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 8
)
	BEGIN
		INSERT INTO Billback_Closing_Methods
		(iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation)
		VALUES
		(8,'Payment EFT',0,4,1,'EFT')
	END

IF NOT EXISTS
(
	SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 9
)
	BEGIN
		INSERT INTO Billback_Closing_Methods
		(iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation)
		VALUES
		(9,'WriteOff',0,2,1,'WO')
	END

IF NOT EXISTS
(
	SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 10
)
	BEGIN
		INSERT INTO Billback_Closing_Methods
		(iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation)
		VALUES
		(10,'Re-Instate',0,2,1,'RI')
	END


-- D46292 Create new closing method - Calculation only
IF NOT EXISTS
(
	SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 11
)
	BEGIN
		INSERT INTO Billback_Closing_Methods
		(iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation)
		VALUES
		(11,'Calculation only',0,2,1,'CAL')
	END

IF NOT EXISTS ( SELECT  1
                FROM    INFORMATION_SCHEMA.COLUMNS
                WHERE   TABLE_NAME = 'Billback_Closing_Methods'
                        AND COLUMN_NAME = 'Require_Bank_Info' )
    ALTER TABLE Billback_Closing_Methods ADD [Require_Bank_Info] [BIT] NOT NULL DEFAULT(0)
GO


--D55620  Update BB Closing Method


IF NOT EXISTS
(
      SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 12
)
BEGIN
      INSERT INTO Billback_Closing_Methods
      (iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation)
      VALUES
      (12,'Draft',0,2,1,'DFT')
END   


--D55703 :: Vendor required setting in closing method settings panel
IF NOT EXISTS ( SELECT  1
                FROM    INFORMATION_SCHEMA.COLUMNS
                WHERE   TABLE_NAME = 'Billback_Closing_Methods'
                        AND COLUMN_NAME = 'Vendor_Required' )
    ALTER TABLE Billback_Closing_Methods ADD [Vendor_Required] [BIT] NOT NULL DEFAULT(0)
GO

--72368 :: Allow Operator Payee for "credit memo" closing method
IF NOT EXISTS ( SELECT  1
                FROM    INFORMATION_SCHEMA.COLUMNS
                WHERE   TABLE_NAME = 'Billback_Closing_Methods'
                        AND COLUMN_NAME = 'Allow_Operator_Payee' )
    ALTER TABLE Billback_Closing_Methods ADD [Allow_Operator_Payee] [BIT] NOT NULL DEFAULT(0)
GO

-- 77239 New BB Closing Methods
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Closing_Methods'
	AND		COLUMN_NAME = 'Closing_Method_Type'
)
BEGIN
	ALTER TABLE Billback_Closing_Methods ADD [Closing_Method_Type] [INT] NULL
	EXEC ('UPDATE Billback_Closing_Methods SET Closing_Method_Type = 1 WHERE iBillback_Closing_Method_ID IN (1, 8, 13, 14, 15, 16, 17) AND Closing_Method_Type IS NULL')
END
GO


IF NOT EXISTS
(
      SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 13
)
BEGIN
      INSERT INTO Billback_Closing_Methods
      (iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation,Closing_Method_Type)
      VALUES
      (13, 'Separate Check', 0, 4, 1, 'PMT3',1)
END   


IF NOT EXISTS
(
      SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 14
)
BEGIN
      INSERT INTO Billback_Closing_Methods
      (iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation,Closing_Method_Type)
      VALUES
      (14, 'Bank Transfer', 0, 3, 1,'PMT4',1)
END   


IF NOT EXISTS
(
      SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 15
)
BEGIN
      INSERT INTO Billback_Closing_Methods
      (iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation,Closing_Method_Type)
      VALUES
      (15, 'Treasury Issued Wires Only', 0, 4, 1,'PMT5',1)
END   

IF NOT EXISTS
(
      SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 16
)
BEGIN
      INSERT INTO Billback_Closing_Methods
      (iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation,Closing_Method_Type)
      VALUES
      (16, 'P-Card', 0, 4, 1,'PMT6',1)
END  

IF NOT EXISTS
(
      SELECT * FROM dbo.Billback_Closing_Methods WHERE iBillback_Closing_Method_ID = 17
)
BEGIN
      INSERT INTO Billback_Closing_Methods
      (iBillback_Closing_Method_ID,vchBillback_Closing_Method_Desc,bEnabled,tiAutoPay_BB_Status,Deleted,Abbreviation,Closing_Method_Type)
      VALUES
      (17, 'P-Card-Manual', 0, 4, 1,'PMT7',1)
END  

IF NOT EXISTS (	SELECT *
				  FROM INFORMATION_SCHEMA.COLUMNS
				 WHERE TABLE_NAME = 'Billback_Closing_Methods' AND COLUMN_NAME = 'Display_Sequence'
)
	ALTER TABLE Billback_Closing_Methods ADD [Display_Sequence] [INT] NULL
GO

-- 86009 BB Upload - incompatible closing method values
IF NOT EXISTS (	SELECT *
				  FROM INFORMATION_SCHEMA.COLUMNS
				 WHERE TABLE_NAME = 'Billback_Closing_Methods' AND COLUMN_NAME = 'Closing_Method_Code'
)
BEGIN
	ALTER TABLE Billback_Closing_Methods ADD [Closing_Method_Code] [varchar] (5) NULL

	EXEC ('UPDATE Billback_Closing_Methods SET Closing_Method_Code = ''P'' WHERE iBillback_Closing_Method_ID = 1 AND Closing_Method_Code IS NULL')
	EXEC ('UPDATE Billback_Closing_Methods SET Closing_Method_Code = ''D'' WHERE iBillback_Closing_Method_ID = 2 AND Closing_Method_Code IS NULL')
	EXEC ('UPDATE Billback_Closing_Methods SET Closing_Method_Code = ''O'' WHERE iBillback_Closing_Method_ID = 3 AND Closing_Method_Code IS NULL')
	EXEC ('UPDATE Billback_Closing_Methods SET Closing_Method_Code = ''A'' WHERE iBillback_Closing_Method_ID = 4 AND Closing_Method_Code IS NULL')
	EXEC ('UPDATE Billback_Closing_Methods SET Closing_Method_Code = ''C'' WHERE iBillback_Closing_Method_ID = 5 AND Closing_Method_Code IS NULL')
	EXEC ('UPDATE Billback_Closing_Methods SET Closing_Method_Code = ''E'' WHERE iBillback_Closing_Method_ID = 8 AND Closing_Method_Code IS NULL')

END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_LUMPSUM_ITEM_ALLOCATION.SQL was last modified on 04/08/2019 08:20:59 AM ---
-------------------------------------------------------------------------------------------------------------------------------
-- Created By Deepa - 04/12/2018 - WR 76379 Additional Retail fields to RDB - Forge changes
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Billback_LumpSum_Item_Allocation'
)
CREATE TABLE [dbo].[Billback_LumpSum_Item_Allocation](
	[Billback_LumpSum_Item_Allocation_ID] [int] IDENTITY(1,1) NOT NULL,
	[Billback_ID] UNIQUEIDENTIFIER NOT NULL,
	[BB_Code] VARCHAR(100) NULL,
	[Billback_Program_ID] UNIQUEIDENTIFIER NOT NULL,
	[BB_LS_Amt] DECIMAL(20, 4),
	[BSA_Foodservice_Items_Master_ID] UNIQUEIDENTIFIER NOT NULL,
	[LS_Allocated_Amt] DECIMAL(20, 4),
	[Cases_Ordered] DECIMAL(20, 4),
	[Created_Date] [datetime]  NOT NULL CONSTRAINT [DF_Billback_LumpSum_Item_Allocation_Created_Date]  DEFAULT (getdate()),
	CONSTRAINT [PK_Billback_LumpSum_Item_Allocation] PRIMARY KEY  CLUSTERED
	(
		[Billback_ID], [Billback_Program_ID], [BSA_Foodservice_Items_Master_ID]
	)  ON [PRIMARY]
) ON [PRIMARY]
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'Billback_LumpSum_Item_Allocation'
                       AND Column_Name = 'Program_Lump_Sum_ID' )
  ALTER TABLE [dbo].Billback_LumpSum_Item_Allocation  
    ADD Program_Lump_Sum_ID  UNIQUEIDENTIFIER
GO

IF  EXISTS ( SELECT 1
             FROM    Information_Schema.Columns
             WHERE   Table_Name = 'Billback_LumpSum_Item_Allocation'
             AND     Column_Name = 'Program_Lump_Sum_ID' )

UPDATE Billback_LumpSum_Item_Allocation SET Program_Lump_Sum_ID = '00000000-0000-0000-0000-000000000000' WHERE Program_Lump_Sum_ID IS NULL
GO

IF  EXISTS ( SELECT 1
             FROM    Information_Schema.Columns
             WHERE   Table_Name = 'Billback_LumpSum_Item_Allocation'
             AND     Column_Name = 'Program_Lump_Sum_ID' )
ALTER TABLE [dbo].Billback_LumpSum_Item_Allocation  ALTER COLUMN  Program_Lump_Sum_ID  UNIQUEIDENTIFIER  NOT NULL 
GO

IF  (  SELECT COUNT(*)  
          FROM     INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab
          INNER JOIN     INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Col 
          ON         Col.Constraint_Name = Tab.Constraint_Name
          AND        Col.Table_Name = Tab.Table_Name
          WHERE      Tab.Constraint_Type = 'PRIMARY KEY'
          AND        Col.Table_Name = 'Billback_LumpSum_Item_Allocation'
          AND        Col.COLUMN_NAME in ('Billback_ID','Billback_Program_ID','BSA_Foodservice_Items_Master_ID','Program_Lump_Sum_ID')
          ) <4  -- if there are less than 4 columns in primary key or if primary key doesnt exists 
BEGIN
              IF EXISTS ( SELECT Constraint_Name  FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE  Constraint_Name ='PK_Billback_LumpSum_Item_Allocation')
              BEGIN
                     ALTER TABLE Billback_LumpSum_Item_Allocation DROP CONSTRAINT [PK_Billback_LumpSum_Item_Allocation]
              END
              
              IF NOT EXISTS ( SELECT Constraint_Name  FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE  Constraint_Name ='PK_Billback_LumpSum_Item_Allocation')
              BEGIN
                     ALTER TABLE Billback_LumpSum_Item_Allocation ADD CONSTRAINT [PK_Billback_LumpSum_Item_Allocation] PRIMARY KEY ([Billback_ID], [Billback_Program_ID], [BSA_Foodservice_Items_Master_ID], Program_Lump_Sum_ID)
              END
END

--WR 84629 - Synching reporting with interfaces - FORGE changes
IF  NOT EXISTS ( SELECT 1
             FROM	Information_Schema.Columns
             WHERE	Table_Name = 'Billback_LumpSum_Item_Allocation'
             AND	Column_Name = 'Distributor_ID' )
ALTER TABLE [dbo].Billback_LumpSum_Item_Allocation  ADD  Distributor_ID  UNIQUEIDENTIFIER  NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000')
GO

IF  (  SELECT	COUNT(*)  
	   FROM     INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab
	   INNER JOIN     INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Col 
	   ON		Col.Constraint_Name = Tab.Constraint_Name
	   AND		Col.Table_Name = Tab.Table_Name
	   WHERE	Tab.Constraint_Type = 'PRIMARY KEY'
	   AND		Col.Table_Name = 'Billback_LumpSum_Item_Allocation'
	   AND		Col.COLUMN_NAME in ('Billback_ID','Billback_Program_ID','BSA_Foodservice_Items_Master_ID','Distributor_ID','Program_Lump_Sum_ID')
	   ) <5  -- if there are less than 5 columns in primary key or if primary key doesnt exists 
BEGIN
		IF EXISTS ( SELECT Constraint_Name  FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE  Constraint_Name ='PK_Billback_LumpSum_Item_Allocation')
		BEGIN
			ALTER TABLE Billback_LumpSum_Item_Allocation DROP CONSTRAINT [PK_Billback_LumpSum_Item_Allocation]
		END
		
		IF NOT EXISTS ( SELECT Constraint_Name  FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE  Constraint_Name ='PK_Billback_LumpSum_Item_Allocation')
		BEGIN
			ALTER TABLE Billback_LumpSum_Item_Allocation ADD CONSTRAINT [PK_Billback_LumpSum_Item_Allocation] PRIMARY KEY ([Billback_ID], [Billback_Program_ID], [BSA_Foodservice_Items_Master_ID],[Distributor_ID], Program_Lump_Sum_ID)
		END
END
-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_PRODUCT.SQL was last modified on 01/14/2019 07:24:28 AM ---
-------------------------------------------------------------------------------------------------------------------------------
-- BillBack_Product    		***********************************
IF not EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='BillBack_Product'
AND C.Name='Distributor_id')


Alter TABLE [dbo].[BillBack_Product] add
	[Distributor_id] [uniqueidentifier] NULL  
go


if exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'BillBack_Product' AND
                        COLUMN_NAME = 'Invalid_Product_Desc'
)
ALTER TABLE BillBack_Product ALTER COLUMN [Invalid_Product_Desc] [varchar](100) NULL 
GO


IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
		AND
		COLUMN_NAME = 'Created_Sort_Order'
)
ALTER TABLE BillBack_Product ADD [Created_Sort_Order]  [INT] NULL 
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'Deleted_By'
)
ALTER TABLE BillBack_Product ADD [Deleted_By] [NVARCHAR](50) NULL 
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'Deleted_Date'
)
ALTER TABLE BillBack_Product ADD [Deleted_Date] [DATETIME] NULL 
GO


-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'Distributor_Owner_ID'
)
ALTER TABLE dbo.BillBack_Product ADD [Distributor_Owner_ID] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'Distributor_Owner_Name'
)
ALTER TABLE dbo.BillBack_Product ADD [Distributor_Owner_Name] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'Operator_Owner_ID'
)
ALTER TABLE dbo.BillBack_Product ADD [Operator_Owner_ID] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'Operator_Owner_Name'
)
ALTER TABLE dbo.BillBack_Product ADD [Operator_Owner_Name] [varchar](255) NULL
GO

/* 77469	Display Dist Channel at BB_Program Distributor Level   [ CF work ] -Anand Rao/12-Jun-2018 */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'BS_Var_2'
)
ALTER TABLE dbo.BillBack_Product ADD [BS_Var_2] [varchar](50) NULL
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'BillBack_Product_Int'
)
ALTER TABLE dbo.BillBack_Product ADD [BillBack_Product_Int] INT IDENTITY(1,1) NOT NULL


/* 81534 - Incorrect BB expected & claimed rate if UOM is CWT / Anand Rao / 03-Dec-2018 */

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
		AND
		COLUMN_NAME = 'User_Picked_UOM'
)
ALTER TABLE BillBack_Product ADD [User_Picked_UOM]  [INT] NULL 
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BillBack_Product'
	AND		COLUMN_NAME = 'User_Entered_Quantity'
)
ALTER TABLE dbo.BillBack_Product ADD [User_Entered_Quantity] [varchar](100) NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_SEARCH.SQL was last modified on 11/04/2019 10:56:36 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
)

CREATE TABLE [dbo].[Billback_Search](
	[Billback_ID_Int] [int] NOT NULL,
	[Billback_ID] [varchar] (50) NOT NULL,
	[BB_Code] [varchar](20) NULL,
	[BB_Reference] [varchar](50) NULL,
	[referenceNum] [varchar](50) NULL,
	[Searchable_BB_Code] [varchar] (15) NULL,
	[BB_Title] [varchar](100) NULL,
	[BB_Amount] [float] NULL,
	[Approved_Amount] [float] NULL,
	[Created_Date] [datetime] NULL,
	[BB_Request_Approval_Date] [datetime] NULL,
	[BB_Date] [datetime] NULL,
	[BB_Start_Date] [datetime] NULL,
	[BB_End_Date] [datetime] NULL,
	[Date_Approved] [datetime] NULL,
	[Check_Number] [varchar](20) NULL,
	[Billback_Status_ID] [tinyint] NULL,
	[BB_Status_Description] [varchar](35) NULL,
	[BB_Status_Abbreviation] [varchar](5) NULL,
	[Billback_Closing_Method_ID] [tinyint] NULL,
	[Billback_Closing_Method_Desc] [varchar](20) NULL,
	[Billback_Closing_Method_Abbreviation] [varchar](5) NULL,
	[BB_Type_ID] [tinyint] NULL,
	[BB_Type_Description] [varchar](10) NULL,	
	[Creator_User_Int] [int] NULL,
	[Request_Approval_User_Int] [int] NULL,
	[Disagree_User_Int] [int] NULL,
	[Reset_User_Int] [int] NULL,
	[Approved_User_Int] [int] NULL,
	[Analyst_User_Int] [int] NULL,
	[Analyst_User_ID] [varchar](50) NULL,
	[Analyst_User] [varchar](50) NULL,
	[Creator_User] [varchar](50) NULL,
	[Request_Approval_User] [varchar](50) NULL,
	[Disagree_User] [varchar](50) NULL,
	[Reset_User] [varchar](50) NULL,
	[Approved_User] [varchar](50) NULL,
	[Billback_Payee_Type_ID] [tinyint] NULL,
	[Payee] [varchar](100) NULL,
	[Payee_ID] [varchar](50) NULL,
	[VendorPayee] [varchar](100) NULL,
	[VendorPayeeID] [varchar](50) NULL,	
	[Deviated] bit NOT NULL,
 CONSTRAINT [PK_Billback_Search] PRIMARY KEY CLUSTERED 
(
	[Billback_ID_Int] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'Inserted_Date'
)
ALTER TABLE Billback_Search ADD [Inserted_Date] [datetime] NOT NULL CONSTRAINT [DF_Billback_Search_Inserted_Date]  DEFAULT (getdate())
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'Billback_Closing_Method_ID_List'
)
ALTER TABLE Billback_Search ADD [Billback_Closing_Method_ID_List] varchar(25) NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'Paid_Date'
)
ALTER TABLE Billback_Search ADD [Paid_Date] [datetime] NULL
GO

if exists 
(
Select * from sysindexes where name = 'Billback_Search_IDX_NC1'
)                   
drop index [dbo].[Billback_Search].[Billback_Search_IDX_NC1] 


-- D60362 Job Failed On Prod - BA_Kraft_Nightly_Common_Schedule
if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'Creator_User'
)
ALTER TABLE Billback_Search ALTER COLUMN [Creator_User] [varchar](100) NULL
GO

-- D60362 Job Failed On Prod - BA_Kraft_Nightly_Common_Schedule
if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'BB_Reference'
)
ALTER TABLE Billback_Search ALTER COLUMN [BB_Reference] varchar(100) NULL
GO

-- D60362 Job Failed On Prod - BA_Kraft_Nightly_Common_Schedule
if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'BB_Title'
)
ALTER TABLE Billback_Search ALTER COLUMN [BB_Title] varchar(100) NULL
GO

-- D60362 Job Failed On Prod - BA_Kraft_Nightly_Common_Schedule
if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'Check_Number'
)
ALTER TABLE Billback_Search ALTER COLUMN [Check_Number] varchar(50) NULL
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'BB_Received_Date'
)
ALTER TABLE Billback_Search ADD [BB_Received_Date] DATETIME NULL
GO
/*************** ONE TIME UPDATE TO COLUMN BB_Received_Date **************/

UPDATE BS SET BS.BB_Received_Date = BB.BB_Received_Date 
-- SELECT BS.BB_Received_Date, BS.Billback_ID, BB.BB_Received_Date, BB.Billback_ID
FROM Billback_Search BS
INNER JOIN dbo.Billback BB ON BB.Billback_ID = BS.Billback_ID
GO 

DROP INDEX Billback_search.Billback_Search_IDX_NC1
GO

/* NOTE TO DEVELOPER: WHEN YOU ADD ANY FIELD ABOVE, ADD IT TO THE INDEX TOO */
CREATE NONCLUSTERED INDEX Billback_Search_IDX_NC1 ON [dbo].[Billback_Search] ([Billback_ID_Int]) 
INCLUDE 
(
[Billback_ID],[BB_Code],[BB_Reference],[referenceNum],[Searchable_BB_Code],[BB_Title]
,[BB_Amount],[Approved_Amount],[Created_Date],[BB_Request_Approval_Date],[BB_Date],[BB_Start_Date],[BB_End_Date],[Date_Approved]
,[Check_Number],[Billback_Status_ID],[BB_Status_Description],[BB_Status_Abbreviation],[Billback_Closing_Method_ID]
,[Billback_Closing_Method_Desc],[Billback_Closing_Method_Abbreviation],[BB_Type_ID],[BB_Type_Description],[Creator_User_Int]
,[Request_Approval_User_Int],[Disagree_User_Int],[Reset_User_Int],[Approved_User_Int],[Analyst_User_Int],[Analyst_User_ID]
,[Analyst_User],[Creator_User],[Request_Approval_User],[Disagree_User],[Reset_User],[Approved_User],[Billback_Payee_Type_ID]
,[Payee],[Payee_ID],[VendorPayee],[VendorPayeeID],[Deviated],[Billback_Closing_Method_ID_List],[Paid_Date],[BB_Received_Date]
)
GO

-- D36252: Job Failed On Prod - GM_FB05_FB01_ACK_UPDATE
if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'BB_Status_Abbreviation'
)
ALTER TABLE Billback_Search ALTER COLUMN [BB_Status_Abbreviation] [varchar](10) NULL
GO

if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'BB_Type_Description'
)
ALTER TABLE Billback_Search ALTER COLUMN [BB_Type_Description] [varchar](15) NULL
GO

-- D37886
if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'BB_Reference'
)
ALTER TABLE Billback_Search ALTER COLUMN [BB_Reference] [varchar](100) NULL
GO

if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'referenceNum'
)
ALTER TABLE Billback_Search ALTER COLUMN [referenceNum] [varchar](100) NULL
GO

if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Search'
	AND		COLUMN_NAME = 'BB_Status_Abbreviation'
)
ALTER TABLE Billback_Search ALTER COLUMN [BB_Status_Abbreviation] [varchar](10) NULL
GO


-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_SETTINGS.SQL was last modified on 08/19/2019 11:12:17 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Billback_Settings'
)
CREATE TABLE [dbo].[Billback_Settings](
	[Billback_Settings_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Billback_Settings_2_Billback_Settings_ID]  DEFAULT (newid()),
	[User_ID] [nvarchar](50) NULL,
	[BB_Range_Update_Date] [datetime] NULL,
	[BB_Range_Editor_ID] [nvarchar](50) NULL,
	[BB_Tolerance_DPP] [float] NULL,
	[BB_Tolerance_DPP_Rate] [float] NULL,
	[BB_Tolerance_DPPO] [int] NULL,
	[BB_Tolerance_BAP] [float] NULL,
	[BB_Tolerance_BAPO] [int] NULL,
	[BB_Tolerance_DVT] [int] NULL,
	[BB_Tolerance_Update_Date] [datetime] NULL,
	[BB_Tolerance_Editor_ID] [nvarchar](50) NULL,
	[BB_Tolerance_TET] [int] NULL,
	[BB_Tolerance_OldDays] [int] NULL,
	[BB_Tolerance_ERT] [int] NULL,
	[BB_Danger_Range] [int] NULL,
	[AutoBB_Notify_Days] [int] NOT NULL CONSTRAINT [DF_BB_Settings_AutoBB_Notify_Days]  DEFAULT (0),
	[Default_Program] [int] NULL,
	[Default_Updated_By] [nvarchar](50) NULL,
	[Default_Updated_Date] [datetime] NULL,
	[Auto_Approve_On] [bit] NULL DEFAULT ((0)),
	[Auto_Approve_Amount] [float] NULL,
	[Auto_Approve_Updated_By] [nvarchar](50) NULL,
	[Auto_Approve_Updated_Date] [datetime] NULL,
	[Search_Expired_Program_Within] [smallint] NULL,
	[Adjustment_Default] [int] NULL DEFAULT ((1)),
	[Auto_Approve_BB_Types] [tinyint] NULL,
	[Auto_Approved_BB_Status] [tinyint] NULL,
	[Adjustment_From_Program_WithOut_PullBack] [int] NOT NULL CONSTRAINT [DF_Billback_Settings_Adjustment_From_Program_WithOut_PullBack]  DEFAULT ((0)),
	[Adjustment_From_Program_With_PullBack] [int] NOT NULL CONSTRAINT [DF_Billback_Settings_Adjustment_From_Program_With_PullBack]  DEFAULT ((0)),
	[Pullback_Adjustment_Updated_By] [varchar](50) NULL,
	[Pullback_Adjustment_Updated_On] [datetime] NULL,
 CONSTRAINT [PK_Billback_Settings_2] PRIMARY KEY CLUSTERED 
(
	[Billback_Settings_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
)
GO

if not exists 
(
    SELECT            *
    FROM   INFORMATION_SCHEMA.COLUMNS
    WHERE  TABLE_NAME = 'Billback_Settings' AND
                COLUMN_NAME = 'Auto_Approve_Dummy_Prog'
)
ALTER TABLE Billback_Settings ADD [Auto_Approve_Dummy_Prog] [bit] NOT NULL 
CONSTRAINT [DF_Billback_Settings_Auto_Approve_Dummy_Prog] DEFAULT (0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'BB_Tolerance_DPP_Rate'
)
ALTER TABLE Billback_Settings ADD [BB_Tolerance_DPP_Rate] [float] NULL
GO


UPDATE	Billback_Settings
SET	BB_Tolerance_DPP_Rate = BB_Tolerance_DPP
WHERE	BB_Tolerance_DPP_Rate IS NULL
AND	BB_Tolerance_DPP IS NOT NULL

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'III_Party_Xref_Enabled'
)
ALTER TABLE Billback_Settings ADD III_Party_Xref_Enabled [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_Party_Xref_Enabled]  DEFAULT ((0))
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Operator_Xref_Enabled'
)
ALTER TABLE Billback_Settings ADD Operator_Xref_Enabled [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Operator_Xref_Enabled]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Allow_Multiple_Operator_Xref '
)
ALTER TABLE Billback_Settings ADD Allow_Multiple_Operator_Xref [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Allow_Multiple_Operator_Xref]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USE_DFLT_PRG '
)
ALTER TABLE Billback_Settings ADD USE_DFLT_PRG [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_USE_DFLT_PRG]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'IS_ReferenceNum '
)
ALTER TABLE Billback_Settings ADD IS_ReferenceNum [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_IS_ReferenceNum]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USE_UOM '
)
ALTER TABLE Billback_Settings ADD USE_UOM [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_USE_UOM]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT * 
	FROM INFORMATION_SCHEMA.COLUMNS 
	WHERE TABLE_NAME = 'Billback_Settings' 
	AND COLUMN_NAME = 'Default_Sort_Option_For_Scorecard'
)
ALTER TABLE dbo.Billback_Settings ADD Default_Sort_Option_For_Scorecard varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Billback_Settings_Default_Sort_Option_For_Scorecard]  DEFAULT ('BBI')	
GO 
 
IF NOT EXISTS
(
	SELECT * 
	FROM INFORMATION_SCHEMA.COLUMNS 
	WHERE TABLE_NAME = 'Billback_Settings' 
	AND COLUMN_NAME = 'Default_Sort_By'
)
ALTER TABLE dbo.Billback_Settings ADD Default_Sort_By varchar(4) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL CONSTRAINT [DF_Billback_Settings_Default_Sort_By]  DEFAULT ('DESC')
GO 

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'III_P_Upload_Single_BB_Per_Invoice'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_Single_BB_Per_Invoice [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Single_BB_Per_Invoice]  DEFAULT ((0))
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'III_P_Upload_Single_BB_Updated_By'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_Single_BB_Updated_By [varchar](50) NULL
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'III_P_Upload_Single_BB_Updated_Date'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_Single_BB_Updated_Date [datetime] NULL
GO

--- 32530 
IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.COLUMNS
                 WHERE Table_Name = 'Billback_Settings'
                       AND Column_Name = 'III_P_Upload_One_Pgm_Per_BB' )
  ALTER TABLE BILLBACK_SETTINGS
    ADD III_P_Upload_One_Pgm_Per_BB [BIT] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_One_Pgm_Per_BB] DEFAULT ((0))

GO 

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.COLUMNS
                 WHERE Table_Name = 'Billback_Settings'
                       AND Column_Name = 'III_P_Upload_Load_Claim_Price' )
  ALTER TABLE BILLBACK_SETTINGS
    ADD III_P_Upload_Load_Claim_Price [BIT] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Load_Claim_Price] DEFAULT ((0))

GO 


IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.COLUMNS
                 WHERE Table_Name = 'Billback_Settings'
                       AND Column_Name = 'III_P_Upload_Alias_Uses_Eshark' )
  ALTER TABLE BILLBACK_SETTINGS
    ADD III_P_Upload_Alias_Uses_Eshark [BIT] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Alias_Uses_Eshark] DEFAULT ((0))

GO 

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USE_Program_Xref'
)
ALTER TABLE Billback_Settings ADD USE_Program_Xref [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_USE_Program_Xref]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Sysco_EDI_Use_Program_Xref'
)
ALTER TABLE Billback_Settings ADD Sysco_EDI_Use_Program_Xref [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Sysco_EDI_Use_Program_Xref]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USFS_EDI_Use_Program_Xref'
)
ALTER TABLE Billback_Settings ADD USFS_EDI_Use_Program_Xref [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_USFS_EDI_Use_Program_Xref]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'III_Use_Program_Xref'
)
ALTER TABLE Billback_Settings ADD III_Use_Program_Xref [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_Use_Program_Xref]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Dist_Xref_Enabled'
)
ALTER TABLE Billback_Settings ADD Dist_Xref_Enabled [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Dist_Xref_Enabled]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Item_Xref_Enabled'
)
ALTER TABLE Billback_Settings ADD Item_Xref_Enabled [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Item_Xref_Enabled]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'III_P_Upload_Operator_Auto_Add'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_Operator_Auto_Add [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Operator_Auto_Add]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Sysco_Use_Mfg_Product_ID'
)
ALTER TABLE Billback_Settings ADD Sysco_Use_Mfg_Product_ID [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Sysco_Use_Mfg_Product_ID]  DEFAULT ((0))
GO


-- Vendor Override for Sysco EDI when invoice length is 12
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Vendor_Override_For_Sysco_EDI'
)
ALTER TABLE Billback_Settings ADD Vendor_Override_For_Sysco_EDI [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Vendor_Override_For_Sysco_EDI]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT * 
	FROM INFORMATION_SCHEMA.COLUMNS 
	WHERE TABLE_NAME = 'Billback_Settings' 
	AND COLUMN_NAME = 'Vendor_ID'
)
ALTER TABLE dbo.Billback_Settings ADD Vendor_ID varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
GO 

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Vendor_Default_Closing_Method_ID'
)
ALTER TABLE Billback_Settings ADD [Vendor_Default_Closing_Method_ID] [tinyint] NULL
GO

/* START: 39812	Validate EDI files for potential billback duplicate/Anand Rao/16-Jan-2014 */


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Enable_BB_Dup_Check'
)
ALTER TABLE Billback_Settings ADD Enable_BB_Dup_Check [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Enable_BB_Dup_Check]  DEFAULT ((0))
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Same_Dollar_Amount'
)
ALTER TABLE Billback_Settings ADD Same_Dollar_Amount [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Same_Dollar_Amount]  DEFAULT ((0))
GO



if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Same_Reference_Number'
)
ALTER TABLE Billback_Settings ADD Same_Reference_Number [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Same_Reference_Number]  DEFAULT ((0))
GO



if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Same_Payee'
)
ALTER TABLE Billback_Settings ADD Same_Payee [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Same_Payee]  DEFAULT ((0))
GO



if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Same_Start_End_Dates'
)
ALTER TABLE Billback_Settings ADD Same_Start_End_Dates [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Same_Start_End_Dates]  DEFAULT ((0))
GO


/*  START :: D41281: Sysco EDI - negative invoices */

--if not exists 
--(
--	SELECT	*
--	FROM	INFORMATION_SCHEMA.COLUMNS
--	WHERE	TABLE_NAME = 'Billback_Settings'
--		AND
--		COLUMN_NAME = 'Sysco_EDI_Filter_Negative_Invoices'
--)
--ALTER TABLE Billback_Settings ADD Sysco_EDI_Filter_Negative_Invoices [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Sysco_EDI_Filter_Negative_Invoices]  DEFAULT ((0))
--GO
--
--if not exists 
--(
--	SELECT	*
--	FROM	INFORMATION_SCHEMA.COLUMNS
--	WHERE	TABLE_NAME = 'Billback_Settings'
--		AND
--		COLUMN_NAME = 'US_Foods_EDI_Filter_Negative_Invoices'
--)
--ALTER TABLE Billback_Settings ADD US_Foods_EDI_Filter_Negative_Invoices [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_US_Foods_EDI_Filter_Negative_Invoices]  DEFAULT ((0))
--GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'III_P_Upload_BB_Title'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_BB_Title [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_BB_Title]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USFS_Concat_Program_Alias_Desc'
)
ALTER TABLE Billback_Settings ADD USFS_Concat_Program_Alias_Desc [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_USFS_Concat_Program_Alias_Desc]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'EDI_create_BB_per_Associated_Shipto'
)
ALTER TABLE Billback_Settings ADD EDI_create_BB_per_Associated_Shipto [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_EDI_create_BB_per_Associated_Shipto]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Override_Use_Program_Xref'
)
ALTER TABLE Billback_Settings ADD Override_Use_Program_Xref [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Override_Use_Program_Xref]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Auto_Approve_CM_OFF'
)
ALTER TABLE Billback_Settings ADD Auto_Approve_CM_OFF [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Auto_Approve_CM_OFF]  DEFAULT ((1))
GO
 

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Sysco_Concat_Program_Alias_ID'
)
ALTER TABLE Billback_Settings ADD Sysco_Concat_Program_Alias_ID [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Sysco_Concat_Program_Alias_ID]  DEFAULT ((0))
GO
 
if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'III_P_Upload_Business_Segment'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_Business_Segment [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Business_Segment]  DEFAULT ((0))
GO

-- 48374: rename the settings
if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Sysco_EDI_Filter_Negative_Invoices'
)
exec sp_rename 'Billback_Settings.Sysco_EDI_Filter_Negative_Invoices', 'Sysco_Load_Negative_Invoices_ADJ_and_PAID' , 'COLUMN'
go

if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'US_Foods_EDI_Filter_Negative_Invoices'
)
exec sp_rename 'Billback_Settings.US_Foods_EDI_Filter_Negative_Invoices', 'USF_Load_Negative_Invoices_ADJ_and_PAID' , 'COLUMN'
go

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Sysco_Load_Negative_Invoices_ADJ_and_PAID'
)
ALTER TABLE Billback_Settings ADD Sysco_Load_Negative_Invoices_ADJ_and_PAID [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_US_Foods_EDI_Load_Negative_Inv_ADJ_PAID]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USF_Load_Negative_Invoices_ADJ_and_PAID'
)
ALTER TABLE Billback_Settings ADD USF_Load_Negative_Invoices_ADJ_and_PAID [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Sysco_EDI_Load_Negative_Inv_ADJ_PAID]  DEFAULT ((0))
GO

/* D52476: Deduction closed in error - process to disable jobs for month end */
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Enable_Jobs_1_To_4'
)
ALTER TABLE Billback_Settings ADD Enable_Jobs_1_To_4 [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Enable_Jobs_1_To_4]  DEFAULT ((1))
GO


if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'Enable_Jobs_1_To_4_Updated_By'
)
ALTER TABLE Billback_Settings ADD Enable_Jobs_1_To_4_Updated_By [varchar](50) NULL
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'Enable_Jobs_1_To_4_Updated_Date'
)
ALTER TABLE Billback_Settings ADD Enable_Jobs_1_To_4_Updated_Date [datetime] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Enable_Job_5'
)
ALTER TABLE Billback_Settings ADD Enable_Job_5 [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Enable_Job_5]  DEFAULT ((1))
GO
 
if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'Enable_Jobs_5_Updated_By'
)
ALTER TABLE Billback_Settings ADD Enable_Jobs_5_Updated_By [varchar](50) NULL
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'Enable_Jobs_5_Updated_Date'
)
ALTER TABLE Billback_Settings ADD Enable_Jobs_5_Updated_Date [datetime] NULL
GO

IF NOT EXISTS 
( 
	SELECT 1
	FROM INFORMATION_SCHEMA.Columns
    WHERE Table_Name = 'Billback_Settings'
	AND Column_Name = 'Third_Party_Upload_Ship_To_Column' 
)
ALTER TABLE Billback_Settings  ADD [Third_Party_Upload_Ship_To_Column] VARCHAR(15) NOT NULL DEFAULT 'Ship_To'
GO

IF NOT EXISTS 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'III_P_Upload_Use_Closing_Method'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_Use_Closing_Method [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Use_Closing_Method]  DEFAULT ((0))
GO 

IF NOT EXISTS 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'III_Party_Load_Negative_Invoices_ADJ_and_PAID'
)
ALTER TABLE Billback_Settings ADD III_Party_Load_Negative_Invoices_ADJ_and_PAID [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_Party_Load_Negative_Invoices_ADJ_and_PAID]  DEFAULT ((0))
GO

-- 76992 Add new bb option for offset to bb delivery period on distributor rebates
IF NOT EXISTS 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'BB_Start_Offset_Days'
)
ALTER TABLE Billback_Settings ADD BB_Start_Offset_Days [int] NOT NULL CONSTRAINT [DF_Billback_Settings_BB_Start_Offset_Days]  DEFAULT ((0))
GO


IF NOT EXISTS 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'BB_End_Offset_Days'
)
ALTER TABLE Billback_Settings ADD BB_End_Offset_Days [int] NOT NULL CONSTRAINT [DF_Billback_Settings_BB_End_Offset_Days]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'EDI_Enable_Alias_Per_Client_Locations'
)
ALTER TABLE Billback_Settings ADD EDI_Enable_Alias_Per_Client_Locations [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_EDI_Enable_Alias_Per_Client_Locations]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'SYSCO_EDI_Distributor_Alias_Per_client_locations'
)
ALTER TABLE Billback_Settings ADD SYSCO_EDI_Distributor_Alias_Per_client_locations [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_SYSCO_EDI_Distributor_Alias_Per_client_locations]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'SYSCO_EDI_Item_Alias_Per_client_locations'
)
ALTER TABLE Billback_Settings ADD SYSCO_EDI_Item_Alias_Per_client_locations [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_SYSCO_EDI_Item_Alias_Per_client_locations]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USFS_EDI_Distributor_Alias_Per_client_locations'
)
ALTER TABLE Billback_Settings ADD USFS_EDI_Distributor_Alias_Per_client_locations [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_USFS_EDI_Distributor_Alias_Per_client_locations]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'USFS_EDI_Item_Alias_Per_client_locations'
)
ALTER TABLE Billback_Settings ADD USFS_EDI_Item_Alias_Per_client_locations [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_USFS_EDI_Item_Alias_Per_client_locations]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Settings'
		AND
		COLUMN_NAME = 'Reject_III_Upload_File'
)
ALTER TABLE Billback_Settings ADD Reject_III_Upload_File [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_Reject_III_Upload_File]  DEFAULT ((0))
GO

-- 85870 Clorox Rebating Holding Pen Changes
IF NOT EXISTS 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Billback_Settings'
      AND  COLUMN_NAME = 'III_P_Upload_Use_Holding_Pen'
)
ALTER TABLE Billback_Settings ADD III_P_Upload_Use_Holding_Pen [bit] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Use_Holding_Pen]  DEFAULT ((0))
GO 

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.COLUMNS
                 WHERE Table_Name = 'Billback_Settings'
                       AND Column_Name = 'III_P_Upload_Uses_BSA_Operator_ID' )
  ALTER TABLE BILLBACK_SETTINGS
    ADD III_P_Upload_Uses_BSA_Operator_ID [BIT] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Uses_BSA_Operator_ID] DEFAULT ((0))

GO 

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.COLUMNS
                 WHERE Table_Name = 'Billback_Settings'
                       AND Column_Name = 'III_P_Upload_Uses_Vendor' )
  ALTER TABLE BILLBACK_SETTINGS
    ADD III_P_Upload_Uses_Vendor [BIT] NOT NULL CONSTRAINT [DF_Billback_Settings_III_P_Upload_Uses_Vendor] DEFAULT ((0))

GO 



IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.COLUMNS
                 WHERE Table_Name = 'Billback_Settings'
                       AND Column_Name = 'Allow_III_P_Create_Zero_Dollar_Adjustment' )
  ALTER TABLE BILLBACK_SETTINGS
    ADD Allow_III_P_Create_Zero_Dollar_Adjustment [BIT] NOT NULL CONSTRAINT [DF_Billback_Settings_Allow_III_P_Create_Zero_Dollar_Adjustment] DEFAULT ((1))

GO 

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.COLUMNS
                 WHERE Table_Name = 'Billback_Settings'
                       AND Column_Name = 'Enable_Program_Picker_Product_Not_On_Program' )
  ALTER TABLE BILLBACK_SETTINGS
    ADD Enable_Program_Picker_Product_Not_On_Program [BIT] NOT NULL CONSTRAINT [DF_Billback_Settings_Enable_Program_Picker_Product_Not_On_Program] DEFAULT ((1))

GO 


-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_TXT_UPLOAD_DETAIL.SQL was last modified on 09/24/2019 10:13:28 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Billback_Txt_Upload_Detail'
)
CREATE TABLE [dbo].[Billback_Txt_Upload_Detail](
	[Billback_Txt_Upload_Detail_ID] [int] IDENTITY(1,1) NOT NULL,
	[Vendor] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Customer_Reference] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Ship_To] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Number] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Program_Number] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Vol_Qty] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Amount] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Discount_Type] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Component_Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Billback_Txt_Upload_Header_ID] [int] NULL,
	[Billback_ID] [uniqueidentifier] NULL,
	[Program_ID] [int] NULL,
	[Billback_Program_ID] [uniqueidentifier] NULL,
	[Distributor_ID] [uniqueidentifier] NULL,
	[Component_Name_ID] [int] NULL,
	[Component_ID] [int] NULL,
	[Product_ID] [uniqueidentifier] NULL,
	[Product_Type_ID] [int] NULL,
	[Billback_Product_ID] [uniqueidentifier] NULL,
	[Vendor_Master_ID] [uniqueidentifier] NULL,
	[bb_detail_id] [int] NULL,
	[bb_header_id] [int] NULL,
	[upload_id] [int] NULL,
	[user_code] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[User_ID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[upload_date] [datetime] NULL,
	[upload_status] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Invalid_Reason] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D1] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D2] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D3] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D4] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D5] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Created_Date]  DEFAULT (getdate()),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Deleted]  DEFAULT ((0)),
	[Latest] [bit] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Latest]  DEFAULT ((1)),
 CONSTRAINT [PK_Billback_Txt_Upload_Detail] PRIMARY KEY CLUSTERED 
(
	[Billback_Txt_Upload_Detail_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO

IF EXISTS 
(	SELECT name FROM sysindexes
	WHERE name = 'IDX_Billback_Txt_Upload_Detail_Latest')
DROP INDEX Billback_Txt_Upload_Detail.IDX_Billback_Txt_Upload_Detail_Latest
CREATE INDEX IDX_Billback_Txt_Upload_Detail_Latest ON Billback_Txt_Upload_Detail(Latest,Upload_ID) 


if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Partial_Invalid'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD [Partial_Invalid] [bit] NOT NULL 
CONSTRAINT [DF_Billback_Txt_Upload_Detail_Partial_Invalid] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'A_R'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD [A_R] [VARCHAR] (50) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Fiscal_Year'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD [Fiscal_Year] [VARCHAR] (50) NULL 
GO

if exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Product_Desc'
)
ALTER TABLE Billback_Txt_Upload_Detail ALTER COLUMN [Product_Desc] [varchar](100) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Debug_Upload_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Debug_Upload_ID INT
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Add_Distributor'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Add_Distributor BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Add_Distributor] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Item_UOM VARCHAR(2) 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Header_Distributor_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Header_Distributor_ID Uniqueidentifier
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Business_Segment_ID INT NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Add_Operator'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Add_Operator BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Add_Operator] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Unknown'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Unknown BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Unknown] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'File_Name'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD [File_Name] VARCHAR(100) NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Add_Payee_to_Program'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Add_Payee_to_Program BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Add_Payee_to_Program] DEFAULT (0)
GO

if exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail ALTER COLUMN item_UOM [varchar](10) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Original_item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Original_item_UOM varchar(10) NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'User_Picked_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD User_Picked_UOM INT NULL
GO



if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'User_Entered_Quantity'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD User_Entered_Quantity varchar(100) NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_TXT_UPLOAD_DETAIL_LOG.SQL was last modified on 09/24/2019 10:13:28 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Billback_Txt_Upload_Detail_Log'
)
CREATE TABLE [dbo].[Billback_Txt_Upload_Detail_Log](
	[Billback_Txt_Upload_Detail_ID] [int] NOT NULL,
	[Vendor] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Customer_Reference] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Ship_To] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Number] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Program_Number] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Vol_Qty] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Amount] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Discount_Type] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Component_Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Billback_Txt_Upload_Header_ID] [int] NULL,
	[Billback_ID] [uniqueidentifier] NULL,
	[Program_ID] [int] NULL,
	[Billback_Program_ID] [uniqueidentifier] NULL,
	[Distributor_ID] [uniqueidentifier] NULL,
	[Component_Name_ID] [int] NULL,
	[Component_ID] [int] NULL,
	[Product_ID] [uniqueidentifier] NULL,
	[Product_Type_ID] [int] NULL,
	[Billback_Product_ID] [uniqueidentifier] NULL,
	[Vendor_Master_ID] [uniqueidentifier] NULL,
	[bb_detail_id] [int] NULL,
	[bb_header_id] [int] NULL,
	[upload_id] [int] NULL, -- To show in the upload claim history page --MAX(Upload_ID) FROM BB_upload_log WHERE Upload_Type =3
	[user_code] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[User_ID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[upload_date] [datetime] NULL,
	[upload_status] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Invalid_Reason] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D1] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D2] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D3] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D4] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D5] [varchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Created_Date]  DEFAULT (getdate()),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Deleted]  DEFAULT ((0)),
	[Latest] [bit] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Latest]  DEFAULT ((1)),
	[IS_III_PU] [bit] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_IS_III_PU]  DEFAULT ((0)),
	[Operator_ID] [int] NULL,
	[Operator_Legacy_ID] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Operator_Name] [nvarchar](256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Product_Desc] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF



if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Partial_Invalid'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD [Partial_Invalid] [bit] NOT NULL 
CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Partial_Invalid] DEFAULT (0)
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Billback_Txt_Upload_Detail_Log'
	AND		COLUMN_NAME = 'Debug_Upload_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Debug_Upload_ID [int] NULL
GO


if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'A_R'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD [A_R] [VARCHAR] (50) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Fiscal_Year'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD [Fiscal_Year] [VARCHAR] (50) NULL 
GO


if exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Product_Desc'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ALTER COLUMN [Product_Desc] [varchar](100) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Add_Distributor'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Add_Distributor BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Add_Distributor] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail' AND
                        COLUMN_NAME = 'Item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail ADD Item_UOM VARCHAR(2) 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Header_Distributor_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Header_Distributor_ID Uniqueidentifier
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Add_Operator'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Add_Operator BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Add_Operator] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Business_Segment_ID INT NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Unknown'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Unknown BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Unknown] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'File_Name'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD [File_Name] VARCHAR(100) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Billback_Number'
)
BEGIN
	ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Billback_Number nvarchar(100) NULL
END
ELSE
BEGIN
	ALTER TABLE Billback_Txt_Upload_Detail_Log ALTER COLUMN Billback_Number nvarchar(100)
END
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Add_Payee_to_Program'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Add_Payee_to_Program BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Log_Add_Payee_to_Program] DEFAULT (0)
GO
if exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ALTER COLUMN item_UOM [varchar](10) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'Original_item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD Original_item_UOM varchar(10) NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'User_Picked_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD User_Picked_UOM INT NULL
GO



if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Log' AND
                        COLUMN_NAME = 'User_Entered_Quantity'
)
ALTER TABLE Billback_Txt_Upload_Detail_Log ADD User_Entered_Quantity varchar(100) NULL
GO


-------------------------------------------------------------------------------------------------------------------------------
--- BILLBACK_TXT_UPLOAD_DETAIL_QUEUE.SQL was last modified on 09/24/2019 10:13:28 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue'
)
CREATE TABLE [dbo].[Billback_Txt_Upload_Detail_Queue](
	[Billback_Txt_Upload_Detail_Queue_ID] [int] IDENTITY(1,1) NOT NULL,
	[Vendor] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Customer_Reference] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Ship_To] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Number] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Program_Number] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Vol_Qty] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item_Amount] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Discount_Type] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Component_Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Billback_Txt_Upload_Header_ID] [int] NULL,
	[Billback_ID] [uniqueidentifier] NULL,
	[Program_ID] [int] NULL,
	[Billback_Program_ID] [uniqueidentifier] NULL,
	[Distributor_ID] [uniqueidentifier] NULL,
	[Component_Name_ID] [int] NULL,
	[Component_ID] [int] NULL,
	[Product_ID] [uniqueidentifier] NULL,
	[Product_Type_ID] [int] NULL,
	[Billback_Product_ID] [uniqueidentifier] NULL,
	[Vendor_Master_ID] [uniqueidentifier] NULL,
	[bb_detail_id] [int] NULL,
	[bb_header_id] [int] NULL,
	[upload_id] [int] NULL,
	[user_code] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[User_ID] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[upload_date] [datetime] NULL,
	[upload_status] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Invalid_Reason] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D1] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D2] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D3] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D4] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BB_Creation_Err_D5] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Queue_Created_Date]  DEFAULT (getdate()),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Queue_Deleted]  DEFAULT ((0)),
	[Latest] [bit] NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Queue_Latest]  DEFAULT ((1)),
 CONSTRAINT [PK_Billback_Txt_Upload_Detail_Queue] PRIMARY KEY CLUSTERED 
(
	[Billback_Txt_Upload_Detail_Queue_ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'IS_III_PU'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD IS_III_PU BIT
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Operator_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Operator_ID INT
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Operator_Legacy_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Operator_Legacy_ID nvarchar(100)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Operator_Name'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Operator_Name nvarchar(512)
GO

IF EXISTS 
(	SELECT name FROM sysindexes
	WHERE name = 'IDX_Billback_Txt_Upload_Detail_Queue_Latest')
DROP INDEX Billback_Txt_Upload_Detail_Queue.IDX_Billback_Txt_Upload_Detail_Queue_Latest
CREATE INDEX IDX_Billback_Txt_Upload_Detail_Queue_Latest ON Billback_Txt_Upload_Detail_Queue(Latest,Upload_ID) 


if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Partial_Invalid'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD [Partial_Invalid] [bit] NOT NULL 
CONSTRAINT [DF_Billback_Txt_Upload_Detail_Queue_Partial_Invalid] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'A_R'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD [A_R] [VARCHAR] (50) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Fiscal_Year'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD [Fiscal_Year] [VARCHAR] (50) NULL 
GO

if NOT exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Product_Desc'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD [Product_Desc] [varchar](100) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Debug_Upload_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Debug_Upload_ID INT
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Add_Distributor'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Add_Distributor BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Queue_Add_Distributor] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Item_UOM VARCHAR(2) 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Header_Distributor_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Header_Distributor_ID Uniqueidentifier
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Business_Segment_ID INT NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Unknown'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Unknown BIT NOT NULL CONSTRAINT [DF_Billback_Txt_Upload_Detail_Queue_Unknown] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'File_Name'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD [File_Name] VARCHAR(100) NULL
GO

IF EXISTS 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Customer_Reference'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue 
ALTER COLUMN Customer_Reference VARCHAR(100)

if exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ALTER COLUMN item_UOM [varchar](10) NULL 
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'Original_item_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD Original_item_UOM varchar(10) NULL
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'User_Picked_UOM'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD User_Picked_UOM INT NULL
GO



if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Billback_Txt_Upload_Detail_Queue' AND
                        COLUMN_NAME = 'User_Entered_Quantity'
)
ALTER TABLE Billback_Txt_Upload_Detail_Queue ADD User_Entered_Quantity varchar(100) NULL
GO



-------------------------------------------------------------------------------------------------------------------------------
--- BSA_FOODSERVICE_ITEMS_MASTER.SQL was last modified on 01/14/2019 07:24:28 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Conagra_Foodservice_Items_Master_ID]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] DROP CONSTRAINT [DF_BSA_Foodservice_Items_Master_Conagra_Foodservice_Items_Master_ID]
END

GO


IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BSA_Foodservice_Items_Master]') AND type in (N'U'))
CREATE TABLE [dbo].[BSA_Foodservice_Items_Master](
	[BSA_Foodservice_Items_Master_ID] [uniqueidentifier] NOT NULL,
	[Item] [nvarchar](255) NULL,
	[UPC] [nvarchar](50) NULL,
	[Case_Count] [nvarchar](50) NULL,
	[Pack_Size] [nvarchar](50) NULL,
	[Pack_Size_UOM] [nvarchar](255) NULL,
	[Description] [nvarchar](255) NULL,
	[Brand] [nvarchar](255) NULL,
	[Net_Weight] [nvarchar](50) NULL,
	[Order_UoM] [nvarchar](255) NULL,
	[Inven_UoM] [nvarchar](255) NULL,
	[Q_Brand] [nvarchar](255) NULL,
	[Q_Brand_Desc] [nvarchar](255) NULL,
	[Type_Code] [nvarchar](50) NULL,
	[Type_Code_Desc] [nvarchar](255) NULL,
	[Type_Group] [nvarchar](50) NULL,
	[Type_Group_Desc] [nvarchar](255) NULL,
	[Style] [nvarchar](50) NULL,
	[Deleted] [bit] NOT NULL,
	[Shelf_Life] [nvarchar](50) NULL,
	[Gross_Weight] [nvarchar](50) NULL,
	[Pallet_Weight] [nvarchar](50) NULL,
	[Length] [nvarchar](50) NULL,
	[Width] [nvarchar](50) NULL,
	[Height] [nvarchar](50) NULL,
	[Cases_Layer] [nvarchar](50) NULL,
	[Layers_Pallet] [nvarchar](50) NULL,
	[Cases_Pallet] [nvarchar](50) NULL,
	[Case_Cube] [nvarchar](50) NULL,
	[Prime_LOB] [nvarchar](50) NULL,
	[Catch_Weight] [nvarchar](50) NULL,
	[Make_Buy_Code] [nvarchar](50) NULL,
	[Prime_Plant] [nvarchar](50) NULL,
	[Plant_Name] [nvarchar](50) NULL,
	[Multi_Mfg] [nvarchar](50) NULL,
	[Curr_Cost] [nvarchar](50) NULL,
	[Mktg_Cost] [nvarchar](50) NULL,
	[Chep_Ind] [nvarchar](50) NULL,
	[Category_ID] [uniqueidentifier] NULL,
	[Type_Code_Desc_ID] [uniqueidentifier] NULL,
	[Type_Group_Desc_ID] [uniqueidentifier] NULL,
	[Brand_ID] [uniqueidentifier] NULL,
	[Active_Code] [char](1) NULL,
	[Style_Name] [nvarchar](50) NULL,
	[Sales_Group] [char](2) NULL,
	[Sales_Country] [char](2) NULL,
	[Item_Class] [char](1) NULL,
	[Line_Of_Business_ID] [uniqueidentifier] NULL,
	[Q_Brand_ID] [uniqueidentifier] NULL,
	[Q_Brand_Desc_ID] [uniqueidentifier] NULL,
	[Created_Date] [datetime] NULL,
	[Pack_Qty] [char](6) NULL,
	[Fcast_Sub_Group] [char](3) NULL,
	[Fcast_Sub_Group_Desc] [char](20) NULL,
	[Inventory_UM] [char](2) NULL,
	[Sales_Group_Desc] [char](20) NULL,
	[Container_Code] [char](14) NULL,
	[Temp_Class] [char](20) NULL,
	[CS_Curr_Cost] [float] NULL,
	[Actual_Curr_Cost] [nvarchar](50) NULL,
	[Updated_Date] [datetime] NULL,
	[Business_Segment_ID] [int] NULL,
	[Product_Heirarchy_1_ID] [uniqueidentifier] NULL,
	[Product_Heirarchy_3_ID] [uniqueidentifier] NULL,
	[Sales_Org_ID] [nvarchar](50) NULL,
	[CASE_UPC] [nvarchar](50) NULL,
	[Signature_SKU_Indicator] [nvarchar](50) NULL,
	[Product_Heirarchy_5_ID] [uniqueidentifier] NULL,
	[Product_Heirarchy_6_ID] [uniqueidentifier] NULL,
	[Item_Class_ID] [uniqueidentifier] NULL,
	[Sub_Brand_ID] [uniqueidentifier] NULL,
	[Class_Code_ID] [int] NULL,
	[Product_Hierarchy_ID] [uniqueidentifier] NULL,
	[FOB_Frt_Cost] [float] NULL,
	[FOB_Warhs] [float] NULL,
	[DEL_Frt_Cost] [float] NULL,
	[DEL_Del_Cost] [float] NULL,
	[DEL_Cust_Pickup] [float] NULL,
	[DEL_Var_Warhs] [float] NULL,
	[Var_Man_Cost] [float] NULL,
	[FX_Man_Cost] [float] NULL,
	[Prod_Grp] [varchar](50) NULL,
	[BSA_Product_Group_ID] [uniqueidentifier] NULL,
	[Case_Equivalent] [nvarchar](50) NULL,
	[Pkg_Cost] [decimal](18, 4) NULL,
	[Mfg_OH_Cost] [decimal](18, 4) NULL,
	[Fixed_Mfg_OH] [decimal](18, 4) NULL,
	[Purchase_Cost] [decimal](18, 4) NULL,
	[Fixed_Direct_Labor] [decimal](18, 4) NULL,
	[Total_Direct_Labor] [decimal](18, 4) NULL,
	[Total_Var_Mfg_Cost] [decimal](18, 4) NULL,
	[Specialty_Product] [bit] NOT NULL,
	[Prod_Var_A_ID] [uniqueidentifier] NULL,
	[Prod_Var_B_ID] [uniqueidentifier] NULL,
	[Prod_Var_C_ID] [uniqueidentifier] NULL,
	[Prod_Var_D_ID] [uniqueidentifier] NULL,
	[Prod_Var_E_ID] [uniqueidentifier] NULL,
	[Prod_Var_F_ID] [uniqueidentifier] NULL,
	[Prod_Var_G_ID] [uniqueidentifier] NULL,
	[Prod_Var_H_ID] [uniqueidentifier] NULL,
	[Prod_Var_J_ID] [uniqueidentifier] NULL,
	[Prod_Var_K_ID] [uniqueidentifier] NULL,
	[Prod_Var_M_ID] [uniqueidentifier] NULL,
	[Case_Count_ID] [uniqueidentifier] NULL,
	[EA_Conversion] [decimal](18, 4) NULL,
	[Class_Code_UUID] [uniqueidentifier] NULL,
	[Division] [varchar](2) NULL,	
	[Distribution_channel] [varchar](2) NULL,
	[GTIN] [varchar](30) NULL,
	[Is_Divested] [bit] NOT NULL,
	[Manually_Updated_Date] [datetime] NULL,
	[Manually_Updated_By] [nvarchar](100) NULL,
	[Is_Item_Group] [bit] NULL,
	[Alt_Description] [nvarchar](255) NULL,
 CONSTRAINT [PK_BSA_Foodservice_Items_Master_1] PRIMARY KEY CLUSTERED 
(
	[BSA_Foodservice_Items_Master_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
GO

SET ANSI_PADDING OFF
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_BSA_Foodservice_Items_Master_ID]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_BSA_Foodservice_Items_Master_ID]  DEFAULT (newid()) FOR [BSA_Foodservice_Items_Master_ID]
GO

IF  NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Deleted_1]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_Deleted_1]  DEFAULT (0) FOR [Deleted]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Created_Date_1]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_Created_Date_1]  DEFAULT (getdate()) FOR [Created_Date]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Business_Segment_ID]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_Business_Segment_ID]  DEFAULT (1) FOR [Business_Segment_ID]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Specialty_Product]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_Specialty_Product]  DEFAULT (0) FOR [Specialty_Product]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master]  DEFAULT ((0)) FOR [Is_Divested]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Manually_Updated_Date]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_Manually_Updated_Date]  DEFAULT (NULL) FOR [Manually_Updated_Date]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Manually_Updated_By]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_Manually_Updated_By]  DEFAULT (NULL) FOR [Manually_Updated_By]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BSA_Foodservice_Items_Master_Is_Item_Group]') AND type = 'D')
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD  CONSTRAINT [DF_BSA_Foodservice_Items_Master_Is_Item_Group]  DEFAULT ((0)) FOR [Is_Item_Group]
GO

IF NOT EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='BSA_Foodservice_Items_Master'
AND C.Name='GTIN')

BEGIN
ALTER TABLE [dbo].[BSA_Foodservice_Items_Master] ADD 
	[GTIN] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
END

  --- D30948:Master data edit page START 
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Manually_Updated_Date'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Manually_Updated_Date] [datetime] NULL CONSTRAINT [DF_BSA_Foodservice_Items_Master_Manually_Updated_Date] DEFAULT NULL
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Manually_Updated_By'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Manually_Updated_By] NVARCHAR(100) NULL CONSTRAINT [DF_BSA_Foodservice_Items_Master_Manually_Updated_By] DEFAULT NULL
GO
  --- D30948:Master data edit page END  
  
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Is_Item_Group'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Is_Item_Group] [BIT] NULL CONSTRAINT [DF_BSA_Foodservice_Items_Master_Is_Item_Group] DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Alt_Description'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Alt_Description] NVARCHAR(255) NULL
GO


IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Length'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ALTER COLUMN [Length] varchar(100)
GO

IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Width'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ALTER COLUMN [Width] varchar(100)
GO

IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Height'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ALTER COLUMN [Height] varchar(100)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'CASE_UPC'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [CASE_UPC] [nvarchar](50) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Profitability_Exclude'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Profitability_Exclude] [varchar](1) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Distributor_Owner_ID'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Distributor_Owner_ID] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Distributor_Owner_Name'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Distributor_Owner_Name] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Operator_Owner_ID'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Operator_Owner_ID] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Operator_Owner_Name'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Operator_Owner_Name] [varchar](255) NULL
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Profit_Center'
)
ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Profit_Center] [varchar](5) NULL
GO


--WR: 77460: Create Tyson product master
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Prod_Var_I_ID'
)
BEGIN
	ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Prod_Var_I_ID] [uniqueidentifier] NULL
END
GO

--WR: 77460: Create Tyson product master
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Prod_Var_L_ID'
)
BEGIN
	ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Prod_Var_L_ID] [uniqueidentifier] NULL
END
GO



--D82428 Modify 100 Product file to add Each and Sleeve UOM
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Foodservice_Items_Master'
	AND		COLUMN_NAME = 'Sleeves_per_case'
)
BEGIN
	ALTER TABLE dbo.BSA_Foodservice_Items_Master ADD [Sleeves_per_case] [nvarchar](255) NULL
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- BSA_OPERATOR.SQL was last modified on 11/11/2019 02:16:44 PM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Operator'
		AND
		COLUMN_NAME = 'Is_PG'
)
ALTER TABLE BSA_Operator ADD Is_PG [Bit] NOT NULL CONSTRAINT [DF_BSA_Operator_Is_PG]  DEFAULT (0)

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Q_Brand_Legacy' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD [Q_Brand_Legacy] varchar(50) NULL
END

GO


-- D45514 Claim rates report - product number from alias tool
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'BSA_Operator'
	AND		COLUMN_NAME = 'Primary_BB_Claim_Source_XREF_ID'
)
ALTER TABLE dbo.BSA_Operator ADD [Primary_BB_Claim_Source_XREF_ID] INT NULL
GO


IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Contact_Address' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD [Contact_Address] varchar(255) NULL
END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Contact_City' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD [Contact_City] varchar(255) NULL
END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Contact_State' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD [Contact_State] varchar(255) NULL
END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Contact_Zip' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD [Contact_Zip] varchar(255) NULL
END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Contact_Email' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD [Contact_Email] varchar(255) NULL
END
GO

-- D82367 

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Operator_GPO_ID' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD Operator_GPO_ID int NULL
END

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Tier' )
BEGIN
  ALTER TABLE BSA_Operator
    ADD [Tier] int NULL
END

IF EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'BSA_Operator_ID_Text' )
BEGIN
  ALTER TABLE BSA_Operator
    ALTER COLUMN BSA_Operator_ID_Text NVARCHAR(50)
END

IF EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Operator_Number_Of_Locations' )
BEGIN
  ALTER TABLE BSA_Operator
    ALTER COLUMN Operator_Number_Of_Locations NVARCHAR(255)
END

--WR 90527 - Adding to avoid "Invalid column name 'Operator_Phone'." event error 
IF EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'BSA_Operator'
                       AND Column_Name = 'Operator_Phone' )
BEGIN
  ALTER TABLE BSA_Operator
    ALTER COLUMN Operator_Phone NVARCHAR(255)
END
ELSE
BEGIN
	ALTER TABLE BSA_Operator ADD Operator_Phone NVARCHAR(255) NULL
END


if not exists 
(
       SELECT *
       FROM   INFORMATION_SCHEMA.COLUMNS
       WHERE  TABLE_NAME = 'BSA_Operator'
       AND           COLUMN_NAME = 'Operator_DBA_Code' 
 )
ALTER TABLE BSA_Operator ADD Operator_DBA_Code VARCHAR(255) NULL
GO

if not exists 
(
       SELECT *
       FROM   INFORMATION_SCHEMA.COLUMNS
       WHERE  TABLE_NAME = 'BSA_Operator'
       AND           COLUMN_NAME = 'Q_Brand_Legacy_Code' 
 )
ALTER TABLE BSA_Operator ADD Q_Brand_Legacy_Code VARCHAR(255) NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- CF_DEMAND_PLAN_STANDARD.SQL was last modified on 07/09/2019 02:06:26 PM ---
-------------------------------------------------------------------------------------------------------------------------------
-- 77432 - Demand Planning interface
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CF_Demand_Plan_Standard]') AND type in (N'U'))
	DROP TABLE [dbo].[CF_Demand_Plan_Standard]
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[CF_Demand_Plan_Standard](
	[Customer] [varchar](100) NULL,
	[Item] [varchar](100) NULL,
	[Start_Date] [varchar](100) NULL,
	[Quantity] [varchar](100) NULL
) ON [PRIMARY]
GO

-------------------------------------------------------------------------------------------------------------------------------
--- CF_PG_MEMBER_UPLOAD.SQL was last modified on 09/17/2019 08:28:04 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT NAME,* FROM Sys.Objects WHERE Name = 'CF_PG_Member_Upload' AND TYPE = 'U')

CREATE TABLE [dbo].[CF_PG_Member_Upload](
    [CF_PG_Member_Upload_ID] INT IDENTITY(1,1) NOT NULL,
	[PG_Category_ID] NVARCHAR(255) ,
	[PG_Type_ID] NVARCHAR(255) ,
	[Group_ID] NVARCHAR(255) ,
	[PG_Category_Definition_ID] NVARCHAR(255) ,
	[PG_Category_Code] NVARCHAR(255) ,
	[PG_Category_Name] NVARCHAR(255) ,
	[Group_Number] NVARCHAR(255) ,
	[Group_Name] NVARCHAR(255) ,
	[Inclusion_Exclusion] NVARCHAR(255) ,
	[PG_Effective_Start_Date] NVARCHAR(255) ,
	[PG_Effective_End_Date] NVARCHAR(255),
	[Flag] BIT DEFAULT(0)
) ON [PRIMARY]


-------------------------------------------------------------------------------------------------------------------------------
--- COMMODITIES.SQL was last modified on 10/07/2019 01:31:58 PM ---
-------------------------------------------------------------------------------------------------------------------------------

/****** Object:  Table [dbo].[Commodities]    Script Date: 10/26/2016 12:38:53 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities'
)
BEGIN
CREATE TABLE [dbo].[Commodities](
	[Commodities_ID] [int] IDENTITY(1,1) NOT NULL,
	[Comm_Symbol] [nvarchar](50) NULL,
	[Comm_Month_Year] [nvarchar](50) NULL,
	[Exchange_Detail_Abrev] [nvarchar](50) NULL,
	[Comm_Last] [float] NULL,
	[Comm_Change] [nvarchar](50) NULL,
	[Comm_Open] [nvarchar](50) NULL,
	[Comm_High] [nvarchar](50) NULL,
	[Comm_Low] [nvarchar](50) NULL,
	[Comm_Previous] [float] NULL,
	[Comm_Datetime] [datetime] NULL,
	[Comm_Update_Date] [datetime] NULL,
	[Comm_Flag] [bit] NOT NULL,
	[Category_ID] [int] NULL,
	[Sub_Category_ID] [int] NULL,
 CONSTRAINT [PK_Commodities] PRIMARY KEY CLUSTERED 
(
	[Commodities_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]


ALTER TABLE [dbo].[Commodities] ADD  CONSTRAINT [DF_Commodities_Comm_Update_Date]  DEFAULT (getdate()) FOR [Comm_Update_Date]

ALTER TABLE [dbo].[Commodities] ADD  CONSTRAINT [DF_Commodities_Comm_Flag]  DEFAULT (0) FOR [Comm_Flag]

END

GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities'
	AND		COLUMN_NAME = 'Created_Date'
)
ALTER TABLE Commodities ADD [Created_Date]  [datetime] NOT NULL CONSTRAINT [DF_Commodities_Created_Date]  DEFAULT (getdate())

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities'
	AND		COLUMN_NAME = 'Commodities_Symbol_ID'
)
ALTER TABLE Commodities ADD [Commodities_Symbol_ID]  INT NOT NULL

ALTER TABLE Commodities ALTER COLUMN [Comm_Last] DECIMAL(12,4) NULL
ALTER TABLE Commodities ALTER COLUMN [Comm_Change] DECIMAL(12,4) NULL
ALTER TABLE Commodities ALTER COLUMN [Comm_Open] DECIMAL(12,4) NULL
ALTER TABLE Commodities ALTER COLUMN [Comm_High] DECIMAL(12,4) NULL
ALTER TABLE Commodities ALTER COLUMN [Comm_Low] DECIMAL(12,4) NULL
ALTER TABLE Commodities ALTER COLUMN [Comm_Previous]DECIMAL(12,4) NULL

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities'
	AND		COLUMN_NAME = 'Commodities_Report_Log_ID'
)
ALTER TABLE Commodities ADD [Commodities_Report_Log_ID] [int] NULL




-------------------------------------------------------------------------------------------------------------------------------
--- COMMODITIES_CATEGORY.SQL was last modified on 02/25/2019 08:24:27 AM ---
-------------------------------------------------------------------------------------------------------------------------------

/****** Object:  Table [dbo].[Commodities_Category]    Script Date: 10/26/2016 8:27:32 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Category'
)
BEGIN
	CREATE TABLE [dbo].[Commodities_Category](
		[Category_ID] [int] NOT NULL,
		[Category_Code] [nvarchar](10) NULL,
		[Category_Name] [nvarchar](255) NULL,
	 CONSTRAINT [PK_Commodities_Category] PRIMARY KEY CLUSTERED 
	(
		[Category_ID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]
END
GO
IF (select columnproperty(object_id('Commodities_Category'),'Category_ID','IsIdentity')) = 0
BEGIN
	IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'PK_Commodities_Category') AND type in (N'PK'))
	ALTER TABLE Commodities_Category DROP CONSTRAINT PK_Commodities_Category

	alter table [dbo].[Commodities_Category] add colx int identity(1,1)
	alter table Commodities_Category drop column Category_ID
	exec sp_rename 'Commodities_Category.colx', 'Category_ID', 'column'

	IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'PK_Commodities_Category') AND type in (N'PK'))
	ALTER TABLE Commodities_Category 
	   ADD  CONSTRAINT [PK_Commodities_Category] PRIMARY KEY CLUSTERED 
	(
		[Category_ID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]

END


-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Category'
	AND		COLUMN_NAME = 'Created_Date'
)
ALTER TABLE Commodities_Category ADD [Created_Date]  [datetime] NOT NULL CONSTRAINT [DF_Commodities_Category_Created_Date]  DEFAULT (getdate())
GO

 IF (NOT EXISTS(SELECT * FROM Commodities_Category WHERE Category_Code = 'Pork'))
    BEGIN
		Insert into Commodities_Category (Category_Code,Category_Name)
		values ('Pork','Pork')
	END

IF (NOT EXISTS(SELECT * FROM Commodities_Category WHERE Category_Code = 'Poultry'))
    BEGIN
		Insert into Commodities_Category (Category_Code,Category_Name)
		values ('Poultry','Poultry')
	END
IF (NOT EXISTS(SELECT * FROM Commodities_Category WHERE Category_Code = 'Beef'))
    BEGIN
		Insert into Commodities_Category (Category_Code,Category_Name)
		values ('Beef','Beef')
	END
IF (NOT EXISTS(SELECT * FROM Commodities_Category WHERE Category_Code = 'By-Product'))
    BEGIN
		Insert into Commodities_Category (Category_Code,Category_Name)
		values ('By-Product','By-Product')
	END


-------------------------------------------------------------------------------------------------------------------------------
--- COMMODITIES_EXCHANGE_DETAIL.SQL was last modified on 02/25/2019 08:24:27 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Commodities_Exchange_Detail]    Script Date: 10/25/2016 2:07:42 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Exchange_Detail'
)
BEGIN
CREATE TABLE [dbo].[Commodities_Exchange_Detail](
	[Exchange_Detail_ID] [int] IDENTITY(1,1) NOT NULL,
	[Exchange_Detail_Abrev] [nvarchar](50) NOT NULL,
	[Exchange_Detail_Name] [nvarchar](255) NULL,
	[Commodity_Exchange_Type_ID] [int] NULL,
 CONSTRAINT [PK_Commodities_Exchange_Detail] PRIMARY KEY CLUSTERED 
(
	[Exchange_Detail_Abrev] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

END

GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Exchange_Detail'
	AND		COLUMN_NAME = 'Web_Service_URL'
)
ALTER TABLE Commodities_Exchange_Detail ADD [Web_Service_URL] varchar(150) NULL
GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Exchange_Detail'
	AND		COLUMN_NAME = 'Active'
)
ALTER TABLE Commodities_Exchange_Detail ADD [Active] [BIT] NOT NULL CONSTRAINT [DF_Commodities_Exchange_Detail_Active]  DEFAULT (1)
GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Exchange_Detail'
	AND		COLUMN_NAME = 'Category_ID'
)
ALTER TABLE Commodities_Exchange_Detail ADD [Category_ID] INT NOT NULL CONSTRAINT [DF_Commodities_Exchange_Detail_Category_ID]  DEFAULT (0)
GO

 IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'LM_PK602'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('LM_PK602','National Daily Pork Report - Negotiated Sales','https://mpr.datamart.ams.usda.gov/ws/report/v1/Hogs/LM_PK602', 1, 1)
	END

 IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'LM_XB401'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('LM_XB401','National Daily Boneless Cow Beef & Beef Trimmings - Negotiated Sales - Afternoon','https://mpr.datamart.ams.usda.gov/ws/report/v1/Hogs/LM_XB401', 1, 3)
	END
	UPDATE Commodities_Exchange_Detail set Category_Id = 3 WHERE Exchange_Detail_Abrev = 'LM_XB401'
	/*
				UPDATE c SET Category_Id = 3  from Commodities_Symbol cs
				INNER JOIN Commodities C ON
					C.Commodities_Symbol_ID = cs.Commodities_Symbol_ID
				left JOIN Commodities_Category CC ON
					CC.Category_ID = C.Category_ID
				where CS.Exchange_Detail_ID = 2

				UPDATE Commodities_Sub_Category SET Category_Id = 3 WHERE Sub_Category_Id in(25,26)

	*/
 IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'LM_HG206'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('LM_HG206','Iowa/Minnesota Daily Direct Hogs - Afternoon','https://mpr.datamart.ams.usda.gov/ws/report/v1/Hogs/LM_HG206', 1, 1)
	END

 IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'LM_PK610'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('LM_PK610','National Weekly Pork Report - Negotiated Sales','https://mpr.datamart.ams.usda.gov/ws/report/v1/Hogs/LM_PK610', 1, 1)
	END

IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'JK_PY001'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('JK_PY001','Daily Southern States Broiler/Fryer Parts','http://www.ams.usda.gov/mnreports/jk_py001.txt', 1, 2)
	END
IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = ''))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('NW_PY029','Daily National Young Turkey Parts','https://www.ams.usda.gov/mnreports/nw_py029.txt', 1, 2)
	END
 IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'LM_XB403'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('LM_XB403','National Daily Boxed Beef Cutout & Boxed Beef Cuts - Negotiated Sales - Afternoon','https://mpr.datamart.ams.usda.gov/ws/report/v1/Hogs/LM_XB403', 1, 3)
	END  
IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'LM_HG231'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('LM_HG231','Iowa/Minnesota Daily Direct Prior Day Sow and Boar - Purchased Swine','https://mpr.datamart.ams.usda.gov/ws/report/v1/Hogs/lm_hg231', 1, 1)
	END
IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'NW_LS440'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('NW_LS440','USDA BY-PRODUCT PRICE REPORT  -  FOB CENTRAL U.S. BASIS','https://www.ams.usda.gov/mnreports/nw_ls440.txt', 1, 4)
	END
IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = 'NW_LS442'))
    BEGIN
		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
		values ('NW_LS442','USDA TALLOW AND PROTEIN REPORT - FOB CENTRAL U.S.','https://www.ams.usda.gov/mnreports/nw_ls442.txt', 1, 4)
	END
--IF (NOT EXISTS(SELECT * FROM Commodities_Exchange_Detail WHERE Exchange_Detail_Abrev = ''))
--    BEGIN
--		Insert into Commodities_Exchange_Detail (Exchange_Detail_Abrev,Exchange_Detail_Name,Web_Service_URL,Commodity_Exchange_Type_Id, Category_Id)
--		values ('','','', 1, 1)
--	END
-------------------------------------------------------------------------------------------------------------------------------
--- COMMODITIES_SUB_CATEGORY.SQL was last modified on 10/07/2019 01:31:58 PM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Commodities_Sub_Category]    Script Date: 10/26/2016 12:35:13 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Sub_Category'
)
BEGIN
	CREATE TABLE [dbo].[Commodities_Sub_Category](
		[Sub_Category_ID] [int] identity(1,1) NOT NULL,
		[Sub_Category_Code] [nvarchar](10) NULL,
		[Sub_Category_Name] [nvarchar](255) NULL,
		[Category_ID] [int] NULL,
	 CONSTRAINT [PK_Commodities_Sub_Category] PRIMARY KEY CLUSTERED 
	(
		[Sub_Category_ID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]
END

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Commodities_Sub_Category'
	AND		COLUMN_NAME = 'Created_Date'
)
ALTER TABLE Commodities_Sub_Category ADD [Created_Date]  [datetime] NOT NULL CONSTRAINT [DF_Commodities_Sub_Category_Created_Date]  DEFAULT (getdate())

GO




-------------------------------------------------------------------------------------------------------------------------------
--- CONTRACT_MAIN_AUX_DATA.SQL was last modified on 07/22/2019 09:01:03 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/*  *** Market_Price_Approved  *** */
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Market_Price_Approved'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD 	[Market_Price_Approved] [bit] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Market_Price_Approved]  DEFAULT ((0))
END
GO
/*  *** Market_Price_Approved_By  *** */
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Market_Price_Approved_By'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Market_Price_Approved_By] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
END
GO
/*  *** Market_Price_Approved_Date  *** */
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Market_Price_Approved_Date'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Market_Price_Approved_Date] [datetime] NULL
END
GO
/*  *** Require_Market_Price_Approval  *** */
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Market_Price_Approval_Variance'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD 	[Market_Price_Approval_Variance] [decimal](18, 2) NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Require_Market_Price_Approval]  DEFAULT ((0))
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Price_List_ID'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD 	[Price_List_ID] [varchar](7) NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'PriceBracket_Update'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [PriceBracket_Update] [bit] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_PriceBracket_Update]  DEFAULT ((0)) 
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'PriceBracket_Update_Date'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [PriceBracket_Update_Date] [datetime] NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'PriceBracket_Update_By'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [PriceBracket_Update_By] [varchar](50) NULL
END
GO

/*  *** LB_Calc_Complete  *** */
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'LB_Calc_Complete'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD 	[LB_Calc_Complete] [bit] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_LB_Calc_Complete]  DEFAULT ((0))
END
GO

/*D35145 Volume Applicator - Disable Auto Volume*/
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Exclude_From_Auto_Volume_Updates'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Exclude_From_Auto_Volume_Updates] [bit] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Exclude_From_Auto_Volume_Updates]  DEFAULT ((0))
END
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Alternate_Payment_Recipient'
)
ALTER TABLE Contract_Main_Aux_Data ADD [Alternate_Payment_Recipient] [int] NULL
GO

/*
	38586: Simplot ENH - Fuel Surcharge Expiring.   CF WORK / Anand Rao / 30-Jul-2013
	-- Send Summarized weekly notification of fuel surcharge expiring
*/

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Fuel_Surcharge_ON'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Fuel_Surcharge_ON] [bit] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Fuel_Surcharge_ON]  DEFAULT ((0))
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Fuel_Surcharge_Amount'
)
ALTER TABLE Contract_Main_Aux_Data ADD [Fuel_Surcharge_Amount] [Float] NULL
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Fuel_Surcharge_Expiration_Date'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Fuel_Surcharge_Expiration_Date] [datetime] NULL
END
GO
-- D38942 :: Program Blackout Period on Frontend
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Program_Start_Zero'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Program_Start_Zero] [tinyint] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Program_Start_Zero] DEFAULT ((0))
END
GO
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Program_Future_Zero'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Program_Future_Zero] [tinyint] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Program_Future_Zero] DEFAULT ((0))
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
	AND		COLUMN_NAME = 'Program_Most_Favored_Nation'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Program_Most_Favored_Nation] [bit] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Program_Most_Favored_Nation]  DEFAULT ((0))
END
GO
--D50326 :: Tru-up to Actuals Button in Program Start
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Set_Committed_Equal_Actual'
)
ALTER TABLE Contract_Main_Aux_Data ADD [Set_Committed_Equal_Actual] [bit] NOT NULL CONSTRAINT [DF_Contract_Main_Aux_Data_Set_Committed_Equal_Actual] DEFAULT (0)
GO
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Set_Committed_Actual_Updated_Date'
)
ALTER TABLE Contract_Main_Aux_Data ADD [Set_Committed_Actual_Updated_Date] [DATETIME] NULL 
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Set_Committed_Actual_Updated_By'
)
ALTER TABLE Contract_Main_Aux_Data ADD [Set_Committed_Actual_Updated_By] [VARCHAR](50) NULL
GO
--D50326 :: Tru-up to Actuals Button in Program END
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
	AND		COLUMN_NAME = 'Paid_Amount'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Paid_Amount] [decimal](20, 4) NULL
END
GO

--D64860 :: Update Segments selection on programs
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
	AND		COLUMN_NAME = 'Business_Segment_IDs'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Business_Segment_IDs] [VARCHAR](50) NULL
END
GO

--D72377 - Program Accrual
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Total_Accrued_Dollars'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD 	[Total_Accrued_Dollars] [decimal](18, 2) NULL
END
GO

--D72377 - Program Accrual
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Total_Spent_Dollars'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD 	[Total_Spent_Dollars] [decimal](18, 2) NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
	AND COLUMN_NAME = 'Product_Group_Members_File_Path'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Product_Group_Members_File_Path] [varchar](500) NULL
END
GO

-- 76539 Volume centric price list & TPA
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Volume_Automation_Updated'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD 	[Volume_Automation_Updated] [datetime] NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Version_Actual_Span'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Version_Actual_Span] [int] NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Version_Togo_Span'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Version_Togo_Span] [int] NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Override_Price_List_Id'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Override_Price_List_Id] [uniqueidentifier] NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'Gpo_Price_List_Id'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [Gpo_Price_List_Id] [uniqueidentifier] NULL
END
GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data'
		AND
		COLUMN_NAME = 'NonGpo_Price_List_Id'
)
BEGIN
	ALTER TABLE [dbo].[Contract_Main_Aux_Data] ADD [NonGpo_Price_List_Id] [uniqueidentifier] NULL
END
GO

---87836 - Event error when saving fixed price page: Changing datatype on Freight_Contract_Start_Date and Freight_Contract_End_Date from smalldatetime to datetime to prevent 9999-12-31 00:00:00.000 date error 
IF EXISTS 
(
	SELECT	* 
	FROM	INFORMATION_SCHEMA.COLUMNS 
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data' AND COLUMN_NAME = 'Freight_Contract_Start_Date'
)
	ALTER TABLE Contract_Main_Aux_Data ALTER COLUMN Freight_Contract_Start_Date datetime
GO

IF EXISTS 
(
	SELECT	* 
	FROM	INFORMATION_SCHEMA.COLUMNS 
	WHERE	TABLE_NAME = 'Contract_Main_Aux_Data' AND COLUMN_NAME = 'Freight_Contract_End_Date'
)
	ALTER TABLE Contract_Main_Aux_Data ALTER COLUMN Freight_Contract_End_Date datetime
GO
-------------------------------------------------------------------------------------------------------------------------------
--- CONTRACT_OPERATORS.SQL was last modified on 05/28/2019 08:04:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.Columns
                 WHERE table_name = 'Contract_Operators'
                       AND column_name = 'Captured_From_Group' )
  ALTER TABLE Contract_Operators
    ADD Captured_From_Group BIT NOT NULL CONSTRAINT [DF_Contract_Operators_Captured_From_Group] DEFAULT (0)

Go

IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.Columns
                 WHERE table_name = 'Contract_Operators'
                       AND column_name = 'Is_Group' )
  ALTER TABLE Contract_Operators
    ADD Is_Group BIT NOT NULL CONSTRAINT [DF_Contract_Operators_Is_Group] DEFAULT (0)

Go 

IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.Columns
                 WHERE table_name = 'Contract_Operators'
                       AND column_name = 'Operator_Group_ID' )
  ALTER TABLE Contract_Operators
    ADD Operator_Group_ID uniqueidentifier NULL

Go 

IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.Columns
                 WHERE table_name = 'Contract_Operators'
                       AND column_name = 'Added_From_BB' )
  ALTER TABLE Contract_Operators
    ADD Added_From_BB BIT NOT NULL CONSTRAINT [DF_Contract_Operators_Added_From_BB] DEFAULT (0)

Go 

IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.Columns
                 WHERE table_name = 'Contract_Operators'
                       AND column_name = 'Operator_Group_ID_Int' )
  ALTER TABLE Contract_Operators
    ADD Operator_Group_ID_Int int NULL

Go
IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.Columns
                 WHERE table_name = 'Contract_Operators'
                       AND column_name = 'Group_Level_Desc' )
  ALTER TABLE Contract_Operators
    ADD Group_Level_Desc Varchar(100) NULL

Go
IF NOT EXISTS ( SELECT 1
                  FROM Information_scHema.Columns
                 WHERE table_name = 'Contract_Operators'
                       AND column_name = 'Group_Level_ID' )
  ALTER TABLE Contract_Operators
    ADD Group_Level_ID INT NULL
Go

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[BSA_Operator]') AND name = N'IX_BSA_Operator_Operator_GPO_ID')
BEGIN
CREATE NONCLUSTERED INDEX [IX_BSA_Operator_Operator_GPO_ID] ON [dbo].[BSA_Operator] 
(
       [Operator_GPO_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
END
GO


IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Contract_Operators]') AND name = N'IDX_Contract_Operators_NC2')
BEGIN
CREATE NONCLUSTERED INDEX [IDX_Contract_Operators_NC2] ON [dbo].[Contract_Operators] 
(
       [Contract_Main_ID] ASC, [Deleted] ASC, [Is_Group] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
END
GO

-------------------------------------------------------------------------------------------------------------------------------
--- CONTRACT_PRODUCTS.SQL was last modified on 04/17/2019 07:10:25 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Contract_Products]    Script Date: 08/27/2010 15:04:29 ******/
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Contract_Products]') AND type in (N'U'))
BEGIN

	CREATE TABLE [dbo].[Contract_Products](
		[Contract_Products_ID] [int] IDENTITY(1,1) NOT NULL,
		[BSA_Foodservice_Items_Master_ID] [uniqueidentifier] NULL,
		[Product_UPC] [nvarchar](50) NULL,
		[Contract_Main_ID] [int] NULL,
		[Discount_Value] [nvarchar](50) NULL,
		[Deleted] [bit] NOT NULL CONSTRAINT [DF_Contract_Products_Deleted_1]  DEFAULT (0),
		[Pricing_Rule] [int] NULL,
		[Creator_ID] [nvarchar](50) NULL,
		[Editor_ID] [nvarchar](50) NULL,
		[Date_Created] [datetime] NULL CONSTRAINT [DF_Contract_Products_Date_Created]  DEFAULT (getdate()),
		[Product_Type_ID] [int] NULL,
		[Product_Process_Flag] [int] NULL CONSTRAINT [DF_Contract_Products_Product_Process_Flag]  DEFAULT (0),
		[Product_Group_Level_ID] [int] NOT NULL CONSTRAINT [DF_Contract_Products_Product_Group_Level_ID]  DEFAULT (0),
		[Product_Group_ID] [nvarchar](50) NULL,
		[Pricing_Level_ID] [int] NOT NULL CONSTRAINT [DF_Pricing_Level_ID]  DEFAULT (1),
		[Is_Group] [bit] NOT NULL DEFAULT (0),
		[Dynamic_Static_Groups] [bit] NOT NULL DEFAULT (0),
		[Discounted_Item] [bit] NOT NULL CONSTRAINT [DF_Contact_Products_Discounted_Item]  DEFAULT (1),
		[Captured_From_Group] [bit] NOT NULL DEFAULT (0),
		[products_not_captured_flag] [bit] NOT NULL CONSTRAINT [DF__Contract_Products_products_not_captured_flag]  DEFAULT (0),
		[EZButton_On_Default] [bit] NOT NULL CONSTRAINT [DF_contract_products_EZButton_On_Default]  DEFAULT (0),
		[Include_In_Margin] [bit] NOT NULL CONSTRAINT [DF_Contract_Products_Include_In_Margin]  DEFAULT ((1)),
		[EZ_Contract_Id] [int] NULL,
		[Include_In_Volume] [bit] NOT NULL  CONSTRAINT [DF_Contact_Products_Include_In_Volume]  DEFAULT ((1)),
		[Exclude_From_Margin] [bit] NULL,
		[Copied_From_Contract_Product_ID] [int] NULL,
		[Base_Sales_CS] [nvarchar](50) NULL,
		[Group_Contract_Product_ID] [int] NULL,
	CONSTRAINT [PK_Contract_Products] PRIMARY KEY CLUSTERED 
	(
		[Contract_Products_ID] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]

END
GO


IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Contract_Products' AND COLUMN_NAME = 'Include_In_Volume')
BEGIN
	ALTER TABLE Contract_Products ADD Include_In_Volume [bit] NOT NULL CONSTRAINT [DF_Contact_Products_Include_In_Volume]  DEFAULT (1)
END
GO

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Contract_Products' AND COLUMN_NAME = 'Exclude_From_Margin')
BEGIN
	ALTER TABLE Contract_Products ADD Exclude_From_Margin [bit] NULL
END
GO


---D30357:Today's Price Wrong on Revision History
IF NOT EXISTS (SELECT *FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Contract_Products' AND COLUMN_NAME = 'Base_Sales_CS')
BEGIN
	ALTER TABLE Contract_Products ADD [Base_Sales_CS] [nvarchar](50) NULL
END
GO

-- 34556: Lump Sum Issue - No Prod on Fund Allocation Screen
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Contract_Products' AND COLUMN_NAME = 'Group_Contract_Product_ID')
BEGIN
	ALTER TABLE Contract_Products ADD Group_Contract_Product_ID [int] NULL
END
GO

-- 77458 - Kerry - Make changes to Group Capture code to flag records being inserteddeleted for Products & Customers
IF NOT EXISTS (SELECT *FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Contract_Products' AND COLUMN_NAME = 'Group_Capture_Delta_Flag')
BEGIN
	ALTER TABLE Contract_Products ADD Group_Capture_Delta_Flag VARCHAR(50) NULL
END
GO

IF NOT EXISTS (SELECT *FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Contract_Products' AND COLUMN_NAME = 'Price_List_Id')
BEGIN
	ALTER TABLE Contract_Products ADD [Price_List_Id] [uniqueidentifier] NULL
END
GO


-------------------------------------------------------------------------------------------------------------------------------
--- CONTRACT_PRODUCT_MARGIN.SQL was last modified on 11/04/2019 10:56:36 AM ---
-------------------------------------------------------------------------------------------------------------------------------
	
--xxxxxxxxxxxxxxxxxxxxxxxxxxxx	
IF not EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='Contract_Product_Margin'
AND C.Name='Broker_Base_CS')

Begin
Alter TABLE [dbo].[Contract_Product_Margin]Add 
	[Broker_Base_CS] [decimal](14, 4) NULL CONSTRAINT [DF_Contract_Product_Margin_Broker_Base_CS]  DEFAULT ((0))	
End
GO
--xxxxxxxxxxxxxxxxxxxxxxxxxxxx
IF not EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='Contract_Product_Margin'
AND C.Name='Brokerage_Rate')

Begin
Alter TABLE [dbo].[Contract_Product_Margin]Add 
	[Brokerage_Rate] [decimal](14, 4) NULL CONSTRAINT [DF_Contract_Product_Margin_Brokerage_Rate]  DEFAULT ((0))	
End
GO
--xxxxxxxxxxxxxxxxxxxxxxxxxxxx
IF not EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='Contract_Product_Margin'
AND C.Name='Broker_Cost_CS')

Begin
Alter TABLE [dbo].[Contract_Product_Margin]Add 
	[Broker_Cost_CS] [decimal](14, 4) NULL CONSTRAINT [DF_Contract_Product_Margin_Broker_Cost_CS]  DEFAULT ((0))	
End
GO
--xxxxxxxxxxxxxxxxxxxxxxxxxxxx
IF not EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='Contract_Product_Margin'
AND C.Name='Broker_Cost_LB')

Begin
Alter TABLE [dbo].[Contract_Product_Margin]Add 
	[Broker_Cost_LB] [decimal](14, 4) NULL CONSTRAINT [DF_Contract_Product_Margin_Broker_Cost_LB]  DEFAULT ((0))	
End
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Annualized_Allowance_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Annualized_Allowance_CS] [decimal](14, 4) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Annualized_Allowance_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Annualized_Allowance_LB] [decimal](14, 4) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Annualized_Allowance_Stat'
)
ALTER TABLE Contract_Product_Margin ADD [Annualized_Allowance_Stat] [decimal](14, 4) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Annualized_Lumpsum_Allowance_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Annualized_Lumpsum_Allowance_CS] [decimal](14, 4) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Annualized_Lumpsum_Allowance_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Annualized_Lumpsum_Allowance_LB] [decimal](14, 4) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Annualized_Lumpsum_Allowance_Stat'
)
ALTER TABLE Contract_Product_Margin ADD [Annualized_Lumpsum_Allowance_Stat] [decimal](14, 4) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Exclude_From_Margin'
)
ALTER TABLE Contract_Product_Margin ADD [Exclude_From_Margin]  [bit] NOT NULL CONSTRAINT [DF_Contract_Product_Margin_Exclude_From_Margin]  DEFAULT (0)
GO
  
-- D28732 : Component as Cost

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_From_Component_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_From_Component_CS] [decimal](14, 4) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_From_Component_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_From_Component_LB] [decimal](14, 4) NULL
GO

-- 77683 Tyson Margin - addtl fields, overwriting values  [SQL & RDB]

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Allowance_Surcharges_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Allowance_Surcharges_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Allowance_Surcharges_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Allowance_Surcharges_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Allowance_Surcharges_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Allowance_Surcharges_STAT] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Customer_Freight_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Customer_Freight_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Customer_Freight_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Customer_Freight_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Customer_Freight_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Customer_Freight_STAT] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Other_Spend_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Other_Spend_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Other_Spend_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Other_Spend_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Other_Spend_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Other_Spend_STAT] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_COGS_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_COGS_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_COGS_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_COGS_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_COGS_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_COGS_STAT] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_Manufacturing_Variance_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_Manufacturing_Variance_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_Manufacturing_Variance_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_Manufacturing_Variance_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_Manufacturing_Variance_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_Manufacturing_Variance_STAT] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Shuttle_Freight_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Shuttle_Freight_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Shuttle_Freight_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Shuttle_Freight_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Shuttle_Freight_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Shuttle_Freight_STAT] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Custom_Warehouse_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Custom_Warehouse_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Custom_Warehouse_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Custom_Warehouse_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Custom_Warehouse_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Custom_Warehouse_STAT] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Custom_Brokerage_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Custom_Brokerage_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Custom_Brokerage_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Custom_Brokerage_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Custom_Brokerage_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Custom_Brokerage_STAT] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'MAP_MDF_CS'
)
ALTER TABLE Contract_Product_Margin ADD [MAP_MDF_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'MAP_MDF_LB'
)
ALTER TABLE Contract_Product_Margin ADD [MAP_MDF_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'MAP_MDF_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [MAP_MDF_STAT] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'SGA_CS'
)
ALTER TABLE Contract_Product_Margin ADD [SGA_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'SGA_LB'
)
ALTER TABLE Contract_Product_Margin ADD [SGA_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'SGA_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [SGA_STAT] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'TPA_Oper_CS'
)
ALTER TABLE Contract_Product_Margin ADD [TPA_Oper_CS] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'TPA_Oper_LB'
)
ALTER TABLE Contract_Product_Margin ADD [TPA_Oper_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'TPA_Oper_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [TPA_Oper_STAT] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Gross_Margin_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Gross_Margin_CS] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Gross_Margin_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Gross_Margin_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Gross_Margin_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Gross_Margin_STAT] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Contribution_Margin_Alt_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Contribution_Margin_Alt_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Contribution_Margin_Alt_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Contribution_Margin_Alt_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Contribution_Margin_Alt_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Contribution_Margin_Alt_STAT] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Variable_Contribution_Margin_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Variable_Contribution_Margin_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Variable_Contribution_Margin_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Variable_Contribution_Margin_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Variable_Contribution_Margin_STAT'
)
ALTER TABLE Contract_Product_Margin ADD [Variable_Contribution_Margin_STAT] [decimal](14, 5) NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_Predicted_Adjustment_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_Predicted_Adjustment_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_Production_Adjustment_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_Production_Adjustment_CS] [decimal](14, 5) NULL
GO



if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Cost_Historical_Adjustment_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Cost_Historical_Adjustment_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Blanket_Bid_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Blanket_Bid_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Blanket_Bid_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Blanket_Bid_LB] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Price_Subtract_TPA_CS'
)
ALTER TABLE Contract_Product_Margin ADD [Price_Subtract_TPA_CS] [decimal](14, 5) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Contract_Product_Margin'
		AND
		COLUMN_NAME = 'Price_Subtract_TPA_LB'
)
ALTER TABLE Contract_Product_Margin ADD [Price_Subtract_TPA_LB] [decimal](14, 5) NULL
GO

-------------------------------------------------------------------------------------------------------------------------------
--- DISTRIBUTOR_SALESORG_MAPPING.SQL was last modified on 11/26/2018 07:40:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Distributor_SalesOrg_Mapping]') AND type in (N'U'))
BEGIN
-- drop table Distributor_SalesOrg_Mapping
	CREATE TABLE [dbo].[Distributor_SalesOrg_Mapping]
	(
		Ship_To VARCHAR (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
		Sales_Org VARCHAR (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
		Distribution_Channel VARCHAR (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
		Division VARCHAR (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
		BSA_Foodservice_Customers_ID UNIQUEIDENTIFIER NULL,
		Deleted BIT NOT NULL DEFAULT (0),
		Updated_Date DATETIME,
		Created_Date DATETIME NOT NULL DEFAULT GETDATE() 
	) ON [PRIMARY]
END
GO


IF NOT EXISTS (	SELECT	*
				FROM	Information_Schema.COLUMNS 
				WHERE	Table_Name = 'Distributor_SalesOrg_Mapping'
				AND		Column_Name = 'Vendor_ID'
			)
BEGIN
	ALTER TABLE Distributor_SalesOrg_Mapping ADD Vendor_ID VARCHAR(50)
END
-------------------------------------------------------------------------------------------------------------------------------
--- FORMULA_PROGRAM_BRACKET_DATA.SQL was last modified on 10/03/2019 12:41:21 PM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Formula_Program_Bracket_Data]    Script Date: 3/12/2019 2:14:07 PM

drop table Formula_Program_Bracket_Data
 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Formula_Program_Bracket_Data]') AND type in (N'U'))
BEGIN

	CREATE TABLE [dbo].[Formula_Program_Bracket_Data](
		[Formula_Program_Bracket_Data_ID] [INT] IDENTITY(1, 1) NOT NULL,
		[Contract_Main_ID] [int] NOT NULL,
		[Bracket_Number] [int] NULL,
		[Bracket_Number_Desc] Varchar(20) NULL,
		[Rate] DECIMAL(12,4) NULL,
		[Rate_UOM_Desc] [varchar](6) NULL,
		[Rate_UOM_Id]  [int] NULL,
		[Deleted] [bit] NOT NULL CONSTRAINT [DF_Formula_Program_Bracket_Data_Created_Deleted]  DEFAULT (0),
		[Created_Date] [DATETIME] NOT NULL CONSTRAINT [DF_Formula_Program_Bracket_Data_Created_Date]  DEFAULT (GETDATE())
	) ON [PRIMARY]

END

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Formula_Program_Bracket_Data'
	AND
	COLUMN_NAME = 'Program_Fixed_Component_Name_Id'
)
BEGIN
	ALTER TABLE [dbo].[Formula_Program_Bracket_Data] ADD [Program_Fixed_Component_Name_Id] [int] NULL
END

GO

IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Formula_Program_Bracket_Data'
	AND		COLUMN_NAME = 'Is_Over_Ride'
)
ALTER TABLE Formula_Program_Bracket_Data ADD [Is_Over_Ride] [bit] NOT NULL DEFAULT(0)
GO

Alter table Formula_Program_Bracket_Data alter column [Rate] DECIMAL(12,4) NULL 


-------------------------------------------------------------------------------------------------------------------------------
--- GLA_INVOICE_FIXED_PRICE_INFO_DETAILS.SQL was last modified on 03/13/2019 09:31:58 PM ---
-------------------------------------------------------------------------------------------------------------------------------
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING OFF
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GLA_Invoice_Fixed_Price_Info_Details]') AND type in (N'U'))
BEGIN
-- drop table GLA_Invoice_Fixed_Price_Info_Details
	CREATE TABLE [dbo].[GLA_Invoice_Fixed_Price_Info_Details](
		[GLA_Invoice_Fixed_Price_Info_Details_ID] INT IDENTITY(1,1) NOT NULL,
		[Order_number] [varchar](100) NULL,
		[Invoice_Version] [varchar](100) NULL,
		[Invoice_Line_Number] [varchar](50) NULL,
		[RBU_Code] [varchar](20) NULL,
		[Distributor_ID] [uniqueidentifier] NULL,
		[Product_ID] [uniqueidentifier] NULL,
		[Cases_Invoiced] [decimal](20, 2) NULL,
		[Pounds_Invoiced] [decimal](20, 2) NULL,
		[CS_Unit_Price] [decimal](20, 2) NULL,
		[LB_Unit_Price] [decimal](20, 2) NULL,
		[Invoice_Type] [varchar](10) NULL,
		[FOB_Price_IND] [varchar](10) NULL,
		[Invoice_Detail_ID] [uniqueidentifier] NULL,
		[Invoice_Header_ID] [uniqueidentifier] NULL,
		[Invoice_Date] [datetime] NULL,
		[Broker_ID] [uniqueidentifier] NULL,
		[RAW_ADJUSTED_PRICE] [decimal](18, 4) NULL,
		[Price_Update_Redi] [decimal](18, 4) NULL,
		[Price_Update_FP] [decimal](18, 4) NULL,
		[Price_Unit_of_Measure] [int] NULL,
		[Resolved_Floor_Price_LB] [decimal](18, 4) NULL,
		[Resolved_Floor_Price_CS] [decimal](18, 4) NULL,
		[Resolved_Rebate_Price_CS] [decimal](18, 4) NULL,
		[Net_Weight] [varchar](50) NULL,
		[Sales_Dollars] [decimal](18, 2) NULL,
		[Gross_Sales_Dollars] [decimal](18, 2) NULL,
		[Contract_Main_ID] [int] NOT NULL,
		[Contract_Number] [nvarchar](255) NULL,
		[RUNDATE] [varchar](50) NULL,
		[Effective_Start_Date] [varchar](10) NULL,
		[Effective_End_Date] [varchar](10) NULL,
		[Program_Fixed_Component_ID] [int] NULL,
		[Program_Fixed_Component_Name_ID] [int] NULL,
		[Component_Name] [varchar](200) NULL,
		[Deduction_Account] [varchar](50) NULL,
		[Payment_Account] [varchar](50) NULL,
		[revision_version] [int] NULL,
		[Revision_of_Contract_Main_ID] [int] NULL,
		[Contract_Products_ID] [int] NULL,
		[BSA_Foodservice_Items_Master_ID] [uniqueidentifier] NULL,
		[Profit_Center] [varchar](50) NULL,
		[ITEM] [varchar](255) NULL,
		[Contract_Distributors_ID] [int] NULL,
		[BSA_Foodservice_Customers_ID] [uniqueidentifier] NULL,
		[Ship_To] [nvarchar](255) NULL,
		[Family_ID] [uniqueidentifier] NULL,
		[RATE] [float] NULL,
		[Unit_Of_Measure_ID] [int] NULL,
		[AMOUNT] [decimal](18, 2) NULL,
		[Segment] [varchar] (10) NULL ,
		[Request_ID] [varchar](100) NULL,
		[Document_Type] [varchar](50) NULL,
		[Currency] [varchar](50) NULL,
		[Category_ID] [varchar](50) NULL,
		[Sales_Org] [varchar](50) NULL,
		[Distribution_Channel] [varchar](50) NULL,
		[Division] [varchar](50) NULL,
		[Sent_To_Vantage] INT NOT NULL CONSTRAINT [DF_GLA_Invoice_Fixed_Price_Info_Details_Sent_To_Vantage] DEFAULT (0),
		[Data_integration_Upload_ID] [int] NOT NULL,
		[CREATED_DATE] [datetime] NOT NULL CONSTRAINT [DF_GLA_Invoice_Fixed_Price_Info_Details_Created_Date]  DEFAULT (GETDATE())
	) ON [PRIMARY]

END
GO

SET ANSI_PADDING OFF
GO

-- drop index GLA_Invoice_Fixed_Price_Info_Details.GLA_Invoice_Fixed_Price_Info_Details_NC1
IF  NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[GLA_Invoice_Fixed_Price_Info_Details]') AND name = N'GLA_Invoice_Fixed_Price_Info_Details_NC1')
CREATE NONCLUSTERED INDEX [GLA_Invoice_Fixed_Price_Info_Details_NC1] ON [dbo].[GLA_Invoice_Fixed_Price_Info_Details] 
(
	[Contract_Main_ID] ASC,
	[Contract_Number] ASC,
	[Data_integration_Upload_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------------------------------------------------
--- GPO_PROGRAM_TIER_DATA.SQL was last modified on 04/08/2019 09:29:40 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Growth_Main_Tier_Detail]    Script Date: 3/12/2019 2:14:07 PM

drop table GPO_Program_Tier_Data
 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GPO_Program_Tier_Data]') AND type in (N'U'))
BEGIN

	CREATE TABLE [dbo].[GPO_Program_Tier_Data](
		[GPO_Program_Tier_Data_ID] [INT] IDENTITY(1, 1) NOT NULL,
		[Contract_Main_ID] [int] NOT NULL,
		[Tier_Number] [int] NULL,
		[Tier_Number_Desc] Varchar(20) NULL,
		[Range_Start] [nvarchar](50) NULL,
		[Range_End] [nvarchar](50) NULL,
		[Rate_Desc] Varchar(20) NULL,
		[Rate] DECIMAL(12,2) NULL,
		[Rate_UOM_Desc] [varchar](6) NULL,
		[Rate_UOM_Id]  [int] NULL,
		[Range_UOM_Desc] [varchar](6) NULL,
		[Range_UOM_Id]  [int] NULL,
		[Deleted] [bit] NOT NULL CONSTRAINT [DF_GPO_Program_Tier_Data_Created_Deleted]  DEFAULT (0),
		[Created_Date] [DATETIME] NOT NULL CONSTRAINT [DF_GPO_Program_Tier_Data_Created_Date]  DEFAULT (GETDATE())
	) ON [PRIMARY]

END

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'GPO_Program_Tier_Data'
	AND
	COLUMN_NAME = 'Program_Fixed_Component_Name_Id'
)
BEGIN
	ALTER TABLE [dbo].[GPO_Program_Tier_Data] ADD [Program_Fixed_Component_Name_Id] [int] NULL
END

GO


-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_CF_DEMAND_PLAN_STANDARD.SQL was last modified on 07/09/2019 02:06:26 PM ---
-------------------------------------------------------------------------------------------------------------------------------
-- 77432 - Demand Planning interface
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[History_CF_Demand_Plan_Standard]') AND type in (N'U'))
BEGIN 
	CREATE TABLE [dbo].[History_CF_Demand_Plan_Standard]
	(	
		[History_CF_Demand_Plan_Standard_ID] INT IDENTITY(1, 1) NOT NULL,
		[Customer] [varchar](100) NULL,
		[Item] [varchar](100) NULL,
		[Start_Date] [varchar](100) NULL,
		[Quantity] [varchar](100) NULL,
		[Process_Date] [datetime] NULL,
		[Created_Date] [datetime] NULL CONSTRAINT [History_CF_Demand_Plan_Standard_Created_Date]  DEFAULT (getdate()),
		[Data_Integration_Upload_ID] [int] NULL,
	 CONSTRAINT [PK_History_CF_Demand_Plan_Standard] PRIMARY KEY CLUSTERED 
	(
		[History_CF_Demand_Plan_Standard_ID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]
END
GO

SET ANSI_PADDING OFF
GO
-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_CF_OUTBOUND_FREIGHT_RATE.SQL was last modified on 06/17/2019 03:48:24 PM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[History_CF_Outbound_Freight_Rate]') AND type in (N'U'))
BEGIN 

CREATE TABLE [dbo].[History_CF_Outbound_Freight_Rate](
	[History_CF_Outbound_Freight_Rate_ID] [int] IDENTITY(1,1) NOT NULL,
	[Warehouse_Code] [varchar](20) NULL,
	[Warehouse_Master_ID] [smallint] NULL,
	[Start_Zip] [varchar](10) NULL,
	[End_Zip] [varchar](20) NULL,
	[Bracket_Rate] [decimal](20, 4) NULL,
	[Freight_Bracket_Setting_ID] [int] NULL,
	[Start_Date] [smalldatetime] NULL,
	[End_Date] [smalldatetime] NULL,
	[Created_Date] [datetime] NOT NULL
 CONSTRAINT [PK_History_CF_Outbound_Freight_Rate] PRIMARY KEY CLUSTERED 
(
	[History_CF_Outbound_Freight_Rate_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[History_CF_Outbound_Freight_Rate] ADD  CONSTRAINT [DF_History_CF_Outbound_Freight_Rate_Created_Date]  DEFAULT (getdate()) FOR [Created_Date]


END

IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS 
            WHERE TABLE_NAME = 'History_CF_Outbound_Freight_Rate'
           AND  COLUMN_NAME = 'Data_integration_Upload_ID')
    BEGIN 
		alter table History_CF_Outbound_Freight_Rate
		add [Data_integration_Upload_ID] [int] NULL
	END

-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_Z_DEAL_BASIC_INFORMATION.SQL was last modified on 06/03/2019 06:35:41 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[History_Z_DEAL_BASIC_INFORMATION]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[History_Z_DEAL_BASIC_INFORMATION](
	[History_Z_DEAL_BASIC_INFORMATION_ID] [int] IDENTITY(1,1) NOT NULL,
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[TEMPLATE_NAME] [varchar](100) NULL,
	[PROGRAM_TITLE] [varchar](1000) NULL,
	[START_DATE] [varchar](50) NULL,
	[END_DATE] [varchar](50) NULL,
	[SALES_PERSON_RESPONSIBLE] [varchar](255) NULL,
	[CREATOR_POSITION] [varchar](255) NULL,
	[CREATED_DATE] [varchar](255) NULL,
	[RFA_POSITION] [varchar](255) NULL,
	[RFA_DATE] [varchar](255) NULL,
	[APPROVAL_POSITION] [varchar](255) NULL,
	[APPROVAL_DATE] [varchar](255) NULL,
	[LEGACY_OPERATOR_ID] [varchar](255) NULL,
	[BID_STATUS] [varchar](255) NULL,
	[REFEREMCE_NUMBER] [varchar](255) NULL,
	[REJECTED] [bit] NULL,
	[Process_Date] [datetime] NULL,
	[History_Created_Date] [datetime] NULL,
	[Data_integration_Upload_ID] [int] NULL,
	[BUSINESS_SEGMENT] [varchar](255) NULL,
	[ACTION_CODE] [varchar](255) NULL,
 CONSTRAINT [PK_History_Z_DEAL_BASIC_INFORMATION] PRIMARY KEY CLUSTERED 
(
	[History_Z_DEAL_BASIC_INFORMATION_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'History_Z_DEAL_BASIC_INFORMATION'
		AND
		COLUMN_NAME = 'BUSINESS_SEGMENT'
)
ALTER TABLE dbo.History_Z_DEAL_BASIC_INFORMATION ADD [BUSINESS_SEGMENT] [varchar](255) NULL 
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'History_Z_DEAL_BASIC_INFORMATION'
		AND
		COLUMN_NAME = 'ACTION_CODE'
)
ALTER TABLE dbo.History_Z_DEAL_BASIC_INFORMATION ADD [ACTION_CODE] [varchar](255) NULL 
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'History_Z_DEAL_BASIC_INFORMATION'
		AND
		COLUMN_NAME = 'History_Created_Date'
)
ALTER TABLE dbo.History_Z_DEAL_BASIC_INFORMATION ADD [History_Created_Date] [datetime] NULL
GO


IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_History_Z_DEAL_BASIC_INFORMATION_Created_Date]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[History_Z_DEAL_BASIC_INFORMATION] ADD  CONSTRAINT [DF_History_Z_DEAL_BASIC_INFORMATION_Created_Date]  DEFAULT (getdate()) FOR [History_Created_Date]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_Z_DEAL_DISTRIBUTORS.SQL was last modified on 05/28/2019 08:32:39 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HISTORY_Z_DEAL_DISTRIBUTORS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HISTORY_Z_DEAL_DISTRIBUTORS](
	[HISTORY_Z_DEAL_DISTRIBUTORS_ID] [int] IDENTITY(1,1) NOT NULL,
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[SHIP_TO] [varchar](100) NULL,
	[DISTRIBUTOR_WEIGHT] [varchar](100) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_HISTORY_Z_DEAL_DISTRIBUTORS_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_HISTORY_Z_DEAL_DISTRIBUTORS_REJECTED]  DEFAULT ((0)) ,
	[Data_integration_Upload_ID] [int] NULL,
 CONSTRAINT [PK_HISTORY_Z_DEAL_DISTRIBUTORS] PRIMARY KEY CLUSTERED 
(
	[HISTORY_Z_DEAL_DISTRIBUTORS_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_Z_DEAL_FIXED_PRICES.SQL was last modified on 05/28/2019 08:32:39 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HISTORY_Z_DEAL_FIXED_PRICES]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HISTORY_Z_DEAL_FIXED_PRICES](
	[HISTORY_Z_DEAL_FIXED_PRICES_ID] [int] IDENTITY(1,1) NOT NULL,
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[FIXED_PRICE_PER_CASE] [varchar](50) NULL,
	[FIXED_PRICE_PER_POUND] [varchar](50) NULL,
	[FREIGHT_ALLOWANCE] [varchar](50) NULL,
	[DELIVERED_PRICE_PER_CASE] [varchar](50) NULL,
	[DELICERED_PRICE_PER_POUND] [varchar](50) NULL,
	[FIXED_PRICE_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[FIXED_PRICE_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_HISTORY_Z_DEAL_FIXED_PRICES_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_HISTORY_Z_DEAL_FIXED_PRICES_REJECTED]  DEFAULT ((0)) ,
	[Data_integration_Upload_ID] [int] NULL,
 CONSTRAINT [PK_HISTORY_Z_DEAL_FIXED_PRICES] PRIMARY KEY CLUSTERED 
(
	[HISTORY_Z_DEAL_FIXED_PRICES_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_Z_DEAL_LUMPSUM.SQL was last modified on 05/28/2019 08:32:39 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HISTORY_Z_DEAL_LUMPSUM]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HISTORY_Z_DEAL_LUMPSUM](
	[HISTORY_Z_DEAL_LUMPSUM_ID] [int] IDENTITY(1,1) NOT NULL,
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[LS_AMOUNT] [varchar](50) NULL,
	[LUMP_SUM_DESCRIPTION] [varchar](50) NULL,
	[LS_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[LS_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_HISTORY_Z_DEAL_LUMPSUM_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_HISTORY_Z_DEAL_LUMPSUM_REJECTED]  DEFAULT ((0)) ,
	[Data_integration_Upload_ID] [int] NULL,
 CONSTRAINT [PK_HISTORY_Z_DEAL_LUMPSUM] PRIMARY KEY CLUSTERED 
(
	[HISTORY_Z_DEAL_LUMPSUM_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_Z_DEAL_OPERATORS.SQL was last modified on 05/28/2019 08:32:39 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HISTORY_Z_DEAL_OPERATORS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HISTORY_Z_DEAL_OPERATORS](
	[HISTORY_Z_DEAL_OPERATORS_ID] [int] IDENTITY(1,1) NOT NULL,
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[SHIP_TO] [varchar](100) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_HISTORY_Z_DEAL_OPERATORS_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_HISTORY_Z_DEAL_OPERATORS_REJECTED]  DEFAULT ((0)) ,
	[Data_integration_Upload_ID] [int] NULL,
 CONSTRAINT [PK_HISTORY_Z_DEAL_OPERATORS] PRIMARY KEY CLUSTERED 
(
	[HISTORY_Z_DEAL_OPERATORS_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_Z_DEAL_REBATES.SQL was last modified on 05/28/2019 08:32:39 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HISTORY_Z_DEAL_REBATES]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HISTORY_Z_DEAL_REBATES](
	[HISTORY_Z_DEAL_REBATES_ID] [int] IDENTITY(1,1) NOT NULL,
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[REBATE] [varchar](50) NULL,
	[REBATE_UOM] [varchar](50) NULL,
	[REBATE_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[REBATE_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_HISTORY_Z_DEAL_REBATES_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_HISTORY_Z_DEAL_REBATES_REJECTED]  DEFAULT ((0)) ,
	[Data_integration_Upload_ID] [int] NULL,
 CONSTRAINT [PK_HISTORY_Z_DEAL_REBATES] PRIMARY KEY CLUSTERED 
(
	[HISTORY_Z_DEAL_REBATES_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- HISTORY_Z_DEAL_VOLUMES.SQL was last modified on 05/28/2019 08:32:39 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HISTORY_Z_DEAL_VOLUMES]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HISTORY_Z_DEAL_VOLUMES](
	[HISTORY_Z_DEAL_VOLUMES_ID] [int] IDENTITY(1,1) NOT NULL,
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[PROGRAM_VOLUME_CASES] [varchar](50) NULL,
	[PROGRAM_VOLUME_POUNDS] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_HISTORY_Z_DEAL_VOLUMES_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_HISTORY_Z_DEAL_VOLUMES_REJECTED]  DEFAULT ((0))  ,
	[Data_integration_Upload_ID] [int] NULL,
 CONSTRAINT [PK_HISTORY_Z_DEAL_VOLUMES] PRIMARY KEY CLUSTERED 
(
	[HISTORY_Z_DEAL_VOLUMES_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- INVOICE_DETAIL.SQL was last modified on 12/03/2018 07:30:22 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Invoice_Detail'
)
CREATE TABLE [dbo].[Invoice_Detail](
	[Invoice_Detail_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Invoice_Detail_Invoice_Detail_ID]  DEFAULT (newid()),
	[Invoice_Header_ID] [uniqueidentifier] NULL,
	[Fiscal_Year] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Fiscal_Period] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Fiscal_Week] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Order_Number] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Invoice_Version] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Line] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Ship_Plant] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Current_Shared_Ship_To] [char](9) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Current_Prime_Broker] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Item] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Buy_Group] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Current_LOB] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Order_Status] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Invoice_Date] [datetime] NULL,
	[Original_Q_Brand] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Original_Q_Brand_Description] [char](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Original_Shared_Ship_To] [char](9) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[MFG_Plant] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Prime_Plant] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Original_Prime_Broker] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Secondary_Broker] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Trade_Mktg] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Cases_Ordered] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Cases_Invoiced] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Pounds_Ordered] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Pounds_Invoiced] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Customer_Requested_Cases] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Gross_Weight] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Price_Unit_of_Measure] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Unit_Price] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Sales_Dollars] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Off_Invoice_Dollars] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Trade_Dollars] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Fixed_Cost] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Variable_Cost] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Freight_Revenue] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Freight_Expense] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Primary_Broker_Commission] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Secondary_Broker_Commission] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Buy_Group_Commission] [char](12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Actual_Deduction_Dollars] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Deduction_Reason] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Deleted] [bit] NULL CONSTRAINT [DF_Invoice_Detail_Deleted]  DEFAULT (0),
	[BSA_Foodservice_Items_Master_ID] [uniqueidentifier] NULL,
	[LB_Unit_Price] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[CS_Unit_Price] [char](11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Created_Date] [datetime] NULL CONSTRAINT [DF_Invoice_Detail_Created_Date]  DEFAULT (getdate()),
	[INVOICE_HDR] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[FOB_PRICE_IND] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Copy_Sales_Dollars] [float] NULL,
	[Gross_Sales_Dollars] [float] NULL,
	[Order_Class] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Price_Structure_Code] [char](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Line_Type] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Company_Number] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Sequence_Number] [char](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Invoice_Number] [char](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Updated_Date] [datetime] NULL,
	[Invoice_Line_Number] [nvarchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Invoice_Type] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[BO_Interface_Flag] [bit] NOT NULL DEFAULT ((0))

) ON [PRIMARY]
SET ANSI_PADDING OFF

IF NOT EXISTS 
(	SELECT name FROM sysindexes
	WHERE name = 'PK_Invoice_Detail')
/****** Object:  Index [PK_Invoice_Detail]    Script Date: 10/23/2007 16:55:52 ******/
ALTER TABLE [dbo].[Invoice_Detail] ADD  CONSTRAINT [PK_Invoice_Detail] PRIMARY KEY NONCLUSTERED 
(
	[Invoice_Detail_ID] ASC
)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80, ONLINE = OFF) ON [PRIMARY]

GO

IF NOT EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='Invoice_Detail'
AND C.Name='Cash_Discount')
BEGIN
	Alter TABLE [dbo].[Invoice_Detail] Add [Cash_Discount] [Decimal] (18,2) NOT NULL CONSTRAINT [DF_Invoice_Detail_Cash_Discount]  DEFAULT (0)
END

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Invoice_Detail' AND
                        COLUMN_NAME = 'Accrued'
)
ALTER TABLE Invoice_Detail ADD [Accrued] [bit] NOT NULL 
CONSTRAINT [DF_Invoice_Detail_Accrued] DEFAULT (0)
GO

if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Invoice_Detail' AND
                        COLUMN_NAME = 'Accrued_On'
)
ALTER TABLE Invoice_Detail ADD [Accrued_On] DateTime NULL 
GO

IF EXISTS 
(	SELECT name FROM sysindexes
	WHERE name = 'IDX_Invoice_Detail_Accrued')
DROP INDEX Invoice_Detail.IDX_Invoice_Detail_Accrued
CREATE INDEX IDX_Invoice_Detail_Accrued ON Invoice_Detail(Accrued) 



if not exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Invoice_Detail' AND
                        COLUMN_NAME = 'Net_Weight'
)
ALTER TABLE Invoice_Detail ADD Net_Weight VARCHAR(50) NULL 
GO 

if  exists 
(
            SELECT            *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE  TABLE_NAME = 'Invoice_Detail' AND
                        COLUMN_NAME = 'Net_Weight'
)
ALTER TABLE Invoice_Detail DROP COLUMN Net_Weight 
GO 


--**** line number field - increase it to 6 - start
if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'Invoice_Line_Number'
)
BEGIN


	IF(
	SELECT	CHARACTER_MAXIMUM_LENGTH
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'Invoice_Line_Number'
	) < 6
	BEGIN
		ALTER TABLE Invoice_Detail ALTER COLUMN [Invoice_Line_Number] [nvarchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
	END
END
--**** line number field - increase it to 6 - end

GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'Updated_Date'
)
ALTER TABLE Invoice_Detail ADD [Updated_Date] [datetime] NULL

GO
if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_Flag')
ALTER TABLE Invoice_Detail ADD Price_Update_Flag INT NOT NULL CONSTRAINT [DF_Invoice_Detail_Price_Update_Flag] DEFAULT (0)
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_Flagpart')
ALTER TABLE Invoice_Detail ADD Price_Update_Flagpart CHAR(2) NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_Redi')
ALTER TABLE Invoice_Detail ADD Price_Update_Redi DECIMAL(18,2) NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_Redi_Date')
ALTER TABLE Invoice_Detail ADD Price_Update_Redi_Date [datetime] NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_FP')
ALTER TABLE Invoice_Detail ADD Price_Update_FP DECIMAL(18,2) NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_DPP')
ALTER TABLE Invoice_Detail ADD Price_Update_DPP DECIMAL(18,2) NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_FP_Date')
ALTER TABLE Invoice_Detail ADD Price_Update_FP_Date [datetime] NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Price_Update_DPP_Date')
ALTER TABLE Invoice_Detail ADD Price_Update_DPP_Date [datetime] NULL 
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Invoice_Detail]') AND name = N'IDX_Invoice_Detail_Price_Update_Flag')
DROP INDEX [IDX_Invoice_Detail_Price_Update_Flag] ON [dbo].[Invoice_Detail] WITH ( ONLINE = OFF )
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Redi_Contract_Main_ID')
ALTER TABLE Invoice_Detail ADD Redi_Contract_Main_ID INT NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'FP_Contract_Main_ID')
ALTER TABLE Invoice_Detail ADD FP_Contract_Main_ID INT NULL 
GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'DPP_Contract_Main_ID')
ALTER TABLE Invoice_Detail ADD DPP_Contract_Main_ID INT NULL 
GO

CREATE NONCLUSTERED INDEX [IDX_Invoice_Detail_Price_Update_Flag] ON [dbo].[Invoice_Detail] 
(
	[Price_Update_Flag] ASC
)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

GO

if not exists
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Invoice_Detail' AND COLUMN_NAME = 'Raw_Adjusted_Price')
ALTER TABLE Invoice_Detail ADD Raw_Adjusted_Price DECIMAL(18,2) NULL 
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'BO_Interface_Flag'
)
ALTER TABLE Invoice_Detail ADD [BO_Interface_Flag] [Bit] DEFAULT (0) NOT NULL
GO


if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Invoice_Detail'
            AND
            COLUMN_NAME = 'Sales_ORG'
)
ALTER TABLE Invoice_Detail ADD [Sales_ORG] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
GO


if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Invoice_Detail'
            AND
            COLUMN_NAME = 'Market_Number'
)
ALTER TABLE Invoice_Detail ADD [Market_Number] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
GO


if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Invoice_Detail'
            AND
            COLUMN_NAME = 'Service_Market_ID'
)
ALTER TABLE Invoice_Detail ADD [Service_Market_ID] INT NULL 
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Invoice_Detail'
            AND
            COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE Invoice_Detail ADD [Business_Segment_ID] INT NULL 
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Invoice_Detail'
            AND
            COLUMN_NAME = 'Original_Business_Segment_ID'
)
ALTER TABLE Invoice_Detail ADD [Original_Business_Segment_ID] INT NULL 
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Invoice_Detail'
            AND
            COLUMN_NAME = 'Original_Service_Market_ID'
)
ALTER TABLE Invoice_Detail ADD [Original_Service_Market_ID] INT NULL 
GO

if not exists 
(
      SELECT      *
      FROM  INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_NAME = 'Invoice_Detail'
            AND
            COLUMN_NAME = 'Company_Number'
)
ALTER TABLE Invoice_Detail ADD [Company_Number] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
GO


IF NOT EXISTS
(	
	SELECT	*
	FROM	SysObjects O 
			INNER JOIN SysColumns C ON O.ID=C.ID 
	WHERE	ObjectProperty(O.ID,'IsUserTable')=1 
	AND		O.Name='Invoice_Detail'
	AND		C.Name='CS_OFF_INVOICE_RATE'
)
ALTER TABLE [dbo].[Invoice_Detail] ADD [CS_OFF_INVOICE_RATE] DECIMAL(18,2) NULL 
GO

if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_HEADER' AND
                        COLUMN_NAME = 'Total_Cases_Invoiced'
)
ALTER TABLE INVOICE_HEADER ADD Total_Cases_Invoiced DECIMAL(10,2) NULL  
GO
if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_HEADER' AND
                        COLUMN_NAME = 'Total_Pounds_Invoiced'
)
ALTER TABLE INVOICE_HEADER ADD Total_Pounds_Invoiced DECIMAL(10,2) NULL  
GO
if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_HEADER' AND
                        COLUMN_NAME = 'Total_Gross_Sales_Dollars'
)
ALTER TABLE INVOICE_HEADER ADD Total_Gross_Sales_Dollars DECIMAL(10,2) NULL  
GO
if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_HEADER' AND
                        COLUMN_NAME = 'Total_Sales_Dollars'
)
ALTER TABLE INVOICE_HEADER ADD Total_Sales_Dollars DECIMAL(10,2) NULL  
GO
if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
           WHERE       TABLE_NAME = 'INVOICE_HEADER' AND
                        COLUMN_NAME = 'BSA_Foodservice_Brokers_ID'
)
ALTER TABLE INVOICE_HEADER ADD BSA_Foodservice_Brokers_ID UNIQUEIDENTIFIER NULL  
GO

if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_DETAIL' AND
                        COLUMN_NAME = 'Gross_Price'
)
ALTER TABLE INVOICE_DETAIL ADD Gross_Price DECIMAL(10,2) NULL  
GO
if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_DETAIL' AND
                        COLUMN_NAME = 'CS_Gross_Price'
)
ALTER TABLE INVOICE_DETAIL ADD CS_Gross_Price DECIMAL(10,2) NULL  
GO
if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_DETAIL' AND
                        COLUMN_NAME = 'LB_Gross_Price'
)
ALTER TABLE INVOICE_DETAIL ADD LB_Gross_Price DECIMAL(10,2) NULL  
GO

if not exists 
(
            SELECT            *
            FROM       INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_NAME = 'INVOICE_DETAIL' AND
                        COLUMN_NAME = 'Contract_Number'
)
ALTER TABLE INVOICE_DETAIL ADD Contract_Number varchar(20) NULL  
GO

if  exists 
(
SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'invoice_detail'
		AND
		COLUMN_NAME = 'Original_Q_Brand_Description'
)
ALTER TABLE invoice_detail alter column Original_Q_Brand_Description varchar(255)

GO

if  exists 
(
SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'invoice_detail'
		AND
		COLUMN_NAME = 'Original_Q_Brand'
)
ALTER TABLE invoice_detail alter column Original_Q_Brand varchar(255)

GO

IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Primary_Broker_Commission'
)
ALTER TABLE dbo.Invoice_Detail ALTER COLUMN [Primary_Broker_Commission] VARCHAR(50) NULL 
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Distributor_Owner_ID'
)
ALTER TABLE dbo.Invoice_Detail ADD [Distributor_Owner_ID] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Distributor_Owner_Name'
)
ALTER TABLE dbo.Invoice_Detail ADD [Distributor_Owner_Name] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Operator_Owner_ID'
)
ALTER TABLE dbo.Invoice_Detail ADD [Operator_Owner_ID] [varchar](255) NULL
GO

-- D50640 Profitability Report in Analytics
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Operator_Owner_Name'
)
ALTER TABLE dbo.Invoice_Detail ADD [Operator_Owner_Name] [varchar](255) NULL
GO

-- WR:63056 - Added OI_Processed flag 
IF NOT EXISTS 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'OI_Processed'
)
ALTER TABLE Invoice_Detail ADD [OI_Processed] BIT NOT NULL CONSTRAINT [DF_Invoice_Detail_OI_Processed]  DEFAULT ((0))
GO



if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'Current_Shared_Ship_To'
)
BEGIN


	IF(
	SELECT	CHARACTER_MAXIMUM_LENGTH
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'Current_Shared_Ship_To'
	) < 25
	BEGIN
		ALTER TABLE Invoice_Detail ALTER COLUMN [Current_Shared_Ship_To] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
	END
END


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Net_Value'
)
ALTER TABLE dbo.Invoice_Detail ADD [Net_Value] DECIMAL(30, 5) NOT NULL CONSTRAINT [DF_Invoice_Detail_Net_Value]  DEFAULT (('0.00000'))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Subtotal_1'
)
ALTER TABLE dbo.Invoice_Detail ADD [Subtotal_1] DECIMAL(30, 5) NOT NULL CONSTRAINT [DF_Invoice_Detail_Subtotal_1]  DEFAULT (('0.00000'))
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Subtotal_2'
)
ALTER TABLE dbo.Invoice_Detail ADD [Subtotal_2] DECIMAL(30, 5) NOT NULL CONSTRAINT [DF_Invoice_Detail_Subtotal_2]  DEFAULT (('0.00000'))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Subtotal_3'
)
ALTER TABLE dbo.Invoice_Detail ADD [Subtotal_3] DECIMAL(30, 5) NOT NULL CONSTRAINT [DF_Invoice_Detail_Subtotal_3]  DEFAULT (('0.00000'))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Subtotal_4'
)
ALTER TABLE dbo.Invoice_Detail ADD [Subtotal_4] DECIMAL(30, 5) NOT NULL CONSTRAINT [DF_Invoice_Detail_Subtotal_4]  DEFAULT (('0.00000'))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Subtotal_5'
)
ALTER TABLE dbo.Invoice_Detail ADD [Subtotal_5] DECIMAL(30, 5) NOT NULL CONSTRAINT [DF_Invoice_Detail_Subtotal_5]  DEFAULT (('0.00000'))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Subtotal_6'
)
ALTER TABLE dbo.Invoice_Detail ADD [Subtotal_6] DECIMAL(30, 5) NOT NULL CONSTRAINT [DF_Invoice_Detail_Subtotal_6]  DEFAULT (('0.00000'))
GO

IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Invoice_Line_Number'
)
ALTER TABLE dbo.Invoice_Detail ALTER COLUMN [Invoice_Line_Number] VARCHAR(50)
GO

IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
	AND		COLUMN_NAME = 'Sequence_Number '
)
ALTER TABLE dbo.Invoice_Detail ALTER COLUMN [Sequence_Number ] VARCHAR(50)
GO

BEGIN
	IF NOT EXISTS
(
       SELECT *
       FROM   INFORMATION_SCHEMA.COLUMNS
       WHERE  TABLE_NAME = 'Invoice_Detail'
       AND    COLUMN_NAME = 'BSA_Foodservice_Brokers_ID'
)
ALTER TABLE dbo.Invoice_Detail ADD BSA_Foodservice_Brokers_ID uniqueidentifier NULL
END

BEGIN
	IF(
	SELECT	CHARACTER_MAXIMUM_LENGTH
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Invoice_Detail'
		AND
		COLUMN_NAME = 'Original_Shared_Ship_To'
	) = 9
	BEGIN
		ALTER TABLE Invoice_Detail ALTER COLUMN [Original_Shared_Ship_To] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
	END
END
-------------------------------------------------------------------------------------------------------------------------------
--- LOG_BB_PRG_AUTOADD_DISTRIBUTOR.SQL was last modified on 07/09/2019 07:32:44 AM ---
-------------------------------------------------------------------------------------------------------------------------------
 
 IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Log_BB_PRG_AutoAdd_Distributor'
)
 
 CREATE TABLE Log_BB_PRG_AutoAdd_Distributor (
				Billback_ID UNIQUEIDENTIFIER,
				Contract_main_ID INT, 
				Distributor_ID UNIQUEIDENTIFIER,
				Billback_Number VARCHAR(50),
				Billback_Title VARCHAR(255),
				Billback_Start_Date DATETIME,
				Billback_End_Date DATETIME,
				Program_Number VARCHAR(50),
				Program_Title  VARCHAR(255),
				Template_Name VARCHAR(255),
				Program_RSP VARCHAR(100),
				Program_RSP_Position  VARCHAR(255),
				Program_Status  VARCHAR(50),
				Program_Start_Date DATETIME,
				Program_End_Date DATETIME,
				Distributor_Number VARCHAR(50),
				Distributor_Name VARCHAR(255),
				Broker_Name VARCHAR(255),
				Created_Date DATETIME NOT NULL CONSTRAINT [DF_Log_BB_PRG_AutoAdd_Distributor_created_date] DEFAULT(GETDATE()),
				Deleted BIT NOT NULL CONSTRAINT [DF_Log_BB_PRG_AutoAdd_Distributor_Deleted] DEFAULT(0),
				Latest BIT NOT NULL CONSTRAINT [DF_Log_BB_PRG_AutoAdd_Distributor_Latest] DEFAULT (1),
				Extracted BIT NOT NULL CONSTRAINT [DF_Log_BB_PRG_AutoAdd_Distributor_Extracted] DEFAULT(0)				
				)

IF NOT EXISTS ( SELECT	*
				FROM	INFORMATION_SCHEMA.COLUMNS
				WHERE	TABLE_NAME = 'Log_BB_PRG_AutoAdd_Distributor'
						AND COLUMN_NAME = 'Program_Title' ) 
	ALTER TABLE Log_BB_PRG_AutoAdd_Distributor ADD Program_Title varchar(4000)
GO
				
-------------------------------------------------------------------------------------------------------------------------------
--- LOG_CF_DEMAND_PLAN_STANDARD.SQL was last modified on 07/09/2019 02:06:26 PM ---
-------------------------------------------------------------------------------------------------------------------------------
-- 77432 - Demand Planning interface
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Log_CF_Demand_Plan_Standard]') AND type in (N'U'))
BEGIN

	CREATE TABLE [dbo].[Log_CF_Demand_Plan_Standard](
	[Log_CF_Demand_Plan_Standard_ID] INT IDENTITY(1,1) NOT NULL,
	[Customer] [varchar](100) NULL,
	[Item] [varchar](100) NULL,
	[Start_Date] [varchar](100) NULL,
	[Quantity] [varchar](100) NULL,
	[Created_Date] DATETIME NOT NULL CONSTRAINT [DF_Log_CF_Demand_Plan_Standard_Created_Date]  DEFAULT (getdate()),
	[Err_Number] INT NULL,
	[Err_Column] VARCHAR(255) NULL,
	[Err_Message] VARCHAR(100) NULL,
    CONSTRAINT [PK_Log_CF_Demand_Plan_Standard] PRIMARY KEY CLUSTERED 
	(
		[Log_CF_Demand_Plan_Standard_ID] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]
END

-------------------------------------------------------------------------------------------------------------------------------
--- LOG_PG_MEMBER_UPLOAD.SQL was last modified on 09/17/2019 08:28:04 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Log_PG_Member_Upload]') AND TYPE in (N'U'))

CREATE TABLE [dbo].[Log_PG_Member_Upload] (
	Log_CF_Item_ID INT IDENTITY(1,1) NOT NULL,
	PG_Type_ID VARCHAR(255), 
	PG_Category_Definition_ID VARCHAR(255), 
	PG_Effective_Start_Date VARCHAR(255), 
	PG_Effective_End_Date VARCHAR(255), 
	Err_Message VARCHAR(255), 
	Created_Date DATETIME
)
-------------------------------------------------------------------------------------------------------------------------------
--- MARGIN_TARGETS_UPLOAD_DOC_ERROR_DETAILS.SQL was last modified on 04/17/2019 07:10:25 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.Tables WHERE Table_Name = 'Margin_Targets_Upload_Doc_Error_Details' )
  BEGIN
      CREATE TABLE [dbo].[Margin_Targets_Upload_Doc_Error_Details]
	(
		[Doc_ID] [int] NOT NULL,
		[item] [nvarchar] (50) NOT NULL,
		[Distribution_Channel] [VARCHAR] (50) NOT NULL,
		[Net_Sales_Target_Value] [VARCHAR] (10) NULL,
		[Net_Sales_Floor_Value] [VARCHAR] (10) NULL,
		[GM_Target_Value] [VARCHAR] (10) NULL,
		[GM_Floor_Value] [VARCHAR] (10) NULL,		
		[Reason]  varchar(MAX)
		)
      ON [PRIMARY]
  END

  IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Margin_Targets_Upload_Doc_Error_Details' AND COLUMN_NAME = 'Net_Sales_Target_Value')
	ALTER TABLE dbo.Margin_Targets_Upload_Doc_Error_Details ALTER COLUMN Net_Sales_Target_Value varchar(Max)
GO 

IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Margin_Targets_Upload_Doc_Error_Details' AND COLUMN_NAME = 'Net_Sales_Floor_Value')
	ALTER TABLE dbo.Margin_Targets_Upload_Doc_Error_Details ALTER COLUMN Net_Sales_Floor_Value varchar(Max)
GO 

  IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Margin_Targets_Upload_Doc_Error_Details' AND COLUMN_NAME = 'GM_Target_Value')
	ALTER TABLE dbo.Margin_Targets_Upload_Doc_Error_Details ALTER COLUMN GM_Target_Value varchar(Max)
GO 

IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Margin_Targets_Upload_Doc_Error_Details' AND COLUMN_NAME = 'GM_Floor_Value')
	ALTER TABLE dbo.Margin_Targets_Upload_Doc_Error_Details ALTER COLUMN GM_Floor_Value varchar(Max)
GO 
-------------------------------------------------------------------------------------------------------------------------------
--- OPERATOR_CATEGORY.SQL was last modified on 11/01/2019 11:41:20 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Operator_Category'
)

CREATE TABLE [dbo].[Operator_Category](
	[Operator_Category_ID] [int] IDENTITY(1,1) NOT NULL,
	[Category_Label] [nvarchar](100) NOT NULL,
	[isDefault] [bit] NOT NULL,
	[Deleted] [bit] NOT NULL,
	[Created_Date] [datetime] NOT NULL,
 CONSTRAINT [PK_Operator_Category] PRIMARY KEY CLUSTERED 
(
	[Operator_Category_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Operator_Category'
	AND		COLUMN_NAME = 'isDefault'
	AND		COLUMN_DEFAULT = '(0)'
)
ALTER TABLE Operator_Category ADD CONSTRAINT [DF_Operator_Category_isDefault] DEFAULT (0) FOR [isDefault]
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Operator_Category'
	AND		COLUMN_NAME = 'Deleted'
	AND		COLUMN_DEFAULT = '(0)'
)
ALTER TABLE Operator_Category ADD CONSTRAINT [DF_Operator_Category_Deleted] DEFAULT (0) FOR [Deleted]
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Operator_Category'
	AND		COLUMN_NAME = 'Created_Date'
	AND		COLUMN_DEFAULT = '(getdate())'
)
ALTER TABLE Operator_Category ADD CONSTRAINT [DF_Operator_Category_Created_Date] DEFAULT (getdate()) FOR [Created_Date]
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Operator_Category'
	AND		COLUMN_NAME = 'Category_Code' 
 )
ALTER TABLE Operator_Category ADD Category_Code VARCHAR(255) NULL
GO

-------------------------------------------------------------------------------------------------------------------------------
--- PG_CUSTOMER_CATEGORY.SQL was last modified on 11/26/2018 07:40:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'PG_Customer_Category'
)
CREATE TABLE [dbo].[PG_Customer_Category](
	[PG_Customer_Category_ID] UNIQUEIDENTIFIER NOT NULL ,
	[PG_Type_ID] INT,
	[PG_Customer_Category_Code] VARCHAR(20),
	[PG_Customer_Category_Name] VARCHAR(50) NOT NULL,
	[Active]  BIT  NOT NULL CONSTRAINT [DF_PG_Customer_Category_Active]  DEFAULT ((1)),
	[Deleted] BIT NOT NULL CONSTRAINT [DF_PG_Customer_Category_Deleted]  DEFAULT ((0)),
	[Created_Date] [datetime]  NOT NULL CONSTRAINT [DF_PG_Customer_Category_Created_Date]  DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	[Created_By] VARCHAR(50),
	[Updated_BY] VARCHAR(50),
	[Include_In_Other_PG] BIT NOT NULL CONSTRAINT [DF_PG_Customer_Category_Include_In_Other_PG]  DEFAULT (0),
	CONSTRAINT [PK_PG_Customer_Category] PRIMARY KEY  CLUSTERED
	(
		[PG_Customer_Category_ID]
	)  ON [PRIMARY]
) ON [PRIMARY]
GO


IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Customer_Category]') AND name = N'IDX_PG_Customer_Category_NC1')

CREATE NONCLUSTERED INDEX IDX_PG_Customer_Category_NC1 ON [PG_Customer_Category]
(
	[PG_Type_ID] ASC,
	[PG_Customer_Category_Name] ASC
)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'PG_Customer_Category'
	AND		COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE PG_Customer_Category ADD [Business_Segment_ID] [int] NOT NULL CONSTRAINT [DF_PG_Customer_Category_Business_Segment_ID]  DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'PG_Customer_Category'
                       AND Column_Name = 'Is_System' )
  ALTER TABLE PG_Customer_Category
    ADD Is_System [BIT] NOT NULL CONSTRAINT [DF_PG_Customer_Category_Is_System] DEFAULT (0)
GO


IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_A_PG_Customer_Category_PG_Customer_Category_ID]') AND type = 'D')
BEGIN
	ALTER TABLE [dbo].[PG_Customer_Category] ADD  CONSTRAINT [DF_A_PG_Customer_Category_PG_Customer_Category_ID]  DEFAULT (newid()) FOR [PG_Customer_Category_ID]
END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Customer_Category'
                       AND Column_Name = 'Is_Master_Group' )
	BEGIN
	  ALTER TABLE PG_Customer_Category
	    ADD [Is_Master_Group] [BIT] NOT NULL CONSTRAINT [DF_PG_Customer_Category_Is_Master_Group] DEFAULT (1)
	END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Customer_Category'
                       AND Column_Name = 'Capture_Removes' )
  ALTER TABLE PG_CUSTOMER_CATEGORY
    ADD [Capture_Removes] [BIT] DEFAULT (0) NOT NULL

GO
		
IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Customer_Category'
                       AND Column_Name = 'vendor_master_id' )
 ALTER TABLE PG_CUSTOMER_CATEGORY
 ADD [vendor_master_id] [uniqueidentifier] NULL
GO


IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Customer_Category'
                       AND Column_Name = 'distributor_id' )
 ALTER TABLE PG_CUSTOMER_CATEGORY
 ADD [distributor_id] [uniqueidentifier] NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Customer_Category'
						AND Column_Name = 'PG_Effective_Date' )
 ALTER TABLE PG_CUSTOMER_CATEGORY ADD [PG_Effective_Date] [datetime] NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Customer_Category'
						AND Column_Name = 'PG_Number_Sequence' )
 ALTER TABLE PG_Customer_Category ADD [PG_Number_Sequence] bigint NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Customer_Category'
						AND Column_Name = 'PG_Effective_Start_Date' )

EXEC sp_RENAME 'PG_Customer_Category.PG_Effective_Date' , 'PG_Effective_Start_Date', 'COLUMN'

GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Customer_Category'
						AND Column_Name = 'PG_Effective_End_Date' )
 ALTER TABLE PG_CUSTOMER_CATEGORY ADD [PG_Effective_End_Date] [datetime] NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PG_CUSTOMER_CATEGORY_DEFINITION.SQL was last modified on 07/15/2019 08:59:49 AM ---
-------------------------------------------------------------------------------------------------------------------------------
--drop table PG_Customer_Category_Definition
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'PG_Customer_Category_Definition'
)
CREATE TABLE [dbo].[PG_Customer_Category_Definition](
	[PG_Customer_Category_Definition_ID] INT IDENTITY (1, 1) NOT NULL ,
	[PG_Customer_Category_ID] VARCHAR(50),
	[PG_Type_ID] INT,
	[Distributor_Group_Level_ID] INT,
	[Distributor_Group_ID] VARCHAR(50),
	[Is_PG] BIT NOT NULL CONSTRAINT [DF_PG_Customer_Category_Definition_Is_PG]  DEFAULT (0),
	[Inclusion_Exclusion] BIT NOT NULL CONSTRAINT [DF_PG_Customer_Category_Definition_Inclusion_Exclusion]  DEFAULT (0),
	[Active]  BIT NOT NULL CONSTRAINT [DF_PG_Customer_Category_Definition_Active]  DEFAULT (1),
	[Deleted] BIT NOT NULL CONSTRAINT [DF_PG_Customer_Category_Definition_Deleted]  DEFAULT (0),
	[Created_Date] [datetime]  NOT NULL CONSTRAINT [DF_PG_Customer_Category_Definition_Created_Date]  DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	[Created_By] VARCHAR(50),
	[Updated_By] VARCHAR(50),
	[Include_In_Other_PG] BIT NOT NULL CONSTRAINT [DF_PG_Customer_Category_Definition_Include_In_Other_PG]  DEFAULT (0),
	CONSTRAINT [PK_PG_Customer_Category_Definition] PRIMARY KEY  CLUSTERED 
	(
		[PG_Customer_Category_Definition_ID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Customer_Category_Definition]') AND name = N'PK_PG_Customer_Category_Definition')
ALTER TABLE [dbo].[PG_Customer_Category_Definition] DROP CONSTRAINT [PK_PG_Customer_Category_Definition]

ALTER TABLE [dbo].[PG_Customer_Category_Definition] ADD  CONSTRAINT [PK_PG_Customer_Category_Definition] PRIMARY KEY NONCLUSTERED 
(
	[PG_Customer_Category_Definition_ID] ASC
)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80, ONLINE = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Customer_Category_Definition]') AND name = N'IDX_PG_Customer_Category_Definition_C')

CREATE CLUSTERED INDEX IDX_PG_Customer_Category_Definition_C ON [PG_Customer_Category_Definition] 
(
	[PG_Customer_Category_ID] ASC,
	[PG_Type_ID] ASC
)
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Customer_Category_Definition]') AND name = N'IDX_PG_Customer_Category_Definition_NC1')

CREATE NONCLUSTERED INDEX IDX_PG_Customer_Category_Definition_NC1 ON [PG_Customer_Category_Definition] 
(	
	[Distributor_Group_Level_ID] ASC,
	[Distributor_Group_ID] ASC)
GO


IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Customer_Category_Definition'
						AND Column_Name = 'PG_Effective_Start_Date' )
 ALTER TABLE PG_Customer_Category_Definition ADD [PG_Effective_Start_Date] [datetime] NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Customer_Category_Definition'
						AND Column_Name = 'PG_Effective_End_Date' )
 ALTER TABLE PG_Customer_Category_Definition ADD [PG_Effective_End_Date] [datetime] NULL
GO



-------------------------------------------------------------------------------------------------------------------------------
--- PG_OPERATOR_CATEGORY.SQL was last modified on 11/26/2018 07:40:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
--drop table PG_Operator_Category
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'PG_Operator_Category'
)
CREATE TABLE [dbo].[PG_Operator_Category](
	[PG_Operator_Category_ID] UNIQUEIDENTIFIER NOT NULL ,
	[PG_Type_ID] INT,
	[PG_Operator_Category_Code] VARCHAR(20),
	[PG_Operator_Category_Name] VARCHAR(50) NOT NULL,
	[Active]  BIT NOT NULL CONSTRAINT [DF_PG_Operator_Category_Active]  DEFAULT (1),
	[Deleted] BIT NOT NULL CONSTRAINT [DF_PG_Operator_Category_Deleted]  DEFAULT (0),
	[Created_Date] [datetime]  NOT NULL CONSTRAINT [DF_PG_Operator_Category_Created_Date]  DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	[Created_By] VARCHAR(50),
	[Updated_By] VARCHAR(50),
	[Include_In_Other_PG] BIT NOT NULL CONSTRAINT [DF_PG_Operator_Category_Include_In_Other_PG]  DEFAULT (0),
	CONSTRAINT [PK_PG_Operator_Category] PRIMARY KEY  CLUSTERED
	(
		[PG_Operator_Category_ID]
	)  ON [PRIMARY]
) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Operator_Category]') AND name = N'IDX_PG_Operator_Category_NC1')

CREATE NONCLUSTERED INDEX IDX_PG_Operator_Category_NC1 ON [PG_Operator_Category]
(
	[PG_Type_ID] ASC,
	[PG_Operator_Category_Name] ASC
)
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'PG_Operator_Category'
                       AND Column_Name = 'Is_System' )
  ALTER TABLE PG_Operator_Category
    ADD Is_System [BIT] NOT NULL CONSTRAINT [DF_PG_Operator_Category_Is_System] DEFAULT (0)

GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE name LIKE 'DF_A_PG_Operator_Category_PG_Operator_Category_ID%' AND type = 'D')
BEGIN
      ALTER TABLE [dbo].[PG_Operator_Category] ADD  CONSTRAINT [DF_A_PG_Operator_Category_PG_Operator_Category_ID]  DEFAULT (newid()) FOR [PG_Operator_Category_ID]
END
GO


IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Operator_Category'
                       AND Column_Name = 'Is_Master_Group' )
	BEGIN
	  ALTER TABLE PG_Operator_Category
	    ADD [Is_Master_Group] [BIT] NOT NULL CONSTRAINT [DF_PG_Operator_Category_Is_Master_Group] DEFAULT (1)
	END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Operator_Category'
                       AND Column_Name = 'Capture_Removes' )
  ALTER TABLE PG_OPERATOR_CATEGORY
    ADD [Capture_Removes] [BIT] DEFAULT (0) NOT NULL

GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_OPERATOR_CATEGORY'
                       AND Column_Name = 'Legacy_ID' )
BEGIN
  ALTER TABLE PG_OPERATOR_CATEGORY
    ADD [Legacy_ID] nvarchar(50) NULL
END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_OPERATOR_CATEGORY'
                       AND Column_Name = 'For_Recapture' )
BEGIN
  ALTER TABLE PG_OPERATOR_CATEGORY
     ADD [For_Recapture] [BIT] NOT NULL CONSTRAINT [DF_PG_Operator_Category_For_Recapture] DEFAULT (0)
END
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_OPERATOR_CATEGORY'
						AND Column_Name = 'PG_Effective_Date' )
 ALTER TABLE PG_OPERATOR_CATEGORY ADD [PG_Effective_Date] [datetime] NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_OPERATOR_CATEGORY'
						AND Column_Name = 'PG_Number_Sequence' )
 ALTER TABLE PG_OPERATOR_CATEGORY ADD [PG_Number_Sequence] bigint NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_OPERATOR_CATEGORY'
						AND Column_Name = 'PG_Effective_Start_Date' )

EXEC sp_RENAME 'PG_OPERATOR_CATEGORY.PG_Effective_Date' , 'PG_Effective_Start_Date', 'COLUMN'

GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_OPERATOR_CATEGORY'
						AND Column_Name = 'PG_Effective_End_Date' )
 ALTER TABLE PG_OPERATOR_CATEGORY ADD [PG_Effective_End_Date] [datetime] NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PG_OPERATOR_CATEGORY_DEFINITION.SQL was last modified on 07/15/2019 08:59:49 AM ---
-------------------------------------------------------------------------------------------------------------------------------
--drop table PG_Operator_Category_Definition
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'PG_Operator_Category_Definition'
)
CREATE TABLE [dbo].[PG_Operator_Category_Definition](
	[PG_Operator_Category_Definition_ID] INT IDENTITY (1, 1) NOT NULL ,
	[PG_Operator_Category_ID] VARCHAR(50),
	[PG_Type_ID] INT,
	[Operator_Group_Level_ID] INT,
	[Operator_Group_ID] VARCHAR(50),
	[Is_PG] Bit NOT NULL CONSTRAINT [DF_PG_Operator_Category_Definition_Is_PG]  DEFAULT (0),
	[Inclusion_Exclusion] BIT  NOT NULL CONSTRAINT [DF_PG_Operator_Category_Definition_Inclusion_Exclusion]  DEFAULT (0),
	[Active]  BIT NOT NULL CONSTRAINT [DF_PG_Operator_Category_Definition_Active]  DEFAULT (1),
	[Deleted] BIT  NOT NULL CONSTRAINT [DF_PG_Operator_Category_Definition_Deleted]  DEFAULT (0),
	[Created_Date] [datetime]   NOT NULL CONSTRAINT [DF_PG_Operator_Category_Definition_Created_Date]  DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	[Created_By] VARCHAR(50),
	[Updated_By] VARCHAR(50),
	[Include_In_Other_PG] BIT NOT NULL CONSTRAINT [DF_PG_Operator_Category_Definition_Include_In_Other_PG]  DEFAULT (0),
	CONSTRAINT [PK_PG_Operator_Category_Definition] PRIMARY KEY  CLUSTERED 
	(
		[PG_Operator_Category_Definition_ID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Operator_Category_Definition]') AND name = N'PK_PG_Operator_Category_Definition')
ALTER TABLE [dbo].[PG_Operator_Category_Definition] DROP CONSTRAINT [PK_PG_Operator_Category_Definition]

ALTER TABLE [dbo].[PG_Operator_Category_Definition] ADD  CONSTRAINT [PK_PG_Operator_Category_Definition] PRIMARY KEY NONCLUSTERED 
(
	[PG_Operator_Category_Definition_ID] ASC
)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80, ONLINE = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Operator_Category_Definition]') AND name = N'IDX_PG_Operator_Category_Definition_C')

CREATE CLUSTERED INDEX IDX_PG_Operator_Category_Definition_C ON [PG_Operator_Category_Definition] 
(
	[PG_Operator_Category_ID] ASC,
	[PG_Type_ID] ASC
)
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Operator_Category_Definition]') AND name = N'IDX_PG_Operator_Category_Definition_NC1')

CREATE NONCLUSTERED INDEX IDX_PG_Operator_Category_Definition_NC1 ON [PG_Operator_Category_Definition] 
(	
	[Operator_Group_Level_ID] ASC,
	[Operator_Group_ID] ASC)
GO


IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Operator_Category_Definition'
						AND Column_Name = 'PG_Effective_Start_Date' )
 ALTER TABLE PG_Operator_Category_Definition ADD [PG_Effective_Start_Date] [datetime] NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Operator_Category_Definition'
						AND Column_Name = 'PG_Effective_End_Date' )
 ALTER TABLE PG_Operator_Category_Definition ADD [PG_Effective_End_Date] [datetime] NULL
GO





 




-------------------------------------------------------------------------------------------------------------------------------
--- PG_PRODUCT_CATEGORY.SQL was last modified on 11/26/2018 07:40:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
--drop table PG_Product_Category
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'PG_Product_Category'
)
CREATE TABLE [dbo].[PG_Product_Category](
	[PG_Product_Category_ID] UNIQUEIDENTIFIER NOT NULL ,
	[PG_Type_ID] INT,
	[PG_Product_Category_Code] VARCHAR(20),
	[PG_Product_Category_Name] VARCHAR(50) NOT NULL,
	[Active]  BIT NOT NULL CONSTRAINT [DF_PG_Product_Category_Active]  DEFAULT (1),
	[Deleted] BIT NOT NULL CONSTRAINT [DF_PG_Product_Category_Deleted]  DEFAULT (0),
	[Created_Date] [datetime]  NOT NULL CONSTRAINT [DF_PG_Product_Category_Created_Date]  DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	[Created_By] VARCHAR(50),
	[Updated_By] VARCHAR(50),
	[Include_In_Other_PG] BIT NOT NULL CONSTRAINT [DF_PG_Product_Category_Include_In_Other_PG]  DEFAULT (0),
	CONSTRAINT [PK_PG_Product_Category] PRIMARY KEY  CLUSTERED
	(
		[PG_Product_Category_ID]
	)  ON [PRIMARY]
) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Product_Category]') AND name = N'IDX_PG_Product_Category_NC1')

CREATE NONCLUSTERED INDEX IDX_PG_Product_Category_NC1 ON [PG_Product_Category]
(
	[PG_Type_ID] ASC,
	[PG_Product_Category_Name] ASC
)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'PG_Product_Category'
	AND		COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE PG_Product_Category ADD [Business_Segment_ID] [int] NOT NULL CONSTRAINT [DF_PG_Product_Category_Business_Segment_ID]  DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'PG_Product_Category'
                       AND Column_Name = 'Is_System' )
  ALTER TABLE PG_Product_Category
    ADD Is_System [BIT] NOT NULL CONSTRAINT [DF_PG_Product_Category_Is_System] DEFAULT (0)

Go


IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_A_PG_Product_Category_PG_Product_Category_ID]') AND type = 'D')
BEGIN
	ALTER TABLE [dbo].[PG_Product_Category] ADD  CONSTRAINT [DF_A_PG_Product_Category_PG_Product_Category_ID]  DEFAULT (newid()) FOR [PG_Product_Category_ID]
END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Product_Category'
                       AND Column_Name = 'Is_Master_Group' )
	BEGIN
	  ALTER TABLE PG_Product_Category
	    ADD [Is_Master_Group] [BIT] NOT NULL CONSTRAINT [DF_PG_Product_Category_Is_Master_Group] DEFAULT (1)
	END
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'PG_Product_Category'
                       AND Column_Name = 'Capture_Removes' )
  ALTER TABLE PG_PRODUCT_CATEGORY
    ADD [Capture_Removes] [BIT] DEFAULT (0) NOT NULL

GO


/* WR: 74279 */
IF EXISTS ( SELECT 1
			FROM Information_Schema.Columns
			WHERE Table_Name = 'PG_Product_Category'
			AND Column_Name = 'PG_Product_Category_Name' )
BEGIN
	ALTER TABLE PG_Product_Category 
	ALTER COLUMN PG_Product_Category_Name VARCHAR(255)
END

GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Product_Category'
						AND Column_Name = 'PG_Effective_Date' )
 ALTER TABLE PG_Product_Category ADD [PG_Effective_Date] [datetime] NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Product_Category'
						AND Column_Name = 'PG_Number_Sequence' )
 ALTER TABLE PG_Product_Category ADD [PG_Number_Sequence] bigint NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Product_Category'
						AND Column_Name = 'PG_Effective_Start_Date' )

EXEC sp_RENAME 'PG_Product_Category.PG_Effective_Date' , 'PG_Effective_Start_Date', 'COLUMN'

GO
IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Product_Category'
						AND Column_Name = 'PG_Effective_End_Date' )
 ALTER TABLE PG_Product_Category ADD [PG_Effective_End_Date] [datetime] NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PG_PRODUCT_CATEGORY_DEFINITION.SQL was last modified on 07/15/2019 08:59:49 AM ---
-------------------------------------------------------------------------------------------------------------------------------
--drop table PG_Product_Category_Definition
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'PG_Product_Category_Definition'
)
CREATE TABLE [dbo].[PG_Product_Category_Definition](
	[PG_Product_Category_Definition_ID] INT IDENTITY (1, 1) NOT NULL ,
	[PG_Product_Category_ID] VARCHAR(50),
	[PG_Type_ID] INT,
	[Product_Group_Level_ID] INT,
	[Product_Group_ID] VARCHAR(50),
	[Is_PG] Bit NOT NULL CONSTRAINT [DF_PG_Product_Category_Definition_Is_PG]  DEFAULT (0),
	[Inclusion_Exclusion] BIT NOT NULL CONSTRAINT [DF_PG_Product_Category_Definition_Inclusion_Exclusion]  DEFAULT (0),	
	[Active]  BIT NOT NULL CONSTRAINT [DF_PG_Product_Category_Definition_Active]  DEFAULT (1),	
	[Deleted] BIT NOT NULL CONSTRAINT [DF_PG_Product_Category_Definition_Deleted]  DEFAULT (0),
	[Created_Date] [datetime]  NOT NULL CONSTRAINT [DF_PG_Product_Category_Definition_Created_Date]  DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	[Created_By] VARCHAR(50),
	[Updated_By] VARCHAR(50),
	[Include_In_Other_PG] BIT NOT NULL CONSTRAINT [DF_PG_Product_Category_Definition_Include_In_Other_PG]  DEFAULT (0),
	CONSTRAINT [PK_PG_Product_Category_Definition] PRIMARY KEY  CLUSTERED 
	(
		[PG_Product_Category_Definition_ID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Product_Category_Definition]') AND name = N'PK_PG_Product_Category_Definition')
ALTER TABLE [dbo].[PG_Product_Category_Definition] DROP CONSTRAINT [PK_PG_Product_Category_Definition]

ALTER TABLE [dbo].[PG_Product_Category_Definition] ADD  CONSTRAINT [PK_PG_Product_Category_Definition] PRIMARY KEY NONCLUSTERED 
(
	[PG_Product_Category_Definition_ID] ASC
)WITH (PAD_INDEX  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80, ONLINE = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Product_Category_Definition]') AND name = N'IDX_PG_Product_Category_Definition_C')

CREATE CLUSTERED INDEX IDX_PG_Product_Category_Definition_C ON [PG_Product_Category_Definition] 
(
	[PG_Product_Category_ID] ASC,
	[PG_Type_ID] ASC
)
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[PG_Product_Category_Definition]') AND name = N'IDX_PG_Product_Category_Definition_NC1')

CREATE NONCLUSTERED INDEX IDX_PG_Product_Category_Definition_NC1 ON [PG_Product_Category_Definition] 
(	
	[Product_Group_Level_ID] ASC,
	[Product_Group_ID] ASC)
GO


IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Product_Category_Definition'
						AND Column_Name = 'PG_Effective_Start_Date' )
 ALTER TABLE PG_Product_Category_Definition ADD [PG_Effective_Start_Date] [datetime] NULL
GO

IF NOT EXISTS (  SELECT 1
						FROM INFORMATION_SCHEMA.Columns
						WHERE Table_Name = 'PG_Product_Category_Definition'
						AND Column_Name = 'PG_Effective_End_Date' )
 ALTER TABLE PG_Product_Category_Definition ADD [PG_Effective_End_Date] [datetime] NULL
GO

-------------------------------------------------------------------------------------------------------------------------------
--- PLANNER_DEMAND_PLAN.SQL was last modified on 07/09/2019 02:10:28 PM ---
-------------------------------------------------------------------------------------------------------------------------------
-- 77432 - Demand Planning interface
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Planner_Demand_Plan]') AND type in (N'U'))
BEGIN
	SET QUOTED_IDENTIFIER ON

	CREATE TABLE Planner_Demand_Plan
	(
		Planner_Demand_Plan_ID INT IDENTITY(1,1) NOT NULL,
		Planner_Week_ID INT NOT NULL, 
		Distributor_ID UNIQUEIDENTIFIER NOT NULL,
		Product_ID UNIQUEIDENTIFIER NOT NULL,
		Demand_Plan_CS DECIMAL(20,2),
		Demand_Plan_LBS DECIMAL(20,4),
		Created_Date DATETIME NOT NULL DEFAULT GETDATE(),
		Updated_Date DATETIME,
		CONSTRAINT FK_Planner_Demand_Plan_Planner_Week_ID FOREIGN KEY (Planner_Week_ID) REFERENCES Planner_Week(Planner_Week_ID),
		CONSTRAINT [PK_Planner_Demand_Plan_ID] PRIMARY KEY CLUSTERED 
		(
			[Planner_Week_ID] ASC, [Distributor_ID] ASC, [Product_ID] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PLANNER_PERF_TYPES.SQL was last modified on 08/19/2019 09:04:38 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table dbo.Planner_Perf_Types    Script Date: 2/26/2016 4:38:23 PM ******/
IF NOT EXISTS
       (SELECT *
        FROM   sys.Objects
        WHERE  Object_Id = Object_id(N'dbo.Planner_Perf_Types')
           AND Type IN ( N'U' ))
  BEGIN
      CREATE TABLE dbo.Planner_Perf_Types
        (
           Planner_Perf_Types_ID INT IDENTITY(1, 1) NOT NULL,
           Description           VARCHAR(50) NULL,
           Sort_Order            INT NULL,
           Color                 VARCHAR(20) NULL,
           Active                BIT NOT NULL,
           Deleted               BIT NOT NULL,
           Created_Date          DATETIME NOT NULL,
           Created_By            NVARCHAR(50) NULL,
           Updated_Date          DATETIME NOT NULL,
           Updated_By            NVARCHAR(50) NULL,
           CONSTRAINT PK_Planner_Perf_Types PRIMARY KEY CLUSTERED ( Planner_Perf_Types_ID ASC )
		   WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
        )
      ON [PRIMARY]

      ALTER TABLE dbo.Planner_Perf_Types ADD CONSTRAINT DF_Planner_Perf_Types_Active DEFAULT 1 FOR Active

      ALTER TABLE dbo.Planner_Perf_Types ADD CONSTRAINT DF_Planner_Perf_Types_Deleted DEFAULT 0 FOR Deleted

      ALTER TABLE dbo.Planner_Perf_Types ADD CONSTRAINT DF_Planner_Perf_Types_Created_Date DEFAULT Getdate() FOR Created_Date

      ALTER TABLE dbo.Planner_Perf_Types ADD CONSTRAINT DF_Planner_Perf_Types_Updated_Date DEFAULT Getdate() FOR Updated_Date
  END

GO 


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Perf_Types'
		AND
		COLUMN_NAME = 'Everyday_Price'
)
ALTER TABLE Planner_Perf_Types ADD [Everyday_Price] [int] NOT NULL DEFAULT(0)

GO

-- Retail 161 Slotting payback calculation
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Perf_Types'
		AND
		COLUMN_NAME = 'Slotting'
)
ALTER TABLE Planner_Perf_Types ADD [Slotting] [bit] NOT NULL DEFAULT(0)

GO

-- 73626 Retail Planner - Design - Sprint 13
-- Retail 329 Auto generate Accrual program

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Perf_Types'
		AND
		COLUMN_NAME = 'Accrual'
)
ALTER TABLE Planner_Perf_Types ADD [Accrual] [bit] NOT NULL DEFAULT(0)

GO
----------------------------
--  86658 for ButterBall  --
----------------------------
IF NOT EXISTS (   SELECT        *
                        FROM    INFORMATION_SCHEMA.COLUMNS
                       WHERE    TABLE_NAME  = 'Planner_Perf_Types'
                         AND    COLUMN_NAME = 'Allow_Duplicate_Programs' )
    ALTER TABLE Planner_Perf_Types ADD [Allow_Duplicate_Programs] [BIT] NOT NULL DEFAULT (0)
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PLANNER_PROFILES_SETTINGS.SQL was last modified on 08/05/2019 10:53:46 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Planner_Profiles_Settings]    Script Date: 02/25/2016 ******/
IF NOT EXISTS
		(	SELECT *
			FROM   sys.Objects
			WHERE  Object_ID = Object_id(N'[dbo].[Planner_Profiles_Settings]')
			AND Type IN ( N'U' )
		)
  BEGIN
		CREATE TABLE dbo.Planner_Profiles_Settings
        (
           Planner_Profiles_Settings_ID INT NOT NULL IDENTITY (1, 1),
           Profiles_ID                  INT NOT NULL,
           Deleted                      BIT NOT NULL,
           Updated_Date                 DATETIME NOT NULL,
           Updated_By                   NVARCHAR(50) NULL,
           Planner_Create               INT NOT NULL,
           Planner_Margin_View          BIT NOT NULL,
           Planner_Approval_Rights      BIT NOT NULL,
           Marketing_Events_Create      INT NOT NULL,
           Planner_Product_Calendar     BIT NOT NULL,
           Planner_Strategic_Guidelines BIT NOT NULL,
           NUC_Targets_Create           INT NOT NULL,
           CONSTRAINT [PK_Planner_Profiles_Settings] PRIMARY KEY CLUSTERED ( [Planner_Profiles_Settings_ID] ASC )
		   WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
		) ON [PRIMARY]
        

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Deleted DEFAULT 0 FOR Deleted

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Updated_Date DEFAULT Getdate() FOR Updated_Date

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Planner_Create DEFAULT 0 FOR Planner_Create

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Planner_Margin_View DEFAULT 0 FOR Planner_Margin_View

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Planner_Approval_Rights DEFAULT 0 FOR Planner_Approval_Rights

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Marketing_Events_Create DEFAULT 0 FOR Marketing_Events_Create

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Planner_Product_Calendar DEFAULT 0 FOR Planner_Product_Calendar

		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_Planner_Strategic_Guidelines DEFAULT 0 FOR Planner_Strategic_Guidelines
		
		ALTER TABLE dbo.Planner_Profiles_Settings ADD CONSTRAINT DF_Planner_Profiles_Settings_NUC_Targets_Create DEFAULT 0 FOR NUC_Targets_Create


  END
GO

IF NOT EXISTS ( SELECT * 
                  FROM INFORMATION_SCHEMA.COLUMNS 
                 WHERE TABLE_NAME = 'Planner_Profiles_Settings' AND COLUMN_NAME = 'Planner_Reassign' )
    ALTER TABLE dbo.Planner_Profiles_Settings 
        ADD Planner_Reassign [bit] NOT NULL CONSTRAINT [DF_Planner_Profiles_Settings_Planner_Reassign] DEFAULT (0)
GO 

-- D72955 Retail Planner - Design - Sprint 11
-- Retail 302 Catalog access
IF NOT EXISTS ( SELECT * 
                  FROM INFORMATION_SCHEMA.COLUMNS 
                 WHERE TABLE_NAME = 'Planner_Profiles_Settings' AND COLUMN_NAME = 'Planner_Catalog' )
    ALTER TABLE dbo.Planner_Profiles_Settings 
        ADD Planner_Catalog [bit] NOT NULL CONSTRAINT [DF_Planner_Profiles_Settings_Planner_Catalog] DEFAULT (0)
GO 

-- 86659 Planner approvals - Max total spend
IF NOT EXISTS ( SELECT * 
                  FROM INFORMATION_SCHEMA.COLUMNS 
                 WHERE TABLE_NAME = 'Planner_Profiles_Settings' AND COLUMN_NAME = 'Planner_Max_Total_Spend' )
    ALTER TABLE dbo.Planner_Profiles_Settings 
        ADD Planner_Max_Total_Spend [varchar](50) NOT NULL CONSTRAINT [DF_Planner_Profiles_Settings_Planner_Max_Total_Spend] DEFAULT ('0')
GO 


-------------------------------------------------------------------------------------------------------------------------------
--- PLANNER_PROGRAM_COPY_LOG.SQL was last modified on 09/10/2019 07:45:33 AM ---
-------------------------------------------------------------------------------------------------------------------------------
-- 70052 Retail Planner - Design - Sprint 5 - Retail 140 Copy Planner - different customer
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Planner_Program_Copy_Log'
)
CREATE TABLE [dbo].[Planner_Program_Copy_Log](
	Planner_Program_Copy_Log_ID		INT NOT NULL IDENTITY (1, 1),
	Planner_Program_Copy_Batch_ID	INT NOT NULL,
	To_Planner_ID					INT NOT NULL,
	From_Planner_ID					INT NOT NULL,
	From_Program_ID					INT NOT NULL,
	New_Program_ID					INT NULL,
	User_ID							NVARCHAR(50) NULL,
	Import_Type						INT NOT NULL CONSTRAINT [DF_Planner_Program_Copy_Log_Import_Type]  DEFAULT (1),
	Deleted							BIT NOT NULL CONSTRAINT [DF_Planner_Program_Copy_Log_Deleted]  DEFAULT (0),
	Created_Date					DATETIME NOT NULL CONSTRAINT [DF_Planner_Program_Copy_Log_Created_Date]  DEFAULT (getdate()),
	Processed						BIT NOT NULL CONSTRAINT [DF_Planner_Program_Copy_Log_Processed]  DEFAULT (0),
	Process_Start_Date				DATETIME NULL,
	Process_End_Date				DATETIME NULL,
	CONSTRAINT PK_Planner_Program_Copy_Log PRIMARY KEY CLUSTERED ( Planner_Program_Copy_Log_ID ASC )
		   WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

-- 88795 - Copy planner to new year
IF NOT EXISTS
(
  SELECT *
  FROM   SysObjects O
		 INNER JOIN SysColumns C
			 ON O.ID = C.ID
  WHERE  OBJECTPROPERTY(O.ID, 'IsUserTable') = 1
		 AND O.Name = 'Planner_Program_Copy_Log'
		 AND C.Name = 'Import_Type'
)
	ALTER TABLE [dbo].[Planner_Program_Copy_Log]
	ADD [Import_Type] [INT] NOT NULL,
		CONSTRAINT [DF_Planner_Program_Copy_Log_Import_Type] DEFAULT(1) FOR [Import_Type]
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PLANNER_TEMPLATE.SQL was last modified on 07/15/2019 08:59:49 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table dbo.Planner_Template    Script Date: 3/1/2016  ******/
IF NOT EXISTS
       (SELECT *
        FROM   sys.Objects
        WHERE  Object_ID = Object_ID(N'dbo.Planner_Template')
           AND Type IN ( N'U' ))
  BEGIN
      CREATE TABLE dbo.Planner_Template
        (
           Planner_Template_ID             INT NOT NULL IDENTITY (1, 1),
           Planner_Type                    NVARCHAR(50) NULL,
           Planner_Description             NVARCHAR(255) NULL,
           Planner_Start_Date              DATETIME NULL,
           Planner_End_Date                DATETIME NULL,
           Planner_Status_ID               INT NULL,
           Retroactive_Planner             BIT NOT NULL,
           Retroactive_Planner_Days        VARCHAR(10) NULL,
           Retroactive_Revision            BIT NOT NULL,
           Retroactive_Revision_Days       VARCHAR(10) NULL,
           UOM_CS                          BIT NOT NULL,
           UOM_LB                          BIT NOT NULL,
           UOM_EA                          BIT NOT NULL,
           UOM_Default                     INT NULL,
           Net_Sales_Display               BIT NOT NULL,
           Trade_Display                   BIT NOT NULL,
           Margin_Display                  BIT NOT NULL,
           NUC_Display                     BIT NOT NULL,
		   PY_Summary_Display              BIT NOT NULL,
           AOP_Display                     BIT NOT NULL,
           AOP_Default                     BIT NOT NULL,
           Prior_Yr_Display                BIT NOT NULL,
           Prior_Yr_Default                BIT NOT NULL,
           Forecast_Display                BIT NOT NULL,
           Forecast_Default                BIT NOT NULL,
           Forecast_Percent_PY_Display     BIT NOT NULL,
           Forecast_Percent_PY_Default     BIT NOT NULL,
           Actual_Display                  BIT NOT NULL,
           Actual_Default                  BIT NOT NULL,
           Actual_Percent_Forecast_Display BIT NOT NULL,
           Actual_Percent_Forecast_Default BIT NOT NULL,
           Deleted                         BIT NOT NULL,
           Active                          BIT NOT NULL,
           Created_Date                    DATETIME NOT NULL,
           Created_By                      NVARCHAR(50) NULL,
           Updated_Date                    DATETIME NOT NULL,
           Updated_By                      NVARCHAR(50) NULL,
		   Business_Segment_ID INT NULL 
           CONSTRAINT PK_Planner_Template PRIMARY KEY CLUSTERED ( Planner_Template_ID ASC )
		   WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
        )
      ON [PRIMARY]

	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Retroactive_Planner DEFAULT 0 FOR Retroactive_Planner
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Retroactive_Revision DEFAULT 0 FOR Retroactive_Revision
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_UOM_CS DEFAULT 0 FOR UOM_CS
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_UOM_LB DEFAULT 0 FOR UOM_LB
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_UOM_EA DEFAULT 0 FOR UOM_EA
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_UOM_Default DEFAULT 0 FOR UOM_Default
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Net_Sales_Display DEFAULT 0 FOR Net_Sales_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Trade_Display DEFAULT 0 FOR Trade_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Margin_Display DEFAULT 0 FOR Margin_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_NUC_Display DEFAULT 0 FOR NUC_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_PY_Summary_Display DEFAULT 0 FOR PY_Summary_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_AOP_Display DEFAULT 0 FOR AOP_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_AOP_Default DEFAULT 0 FOR AOP_Default
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Prior_YR_Display DEFAULT 0 FOR Prior_YR_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Prior_YR_Default DEFAULT 0 FOR Prior_YR_Default
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Forecast_Display DEFAULT 0 FOR Forecast_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Forecast_Default DEFAULT 0 FOR Forecast_Default
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Forecast_Percent_PY_Display DEFAULT 0 FOR Forecast_Percent_PY_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Forecast_Percent_PY_Default DEFAULT 0 FOR Forecast_Percent_PY_Default
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Actual_Display DEFAULT 0 FOR Actual_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Actual_Default DEFAULT 0 FOR Actual_Default
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Actual_Percent_Forecast_Display DEFAULT 0 FOR Actual_Percent_Forecast_Display
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Actual_Percent_Forecast_Default DEFAULT 0 FOR Actual_Percent_Forecast_Default
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Deleted DEFAULT 0 FOR Deleted
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Active DEFAULT 0 FOR Active
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Created_Date DEFAULT Getdate() FOR Created_Date
	ALTER TABLE dbo.Planner_Template ADD CONSTRAINT DF_Planner_Template_Updated_Date DEFAULT Getdate() FOR Updated_Date
END

GO

IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Planner_Template' AND COLUMN_NAME = 'AOP_Default')
	ALTER TABLE dbo.Planner_Template ADD AOP_Default BIT NOT NULL CONSTRAINT DF_Planner_Template_AOP_Default  DEFAULT (0)
GO
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Planner_Template' AND COLUMN_NAME = 'Prior_YR_Default')
	ALTER TABLE dbo.Planner_Template ADD Prior_YR_Default BIT NOT NULL CONSTRAINT DF_Planner_Template_Prior_YR_Default  DEFAULT (0)
GO
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Planner_Template' AND COLUMN_NAME = 'Forecast_Default')
	ALTER TABLE dbo.Planner_Template ADD Forecast_Default BIT NOT NULL CONSTRAINT DF_Planner_Template_Forecast_Default  DEFAULT (0)
GO
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Planner_Template' AND COLUMN_NAME = 'Forecast_Percent_PY_Default')
	ALTER TABLE dbo.Planner_Template ADD Forecast_Percent_PY_Default BIT NOT NULL CONSTRAINT DF_Planner_Template_Forecast_Percent_PY_Default  DEFAULT (0)
GO
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Planner_Template' AND COLUMN_NAME = 'Actual_Default')
	ALTER TABLE dbo.Planner_Template ADD Actual_Default BIT NOT NULL CONSTRAINT DF_Planner_Template_Actual_Default  DEFAULT (0)
GO
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Planner_Template' AND COLUMN_NAME = 'Actual_Percent_Forecast_Default')
	ALTER TABLE dbo.Planner_Template ADD Actual_Percent_Forecast_Default BIT NOT NULL CONSTRAINT DF_Planner_Template_Actual_Percent_Forecast_Default  DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Locked_Forecast_Default' )
    ALTER TABLE Planner_Template ADD Locked_Forecast_Default [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Locked_Forecast_Default] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Locked_Forecast_Display' )
    ALTER TABLE Planner_Template ADD Locked_Forecast_Display [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Locked_Forecast_Display] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Price_List_Header_ID' )
	ALTER TABLE Planner_Template ADD [Price_List_Header_ID] uniqueidentifier NULL
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Program_Default_UOM' )
	ALTER TABLE Planner_Template ADD Program_Default_UOM int NOT NULL CONSTRAINT [DF_Planner_Template_Program_Default_UOM] DEFAULT (2)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'PY_Summary_Display' )
	ALTER TABLE Planner_Template ADD PY_Summary_Display [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_PY_Summary_Display] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Planner_Output_Setting_Config_ID' )
	ALTER TABLE Planner_Template ADD Planner_Output_Setting_Config_ID [INT] NULL
GO

-- 72194 Retail Planner - Design - Sprint 9
-- Retail 247 Planner Template Settings updates for Indirect planners

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Wholesaler_Planner' )
	ALTER TABLE Planner_Template ADD Wholesaler_Planner [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Wholesaler_Planner] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Indirect_Volume_Display' )
    ALTER TABLE Planner_Template ADD Indirect_Volume_Display [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Indirect_Volume_Display] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Indirect_Volume_Default' )
    ALTER TABLE Planner_Template ADD Indirect_Volume_Default [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Indirect_Volume_Default] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Indirect_Volume_Percent_Forecast_Display' )
    ALTER TABLE Planner_Template ADD Indirect_Volume_Percent_Forecast_Display [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Indirect_Volume_Percent_Forecast_Display] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Indirect_Volume_Percent_Forecast_Default' )
    ALTER TABLE Planner_Template ADD Indirect_Volume_Percent_Forecast_Default [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Indirect_Volume_Percent_Forecast_Default] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Indirect_Product_Source' )
    ALTER TABLE Planner_Template ADD Indirect_Product_Source [TINYINT] NOT NULL CONSTRAINT [DF_Planner_Template_Indirect_Product_Source] DEFAULT (1)
GO

-- 72628 Retail Planner - Design - Sprint 10
-- Retail 268 Duplicate check planners

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Check_Duplicate_Planner' )
    ALTER TABLE Planner_Template ADD Check_Duplicate_Planner [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Check_Duplicate_Planner] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Check_Duplicate_Planner_Action' )
    ALTER TABLE Planner_Template ADD Check_Duplicate_Planner_Action [TINYINT] NOT NULL CONSTRAINT [DF_Planner_Template_Check_Duplicate_Planner_Action] DEFAULT (1)
GO

-- 72955 Retail Planner - Design - Sprint 11
-- Retail 302 Catalog access

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Include_In_Catalog' )
    ALTER TABLE Planner_Template ADD Include_In_Catalog [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Include_In_Catalog] DEFAULT (0)
GO

-- 73626 Retail Planner - Design - Sprint 13
-- Retail 329 Auto generate Accrual program

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Auto_Generate_Accrual_Program' )
    ALTER TABLE Planner_Template ADD Auto_Generate_Accrual_Program [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Auto_Generate_Accrual_Program] DEFAULT (0)
GO

-- 73626 - Retail Planner - Design - Sprint 13
-- RETAIL-203 Alert Template Settings

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Alert_RFA_Programs' )
    ALTER TABLE Planner_Template ADD Alert_RFA_Programs [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Alert_RFA_Programs] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Alert_RFA_Programs_Days' )
    ALTER TABLE Planner_Template ADD Alert_RFA_Programs_Days [TINYINT] NULL 
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Alert_Pending_Accept_Programs' )
    ALTER TABLE Planner_Template ADD Alert_Pending_Accept_Programs [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Alert_Pending_Accept_Programs] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Alert_Pending_Accept_Programs_Days' )
    ALTER TABLE Planner_Template ADD Alert_Pending_Accept_Programs_Days [TINYINT] NULL 
GO


-- 77432, 86955 - Planner Volume Plan - update for Demand Plan

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Demand_Plan_Display' )
    ALTER TABLE Planner_Template ADD Demand_Plan_Display [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Demand_Plan_Display] DEFAULT (0) 
GO

IF NOT EXISTS ( SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNS.TABLE_NAME = 'Planner_Template' AND COLUMNS.COLUMN_NAME = 'Demand_Plan_Default' )
    ALTER TABLE Planner_Template ADD Demand_Plan_Default [BIT] NOT NULL CONSTRAINT [DF_Planner_Template_Demand_Plan_Default] DEFAULT (0) 
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PLANNER_VOLUME_PLAN.SQL was last modified on 07/15/2019 08:59:49 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Planner_Volume_Plan]') AND type in (N'U'))
-- DROP TABLE [Planner_Volume_Plan]
BEGIN
	SET QUOTED_IDENTIFIER ON

	CREATE TABLE Planner_Volume_Plan
	(
		Planner_Volume_Plan_ID INT IDENTITY(1,1) NOT NULL,
		BSA_Foodservice_Customers_ID UNIQUEIDENTIFIER NOT NULL,
		BSA_Foodservice_Items_Master_ID UNIQUEIDENTIFIER NOT NULL,
		Planner_Week_ID INT NOT NULL, 
		AOP_CS DECIMAL(20,2),
		AOP_LBS DECIMAL(20,4),
		Prior_Year_CS DECIMAL(20,2),
		Prior_Year_LBS DECIMAL(20,4),
		Forecast_CS DECIMAL(20,2),
		Forecast_LBS DECIMAL(20,4),
		Forecast_Base_CS DECIMAL(20,2),
		Forecast_Base_LBS DECIMAL(20,4),
		Forecast_Lift_CS DECIMAL(20,2),
		Forecast_Lift_LBS DECIMAL(20,4),
		Locked_CS DECIMAL(20,2),
		Locked_LBS DECIMAL(20,4),
		Locked_Base_CS DECIMAL(20,2),
		Locked_Base_LBS DECIMAL(20,4),
		Locked_Lift_CS DECIMAL(20,2),
		Locked_Lift_LBS DECIMAL(20,4),		
		Actual_CS DECIMAL(20,2),
		Actual_LBS DECIMAL(20,4),
		Forecast_Percent_Prior_Year_CS INT,
		Forecast_Percent_Prior_Year_LBS INT,
		Actual_Percent_Forecast_CS INT,
		Actual_Percent_Forecast_LBS INT,
		Forecast_Updated BIT,
		Created_Date DATETIME NOT NULL DEFAULT GETDATE(),
		Updated_Date DATETIME,
		CONSTRAINT fk_Planner_Week_ID FOREIGN KEY (Planner_Week_ID) REFERENCES Planner_Week(Planner_Week_ID),
		CONSTRAINT [PK_Planner_Volume_Plan_ID] PRIMARY KEY CLUSTERED 
		(
			[Planner_Week_ID] ASC, [BSA_Foodservice_Customers_ID] ASC, [BSA_Foodservice_Items_Master_ID] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]
END
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Locked_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Locked_CS DECIMAL(20,4)		
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Locked_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Locked_LBS DECIMAL(20,4)		
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Forecast_Base_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Forecast_Base_CS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Forecast_Base_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Forecast_Base_LBS  DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Forecast_Lift_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Forecast_Lift_CS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Forecast_Lift_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Forecast_Lift_LBS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Locked_Base_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Locked_Base_CS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Locked_Base_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Locked_Base_LBS  DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Locked_Lift_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Locked_Lift_CS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Locked_Lift_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Locked_Lift_LBS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Prior_Year_Dollar'
)
ALTER TABLE Planner_Volume_Plan ADD Prior_Year_Dollar DECIMAL(20,2)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Actual_Dollar'
)
ALTER TABLE Planner_Volume_Plan ADD Actual_Dollar DECIMAL(20,2)
GO


-- 72194 Retail Planner - Design - Sprint 9
-- Retail 201 Volume Plan - Add Indirect Volume

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Indirect_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Indirect_CS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Indirect_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Indirect_LBS DECIMAL(20,4)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Indirect_Percent_Forecast_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Indirect_Percent_Forecast_CS INT
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Indirect_Percent_Forecast_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Indirect_Percent_Forecast_LBS INT
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Prior_Year_Program_Perf_Type_ID'
)
ALTER TABLE Planner_Volume_Plan ADD Prior_Year_Program_Perf_Type_ID INT
GO

/*

77432 - Demand Planning interface
86955 - Planner Volume Plan - update for Demand Plan
86956 - Planner Volume Plan - Application settings to drive source for Latest Plan
*/
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Demand_Plan_CS'
)
ALTER TABLE Planner_Volume_Plan ADD Demand_Plan_CS INT
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Planner_Volume_Plan'
		AND COLUMN_NAME = 'Demand_Plan_LBS'
)
ALTER TABLE Planner_Volume_Plan ADD Demand_Plan_LBS INT
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PRICE_LIST_DETAIL_DELETED.SQL was last modified on 11/26/2018 07:40:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Price_List_Detail_Deleted]') AND type in (N'U'))
CREATE TABLE [dbo].[Price_List_Detail_Deleted](
	[Price_List_Detail_Deleted_ID] [int] IDENTITY(1,1) NOT NULL,
	[Price_List_Detail_ID] [uniqueidentifier] NULL,
	[Price_List_Header_ID] [uniqueidentifier] NULL,
	[Price_List_ID] [char](7) NULL,
	[Item_Number] [nvarchar](15) NULL,
	[Item_UPC_Number] [nvarchar](35) NULL,
	[Start_Date] [datetime] NULL,
	[End_Date] [datetime] NULL,
	[Unit_Of_Measure] [char](2) NULL,
	[Price] [nvarchar](14) NULL,
	[Unit_Of_Measure_ID] [int] NULL,
	[Case_Unit_Of_Measure_ID] [int] NULL,
	[Price_Err] [nvarchar](50) NULL,
	[Mkt_Flt] [nvarchar](50) NULL,
	[Active_Code] [char](1) NULL,
	[Created_Date] [datetime] NULL,
	[Updated_Date] [datetime] NULL,
	[Deleted] [bit] NULL,
	[LB_Bracket_1] [nvarchar](50) NULL,
	[LB_Bracket_2] [nvarchar](50) NULL,
	[LB_Bracket_3] [nvarchar](50) NULL,
	[LB_Bracket_4] [nvarchar](50) NULL,
	[LB_Bracket_5] [nvarchar](50) NULL,
	[CS_Bracket_1] [nvarchar](50) NULL,
	[CS_Bracket_2] [nvarchar](50) NULL,
	[CS_Bracket_3] [nvarchar](50) NULL,
	[CS_Bracket_4] [nvarchar](50) NULL,
	[CS_Bracket_5] [nvarchar](50) NULL,
	[LB_Bracket_AVG] [nvarchar](50) NULL,
	[CS_Bracket_AVG] [nvarchar](50) NULL,
	[LB_FOB_Price] [nvarchar](50) NULL,
	[CS_FOB_Price] [nvarchar](50) NULL,
	[LB_FOB_Price_AVG] [nvarchar](50) NULL,
	[CS_FOB_Price_AVG] [nvarchar](50) NULL,
	[Total_LB_Bracket_AVG] [nvarchar](50) NULL,
	[Total_CS_Bracket_AVG] [nvarchar](50) NULL,
	[Product_ID] [uniqueidentifier] NULL,
	[Day_Check] [int] NULL,
	[Log_Check] [int] NULL,
	[Weekly_Check] [int] NULL,
	[Price_Structure_Code] [varchar](50) NULL,
	[FOB_Indicator] [varchar](50) NULL,
	[Facility_Code_1] [varchar](50) NULL,
	[Facility_Code_2] [varchar](50) NULL,
	[Facility_Code_3] [varchar](50) NULL,
	[Facility_Code_4] [varchar](50) NULL,
	[Facility_Code_5] [varchar](50) NULL,
	[Facility_Code_6] [varchar](50) NULL,
	[SBD_1] [varchar](50) NULL,
	[SBD_2] [varchar](50) NULL,
	[SBD_3] [varchar](50) NULL,
	[SBD_4] [varchar](50) NULL,
	[SBD_5] [varchar](50) NULL,
	[SBD_6] [varchar](50) NULL,
	[SBD_7] [varchar](50) NULL,
	[SBD_8] [varchar](50) NULL,
	[Business_Segment_ID] [int] NULL,
	[Condition_Record] [varchar](50) NULL,
	[Deleted_Date] [datetime] NULL,
 CONSTRAINT [PK_Price_List_Detail_Deleted] PRIMARY KEY CLUSTERED 
(
	[Price_List_Detail_Deleted_Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY] 
GO

IF EXISTS ( SELECT 1 FROM Information_Schema.Columns WHERE Table_Name = 'Price_List_Detail_Deleted' AND Column_Name = 'Price_List_ID' )
  ALTER TABLE Price_List_Detail_Deleted ALTER COLUMN Price_List_ID NVARCHAR(50)
GO

IF EXISTS ( SELECT 1 FROM Information_Schema.Columns WHERE Table_Name = 'Price_List_Detail_Deleted' AND Column_Name = 'Item_Number' )
  ALTER TABLE Price_List_Detail_Deleted ALTER COLUMN Item_Number NVARCHAR(50)
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PRICE_LIST_HEADER.SQL was last modified on 03/25/2019 09:09:39 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Price_List_Header'
)

CREATE TABLE [dbo].[Price_List_Header](
	[Price_List_Header_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Price_List_Header_Price_List_Header_ID]  DEFAULT (newid()),
	[Price_List_ID] [char](7) NULL,
	[Price_List_Description] [nvarchar](50) NULL,
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Price_List_Header_Created_Date]  DEFAULT (getdate()),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Price_List_Header_Deleted]  DEFAULT (0),
	[Brkt_1_Lo] [nvarchar](50) NULL,
	[Brkt_1_Hi] [nvarchar](50) NULL,
	[Brkt_2_Lo] [nvarchar](50) NULL,
	[Brkt_2_Hi] [nvarchar](50) NULL,
	[Brkt_3_Lo] [nvarchar](50) NULL,
	[Brkt_3_Hi] [nvarchar](50) NULL,
	[Brkt_4_Lo] [nvarchar](50) NULL,
	[Brkt_4_Hi] [nvarchar](50) NULL,
	[Brkt_5_Lo] [nvarchar](50) NULL,
	[Brkt_5_Hi] [nvarchar](50) NULL,
	[Update_Flag] [char](1) NULL,
 CONSTRAINT [PK_Price_List_Header] PRIMARY KEY CLUSTERED 
(
	[Price_List_Header_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO

IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Price_List_Header]') AND name = N'IX_Price_List_Header_Price_List_ID')
DROP INDEX Price_List_Header.IX_Price_List_Header_Price_List_ID
GO

IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Price_List_Header'
	AND		COLUMN_NAME = 'Price_List_ID'
)
ALTER TABLE Price_List_Header ALTER COLUMN Price_List_ID VARCHAR(50)
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Price_List_Header]') AND name = N'IX_Price_List_Header_Price_List_ID')

CREATE NONCLUSTERED INDEX IX_Price_List_Header_Price_List_ID ON [Price_List_Header]
(
	Price_List_ID ASC
)
GO

-- D82364 Clorox 3100 GPO Price List

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Price_List_Header'
	AND		COLUMN_NAME = 'GPO_Key'
)
ALTER TABLE Price_List_Header ADD GPO_Key VARCHAR(50)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Price_List_Header'
	AND		COLUMN_NAME = 'GPO_Name'
)
ALTER TABLE Price_List_Header ADD GPO_Name VARCHAR(100)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Price_List_Header'
	AND		COLUMN_NAME = 'Tier'
)
ALTER TABLE Price_List_Header ADD Tier INT
GO



-------------------------------------------------------------------------------------------------------------------------------
--- PRODUCT_COST_CUSTOM.SQL was last modified on 02/01/2019 09:27:54 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Product_Cost_Custom'
)
CREATE TABLE [dbo].[Product_Cost_Custom](
	[Product_Cost_Custom_ID] [int] IDENTITY(1,1) NOT NULL,
	[Product_ID] [uniqueidentifier] NOT NULL,
	[Start_Date] [date] NOT NULL,
	[End_Date] [date] NOT NULL,
	[Unit_of_Measure] [VARCHAR](50) NULL,
	[Meat_Cost] [decimal](20, 5) NULL,
	[Var_Cost] [decimal](20, 5) NULL,
	[Fixed_Cost] [decimal](20, 5) NULL,
	Created_Date [datetime] NOT NULL CONSTRAINT [DF_Product_Cost_Custom_Created_Date] DEFAULT (getdate()),
 CONSTRAINT [PK_Product_Cost_Custom] PRIMARY KEY CLUSTERED 
(
	[Product_ID] ASC, [Start_Date] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

-------------------------------------------------------------------------------------------------------------------------------
--- PRODUCT_COST_CUSTOM_HISTORY.SQL was last modified on 02/01/2019 09:27:54 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Product_Cost_Custom_History'
)
CREATE TABLE [dbo].[Product_Cost_Custom_History](
	[Product_Cost_Custom_History_ID] [int] IDENTITY(1,1) NOT NULL,
	[Product_ID] [uniqueidentifier] NOT NULL,
	[Start_Date] [date] NOT NULL,
	[End_Date] [date] NOT NULL,
	[Unit_of_Measure] [VARCHAR](50) NULL,
	[Meat_Cost] [decimal](20, 5) NULL,
	[Var_Cost] [decimal](20, 5) NULL,
	[Fixed_Cost] [decimal](20, 5) NULL,
	Created_Date [datetime] NOT NULL CONSTRAINT [DF_Product_Cost_Custom_History_Created_Date] DEFAULT (getdate())
) ON [PRIMARY]

-------------------------------------------------------------------------------------------------------------------------------
--- PROFILES_SETTINGS.SQL was last modified on 12/17/2018 08:05:35 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Profiles_Settings]    Script Date: 10/01/2010 13:16:15 ******/
IF not EXISTS
(SELECT * FROM SysObjects O WHERE ObjectProperty(O.ID,'IsUserTable')=1 AND O.Name='Profiles_Settings')
BEGIN
	CREATE TABLE [dbo].[Profiles_Settings](
		[Profiles_Settings_ID] [int] IDENTITY(1,1) NOT NULL,
		[Profiles_ID] [int] NOT NULL,
		[Last_Changed_Date] [datetime] NOT NULL CONSTRAINT [DF_Profile_Settings_Last_Changed_Date]  DEFAULT (getdate()),
		[Last_Changed_User_ID] [varchar](50) NULL,
		[Cont_Prog_Approval_Rights] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_Approval_Rights]  DEFAULT (0),
		[Cont_Prog_Minimum_Lineitem_Margin] [nvarchar](50) NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_Minimum_Lineitem_Margin]  DEFAULT (0),
		[Cont_Prog_Maximum_Lineitem_Margin] [nvarchar](50) NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_Maximum_Lineitem_Margin]  DEFAULT (0),
		[Cont_Prog_View_Margins] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_View_Margins]  DEFAULT (0),
		[Pay_Bill_Approval_Rights] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Pay_Bill_Approval_Rights]  DEFAULT (0),
		[Pay_Bill_Minimum_Aggregate_Deviation] [int] NULL CONSTRAINT [DF_Profiles_Settings_Pay_Bill_Minimum_Aggregate_Deviation]  DEFAULT (0),
		[Pay_Bill_Maximum_Aggregate_Deviation] [int] NULL CONSTRAINT [DF_Profiles_Settings_Pay_Bill_Maximum_Aggregate_Deviation]  DEFAULT (0),
		[Pay_Bill_View_Expected_Rate] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Pay_Bill_View_Expected_Rate]  DEFAULT (0),
		[Pay_Ded_Approval_Rights] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Pay_Ded_Approval_Rights]  DEFAULT (0),
		[Pay_Ded_Minimum_Deduction_Amount] [int] NULL CONSTRAINT [DF_Profiles_Settings_Pay_Ded_Minimum_Deduction_Amount]  DEFAULT (0),
		[Pay_Ded_Maximum_Deduction_Amount] [int] NULL CONSTRAINT [DF_Profiles_Settings_Pay_Ded_Maximum_Deduction_Amount]  DEFAULT (0),
		[Pda_Download] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Pda_Download]  DEFAULT (0),
		[Pda_Upload] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Pda_Upload]  DEFAULT (0),
		[Rep_Run_Reports] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Rep_Run_Reports]  DEFAULT (0),
		[Com_Tools_CreateEdit_Pricing_Formula] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Com_Tools_CreateEdit_Pricing_Formula]  DEFAULT (0),
		[Com_Tools_View_Pricing_Formula] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Com_Tools_View_Pricing_Formula]  DEFAULT (0),
		[Com_Tools_View_Market_Data] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Com_Tools_View_Market_Data]  DEFAULT (0),
		[Use_Set_User_Password] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Use_Set_User_Password]  DEFAULT (0),
		[Use_Set_Email_Message] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Use_Set_Email_Message]  DEFAULT (0),
		[Use_Set_Tickler] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Use_Set_Tickler]  DEFAULT (0),
		[Comm_Fax] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Comm_Fax]  DEFAULT (0),
		[Comm_Email] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Comm_Email]  DEFAULT (0),
		[Comm_Print] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Comm_Print]  DEFAULT (0),
		[Admin_Data_Purging] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Admin_Data_Purging]  DEFAULT (0),
		[Admin_Data_Exceptions] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Admin_Data_Exceptions]  DEFAULT (0),
		[Admin_Data_Integ_Schedule] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Admin_Data_Integ_Schedule]  DEFAULT (0),
		[Admin_Profile_Maintenance] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Admin_Profile_Maintenance]  DEFAULT (0),
		[Admin_AddDelete_Users] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Admin_AddDelete_Users]  DEFAULT (0),
		[Ctr_Pnl_Programs] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Ctr_Pnl_Programs]  DEFAULT (0),
		[Ctr_Pnl_Payables] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Ctr_Pnl_Payables]  DEFAULT (0),
		[Ctr_Pnl_Commod_Pricing] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Ctr_Pnl_Commod_Pricing]  DEFAULT (0),
		[Admin_Control_Panels] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Admin_Control_Panels]  DEFAULT (0),
		[Commodity_Settings] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Commodity_Settings]  DEFAULT (0),
		[Commodity_Price_Rule_Create_Edit] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Commodity_Price_Rule_Create]  DEFAULT (0),
		[Commodity_Price_Rule_View] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Commodity_Price_Rule_View]  DEFAULT (0),
		[Report_Scheduler] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Report_Scheduler]  DEFAULT (0),
		[Settings_Panel] [int] NOT NULL CONSTRAINT [DF_Profiles_Settings_Settings_Panel]  DEFAULT (0),
		[Geographic_Access] [int] NULL CONSTRAINT [DF_Profiles_Settings_Geographic_Access_National]  DEFAULT (0),
		[PM_Access] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_PM_Access]  DEFAULT (0),
		[Cont_Prog_View_Create_Program] [int] NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_View_Create_Program]  DEFAULT ((0)),
		[Reassign_Program_Access] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Reassign_Program_Access]  DEFAULT (0),
		[Special_Price_List_Access] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Special_Price_List_Access]  DEFAULT (0),
		[Reassign_Project_Access] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Reassign_Project_Access]  DEFAULT (0),
		[Clause_Library_Access] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Clause_Create_Edit]  DEFAULT (0),
		[Clause_Program_Edit_Remove] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Clause_Override]  DEFAULT (0),
		[Lump_Sum_Approval_Amount] [nvarchar](50) NULL CONSTRAINT [DF_Profiles_Settings_Lump_Sum_Approval_Amount]  DEFAULT (0),
		[Inactive_LS_Approval_Amount] [nvarchar](50) NULL CONSTRAINT [DF_Profiles_Settings_Inactive_LS_Approval_Amount]  DEFAULT (0),
		[Deleted] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Deleted]  DEFAULT (0),
		[Approve_All_Products_Program] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Approve_All_Products_Program]  DEFAULT (0),
		[RFA_Agreed] [int] NULL CONSTRAINT [DF_Profiles_Settings_Scorecard_Program_Agree]  DEFAULT (0),
		[Approve_Duplicate_Programs] [bit] NULL,
		[Reimbursement_Update] [bit] NULL,
		[program_margin_approval_method] [int] NULL,
		[Mass_RFA_Program_Approve] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Mass_RFA_Program_Approve]  DEFAULT (0),
		[View_Broker_List] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_Broker_List]  DEFAULT (1),
		[Approve_Below_Floor] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Below_Floor_1]  DEFAULT (0),
		[Approve_Below_Floor_Amount] [nvarchar](50) NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Below_Floor_Amount_1]  DEFAULT (0),
		[Approve_Group_Deals] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Group_Deals]  DEFAULT (0),
		[Approve_Equipment_Placement] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Equipment_Placement_1]  DEFAULT (0),
		[Read_Only_Catalog_Access] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Catalog_Access]  DEFAULT (0),
		[Approve_Roll_Over_Programs] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Roll_Over_Programs]  DEFAULT (0),
		[Fund_Setting_Access] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Fund_Setting_Access]  DEFAULT (0),
		[Approve_Growth_Programs] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Growth_Programs]  DEFAULT (0),
		[Approve_Upfront_Payments] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Upfront_Payments]  DEFAULT (0),
		[Max_Approval_Volume] [nvarchar](50) NULL,
		[Max_Approval_Volume_Uom] [char](10) NULL,
		[Margin_Target_Variation] [char](10) NULL,
		[Base_View] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Base_View]  DEFAULT (0),
		[View_Operating_Income] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_Operating_Income]  DEFAULT (0),
		[View_Cost] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_Cost]  DEFAULT (0),
		[View_Target_Margins] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_Target_Margins]  DEFAULT (0),
		[Max_Opr_Margin] [nvarchar](50) NULL,
		[Approve_Lumpsum] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Lumpsum]  DEFAULT (0),
		[Executive_Agreement] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Executive_Agree]  DEFAULT (0),
		[Delete_Program_Access] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Delete_Program_Access]  DEFAULT (1),
		[Min_Approval_Volume] [nvarchar](50) NULL,
		[Min_Approval_Volume_Uom] [char](10) NULL,
		[Payment_Processor] [bit] NOT NULL DEFAULT (0),
		[Lumpsum_Approval_Amount] [nvarchar](50) NULL,
		[Program_Scorecard_Restrict_Created_By] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Program_Scorecard_Restrict_Created_By]  DEFAULT (0),
		[Access_Price_List] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Access_Price_List]  DEFAULT (0),
		[Reports_Access_Level] [int] NOT NULL CONSTRAINT [DF_Profiles_Settings_Reports_Access_Level]  DEFAULT (0),
		[Create_Operator_Access] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Create_Operator_Access]  DEFAULT (1),
		[Max_Program_Spend] [nvarchar](50) NULL CONSTRAINT [DF_Profiles_Settings_Max_Program_Spend]  DEFAULT ('*'),
		[Internal_Notes] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Internal_Notes]  DEFAULT (0),
		[See_Awarded_in_Catalog] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_See_Awarded_in_Catalog]  DEFAULT (0),
		[Total_LS_Approval_Amount] [nvarchar](50) NOT NULL CONSTRAINT [DF_Profiles_Settings_Total_LS_Approval_Amount]  DEFAULT ((0)),
		[Approve_Sysco_Deals] [bit] NOT NULL CONSTRAINT [DF_Approve_Sysco_Deals]  DEFAULT (0),
		[View_TPA] [bit] NOT NULL CONSTRAINT [DF_View_TPA]  DEFAULT (0),
		[View_Net_Sales] [bit] NOT NULL CONSTRAINT [DF_View_Net_Sales]  DEFAULT (0),
		[Payment_History_Alert] [bit] NOT NULL CONSTRAINT [DF_Payment_History_Alert]  DEFAULT (0),
		[Approve_Zero_Product_Cost] [bit] NOT NULL CONSTRAINT [Profiles_Settings_Approve_Zero_Product_Cost]  DEFAULT (0),
		[Approve_Revision_Types_A] [bit] NOT NULL DEFAULT (0),
		[Approve_Revision_Types_B] [bit] NOT NULL DEFAULT (0),
		[Approve_Revision_Types_C] [bit] NOT NULL DEFAULT (0),
		[Approve_Pullbacks_Percent] [char](10) NULL,
		[Approve_Program_No_Pullback] [bit] NOT NULL CONSTRAINT [DF__contract_main_Approve_Program_No_Pullback]  DEFAULT (0),
		[View_Invoices] [bit] NOT NULL DEFAULT (1),
		[Is_Locked] [bit] NOT NULL DEFAULT (0),
		[Locked_By_User_ID] [nvarchar](50) NULL,
		[Lock_Date] [datetime] NULL,
		[Approve_Pullback] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Approve_Pullback]  DEFAULT (0),
		[Cont_Prog_View_Approved_Margins] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_View_Approved_Margins]  DEFAULT (0),
		[Release_Settlement] [bit] NOT NULL CONSTRAINT [DF_profiles_settings_Release_Settlement]  DEFAULT (0),
		[Create_Budget] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Create_Budget]  DEFAULT (0),
		[Approve_Pgm_Beyond_Budget] [bit] NULL CONSTRAINT [DF_Profiles_Settings_Approve_Pgm_Beyond_Budget]  DEFAULT (0),
		[Create_Export_Agreements] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Create_Export_Agreements]  DEFAULT (0),
		[Approve_Export_Agreements] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Export_Agreements]  DEFAULT (0),
		[Create_Approve_Export_Agreements] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Create_Approve_Export_Agreements]  DEFAULT (0),
		[Create_New_Export_Customer] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Create_New_Export_Customer]  DEFAULT (0),
		[Credit_Manager] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Credit_Manager]  DEFAULT (0),
		[Install_Patch] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Install_Patch]  DEFAULT ((0)),
		[Submit_Work_Request] [bit] NULL DEFAULT ((0)),
		[Margin_Display_UOM_LB] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Margin_Display_UOM_LB]  DEFAULT ((0)),
		[Margin_Display_UOM_CS] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Margin_Display_UOM_CS]  DEFAULT ((0)),
		[Margin_Display_UOM_EQ] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Margin_Display_UOM_EQ]  DEFAULT ((0)),
		[Cont_Prog_View_Brokerage_Margins] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_View_Brokerage_Margins]  DEFAULT ((0)),
		[Approve_Freight_Programs] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Freight_Programs]  DEFAULT ((0)),
		[Freight_View_Create] [tinyint] NOT NULL CONSTRAINT [DF_Profiles_Settings_Freight_View_Create]  DEFAULT ((0)),
		[Search_Documents] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Search_Documents]  DEFAULT ((0)),
		[Show_Trade_Checkbook] [bit] NULL DEFAULT ((0)),
		[View_Prog_In_Duplicate_Check_Window] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_Prog_In_Duplicate_Check_Window]  DEFAULT ((0)),
		[Volume_Details_Tab_Display] [bit] NOT NULL CONSTRAINT [DF_Volume_Details_Tab_Display_Default]  DEFAULT ((0)),
		[Approve_Zero_Product_Price] [bit] NOT NULL CONSTRAINT [DF__Profiles_Settings_Approve_Zero_Product_Price]  DEFAULT ((0)),
		[View_LH_Pane_Budget_Link] [bit] NOT NULL CONSTRAINT [DF_View_LH_Pane_Budget_Link_Default]  DEFAULT ((1)),
		[Max_Net_Sales_Dollar] [varchar](100) NOT NULL CONSTRAINT [DF_Profiles_Settings_Max_Net_Sales_Dollar]  DEFAULT ('*'),
		[View_Private_Documents] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_Private_Documents]  DEFAULT ((1)),
		[Approve_Beyond_Annual_Case_Rate] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Beyond_Annual_Case_Rate]  DEFAULT ((0)),
	 CONSTRAINT [PK_Profiles_Settings] PRIMARY KEY CLUSTERED
	(
		[Profiles_Settings_ID] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]
END
GO

/* Alter Scripts */

IF not EXISTS(
SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1
AND O.Name='Profiles_Settings'
AND C.Name='Cont_Prog_View_Brokerage_Margins')

Begin
Alter TABLE [dbo].[Profiles_Settings]Add
	[Cont_Prog_View_Brokerage_Margins] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Cont_Prog_View_Brokerage_Margins]  DEFAULT ((0))

End

GO

IF not EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1
AND O.Name='Profiles_Settings'
AND C.Name='Market_Price_Variance')

Begin

ALTER TABLE [dbo].[Profiles_Settings] ADD
	[Market_Price_Variance] [decimal](14, 4) NULL

END

GO


IF not EXISTS(
SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1
AND O.Name='Profiles_Settings'
AND C.Name='Approve_Freight_Adjustment_Programs')

Begin
Alter TABLE [dbo].[Profiles_Settings]Add
	[Approve_Freight_Adjustment_Programs] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Approve_Freight_Adjustment_Programs]  DEFAULT ((0))

End
GO


IF not EXISTS
(
 SELECT *
 FROM   INFORMATION_SCHEMA.COLUMNS
 WHERE TABLE_NAME = 'Profiles_Settings'
 AND COLUMN_NAME = 'Delete_Pages_Program_Letter'
)
ALTER TABLE Profiles_Settings ADD [Delete_Pages_Program_Letter] [bit] NOT NULL
CONSTRAINT [DF_Profiles_Settings_Delete_Pages_Program_Letter]  DEFAULT ((1))

IF NOT EXISTS
(
 SELECT *
 FROM   INFORMATION_SCHEMA.COLUMNS
 WHERE TABLE_NAME = 'Profiles_Settings'
 AND COLUMN_NAME = 'View_Workflow_Report_Data'
)
ALTER TABLE Profiles_Settings ADD [View_Workflow_Report_Data] [bit] NOT NULL
CONSTRAINT [DF_Profiles_Settings_View_Workflow_Report_Data]  DEFAULT ((1))

GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'profiles_settings'
		AND
		COLUMN_NAME = 'Re_instate_deleted_programs'
)
ALTER TABLE profiles_settings ADD [Re_instate_deleted_programs] [bit] NOT NULL CONSTRAINT [DF__profiles_settings_Re_instate_deleted_programs]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
		AND
		COLUMN_NAME = 'Generate_Program_Letters'
)
ALTER TABLE dbo.Profiles_Settings ADD Generate_Program_Letters BIT NOT NULL CONSTRAINT DF__Profiles_Settings_Generate_Program_Letters DEFAULT ((0))
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
		AND
		COLUMN_NAME = 'Volume_Forecast'
)
ALTER TABLE dbo.Profiles_Settings ADD Volume_Forecast BIT NOT NULL CONSTRAINT DF__Profiles_Settings_Volume_Forecast DEFAULT ((0))
GO


/*D29929:DashBoard Settings*/
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
		AND
		COLUMN_NAME = 'Dashboard_UOM'
)
ALTER TABLE dbo.Profiles_Settings ADD Dashboard_UOM INT NOT NULL CONSTRAINT DF__Profiles_Settings_Dashboard_UOM DEFAULT ((4))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
		AND
		COLUMN_NAME = 'Dashboard_Remote_Access'
)
ALTER TABLE dbo.Profiles_Settings ADD Dashboard_Remote_Access BIT NOT NULL CONSTRAINT DF__Profiles_Settings_Dashboard_Remote_Access DEFAULT ((0))
GO


IF EXISTS
(
	SELECT *
	FROM	information_schema.columns
	WHERE	column_name = 'Remote_Dashboard_Access'
)
	ALTER TABLE Profiles_Settings DROP COLUMN Remote_Dashboard_Access
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND COLUMN_NAME = 'Edit_Product_MasterData'
)
ALTER TABLE Profiles_Settings ADD [Edit_Product_MasterData] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Edit_Product_MasterData]  DEFAULT ((0))
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND COLUMN_NAME = 'Budgets_Actual_Adjustment'
)
ALTER TABLE Profiles_Settings ADD [Budgets_Actual_Adjustment] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Budgets_Actual_Adjustment]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
		AND
		COLUMN_NAME = 'ProgramView_WIPPositionsBelowMe'
)
ALTER TABLE Profiles_Settings ADD [ProgramView_WIPPositionsBelowMe] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_ProgramView_WIPPositionsBelowMe]  DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE Table_Name = 'Profiles_Settings'
                       AND Column_Name = 'Edit_Volume_FC_Below_Me' )
  ALTER TABLE PROFILES_SETTINGS
    ADD [Edit_Volume_FC_Below_Me] [BIT] NOT NULL CONSTRAINT [DF_Profiles_Settings_Edit_Volume_FC_Below_Me] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE Table_Name = 'Profiles_Settings'
                       AND Column_Name = 'Profitability_Model' )
  ALTER TABLE PROFILES_SETTINGS ADD [Profitability_Model] [BIT] NOT NULL CONSTRAINT [DF_Profiles_Settings_Profitability_Model] DEFAULT (0)
GO

--- D40664 :: Settings page to show Deleted Billbacks
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'profiles_settings'
		AND
		COLUMN_NAME = 'Re_instate_deleted_billbacks'
)
ALTER TABLE profiles_settings ADD [Re_instate_deleted_billbacks] [bit] NOT NULL CONSTRAINT [DF__profiles_settings_Re_instate_deleted_billbacks]  DEFAULT ((0))
GO

--D39479 :: Short Cut Routing profile switch
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND COLUMN_NAME = 'Prevent_short_cut_routing'
)
ALTER TABLE Profiles_Settings ADD [Prevent_short_cut_routing] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Prevent_short_cut_routing]  DEFAULT ((0))
GO

--D38941 :: New Limited User Profile Edit Functionality
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND COLUMN_NAME = 'Limited_Revise'
)
ALTER TABLE Profiles_Settings ADD [Limited_Revise] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Limited_Revise]  DEFAULT ((0))
GO

--Tim Ford - 10/22/2013: Label 39875 :: Redistribution Module - Profile Setting
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Redistribution'
)
ALTER TABLE Profiles_Settings ADD [Redistribution] [bit] NOT NULL CONSTRAINT [DF_Profiles_Redistribution]  DEFAULT ((0))
GO

-- 41568 - Profile Settings - Message Center
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'Message_Center_Viewing'
)
ALTER TABLE Profiles_Settings ADD [Message_Center_Viewing] [bit] NOT NULL CONSTRAINT [DF_Profiles_Message_Center_Viewing]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'Message_Center_Administration'
)
ALTER TABLE Profiles_Settings ADD [Message_Center_Administration] [bit] NOT NULL CONSTRAINT [DF_Profiles_Message_Center_Administration]  DEFAULT ((0))
GO
--D42287 :: Competitive Info not required by User Profile
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'Competitive_Info_not_required'
)
ALTER TABLE Profiles_Settings ADD [Competitive_Info_not_required] [bit] NOT NULL CONSTRAINT [DF_Profiles_Competitive_Info_not_required]  DEFAULT ((0))
GO

--44346 :: Adding Recapture Link for user profile
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'View_LH_Pane_Recapture_Link'
)
ALTER TABLE Profiles_Settings ADD [View_LH_Pane_Recapture_Link] [bit] NOT NULL CONSTRAINT [DF_View_LH_Pane_Recapture_Link_Default]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'View_LH_pane_Vertical_P_L'
)
ALTER TABLE Profiles_Settings ADD [View_LH_pane_Vertical_P_L] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_LH_pane_Vertical_P_L]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'View_LH_pane_What_If_P_L'
)
ALTER TABLE Profiles_Settings ADD [View_LH_pane_What_If_P_L] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_LH_pane_What_If_P_L]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'Browse_BBDoc_Server_Files'
)
ALTER TABLE Profiles_Settings ADD [Browse_BBDoc_Server_Files] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Browse_BBDoc_Server_Files]  DEFAULT ((0))
GO


--44077 :: User can modify program date after program approval.
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'Mass_Change_Program_Date'
)
ALTER TABLE Profiles_Settings ADD [Mass_Change_Program_Date] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Mass_Change_Program_Date]  DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT *
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'Profiles_Settings'
                       AND Column_Name = 'What_If_From_Scratch' )
  ALTER TABLE Profiles_Settings
    ADD What_If_From_Scratch [BIT] NOT NULL CONSTRAINT [DF_Profiles_Settings_What_If_From_Scratch] DEFAULT ((0))

GO

--47065 :: Change Order - Program Approvals
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'Manually_Select_Approvers'
)
ALTER TABLE Profiles_Settings ADD [Manually_Select_Approvers] [bit] NOT NULL CONSTRAINT [DF_Manually_Select_Approvers_Default]  DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'Profiles_Settings'
                       AND Column_Name = 'Vendor_Hold_Research' )
	ALTER TABLE Profiles_Settings
		ADD [Vendor_Hold_Research] [BIT] NOT NULL CONSTRAINT [DF_Vendor_Hold_Research_Default] DEFAULT ((0))

GO
-- D50074 :: Viewing and Editing prior program versions
IF NOT EXISTS ( SELECT 1
                FROM INFORMATION_SCHEMA.Columns
                WHERE Table_Name = 'Profiles_Settings'
                AND Column_Name = 'Modify_Expired_Programs' )
	ALTER TABLE Profiles_Settings
	ADD [Modify_Expired_Programs] [BIT] NOT NULL CONSTRAINT [DF_Modify_Expired_Programs_Default] DEFAULT ((0))
GO



---------------------------------------
-- 51515 :: create budget none setting
---------------------------------------
ALTER TABLE dbo.Profiles_Settings
    DROP CONSTRAINT DF_Profiles_Settings_Create_Budget
ALTER TABLE dbo.Profiles_Settings
    ALTER COLUMN Create_Budget SMALLINT
-----------------------------------
--  -1 = budget :: none (default)
--   0 = budget :: view
--   1 = budget :: view & create
-----------------------------------
ALTER TABLE dbo.Profiles_Settings
    ADD CONSTRAINT [DF_Profiles_Settings_Create_Budget] DEFAULT((-1)) FOR Create_Budget

-- D55551 Manual Reject Billback
IF NOT EXISTS ( SELECT  1
                FROM    INFORMATION_SCHEMA.COLUMNS
                WHERE   TABLE_NAME = 'Profiles_Settings'
                        AND COLUMN_NAME = 'Manual_Reject_Billback' )
    ALTER TABLE Profiles_Settings
    ADD [Manual_Reject_Billback] [BIT] NOT NULL CONSTRAINT [DF_Manual_Reject_Billback] DEFAULT ((0))
GO

/************* 56440: 'Duplicate Check' link inside a program/Anand Rao/04-Jan-2016 **************/

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND	COLUMN_NAME = 'View_LH_Pane_Duplicate_Checker_Link'
)
ALTER TABLE Profiles_Settings ADD [View_LH_Pane_Duplicate_Checker_Link] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_View_LH_Pane_Duplicate_Checker_Link]  DEFAULT ((0))
GO
--D57447 :: Create and modify vendor records
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Modify_Vendors_VendorManagement'
)
ALTER TABLE Profiles_Settings ADD [Modify_Vendors_VendorManagement] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Modify_Vendors_VendorManagement]  DEFAULT ((0))
GO
---D64200 :: Create new accrual budget forecast process
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Budget_Forecast'
)
ALTER TABLE Profiles_Settings ADD [Budget_Forecast] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Budget_Forecast]  DEFAULT ((0))
GO
---D66995 :: Rework - Best Plans
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Best_Plan_Program'
)
ALTER TABLE Profiles_Settings ADD [Best_Plan_Program] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Best_Plan_Program]  DEFAULT ((0))
GO
---71460 :: Analytics Single Sign On
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Analytics_SSO'
)
ALTER TABLE Profiles_Settings ADD [Analytics_SSO] [bit] NOT NULL CONSTRAINT [DF_Profiles_Settings_Analytics_SSO]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Max_Approval_Annual_Volume'
)
ALTER TABLE Profiles_Settings ADD [Max_Approval_Annual_Volume] varchar(50) NOT NULL CONSTRAINT [DF_Profiles_Settings_Max_Approval_Annual_Volume]  DEFAULT (('*'))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Max_Approval_Annual_Volume_UOM'
)
ALTER TABLE Profiles_Settings ADD [Max_Approval_Annual_Volume_UOM] BIT NOT NULL CONSTRAINT [DF_Profiles_Settings_Max_Approval_Annual_Volume_UOM]  DEFAULT ((0))

GO

--- 72497
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Ember_Access'
)
ALTER TABLE Profiles_Settings ADD [Ember_Access] BIT NOT NULL CONSTRAINT [DF_Profiles_Settings_Ember_Access]  DEFAULT ((0))

GO
---76537 :: Margin analysis to various targets
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'View_Additional_Margins_Targets'
)
ALTER TABLE Profiles_Settings ADD [View_Additional_Margins_Targets] BIT NOT NULL CONSTRAINT [DF_Profiles_Settings_View_Additional_Margins_Targets]  DEFAULT ((0))

GO

---81335 :: Tyson feedback on program upload feature 10 15 2018
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Profiles_Settings'
	AND		COLUMN_NAME = 'Upload_Programs'
)
ALTER TABLE Profiles_Settings ADD [Upload_Programs] BIT NOT NULL CONSTRAINT [DF_Profiles_Settings_Upload_Programs]  DEFAULT ((0))

GO
-------------------------------------------------------------------------------------------------------------------------------
--- PROFILE_FORBIDDEN_PLANNER.SQL was last modified on 03/18/2019 08:25:35 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (	  SELECT *
					FROM sys.objects
				   WHERE object_id = OBJECT_ID(N'dbo.Profile_Forbidden_Planner')
						 AND type IN ( N'U' ))
	BEGIN
		CREATE TABLE [dbo].[Profile_Forbidden_Planner] (
			[Profile_Forbidden_Planner_ID] [INT]	  IDENTITY(1, 1) NOT NULL
		   ,[Profile_ID]				   [INT]	  NULL
		   ,[Planner_Template_ID]		   [INT]	  NULL
		   ,[Deleted]					   [BIT]	  NULL
		   ,[Access_is_forbidden]		   [BIT]	  NULL
		   ,[Created_Date]				   [DATETIME] NOT NULL
		   ,[Updated_Date]				   [DATETIME] NOT NULL
		   ,CONSTRAINT [PK_Profile_Forbidden_Planner] PRIMARY KEY NONCLUSTERED ([Profile_Forbidden_Planner_ID] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
		) ON [PRIMARY];

		ALTER TABLE dbo.Profile_Forbidden_Planner
			ADD CONSTRAINT [DF_Profile_Forbidden_Planner_Deleted] DEFAULT (0) FOR [Deleted];

		ALTER TABLE dbo.Profile_Forbidden_Planner
			ADD CONSTRAINT [DF_Profile_Forbidden_Planner_Created_Date] DEFAULT (GETDATE()) FOR [Created_Date];

		ALTER TABLE dbo.Profile_Forbidden_Planner
			ADD CONSTRAINT [DF_Profile_Forbidden_Planner_Updated_Date] DEFAULT (GETDATE()) FOR [Updated_Date];

		--------------------------------
		-- DEFAULT ACCESS PERMISSIONS --
		--------------------------------
		-- grant access permissions to any new profiles
		INSERT INTO Profile_Forbidden_Planner
			(
				Profile_ID
			   ,Access_is_forbidden
			   ,Planner_Template_ID
			)
		SELECT 0
			  ,0
			  ,Planner_Template_ID
		  FROM dbo.Planner_Template
		 WHERE Deleted = 0;

		-- grant access permissions to allowed profiles (planner_create <> 0) in all planner templates
		INSERT INTO Profile_Forbidden_Planner
			(
				Profile_ID
			   ,Access_is_forbidden
			   ,Planner_Template_ID
			)
		SELECT Profiles_ID
			  ,0
			  ,Planner_Template_ID
		  FROM dbo.Profiles
			   INNER JOIN dbo.Planner_Template
				   ON 1 = 1
		 WHERE Profiles.Deleted = 0
			   AND Planner_Template.Deleted = 0
			   AND Profiles_ID IN (	  SELECT DISTINCT
											 Profiles_ID
										FROM dbo.Planner_Profiles_Settings
									   WHERE Planner_Create <> 0
											 AND Deleted = 0 );

		-- disable access permissions to profiles with planner none permission (planner_create = 0) in all planner templates
		INSERT INTO Profile_Forbidden_Planner
			(
				Profile_ID
			   ,Access_is_forbidden
			   ,Planner_Template_ID
			)
		SELECT Profiles_ID
			  ,1
			  ,Planner_Template_ID
		  FROM dbo.Profiles
			   INNER JOIN dbo.Planner_Template
				   ON 1 = 1
		 WHERE Profiles.Deleted = 0
			   AND Planner_Template.Deleted = 0
			   AND Profiles_ID IN (	  SELECT DISTINCT
											 Profiles_ID
										FROM dbo.Planner_Profiles_Settings
									   WHERE Planner_Create = 0
											 AND Deleted = 0 );

	END;
ELSE
	BEGIN
		IF NOT EXISTS
		(
     	  		SELECT *
       			FROM   INFORMATION_SCHEMA.COLUMNS
       			WHERE  TABLE_NAME = 'Profile_Forbidden_Planner'
       			AND    COLUMN_NAME = 'Updated_Date'
		)
		ALTER TABLE dbo.Profile_Forbidden_Planner ADD [Updated_Date] [DATETIME] NOT NULL CONSTRAINT [DF_Profile_Forbidden_Planner_Updated_Date]  DEFAULT (GETDATE())
	END	
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_CONTROL_PANEL_OPTIONS.SQL was last modified on 08/05/2019 10:53:46 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Pre_Defined_Page_Break'
)
ALTER TABLE Program_Control_Panel_Options ADD [Pre_Defined_Page_Break] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Pre_Defined_Page_Break]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_UOM'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_UOM] [tinyint] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_UOM]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_UOM'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_UOM] [tinyint] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_UOM]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Discount_Type'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Discount_Type] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Discount_Type]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Discount_Type'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Discount_Type] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Discount_Type]  DEFAULT ((1))
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Component_Name'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Component_Name] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Component_Name]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Component_Name'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Component_Name] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Component_Name]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Claim_Mechanism'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Claim_Mechanism] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Claim_Mechanism]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Claim_Mechanism'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Claim_Mechanism] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Claim_Mechanism]  DEFAULT ((1))
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Payable_To'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Payable_To] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Payable_To]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Payable_To'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Payable_To] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Payable_To]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Pricing_Type'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Pricing_Type] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Pricing_Type]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Pricing_Type'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Pricing_Type] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Pricing_Type]  DEFAULT ((1))
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Payment_Frequency'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Payment_Frequency] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Payment_Frequency]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Payment_Frequency'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Payment_Frequency] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Payment_Frequency]  DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_GTIN'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_GTIN] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_GTIN]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_GTIN'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_GTIN] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_GTIN]  DEFAULT ((0))
GO


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Pack_Size'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Distributor_Pack_Size
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Distributor_Pack_Size
End


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Pack_Size'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Operator_Pack_Size
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Operator_Pack_Size
End


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Type_Code'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Distributor_Type_Code
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Distributor_Type_Code
End


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Type_Code'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Operator_Type_Code
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Operator_Type_Code
End
GO

if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Type_Group'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Distributor_Type_Group
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Distributor_Type_Group
End
GO


if  exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Type_Group'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Operator_Type_Group
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Operator_Type_Group
End
GO


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Qbrand'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Distributor_Qbrand
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Distributor_Qbrand
End
GO


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Qbrand'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Operator_Qbrand
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Operator_Qbrand
End
GO


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Brand'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Distributor_Brand
ALTER TABLE Program_Control_Panel_Options DROP  COLUMN Distributor_Brand
End
GO


if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Brand'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT DF__Program_Control_Panel_Options_Operator_Brand
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Operator_Brand
End
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'BB_D_Purchase_Period_OverRide_Rate'
)
ALTER TABLE Program_Control_Panel_Options ADD [BB_D_Purchase_Period_OverRide_Rate] [int] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_BB_D_Purchase_Period_OverRide_Rate]  DEFAULT ((0))
GO



UPDATE	Program_Control_Panel_Options
SET	BB_D_Purchase_Period_OverRide_Rate = BB_D_Purchase_Period_OverRide
WHERE	BB_D_Purchase_Period_OverRide_Rate = 0
AND	BB_D_Purchase_Period_OverRide <> 0

GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Distributor_Product_Attribute_1'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Product_Attribute_1] [int] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Distributor_Product_Attribute_1]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Operator_Product_Attribute_1'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Product_Attribute_1] [int] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Product_Attribute_1]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Market_Price'
)
ALTER TABLE Program_Control_Panel_Options ADD [Market_Price] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Market_Price]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'DispalyPaysToOnViewProgPage'
)
ALTER TABLE Program_Control_Panel_Options ADD [DispalyPaysToOnViewProgPage] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_DispalyPaysToOnViewProgPage]  DEFAULT ((0))
GO

/**************  Bid Programs Template Settings ******************/
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Won_By'
)
ALTER TABLE Program_Control_Panel_Options ADD [Won_By] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Won_By]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Won_Rate'
)
ALTER TABLE Program_Control_Panel_Options ADD [Won_Rate] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Won_Rate]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Won_UOM'
)
ALTER TABLE Program_Control_Panel_Options ADD [Won_UOM] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Won_UOM]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Delivery_Type'
)
ALTER TABLE Program_Control_Panel_Options ADD [Delivery_Type] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Delivery_Type]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Category'
)
ALTER TABLE Program_Control_Panel_Options ADD [Category] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Category]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Package'
)
ALTER TABLE Program_Control_Panel_Options ADD [Package] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Package]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Shared'
)
ALTER TABLE Program_Control_Panel_Options ADD [Shared] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Shared]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Incremental'
)
ALTER TABLE Program_Control_Panel_Options ADD [Incremental] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Incremental]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Source'
)
ALTER TABLE Program_Control_Panel_Options ADD [Source] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Source]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Date_Source_Received'
)
ALTER TABLE Program_Control_Panel_Options ADD [Date_Source_Received] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Date_Source_Received]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Source_Type'
)
ALTER TABLE Program_Control_Panel_Options ADD [Source_Type] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Source_Type]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Download_Comp_Data_History'
)
ALTER TABLE Program_Control_Panel_Options ADD [Download_Comp_Data_History] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Download_Comp_Data_History]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Opportunity_Volume'
)
ALTER TABLE Program_Control_Panel_Options ADD [Opportunity_Volume] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Opportunity_Volume]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Include_Time_Of_Open_Date'
)
ALTER TABLE Program_Control_Panel_Options ADD [Include_Time_Of_Open_Date] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Include_Time_Of_Open_Date]  DEFAULT ((0))
GO

/*
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Update_Program_Distributors_Approved_Billbacks'
)
ALTER TABLE Program_Control_Panel_Options ADD [Update_Program_Distributors_Approved_Billbacks] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Update_Program_Distributors_Approved_Billbacks]  DEFAULT ((0))
GO
*/

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Is_Fiscal'
)
ALTER TABLE Program_Control_Panel_Options ADD [Is_Fiscal] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Is_Fiscal]  DEFAULT ((1))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Freight_accrual_considers_cash_discount'
)
ALTER TABLE Program_Control_Panel_Options ADD [Freight_accrual_considers_cash_discount] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Freight_accrual_considers_cash_discount]  DEFAULT ((1))
GO

--28112
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Single_Component_Per_Discount_Type'
)
ALTER TABLE Program_Control_Panel_Options ADD [Single_Component_Per_Discount_Type] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Single_Component_Per_Discount_Type]  DEFAULT ((0))
GO

--28113
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'AutoAdd_Distributor_ThirdPartyClaims'
)
ALTER TABLE Program_Control_Panel_Options ADD [AutoAdd_Distributor_ThirdPartyClaims] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_AutoAdd_Distributor_ThirdPartyClaims]  DEFAULT ((0))
GO


--28114
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Auto_Volume'
)
ALTER TABLE Program_Control_Panel_Options ADD [Auto_Volume] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Volume]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Auto_Actual'
)
ALTER TABLE Program_Control_Panel_Options ADD [Auto_Actual] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Actual]  DEFAULT ((0))
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Auto_Future'
)
ALTER TABLE Program_Control_Panel_Options ADD [Auto_Future] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Future]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Future_Zero'
)
ALTER TABLE Program_Control_Panel_Options ADD [Future_Zero] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Future_Zero]  DEFAULT ((0))
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Clear_Lumpsum'
)
ALTER TABLE Program_Control_Panel_Options ADD [Clear_Lumpsum] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Clear_Lumpsum]  DEFAULT ((0))
GO

--27180
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Base_Sales_Equal_To_Lowest_Bracket'
)
ALTER TABLE Program_Control_Panel_Options ADD [Base_Sales_Equal_To_Lowest_Bracket] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Base_Sales_Equal_To_Lowest_Bracket]  DEFAULT ((0))
GO

--28271
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Margin_Price_List_Header_ID'
)
ALTER TABLE Program_Control_Panel_Options ADD [Margin_Price_List_Header_ID] [uniqueidentifier] NULL
GO

-- D28559: Warning / Prevent - Identical FIXED PRICE / REBATE / PAID TO
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Item_Fixed_Rebate_Paid_To_Dup_Message'
)
ALTER TABLE Program_Control_Panel_Options ADD [Item_Fixed_Rebate_Paid_To_Dup_Message] [tinyint] NULL
GO

-- D26567	Program Letters display price list info
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Price_Brackets'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Price_Brackets] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Price_Brackets]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Price_Brackets'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Price_Brackets] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Price_Brackets]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Open_Date'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Open_Date] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Open_Date]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Open_Date'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Open_Date] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Open_Date]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Date_Needed'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Date_Needed] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Date_Needed]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Date_Needed'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Date_Needed] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Date_Needed]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Expected_Date'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Expected_Date] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Expected_Date]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Expected_Date'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Expected_Date] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Expected_Date]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Est_Value_Volume'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Est_Value_Volume] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Est_Value_Volume]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Est_Value_Volume'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Est_Value_Volume] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Est_Value_Volume]  DEFAULT ((0))
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Dist_Product_Codes'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Dist_Product_Codes] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Dist_Product_Codes]  DEFAULT ((0))
GO

if exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Dist_Product_Codes'
)
Begin
ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Dist_Product_Codes]
ALTER TABLE Program_Control_Panel_Options DROP COLUMN Operator_Dist_Product_Codes
End
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Customer_Acceptance_Block'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Customer_Acceptance_Block] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Customer_Acceptance_Block]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Customer_Acceptance_Block'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Customer_Acceptance_Block] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Customer_Acceptance_Block]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Line'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Line] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Line]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Line'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Line] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Line]  DEFAULT ((0))
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Display_Bid_Info_Page'
)
ALTER TABLE Program_Control_Panel_Options ADD [Display_Bid_Info_Page] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Display_Bid_Info_Page]  DEFAULT ((0))
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Line_Number'
)
ALTER TABLE Program_Control_Panel_Options ADD [Line_Number] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Line_Number]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Specd'
)
ALTER TABLE Program_Control_Panel_Options ADD [Specd] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Specd]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Base_Sales_based_on_Prg_Start_Date'
)
ALTER TABLE Program_Control_Panel_Options ADD [Base_Sales_based_on_Prg_Start_Date] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Base_Sales_based_on_Prg_Start_Date]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Select_Effective_Date_for_Price'
)
ALTER TABLE Program_Control_Panel_Options ADD [Select_Effective_Date_for_Price] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Select_Effective_Date_for_Price]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Distributor_Notes'
)
ALTER TABLE Program_Control_Panel_Options ADD [Distributor_Notes] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Distributor_Notes]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Operator_Notes'
)
ALTER TABLE Program_Control_Panel_Options ADD [Operator_Notes] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Operator_Notes]  DEFAULT ((0))
GO

-- D29498: Volume Deviation - setting to not run and not consider
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Ignore_Billback_Volume_Deviation'
)
ALTER TABLE Program_Control_Panel_Options ADD [Ignore_Billback_Volume_Deviation] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Ignore_Billback_Volume_Deviation]  DEFAULT ((0))
GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'BB_Tolerance_DVT'
)
ALTER TABLE Program_Control_Panel_Options ADD [BB_Tolerance_DVT] [int] NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'BB_Tolerance_ERT'
)
ALTER TABLE Program_Control_Panel_Options ADD [BB_Tolerance_ERT] [int] NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Cannot_Exceed_Percent'
)
ALTER TABLE Program_Control_Panel_Options ADD [Cannot_Exceed_Percent] [decimal](18, 2) NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Cannot_Exceed_Dollar'
)
ALTER TABLE Program_Control_Panel_Options ADD [Cannot_Exceed_Dollar] [decimal](18, 2) NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Maximum_Dollar_Amount_Checked'
)
ALTER TABLE Program_Control_Panel_Options ADD  [Maximum_Dollar_Amount_Checked] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Maximum_Dollar_Amount_Checked]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Maximum_Dollar_Amount'
)
ALTER TABLE Program_Control_Panel_Options ADD  [Maximum_Dollar_Amount] [decimal](18, 0) NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Billback_Status_For_Max_Dollar_Amt'
)
ALTER TABLE Program_Control_Panel_Options ADD  [Billback_Status_For_Max_Dollar_Amt] [tinyint] NOT NULL  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Auto_Deviation_Inc_Manual_BB'
)
ALTER TABLE Program_Control_Panel_Options ADD   [Auto_Deviation_Inc_Manual_BB] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Auto_Deviation_Inc_Manual_BB]  DEFAULT ((0))
GO

--D30064:  Max Rate to consider Rebate and Lump Sum
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'EzButton_Max_Rate_Consider'
)
ALTER TABLE Program_Control_Panel_Options ADD   [EzButton_Max_Rate_Consider] [tinyint] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_EzButton_Max_Rate_Consider]  DEFAULT ((0))
GO

--- D31561: Operator Groups Search
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Specify_Operator_Groups'
)
ALTER TABLE Program_Control_Panel_Options ADD   [Specify_Operator_Groups] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Specify_Operator_Groups]  DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE Table_Name = 'Program_Control_Panel_Options'
                       AND Column_Name = 'Currency_Conversion_Factor' )
  ALTER TABLE PROGRAM_CONTROL_PANEL_OPTIONS
    ADD [Currency_Conversion_Factor] [BIT] NOT NULL DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Discount_Fixed_Group_Level'
)
ALTER TABLE Program_Control_Panel_Options ADD [Discount_Fixed_Group_Level] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Discount_Fixed_Group_Level]  DEFAULT ((0))
GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Discount_Fixed_Item_Level'
)
ALTER TABLE Program_Control_Panel_Options ADD [Discount_Fixed_Item_Level] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Discount_Fixed_Item_Level]  DEFAULT ((0))
GO

----D35731 Growth Auto Pay
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Growth_Auto_Pay'
)
ALTER TABLE Program_Control_Panel_Options ADD [Growth_Auto_Pay] [bit] NOT NULL DEFAULT ((0))
GO

---- D36100 :: MOVE 'Letters Accepted By text' SETTING TO BE AT THE TEMPLATE LEVEL
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Letters_Accepted_By'
)
ALTER TABLE Program_Control_Panel_Options ADD Letters_Accepted_By VARCHAR(200) NULL
GO

-----
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Ignore_Date_Overlap_Deviation'
)
ALTER TABLE program_Control_Panel_Options  ADD [Ignore_Date_Overlap_Deviation] [BIT] NOT NULL DEFAULT ((0))
GO

--- D36607
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Default_rate_equal_to_zero'
)
ALTER TABLE program_Control_Panel_Options  ADD [Default_rate_equal_to_zero] [BIT] NOT NULL DEFAULT ((0))
GO
-- D37492
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Alternate_Payment_Recipient'
)
ALTER TABLE Program_Control_Panel_Options ADD [Alternate_Payment_Recipient] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Alternate_Payment_Recipient]  DEFAULT ((0))
GO
-- D37702
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Allow_Only_One_Broker'
)
ALTER TABLE Program_Control_Panel_Options ADD [Allow_Only_One_Broker] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Allow_Only_One_Broker]  DEFAULT ((0))

GO

-- D34597 Cusom (Print) Fixed Price Options
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Custom_Fixed_Price_Options'
)
ALTER TABLE Program_Control_Panel_Options ADD [Custom_Fixed_Price_Options] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Custom_Fixed_Price_Options]  DEFAULT ((0))

GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE Table_Name = 'Program_Control_Panel_Options'
                       AND Column_Name = 'Claim_Rates_Config_ID' )
  ALTER TABLE PROGRAM_CONTROL_PANEL_OPTIONS
    ADD [Claim_Rates_ConFig_Id] [INT] NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Generate_Letters_On_Approval'
)
ALTER TABLE Program_Control_Panel_Options ADD Generate_Letters_On_Approval bit NOT NULL CONSTRAINT DF_Program_Control_Panel_Options_Generate_Letters_On_Approval DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'ItemMarked_Lost_Budget_Committed_Dollars'
)
ALTER TABLE Program_Control_Panel_Options ADD ItemMarked_Lost_Budget_Committed_Dollars bit NOT NULL CONSTRAINT DF_Program_Control_Panel_Options_ItemMarked_Lost_Budget_Committed_Dollars DEFAULT ((1))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'ItemMarked_Lost_Program_Volume_Automation'
)
ALTER TABLE Program_Control_Panel_Options ADD ItemMarked_Lost_Program_Volume_Automation bit NOT NULL CONSTRAINT DF_Program_Control_Panel_Options_ItemMarked_Lost_Program_Volume_Automation  DEFAULT ((1))
GO
-- D38942 :: Program Blackout Period on Frontend
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Blackout_Periods'
)
ALTER TABLE Program_Control_Panel_Options ADD [Blackout_Periods] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Blackout_Periods]  DEFAULT ((1))
GO
-- D38942 :: Program Blackout Period on Frontend
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Start_Zero'
)
ALTER TABLE Program_Control_Panel_Options ADD [Start_Zero] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Start_Zero]  DEFAULT ((0))
GO

-- 36513 - TOPOP Reminder - no payment over 90 days
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Payment_Notification'
)
ALTER TABLE Program_Control_Panel_Options ADD [Payment_Notification] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Payment_Notification]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Payment_Notification_Span'
)
ALTER TABLE Program_Control_Panel_Options ADD [Payment_Notification_Span] [int] NULL
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Recapture_Pays_To_Id'
)
BEGIN
	ALTER TABLE Program_Control_Panel_Options ADD [Recapture_Pays_To_Id] [int] NOT NULL DEFAULT ((0))
END
GO
	declare @bUpdRecapPayTo int = 0
	SELECT @bUpdRecapPayTo = CASE WHEN BB_Count_Indicator = 'Operator' THEN 2 ELSE 1 END
	FROM	_Application_Settings
	UPDATE Program_Control_Panel_Options
	SET [Recapture_Pays_To_Id] = @bUpdRecapPayTo
	WHERE [Recapture_Pays_To_Id] = 0

GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Default_Rebate_Component_Name_Id'
)
ALTER TABLE Program_Control_Panel_Options ADD [Default_Rebate_Component_Name_Id] [INT] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Default_Rebate_Component_Name_Id]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Default_Fixed_Component_Name_Id'
)
ALTER TABLE Program_Control_Panel_Options ADD [Default_Fixed_Component_Name_Id] [INT] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Default_Fixed_Component_Name_Id]  DEFAULT ((0))

GO

/*
	D41801:  Billback Sales Tax/Anand Rao/04-Mar-2014
	Adding Billback sales tax in the template.

*/

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Billback_Sales_Tax'
)
ALTER TABLE Program_Control_Panel_Options ADD [Billback_Sales_Tax] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Billback_Sales_Tax]  DEFAULT ((0))
GO

-- 42102 Expired Program Committed $ True-Up Process
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Auto_Committed_Equal_Actual'
)
ALTER TABLE Program_Control_Panel_Options ADD [Auto_Committed_Equal_Actual] [int] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Committed_Equal_Actual]  DEFAULT ((0))
GO
--- D42733 :: Ability to disable Qualifications
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Enable_Program_Qualifications'
)
ALTER TABLE Program_Control_Panel_Options ADD [Enable_Program_Qualifications] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Enable_Program_Qualifications]  DEFAULT ((0))
GO

/*
	42591: Template setting - document attachment required/Anand Rao/09-May-2014
	Adding new switch for document attachment is required

*/
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Document_Attachment_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD [Document_Attachment_Required] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Document_Attachment_Required]  DEFAULT ((0))
GO

IF EXISTS (SELECT Auto_Renew_Option FROM Program_Control_Panel_Options)
begin
	ALTER TABLE Program_Control_Panel_Options DROP CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Renew_Option]
	ALTER TABLE Program_Control_Panel_Options ALTER COLUMN Auto_Renew_Option TINYINT
	ALTER TABLE Program_Control_Panel_Options ADD CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Renew_Option] DEFAULT (0) for Auto_Renew_Option
end
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Previous_Fiscal_Year_Volume'
)
ALTER TABLE Program_Control_Panel_Options ADD [Previous_Fiscal_Year_Volume] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Previous_Fiscal_Year_Volume]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND	COLUMN_NAME = 'Bonus_Field'
)
ALTER TABLE Program_Control_Panel_Options ADD [Bonus_Field] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Bonus_Field]  DEFAULT ((0))
GO

-- 42594 Program CRA Routing to consider Min Operating Margin% AND Max Net Sales $
-- 43541 CA Finance Manager able to approve program
if not exists
(
    SELECT	*
    FROM	INFORMATION_SCHEMA.COLUMNS
    WHERE	TABLE_NAME = 'Program_Control_Panel_Options' AND
			COLUMN_NAME = 'Sequential_Net_Sales_Operating_Margin'
)
ALTER TABLE Program_Control_Panel_Options ADD [Sequential_Net_Sales_Operating_Margin] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Sequential_Net_Sales_Operating_Margin] DEFAULT (0)
GO

/*
	Tim Ford - 05/13/2014: Label 42349 - Most Favored Nations - setup and alert
	Adding new column for Most Favored Nations template setting

*/
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Most_Favored_Nation'
)
ALTER TABLE Program_Control_Panel_Options ADD [Most_Favored_Nation] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Most_Favored_Nation]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Approval_Considerations_ID'
)
ALTER TABLE Program_Control_Panel_Options ADD [Approval_Considerations_ID] [INT] NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Program_Qualifications_Doc_Attach_Req'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Program_Qualifications_Doc_Attach_Req] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Program_Qualifications_Doc_Attach_Req]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Program_Qualifications_Doc_Msg'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Program_Qualifications_Doc_Msg] [varchar](75) NULL
GO

-- D45068 Growth ? Minimum $ Purchase
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Growth_Min_Purchase'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Growth_Min_Purchase] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Growth_Min_Purchase]  DEFAULT ((0))
GO

/*
	Tim Ford - 11/13/2014: WR 45899 - 45899 - Planning Groups and EZ Button Settings - Last Saved By and Date
	Adding new columns to hold EZ Button Last Updated By data

*/
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'EZ_Button_Last_Updated_By'
)
ALTER TABLE Program_Control_Panel_Options ADD [EZ_Button_Last_Updated_By] [NVARCHAR](50) NULL
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'EZ_Button_Last_Updated_Date'
)
ALTER TABLE Program_Control_Panel_Options ADD [EZ_Button_Last_Updated_Date] [DATETIME] NULL
GO

-- 46716 - 7.1 Volume Applicator only displays default UOM
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Volume_Page_UOM_CS'
)
ALTER TABLE Program_Control_Panel_Options ADD [Volume_Page_UOM_CS] [int] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Volume_Page_UOM_CS]  DEFAULT ((1))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Volume_Page_UOM_LB'
)
ALTER TABLE Program_Control_Panel_Options ADD [Volume_Page_UOM_LB] [int] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Volume_Page_UOM_LB]  DEFAULT ((0))
GO
--- D47306 : Price List Download
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Price_List_Download'
)
ALTER TABLE Program_Control_Panel_Options ADD [Price_List_Download] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Price_List_Download]  DEFAULT ((0))
GO

--- D47065 : Change Order - Program Approvals
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
		AND
		COLUMN_NAME = 'Manual_Selection_Of_Approvers'
)
ALTER TABLE Program_Control_Panel_Options ADD [Manual_Selection_Of_Approvers] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Manual_Selection_Of_Approvers]  DEFAULT ((0))
GO
---D47825 :: Payment frequency:  Add fiscal year option
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'PayCycleOption_12'
)
ALTER TABLE Program_Control_Panel_Options ADD [PayCycleOption_12] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_PayCycleOption_12]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Distributor_Growth'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Growth] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Growth]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Operator_Growth'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Growth] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Growth]  DEFAULT ((0))
GO

--D48049: Count / Dont Count Volume based on Program Component
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'BB_Dont_Count_Volume_Select'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [BB_Dont_Count_Volume_Select] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_BB_Dont_Count_Volume_Select]  DEFAULT ((0))
GO

--43093: Sales tracker dashbaord
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Include_In_Sales_Tracker_Dashboard'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Include_In_Sales_Tracker_Dashboard] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Include_In_Sales_Tracker_Dashboard]  DEFAULT ((1))
GO

/***************** BEGIN 50516 - Enhancement to change templates settings for Program Letters *****************/
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Operator_Fixed_Pricing_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Fixed_Pricing_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Fixed_Pricing_Default]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Operator_Rebate_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Rebate_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Rebate_Default]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Operator_Lumpsum_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Lumpsum_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Lumpsum_Default]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Operator_Bid_Request_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Bid_Request_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Bid_Request_Default]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Distributor_Fixed_Pricing_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Fixed_Pricing_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Fixed_Pricing_Default]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Distributor_Rebate_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Rebate_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Rebate_Default]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Distributor_Lumpsum_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Lumpsum_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Lumpsum_Default]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Distributor_Bid_Request_Default'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Bid_Request_Default] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Bid_Request_Default]  DEFAULT ((0))
GO

/***************** END 50516 - Enhancement to change templates settings for Program Letters *****************/

-- 50276 Volume automation on expiration only
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Auto_Committed_Equal_Actual_ON'
)
BEGIN
	ALTER TABLE Program_Control_Panel_Options ADD [Auto_Committed_Equal_Actual_ON] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Committed_Equal_Actual_ON]  DEFAULT ((0))
	EXEC('
	UPDATE	Program_Control_Panel_Options
	SET		Auto_Committed_Equal_Actual_ON = 1
	WHERE	ISNULL(Auto_Volume, 0) != 0')
END
GO

-- 50276 Volume automation on expiration only
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Auto_Volume_Program_Equal_Actual_Weeks'
)
BEGIN
	ALTER TABLE Program_Control_Panel_Options ADD [Auto_Volume_Program_Equal_Actual_Weeks] [int] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Auto_Volume_Program_Equal_Actual_Weeks]  DEFAULT ((0))
	EXEC('
	UPDATE	Program_Control_Panel_Options
	SET		Auto_Volume_Program_Equal_Actual_Weeks = Auto_Committed_Equal_Actual')
END
GO
--D50326
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Manual_Committed_Equal_Actual'
)
ALTER TABLE Program_Control_Panel_Options ADD [Manual_Committed_Equal_Actual] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Manual_Committed_Equal_Actual]  DEFAULT ((0))
GO


IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'Program_Control_Panel_Options'
                       AND Column_Name = 'Hide_On_Create_Program' )
  ALTER TABLE Program_Control_Panel_Options
      ADD Hide_On_Create_Program [BIT] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Hide_On_Create_Program] DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'Program_Control_Panel_Options'
                       AND Column_Name = 'Market_Price_Update_Process' )
  ALTER TABLE Program_Control_Panel_Options
      ADD Market_Price_Update_Process [BIT] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Market_Price_Update_Process] DEFAULT ((1))
GO


/***************** BEGIN: D48146 - % of List Price ----- 8.0 Release *****************/

IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                 WHERE Table_Name = 'Program_Control_Panel_Options'
                       AND Column_Name = 'Percentage_Of_List_Price' )
  ALTER TABLE Program_Control_Panel_Options
      ADD Percentage_Of_List_Price [BIT] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Percentage_Of_List_Price] DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Price_List_ID'
)
ALTER TABLE Program_Control_Panel_Options ADD [Price_List_ID] [NVARCHAR](50) NULL
GO

/***************** END: D48146 - % of List Price ----- 8.0 Release *****************/
---D55544 :: template settings:  allow distributors to be selected as group & ship to level on programs
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND 	COLUMN_NAME = 'Specify_Individual_Distributors'
)
ALTER TABLE Program_Control_Panel_Options ADD [Specify_Individual_Distributors] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_Specify_Individual_Distributors]  DEFAULT ((0))
GO

--WR:55348
IF NOT EXISTS (   SELECT 1
                  FROM INFORMATION_SCHEMA.Columns
                  WHERE Table_Name = 'Program_Control_Panel_Options'
                  AND Column_Name = 'Set_Billbacks_To_Paid_No_Interface' )
  ALTER TABLE Program_Control_Panel_Options
      ADD Set_Billbacks_To_Paid_No_Interface [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Set_Billbacks_To_Paid_No_Interface] DEFAULT ((0))
GO

/***************** BEGIN: 55147: EZ Button Settings - New Location in Application *****************/

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'EZ_Button_Rate_ID'
)
ALTER TABLE Program_Control_Panel_Options ADD [EZ_Button_Rate_ID] [int] NULL
GO

/***************** END: 55147: EZ Button Settings - New Location in Application *****************/

-- 57305 Retail Planner
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Retail_Planner'
)
ALTER TABLE Program_Control_Panel_Options ADD [Retail_Planner] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Retail_Planner] DEFAULT 0
GO
--60410
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Optional_Dates_Program'
)
ALTER TABLE Program_Control_Panel_Options ADD [Optional_Dates_Program] [BIT] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Optional_Dates_Program] DEFAULT 0
GO

/********** BEGIN: 62997: Template level control needed for Competitor Source and Type on  Basic Information Page and Rebate **********/

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Source_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD [Source_Required] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Source_Required]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Source_Type_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD [Source_Type_Required] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Source_Type_Required]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Date_Source_Received_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD [Date_Source_Received_Required] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Date_Source_Received_Required]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Won_By_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD [Won_By_Required] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Won_By_Required]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Won_Rate_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD [Won_Rate_Required] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Won_Rate_Required]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Won_UOM_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD [Won_UOM_Required] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Won_UOM_Required]  DEFAULT ((0))
GO

/********** END: 62997: Template level control needed for Competitor Source and Type on  Basic Information Page and Rebate **********/

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Operator_Rate_Change'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Rate_Change] [bit] NOT NULL
CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Rate_Change]  DEFAULT ((0))


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Distributor_Rate_Change'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Rate_Change] [bit] NOT NULL
CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Rate_Change]  DEFAULT ((0))


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Distributor_Display_Product_Groups'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Display_Product_Groups] [bit] NOT NULL
CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Display_Product_Groups]  DEFAULT ((0))

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND
	COLUMN_NAME = 'Operator_Display_Product_Groups'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Display_Product_Groups] [bit] NOT NULL
CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Display_Product_Groups]  DEFAULT ((0))

---63628 EZ Button - new template setting to determine if product search filters on EZ Button products
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Filter_EZButton_Products'
)
ALTER TABLE Program_Control_Panel_Options ADD [Filter_EZButton_Products] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Filter_EZButton_Products]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Show_Contract_Dates'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Show_Contract_Dates] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Show_Contract_Dates]  DEFAULT ((0))
GO
--- 60308 :: Best Plans Enhancement
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'allow_Best_Plan_Programs'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [allow_Best_Plan_Programs] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_allow_Best_Plan_Programs]  DEFAULT ((0))
GO

-- 63886 Smithfield Recapture Settings
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Pullback_Operator_Fixed_Price_Only'
)
ALTER TABLE Program_Control_Panel_Options ADD [Pullback_Operator_Fixed_Price_Only] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Pullback_Operator_Fixed_Price_Only]  DEFAULT ((0))
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Distributor_show_volume_summary'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_show_volume_summary] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_show_volume_summary]  DEFAULT ((3))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Operator_show_volume_summary'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_show_volume_summary] [tinyint] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Operator_show_volume_summary]  DEFAULT ((3))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Distributor_Product_Net_Weight'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Product_Net_Weight] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Product_Net_Weight]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Operator_Product_Net_Weight'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Product_Net_Weight] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Product_Net_Weight]  DEFAULT ((0))
GO

---68628 :: Accrual Interface Update - Final Settlements
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'RS_CreatedDaysGreater'
)
ALTER TABLE Program_Control_Panel_Options ADD [RS_CreatedDaysGreater] [int] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_RS_CreatedDaysGreater]  DEFAULT ((0))
GO
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'RS_CreatedDaysFilter'
)
ALTER TABLE Program_Control_Panel_Options ADD [RS_CreatedDaysFilter] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_RS_CreatedDaysFilter]  DEFAULT ((0))
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Restrict_On_Inventory_UOM_Case'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Restrict_On_Inventory_UOM_Case] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Restrict_On_Inventory_UOM_Case]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Restrict_On_Inventory_UOM_Pound'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Restrict_On_Inventory_UOM_Pound] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Restrict_On_Inventory_UOM_Pound]  DEFAULT ((0))
GO
---71241
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'price_list_type'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [price_list_type] [int] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_price_list_type]  DEFAULT ((0))
GO

--D71856 RETAIL-195
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'Ignore_Rate_Deviation'
)
ALTER TABLE Program_Control_Panel_Options  ADD [Ignore_Rate_Deviation] [BIT] NOT NULL DEFAULT ((0))
GO

---69720
IF NOT EXISTS
(
                SELECT  *
                FROM   INFORMATION_SCHEMA.COLUMNS
                WHERE TABLE_NAME = 'Program_Control_Panel_Options'
                AND                       COLUMN_NAME = 'Disable_Duplicate_Check_For_Revisions'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Disable_Duplicate_Check_For_Revisions] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Disable_Duplicate_Check_For_Revisions]  DEFAULT ((0))
GO
--- 74641
IF NOT EXISTS
(
                SELECT  *
                FROM   INFORMATION_SCHEMA.COLUMNS
                WHERE TABLE_NAME = 'Program_Control_Panel_Options'
                AND COLUMN_NAME = 'isBrokerage'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [isBrokerage] [bit] NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_isBrokerage]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Retail_Performance_Dates_Required'
)
ALTER TABLE Program_Control_Panel_Options ADD Retail_Performance_Dates_Required [bit] 
NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Retail_Performance_Dates_Required] DEFAULT (0)
GO

---D76514 :: Add additional payment frequencies (cycles)
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'PayCycleOption_13'
)
ALTER TABLE Program_Control_Panel_Options ADD [PayCycleOption_13] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_PayCycleOption_13]  DEFAULT ((0))
GO


---D76514 :: Add additional payment frequencies (cycles)
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'PayCycleOption_14'
)
ALTER TABLE Program_Control_Panel_Options ADD [PayCycleOption_14] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_PayCycleOption_14]  DEFAULT ((0))
GO


---D76514 :: Add additional payment frequencies (cycles)
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND		COLUMN_NAME = 'PayCycleOption_15'
)
ALTER TABLE Program_Control_Panel_Options ADD [PayCycleOption_15] [bit] NOT NULL CONSTRAINT [DF__Program_Control_Panel_Options_PayCycleOption_15]  DEFAULT ((0))
GO

---77472	Recapture by Operator (multiple lists) and template   [ CF work ]
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Template_In_Program_LH_Recapture_Link'
)
ALTER TABLE Program_Control_Panel_Options ADD Template_In_Program_LH_Recapture_Link [bit] 
NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Template_In_Program_LH_Recapture_Link] DEFAULT (0)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Template_In_Program_LH_Recapture_Link_Default'
)
ALTER TABLE Program_Control_Panel_Options ADD Template_In_Program_LH_Recapture_Link_Default [bit] 
NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_Template_In_Program_LH_Recapture_Link_Default] DEFAULT (0)
GO

---77539 Program Basic Info - additional field for reference #
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'allow_Reference_2'
)
ALTER TABLE Program_Control_Panel_Options ADD allow_Reference_2 [bit] 
NOT NULL CONSTRAINT [DF_Program_Control_Panel_Options_allow_Reference_2] DEFAULT (0)
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Operator_Broker_Number'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Broker_Number] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Broker_Number]  DEFAULT (0)

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Distributor_Broker_Number'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Broker_Number] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Broker_Number]  DEFAULT (0)

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Operator_UPC'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_UPC] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Operator_UPC]  DEFAULT (0)

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Distributor_UPC'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_UPC] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_UPC]  DEFAULT (0)

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Operator_Approval_Date'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Approval_Date] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Approval_Date]  DEFAULT ((0))

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Distributor_Approval_Date'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Approval_Date] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_Approval_Date]  DEFAULT ((0))


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Distributor_Generate_Excel_File_Product_Group_Members'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Distributor_Generate_Excel_File_Product_Group_Members] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Distributor_generate_excel_File_product_group_members]  DEFAULT ((0))


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Operator_Generate_Excel_File_Product_Group_Members'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Operator_Generate_Excel_File_Product_Group_Members] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Operator_Generate_Excel_File_Product_Group_Members]  DEFAULT ((0))

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Allow_Vendor_Only'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Allow_Vendor_Only] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Allow_Vendor_Only]  DEFAULT ((0))


/* 79614: Bid Templates - only count fixed price component - Anand Rao/12-Sep-2018 */

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Ignore_Rebate_Volume'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Ignore_Rebate_Volume] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Ignore_Rebate_Volume]  DEFAULT ((0))

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Display_Blanket_Bid'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Display_Blanket_Bid] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Display_Blanket_Bid]  DEFAULT ((0))


/* D81335: Tyson feedback on program upload feature 10 15 2018 */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Include_Program_Upload_Template_List'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Include_Program_Upload_Template_List] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Include_Program_Upload_Template_List]  DEFAULT ((0))

/* 82139: Filter distributor results based on program position */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Filter_Distributor_Results_Based_On_Program_Position'
)
ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Filter_Distributor_Results_Based_On_Program_Position] [bit] NOT NULL 
CONSTRAINT [DF_Program_Control_Panel_Options_Filter_Distributor_Results_Based_On_Program_Position]  DEFAULT ((0))

/* 87084: Planner program version settings change */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Control_Panel_Options'
	AND COLUMN_NAME = 'Retail_Revision_Replace_Parent'
)
BEGIN
	ALTER TABLE [dbo].[Program_Control_Panel_Options] ADD [Retail_Revision_Replace_Parent] [bit] NOT NULL 
	CONSTRAINT [DF_Program_Control_Panel_Options_Retail_Revision_Replace_Parent]  DEFAULT ((0))

	-- if app setting is ON, update template setting to be ON
	IF EXISTS (
		SELECT	*
		FROM	_Settings
		WHERE	Input_Name = 'Retail_Revision_Replace_Parent'
		AND		Value = '1'
	)
	BEGIN

		EXEC('
		UPDATE	Program_Control_Panel_Options
		SET		Retail_Revision_Replace_Parent = 1
		WHERE	Retail_Planner = 1	
		AND		Retail_Revision_Replace_Parent = 0')

	END

END


-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_DISTRIBUTORS_TRADE.SQL was last modified on 03/18/2019 08:25:35 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Program_Distributors_Trade]') AND type in (N'U'))
DROP TABLE [dbo].[Program_Distributors_Trade]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Program_Distributors_Trade](
	[Contract_Number] [varchar](50) NOT NULL,
	[Product_Type_ID] [int] NOT NULL,
	[Contract_Main_ID] [int] NOT NULL,
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Program_Distributors_Trade_Deleted]  DEFAULT ((0)),
	[BSA_Foodservice_Customers_ID] [uniqueidentifier] NOT NULL,
	[BSA_Foodservice_Items_Master_ID] [uniqueidentifier] NOT NULL,
	[Rate] [float] NULL,
	[Unit_Of_Measure_ID] [int] NULL,
	[Date_Created] [datetime] NULL CONSTRAINT [DF_Program_Distributors_Trade_Date_Created]  DEFAULT (getdate()),
	[Operating_Group_ID] [int] NULL,
	[Search_Sequence_ID] [int] NULL,
	[Min_Search_Sequence_ID] [int] NULL,
	[Rate_Percent_On_Fixed_Price] [decimal](20, 9) NULL,
	[Contract_Start_Date] [datetime] NOT NULL,
	[Contract_End_Date] [datetime] NOT NULL,
	[Contract_Status_Type_IDX] [int] NOT NULL,
	[Operator_Distributor] [bit] NOT NULL CONSTRAINT [DF_Program_Distributors_Trade_Operator_Distributor]  DEFAULT ((0)),
 CONSTRAINT [PK_Program_Distributors_Trade] PRIMARY KEY NONCLUSTERED 
(
	[Product_Type_ID] ASC,
	[Contract_Main_ID] ASC,
	[BSA_Foodservice_Customers_ID] ASC,
	[BSA_Foodservice_Items_Master_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

-- D28732: Component as Cost
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Distributors_Trade'
	AND COLUMN_NAME = 'TPA_Record_Type'
)
ALTER TABLE Program_Distributors_Trade ADD [TPA_Record_Type] [bit] NOT NULL CONSTRAINT [DF__Program_Distributors_Trade_TPA_Record_Type]  DEFAULT (0)
GO

-- D79244 Distributor Program - calculation of operator TPA
if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Distributors_Trade'
	AND		COLUMN_NAME = 'Operator_Distributor'
	AND		DATA_TYPE = 'bit'
)
BEGIN
	-- Drop index
	if exists(select name from sysindexes where name = 'IDX_Program_Distributors_Trade_NC1' and id = object_id ('Program_Distributors_Trade')) 
	drop index Program_Distributors_Trade.IDX_Program_Distributors_Trade_NC1

	-- Drop constraint
	if exists (
		SELECT	default_constraints.name
		FROM	sys.all_columns
		INNER JOIN sys.tables ON all_columns.object_id = tables.object_id
		INNER JOIN sys.schemas ON tables.schema_id = schemas.schema_id
		INNER JOIN sys.default_constraints ON all_columns.default_object_id = default_constraints.object_id
		WHERE	schemas.name = 'dbo'
		AND		tables.name = 'Program_Distributors_Trade'
		AND		all_columns.name = 'Operator_Distributor'
	)
	ALTER TABLE Program_Distributors_Trade DROP CONSTRAINT [DF_Program_Distributors_Trade_Operator_Distributor]

	-- Alter column
	ALTER TABLE Program_Distributors_Trade ALTER COLUMN [Operator_Distributor] [tinyint] NOT NULL 

	-- Add default constratint back
	ALTER TABLE Program_Distributors_Trade ADD CONSTRAINT [DF_Program_Distributors_Trade_Operator_Distributor]  DEFAULT ((0)) FOR [Operator_Distributor]

	-- Add index back
	CREATE NONCLUSTERED INDEX IDX_Program_Distributors_Trade_NC1 ON [dbo].[Program_Distributors_Trade] ([BSA_Foodservice_Items_Master_ID], [BSA_Foodservice_Customers_ID]) 
		INCLUDE ([Contract_Number], [Contract_Main_ID], [Rate], [Rate_Percent_On_Fixed_Price], [Contract_Start_Date], [Contract_End_Date], [Operator_Distributor])

END
GO


IF EXISTS(SELECT * FROM	INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Program_Distributors_Trade' AND COLUMN_NAME = 'TPA_Record_Type' AND DATA_TYPE = 'bit')
BEGIN

	IF EXISTS(SELECT name from sysobjects where name = 'PK_Program_Distributors_Trade')
		ALTER TABLE [dbo].[Program_Distributors_Trade] DROP CONSTRAINT [PK_Program_Distributors_Trade];

	IF EXISTS(SELECT name from sysobjects where name = 'DF__Program_Distributors_Trade_TPA_Record_Type')
		ALTER TABLE [dbo].[Program_Distributors_Trade] DROP CONSTRAINT [DF__Program_Distributors_Trade_TPA_Record_Type];

	ALTER TABLE [dbo].[Program_Distributors_Trade] ALTER COLUMN [TPA_Record_Type] TINYINT NOT NULL;

	ALTER TABLE [dbo].[Program_Distributors_Trade] ADD CONSTRAINT [DF__Program_Distributors_Trade_TPA_Record_Type] DEFAULT (0) FOR [TPA_Record_Type];

	ALTER TABLE [dbo].[Program_Distributors_Trade] ADD CONSTRAINT PK_Program_Distributors_Trade PRIMARY KEY CLUSTERED 
	(
		[Contract_Main_ID] ASC,
		[BSA_Foodservice_Customers_ID] ASC,
		[BSA_Foodservice_Items_Master_ID] ASC,
		[Product_Type_ID] ASC,
		[TPA_Record_Type] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY];

END
GO

-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_DISTRIBUTOR_WEIGHT_FROM_VOLUME_LOG.SQL was last modified on 01/30/2019 10:43:16 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Program_Distributor_Weight_From_Volume_Log'
)
CREATE TABLE Program_Distributor_Weight_From_Volume_Log (
	[Program_Distributor_Weight_From_Volume_Log_ID] [int] IDENTITY (1, 1) NOT NULL,
	[Contract_Main_ID] [int] NOT NULL,
	[Version_Actual_Span] [decimal] (20, 4) NULL,
	[Version_Togo_Span] [decimal] (20, 4) NULL,
	[Update_Weight] [bit] NULL,
	[Automation_Percentage] [decimal] (20, 4) NULL,
	[Forecast_Percentage] [decimal] (20, 4) NULL,
	[Forecast_Record_Count] [int] NULL,
	[Automation_Record_Count] [int] NULL,
	[BSA_Foodservice_Customers_ID] [uniqueidentifier] NULL,
	[Program_Weight_Old] [decimal] (20, 4) NULL,
	[Program_Weight_Automation] [decimal] (20, 4) NULL,
	[Program_Weight_Forecast] [decimal] (20, 4) NULL,
	[Program_Weight_New] [decimal] (20, 4) NULL,
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Program_Distributor_Weight_From_Volume_Log_Created_Date] DEFAULT (getdate()),
	CONSTRAINT [PK_Program_Distributor_Weight_From_Volume_Log] PRIMARY KEY  CLUSTERED 
	(
		[Program_Distributor_Weight_From_Volume_Log_ID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO

-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_FIXED_COMPONENT_NAME.SQL was last modified on 04/17/2019 07:10:25 AM ---
-------------------------------------------------------------------------------------------------------------------------------
-- Program_Fixed_Component_Name.sql

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Business_Segment_ID] [int] NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Is_Fiscal'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Is_Fiscal] [bit] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
		AND
		COLUMN_NAME = 'Fixed_Price_Type'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Fixed_Price_Type] [tinyint] NULL CONSTRAINT [DF_Program_Fixed_Component_Name_Fixed_Price_Type] DEFAULT (0)
GO

IF NOT EXISTS ( SELECT 1
									FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE Table_Name = 'Program_Fixed_Component_Name'
                       AND Column_Name = 'Greatest_Program_Value' )
  ALTER TABLE PROGRAM_FIXED_COMPONENT_NAME
    ADD [Greatest_Program_Value] [BIT] NOT NULL DEFAULT(0)
GO
---D41867 :: Sysco - Update BB Expected Rate for Operator Deviated Programs.  CF Work START
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Update_BB_Expected_Rate'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Update_BB_Expected_Rate] [bit] NOT NULL DEFAULT(0)
GO
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Expected_Rate'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Expected_Rate] [tinyint] NOT NULL DEFAULT(0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Program_Pays_To'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Program_Pays_To] [tinyint] NOT NULL DEFAULT(0)
GO
---D41867 :: Sysco - Update BB Expected Rate for Operator Deviated Programs.  CF Work END
--D58135 ::  Additional Component info displaye inside program
--Display ID on View Program page
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'ID_on_ViewProgramPage'
)
ALTER TABLE Program_Fixed_Component_Name ADD [ID_on_ViewProgramPage] INT NOT NULL DEFAULT(0)
GO
--Display Deduction Account on View Program page
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'DeductionAccount_on_ViewProgramPage'
)
ALTER TABLE Program_Fixed_Component_Name ADD [DeductionAccount_on_ViewProgramPage] INT NOT NULL DEFAULT(0)
GO
--Display Payment Account on View Program page
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'PaymentAccount_on_ViewProgramPage'
)
ALTER TABLE Program_Fixed_Component_Name ADD [PaymentAccount_on_ViewProgramPage] INT NOT NULL DEFAULT(0)
GO
---62455 :: Fixed Price Components - Additional Drop Down for Fixed Price Type
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'FP_Type'
)
ALTER TABLE Program_Fixed_Component_Name ADD [FP_Type] [tinyint] NOT NULL DEFAULT(0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Formula_Pricing'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Formula_Pricing] [bit] NOT NULL DEFAULT(0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Program_Lock_Type_ID'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Program_Lock_Type_ID] [tinyint] NOT NULL CONSTRAINT [DF_Program_Fixed_Component_Name_Program_Lock_Type_ID]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Include_Second_Component'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Include_Second_Component] [bit] NOT NULL CONSTRAINT [DF_Program_Fixed_Component_Name_Include_Second_Component]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Second_Component_Name_ID'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Second_Component_Name_ID] [int] NOT NULL CONSTRAINT [DF_Program_Fixed_Component_Name_Second_Component_Name_ID]  DEFAULT ((0))
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Second_Component_Payment_Type_ID'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Second_Component_Payment_Type_ID] [tinyint] NOT NULL CONSTRAINT [DF_Program_Fixed_Component_Name_Second_Component_Payment_Type_ID]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Second_Component_GL_Account_ID'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Second_Component_GL_Account_ID] [int] NOT NULL CONSTRAINT [DF_Program_Fixed_Component_Name_Second_Component_GL_Account_ID]  DEFAULT ((0))
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND		COLUMN_NAME = 'Second_Component_Payment_Cycle_ID'
)
ALTER TABLE Program_Fixed_Component_Name ADD [Second_Component_Payment_Cycle_ID] [tinyint] NOT NULL CONSTRAINT [DF_Program_Fixed_Component_Name_Second_Component_Payment_Cycle_ID]  DEFAULT ((0))
GO

IF not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Fixed_Component_Name'
	AND
	COLUMN_NAME = 'GPO_Program_Tier_Number'
)
BEGIN
	ALTER TABLE [dbo].[Program_Fixed_Component_Name] ADD [GPO_Program_Tier_Number] [int] NOT NULL CONSTRAINT [DF_Program_Fixed_Component_Name_GPO_Program_Tier_Number]  DEFAULT ((0))
END

-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_FORMULA_PRICING_RULES.SQL was last modified on 10/07/2019 01:31:58 PM ---
-------------------------------------------------------------------------------------------------------------------------------

/****** Object:  Table [dbo].[Program_Formula_Pricing_Rules]  ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
)
BEGIN
CREATE TABLE [dbo].[Program_Formula_Pricing_Rules](
	[Program_Formula_Pricing_Rule_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rules_Program_Formula_Pricing_Rule_ID]  DEFAULT (newid()),
	[Program_ID] [int] NOT NULL,
	[Rule_Name] [nvarchar](255) NOT NULL,
	[Number_Of_Comms] [int] NOT NULL,
	[Active] [bit] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rules_Active]  DEFAULT (0),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rules_Deleted]  DEFAULT (0)
) ON [PRIMARY]
END
GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'Created_Date'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [Created_Date]  [datetime] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rules_Created_Date]  DEFAULT (getdate())
GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'FP_Schedule_Option_ID'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [FP_Schedule_Option_ID]  [int] NULL 
GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'FP_Formula_Type_ID'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [FP_Formula_Type_ID]  [int] NULL 
GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'Calc_Date'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [Calc_Date]  [datetime] NULL
GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'Price_Date'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [Price_Date]  [datetime] NULL
GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'Formula_Price'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [Formula_Price]  DECIMAL(14,4) NULL
GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'Contract_Products_Id'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [Contract_Products_Id]  Int NULL
GO

if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rules'
	AND		COLUMN_NAME = 'Saved'
)
ALTER TABLE Program_Formula_Pricing_Rules ADD [Saved] [bit] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rules_Saved]  DEFAULT (0)
GO

ALTER TABLE Program_Formula_Pricing_Rules
   ADD CONSTRAINT PK_Program_Formula_Pricing_Rules_Program_Formula_Pricing_Rule_ID PRIMARY KEY CLUSTERED (Program_Formula_Pricing_Rule_ID);

GO


-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_FORMULA_PRICING_RULE_COMM_DATA.SQL was last modified on 10/07/2019 01:31:58 PM ---
-------------------------------------------------------------------------------------------------------------------------------

/****** Object:  Table [dbo].[Program_Formula_Pricing_Rule_Comm_Data]    Script Date: 11/1/2016 10:57:48 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
)
BEGIN
	CREATE TABLE [dbo].[Program_Formula_Pricing_Rule_Comm_Data](
		[Program_Formula_Pricing_Rule_Comm_Data_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rule_Comm_Data_Program_Formula_Pricing_Rule_Comm_Data_ID]  DEFAULT (newid()),
		[Program_ID] [int] NULL,
		[Program_Formula_Pricing_Rule_ID] [uniqueidentifier] NOT NULL,
		[Comm_Count] [int] NOT NULL,
		[Exchange] [nvarchar](50) NOT NULL,
		[Symbol] [nvarchar](50) NOT NULL,
		[Point_In_Time] [int] NULL,
		[Point_In_Time_UOM] [nvarchar](50) NULL,
		[Sample_Size] [int] NULL,
		[Sample_Size_UOM] [nvarchar](50) NULL,
		[Weight] [decimal](20, 5) NULL,
		[Active] [bit] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rule_Comm_Data_Active]  DEFAULT (0),
		[Deleted] [bit] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rule_Comm_Data_Deleted]  DEFAULT (0)
	) ON [PRIMARY]
END

GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
	AND		COLUMN_NAME = 'Created_Date'
)
ALTER TABLE Program_Formula_Pricing_Rule_Comm_Data ADD [Created_Date]  [datetime] NOT NULL CONSTRAINT [DF_Program_Formula_Pricing_Rule_Comm_Data_Created_Date]  DEFAULT (getdate())
GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
	AND		COLUMN_NAME = 'Commodities_Symbol_ID'
)
ALTER TABLE Program_Formula_Pricing_Rule_Comm_Data ADD [Commodities_Symbol_ID]  INT NULL

GO

-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
	AND		COLUMN_NAME = 'Start_Price'
)
ALTER TABLE Program_Formula_Pricing_Rule_Comm_Data ADD [Start_Price]  DECIMAL(14,4) NULL

GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
	AND		COLUMN_NAME = 'Compound_Price'
)
ALTER TABLE Program_Formula_Pricing_Rule_Comm_Data ADD [Compound_Price]  DECIMAL(14,4) NULL

GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
	AND		COLUMN_NAME = 'Independent_Price'
)
ALTER TABLE Program_Formula_Pricing_Rule_Comm_Data ADD [Independent_Price]  DECIMAL(14,4) NULL

GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
	AND		COLUMN_NAME = 'Final_Price'
)
ALTER TABLE Program_Formula_Pricing_Rule_Comm_Data ADD [Final_Price]  DECIMAL(14,4) NULL

GO
-- New column
if NOT exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Formula_Pricing_Rule_Comm_Data'
	AND		COLUMN_NAME = 'FP_Formula_Type_ID'
)
ALTER TABLE Program_Formula_Pricing_Rule_Comm_Data ADD [FP_Formula_Type_ID]  INT NULL

GO





-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_MARGIN_LOG_STATUS.SQL was last modified on 02/15/2019 10:57:14 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Margin_Log_Status'
	AND		COLUMN_NAME = 'Unit_Of_Time'
)
ALTER TABLE Program_Margin_Log_Status ADD [Unit_Of_Time] [bit] NOT NULL CONSTRAINT [DF_Program_Margin_Log_Status_Unit_Of_Time] DEFAULT (0)
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_PRODUCT_DISTRIBUTOR_VOLUME.SQL was last modified on 01/30/2019 10:43:16 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Program_Product_Distributor_Volume'
)
CREATE TABLE [Program_Product_Distributor_Volume] (
	[Program_Product_Distributor_Volume_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Program_ID] [int] NOT NULL,
	[BSA_Foodservice_Items_Master_ID] [uniqueidentifier] NOT NULL,
	[BSA_Foodservice_Customers_ID] [uniqueidentifier] NOT NULL,
	[Volume_LB] [decimal] (25, 4) NULL,
	[Volume_CS] [decimal] (25, 4) NULL,
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Program_Product_Distributor_Volume_Created_Date] DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	CONSTRAINT [PK_Program_Product_Distributor_Volume] PRIMARY KEY  CLUSTERED 
	(
		[Program_ID], [BSA_Foodservice_Items_Master_ID], [BSA_Foodservice_Customers_ID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO
-------------------------------------------------------------------------------------------------------------------------------
--- PROGRAM_REVISION_CHANGES.SQL was last modified on 08/19/2019 11:12:17 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT *
	FROM   INFORMATION_SCHEMA.COLUMNS
	WHERE TABLE_NAME = 'Program_Revision_Changes'
)
CREATE TABLE [dbo].[Program_Revision_Changes](
	[Program_Revision_Changes_ID] [int] IDENTITY(1,1) NOT NULL,
	[Contract_Main_ID] [int] NULL,
	[Created_On] [datetime] NULL DEFAULT (getdate()),
	[Deleted_On] [datetime] NULL DEFAULT (getdate()),
	[Deleted] [bit] NULL DEFAULT (0),
	[Title_Changed] [int] NULL DEFAULT (0),
	[Date_Changed] [int] NULL DEFAULT (0),
	[Products_Added] [int] NULL DEFAULT (0),
	[Products_Removed] [int] NULL DEFAULT (0),
	[Products_Rates_Changed] [int] NULL DEFAULT (0),
	[Growth_Target_Changed] [int] NULL DEFAULT (0),
	[Products_UOM_Changed] [int] NULL DEFAULT (0),
	[Lump_Sum_Changed] [int] NULL DEFAULT (0),
	[Lump_Sum_Created] [int] NULL DEFAULT (0),
	[Lump_Sum_Removed] [int] NULL DEFAULT (0),
	[Distributors_Added] [int] NULL DEFAULT (0),
	[Distributors_Removed] [int] NULL DEFAULT (0),
	[Operators_Added] [int] NULL DEFAULT (0),
	[Operators_Removed] [int] NULL DEFAULT (0),
	[Require_Private_Notes_Changed] [int] NULL DEFAULT (0),
	[Require_public_Notes_Changed] [int] NULL DEFAULT (0),
	[Start_Date_Changed] [int] NULL DEFAULT (0),
	[End_Date_Changed] [int] NULL DEFAULT (0),
	[Other_Program_BasicInfo_Changes] [bit] NULL CONSTRAINT [DF_Program_Revision_Changes_BasicInfo_Changes]  DEFAULT ((0)),
	[Program_Reference_Number_Changes] [int] NOT NULL CONSTRAINT [DF_Program_Revision_Changes_Program_Reference_Number_Changes]  DEFAULT ((0)) ,
	[Component_ClaimMech_Changed] [int] NOT NULL CONSTRAINT [DF__Program_Revision_Changes_Component_ClaimMech_Changed]  DEFAULT ((0)),
	[Products_Added_FixedEqPricelist] [int] NOT NULL CONSTRAINT [DF__Program_Revision_Changes_Products_Added_FixedEqPricelist]  DEFAULT ((0)),
	[Freight_Approval_Only] [int] NOT NULL CONSTRAINT [DF__Program_Revision_Changes_Freight_Approval_Only]  DEFAULT ((0)),
	[Program_Notes_Change] [int] NOT NULL CONSTRAINT [DF_Program_Revision_Changes_Program_Notes_Change]  DEFAULT ((0))
) ON [PRIMARY]

GO

-- D32785: Shortcut Approval 1010127
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Revision_Changes'
		AND
		COLUMN_NAME = 'No_Change'
)
ALTER TABLE Program_Revision_Changes ADD [No_Change] [tinyint] NOT NULL CONSTRAINT [DF_Program_Revision_Changes_No_Change] DEFAULT (0)
GO


-- D34880: Max Rate Easy Button and Short Cut Routing
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Revision_Changes'
	AND		COLUMN_NAME = 'Products_Rates_Increase'
)
ALTER TABLE Program_Revision_Changes ADD [Products_Rates_Increase] [int] NOT NULL CONSTRAINT [DF_Program_Revision_Changes_Products_Rates_Increase] DEFAULT (0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Revision_Changes'
	AND		COLUMN_NAME = 'Products_Rates_Decrease'
)
ALTER TABLE Program_Revision_Changes ADD [Products_Rates_Decrease] [int] NOT NULL CONSTRAINT [DF_Program_Revision_Changes_Products_Rates_Decrease] DEFAULT (0)
GO

--D86748: Short Cut Approval - add option for duration change
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Revision_Changes'
		AND
		COLUMN_NAME = 'Program_Duration_Changed'
)
ALTER TABLE Program_Revision_Changes ADD [Program_Duration_Changed] [tinyint] NOT NULL CONSTRAINT [DF_Program_Revision_Changes_Program_Duration_Changed] DEFAULT (0)
GO
-------------------------------------------------------------------------------------------------------------------------------
--- RERUN_CAPTURE_MODIFIED_GROUPS.SQL was last modified on 04/26/2019 06:24:40 PM ---
-------------------------------------------------------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RERUN_CAPTURE_MODIFIED_GROUPS]') AND type in (N'U'))
BEGIN
	DROP TABLE [dbo].[RERUN_CAPTURE_MODIFIED_GROUPS]
END
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RERUN_CAPTURE_MODIFIED_GROUPS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[RERUN_CAPTURE_MODIFIED_GROUPS](
	[RERUN_CAPTURE_MODIFIED_GROUPS_ID] [int] IDENTITY(1,1) NOT NULL,
	[Product_Group_ID] [uniqueidentifier] NOT NULL,
	[Process_Date] [datetime] NULL,
	[Created_Date] [DATETIME] NOT NULL CONSTRAINT [DF_RERUN_CAPTURE_MODIFIED_GROUPS_Created_Date] DEFAULT (Getdate()),
	[Group_Updated] [BIT] NOT NULL CONSTRAINT [DF_RERUN_CAPTURE_MODIFIED_GROUPS_Group_Updated] DEFAULT (0),
 CONSTRAINT [PK_RERUN_CAPTURE_MODIFIED_GROUPS] PRIMARY KEY CLUSTERED 
(
--	[RERUN_CAPTURE_MODIFIED_GROUPS_ID] ASC
	[Product_Group_ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_RERUN_CAPTURE_MODIFIED_GROUPS_Created_Date]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RERUN_CAPTURE_MODIFIED_GROUPS] ADD  CONSTRAINT [DF_RERUN_CAPTURE_MODIFIED_GROUPS_Created_Date]  DEFAULT (getdate()) FOR [Created_Date]
END
GO


IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_RERUN_CAPTURE_MODIFIED_GROUPS_Group_Updated]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RERUN_CAPTURE_MODIFIED_GROUPS] ADD  CONSTRAINT [DF_RERUN_CAPTURE_MODIFIED_GROUPS_Group_Updated]  DEFAULT (0) FOR [Group_Updated]
END
GO

-------------------------------------------------------------------------------------------------------------------------------
--- RERUN_CAPTURE_PROGRAM_LIST.SQL was last modified on 04/26/2019 06:24:40 PM ---
-------------------------------------------------------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RERUN_CAPTURE_PROGRAM_LIST]') AND type in (N'U'))
BEGIN
	DROP TABLE [dbo].[RERUN_CAPTURE_PROGRAM_LIST]
END
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RERUN_CAPTURE_PROGRAM_LIST]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[RERUN_CAPTURE_PROGRAM_LIST](
--	[RERUN_CAPTURE_PROGRAM_LIST_ID] [int] IDENTITY(1,1) NOT NULL,
	[Contract_Main_ID] [int] NOT NULL,
	[Process_Date] [datetime] NULL,
	[Created_Date] [DATETIME] NOT NULL CONSTRAINT [DF_RERUN_CAPTURE_PROGRAM_LIST_Created_Date] DEFAULT (Getdate()),
	[Group_Updated] [BIT] NOT NULL CONSTRAINT [DF_RERUN_CAPTURE_PROGRAM_LIST_Group_Updated] DEFAULT (0),
 CONSTRAINT [PK_RERUN_CAPTURE_PROGRAM_LIST] PRIMARY KEY CLUSTERED 
(
--	[RERUN_CAPTURE_PROGRAM_LIST_ID] ASC
	[Contract_Main_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_RERUN_CAPTURE_PROGRAM_LIST_Created_Date]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RERUN_CAPTURE_PROGRAM_LIST] ADD  CONSTRAINT [DF_RERUN_CAPTURE_PROGRAM_LIST_Created_Date]  DEFAULT (getdate()) FOR [Created_Date]
END
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DF_RERUN_CAPTURE_PROGRAM_LIST_Group_Updated]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RERUN_CAPTURE_PROGRAM_LIST] ADD  CONSTRAINT [DF_RERUN_CAPTURE_PROGRAM_LIST_Group_Updated]  DEFAULT (0) FOR [Group_Updated]
END
GO

--DROP INDEX [RERUN_CAPTURE_PROGRAM_LIST_NC1] ON [dbo].[RERUN_CAPTURE_PROGRAM_LIST]
--GO


CREATE NONCLUSTERED INDEX [RERUN_CAPTURE_PROGRAM_LIST_NC1] ON [dbo].[RERUN_CAPTURE_PROGRAM_LIST]
(
	[Contract_Main_ID] ASC,
	[Group_Updated] ASC
)
INCLUDE ( 	[Process_Date]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO


-------------------------------------------------------------------------------------------------------------------------------
--- REVISION_SETTINGS.SQL was last modified on 08/19/2019 11:12:17 AM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
            SELECT *
            FROM   INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'Revision_Settings'
)
CREATE TABLE [Revision_Settings] (
	[Revision_Settings_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Revision_Setting_Created_By] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Revision_Setting_Created_On] [datetime] NOT NULL CONSTRAINT [DF__Revision___Revis__3CB8D866] DEFAULT (getdate()),
	[Revision_Setting_Deleted] [int] NOT NULL CONSTRAINT [DF__Revision___Revis__3DACFC9F] DEFAULT (0),
	[Title_Changes_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Title_Changes_Approval] DEFAULT (2),
	[Title_Changes_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Title_Changes_Approval_Type] DEFAULT (0),
	[Date_Changes_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Date_Changes_Approval] DEFAULT (2),
	[Date_Changes_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Date_Changes_Approval_Type] DEFAULT (0),
	[Products_Added_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_Added_Approval] DEFAULT (2),
	[Products_Added_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_Added_Approval_Type] DEFAULT (0),
	[Products_Rates_Changes_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_Rates_Changes_Approval] DEFAULT (2),
	[Products_Rates_Changes_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_Rates_Changes_Approval_Type] DEFAULT (0),
	[Products_Removed_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_Removed_Approval] DEFAULT (2),
	[Products_Removed_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_Removed_Approval_Type] DEFAULT (0),
	[Growth_Change_Target_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Growth_Change_Target_Approval] DEFAULT (2),
	[Growth_Change_Target_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Growth_Change_Target_Approval_Type] DEFAULT (0),
	[Products_UOM_Changes_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_UOM_Changes_Approval] DEFAULT (2),
	[Products_UOM_Changes_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Products_UOM_Changes_Approval_Type] DEFAULT (0),
	[Lump_Sum_Changed_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Lump_Sum_Changed_Approval] DEFAULT (2),
	[Lump_Sum_Changed_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Lump_Sum_Changed_Approval_Type] DEFAULT (0),
	[Lump_Sum_Created_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Lump_Sum_Created_Approval] DEFAULT (2),
	[Lump_Sum_Created_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Lump_Sum_Created_Approval_Type] DEFAULT (0),
	[Lump_Sum_Removed_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Lump_Sum_Removed_Approval] DEFAULT (2),
	[Lump_Sum_Removed_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Lump_Sum_Removed_Approval_Type] DEFAULT (0),
	[Distributors_Added_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Distributors_Added_Approval] DEFAULT (2),
	[Distributors_Added_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Distributors_Added_Approval_Type] DEFAULT (0),
	[Distributors_Removed_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Distributors_Removed_Approval] DEFAULT (2),
	[Distributors_Removed_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Distributors_Removed_Approval_Type] DEFAULT (0),
	[Operators_Added_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Operators_Added_Approval] DEFAULT (2),
	[Operators_Added_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Operators_Added_Approval_Type] DEFAULT (0),
	[Operators_Removed_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Operators_Removed_Approval] DEFAULT (2),
	[Operators_Removed_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Operators_Removed_Approval_Type] DEFAULT (0),
	[Require_Private_Notes_Changed_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Require_Private_Notes_Changed_Approval] DEFAULT (2),
	[Require_Private_Notes_Changed_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Require_Private_Notes_Changed_Approval_Type] DEFAULT (0),
	[Require_public_Notes_Changed_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Require_public_Notes_Changed_Approval] DEFAULT (2),
	[Require_public_Notes_Changed_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Require_public_Notes_Changed_Approval_Type] DEFAULT (0),
	[Start_Date_Change_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_Start_Date_Change_Approval] DEFAULT (2),
	[Start_Date_Change_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Start_Date_Change_Approval_Type] DEFAULT (0),
	[End_Date_Change_Approval] [int] NOT NULL CONSTRAINT [DF_revision_settings_End_Date_Change_Approval] DEFAULT (2),
	[End_Date_Change_Approval_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_End_Date_Change_Approval_Type] DEFAULT (0),
	[Apply_to_All] [int] NULL ,
	[Title_Changes] [int] NULL ,
	[Date_Changes] [int] NULL ,
	[Products_Added] [int] NULL ,
	[Products_Removed] [int] NULL ,
	[Products_Rates_Changes] [int] NULL ,
	[Products_UOM_Changes] [int] NULL ,
	[Lump_Sum_Changed] [int] NULL ,
	[Lump_Sum_Created] [int] NULL ,
	[Lump_Sum_Removed] [int] NULL ,
	[Distributors_Added] [int] NULL ,
	[Distributors_Removed] [int] NULL ,
	[Operators_Added] [int] NULL ,
	[Operators_Removed] [int] NULL ,
	[Growth_Change_Target] [int] NULL CONSTRAINT [DF_Revision_Settings_Growth_Change_Target] DEFAULT (1),
	[Start_Date_Change] [int] NULL CONSTRAINT [DF_Revision_Settings_Start_Date_Change] DEFAULT (1),
	[End_Date_Change] [int] NULL CONSTRAINT [DF_Revision_Settings_End_Date_Change] DEFAULT (1),
	[Require_Private_Notes_Changed] [int] NULL CONSTRAINT [DF_Revision_Settings_Require_Private_Notes_Changed] DEFAULT (2),
	[Require_Public_Notes_Changed] [int] NULL CONSTRAINT [DF_Revision_Settings_Require_Public_Notes_Changed] DEFAULT (2)
) ON [PRIMARY]
GO



if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Apply_to_All'
)
ALTER TABLE Revision_Settings ADD [Apply_to_All] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Title_Changes'
)
ALTER TABLE Revision_Settings ADD [Title_Changes] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Date_Changes'
)
ALTER TABLE Revision_Settings ADD [Date_Changes] [int] NULL
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Products_Added'
)
ALTER TABLE Revision_Settings ADD [Products_Added] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Products_Removed'
)
ALTER TABLE Revision_Settings ADD [Products_Removed] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Products_Rates_Changes'
)
ALTER TABLE Revision_Settings ADD [Products_Rates_Changes] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Products_UOM_Changes'
)
ALTER TABLE Revision_Settings ADD [Products_UOM_Changes] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Lump_Sum_Changed'
)
ALTER TABLE Revision_Settings ADD [Lump_Sum_Changed] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Lump_Sum_Created'
)
ALTER TABLE Revision_Settings ADD [Lump_Sum_Created] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Lump_Sum_Removed'
)
ALTER TABLE Revision_Settings ADD [Lump_Sum_Removed] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Distributors_Added'
)
ALTER TABLE Revision_Settings ADD [Distributors_Added] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Distributors_Removed'
)
ALTER TABLE Revision_Settings ADD [Distributors_Removed] [int] NULL
GO	

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Operators_Added'
)
ALTER TABLE Revision_Settings ADD [Operators_Added] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Operators_Removed'
)
ALTER TABLE Revision_Settings ADD [Operators_Removed] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Revision_Setting_Created_By'
)
ALTER TABLE Revision_Settings ADD [Revision_Setting_Created_By] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Revision_Setting_Created_On'
)
ALTER TABLE Revision_Settings ADD [Revision_Setting_Created_On] [int] NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Revision_Setting_Deleted'
)
ALTER TABLE Revision_Settings ADD [Revision_Setting_Deleted] [int] NULL
GO	


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Growth_Change_Target'
)
ALTER TABLE Revision_Settings ADD [Growth_Change_Target] [int] NULL CONSTRAINT [DF_Revision_Settings_Growth_Change_Target] DEFAULT (1)
GO	

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Start_Date_Change'
)
ALTER TABLE Revision_Settings ADD [Start_Date_Change] [int] NULL CONSTRAINT [DF_Revision_Settings_Start_Date_Change] DEFAULT (1)
GO	

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'End_Date_Change'
)
ALTER TABLE Revision_Settings ADD [End_Date_Change] [int] NULL CONSTRAINT [DF_Revision_Settings_End_Date_Change] DEFAULT (1)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Require_Private_Notes_Changed'
)
ALTER TABLE Revision_Settings ADD [Require_Private_Notes_Changed] [int] NULL CONSTRAINT [DF_Revision_Settings_Require_Private_Notes_Changed] DEFAULT (2)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Require_Public_Notes_Changed'
)
ALTER TABLE Revision_Settings ADD [Require_Public_Notes_Changed] [int] NULL CONSTRAINT [DF_Revision_Settings_Require_Public_Notes_Changed] DEFAULT (2)
GO

-- D28558 - Shortcut Routing Changes
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'No_Routing_Required_A'
)
ALTER TABLE Revision_Settings ADD [No_Routing_Required_A] [bit] NULL CONSTRAINT [DF_Revision_Settings_No_Routing_Required_A] DEFAULT (0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'No_Routing_Required_B'
)
ALTER TABLE Revision_Settings ADD [No_Routing_Required_B] [bit] NULL CONSTRAINT [DF_Revision_Settings_No_Routing_Required_B] DEFAULT (0)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'No_Routing_Required_C'
)
ALTER TABLE Revision_Settings ADD [No_Routing_Required_C] [bit] NULL CONSTRAINT [DF_Revision_Settings_No_Routing_Required_C] DEFAULT (0)
GO

-- D32785: Shortcut Approval 1010127
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'No_Changes_Approval'
)
ALTER TABLE Revision_Settings ADD [No_Changes_Approval] [tinyint] NOT NULL CONSTRAINT [DF_revision_settings_No_Changes_Approval] DEFAULT (2)
GO

-- D32785: Shortcut Approval 1010127
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'No_Changes_Approval_Type'
)
ALTER TABLE Revision_Settings ADD [No_Changes_Approval_Type] [tinyint] NOT NULL CONSTRAINT [DF_revision_settings_No_Changes_Approval_Type] DEFAULT (0)
GO

-- D34880: Max Rate Easy Button and Short Cut Routing
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
	AND		COLUMN_NAME = 'Products_Rates_Decreased_Approval'
)
ALTER TABLE Revision_Settings ADD [Products_Rates_Decreased_Approval] [tinyint] NOT NULL CONSTRAINT [DF_revision_settings_Products_Rates_Decreased_Approval] DEFAULT (2)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
	AND		COLUMN_NAME = 'Products_Rates_Decreased_Approval_Type'
)
ALTER TABLE Revision_Settings ADD [Products_Rates_Decreased_Approval_Type] [tinyint] NOT NULL CONSTRAINT [DF_revision_settings_Products_Rates_Decreased_Approval_Type] DEFAULT (0)
GO

--D86748: Short Cut Approval - add option for duration change
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Program_Date_Changed_Same_Duration'
)
ALTER TABLE Revision_Settings ADD [Program_Date_Changed_Same_Duration] [int] NOT NULL CONSTRAINT [DF_revision_settings_Program_Date_Changed_Same_Duration] DEFAULT (2)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Revision_Settings'
		AND
		COLUMN_NAME = 'Program_Date_Changed_Same_Duration_Type'
)
ALTER TABLE Revision_Settings ADD [Program_Date_Changed_Same_Duration_Type] [int] NOT NULL CONSTRAINT [DF_revision_settings_Program_Date_Changed_Same_Duration_Type] DEFAULT (0)
GO
-------------------------------------------------------------------------------------------------------------------------------
--- SEARCH_SETTINGS.SQL was last modified on 05/28/2019 08:04:47 AM ---
-------------------------------------------------------------------------------------------------------------------------------
 
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Search_Settings'
)
CREATE TABLE [Search_Settings] (
	[Search_Settings_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Type_ID] [tinyint] NOT NULL,
	[Field_Name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Display_In_Search] [bit] NOT NULL CONSTRAINT [DF_Search_Settings_Display_In_Search] DEFAULT (0),
	[List_Order] [int] NOT NULL,
	[Created_Date] [datetime] NOT NULL CONSTRAINT [DF_Search_Settings_Created_Date] DEFAULT (getdate()),	
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Search_Settings_Deleted] DEFAULT (0),	
	CONSTRAINT [PK_Search_Settings] PRIMARY KEY  CLUSTERED 
	(
		[Search_Settings_ID]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO

/******************   DATA INSERT SCRIPT STARTS HERE ********************/ 
 
/*************************************************************
*************	Distributor Search Settings ******************
**************************************************************/
IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'Country' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	2,
	'Country',
	1,
	10000,
	GETDATE(),
	0
)
	 
	 
IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'Name' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	2,
	'Name',
	1,
	10001,
	GETDATE(),
	0
)
	 	 
IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'Ship To' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	2,
	'Ship To',
	1,
	10002,
	GETDATE(),
	0
)
	 	
	 	 
IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'State' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	2,
	'State',
	1,
	10003,
	GETDATE(),
	0
)
	 	 	 	
	 	 
IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'Sort By' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	2,
	'Sort By',
	1,
	10004,
	GETDATE(),
	0
)
	 	
IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'Order' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	2,
	'Order',
	1,
	10005,
	GETDATE(),
	0
)
	 	
IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'Status' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	2,
	'Status',
	1,
	10006,
	GETDATE(),
	0
)
	 	
	 		 	
/*************************************************************
*************	Product Search Settings ******************
**************************************************************/	 		 	 	 	 	 

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'Status' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	1,
	'Status',
	1,
	10000,
	GETDATE(),
	0
)	

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'Product Number' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	1,
	'Product Number',
	1,
	10001,
	GETDATE(),
	0
) 

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'Description' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	1,
	'Description',
	1,
	10002,
	GETDATE(),
	0
) 	 	 

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'Search Product From' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	1,
	'Search Product From',
	1,
	10003,
	GETDATE(),
	0
) 	 	 

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'Search Groups From' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	1,
	'Search Groups From',
	1,
	10004,
	GETDATE(),
	0
) 	 

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'Invoices(past N days)' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	1,
	'Invoices(past N days)',
	1,
	10005,
	GETDATE(),
	0
) 	 

/*************************************************************
*************	Operator Search Settings ******************
**************************************************************/	 		 	 	 	 	 

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Operator Name' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Operator Name',
	1,
	10000,
	GETDATE(),
	0
)	

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Doing Business As' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Doing Business As',
	1,
	10001,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'City' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'City',
	1,
	10002,
	GETDATE(),
	0
)	

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'State' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'State',
	1,
	10003,
	GETDATE(),
	0
)	

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Location Type' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Location Type',
	1,
	10004,
	GETDATE(),
	0
)		

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Type of Operator' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Type of Operator',
	1,
	10005,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Operator Category' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Operator Category',
	1,
	10006,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Operator Priority' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Operator Priority',
	1,
	10007,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = '# of Locations' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'# of Locations',
	1,
	10008,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Customer Type' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Customer Type',
	1,
	10009,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Market' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Market',
	1,
	10010,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Position' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Position',
	1,
	10011,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Country' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Country',
	1,
	10012,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Operator ID' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Operator ID',
	1,
	10013,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'BSA Operator ID' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'BSA Operator ID',
	1,
	10014,
	GETDATE(),
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Operator Status' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Operator Status',
	1,
	10015,
	GETDATE(),
	0
)

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Search_Settings'
	AND COLUMN_NAME = 'Display_in_Search_Results'
)
ALTER TABLE Search_Settings ADD [Display_in_Search_Results] [bit] NOT NULL CONSTRAINT [DF_Search_Settings_Display_in_Search_Result]  DEFAULT ((0))
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'UPC' 
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Display_In_Search_Results
)
VALUES
(
	1,
	'UPC',
	0,
	0,
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 2 AND Field_Name = 'Address'
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Display_In_Search_Results
)
VALUES
(
	2,
	'Address',
	0,
	0,
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'Business Segment'
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Display_In_Search_Results
)
VALUES
(
	3,
	'Business Segment',
	0,
	0,
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 3 AND Field_Name = 'List Programs'
)
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Display_In_Search_Results
)
VALUES
(
	3,
	'List Programs',
	0,
	0,
	0
)

IF NOT EXISTS
(
	SELECT	*
	FROM	Search_Settings
	WHERE	Type_ID = 1 AND Field_Name = 'Hierarchy'
)
BEGIN
DECLARE @Use_Product_Hierarchy BIT
SELECT @Use_Product_Hierarchy  = UseProductHierarchy FROM _Application_Settings

INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Display_In_Search_Results
)
VALUES
(
	1,
	'Hierarchy',
	0,
	0,
	@Use_Product_Hierarchy
)
END

IF NOT EXISTS (SELECT	* FROM	Search_Settings WHERE Type_ID = 3 AND Field_Name = 'Zip Code')
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'Zip Code',
	0,
	0,
	GETDATE(),
	0
)

IF NOT EXISTS (SELECT	* FROM	Search_Settings WHERE Type_ID = 3 AND Field_Name = 'GPO Key')
INSERT INTO Search_Settings
(
	Type_ID,
	Field_Name,
	Display_In_Search,
	List_Order,
	Created_Date,
	Deleted
)
VALUES
(
	3,
	'GPO Key',
	0,
	0,
	GETDATE(),
	0
)
-------------------------------------------------------------------------------------------------------------------------------
--- SETTINGS_LIST.SQL was last modified on 08/05/2019 10:53:46 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/***************************************************************************
--need below ONE script for new setting accordingly, please have "if not exists" in the script:
------add new setting in Program_Wizard/create_edit.cfm
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Template', 'column_name_of_the_new_setting', 'Setting Label','program/billback');

------add new setting in Program_Wizard/secondpage.cfm
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'column_name_of_the_new_setting', 'Setting Label','program/billback')

------add new setting in settings\Access_Rights\access_rights_matrix.cfm
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Profile', 'column_name_of_the_new_setting', 'Setting Label','program/billback');
GO

--select Setting_Name, Setting_Type,count(*) as cnt from	Settings_List where	deleted = 0 group by Setting_Name,Setting_type having count(*) > 1
****************************************************************************/

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Settings_List'
)
CREATE TABLE [dbo].[Settings_List](
	[Setting_ID] [int] IDENTITY(1,1) NOT NULL,
	[Setting_Type] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Setting_Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Setting_Label] [varchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Setting_Display_Value] [bit] NOT NULL CONSTRAINT [DF_Settings_List_Setting_Display_Value]  DEFAULT ((1)),
	[Deleted] [bit] NULL CONSTRAINT [DF_Settings_List_Deleted]  DEFAULT ((0)),
	[category] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Notes] [varchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_Settings_List] PRIMARY KEY CLUSTERED
(
	[Setting_ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [Settings_List]
ALTER COLUMN [Setting_Name] [varchar](100) NULL

-- populate template settings
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Discount_Identifier_ID'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Discount_Identifier_ID', 'Discount Identifier');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allocation_Method'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allocation_Method', 'Allocation_Method');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'GroupLevelBB'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'GroupLevelBB', 'Group Level Billback');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Trade'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Trade', 'Include Trade');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Trade_Blurb'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Trade_Blurb', 'Exclude Trade Explanation');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Broker_Trade_Question'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Broker_Trade_Question', 'Enable Broker and Trade Questions');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Max_Duration'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Max_Duration', 'Maximum Duration');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Max_Duration_Length'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Max_Duration_Length', 'Maximum Duration');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Min_Duration'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Min_Duration', 'Minimum Duration');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Min_Duration_Length'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Min_Duration_Length', 'Minimum Duration');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Max_Global_Volume'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Max_Global_Volume', 'Maximum Total Volume');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Max_Global_Volume_Size_LBS'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Max_Global_Volume_Size_LBS', 'Maximum Total Volume');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Max_Global_Volume_Size_CS'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Max_Global_Volume_Size_CS', 'Maximum Total Volume');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Min_Lump_Sum'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Min_Lump_Sum', 'Minimum LumpSum');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Max_Lump_Sum'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Max_Lump_Sum', 'Maximum Application.LumpsumLabel');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Lump_Sum_Cap'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Lump_Sum_Cap', 'Application.LumpsumLabel cap');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Retro_Create'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Retro_Create', 'Allow Retroactive Programs');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Retro_Create_Max'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Retro_Create_Max', 'Allow Retroactive Programs');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'No_Negative_OI'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'No_Negative_OI', 'Only allow price decrease OI');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Revision_Not_Allowed'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Revision_Not_Allowed', 'Do Not Allow Revisions');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Retro_Revision'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Retro_Revision', 'Allow Retroactive Revisions');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Retro_Revision_Span'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Retro_Revision_Span', 'Allow Retroactive Revisions');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Auto_Renew_Option'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Auto_Renew_Option', 'Allow Auto Renewal');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_AR_Modification'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_AR_Modification', 'User can modify Auto Renew Span');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Billback_date'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Billback_date', 'Last Date to Claim');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Billback_date'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Billback_date', 'Last Date to Claim');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Billback_Date_Span'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Billback_Date_Span', 'Last Date to Claim');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Payable_To'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Payable_To', 'Payable To');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Payable_To_Required'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Payable_To_Required', 'Payable To - Required');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Send_Payment_To'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Send_Payment_To', 'Send Payment To');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Customer_Acceptance'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Customer_Acceptance', 'Customer Acceptance Block');
GO


-- need to remove Controllable_Volume and Adv_Spend as we both of them are related to Zero_Volume
--Controllable_Volume input type="hidden" name="Controllable_Volume" value="0"
if exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Controllable_Volume'
)
DELETE FROM Settings_List
WHERE	Setting_Name = 'Controllable_Volume'
AND Setting_Type = 'Template'
GO

--Adv_Spend  input type="hidden" name="Adv_Spend" value="0"
if exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Adv_Spend'
)
DELETE FROM Settings_List
WHERE	Setting_Name = 'Adv_Spend'
AND Setting_Type = 'Template'
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Zero_Volume'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Zero_Volume', 'Allow Zero Volume');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Specify_Distributors'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Specify_Distributors', 'Allow application.returned_customer_setting.distributor_label_plural');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Require_Distributor'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Require_Distributor', 'Allow application.returned_customer_setting.distributor_label_plural');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'One_Distributor'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'One_Distributor', 'Allow application.returned_customer_setting.distributor_label_plural');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Specify_Distributor_Groups'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Specify_Distributor_Groups', 'Select application.returned_customer_setting.distributor_label_plural by Groups');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Specify_Operators'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Specify_Operators', 'Allow application.returned_customer_setting.operator_label_plural');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Require_Operator'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Require_Operator', 'Allow application.returned_customer_setting.operator_label_plural');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'One_Operator'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'One_Operator', 'Allow application.returned_customer_setting.operator_label_plural');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Specify_Brokers'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Specify_Brokers', 'Allow application.returned_customer_setting.broker_label_plural');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'One_Discount_Mandated'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'One_Discount_Mandated', 'Discount Type');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Only_One_Discount'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Only_One_Discount', 'Discount Type');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Equipment_Placement'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Equipment_Placement', 'Equipment and Dispenser Placement');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Volume_Cap'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Volume_Cap', 'Volume Cap');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_In_Catalog'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_In_Catalog', 'Include in Catalog');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Show_Awarded_in_Catalog'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Show_Awarded_in_Catalog', 'Include awarded in Catalog');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Catalog_Type'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Catalog_Type', 'Include in Catalog');
GO


/*
---- removed by 14333
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Program'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Program', 'Include in Catalog');
GO
*/


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Dynamic_Static_Groups'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Dynamic_Static_Groups', 'Dynamic Groups only applies to groups');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Restrict_Product_Group_Level'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Restrict_Product_Group_Level', 'Restrict group level');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Restrict_Product_Group_Level'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Restrict_Product_Group_Level', 'Restrict group level');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Check_Duplicate_Program'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Check_Duplicate_Program', 'Check for Duplicate Programs');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Restrict_On_Approval_Group'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Restrict_On_Approval_Group', 'Restrict on approvalGroupType.label');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Sysco_Report_ON'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Sysco_Report_ON', 'Sysco Report');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'exclude_sig_products'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'exclude_sig_products', 'Exclude signature products');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Approval_group'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Approval_group', 'Allow approvalGroupType.label');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Group_Deal'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Group_Deal', 'Select Products by Groups');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Program_Date_Type'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Program_Date_Type', 'Program Date Type');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Days_Before_Auto_Renew'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Days_Before_Auto_Renew', 'Days Before Expiration to Auto Renew');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Expiring_Notification_Span'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Expiring_Notification_Span', 'Weeks Before End of Program to Mark as Expiring');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Days_For_Reminder'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Days_For_Reminder', 'Days After RFA to Send Approval Reminder');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'apply_rebate_rates'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'apply_rebate_rates', 'Apply default rates for Application.RebateLabel');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'mass_billback_pay'
	and Setting_Type = 'Template'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'mass_billback_pay', 'Allow mass payment on billbacks');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Competitive_Information_On'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Competitive_Information_On', 'Competitive Information');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Program_Start_Day'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Program_Start_Day', 'Program Start Day');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Program_End_Day'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Program_End_Day', 'Program End Day');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Program_Min_Start_Date'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Program_Min_Start_Date', 'Program start date cannot start before');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Program_Max_End_Date'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Program_Max_End_Date', 'rogram end date cannot end after');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Pullbacks_on'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Pullbacks_on', 'appSettings.getPullbackLabel On');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'is_pullback_corporate_deal'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'is_pullback_corporate_deal', 'Corporate Deal');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'pullback_from_corporate'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'pullback_from_corporate', 'appSettings.getPullbackLabel from Corporate');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Pullback_Include_RediVolume'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Pullback_Include_RediVolume', 'Include Redi Volume in Distributor Trade payments');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Pullback_redi_volume_percent'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Pullback_redi_volume_percent', 'What precent of gross price should be used when calculating earnings for redi volume?');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Open_Date'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Open_Date', 'Include Open Date');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Date_Needed_by'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Date_Needed_by', 'Include Date Needed By');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Reply_Date'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Reply_Date', 'Include Expected Reply Date');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Competitive_Data_Tracking'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Competitive_Data_Tracking', 'Include Competitive Data Tracking');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'display_basesales_Competitive_Data'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'display_basesales_Competitive_Data', 'Display Base Sales in Competitive Data');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BidRequestStatusOn'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'BidRequestStatusOn', 'Proposal Status On');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BidRequestStatusChangePgmStatus'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'BidRequestStatusChangePgmStatus', 'Proposal Status Affects Program Status');
GO



if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Template_In_Deals_IF'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Template_In_Deals_IF', 'Include in deals interface');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Include_Treatment_Basis_Code'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Include_Treatment_Basis_Code', 'Include treatment code and basis code');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Exclude_Same_Spending_Cat_From_TPA'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Exclude_Same_Spending_Cat_From_TPA', 'Exclude same spending category programs from TPA');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'ByPass_Margin_Evaluation'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'ByPass_Margin_Evaluation', 'Does not require margin evaluation');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'ByPass_Margin_Evaluation_Options'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'ByPass_Margin_Evaluation_Options', 'Does not require margin evaluation');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'EZButton_On'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'EZButton_On', 'EZ Button');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BB_D_Template_Overrides_Deviation_Tolerances'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'BB_D_Template_Overrides_Deviation_Tolerances', 'Template Overrides Deviation Tolerances');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BB_D_Purchase_Period_OverRide'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'BB_D_Purchase_Period_OverRide', 'Billback Purchase Period Over Ride for Volume Days from billback end date to capture invoice data');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BB_D_Purchase_Period_OverRide_Rate'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'BB_D_Purchase_Period_OverRide_Rate', 'Billback Purchase Period Over Ride for Rate Days from billback end date to capture invoice data');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BB_D_Aggregation_Period_OverRide'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'BB_D_Aggregation_Period_OverRide', 'Billback Aggregation Period Over Ride Days from BB end date to capture other operator billbacks');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Release_Settlement'
	AND 	Setting_Type = 'Template'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Release_Settlement', 'Release Settlement');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'RS_DaysToClaim'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'RS_DaysToClaim', 'Days after Program end date to send release settlement');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Retail_Performance_Dates'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Retail_Performance_Dates', 'Performance Dates On');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'price_protection_on'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'price_protection_on', 'Price Protection On');
GO


-- No need below 2 columns, removed by TSF - Label 18943:
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Distribution_Channel'
)
DELETE FROM Settings_List
WHERE	Setting_Name = 'Distribution_Channel'
AND Setting_Type = 'Template'
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Division_Num'
)
DELETE FROM Settings_List
WHERE	Setting_Name = 'Division_Num'
AND Setting_Type = 'Template'
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Interface_On_Approval'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Interface_On_Approval', 'Interface on Program Approval');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Track_Price_Comp'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Track_Price_Compl', 'Track Price and Competitor on lost programs?');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Retailer_Info_On'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Retailer_Info_On', 'Retailer Information On');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Send_RFA_Email'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Send_RFA_Email', 'Send Email On RFA');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Distributor_Product_Integrity_Rule_ID'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Distributor_Product_Integrity_Rule_ID', 'application.returned_customer_setting.distributor_label_singular/Product Integrity Rule');
GO


--insert Freight_Approval_Reqd to Settings_list instead of Freight_Approval_Required (Program_Control_Panel_Options.Freight_Approval_Required)
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Freight_Approval_Reqd'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Freight_Approval_Reqd', 'Freight Approval Required');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Use_Fixed_Price_As_Base_Sales'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Use_Fixed_Price_As_Base_Sales', 'Use Fixed Price as Base Sales');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Template_UPC_Display'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Template_UPC_Display', 'Display UPC');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Track_Price_Comp'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Track_Price_Comp', 'Track Price and Competitor on lost programs?');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Discount_Identifier_ID'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Discount_Identifier_ID', 'Discount Identifier');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Min_Global_Volume'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Min_Global_Volume', 'Minimum Total Volume');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Lower_Pricing_Level'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Lower_Pricing_Level', 'Level[2] / Level[3] allowed');
GO


-- Allow_Product_Group_Level is saved in TemplateAllowProductGroupLevel table, but insert below in Settings_list table for show/hide
-- 
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Product_Group_Level'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Allow_Product_Group_Level', 'Allow group levels');
GO

-- set templateprogrampostapprovalstatus for TemplateProgramPostApprovalStatus_#Program_Post_Approval_Status_ID#
-- loop through qGetTemplateProgramPostApprovalStatus Include in #Program_Post_Approval_Status_Desc#
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'templateprogrampostapprovalstatus'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'templateprogrampostapprovalstatus', 'Include in #Program_Post_Approval_Status_Desc#');
GO

-- profile settings, show/hide
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Program_Post_Approval_Status'
		AND
		COLUMN_NAME = 'Setting_Display_Value'
)
ALTER TABLE Program_Post_Approval_Status  ADD [Setting_Display_Value] [bit] Not NULL CONSTRAINT [DF_Program_Post_Approval_Status_Setting_Display_Value]  DEFAULT ((1))
GO


-- populate user profile settings
-- columns_BB_Profiles_Settings_table
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_BB_Beyond_Budget'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Approve_BB_Beyond_Budget', 'Approve Billback Beyond Budget','BB','appSettings.getBudgetsFunctionalityOn()');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Last_Date_To_Claim'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Last_Date_To_Claim', 'Approve Last Date To Claim','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Add_Payee_Any_Position'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Add_Payee_Any_Position', 'Add Payee/Program from any position','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Add_Program'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Add_Program', 'Add program without payee','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Allow_Vendor_Master_Search'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Allow_Vendor_Master_Search', 'Allow Vendor Master Search','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Apply_Pullback'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Apply_Pullback', 'Apply #appSettings.getPullbackLabel()#','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Apply_Pullback_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Apply_Pullback_Amount', 'Apply #appSettings.getPullbackLabel()# Amount','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Apply_Rebate_Rates'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Apply_Rebate_Rates', 'Apply Rebate Rates','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Approve'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Approve', 'Approve','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Approve_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Approve_Amount', 'Approve Deviation Amount','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Approve_Critical'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Approve_Critical', 'Approve Critical','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Create'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Create', 'sstring','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Create_View'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Create_View', 'Billback View','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Create_None'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Create_None', 'Billback - None','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Delete'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Delete', 'Delete Billback','BB');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Dev_Grid_Manual_Rate_Override_Check'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Dev_Grid_Manual_Rate_Override_Check', 'Manual rate override > claimed rate','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Pay_Req_Approval_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Pay_Req_Approval_Amount', 'Pay.Req. Approval Amount','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Profiles_Settings_ID'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Profiles_Settings_ID', 'sstring','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Rate_Override'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Rate_Override', 'Rate Override','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Reverse'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Reverse', 'Reverse Billback','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_RFA_Agreed'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_RFA_Agreed', 'RFA scorecard - Agreed','BB');
GO




if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Search_By_Analyst'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Search_By_Analyst', 'Search BB by Analyst','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Tot_Approve_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Tot_Approve_Amount', 'Approve Total Amount','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_UnApply_Pullback'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_UnApply_Pullback', 'Un-apply #appSettings.getPullbackLabel()#','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Updated_Date'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Updated_Date', 'sstring','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_View_Deviation'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_View_Deviation', 'View Deviation','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Volume_Override'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Volume_Override', 'Volume Override','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Credit_Memo_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Credit_Memo_Amount', 'Credit Memo Amount','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Mass_Billback_Pay'
and Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Mass_Billback_Pay', 'Mass Pay Billbacks','BB');
GO

--columns_DD_Status_table, using below for show/hide 'Hide #DD_Status_Description#' on deduction profile settings
if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'DD_Status'
		AND
		COLUMN_NAME = 'Setting_Display_Value'
)
ALTER TABLE DD_Status  ADD [Setting_Display_Value] [bit] Not NULL CONSTRAINT [DF_DD_Status_Setting_Display_Value]  DEFAULT ((1))
GO

/*  remove below from setting-llist table
DD_Status_ID	DD_Status_Description
1	New
2	Open
3	RFA
4	Closed
5	Auto Closed
6	Deleted
7	ReBill
8	Credit
9	Closed Credit
*/

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_1'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_1'
and Setting_Type = 'Profile'
GO

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_2'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_2'
and Setting_Type = 'Profile'
GO


if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_3'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_3'
and Setting_Type = 'Profile'
GO

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_4'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_4'
and Setting_Type = 'Profile'
GO

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_5'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_5'
and Setting_Type = 'Profile'
GO

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_6'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_6'
and Setting_Type = 'Profile'
GO

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_7'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_7'
and Setting_Type = 'Profile'
GO

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_8'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_8'
and Setting_Type = 'Profile'
GO

if exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Hide_9'
)
delete from Settings_List
where Setting_Name = 'DD_Hide_9'
and Setting_Type = 'Profile'
GO

-- columns_Deductions_Profiles_Settings_table
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_ACCESS_LEVEL'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_ACCESS_LEVEL', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_ACCESS_LEVEL_View'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_ACCESS_LEVEL_View', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_ACCESS_LEVEL_None'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_ACCESS_LEVEL_None', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Approve'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Approve', 'Approve','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Approve_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Approve_Amount', 'Approve Amount','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Approve_Rebill'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Approve_Rebill', 'Allow Rebill','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Created_Date'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Created_Date', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Delete'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Delete', 'Delete/Undelete Deductions','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Disable_Inv_Link'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Disable_Inv_Link', 'Disable Invoice Link','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Edit_Cust_RefNo'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Edit_Cust_RefNo', 'Edit Customer Reference ##','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Internal_Notes'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Internal_Notes', 'Internal Action Notes','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Match_Central'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Match_Central', 'Match Central','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Match_Central_Write_Off_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Match_Central_Write_Off_Amount', 'Match Central Write Off Amount','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Open_Rebill_Transfer'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Open_Rebill_Transfer', 'Rebill <=> Open','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Reassign_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Reassign_Access', 'Reassign Deductions','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Reject'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Reject', 'Reject Deductions','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_RFA_Agreed'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_RFA_Agreed', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Search_By_Analyst'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Search_By_Analyst', 'Search DD by Analyst','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Split'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Split', 'Split Deductions','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_Updated_Date'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_Updated_Date', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_User_ID'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_User_ID', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Deduction_Analyst'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Deduction_Analyst', 'sstring','DD');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Deleted'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Deleted', 'sstring','DD');
GO


-- columns_Operating_Group_table


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Operating_Group_Profile_Settings_On'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Operating_Group_Profile_Settings_On', 'Operating Group Profile Settings','Operating Group');
GO

-- columns_Profiles_Settings_table

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Access_Price_List'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Access_Price_List', 'Price List Access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Admin_AddDelete_Users'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Admin_AddDelete_Users', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Admin_Control_Panels'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Admin_Control_Panels', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Admin_Data_Exceptions'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Admin_Data_Exceptions', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Admin_Data_Integ_Schedule'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Admin_Data_Integ_Schedule', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Admin_Data_Purging'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Admin_Data_Purging', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Admin_Profile_Maintenance'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Admin_Profile_Maintenance', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_All_Products_Program'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_All_Products_Program', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Below_Floor'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Below_Floor', 'Approve Below Pricing Floor','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Below_Floor_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Below_Floor_Amount', 'Approve Below Pricing Floor Amount','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Beyond_Annual_Case_Rate'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Beyond_Annual_Case_Rate', 'Approve Beyond Annual Case Rate','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Duplicate_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Duplicate_Programs', 'Approve Duplicate Programs','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Equipment_Placement'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Equipment_Placement', 'Approve Equipment/Dispenser Placement','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Export_Agreements'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Export_Agreements', 'Approval Rights','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Freight_Adjustment_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Freight_Adjustment_Programs', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Freight_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Freight_Programs', 'Approve Freight Programs','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Group_Deals'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Group_Deals', 'Approve Group Program','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Growth_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Growth_Programs', 'Approve Growth Programs','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Lumpsum'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Lumpsum', 'Approve Lumpsum','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Pgm_Beyond_Budget'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Pgm_Beyond_Budget', 'Approve Program Beyond Budget','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Program_No_Pullback'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Program_No_Pullback', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Pullback'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Approve_Pullback', 'Approve #appSettings.getPullbackLabel()','Program','appSettings.getPullbacksOn()');
GO


-- added pullback_profile_template_view for the link popuping "Approve #appSettings.getPullbackLabel()# - template list"
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'pullback_profile_template_view'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'pullback_profile_template_view', 'Approve #appSettings.getPullbackLabel()# - template list','Program','appSettings.getPullbacksOn()');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Pullbacks_Percent'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Pullbacks_Percent', 'sstring','Program');
GO

-- onlu use  Approve_Revision_Types_A for the setting
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Revision_Types_A'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Revision_Types_A', 'Approve Revision Types','Program');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Revision_Types_B'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Revision_Types_B', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Revision_Types_C'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Revision_Types_C', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Roll_Over_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Roll_Over_Programs', 'Approve Roll Over Programs','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Sysco_Deals'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Sysco_Deals', 'Approve Sysco Deals','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Upfront_Payments'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Upfront_Payments', 'Approve Advanced Funds','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Zero_Product_Cost'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Zero_Product_Cost', 'Approve $0 Product Costs','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Zero_Product_Price'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Approve_Zero_Product_Price', 'Approve $0 Product Price','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Base_View'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Base_View', 'Base View','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Clause_Library_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Clause_Library_Access', 'Clause Library Access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Clause_Program_Edit_Remove'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Clause_Program_Edit_Remove', 'Program - Edit/Remove Required Clause','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Com_Tools_CreateEdit_Pricing_Formula'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Com_Tools_CreateEdit_Pricing_Formula', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Com_Tools_View_Market_Data'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Com_Tools_View_Market_Data', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Com_Tools_View_Pricing_Formula'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Com_Tools_View_Pricing_Formula', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Comm_Email'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Comm_Email', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Comm_Fax'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Comm_Fax', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Comm_Print'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Comm_Print', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Commodity_Price_Rule_Create_Edit'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Commodity_Price_Rule_Create_Edit', 'Create/Edit Price Rule','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Commodity_Price_Rule_View'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Commodity_Price_Rule_View', 'View Price Rule','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Commodity_Settings'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Commodity_Settings', 'Commodity Settings','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_Approval_Rights'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_Approval_Rights', 'Approval Rights','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_Maximum_Lineitem_Margin'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_Maximum_Lineitem_Margin', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_Minimum_Lineitem_Margin'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_Minimum_Lineitem_Margin', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_View_Approved_Margins'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_View_Approved_Margins', 'View LH pane Approved Margins Link','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_View_Brokerage_Margins'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Cont_Prog_View_Brokerage_Margins', 'View Brokerage Margins','Program','appsettings.getBrokerage_Functionality_On');
GO

------Cont_Prog_View_Create_Program has -1,0,1 values, so we have 3 options on user profiles page
------ added 2 more records on Settings_List table
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_View_Create_Program'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_View_Create_Program', 'Program - View & Create','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_View_Create_Program_View'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_View_Create_Program_View', 'Program - View','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_View_Create_Program_None'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_View_Create_Program_None', 'Program - None','Program');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Cont_Prog_View_Margins'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Cont_Prog_View_Margins', 'View Margins','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Create_Approve_Export_Agreements'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Create_Approve_Export_Agreements', 'Approval & Creation Rights','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Create_Budget'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Create_Budget', 'Create Budgets','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Create_Export_Agreements'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Create_Export_Agreements', 'Creation Rights','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Create_New_Export_Customer'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Create_New_Export_Customer', 'Create New Customer','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Create_Operator_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Create_Operator_Access', 'Create #application.returned_customer_setting.operator_label_singular# access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Credit_Manager'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Credit_Manager', 'Credit Manager','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Ctr_Pnl_Commod_Pricing'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Ctr_Pnl_Commod_Pricing', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Ctr_Pnl_Payables'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Ctr_Pnl_Payables', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Ctr_Pnl_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Ctr_Pnl_Programs', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Delete_Program_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Delete_Program_Access', 'Cancel Program','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Executive_Agreement'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Executive_Agreement', 'sstring','Program');
GO




if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Freight_View_Create'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Freight_View_Create', 'Freight - View & Create','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Freight_View_Create_View'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Freight_View_Create_View', 'Freight - View','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Freight_View_Create_None'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Freight_View_Create_None', 'Freight - None','Program');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Fund_Setting_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Fund_Setting_Access', 'Fund Setting Access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Geographic_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Geographic_Access', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Inactive_LS_Approval_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Inactive_LS_Approval_Amount', 'Inactive #Application.LumpsumLabel# Approval','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Install_Patch'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Install_Patch', 'Install Patch','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Internal_Notes'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Internal_Notes', 'Business Considerations','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Is_Locked'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Is_Locked', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Last_Changed_Date'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Last_Changed_Date', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Last_Changed_User_ID'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Last_Changed_User_ID', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Lock_Date'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Lock_Date', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Locked_By_User_ID'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Locked_By_User_ID', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Lump_Sum_Approval_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Lump_Sum_Approval_Amount', 'Growth #Application.LumpsumLabel# Approval','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Lumpsum_Approval_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Lumpsum_Approval_Amount', 'Lumpsum Approval Amount','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Margin_Display_UOM_CS'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Margin_Display_UOM_CS', 'Margin Display UOM - CS','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Margin_Display_UOM_EQ'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Margin_Display_UOM_EQ', 'Margin Display UOM - EQ CS','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Margin_Display_UOM_LB'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Margin_Display_UOM_LB', 'Margin Display UOM - LB','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Margin_Target_Variation'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Margin_Target_Variation', 'Margin Target Variation','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Mass_RFA_Program_Approve'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Mass_RFA_Program_Approve', 'Mass Approve RFA Programs','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Max_Approval_Volume'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Max_Approval_Volume', 'Max Approvable Volume','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Max_Approval_Volume_Uom'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Max_Approval_Volume_Uom', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Max_Net_Sales_Dollar'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Max_Net_Sales_Dollar', 'Max Net Sales $','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Max_Opr_Margin'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Max_Opr_Margin', 'Min Operating Margin%','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Max_Program_Spend'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Max_Program_Spend', 'Max #appsettings.getMarginColHeader14()#','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Min_Approval_Volume'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Min_Approval_Volume', 'Min Approvable Volume','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Min_Approval_Volume_Uom'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Min_Approval_Volume_Uom', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pay_Bill_Approval_Rights'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pay_Bill_Approval_Rights', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pay_Bill_Maximum_Aggregate_Deviation'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pay_Bill_Maximum_Aggregate_Deviation', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pay_Bill_Minimum_Aggregate_Deviation'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pay_Bill_Minimum_Aggregate_Deviation', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pay_Bill_View_Expected_Rate'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pay_Bill_View_Expected_Rate', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pay_Ded_Approval_Rights'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pay_Ded_Approval_Rights', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pay_Ded_Maximum_Deduction_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pay_Ded_Maximum_Deduction_Amount', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pay_Ded_Minimum_Deduction_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pay_Ded_Minimum_Deduction_Amount', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Payment_History_Alert'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Payment_History_Alert', 'Payment history alert on approval','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Payment_Processor'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Payment_Processor', 'Payment Processor','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pda_Download'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pda_Download', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Pda_Upload'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Pda_Upload', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'PM_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'PM_Access', 'Project Management Access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'program_margin_approval_method'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'program_margin_approval_method', 'Approval is based on','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Program_Scorecard_Restrict_Created_By'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Program_Scorecard_Restrict_Created_By', 'Restrict Program Access to Created by','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Read_Only_Catalog_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Read_Only_Catalog_Access', 'Read Only Catalog Access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Reassign_Program_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Reassign_Program_Access', 'Reassign Programs','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Reassign_Project_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Reassign_Project_Access', 'Project Reassign Access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Reimbursement_Update'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Reimbursement_Update', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'ReleaseSettlement'
AND 	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'ReleaseSettlement', 'Release Settlement','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Rep_Run_Reports'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Rep_Run_Reports', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Report_Scheduler'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Report_Scheduler', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Reports_Access_Level'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Reports_Access_Level', 'Reports Access Level','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'RFA_Agreed'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'RFA_Agreed', 'RFA scorecard - Agreed','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'RFA_Agreed_DA'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'RFA_Agreed_DA', 'RFA scorecard - Display all','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Search_Documents'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Search_Documents', 'Search Documents','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'See_Awarded_in_Catalog'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'See_Awarded_in_Catalog', 'See Only Awarded in Catalog','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Settings_Panel'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Settings_Panel', 'Settings Control Panel','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Show_Export_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Show_Export_Programs', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Show_Trade_Checkbook'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Show_Trade_Checkbook', 'Trade Checkbook Access','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Special_Price_List_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Special_Price_List_Access', 'View Special Price List','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Submit_Work_Request'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Submit_Work_Request', 'Submit Work Request Tickets','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Total_LS_Approval_Amount'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Total_LS_Approval_Amount', 'Total #Application.LumpsumLabel# Approval','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Use_Set_Email_Message'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Use_Set_Email_Message', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Use_Set_Tickler'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Use_Set_Tickler', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Use_Set_User_Password'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Use_Set_User_Password', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Broker_List'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Broker_List', 'Display broker list','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Cost'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Cost', 'View Cost','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Invoices'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Invoices', 'View Invoices','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_LH_Pane_Budget_Link'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_LH_Pane_Budget_Link', 'View LH pane Budget Link','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Net_Sales'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Net_Sales', 'View Net Sales','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Operating_Income'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Operating_Income', 'View Operating Income','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Private_Documents'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Private_Documents', 'sstring','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Prog_In_Duplicate_Check_Window'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Prog_In_Duplicate_Check_Window', 'View Prog in Duplicate Check Window','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Target_Margins'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Target_Margins', 'View Target Margins','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_TPA'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_TPA', 'View Trade Adjustment','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Volume_Details_Tab_Display'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Volume_Details_Tab_Display', 'Volume Details Tab Display','Program');
GO


-- View link or loop in user profiles page:
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Lumpsum_Profile_View_Disabled_Enabled'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Lumpsum_Profile_View_Disabled_Enabled', '#Application.LumpsumLabel# Component Approval','Program','popup window-view link');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'ProfileProgramPostApprovalStatus_CurrentID'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'ProfileProgramPostApprovalStatus_CurrentID', 'Allow Change Status #Program_Post_Approval_Status_Desc#','Program','settings in the loop');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'approvalGroupType_view'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'approvalGroupType_view', '#approvalGroupType.Label# Access/Approve','Program','popup window-view link');
GO

-- Show_Fund_Settings is not the input name in Program_Wizard/create_edit.cfm
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Show_Fund_Settings'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Show_Fund_Settings', 'Fiscal Year, A/R and Allocation','Program','control Fiscal Year section, no column in Program_Control_Panel_Options');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approve_Freight_Adjustment_Programs'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Approve_Freight_Adjustment_Programs', 'Approve Freight Adjustment Programs','Program','Approve Freight Adjustment Programs');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Delete_Pages_Program_Letter'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Delete_Pages_Program_Letter', 'Delete Pages in Program Letter','Program','appSettings.getlettersavailable');
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'View_Workflow_Report_Data'
	AND	Setting_Type = 'Profile'   -- for User profile
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_Workflow_Report_Data', 'View Workflow Report Data','Program')
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Market_Price_Variance'
AND	Setting_Type = 'Profile'   -- for User profile
--AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Market_Price_Variance', 'Max Market Price Variance','Program','Max Market Price Variance');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Search_Inactive_Products_Programs'
AND	Setting_Type = 'Profile'   -- for User profile
--AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Search_Inactive_Products_Programs', 'Search inactive products','Program','Search inactive products');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Search_Inactive_Distributors_Programs'
AND	Setting_Type = 'Profile'   -- for User profile
--AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Search_Inactive_Distributors_Programs', 'Search inactive distributors','Program','Search inactive distributors');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Search_Inactive_Operators_Programs'
AND	Setting_Type = 'Profile'   -- for User profile
--AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type,Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Search_Inactive_Operators_Programs', 'Search inactive operators','admin','Search inactive operators');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Re_instate_deleted_programs'
AND	Setting_Type = 'Profile'   -- for User profile
--AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Re_instate_deleted_programs', 'Re-instate deleted programs','admin','undeleted programs page');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Generate_Program_Letters'
AND	Setting_Type = 'Profile'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value,Notes)
VALUES
('Profile', 'Generate_Program_Letters', 'Generate Program Letters','Program',1,'Generate Program Letters')
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Freight_Accrual_Considers_Cash_Discount'
	AND	Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Freight_Accrual_Considers_Cash_Discount', 'Freight accrual considers cash discount');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Single_Component_Per_Discount_Type'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Single_Component_Per_Discount_Type', 'Single component per discount type');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'AutoAdd_Distributor_ThirdPartyClaims'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'AutoAdd_Distributor_ThirdPartyClaims', 'Auto add distributor for third party claims');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Auto_Volume'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Auto_Volume', 'Automate volume');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Auto_Actual'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Auto_Actual', 'Weeks after start date to update actual');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Auto_Future'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Auto_Future', 'Weeks after start date to automate future volume');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Future_Zero'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Future_Zero', 'Weeks before end date to set future volume to zero');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Clear_Lumpsum'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Clear_Lumpsum', 'Days after expiration to clear open lump sums');
GO


/*
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Update_Program_Distributors_Approved_Billbacks'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Update_Program_Distributors_Approved_Billbacks', 'updated Distributors on Program based on Approved Billbacks');
GO
*/


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Base_Sales_Equal_To_Lowest_Bracket'
)
BEGIN
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Base_Sales_Equal_To_Lowest_Bracket', 'Base Sales Equal To Lowest Bracket');

DECLARE @SettingID INT
SET @SettingID =(SELECT @@IDENTITY)


	--set up the default value to 0 for Distributor Trade/Shelter,Field Execution,Operator Direct or HQ Programs,Operator-Deviated Pricing,Brokerage,LSAutoPay
	INSERT INTO Settings_Template_Display(Generic_Type,Setting_ID,Setting_Display_Value)
		VALUES ('Distributor Trade/Shelter',@SettingID,0)

	INSERT INTO Settings_Template_Display(Generic_Type,Setting_ID,Setting_Display_Value)
		VALUES ('Field Execution',@SettingID,0)

	INSERT INTO Settings_Template_Display(Generic_Type,Setting_ID,Setting_Display_Value)
		VALUES ('Operator Direct or HQ Programs',@SettingID,0)

	INSERT INTO Settings_Template_Display(Generic_Type,Setting_ID,Setting_Display_Value)
		VALUES ('Operator-Deviated Pricing',@SettingID,0)

	INSERT INTO Settings_Template_Display(Generic_Type,Setting_ID,Setting_Display_Value)
		VALUES ('Brokerage',@SettingID,0)

	INSERT INTO Settings_Template_Display(Generic_Type,Setting_ID,Setting_Display_Value)
		VALUES ('LSAutoPay',@SettingID,0)

END
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Edit_Price_Bracket'
AND	Setting_Type = 'Profile'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value,Notes)
VALUES
('Profile', 'Edit_Price_Bracket', 'Edit Price Bracket','Program',1,'Edit Price Bracket')
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Margin_Price_List_Header_ID'
	AND	Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Margin_Price_List_Header_ID', 'Margin Price List');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'EzButton_Approve_Beyond_MaxRate'
AND	Setting_Type = 'Profile'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value,Notes)
VALUES
('Profile', 'EzButton_Approve_Beyond_MaxRate', 'EZ Button - Approve Beyond  Max Rate','Program',1,'EZ Button - Approve Beyond  Max Rate')
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Adjust'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'BB_Adjust', 'Adjust Billback','BB','Adjust Billback');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Adjust'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'BB_Adjust', 'Adjust Billback','BB','Adjust Billback');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_closing_methods_view'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'BB_closing_methods_view', 'Billback Closing Methods List','BB','BB_closing_methods_view');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Mass_Approve'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'BB_Mass_Approve', 'Mass Approve Billback','BB','BB_Mass_Approve');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Mass_Delete'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'BB_Mass_Delete', 'Mass Delete Billback','BB','BB_Mass_Delete');
GO

-- D28559: Warning / Prevent - Identical FIXED PRICE / REBATE / PAID TO
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Item_Fixed_Rebate_Paid_To_Dup_Message'
	AND	Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name, Setting_Label)
VALUES
('Template', 'Item_Fixed_Rebate_Paid_To_Dup_Message', 'Identify items having rebate and fixed price for same paid to');
GO



-- D28354 Program - new page to enter Line #
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'display_bid_info_page'
	AND	Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name, Setting_Label)
VALUES
('Template', 'display_bid_info_page', 'Display Bid Info Page');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Volume_Forecast'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Volume_Forecast', 'Volume Forecast','Program');
GO

-- D29125 Base Sales for a program
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Base_Sales_based_on_Prg_Start_Date'
	AND	Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name, Setting_Label)
VALUES
('Template', 'Base_Sales_based_on_Prg_Start_Date', 'Base Sales based on Prg Start Date');
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Select_Effective_Date_for_Price'
	AND	Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name, Setting_Label)
VALUES
('Template', 'Select_Effective_Date_for_Price', 'Select Effective Date for Price');
GO

-- D29498: Volume Deviation - setting to not run and not consider
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Ignore_Billback_Volume_Deviation'
	AND	Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name, Setting_Label)
VALUES
('Template', 'Ignore_Billback_Volume_Deviation', 'Ignore billback volume deviation');
GO




/*D29929: Dashboard - Settings*/


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Dashboard_UOM'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Dashboard_UOM', 'Dashboard UOM','settings');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Dashboard_Remote_Access'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Dashboard_Remote_Access', 'Dashboard Remote Access','settings');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Dashboard_Access_View'
AND	Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Dashboard_Access_View', 'Dashboard Access View','admin');
GO






/* --- D28359:Deviation Grid - don't consider volume, only can approve Expected $/ Anand Rao/09-Jan-2012 ---> */

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_DevGrid_Expected'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_DevGrid_Expected', '','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_DevGrid_ELT'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_DevGrid_ELT', '','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_DevGrid_Claimed'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_DevGrid_Claimed', '','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_DevGrid_Selected'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_DevGrid_Selected', '','BB');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Edit_Product_MasterData'
	AND	Setting_Type = 'Profile'   -- for User profile
	--AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Profile', 'Edit_Product_MasterData', 'Edit Product Master Data','Admin','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BB_Tolerance_DVT'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'BB_Tolerance_DVT', 'Distributor Volume Tolerance','Template','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'BB_Tolerance_ERT'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'BB_Tolerance_ERT', 'Rate Tolerance','Template','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Cannot_Exceed_Percent'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Cannot_Exceed_Percent', 'Deviation Cannot Exceed Percent','Template','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Cannot_Exceed_Dollar'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Cannot_Exceed_Dollar', 'Deviation Cannot Exceed Dollar ','Template','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Maximum_Dollar_Amount_Checked'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Maximum_Dollar_Amount_Checked', 'Include Max Dollar Amt','Template','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Auto_Deviation_Inc_Manual_BB'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Auto_Deviation_Inc_Manual_BB', 'Include manually entered billbacks in auto processing','Template','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Billback_Status_if_Below_Deviation'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Billback_Status_if_Below_Deviation', 'Billback Status if Below Deviation','Template','');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Billback_Status_if_Exceeds_Deviation'
	--AND	Setting_Type = 'Profile'   -- for User profile
	AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Billback_Status_if_Exceeds_Deviation', 'Billback Status if Exceeds Deviation','Template','');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_BB_CRA_Analysis_Report'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_BB_CRA_Analysis_Report', 'View BB CRA Analysis Rpt','BB');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Specify_Operator_Groups'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Template', 'Specify_Operator_Groups', 'Specify_Operator_Groups','');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Change_BB_Start_End_Date'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Change_BB_Start_End_Date', 'Change BB start/end dates','BB');
GO

IF NOT EXISTS ( SELECT 1
                  FROM SETTINGS_LIST
                 WHERE Setting_Name = 'Currency_Conversion_Factor' )
  INSERT INTO SETTINGS_LIST
              (Setting_Type
               ,Setting_Name
               ,Setting_Label
               ,Category)
       VALUES ('Template'
               ,'Currency_Conversion_Factor'
               ,'Currency_Conversion_Factor'
               ,'');
GO

IF NOT EXISTS ( SELECT 1
                  FROM SETTINGS_LIST
                 WHERE Setting_Name = 'Edit_Volume_FC_Below_Me' )
  INSERT INTO SETTINGS_LIST
              (Setting_Type
               ,Setting_Name
               ,Setting_Label
               ,Category)
       VALUES ('Profile'
               ,'Edit_Volume_FC_Below_Me'
               ,'Program ? Edit Volume Forecasts Below Me'
               ,'Program');
GO
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'ProgramView_WIPPositionsBelowMe'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'ProgramView_WIPPositionsBelowMe', 'Program ? View WIP From Positions Below Me','Program');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Ignore_Date_Overlap_Deviation'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Ignore_Date_Overlap_Deviation', 'Ignore date overlap deviation','Template','');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Add_Templates_To_Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Add_Templates_To_Profile', 'Templates','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Budgets_Actual_Adjustment'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Budgets_Actual_Adjustment', 'Budgets Actual Adjustment','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Profitability_Model'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Profitability_Model', 'Profitability Model','Program');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Apply_Lead_Time_To_All'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Apply_Lead_Time_To_All', 'Apply Auto Renew lead time to all');
GO

--37492
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Alternate_Payment_Recipient'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Alternate_Payment_Recipient', 'Alternate Payment Recipient');
GO

--34597
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Custom_Fixed_Price_Options'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Custom_Fixed_Price_Options', 'Cusom Print Fixed Price Options');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Claim_Rates_Config_ID'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Claim_Rates_Config_ID', 'Claim Rates Config ID');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Change_BB_Start_End_Date1'
)
INSERT INTO Settings_List
(Setting_Type,Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Change_BB_Start_End_Date1','Change BB start/end dates','Billbacks');
GO

--- D39479 :: Short Cut Routing profile switch
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Prevent_short_cut_routing'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Prevent_short_cut_routing', 'Prevent Short Cut Routing','Program');
GO
-- D38942 :: Program Blackout Period on Frontend
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Blackout_Periods'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Blackout_Periods', 'Blackout Periods');
GO
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'start_zero'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'start_zero', 'Weeks after start date to ignore for volume automation');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'ItemMarked_Lost_Program_Volume_Automation'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Template', 'ItemMarked_Lost_Program_Volume_Automation', 'items marked as lost in Program Volume Automation','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'ItemMarked_Lost_Budget_Committed_Dollars'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Template', 'ItemMarked_Lost_Budget_Committed_Dollars', 'Include items marked as lost in Budget Committed Dollars','Program');
GO



--D38941 :: New Limited User Profile Edit Functionality
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Limited_Revise'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Limited_Revise', 'Limited Revise','Program');
GO

--Tim Ford - 10/22/2013: Label 39875 :: Redistribution Module - Profile Setting
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Redistribution'
)
INSERT INTO Settings_List
	(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
	('Profile', 'Redistribution', 'Redistribution','Program');
GO
--Dinesh D40664 :: Settings page to show Deleted Billbacks
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Re_instate_deleted_billbacks'
)
INSERT INTO Settings_List
	(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
	('Profile', 'Re_instate_deleted_billbacks', 'Re-instate deleted billbacks','admin');
GO

/* 36513 - TOPOP Reminder - no payment over 90 days */
IF NOT EXISTS
(
	SELECT *
    FROM   Settings_List
	WHERE  Setting_Name = 'Payment_Notification' AND Setting_Label = 'Payment Notification'
)


INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Setting_Display_Value, Deleted, category)
VALUES('Template', 'Payment_Notification', 'Payment Notification', 1, 0, 'Template')

GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Recapture_Pays_To_Id'
AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Notes)
VALUES
('Template', 'Recapture_Pays_To_Id', 'Recapture Pays To Id','Program','Determines the component Pay to id that this template considers for recapture.');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Message_Center_Viewing'
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Profile', 'Message_Center_Viewing', 'Message Center Viewing','Setting')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Message_Center_Administration'
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Profile', 'Message_Center_Administration', 'Message Center Administration','Setting')
GO

/* D41801:  Billback Sales Tax */
IF NOT EXISTS
(
	SELECT *
    FROM   Settings_List
	WHERE  Setting_Name = 'Billback_Sales_Tax' AND Setting_Label = 'Add Sales Tax on Billbacks'
)

INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Setting_Display_Value, Deleted, category)
VALUES('Template', 'Billback_Sales_Tax', 'Add Sales Tax on Billbacks', 1, 0, 'Template')

GO

--
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Competitive_Info_not_required'
AND	Setting_Type = 'Profile'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Profile', 'Competitive_Info_not_required', 'Competitive Info not required','Program',1)
GO

-- D42102 Expired Program Committed $ True-Up Process
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Auto_Committed_Equal_Actual'
	AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label, Setting_Display_Value, Deleted)
select	'Template' as Setting_Type, 'Auto_Committed_Equal_Actual' as Setting_Name, 'Weeks after end date to set Committed $ equal to Actual $' as Setting_Label,
		1 as Setting_Display_Value, 0 as Deleted
GO
--- D42733 :: Ability to disable Qualifications
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Enable_Program_Qualifications'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Enable_Program_Qualifications', 'Enable Program Qualifications','Template',1);
GO
--- D42591: Template setting - document attachment required
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Document_Attachment_Required'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Document_Attachment_Required', 'Document Attachment Required','Template',1);
GO

-- 42982 Autopay - Reverse
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Autopay_Reverse'
	AND		Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label, Category, Setting_Display_Value, Deleted)
select	'Profile' as Setting_Type,
		'Autopay_Reverse' as Setting_Name,
		'Autopay Reverse' as Setting_Label,
		'BB' as Category,
		1 as Setting_Display_Value, 0 as Deleted


GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Previous_Fiscal_Year_Volume'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Template', 'Previous_Fiscal_Year_Volume', 'Use Previous Fiscal Year Volume','Program');
GO


-- 43541 CA Finance Manager able to approve program
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Sequential_Net_Sales_Operating_Margin'
	AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label, Setting_Display_Value, Deleted)
select	'Template' as Setting_Type, 'Sequential_Net_Sales_Operating_Margin' as Setting_Name, 'Sequential - Net Sales and then Operating Margin' as Setting_Label,
		1 as Setting_Display_Value, 0 as Deleted
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Reassign'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'BB_Reassign', 'BB Reassign','BB');
GO

---42349: Most Favored Nations - setup and alert
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Most_Favored_Nation'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Most_Favored_Nation', 'Most Favored Nation','Template',1);
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'DD_New_From_Open'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'DD_New_From_Open', 'Status To "New" From "Open"','DD');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Approval_Considerations_ID'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Approval_Considerations_ID', 'Approval Considerations','Template',1);
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_LH_Pane_Recapture_Link'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_LH_Pane_Recapture_Link', 'View LH pane Recapture Link','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_LH_pane_Vertical_P_L'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_LH_pane_Vertical_P_L', 'View LH pane Vertical P&L','settings');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_LH_pane_What_If_P_L'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_LH_pane_What_If_P_L', 'View LH pane What If P&L','settings');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Browse_BBDoc_Server_Files'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Browse_BBDoc_Server_Files', 'Browse Files on Document Server','settings');
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Mass_Change_Program_Date'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Mass_Change_Program_Date', 'Mass Change Program Date','settings');
GO


IF NOT EXISTS ( SELECT *
                  FROM Settings_List
                 WHERE Setting_Name = 'What_If_From_Scratch' )
  INSERT INTO Settings_List
              (Setting_Type,
               Setting_Name,
               Setting_Label,
               Category)
       VALUES ('Profile',
               'What_If_From_Scratch',
               'What If P&L on Home Page',
               'settings');

GO

-- 45068 Growth – Minimum $ Purchase
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Growth_Min_Purchase'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name, Setting_Label, Category, Setting_Display_Value, TemplatePageSequence)
VALUES
('Template', 'Growth_Min_Purchase', 'Approval Considerations','Template', 1, 2);
GO

---D47306 : Price List Download
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Price_List_Download'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Price_List_Download', 'Price List Download','Template',1);
GO

---D47065 : Change Order - Program Approvals
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Manual_Selection_Of_Approvers'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Manual_Selection_Of_Approvers', 'Manual Selection of Approvers','Template',1)
GO

---D47065 : Change Order - Program Approvals
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Manually_Select_Approvers'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Manually_Select_Approvers', 'Manually Select Approvers','Program')
GO
---D47825 :: Payment frequency:  Add fiscal year option
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'PayCycleOption_12'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label)
VALUES ('TemplateSecondpage', 2, 'PayCycleOption_12', 'Fiscal Year')
GO

---D48049: Count / Dont Count Volume based on Program Component
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'BB_Dont_Count_Volume_Select'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'BB_Dont_Count_Volume_Select', 'BB Volume Dont Count Select','Template',1)
GO



IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Vendor_Hold_Research'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Profile','Vendor_Hold_Research','Vendor Hold Research','bb')
GO

-- 48779 : Manual Void: Void Credit Requests
IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Void_Credit_Request'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Profile','Void_Credit_Request','Void Credit Request','BB')
GO
-- D50074 :: Viewing and Editing prior program versions
IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Modify_Expired_Programs'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Profile','Modify_Expired_Programs','Modify Expired Programs','Program')
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Include_In_Sales_Tracker_Dashboard'
AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Template', 'Include_In_Sales_Tracker_Dashboard', 'Include In Sales Tracker Dashboard','program');
GO

-- D50276 Volume automation on expiration only
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Auto_Committed_Equal_Actual_ON'
AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Template', 'Auto_Committed_Equal_Actual_ON', 'Update Budget Committed $ equal to Actual $','program');
GO

-- D50276 Volume automation on expiration only
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Auto_Volume_Program_Equal_Actual_Weeks'
AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Template', 'Auto_Volume_Program_Equal_Actual_Weeks', 'Weeks after start date to ignore for volume automation','program');
GO

-- D51148:Viewing uploaded files inside Billback
IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Display_BB_EDI_Download'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Profile','Display_BB_EDI_Download','Display ''Download raw data'' link for EDI Billbacks','BB')
GO

-- D51148:Viewing uploaded files inside Billback
IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Display_BB_User_Download'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Profile','Display_BB_User_Download','Display ''Download raw data'' link for User Uploaded Billbacks','BB')
GO

-- D51148:Viewing uploaded files inside Billback
IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Display_BB_III_Party_Download'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Profile','Display_BB_III_Party_Download','Display ''Download raw data'' link for User 3rd Party Billbacks','BB')
GO

IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Hide_On_Create_Program'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Template','Hide_On_Create_Program','Hide on Create Program Page','Program')
GO

IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Manual_Committed_Equal_Actual'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Template','Manual_Committed_Equal_Actual','Manual Committed Equal Actual','Program')
GO

IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Market_Price_Update_Process'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category, TemplatePageSequence)
	VALUES ('Template','Market_Price_Update_Process','Market Price Update Process','Program', 2)
GO


IF NOT EXISTS (
		SELECT *
		FROM Settings_List
		WHERE Setting_Name = 'Auto_Approve_Analysis'
		)
	INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
	VALUES ('Profile','Auto_Approve_Analysis','Auto Approve Analysis','BB')
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Percentage_Of_List_Price'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Percentage_Of_List_Price', '% of List Price','Template',1)
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Price_List_ID'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Price_List_ID', 'Price List','Template',1)
GO


if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Set_Billbacks_To_Paid_No_Interface'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Set_Billbacks_To_Paid_No_Interface', 'Set Billbacks to Paid No Interface','Template',0)
GO 

---D55544 :: template settings:  allow distributors to be selected as group & ship to level on programs
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Specify_Individual_Distributors'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label)
VALUES
('Template', 'Specify_Individual_Distributors', 'Select Individual application.returned_customer_setting.distributor_label_plural');
GO

------------------------------------------------------------------------------------------------------------
-- please add the new setting above
------------------------------------------------------------------------------------------------------------

/* Sample Scripts for adding the new setting in Program_Wizard\create_edit.cfm, Program_Wizard\secondpage.cfm and access_rights_matrix.cfm
------ script for settings on Program_Wizard\create_edit.cfm
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'column name of the new setting'
AND	Setting_Type = 'Template'  -- for Template
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Template', 'column_name_of_the_new_setting', 'Setting Label','program/billback');
GO

------ script for settings on Program_Wizard\secondpage.cfm
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Group_Programs_UOM'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label)
VALUES ('TemplateSecondpage', 2, 'column_name_of_the_new_setting', 'Setting Label')
GO

------ script for settings on settings\Access_Rights\access_rights_matrix.cfm
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'column name of the new setting'
AND	Setting_Type = 'Profile'  -- for user profile
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Profile', 'column name of the new setting', 'Setting Label','program/billback');
GO



------------------------------------------------------------------------------------------------------------
select	Setting_Name, Setting_Type,count(*) as cnt
from	Settings_List
where	deleted = 0
group by Setting_Name,Setting_type
having count(*) > 1
------------------------------------------------------------------------------------------------------------
*/
-- D55551 Manual Reject Billback
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Manual_Reject_Billback' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Manual_Reject_Billback', 'Manual Reject Billback', 'BB' )
GO

/************* 56440: 'Duplicate Check' link inside a program/Anand Rao/04-Jan-2016 **************/

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_LH_Pane_Duplicate_Checker_Link'
and Setting_Type = 'Profile'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'View_LH_Pane_Duplicate_Checker_Link', 'View LH Pane Duplicate Checker Link','Program');
GO
--D57447 :: Create and modify vendor records
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Modify_Vendors_VendorManagement' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label)
    VALUES  ( 'Profile', 'Modify_Vendors_VendorManagement', 'Modify Vendors')
GO

/********* 57305 Retail Planner/Anand Rao/7-Mar-2016 *****************/

/************** Planner Create  **************/
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Create' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Create', 'sstring', 'Planner' )
GO
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Create_view' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Create_view', 'Planner - View', 'Planner' )
GO
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Create_None' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Create_None', 'Planner - None', 'Planner' )
GO
 
/************** Planner Margin View  **************/

IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Margin_View' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Margin_View', 'Planner Margin View', 'Planner' )
GO

/************** Planner Approval Rights  **************/


IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Approval_Rights' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Approval_Rights', 'Planner Approval Rights', 'Planner' )
GO
 

/************** Marketing Events  **************/
 
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Marketing_Events_Create' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Marketing_Events_Create', 'sstring', 'Planner' )
GO
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Marketing_Events_Create_View' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Marketing_Events_Create_View', 'Marketing Events - View', 'Planner' )
GO
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Marketing_Events_Create_None' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Marketing_Events_Create_None', 'Marketing Events - None', 'Planner' )
GO

/************** Planner Product Calendar  **************/

IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Product_Calendar' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Product_Calendar', 'Planner Product Calendar', 'Planner' )
GO

/************** Strategic Guidelines  **************/

IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Strategic_Guidelines' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Strategic_Guidelines', 'Strategic Guidelines', 'Planner' )
GO


/************** NUC Targets **************/

IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'NUC_Targets_Create' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'NUC_Targets_Create', 'sstring', 'Planner' )
GO
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'NUC_Targets_Create_View' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'NUC_Targets_Create_View', 'NUC Targets - View', 'Planner' )
GO
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'NUC_Targets_Create_None' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'NUC_Targets_Create_None', 'NUC Targets - None', 'Planner' )
GO



/********************************************/

IF NOT EXISTS
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Retail_Planner'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Retail_Planner', 'Customer Planner','Template',1)
GO

--61486 : Default program only when $'s equal to $0.00...
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Allow_RFA_With_Default_Program' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Allow_RFA_With_Default_Program', 'Allow RFA With Default Program', 'BB' )
GO

 -- SELECT * FROM Settings_List
---63631 :: Settings Management - template settings show/hide START
 if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Optional_Dates_Program'
)

INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Template', 'Optional_Dates_Program', 'Optional Dates Program','Template');
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Label_Set'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'Label_Set', 'Label Set','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'French'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'French', 'French','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'LabelSetDefaultOption'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'LabelSetDefaultOption', 'No Default','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Program_Qualifications_Doc_Attach_Req'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'Program_Qualifications_Doc_Attach_Req', 'Document Attachment Required','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Program_Qualifications_Doc_Message'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'Program_Qualifications_Doc_Message', 'Document Message','Template')
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'CurrencyDefaultOption'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'CurrencyDefaultOption', 'No Default','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Per_Pound'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'Per_Pound', 'Per Pound','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Per_Case'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'Per_Case', 'Per Case','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Percent_of_Revenue'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'Percent_of_Revenue', 'Percent of Revenue','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'UOMDefaultOption'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'UOMDefaultOption', 'No Default','Template')
GO
---63631 :: Settings Management - template settings show/hide END
---63887 :: Need new UOM for Per Hundred Weight (CWT)
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Per_Hundred_Weight'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'Per_Hundred_Weight', 'Per Hundred Weight','Template')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Show_Contract_Dates'
	AND 	Setting_Type = 'Template'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 0, 'Show_Contract_Dates', 'Contract Dates','Program')
GO

---60308 :: Best Plans Enhancement
IF NOT EXISTS(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'allow_Best_Plan_Programs'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,TemplatePageSequence)
VALUES
('Template', 'allow_Best_Plan_Programs', 'Allow Best Plan Programs','Template',1);
GO

---D64200 :: Create new accrual budget forecast process
IF NOT EXISTS(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Budget_Forecast'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Budget_Forecast', 'Budget Forecast','Budgets');
GO

--- 63886 Smithfield Recapture Settings
IF NOT EXISTS(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Pullback_Operator_Fixed_Price_Only'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,TemplatePageSequence)
VALUES
('Template', 'Pullback_Operator_Fixed_Price_Only', 'Recapture Operator Fixed Price Only','Template',1);
GO
---D66995 :: Rework - Best Plans
IF NOT EXISTS(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Best_Plan_Program'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Best_Plan_Program', 'Best Plan Program','Program');
GO
---68628 :: Accrual Interface Update - Final Settlements
IF NOT EXISTS(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'RS_CreatedDaysGreater'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,TemplatePageSequence)
VALUES
('Template', 'RS_CreatedDaysGreater', 'Release Settlement: Created by Date is greater than','Template',1);
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Restrict_On_Inventory_UOM_Case'
	AND 	Setting_Type = 'Template'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 2, 'Restrict_On_Inventory_UOM_Case', 'Case','Program')
GO

if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Restrict_On_Inventory_UOM_Pound'
	AND 	Setting_Type = 'Template'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 2, 'Restrict_On_Inventory_UOM_Pound', 'Pound','Program')
GO

/************** Planner Reassign  **************/
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Reassign' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Reassign', 'sstring', 'Planner' )
GO
---71241
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'price_list_type'	
				AND 	Setting_Type = 'Template'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'price_list_type', 'Price List Type','Program')
GO
/* ---73454 - Earlier, this setting was on the "basic info tab, but now has moved to the "details" tab */
UPDATE Settings_List
SET TemplatePageSequence = 2
WHERE   Setting_Name = 'price_list_type'	
AND 	Setting_Type = 'Template'

---71460
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Analytics_SSO'	
				AND 	Setting_Type = 'Profile'
)
INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
VALUES ('Profile', 'Analytics_SSO', 'FORGE Analytics Single Sign On','Login')
GO


if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Ignore_Rate_Deviation'
	AND 	Setting_Type = 'Template'
)
INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label,Category)
VALUES ('Template', 'Ignore_Rate_Deviation', 'Ignore rate deviation','Template')
GO

IF NOT EXISTS(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Max_Approval_Annual_Volume'
)
INSERT INTO Settings_List(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES('Profile', 'Max_Approval_Annual_Volume', 'Max Approval Annual Volume','Program');
GO

if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Max_Approval_Annual_Volume_Uom'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Max_Approval_Annual_Volume_Uom', 'Max Approval Annual Volume UOM','Program');
GO

-- D72955 Retail Planner - Design - Sprint 11
-- Retail 302 Catalog access
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Planner_Catalog'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES
('Profile', 'Planner_Catalog', 'Read only catalog access','Planner');
GO
--- 74641
if not exists(
					SELECT	*
					FROM	Settings_List
					WHERE	Setting_Name = 'isBrokerage'
					)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES('Template', 'isBrokerage', 'is Brokerage','Template');
GO

--- 76541 Allow user to create program in Eaches unit of measure
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'UOM_Each'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'UOM_Each', 'Eaches','Template')
GO


---D76514 :: Add additional payment frequencies (cycles)
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'PayCycleOption_13'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label)
VALUES ('TemplateSecondpage', 2, 'PayCycleOption_13', 'Fiscal Week')
GO


---D76514 :: Add additional payment frequencies (cycles)
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'PayCycleOption_14'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label)
VALUES ('TemplateSecondpage', 2, 'PayCycleOption_14', 'Fiscal Bi Annual')
GO


---D76514 :: Add additional payment frequencies (cycles)
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'PayCycleOption_15'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label)
VALUES ('TemplateSecondpage', 2, 'PayCycleOption_15', '13 Period Calendar')

GO

---77472	Recapture by Operator (multiple lists) and template   [ CF work ]
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Template_In_Program_LH_Recapture_Link'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'Template_In_Program_LH_Recapture_Link', 'Template in programs LH recapture link','Template')

---77539 Program Basic Info - additional field for reference #
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'allow_Reference_2'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'allow_Reference_2', 'Allow Reference 2','Template')

-- 77469	Display Dist Channel at BB_Program Distributor Level   [ CF work ] - Anand Rao/12-Jun-2018
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'BB_Display_Dist_Channel_Per_Program_Distributor'	
				AND 	Setting_Type = 'Profile'
)
INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
VALUES ('Profile', 'BB_Display_Dist_Channel_Per_Program_Distributor', 'Update Dist Channel','BB')
GO

---76537 :: Margin analysis to various targets
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Additional_Margins_Targets'
)
INSERT INTO Settings_List(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES('Profile', 'View_Additional_Margins_Targets', 'View Additional Margins Targets','Program');
GO

---78635 :: Lump Sum programs that pay to Vendor
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Allow_Vendor_Only'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'Allow_Vendor_Only', 'Allow_Vendor_Only','Template')


/*  76536: BB Oper Location Level - dup check - Anand Rao/09-Aug-2018  */
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Max_BB_Oper_Location_Level_Dup_Approval_Amount'	
				AND 	Setting_Type = 'Profile'
)
INSERT INTO Settings_List (Setting_Type, Setting_Name, Setting_Label, Category)
VALUES ('Profile', 'Max_BB_Oper_Location_Level_Dup_Approval_Amount', 'Max BB Oper Location Level Dup Approval Amount','BB')
GO

/*  79028: BB Deviation Grid - default to only display items with deviation amt greater than $0 - Anand Rao/05-Sep-2018  */

IF not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Deviated_Items_Only_OnLoad'
)
INSERT INTO Settings_List(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES('Profile', 'View_Deviated_Items_Only_OnLoad', 'View Deviated Items Only On Load','BB');
GO


/* 79614: Bid Templates - only count fixed price component - Anand Rao/13-Sep-2018 */ 
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Ignore_Rebate_Volume'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'Ignore_Rebate_Volume', 'Ignore Rebate Volume','Template')

 /*  79426 :: Blanket Bid Price display */
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Display_Blanket_Bid'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'Display_Blanket_Bid', 'Display_Blanket_Bid','Template')

IF not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'View_Count_Column_In_Deviation_Grid'
)
INSERT INTO Settings_List(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES('Profile', 'View_Count_Column_In_Deviation_Grid', 'View Count column in deviation grid','BB');
GO

if not exists(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Search_Customer_Invoice'
)
INSERT INTO Settings_List(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES('Profile', 'Search_Customer_Invoice', 'Search Customer Invoice','DD');
GO


---81335 :: Tyson feedback on program upload feature 10 15 2018
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Upload_Programs'
)
INSERT INTO Settings_List(Setting_Type, Setting_Name,Setting_Label,Category)
VALUES('Profile', 'Upload_Programs', 'Upload Programs','Program');
GO


/* D81335: Tyson feedback on program upload feature 10 15 2018 */
if not exists
(
SELECT	*
FROM	Settings_List
WHERE	Setting_Name = 'Include_Program_Upload_Template_List'
AND		Setting_Type = 'Template'
)
INSERT INTO Settings_List
(Setting_Type, Setting_Name,Setting_Label,Category,Setting_Display_Value)
VALUES
('Template', 'Include_Program_Upload_Template_List', 'Include in Program Upload template list','Template',1);
GO

/* 82139: Filter distributor results based on program position */
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Filter_Distributor_Results_Based_On_Program_Position'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'Filter_Distributor_Results_Based_On_Program_Position', 'Filter Distributor Results Based On Program Position','Template')
GO

-- 76021 Ember_Access
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Ember_Access'
)
INSERT INTO Settings_List (Setting_Type, Setting_Name,Setting_Label,Category)
VALUES ('Profile', 'Ember_Access', 'Ember_Access','Profile');
GO

--- 82429 Add new UOMs to Programs
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'UOM_Sleeve'
	AND 	Setting_Type = 'TemplateSecondPage'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('TemplateSecondpage', 2, 'UOM_Sleeve', 'Sleeves','Template')
GO

/* 87084: Planner program version settings change */
if not exists
(
	SELECT	*
	FROM	Settings_List
	WHERE	Setting_Name = 'Retail_Revision_Replace_Parent'
)
INSERT INTO Settings_List (Setting_Type, TemplatePageSequence, Setting_Name, Setting_Label,Category)
VALUES ('Template', 1, 'Retail_Revision_Replace_Parent', 'Retail - Revision replaces prior version','Template')
GO



-- 86659 Planner approvals - Max total spend
IF NOT EXISTS ( SELECT  1
                FROM    Settings_List
                WHERE   Setting_Name = 'Planner_Max_Total_Spend' )
    INSERT  INTO Settings_List ( Setting_Type, Setting_Name, Setting_Label, Category )
    VALUES  ( 'Profile', 'Planner_Max_Total_Spend', 'Planner Max Total Spend', 'Planner' )
GO
-------------------------------------------------------------------------------------------------------------------------------
--- UNITS_OF_MEASURE.SQL was last modified on 01/31/2019 04:03:35 PM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Tables
                 WHERE Table_Name = 'Units_of_Measure' )
  BEGIN

CREATE TABLE [dbo].[Units_of_Measure](
	[Unit_Of_Measure_ID] [int] IDENTITY(1,1) NOT NULL,
	[Unit_Of_Measure_Desc] [nvarchar](50) NULL,
	[Abbreviation] [char](10) NULL,
	[Display_Order] [int] NULL,
	[External_Id] [nvarchar](5) NULL,
	[Unit_of_Measure_Desc_Singular] [nvarchar](50) NULL,
	[Abbreviation_Singular] [nvarchar](50) NULL,
 CONSTRAINT [PK_Units_of_Measure] PRIMARY KEY CLUSTERED 
(
	[Unit_Of_Measure_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

END

GO

IF NOT EXISTS(SELECT	* FROM	Units_Of_Measure WHERE	Abbreviation = 'CS' AND Unit_Of_Measure_Desc = 'Cases')

INSERT Units_Of_Measure (Unit_Of_Measure_Desc,Abbreviation,Abbreviation_Singular, Unit_of_Measure_Desc_Singular)
VALUES('Cases','CS','CS','Cases')

GO

IF NOT EXISTS(SELECT	* FROM	Units_Of_Measure WHERE	Abbreviation = 'LBS' AND Unit_Of_Measure_Desc = 'Pounds')

INSERT Units_Of_Measure (Unit_Of_Measure_Desc,Abbreviation,Abbreviation_Singular, Unit_of_Measure_Desc_Singular)
VALUES('Pounds','LBS','LB','Pound')

GO

IF NOT EXISTS(SELECT	* FROM	Units_Of_Measure WHERE	Abbreviation = '%' AND Unit_Of_Measure_Desc = '%')

INSERT Units_Of_Measure (Unit_Of_Measure_Desc,Abbreviation,Abbreviation_Singular, Unit_of_Measure_Desc_Singular)
VALUES('%','%','%','%')

GO

IF NOT EXISTS(SELECT	* FROM	Units_Of_Measure WHERE	Abbreviation = '$' AND Unit_Of_Measure_Desc = '$')

INSERT Units_Of_Measure (Unit_Of_Measure_Desc,Abbreviation,Abbreviation_Singular, Unit_of_Measure_Desc_Singular)
VALUES('$','$','$','$')

GO

IF NOT EXISTS(SELECT	* FROM	Units_Of_Measure WHERE	Abbreviation = 'EA' AND Unit_Of_Measure_Desc = 'Eaches')

INSERT Units_Of_Measure (Unit_Of_Measure_Desc,Abbreviation,Abbreviation_Singular, Unit_of_Measure_Desc_Singular)
VALUES('Eaches','EA','EA','Each')

GO

IF NOT EXISTS(SELECT	* FROM	Units_Of_Measure WHERE	Abbreviation = 'CWT' AND Unit_Of_Measure_Desc = 'Hundred Weight')

INSERT Units_Of_Measure (Unit_Of_Measure_Desc,Abbreviation,Abbreviation_Singular, Unit_of_Measure_Desc_Singular)
VALUES('Hundred Weight','CWT','CWT','CWT')

GO


IF NOT EXISTS(SELECT	* FROM	Units_Of_Measure WHERE	Abbreviation = 'SL' AND Unit_Of_Measure_Desc = 'Sleeves')

INSERT Units_Of_Measure (Unit_Of_Measure_Desc,Abbreviation,Abbreviation_Singular, Unit_of_Measure_Desc_Singular)
VALUES('Sleeves','SL','SL','Sleeve')

GO
-------------------------------------------------------------------------------------------------------------------------------
--- UPLOAD_DETAIL.SQL was last modified on 06/07/2019 09:30:10 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Upload_Detail]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Upload_Detail](
	[Upload_ID] [int] IDENTITY(1,1) NOT NULL,
	[Upload_Source] [varchar](50) NULL,
	[Upload_Source_Number] [varchar](50) NULL,
	[Upload_Description] [varchar](100) NULL,
	[Upload_Business_ID] [varchar](100) NULL,
	[Upload_Date] [datetime] NULL CONSTRAINT [DF_Upload_Detail_Upload_Date]  DEFAULT (getdate()),
	[Upload_Ratio] [char](10) NULL,
 CONSTRAINT [PK_Upload_Detail] PRIMARY KEY CLUSTERED 
(
	[Upload_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


-------------------------------------------------------------------------------------------------------------------------------
--- USER_PROGRAM_LIST_DATA.SQL was last modified on 07/09/2019 07:32:44 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[User_Program_list_Data]    Script Date: 04/01/2009 09:54:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON

GO
/****** Object:  Table [dbo].[User_Program_list_Data]    Script Date: 04/01/2009 09:54:08 ******/
IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[User_Program_list_Data]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[User_Program_list_Data](
	[User_Program_List_Id] [int] NOT NULL,
	[Ship_To] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[BSA_Foodservice_Customers_ID] [uniqueidentifier] NULL,
 CONSTRAINT [PK_User_Program_list_Data] PRIMARY KEY CLUSTERED 
(
	[User_Program_List_Id] ASC,
	[Ship_To] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF

 if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'BuyingGroup'
)
ALTER TABLE User_Program_list_Data ALTER COLUMN [BuyingGroup] [varchar](1000)
GO

if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'Family'
)
ALTER TABLE User_Program_list_Data ALTER COLUMN [Family] [varchar](1000)
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'UserInfo'
)
ALTER TABLE [dbo].[User_Program_list_Data] ADD [UserInfo] [varchar](1000) NULL
GO

if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'Template'
)
ALTER TABLE User_Program_list_Data ALTER COLUMN [Template] [varchar](500)
GO

if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'RSP'
)
ALTER TABLE User_Program_list_Data ALTER COLUMN [RSP] [varchar](1000)
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'BudgetClass'
)
ALTER TABLE [dbo].[User_Program_list_Data] ADD [BudgetClass] [varchar](50) NULL
GO

if  exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'Status'
)
ALTER TABLE [dbo].[User_Program_list_Data] ALTER COLUMN [Status] [varchar](100) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'BusinessSegment'
)
ALTER TABLE [dbo].[User_Program_list_Data] ADD [BusinessSegment] [varchar](50) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'Datasource'
)
ALTER TABLE [dbo].[User_Program_list_Data] ADD [Datasource] [varchar](10) NULL
GO

if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'User_Program_list_Data'
	AND COLUMN_NAME = 'BusinessSegment'
)
ALTER TABLE User_Program_list_Data ALTER COLUMN [BusinessSegment] [varchar](250) NULL
GO
-------------------------------------------------------------------------------------------------------------------------------
--- VENDOR_MASTER.SQL was last modified on 10/07/2019 01:31:58 PM ---
-------------------------------------------------------------------------------------------------------------------------------
if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.TABLES
	WHERE	TABLE_NAME = 'Vendor_Master'
)
CREATE TABLE [dbo].[Vendor_Master](
	[Vendor_Master_ID] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Vendor_Master_Vendor_Master_ID]  DEFAULT (newid()),
	[Vendor_ID] [varchar](50) NULL,
	[Vendor_Name] [varchar](255) NULL,
	[Company_Code] [char](2) NULL,
	[Active_Code] [char](1) NULL,
	[Address_1] [varchar](255) NULL,
	[Address_2] [varchar](255) NULL,
	[City] [varchar](50) NULL,
	[State] [char](3) NULL,
	[Zipcode] [varchar](10) NULL,
	[Payment_Type] [char](1) NULL,
	[Vendor_Type] [char](4) NULL,
	[Date_Last_Paid] [datetime] NULL,
	[Customer] [nvarchar](20) NULL,
	[Customer_Name] [nvarchar](50) NULL,
	[Deleted] [int] NULL CONSTRAINT [DF_Vendor_Master_Deleted]  DEFAULT ((0)),
	[Created_Date] [datetime] NULL CONSTRAINT [DF_Vendor_Master_Created_Date]  DEFAULT (getdate()),
	[Updated_Date] [datetime] NULL,
	[Address_3] [nvarchar](255) NULL
) ON [PRIMARY]
SET ANSI_PADDING OFF
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND
	COLUMN_NAME = 'Update_Info'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Update_Info] [char](1) NULL CONSTRAINT [DF_Vendor_Master_Update_Info]  DEFAULT ('U')
GO

IF  NOT EXISTS 
(
SELECT * FROM sys.indexes 
WHERE object_id = OBJECT_ID(N'[dbo].[Vendor_Master]') 
AND name = N'PK_Vendor_Master'
)
ALTER TABLE [dbo].[Vendor_Master] ADD  CONSTRAINT [PK_Vendor_Master] PRIMARY KEY CLUSTERED 
(
	[Vendor_Master_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND
	COLUMN_NAME = 'Country_Code'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Country_Code] [char](3) NULL
GO

if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND
	COLUMN_NAME = 'Source_Code'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Source_Code] [varchar](50) NULL
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'Vendor_Master'
                       AND Column_Name = 'Is_Batched' )
  ALTER TABLE [dbo].[VENDOR_MASTER]
    ADD [Is_Batched] [BIT] NOT NULL CONSTRAINT [DF_Vendor_Master_Is_Batched] DEFAULT ((0))
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'Vendor_Master'
                       AND Column_Name = 'Batched_By' )
  ALTER TABLE [dbo].[VENDOR_MASTER]
    ADD [Batched_By] [varchar](50) NULL
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'Vendor_Master'
                       AND Column_Name = 'Batched_Date' )
  ALTER TABLE [dbo].[VENDOR_MASTER]
    ADD [Batched_Date] [datetime] NULL
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'Vendor_Master'
                       AND Column_Name = 'UnBatched_By' )
  ALTER TABLE [dbo].[VENDOR_MASTER]
    ADD [UnBatched_By] [varchar](50) NULL
GO

IF NOT EXISTS ( SELECT 1
                  FROM Information_Schema.Columns
                 WHERE Table_Name = 'Vendor_Master'
                       AND Column_Name = 'UnBatched_Date' )
  ALTER TABLE [dbo].[VENDOR_MASTER]
    ADD [UnBatched_Date] [datetime] NULL
GO

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'VENDOR_MASTER' AND COLUMN_NAME = 'EFT_CUSTOMER') 
ALTER TABLE VENDOR_MASTER ADD EFT_CUSTOMER VARCHAR(50) DEFAULT ('NO')
GO


if not exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND
	COLUMN_NAME = 'Business_Segment_ID'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Business_Segment_ID] [INT] NULL 
GO

/* Added for WR: 52922	700 Check Request - Wells Fargo */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Vendor_Bank_Name'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Vendor_Bank_Name] VARCHAR(50) NULL 
GO


/* Added for WR: 52922	700 Check Request - Wells Fargo */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Vendor_Bank_Routing_Number'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Vendor_Bank_Routing_Number] VARCHAR(50) NULL 
GO

/* Added for WR: 52922	700 Check Request - Wells Fargo */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Vendor_Bank_Account_Number'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Vendor_Bank_Account_Number] VARCHAR(50) NULL 
GO

/* Added for WR: 52922	700 Check Request - Wells Fargo */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Email_Address'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Email_Address] VARCHAR(255) NULL 
GO

/* Added for WR: 52922	700 Check Request - Wells Fargo */
IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Fax_Number'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Fax_Number] VARCHAR(255) NULL 
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Payment_Delivery_Type'
)
ALTER TABLE [dbo].[Vendor_Master] ADD [Payment_Delivery_Type] VARCHAR(255) NOT NULL DEFAULT ('EMAIL')
GO


/* WR: 79659 - need to store the default billback closing method to update default vendor and closing method on the shipto*/
IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Payment_Type'
)
BEGIN
	ALTER TABLE [dbo].[Vendor_Master] ALTER COLUMN Payment_Type VARCHAR(10)
END
GO

/* WR: 79659 - need to store the default billback closing method to update default vendor and closing method on the shipto*/
IF EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
	AND 	COLUMN_NAME = 'Vendor_Type'
)
BEGIN
	ALTER TABLE [dbo].[Vendor_Master] ALTER COLUMN Vendor_Type VARCHAR(10)
END
GO

--**** State field - increase it to 255 - start
if exists 
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
		AND
		COLUMN_NAME = 'State'
)
BEGIN


	IF(
	SELECT	CHARACTER_MAXIMUM_LENGTH
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Vendor_Master'
		AND
		COLUMN_NAME = 'State'
	) < 255
	BEGIN
	
		IF ((SELECT COLUMNPROPERTY(OBJECT_ID('dbo.Vendor_Master'), 'State', 'IsFulltextIndexed')) = 1)
		BEGIN
			ALTER FULLTEXT INDEX ON [dbo].[Vendor_Master] DROP ([State]) 
			ALTER TABLE Vendor_Master ALTER COLUMN [State] [nvarchar](255)  NULL
			ALTER FULLTEXT INDEX ON [dbo].[Vendor_Master] ADD ([State])
			ALTER FULLTEXT INDEX ON [dbo].[Vendor_Master] ENABLE
			ALTER FULLTEXT INDEX ON [dbo].[Vendor_Master] SET CHANGE_TRACKING = AUTO
		END
		ELSE
			ALTER TABLE Vendor_Master ALTER COLUMN [State] [nvarchar](255)  NULL
	END
END
GO
--**** State field - increase it to 255 - end
-------------------------------------------------------------------------------------------------------------------------------
--- Y_DEAL_UI_UPLOAD.SQL was last modified on 01/02/2019 07:40:15 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[Y_DEAL_UI_Upload]    Script Date: 09/04/2018 11:20:13 ******/
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Y_DEAL_UI_Upload]') AND type in (N'U'))
CREATE TABLE [dbo].[Y_DEAL_UI_Upload](
	[Y_DEAL_UI_Upload_ID] [int]IDENTITY (1, 1) NOT NULL,
	[Batch_ID] [int] NULL,
	[Record_Type] [nvarchar](255) NULL,
	[Header_Action] [nvarchar](255) NULL,
	[External_Program] [nvarchar](255) NULL,
	[FORGE_Program] [nvarchar](255) NULL,
	[Title] [nvarchar](255) NULL,
	[Start] [nvarchar](255) NULL,
	[End] [nvarchar](255) NULL,
	[RSP_ID] [nvarchar] (255) NULL,
	[Position_ID] [float] NULL,
	[Segment] [nvarchar](255) NULL,
	[Detail_Action] [nvarchar](255) NULL,
	[Sold_To] [varchar](100) NULL,
	[Operator_ID] [varchar](100) NULL,
	[Material] [nvarchar](100) NULL,
	[Rate] [float] NULL,
	[UOM] [nvarchar](255) NULL,
	[Discount_Type] [nvarchar](255) NULL,
	[Component] [nvarchar](255) NULL,
	[Pays_To] [nvarchar](255) NULL,
	[Frequency] [nvarchar](255) NULL,
	[Claim_Mechanic] [nvarchar](255) NULL,
	[Currency] [nvarchar](255) NULL,
	[Volume] [float] NULL,
	[Volume_UOM]  [nvarchar](255) NULL,
	[TEMPLATE] [varchar](100) NULL,
	[Error_Info] [nvarchar](max) NULL
) ON [PRIMARY]

GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Y_DEAL_UI_Upload'
	AND		COLUMN_NAME = 'Creator_ID'
)
ALTER TABLE Y_DEAL_UI_Upload ADD [Creator_ID] [nvarchar](255) NULL
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Y_DEAL_UI_Upload'
	AND		COLUMN_NAME = 'Upload_File_Name'
)
ALTER TABLE Y_DEAL_UI_Upload ADD [Upload_File_Name] [nvarchar](255) NULL
GO


IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Y_DEAL_UI_Upload'
	AND		COLUMN_NAME = 'Upload_Header_ID'
)
ALTER TABLE Y_DEAL_UI_Upload ADD [Upload_Header_ID] [int] NULL
GO



IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = 'Y_DEAL_UI_Upload'
	AND		COLUMN_NAME = 'Created_Date'
)
ALTER TABLE Y_DEAL_UI_Upload ADD [Created_Date] [datetime] NULL CONSTRAINT [DF_Y_DEAL_UI_Upload_Created_Date]  DEFAULT (getdate())
GO
-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_BASIC_INFORMATION.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Z_DEAL_BASIC_INFORMATION]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Z_DEAL_BASIC_INFORMATION](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[TEMPLATE_NAME] [varchar](100) NULL,
	[PROGRAM_TITLE] [varchar](1000) NULL,
	[START_DATE] [varchar](50) NULL,
	[END_DATE] [varchar](50) NULL,
	[SALES_PERSON_RESPONSIBLE] [varchar](255) NULL,
	[CREATOR_POSITION] [varchar](255) NULL,
	[CREATED_DATE] [varchar](255) NULL,
	[RFA_POSITION] [varchar](255) NULL,
	[RFA_DATE] [varchar](255) NULL,
	[APPROVAL_POSITION] [varchar](255) NULL,
	[APPROVAL_DATE] [varchar](255) NULL,
	[LEGACY_OPERATOR_ID] [varchar](255) NULL,
	[BID_STATUS] [varchar](255) NULL,
	[REFEREMCE_NUMBER] [varchar](255) NULL,
	[REJECTED] [bit] NOT NULL,
	[ACTION_CODE] [varchar](255) NULL,
	[BUSINESS_SEGMENT] [varchar](255) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Z_DEAL_BASIC_INFORMATION] ADD  CONSTRAINT [DF_Z_DEAL_BASIC_INFORMATION_REJECTED]  DEFAULT ((0)) FOR [REJECTED]
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_BASIC_INFORMATION_LOG.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Z_DEAL_BASIC_INFORMATION_LOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Z_DEAL_BASIC_INFORMATION_LOG](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[TEMPLATE_NAME] [varchar](100) NULL,
	[PROGRAM_TITLE] [varchar](1000) NULL,
	[START_DATE] [varchar](50) NULL,
	[END_DATE] [varchar](50) NULL,
	[SALES_PERSON_RESPONSIBLE] [varchar](255) NULL,
	[CREATOR_POSITION] [varchar](255) NULL,
	[CREATED_DATE] [varchar](255) NULL,
	[RFA_POSITION] [varchar](255) NULL,
	[RFA_DATE] [varchar](255) NULL,
	[APPROVAL_POSITION] [varchar](255) NULL,
	[APPROVAL_DATE] [varchar](255) NULL,
	[LEGACY_OPERATOR_ID] [varchar](255) NULL,
	[BID_STATUS] [varchar](255) NULL,
	[REFEREMCE_NUMBER] [varchar](255) NULL,
	[ACTION_CODE] [varchar](255) NULL,
	[BUSINESS_SEGMENT] [varchar](255) NULL,
	[process_Date] [datetime] NULL,
	[History_Created_date] [datetime] NOT NULL CONSTRAINT [DF_Z_DEAL_BASIC_INFORMATION_LOG_History_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_Z_DEAL_BASIC_INFORMATION_LOG_REJECTED]  DEFAULT ((0))
) ON [PRIMARY]
END
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_DISTRIBUTORS.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Z_DEAL_DISTRIBUTORS]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Z_DEAL_DISTRIBUTORS](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[SHIP_TO] [varchar](100) NULL,
	[DISTRIBUTOR_WEIGHT] [varchar](100) NULL,
	[REJECTED] [bit] NOT NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Z_DEAL_DISTRIBUTORS] ADD  CONSTRAINT [DF_Z_DEAL_DISTRIBUTORS_REJECTED]  DEFAULT ((0)) FOR [REJECTED]
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_DISTRIBUTORS_LOG.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Z_DEAL_DISTRIBUTORS_LOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Z_DEAL_DISTRIBUTORS_LOG](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[SHIP_TO] [varchar](100) NULL,
	[DISTRIBUTOR_WEIGHT] [varchar](100) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_Z_DEAL_DISTRIBUTORS_LOG_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_Z_DEAL_DISTRIBUTORS_LOG_REJECTED]  DEFAULT ((0)) 
) ON [PRIMARY]
END
GO

-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_FIXED_PRICES.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Z_DEAL_FIXED_PRICES]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Z_DEAL_FIXED_PRICES](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[FIXED_PRICE_PER_CASE] [varchar](50) NULL,
	[FIXED_PRICE_PER_POUND] [varchar](50) NULL,
	[FREIGHT_ALLOWANCE] [varchar](50) NULL,
	[DELIVERED_PRICE_PER_CASE] [varchar](50) NULL,
	[DELICERED_PRICE_PER_POUND] [varchar](50) NULL,
	[FIXED_PRICE_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[FIXED_PRICE_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[REJECTED] [bit] NOT NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Z_DEAL_FIXED_PRICES] ADD  CONSTRAINT [DF_Z_DEAL_FIXED_PRICES_REJECTED]  DEFAULT ((0)) FOR [REJECTED]
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_FIXED_PRICES_LOG.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Z_DEAL_FIXED_PRICES_LOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Z_DEAL_FIXED_PRICES_LOG](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[FIXED_PRICE_PER_CASE] [varchar](50) NULL,
	[FIXED_PRICE_PER_POUND] [varchar](50) NULL,
	[FREIGHT_ALLOWANCE] [varchar](50) NULL,
	[DELIVERED_PRICE_PER_CASE] [varchar](50) NULL,
	[DELICERED_PRICE_PER_POUND] [varchar](50) NULL,
	[FIXED_PRICE_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[FIXED_PRICE_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_Z_DEAL_FIXED_PRICES_LOG_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_Z_DEAL_FIXED_PRICES_LOG_REJECTED]  DEFAULT ((0))
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_LUMPSUM.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Z_DEAL_LUMPSUM]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Z_DEAL_LUMPSUM](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[LS_AMOUNT] [varchar](50) NULL,
	[LUMP_SUM_DESCRIPTION] [varchar](50) NULL,
	[LS_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[LS_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[REJECTED] [bit] NOT NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Z_DEAL_LUMPSUM] ADD  CONSTRAINT [DF_Z_DEAL_LUMPSUM_REJECTED]  DEFAULT ((0)) FOR [REJECTED]
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_LUMPSUM_LOG.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Z_DEAL_LUMPSUM_LOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Z_DEAL_LUMPSUM_LOG](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[LS_AMOUNT] [varchar](50) NULL,
	[LUMP_SUM_DESCRIPTION] [varchar](50) NULL,
	[LS_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[LS_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_Z_DEAL_LUMPSUM_LOG_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_Z_DEAL_LUMPSUM_LOG_REJECTED]  DEFAULT ((0))
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_OPERATORS.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Z_DEAL_OPERATORS]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Z_DEAL_OPERATORS](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[SHIP_TO] [varchar](100) NULL,
	[REJECTED] [bit] NOT NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Z_DEAL_OPERATORS] ADD  CONSTRAINT [DF_Z_DEAL_OPERATORS_REJECTED]  DEFAULT ((0)) FOR [REJECTED]
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_OPERATORS_LOG.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Z_DEAL_OPERATORS_LOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Z_DEAL_OPERATORS_LOG](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[SHIP_TO] [varchar](100) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_Z_DEAL_OPERATORS_LOG_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_Z_DEAL_OPERATORS_LOG_REJECTED]  DEFAULT ((0))
) ON [PRIMARY]
END
GO

-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_REBATES.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Z_DEAL_REBATES]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Z_DEAL_REBATES](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[REBATE] [varchar](50) NULL,
	[REBATE_UOM] [varchar](50) NULL,
	[REBATE_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[REBATE_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[REJECTED] [bit] NOT NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Z_DEAL_REBATES] ADD  CONSTRAINT [DF_Z_DEAL_REBATES_REJECTED]  DEFAULT ((0)) FOR [REJECTED]
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_REBATES_LOG.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Z_DEAL_REBATES_LOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Z_DEAL_REBATES_LOG](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[REBATE] [varchar](50) NULL,
	[REBATE_UOM] [varchar](50) NULL,
	[REBATE_COMPONENT_NAME] [varchar](50) NULL,
	[GL_ACCOUNT] [varchar](50) NULL,
	[REBATE_PAYS_TO] [varchar](50) NULL,
	[PAYMENT_FREQUENCY] [varchar](50) NULL,
	[CLAIM_MECHANIC] [varchar](50) NULL,
	[PAYEE_ELIGIBILITY] [varchar](50) NULL,
	[PAYEE] [varchar](50) NULL,
	[CURRENCY] [varchar](50) NULL,
	[GROUP] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_Z_DEAL_REBATES_LOG_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_Z_DEAL_REBATES_LOG_REJECTED]  DEFAULT ((0))
) ON [PRIMARY]
END
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_VOLUMES.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
DROP TABLE [dbo].[Z_DEAL_VOLUMES]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Z_DEAL_VOLUMES](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[PROGRAM_VOLUME_CASES] [varchar](50) NULL,
	[PROGRAM_VOLUME_POUNDS] [varchar](50) NULL,
	[REJECTED] [bit] NOT NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Z_DEAL_VOLUMES] ADD  CONSTRAINT [DF_Z_DEAL_VOLUMES_REJECTED]  DEFAULT ((0)) FOR [REJECTED]
GO


-------------------------------------------------------------------------------------------------------------------------------
--- Z_DEAL_VOLUMES_LOG.SQL was last modified on 05/28/2019 08:31:18 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Z_DEAL_VOLUMES_LOG]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Z_DEAL_VOLUMES_LOG](
	[LEGACY_PROGRAM_ID] [varchar](100) NULL,
	[ITEM_NUMBER] [varchar](50) NULL,
	[PROGRAM_VOLUME_CASES] [varchar](50) NULL,
	[PROGRAM_VOLUME_POUNDS] [varchar](50) NULL,
	[process_Date] [datetime] NULL,
	[Created_date] [datetime] NOT NULL CONSTRAINT [DF_Z_DEAL_VOLUMES_LOG_Created_date] DEFAULT (GETDATE()),
	[REJECTED] [bit] NOT NULL  CONSTRAINT [DF_Z_DEAL_VOLUMES_LOG_REJECTED]  DEFAULT ((0)) 
) ON [PRIMARY]
END
GO
-------------------------------------------------------------------------------------------------------------------------------
--- _SETTINGS.SQL was last modified on 10/24/2019 10:56:17 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/************************************************************************************************************
  Label:    47768
  Name:     \AwayX_SQL\Table\_Settings.sql
  Purpose:  Introduced new storage for internal setting.
            Only new internal settings (created after 2015 January 24) are stored in this new table.
            Previous internal settings remain in _Application_Settings table.

  Author:   Chris Nguyen
  Date:     2015 January 24

  UDF to get setting from SQL: udf_GetAppSetting
  eg: SELECT DBO.udf_GetAppSetting('BB_Expected_Rate_GT_Claim_Rate_Distributor')

  Step 1: Insert a new row into _Settings table using this script
  Step 2: Modify file app_settings_2.cfm to add the setting to UI
  Step 3: Start using it in CF or SQL
************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM INFORMATION_SCHEMA.Tables
                 WHERE Table_Name = '_Settings' )
  BEGIN
      CREATE TABLE [dbo].[_Settings]([Input_Name] [VARCHAR]( 50 ) NOT NULL,
                                     [Value]      [VARCHAR]( max ) NULL)
      ON [PRIMARY]
  END

GO

/****** Object:  Index [PK__Settings]    Script Date: 01/28/2015 07:57:50 ******/
IF NOT EXISTS ( SELECT *
                  FROM sys.Indexes
                 WHERE Object_Id = Object_Id( N'[dbo].[_Settings]' )
                       AND Name = N'PK__Settings' )
  ALTER TABLE [dbo].[_Settings]
      ADD CONSTRAINT [PK__Settings] PRIMARY KEY CLUSTERED ( [Input_Name] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Budget_Participation' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Budget_Participation',
                    '0' )
  END

GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Budget_Overlay' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Budget_Overlay',
                    '0' )
  END

GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Deduction_Ship_To_Bill_To_Association_Required' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Deduction_Ship_To_Bill_To_Association_Required',
                    '1' )
  END

GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_Doc_Server_Folder' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'BB_Doc_Server_Folder',
                    NULL )
  END

GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_Expected_Rate_GT_Claim_Rate_Distributor' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'BB_Expected_Rate_GT_Claim_Rate_Distributor',
                    '0' )
  END

GO

-- 48779
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Manual_Void_Credit_Request' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name, Value)
           VALUES ( 'Manual_Void_Credit_Request', '0' )
  END

GO

--49907
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Vendor_Batching' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Vendor_Batching',
                    '0' )
  END

GO

--51056
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Dashboards' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Dashboards',
                    '0' )
  END
GO

-- 51726
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Copy_Distributors_to_Vendors')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Copy_Distributors_to_Vendors','0' )
  END
GO

-- 51726
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Copy_Operators_to_Vendors')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Copy_Operators_to_Vendors','0' )
  END
GO
 --  48146

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Percentage_Of_List_Price')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Percentage_Of_List_Price','0' )
  END
GO

-- 50391 US Food Local Marketing Rebates
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Margin_Use_Net_Price_For_Net_Rebate')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Margin_Use_Net_Price_For_Net_Rebate','0' )
  END
GO

-- D55718 Check to see if deduction exists for billback and update closing method
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Update_BB_To_DD_CM_If_DD_Exists')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Update_BB_To_DD_CM_If_DD_Exists','0' )
  END
GO


-- 57075 Deviation settings and trade templates
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Dist_Trade_Deviation_Tolerance_Override')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Dist_Trade_Deviation_Tolerance_Override','0' )
  END
GO


-- 57305 Retail Planner
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Planner')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Retail_Planner','0' )
  END
GO

-- 57305 Retail Planner
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Planner_Week_Start')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Retail_Planner_Week_Start','' )
  END
GO


-- 57305 Retail Planner
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Planner_Vol_Forcast_Weeks')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Retail_Planner_Vol_Forcast_Weeks','' )
  END
GO


-- D49429: APF Enhancement: INCLUDE OI TRANSACTIONS IN BB VALIDATION

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_Deviation_Include_Invoices_With_Operator_ID')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'BB_Deviation_Include_Invoices_With_Operator_ID','0' )
  END
GO


-- 57867 Auto Pay - option to use calendar months instead of fiscal periods

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Auto_Pay_Use_Calendar_Months')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,Value)
           VALUES ( 'Auto_Pay_Use_Calendar_Months','0' )
  END
GO
---57639	View all versions of programs in program search
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Display_PGR_Versions_In_search')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Display_PGR_Versions_In_search','0' )
  END
GO

---55874 Modify claim rates report for bid programs
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Prg_Claim_Rates_Report_Agg_Rates_At_Product_Level')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Prg_Claim_Rates_Report_Agg_Rates_At_Product_Level','0' )
  END
GO

-- 62235 BB Payee page, display distributor payee type
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_display_distributor_payee')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'BB_display_distributor_payee','1' )
  END
GO

-- 62235 BB Payee page, display operator payee type
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_display_operator_payee')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'BB_display_operator_payee','1' )
  END
GO

-- 62235 BB Payee page, display broker payee type
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_display_broker_payee')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'BB_display_broker_payee','1' )
  END
GO

-- 62343 8.0 - Blended Rate, CF
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Blended_Rate')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Blended_Rate','0' )
  END
GO

-- 62697 Planner Retail Product Group Setting
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Target_Product_Group')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Retail_Target_Product_Group','11' )
  END
GO

-- Retail 225 - Margin subtotal - 71856 Retail Planner - Design - Sprint 8
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Margin_Sub_Total_Group')
  BEGIN

      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
	  SELECT TOP 1 'Retail_Margin_Sub_Total_Group', Value
	  FROM	_Settings
	  WHERE Input_Name = 'Retail_Target_Product_Group'

  END
GO


IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Deduction_match_using_bill_to_vendor')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Deduction_match_using_bill_to_vendor','0' )
  END
GO
--64149 :: Create new accrual budget process
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Accrual_Budgets_Calculation_By_Client')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Accrual_Budgets_Calculation_By_Client','0' )
  END
GO


-- 65603:: Hiding Item no. and Shr_ship to changes

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Display_Item_No')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Display_Item_No','1' )
  END
GO
/*
Values are
ON = 1 -- Display Item no.
OFF = 0 -- Do not Display Item No.
*/


IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Display_Distributor_ID')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Display_Distributor_ID','1' )
  END
GO
/*
Values are
ON = 1 -- Display Shared_Ship_To
OFF = 0 -- Display Ship_To
*/

-- 65859 Match central split reason code
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'DD_Match_Central_Keep_It_Open')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'DD_Match_Central_Keep_It_Open','1' )
  END
GO
/*
Values are
ON = 1 (default) -- Keep It Open will be avilable
OFF = 0 -- Keep It Open will not be avilable
*/
 ---66094 :: Release Settlement:  Update condition requiring OI Program Ack
 IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'Release_Settlement_Availability')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Release_Settlement_Availability','2' )
  END
GO
 /*
Values are
ON = 1 -- Only after ack
OFF = 2 -- Always
*/
--D64200 :: Create new accrual budget forecast process
 IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'Annual_Budget_Forecast')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Annual_Budget_Forecast','0' )
  END
GO

/* 66060:: Claims Input Accelerator */

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'OCR_Upload_ON')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'OCR_Upload_ON','0' )
  END
GO

/* 68872:: Restricting only one component per billback in upload and manual process */

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Restrict_One_Component_Per_Billback')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Restrict_One_Component_Per_Billback','0' )
  END
GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Base_Volume_Basis')
  BEGIN
      INSERT INTO _Settings (Input_Name, Value)
           VALUES ( 'Retail_Base_Volume_Basis', '13' )
  END
GO
--- 70576	Margin not calculating correctly
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Contribution_Margin_Calculation')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Contribution_Margin_Calculation','0' )
  END
GO
--- 70923 :: Create new feature for deduction workflow
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Custom_Deduction_workflow')
  BEGIN
      -- place the default value into Value column in a string format
		INSERT INTO _Settings (Input_Name,Value)
		VALUES ( 'Custom_Deduction_workflow','0' )
  END
GO

--- 71460 :: Single sign-on for Analytics
IF EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Analytics_SSO')
  BEGIN
      -- place the default value into Value column in a string format
	  ---  DEPRECARED WE USE Analytics_Logon_URL INSTEAD
		delete from _Settings Where Input_Name = 'Analytics_SSO'
  END
GO

--- 71997 - Disable Quick Update option in Deductions
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'deduction_Quick_Update_For_New_Open_RFA')
  BEGIN
      -- place the default value into Value column in a string format
		INSERT INTO _Settings (Input_Name,Value)
		VALUES ( 'deduction_Quick_Update_For_New_Open_RFA','1' )
  END
GO

--- 72014 - Disable Pay each entity individually
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_Auto_Pay_Disable_Pay_Each_Entity_Individually')
  BEGIN
      -- place the default value into Value column in a string format
		INSERT INTO _Settings (Input_Name,Value)
		VALUES ( 'BB_Auto_Pay_Disable_Pay_Each_Entity_Individually','0' )
  END
GO

--- 72305- Do not show claim rates on program letters
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Dont_Show_Claim_Rates_On_Program_Letters')
  BEGIN
    -- place the default value into Value column in a string format
		INSERT INTO _Settings (Input_Name,Value)
		VALUES ( 'Dont_Show_Claim_Rates_On_Program_Letters','0' )
  END
GO
--- D86973- Letters not generating; event error
IF EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Dont_Show_Claim_Rates_On_Program_Letters')
  BEGIN
      UPDATE _Settings SET	Value = isnull(Value, '0') 
	  WHERE  Input_Name = 'Dont_Show_Claim_Rates_On_Program_Letters'                                
  END
GO


--- D73292 Retail Planner - Design - Sprint 11
--- Retail 319 New Setting - Program revise
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Revision_Replace_Parent')
  BEGIN
      -- place the default value into Value column in a string format
                                INSERT INTO _Settings (Input_Name)
                                VALUES ( 'Retail_Revision_Replace_Parent' )
  END
GO

-- Retail 309 - Consumer Events
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Consumer_Events_Group')
  BEGIN

      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
	  SELECT TOP 1 'Retail_Consumer_Events_Group', Value
	  FROM	_Settings
	  WHERE Input_Name = 'Retail_Target_Product_Group'

  END
GO
---73750
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Business_Considerations_All_Time')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name)
	  VALUES( 'Business_Considerations_All_Time')
   END
GO

--- 74085 - Email notifications are not being received for Letters
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Use_this_email_for_Program_Letters')
  BEGIN
      -- place the default value into Value column in a string format
       INSERT INTO _Settings (Input_Name)
       VALUES ( 'Use_this_email_for_Program_Letters' )
  END
GO


/******************************************************************************************************************
 AG_GRID - set it to blank to pull ag-grid from local server
--   CDN:  	https://unpkg.com/ag-grid-enterprise@17.0.0/dist/ag-grid-enterprise.min.noStyle.js
-- 			https://cdn.jsdelivr.net/npm/ag-grid-enterprise@17.0.0/dist/ag-grid-enterprise.min.noStyle.js
*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'ag_grid17_js')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'ag_grid17_js' )
  END
GO
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'ag_grid17_css')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'ag_grid17_css' )
  END
GO
UPDATE _Settings
   SET Value = 'https://cdn.jsdelivr.net/npm/ag-grid-enterprise@17.0.0/dist/ag-grid-enterprise.min.noStyle.js'
WHERE Input_Name = 'ag_grid17_js'
UPDATE _Settings
   SET Value = 'https://cdnjs.cloudflare.com/ajax/libs/ag-grid/17.0.0/styles/ag-grid.css,https://cdnjs.cloudflare.com/ajax/libs/ag-grid/17.0.0/styles/ag-theme-balham.css'
WHERE Input_Name = 'ag_grid17_css'

/******************************************************************************************************************
 AG_GRID_LICENSE
*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'ag_Grid17_license')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'ag_Grid17_license' )
  END
GO
UPDATE _Settings
   SET Value = 'Blacksmith_Applications_Inc._FORGE_7Devs9_March_2019__MTU1MjA4OTYwMDAwMA==6d6285876c3b468cfcee03d2cd2fa1ee'
WHERE Input_Name = 'ag_Grid17_license'




IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Quick_Pay_in_Program_Search')
  BEGIN
      -- place the default value into Value column in a string format
       INSERT INTO _Settings (Input_Name)
       VALUES ( 'Quick_Pay_in_Program_Search' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'DD_Edit_Reference')
  BEGIN
       INSERT INTO _Settings (Input_Name, Value)
       VALUES ( 'DD_Edit_Reference', 0)
  END
GO

/******************************************************************************************************************
 NOTY Version 3 -- set it to blank to pull noty from local server
*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'noty3_js')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'noty3_js' )
  END
GO
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'noty3_css')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'noty3_css' )
  END
GO
UPDATE _Settings
   SET Value = 'https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.js'
WHERE Input_Name = 'noty3_js'
UPDATE _Settings
   SET Value = 'https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.css'
WHERE Input_Name = 'noty3_css'


/******************************************************************************************************************
DropzoneJS -- open source library URLs.  Set them to blank to pull dropzone from local server
*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'dropzone_js_url')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'dropzone_js_url' )
  END
GO
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'dropzone_css_url')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'dropzone_css_url' )
  END
GO
UPDATE _Settings
   SET Value = 'https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.js'
WHERE Input_Name = 'dropzone_js_url'
UPDATE _Settings
   SET Value = 'https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.css'
WHERE Input_Name = 'dropzone_css_url'

/******************************************************************************************************************
FLASH MIGRATION: We are removing Flash / Flex implementations due to Flash deprecation.
These settings are here temporarily to enable the Flash code to continue to work during testing.
Set to "Flash" in order to use the old code, defaults to the new code.
*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'upload_documents_method ')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'upload_documents_method' )
  END
GO
UPDATE _Settings
   SET Value = 'dropzone'
WHERE Input_Name = 'upload_documents_method'

---76132 Enhancement: Set BB to Paid after Prepare Check Request 
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Billback_Set_Paid_After_Approved')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Billback_Set_Paid_After_Approved','0' )
  END

GO


-- 76021 Ember:  Open Document from FORGE Application :: LOGON URL
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Ember_Logon_URL')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Ember_Logon_URL','' )
  END
GO

-- 76021 Ember:  Open Document from FORGE Application :: DOCUMENT URL
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Ember_OpenDocument_URL')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Ember_OpenDocument_URL','' )
  END
GO

--  83599 : FORGE Analytics:  SSO From FORGE Application
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Analytics_Logon_URL')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Analytics_Logon_URL','' )
  END
GO

-- 83599 : FORGE Analytics:  SSO From FORGE Application
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Analytics_OpenDocument_URL')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
           VALUES ( 'Analytics_OpenDocument_URL','' )
  END
GO


---76307	Auto pay updates for BB number and BB Reference number
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'BB_Auto_Pay_enable_BB_Number')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'BB_Auto_Pay_enable_BB_Number','0' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'BB_Auto_Pay_enable_Ref_Number')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'BB_Auto_Pay_enable_Ref_Number','0' )
  END
GO
----76380 decimal places START
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Decimal_display_for_LB')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Decimal_display_for_LB','4' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Decimal_display_for_CS')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Decimal_display_for_CS','2' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Decimal_display_for_EA')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Decimal_display_for_EA','4' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Decimal_display_for_Percentage')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Decimal_display_for_Percentage','4' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Decimal_display_for_CWT')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Decimal_display_for_CWT','4' )
  END
GO
---76380 decimal places   END

/******************************************************************************************************************
 FORGE CDN
*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
				  FROM _Settings
				  WHERE Input_Name = 'Forge_CDN')
  BEGIN
	INSERT INTO _Settings
		(Input_Name)
	VALUES
		( 'Forge_CDN' )
END
GO

UPDATE _Settings
   SET Value = 'https://cdn.awayx.com/base'
WHERE Input_Name = 'Forge_CDN'
GO

/******************************************************************************************************************
ABBYY Install date WR - D77068 Claims Input Accelerator - Phase 13 - Sprint 23 - Additional Changes
*******************************************************************************************************************/

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'ABBYY_Install_Date')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'ABBYY_Install_Date','' )
  END
GO
/******* THIS VALUE NEEDS TO BE UPDATED BY ABBYY ADMIN LATER TO REFLECT THE CORRECT DATE OF ABBYY INSTALL ********/
  UPDATE _settings SET value = GETDATE() 
  -- SELECT value FROM _settings 
  WHERE Input_Name = 'ABBYY_Install_Date'


IF NOT EXISTS ( SELECT 1
		FROM _Settings
		WHERE Input_Name = 'Recapture_By_Operator_For_Multiple_Lists')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Recapture_By_Operator_For_Multiple_Lists','0' )
  END
GO

---77242 :: BB - Disable pages in RFA, reset to make changes
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Billback_Disable_Pages_RFA')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Billback_Disable_Pages_RFA','0' )
  END
GO

----77024 :: BB Assignment - by template
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'BB_Assignment_By_Template' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'BB_Assignment_By_Template','0' )
  END
GO

/* 77469	Display Dist Channel at BB_Program Distributor Level   [ CF work ] -Anand Rao/12-Jun-2018 */
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'BB_Display_Dist_Channel_Per_Program_Distributor' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'BB_Display_Dist_Channel_Per_Program_Distributor','0' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Redistributor_default_Segment_BS_Var_2' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Redistributor_default_Segment_BS_Var_2','99' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Growth_Consolidated_View' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Growth_Consolidated_View','0' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Product_Group_Sequencing' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Product_Group_Sequencing','0' )
  END
GO

IF NOT EXISTS ( SELECT 1
		FROM _Settings
		WHERE Input_Name = 'Lump_Sums_Programs_Paid_To_Vendor' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Lump_Sums_Programs_Paid_To_Vendor','0' )
  END
GO

/*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Margin_Display_Style')
    INSERT INTO _Settings (Input_Name) VALUES ( 'Margin_Display_Style' )
GO
/*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Margin_Cost_Predictive_Selected')
    INSERT INTO _Settings (Input_Name) VALUES ( 'Margin_Cost_Predictive_Selected' )
GO
/*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Margin_Cost_Production_Selected')
    INSERT INTO _Settings (Input_Name) VALUES ( 'Margin_Cost_Production_Selected' )
GO
/*******************************************************************************************************************/
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Margin_Cost_Historical_Selected')
    INSERT INTO _Settings (Input_Name) VALUES ( 'Margin_Cost_Historical_Selected' )
GO
/*******************************************************************************************************************/
UPDATE _Settings
   SET Value = 'Blacksmith'
WHERE Input_Name = 'Margin_Display_Style' AND (Value IS NULL OR Value = '')
GO

/*******************************************************************************************************************/
/*  76536: BB Oper Location Level - dup check 08/08/18  */
IF NOT EXISTS ( SELECT 1
		FROM _Settings
		WHERE Input_Name = 'BB_Oper_Location_Level_Dup_Checker' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'BB_Oper_Location_Level_Dup_Checker','0' )
  END
GO

/* D78742: Remote Approval for Billbacks 08/08/18 */
IF NOT EXISTS ( SELECT 1
		FROM _Settings
		WHERE Input_Name = 'BB_Approval_Via_Email' )
  BEGIN      
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'BB_Approval_Via_Email','0' )
  END
GO

IF NOT EXISTS ( SELECT 1  FROM _Settings WHERE Input_Name = 'BB_Email_Out_Job_Time')
BEGIN
	INSERT INTO _Settings (Input_Name,Value)
	VALUES ('BB_Email_Out_Job_Time', '06:30 am')
END
GO

IF NOT EXISTS ( SELECT 1  FROM _Settings WHERE Input_Name = 'BB_Email_Out_Job_Success')
BEGIN
	INSERT INTO _Settings (Input_Name,Value)
	VALUES ('BB_Email_Out_Job_Success', 'kehrlich@bigredflame.com')
END
GO

IF NOT EXISTS ( SELECT 1  FROM _Settings WHERE Input_Name = 'BB_Email_In_Job_Interval')
BEGIN
	INSERT INTO _Settings (Input_Name,Value)
	VALUES ('BB_Email_In_Job_Interval', '3')
END
GO

IF NOT EXISTS ( SELECT 1  FROM _Settings WHERE Input_Name = 'BB_Email_In_Job_Success')
BEGIN
	INSERT INTO _Settings (Input_Name,Value)
	VALUES ('BB_Email_In_Job_Success', 'kehrlich@bigredflame.com')
END
GO

IF NOT EXISTS ( SELECT 1  FROM _Settings WHERE Input_Name = 'BB_Email_Approval_Instructions')
BEGIN
	INSERT INTO _Settings (Input_Name,Value)
	VALUES ('BB_Email_Approval_Instructions', 
	'The following billback requires your approval. To Approve: 
	- Hit Reply.
	- Type in your PIN surrounded # signs (e.g. #XXXX#).')
END

GO

IF NOT EXISTS ( SELECT 1
		FROM _Settings
		WHERE Input_Name = 'Display_Segment_In_Deduction' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings 
	  	( Input_Name, Value )
      VALUES 
	  	( 'Display_Segment_In_Deduction', '0' )
  END
GO

IF NOT EXISTS ( SELECT 1
		FROM _Settings
		WHERE Input_Name = 'Display_Operating_Unit_In_Deduction' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings 
	  	( Input_Name, Value )
      VALUES 
	  	( 'Display_Operating_Unit_In_Deduction', '1' )
  END
GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_Show_DD_Link')
  BEGIN
    INSERT INTO _Settings (Input_Name,Value) 
    VALUES ( 'BB_Show_DD_Link','0')
  END

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Include_Second_Component_Feature')
  BEGIN
    INSERT INTO _Settings (Input_Name,Value) 
    VALUES ( 'Include_Second_Component_Feature','0')
  END

GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'PG_Eff_Date_Product' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'PG_Eff_Date_Product', '0' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'PG_Eff_Date_Distributor' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'PG_Eff_Date_Distributor', '0' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'PG_Eff_Date_Operator' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'PG_Eff_Date_Operator', '0' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'Autopay_Brokerage_From_Zipcode' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'Autopay_Brokerage_From_Zipcode', '0' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'Autopay_Brokerage_Perf_Req_Base' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'Autopay_Brokerage_Perf_Req_Base', '' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'Autopay_Brokerage_Perf_Req_Override_List' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'Autopay_Brokerage_Perf_Req_Override_List', '' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'Oper_REDI_BB_Only_Include_REDI_Invoice' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'Oper_REDI_BB_Only_Include_REDI_Invoice', '0' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'REDI_Invoice_Type_List' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'REDI_Invoice_Type_List', '' )
  END
GO

IF NOT EXISTS ( SELECT 1 FROM _Settings WHERE Input_Name = 'PG_Number_Sequence' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name, Value)
      VALUES ( 'PG_Number_Sequence', '1000000000' )
  END

GO

IF NOT EXISTS (	  SELECT 1
					FROM dbo._Settings
				   WHERE Input_Name = 'GenerateSecretKey_AES_128')
	BEGIN
		-- place the default value into Value column in a string format
		INSERT INTO dbo._Settings
			(
				Input_Name
			   ,Value
			)
		VALUES
			(
				'GenerateSecretKey_AES_128'
			   ,'pS5TTzlv0us673kAx6z95g=='
			);
	END;
GO

IF NOT EXISTS (	  SELECT 1
					FROM dbo._Settings
				   WHERE Input_Name = 'CF_Admin_Password')
	BEGIN
		-- place the default value into Value column in a string format
		INSERT INTO dbo._Settings
			(
				Input_Name
			   ,Value
			)
		VALUES
			(
				'CF_Admin_Password'
			   ,'Y+Slto8jcQ0mHos5wRtdOw=='
			);
	END;
GO

--82949- Create setting to not override Distributor Owner and Operator Owner
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Dont_override_Invoice_Owner_fields')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Dont_override_Invoice_Owner_fields','0' )
  END
GO


--82535 - Accrual Records Overview in FORGE
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Accrual_Exclude_Document_Types')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'Accrual_Exclude_Document_Types','' )
  END
GO


--GPO - One Page Program Creation
IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'GPO_One_Page_Program_Creation')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
      VALUES ( 'GPO_One_Page_Program_Creation','0' )
  END
GO


-- Possible format values are 'Flex', 'ColdFusion', 'Flex and ColdFusion'
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Program_Search_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Program_Search_Format', 'Flex and ColdFusion' );
GO
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Alias_Management_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Alias_Management_Format', 'Flex and ColdFusion' );
GO
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Edit_Volume_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Edit_Volume_Format', 'Flex and ColdFusion' );
GO
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'BB_Deviation_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'BB_Deviation_Format', 'Flex' );
GO
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'EDI_Viewer_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'EDI_Viewer_Format', 'Flex' );
GO
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Redistribution_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Redistribution_Format', 'Flex' );
GO
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Program_Rate_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Program_Rate_Format', 'Flex' );
GO

-- 2019 April 11 - Karen requested to maintain the default format to Flex 
UPDATE dbo._Settings 
   SET Value = 'Flex' 
 WHERE Input_Name IN ('Edit_Volume_Format', 'Program_Search_Format', 'Alias_Management_Format')
GO 

UPDATE dbo._Settings 
   SET Value = 'None' 
 WHERE Input_Name = 'EDI_Viewer_Format'
GO 

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'Program_Search_CacheBlockSize')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
                VALUES ( 'Program_Search_CacheBlockSize', '20000' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'EDI_Viewer_CacheBlockSize')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
                VALUES ( 'EDI_Viewer_CacheBlockSize', '20000' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'queryDatabase_maxrows')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
                VALUES ( 'queryDatabase_maxrows', '1000' )
  END
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'event_errors_auto_refresh_in_minutes')
  BEGIN
      INSERT INTO _Settings (Input_Name,Value)
                VALUES ( 'event_errors_auto_refresh_in_minutes', '5' )
  END
GO


/******************************************************************************************************************
 AG_GRID_LICENSE
*******************************************************************************************************************/
-- DELETE _Settings WHERE Input_Name LIKE 'ag_Grid17_%' or Input_Name = 'ag_grid_source'
-- GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'ag_Grid_license')
  BEGIN
       INSERT INTO _Settings (Input_Name) VALUES ( 'ag_Grid_license' )
  END
GO
UPDATE _Settings
   SET Value = 'Blacksmith_Apps_Forge_7Devs_2Deployment_27_March_2020__MTU4NTI2NzIwMDAwMA==7a792a14e407501b7ad83045a0912fdd'
WHERE Input_Name = 'ag_Grid_license'

IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Redistribution_page_size')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Redistribution_page_size', '500' );
GO

IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Edit_volume_page_size')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Edit_volume_page_size', '500' );
GO

UPDATE _Settings SET Value = 10000 WHERE Input_Name = 'Edit_volume_page_size'
GO

IF NOT EXISTS ( SELECT 1
						FROM _Settings
						WHERE Input_Name = 'BB_Manual_VOID_Detach_DD')
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings (Input_Name,Value)
                VALUES ( 'BB_Manual_VOID_Detach_DD', '1' )
  END
GO

-- 85551 3000 Rebate Intake File (Rebating) - Billback Validation Changes
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'BB_Expected_Rate_GT_Claim_Rate_Fixed_Price' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'BB_Expected_Rate_GT_Claim_Rate_Fixed_Price',
                    '0' )
  END

GO

-- 77432 - Demand Planning interface
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Demand_Plan_Enabled' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Retail_Demand_Plan_Enabled',
                    '0' )
  END

GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Demand_Plan_Populate_Latest_FCST' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Retail_Demand_Plan_Populate_Latest_FCST',
                    '0' )
  END

GO


IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Retail_Demand_Plan_Interface_UOM' )
  BEGIN
      -- place the default value into Value column in a string format
      INSERT INTO _Settings
                  (Input_Name,
                   Value)
           VALUES ( 'Retail_Demand_Plan_Interface_UOM',
                    '2' )
  END

GO

-- 86656 Planner approval - absolute variance amount
IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Margin_Profile_Variance_Type')
    INSERT INTO _Settings (Input_Name, Value) VALUES ( 'Margin_Profile_Variance_Type', '1')
GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'CF_2020_BB_Deviation')
    INSERT INTO _Settings (Input_Name, Value) VALUES ( 'CF_2020_BB_Deviation', '0')
GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'CF_2020_Alias_Mgmt')
    INSERT INTO _Settings (Input_Name, Value) VALUES ( 'CF_2020_Alias_Mgmt', '0')
GO

DELETE _Settings WHERE Input_Name = 'CF_2020_Alias_Mgmt'
GO 

DELETE _Settings WHERE Input_Name = 'CF_2020_BB_Deviation'
GO 

/* D88808 NSC: Update Planning Group Member Date Functionality */

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'PG_Effective_Date_Upload_Download')
    INSERT INTO _Settings (Input_Name, Value) VALUES ( 'PG_Effective_Date_Upload_Download', '0')
GO

IF NOT EXISTS ( SELECT 1
                  FROM _Settings
                 WHERE Input_Name = 'Formula_Price_Item_Level_Config')
    INSERT INTO _Settings (Input_Name, Value) VALUES ( 'Formula_Price_Item_Level_Config', '0')
GO

<<<<<<< _Settings.sql
IF NOT EXISTS (	SELECT 1 FROM dbo._Settings WHERE Input_Name = 'Redistribution_Format')
	INSERT INTO dbo._Settings ( Input_Name, Value ) VALUES ( 'Redistribution_Format', 'Flex' );
GO
=======
-- 88713 - BB Analyst Updates for BB Uploads Only
IF NOT EXISTS ( SELECT 1
                FROM _Settings
                WHERE Input_Name = 'Update_Analyst_with_Creator_ID')
    INSERT INTO _Settings (Input_Name, Value) VALUES ( 'Update_Analyst_with_Creator_ID', '0')
GO

>>>>>>> 1.111
-------------------------------------------------------------------------------------------------------------------------------
--- _USERS.SQL was last modified on 12/17/2018 08:05:35 AM ---
-------------------------------------------------------------------------------------------------------------------------------
/****** Object:  Table [dbo].[_Users]    Script Date: 05/07/2010 13:56:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '_Users')
BEGIN
	CREATE TABLE [dbo].[_Users]
	(
		[User_ID] [nvarchar](50) NOT NULL,
		[Name_First] [nvarchar](50) NULL,
		[Name_Last] [nvarchar](50) NULL,
		[User_Code] [nvarchar](50) NULL,
		[User_Password] [nvarchar](50) NULL,
		[User_Email] [nvarchar](50) NULL,
		[Profiles_ID] [int] NULL,
		[Company_Code] [nvarchar](50) NULL,
		[Home_Address_1] [nvarchar](255) NULL,
		[Home_Address_2] [nvarchar](50) NULL,
		[Home_City] [nvarchar](50) NULL,
		[Home_State] [nvarchar](50) NULL,
		[Home_Zip] [nvarchar](50) NULL,
		[Home_Phone] [nvarchar](50) NULL,
		[Title] [nvarchar](50) NULL,
		[Work_Address_1] [nvarchar](255) NULL,
		[Work_Address_2] [nvarchar](50) NULL,
		[Work_City] [nvarchar](50) NULL,
		[Work_State] [nvarchar](50) NULL,
		[Work_Zip] [nvarchar](50) NOT NULL,
		[Work_Phone] [nvarchar](50) NULL,
		[Password_Question] [nvarchar](50) NULL,
		[Password_Answer] [nvarchar](50) NULL,
		[Company_Main_ID] [nvarchar](50) NULL,
		[Access_Level] [nvarchar](50) NULL,
		[This_Component_Title] [nvarchar](255) NULL,
		[User_Rights_ID] [int] NULL CONSTRAINT [DF__Users_User_Rights_ID_1]  DEFAULT ((1000)),
		[Deleted] [bit] NOT NULL CONSTRAINT [DF__Users_Deleted_1]  DEFAULT ((0)),
		[Work_Phone_1] [nvarchar](50) NULL,
		[Work_Phone_2] [nvarchar](50) NULL,
		[Work_Phone_3] [nvarchar](50) NULL,
		[Work_Phone_Ext] [nvarchar](50) NULL,
		[Work_Fax_1] [nvarchar](50) NULL,
		[Work_Fax_2] [nvarchar](50) NULL,
		[Work_Fax_3] [nvarchar](50) NULL,
		[BSA_Foodservice_Customers_ID] [nvarchar](50) NULL,
		[Is_System_Administrator] [bit] NULL CONSTRAINT [DF__Users_Is_System_Administrator]  DEFAULT ((0)),
		[Login_Status] [bit] NULL CONSTRAINT [DF__Users_Login_Status]  DEFAULT ((0)),
		[LoginTries] [int] NOT NULL CONSTRAINT [DF__Users_LoginTries_1]  DEFAULT ((0)),
		[Is_Locked] [bit] NOT NULL CONSTRAINT [DF__Users_Is_Locked_1]  DEFAULT ((0)),
		[Is_First_Time] [bit] NOT NULL CONSTRAINT [DF__Users_Is_First_Time_1]  DEFAULT ((0)),
		[Contact_Administrator] [bit] NULL CONSTRAINT [DF__Users_Contact_Administrator]  DEFAULT ((0)),
		[User_Created_Date] [datetime] NULL CONSTRAINT [DF__Users_Created_Date]  DEFAULT (getdate()),
		[Authority_Sequence_ID] [int] NULL,
		[User_Number] [nvarchar](50) NULL,
		[USER_USDA_STATE_ID] [int] NOT NULL CONSTRAINT [DF__Users_USER_USDA_STATE_ID]  DEFAULT ((0)),
		[USER_USDA_COUNTY_ID] [int] NOT NULL CONSTRAINT [DF__Users_USER_USDA_COUNTY_ID]  DEFAULT ((0)),
		[USER_USDA_OPERATOR_ID] [int] NOT NULL CONSTRAINT [DF__Users_USER_USDA_OPERATOR_ID]  DEFAULT ((0)),
		[Is_USDA_User] [bit] NOT NULL CONSTRAINT [DF__Users_Is_USDA_User]  DEFAULT ((0)),
		[user_usda_distributor_id] [uniqueidentifier] NULL,
		[Password_Update_Date] [datetime] NOT NULL CONSTRAINT [DF__Users_Password_Update_Date]  DEFAULT (getdate()),
		[Home_Country_Code] [varchar](3) NULL,
		[Work_Country_Code] [varchar](3) NULL,
		[User_PasswordHistory] [text] NULL,
		[Crucible_File_Download] [bit] NOT NULL CONSTRAINT [DF__Users_Crucible_File_Download]  DEFAULT ((0)),
		[Is_Eligible_RSP] [bit] NOT NULL CONSTRAINT [DF___Users__Is_Eligi__6DB1157C]  DEFAULT ((1)),
		[Company_Name] [nvarchar](50) NULL,
		[deleted_date] [datetime] NULL,
		[deleted_by] [nvarchar](50) NULL,
		[Updated_By] [nvarchar](50) NULL,
		[Updated_Date] [datetime] NULL,
		[Sales_Person_ID] [int] IDENTITY(1,1) NOT NULL,
		[Blacksmith_User] [bit] NOT NULL CONSTRAINT [DF__Users_Blacksmith_User]  DEFAULT ((0)),
		[Is_On_Behalf_Of] [bit] NOT NULL CONSTRAINT [DF__Users_Is_On_Behalf_Of]  DEFAULT ((0)),
		[Last_Unlock_By] [nvarchar](50) NULL,
		[Last_Unlock_Date] [datetime] NULL,
		[USER_PIN] [nvarchar](50) NULL,
		[PIN_UPDATE_DATE] [datetime] NULL CONSTRAINT [DF__USERS_PIN_UPDATE_DATE]  DEFAULT (getdate()),
		[LDAP_User_ID] [varchar](100) NULL,
		[LDAP_User_Name] [varchar](100) NULL,
	 CONSTRAINT [PK__Users_1] PRIMARY KEY CLUSTERED 
	(
		[User_ID] ASC
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO

-- 21554 : LDAP/SSO Settings
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'LDAP_User_ID')
	ALTER TABLE dbo._Users ADD LDAP_User_ID varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL	
GO 
-- 21554 : LDAP/SSO Settings
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'LDAP_User_Name')
	ALTER TABLE dbo._Users ADD LDAP_User_Name varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
GO 

-- D23915: Single Instance Remote Approval
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'RFA_Notification_Email')
	ALTER TABLE dbo._Users ADD RFA_Notification_Email [bit] NOT NULL CONSTRAINT [DF__Users_RFA_Notification_Email]  DEFAULT (1)
GO 
-- D23915: Single Instance Remote Approval
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'Remote_Approval_Option')
	ALTER TABLE dbo._Users ADD Remote_Approval_Option [int] NOT NULL CONSTRAINT [DF__Users_Remote_Approval_Option]  DEFAULT (2)
GO 

-- D27172: Added middle initial
IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'Name_Middle_Initial')
	ALTER TABLE dbo._Users ADD Name_Middle_Initial varchar(1) CONSTRAINT [DF__Users_Name_Middle_Initial]  NULL
GO 

IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'User_Language')
	ALTER TABLE dbo._Users ADD User_Language varchar(20) NOT NULL CONSTRAINT [DF__Users_User_Language]  DEFAULT 'English'
GO 

IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'Analytics_SSO_USER_NAME')
	ALTER TABLE dbo._Users ADD Analytics_SSO_User_Name varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
GO 

-- D78742 - Remote Approval for Billbacks
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '_Users' AND COLUMN_NAME = 'BB_Remote_Approval_Option')
	ALTER TABLE dbo._Users ADD BB_Remote_Approval_Option [int] NOT NULL CONSTRAINT [DF__Users_BB_Remote_Approval_Option]  DEFAULT (0)
GO 

SET ANSI_PADDING OFF
GO
--- 72497 
IF NOT EXISTS(
					SELECT 1 
					FROM INFORMATION_SCHEMA.COLUMNS 
					WHERE TABLE_NAME = '_Users' 
					AND COLUMN_NAME = 'Ember_Info')
	ALTER TABLE dbo._Users ADD Ember_Info varchar(250) NULL
GO 
-------------------------------------------------------------------------------------------------------------------------------
--- _USERS_CONFIG.SQL was last modified on 08/13/2019 01:37:50 PM ---
-------------------------------------------------------------------------------------------------------------------------------
/************************************************************************************************************
  WR:        ?
  Name:      _Users_Config.sql
  Purpose:   Various settings for users (e.g. ag-grid settings)

  Author:    Chris Nguyen
  Date:      2019 August
************************************************************************************************************/

IF NOT EXISTS (
                    SELECT 1
                    FROM INFORMATION_SCHEMA.TABLES
                    WHERE TABLE_NAME = '_Users_Config'
                )
BEGIN
    CREATE TABLE [dbo].[_Users_Config] (
        [User_ID] [VARCHAR](50) NOT NULL,
        [Setting] [VARCHAR](50) NOT NULL,
        [Value] [VARCHAR](MAX) NULL,
        [Last_Modified] [DATETIME] NULL,
        CONSTRAINT [PK__Users_Setup]
            PRIMARY KEY CLUSTERED (
                                      [User_ID] ASC,
                                      [Setting] ASC
                                  )
            WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
                  ALLOW_PAGE_LOCKS = ON
                 ) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];
END;
GO
-------------------------------------------------------------------------------------------------------------------------------
--- _USERS_SETTINGS.SQL was last modified on 02/25/2019 08:24:27 AM ---
-------------------------------------------------------------------------------------------------------------------------------
IF not EXISTS
(SELECT * FROM SysObjects O INNER JOIN SysColumns C ON O.ID=C.ID
WHERE ObjectProperty(O.ID,'IsUserTable')=1 
AND O.Name='_Users_Settings'
AND C.Name='Max_Program_Product_Display')

Begin
Alter TABLE [dbo].[_Users_Settings]Add 
	[Max_Program_Product_Display] [INT] NOT NULL 
	CONSTRAINT [DF_Users_Settings_Max_Program_Product_Display] DEFAULT (300)

End
GO

IF NOT EXISTS
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND		COLUMN_NAME = 'Cancel_Program_Options'
)
ALTER TABLE dbo._Users_Settings ADD [Cancel_Program_Options] [INT] NOT NULL CONSTRAINT [DF__Users_Settings_Cancel_Program_Options] DEFAULT ((3))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND
	COLUMN_NAME = 'Display_Trade_Dollars'
)
ALTER TABLE [dbo].[_Users_Settings] ADD [Display_Trade_Dollars] [bit] NOT NULL
CONSTRAINT [DF__Users_Settings_Display_Trade_Dollars]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND
	COLUMN_NAME = 'Display_Trade_Dollars_Type'
)
ALTER TABLE [dbo].[_Users_Settings] ADD [Display_Trade_Dollars_Type] [bit] NOT NULL
CONSTRAINT [DF__Users_Settings_Display_Trade_Dollars_Type]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND
	COLUMN_NAME = 'Display_Payment_Dollars'
)
ALTER TABLE [dbo].[_Users_Settings] ADD [Display_Payment_Dollars] [bit] NOT NULL
CONSTRAINT [DF__Users_Settings_Display_Payment_Dollars]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND
	COLUMN_NAME = 'Display_Volume'
)
ALTER TABLE [dbo].[_Users_Settings] ADD [Display_Volume] [bit] NOT NULL
CONSTRAINT [DF__Users_Settings_Display_Volume]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND
	COLUMN_NAME = 'Display_Volume_Type'
)
ALTER TABLE [dbo].[_Users_Settings] ADD [Display_Volume_Type] [bit] NOT NULL
CONSTRAINT [DF__Users_Settings_Display_Volume_Type]  DEFAULT ((0))
GO

if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND
	COLUMN_NAME = 'Accrual_Product_Group_Level_ID'
)
ALTER TABLE [dbo].[_Users_Settings] ADD [Accrual_Product_Group_Level_ID] [tinyint] NOT NULL 
CONSTRAINT [DF__Users_Settings_Accrual_Product_Group_Level_ID]  DEFAULT ((0))
GO


if not exists
(
	SELECT	*
	FROM	INFORMATION_SCHEMA.COLUMNS
	WHERE	TABLE_NAME = '_Users_Settings'
	AND
	COLUMN_NAME = 'Display_Operator_Info'
)
ALTER TABLE [dbo].[_Users_Settings] ADD [Display_Operator_Info] [bit] NOT NULL
CONSTRAINT [DF__Users_Settings_Display_Operator_Info]  DEFAULT ((0))
GO