------------------------------------------------------------------------------
-- ADVANTAGE 2004.4.3
-- DB OBJECT CHANGES SINCE ADVANTAGE 2004.4.2
-- 21/03/2009
------------------------------------------------------------------------------



-------------------------------------------------------------------------------
-- NEW TABLES
-------------------------------------------------------------------------------

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AP_Stock_Take_Procedures]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AP_Stock_Take_Procedures]
GO

CREATE TABLE [dbo].[AP_Stock_Take_Procedures] (
	[AP_Stock_Take_Procedures_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Description] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Procedure_Date] [datetime] NULL ,
	[Slu_AW_Months_ID] [tinyint] NULL ,
	[Slu_AW_Years_ID] [int] NULL ,
	[Stock_Valuation] [money] NULL ,
	[AB_Journals_ID] [int] NULL ,
	[Stock_Adjustment_Total] [money] NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AP_Stock_Take_Procedures] WITH NOCHECK ADD 
	CONSTRAINT [PK_AP_Stock_Take_Procedures] PRIMARY KEY  CLUSTERED 
	(
		[AP_Stock_Take_Procedures_ID]
	)  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AP_Stock_Take_Procedures].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AP_Stock_Take_Procedures].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Active]', N'[AP_Stock_Take_Procedures].[Slu_AW_Active_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Stock_Take_Procedures].[Stock_Valuation]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[AP_Stock_Take_Procedures].[User_ID]'
GO

setuser
GO


-----------------------------------------


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AP_Products_Stock_Takes]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AP_Products_Stock_Takes]
GO

CREATE TABLE [dbo].[AP_Products_Stock_Takes] (
	[AP_Products_Stock_Takes_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[AP_Stock_Take_Procedures_ID] [int] NULL ,
	[AP_Products_ID] [int] NULL ,
	[Count1] [decimal](9, 3) NULL ,
	[Count2] [decimal](9, 3) NULL ,
	[Count3] [decimal](9, 3) NULL ,
	[Total_Count] [decimal](12, 3) NULL ,
	[Unit_Cost] [money] NULL ,
	[On_Hand] [decimal](9, 3) NULL ,
	[Variance] [decimal](12, 3) NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AP_Products_Stock_Takes] WITH NOCHECK ADD 
	CONSTRAINT [PK_AP_Products_Stock_Takes] PRIMARY KEY  CLUSTERED 
	(
		[AP_Products_Stock_Takes_ID]
	)  ON [PRIMARY] 
GO

 CREATE  INDEX [IX_AP_Products_Stock_Takes_AP_Products_ID] ON [dbo].[AP_Products_Stock_Takes]([AP_Products_ID]) ON [PRIMARY]
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products_Stock_Takes].[Count1]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products_Stock_Takes].[Count2]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products_Stock_Takes].[Count3]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products_Stock_Takes].[Total_Count]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products_Stock_Takes].[Unit_Cost]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products_Stock_Takes].[On_Hand]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AP_Products_Stock_Takes].[Variance]'
GO

EXEC sp_bindefault N'[dbo].[df_User_Companies]', N'[AP_Products_Stock_Takes].[AW_User_Companies_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[AP_Products_Stock_Takes].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Active]', N'[AP_Products_Stock_Takes].[Slu_AW_Active_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[AP_Products_Stock_Takes].[User_ID]'
GO


setuser
GO


-----------------------------------------


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Slu_AC_Statement_Messages]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Slu_AC_Statement_Messages]
GO

CREATE TABLE [dbo].[Slu_AC_Statement_Messages] (
	[Slu_AC_Statement_Messages_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Description] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Message] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Slu_AC_Statement_Messages] WITH NOCHECK ADD 
	CONSTRAINT [PK_Slu_AC_Statement_Messages] PRIMARY KEY  CLUSTERED 
	(
		[Slu_AC_Statement_Messages_ID]
	)  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Date_Captured]', N'[Slu_AC_Statement_Messages].[Date_Captured]'
GO

EXEC sp_bindefault N'[dbo].[df_Active]', N'[Slu_AC_Statement_Messages].[Slu_AW_Active_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[Slu_AC_Statement_Messages].[User_ID]'
GO

setuser
GO

-----------------------------------------

INSERT Slu_AC_Statement_Messages
    (
        Description
    )
VALUES
    (
        '<None>'
    )


-------------------------------------------------------------------------------
-- TABLE MODS
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- DELETE REDUNDANT TABLES
-------------------------------------------------------------------------------


----------------------------------------------------
--> NEW INDEXES
----------------------------------------------------




-------------------------------------------------------------------------------