ALTER TABLE TBPDV_CONFERENCIA_TROCA_ITEM
    ADD PDV_CONFERENCIA_MOVIMENTACAO_ID INTEGER DEFAULT 0 NOT NULL;


ALTER TABLE TBPDV_CONFERENCIA_MOVIMENTACAO
    ADD DATAHORA_FECHAMENTO TIMESTAMP;

SET TERM ^ ;

CREATE trigger ttbpdv_conferencia_mov_b02i for tbpdv_conferencia_movimentacao
active before insert position 2
AS
BEGIN   
    IF(NEW.SITUACAO = 2) THEN
    BEGIN
        NEW.DATAHORA_FECHAMENTO = CURRENT_TIMESTAMP;
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbpdv_conferencia_mov_b01u for tbpdv_conferencia_movimentacao
active before update position 1
AS
BEGIN
    IF(OLD.SITUACAO <> NEW.SITUACAO AND NEW.SITUACAO = 2) THEN
    BEGIN
        NEW.DATAHORA_FECHAMENTO = CURRENT_TIMESTAMP;
    END
END
^

SET TERM ; ^

