SET TERM ^ ;

CREATE trigger ttbimplantacao_dev_b01u for tbimplantacao_desenvolvimento
active before update position 9
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

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

    IF(NEW.DATA <> OLD.DATA) THEN
    BEGIN
        HISTORICO = HISTORICO||' DATA: '||COALESCE(FORMATDATE(OLD.DATA),'')||' -> '||FORMATDATE(NEW.DATA);
    END

    IF(NEW.MODULO <> OLD.MODULO) THEN
    BEGIN
        HISTORICO = HISTORICO||' MÓDULO: '||OLD.MODULO||' -> '||NEW.MODULO;
    END

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

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

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbimplantacao_dev_b02i for tbimplantacao_desenvolvimento
active before insert position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

    IF(NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' DEV: '||NEW.ID||' INCLUÍDO';
    END

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

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbimplantacao_dev_b01d for tbimplantacao_desenvolvimento
active before delete position 0
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

    IF(OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' DEV: '||OLD.ID||' EXCLUÍDO';
    END

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

^

SET TERM ; ^



