Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.97 KB | None | 0 0
  1. create or replace view vr_xmlnfe as
  2. select x.Id, x.ide_cUF, x.ide_cNF, x.ide_natOP, x.ide_indPag, x.ide_mod,
  3. x.ide_serie, x.ide_nNF, x.ide_dEmi, x.ide_dhEmi, x.ide_dSaiEnt,
  4. x.ide_hSaiEnt, x.ide_dhSaiEnt, x.ide_tpNF, x.ide_cMunFG, x.ide_tpImp,
  5. x.ide_tpEmis, x.ide_cDV, x.ide_tpAmb, x.ide_finNFe, x.ide_procEmi,
  6. x.ide_verProc, x.ide_idDest, x.ide_indFinal, x.ide_indPres,
  7. x.ide_dhCont, x.ide_xJust,
  8. --emit
  9. x.emit_cnpj, x.emit_cpf, x.emit_xNome, x.emit_xFant,
  10. --emit_enderEmit
  11. x.emit_enderEmit_xLgr, x.emit_enderEmit_nro, x.emit_enderEmit_xCpl,
  12. x.emit_enderEmit_xBairro, x.emit_enderEmit_cMun,
  13. x.emit_enderEmit_xMun, x.emit_enderEmit_UF, x.emit_enderEmit_CEP,
  14. x.emit_enderEmit_cPais, x.emit_enderEmit_xPais, x.emit_enderEmit_fone,
  15. x.emit_IE, x.emit_IEST, x.emit_IM, x.emit_CNAE, x.emit_CRT,
  16. --dest
  17. x.dest_cnpj, x.dest_cpf, x.dest_xNome, x.dest_indIEDest,
  18. --dest_enderDest
  19. x.dest_enderDest_xLgr, x.dest_enderDest_nro, x.dest_enderDest_xCpl,
  20. x.dest_enderDest_xBairro, x.dest_enderDest_cMun,
  21. x.dest_enderDest_xMun, x.dest_enderDest_UF, x.dest_enderDest_CEP,
  22. x.dest_enderDest_cPais, x.dest_enderDest_xPais, x.dest_enderDest_fone,
  23. x.dest_IE, x.dest_ISUF,
  24. --retirada
  25. x.retirada_CNPJ, x.retirada_xLgr, x.retirada_nro, x.retirada_xCpl,
  26. x.retirada_xBairro, x.retirada_cMun, x.retirada_xMun, x.retirada_UF,
  27. --entrega
  28. x.entrega_CNPJ, x.entrega_CPF, x.entrega_xLgr, x.entrega_nro,
  29. x.entrega_xCpl, x.entrega_xBairro, x.entrega_cMun, x.entrega_xMun,
  30. x.entrega_UF,
  31. --total_ICMSTot
  32. x.total_ICMSTot_vbc, x.total_ICMSTot_vICMS,
  33. x.total_ICMSTot_vICMSDeson, x.total_ICMSTot_vFCPUFDest,
  34. x.total_ICMSTot_vICMSUFDest, x.total_ICMSTot_vICMSUFRemet,
  35. x.total_ICMSTot_vBCST, x.total_ICMSTot_vST, x.total_ICMSTot_vprod,
  36. x.total_ICMSTot_vFrete, x.total_ICMSTot_vSeg, x.total_ICMSTot_vDesc,
  37. x.total_ICMSTot_vII, x.total_ICMSTot_vIPI, x.total_ICMSTot_vPIS,
  38. x.total_ICMSTot_vCOFINS, x.total_ICMSTot_vOutro, x.total_ICMSTot_vNF,
  39. x.total_ICMSTot_vFCP, x.total_ICMSTot_vFCPST,
  40. x.total_ICMSTot_vFCPSTRet, x.total_ICMSTot_vIPIDevol,
  41. --total_ISSQNTot
  42. x.total_ISSQNTot_vServ, x.total_ISSQNTot_vBC, x.total_ISSQNTot_vISS,
  43. x.total_ISSQNTot_vPIS, x.total_ISSQNTot_vCOFINS,
  44. --total_RetTrib
  45. x.total_RetTrib_vRetPIS, x.total_RetTrib_vRetCOFINS,
  46. x.total_RetTrib_vRetCSLL, x.total_RetTrib_vBCIRRF,
  47. x.total_RetTrib_vIRRF, x.total_RetTrib_vBCRetPrev,
  48. x.total_RetTrib_vRetPrev, x.pag_detPag_vPag,
  49. --transp
  50. x.transp_modFrete,
  51. --transp_transporta
  52. case
  53. when ((x.ide_idDest = 2) or
  54. (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
  55. null
  56. else
  57. x.transp_transporta_CNPJ
  58. end transp_transporta_CNPJ,
  59. case
  60. when ((x.ide_idDest = 2) or
  61. (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
  62. null
  63. else
  64. x.transp_transporta_CPF
  65. end transp_transporta_CPF,
  66. case
  67. when ((x.ide_idDest = 2) or
  68. (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
  69. null
  70. else
  71. x.transp_transporta_xNome
  72. end transp_transporta_xNome,
  73. case
  74. when ((x.ide_idDest = 2) or
  75. (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
  76. null
  77. else
  78. x.transp_transporta_IE
  79. end transp_transporta_IE,
  80. case
  81. when ((x.ide_idDest = 2) or
  82. (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
  83. null
  84. else
  85. x.transp_transporta_xEnder
  86. end transp_transporta_xEnder,
  87. case
  88. when ((x.ide_idDest = 2) or
  89. (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
  90. null
  91. else
  92. x.transp_transporta_xMun
  93. end transp_transporta_xMun,
  94. case
  95. when ((x.ide_idDest = 2) or
  96. (x.ide_idDest = 1 and x.enviagrupotransporta = 0)) then
  97. null
  98. else
  99. x.transp_transporta_UF
  100. end transp_transporta_UF,
  101. --transp_rettransp
  102. x.transp_retTransp_vServ, x.transp_retTransp_vBCRet,
  103. x.transp_retTransp_pICMSRet, x.transp_retTransp_vICMSRet,
  104. x.transp_retTransp_CFOP, x.transp_retTransp_cMunFG,
  105. --veiculo
  106. case
  107. when ((x.ide_idDest = 2) or
  108. (x.ide_idDest = 1 and x.enviagrupoveiculotransp = 0)) then
  109. null
  110. else
  111. x.transp_veicTransp_placa
  112. end transp_veicTransp_placa,
  113. case
  114. when ((x.ide_idDest = 2) or
  115. (x.ide_idDest = 1 and x.enviagrupoveiculotransp = 0)) then
  116. null
  117. else
  118. x.transp_veicTransp_UF
  119. end transp_veicTransp_UF,
  120. case
  121. when ((x.ide_idDest = 2) or
  122. (x.ide_idDest = 1 and x.enviagrupoveiculotransp = 0)) then
  123. null
  124. else
  125. x.transp_veicTransp_RNTC
  126. end transp_veicTransp_RNTC,
  127. --vol
  128. x.transp_vol_qVol, x.transp_vol_esp, x.transp_vol_marca,
  129. x.transp_vol_nVol, x.transp_vol_pesoL, x.transp_vol_pesoB,
  130. --cobr_fat
  131. x.cobr_fat_nFat, x.cobr_fat_vOrig, x.cobr_fat_vDesc, x.cobr_fat_vLiq,
  132. --infAdic
  133. x.infAdic_infAdFisco, x.infAdic_infCpl,
  134. --exporta
  135. x.exporta_UFEmbarq, x.exporta_xLocEmbarq,
  136. --compra
  137. x.compra_xNEmp, x.compra_xPed, x.compra_xCont, x.h$idprenf,
  138. x.h$dataemissao, x.autxml_cnpj
  139. from (select 'NFe' || nfi.chaveacessonfe Id,
  140. pk_utilities.getCodigoFederecaoEstado(nfi.estado_emit) ide_cUF,
  141. lpad(nfi.codigointerno, 8, 0) ide_cNF,
  142. trim(substr(nfi.descroper, 1, 60)) ide_natOP,
  143. nvl(nfi.formapagamento, 0) ide_indPag,
  144. nvl(nfi.modelodocfiscal, '55') ide_mod,
  145. decode(nfi.sequencia, null, '0', nfi.sequencia) ide_serie,
  146. nfi.codigointerno ide_nNF,
  147. to_char(to_date(nfi.data_emissao, 'dd/mm/yyyy'), 'rrrr-mm-dd') ide_dEmi,
  148. to_char(to_date(nfi.data_emissao ||
  149. to_char(sysdate, 'hh24:mi:ss'),
  150. 'dd/mm/yyyy hh24:mi:ss'),
  151. 'YYYY-MM-DD"T"HH24:MI:SS') ||
  152. TO_CHAR(SYSTIMESTAMP, 'tzr') ide_dhEmi,
  153. to_char(to_date(nvl(nfi.data_saida_entrada, nfi.data_emissao),
  154. 'dd/mm/yy', 'NLS_DATE_LANGUAGE = AMERICAN'),
  155. 'rrrr-mm-dd') ide_dSaiEnt, null ide_hSaiEnt,
  156. to_char(to_date(nvl(nfi.data_saida_entrada, nfi.data_emissao) ||
  157. to_char(sysdate, 'hh24:mi:ss'),
  158. 'dd/mm/yyyy hh24:mi:ss'),
  159. 'YYYY-MM-DD"T"HH24:MI:SS') ||
  160. TO_CHAR(SYSTIMESTAMP, 'tzr') ide_dhSaiEnt,
  161. decode(nfi.tipo, 'E', 0, 'S', 1) ide_tpNF,
  162. nfi.codmunic_emit ide_cMunFG,
  163. nfi.formatoimpressadante ide_tpImp,
  164. nfi.formaemissaonfe ide_tpEmis,
  165. substr(nfi.chaveacessonfe, 44, 1) ide_cDV,
  166. decode(nfi.tipoambiente, 0, 2, 1) ide_tpAmb,
  167. nfi.finalidadeemissao ide_finNFe,
  168. nfi.processoemissao ide_procEmi,
  169. nfi.versaosistemagerounfe ide_verProc,
  170. decode(substr(nfi.cfop1, 0, 1), 5, '1', 6, '2', 7, '3', 1, '1',
  171. 2, '2', 3, '3', nfi.cfop1) ide_idDest,
  172. decode(dest.tipoinscricaoestadual, 1, 0, 1) ide_indFinal,
  173. nvl(nfi.presencacomprador, 9) ide_indPres,
  174. decode(nfi.dtcontingencianfe, null, null,
  175. to_char(nfi.dtcontingencianfe, 'YYYY-MM-DD"T"HH24:MI:SS') ||
  176. TO_CHAR(SYSTIMESTAMP, 'tzr')) ide_dhCont,
  177. nfi.justcontingencianfe ide_xJust,
  178. --emit
  179. decode(length(replace(replace(replace(nfi.cnpj_emitente, '.',
  180. ''), '/', ''), '-', '')),
  181. 14,
  182. replace(replace(replace(nfi.cnpj_emitente, '.', ''), '/',
  183. ''), '-', ''), null) emit_cnpj,
  184. decode(length(replace(replace(replace(nfi.cnpj_emitente, '.',
  185. ''), '/', ''), '-', '')),
  186. 11,
  187. replace(replace(replace(nfi.cnpj_emitente, '.', ''), '/',
  188. ''), '-', ''), null) emit_cpf,
  189. nfi.nome_emit emit_xNome, '' emit_xFant,
  190. --emit_enderEmit
  191. trim(nfi.endereco_emit) emit_enderEmit_xLgr,
  192. nvl(nfi.numend_emit, 0) emit_enderEmit_nro,
  193. trim(nfi.complementoend_emit) emit_enderEmit_xCpl,
  194. trim(nfi.bairro_emit) emit_enderEmit_xBairro,
  195. nfi.codmunic_emit emit_enderEmit_cMun,
  196. trim(nfi.cidade_emit) emit_enderEmit_xMun,
  197. nfi.estado_emit emit_enderEmit_UF,
  198. replace(replace(nvl(nfi.cep_emit, '00000000'), '.', ''), '-',
  199. '') emit_enderEmit_CEP, 1058 emit_enderEmit_cPais,
  200. 'BRASIL' emit_enderEmit_xPais,
  201. replace(nfi.fone_emit, ' ', '') emit_enderEmit_fone,
  202. replace(replace(replace(replace(replace(nfi.Ie_Emit, ' ', ''),
  203. '.', ''), '-', ''), '/', ''),
  204. ':', '') emit_IE,
  205. nfi.inscrestadualsubsttrib emit_IEST, nfi.im_emit emit_IM,
  206. decode(nfi.im_emit, null, null, nfi.cnaefiscal_emit) emit_CNAE,
  207. decode(nfi.tipoRegimeTributacao, 0, 3, 1) emit_CRT,
  208. --dest
  209. decode(length(replace(replace(replace(nfi.cnpj_dest, '.', ''),
  210. '/', ''), '-', '')), 14,
  211. replace(replace(replace(nfi.cnpj_dest, '.', ''), '/', ''),
  212. '-', ''), null) dest_cnpj,
  213. decode(length(replace(replace(replace(nfi.cnpj_dest, '.', ''),
  214. '/', ''), '-', '')), 11,
  215. replace(replace(replace(nfi.cnpj_dest, '.', ''), '/', ''),
  216. '-', ''), null) dest_cpf,
  217. decode(nfi.tipoambiente, 0,
  218. 'NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL',
  219. nfi.nome_dest) dest_xNome,
  220. nvl(nfi.indIEDest, 1) dest_indIEDest,
  221. --dest_enderDest
  222. trim(nfi.endereco_dest) dest_enderDest_xLgr,
  223. trim(nvl(nfi.numend_dest, 0)) dest_enderDest_nro,
  224. trim(nfi.complementoend_dest) dest_enderDest_xCpl,
  225. trim(nfi.bairro_dest) dest_enderDest_xBairro,
  226. nfi.codmunic_dest dest_enderDest_cMun,
  227. trim(nfi.cidade_dest) dest_enderDest_xMun,
  228. nfi.estado_dest dest_enderDest_UF,
  229. replace(replace(nvl(nfi.cep_dest, '00000000'), '.', ''), '-',
  230. '') dest_enderDest_CEP, 1058 dest_enderDest_cPais,
  231. 'BRASIL' dest_enderDest_xPais,
  232. replace(nfi.telefone_dest, ' ', '') dest_enderDest_fone,
  233. decode(nfi.indIEDest, 1,
  234. replace(replace(replace(replace(replace(nfi.inscrestadual_dest,
  235. ' ', ''), '.', ''),
  236. '-', ''), '/', ''), ':', ''),
  237. null) dest_IE, nfi.suframa_dest dest_ISUF,
  238. --retirada
  239. decode(o.tipooper, 'TG', null, 'TS',
  240. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  241. replace(replace(replace(nfi.cnpj_unidade, '.', ''),
  242. '/', ''), '-', '')), 'RG', null,
  243. replace(replace(replace(nfi.cnpj_unidade, '.', ''), '/',
  244. ''), '-', '')) retirada_CNPJ,
  245. decode(o.tipooper, 'TG', null, 'TS',
  246. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  247. nfi.endereco_unid), 'RG', null,
  248. nfi.endereco_unid) retirada_xLgr,
  249. decode(o.tipooper, 'TG', null, 'TS',
  250. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  251. nfi.numend_unid), 'RG', null, nfi.numend_unid) retirada_nro,
  252. decode(o.tipooper, 'TG', null, 'TS',
  253. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  254. nfi.complementoend_unid), 'RG', null,
  255. nfi.complementoend_unid) retirada_xCpl,
  256. decode(o.tipooper, 'TG', null, 'TS',
  257. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  258. nfi.bairro_unid), 'RG', null, nfi.bairro_unid) retirada_xBairro,
  259. decode(o.tipooper, 'TG', null, 'TS',
  260. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  261. nfi.codmunic_unid), 'RG', null,
  262. nfi.codmunic_unid) retirada_cMun,
  263. decode(o.tipooper, 'TG', null, 'TS',
  264. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  265. nfi.cidade_unid), 'RG', null, nfi.cidade_unid) retirada_xMun,
  266. decode(o.tipooper, 'TG', null, 'TS',
  267. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  268. nfi.estado_unid), 'RG', null, nfi.estado_unid) retirada_UF,
  269. --entrega
  270. decode(o.tipooper, 'TG', null, 'TS',
  271. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  272. decode(length(replace(replace(replace(nfi.cnpj_entrega,
  273. '.', ''), '/',
  274. ''), '-', '')), 14,
  275. replace(replace(replace(nfi.cnpj_entrega,
  276. '.', ''), '/', ''),
  277. '-', ''), null)), 'RG', null,
  278. decode(length(replace(replace(replace(nfi.cnpj_entrega,
  279. '.', ''), '/', ''),
  280. '-', '')), 14,
  281. replace(replace(replace(nfi.cnpj_entrega, '.', ''),
  282. '/', ''), '-', ''), null)) entrega_CNPJ,
  283. decode(o.tipooper, 'TG', null, 'TS',
  284. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  285. decode(length(replace(replace(replace(nfi.cnpj_entrega,
  286. '.', ''), '/',
  287. ''), '-', '')), 11,
  288. replace(replace(replace(nfi.cnpj_entrega,
  289. '.', ''), '/', ''),
  290. '-', ''), null)), 'RG', null,
  291. decode(length(replace(replace(replace(nfi.cnpj_entrega,
  292. '.', ''), '/', ''),
  293. '-', '')), 11,
  294. replace(replace(replace(nfi.cnpj_entrega, '.', ''),
  295. '/', ''), '-', ''), null)) entrega_CPF,
  296. decode(o.tipooper, 'TG', null, 'TS',
  297. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  298. nfi.endereco_entrega), 'RG', null,
  299. nfi.endereco_entrega) entrega_xLgr,
  300. decode(o.tipooper, 'TG', null, 'TS',
  301. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  302. nfi.numend_entrega), 'RG', null,
  303. nfi.numend_entrega) entrega_nro,
  304. decode(o.tipooper, 'TG', null, 'TS',
  305. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  306. nfi.complementoend_entrega), 'RG', null,
  307. nfi.complementoend_entrega) entrega_xCpl,
  308. decode(o.tipooper, 'TG', null, 'TS',
  309. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  310. nfi.bairro_entrega), 'RG', null,
  311. nfi.bairro_entrega) entrega_xBairro,
  312. decode(o.tipooper, 'TG', null, 'TS',
  313. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  314. nfi.codmunic_entrega), 'RG', null,
  315. nfi.codmunic_entrega) entrega_cMun,
  316. decode(o.tipooper, 'TG', null, 'TS',
  317. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  318. nfi.cidade_entrega), 'RG', null,
  319. nfi.cidade_entrega) entrega_xMun,
  320. decode(o.tipooper, 'TG', null, 'TS',
  321. decode(nvl(nfi.indIEDest, 0), 0, null, 2, null, 9, null,
  322. nfi.estado_entrega), 'RG', null,
  323. nfi.estado_entrega) entrega_UF,
  324. --total_ICMSTot
  325. pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf,
  326. 'baseicms') total_ICMSTot_vbc,
  327. pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf,
  328. 'valoricms') total_ICMSTot_vICMS,
  329. 0 total_ICMSTot_vICMSDeson,
  330. (case
  331. when o.tipooper = 'RT'
  332. and (nfi.estado_dest <> nfi.estado_emit) then
  333. nfi.vfcpufdest
  334. end) total_ICMSTot_vFCPUFDest,
  335. (case
  336. when o.tipooper = 'RT'
  337. and (nfi.estado_dest <> nfi.estado_emit) then
  338. nfi.vicmsufdest
  339. end) total_ICMSTot_vICMSUFDest,
  340. (case
  341. when o.tipooper = 'RT'
  342. and (nfi.estado_dest <> nfi.estado_emit) then
  343. nfi.vicmsufremet
  344. end) total_ICMSTot_vICMSUFRemet,
  345. pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf,
  346. 'baseicmssubst') total_ICMSTot_vBCST,
  347. nvl(nfi.valorsubstituicao, 0) total_ICMSTot_vST,
  348. round(nvl(nfi.vlrprodutos, 0), 2) total_ICMSTot_vprod,
  349. nvl(nfi.frete, 0) total_ICMSTot_vFrete,
  350. nvl(nfi.seguro, 0) total_ICMSTot_vSeg,
  351. nvl(nfi.valordesconto, 0) total_ICMSTot_vDesc,
  352. nvl(nfi.valortotalimpimportacao, 0) total_ICMSTot_vII,
  353. pk_notafiscal.retornaValorImpostoTotalizado(nfi.idprenf, 'ipi') total_ICMSTot_vIPI,
  354. nvl(nfi.pis, 0) total_ICMSTot_vPIS,
  355. nvl(nfi.cofins, 0) total_ICMSTot_vCOFINS,
  356. nvl(nfi.despesasacessorias, 0) total_ICMSTot_vOutro,
  357. round(nvl(nfi.vlrtotal, 0), 4) total_ICMSTot_vNF,
  358. nvl(nfi.totalfcp, 0) total_ICMSTot_vFCP,
  359. nvl(nfi.totalfcpst, 0) total_ICMSTot_vFCPST,
  360. nvl(nfi.totalfcpstret, 0) total_ICMSTot_vFCPSTRet,
  361. nvl(nfi.totalipidevolvido, 0) total_ICMSTot_vIPIDevol,
  362. --total_ISSQNTot
  363. /*decode(nfi.valorservicos, 0, null, nfi.valorservicos)*/
  364. null total_ISSQNTot_vServ, null total_ISSQNTot_vBC,
  365. /*decode(nfi.valoriss, 0, null, nfi.valoriss)*/
  366. null total_ISSQNTot_vISS,
  367. /*decode(nfi.pis, 0, null, nfi.pis)*/ null total_ISSQNTot_vPIS,
  368. /*decode(nfi.cofins, 0, null, nfi.cofins)*/
  369. null total_ISSQNTot_vCOFINS,
  370. --total_RetTrib
  371. null total_RetTrib_vRetPIS, null total_RetTrib_vRetCOFINS,
  372. decode(nfi.cs, 0, null, nfi.cs) total_RetTrib_vRetCSLL,
  373. null total_RetTrib_vBCIRRF,
  374. decode(nfi.ir, 0, null, nfi.ir) total_RetTrib_vIRRF,
  375. null total_RetTrib_vBCRetPrev, null total_RetTrib_vRetPrev,
  376. decode(c.versaonfe, 1, round(nvl(nfi.vlrprodutos, 0), 2), null) pag_detPag_vPag,
  377. --transp
  378. decode(o.tipooper, 'TS', 9, 'TG', 9,
  379. decode(nvl(transp.transportadoraimune, 0), 0,
  380. decode(nvl(to_char(nfi.ciffob), 1), '1', 0, '2', 1,
  381. '4', 2, '5', 9, 0), 9)) transp_modFrete,
  382. --transp_transporta
  383. decode(nvl(transp.transportadoraimune, 0), 0,
  384. decode(length(replace(replace(replace(nfi.cnpj_transp,
  385. '.', ''), '/', ''),
  386. '-', '')), 14,
  387. replace(replace(replace(nfi.cnpj_transp, '.', ''),
  388. '/', ''), '-', ''), null), '') transp_transporta_CNPJ,
  389. decode(length(replace(replace(replace(nfi.cnpj_transp, '.', ''),
  390. '/', ''), '-', '')), 11,
  391. replace(replace(replace(nfi.cnpj_transp, '.', ''), '/',
  392. ''), '-', ''), null) transp_transporta_CPF,
  393.  
  394. decode(nvl(transp.transportadoraimune, 0), 1, '',
  395. nfi.nome_transp) transp_transporta_xNome,
  396. decode(upper(nfi.inscrestadual_transp), 'INSCRICAOESTADUAL',
  397. null,
  398. replace(replace(replace(replace(replace(nfi.inscrestadual_transp,
  399. ' ', ''), '.', ''),
  400. '-', ''), '/', ''), ':', '')) transp_transporta_IE,
  401. decode(nvl(transp.transportadoraimune, 0), 0,
  402. trim(substr(replace(trim(nfi.endereco_transp) || ' ' ||
  403. nfi.numend_transp || ' ' ||
  404. trim(nfi.bairro_transp), ',', ''), 1,
  405. 60)), '') transp_transporta_xEnder,
  406. decode(nvl(transp.transportadoraimune, 0), 0,
  407. trim(nfi.cidade_transp), '') transp_transporta_xMun,
  408. decode(nvl(transp.transportadoraimune, 0), 0,
  409. nfi.estado_transp, '') transp_transporta_UF,
  410. --transp_rettransp
  411. null transp_retTransp_vServ, null transp_retTransp_vBCRet,
  412. null transp_retTransp_pICMSRet, null transp_retTransp_vICMSRet,
  413. null transp_retTransp_CFOP, null transp_retTransp_cMunFG,
  414. --veiculo
  415. replace(nfi.veiculo, '-', '') transp_veicTransp_placa,
  416. nfi.estado_veiculo transp_veicTransp_UF,
  417. decode(nfi.veiculo, null, null, nfi.registroantt) transp_veicTransp_RNTC,
  418. --vol
  419. decode(nvl(transp.transportadoraimune, 0), 0,
  420. decode(v.qtdevolumes, 0, null,
  421. nvl(v.qtdevolumes, round(nfi.qtde))), '') transp_vol_qVol,
  422. trim(nfi.especie) transp_vol_esp, nfi.marca transp_vol_marca,
  423. nfi.numero transp_vol_nVol,
  424. decode(nvl(transp.transportadoraimune, 0), 0,
  425. round(nfi.pesoliquido / 1000, 3), '') transp_vol_pesoL,
  426. decode(nvl(transp.transportadoraimune, 0), 0,
  427. round(nfi.pesobruto / 1000, 3), '') transp_vol_pesoB,
  428. --cobr_fat
  429. decode(round(nvl(nfi.vlrtotal, 0), 4), 0, null,
  430. nfi.codigointerno) cobr_fat_nFat,
  431. decode(round(nvl(nfi.vlrtotal, 0), 4) +
  432. nvl(nfi.valordesconto, 0), 0, null,
  433. round(nvl(nfi.vlrtotal, 0), 4) +
  434. nvl(nfi.valordesconto, 0)) cobr_fat_vOrig,
  435. decode(nfi.valordesconto, 0, decode(c.versaonfe, 1, 0, null),
  436. nfi.valordesconto) cobr_fat_vDesc,
  437. decode(round(nvl(nfi.vlrtotal, 0), 4), 0, null,
  438. round(nvl(nfi.vlrtotal, 0), 4)) cobr_fat_vLiq,
  439. --infAdic
  440. trim(translate(substr(trim(nfi.observacao), 0, 256),
  441. ',$%#@*''&''º°ª–´`', '')) infAdic_infAdFisco,
  442. trim(translate(substr(replace(trim(trim(nfi.mensagemoperacao1) ||
  443. decode(trim(nfi.mensagemoperacao1),
  444. null, null, ' ') ||
  445. trim(nfi.mensagemoperacao2) ||
  446. decode(trim(nfi.mensagemoperacao2),
  447. null, null, ' ') ||
  448. trim(nfi.mensagemretorno) ||
  449. decode(trim(nfi.mensagemcoberturanf),
  450. null, null, ' | ') ||
  451. trim(nfi.mensagemcoberturanf) ||
  452. decode(trim(trim(decode(nfi.instrucao1,
  453. nfi.mensagemoperacao1,
  454. '',
  455. nfi.instrucao1)) || ' ' ||
  456. trim(decode(nfi.instrucao2,
  457. nfi.mensagemoperacao2,
  458. '',
  459. nfi.instrucao2)) || ' ' ||
  460. trim(nfi.instrucao3) || ' ' ||
  461. trim(nfi.instrucao4) || ' ' ||
  462. trim(nfi.instrucao5) || ' ' ||
  463. trim(nfi.instrucao6) || ' ' ||
  464. trim(nfi.instrucao7) || ' ' ||
  465. trim(nfi.instrucao8) || ' ' ||
  466. trim(nfi.instrucao9) || ' ' ||
  467. trim(nfi.instrucao10) || ' ' ||
  468. trim(nfi.instrucao11) || ' ' ||
  469. trim(nfi.instrucao12) || ' ' ||
  470. trim(nfi.instrucao13) || ' ' ||
  471. trim(nfi.instrucao14) || ' ' ||
  472. trim(nfi.instrucao15) || ' ' ||
  473. trim(nfi.instrucao16) || ' ' ||
  474. trim(nfi.instrucao17) || ' ' ||
  475. trim(nfi.instrucao18) || ' ' ||
  476. trim(nfi.instrucao19) || ' ' ||
  477. trim(nfi.instrucao20) || ' ' ||
  478. trim(nfi.instrucao21) || ' ' ||
  479. trim(nfi.instrucao22) || ' ' ||
  480. substr(trim(nfi.observacao),
  481. 0, 256)),
  482. null, null, ' | ') ||
  483. trim(decode(nfi.instrucao1,
  484. nfi.mensagemoperacao1,
  485. '',
  486. nfi.instrucao1)) || ' ' ||
  487. trim(decode(nfi.instrucao2,
  488. nfi.mensagemoperacao2,
  489. '',
  490. nfi.instrucao2)) || ' ' ||
  491. trim(nfi.instrucao3) || ' ' ||
  492. trim(nfi.instrucao4) || ' ' ||
  493. trim(nfi.instrucao5) || ' ' ||
  494. trim(nfi.instrucao6) || ' ' ||
  495. trim(nfi.instrucao7) || ' ' ||
  496. trim(nfi.instrucao8) || ' ' ||
  497. trim(nfi.instrucao9) || ' ' ||
  498. trim(nfi.instrucao10) || ' ' ||
  499. trim(nfi.instrucao11) || ' ' ||
  500. trim(nfi.instrucao12) || ' ' ||
  501. trim(nfi.instrucao13) || ' ' ||
  502. trim(nfi.instrucao14) || ' ' ||
  503. trim(nfi.instrucao15) || ' ' ||
  504. trim(nfi.instrucao16) || ' ' ||
  505. trim(nfi.instrucao17) || ' ' ||
  506. trim(nfi.instrucao18) || ' ' ||
  507. trim(nfi.instrucao19) || ' ' ||
  508. trim(nfi.instrucao20) || ' ' ||
  509. trim(nfi.instrucao21) || ' ' ||
  510. trim(nfi.instrucao22) || ' ' ||
  511. substr(trim(nfi.observacao),
  512. 0, 256)), chr(13)), 1,
  513. 5000), ',$%#@*''&''º°ª–´`', ' ')) infAdic_infCpl,
  514. --exporta
  515. nfi.uflocalembarque exporta_UFEmbarq,
  516. nfi.localembarque exporta_xLocEmbarq,
  517. --compra
  518. '' compra_xNEmp, nfi.numpedido compra_xPed, '' compra_xCont,
  519. nfi.idprenf h$idprenf, nfi.data_emissao h$dataemissao,
  520. decode(nfi.estado_emit, 'BA', '13937073000156', null) autxml_cnpj,
  521. et.enviagrupotransporta, et.enviagrupoveiculotransp,
  522. et.enviagruporeboque
  523. from nfimpressao nfi, configuracao c,
  524. (select nf.idprenf, count(1) qtdevolumes
  525. from notafiscal nf, volumeromaneio vr
  526. where vr.idnotafiscal = nf.idnotafiscal
  527. and vr.statusvolume = 0
  528. and vr.geradoautomaticamente = 0
  529. group by nf.idprenf) v, notafiscal nf, operacao o,
  530. entidade transp, entidade dest, depositante dep, regime r,
  531. estado et
  532. where v.idprenf(+) = nfi.idprenf
  533. and nf.idprenf = nfi.idprenf
  534. and o.idoperacao = nf.idoperacao
  535. and transp.identidade(+) = nf.transportadoranotafiscal
  536. and dest.identidade = nf.destinatario
  537. and nf.iddepositante = dep.identidade
  538. and dep.idregime = r.idregime
  539. and et.uf(+) = nfi.estado_dest
  540. and c.ativo = 'S') x;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement