
/*------ ATD 489868 ------*/
-- Adicionando coluna FULFILLMENT na tabela PEDICLICOMPLEMENTO
IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS WHERE name = 'FULFILLMENT' and syscolumns.id IN (SELECT ID FROM SYSOBJECTS WHERE xtype='U' AND name='PEDICLICOMPLEMENTO')) 
ALTER TABLE PEDICLICOMPLEMENTO ADD FULFILLMENT Tinyint
go

-- Adicionando coluna MARKETPLACE na tabela MU_CONFIGURACAO_IMPORTANFVENDA
IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS WHERE name = 'MARKETPLACE' and syscolumns.id IN (SELECT ID FROM SYSOBJECTS WHERE xtype='U' AND name='MU_CONFIGURACAO_IMPORTANFVENDA')) 
ALTER TABLE MU_CONFIGURACAO_IMPORTANFVENDA ADD MARKETPLACE VARCHAR(100)
go

-- Adicionando coluna PASTAIMPORTACAO na tabela MU_CONFIGURACAO_IMPORTANFVENDA
IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS WHERE name = 'PASTAIMPORTACAO' and syscolumns.id IN (SELECT ID FROM SYSOBJECTS WHERE xtype='U' AND name='MU_CONFIGURACAO_IMPORTANFVENDA')) 
ALTER TABLE MU_CONFIGURACAO_IMPORTANFVENDA ADD PASTAIMPORTACAO VARCHAR(254)
go

-- Adicionando coluna DEPOSITO na tabela MU_CONFIGURACAO_IMPORTANFVENDA
IF NOT EXISTS (SELECT 1 FROM SYSCOLUMNS WHERE name = 'DEPOSITO' and syscolumns.id IN (SELECT ID FROM SYSOBJECTS WHERE xtype='U' AND name='MU_CONFIGURACAO_IMPORTANFVENDA')) 
ALTER TABLE MU_CONFIGURACAO_IMPORTANFVENDA ADD DEPOSITO CHAR(2)
go

-- Adicionando coluna INATIVO na tabela MU_CONFIGURACAO_IMPORTANFVENDA
IF NOT EXISTS (SELECT 1 FROM sys.columns WHERE object_id = OBJECT_ID('MU_CONFIGURACAO_IMPORTANFVENDA') AND name = 'INATIVO')
BEGIN
    ALTER TABLE MU_CONFIGURACAO_IMPORTANFVENDA
        ADD INATIVO TINYINT;

    EXEC('
        UPDATE MU_CONFIGURACAO_IMPORTANFVENDA
        SET INATIVO = 1;

        UPDATE MU_CONFIGURACAO_IMPORTANFVENDA
        SET INATIVO = 0
        WHERE ID = (
            SELECT MAX(ID)
            FROM MU_CONFIGURACAO_IMPORTANFVENDA
        );
    ');
END;

-- Adicionando coluna ID_CONFIGURACAO na tabela MU_IMPORTANFVENDA
IF NOT EXISTS (SELECT 1 FROM sys.columns WHERE object_id = OBJECT_ID('MU_IMPORTANFVENDA') AND name = 'ID_CONFIGURACAO')
BEGIN
    ALTER TABLE MU_IMPORTANFVENDA
        ADD ID_CONFIGURACAO INT;

    EXEC('UPDATE MU_IMPORTANFVENDA
          SET ID_CONFIGURACAO  = (SELECT ID FROM MU_CONFIGURACAO_IMPORTANFVENDA WHERE INATIVO=0);'
        );
END;

