Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select *
- from
- (select
- hist.nu_aaaamm_processo as anoMes,
- hist.cd_empresa_credora as empresaCredora,
- age.cd_identificador_empresa as identificadorEmpresa,
- age.cd_sigla_empresa as siglaEmpresa,
- NVL(ROUND((SUM(hist.vl_primeira_parcela) + SUM(hist.vl_segunda_parcela) + SUM(hist.vl_terceira_parcela)),2),0) as Total,
- NVL((SELECT f.nu_qtd_parcelas || '-AgeFormaPagto'
- FROM tb_agente_forma_pagamento af,
- tb_forma_pagamento f
- WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
- AND af.cd_empresa = 66
- AND af.id_transmissora = age.cd_empresa
- AND af.dt_fim_vigencia IS NULL
- UNION
- SELECT f.nu_qtd_parcelas || '-TipoAge'
- FROM tb_tpageinstformapagto af,
- tb_forma_pagamento f,
- tb_agenteconcessao ag
- WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
- AND ag.cd_tipo_agente = af.id_tipo_agente
- AND ag.cd_empresa = age.cd_empresa),
- null) as parcelas,
- NVL((SELECT CASE WHEN f.in_parcela_vencimento_1 = 'S' THEN '15'
- WHEN f.in_parcela_vencimento_2 = 'S' THEN '25'
- WHEN f.in_parcela_vencimento_3 = 'S' THEN '05'
- END
- FROM tb_agente_forma_pagamento af,
- tb_forma_pagamento f
- WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
- AND af.cd_empresa = 66
- AND af.id_transmissora = age.cd_empresa
- AND af.dt_fim_vigencia IS NULL
- UNION
- SELECT CASE WHEN f.in_parcela_vencimento_1 = 'S' THEN '15'
- WHEN f.in_parcela_vencimento_2 = 'S' THEN '25'
- WHEN f.in_parcela_vencimento_3 = 'S' THEN '05'
- END
- FROM tb_tpageinstformapagto af,
- tb_forma_pagamento f,
- tb_agenteconcessao ag
- WHERE af.cd_forma_pagamento = f.cd_forma_pagamento
- AND ag.cd_tipo_agente = af.id_tipo_agente
- AND ag.cd_empresa = age.cd_empresa),
- null) as vencimento,
- age.ds_razao_social as razaoSocial,
- age.cd_empresa as empresa,
- tp.dsc_tipo_agente as tipoAgente,
- Case when pr.cd_empresasolicitante = 66 then 'PorMim' when pr.cd_empresasolicitada = 66 then 'ParaMim' End as tipoFormaPagto
- from tb_agenteconcessao age,
- outer tb_historico_avc_avd hist,
- outer tb_tpageinst tp,
- outer TB_PROPOSTAPAGTOCOBRANCA pr
- where 1=1
- AND age.sts_agente = 'A'
- AND age.cd_empresa = hist.cd_empresa_credora
- AND age.cd_tipo_agente = tp.id_tipo_agente
- AND hist.cd_empresa_pgto = 66
- AND age.cd_empresa NOT IN (66)
- AND hist.nu_aaaamm_processo >= 201804 --Apuração Inicial
- AND hist.nu_aaaamm_processo <= 201805 --Apuração Final
- AND ((age.cd_empresa = pr.cd_empresasolicitante AND pr.cd_empresasolicitada = 66) or (age.cd_empresa = pr.cd_empresasolicitada AND pr.cd_empresasolicitante = 66))
- AND pr.id_propostapagtocobranca Not IN (Select id_propostapagtocobranca from tb_reprovacaopropostapagto )
- GROUP BY 1,2,3,4,6,7,8,9,10,11) as R1
- WHERE R1.tipoagente = 'Transmissão'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement