SET TERM ^ ;

CREATE OR ALTER trigger ttbvoucher_b04u for tbvoucher
active before update position 4
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF(NEW.SALDO = 0) THEN
    BEGIN
        HISTORICO = ' SALDO ENCERRADO ';
    END

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

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbvoucher_b05u for tbvoucher
active before update position 5
AS
BEGIN
    IF(NEW.SALDO > 0) THEN
    BEGIN
        NEW.ULTIMO_SALDO = NEW.SALDO;
    END
END
^

SET TERM ; ^

