CREATE OR REPLACE PROCEDURE GERARNFSAP(P_CDFILIAL IN VARCHAR,
                                       P_CDOPERADOR IN VARCHAR,
                                       P_DTINICIAL IN DATE,
                                       P_DTFINAL IN DATE)
AS
   V_COUNT NUMBER;
   V_SEQUENCIAL VARCHAR2(20);
   V_SEQHEADER VARCHAR2(20);
   V_SEQRNF NUMBER;
   V_SEQBODY NUMBER;
   V_SEQITEM NUMBER;
   V_SEQIMP NUMBER;
   V_CDCSTICMS VARCHAR(02);
   V_VRBASECALC NUMBER;
   V_VROUTRAS NUMBER;
   V_VRBCREDUZ NUMBER;
   V_VRTOTALNOTA NUMBER;
   V_VRITEM NUMBER;
   FUNCTION RETORNAPK(P_CODIGO IN VARCHAR) RETURN VARCHAR
   AS
   BEGIN
      NOVO_CODIGO_NT(P_CODIGO, V_SEQUENCIAL);
      RETURN V_SEQUENCIAL;
   END;
BEGIN
   FOR C_FILIAL IN
      (SELECT F.CDFILIAL, E.CDEXTERNO CDEMPRESAEXT, FILIALSAPRNF(F.CDFILIAL) CDFILISAP,
              F.CDFILIALEXT
         FROM FILIAL F, FILIOPER FO, EMPRESA E
        WHERE ((INSTR(P_CDFILIAL, F.CDFILIAL) > 0) OR (P_CDFILIAL = 'T'))
          AND FO.CDOPERADOR = P_CDOPERADOR
          AND F.CDFILIAL = FO.CDFILIAL
          AND F.CDEMPRESA = E.CDEMPRESA) LOOP
      FOR C_DATA IN
         (SELECT DTDATA DIA
            FROM DATA D
           WHERE DTDATA BETWEEN P_DTINICIAL AND P_DTFINAL
           ORDER BY 1) LOOP
         FOR C_VENDAS IN
            (SELECT V.CDFILIAL, DECODE(C.IDTPEMISSAOFOS, 'FNC', '14', 'SAT', '15') TIP_LOTE,
                    COUNT(*) QTNOTAS
               FROM VENDA V, CAIXA C,
                    (SELECT F.CDFILIAL, F.CDLOJA, F.CDCAIXA
                       FROM V_FILIALLOJACAIXA F, FILIOPER FO
                      WHERE F.CDFILIAL = C_FILIAL.CDFILIAL
                        AND FO.CDOPERADOR = P_CDOPERADOR
                        AND F.CDFILIAL = FO.CDFILIAL) FO
              WHERE V.CDFILIAL = FO.CDFILIAL
                AND V.CDCAIXA = FO.CDCAIXA
                AND V.CDLOJA = FO.CDLOJA
                AND V.DTENTRVENDA = C_DATA.DIA
                AND V.IDSITUVENDA = 'O'
                AND V.CDFILIAL = C.CDFILIAL
                AND V.CDCAIXA = C.CDCAIXA
                AND (V.NRBODYINTSAP IS NULL OR V.NRHEADERINTSAP IS NULL)
                AND EXISTS (SELECT 1
                              FROM TURCAIXA T
                             WHERE T.CDFILIAL = V.CDFILIAL
                               AND T.CDCAIXA = V.CDCAIXA
                               AND TRUNC(DTABERCAIX) = V.DTENTRVENDA
                               AND T.IDULTFECHAMEN = 'S')
              GROUP BY V.CDFILIAL, DECODE(C.IDTPEMISSAOFOS, 'FNC', '14', 'SAT', '15')) LOOP
            V_SEQHEADER := SUBSTR(RETORNAPK('HEADERINTSAPFOS'), -18, 18);
            V_SEQHEADER := 'TF'||V_SEQHEADER;
            V_SEQRNF := TO_NUMBER(RETORNAPK('NUMRNF'||C_FILIAL.CDFILIAL));
            INSERT INTO HEADERINTSAPFOS
               (NUM_SEQ_HEADER, COD_EMP_SAP, COD_UNIDADE_SAP, NUM_RNF, DTA_RNF,
                HRA_RNF, DES_ARQUIVO, QTD_NOTAS, TIP_LOTE, COD_UNIDADE_NL, DTA_IMPORTACAO,
                DTA_PROCESS, HRA_PROCESS, IND_EXCLUSAO, DTH_GERACAO_ARQ_CLI, SEQ_ESCOLA_BRITANICA,
                QTD_NOTAS_ATIVAS, NUM_HEADER_ORI, DTA_REPROCESS, HRA_REPROCESS)
            VALUES
               (V_SEQHEADER, C_FILIAL.CDEMPRESAEXT, C_FILIAL.CDFILISAP, V_SEQRNF, C_DATA.DIA,
                TO_CHAR(SYSDATE, 'HH24MISS'), NULL, C_VENDAS.QTNOTAS, C_VENDAS.TIP_LOTE, C_FILIAL.CDFILIALEXT, NULL,
                NULL, NULL, NULL, NULL, NULL,
                C_VENDAS.QTNOTAS, NULL, NULL, NULL);
            FOR C_BODY IN
               (SELECT SUM((TRUNC(IT.QTPRODVEND * (IT.VRUNITVEND + NVL(IT.VRUNITVENDCL,0)),2)) - NVL(IT.VRDESITVEND,0) + NVL(IT.VRACRITVEND, 0)) VRTOTVENDA,
                       DECODE(ISNUMBER(MAX(NRNOTAFISCALCE)), 'S', TO_CHAR(TO_NUMBER(MAX(NRNOTAFISCALCE))), MAX(NRNOTAFISCALCE)) NRNOTAFISC,
                       DECODE(C.IDTPEMISSAOFOS, 'FNC', '5214', 'SAT', '5215') CODOPER,
                       CL.CDEXCLIENTE NUMCPFCNPJ, NVL(C.CDSERIECX, C.CDCAIXA) CDSERIE,
                       TRUNC(V.DTEMISSAONFCE) DTEMISSAONFCE
                  FROM V_FILIALLOJACAIXA FLC, VENDA V, CAIXA C, PARAVEND P, CLIENTE CL, ITEMVENDA IT
                 WHERE FLC.CDFILIAL = C_FILIAL.CDFILIAL
                   AND FLC.CDFILIAL = V.CDFILIAL
                   AND FLC.CDCAIXA = V.CDCAIXA
                   AND FLC.CDLOJA = V.CDLOJA
                   AND FLC.CDFILIAL = C.CDFILIAL
                   AND FLC.CDCAIXA = C.CDCAIXA
                   AND FLC.CDFILIAL = P.CDFILIAL
                   AND P.CDCLIENTE = CL.CDCLIENTE
                   AND V.DTENTRVENDA = C_DATA.DIA
                   AND (V.NRBODYINTSAP IS NULL OR V.NRHEADERINTSAP IS NULL)
                   AND V.IDSITUVENDA = 'O'
                   AND V.CDFILIAL = IT.CDFILIAL
                   AND V.CDCAIXA = IT.CDCAIXA
                   AND V.NRSEQVENDA = IT.NRSEQVENDA
                   AND EXISTS (SELECT 1
                                 FROM TURCAIXA T
                                WHERE T.CDFILIAL = V.CDFILIAL
                                  AND T.CDCAIXA = V.CDCAIXA
                                  AND TRUNC(DTABERCAIX) = V.DTENTRVENDA
                                  AND T.IDULTFECHAMEN = 'S')
                   GROUP BY DECODE(C.IDTPEMISSAOFOS, 'FNC', '5214', 'SAT', '5215'), CL.CDEXCLIENTE,
                            NVL(C.CDSERIECX, C.CDCAIXA), TRUNC(V.DTEMISSAONFCE)) LOOP
               V_SEQBODY := TO_NUMBER(RETORNAPK('BODYINTSAPFOS'||C_FILIAL.CDFILIAL||TO_CHAR(V_SEQRNF)));
               INSERT INTO BODYINTSAPFOS
                  (NUM_SEQ_HEADER, NUM_SEQ_CORPO, NUM_CNPJ_CPF, COD_SERIE, NUM_NOTA,
                   COD_RESULT_NFE, IND_CONTINGENCIA, NUM_RECIBO_NFE, DES_CHAVE_NFE, DTA_DANFE,
                   HRA_DANFE, VLR_TOTAL, DTA_EMISSAO, DTA_LANCAMENTO, DTA_VENCIMENTO,
                   NUM_NES, NUM_SEQ_NE_NL, COD_MAQ_NE_NL, NUM_SEQ_NS_NL, COD_MAQ_NS_NL, NUM_DOC_CONT,
                   NUM_DOC_FISC, NUM_DOC_RELAC, IND_EXCLUSAO, NUM_SEQ_TRF, COD_MAQ_TRF,
                   COD_OPER, NUM_CHAMADO, NUM_REQUISICAO_WEBB, DTA_REPROCESS, HRA_REPROCESS,
                   NUM_CNO)
               VALUES
                  (V_SEQHEADER, V_SEQBODY, C_BODY.NUMCPFCNPJ, C_BODY.CDSERIE, C_BODY.NRNOTAFISC,
                  NULL, NULL, NULL, NULL, NULL,
                  NULL, C_BODY.VRTOTVENDA, C_BODY.DTEMISSAONFCE, C_DATA.DIA, NULL,
                  NULL, NULL, NULL, NULL, NULL, NULL,
                  NULL, NULL, NULL, NULL, NULL,
                  C_BODY.CODOPER, NULL, NULL, NULL, NULL,
                  NULL);
               V_SEQITEM := 0;
               V_VRTOTALNOTA := 0;
               FOR C_ITEM IN
                  (SELECT CDARVPROD, CDPRODINTE, NMPRODUTO, CDCFOPPROD, CDNCM, VRUNIT, CDTPDOC,
                          VRDESC, QTDEITEM, TRUNC(QTDEITEM * VRUNIT, 2) AS VRITEM,
                          VROUTDESP
                     FROM (SELECT P.CDARVPROD, P.CDPRODINTE, P.NMPRODUTO, II.CDCFOPPROD, P.CDCLASFISC CDNCM, NVL(VRUNITVEND, 0) + NVL(I.VRUNITVENDCL,0) VRUNIT,
                                  TPDOC.CDTPDOC,
                                  SUM(NVL(I.VRDESITVEND,0)) VRDESC, SUM(I.QTPRODVEND) QTDEITEM, SUM(NVL(I.VRACRITVEND, 0)) VROUTDESP
                             FROM V_FILIALLOJACAIXA FLC, VENDA V, ITEMVENDA I, ITVENDAIMPOS II, TPDOCINTSAPFOS TPDOC,
                                  CAIXA C, PRODUTO P
                            WHERE FLC.CDFILIAL = C_FILIAL.CDFILIAL
                              AND FLC.CDFILIAL = V.CDFILIAL
                              AND FLC.CDCAIXA = V.CDCAIXA
                              AND FLC.CDLOJA = V.CDLOJA
                              AND FLC.CDFILIAL = C.CDFILIAL
                              AND FLC.CDCAIXA = C.CDCAIXA
                              AND V.DTENTRVENDA = C_DATA.DIA
                              AND V.CDFILIAL = C.CDFILIAL
                              AND V.CDCAIXA = C.CDCAIXA
                              AND V.CDFILIAL = I.CDFILIAL
                              AND V.CDCAIXA = I.CDCAIXA
                              AND V.NRSEQVENDA = I.NRSEQVENDA
                              AND I.CDPRODUTO = P.CDPRODUTO
                              AND II.CDFILIAL = I.CDFILIAL
                              AND II.CDCAIXA = I.CDCAIXA
                              AND II.NRSEQVENDA = I.NRSEQVENDA
                              AND II.NRSEQUITVEND = I.NRSEQUITVEND
                              AND II.CDCFOPPROD = TPDOC.CDCFOP
                              AND II.CDCSTPRODI = TPDOC.CDCST
                              AND P.CDCLASFISC = TPDOC.CDNCM
                              AND NVL(C.CDSERIECX, C.CDCAIXA) = C_BODY.CDSERIE
                              AND V.IDSITUVENDA = 'O'
                              AND (V.NRBODYINTSAP IS NULL OR V.NRHEADERINTSAP IS NULL)
                              AND EXISTS (SELECT 1
                                            FROM TURCAIXA T
                                           WHERE T.CDFILIAL = V.CDFILIAL
                                             AND T.CDCAIXA = V.CDCAIXA
                                             AND TRUNC(DTABERCAIX) = V.DTENTRVENDA
                                             AND T.IDULTFECHAMEN = 'S')
                              GROUP BY P.CDARVPROD, P.CDPRODINTE, P.NMPRODUTO, II.CDCFOPPROD, P.CDCLASFISC, NVL(VRUNITVEND, 0) + NVL(I.VRUNITVENDCL,0),
                                       TPDOC.CDTPDOC)X) LOOP
                  V_VRITEM := 0;
                  V_VRITEM := TRUNC(C_ITEM.VRITEM - NVL(C_ITEM.VRDESC, 0), 2);
                  V_VRTOTALNOTA := V_VRTOTALNOTA + V_VRITEM + C_ITEM.VROUTDESP;
                  V_SEQITEM := V_SEQITEM + 1;
                 INSERT INTO ITEMINTSAPFOS
                     (NUM_SEQ_HEADER, NUM_SEQ_CORPO, NUM_SEQ_ITEM, NUM_ITEM,
                      TIP_DOCUMENTO, VLR_ITEM, NUM_CFOP, VLR_DESCONTO,
                      VLR_FRETE, VLR_SEGURO, VLR_OUTRAS_DESP, COD_ITEM,
                      QTD_ITEM, VLR_UNITARIO, NUM_NOTA_ORIGEM, COD_SERIE_ORIGEM,
                      DES_ITEM, COD_CC, COD_NAT_R_PISCOF, COD_TP_CR_PISCOF,
                      COD_NT_BC_PISCOF, COD_NAT_FRETE, COD_NBM, COD_ITEM_NL)
                  VALUES
                     (V_SEQHEADER, V_SEQBODY, V_SEQITEM, V_SEQITEM,
                      C_ITEM.CDTPDOC, C_ITEM.VRITEM, C_ITEM.CDCFOPPROD, C_ITEM.VRDESC,
                      NULL, NULL, C_ITEM.VROUTDESP, C_ITEM.CDPRODINTE,
                      C_ITEM.QTDEITEM, C_ITEM.VRUNIT, NULL, NULL,
                      C_ITEM.NMPRODUTO, C_FILIAL.CDFILIALEXT, NULL, NULL,
                      NULL, NULL, C_ITEM.CDNCM, C_ITEM.CDARVPROD);
                  
                  FOR C_IMP_ITEM IN
                     (SELECT II.VRPERCOFINS, II.VRPERPIS, II.CDCSTPRODI, II.CDCSTPRODPC, II.VRPEALPRODIT,
                             SUM(II.VRBCPISCOFINS) BASEPISCOFINS, 0 VRREDBASEPISCOFINS,
                             SUM(II.VRBASECALCICMS) VRBASECALCICMS,
                             SUM(II.VRBCREDUZICMS) VRBCREDUZICMS, SUM(II.VRIMPOPRODIT) VRIMPOPRODIT,
                             SUM(II.VRIMPPIS) VRIMPPIS, SUM(II.VRIMPCOFINS) VRIMPCOFINS
                        FROM V_FILIALLOJACAIXA FLC, VENDA V, ITEMVENDA I, ITVENDAIMPOS II, TPDOCINTSAPFOS TPDOC,
                             CAIXA C, PRODUTO P
                       WHERE FLC.CDFILIAL = C_FILIAL.CDFILIAL
                         AND FLC.CDFILIAL = V.CDFILIAL
                         AND FLC.CDCAIXA = V.CDCAIXA
                         AND FLC.CDLOJA = V.CDLOJA
                         AND FLC.CDFILIAL = C.CDFILIAL
                         AND FLC.CDCAIXA = C.CDCAIXA
                         AND V.DTENTRVENDA = C_DATA.DIA
                         AND V.CDFILIAL = C.CDFILIAL
                         AND V.CDCAIXA = C.CDCAIXA
                         AND V.CDFILIAL = I.CDFILIAL
                         AND V.CDCAIXA = I.CDCAIXA
                         AND V.NRSEQVENDA = I.NRSEQVENDA
                         AND I.CDPRODUTO = P.CDPRODUTO
                         AND II.CDFILIAL = I.CDFILIAL
                         AND II.CDCAIXA = I.CDCAIXA
                         AND II.NRSEQVENDA = I.NRSEQVENDA
                         AND II.NRSEQUITVEND = I.NRSEQUITVEND
                         AND II.CDCFOPPROD = TPDOC.CDCFOP
                         AND II.CDCSTPRODI = TPDOC.CDCST
                         AND P.CDCLASFISC = TPDOC.CDNCM
                         AND NVL(C.CDSERIECX, C.CDCAIXA) = C_BODY.CDSERIE
                         AND V.IDSITUVENDA = 'O'
                         AND P.CDARVPROD = C_ITEM.CDARVPROD
                         AND P.CDPRODINTE = C_ITEM.CDPRODINTE
                         AND II.CDCFOPPROD = C_ITEM.CDCFOPPROD
                         AND P.CDCLASFISC = C_ITEM.CDNCM
                         AND NVL(VRUNITVEND, 0) + NVL(I.VRUNITVENDCL,0) = C_ITEM.VRUNIT
                         AND TPDOC.CDTPDOC = C_ITEM.CDTPDOC
                         AND (V.NRBODYINTSAP IS NULL OR V.NRHEADERINTSAP IS NULL)
                         AND EXISTS (SELECT 1
                                       FROM TURCAIXA T
                                      WHERE T.CDFILIAL = V.CDFILIAL
                                        AND T.CDCAIXA = V.CDCAIXA
                                        AND TRUNC(DTABERCAIX) = V.DTENTRVENDA
                                        AND T.IDULTFECHAMEN = 'S')
                       GROUP BY II.VRPERCOFINS, II.VRPERPIS, II.CDCSTPRODI, II.CDCSTPRODPC, II.VRPEALPRODIT) LOOP
                     IF LENGTH(C_IMP_ITEM.CDCSTPRODI) > 2 THEN
                        V_CDCSTICMS := SUBSTR(C_IMP_ITEM.CDCSTPRODI, 2, 2);
                     ELSE
                        V_CDCSTICMS := C_IMP_ITEM.CDCSTPRODI;
                     END IF;
                     IF V_CDCSTICMS IN ('00', '20') THEN
                        V_VRBASECALC := C_IMP_ITEM.VRBASECALCICMS;
                        V_VROUTRAS := 0;
                        V_VRBCREDUZ := C_IMP_ITEM.VRBCREDUZICMS;
                     ELSIF V_CDCSTICMS IN ('40', '41') THEN
                        V_VRBASECALC := 0;
                        V_VROUTRAS := 0;
                        V_VRBCREDUZ := C_IMP_ITEM.VRBASECALCICMS;
                     ELSIF V_CDCSTICMS IN ('60', '90') THEN
                        V_VRBASECALC := 0;
                        V_VROUTRAS := C_IMP_ITEM.VRBASECALCICMS;
                        V_VRBCREDUZ := C_IMP_ITEM.VRBCREDUZICMS;
                     END IF;
                     
                     begin
                     V_SEQIMP := 1;
                     INSERT INTO IMPOSTOINTSAPFOS
                        (NUM_SEQ_HEADER, NUM_SEQ_CORPO, NUM_SEQ_ITEM, NUM_SEQ_IMPOSTO,
                         TIP_IMPOSTO, VLR_BASE, VLR_RED_BASE, VLR_OUTRAS,
                         PER_IMPOSTO, VLR_IMPOSTO, TIP_TRIBUTACAO)
                     VALUES
                        (V_SEQHEADER, V_SEQBODY, V_SEQITEM, V_SEQIMP,
                         'ICMS', V_VRBASECALC, V_VRBCREDUZ, V_VROUTRAS,
                         C_IMP_ITEM.VRPEALPRODIT, C_IMP_ITEM.VRIMPOPRODIT, V_CDCSTICMS);
                    exception
                       when others then
                          raise_application_error(-20501, 'serie: '||C_BODY.CDSERIE||' '||
                                                          'CDARVPROD: '||C_ITEM.CDARVPROD||' ' ||
                                                          'CDPRODINTE: '||C_ITEM.CDPRODINTE||' '||
                                                          'CDCFOPPROD: '||C_ITEM.CDCFOPPROD|| ' '||
                                                          'CDNCM: '|| C_ITEM.CDNCM||' '||
                                                          'VRUNIT: '||TO_CHAR(C_ITEM.VRUNIT)||' '||
                                                          'CDTPDOC: '||C_ITEM.CDTPDOC, true);
                    end;
                     IF C_IMP_ITEM.CDCSTPRODPC IN ('04') THEN
                        V_VRBASECALC := 0;
                        V_VROUTRAS := C_IMP_ITEM.BASEPISCOFINS;
                     ELSE
                        V_VRBASECALC := C_IMP_ITEM.BASEPISCOFINS;
                        V_VROUTRAS := 0;
                     END IF;
                     V_SEQIMP := 2;
                     INSERT INTO IMPOSTOINTSAPFOS
                        (NUM_SEQ_HEADER, NUM_SEQ_CORPO, NUM_SEQ_ITEM, NUM_SEQ_IMPOSTO,
                         TIP_IMPOSTO, VLR_BASE, VLR_RED_BASE, VLR_OUTRAS,
                         PER_IMPOSTO, VLR_IMPOSTO, TIP_TRIBUTACAO)
                     VALUES
                        (V_SEQHEADER, V_SEQBODY, V_SEQITEM, V_SEQIMP,
                         'PIS', V_VRBASECALC, C_IMP_ITEM.VRREDBASEPISCOFINS, V_VROUTRAS,
                         C_IMP_ITEM.VRPERPIS, C_IMP_ITEM.VRIMPPIS, C_IMP_ITEM.CDCSTPRODPC);
                     V_SEQIMP := 3;
                     INSERT INTO IMPOSTOINTSAPFOS
                        (NUM_SEQ_HEADER, NUM_SEQ_CORPO, NUM_SEQ_ITEM, NUM_SEQ_IMPOSTO,
                         TIP_IMPOSTO, VLR_BASE, VLR_RED_BASE, VLR_OUTRAS,
                         PER_IMPOSTO, VLR_IMPOSTO, TIP_TRIBUTACAO)
                     VALUES
                        (V_SEQHEADER, V_SEQBODY, V_SEQITEM, V_SEQIMP,
                         'COFINS', V_VRBASECALC, C_IMP_ITEM.VRREDBASEPISCOFINS, V_VROUTRAS,
                         C_IMP_ITEM.VRPERCOFINS, C_IMP_ITEM.VRIMPCOFINS, C_IMP_ITEM.CDCSTPRODPC);
                  END LOOP;
               END LOOP;
               FOR C_UP_VENDA IN
                  (SELECT DISTINCT V.CDFILIAL, V.CDCAIXA, V.NRSEQVENDA
                     FROM V_FILIALLOJACAIXA FLC, VENDA V, CAIXA C, PARAVEND P, CLIENTE CL
                    WHERE FLC.CDFILIAL = C_FILIAL.CDFILIAL
                      AND FLC.CDFILIAL = V.CDFILIAL
                      AND FLC.CDCAIXA = V.CDCAIXA
                      AND FLC.CDLOJA = V.CDLOJA
                      AND FLC.CDFILIAL = C.CDFILIAL
                      AND FLC.CDCAIXA = C.CDCAIXA
                      AND FLC.CDFILIAL = P.CDFILIAL
                      AND P.CDCLIENTE = CL.CDCLIENTE
                      AND V.DTENTRVENDA = C_DATA.DIA
                      AND NVL(C.CDSERIECX, C.CDCAIXA) = C_BODY.CDSERIE
                      AND V.IDSITUVENDA = 'O'
                      AND (V.NRBODYINTSAP IS NULL OR V.NRHEADERINTSAP IS NULL)
                      AND EXISTS (SELECT 1
                                    FROM TURCAIXA T
                                   WHERE T.CDFILIAL = V.CDFILIAL
                                     AND T.CDCAIXA = V.CDCAIXA
                                     AND TRUNC(DTABERCAIX) = V.DTENTRVENDA
                                     AND T.IDULTFECHAMEN = 'S')) LOOP
                  UPDATE VENDA
                     SET NRBODYINTSAP = V_SEQBODY,
                         NRHEADERINTSAP = V_SEQHEADER
                   WHERE CDFILIAL = C_UP_VENDA.CDFILIAL
                     AND CDCAIXA = C_UP_VENDA.CDCAIXA
                     AND NRSEQVENDA = C_UP_VENDA.NRSEQVENDA;
               END LOOP;
               UPDATE BODYINTSAPFOS
                  SET VLR_TOTAL = V_VRTOTALNOTA
                WHERE NUM_SEQ_HEADER = V_SEQHEADER
                  AND NUM_SEQ_CORPO = V_SEQBODY;
            END LOOP;
         END LOOP;
      END LOOP;
   END LOOP;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('GERARNFSAP','6.39.006'); END;
/
