SET TERM ^ ;

CREATE trigger ttbncm_secao_b01i for tbncm_secao
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);

BEGIN

    HISTORICO = '';

    IF ( NEW.SECAO > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'REGISTRO INCLUIDO';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',NEW.SECAO, HISTORICO);
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_secao_b01d for tbncm_secao
active before delete position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);

BEGIN

    HISTORICO = '';

    IF ( OLD.SECAO > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'REGISTRO EXCLUIDO';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',OLD.SECAO, HISTORICO);
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_secao_b01u for tbncm_secao
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF ( NEW.DESCRICAO <> OLD.DESCRICAO) THEN
    BEGIN
        HISTORICO = HISTORICO||' DESC:'||OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END

    IF ( NEW.CAPITULO <> OLD.CAPITULO) THEN
    BEGIN
        HISTORICO = HISTORICO||' CAP:'||OLD.CAPITULO||'->'||NEW.CAPITULO;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        HISTORICO = ' REGISTRO ALTERADO: '||HISTORICO;
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',NEW.SECAO, HISTORICO);
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_capitulo_b01i for tbncm_capitulo
active before insert position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);

BEGIN

    HISTORICO = '';

    IF ( NEW.CAPITULO > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'CAPITULO INCLUIDO:'||NEW.CAPITULO||' - '||NEW.DESCRICAO;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',NEW.SECAO, HISTORICO);
    END
end
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_capitulo_b01d for tbncm_capitulo
active before delete position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);

BEGIN

    HISTORICO = '';

    IF ( OLD.CAPITULO > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'CAPITULO EXCLUIDO:'||OLD.CAPITULO||' - '||OLD.DESCRICAO;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',OLD.SECAO, HISTORICO);
    END
end
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_capitulo_b01u for tbncm_capitulo
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF ( NEW.DESCRICAO <> OLD.DESCRICAO) THEN
    BEGIN
        HISTORICO = HISTORICO||' DESC:'||OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END

    IF ( NEW.CAPITULO <> OLD.CAPITULO) THEN
    BEGIN
        HISTORICO = HISTORICO||' CAP:'||OLD.CAPITULO||'->'||NEW.CAPITULO;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        HISTORICO = ' CAP. ALTERADO: '||HISTORICO;
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',NEW.SECAO, HISTORICO);
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_b02i for tbncm
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( NEW.CODIGO > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'NCM INCLUIDO: '||FN_MASK(NEW.NCM, 'NCM')||' - '||NEW.DESCRICAO;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',NEW.CAPITULO, HISTORICO);
    END
end
^

SET TERM ; ^



SET TERM ^ ;

CREATE trigger ttbncm_b01d for tbncm
active before delete position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.CODIGO > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'NCM EXCLUIDO: '||FN_MASK(OLD.NCM, 'NCM')||' - '||OLD.DESCRICAO;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',OLD.CAPITULO, HISTORICO);
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_b01u for tbncm
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF ( NEW.DESCRICAO <> OLD.DESCRICAO) THEN
    BEGIN
        HISTORICO = HISTORICO||' DESC:'||OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END

    IF ( NEW.NCM <> OLD.NCM) THEN
    BEGIN
        HISTORICO = HISTORICO||' NCM:'||FN_MASK(OLD.NCM, 'NCM')||'->'||FN_MASK(OLD.NCM, 'NCM');
    END

    IF ( NEW.IPI <> OLD.IPI) THEN
    BEGIN
        HISTORICO = HISTORICO||' NCM:'||OLD.IPI||'->'||OLD.IPI;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        HISTORICO = ' NCM: '||FN_MASK(OLD.NCM, 'NCM') ||' ALTERADO: '||HISTORICO;
        EXECUTE PROCEDURE SPI_HISTORICO('TBNCM_SECAO',NEW.CAPITULO, HISTORICO);
    END
END
^

SET TERM ; ^









