------------------------------------------------------------------------------
-- ADVANTAGE 2004.4.5
-- OPTIONS and APPLICATION SINCE ADVANTAGE 2004.4.4
-- 04/08/2009
------------------------------------------------------------------------------


----------------------------------------------------------------
-- New System Options
----------------------------------------------------------------

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'CheckBox' AND
                  Control_Name = 'chkSendConnectivitySales' AND
                  Control_Index = 0
        )
        BEGIN
            INSERT Sys_AW_Options
                (
                    Control_Type,
                    Control_Name,
                    Control_Index,
                    Control_Value
                )
            VALUES
                (
                    'CheckBox',
                    'chkSendConnectivitySales',
                    0,
                    '0'
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'CheckBox' AND
                  Control_Name = 'chkPreventSwitchCustomer' AND
                  Control_Index = 0
        )
        BEGIN
            INSERT Sys_AW_Options
                (
                    Control_Type,
                    Control_Name,
                    Control_Index,
                    Control_Value
                )
            VALUES
                (
                    'CheckBox',
                    'chkPreventSwitchCustomer',
                    0,
                    '0'
                )
        END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Options_ID
        FROM Sys_AW_Options
        WHERE Control_Type = 'TextBox' AND
              Control_Name = 'txtTargetStockTurnover' AND
              Control_Index = 0
    )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'TextBox',
                'txtTargetStockTurnover',
                0,
                '2.0'
            )
    END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Options_ID
        FROM Sys_AW_Options
        WHERE Control_Type = 'TextBox' AND
              Control_Name = 'txtTargetStockDaysSales' AND
              Control_Index = 0
    )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'TextBox',
                'txtTargetStockDaysSales',
                0,
                '14.0'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'CheckBox' AND
                  Control_Name = 'chkPOSPrintSortOrder' AND
                  Control_Index = 0
        )
        BEGIN
            INSERT Sys_AW_Options
                (
                    Control_Type,
                    Control_Name,
                    Control_Index,
                    Control_Value
                )
            VALUES
                (
                    'CheckBox',
                    'chkPOSPrintSortOrder',
                    0,
                    '0'
                )
        END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 0
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                0,
                'False'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 1
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                1,
                'True'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 2
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                2,
                'False'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 3
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                3,
                'False'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 4
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                4,
                'False'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 5
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                5,
                'False'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 6
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                6,
                'False'
            )
    END

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

    IF NOT EXISTS
        (
            SELECT Sys_AW_Options_ID
            FROM Sys_AW_Options
            WHERE Control_Type = 'OptionButton' AND
                  Control_Name = 'optPOSSortOrderFilter' AND
                  Control_Index = 7
        )
    BEGIN
        INSERT Sys_AW_Options
            (
                Control_Type,
                Control_Name,
                Control_Index,
                Control_Value
            )
        VALUES
            (
                'OptionButton',
                'optPOSSortOrderFilter',
                7,
                'False'
            )
    END

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


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

----------------------------------------------------------------
-- Retired System Options
----------------------------------------------------------------


----------------------------------------------------------------
-- New Applications
----------------------------------------------------------------


DECLARE @AppID int 


IF NOT EXISTS
    (
        SELECT Sys_AW_Applications_ID
        FROM Sys_AW_Applications
        WHERE Description = 'Enterprise Supplier Reports' AND
              Form_Name = 'frmSupplierEnterpriseReports'
    )
    BEGIN
        INSERT Sys_AW_Applications
            (
                Description,
                Sys_AW_Modules_ID,
                Application_Seq,
                Form_Name,
                Date_Captured,
                User_ID,
                Slu_AW_Active_ID
            )
        VALUES
            (
                'Enterprise Supplier Reports',
                4,
                97,
                'frmSupplierEnterpriseReports',
                getdate(),
                1,
                1
            )

        SELECT @AppID = Scope_Identity()
        
        EXEC sp_AW_Insert_Apps_Per_Role 2, @AppID, 1, 1

    END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Applications_ID
        FROM Sys_AW_Applications
        WHERE Description = 'Enterprise Financial Reports' AND
              Form_Name = 'frmFinancialEnterpriseReports'
    )
    BEGIN
        INSERT Sys_AW_Applications
            (
                Description,
                Sys_AW_Modules_ID,
                Application_Seq,
                Form_Name,
                Date_Captured,
                User_ID,
                Slu_AW_Active_ID
            )
        VALUES
            (
                'Enterprise Financial Reports',
                5,
                97,
                'frmFinancialEnterpriseReports',
                getdate(),
                1,
                1
            )

        SELECT @AppID = Scope_Identity()
        
        EXEC sp_AW_Insert_Apps_Per_Role 2, @AppID, 1, 1

    END

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

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


----------------------------------------------------------------------------
-- Retired Applications
----------------------------------------------------------------------------



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

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

----------------------------------------------------------------------------
-- Lookup Editor
----------------------------------------------------------------------------

----------------------------------------------------------------
-- New Lookups
----------------------------------------------------------------

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'AW_Messages' AND
              Caption = 'Credit Manager Messages'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
            VALUES
            (
                81,
                'AW_Messages',
                'Credit Manager Messages',
                '620,10000'
            )
    END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'Lup_AS_Procurement_Providers' AND
              Caption = 'Procurement Providers'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
            VALUES
            (
                82,
                'Lup_AS_Procurement_Providers',
                'Procurement Providers',
                '0,3755,2500,1500,1500,2500,1005'
            )
    END


----------------------------------------------------------------
-- Modify Lookups
----------------------------------------------------------------

UPDATE Sys_AW_Lookup_Editor
SET ColumnWidths ='0,6460,6460,1005'
WHERE TableName = 'Slu_AW_Inflections' AND
      Caption = 'Inflections'

UPDATE Sys_AW_Lookup_Editor
SET ColumnWidths ='0,6460,6460,1005'
WHERE TableName = 'Slu_AW_SMS_Messages' AND
      Caption = 'SMS Messages'

UPDATE Sys_AW_Lookup_Editor
SET ColumnWidths ='0,6460,6460,995'
WHERE TableName = 'Sys_AW_Tax_Codes' AND
      Caption = 'V.A.T. Code Rates'

UPDATE Sys_AW_Lookup_Editor
SET ColumnWidths ='0,3755,2500,1500,1500,2500,1005'
WHERE TableName = 'Lup_AS_Procurement_Providers' AND
      Caption = 'Procurement Providers'

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