julio 2017-08-31 18:51:59 +00:00
parent ed151a6d33
commit baac8d615e
1 changed files with 19 additions and 27 deletions

View File

@ -73,10 +73,13 @@ public class RelatorioFinanceiroAnalitico extends Relatorio {
fs.setCodigoAgencia(rset.getString("codigo"));
fs.setFechorVenta(rset.getDate("fechorVenta"));
fs.setReceitaBPR(getBigDecimal(rset, "receita_bpr"));
BigDecimal receitaBPR = getBigDecimal(rset, "receita_bpr");
fs.setGapVenda(getBigDecimal(rset, "receita_gap"));
fs.setGapImpressa(getBigDecimal(rset, "entrega_gap"));
receitaBPR = receitaBPR.add(fs.getGapImpressa());
fs.setReceitaBPR(receitaBPR);
BigDecimal totalVendaPassagens = fs.getReceitaBPR().add(fs.getGapVenda());
totalVendaPassagens = totalVendaPassagens.subtract(fs.getGapImpressa());
fs.setTotalVendaPassagens(totalVendaPassagens);
@ -161,18 +164,16 @@ public class RelatorioFinanceiroAnalitico extends Relatorio {
sql.append(" cd.puntoventaId, ");
sql.append(" cd.empresaId, ");
sql.append(" cd.fechorVenta, ");
sql.append(" sum(case when cd.venda = 1 then cd.taxaEmbarque else 0 end) as taxaEmbarque, ");
sql.append(" sum(case when cd.venda = 1 then cd.pedagio else 0 end) as pedagio, ");
sql.append(" sum(case when cd.venda = 1 then cd.seguro else 0 end) as seguro, ");
sql.append(" sum(case when (cd.venda = 1 and cd.bpr = 1) then cd.tarifa else 0 end) as receita_bpr, ");
sql.append(" sum(case when (cd.venda = 1 and cd.gap = 1) then cd.valorpago else 0 end) as receita_gap, ");
sql.append(" sum(case when (cd.entrega_gap = 1) then cd.valorpago else 0 end) as entrega_gap, ");
sql.append(" sum(case when (cd.indcancelacion = 1 and cd.bpr = 1) then cd.valorpago else 0 end) as receita_devol_bpr, ");
sql.append(" sum(case when (cd.indcancelacion = 1 and cd.gap = 1) then cd.valorpago else 0 end) as receita_devol_gap, ");
sql.append(" sum(case when (cd.venda = 1 and cd.pagamento_credito = 1) then cd.valorpago else 0 end) as cartao_credito, ");
sql.append(" sum(case when (cd.venda = 1 and cd.pagamento_debito = 1) then cd.valorpago else 0 end) as cartao_debito, ");
sql.append(" sum(case when (cd.indcancelacion = 1 and cd.ocd_deb = 1) then cd.valorpago else 0 end) as receita_ocd_deb, ");
sql.append(" sum(case when (cd.ocd_cred = 1) then cd.valorpago else 0 end) as receita_ocd_cred ");
sql.append(" sum(case when (cd.indcancelacion = 0 and cd.indstatusboleto = 'V') then cd.pedagio else 0 end) as pedagio, ");
sql.append(" sum(case when (cd.indcancelacion = 0 and cd.indstatusboleto = 'V') then cd.valorpago else 0 end) as receita_bpr, ");
sql.append(" sum(case when (cd.indcancelacion = 1 and cd.motivocancelacion_id in (31,32)) then cd.valorpago else 0 end) as receita_devol_bpr, ");
sql.append(" sum(case when (cd.indcancelacion = 0 and cd.numfoliosistema is null) then cd.valorpago else 0 end) as receita_gap, ");
sql.append(" sum(case when (cd.indcancelacion = 1 and cd.motivocancelacion_id in (31,32) and cd.numfoliosistema is null) then cd.valorpago else 0 end) as receita_devol_gap, ");
sql.append(" sum(case when (cd.indstatusboleto = 'E') then cd.valorpago else 0 end) as entrega_gap, ");
sql.append(" sum(case when (cd.indcancelacion = 0 and cd.indstatusboleto = 'V' and cd.formapago_id in (2,25)) then cd.valorpago else 0 end) as cartao_credito, ");
sql.append(" sum(case when (cd.indcancelacion = 0 and cd.indstatusboleto = 'V' and cd.formapago_id in (3,26)) then cd.valorpago else 0 end) as cartao_debito, ");
sql.append(" sum(case when (cd.indcancelacion = 1 and cd.motivocancelacion_id in (35)) then cd.valorpago else 0 end) as receita_ocd_deb, ");
sql.append(" sum(case when (cd.indcancelacion = 1 and cd.motivocancelacion_id in (99) ) then cd.valorpago else 0 end) as receita_ocd_cred ");
sql.append(" ");
sql.append("from ( ");
sql.append(" select ");
@ -186,10 +187,7 @@ public class RelatorioFinanceiroAnalitico extends Relatorio {
sql.append(" c.indstatusboleto, ");
sql.append(" c.indreimpresion, ");
sql.append(" c.indcancelacion, ");
sql.append(" case when c.indstatusboleto = 'V' and c.indcancelacion = 0 and c.indreimpresion = 0 then 1 else 0 end as venda, ");
sql.append(" case when c.tipoventa_id not in (5,12,18,49) then 1 else 0 end as bpr, ");
sql.append(" case when c.tipoventa_id in (5,12,18,49) then 1 else 0 end as gap, ");
sql.append(" case when c.motivocancelacion_id in (35) then 1 else 0 end as ocd_deb, ");
sql.append(" c.numfoliosistema, ");
sql.append(" coalesce(cfp.importe, 0) as valorpago, ");
sql.append(" coalesce(c.preciobase, 0) as precobase, ");
sql.append(" coalesce(c.preciopagado, 0) as tarifa, ");
@ -199,14 +197,7 @@ public class RelatorioFinanceiroAnalitico extends Relatorio {
sql.append(" coalesce(c.importeoutros, 0) as outros, ");
sql.append(" cfp.formapago_id, ");
sql.append(" c.motivocancelacion_id as motivocancelacion_id, ");
sql.append(" c.tipoventa_id as tipoventa_id, ");
sql.append(" case when (c.tipoventa_id in (5,12,18,49) and indstatusboleto = 'E') then 1 else 0 end as entrega_gap, ");
sql.append(" case when c.indreimpresion = 1 and indstatusboleto = 'T' then 1 else 0 end as nao_entra_no_caixa, ");
sql.append(" case when cfp.formapago_id = 1 then 1 else 0 end as pagamento_dinheiro, ");
sql.append(" case when cfp.formapago_id in (3,26) then 1 else 0 end as pagamento_debito, ");
sql.append(" case when cfp.formapago_id in (2,25) then 1 else 0 end as pagamento_credito, ");
sql.append(" case when cfp.formapago_id not in (1,2,3,25,26) then 1 else 0 end as pagamento_outro, ");
sql.append(" case when c.motivocancelacion_id in (99) then 1 else 0 end as ocd_cred ");
sql.append(" c.tipoventa_id as tipoventa_id ");
sql.append(" from caja c ");
sql.append(" inner join caja_formapago cfp on cfp.caja_id = c.caja_id ");
sql.append(" inner join punto_venta pv on pv.puntoventa_id = c.puntoventa_id ");
@ -222,13 +213,14 @@ public class RelatorioFinanceiroAnalitico extends Relatorio {
sql.append(pdvs == null ? "" : "and pv.puntoventa_id in ( " + pdvs + " ) ");
sql.append(tipoptovtaId == -1 ? "" : "and pv.tipoptovta_id = " + tipoptovtaId);
sql.append(" ) cd ");
sql.append(" where cd.nao_entra_no_caixa = 0 ");
sql.append(" group by cd.estadoOrigem, cd.estadoId, cd.codigo, cd.puntoventaId, cd.empresaId, cd.fechorVenta ) agrc ");
sql.append("left join ( ");
sql.append(" select ed.puntoventaId, ed.estadoId, ed.empresaId, ");
sql.append(" ed.fechorVenta, ");
sql.append(" sum(case when tipoeventoextra_id = 2 and indtipo = 1 then impingreso else 0 end) as taxaEmbarque, ");
sql.append(" sum(case when tipoeventoextra_id = 25 and indtipo = 1 then impingreso else 0 end) as seguro, ");
sql.append(" sum(case when tipoeventoextra_id = 82 and indtipo = 1 then impingreso else 0 end) as receita_eb, ");
sql.append(" sum(case when tipoeventoextra_id in (102,42) and indtipo = 1 then impingreso else 0 end) as receita_multa, ");
sql.append(" sum(case when tipoeventoextra_id in (41) and indtipo = 1 then impingreso else 0 end) as receita_multa, ");
sql.append(" sum(case when tipoeventoextra_id in (103,99978,99999) and indtipo = 1 then impingreso else 0 end) as receita_dif_troca_ocd, ");
sql.append(" sum(case when tipoeventoextra_id in (43) and indtipo = 1 then impingreso else 0 end) as receita_dif_dif_tarifa_maior, ");
sql.append(" sum(case when tipoeventoextra_id in (44) and indtipo = 0 then impingreso else 0 end) as receita_dif_dif_tarifa_menor, ");