CREATE trigger ttbgp_fluxo_b02i for tbgp_fluxo
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF ( NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' GP INCLUIDO: '||NEW.GP_ID||' - '||(SELECT FIRST 1 T.DESCRICAO FROM TBGP T WHERE T.ID = NEW.GP_ID);
    END

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



CREATE trigger ttbgp_fluxo_b02d for tbgp_fluxo
active before delete position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF ( OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' GP EXCLUIDO: '||OLD.GP_ID||' - '||(SELECT FIRST 1 T.DESCRICAO FROM TBGP T WHERE T.ID = OLD.GP_ID);
    END

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

