Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. select *
  2. from
  3. (select
  4. hist.nu_aaaamm_processo as anoMes,
  5. hist.cd_empresa_credora as empresaCredora,
  6. age.cd_identificador_empresa as identificadorEmpresa,
  7. age.cd_sigla_empresa as siglaEmpresa,
  8. NVL(ROUND((SUM(hist.vl_primeira_parcela) + SUM(hist.vl_segunda_parcela) + SUM(hist.vl_terceira_parcela)),2),0) as Total,
  9. NVL((SELECT f.nu_qtd_parcelas || '-AgeFormaPagto'
  10. FROM tb_agente_forma_pagamento af,
  11. tb_forma_pagamento f
  12. WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
  13. AND af.cd_empresa = 66
  14. AND af.id_transmissora = age.cd_empresa
  15. AND af.dt_fim_vigencia IS NULL
  16. UNION
  17. SELECT f.nu_qtd_parcelas || '-TipoAge'
  18. FROM tb_tpageinstformapagto af,
  19. tb_forma_pagamento f,
  20. tb_agenteconcessao ag
  21. WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
  22. AND ag.cd_tipo_agente = af.id_tipo_agente
  23. AND ag.cd_empresa = age.cd_empresa),
  24. null) as parcelas,
  25. NVL((SELECT CASE WHEN f.in_parcela_vencimento_1 = 'S' THEN '15'
  26. WHEN f.in_parcela_vencimento_2 = 'S' THEN '25'
  27. WHEN f.in_parcela_vencimento_3 = 'S' THEN '05'
  28. END
  29. FROM tb_agente_forma_pagamento af,
  30. tb_forma_pagamento f
  31. WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
  32. AND af.cd_empresa = 66
  33. AND af.id_transmissora = age.cd_empresa
  34. AND af.dt_fim_vigencia IS NULL
  35. UNION
  36. SELECT CASE WHEN f.in_parcela_vencimento_1 = 'S' THEN '15'
  37. WHEN f.in_parcela_vencimento_2 = 'S' THEN '25'
  38. WHEN f.in_parcela_vencimento_3 = 'S' THEN '05'
  39. END
  40. FROM tb_tpageinstformapagto af,
  41. tb_forma_pagamento f,
  42. tb_agenteconcessao ag
  43. WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
  44. AND ag.cd_tipo_agente = af.id_tipo_agente
  45. AND ag.cd_empresa = age.cd_empresa),
  46. null) as vencimento,
  47. age.ds_razao_social as razaoSocial,
  48. age.cd_empresa as empresa,
  49. tp.dsc_tipo_agente as tipoAgente,
  50. Case when pr.cd_empresasolicitante = 66 then 'PorMim' when pr.cd_empresasolicitada = 66 then 'ParaMim' End as tipoFormaPagto
  51. from tb_agenteconcessao age,
  52. outer tb_historico_avc_avd hist,
  53. outer tb_tpageinst tp,
  54. outer TB_PROPOSTAPAGTOCOBRANCA pr
  55. where 1=1
  56. AND age.sts_agente = 'A'
  57. AND age.cd_empresa = hist.cd_empresa_credora
  58. AND age.cd_tipo_agente = tp.id_tipo_agente
  59. AND hist.cd_empresa_pgto = 66
  60. AND age.cd_empresa NOT IN (66)
  61. AND hist.nu_aaaamm_processo >= 201804 --Apuração Inicial
  62. AND hist.nu_aaaamm_processo <= 201805 --Apuração Final
  63. AND ((age.cd_empresa = pr.cd_empresasolicitante AND pr.cd_empresasolicitada = 66) or (age.cd_empresa = pr.cd_empresasolicitada AND pr.cd_empresasolicitante = 66))
  64. AND pr.id_propostapagtocobranca Not IN (Select id_propostapagtocobranca from tb_reprovacaopropostapagto )
  65. GROUP BY 1,2,3,4,6,7,8,9,10,11) as R1
  66. WHERE R1.tipoagente = 'Transmissão'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement