INSERT INTO TBMENU (DESCRICAO, CONTROLE, GRUPO, SUBGRUPO, TIPO, URL)
            VALUES ('REGISTRO DE PREVISÃO DE TRIBUTOS', 17030, 'CONT', 'CONT', '1   ', '');

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

    HISTORICO = '';

    IF ( NEW.id > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' Registro Incluido';
    END

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

CREATE trigger tTBPROVISAO_b01u for TBPROVISAO
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.descricao <> NEW.descricao) THEN
    BEGIN
        HISTORICO = HISTORICO||'Descricao:'|| OLD.descricao||'->'||NEW.descricao;
    END
	
	IF ( OLD.ano <> NEW.ano) THEN
    BEGIN
        HISTORICO = HISTORICO||', Ano:'|| OLD.ano||'->'||NEW.ano;
    END
	
	IF ( OLD.valor <> NEW.valor) THEN
    BEGIN
        HISTORICO = HISTORICO||', Valor:'|| OLD.valor||'->'||NEW.valor;
    END

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

CREATE OR ALTER trigger tTBPROVISAO_b01d for TBPROVISAO
active before delete position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.id > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'Registro Excluido';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBPROVISAO',old.id, HISTORICO);
    END
end;


