diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioAproveitamentosFinanceiros.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioAproveitamentosFinanceiros.java new file mode 100644 index 000000000..57f94dc32 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioAproveitamentosFinanceiros.java @@ -0,0 +1,241 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.relatorios.impl; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Timestamp; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import com.rjconsultores.ventaboletos.relatorios.utilitarios.ArrayDataSource; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.utilerias.DateUtil; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + + +public class RelatorioAproveitamentosFinanceiros extends Relatorio { + + private final BigDecimal cem = new BigDecimal("100"); + + public RelatorioAproveitamentosFinanceiros(Map parametros, Connection conexao) throws Exception { + super(parametros, conexao); + + this.setCustomDataSource(new ArrayDataSource(this) { + @Override + public void initDados() throws Exception { + + Connection conexao = this.relatorio.getConexao(); + Map parametros = this.relatorio.getParametros(); + + StringBuilder sql = new StringBuilder(); + + sql.append("select * from ( "); + sql.append(" SELECT "); + sql.append(" r.DESCRUTA as linha, "); + sql.append(" count( c.caja_id) as passageiros, "); + sql.append(" sum( c.PRECIOPAGADO )as valor, "); + sql.append(" to_char( c.FECHORVENTA, 'DY') as dia, "); + sql.append(" count(DISTINCT to_char( c.FECHORVENTA, 'WW')) as qtde, "); + sql.append(" r.indsentidoida as sentido, "); + sql.append(" da.cantasientos as assentos, "); + sql.append(" TO_CHAR(co.fechorsalidaoriginal ,'HH24:mi') as horario, "); + sql.append(" c.CORRIDA_ID as servico, "); + sql.append(" max(c.preciobase) as tarifa "); + sql.append(" FROM CAJA c "); + sql.append(" inner join corrida co "); + sql.append(" on c.CORRIDA_ID = co.CORRIDA_ID "); + sql.append(" and c.FECCORRIDA = co.FECCORRIDA "); + sql.append(" and co.ACTIVO = 1 "); + sql.append(" inner join ruta r "); + sql.append(" on c.RUTA_ID = r.RUTA_ID "); + sql.append(" and r.ACTIVO = 1 "); + sql.append(" inner join MARCA m "); + sql.append(" on m.marca_id = c.marca_id "); + sql.append(" and m.activo = 1 "); + sql.append(" left join rol_operativo ro "); + sql.append(" on ro.roloperativo_id = co.roloperativo_id "); + sql.append(" left join diagrama_autobus da "); + sql.append(" on ro.diagramaautobus_id = da.diagramaautobus_id "); + sql.append(" WHERE c.activo = 1 "); + sql.append(" AND m.EMPRESA_ID = :EMPRESA_ID "); + sql.append(" and c.FECHORVENTA >= :DATA_INICIAL "); + sql.append(" and c.FECHORVENTA <= :DATA_FINAL "); + + if (parametros.get("LINHAS") != null && !possuiFiltroTodos("LINHAS")) { + sql.append(" and c.ruta_id IN (" + parametros.get("LINHAS").toString() + ")"); + } + + sql.append(" and c.MOTIVOCANCELACION_ID is null "); + sql.append(" and c.INDSTATUSBOLETO = 'V' "); + sql.append(" GROUP by r.DESCRUTA, r.indsentidoida, da.cantasientos, "); + sql.append(" to_char( c.FECHORVENTA, 'DY'), TO_CHAR(co.fechorsalidaoriginal ,'HH24:mi'), "); + sql.append(" c.CORRIDA_ID "); + sql.append(" ORDER by r.DESCRUTA, r.indsentidoida desc, to_char( c.FECHORVENTA, 'DY') "); + sql.append(" ) "); + sql.append("PIVOT "); + sql.append("( "); + sql.append(" max(valor) receita_ope, "); + sql.append(" count(qtde) qtde, "); + sql.append(" max(passageiros) tot "); + sql.append(" for dia in ('SEG', 'TER', 'QUA', 'QUI', 'SEX', 'SAB', 'DOM') "); + sql.append(") "); + + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql.toString()); + + stmt.setInt("EMPRESA_ID", Integer.valueOf(parametros.get("EMPRESA_ID").toString())); + stmt.setTimestamp("DATA_INICIAL", new Timestamp(DateUtil.inicioFecha((Date) parametros.get("DATA_INICIAL")).getTime())); + stmt.setTimestamp("DATA_FINAL", new Timestamp(DateUtil.fimFecha((Date) parametros.get("DATA_FINAL")).getTime())); + + ResultSet rset = stmt.executeQuery(); + + rset.setFetchSize(500); + + while (rset.next()) { + + Map dataResult = new HashMap(); + + dataResult.put("LINHA", rset.getString("linha")); + dataResult.put("SENTIDO", rset.getString("sentido")); + dataResult.put("SERVICO", rset.getString("servico")); + dataResult.put("HORARIO", rset.getString("horario")); + + BigDecimal assentos = limpaNulo(rset.getBigDecimal("assentos")); + BigDecimal tarifa = limpaNulo(rset.getBigDecimal("tarifa")); + BigDecimal totPassageiros = BigDecimal.ZERO; + BigDecimal totReceita = BigDecimal.ZERO; + BigDecimal viagens = BigDecimal.ZERO; + + BigDecimal segReceitaOpe = limpaNulo(rset.getBigDecimal("'SEG'_RECEITA_OPE")); + BigDecimal segQtde = limpaNulo(rset.getBigDecimal("'SEG'_QTDE")); + BigDecimal segTot = limpaNulo(rset.getBigDecimal("'SEG'_TOT")); + totPassageiros = totPassageiros.add(segTot); + totReceita = totReceita.add(segReceitaOpe); + viagens = viagens.add(segQtde); + + BigDecimal terReceitaOpe = limpaNulo(rset.getBigDecimal("'TER'_RECEITA_OPE")); + BigDecimal terQtde = limpaNulo(rset.getBigDecimal("'TER'_QTDE")); + BigDecimal terTot = limpaNulo(rset.getBigDecimal("'TER'_TOT")); + totPassageiros = totPassageiros.add(terTot); + totReceita = totReceita.add(terReceitaOpe); + viagens = viagens.add(terQtde); + + BigDecimal quaReceitaOpe = limpaNulo(rset.getBigDecimal("'QUA'_RECEITA_OPE")); + BigDecimal quaQtde = limpaNulo(rset.getBigDecimal("'QUA'_QTDE")); + BigDecimal quaTot = limpaNulo(rset.getBigDecimal("'QUA'_TOT")); + totPassageiros = totPassageiros.add(quaTot); + totReceita = totReceita.add(quaReceitaOpe); + viagens = viagens.add(quaQtde); + + BigDecimal quiReceitaOpe = limpaNulo(rset.getBigDecimal("'QUI'_RECEITA_OPE")); + BigDecimal quiQtde = limpaNulo(rset.getBigDecimal("'QUI'_QTDE")); + BigDecimal quiTot = limpaNulo(rset.getBigDecimal("'QUI'_TOT")); + totPassageiros = totPassageiros.add(quiTot); + totReceita = totReceita.add(quiReceitaOpe); + viagens = viagens.add(quiQtde); + + BigDecimal sexReceitaOpe = limpaNulo(rset.getBigDecimal("'SEX'_RECEITA_OPE")); + BigDecimal sexQtde = limpaNulo(rset.getBigDecimal("'SEX'_QTDE")); + BigDecimal sexTot = limpaNulo(rset.getBigDecimal("'SEX'_TOT")); + totPassageiros = totPassageiros.add(sexTot); + totReceita = totReceita.add(sexReceitaOpe); + viagens = viagens.add(sexQtde); + + BigDecimal sabReceitaOpe = limpaNulo(rset.getBigDecimal("'SAB'_RECEITA_OPE")); + BigDecimal sabQtde = limpaNulo(rset.getBigDecimal("'SAB'_QTDE")); + BigDecimal sabTot = limpaNulo(rset.getBigDecimal("'SAB'_TOT")); + totPassageiros = totPassageiros.add(sabTot); + totReceita = totReceita.add(sabReceitaOpe); + viagens = viagens.add(sabQtde); + + BigDecimal domReceitaOpe = limpaNulo(rset.getBigDecimal("'DOM'_RECEITA_OPE")); + BigDecimal domQtde = limpaNulo(rset.getBigDecimal("'DOM'_QTDE")); + BigDecimal domTot = limpaNulo(rset.getBigDecimal("'DOM'_TOT")); + totPassageiros = totPassageiros.add(domTot); + totReceita = totReceita.add(domReceitaOpe); + viagens = viagens.add(domQtde); + + dataResult.put("VIAGENS", viagens); + dataResult.put("ASSENTOS", assentos); + dataResult.put("TARIFA", tarifa); + dataResult.put("TOT_PASSAGEIROS", totPassageiros); + dataResult.put("TOT_RECEITA", totReceita); + + dataResult.put("SEG_RECEITA_OPE", segReceitaOpe); + dataResult.put("SEG_QTDE", segQtde); + dataResult.put("SEG_TOT", segTot); + dataResult.put("SEG_FIN", calculaMedia(segReceitaOpe, tarifa, segQtde, segTot)); + + dataResult.put("TER_RECEITA_OPE", terReceitaOpe); + dataResult.put("TER_QTDE", terQtde); + dataResult.put("TER_TOT", terTot); + dataResult.put("TER_FIN", calculaMedia(terReceitaOpe, tarifa, terQtde, terTot)); + + dataResult.put("QUA_RECEITA_OPE", quaReceitaOpe); + dataResult.put("QUA_QTDE", quaQtde); + dataResult.put("QUA_TOT", quaTot); + dataResult.put("QUA_FIN", calculaMedia(quaReceitaOpe, tarifa, quaQtde, quaTot)); + + dataResult.put("QUI_RECEITA_OPE", quiReceitaOpe); + dataResult.put("QUI_QTDE", quiQtde); + dataResult.put("QUI_TOT", quiTot); + dataResult.put("QUI_FIN", calculaMedia(quiReceitaOpe, tarifa, quiQtde, quiTot)); + + dataResult.put("SEX_RECEITA_OPE", sexReceitaOpe); + dataResult.put("SEX_QTDE", sexQtde); + dataResult.put("SEX_TOT", sexTot); + dataResult.put("SEX_FIN", calculaMedia(sexReceitaOpe, tarifa, sexQtde, sexTot)); + + dataResult.put("SAB_RECEITA_OPE", sabReceitaOpe); + dataResult.put("SAB_QTDE", sabQtde); + dataResult.put("SAB_TOT", sabTot); + dataResult.put("SAB_FIN", calculaMedia(sabReceitaOpe, tarifa, sabQtde, sabTot)); + + dataResult.put("DOM_RECEITA_OPE", domReceitaOpe); + dataResult.put("DOM_QTDE", domQtde); + dataResult.put("DOM_TOT", domTot); + dataResult.put("DOM_FIN", calculaMedia(domReceitaOpe, tarifa, domQtde, domTot)); + + this.dados.add(dataResult); + } + + this.resultSet = rset; + } + }); + } + + @Override + protected void processaParametros() throws Exception { + + } + + private BigDecimal limpaNulo( BigDecimal val ) { + if( val == null ) { + return BigDecimal.ZERO; + }else { + return val; + } + } + + private BigDecimal calculaMedia(BigDecimal totReceita, BigDecimal tarifa, BigDecimal qtde, BigDecimal tot) { + if( qtde.intValue() != 0 && tot.intValue() !=0 ) { + BigDecimal dividendo = tarifa.multiply(qtde); + dividendo = dividendo.multiply(tot); + + if(dividendo.intValue() == 0 ) { + return BigDecimal.ZERO; + } + + BigDecimal fin = totReceita.divide(dividendo, 4, BigDecimal.ROUND_HALF_UP); + fin = fin.multiply(cem); + fin.setScale(2); + return fin; + }else{ + return BigDecimal.ZERO; + } + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioAproveitamentosFinanceiros_pt_BR.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioAproveitamentosFinanceiros_pt_BR.properties new file mode 100644 index 000000000..03412d849 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioAproveitamentosFinanceiros_pt_BR.properties @@ -0,0 +1,13 @@ +#geral +msg.noData=Não foi possivel obter dados com os parâmetros informados. + + +#Labels cabeçalho +cabecalho.relatorio=Relatório: +cabecalho.periodo=Período: +cabecalho.periodoA=à +cabecalho.dataHora=Data/Hora: +cabecalho.impressorPor=Impresso por: +cabecalho.pagina=Página +cabecalho.de=de +cabecalho.filtros=Filtros: \ No newline at end of file diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jasper b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jasper index 2b9d321be..3956cbe16 100644 Binary files a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jasper and b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jasper differ diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jrxml index fea7ad9d8..221a5bad2 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jrxml +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiro.jrxml @@ -526,7 +526,7 @@ - + @@ -539,7 +539,7 @@ - + @@ -552,7 +552,7 @@ - + @@ -564,7 +564,7 @@ - + @@ -577,7 +577,7 @@ - + @@ -589,7 +589,7 @@ - + @@ -602,7 +602,7 @@ - + @@ -614,7 +614,7 @@ - + @@ -627,7 +627,7 @@ - + @@ -640,7 +640,7 @@ - + @@ -652,7 +652,7 @@ - + @@ -665,7 +665,7 @@ - + @@ -678,7 +678,7 @@ - + @@ -690,7 +690,7 @@ - + @@ -703,7 +703,7 @@ - + @@ -716,7 +716,7 @@ - + @@ -729,7 +729,7 @@ - + @@ -1219,7 +1219,7 @@ - + @@ -1232,7 +1232,7 @@ - + @@ -1244,7 +1244,7 @@ - + @@ -1257,7 +1257,7 @@ - + @@ -1269,7 +1269,7 @@ - + @@ -1282,7 +1282,7 @@ - + @@ -1294,7 +1294,7 @@ - + @@ -1307,7 +1307,7 @@ - + @@ -1319,7 +1319,7 @@ - + @@ -1332,7 +1332,7 @@ - + @@ -1344,7 +1344,7 @@ - + @@ -1357,7 +1357,7 @@ - + @@ -1369,7 +1369,7 @@ - + @@ -1382,7 +1382,7 @@ - + @@ -1395,7 +1395,7 @@ - + @@ -1413,7 +1413,7 @@ - + @@ -1430,7 +1430,7 @@ - + @@ -1447,7 +1447,7 @@ - + @@ -1460,7 +1460,7 @@ - + @@ -1473,7 +1473,7 @@ - + @@ -1485,7 +1485,7 @@ - + @@ -1497,7 +1497,7 @@ - + @@ -1510,7 +1510,7 @@ - + @@ -1523,7 +1523,7 @@ - + @@ -1536,7 +1536,7 @@ - + @@ -1548,7 +1548,7 @@ - + @@ -1560,7 +1560,7 @@ - + @@ -1573,7 +1573,7 @@ - + @@ -1586,7 +1586,7 @@ - + @@ -1599,7 +1599,7 @@ - + @@ -1611,7 +1611,7 @@ - + @@ -1635,7 +1635,7 @@ - + @@ -1648,7 +1648,7 @@ - + @@ -1674,20 +1674,20 @@ - + - + - - + + diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentosFinanceiros.jasper b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentosFinanceiros.jasper new file mode 100644 index 000000000..2268125a6 Binary files /dev/null and b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentosFinanceiros.jasper differ diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentosFinanceiros.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentosFinanceiros.jrxml new file mode 100644 index 000000000..221a5bad2 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentosFinanceiros.jrxml @@ -0,0 +1,1709 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 ? ($F{TOT_RECEITA}.divide ( + $F{TARIFA}.multiply( + $F{VIAGENS}.multiply( + $F{ASSENTOS} + ) + ) +, 2, BigDecimal.ROUND_HALF_UP ) +.multiply( new BigDecimal("100") )) : new BigDecimal(0)]]> + + + + 0 ? ($F{TOT_RECEITA}.divide ( + $F{TARIFA}.multiply( + $F{VIAGENS}.multiply( + $F{ASSENTOS} + ) + ) +, 2, BigDecimal.ROUND_HALF_UP ) +.multiply( new BigDecimal("100") )) : new BigDecimal(0)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioAproveitamentoFinanceiroController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioAproveitamentoFinanceiroController.java index 1e81c42f5..1d948eaa7 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioAproveitamentoFinanceiroController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioAproveitamentoFinanceiroController.java @@ -25,7 +25,7 @@ import org.zkoss.zul.Textbox; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Ruta; -import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioAproveitamentoFinanceiro; +import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioAproveitamentosFinanceiros; import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; import com.rjconsultores.ventaboletos.service.RutaService; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; @@ -155,7 +155,7 @@ public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwar } parametros.put("FILTROS", filtro.toString()); - relatorio = new RelatorioAproveitamentoFinanceiro(parametros, dataSourceRead.getConnection()); + relatorio = new RelatorioAproveitamentosFinanceiros(parametros, dataSourceRead.getConnection()); Map args = new HashMap(); args.put("relatorio", relatorio);