USE [CabalCash]
GO
/****** Object:  StoredProcedure [dbo].[cabal_send_starter_kit]    Script Date: 08/06/2025 00:24:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- NOVO PARÂMETRO: @ID
ALTER PROCEDURE [dbo].[cabal_send_starter_kit]
    @usernum INT,
    @kit INT,
    @ID VARCHAR(50) -- <--- NOVO PARÂMETRO. Ajuste o tamanho do VARCHAR para corresponder à sua coluna de login (por exemplo, VARCHAR(16) ou VARCHAR(20))
AS
BEGIN
    SET NOCOUNT ON;

    -- A correção precisa ser aplicada em CADA bloco 'IF NOT EXISTS'
    -- onde você insere na WebiNext.dbo.cabal_Kit_iniciante.

    -- --- KIT = 1 ---
    IF (@kit = 1)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0); -- <--- ID agora é fornecido
        END

        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado1 = 1, Kit = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122993, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123038, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123083, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123128, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122979, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415, 808131515, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310, 0, 12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195, 0, 12;
    END

    -- --- KIT = 2 ---
    ELSE IF (@kit = 2)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado2 = 1, Kit2 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122994, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123039, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123084, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123129, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122919, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415, 808131515, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310, 0, 12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195, 0, 12;
    END

    -- --- KIT = 3 ---
    ELSE IF (@kit = 3)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado3 = 1, Kit3 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123008, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123053, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123098, 536877279, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123143, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122904, 536871124, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814, 0, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415, 808131515, 17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310, 0, 12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195, 0, 12;
    END

    -- --- KIT = 4 ---
    ELSE IF (@kit = 4)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado4 = 1, Kit4 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123009,536877535,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123054,536877535,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123099,536877535,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123144,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122904,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122904,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 793,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 793,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415,808131515,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310,0,12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195,0,12;
    END

    -- --- KIT = 5 ---
    ELSE IF (@kit = 5)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado5 = 1, Kit5 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123024,536877535,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123069,536877535,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123114,536877535,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123159,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122904,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122904,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 793,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 793,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415,808131515,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310,0,12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195,0,12;
    END

    -- --- KIT = 6 ---
    ELSE IF (@kit = 6)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado6 = 1, Kit6 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123023,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123068,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123113,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123158,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415,808131515,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310,0,12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195,0,12;
    END

    -- --- KIT = 7 ---
    ELSE IF (@kit = 7)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        -- Lembre-se de verificar se 'Enviado7' e 'Kit7' estão corretos aqui.
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado7 = 1, Kit7 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123023,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123068,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123113,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123158,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415,808131515,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310,0,12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195,0,12;
    END

    -- --- KIT = 8 ---
    ELSE IF (@kit = 8)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        -- Lembre-se de verificar se 'Enviado8' e 'Kit8' estão corretos aqui.
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado8 = 1, Kit8 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123023,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123068,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123113,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123158,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415,808131515,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310,0,12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195,0,12;
    END

    -- --- KIT = 9 ---
    ELSE IF (@kit = 9)
    BEGIN
        IF NOT EXISTS (SELECT 1 FROM WebiNext.dbo.cabal_Kit_iniciante WHERE UserNum = @usernum)
        BEGIN
            -- INSERT CORRIGIDO: Agora inclui ID (login)
            INSERT INTO WebiNext.dbo.cabal_Kit_iniciante (ID, UserNum, Enviado)
            VALUES (@ID, @usernum, 0);
        END
        -- Lembre-se de verificar se 'Enviado9' e 'Kit9' estão corretos aqui.
        UPDATE WebiNext.dbo.cabal_Kit_iniciante SET Enviado = Enviado + 1, Enviado9 = 1, Kit9 = @kit, DataCriacao = GETDATE() WHERE UserNum = @usernum;
        -- ... (suas chamadas exec up_AddMyCashItemByItem) ...
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123023,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123068,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123113,536877279,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 123158,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 122949,536871124,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4512,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4502,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4410,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 4407,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 788,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 814,0,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 127415,808131515,17;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2310,0,12;
        exec up_AddMyCashItemByItem @usernum, 1, 1, 2195,0,12;
    END

    -- Inserção final na cabal_Kit_Log (parece ser um log geral)
    INSERT INTO Server01.dbo.cabal_Kit_Log (UserNum, Kit, DataEnvio)
    VALUES (@usernum, @kit, GETDATE());

END