-----------------------------------------------------------------------------
-- ADVANTAGE 2004.5.1.2
-- DB OBJECT CHANGES
-- 11/06/2011
------------------------------------------------------------------------------



-------------------------------------------------------------------------------
-- INSERT DEFAULT VALUES for NEWLY CREATED COLUMN in 0.sql !!! Cannot do it there !!!
-------------------------------------------------------------------------------


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



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

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

CREATE TABLE [dbo].[AF_Job_Tickets] (
	[AF_Job_Tickets_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Post] [bit] NULL ,
	[Job_No] [int] NULL ,
	[Job_Date] [datetime] NULL ,
	[AC_Customers_ID] [int] NULL ,
	[Order_No] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[AP_Products_ID] [int] NULL ,
	[Lup_AP_Product_Manufacturers_ID] [int] NULL ,
	[Serial_No] [varchar] (13) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Lup_AF_Instructions_ID] [smallint] NULL ,
	[Job_User_ID] [int] NULL ,
	[AF_Waybills_ID] [int] NULL ,
	[AO_Suppliers_ID] [int] NULL ,
	[Waybill_Date] [datetime] NULL ,
	[Waybill_User_ID] [int] NULL ,
	[AO_GRV_ID] [int] NULL ,
	[GRV_Date] [datetime] NULL ,
	[Invoice_No] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Retread_Cost] [money] NULL ,
	[Repair_Cost] [money] NULL ,
	[Other_Cost] [money] NULL ,
	[AP_Repair_Products_ID] [int] NULL ,
	[AP_Other_Products_ID] [int] NULL ,
	[GRV_User_ID] [int] NULL ,
	[AS_Transactions_ID] [int] NULL ,
	[Billing_Date] [datetime] NULL ,
	[Billing_No] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Retread_Price] [money] NULL ,
	[Repair_Price] [money] NULL ,
	[Other_Price] [money] NULL ,
	[Amount] [money] NULL ,
	[Tax] [money] NULL ,
	[Total] [money] NULL ,
	[Comment] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Billing_User_ID] [int] NULL ,
	[AP_Inventory_Adjustments_ID] [int] NULL ,
	[Adjustment_Date] [datetime] NULL ,
	[AP_Stock_Products_ID] [int] NULL ,
	[Casing_Credit] [money] NULL ,
	[Stock_Cost] [money] NULL ,
	[Adjustment_User_ID] [int] NULL ,
	[Date_Captured] [datetime] NULL ,
	[AW_User_Companies_ID] [int] NOT NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[AF_Job_Tickets] WITH NOCHECK ADD 
	CONSTRAINT [PK_AF_Job_Tickets] PRIMARY KEY  CLUSTERED 
	(
		[AF_Job_Tickets_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

 CREATE  INDEX [IX_AF_Job_Tickets_Factory_ID] ON [dbo].[AF_Job_Tickets]([AO_Suppliers_ID]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_AF_Job_Tickets_Job_No] ON [dbo].[AF_Job_Tickets]([Job_No]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_AF_Job_Tickets_Customer_ID] ON [dbo].[AF_Job_Tickets]([AC_Customers_ID]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_AF_Job_Tickets_Waybill_No] ON [dbo].[AF_Job_Tickets]([AF_Waybills_ID]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_AF_Job_Tickets_Invoice_No] ON [dbo].[AF_Job_Tickets]([Invoice_No]) ON [PRIMARY]
GO

 CREATE  INDEX [IX_AF_Job_Tickets_Billing_No] ON [dbo].[AF_Job_Tickets]([Billing_No]) ON [PRIMARY]
GO

setuser
GO

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

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

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AF_Job_Tickets].[Post]'
GO

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

setuser
GO

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

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

CREATE TABLE [dbo].[AF_Waybills] (
	[AF_Waybills_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[AO_Suppliers_ID] [int] NULL ,
	[Waybill_Date] [datetime] 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].[AF_Waybills] WITH NOCHECK ADD 
	CONSTRAINT [PK_AF_Waybills] PRIMARY KEY  CLUSTERED 
	(
		[AF_Waybills_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

setuser
GO

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

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

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

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

setuser
GO

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

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

CREATE TABLE [dbo].[Lup_AF_Instructions] (
	[Lup_AF_Instructions_ID] [smallint] IDENTITY (1, 1) NOT NULL ,
	[Description] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[AW_User_Companies_ID] [int] NOT NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Lup_AF_Instructions] WITH NOCHECK ADD 
	CONSTRAINT [PK_Lup_AF_Instructions] PRIMARY KEY  CLUSTERED 
	(
		[Lup_AF_Instructions_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

setuser
GO

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

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

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

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

setuser
GO

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

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Sys_AF_App_Startup_Sys_AF_Applications]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Sys_AF_App_Startup] DROP CONSTRAINT FK_Sys_AF_App_Startup_Sys_AF_Applications
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Sys_AF_Applications_Sys_AF_Modules]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Sys_AF_Applications] DROP CONSTRAINT FK_Sys_AF_Applications_Sys_AF_Modules
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Sys_AF_Reports_Sys_AF_Modules]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Sys_AF_Reports] DROP CONSTRAINT FK_Sys_AF_Reports_Sys_AF_Modules
GO

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

CREATE TABLE [dbo].[Sys_AF_Modules] (
	[Sys_AF_Modules_ID] [tinyint] IDENTITY (1, 1) NOT NULL ,
	[Description] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Module_Seq] [smallint] NOT NULL ,
	[Start_Date] [datetime] NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Sys_AF_Modules] WITH NOCHECK ADD 
	CONSTRAINT [PK_Sys_AF_Modules] PRIMARY KEY  CLUSTERED 
	(
		[Sys_AF_Modules_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

setuser
GO

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

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

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

setuser
GO

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

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

CREATE TABLE [dbo].[Sys_AF_Applications] (
	[Sys_AF_Applications_ID] [smallint] IDENTITY (1, 1) NOT NULL ,
	[Description] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Sys_AF_Modules_ID] [tinyint] NULL ,
	[Application_Seq] [smallint] NOT NULL ,
	[Form_Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [int] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Sys_AF_Applications] WITH NOCHECK ADD 
	CONSTRAINT [PK_Sys_AF_Applications] PRIMARY KEY  CLUSTERED 
	(
		[Sys_AF_Applications_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

 CREATE  INDEX [IX_Sys_AF_Applications_Key] ON [dbo].[Sys_AF_Applications]([Sys_AF_Modules_ID], [Application_Seq], [Description], [Form_Name]) WITH  FILLFACTOR = 90 ON [PRIMARY]
GO

setuser
GO

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

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

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

setuser
GO

ALTER TABLE [dbo].[Sys_AF_Applications] ADD 
	CONSTRAINT [FK_Sys_AF_Applications_Sys_AF_Modules] FOREIGN KEY 
	(
		[Sys_AF_Modules_ID]
	) REFERENCES [dbo].[Sys_AF_Modules] (
		[Sys_AF_Modules_ID]
	)
GO

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

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

CREATE TABLE [dbo].[Sys_AF_Reports] (
	[Sys_AF_Reports_ID] [smallint] IDENTITY (1, 1) NOT NULL ,
	[Sys_AF_Modules_ID] [tinyint] NOT NULL ,
	[Type_ID] [tinyint] NOT NULL ,
	[Location] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Report_No] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Report_Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Description] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Object_DLL] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Class_Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Method_Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[Date_Captured] [datetime] NULL ,
	[User_ID] [int] NULL ,
	[Touched] [timestamp] NULL ,
	[Slu_AW_Active_ID] [int] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Sys_AF_Reports] WITH NOCHECK ADD 
	CONSTRAINT [PK_Sys_AF_Reports] PRIMARY KEY  CLUSTERED 
	(
		[Sys_AF_Reports_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[Sys_AF_Reports].[Class_Name]'
GO

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

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[Sys_AF_Reports].[Description]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[Sys_AF_Reports].[Location]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[Sys_AF_Reports].[Method_Name]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[Sys_AF_Reports].[Object_DLL]'
GO

EXEC sp_bindefault N'[dbo].[df_Nullstring]', N'[Sys_AF_Reports].[Report_Name]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[Sys_AF_Reports].[Report_No]'
GO

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

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[Sys_AF_Reports].[Sys_AF_Modules_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[Sys_AF_Reports].[Type_ID]'
GO

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

setuser
GO

ALTER TABLE [dbo].[Sys_AF_Reports] ADD 
	CONSTRAINT [FK_Sys_AF_Reports_Sys_AF_Modules] FOREIGN KEY 
	(
		[Sys_AF_Modules_ID]
	) REFERENCES [dbo].[Sys_AF_Modules] (
		[Sys_AF_Modules_ID]
	)
GO

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

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

CREATE TABLE [dbo].[Sys_AF_App_Startup] (
	[Sys_AF_App_Startup_ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Sys_AF_Applications_ID] [smallint] NULL ,
	[AW_Users_ID] [int] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Sys_AF_App_Startup] WITH NOCHECK ADD 
	CONSTRAINT [PK_Sys_AF_App_Startup] PRIMARY KEY  CLUSTERED 
	(
		[Sys_AF_App_Startup_ID]
	) WITH  FILLFACTOR = 90  ON [PRIMARY] 
GO

 CREATE  INDEX [IX_Sys_AF_Startup_Application] ON [dbo].[Sys_AF_App_Startup]([AW_Users_ID], [Sys_AF_Applications_ID]) ON [PRIMARY]
GO

setuser
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_One]', N'[Sys_AF_App_Startup].[Sys_AF_Applications_ID]'
GO

EXEC sp_bindefault N'[dbo].[df_User_ID]', N'[Sys_AF_App_Startup].[AW_Users_ID]'
GO

setuser
GO

ALTER TABLE [dbo].[Sys_AF_App_Startup] ADD 
	CONSTRAINT [FK_Sys_AF_App_Startup_Sys_AF_Applications] FOREIGN KEY 
	(
		[Sys_AF_Applications_ID]
	) REFERENCES [dbo].[Sys_AF_Applications] (
		[Sys_AF_Applications_ID]
	)
GO

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



-------------------------------------------------------
-- POPULATE DATA
-------------------------------------------------------
INSERT Lup_AF_Instructions (Description) VALUES ('<None>')
INSERT Lup_AF_Instructions (Description) VALUES ('Tyre on rim')
INSERT Lup_AF_Instructions (Description) VALUES ('Fit own tyre to rim')
INSERT Lup_AF_Instructions (Description) VALUES ('Return loose rim')
INSERT Lup_AF_Instructions (Description) VALUES ('Return loose tube')
INSERT Lup_AF_Instructions (Description) VALUES ('Return loose flap')
INSERT Lup_AF_Instructions (Description) VALUES ('Return old tyre')
-------------------------------------------
-------------------------------------------
INSERT Sys_AF_Modules (Description, Module_Seq) VALUES ('Casing Tracking', 1)
-------------------------------------------
-------------------------------------------
INSERT Sys_AF_Applications (Description, Sys_AF_Modules_ID, Application_Seq, Form_Name) VALUES ('Job Tickets', 1, 1, 'frmJobTickets')
INSERT Sys_AF_Applications (Description, Sys_AF_Modules_ID, Application_Seq, Form_Name) VALUES ('Factory Waybills', 1, 2, 'frmFactoryWaybills')
INSERT Sys_AF_Applications (Description, Sys_AF_Modules_ID, Application_Seq, Form_Name) VALUES ('Factory Receipts', 1, 3, 'frmFactoryReceipts')
INSERT Sys_AF_Applications (Description, Sys_AF_Modules_ID, Application_Seq, Form_Name) VALUES ('Customer Billing', 1, 4, 'frmCustomerBilling')
INSERT Sys_AF_Applications (Description, Sys_AF_Modules_ID, Application_Seq, Form_Name) VALUES ('Casing for Credit', 1, 5, 'frmCasingCredit')
INSERT Sys_AF_Applications (Description, Sys_AF_Modules_ID, Application_Seq, Form_Name) VALUES ('Reports Library', 1, 99, 'frmReportsLibrary')
-------------------------------------------
-------------------------------------------

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Transaction_Types_ID
            FROM Sys_AW_Transaction_Types
            WHERE Sys_AW_Transaction_Types_ID = 24 AND
                  Description = 'Stock Transfer In'
        ) 
        BEGIN
            INSERT Sys_AW_Transaction_Types
                (
                    Description,
                    Type_Code,
                    POS_Used,
                    Cash_Up,
                    Factor
                )
            VALUES
                (
                    'Stock Transfer In',
                    'PJTRF',
                    0,
                    0,
                    1
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Transaction_Types_ID
            FROM Sys_AW_Transaction_Types
            WHERE Sys_AW_Transaction_Types_ID = 25 AND
                  Description = 'Job Received'
        ) 
        BEGIN
            INSERT Sys_AW_Transaction_Types
                (
                    Description,
                    Type_Code,
                    POS_Used,
                    Cash_Up,
                    Factor
                )
            VALUES
                (
                    'Job Received',
                    'PJJRV',
                    0,
                    0,
                    1
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Transaction_Types_ID
            FROM Sys_AW_Transaction_Types
            WHERE Sys_AW_Transaction_Types_ID = 26 AND
                  Description = 'Job Returned'
        ) 
        BEGIN
            INSERT Sys_AW_Transaction_Types
                (
                    Description,
                    Type_Code,
                    POS_Used,
                    Cash_Up,
                    Factor
                )
            VALUES
                (
                    'Job Returned',
                    'PJJRT',
                    0,
                    0,
                    1
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Transaction_Types_ID
            FROM Sys_AW_Transaction_Types
            WHERE Sys_AW_Transaction_Types_ID = 27 AND
                  Description = 'Waybill'
        ) 
        BEGIN
            INSERT Sys_AW_Transaction_Types
                (
                    Description,
                    Type_Code,
                    POS_Used,
                    Cash_Up,
                    Factor
                )
            VALUES
                (
                    'Waybill',
                    'SJWBL',
                    0,
                    0,
                    1
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Transaction_Types_ID
            FROM Sys_AW_Transaction_Types
            WHERE Sys_AW_Transaction_Types_ID = 28 AND
                  Description = 'Waybill In'
        ) 
        BEGIN
            INSERT Sys_AW_Transaction_Types
                (
                    Description,
                    Type_Code,
                    POS_Used,
                    Cash_Up,
                    Factor
                )
            VALUES
                (
                    'Waybill In',
                    'PJWBL',
                    0,
                    0,
                    1
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Transaction_Types_ID
            FROM Sys_AW_Transaction_Types
            WHERE Sys_AW_Transaction_Types_ID = 29 AND
                  Description = 'Factory Received'
        ) 
        BEGIN
            INSERT Sys_AW_Transaction_Types
                (
                    Description,
                    Type_Code,
                    POS_Used,
                    Cash_Up,
                    Factor
                )
            VALUES
                (
                    'Factory Received',
                    'PJFGR',
                    0,
                    0,
                    1
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Transaction_Types_ID
            FROM Sys_AW_Transaction_Types
            WHERE Sys_AW_Transaction_Types_ID = 30 AND
                  Description = 'Factory Returned'
        ) 
        BEGIN
            INSERT Sys_AW_Transaction_Types
                (
                    Description,
                    Type_Code,
                    POS_Used,
                    Cash_Up,
                    Factor
                )
            VALUES
                (
                    'Factory Returned',
                    'SJFRT',
                    0,
                    0,
                    1
                )
        END

-------------------------------------------------------------------------------
-- NEW REPORTS
-------------------------------------------------------------------------------


    IF NOT EXISTS
        (
            SELECT Sys_AF_Reports_ID
            FROM Sys_AF_Reports
            WHERE Report_No = '001' AND
                  Method_Name = 'Show_CasingStock'
        ) 
        BEGIN
            INSERT Sys_AF_Reports
                (
                    Sys_AF_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    1,
                    0,
                    'Factory Reports',
                    '001',
                    'Casing Stock without Waybill',
                    'Casing Stock without Waybill',
                    'SpSFactoryReports',
                    'CInterface',
                    'Show_CasingStock'
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AF_Reports_ID
            FROM Sys_AF_Reports
            WHERE Report_No = '002' AND
                  Method_Name = 'Show_OutstandingJobs'
        ) 
        BEGIN
            INSERT Sys_AF_Reports
                (
                    Sys_AF_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    1,
                    0,
                    'Factory Reports',
                    '002',
                    'Outstanding Jobs at Factory',
                    'Outstanding Jobs at Factory',
                    'SpSFactoryReports',
                    'CInterface',
                    'Show_OutstandingJobs'
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AF_Reports_ID
            FROM Sys_AF_Reports
            WHERE Report_No = '003' AND
                  Method_Name = 'Show_UninvoicedJobs'
        ) 
        BEGIN
            INSERT Sys_AF_Reports
                (
                    Sys_AF_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    1,
                    0,
                    'Factory Reports',
                    '003',
                    'Uninvoiced Jobs',
                    'Uninvoiced Jobs',
                    'SpSFactoryReports',
                    'CInterface',
                    'Show_UninvoicedJobs'
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AF_Reports_ID
            FROM Sys_AF_Reports
            WHERE Report_No = '004' AND
                  Method_Name = 'Show_CasingVsStock'
        ) 
        BEGIN
            INSERT Sys_AF_Reports
                (
                    Sys_AF_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    1,
                    0,
                    'Factory Reports',
                    '004',
                    'Casing vs Stock Product',
                    'Casing vs Stock Product',
                    'SpSFactoryReports',
                    'CInterface',
                    'Show_CasingVsStock'
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AF_Reports_ID
            FROM Sys_AF_Reports
            WHERE Report_No = '005' AND
                  Method_Name = 'Show_UnusedTickets'
        ) 
        BEGIN
            INSERT Sys_AF_Reports
                (
                    Sys_AF_Modules_ID,
                    Type_ID,
                    Location,
                    Report_No,
                    Report_Name,
                    Description,
                    Object_DLL,
                    Class_Name,
                    Method_Name
                )
            VALUES
                (
                    1,
                    0,
                    'Factory Reports',
                    '005',
                    'Unused Job Ticket Numbers',
                    'Unused Job Ticket Numbers',
                    'SpSFactoryReports',
                    'CInterface',
                    'Show_UnusedTickets'
                )
        END

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

-------------------------------------------------------------------------------
-- RETIRED REPORTS
-------------------------------------------------------------------------------


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


-------------------------------------------------------------------------------
--> DATA MODS
-------------------------------------------------------------------------------

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AO_Suppliers].[Use_Other_Discount_Control_Acc]'
GO

EXEC sp_bindefault N'[dbo].[df_Numeric_Zero]', N'[AO_Suppliers].[Use_Rebate_Discount_Control_Acc]'
GO

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



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





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



