SET TERM ^ ;

CREATE OR ALTER trigger ttbpdv_produtos_biud998 for tbpdv_produtos
active before insert or update or delete position 998
AS
BEGIN

    IF(INSERTING) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_PRODUTOS', NEW.ID, 2);
    END ELSE
    IF(DELETING) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_PRODUTOS', OLD.ID, 2);
    END
    IF(UPDATING) THEN
    BEGIN
        IF      ( OLD.ESTABELECIMENTO_ID            IS DISTINCT FROM NEW.ESTABELECIMENTO_ID
             OR   OLD.LOCALIZACAO_ID                IS DISTINCT FROM NEW.LOCALIZACAO_ID
             OR   OLD.FAMILIA_ID                    IS DISTINCT FROM NEW.FAMILIA_ID
             OR   OLD.FAMILIA_DESCRICAO             IS DISTINCT FROM NEW.FAMILIA_DESCRICAO
             OR   OLD.MODELO_ID                     IS DISTINCT FROM NEW.MODELO_ID
             OR   OLD.MODELO_DESCRICAO              IS DISTINCT FROM NEW.MODELO_DESCRICAO
             OR   OLD.PRODUTO_ID                    IS DISTINCT FROM NEW.PRODUTO_ID
             OR   OLD.PRODUTO_DESCRICAO             IS DISTINCT FROM NEW.PRODUTO_DESCRICAO
             OR   OLD.DESC_PRODUTO                  IS DISTINCT FROM NEW.DESC_PRODUTO
             OR   OLD.UM                            IS DISTINCT FROM NEW.UM
             OR   OLD.NCM                           IS DISTINCT FROM NEW.NCM
             OR   OLD.EAN                           IS DISTINCT FROM NEW.EAN
             OR   OLD.EAN_2                         IS DISTINCT FROM NEW.EAN_2
             OR   OLD.TAMANHO                       IS DISTINCT FROM NEW.TAMANHO
             OR   OLD.TAM_DESCRICAO                 IS DISTINCT FROM NEW.TAM_DESCRICAO
             OR   OLD.FRACIONAR                     IS DISTINCT FROM NEW.FRACIONAR
             OR   OLD.CEST                          IS DISTINCT FROM NEW.CEST
             OR   OLD.CFOP_CODIGO                   IS DISTINCT FROM NEW.CFOP_CODIGO
             OR   OLD.OPERACAO_CODIGO               IS DISTINCT FROM NEW.OPERACAO_CODIGO
             OR   OLD.TABELA_PRECO_ID               IS DISTINCT FROM NEW.TABELA_PRECO_ID
             OR   OLD.TABELA_PRECO_ID_PROMOCIONAL   IS DISTINCT FROM NEW.TABELA_PRECO_ID_PROMOCIONAL
             OR   OLD.VALOR_UNITARIO                IS DISTINCT FROM NEW.VALOR_UNITARIO
             OR   OLD.VALOR_UNITARIO_PROMOCIONAL    IS DISTINCT FROM NEW.VALOR_UNITARIO_PROMOCIONAL
             OR   OLD.VALOR_UNITARIO_PROMO_PROD     IS DISTINCT FROM NEW.VALOR_UNITARIO_PROMO_PROD
             OR   OLD.QUANTIDADE_MINIMA             IS DISTINCT FROM NEW.QUANTIDADE_MINIMA
             OR   OLD.QUANTIDADE_MINIMA_PROD        IS DISTINCT FROM NEW.QUANTIDADE_MINIMA_PROD
             OR   OLD.TRIBUTACAO_ORIGEM             IS DISTINCT FROM NEW.TRIBUTACAO_ORIGEM
             OR   OLD.TRIBUTACAO_ICMS               IS DISTINCT FROM NEW.TRIBUTACAO_ICMS
             OR   OLD.PERCENTUAL_BASECALCULO_ICMS   IS DISTINCT FROM NEW.PERCENTUAL_BASECALCULO_ICMS
             OR   OLD.ICMS_ALIQUOTA                 IS DISTINCT FROM NEW.ICMS_ALIQUOTA
             OR   OLD.TRIBUTACAO_PIS                IS DISTINCT FROM NEW.TRIBUTACAO_PIS
             OR   OLD.PIS_ALIQUOTA                  IS DISTINCT FROM NEW.PIS_ALIQUOTA
             OR   OLD.TRIBUTACAO_COFINS             IS DISTINCT FROM NEW.TRIBUTACAO_COFINS
             OR   OLD.COFINS_ALIQUOTA               IS DISTINCT FROM NEW.COFINS_ALIQUOTA
             OR   OLD.REDUCAO_BASE_PISCOF           IS DISTINCT FROM NEW.REDUCAO_BASE_PISCOF
             OR   OLD.TIPO_DESCONTO                 IS DISTINCT FROM NEW.TIPO_DESCONTO
             OR   OLD.COR_ID                        IS DISTINCT FROM NEW.COR_ID
             OR   OLD.DESC_LOCALIZACAO_ID           IS DISTINCT FROM NEW.DESC_LOCALIZACAO_ID
             OR   OLD.LOCALIZACAO_DESCRICAO         IS DISTINCT FROM NEW.LOCALIZACAO_DESCRICAO
             OR   OLD.COR_DESCRICAO                 IS DISTINCT FROM NEW.COR_DESCRICAO                               )
             THEN EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_PRODUTOS', OLD.ID, 2);
    END

END
^

SET TERM ; ^

