create or replace
PROCEDURE FCT_CONSISTE_FERI_BANC
     (P_CDFILIAL IN VARCHAR2,
      P_DTVENCIMENTO IN DATE,
      P_DTVENC OUT DATE,
      P_IDTIPODTPGTO IN VARCHAR2,
      P_DTREFERENCIA IN DATE)
   IS
      V_BOFERIFILI BOOLEAN;
      V_NRDIASFERI NUMBER;
      V_DTANTERIOR DATE;
   BEGIN
      V_BOFERIFILI := TRUE;
      P_DTVENC := P_DTVENCIMENTO;
      WHILE V_BOFERIFILI LOOP
            BEGIN
               SELECT COUNT(*)
                 INTO V_NRDIASFERI
                 FROM FERIBANC
                WHERE CDFILIAL = P_CDFILIAL
                  AND DTFERIBANC BETWEEN P_DTREFERENCIA + 1 AND P_DTVENC;
            EXCEPTION
               WHEN NO_DATA_FOUND THEN
                  V_NRDIASFERI := 0;
            END;
         
         IF NOT (V_NRDIASFERI = 0) THEN
            V_DTANTERIOR := P_DTVENC;
            P_DTVENC := P_DTVENC + V_NRDIASFERI;
            WHILE V_BOFERIFILI LOOP
               V_DTANTERIOR := V_DTANTERIOR+1;
               BEGIN
                  SELECT COUNT(*)
                    INTO V_NRDIASFERI
                    FROM FERIBANC
                   WHERE CDFILIAL = P_CDFILIAL
                     AND DTFERIBANC BETWEEN V_DTANTERIOR AND P_DTVENC;
               EXCEPTION
                  WHEN NO_DATA_FOUND THEN
                     V_NRDIASFERI := 0;
               END;
               IF V_NRDIASFERI > 0 THEN
                  V_DTANTERIOR := P_DTVENC;
                  P_DTVENC := P_DTVENC + V_NRDIASFERI;
               ELSE
                  V_BOFERIFILI := FALSE;
               END IF;
            END LOOP;
         ELSE
            V_BOFERIFILI := FALSE;
         END IF;
      END LOOP;
   END;
/

-- VERSAO --
BEGIN ATUVEROBJ('FCT_CONSISTE_FERI_BANC','6.10.xxx'); END;
/