Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace view vr_xmlnfe as
- select x.Id, x.ide_cUF, x.ide_cNF, x.ide_natOP, x.ide_indPag, x.ide_mod,
- x.ide_serie, x.ide_nNF, x.ide_dEmi, x.ide_dhEmi, x.ide_dSaiEnt,
- x.ide_hSaiEnt, x.ide_dhSaiEnt, x.ide_tpNF, x.ide_cMunFG, x.ide_tpImp,
- x.ide_tpEmis, x.ide_cDV, x.ide_tpAmb, x.ide_finNFe, x.ide_procEmi,
- x.ide_verProc, x.ide_idDest, x.ide_indFinal, x.ide_indPres,
- x.ide_dhCont, x.ide_xJust,
- --emit
- x.emit_cnpj, x.emit_cpf, x.emit_xNome, x.emit_xFant,
- --emit_enderEmit
- x.emit_enderEmit_xLgr, x.emit_enderEmit_nro, x.emit_enderEmit_xCpl,
- x.emit_enderEmit_xBairro, x.emit_enderEmit_cMun,
- x.emit_enderEmit_xMun, x.emit_enderEmit_UF, x.emit_enderEmit_CEP,
- x.emit_enderEmit_cPais, x.emit_enderEmit_xPais, x.emit_enderEmit_fone,
- x.emit_IE, x.emit_IEST, x.emit_IM, x.emit_CNAE, x.emit_CRT,
- --dest
- x.dest_cnpj, x.dest_cpf, x.dest_xNome, x.dest_indIEDest,
- --dest_enderDest
- x.dest_enderDest_xLgr, x.dest_enderDest_nro, x.dest_enderDest_xCpl,
- x.dest_enderDest_xBairro, x.dest_enderDest_cMun,
- x.dest_enderDest_xMun, x.dest_enderDest_UF, x.dest_enderDest_CEP,
- x.dest_enderDest_cPais, x.dest_enderDest_xPais, x.dest_enderDest_fone,
- x.dest_IE, x.dest_ISUF,
- --retirada
- x.retirada_CNPJ, x.retirada_xLgr, x.retirada_nro, x.retirada_xCpl,
- x.retirada_xBairro, x.retirada_cMun, x.retirada_xMun, x.retirada_UF,
- --entrega
- x.entrega_CNPJ, x.entrega_CPF, x.entrega_xLgr, x.entrega_nro,
- x.entrega_xCpl, x.entrega_xBairro, x.entrega_cMun, x.entrega_xMun,
- x.entrega_UF,
- --total_ICMSTot
- x.total_ICMSTot_vbc, x.total_ICMSTot_vICMS,
- x.total_ICMSTot_vICMSDeson, x.total_ICMSTot_vFCPUFDest,
- x.total_ICMSTot_vICMSUFDest, x.total_ICMSTot_vICMSUFRemet,
- x.total_ICMSTot_vBCST, x.total_ICMSTot_vST, x.total_ICMSTot_vprod,
- x.total_ICMSTot_vFrete, x.total_ICMSTot_vSeg, x.total_ICMSTot_vDesc,
- x.total_ICMSTot_vII, x.total_ICMSTot_vIPI, x.total_ICMSTot_vPIS,
- x.total_ICMSTot_vCOFINS, x.total_ICMSTot_vOutro, x.total_ICMSTot_vNF,
- x.total_ICMSTot_vFCP, x.total_ICMSTot_vFCPST,
- x.total_ICMSTot_vFCPSTRet, x.total_ICMSTot_vIPIDevol,
- --total_ISSQNTot
- x.total_ISSQNTot_vServ, x.total_ISSQNTot_vBC, x.total_ISSQNTot_vISS,
- x.total_ISSQNTot_vPIS, x.total_ISSQNTot_vCOFINS,
- --total_RetTrib
- x.total_RetTrib_vRetPIS, x.total_RetTrib_vRetCOFINS,
- x.total_RetTrib_vRetCSLL, x.total_RetTrib_vBCIRRF,
- x.total_RetTrib_vIRRF, x.total_RetTrib_vBCRetPrev,
- x.total_RetTrib_vRetPrev, x.pag_detPag_vPag,
- --transp
- x.transp_modFrete,
- --transp_transporta
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
- null
- else
- x.transp_transporta_CNPJ
- end transp_transporta_CNPJ,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
- null
- else
- x.transp_transporta_CPF
- end transp_transporta_CPF,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
- null
- else
- x.transp_transporta_xNome
- end transp_transporta_xNome,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
- null
- else
- x.transp_transporta_IE
- end transp_transporta_IE,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
- null
- else
- x.transp_transporta_xEnder
- end transp_transporta_xEnder,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
- null
- else
- x.transp_transporta_xMun
- end transp_transporta_xMun,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
- null
- else
- x.transp_transporta_UF
- end transp_transporta_UF,
- --transp_rettransp
- x.transp_retTransp_vServ, x.transp_retTransp_vBCRet,
- x.transp_retTransp_pICMSRet, x.transp_retTransp_vICMSRet,
- x.transp_retTransp_CFOP, x.transp_retTransp_cMunFG,
- --veiculo
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupoveiculotransp = 0)) then
- null
- else
- x.transp_veicTransp_placa
- end transp_veicTransp_placa,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupoveiculotransp = 0)) then
- null
- else
- x.transp_veicTransp_UF
- end transp_veicTransp_UF,
- case
- when ((x.ide_idDest = 2) or
- (x.ide_idDest = 1 and x.enviagrupoveiculotransp = 0)) then
- null
- else
- x.transp_veicTransp_RNTC
- end transp_veicTransp_RNTC,
- --vol
- x.transp_vol_qVol, x.transp_vol_esp, x.transp_vol_marca,
- x.transp_vol_nVol, x.transp_vol_pesoL, x.transp_vol_pesoB,
- --cobr_fat
- x.cobr_fat_nFat, x.cobr_fat_vOrig, x.cobr_fat_vDesc, x.cobr_fat_vLiq,
- --infAdic
- x.infAdic_infAdFisco, x.infAdic_infCpl,
- --exporta
- x.exporta_UFEmbarq, x.exporta_xLocEmbarq,
- --compra
- x.compra_xNEmp, x.compra_xPed, x.compra_xCont, x.h$idprenf,
- x.h$dataemissao, x.autxml_cnpj
- from (select 'NFe' || nfi.chaveacessonfe Id,
- pk_utilities.getCodigoFederecaoEstado(nfi.estado_emit) ide_cUF,
- lpad(nfi.codigointerno, 8, 0) ide_cNF,
- trim(substr(nfi.descroper, 1, 60)) ide_natOP,
- nvl(nfi.formapagamento, 0) ide_indPag,
- nvl(nfi.modelodocfiscal, '55') ide_mod,
- decode(nfi.sequencia, null, '0', nfi.sequencia) ide_serie,
- nfi.codigointerno ide_nNF,
- to_char(to_date(nfi.data_emissao, 'dd/mm/yyyy'), 'rrrr-mm-dd') ide_dEmi,
- to_char(to_date(nfi.data_emissao ||
- to_char(sysdate, 'hh24:mi:ss'),
- 'dd/mm/yyyy hh24:mi:ss'),
- 'YYYY-MM-DD"T"HH24:MI:SS') ||
- TO_CHAR(SYSTIMESTAMP, 'tzr') ide_dhEmi,
- to_char(to_date(nvl(nfi.data_saida_entrada, nfi.data_emissao),
- 'dd/mm/yy', 'NLS_DATE_LANGUAGE = AMERICAN'),
- 'rrrr-mm-dd') ide_dSaiEnt, null ide_hSaiEnt,
- to_char(to_date(nvl(nfi.data_saida_entrada, nfi.data_emissao) ||
- to_char(sysdate, 'hh24:mi:ss'),
- 'dd/mm/yyyy hh24:mi:ss'),
- 'YYYY-MM-DD"T"HH24:MI:SS') ||
- TO_CHAR(SYSTIMESTAMP, 'tzr') ide_dhSaiEnt,
- decode(nfi.tipo, 'E', 0, 'S', 1) ide_tpNF,
- nfi.codmunic_emit ide_cMunFG,
- nfi.formatoimpressadante ide_tpImp,
- nfi.formaemissaonfe ide_tpEmis,
- substr(nfi.chaveacessonfe, 44, 1) ide_cDV,
- decode(nfi.tipoambiente, 0, 2, 1) ide_tpAmb,
- nfi.finalidadeemissao ide_finNFe,
- nfi.processoemissao ide_procEmi,
- nfi.versaosistemagerounfe ide_verProc,
- decode(substr(nfi.cfop1, 0, 1), 5, '1', 6, '2', 7, '3', 1, '1',
- 2, '2', 3, '3', nfi.cfop1) ide_idDest,
- decode(dest.tipoinscricaoestadual, 1, 0, 1) ide_indFinal,
- nvl(nfi.presencacomprador, 9) ide_indPres,
- decode(nfi.dtcontingencianfe, null, null,
- to_char(nfi.dtcontingencianfe, 'YYYY-MM-DD"T"HH24:MI:SS') ||
- TO_CHAR(SYSTIMESTAMP, 'tzr')) ide_dhCont,
- nfi.justcontingencianfe ide_xJust,
- --emit
- decode(length(replace(replace(replace(nfi.cnpj_emitente, '.',
- ''), '/', ''), '-', '')),
- 14,
- replace(replace(replace(nfi.cnpj_emitente, '.', ''), '/',
- ''), '-', ''), null) emit_cnpj,
- decode(length(replace(replace(replace(nfi.cnpj_emitente, '.',
- ''), '/', ''), '-', '')),
- 11,
- replace(replace(replace(nfi.cnpj_emitente, '.', ''), '/',
- ''), '-', ''), null) emit_cpf,
- nfi.nome_emit emit_xNome, '' emit_xFant,
- --emit_enderEmit
- trim(nfi.endereco_emit) emit_enderEmit_xLgr,
- nvl(nfi.numend_emit, 0) emit_enderEmit_nro,
- trim(nfi.complementoend_emit) emit_enderEmit_xCpl,
- trim(nfi.bairro_emit) emit_enderEmit_xBairro,
- nfi.codmunic_emit emit_enderEmit_cMun,
- trim(nfi.cidade_emit) emit_enderEmit_xMun,
- nfi.estado_emit emit_enderEmit_UF,
- replace(replace(nvl(nfi.cep_emit, '00000000'), '.', ''), '-',
- '') emit_enderEmit_CEP, 1058 emit_enderEmit_cPais,
- 'BRASIL' emit_enderEmit_xPais,
- replace(nfi.fone_emit, ' ', '') emit_enderEmit_fone,
- replace(replace(replace(replace(replace(nfi.Ie_Emit, ' ', ''),
- '.', ''), '-', ''), '/', ''),
- ':', '') emit_IE,
- nfi.inscrestadualsubsttrib emit_IEST, nfi.im_emit emit_IM,
- decode(nfi.im_emit, null, null, nfi.cnaefiscal_emit) emit_CNAE,
- decode(nfi.tipoRegimeTributacao, 0, 3, 1) emit_CRT,
- --dest
- decode(length(replace(replace(replace(nfi.cnpj_dest, '.', ''),
- '/', ''), '-', '')), 14,
- replace(replace(replace(nfi.cnpj_dest, '.', ''), '/', ''),
- '-', ''), null) dest_cnpj,
- decode(length(replace(replace(replace(nfi.cnpj_dest, '.', ''),
- '/', ''), '-', '')), 11,
- replace(replace(replace(nfi.cnpj_dest, '.', ''), '/', ''),
- '-', ''), null) dest_cpf,
- decode(nfi.tipoambiente, 0,
- 'NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL',
- nfi.nome_dest) dest_xNome,
- nvl(nfi.indIEDest, 1) dest_indIEDest,
- --dest_enderDest
- trim(nfi.endereco_dest) dest_enderDest_xLgr,
- trim(nvl(nfi.numend_dest, 0)) dest_enderDest_nro,
- trim(nfi.complementoend_dest) dest_enderDest_xCpl,
- trim(nfi.bairro_dest) dest_enderDest_xBairro,
- nfi.codmunic_dest dest_enderDest_cMun,
- trim(nfi.cidade_dest) dest_enderDest_xMun,
- nfi.estado_dest dest_enderDest_UF,
- replace(replace(nvl(nfi.cep_dest, '00000000'), '.', ''), '-',
- '') dest_enderDest_CEP, 1058 dest_enderDest_cPais,
- 'BRASIL' dest_enderDest_xPais,
- replace(nfi.telefone_dest, ' ', '') dest_enderDest_fone,
- decode(nfi.indIEDest, 1,
- replace(replace(replace(replace(replace(nfi.inscrestadual_dest,
- ' ', ''), '.', ''),
- '-', ''), '/', ''), ':', ''),
- null) dest_IE, nfi.suframa_dest dest_ISUF,
- --retirada
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- replace(replace(replace(nfi.cnpj_unidade, '.', ''),
- '/', ''), '-', '')), 'RG', null,
- replace(replace(replace(nfi.cnpj_unidade, '.', ''), '/',
- ''), '-', '')) retirada_CNPJ,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.endereco_unid), 'RG', null,
- nfi.endereco_unid) retirada_xLgr,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.numend_unid), 'RG', null, nfi.numend_unid) retirada_nro,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.complementoend_unid), 'RG', null,
- nfi.complementoend_unid) retirada_xCpl,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.bairro_unid), 'RG', null, nfi.bairro_unid) retirada_xBairro,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.codmunic_unid), 'RG', null,
- nfi.codmunic_unid) retirada_cMun,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.cidade_unid), 'RG', null, nfi.cidade_unid) retirada_xMun,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.estado_unid), 'RG', null, nfi.estado_unid) retirada_UF,
- --entrega
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- decode(length(replace(replace(replace(nfi.cnpj_entrega,
- '.', ''), '/',
- ''), '-', '')), 14,
- replace(replace(replace(nfi.cnpj_entrega,
- '.', ''), '/', ''),
- '-', ''), null)), 'RG', null,
- decode(length(replace(replace(replace(nfi.cnpj_entrega,
- '.', ''), '/', ''),
- '-', '')), 14,
- replace(replace(replace(nfi.cnpj_entrega, '.', ''),
- '/', ''), '-', ''), null)) entrega_CNPJ,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- decode(length(replace(replace(replace(nfi.cnpj_entrega,
- '.', ''), '/',
- ''), '-', '')), 11,
- replace(replace(replace(nfi.cnpj_entrega,
- '.', ''), '/', ''),
- '-', ''), null)), 'RG', null,
- decode(length(replace(replace(replace(nfi.cnpj_entrega,
- '.', ''), '/', ''),
- '-', '')), 11,
- replace(replace(replace(nfi.cnpj_entrega, '.', ''),
- '/', ''), '-', ''), null)) entrega_CPF,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.endereco_entrega), 'RG', null,
- nfi.endereco_entrega) entrega_xLgr,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.numend_entrega), 'RG', null,
- nfi.numend_entrega) entrega_nro,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.complementoend_entrega), 'RG', null,
- nfi.complementoend_entrega) entrega_xCpl,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.bairro_entrega), 'RG', null,
- nfi.bairro_entrega) entrega_xBairro,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.codmunic_entrega), 'RG', null,
- nfi.codmunic_entrega) entrega_cMun,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.cidade_entrega), 'RG', null,
- nfi.cidade_entrega) entrega_xMun,
- decode(o.tipooper, 'TG', null, 'TS',
- decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
- nfi.estado_entrega), 'RG', null,
- nfi.estado_entrega) entrega_UF,
- --total_ICMSTot
- pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf,
- 'baseicms') total_ICMSTot_vbc,
- pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf,
- 'valoricms') total_ICMSTot_vICMS,
- 0 total_ICMSTot_vICMSDeson,
- (case
- when o.tipooper = 'RT'
- and (nfi.estado_dest <> nfi.estado_emit) then
- nfi.vfcpufdest
- end) total_ICMSTot_vFCPUFDest,
- (case
- when o.tipooper = 'RT'
- and (nfi.estado_dest <> nfi.estado_emit) then
- nfi.vicmsufdest
- end) total_ICMSTot_vICMSUFDest,
- (case
- when o.tipooper = 'RT'
- and (nfi.estado_dest <> nfi.estado_emit) then
- nfi.vicmsufremet
- end) total_ICMSTot_vICMSUFRemet,
- pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf,
- 'baseicmssubst') total_ICMSTot_vBCST,
- nvl(nfi.valorsubstituicao, 0) total_ICMSTot_vST,
- round(nvl(nfi.vlrprodutos, 0), 2) total_ICMSTot_vprod,
- nvl(nfi.frete, 0) total_ICMSTot_vFrete,
- nvl(nfi.seguro, 0) total_ICMSTot_vSeg,
- nvl(nfi.valordesconto, 0) total_ICMSTot_vDesc,
- nvl(nfi.valortotalimpimportacao, 0) total_ICMSTot_vII,
- pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf, 'ipi') total_ICMSTot_vIPI,
- nvl(nfi.pis, 0) total_ICMSTot_vPIS,
- nvl(nfi.cofins, 0) total_ICMSTot_vCOFINS,
- nvl(nfi.despesasacessorias, 0) total_ICMSTot_vOutro,
- round(nvl(nfi.vlrtotal, 0), 4) total_ICMSTot_vNF,
- nvl(nfi.totalfcp, 0) total_ICMSTot_vFCP,
- nvl(nfi.totalfcpst, 0) total_ICMSTot_vFCPST,
- nvl(nfi.totalfcpstret, 0) total_ICMSTot_vFCPSTRet,
- nvl(nfi.totalipidevolvido, 0) total_ICMSTot_vIPIDevol,
- --total_ISSQNTot
- /*decode(nfi.valorservicos, 0, null, nfi.valorservicos)*/
- null total_ISSQNTot_vServ, null total_ISSQNTot_vBC,
- /*decode(nfi.valoriss, 0, null, nfi.valoriss)*/
- null total_ISSQNTot_vISS,
- /*decode(nfi.pis, 0, null, nfi.pis)*/ null total_ISSQNTot_vPIS,
- /*decode(nfi.cofins, 0, null, nfi.cofins)*/
- null total_ISSQNTot_vCOFINS,
- --total_RetTrib
- null total_RetTrib_vRetPIS, null total_RetTrib_vRetCOFINS,
- decode(nfi.cs, 0, null, nfi.cs) total_RetTrib_vRetCSLL,
- null total_RetTrib_vBCIRRF,
- decode(nfi.ir, 0, null, nfi.ir) total_RetTrib_vIRRF,
- null total_RetTrib_vBCRetPrev, null total_RetTrib_vRetPrev,
- decode(c.versaonfe, 1, round(nvl(nfi.vlrprodutos, 0), 2), null) pag_detPag_vPag,
- --transp
- decode(o.tipooper, 'TS', 9, 'TG', 9,
- decode(nvl(transp.transportadoraimune, 0), 0,
- decode(nvl(to_char(nfi.ciffob), 1), '1', 0, '2', 1,
- '4', 2, '5', 9, 0), 9)) transp_modFrete,
- --transp_transporta
- decode(nvl(transp.transportadoraimune, 0), 0,
- decode(length(replace(replace(replace(nfi.cnpj_transp,
- '.', ''), '/', ''),
- '-', '')), 14,
- replace(replace(replace(nfi.cnpj_transp, '.', ''),
- '/', ''), '-', ''), null), '') transp_transporta_CNPJ,
- decode(length(replace(replace(replace(nfi.cnpj_transp, '.', ''),
- '/', ''), '-', '')), 11,
- replace(replace(replace(nfi.cnpj_transp, '.', ''), '/',
- ''), '-', ''), null) transp_transporta_CPF,
- decode(nvl(transp.transportadoraimune, 0), 1, '',
- nfi.nome_transp) transp_transporta_xNome,
- decode(upper(nfi.inscrestadual_transp), 'INSCRICAOESTADUAL',
- null,
- replace(replace(replace(replace(replace(nfi.inscrestadual_transp,
- ' ', ''), '.', ''),
- '-', ''), '/', ''), ':', '')) transp_transporta_IE,
- decode(nvl(transp.transportadoraimune, 0), 0,
- trim(substr(replace(trim(nfi.endereco_transp) || ' ' ||
- nfi.numend_transp || ' ' ||
- trim(nfi.bairro_transp), ',', ''), 1,
- 60)), '') transp_transporta_xEnder,
- decode(nvl(transp.transportadoraimune, 0), 0,
- trim(nfi.cidade_transp), '') transp_transporta_xMun,
- decode(nvl(transp.transportadoraimune, 0), 0,
- nfi.estado_transp, '') transp_transporta_UF,
- --transp_rettransp
- null transp_retTransp_vServ, null transp_retTransp_vBCRet,
- null transp_retTransp_pICMSRet, null transp_retTransp_vICMSRet,
- null transp_retTransp_CFOP, null transp_retTransp_cMunFG,
- --veiculo
- replace(nfi.veiculo, '-', '') transp_veicTransp_placa,
- nfi.estado_veiculo transp_veicTransp_UF,
- decode(nfi.veiculo, null, null, nfi.registroantt) transp_veicTransp_RNTC,
- --vol
- decode(nvl(transp.transportadoraimune, 0), 0,
- decode(v.qtdevolumes, 0, null,
- nvl(v.qtdevolumes, round(nfi.qtde))), '') transp_vol_qVol,
- trim(nfi.especie) transp_vol_esp, nfi.marca transp_vol_marca,
- nfi.numero transp_vol_nVol,
- decode(nvl(transp.transportadoraimune, 0), 0,
- round(nfi.pesoliquido / 1000, 3), '') transp_vol_pesoL,
- decode(nvl(transp.transportadoraimune, 0), 0,
- round(nfi.pesobruto / 1000, 3), '') transp_vol_pesoB,
- --cobr_fat
- decode(round(nvl(nfi.vlrtotal, 0), 4), 0, null,
- nfi.codigointerno) cobr_fat_nFat,
- decode(round(nvl(nfi.vlrtotal, 0), 4) +
- nvl(nfi.valordesconto, 0), 0, null,
- round(nvl(nfi.vlrtotal, 0), 4) +
- nvl(nfi.valordesconto, 0)) cobr_fat_vOrig,
- decode(nfi.valordesconto, 0, decode(c.versaonfe, 1, 0, null),
- nfi.valordesconto) cobr_fat_vDesc,
- decode(round(nvl(nfi.vlrtotal, 0), 4), 0, null,
- round(nvl(nfi.vlrtotal, 0), 4)) cobr_fat_vLiq,
- --infAdic
- trim(translate(substr(trim(nfi.observacao), 0, 256),
- ',$%#@*''&''º°ª–´`', '')) infAdic_infAdFisco,
- trim(translate(substr(replace(trim(trim(nfi.mensagemoperacao1) ||
- decode(trim(nfi.mensagemoperacao1),
- null, null, ' ') ||
- trim(nfi.mensagemoperacao2) ||
- decode(trim(nfi.mensagemoperacao2),
- null, null, ' ') ||
- trim(nfi.mensagemretorno) ||
- decode(trim(nfi.mensagemcoberturanf),
- null, null, ' | ') ||
- trim(nfi.mensagemcoberturanf) ||
- decode(trim(trim(decode(nfi.instrucao1,
- nfi.mensagemoperacao1,
- '',
- nfi.instrucao1)) || ' ' ||
- trim(decode(nfi.instrucao2,
- nfi.mensagemoperacao2,
- '',
- nfi.instrucao2)) || ' ' ||
- trim(nfi.instrucao3) || ' ' ||
- trim(nfi.instrucao4) || ' ' ||
- trim(nfi.instrucao5) || ' ' ||
- trim(nfi.instrucao6) || ' ' ||
- trim(nfi.instrucao7) || ' ' ||
- trim(nfi.instrucao8) || ' ' ||
- trim(nfi.instrucao9) || ' ' ||
- trim(nfi.instrucao10) || ' ' ||
- trim(nfi.instrucao11) || ' ' ||
- trim(nfi.instrucao12) || ' ' ||
- trim(nfi.instrucao13) || ' ' ||
- trim(nfi.instrucao14) || ' ' ||
- trim(nfi.instrucao15) || ' ' ||
- trim(nfi.instrucao16) || ' ' ||
- trim(nfi.instrucao17) || ' ' ||
- trim(nfi.instrucao18) || ' ' ||
- trim(nfi.instrucao19) || ' ' ||
- trim(nfi.instrucao20) || ' ' ||
- trim(nfi.instrucao21) || ' ' ||
- trim(nfi.instrucao22) || ' ' ||
- substr(trim(nfi.observacao),
- 0, 256)),
- null, null, ' | ') ||
- trim(decode(nfi.instrucao1,
- nfi.mensagemoperacao1,
- '',
- nfi.instrucao1)) || ' ' ||
- trim(decode(nfi.instrucao2,
- nfi.mensagemoperacao2,
- '',
- nfi.instrucao2)) || ' ' ||
- trim(nfi.instrucao3) || ' ' ||
- trim(nfi.instrucao4) || ' ' ||
- trim(nfi.instrucao5) || ' ' ||
- trim(nfi.instrucao6) || ' ' ||
- trim(nfi.instrucao7) || ' ' ||
- trim(nfi.instrucao8) || ' ' ||
- trim(nfi.instrucao9) || ' ' ||
- trim(nfi.instrucao10) || ' ' ||
- trim(nfi.instrucao11) || ' ' ||
- trim(nfi.instrucao12) || ' ' ||
- trim(nfi.instrucao13) || ' ' ||
- trim(nfi.instrucao14) || ' ' ||
- trim(nfi.instrucao15) || ' ' ||
- trim(nfi.instrucao16) || ' ' ||
- trim(nfi.instrucao17) || ' ' ||
- trim(nfi.instrucao18) || ' ' ||
- trim(nfi.instrucao19) || ' ' ||
- trim(nfi.instrucao20) || ' ' ||
- trim(nfi.instrucao21) || ' ' ||
- trim(nfi.instrucao22) || ' ' ||
- substr(trim(nfi.observacao),
- 0, 256)), chr(13)), 1,
- 5000), ',$%#@*''&''º°ª–´`', ' ')) infAdic_infCpl,
- --exporta
- nfi.uflocalembarque exporta_UFEmbarq,
- nfi.localembarque exporta_xLocEmbarq,
- --compra
- '' compra_xNEmp, nfi.numpedido compra_xPed, '' compra_xCont,
- nfi.idprenf h$idprenf, nfi.data_emissao h$dataemissao,
- decode(nfi.estado_emit, 'BA', '13937073000156', null) autxml_cnpj,
- et.enviagrupotransporta, et.enviagrupoveiculotransp,
- et.enviagruporeboque
- from nfimpressao nfi, configuracao c,
- (select nf.idprenf, count(1) qtdevolumes
- from notafiscal nf, volumeromaneio vr
- where vr.idnotafiscal = nf.idnotafiscal
- and vr.statusvolume = 0
- and vr.geradoautomaticamente = 0
- group by nf.idprenf) v, notafiscal nf, operacao o,
- entidade transp, entidade dest, depositante dep, regime r,
- estado et
- where v.idprenf(+) = nfi.idprenf
- and nf.idprenf = nfi.idprenf
- and o.idoperacao = nf.idoperacao
- and transp.identidade(+) = nf.transportadoranotafiscal
- and dest.identidade = nf.destinatario
- and nf.iddepositante = dep.identidade
- and dep.idregime = r.idregime
- and et.uf(+) = nfi.estado_dest
- and c.ativo = 'S') x;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement