diff --git a/pom.xml b/pom.xml index 8c6ac773f..f20d288f7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,11 +4,11 @@ 4.0.0 br.com.rjconsultores ventaboletosadm - 1.8.9 + 1.8.10 war - 1.6.6 + 1.6.7 1.5.2 UTF-8 UTF-8 diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioAproveitamentoFinanceiroTrecho.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioAproveitamentoFinanceiroTrecho.java new file mode 100644 index 000000000..f249e156a --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioAproveitamentoFinanceiroTrecho.java @@ -0,0 +1,375 @@ +/** + * + */ +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.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.log4j.Logger; + +import com.rjconsultores.ventaboletos.relatorios.utilitarios.ArrayDataSource; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.utilerias.DateUtil; +import com.rjconsultores.ventaboletos.vo.parada.ParadaVO; +import com.rjconsultores.ventaboletos.vo.ruta.RutaVO; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + + +public class RelatorioAproveitamentoFinanceiroTrecho extends Relatorio { + + private static Logger log = Logger.getLogger(RelatorioAproveitamentoFinanceiroTrecho.class); + + public RelatorioAproveitamentoFinanceiroTrecho(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(); + String sqlCombinacoes = gerarCombinacaoTrechos(parametros); + StringBuilder sql = getSQL(parametros, sqlCombinacoes); + + 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("NUMLINHA", rset.getString("numLinha")); + dataResult.put("SENTIDO", rset.getString("sentido")); + dataResult.put("SERVICO", rset.getString("servico")); + dataResult.put("HORARIO", rset.getString("horario")); + dataResult.put("ORIGEM", rset.getString("origem")); + dataResult.put("DESTINO", rset.getString("destino")); + //Quantidade de assentos do diagrana autobus + BigDecimal assentos = limpaNulo(rset.getBigDecimal("assentos")); + BigDecimal tarifa = limpaNulo(rset.getBigDecimal("tarifa")); + BigDecimal totPassageiros = BigDecimal.ZERO; + BigDecimal totReceita = BigDecimal.ZERO; + Integer viagens =0; + + BigDecimal segReceitaOpe = limpaNulo(rset.getBigDecimal("'2'_RECEITA_OPE")); + Integer segQtde = rset.getInt("'2'_QTDE"); + BigDecimal segTot = limpaNulo(rset.getBigDecimal("'2'_TOT")); + totPassageiros = totPassageiros.add(segTot); + totReceita = totReceita.add(segReceitaOpe); + viagens = viagens + segQtde; + + BigDecimal terReceitaOpe = limpaNulo(rset.getBigDecimal("'3'_RECEITA_OPE")); + Integer terQtde = rset.getInt("'3'_QTDE"); + BigDecimal terTot = limpaNulo(rset.getBigDecimal("'3'_TOT")); + totPassageiros = totPassageiros.add(terTot); + totReceita = totReceita.add(terReceitaOpe); + viagens = viagens .intValue() + terQtde.intValue(); + + BigDecimal quaReceitaOpe = limpaNulo(rset.getBigDecimal("'4'_RECEITA_OPE")); + Integer quaQtde = rset.getInt("'4'_QTDE"); + BigDecimal quaTot = limpaNulo(rset.getBigDecimal("'4'_TOT")); + totPassageiros = totPassageiros.add(quaTot); + totReceita = totReceita.add(quaReceitaOpe); + viagens = viagens.intValue() + quaQtde.intValue(); + + BigDecimal quiReceitaOpe = limpaNulo(rset.getBigDecimal("'5'_RECEITA_OPE")); + Integer quiQtde = rset.getInt("'5'_QTDE"); + BigDecimal quiTot = limpaNulo(rset.getBigDecimal("'5'_TOT")); + totPassageiros = totPassageiros.add(quiTot); + totReceita = totReceita.add(quiReceitaOpe); + viagens = viagens.intValue() + quiQtde.intValue(); + + BigDecimal sexReceitaOpe = limpaNulo(rset.getBigDecimal("'6'_RECEITA_OPE")); + Integer sexQtde = rset.getInt("'6'_QTDE"); + BigDecimal sexTot = limpaNulo(rset.getBigDecimal("'6'_TOT")); + totPassageiros = totPassageiros.add(sexTot); + totReceita = totReceita.add(sexReceitaOpe); + viagens = viagens.intValue() + sexQtde.intValue(); + + BigDecimal sabReceitaOpe = limpaNulo(rset.getBigDecimal("'7'_RECEITA_OPE")); + Integer sabQtde = rset.getInt("'7'_QTDE"); + BigDecimal sabTot = limpaNulo(rset.getBigDecimal("'7'_TOT")); + totPassageiros = totPassageiros.add(sabTot); + totReceita = totReceita.add(sabReceitaOpe); + viagens = viagens.intValue() + sabQtde.intValue(); + + BigDecimal domReceitaOpe = limpaNulo(rset.getBigDecimal("'1'_RECEITA_OPE")); + Integer domQtde = rset.getInt("'1'_QTDE"); + BigDecimal domTot = limpaNulo(rset.getBigDecimal("'1'_TOT")); + totPassageiros = totPassageiros.add(domTot); + totReceita = totReceita.add(domReceitaOpe); + viagens = viagens.intValue() + domQtde.intValue(); + dataResult.put("VIAGENS", new BigDecimal(viagens)); + log.info("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", new BigDecimal(segQtde)); + dataResult.put("SEG_TOT", segTot); + dataResult.put("SEG_FIN", calculaMedia(segReceitaOpe, tarifa, segQtde, assentos)); + + dataResult.put("TER_RECEITA_OPE", terReceitaOpe); + dataResult.put("TER_QTDE", new BigDecimal(terQtde)); + dataResult.put("TER_TOT", terTot); + dataResult.put("TER_FIN", calculaMedia(terReceitaOpe, tarifa, terQtde, assentos)); + + dataResult.put("QUA_RECEITA_OPE", quaReceitaOpe); + dataResult.put("QUA_QTDE", new BigDecimal(quaQtde)); + dataResult.put("QUA_TOT", quaTot); + dataResult.put("QUA_FIN", calculaMedia(quaReceitaOpe, tarifa, quaQtde, assentos)); + + dataResult.put("QUI_RECEITA_OPE", quiReceitaOpe); + dataResult.put("QUI_QTDE", new BigDecimal(quiQtde)); + dataResult.put("QUI_TOT", quiTot); + dataResult.put("QUI_FIN", calculaMedia(quiReceitaOpe, tarifa, quiQtde, assentos)); + + dataResult.put("SEX_RECEITA_OPE", sexReceitaOpe); + dataResult.put("SEX_QTDE", new BigDecimal(sexQtde)); + dataResult.put("SEX_TOT", sexTot); + dataResult.put("SEX_FIN", calculaMedia(sexReceitaOpe, tarifa, sexQtde, assentos)); + + dataResult.put("SAB_RECEITA_OPE", sabReceitaOpe); + dataResult.put("SAB_QTDE", new BigDecimal(sabQtde)); + dataResult.put("SAB_TOT", sabTot); + dataResult.put("SAB_FIN", calculaMedia(sabReceitaOpe, tarifa, sabQtde, assentos)); + + dataResult.put("DOM_RECEITA_OPE", domReceitaOpe); + dataResult.put("DOM_QTDE", new BigDecimal(domQtde)); + dataResult.put("DOM_TOT", domTot); + dataResult.put("DOM_FIN", calculaMedia(domReceitaOpe, tarifa, domQtde, assentos)); + + this.dados.add(dataResult); + } + + this.resultSet = rset; + } + + private StringBuilder getSQL(Map parametros, String sqlCombinacoes) { + + StringBuilder sql = new StringBuilder(); + sql.append(" select TB.*, "); + sql.append(" (SELECT "); + sql.append(" max (TF.PRECIO) "); + sql.append(" FROM "); + sql.append(" CORRIDA CR, "); + sql.append(" TRAMO TR, "); + sql.append(" RUTA R, "); + sql.append(" RUTA_COMBINACION RC, "); + sql.append(" TARIFA TF, "); + sql.append(" VIGENCIA_TARIFA VT "); + sql.append(" WHERE "); + sql.append(" CR.CORRIDA_ID = TB.SERVICO "); + sql.append(" AND CR.FECCORRIDA BETWEEN :DATA_INICIAL and :DATA_FINAL "); + sql.append(" AND CR.RUTA_ID = TB.RUTAID "); + sql.append(" AND CR.RUTA_ID = R.RUTA_ID AND R.ACTIVO = 1 "); + sql.append(" AND CR.RUTA_ID = RC.RUTA_ID AND RC.ACTIVO = 1 "); + sql.append(" AND RC.TRAMO_ID = TR.TRAMO_ID "); + sql.append(" AND TF.TRAMO_ID = TR.TRAMO_ID "); + sql.append(" AND TF.MARCA_ID = CR.MARCA_ID "); + sql.append(" AND TF.RUTA_ID = CR.RUTA_ID "); + sql.append(" AND TF.STATUSTARIFA = 'A' "); + sql.append(" AND CR.ACTIVO <> 0 "); + sql.append(" AND TF.ACTIVO = 1 "); + sql.append(" AND TR.ORIGEN_ID = CR.ORIGEN_ID "); + sql.append(" AND TR.DESTINO_ID = CR.DESTINO_ID "); + sql.append(" AND TF.VIGENCIATARIFA_ID = VT.VIGENCIATARIFA_ID "); + sql.append(" AND TF.ORGAOCONCEDENTE_ID = R.ORGAOCONCEDENTE_ID "); + sql.append(" AND VT.ACTIVO = 1 "); + sql.append(" AND CR.FECCORRIDA BETWEEN VT.FECINICIOVIGENCIA AND VT.FECFINVIGENCIA "); + sql.append(" AND TF.CLASESERVICIO_ID = CR.CLASESERVICIO_ID "); + sql.append(" ) TARIFA "); + sql.append(" from "); + sql.append(" ( "); + sql.append(" select * from ( "); + sql.append(" SELECT "); + sql.append(" r.DESCRUTA as linha, "); + sql.append(" r.NUMRUTA as numLinha, "); + sql.append(" r.ruta_id as rutaid, "); + sql.append(" count( c.boleto_id) as passageiros, "); + sql.append(" sum( coalesce(c.preciopagado, 0) )as valor, "); + sql.append(" to_char( co.FECCORRIDA, 'D') as dia, "); + // Quantidade de dias da semana diferente vendidas + // "WW" Esse parâmetro para o to_char tras o dia da semana da data + sql.append(" coalesce(count(DISTINCT to_char( co.FECCORRIDA, 'WW')), 0) 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(" co.CORRIDA_ID as servico, "); + sql.append(" ORI.descparada as origem, "); + sql.append(" DES.descparada as destino "); + sql.append(" FROM boleto c "); + sql.append(" RIGHT OUTER 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 co.RUTA_ID = r.RUTA_ID "); + sql.append(" and r.ACTIVO = 1 "); + sql.append(" inner join MARCA m "); + sql.append(" on m.marca_id = co.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(" left join corrida_tramo ct ON ct.corrida_id = co.corrida_id and ct.FECCORRIDA = co.FECCORRIDA and ct.ACTIVO = 1 "); + sql.append(" left join tramo t ON t.TRAMO_ID = ct.TRAMO_ID and t.ACTIVO = 1 "); + sql.append(" left join parada ORI ON ORI.parada_id = c.origen_id "); + sql.append(" left join parada DES ON DES.parada_id = c.destino_id "); + sql.append(" WHERE co.activo = 1 "); + sql.append(" AND c.activo = 1 "); + sql.append(" AND m.EMPRESA_ID = :EMPRESA_ID "); + sql.append(" and co.FECCORRIDA >= :DATA_INICIAL "); + sql.append(" and co.FECCORRIDA <= :DATA_FINAL "); + + if (parametros.get("LINHAS") != null && !possuiFiltroTodos("LINHAS")) { + sql.append(" and co.ruta_id IN (" + parametros.get("LINHAS").toString() + ")"); + } + if (sqlCombinacoes != null && !sqlCombinacoes.isEmpty()) { + sql.append(" " +sqlCombinacoes+ " "); + } + + sql.append(" and c.MOTIVOCANCELACION_ID is null "); + sql.append(" GROUP by r.DESCRUTA, r.ruta_id, r.indsentidoida, r.NUMRUTA, da.cantasientos, "); + sql.append(" to_char( co.FECCORRIDA, 'D'), TO_CHAR(co.fechorsalidaoriginal ,'HH24:mi'), "); + sql.append(" co.CORRIDA_ID, ORI.descparada, DES.descparada "); + sql.append(" ORDER by r.DESCRUTA, r.indsentidoida desc, to_char( co.FECCORRIDA, 'D') "); + sql.append(" ) "); + sql.append("PIVOT "); + sql.append("( "); + sql.append(" max(valor) receita_ope, "); + sql.append(" max(qtde) qtde, "); + sql.append(" max(passageiros) tot "); + sql.append(" for dia in ('1', '2', '3', '4', '5', '6', '7') "); + sql.append(") "); + sql.append(") TB"); + return sql; + } + }); + } + + @Override + protected void processaParametros() throws Exception { + + } + + + private BigDecimal limpaNulo( BigDecimal val ) { + if( val == null ) { + return BigDecimal.ZERO; + }else { + return val; + } + } + + /** + * Faz calculo da media na seguinte formula (Tot. Rceita / (tarifa * qtde * assentos)) + * (1427,17 / (108,30*1*42)) * 100 + * @param totReceita + * @param tarifa + * @param qtde (Quantidade viagens do dia da semana no periodo. + * Ex 01 a 07, sendo 01 Domingo e 07 Sabado, tera sempre quantidade igual a 7 se o servico for executado todo dia) + * @param tot + * @return + */ + private BigDecimal calculaMedia(BigDecimal totReceita, BigDecimal tarifa, Integer qtde, BigDecimal tot) { + if( qtde.intValue() != 0 && tot.intValue() !=0 ) { + //Multiplica a tarifa pela quantidade de viagens no dia da semana (Segunda, terça...) no período + BigDecimal dividendo = tarifa.multiply(new BigDecimal(qtde)); + //Multiplica o dividendo pelo total de passegeiros + dividendo = dividendo.multiply(tot); + + if(dividendo.intValue() == 0 ) { + return BigDecimal.ZERO; + } + + BigDecimal fin = totReceita.divide(dividendo, 4, BigDecimal.ROUND_HALF_UP); + fin = fin.multiply(new BigDecimal(new Long(100L))).setScale(2); + return fin !=null ? fin : BigDecimal.ZERO; + }else{ + return BigDecimal.ZERO; + } + } + + private String gerarCombinacaoTrechos(Map parametros) { + + String linhas = (String) parametros.get("LINHAS"); + String[] arrayLinhas = null; + + if(linhas != null) { + arrayLinhas = linhas.split(";"); + } + + @SuppressWarnings("unchecked") + List trechos = (List) parametros.get("TRECHOS"); + + List listParada1 = new ArrayList<>(); + List listParada2 = new ArrayList<>(); + StringBuilder sql = new StringBuilder(); + + for (RutaVO tramoVO : trechos) { + listParada1.add(new ParadaVO(tramoVO.getOrigenId(), tramoVO.getRutaId().intValue())); + } + + listParada2.addAll(listParada1); + + if (trechos != null) { + + LinkedList> lists = new LinkedList>(); + + lists.add(listParada1); + lists.add(listParada2); + + Set combinacoes = new TreeSet(); + + sql.append("AND ("); + for (ParadaVO s : lists.removeFirst()) + combinacoes.add(s.getParadaId().toString()); + + while (!lists.isEmpty()) { + List next = lists.removeFirst(); + Set novasCombinacoes = new TreeSet(); + for (String s1 : combinacoes) { + for (ParadaVO s2 : next) { + novasCombinacoes.add(s1 + ";" + s2.getParadaId()); + sql.append("(c.origen_id = ").append(s1).append(" AND c.destino_id = ").append(s2.getParadaId()).append(" and c.ruta_id = " + s2.getRutaId() + " ) OR "); + } + } + combinacoes = novasCombinacoes; + } + + // Remover o último " OR " da string + if (combinacoes.size() > 0) { + sql.delete(sql.length() - 4, sql.length()); + } + sql.append(")"); + + } + + return sql.toString(); + + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioAproveitamentoFinanceiroTrecho_pt_BR.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioAproveitamentoFinanceiroTrecho_pt_BR.properties new file mode 100644 index 000000000..2bc62084a --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioAproveitamentoFinanceiroTrecho_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/RelatorioAproveitamentoFinanceiroTrecho.jasper b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiroTrecho.jasper new file mode 100644 index 000000000..668623ee4 Binary files /dev/null and b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiroTrecho.jasper differ diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiroTrecho.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiroTrecho.jrxml new file mode 100644 index 000000000..f72b863b1 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioAproveitamentoFinanceiroTrecho.jrxml @@ -0,0 +1,1552 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..c4bc606af 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 @@ -21,23 +21,29 @@ import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zul.Comboitem; import org.zkoss.zul.Datebox; +import org.zkoss.zul.Radiogroup; +import org.zkoss.zul.Row; 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.RelatorioAproveitamentoFinanceiroTrecho; import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; import com.rjconsultores.ventaboletos.service.RutaService; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; +import com.rjconsultores.ventaboletos.vo.ruta.RutaVO; import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar; import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; import com.rjconsultores.ventaboletos.web.utilerias.MyListbox; import com.rjconsultores.ventaboletos.web.utilerias.render.RenderRelatorioAproveitamentoFinanceiro; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderRelatorioAproveitamentoFinanceiroTrecho; @Controller("relatorioAproveitamentoFinanceiroController") @Scope("prototype") @SuppressWarnings({ "rawtypes", "unchecked" }) + public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwardComposer { private static final long serialVersionUID = 1L; @@ -48,17 +54,19 @@ public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwar private Datebox datInicial; private Datebox datFinal; - private MyComboboxEstandar cmbEmpresa; - private List lsEmpresa; - + private List lsEmpresa; + private ArrayList rutaVO = new ArrayList(); @Autowired private RutaService rutaService; private MyListbox linhaList; + private MyListbox trechoList; private MyListbox linhaListSelList; private Textbox txtPalavraPesquisaLinha; private ArrayList lsNumLinha = new ArrayList(); + private Radiogroup rgLayout; + private Row rowTrecho; @Override public void doAfterCompose(Component comp) throws Exception { @@ -67,6 +75,26 @@ public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwar lsEmpresa = UsuarioLogado.getUsuarioLogado().getEmpresa(); linhaList.setItemRenderer(new RenderRelatorioAproveitamentoFinanceiro()); linhaListSelList.setItemRenderer(new RenderRelatorioAproveitamentoFinanceiro()); + trechoList.setItemRenderer(new RenderRelatorioAproveitamentoFinanceiroTrecho()); + + } + + public void carregarTramos(Ruta rutaSelecionada) { + + List lsRutaVO = rutaService.buscaRutaParadas(rutaSelecionada.getRutaId()); + RutaVO ultimaRuta = lsRutaVO.get(lsRutaVO.size()-1); + RutaVO novaRuta = new RutaVO(ultimaRuta.getRutaId(), ultimaRuta.getNumRuta(), ultimaRuta.getPrefixo(),ultimaRuta.getDescruta(),ultimaRuta.getDescDestino(), ultimaRuta.getNumSecuencia(), ultimaRuta.getDestinoId(), ultimaRuta.getDestinoId()); + novaRuta.setDescOrigem(novaRuta.getDescParada()); + lsRutaVO.add(novaRuta); + List lsRutaVOAux = new ArrayList(); + lsRutaVOAux.addAll(trechoList.getListData()); + lsRutaVOAux.addAll(lsRutaVO); + trechoList.setData(lsRutaVOAux); + + } + + public void actualizarDados(List listaRutaVO) { + } public List getLsEmpresa() { @@ -80,13 +108,14 @@ public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwar public void onDoubleClick$linhaList(Event ev) { Ruta rutaAux = (Ruta) linhaList.getSelected(); linhaListSelList.addItemNovo(rutaAux); + carregarTramos(rutaAux); } private void executarPesquisaLinha() { String palavraPesquisaRuta = txtPalavraPesquisaLinha.getText(); linhaList.setData(rutaService.buscaRuta(palavraPesquisaRuta)); - + if (linhaList.getData().length == 0) { try { Messagebox.show(Labels.getLabel("MSG.ningunRegistro"), @@ -112,7 +141,16 @@ public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwar } private void executarRelatorio() throws Exception { - Relatorio relatorio; + + if(rgLayout.getSelectedItem().getValue().equals("EMISSAO_LINHA")) { + executarRelatorioLinha(); + }else { + executarRelatorioTrecho(); + } + } + + private void executarRelatorioLinha() throws Exception { + Map parametros = new HashMap(); StringBuilder filtro = new StringBuilder(); @@ -155,7 +193,7 @@ public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwar } parametros.put("FILTROS", filtro.toString()); - relatorio = new RelatorioAproveitamentoFinanceiro(parametros, dataSourceRead.getConnection()); + Relatorio relatorio = new RelatorioAproveitamentoFinanceiro(parametros, dataSourceRead.getConnection()); Map args = new HashMap(); args.put("relatorio", relatorio); @@ -163,4 +201,57 @@ public class RelatorioAproveitamentoFinanceiroController extends MyGenericForwar openWindow("/component/reportView.zul", Labels.getLabel("relatorioAproveitamentoFinanceiroController.window.title"), args, MODAL); } + private void executarRelatorioTrecho() throws Exception { + Map parametros = new HashMap(); + StringBuilder filtro = new StringBuilder(); + + filtro.append("Linha: "); + String linhaIds = ""; + String linhas = ""; + List lslinhaSelecionados = new ArrayList(Arrays.asList(linhaListSelList.getData())); + if (lslinhaSelecionados.isEmpty()) { + linhas = "Todas"; + } else { + for (int i = 0; i < lslinhaSelecionados.size(); i++) { + Ruta linha = lslinhaSelecionados.get(i); + linhas = linhas + linha.getDescruta() + ", "; + + linhaIds = linhaIds + linha.getRutaId() + ", "; + } + + // removendo ultima virgula + linhaIds = linhaIds.substring(0, linhaIds.length() - 2); + linhas = linhas.substring(0, linhas.length() - 2); + parametros.put("LINHAS", linhaIds); + } + filtro.append(linhas).append(";"); + + parametros.put("DATA_INICIAL", (java.util.Date) this.datInicial.getValue()); + parametros.put("DATA_FINAL", (java.util.Date) this.datFinal.getValue()); + parametros.put("NOME_RELATORIO", Labels.getLabel("relatorioAproveitamentoFinanceiroController.window.title")); + parametros.put("USUARIO", UsuarioLogado.getUsuarioLogado().getNombusuario()); + parametros.put("TRECHOS", trechoList.getListData()); + + filtro.append(" Empresa: "); + + Comboitem itemEmpresa = cmbEmpresa.getSelectedItem(); + if (itemEmpresa != null) { + Empresa empresa = (Empresa) itemEmpresa.getValue(); + parametros.put("EMPRESA_ID", empresa.getEmpresaId()); + parametros.put("EMPRESA", empresa.getNombempresa()); + filtro.append(empresa.getNombempresa() + ";"); + } else { + filtro.append(" Todas;"); + } + + parametros.put("FILTROS", filtro.toString()); + Relatorio relatorio = new RelatorioAproveitamentoFinanceiroTrecho(parametros, dataSourceRead.getConnection()); + + Map args = new HashMap(); + args.put("relatorio", relatorio); + + openWindow("/component/reportView.zul", + Labels.getLabel("relatorioAproveitamentoFinanceiroController.window.title"), args, MODAL); + } + } diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderRelatorioAproveitamentoFinanceiroTrecho.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderRelatorioAproveitamentoFinanceiroTrecho.java new file mode 100644 index 000000000..6dacec1ec --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderRelatorioAproveitamentoFinanceiroTrecho.java @@ -0,0 +1,61 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.web.utilerias.render; + +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zul.Button; +import org.zkoss.zul.Listcell; +import org.zkoss.zul.Listitem; +import org.zkoss.zul.ListitemRenderer; + +import com.rjconsultores.ventaboletos.vo.ruta.RutaVO; +import com.rjconsultores.ventaboletos.web.utilerias.MyListbox; + +/** + * @author Wallace + * + */ +public class RenderRelatorioAproveitamentoFinanceiroTrecho implements ListitemRenderer { + + @Override + public void render(Listitem lstm, Object o) throws Exception { + RutaVO ruta = (RutaVO) o; + + Listcell lc = new Listcell(ruta.getNumRuta().toString()); + lc.setParent(lstm); + + lc = new Listcell(ruta.getPrefixo()); + lc.setParent(lstm); + + lc = new Listcell(ruta.getDescruta()); + lc.setParent(lstm); + + lc = new Listcell(ruta.getDescOrigem()); + lc.setParent(lstm); + + Button btn = new Button(); + + lc = new Listcell(); + lc.setParent(lstm); + + btn.setWidth("16"); + btn.setHeight("16"); + btn.setImage("/gui/img/remove.png"); + + btn.addEventListener("onClick", new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + MyListbox listBox = (MyListbox) event.getTarget().getParent().getParent().getParent(); + Listitem listItem = (Listitem) event.getTarget().getParent().getParent(); + listBox.removeItem((RutaVO) listItem.getAttribute("data")); + } + }); + + lc.appendChild(btn); + + lstm.setAttribute("data", ruta); + } + +} diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index e95cb3ff8..edb59c917 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -10421,6 +10421,14 @@ relatorioAproveitamentoFinanceiroController.lbEmpresa.value = Empresa relatorioAproveitamentoFinanceiroController.btnPesquisa.label = Buscar relatorioAproveitamentoFinanceiroController.btnLimpar.label = Limpar relatorioAproveitamentoFinanceiroController.lbNumero.value = Número Agência +relatorioAproveitamentoFinanceiroController.window.title = Relatório de Aproveitamento Financeiro +relatorioAproveitamentoFinanceiroController.linha = Relatório por Linha +relatorioAproveitamentoFinanceiroController.trecho = Relatório por Trecho +relatorioAproveitamentoFinanceiroController.lbOrigem.value = Origem +relatorioAproveitamentoFinanceiroController.lbDestino.value = Destino +relatorioAproveitamentoFinanceiroController.lbNumRuta.label = Num. Linha +relatorioAproveitamentoFinanceiroController.lbPrefixo.label = Prefixo +relatorioLinhasHorarioController.lbOrgao.label = Orgão Concedente #Relatório MMPH - DER-PR relatorioMmphDerController.window.title = Relatório MMPH - DER-PR diff --git a/web/gui/relatorios/filtroRelatorioAproveitamentoFinanceiro.zul b/web/gui/relatorios/filtroRelatorioAproveitamentoFinanceiro.zul index e481fa8c2..d4642234a 100644 --- a/web/gui/relatorios/filtroRelatorioAproveitamentoFinanceiro.zul +++ b/web/gui/relatorios/filtroRelatorioAproveitamentoFinanceiro.zul @@ -6,7 +6,7 @@ @@ -46,10 +46,25 @@ model="@{winFiltroRelatorioAproveitamentoFinanceiro$composer.lsEmpresa}" width="95%" /> + + + +