SET TERM ^ ;

CREATE OR ALTER TRIGGER TBNFS_FORMA_PAGAMENTO_B01U FOR TBNFS_FORMA_PAGAMENTO
ACTIVE BEFORE INSERT OR UPDATE POSITION 0
AS
BEGIN
   
   IF(INSERTING)THEN
   BEGIN
    IF(NEW.VALOR_TAXA > 0)THEN
    BEGIN
       NEW.VALOR_LIQUIDO = (COALESCE(NEW.VALOR,0.00) - COALESCE(NEW.VALOR_TAXA,0.00));
    END
   END

   IF(UPDATING)THEN
   BEGIN
    IF((NEW.VALOR_TAXA <> OLD.VALOR_TAXA) OR (NEW.VALOR_LIQUIDO <> (NEW.VALOR - COALESCE(NEW.VALOR_TAXA,0.00))))THEN
    BEGIN
       NEW.VALOR_LIQUIDO = NEW.VALOR - NEW.VALOR_TAXA;
    END
   END
END^

SET TERM ;^