CREATE OR REPLACE PROCEDURE LIMPEZA_NOTAFISCAL(
   P_NRLISTA       IN VARCHAR2, 
   P_DTFINAL       IN DATE,
   P_DSSISTLIMPEZ  IN VARCHAR2,
   P_NMOPERLIMPEZ  IN VARCHAR2,
   P_IDSISTEMA     IN VARCHAR2)

AS

   V_VALOR    VARCHAR2(10);
   V_STATUS   VARCHAR2(01);
   V_CDFILIAL VARCHAR2(04);
   V_PASSO             NUMBER := 0;
   V_ERROR             VARCHAR2(2000);
   V_NRORDEM           VARCHAR2(03);

   V_DSIP              VARCHAR2(50);
   V_DSUSUARIO         VARCHAR2(50);
   V_DSRDM             VARCHAR2(50);
   V_DSMETODO          VARCHAR2(250);
   V_DSOPERADOR        VARCHAR2(12);

   V_EXCLUNOTAFISCAL    NUMBER := 0;

   V_COUNT_COMMIT      NUMBER := 1;
   V_NUM_TO_COMMIT     NUMBER := 10; -- NUMERO UTILIZADO PARA REGULARIZAR A QUANTIDADE DE DMLS PARA O COMMIT.

   V_DTHRFINLIMPEZA  DATE;

   CURSOR C_LISTA IS (SELECT CDFILIAL
                      FROM TRABLIMPFILIAL
                      WHERE IDLIMPEZA = P_IDSISTEMA);

   PROCEDURE VerifTimeOut(DTLIMITE IN DATE)
   IS
   BEGIN
      IF SYSDATE > DTLIMITE THEN
         COMMIT;
         RAISE_APPLICATION_ERROR(-20001,'TIMEOUT - EXCECAO PROPOSITAL TEKNISA');
      END IF;
   END;

BEGIN
   V_PASSO:= 1;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER LOG_FIS_NOTAFISCAL DISABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 2;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER NF_BAIXA_SAIDA DISABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 3;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER BLOQ_DEL_NFE DISABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 4;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER GRAVA_CANCELAMENTO_EXP DISABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 5;
   WEBTUNNING(V_DSIP, V_DSUSUARIO, V_DSRDM, V_DSMETODO, V_DSOPERADOR);
   V_PASSO:= 6;
   V_NRORDEM := '0';
   V_PASSO:= 7;
   DELETE FROM TRABPROCLIMPEZA
   WHERE IDLIMPEZA = P_IDSISTEMA;
   V_PASSO:= 8;
   UPDATE TRABLIMPEZA
   SET IDSTATUSLIMPEZA = 'A'
   WHERE IDLIMPEZA = P_IDSISTEMA;
   V_PASSO:= 9;
   --PEGA A DATA INICIAL E FINAL DA EXECUCAO
   SELECT TO_DATE(TO_CHAR(SYSDATE,'DDMMYYYY') || HRFINLIMPEZA||'00','DDMMYYYYHH24MISS')
   INTO V_DTHRFINLIMPEZA
   FROM TRABLIMPEZA
   WHERE IDLIMPEZA = P_IDSISTEMA;
   V_PASSO:= 10;
   IF V_DTHRFINLIMPEZA <= SYSDATE THEN
      V_DTHRFINLIMPEZA := V_DTHRFINLIMPEZA + 1;
   END IF;
   COMMIT;

   V_NRORDEM := LPAD(TO_CHAR(TO_NUMBER(V_NRORDEM)+1), 3, '0');

   UPDATE TABLIMPEZA
      SET NRORDEMLIMPEZA = V_NRORDEM
    WHERE IDLIMPEZA = P_IDSISTEMA
      AND NMTABELALIMP = 'NOTAFISCAL';
   V_PASSO:= 11;
    IF NOT(SQL%ROWCOUNT > 0) THEN
       INSERT INTO TABLIMPEZA (IDLIMPEZA, NMTABELALIMP, NRORDEMLIMPEZA)
       VALUES
       (P_IDSISTEMA, 'NOTAFISCAL', V_NRORDEM);
    END IF;
   V_PASSO:= 12;
    INSERT INTO TRABPROCLIMPEZA
      (IDLIMPEZA, NMTABELALIMP, IDSITUPROCLIMP)
    VALUES
       (P_IDSISTEMA, 'NOTAFISCAL', 'A');
   V_PASSO:= 13;
    COMMIT;

   /*Verifica se a procedure estourou o tempo limite*/
   VERIFTIMEOUT(V_DTHRFINLIMPEZA);

   V_STATUS := 'S';

   OPEN C_LISTA;
   LOOP
      FETCH C_LISTA INTO V_CDFILIAL;
      EXIT WHEN C_LISTA%NOTFOUND;

      FOR C_NOTAFISCAL IN (SELECT ROWID, NOTAFISCAL.CDFILIAL, NOTAFISCAL.NRLANCTONF, IDENTRSAIDOP
                           FROM NOTAFISCAL
                           WHERE NOTAFISCAL.CDFILIRECE  = V_CDFILIAL AND
                                 IDENTRSAIDOP = 'E'                  AND
                                 NOTAFISCAL.DTENTRSAID <= P_DTFINAL
                           UNION ALL
                           SELECT ROWID, NOTAFISCAL.CDFILIAL, NOTAFISCAL.NRLANCTONF, IDENTRSAIDOP
                           FROM NOTAFISCAL
                           WHERE NOTAFISCAL.CDFILIEMIT  = V_CDFILIAL AND
                                 IDENTRSAIDOP = 'S'                 AND
                                 NOTAFISCAL.DTENTRSAID <= P_DTFINAL)
      LOOP
         V_PASSO:= 14;
         V_STATUS := 'S';

         IF V_STATUS = 'S' THEN
            SELECT MAX(L.CDFILIAL)
            INTO V_VALOR
            FROM LANCTOESTOQ L
            WHERE L.CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  L.NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;

            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;
         END IF;
         V_PASSO:= 15;
         IF V_STATUS = 'S' THEN
            SELECT MAX(L.CDFILIAL)
            INTO V_VALOR
            FROM MAPARESUMECF L
            WHERE L.CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  L.NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;

            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;
         END IF;
         V_PASSO:= 16;
         IF V_STATUS = 'S' THEN
            SELECT MAX(L.CDFILIAL)
            INTO V_VALOR
            FROM INVOICE L
            WHERE L.CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  L.NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;

            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;

         END IF;
         V_PASSO:= 17;

         IF V_STATUS = 'S' THEN

            SELECT MAX(C.CDFILIAL)
            INTO V_VALOR
            FROM CONTARECEBER C, BOLETRECEBER B
            WHERE C.CDFILIAL      = C_NOTAFISCAL.CDFILIAL    AND
                  C.NRLANCTONF    = C_NOTAFISCAL.NRLANCTONF  AND
                  C.CDFILIBOLREC  = B.CDFILIAL               AND
                  C.NRLANBOLREC   = B.NRLANBOLREC            AND
                  NOT EXISTS (SELECT CDFILIAL
                              FROM BAIXARECEBIDA I
                              WHERE I.CDFILIAL   = B.CDFILIAL AND
                                    i.NRBAIXAREC = B.NRBAIXAREC);

            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;

         END IF;
         V_PASSO:= 18;
         IF V_STATUS = 'S' THEN

            SELECT MAX(C.CDFILIAL)
            INTO V_VALOR
            FROM CONTAPAGAR C, BOLETPAGAR B
            WHERE C.CDFILIAL      = C_NOTAFISCAL.CDFILIAL    AND
                  C.NRLANCTONF    = C_NOTAFISCAL.NRLANCTONF  AND
                  C.CDFILIBPAG    = B.CDFILIAL               AND
                  C.NRLANBOLPAG   = B.NRLANBOLPAG            AND
                  NOT EXISTS (SELECT CDFILIAL
                              FROM BAIXAPAGA I
                              WHERE I.CDFILIAL   = B.CDFILIAL AND
                                    i.NRBAIXAPAG = B.NRBAIXAPAG);

            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;

         END IF;
         V_PASSO:= 19;

         IF V_STATUS = 'S' THEN

            SELECT MAX(C.CDFILIAL)
            INTO V_VALOR
            FROM ITEMNOTAFISC C
            WHERE C.CDFILIAL      = C_NOTAFISCAL.CDFILIAL    AND
                  C.NRLANCTONF    = C_NOTAFISCAL.NRLANCTONF;

            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;

         END IF;
         V_PASSO:= 20;
         IF V_STATUS = 'S' THEN
            SELECT MAX(C.CDFILIAL)
            INTO V_VALOR
            FROM ITEMNOTAFISC C
            WHERE C.CDFILIALIT = C_NOTAFISCAL.CDFILIAL    AND
                  C.NRLANCTONFIT = C_NOTAFISCAL.NRLANCTONF;

            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;
         END IF;
         V_PASSO:= 21;
         IF C_NOTAFISCAL.IDENTRSAIDOP = 'E' THEN
            IF V_STATUS = 'S' THEN

               DELETE AJCTPAGAR
                WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                      NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
               V_PASSO:= 62;
               DELETE CONTAGERADA
                WHERE CDFILIALPAG = C_NOTAFISCAL.CDFILIAL AND
                      NRLANCTOPAG = C_NOTAFISCAL.NRLANCTONF;
               V_PASSO:= 63;
               DELETE ADIANTAPAGAR
                WHERE CDFILIAL = C_NOTAFISCAL.CDFILIAL AND
                      NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
               V_PASSO:= 64;
            END IF;
         END IF;
         V_PASSO:= 22;
         IF C_NOTAFISCAL.IDENTRSAIDOP = 'S' THEN
            IF V_STATUS = 'S' THEN
               DELETE AJCTRECEBER
                WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                      NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
               V_PASSO:= 65;
               DELETE PARCELAVENDA
                WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                      NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
               V_PASSO:= 66;
               DELETE ADIANTARECEB
                WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                      NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
               V_PASSO:= 67;
            END IF;
         END IF;
         V_PASSO:= 23;

         IF V_STATUS = 'S' THEN
            SELECT MAX(I.CDFILIAL)
            INTO V_VALOR
            FROM ITMAPARECUP I
            WHERE I.CDFILIAL = C_NOTAFISCAL.CDFILIAL    AND
                  I.NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            IF V_VALOR IS NOT NULL THEN
               V_STATUS := 'N';
            END IF;
         END IF;

         IF V_STATUS = 'S' THEN
            UPDATE MOVOCORR
            SET CDFILIALNF   = NULL,
                NRLANCTONF = NULL
            WHERE CDFILIALNF   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF   = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 24;
            UPDATE MAPAAPURAC
            SET CDFILIAL   = NULL,
                NRLANCTONF = NULL
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 25;
            UPDATE PREVRETI
            SET CDFILIALNF = NULL,
                NRLANCTONF = NULL
            WHERE CDFILIALNF = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 26;
            UPDATE ITEMAUTF
            SET NRLANCTONF = NULL
            WHERE CDFILLANC   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 27;
            DELETE AMOSTRAPROC
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 28;
            DELETE ITEMROMANEIO
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 29;
            DELETE ROMANEIONF
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 30;
            UPDATE ITREQUESTO
            SET NRLANCTONF = NULL
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 31;
            UPDATE APURFATUFAS
            SET NRLANCTONF = NULL
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 32;
            DELETE EXPNFFRETE
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 33;
            DELETE NFRELACAFSAI
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 34;
            DELETE NFRELACPEXOL
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 35;
            DELETE NFRELACORC
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 36;
            UPDATE  FORMULARIONF
            SET CDFILIAL   = NULL,
                NRLANCTONF = NULL
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 37;
            UPDATE OCORRERFATUR
            SET CDFILIALNF = NULL,
                NRLANCTONF = NULL
            WHERE CDFILIALNF = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 38;
            UPDATE AUDITORIA
            SET CDFILIALNF  = NULL,
                NRLANCTONF  = NULL,
                NRSEQITPROD = NULL
            WHERE CDFILIALNF = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 39;
            UPDATE ITEMVENDA
            SET CDFILIALNF  = NULL,
                NRLANCTONF  = NULL,
                NRSEQITPROD = NULL
            WHERE CDFILIALNF = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 40;
            UPDATE ITVENDAVMN
            SET CDFILIALNFV = NULL,
                NRLANCTONF  = NULL,
                NRSEQITPROD = NULL
            WHERE CDFILIALNFV = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF  = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 41;
            DELETE CONTARECEBER
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 42;
            DELETE CONTAPAGAR
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 43;
            DELETE SERVPLANO
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 44;
            DELETE NFRELACAF
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 45;
            DELETE LANCDESPFATU
            WHERE CDFILILANC = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 46;
            DELETE NFABASTEROTA
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 47;
            DELETE PARCLANCATIV
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 48;
            DELETE CTRAPUITPROD
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 49;
            DELETE SERVFATU
            WHERE CDFILIAL   = C_NOTAFISCAL.CDFILIAL AND
                  NRLANCTONF = C_NOTAFISCAL.NRLANCTONF;
            V_PASSO:= 50;
            DELETE NOTAFISCAL
            WHERE ROWID = C_NOTAFISCAL.ROWID;
            V_EXCLUNOTAFISCAL := V_EXCLUNOTAFISCAL + 1;
            V_PASSO:= 51;
            IF V_COUNT_COMMIT >= V_NUM_TO_COMMIT THEN
               UPDATE TRABPROCLIMPEZA
                 SET QTREGEXCLIMPEZA = V_EXCLUNOTAFISCAL
               WHERE IDLIMPEZA = P_IDSISTEMA
                 AND NMTABELALIMP = 'NOTAFISCAL';

              /*CONTROLE DE COMMIT HA CADA 1000 REGISTRO DELETEDO  E PARA ATUALIZAR A TELA DE LIMPEZA*/
              V_COUNT_COMMIT:= 1;
              COMMIT;
            ELSE
              V_COUNT_COMMIT:= V_COUNT_COMMIT + 1;
            END IF;
            V_PASSO:= 52;
         END IF;
         /*Verifica se a procedure estourou o tempo limite*/
         VERIFTIMEOUT(V_DTHRFINLIMPEZA);
      END LOOP;
   END LOOP;
   CLOSE C_LISTA;

   V_PASSO:= 53;
   UPDATE TRABPROCLIMPEZA
      SET IDSITUPROCLIMP = 'C',
          QTREGEXCLIMPEZA = V_EXCLUNOTAFISCAL,
          DTHRFINLIMPEZA = SYSDATE
    WHERE IDLIMPEZA = P_IDSISTEMA AND
          NMTABELALIMP = 'NOTAFISCAL';
   V_PASSO:= 54;
   UPDATE TRABLIMPEZA
   SET IDSTATUSLIMPEZA = 'C'
   WHERE IDLIMPEZA = P_IDSISTEMA;
   V_PASSO:= 55;
   INSERT INTO LOGLIMPEZA (DSSISTLIMPEZ, NMTABLIMP, DTLIMPDADOS, NMOPERLIMPEZ, DTFINALIMPEZ, DSLIMPEZA, DSRDMUSULOGL, DSENDUSULOGL, DSNMUSUOLOGL, DSMETUSULOGL, QTDLINHAEXCL)
   VALUES (P_DSSISTLIMPEZ, 'NOTAFISCAL', SYSDATE, P_NMOPERLIMPEZ, P_DTFINAL, 'NOTAFISCAL', V_DSRDM, V_DSIP, V_DSUSUARIO, V_DSMETODO, V_EXCLUNOTAFISCAL);

   COMMIT;
   V_PASSO:= 56;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER LOG_FIS_NOTAFISCAL ENABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 57;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER NF_BAIXA_SAIDA ENABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 58;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER BLOQ_DEL_NFE ENABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 59;
   BEGIN
      EXECUTE IMMEDIATE 'ALTER TRIGGER GRAVA_CANCELAMENTO_EXP ENABLE';
   EXCEPTION
      WHEN OTHERS THEN NULL;
   END;
   V_PASSO:= 60;
   /*Apagando a lista utilizada para a limpeza*/
   DELETE FROM LISTA
   WHERE NRLISTA =P_NRLISTA;

   COMMIT;
   V_PASSO:= 61;
EXCEPTION
  WHEN OTHERS THEN
    V_ERROR:= SQLERRM(SQLCODE);

    IF INSTR(V_ERROR, 'TIMEOUT - EXCECAO PROPOSITAL TEKNISA') = 0 THEN
       /*Apagando a lista utilizada para a limpeza*/
       DELETE FROM LISTA
       WHERE NRLISTA =P_NRLISTA;

       UPDATE TRABLIMPEZA
       SET IDSTATUSLIMPEZA = 'C', IDLIMPEZACONCERRO = 'S'
       WHERE IDLIMPEZA = P_IDSISTEMA;

       COMMIT;
    ELSE
        UPDATE TRABLIMPEZA
        SET IDSTATUSLIMPEZA = 'P'
        WHERE IDLIMPEZA = P_IDSISTEMA;
    END IF;

    IF (V_EXCLUNOTAFISCAL > 0) THEN
       INSERT INTO LOGLIMPEZA (DSSISTLIMPEZ, NMTABLIMP, DTLIMPDADOS, NMOPERLIMPEZ, DTFINALIMPEZ, DSLIMPEZA, DSRDMUSULOGL, DSENDUSULOGL, DSNMUSUOLOGL, DSMETUSULOGL, QTDLINHAEXCL)
       VALUES (P_DSSISTLIMPEZ, 'NOTAFISCAL', SYSDATE, P_NMOPERLIMPEZ, P_DTFINAL, 'NOTAFISCAL', V_DSRDM, V_DSIP, V_DSUSUARIO, V_DSMETODO, V_EXCLUNOTAFISCAL);
    END IF;

    COMMIT;

    BEGIN
       EXECUTE IMMEDIATE 'ALTER TRIGGER LOG_FIS_NOTAFISCAL  ENABLE';
    EXCEPTION
       WHEN OTHERS THEN NULL;
    END;

    BEGIN
       EXECUTE IMMEDIATE 'ALTER TRIGGER NF_BAIXA_SAIDA ENABLE';
    EXCEPTION
       WHEN OTHERS THEN NULL;
    END;

    BEGIN
       EXECUTE IMMEDIATE 'ALTER TRIGGER BLOQ_DEL_NFE ENABLE';
    EXCEPTION
       WHEN OTHERS THEN NULL;
    END;

    BEGIN
       EXECUTE IMMEDIATE 'ALTER TRIGGER GRAVA_CANCELAMENTO_EXP ENABLE';
    EXCEPTION
       WHEN OTHERS THEN NULL;
    END;

    RAISE_APPLICATION_ERROR (-20101, 'PASSO : ' || V_PASSO || '   -   ' || V_ERROR);
END;
/