SET TERM ^ ;

CREATE OR ALTER trigger ttbpdv_conferencia_item_b04iu for tbpdv_conferencia_item
active before insert or update position 4
AS
BEGIN   
    IF(INSERTING) THEN
    BEGIN
        UPDATE TBPDV_CONFERENCIA T SET T.VERSAO_ALTERACAO = T.VERSAO_ALTERACAO + 1 WHERE T.ID = NEW.PDV_CONFERENCIA_ID;

    END

    IF(UPDATING) THEN
    BEGIN
        IF(OLD.SEQUENCIA IS DISTINCT FROM NEW.SEQUENCIA
        OR OLD.PRODUTO_ID IS DISTINCT FROM NEW.PRODUTO_ID
        OR OLD.QUANTIDADE IS DISTINCT FROM NEW.QUANTIDADE
        OR OLD.VALOR_UNITARIO IS DISTINCT FROM NEW.VALOR_UNITARIO
        OR OLD.VALOR_DESCONTO IS DISTINCT FROM NEW.VALOR_DESCONTO
        OR OLD.VALOR_TOTAL IS DISTINCT FROM NEW.VALOR_TOTAL
        OR OLD.VALOR_LIQUIDO IS DISTINCT FROM NEW.VALOR_LIQUIDO
        OR OLD.TAMANHO IS DISTINCT FROM NEW.TAMANHO
        OR OLD.SITUACAO IS DISTINCT FROM NEW.SITUACAO
        OR OLD.PROMOCIONAL IS DISTINCT FROM NEW.PROMOCIONAL
        or OLD.QTD_ESTOQUE IS DISTINCT FROM NEW.QTD_ESTOQUE) THEN
        BEGIN
            UPDATE TBPDV_CONFERENCIA T SET T.VERSAO_ALTERACAO = T.VERSAO_ALTERACAO + 1 WHERE T.ID = OLD.PDV_CONFERENCIA_ID;
        END

    END

END
^

SET TERM ; ^

