CREATE OR REPLACE TRIGGER FCT_ATUALIZA_SITUACAO_PARCELA
AFTER UPDATE ON "NOTAFISCAL"
FOR EACH ROW
BEGIN

    IF (:NEW.NRNOTAFISC IS NOT NULL) THEN

        FOR C_APURACAO IN (SELECT NRAPURACAO
                             FROM FCT_APURACAO
                            WHERE CDFILIAL = :OLD.CDFILIAL
                             AND NRLANCTONF = :OLD.NRLANCTONF
                             AND NRORG = :OLD.NRORG) LOOP

            UPDATE FCT_FATURACONT
               SET IDSITUACAO = 3,
                   DTULTATU = SYSDATE,
                   NRORGULTATU = :OLD.NRORG
             WHERE NRAPURACAO =  C_APURACAO.NRAPURACAO
               AND IDSITUACAO = 2
               AND NRORG = :OLD.NRORG;

        END LOOP;
    END IF;

END;
