DROP TRIGGER TTVOUCHER_B01U;

SET TERM ^ ;

CREATE OR ALTER trigger ttbvoucher_b03u for tbvoucher
active before update position 3
AS
BEGIN   
    IF(OLD.SALDO IS DISTINCT FROM NEW.SALDO) THEN
    BEGIN
        IF(NEW.SALDO = NEW.VALOR) THEN
        BEGIN
            NEW.STATUS = 0;

        END ELSE
        BEGIN
            IF(NEW.TIPO_BAIXA = 0) THEN
            BEGIN
                IF(NEW.SALDO = 0) THEN
                BEGIN
                    NEW.STATUS = 1;

                END ELSE
                BEGIN
                    NEW.STATUS = 0;
                END
            END ELSE
            BEGIN
                IF(NEW.SALDO <= NEW.VALOR) THEN
                BEGIN
                     NEW.STATUS = 1;
                END

            END

        END

    END
END
^

SET TERM ; ^

