SET TERM ^ ;

CREATE OR ALTER trigger ttbpdv_cfe_b12i for tbpdv_cfe
active before insert position 12
AS
BEGIN   
    /* DEFININDO CONTINGENCIA PARA NFCE */
    IF(NEW.FORMA_EMISSAO = 2 AND NEW.TIPO = 2 AND NEW.SITUACAO = 1) THEN
    BEGIN
        NEW.NFCE_CONTINGENCIA = 1;
    END

    /* DEFININDO CONTINGENCIA PARA CFE */
    IF(NEW.FORMA_EMISSAO = 2 AND NEW.TIPO = 0 AND NEW.SITUACAO = 1) THEN
    BEGIN
        NEW.NFCE_CONTINGENCIA = 0;
        NEW.FORMA_EMISSAO = 1;
    END
END
^

SET TERM ; ^

