CREATE OR REPLACE PROCEDURE EXPCUPMASTERSAF(
   P_CDFILIAL IN VARCHAR2,
   P_DTINICIAL IN DATE,
   P_DTFINAL IN DATE,
   P_IDTIPOCAIXA IN VARCHAR2
)
AS
   V_QTCOMMIT NUMBER;
   V_COMMITA NUMBER;
   V_CDMUNICIPIO VARCHAR2(05);
   V_IDTRIBICMS VARCHAR2(01);
   V_VLR_BASE_ICMS NUMBER;
   V_VLR_ALIQ_ICMS NUMBER;
   V_VLR_ICMS NUMBER;
   V_COD_NAT_REC VARCHAR2(10);
   PROCEDURE COMMITAR
   AS
   BEGIN
      V_QTCOMMIT := V_QTCOMMIT + 1;
      IF V_QTCOMMIT = V_COMMITA THEN
         V_QTCOMMIT := 0;
         COMMIT;
      END IF;
   END;
BEGIN
   V_COMMITA := 5000;
   V_QTCOMMIT := 1; 

   IF INSTR(P_IDTIPOCAIXA, 'S') > 0 THEN
      DELETE
        FROM SAFX201 S
       WHERE EXISTS (SELECT 1
                       FROM FILIAL F
                      WHERE F.CDFILIAL = P_CDFILIAL
                        AND F.CDFILIALEXT = S.COD_ESTAB
                        AND TO_DATE(S.DATA_EMISSAO, 'YYYYMMDD') BETWEEN P_DTINICIAL AND P_DTFINAL);
      DELETE
        FROM SAFX202 S
       WHERE EXISTS (SELECT 1
                       FROM FILIAL F
                      WHERE F.CDFILIAL = P_CDFILIAL
                        AND F.CDFILIALEXT = S.COD_ESTAB
                        AND TO_DATE(S.DATA_EMISSAO, 'YYYYMMDD') BETWEEN P_DTINICIAL AND P_DTFINAL);
   END IF;

   IF INSTR(P_IDTIPOCAIXA, 'N') > 0 THEN
      DELETE
        FROM SAFX07 S
       WHERE EXISTS (SELECT 1
                       FROM FILIAL F
                      WHERE F.CDFILIAL = P_CDFILIAL
                        AND F.CDFILIALEXT = S.COD_ESTAB
                        AND TO_DATE(S.DATA_EMISSAO, 'YYYYMMDD') BETWEEN P_DTINICIAL AND P_DTFINAL);

      DELETE
        FROM SAFX08 S
       WHERE EXISTS (SELECT 1
                       FROM FILIAL F
                      WHERE F.CDFILIAL = P_CDFILIAL
                        AND F.CDFILIALEXT = S.COD_ESTAB
                        AND TO_DATE(S.DATA_FISCAL, 'YYYYMMDD') BETWEEN P_DTINICIAL AND P_DTFINAL);
   END IF;
   
   /* NOTAS DE TIPO DE EMISSAO SAT */
   FOR C_SAFX201 IN
      (SELECT '002' COD_EMPRESA, F.CDFILIALEXT AS COD_ESTAB, V.CDSERIESAT NUM_EQUIP, NRNOTAFISCALCE NUM_CUPOM,
              TO_CHAR(DTEMISSAONFCE, 'YYYYMMDD') DATA_EMISSAO, '59' COD_MODELO, DECODE(IDSITUVENDA, 'O', '00', '02') IND_SITUACAO_CUPOM, NMCONSVEND NOME_CLIENTE,
              NVL(NRINSCRCONS, REPLACE(REPLACE(REPLACE(F.NRINSJURFILI, '.', ''), '-', ''), '/', '')) CPF_CNPJ_CLIENTE, SUBSTR(NRACESSONFCE, 4, 44) NUM_AUTENTIC_NFE, V.CDFILIAL, V.CDCAIXA,V.NRSEQVENDA,
              VALORVARCHAR(SUM(TRUNC(IT.QTPRODVEND * (NVL(IT.VRUNITVEND,0) + NVL(IT.VRUNITVENDCL,0)),2)), 15, 2) AS VLR_TOT,
              VALORVARCHAR(SUM(NVL(IT.VRDESITVEND, 0)), 15, 2) VLR_DESC,
              VALORVARCHAR(SUM(NVL(IT.VRACRITVEND, 0)), 15, 2) VLR_ACRES,
              VALORVARCHAR(SUM(TRUNC(IT.QTPRODVEND * (NVL(IT.VRUNITVEND,0) + NVL(IT.VRUNITVENDCL,0)),2) - NVL(IT.VRDESITVEND,0) + NVL(IT.VRACRITVEND,0)), 15, 2) AS VLR_TOT_LIQ,
              '@' VLR_DESP_ACS
         FROM FILIAL F, VENDA V, ITEMVENDA IT
        WHERE F.CDFILIAL = P_CDFILIAL
          AND F.CDFILIAL = V.CDFILIAL
          AND DTENTRVENDA BETWEEN P_DTINICIAL AND P_DTFINAL
          AND V.CDFILIAL = IT.CDFILIAL
          AND V.CDCAIXA = IT.CDCAIXA
          AND V.NRSEQVENDA = IT.NRSEQVENDA
          AND V.IDSTATUSNFCE IN ('C', 'A')
          AND V.IDTPEMISVEND = 'S'
          AND V.IDSITUVENDA IN ('O', 'C')
          AND INSTR(P_IDTIPOCAIXA, 'S') > 0
         GROUP BY F.CDFILIALEXT, V.CDSERIESAT, NRNOTAFISCALCE,
              DTEMISSAONFCE, DECODE(IDSITUVENDA, 'O', '00', '02'), NMCONSVEND, NVL(NRINSCRCONS, REPLACE(REPLACE(REPLACE(F.NRINSJURFILI, '.', ''), '-', ''), '/', '')),
              SUBSTR(NRACESSONFCE, 4, 44), V.CDFILIAL, V.CDCAIXA,V.NRSEQVENDA) LOOP
      INSERT INTO SAFX201
         (COD_EMPRESA, COD_ESTAB, NUM_EQUIP, NUM_CUPOM,
          DATA_EMISSAO, COD_MODELO, IND_SITUACAO_CUPOM, NOME_CLIENTE,
          CPF_CNPJ_CLIENTE, NUM_AUTENTIC_NFE, VLR_TOT, VLR_DESC,
          VLR_ACRES, VLR_TOT_LIQ, VLR_DESP_ACS, DAT_GRAVACAO)
      VALUES
         (C_SAFX201.COD_EMPRESA, C_SAFX201.COD_ESTAB, C_SAFX201.NUM_EQUIP, C_SAFX201.NUM_CUPOM,
          C_SAFX201.DATA_EMISSAO, C_SAFX201.COD_MODELO, C_SAFX201.IND_SITUACAO_CUPOM, C_SAFX201.NOME_CLIENTE,
          C_SAFX201.CPF_CNPJ_CLIENTE, C_SAFX201.NUM_AUTENTIC_NFE, C_SAFX201.VLR_TOT, C_SAFX201.VLR_DESC,
          C_SAFX201.VLR_ACRES, C_SAFX201.VLR_TOT_LIQ, C_SAFX201.VLR_DESP_ACS, SYSDATE);
      COMMITAR;

      FOR C_SAFX202 IN
         (SELECT C_SAFX201.COD_EMPRESA, C_SAFX201.COD_ESTAB, C_SAFX201.NUM_EQUIP,
                 C_SAFX201.NUM_CUPOM, C_SAFX201.DATA_EMISSAO, RPAD(IT.NRSEQUITVEND, 5, ' ') NUM_ITEM,
                 '1' IND_PRODUTO, LTRIM(LPAD(P.CDPRODINTE, 18, '0')) COD_PRODUTO, '@' COD_SERVICO,
                 RPAD(CDCFOPPROD, 4, ' ') COD_CFO, '@' COD_CONTA,  '0' COD_SITUACAO_A,
                 RPAD(CDCSTPRODI, 2, ' ') COD_SITUACAO_B, VALORVARCHAR(IT.QTPRODVEND, 11, 6) QTDE, VALORVARCHAR(NVL(IT.VRUNITVEND,0), 15, 4) VLR_UNIT,
                 VALORVARCHAR(TRUNC(IT.QTPRODVEND * (NVL(IT.VRUNITVEND,0) + NVL(IT.VRUNITVENDCL,0)),2), 15, 2) VLR_ITEM,
                 VALORVARCHAR(NVL(IT.VRDESITVEND, 0), 15, 2) VLR_DESC,
                 VALORVARCHAR(NVL(IT.VRACRITVEND, 0), 15, 2) VLR_ACRES,
                 VALORVARCHAR(TRUNC(IT.QTPRODVEND * (NVL(IT.VRUNITVEND,0) + NVL(IT.VRUNITVENDCL,0)),2) - NVL(IT.VRDESITVEND,0) + NVL(IT.VRACRITVEND,0), 15, 2) VLR_TOT_LIQ,
                 VALORVARCHAR(NVL(II.VRBASECALCICMS, 0), 15, 2) VLR_BASE_ICMS,
                 VALORVARCHAR(ROUND(NVL(II.VRIMPOPRODIT, 0), 2), 15, 2) VLR_ICMS,
                 VALORVARCHAR(NVL(II.VRPEALPRODIT, 0), 3, 4) VLR_ALIQ_ICMS,
                 RPAD(II.CDCSTPRODPC, 2, ' ') COD_SIT_TRIB_PIS,
                 '@' QTD_BASE_PIS,
                 '@' VLR_ALIQ_PIS_R,
                 VALORVARCHAR(NVL(II.VRBASECALCICMS, 0), 15, 2) VLR_BASE_PIS,
                 VALORVARCHAR(II.VRIMPPIS, 15, 2) VLR_PIS,
                 VALORVARCHAR(II.VRPERPIS, 3, 4) VLR_ALIQ_PIS,
                 RPAD(II.CDCSTPRODPC, 2, ' ') COD_SIT_TRIB_COFINS,
                 '@' QTD_BASE_COFINS,
                 '@' VLR_ALIQ_COFINS_R,
                 VALORVARCHAR(NVL(II.VRBASECALCICMS, 0), 15, 2) VLR_BASE_COFINS,
                 VALORVARCHAR(II.VRIMPCOFINS, 15, 2) VLR_COFINS,
                 VALORVARCHAR(II.VRPERCOFINS, 3, 4) VLR_ALIQ_COFINS,
                 '@' VLR_BASE_PIS_ST,
                 '@' VLR_PIS_ST,
                 '@' VLR_ALIQ_PIS_ST,
                 '@' VLR_BASE_COFINS_ST,
                 '@' VLR_COFINS_ST,
                 '@' VLR_ALIQ_COFINS_ST,
                 '@' VLR_DESP_ACS,
                 '@' COD_OBSERVACAO,
                 R.CDNATUREC COD_NAT_REC,
                 '@' VLR_EXC_BASE_PISCOFINS,
                 '@' COD_MEDIDA
            FROM ITEMVENDA IT, ITVENDAIMPOS II, PRODUTO P LEFT JOIN RELACPRODITGEN R
                                                                 ON R.CDLIVROMAG = '0000000001'
                                                                AND R.CDPRODUTO = P.CDPRODUTO

           WHERE IT.CDFILIAL = C_SAFX201.CDFILIAL
             AND IT.CDCAIXA = C_SAFX201.CDCAIXA
             AND IT.NRSEQVENDA = C_SAFX201.NRSEQVENDA
             AND IT.CDFILIAL = II.CDFILIAL
             AND IT.CDCAIXA = II.CDCAIXA
             AND IT.NRSEQVENDA = II.NRSEQVENDA
             AND IT.NRSEQUITVEND = II.NRSEQUITVEND
             AND P.CDPRODUTO = IT.CDPRODUTO) LOOP
         IF C_SAFX202.COD_SITUACAO_B IN ('30', '40', '41', '50', '60') THEN
            V_VLR_BASE_ICMS := VALORVARCHAR(0, 15, 2);
            V_VLR_ICMS := VALORVARCHAR(0, 15, 2);
            V_VLR_ALIQ_ICMS := VALORVARCHAR(0, 3, 4);
         ELSE
            V_VLR_BASE_ICMS := C_SAFX202.VLR_BASE_ICMS;
            V_VLR_ICMS := C_SAFX202.VLR_ICMS;
            V_VLR_ALIQ_ICMS := C_SAFX202.VLR_ALIQ_ICMS;
         END IF;

         IF C_SAFX202.COD_SIT_TRIB_PIS NOT IN ('01') THEN
            V_COD_NAT_REC := C_SAFX202.COD_NAT_REC;
         ELSE
            V_COD_NAT_REC := '@';
         END IF;

         INSERT INTO SAFX202
            (COD_EMPRESA, COD_ESTAB, NUM_EQUIP,
             NUM_CUPOM, DATA_EMISSAO, NUM_ITEM,
             IND_PRODUTO, COD_PRODUTO, COD_SERVICO,
             COD_CFO, COD_CONTA, COD_SITUACAO_A,
             COD_SITUACAO_B, QTDE, VLR_UNIT, VLR_ITEM,
             VLR_DESC, VLR_ACRES, VLR_TOT_LIQ,
             VLR_BASE_ICMS,
             VLR_ICMS,
             VLR_ALIQ_ICMS,
             COD_SIT_TRIB_PIS,
             QTD_BASE_PIS,
             VLR_ALIQ_PIS_R,
             VLR_BASE_PIS,
             VLR_PIS,
             VLR_ALIQ_PIS,
             COD_SIT_TRIB_COFINS,
             QTD_BASE_COFINS,
             VLR_ALIQ_COFINS_R,
             VLR_BASE_COFINS,
             VLR_COFINS,
             VLR_ALIQ_COFINS,
             VLR_BASE_PIS_ST,
             VLR_PIS_ST,
             VLR_ALIQ_PIS_ST,
             VLR_BASE_COFINS_ST,
             VLR_COFINS_ST,
             VLR_ALIQ_COFINS_ST,
             VLR_DESP_ACS,
             COD_OBSERVACAO,
             DAT_GRAVACAO,
             COD_NAT_REC,
             VLR_EXC_BASE_PISCOFINS,
             COD_MEDIDA)
         VALUES
            (C_SAFX202.COD_EMPRESA, C_SAFX202.COD_ESTAB, C_SAFX202.NUM_EQUIP,
             C_SAFX202.NUM_CUPOM, C_SAFX202.DATA_EMISSAO, C_SAFX202.NUM_ITEM,
             C_SAFX202.IND_PRODUTO, C_SAFX202.COD_PRODUTO, C_SAFX202.COD_SERVICO,
             C_SAFX202.COD_CFO, C_SAFX202.COD_CONTA, C_SAFX202.COD_SITUACAO_A,
             C_SAFX202.COD_SITUACAO_B, C_SAFX202.QTDE, C_SAFX202.VLR_UNIT, C_SAFX202.VLR_ITEM,
             C_SAFX202.VLR_DESC, C_SAFX202.VLR_ACRES, C_SAFX202.VLR_TOT_LIQ,
             V_VLR_BASE_ICMS,
             V_VLR_ICMS,
             V_VLR_ALIQ_ICMS,
             C_SAFX202.COD_SIT_TRIB_PIS,
             C_SAFX202.QTD_BASE_PIS,
             C_SAFX202.VLR_ALIQ_PIS_R,
             C_SAFX202.VLR_BASE_PIS,
             C_SAFX202.VLR_PIS,
             C_SAFX202.VLR_ALIQ_PIS,
             C_SAFX202.COD_SIT_TRIB_COFINS,
             C_SAFX202.QTD_BASE_COFINS,
             C_SAFX202.VLR_ALIQ_COFINS_R,
             C_SAFX202.VLR_BASE_COFINS,
             C_SAFX202.VLR_COFINS,
             C_SAFX202.VLR_ALIQ_COFINS,
             C_SAFX202.VLR_BASE_PIS_ST,
             C_SAFX202.VLR_PIS_ST,
             C_SAFX202.VLR_ALIQ_PIS_ST,
             C_SAFX202.VLR_BASE_COFINS_ST,
             C_SAFX202.VLR_COFINS_ST,
             C_SAFX202.VLR_ALIQ_COFINS_ST,
             C_SAFX202.VLR_DESP_ACS,
             C_SAFX202.COD_OBSERVACAO,
             SYSDATE,
             V_COD_NAT_REC,
             C_SAFX202.VLR_EXC_BASE_PISCOFINS,
             C_SAFX202.COD_MEDIDA);
         COMMITAR;
      END LOOP;
   END LOOP;

   /* NOTAS DE TIPO DE EMISSAO NFC-E */
   FOR C_SAFX07 IN
      (SELECT '002' COD_EMPRESA, F.CDFILIALEXT AS COD_ESTAB,         '9' MOVTO_E_S,       '1' NORM_DEV,
              'NFCE' COD_DOCTO, '5' IDENT_FIS_JUR, REPLACE(REPLACE(REPLACE(F.NRINSJURFILI, '.', ''), '-', ''), '/', '') COD_FIS_JUR, V.NRNOTAFISCALCE NUM_DOCFIS,
              V.CDSERIENFCE SERIE_DOCFIS, '@' SUB_SERIE_DOCFIS,      TO_CHAR(DTEMISSAONFCE, 'YYYYMMDD') DATA_EMISSAO, '1' COD_CLASS_DOC_FIS,
              '65' COD_MODELO,            NULL COD_CFO,     '@' COD_NATUREZA_OP, '@' NUM_DOCFIS_REF,
              '@' SERIE_DOCFIS_REF,       '@' S_SER_DOCFIS_REF,      '@' NUM_DEC_IMP_REF, TO_CHAR(DTVENDA, 'YYYYMMDD') DATA_SAIDA_REC,
              '@' INSC_ESTAD_SUBSTIT,
              VALORVARCHAR(SUM(TRUNC(IT.QTPRODVEND * (NVL(IT.VRUNITVEND,0) + NVL(IT.VRUNITVENDCL,0)),2) - NVL(IT.VRDESITVEND,0) + NVL(IT.VRACRITVEND,0)), 15, 2) VLR_PRODUTO,
              VALORVARCHAR(SUM(TRUNC(IT.QTPRODVEND * (NVL(IT.VRUNITVEND,0) + NVL(IT.VRUNITVENDCL,0)),2) - NVL(IT.VRDESITVEND,0) + NVL(IT.VRACRITVEND,0)), 15, 2) VLR_TOT_NOTA,
              '@' VLR_FRETE,    '@' VLR_SEGURO,   '@' VLR_OUTRAS,    '@' VLR_BASE_DIF_FRETE,
              VALORVARCHAR(SUM(NVL(IT.VRDESITVEND, 0)), 15, 2) VLR_DESCONTO, 'N' CONTRIB_FINAL, DECODE(V.IDSITUVENDA, 'O', 'N', 'S') SITUACAO, '@' COD_INDICE,
              '@' VLR_NOTA_CONV,'@' COD_CONTA,    '@' VLR_ALIQ_ICMS,                      '@' VLR_ICMS,
              '@' DIF_ALIQ_ICMS,'@' OBS_ICMS,     '@' COD_APUR_ICMS,                      '@' VLR_ALIQ_IPI,
              '@' VLR_IPI,      '@' OBS_IPI,      '@' COD_APUR_IPI,                       '@' VLR_ALIQ_IR,
              '@' VLR_IR,       '@' VLR_ALIQ_ISS, '@' VLR_ISS,                            '@' VLR_ALIQ_SUB_ICMS,
              '@' VLR_SUBST_ICMS, '@' OBS_SUBST_ICMS,  '@' COD_APUR_SUB_ICMS,             '@' BASE_TRIB_ICMS,
              '@' BASE_ISEN_ICMS, '@' BASE_OUTR_ICMS,  NULL BASE_REDU_ICMS,      '@' BASE_TRIB_IPI,
              '@' BASE_ISEN_IPI,  '@' BASE_OUTR_IPI,   '@' BASE_REDU_IPI,                 '@' BASE_TRIB_IR,
              '@' BASE_ISEN_IR,   '@' BASE_TRIB_ISS,   '@' BASE_ISEN_ISS,                 '@' BASE_REAL_TERC_ISS,
              '@' BASE_SUB_TRIB_ICMS, '@' NUM_MAQ_REG, '@' NUM_CUPON_FISC,                '@' IND_MODELO_CUPOM,
              '@' VLR_CONTAB_COMPL,    NULL NUM_CONTROLE_DOCTO, '@' VLR_ALIQ_DESTINO,     '@' IND_NF_ESPECIAL,
              '@' IND_TP_FRETE,       '@' COD_MUNICIPIO,        '@' IND_TRANSF_CRED,      '@' DAT_DI,
              '@' VLR_TOM_SERVICO,    '@' DAT_ESCR_EXTEMP,      '@' COD_TRIB_INT,         '@' COD_REGIAO,
              '@' DAT_AUTENTIC,       '@' COD_CANAL_DISTRIB,    'N' IND_CRED_ICMSS,       '@' VLR_ICMS_NDESTAC,
              '@' VLR_IPI_NDESTAC,    '@' VLR_BASE_INSS,        '@' VLR_ALIQ_INSS,        '@' VLR_INSS_RETIDO,
              '@' VLR_MAT_APLIC_ISS,  '@' VLR_SUBEMPR_ISS,      '@' IND_MUNIC_ISS,        '@' IND_CLASSE_OP_ISS,
              '@' VLR_OUTROS1,         NULL DAT_FATO_GERADOR,   NULL DAT_CANCELAMENTO,    '@' NUM_PAGINA,
              '@' NUM_LIVRO,          '@' NRO_AIDF_NF,          '@' DAT_VALID_DOC_AIDF,   '1' IND_FATURA,
              '@' COD_QUITACAO,       '@' NUM_SELO_CONT_ICMS,   '@' VLR_BASE_PIS,         '@' VLR_PIS,
              '@' VLR_BASE_COFINS,    '@' VLR_COFINS,           '@' BASE_ICMS_ORIGDEST,   '@' VLR_ICMS_ORIGDEST,
              '@' ALIQ_ICMS_ORIGDEST, '@' VLR_DESC_CONDIC,     '@' VLR_BASE_ISE_ICMSS,   '@' VLR_BASE_OUT_ICMSS,
              '@' VLR_RED_BASE_ICMSS,  '@' PERC_RED_BASE_ICMS,  '@' IND_FISJUR_CPDIR,     '@' COD_FISJUR_CPDIR,
              '@' IND_MEDIDAJUDICIAL,  EF.SGESTADO UF_ORIG_DEST,'@' IND_COMPRA_VENDA,
              '@' COD_TP_DISP_SEG,     '@' NUM_CTR_DISP,        '@' NUM_FIM_DOCTO,        EF.SGESTADO UF_DESTINO,
              '@' SERIE_CTR_DISP,      '@' SUB_SERIE_CTR_DISP,  '@' IND_SITUACAO_ESP,     '@' INSC_ESTADUAL,
              '@' COD_PAGTO_INSS,      '@' DAT_INTERN_AM,       '@' IND_FISJUR_LSG,      '@' COD_FISJUR_LSG,
              '@' COMPROV_EXP,         '@' NUM_FINAL_CRT_DISP,  '@' NUM_ALVARA,           '@' NOTIFICA_SEFAZ,
              '@' INTERNA_SUFRAMA,     '@' IND_NOTA_SERVICO,    '@' COD_MOTIVO,           '@' COD_AMPARO,
              '@' UF_AMPARO_LEGAL,     '@' SEQ_ARQ,   '@' OBS_COMPL_MOTIVO,     '@' IND_TP_RET,
              '@' IND_TP_TOMADOR,      '@' COD_ANTEC_ST,        '@' CNPJ_ARMAZ_ORIG,      '@' UF_ARMAZ_ORIG,
              '@' INS_EST_ARMAZ_ORIG,  '@' CNPJ_ARMAZ_DEST,     '@' UF_ARMAZ_DEST,       '@' INS_EST_ARMAZ_DEST,
              '@' OBS_INF_ADIC_NF,     '@' VLR_BASE_INSS_2,     '@' VLR_ALIQ_INSS_2,      '@' VLR_INSS_RETIDO_2,
              '@' COD_PAGTO_INSS_2,    '@' VLR_BASE_PIS_ST,     '@' VLR_ALIQ_PIS_ST,      '@' VLR_PIS_ST,
              '@' VLR_BASE_COFINS_ST,  '@' VLR_ALIQ_COFINS_ST,  '@' VLR_COFINS_ST,        '@' VLR_BASE_CSLL,
              '@' VLR_ALIQ_CSLL,       '@' VLR_CSLL,            '@' VLR_ALIQ_PIS,         '@' VLR_ALIQ_COFINS,
              '@' BASE_ICMSS_SUBSTITUIDO, '@' VLR_ICMSS_SUBSTITUIDO, '@' COD_CEI,         '@' VLR_JUROS_INSS,
              '@' VLR_MULTA_INSS,      '@' DT_PAGTO_NF,         '@' IND_SITUACAO_ESP_ST,  '@' VLR_ICMSS_NDESTAC,
              '@' IND_DOCTO_REC,       '@' DAT_PGTO_GNRE_DARJ,   '@' HORA_SAIDA,           DECODE(IDSITUVENDA, 'O', '00', '02') COD_SIT_DOCFIS,
              '@' COD_OBSERVACAO,      '@' COD_SITUACAO_A,      '@' COD_SITUACAO_B,       '@' NUM_CONT_REDUC,
              M.CDMUNICIBGE COD_MUNICIPIO_ORIG, M.CDMUNICIBGE COD_MUNICIPIO_DEST,         '@' COD_CFPS, '@' NUM_LANCAMENTO,
              '@' VLR_MAT_PROP,        '@' VLR_MAT_TERC,        '@' VLR_BASE_ISS_RETIDO,  '@' VLR_ISS_RETIDO,
              '@' VLR_DEDUCAO_ISS,     '@' COD_MUNIC_ARMAZ_ORIG,'@' INS_MUNIC_ARMAZ_ORIG, '@' COD_MUNIC_ARMAZ_DEST,
              '@' INS_MUNIC_ARMAZ_DEST,'@' COD_CLASSE_CONSUMO,  '@' IND_ESPECIF_RECEITA,  '@' NUM_CONTRATO,
              '@' COD_AREA_TERMINAL,   '@' COD_TP_UTIL,         '@' GRUPO_TENSAO,         '@' DATA_CONSUMO_INI,
              '@' DATA_CONSUMO_FIM,    '@' DATA_CONSUMO_LEIT,   '@' QTD_CONTRATADA_PONTA, '@' QTD_CONTRATADA_FPONTA,
              '@' QTD_CONSUMO_TOTAL,   '@' UF_CONSUMO,          '@' COD_MUNIC_CONSUMO,    '@' COD_OPER_ESP_ST,
              '@' ATO_NORMATIVO,       '@' NUM_ATO_NORMATIVO,   '@' ANO_ATO_NORMATIVO,    '@' CAPITULACAO_NORMA,
              '@' VLR_OUTRAS_ENTID,    '@' VLR_TERCEIROS,       '@' IND_TP_COMPL_ICMS,    '@' VLR_BASE_CIDE,
              '@' VLR_ALIQ_CIDE,       '@' VLR_CIDE,            '@' COD_VERIFIC_NFE,      '@' COD_TP_RPS_NFE,
              '@' NUM_RPS_NFE,         '@' SERIE_RPS_NFE,       '@' DAT_EMISSAO_RPS_NFE,  '@' DSC_SERVICO_NFE,
              V.NRACESSONFCE NUM_AUTENTIC_NFE, NULL NUM_DV_NFE, '@' MODELO_NF_DMS,        '65' COD_MODELO_COTEPE,
              '@' VLR_COMISSAO,        '@' IND_NFE_DENEG_INUT,  '@' IND_NF_REG_ESPECIAL,  '@' VLR_ABAT_NTRIBUTADO,
              '@' VLR_OUTROS_ICMS,    '@' HORA_EMISSAO,        '@' OBS_DADOS_FATURA,     '@' IND_FIS_CONCES,
              '@' COD_FIS_CONCES,      '@' COD_AUTENTIC,        '@' IND_PORT_CAT44,       '@' VLR_BASE_INSS_RURAL,
              '@' VLR_ALIQ_INSS_RURAL, '@' VLR_INSS_RURAL,      '@' COD_CLASSE_CONSUMO_SEF_PE, '@' VLR_PIS_RETIDO,
              '@' VLR_COFINS_RETIDO,   TO_CHAR(V.DTENTRVENDA, 'YYYYMMDD') DAT_LANC_PIS_COFINS,  '@' IND_PIS_COFINS_EXTEMP, '@' COD_SIT_PIS,
              '@' COD_SIT_COFINS,      '@' IND_NAT_FRETE, '@' COD_NAT_REC,      '@' IND_VENDA_CANC,
              '@' IND_NAT_BASE_CRED,   'N' IND_NF_CONTINGENCIA,  '@' VLR_ACRESCIMO,        '@' VLR_ANTECIP_TRIB,
              '@' IND_IPI_NDESTAC_DF, '@' DSC_RESERVADO1,      '@' DSC_RESERVADO2,       '@' DSC_RESERVADO3,
              '@' NUM_NFTS,            '@' IND_NF_VENDA_TERCEIROS, '@' DSC_RESERVADO4,    '@' DSC_RESERVADO5,
              '@' DSC_RESERVADO6,      '@' DSC_RESERVADO7,      '@' DSC_RESERVADO8,       '@' IDENTIF_DOCFIS,
              'TF' COD_SISTEMA_ORIG,    '@' COD_SCP,             '@' IND_PREST_SERV,       '@' IND_TIPO_PROC,
              '@' NUM_PROC_JUR,        '@' IND_DEC_PROC,        '@' IND_TIPO_AQUIS,       '@' VLR_DESC_GILRAT,
              '@' VLR_DESC_SENAR,      '@' CNPJ_SUBEMPREITEIRO, '@' CNPJ_CPF_PROPRIETARIO_CNO, '@' VLR_RET_SUBEMPREITADO,
              '@' NUM_DOCFIS_SERV,     '@' VLR_FCP_UF_DEST,     '@' VLR_ICMS_UF_DEST,     '@' VLR_ICMS_UF_ORIG,
              '@' VLR_CONTRIB_PREV,    '@' VLR_GILRAT,          '@' VLR_CONTRIB_SENAR,    V.NRINSCRCONS CPF_CNPJ,

              '@' VLR_OUTROS2,         '@' VLR_OUTROS3,         '@' VLR_OUTROS4,          '@' VLR_OUTROS5,
              '@' VLR_ALIQ_OUTROS1,    '@' VLR_ALIQ_OUTROS2,    '@' IND_ATO_COTEPE,       '@' HORA_SAIDA_REC,
              '@' CATEGORIA_TRAB,      '@' NUM_CERTIF_QUAL,     NULL NUM_PROCESSO,         '@' DATA_TRAB,
              '@' OBS_REINF,           '@' VLR_TOT_ADIC,        '@' VLR_RET_SERV,         '@' VLR_SERV_15,
              '@' VLR_SERV_20,         '@' VLR_SERV_25,         '@' VLR_IPI_DEV,          '@' VLR_SEST,
              '@' VLR_SENAT,

              V.CDFILIAL, V.CDCAIXA,V.NRSEQVENDA
         FROM FILIAL F, VENDA V, ITEMVENDA IT, ENDEFILI EF, MUNICIPIO M
        WHERE F.CDFILIAL = P_CDFILIAL
          AND F.CDFILIAL = V.CDFILIAL
          AND V.DTENTRVENDA BETWEEN P_DTINICIAL AND P_DTFINAL
          AND V.CDFILIAL = IT.CDFILIAL
          AND V.CDCAIXA = IT.CDCAIXA
          AND V.NRSEQVENDA = IT.NRSEQVENDA
          AND V.IDTPEMISVEND = 'N'
          AND INSTR(P_IDTIPOCAIXA, 'N') > 0
          AND V.IDTPAMBNFCE = '1'
          AND V.IDSTATUSNFCE IN ('C', 'A')
          AND V.IDSITUVENDA IN ('O', 'C')
          AND V.CDFILIAL = EF.CDFILIAL
          AND EF.IDTPENDEFILI = 'P'
          AND EF.CDPAIS = M.CDPAIS
          AND EF.SGESTADO = M.SGESTADO
          AND EF.CDMUNICIPIO = M.CDMUNICIPIO
         GROUP BY F.CDFILIALEXT, REPLACE(REPLACE(REPLACE(F.NRINSJURFILI, '.', ''), '-', ''), '/', ''), V.NRNOTAFISCALCE, V.CDSERIENFCE, TO_CHAR(DTEMISSAONFCE, 'YYYYMMDD'),
                  TO_CHAR(DTVENDA, 'YYYYMMDD'), DECODE(V.IDSITUVENDA, 'O', 'N', 'S'), EF.SGESTADO,
                  EF.SGESTADO, DECODE(IDSITUVENDA, 'O', '00', '02'), M.CDMUNICIBGE, M.CDMUNICIBGE, V.NRACESSONFCE,
                  TO_CHAR(V.DTENTRVENDA, 'YYYYMMDD'), V.NRINSCRCONS, V.CDFILIAL, V.CDCAIXA,V.NRSEQVENDA) LOOP
      V_CDMUNICIPIO := C_SAFX07.COD_MUNICIPIO;
      IF LENGTH(V_CDMUNICIPIO) > 5 THEN
         V_CDMUNICIPIO := SUBSTR(V_CDMUNICIPIO, -5, 5);
      END IF;
      INSERT INTO SAFX07
         (COD_EMPRESA,      COD_ESTAB,        MOVTO_E_S,       NORM_DEV,
          COD_DOCTO,        IDENT_FIS_JUR,    COD_FIS_JUR,     NUM_DOCFIS,
          SERIE_DOCFIS,     SUB_SERIE_DOCFIS, DATA_EMISSAO,    COD_CLASS_DOC_FIS,
          COD_MODELO,       COD_CFO,          COD_NATUREZA_OP, NUM_DOCFIS_REF,
          SERIE_DOCFIS_REF, S_SER_DOCFIS_REF, NUM_DEC_IMP_REF, DATA_SAIDA_REC,
          INSC_ESTAD_SUBSTIT,
          VLR_PRODUTO,
          VLR_TOT_NOTA,
          VLR_FRETE,        VLR_SEGURO,       VLR_OUTRAS,      VLR_BASE_DIF_FRETE,
          VLR_DESCONTO,     CONTRIB_FINAL,    SITUACAO,        COD_INDICE,
          VLR_NOTA_CONV,    COD_CONTA,        VLR_ALIQ_ICMS,   VLR_ICMS,
          DIF_ALIQ_ICMS,    OBS_ICMS,         COD_APUR_ICMS,   VLR_ALIQ_IPI,
          VLR_IPI,          OBS_IPI,          COD_APUR_IPI,    VLR_ALIQ_IR,
          VLR_IR,           VLR_ALIQ_ISS,     VLR_ISS,         VLR_ALIQ_SUB_ICMS,
          VLR_SUBST_ICMS,   OBS_SUBST_ICMS,   COD_APUR_SUB_ICMS, BASE_TRIB_ICMS,
          BASE_ISEN_ICMS,   BASE_OUTR_ICMS,   BASE_REDU_ICMS,  BASE_TRIB_IPI,
          BASE_ISEN_IPI,    BASE_OUTR_IPI,    BASE_REDU_IPI,   BASE_TRIB_IR,
          BASE_ISEN_IR,     BASE_TRIB_ISS,    BASE_ISEN_ISS,   BASE_REAL_TERC_ISS,
          BASE_SUB_TRIB_ICMS, NUM_MAQ_REG,    NUM_CUPON_FISC,  IND_MODELO_CUPOM,
          VLR_CONTAB_COMPL, NUM_CONTROLE_DOCTO, VLR_ALIQ_DESTINO, IND_NF_ESPECIAL,
          IND_TP_FRETE,     COD_MUNICIPIO,    IND_TRANSF_CRED, DAT_DI,
          VLR_TOM_SERVICO,  DAT_ESCR_EXTEMP,  COD_TRIB_INT,    COD_REGIAO,
          DAT_AUTENTIC,     COD_CANAL_DISTRIB,IND_CRED_ICMSS,  VLR_ICMS_NDESTAC,
          VLR_IPI_NDESTAC,  VLR_BASE_INSS,    VLR_ALIQ_INSS,   VLR_INSS_RETIDO,
          VLR_MAT_APLIC_ISS, VLR_SUBEMPR_ISS, IND_MUNIC_ISS,   IND_CLASSE_OP_ISS,
          VLR_OUTROS1,      DAT_FATO_GERADOR, DAT_CANCELAMENTO,NUM_PAGINA,
          NUM_LIVRO,        NRO_AIDF_NF,      DAT_VALID_DOC_AIDF, IND_FATURA,
          COD_QUITACAO,     NUM_SELO_CONT_ICMS, VLR_BASE_PIS,       VLR_PIS,
          VLR_BASE_COFINS,  VLR_COFINS,         BASE_ICMS_ORIGDEST, VLR_ICMS_ORIGDEST,
          ALIQ_ICMS_ORIGDEST, VLR_DESC_CONDIC, VLR_BASE_ISE_ICMSS, VLR_BASE_OUT_ICMSS,
          VLR_RED_BASE_ICMSS,  PERC_RED_BASE_ICMS, IND_FISJUR_CPDIR, COD_FISJUR_CPDIR,
          IND_MEDIDAJUDICIAL, UF_ORIG_DEST,        IND_COMPRA_VENDA,
          COD_TP_DISP_SEG,  NUM_CTR_DISP,       NUM_FIM_DOCTO,      UF_DESTINO,
          SERIE_CTR_DISP,   SUB_SERIE_CTR_DISP, IND_SITUACAO_ESP,   INSC_ESTADUAL,
          COD_PAGTO_INSS,   DAT_INTERN_AM,      IND_FISJUR_LSG,    COD_FISJUR_LSG,
          COMPROV_EXP,      NUM_FINAL_CRT_DISP, NUM_ALVARA,         NOTIFICA_SEFAZ,
          INTERNA_SUFRAMA,  IND_NOTA_SERVICO,   COD_MOTIVO,         COD_AMPARO,
          UF_AMPARO_LEGAL,  SEQ_ARQ,            OBS_COMPL_MOTIVO,   IND_TP_RET,
          IND_TP_TOMADOR,   COD_ANTEC_ST,       CNPJ_ARMAZ_ORIG,    UF_ARMAZ_ORIG,
          INS_EST_ARMAZ_ORIG,   CNPJ_ARMAZ_DEST,      UF_ARMAZ_DEST,        INS_EST_ARMAZ_DEST,
          OBS_INF_ADIC_NF,      VLR_BASE_INSS_2,      VLR_ALIQ_INSS_2,       VLR_INSS_RETIDO_2,
          COD_PAGTO_INSS_2,     VLR_BASE_PIS_ST,      VLR_ALIQ_PIS_ST,       VLR_PIS_ST,
          VLR_BASE_COFINS_ST,   VLR_ALIQ_COFINS_ST,   VLR_COFINS_ST,         VLR_BASE_CSLL,
          VLR_ALIQ_CSLL,        VLR_CSLL,             VLR_ALIQ_PIS,          VLR_ALIQ_COFINS,
          BASE_ICMSS_SUBSTITUIDO,  VLR_ICMSS_SUBSTITUIDO,  COD_CEI,          VLR_JUROS_INSS,
          VLR_MULTA_INSS,       DT_PAGTO_NF,          IND_SITUACAO_ESP_ST,   VLR_ICMSS_NDESTAC,
          IND_DOCTO_REC,        DAT_PGTO_GNRE_DARJ,   HORA_SAIDA,            COD_SIT_DOCFIS,
          COD_OBSERVACAO,       COD_SITUACAO_A,       COD_SITUACAO_B,        NUM_CONT_REDUC,
          COD_MUNICIPIO_ORIG,   COD_MUNICIPIO_DEST,   COD_CFPS,              NUM_LANCAMENTO,
          VLR_MAT_PROP,         VLR_MAT_TERC,         VLR_BASE_ISS_RETIDO,   VLR_ISS_RETIDO,
          VLR_DEDUCAO_ISS,      COD_MUNIC_ARMAZ_ORIG, INS_MUNIC_ARMAZ_ORIG,  COD_MUNIC_ARMAZ_DEST,
          INS_MUNIC_ARMAZ_DEST, COD_CLASSE_CONSUMO,   IND_ESPECIF_RECEITA,   NUM_CONTRATO,
          COD_AREA_TERMINAL,    COD_TP_UTIL,          GRUPO_TENSAO,          DATA_CONSUMO_INI,
          DATA_CONSUMO_FIM,     DATA_CONSUMO_LEIT,    QTD_CONTRATADA_PONTA,  QTD_CONTRATADA_FPONTA,
          QTD_CONSUMO_TOTAL,    UF_CONSUMO,           COD_MUNIC_CONSUMO,     COD_OPER_ESP_ST,
          ATO_NORMATIVO,        NUM_ATO_NORMATIVO,    ANO_ATO_NORMATIVO,     CAPITULACAO_NORMA,
          VLR_OUTRAS_ENTID,     VLR_TERCEIROS,        IND_TP_COMPL_ICMS,     VLR_BASE_CIDE,
          VLR_ALIQ_CIDE,        VLR_CIDE,             COD_VERIFIC_NFE,       COD_TP_RPS_NFE,
          NUM_RPS_NFE,          SERIE_RPS_NFE,        DAT_EMISSAO_RPS_NFE,   DSC_SERVICO_NFE,
          NUM_AUTENTIC_NFE,     NUM_DV_NFE,           MODELO_NF_DMS,         COD_MODELO_COTEPE,
          VLR_COMISSAO,         IND_NFE_DENEG_INUT,   IND_NF_REG_ESPECIAL,   VLR_ABAT_NTRIBUTADO,
          VLR_OUTROS_ICMS,     HORA_EMISSAO,         OBS_DADOS_FATURA,      IND_FIS_CONCES,
          COD_FIS_CONCES,       COD_AUTENTIC,         IND_PORT_CAT44,        VLR_BASE_INSS_RURAL,
          VLR_ALIQ_INSS_RURAL,  VLR_INSS_RURAL,      COD_CLASSE_CONSUMO_SEF_PE,  VLR_PIS_RETIDO,
          VLR_COFINS_RETIDO,    DAT_LANC_PIS_COFINS,  IND_PIS_COFINS_EXTEMP, COD_SIT_PIS,
          COD_SIT_COFINS,       IND_NAT_FRETE,        COD_NAT_REC,           IND_VENDA_CANC,
          IND_NAT_BASE_CRED,    IND_NF_CONTINGENCIA,   VLR_ACRESCIMO,         VLR_ANTECIP_TRIB,
          IND_IPI_NDESTAC_DF,  DSC_RESERVADO1,       DSC_RESERVADO2,        DSC_RESERVADO3,
          NUM_NFTS,             IND_NF_VENDA_TERCEIROS,  DSC_RESERVADO4,     DSC_RESERVADO5,
          DSC_RESERVADO6,       DSC_RESERVADO7,       DSC_RESERVADO8,        IDENTIF_DOCFIS,
          COD_SISTEMA_ORIG,      COD_SCP,              IND_PREST_SERV,       IND_TIPO_PROC,
          NUM_PROC_JUR,         IND_DEC_PROC,         IND_TIPO_AQUIS,        VLR_DESC_GILRAT,
          VLR_DESC_SENAR,       CNPJ_SUBEMPREITEIRO,  CNPJ_CPF_PROPRIETARIO_CNO,  VLR_RET_SUBEMPREITADO,
          NUM_DOCFIS_SERV,      VLR_FCP_UF_DEST,      VLR_ICMS_UF_DEST,      VLR_ICMS_UF_ORIG,
          VLR_CONTRIB_PREV,     VLR_GILRAT,           VLR_CONTRIB_SENAR,     CPF_CNPJ,
          VLR_OUTROS2,          VLR_OUTROS3,          VLR_OUTROS4,           VLR_OUTROS5,
          VLR_ALIQ_OUTROS1,     VLR_ALIQ_OUTROS2,     IND_ATO_COTEPE,        HORA_SAIDA_REC,
          CATEGORIA_TRAB,       NUM_CERTIF_QUAL,      NUM_PROCESSO,          DATA_TRAB,
          OBS_REINF,            VLR_TOT_ADIC,         VLR_RET_SERV,          VLR_SERV_15,
          VLR_SERV_20,          VLR_SERV_25,          VLR_IPI_DEV,           VLR_SEST,
          VLR_SENAT, DAT_GRAVACAO)
      VALUES
         (C_SAFX07.COD_EMPRESA,   C_SAFX07.COD_ESTAB,        C_SAFX07.MOVTO_E_S,     C_SAFX07.NORM_DEV,
          C_SAFX07.COD_DOCTO,     C_SAFX07.IDENT_FIS_JUR,    C_SAFX07.COD_FIS_JUR,   C_SAFX07.NUM_DOCFIS,
          C_SAFX07.SERIE_DOCFIS,  C_SAFX07.SUB_SERIE_DOCFIS, C_SAFX07.DATA_EMISSAO,  C_SAFX07.COD_CLASS_DOC_FIS,
          C_SAFX07.COD_MODELO,    C_SAFX07.COD_CFO,          C_SAFX07.COD_NATUREZA_OP, C_SAFX07.NUM_DOCFIS_REF,
          C_SAFX07.SERIE_DOCFIS_REF,   C_SAFX07.S_SER_DOCFIS_REF, C_SAFX07.NUM_DEC_IMP_REF, C_SAFX07.DATA_SAIDA_REC,
          C_SAFX07.INSC_ESTAD_SUBSTIT,
          C_SAFX07.VLR_PRODUTO,
          C_SAFX07.VLR_TOT_NOTA,
          C_SAFX07.VLR_FRETE,          C_SAFX07.VLR_SEGURO,       C_SAFX07.VLR_OUTRAS,      C_SAFX07.VLR_BASE_DIF_FRETE,
          C_SAFX07.VLR_DESCONTO,       C_SAFX07.CONTRIB_FINAL,    C_SAFX07.SITUACAO,        C_SAFX07.COD_INDICE,
          C_SAFX07.VLR_NOTA_CONV,      C_SAFX07.COD_CONTA,        C_SAFX07.VLR_ALIQ_ICMS,   C_SAFX07.VLR_ICMS,
          C_SAFX07.DIF_ALIQ_ICMS,      C_SAFX07.OBS_ICMS,         C_SAFX07.COD_APUR_ICMS,   C_SAFX07.VLR_ALIQ_IPI,
          C_SAFX07.VLR_IPI,            C_SAFX07.OBS_IPI,          C_SAFX07.COD_APUR_IPI,    C_SAFX07.VLR_ALIQ_IR,
          C_SAFX07.VLR_IR,             C_SAFX07.VLR_ALIQ_ISS,     C_SAFX07.VLR_ISS,         C_SAFX07.VLR_ALIQ_SUB_ICMS,
          C_SAFX07.VLR_SUBST_ICMS,     C_SAFX07.OBS_SUBST_ICMS,   C_SAFX07.COD_APUR_SUB_ICMS, C_SAFX07.BASE_TRIB_ICMS,
          C_SAFX07.BASE_ISEN_ICMS,     C_SAFX07.BASE_OUTR_ICMS,   C_SAFX07.BASE_REDU_ICMS,  C_SAFX07.BASE_TRIB_IPI,
          C_SAFX07.BASE_ISEN_IPI,      C_SAFX07.BASE_OUTR_IPI,    C_SAFX07.BASE_REDU_IPI,   C_SAFX07.BASE_TRIB_IR,
          C_SAFX07.BASE_ISEN_IR,       C_SAFX07.BASE_TRIB_ISS,    C_SAFX07.BASE_ISEN_ISS,   C_SAFX07.BASE_REAL_TERC_ISS,
          C_SAFX07.BASE_SUB_TRIB_ICMS, C_SAFX07.NUM_MAQ_REG,      C_SAFX07.NUM_CUPON_FISC,  C_SAFX07.IND_MODELO_CUPOM,
          C_SAFX07.VLR_CONTAB_COMPL,   C_SAFX07.NUM_CONTROLE_DOCTO, C_SAFX07.VLR_ALIQ_DESTINO,C_SAFX07.IND_NF_ESPECIAL,
          C_SAFX07.IND_TP_FRETE,       C_SAFX07.COD_MUNICIPIO,    C_SAFX07.IND_TRANSF_CRED, C_SAFX07.DAT_DI,
          C_SAFX07.VLR_TOM_SERVICO,    C_SAFX07.DAT_ESCR_EXTEMP,  C_SAFX07.COD_TRIB_INT,    C_SAFX07.COD_REGIAO,
          C_SAFX07.DAT_AUTENTIC,       C_SAFX07.COD_CANAL_DISTRIB,C_SAFX07.IND_CRED_ICMSS,  C_SAFX07.VLR_ICMS_NDESTAC,
          C_SAFX07.VLR_IPI_NDESTAC,    C_SAFX07.VLR_BASE_INSS,    C_SAFX07.VLR_ALIQ_INSS,   C_SAFX07.VLR_INSS_RETIDO,
          C_SAFX07.VLR_MAT_APLIC_ISS,  C_SAFX07.VLR_SUBEMPR_ISS,  C_SAFX07.IND_MUNIC_ISS,   C_SAFX07.IND_CLASSE_OP_ISS,
          C_SAFX07.VLR_OUTROS1,        C_SAFX07.DAT_FATO_GERADOR, C_SAFX07.DAT_CANCELAMENTO,C_SAFX07.NUM_PAGINA,
          C_SAFX07.NUM_LIVRO,          C_SAFX07.NRO_AIDF_NF,      C_SAFX07.DAT_VALID_DOC_AIDF, C_SAFX07.IND_FATURA,
          C_SAFX07.COD_QUITACAO,       C_SAFX07.NUM_SELO_CONT_ICMS, C_SAFX07.VLR_BASE_PIS,  C_SAFX07.VLR_PIS,
          C_SAFX07.VLR_BASE_COFINS,    C_SAFX07.VLR_COFINS,       C_SAFX07.BASE_ICMS_ORIGDEST, C_SAFX07.VLR_ICMS_ORIGDEST,
          C_SAFX07.ALIQ_ICMS_ORIGDEST,C_SAFX07.VLR_DESC_CONDIC,  C_SAFX07.VLR_BASE_ISE_ICMSS, C_SAFX07.VLR_BASE_OUT_ICMSS,
          C_SAFX07.VLR_RED_BASE_ICMSS, C_SAFX07.PERC_RED_BASE_ICMS, C_SAFX07.IND_FISJUR_CPDIR, C_SAFX07.COD_FISJUR_CPDIR,
          C_SAFX07.IND_MEDIDAJUDICIAL, C_SAFX07.UF_ORIG_DEST,     C_SAFX07.IND_COMPRA_VENDA,
          C_SAFX07.COD_TP_DISP_SEG,    C_SAFX07.NUM_CTR_DISP,     C_SAFX07.NUM_FIM_DOCTO,      C_SAFX07.UF_DESTINO,
          C_SAFX07.SERIE_CTR_DISP,     C_SAFX07.SUB_SERIE_CTR_DISP, C_SAFX07.IND_SITUACAO_ESP, C_SAFX07.INSC_ESTADUAL,
          C_SAFX07.COD_PAGTO_INSS,     C_SAFX07.DAT_INTERN_AM,      C_SAFX07.IND_FISJUR_LSG,  C_SAFX07.COD_FISJUR_LSG,
          C_SAFX07.COMPROV_EXP,        C_SAFX07.NUM_FINAL_CRT_DISP, C_SAFX07.NUM_ALVARA,       C_SAFX07.NOTIFICA_SEFAZ,
          C_SAFX07.INTERNA_SUFRAMA,    C_SAFX07.IND_NOTA_SERVICO,   C_SAFX07.COD_MOTIVO,       C_SAFX07.COD_AMPARO,
          C_SAFX07.UF_AMPARO_LEGAL,    C_SAFX07.SEQ_ARQ,            C_SAFX07.OBS_COMPL_MOTIVO, C_SAFX07.IND_TP_RET,
          C_SAFX07.IND_TP_TOMADOR,     C_SAFX07.COD_ANTEC_ST,       C_SAFX07.CNPJ_ARMAZ_ORIG,  C_SAFX07.UF_ARMAZ_ORIG,
          C_SAFX07.INS_EST_ARMAZ_ORIG, C_SAFX07.CNPJ_ARMAZ_DEST,    C_SAFX07.UF_ARMAZ_DEST,   C_SAFX07.INS_EST_ARMAZ_DEST,
          C_SAFX07.OBS_INF_ADIC_NF,    C_SAFX07.VLR_BASE_INSS_2,    C_SAFX07.VLR_ALIQ_INSS_2,  C_SAFX07.VLR_INSS_RETIDO_2,
          C_SAFX07.COD_PAGTO_INSS_2,   C_SAFX07.VLR_BASE_PIS_ST,    C_SAFX07.VLR_ALIQ_PIS_ST,  C_SAFX07.VLR_PIS_ST,
          C_SAFX07.VLR_BASE_COFINS_ST, C_SAFX07.VLR_ALIQ_COFINS_ST, C_SAFX07.VLR_COFINS_ST,    C_SAFX07.VLR_BASE_CSLL,
          C_SAFX07.VLR_ALIQ_CSLL,      C_SAFX07.VLR_CSLL,           C_SAFX07.VLR_ALIQ_PIS,     C_SAFX07.VLR_ALIQ_COFINS,
          C_SAFX07.BASE_ICMSS_SUBSTITUIDO,  C_SAFX07.VLR_ICMSS_SUBSTITUIDO,  C_SAFX07.COD_CEI, C_SAFX07.VLR_JUROS_INSS,
          C_SAFX07.VLR_MULTA_INSS,     C_SAFX07.DT_PAGTO_NF,        C_SAFX07.IND_SITUACAO_ESP_ST, C_SAFX07.VLR_ICMSS_NDESTAC,
          C_SAFX07.IND_DOCTO_REC,      C_SAFX07.DAT_PGTO_GNRE_DARJ,  C_SAFX07.HORA_SAIDA,       C_SAFX07.COD_SIT_DOCFIS,
          C_SAFX07.COD_OBSERVACAO,     C_SAFX07.COD_SITUACAO_A,     C_SAFX07.COD_SITUACAO_B,   C_SAFX07.NUM_CONT_REDUC,
          V_CDMUNICIPIO,               V_CDMUNICIPIO,               C_SAFX07.COD_CFPS,         C_SAFX07.NUM_LANCAMENTO,
          C_SAFX07.VLR_MAT_PROP,       C_SAFX07.VLR_MAT_TERC,       C_SAFX07.VLR_BASE_ISS_RETIDO,     C_SAFX07.VLR_ISS_RETIDO,
          C_SAFX07.VLR_DEDUCAO_ISS,    C_SAFX07.COD_MUNIC_ARMAZ_ORIG, C_SAFX07.INS_MUNIC_ARMAZ_ORIG,  C_SAFX07.COD_MUNIC_ARMAZ_DEST,
          C_SAFX07.INS_MUNIC_ARMAZ_DEST, C_SAFX07.COD_CLASSE_CONSUMO, C_SAFX07.IND_ESPECIF_RECEITA,   C_SAFX07.NUM_CONTRATO,
          C_SAFX07.COD_AREA_TERMINAL,    C_SAFX07.COD_TP_UTIL,        C_SAFX07.GRUPO_TENSAO,          C_SAFX07.DATA_CONSUMO_INI,
          C_SAFX07.DATA_CONSUMO_FIM,     C_SAFX07.DATA_CONSUMO_LEIT,  C_SAFX07.QTD_CONTRATADA_PONTA,  C_SAFX07.QTD_CONTRATADA_FPONTA,
          C_SAFX07.QTD_CONSUMO_TOTAL,    C_SAFX07.UF_CONSUMO,         C_SAFX07.COD_MUNIC_CONSUMO,     C_SAFX07.COD_OPER_ESP_ST,
          C_SAFX07.ATO_NORMATIVO,        C_SAFX07.NUM_ATO_NORMATIVO,  C_SAFX07.ANO_ATO_NORMATIVO,     C_SAFX07.CAPITULACAO_NORMA,
          C_SAFX07.VLR_OUTRAS_ENTID,     C_SAFX07.VLR_TERCEIROS,      C_SAFX07.IND_TP_COMPL_ICMS,     C_SAFX07.VLR_BASE_CIDE,
          C_SAFX07.VLR_ALIQ_CIDE,        C_SAFX07.VLR_CIDE,           C_SAFX07.COD_VERIFIC_NFE,       C_SAFX07.COD_TP_RPS_NFE,
          C_SAFX07.NUM_RPS_NFE,          C_SAFX07.SERIE_RPS_NFE,      C_SAFX07.DAT_EMISSAO_RPS_NFE,   C_SAFX07.DSC_SERVICO_NFE,
          C_SAFX07.NUM_AUTENTIC_NFE,     C_SAFX07.NUM_DV_NFE,         C_SAFX07.MODELO_NF_DMS,         C_SAFX07.COD_MODELO_COTEPE,
          C_SAFX07.VLR_COMISSAO,         C_SAFX07.IND_NFE_DENEG_INUT, C_SAFX07.IND_NF_REG_ESPECIAL,   C_SAFX07.VLR_ABAT_NTRIBUTADO,
          C_SAFX07.VLR_OUTROS_ICMS,     C_SAFX07.HORA_EMISSAO,       C_SAFX07.OBS_DADOS_FATURA,      C_SAFX07.IND_FIS_CONCES,
          C_SAFX07.COD_FIS_CONCES,       C_SAFX07.COD_AUTENTIC,       C_SAFX07.IND_PORT_CAT44,        C_SAFX07.VLR_BASE_INSS_RURAL,
          C_SAFX07.VLR_ALIQ_INSS_RURAL,  C_SAFX07.VLR_INSS_RURAL,    C_SAFX07.COD_CLASSE_CONSUMO_SEF_PE,  C_SAFX07.VLR_PIS_RETIDO,
          C_SAFX07.VLR_COFINS_RETIDO,    C_SAFX07.DAT_LANC_PIS_COFINS,C_SAFX07.IND_PIS_COFINS_EXTEMP, C_SAFX07.COD_SIT_PIS,
          C_SAFX07.COD_SIT_COFINS,       C_SAFX07.IND_NAT_FRETE,      C_SAFX07.COD_NAT_REC,           C_SAFX07.IND_VENDA_CANC,
          C_SAFX07.IND_NAT_BASE_CRED,    C_SAFX07.IND_NF_CONTINGENCIA, C_SAFX07.VLR_ACRESCIMO,         C_SAFX07.VLR_ANTECIP_TRIB,
          C_SAFX07.IND_IPI_NDESTAC_DF,   C_SAFX07.DSC_RESERVADO1,     C_SAFX07.DSC_RESERVADO2,        C_SAFX07.DSC_RESERVADO3,
          C_SAFX07.NUM_NFTS,             C_SAFX07.IND_NF_VENDA_TERCEIROS,  C_SAFX07.DSC_RESERVADO4,   C_SAFX07.DSC_RESERVADO5,
          C_SAFX07.DSC_RESERVADO6,       C_SAFX07.DSC_RESERVADO7,     C_SAFX07.DSC_RESERVADO8,        C_SAFX07.IDENTIF_DOCFIS,
          C_SAFX07.COD_SISTEMA_ORIG,     C_SAFX07.COD_SCP,            C_SAFX07.IND_PREST_SERV,        C_SAFX07.IND_TIPO_PROC,
          C_SAFX07.NUM_PROC_JUR,         C_SAFX07.IND_DEC_PROC,       C_SAFX07.IND_TIPO_AQUIS,        C_SAFX07.VLR_DESC_GILRAT,
          C_SAFX07.VLR_DESC_SENAR,       C_SAFX07.CNPJ_SUBEMPREITEIRO,C_SAFX07.CNPJ_CPF_PROPRIETARIO_CNO,  C_SAFX07.VLR_RET_SUBEMPREITADO,
          C_SAFX07.NUM_DOCFIS_SERV,      C_SAFX07.VLR_FCP_UF_DEST,    C_SAFX07.VLR_ICMS_UF_DEST,      C_SAFX07.VLR_ICMS_UF_ORIG,
          C_SAFX07.VLR_CONTRIB_PREV,     C_SAFX07.VLR_GILRAT,         C_SAFX07.VLR_CONTRIB_SENAR,     C_SAFX07.CPF_CNPJ,

          C_SAFX07.VLR_OUTROS2,          C_SAFX07.VLR_OUTROS3,        C_SAFX07.VLR_OUTROS4,           C_SAFX07.VLR_OUTROS5,
          C_SAFX07.VLR_ALIQ_OUTROS1,     C_SAFX07.VLR_ALIQ_OUTROS2,   C_SAFX07.IND_ATO_COTEPE,        C_SAFX07.HORA_SAIDA_REC,
          C_SAFX07.CATEGORIA_TRAB,       C_SAFX07.NUM_CERTIF_QUAL,    C_SAFX07.NUM_PROCESSO,          C_SAFX07.DATA_TRAB,
          C_SAFX07.OBS_REINF,            C_SAFX07.VLR_TOT_ADIC,       C_SAFX07.VLR_RET_SERV,          C_SAFX07.VLR_SERV_15,
          C_SAFX07.VLR_SERV_20,          C_SAFX07.VLR_SERV_25,        C_SAFX07.VLR_IPI_DEV,           C_SAFX07.VLR_SEST,
          C_SAFX07.VLR_SENAT, SYSDATE);
         COMMITAR;
      FOR C_SAFX08 IN
         (SELECT C_SAFX07.COD_EMPRESA, C_SAFX07.COD_ESTAB, TO_CHAR(V.DTEMISSAONFCE, 'YYYYMMDD') DATA_FISCAL, '9' MOVTO_E_S,
                 '1' NORM_DEV, 'NFCE' COD_DOCTO, '5' IND_FIS_JUR, REPLACE(REPLACE(REPLACE(F.NRINSJURFILI, '.', ''), '-', ''), '/', '') COD_FIS_JUR,
                 NRNOTAFISCALCE NUM_DOCFIS, V.CDSERIENFCE SERIE_DOCFIS, '@' SUB_SERIE_DOCFIS, 'N' IND_BEM_PATR,
                 '1' IND_PRODUTO,           LTRIM(LPAD(P.CDPRODINTE, 18, '0')) COD_PRODUTO,    '@' COD_BEM,          '@' COD_INC_BEM,
                 P.SGUNIDADE COD_UND_PADRAO,RPAD(I.NRSEQUITVEND, 5, ' ') NUM_ITEM, '@' COD_ALMOX, '@' COD_CUSTO,
                 '@' DESCRICAO_COMPL,       RPAD(CDCFOPPROD, 4, ' ') COD_CFO,      '@' COD_NATUREZA_OP, VALORVARCHAR(I.QTPRODVEND, 11, 6) QUANTIDADE,
                 P.SGUNIDADE COD_MEDIDA,    P.CDCLASFISC COD_NBM,  VALORVARCHAR(I.VRUNITVEND, 15, 4) VLR_UNIT,
                 VALORVARCHAR(TRUNC(I.QTPRODVEND * (NVL(I.VRUNITVEND,0) + NVL(I.VRUNITVENDCL,0)),2), 15, 2) VLR_ITEM,
                 VALORVARCHAR(I.VRDESITVEND, 15, 2) VLR_DESCONTO, '0' COD_SITUACAO_A, RPAD(CDCSTPRODI, 2, ' ') COD_SITUACAO_B, '@' COD_FEDERAL,
                 'N' IND_IPI_INCLUSO,      '@' NUM_ROMANEIO,    '@' DATA_ROMANEIO, '@' PESO_LIQUIDO,
                 '@' COD_INDICE,           '@' VLR_ITEM_CONVER, '@' VLR_FRETE,     '@' VLR_SEGURO,
                 '@' VLR_OUTRAS, VALORVARCHAR(II.VRPEALPRODIT, 3, 4) VLR_ALIQ_ICMS, VALORVARCHAR(ROUND(II.VRIMPOPRODIT, 2), 15, 2) VLR_ICMS, '@' DIF_ALIQ_ICMS,
                 '@' OBS_ICMS,             '@' COD_APUR_ICMS,   '@' VLR_ALIQ_IPI,  '@' VLR_IPI,
                 '@' OBS_IPI,              '@' COD_APUR_IPI,    '@' VLR_ALIQ_SUB_ICMS, '@' VLR_SUBST_ICMS,
                 '@' OBS_SUBST_ICMS,       '@' COD_APUR_SUB_ICMS, NULL TRIB_ICMS, VALORVARCHAR(II.VRBASECALCICMS, 15, 2) BASE_ICMS,
                 '@' BASE_REDU_ICMS,       '@' TRIB_IPI,        '@' BASE_IPI,      '@' BASE_REDU_IPI,
                 '@' BASE_SUB_TRIB_ICMS,   '@' VLR_CONTAB_COMPL,'@' VLR_ALIQ_DESTINO,
                 VALORVARCHAR(TRUNC(I.QTPRODVEND * (NVL(I.VRUNITVEND,0) + NVL(I.VRUNITVENDCL,0)),2) - NVL(I.VRDESITVEND,0) + NVL(I.VRACRITVEND,0), 15, 2) VLR_CONTAB_ITEM,
                 '@' COD_OBS_VCONT_COMP,   '@' COD_OBS_VCONT_ITEM, '@' VLR_OUTROS_ICMS,    '@' VLR_OUTROS_IPI,
                 '@' VLR_OUTROS1,          '@' NUM_ATO_CONCES,     '@' DAT_EMBARQUE,       '@' NUM_REG_EXP,
                 '@' NUM_DESP_EXP,         '@' VLR_TOM_SERVICO,    '@' VLR_DESP_MOEDA_EXP, '@' COD_MOEDA_NEGOC,
                 '@' COD_PAIS_DEST_ORIG,   '@' IND_CRED_ICMSS,     '@' COD_TRIB_INT,       '@' VLR_ICMS_NDESTAC,
                 '@' VLR_IPI_NDESTAC,      '@' TRIB_ICMS_AUX,      '@' BASE_ICMS_AUX,      '@' TRIB_IPI_AUX,
                 '@' BASE_IPI_AUX, VALORVARCHAR(II.VRBASECALCICMS, 15, 2) VLR_BASE_PIS, VALORVARCHAR(II.VRIMPPIS, 15, 2) VLR_PIS, VALORVARCHAR(II.VRBASECALCICMS, 15, 2) VLR_BASE_COFINS,
                 VALORVARCHAR(VRIMPCOFINS, 15, 2) VLR_COFINS,      '@' BASE_ICMS_ORIGDEST, '@' VLR_ICMS_ORIGDEST, '@' ALIQ_ICMS_ORIGDEST,
                 '@' VLR_DESC_CONDIC,      '@' TRIB_ICMSS,         '@' BASE_REDU_ICMSS,    '@' VLR_CUSTO_TRANSF,
                 '@' PERC_RED_BASE_ICMS,   '@' QTD_EMBARCADA,      '@' DAT_REGISTRO_EXP,   '@' DAT_DESPACHO,
                 '@' DAT_AVERBACAO,        '@' DAT_DI,             '@' NUM_DEC_IMP_REF,   '@' DSC_MOT_OCOR,
                 '@' COD_CONTA,            '@' VLR_BASE_ICMS_ORIG, '@' VLR_TRIB_ICMS_ORIG, '@' VLR_BASE_ICMS_DEST,
                 '@' VLR_TRIB_ICMS_DEST,   '@' VLR_PERC_PRES_ICMS, '@' VLR_PRECO_BASE_ST,  '@' COD_OPER_OIL,
                 '@' COD_DCR,              '@' COD_PROJETO,        'N' IND_MOV_FIS,        '@' CHASSI,
                 '@' NUM_DOCFIS_REF,       '@' SERIE_DOCFIS_REF,   '@' SSERIE_DOCFIS_REF,  '@' VLR_BASE_PIS_ST,
                 '@' VLR_ALIQ_PIS_ST,      '@' VLR_PIS_ST,         '@' VLR_BASE_COFINS_ST, '@' VLR_ALIQ_COFINS_ST,
                 '@' VLR_COFINS_ST,        '@' VLR_BASE_CSLL,      '@' VLR_ALIQ_CSLL,      '@' VLR_CSLL,
                 VALORVARCHAR(II.VRPERPIS, 3, 4)  VLR_ALIQ_PIS, VALORVARCHAR(II.VRPERCOFINS, 3, 4) VLR_ALIQ_COFINS, '@' IND_FORNEC_ICMSS, '@' IND_SITUACAO_ESP_ST,
                 '@' VLR_ICMSS_NDESTAC,    '@' IND_DOCTO_REC,      '@' DAT_PGTO_GNRE_DARJ, '@' VLR_CUSTO_UNIT,
                 '@' QUANTIDADE_CONV,      '@' VLR_FECP_ICMS,      '@' VLR_FECP_DIFALIQ,   '@' VLR_FECP_ICMS_ST,
                 '@' VLR_FECP_FONTE,       '@' TRIB_ICMSS_AUX2,    '@' BASE_ICMSS_AUX2,     '@' VLR_BASE_ICMSS_N_ESCRIT,
                 '@' VLR_ICMSS_N_ESCRIT,   '@' COD_TRIB_IPI,       '@' LOTE_MEDICAMENTO,   '@' VALID_MEDICAMENTO,
                 '@' IND_BASE_MEDICAMENTO, '@' VLR_PRECO_MEDICAMENTO, '@' IND_TIPO_ARMA,   '@' NUM_SERIE_ARMA,
                 '@' NUM_CANO_ARMA,        '@' DSC_ARMA,           '@' COD_OBSERVACAO,     '@' COD_EX_NCM,
                 '@' COD_EX_IMP,           '@' CNPJ_OPERADORA,     '@' CPF_OPERADORA,      '@' UF_OPERADORA,
                 '@' INS_EST_OPERADORA,    '@' IND_ESPECIF_RECEITA,'@' COD_CLASS_ITEM,     '@' VLR_TERCEIROS,
                 '@' VLR_PRECO_SUGER,      '@' VLR_BASE_CIDE,      '@' VLR_ALIQ_CIDE,      '@' VLR_CIDE,
                 '@' COD_OPER_ESP_ST,      '@' VLR_COMISSAO,       '@' VLR_ICMS_FRETE,     '@' VLR_DIFAL_FRETE,
                 'S' IND_VLR_PIS_COFINS,   '@' COD_ENQUAD_IPI, II.CDCSTPRODPC COD_SITUACAO_PIS, '@' QTD_BASE_PIS,
                 '@' VLR_ALIQ_PIS_R, II.CDCSTPRODPC COD_SITUACAO_COFINS, '@' QTD_BASE_COFINS,   '@' VLR_ALIQ_COFINS_R,
                 '@' ITEM_PORT_TARE,       '@' VLR_FUNRURAL,       '@' IND_TP_PROD_MEDIC,  '@' VLR_CUSTO_DCA,
                 '@' COD_TP_LANCTO,        '@' VLR_PERC_CRED_OUT,  '@' VLR_CRED_OUT,       '@' VLR_ICMS_DCA,
                 '@' VLR_PIS_EXP,          '@' VLR_PIS_TRIB,       '@' VLR_PIS_N_TRIB,     '@' VLR_COFINS_EXP,
                 '@' VLR_COFINS_TRIB,      '@' VLR_COFINS_N_TRIB,  '@' COD_ENQ_LEGAL, TO_CHAR(V.DTEMISSAONFCE, 'YYYYMMDD') DAT_LANC_PIS_COFINS,
                 '@' IND_PIS_COFINS_EXTEMP,'@' IND_NATUREZA_FRETE, R.CDNATUREC COD_NAT_REC, '@' IND_NAT_BASE_CRED,
                 '@' VLR_ACRESCIMO,        '@' IND_IPI_NDESTAC_DF, '@' DSC_RESERVADO1,     '@' DSC_RESERVADO2,
                 '@' DSC_RESERVADO3,       '@' COD_TRIB_PROD,      '@' DSC_RESERVADO4,     '@' DSC_RESERVADO5,
                 '@' DSC_RESERVADO6,       '@' DSC_RESERVADO7,     '@' DSC_RESERVADO8,     '@' INDICE_PROD_ACAB,
                 '@' VLR_BASE_DIA_AM,      '@' VLR_ALIQ_DIA_AM,    '@' VLR_ICMS_DIA_AM,    '@' VLR_ADUANEIRO,
                 '@' COD_SITUACAO_PIS_ST,  '@' COD_SITUACAO_COFINS_ST, '@' VLR_ALIQ_DCIP,  '@' NUM_LI,
                 '@' VLR_FCP_UF_DEST,      '@' VLR_ICMS_UF_DEST,       '@' VLR_ICMS_UF_ORIG,       '@' VLR_DIF_DUB,
                 '@' VLR_ICMS_NAO_DEST,    '@' VLR_BASE_ICMS_NAO_DEST, '@' VLR_ALIQ_ICMS_NAO_DEST, '@' IND_MOTIVO_RES,
                 '@' NUM_DOCFIS_RET,       '@' SERIE_DOCFIS_RET,       '@' NUM_AUTENTIC_NFE_RET,   '@' NUM_ITEM_RET,
                 '@' IND_FIS_JUR_RET,      '@' COD_FIS_JUR_RET,        '@' IND_TP_DOC_ARREC,       '@' NUM_DOC_ARREC,
                 '@' COD_CFO_DCIP,
                 '@' VLR_OUTROS2,          '@' VLR_OUTROS3,            '@' VLR_OUTROS4,            '@' VLR_OUTROS5,
                 '@' VLR_ALIQ_OUTROS1,     '@' VLR_ALIQ_OUTROS2,       '@' IND_ATO_COTEPE,
                 '@' VLR_FATOR_CONV,       NULL NUM_PROCESSO,          '@' VLR_BASE_INSS,          '@' VLR_INSS_RETIDO,
                 '@' VLR_TOT_ADIC,         '@' VLR_N_RET_PRINC,        '@' VLR_N_RET_ADIC,         '@' VLR_ALIQ_INSS,
                 '@' VLR_RET_SERV,         '@' VLR_SERV_15,            '@' VLR_SERV_20,            '@' VLR_SERV_25,
                 '@' IND_TP_PROC_ADJ_PRINC, '@' NUM_PROC_ADJ_PRINC,    '@' COD_SUSP_PRINC,         '@' IND_TP_PROC_ADJ_ADIC,
                 '@' NUM_PROC_ADJ_ADIC,    '@' COD_SUSP_ADIC,          '@' VLR_IPI_DEV,            '@' COD_BENEFICIO,
                 '@' VLR_ABAT_NTRIBUTADO
           FROM VENDA V, ITEMVENDA I, ITVENDAIMPOS II, IMPOSTO IMP, FILIAL F, PRODUTO P LEFT JOIN RELACPRODITGEN R
                                                                                               ON R.CDLIVROMAG = '0000000001'
                                                                                              AND R.CDPRODUTO = P.CDPRODUTO
          WHERE F.CDFILIAL = V.CDFILIAL
            AND V.CDFILIAL = C_SAFX07.CDFILIAL
            AND V.CDCAIXA = C_SAFX07.CDCAIXA
            AND V.NRSEQVENDA = C_SAFX07.NRSEQVENDA
            AND V.CDFILIAL = I.CDFILIAL
            AND V.CDCAIXA = I.CDCAIXA
            AND V.NRSEQVENDA = I.NRSEQVENDA
            AND I.CDPRODUTO = P.CDPRODUTO
            AND I.CDFILIAL = II.CDFILIAL
            AND I.CDCAIXA = II.CDCAIXA
            AND I.NRSEQVENDA = II.NRSEQVENDA
            AND I.NRSEQUITVEND = II.NRSEQUITVEND
            AND II.CDIMPOSTO = IMP.CDIMPOSTO) LOOP
         IF C_SAFX08.COD_SITUACAO_B IN ('00') THEN
            V_IDTRIBICMS := '1';
         ELSIF C_SAFX08.COD_SITUACAO_B IN ('20', '40', '41') THEN
            V_IDTRIBICMS := '2';
         ELSE
            V_IDTRIBICMS := '3';
         END IF;

         IF C_SAFX08.COD_SITUACAO_B IN ('30', '40', '41', '50', '60') THEN
            V_VLR_ICMS := VALORVARCHAR(0, 15, 2);
            V_VLR_ALIQ_ICMS := VALORVARCHAR(0, 3, 4);
         ELSE
            V_VLR_ICMS := C_SAFX08.VLR_ICMS;
            V_VLR_ALIQ_ICMS := C_SAFX08.VLR_ALIQ_ICMS;
         END IF;

         IF C_SAFX08.COD_SITUACAO_PIS NOT IN ('01') THEN
            V_COD_NAT_REC := C_SAFX08.COD_NAT_REC;
         ELSE
            V_COD_NAT_REC := '@';
         END IF;
         
         INSERT INTO SAFX08
            (COD_EMPRESA, COD_ESTAB, DATA_FISCAL, MOVTO_E_S,
             NORM_DEV, COD_DOCTO, IND_FIS_JUR, COD_FIS_JUR,
             NUM_DOCFIS, SERIE_DOCFIS, SUB_SERIE_DOCFIS, IND_BEM_PATR,
             IND_PRODUTO, COD_PRODUTO,COD_BEM,COD_INC_BEM,
             COD_UND_PADRAO, NUM_ITEM, COD_ALMOX, COD_CUSTO,
             DESCRICAO_COMPL,COD_CFO,COD_NATUREZA_OP, QUANTIDADE,
             COD_MEDIDA, COD_NBM,VLR_UNIT, VLR_ITEM,
             VLR_DESCONTO, COD_SITUACAO_A, COD_SITUACAO_B, COD_FEDERAL,
             IND_IPI_INCLUSO, NUM_ROMANEIO,DATA_ROMANEIO, PESO_LIQUIDO,
             COD_INDICE, VLR_ITEM_CONVER, VLR_FRETE, VLR_SEGURO,
             VLR_OUTRAS,
             VLR_ALIQ_ICMS, VLR_ICMS,
             DIF_ALIQ_ICMS,
             OBS_ICMS, COD_APUR_ICMS, VLR_ALIQ_IPI, VLR_IPI,
             OBS_IPI, COD_APUR_IPI, VLR_ALIQ_SUB_ICMS, VLR_SUBST_ICMS,
             OBS_SUBST_ICMS, COD_APUR_SUB_ICMS, TRIB_ICMS, BASE_ICMS,
             BASE_REDU_ICMS, TRIB_IPI, BASE_IPI, BASE_REDU_IPI,
             BASE_SUB_TRIB_ICMS, VLR_CONTAB_COMPL, VLR_ALIQ_DESTINO,
             VLR_CONTAB_ITEM,
             COD_OBS_VCONT_COMP, COD_OBS_VCONT_ITEM, VLR_OUTROS_ICMS, VLR_OUTROS_IPI,
             VLR_OUTROS1, NUM_ATO_CONCES, DAT_EMBARQUE, NUM_REG_EXP,
             NUM_DESP_EXP, VLR_TOM_SERVICO, VLR_DESP_MOEDA_EXP, COD_MOEDA_NEGOC,
             COD_PAIS_DEST_ORIG, IND_CRED_ICMSS, COD_TRIB_INT, VLR_ICMS_NDESTAC,
             VLR_IPI_NDESTAC, TRIB_ICMS_AUX, BASE_ICMS_AUX, TRIB_IPI_AUX,
             BASE_IPI_AUX, VLR_BASE_PIS, VLR_PIS, VLR_BASE_COFINS,
             VLR_COFINS, BASE_ICMS_ORIGDEST, VLR_ICMS_ORIGDEST, ALIQ_ICMS_ORIGDEST,
             VLR_DESC_CONDIC, TRIB_ICMSS, BASE_REDU_ICMSS, VLR_CUSTO_TRANSF,
             PERC_RED_BASE_ICMS, QTD_EMBARCADA, DAT_REGISTRO_EXP, DAT_DESPACHO,
             DAT_AVERBACAO, DAT_DI, NUM_DEC_IMP_REF, DSC_MOT_OCOR,
             COD_CONTA, VLR_BASE_ICMS_ORIG, VLR_TRIB_ICMS_ORIG, VLR_BASE_ICMS_DEST,
             VLR_TRIB_ICMS_DEST, VLR_PERC_PRES_ICMS, VLR_PRECO_BASE_ST, COD_OPER_OIL,
             COD_DCR, COD_PROJETO, IND_MOV_FIS, CHASSI,
             NUM_DOCFIS_REF, SERIE_DOCFIS_REF, SSERIE_DOCFIS_REF, VLR_BASE_PIS_ST,
             VLR_ALIQ_PIS_ST, VLR_PIS_ST, VLR_BASE_COFINS_ST, VLR_ALIQ_COFINS_ST,
             VLR_COFINS_ST, VLR_BASE_CSLL, VLR_ALIQ_CSLL, VLR_CSLL,
             VLR_ALIQ_PIS, VLR_ALIQ_COFINS, IND_FORNEC_ICMSS, IND_SITUACAO_ESP_ST,
             VLR_ICMSS_NDESTAC, IND_DOCTO_REC, DAT_PGTO_GNRE_DARJ, VLR_CUSTO_UNIT,
             QUANTIDADE_CONV, VLR_FECP_ICMS, VLR_FECP_DIFALIQ, VLR_FECP_ICMS_ST,
             VLR_FECP_FONTE, TRIB_ICMSS_AUX2, BASE_ICMSS_AUX2, VLR_BASE_ICMSS_N_ESCRIT,
             VLR_ICMSS_N_ESCRIT, COD_TRIB_IPI, LOTE_MEDICAMENTO, VALID_MEDICAMENTO,
             IND_BASE_MEDICAMENTO, VLR_PRECO_MEDICAMENTO, IND_TIPO_ARMA, NUM_SERIE_ARMA,
             NUM_CANO_ARMA, DSC_ARMA, COD_OBSERVACAO, COD_EX_NCM,
             COD_EX_IMP, CNPJ_OPERADORA, CPF_OPERADORA, UF_OPERADORA,
             INS_EST_OPERADORA, IND_ESPECIF_RECEITA, COD_CLASS_ITEM, VLR_TERCEIROS,
             VLR_PRECO_SUGER, VLR_BASE_CIDE, VLR_ALIQ_CIDE, VLR_CIDE,
             COD_OPER_ESP_ST, VLR_COMISSAO, VLR_ICMS_FRETE, VLR_DIFAL_FRETE,
             IND_VLR_PIS_COFINS, COD_ENQUAD_IPI, COD_SITUACAO_PIS, QTD_BASE_PIS,
             VLR_ALIQ_PIS_R, COD_SITUACAO_COFINS, QTD_BASE_COFINS, VLR_ALIQ_COFINS_R,
             ITEM_PORT_TARE, VLR_FUNRURAL, IND_TP_PROD_MEDIC, VLR_CUSTO_DCA,
             COD_TP_LANCTO, VLR_PERC_CRED_OUT, VLR_CRED_OUT, VLR_ICMS_DCA,
             VLR_PIS_EXP, VLR_PIS_TRIB, VLR_PIS_N_TRIB, VLR_COFINS_EXP,
             VLR_COFINS_TRIB, VLR_COFINS_N_TRIB, COD_ENQ_LEGAL, DAT_LANC_PIS_COFINS,
             IND_PIS_COFINS_EXTEMP, IND_NATUREZA_FRETE, COD_NAT_REC, IND_NAT_BASE_CRED,
             VLR_ACRESCIMO, IND_IPI_NDESTAC_DF, DSC_RESERVADO1, DSC_RESERVADO2,
             DSC_RESERVADO3, COD_TRIB_PROD, DSC_RESERVADO4, DSC_RESERVADO5,
             DSC_RESERVADO6, DSC_RESERVADO7, DSC_RESERVADO8, INDICE_PROD_ACAB,
             VLR_BASE_DIA_AM, VLR_ALIQ_DIA_AM, VLR_ICMS_DIA_AM, VLR_ADUANEIRO,
             COD_SITUACAO_PIS_ST, COD_SITUACAO_COFINS_ST, VLR_ALIQ_DCIP, NUM_LI,
             VLR_FCP_UF_DEST, VLR_ICMS_UF_DEST, VLR_ICMS_UF_ORIG, VLR_DIF_DUB,
             VLR_ICMS_NAO_DEST, VLR_BASE_ICMS_NAO_DEST, VLR_ALIQ_ICMS_NAO_DEST, IND_MOTIVO_RES,
             NUM_DOCFIS_RET, SERIE_DOCFIS_RET, NUM_AUTENTIC_NFE_RET, NUM_ITEM_RET,
             IND_FIS_JUR_RET, COD_FIS_JUR_RET, IND_TP_DOC_ARREC, NUM_DOC_ARREC,
             COD_CFO_DCIP,
             VLR_OUTROS2, VLR_OUTROS3, VLR_OUTROS4, VLR_OUTROS5,
             VLR_ALIQ_OUTROS1, VLR_ALIQ_OUTROS2, IND_ATO_COTEPE,
             VLR_FATOR_CONV, NUM_PROCESSO, VLR_BASE_INSS, VLR_INSS_RETIDO,
             VLR_TOT_ADIC, VLR_N_RET_PRINC, VLR_N_RET_ADIC, VLR_ALIQ_INSS,
             VLR_RET_SERV, VLR_SERV_15, VLR_SERV_20, VLR_SERV_25,
             IND_TP_PROC_ADJ_PRINC, NUM_PROC_ADJ_PRINC, COD_SUSP_PRINC, IND_TP_PROC_ADJ_ADIC,
             NUM_PROC_ADJ_ADIC, COD_SUSP_ADIC, VLR_IPI_DEV, COD_BENEFICIO,
             VLR_ABAT_NTRIBUTADO, DAT_GRAVACAO)
         VALUES
            (C_SAFX08.COD_EMPRESA, C_SAFX08.COD_ESTAB, C_SAFX08.DATA_FISCAL, C_SAFX08.MOVTO_E_S,
             C_SAFX08.NORM_DEV, C_SAFX08.COD_DOCTO, C_SAFX08.IND_FIS_JUR, C_SAFX08.COD_FIS_JUR,
             C_SAFX08.NUM_DOCFIS, C_SAFX08.SERIE_DOCFIS, C_SAFX08.SUB_SERIE_DOCFIS, C_SAFX08.IND_BEM_PATR,
             C_SAFX08.IND_PRODUTO, C_SAFX08.COD_PRODUTO,C_SAFX08.COD_BEM,C_SAFX08.COD_INC_BEM,
             C_SAFX08.COD_UND_PADRAO, C_SAFX08.NUM_ITEM, C_SAFX08.COD_ALMOX, C_SAFX08.COD_CUSTO,
             C_SAFX08.DESCRICAO_COMPL,C_SAFX08.COD_CFO,C_SAFX08.COD_NATUREZA_OP, C_SAFX08.QUANTIDADE,
             C_SAFX08.COD_MEDIDA, C_SAFX08.COD_NBM,C_SAFX08.VLR_UNIT, C_SAFX08.VLR_ITEM,
             C_SAFX08.VLR_DESCONTO, C_SAFX08.COD_SITUACAO_A, C_SAFX08.COD_SITUACAO_B, C_SAFX08.COD_FEDERAL,
             C_SAFX08.IND_IPI_INCLUSO, C_SAFX08.NUM_ROMANEIO,C_SAFX08.DATA_ROMANEIO, C_SAFX08.PESO_LIQUIDO,
             C_SAFX08.COD_INDICE, C_SAFX08.VLR_ITEM_CONVER, C_SAFX08.VLR_FRETE, C_SAFX08.VLR_SEGURO,
             C_SAFX08.VLR_OUTRAS,
             V_VLR_ALIQ_ICMS, V_VLR_ICMS,
             C_SAFX08.DIF_ALIQ_ICMS,
             C_SAFX08.OBS_ICMS, C_SAFX08.COD_APUR_ICMS, C_SAFX08.VLR_ALIQ_IPI, C_SAFX08.VLR_IPI,
             C_SAFX08.OBS_IPI, C_SAFX08.COD_APUR_IPI, C_SAFX08.VLR_ALIQ_SUB_ICMS, C_SAFX08.VLR_SUBST_ICMS,
             C_SAFX08.OBS_SUBST_ICMS, C_SAFX08.COD_APUR_SUB_ICMS, V_IDTRIBICMS, C_SAFX08.BASE_ICMS,
             C_SAFX08.BASE_REDU_ICMS, C_SAFX08.TRIB_IPI, C_SAFX08.BASE_IPI, C_SAFX08.BASE_REDU_IPI,
             C_SAFX08.BASE_SUB_TRIB_ICMS, C_SAFX08.VLR_CONTAB_COMPL, C_SAFX08.VLR_ALIQ_DESTINO,
             C_SAFX08.VLR_CONTAB_ITEM,
             C_SAFX08.COD_OBS_VCONT_COMP, C_SAFX08.COD_OBS_VCONT_ITEM, C_SAFX08.VLR_OUTROS_ICMS, C_SAFX08.VLR_OUTROS_IPI,
             C_SAFX08.VLR_OUTROS1, C_SAFX08.NUM_ATO_CONCES, C_SAFX08.DAT_EMBARQUE, C_SAFX08.NUM_REG_EXP,
             C_SAFX08.NUM_DESP_EXP, C_SAFX08.VLR_TOM_SERVICO, C_SAFX08.VLR_DESP_MOEDA_EXP, C_SAFX08.COD_MOEDA_NEGOC,
             C_SAFX08.COD_PAIS_DEST_ORIG, C_SAFX08.IND_CRED_ICMSS, C_SAFX08.COD_TRIB_INT, C_SAFX08.VLR_ICMS_NDESTAC,
             C_SAFX08.VLR_IPI_NDESTAC, C_SAFX08.TRIB_ICMS_AUX, C_SAFX08.BASE_ICMS_AUX, C_SAFX08.TRIB_IPI_AUX,
             C_SAFX08.BASE_IPI_AUX, C_SAFX08.VLR_BASE_PIS, C_SAFX08.VLR_PIS, C_SAFX08.VLR_BASE_COFINS,
             C_SAFX08.VLR_COFINS, C_SAFX08.BASE_ICMS_ORIGDEST, C_SAFX08.VLR_ICMS_ORIGDEST, C_SAFX08.ALIQ_ICMS_ORIGDEST,
             C_SAFX08.VLR_DESC_CONDIC, C_SAFX08.TRIB_ICMSS, C_SAFX08.BASE_REDU_ICMSS, C_SAFX08.VLR_CUSTO_TRANSF,
             C_SAFX08.PERC_RED_BASE_ICMS, C_SAFX08.QTD_EMBARCADA, C_SAFX08.DAT_REGISTRO_EXP, C_SAFX08.DAT_DESPACHO,
             C_SAFX08.DAT_AVERBACAO, C_SAFX08.DAT_DI, C_SAFX08.NUM_DEC_IMP_REF, C_SAFX08.DSC_MOT_OCOR,
             C_SAFX08.COD_CONTA, C_SAFX08.VLR_BASE_ICMS_ORIG, C_SAFX08.VLR_TRIB_ICMS_ORIG, C_SAFX08.VLR_BASE_ICMS_DEST,
             C_SAFX08.VLR_TRIB_ICMS_DEST, C_SAFX08.VLR_PERC_PRES_ICMS, C_SAFX08.VLR_PRECO_BASE_ST, C_SAFX08.COD_OPER_OIL,
             C_SAFX08.COD_DCR, C_SAFX08.COD_PROJETO, C_SAFX08.IND_MOV_FIS, C_SAFX08.CHASSI,
             C_SAFX08.NUM_DOCFIS_REF, C_SAFX08.SERIE_DOCFIS_REF, C_SAFX08.SSERIE_DOCFIS_REF, C_SAFX08.VLR_BASE_PIS_ST,
             C_SAFX08.VLR_ALIQ_PIS_ST, C_SAFX08.VLR_PIS_ST, C_SAFX08.VLR_BASE_COFINS_ST, C_SAFX08.VLR_ALIQ_COFINS_ST,
             C_SAFX08.VLR_COFINS_ST, C_SAFX08.VLR_BASE_CSLL, C_SAFX08.VLR_ALIQ_CSLL, C_SAFX08.VLR_CSLL,
             C_SAFX08.VLR_ALIQ_PIS, C_SAFX08.VLR_ALIQ_COFINS, C_SAFX08.IND_FORNEC_ICMSS, C_SAFX08.IND_SITUACAO_ESP_ST,
             C_SAFX08.VLR_ICMSS_NDESTAC, C_SAFX08.IND_DOCTO_REC, C_SAFX08.DAT_PGTO_GNRE_DARJ, C_SAFX08.VLR_CUSTO_UNIT,
             C_SAFX08.QUANTIDADE_CONV, C_SAFX08.VLR_FECP_ICMS, C_SAFX08.VLR_FECP_DIFALIQ, C_SAFX08.VLR_FECP_ICMS_ST,
             C_SAFX08.VLR_FECP_FONTE, C_SAFX08.TRIB_ICMSS_AUX2, C_SAFX08.BASE_ICMSS_AUX2, C_SAFX08.VLR_BASE_ICMSS_N_ESCRIT,
             C_SAFX08.VLR_ICMSS_N_ESCRIT, C_SAFX08.COD_TRIB_IPI, C_SAFX08.LOTE_MEDICAMENTO, C_SAFX08.VALID_MEDICAMENTO,
             C_SAFX08.IND_BASE_MEDICAMENTO, C_SAFX08.VLR_PRECO_MEDICAMENTO, C_SAFX08.IND_TIPO_ARMA, C_SAFX08.NUM_SERIE_ARMA,
             C_SAFX08.NUM_CANO_ARMA, C_SAFX08.DSC_ARMA, C_SAFX08.COD_OBSERVACAO, C_SAFX08.COD_EX_NCM,
             C_SAFX08.COD_EX_IMP, C_SAFX08.CNPJ_OPERADORA, C_SAFX08.CPF_OPERADORA, C_SAFX08.UF_OPERADORA,
             C_SAFX08.INS_EST_OPERADORA, C_SAFX08.IND_ESPECIF_RECEITA, C_SAFX08.COD_CLASS_ITEM, C_SAFX08.VLR_TERCEIROS,
             C_SAFX08.VLR_PRECO_SUGER, C_SAFX08.VLR_BASE_CIDE, C_SAFX08.VLR_ALIQ_CIDE, C_SAFX08.VLR_CIDE,
             C_SAFX08.COD_OPER_ESP_ST, C_SAFX08.VLR_COMISSAO, C_SAFX08.VLR_ICMS_FRETE, C_SAFX08.VLR_DIFAL_FRETE,
             C_SAFX08.IND_VLR_PIS_COFINS, C_SAFX08.COD_ENQUAD_IPI, C_SAFX08.COD_SITUACAO_PIS, C_SAFX08.QTD_BASE_PIS,
             C_SAFX08.VLR_ALIQ_PIS_R, C_SAFX08.COD_SITUACAO_COFINS, C_SAFX08.QTD_BASE_COFINS, C_SAFX08.VLR_ALIQ_COFINS_R,
             C_SAFX08.ITEM_PORT_TARE, C_SAFX08.VLR_FUNRURAL, C_SAFX08.IND_TP_PROD_MEDIC, C_SAFX08.VLR_CUSTO_DCA,
             C_SAFX08.COD_TP_LANCTO, C_SAFX08.VLR_PERC_CRED_OUT, C_SAFX08.VLR_CRED_OUT, C_SAFX08.VLR_ICMS_DCA,
             C_SAFX08.VLR_PIS_EXP, C_SAFX08.VLR_PIS_TRIB, C_SAFX08.VLR_PIS_N_TRIB, C_SAFX08.VLR_COFINS_EXP,
             C_SAFX08.VLR_COFINS_TRIB, C_SAFX08.VLR_COFINS_N_TRIB, C_SAFX08.COD_ENQ_LEGAL, C_SAFX08.DAT_LANC_PIS_COFINS,
             C_SAFX08.IND_PIS_COFINS_EXTEMP, C_SAFX08.IND_NATUREZA_FRETE, V_COD_NAT_REC, C_SAFX08.IND_NAT_BASE_CRED,
             C_SAFX08.VLR_ACRESCIMO, C_SAFX08.IND_IPI_NDESTAC_DF, C_SAFX08.DSC_RESERVADO1, C_SAFX08.DSC_RESERVADO2,
             C_SAFX08.DSC_RESERVADO3, C_SAFX08.COD_TRIB_PROD, C_SAFX08.DSC_RESERVADO4, C_SAFX08.DSC_RESERVADO5,
             C_SAFX08.DSC_RESERVADO6, C_SAFX08.DSC_RESERVADO7, C_SAFX08.DSC_RESERVADO8, C_SAFX08.INDICE_PROD_ACAB,
             C_SAFX08.VLR_BASE_DIA_AM, C_SAFX08.VLR_ALIQ_DIA_AM, C_SAFX08.VLR_ICMS_DIA_AM, C_SAFX08.VLR_ADUANEIRO,
             C_SAFX08.COD_SITUACAO_PIS_ST, C_SAFX08.COD_SITUACAO_COFINS_ST, C_SAFX08.VLR_ALIQ_DCIP, C_SAFX08.NUM_LI,
             C_SAFX08.VLR_FCP_UF_DEST, C_SAFX08.VLR_ICMS_UF_DEST, C_SAFX08.VLR_ICMS_UF_ORIG, C_SAFX08.VLR_DIF_DUB,
             C_SAFX08.VLR_ICMS_NAO_DEST, C_SAFX08.VLR_BASE_ICMS_NAO_DEST, C_SAFX08.VLR_ALIQ_ICMS_NAO_DEST, C_SAFX08.IND_MOTIVO_RES,
             C_SAFX08.NUM_DOCFIS_RET, C_SAFX08.SERIE_DOCFIS_RET, C_SAFX08.NUM_AUTENTIC_NFE_RET, C_SAFX08.NUM_ITEM_RET,
             C_SAFX08.IND_FIS_JUR_RET, C_SAFX08.COD_FIS_JUR_RET, C_SAFX08.IND_TP_DOC_ARREC, C_SAFX08.NUM_DOC_ARREC,
             C_SAFX08.COD_CFO_DCIP,
             C_SAFX08.VLR_OUTROS2, C_SAFX08.VLR_OUTROS3, C_SAFX08.VLR_OUTROS4, C_SAFX08.VLR_OUTROS5,
             C_SAFX08.VLR_ALIQ_OUTROS1, C_SAFX08.VLR_ALIQ_OUTROS2, C_SAFX08.IND_ATO_COTEPE,
             C_SAFX08.VLR_FATOR_CONV, C_SAFX08.NUM_PROCESSO, C_SAFX08.VLR_BASE_INSS, C_SAFX08.VLR_INSS_RETIDO,
             C_SAFX08.VLR_TOT_ADIC, C_SAFX08.VLR_N_RET_PRINC, C_SAFX08.VLR_N_RET_ADIC, C_SAFX08.VLR_ALIQ_INSS,
             C_SAFX08.VLR_RET_SERV, C_SAFX08.VLR_SERV_15, C_SAFX08.VLR_SERV_20, C_SAFX08.VLR_SERV_25,
             C_SAFX08.IND_TP_PROC_ADJ_PRINC, C_SAFX08.NUM_PROC_ADJ_PRINC, C_SAFX08.COD_SUSP_PRINC, C_SAFX08.IND_TP_PROC_ADJ_ADIC,
             C_SAFX08.NUM_PROC_ADJ_ADIC, C_SAFX08.COD_SUSP_ADIC, C_SAFX08.VLR_IPI_DEV, C_SAFX08.COD_BENEFICIO,
             C_SAFX08.VLR_ABAT_NTRIBUTADO, SYSDATE);
         COMMITAR;
      END LOOP;
   END LOOP;
   COMMIT;
END;