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 FCT_RELACAPURACAOFATURA.NRFATURACONT
                             FROM FCT_APURACAO
                             JOIN FCT_RELACAPURACAOFATURA
                               ON FCT_RELACAPURACAOFATURA.NRAPURACAO =  FCT_APURACAO.NRAPURACAO
                              AND FCT_RELACAPURACAOFATURA.NRORG =  FCT_APURACAO.NRORG
                            WHERE FCT_APURACAO.CDFILIAL = :OLD.CDFILIAL
                             AND FCT_APURACAO.NRLANCTONF = :OLD.NRLANCTONF
                             AND FCT_APURACAO.NRORG = :OLD.NRORG) LOOP

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

        END LOOP;
    END IF;

END;