-- INSERT
CREATE OR ALTER trigger tbavaliacao_des_resumo_b02i for tbavaliacao_des_resumo
active before insert position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'Reg. incluido';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBAVALIACAO_DES_RESUMO',NEW.id, HISTORICO);
    END
END;

-- INSERT ITEM

CREATE trigger tbavaliacao_des_resumo_tipo_b02 for tbavaliacao_des_resumo_tipo
active before insert position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'Reg. Fator:'||NEW.avaliacao_des_fator_tipo_id||' INCLUIDO.';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBAVALIACAO_DES_RESUMO',NEW.avaliacao_des_resumo_id, HISTORICO);
    END
END

-- DELETE ITEM

CREATE trigger tbavaliacao_des_resumo_tipo_b03 for tbavaliacao_des_resumo_tipo
active before update position 0
AS

DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( NEW.STATUSEXCLUSAO = '1' AND OLD.STATUSEXCLUSAO = '0' ) THEN
    BEGIN
       HISTORICO = HISTORICO||'Reg. Fator: '||OLD.avaliacao_des_fator_tipo_id||' excluido';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBAVALIACAO_DES_RESUMO',OLD.avaliacao_des_resumo_id, HISTORICO);
    END

END;