CREATE OR REPLACE TRIGGER ATUALIZA_ADIANTAMENTOPAG
AFTER DELETE OR INSERT
ON ADIANTAPAGAR FOR EACH ROW
BEGIN
   IF INSERTING THEN
      UPDATE CONTAPAGAR
         SET VRADIAPAGUTL = NVL(VRADIAPAGUTL, 0) + :NEW.VRADIANTAPAG
       WHERE CDFILIAL = :NEW.CDFILIAL
         AND NRLANCTONF = :NEW.NRLANCTONF
         AND NRSEQVENPAG = :NEW.NRSEQVENPAG
         AND NRPARCELAPAG = :NEW.NRPARCELAPAG;
   END IF;

   IF DELETING THEN
      UPDATE CONTAPAGAR
         SET VRADIAPAGUTL = NVL(VRADIAPAGUTL, 0) - :OLD.VRADIANTAPAG
       WHERE CDFILIAL = :OLD.CDFILIAL
         AND NRLANCTONF = :OLD.NRLANCTONF
         AND NRSEQVENPAG = :OLD.NRSEQVENPAG
         AND NRPARCELAPAG = :OLD.NRPARCELAPAG;
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('ATUALIZA_ADIANTAMENTOPAG','5.11.000'); END;
/