
------------------------------------------------------------------------------
-- ADVANTAGE 2004.3.7
-- OPTIONS and APPLICATION SINCE ADVANTAGE 2004.3.6
-- 30 NOV 2007
------------------------------------------------------------------------------


--************************************************
--******     NB. NB. NB. RUN ONLY ONCE     *******
--************************************************


-- USE ADV2004
-- GO



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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


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

DECLARE @AppID int 


IF NOT EXISTS
    (
        SELECT Sys_AW_Applications_ID
        FROM Sys_AW_Applications
        WHERE Description = 'Customer Cost+Plus Billing' AND
              Form_Name = 'frmCustomerCostPlus'
    )
    BEGIN
        INSERT Sys_AW_Applications
            (
                Description,
                Sys_AW_Modules_ID,
                Application_Seq,
                Form_Name,
                Date_Captured,
                User_ID,
                Slu_AW_Active_ID
            )
        VALUES
            (
                'Customer Cost+Plus Billing',
                3,
                17,
                'frmCustomerCostPlus',
                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 = 'Customer Cost+Plus Filters' AND
              Form_Name = 'frmCustomerCostPlusFilters'
    )
    BEGIN
        INSERT Sys_AW_Applications
            (
                Description,
                Sys_AW_Modules_ID,
                Application_Seq,
                Form_Name,
                Date_Captured,
                User_ID,
                Slu_AW_Active_ID
            )
        VALUES
            (
                'Customer Cost+Plus Filters',
                3,
                18,
                'frmCustomerCostPlusFilters',
                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 = 'GL Account Filters' AND
              Form_Name = 'frmGLFilters'
    )
    BEGIN
        INSERT Sys_AW_Applications
            (
                Description,
                Sys_AW_Modules_ID,
                Application_Seq,
                Form_Name,
                Date_Captured,
                User_ID,
                Slu_AW_Active_ID
            )
        VALUES
            (
                'GL Account Filters',
                5,
                10,
                'frmGLFilters',
                getdate(),
                1,
                1
            )

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

    END

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

UPDATE Sys_AW_Applications
SET Application_Seq = 9
WHERE Description = 'GL Transaction Editor' AND
      Form_Name = 'frmGLTranEditor'

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

UPDATE Sys_AW_Applications
SET Description = 'Month-End Procedures'
WHERE Description = 'Period Procedures' AND
      Form_Name = 'frmPeriodProcedures'


----------------------------------------------------------------------------
-- Disable Products.Purchase Discounts - Now using Standard_Cost as Unit Price
----------------------------------------------------------------------------
UPDATE Sys_AW_Applications
SET Slu_AW_Active_ID = 2
WHERE Description = 'Purchase Discounts' AND
      Form_Name = 'frmPurchaseDiscounts'

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'Lup_AC_Markup_Categories' AND
              Caption = 'Cost+Plus Categories'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
        VALUES
            (
                68,
                'Lup_AC_Markup_Categories',
                'Cost+Plus Categories',
                '0,7275,0,0,0,1005'
            )
    END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'Lup_AP_Markup_Groups' AND
              Caption = 'Cost+Plus Groups'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
        VALUES
            (
                69,
                'Lup_AP_Markup_Groups',
                'Cost+Plus Groups',
                '0,7275,0,0,0,1005'
            )
    END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'Lup_AB_Account_Groups' AND
              Caption = 'GL Account Groups'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
        VALUES
            (
                70,
                'Lup_AB_Account_Groups',
                'GL Account Groups',
                '0,7275,0,0,0,1005'
            )
    END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'Lup_AB_Account_Divisions' AND
              Caption = 'GL Account Divisions'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
        VALUES
            (
                71,
                'Lup_AB_Account_Divisions',
                'GL Account Divisions',
                '0,7275,0,0,0,1005'
            )
    END
----------------------------------------------------------------------------