------------------------------------------------------------------------------
-- ADVANTAGE 2004.4.9.1
-- OPTIONS and APPLICATION
-- 08/10/2010
------------------------------------------------------------------------------


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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




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


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

UPDATE Sys_AW_Applications
SET Slu_AW_Active_ID = 2
WHERE Description = 'Loyalty and VMI' AND
      Form_Name = 'frmLoyaltyVMI'

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

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

DECLARE @AppID int 


IF NOT EXISTS
    (
        SELECT Sys_AW_Applications_ID
        FROM Sys_AW_Applications
        WHERE Description = 'Bonded Stock' AND
              Form_Name = 'frmStockBonded'
    )
    BEGIN
        INSERT Sys_AW_Applications
            (
                Description,
                Sys_AW_Modules_ID,
                Application_Seq,
                Form_Name,
                Date_Captured,
                User_ID,
                Slu_AW_Active_ID
            )
        VALUES
            (
                'Bonded Stock',
                2,
                19,
                'frmStockBonded',
                getdate(),
                1,
                1
            )

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

    END
ELSE
    BEGIN
        UPDATE Sys_AW_Applications
        SET Slu_AW_Active_ID = 1,
            Application_Seq = 19
        WHERE Description = 'Bonded Stock' AND
              Form_Name = 'frmStockBonded'
    END



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

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'Lup_AP_Shipping_Agents' AND
              Caption = 'Shipping Agents'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
            VALUES
            (
                84,
                'Lup_AP_Shipping_Agents',
                'Shipping Agents',
                '0,3265,2005,2005,1005'
            )
    END

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

IF NOT EXISTS
    (
        SELECT Sys_AW_Lookup_Editor_ID
        FROM Sys_AW_Lookup_Editor
        WHERE TableName = 'Lup_AP_Shipping_Agent_Files' AND
              Caption = 'Shipping Agent Files'
    )
    BEGIN
        INSERT Sys_AW_Lookup_Editor
            (
                Sys_AW_Lookup_Editor_ID,
                TableName,
                Caption,
                ColumnWidths
            )
            VALUES
            (
                85,
                'Lup_AP_Shipping_Agent_Files',
                'Shipping Agent Files',
                '0,2255,1500,2000,1500,1500,1500,1005'
            )
    END

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

UPDATE Sys_AW_Lookup_Editor
SET ColumnWidths = '0,3265,2005,2005,1005'
WHERE TableName = 'Lup_AP_Shipping_Agents' AND
      Caption = 'Shipping Agents'


UPDATE Sys_AW_Lookup_Editor
SET ColumnWidths = '0,2255,1500,2000,1500,1500,1500,1005'
WHERE TableName = 'Lup_AP_Shipping_Agent_Files' AND
      Caption = 'Shipping Agent Files'

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


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