diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java index cc1345879..5bfc3b57d 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java @@ -14,7 +14,9 @@ import java.util.HashMap; import java.util.Map; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; +import com.rjconsultores.ventaboletos.relatorios.negocio.CalculoImposto; import com.rjconsultores.ventaboletos.relatorios.utilitarios.ArrayDataSource; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.ExceptionConfiguracao; import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; @@ -24,14 +26,12 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; */ public class RelatorioReceitaDiariaAgencia extends Relatorio { - private Map> mapCacheConfigImposto; private Map> mapCacheConfigComissao; public RelatorioReceitaDiariaAgencia(Map parametros, Connection conexao) throws Exception { super(parametros, conexao); - this.mapCacheConfigImposto = new HashMap>(); this.mapCacheConfigComissao = new HashMap>(); this.setCustomDataSource(new ArrayDataSource(this) { @@ -265,18 +265,18 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { if (motivoCancelacionId == null) { row.put("RECEITA_TARIFA", ((BigDecimal) row.get("RECEITA_TARIFA")).add(!tipoVentaId.equals(18) && !tipoVentaId.equals(39) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); - row.put("RECEITA_TARIFA_GAP", ((BigDecimal) row.get("RECEITA_TARIFA_GAP")).add( (tipoVentaId.equals(18) || tipoVentaId.equals(39))? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); + row.put("RECEITA_TARIFA_GAP", ((BigDecimal) row.get("RECEITA_TARIFA_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); row.put("RECEITA_SEGURO", ((BigDecimal) row.get("RECEITA_SEGURO")).add(!tipoVentaId.equals(18) && !tipoVentaId.equals(39) && this.resultSet.getBigDecimal("IMPORTESEGURO") != null ? this.resultSet.getBigDecimal("IMPORTESEGURO") : BigDecimal.ZERO)); - row.put("RECEITA_SEGURO_GAP", ((BigDecimal) row.get("RECEITA_SEGURO_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) ? this.resultSet.getBigDecimal("IMPORTESEGURO") : BigDecimal.ZERO)); + row.put("RECEITA_SEGURO_GAP", ((BigDecimal) row.get("RECEITA_SEGURO_GAP")).add(((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTESEGURO") != null) ? this.resultSet.getBigDecimal("IMPORTESEGURO") : BigDecimal.ZERO)); row.put("RECEITA_EMBARQUE", ((BigDecimal) row.get("RECEITA_EMBARQUE")).add(!tipoVentaId.equals(18) && !tipoVentaId.equals(39) && this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") != null ? this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") : BigDecimal.ZERO)); - row.put("RECEITA_EMBARQUE_GAP", ((BigDecimal) row.get("RECEITA_EMBARQUE_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") != null ? this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") : BigDecimal.ZERO)); + row.put("RECEITA_EMBARQUE_GAP", ((BigDecimal) row.get("RECEITA_EMBARQUE_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") != null ? this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") : BigDecimal.ZERO)); row.put("RECEITA_OUTROS", ((BigDecimal) row.get("RECEITA_OUTROS")).add(!tipoVentaId.equals(18) && !tipoVentaId.equals(39) && this.resultSet.getBigDecimal("IMPORTEOUTROS") != null ? this.resultSet.getBigDecimal("IMPORTEOUTROS") : BigDecimal.ZERO)); - row.put("RECEITA_OUTROS_GAP", ((BigDecimal) row.get("RECEITA_OUTROS_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTEOUTROS") != null ? this.resultSet.getBigDecimal("IMPORTEOUTROS") : BigDecimal.ZERO)); + row.put("RECEITA_OUTROS_GAP", ((BigDecimal) row.get("RECEITA_OUTROS_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTEOUTROS") != null ? this.resultSet.getBigDecimal("IMPORTEOUTROS") : BigDecimal.ZERO)); row.put("RECEITA_PEDAGIO", ((BigDecimal) row.get("RECEITA_PEDAGIO")).add(!tipoVentaId.equals(18) && !tipoVentaId.equals(39) && this.resultSet.getBigDecimal("IMPORTEPEDAGIO") != null ? this.resultSet.getBigDecimal("IMPORTEPEDAGIO") : BigDecimal.ZERO)); - row.put("RECEITA_PEDAGIO_GAP", ((BigDecimal) row.get("RECEITA_PEDAGIO_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTEPEDAGIO") != null ? this.resultSet.getBigDecimal("IMPORTEPEDAGIO") : BigDecimal.ZERO)); + row.put("RECEITA_PEDAGIO_GAP", ((BigDecimal) row.get("RECEITA_PEDAGIO_GAP")).add((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTEPEDAGIO") != null ? this.resultSet.getBigDecimal("IMPORTEPEDAGIO") : BigDecimal.ZERO)); row.put("IMPOSTOS", ((BigDecimal) row.get("IMPOSTOS")).add(!tipoVentaId.equals(18) || (tipoVentaId.equals(18) && (Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")) ? getValorImposto(puntoVentaId, this.resultSet.getString("INTERESTADUAL"), this.resultSet.getBigDecimal("PRECIOPAGADO"), this.resultSet.getBigDecimal("IMPORTESEGURO"), this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), this.resultSet.getBigDecimal("IMPORTEPEDAGIO")) : BigDecimal.ZERO)); // Realiza os calculos de comissão se o tipo de venda não for "EM ABERTO" e se for venda normal, ou se for GAP e o check estiver marcado - if (!tipoVentaId.equals(9) && ((!tipoVentaId.equals(18) && !tipoVentaId.equals(39) ) || ((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && (Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")))) + if (!tipoVentaId.equals(9) && ((!tipoVentaId.equals(18) && !tipoVentaId.equals(39)) || ((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && (Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")))) this.setRowComissao(row); } else { @@ -370,8 +370,6 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { mapCacheConfigComissao.put(puntoVentaId.toString() + "_" + empresaId.toString(), cacheConfig); - - } else { StringBuilder sqlParam = new StringBuilder(); @@ -394,7 +392,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { rsParam.close(); stmtParam.close(); } - + rs.close(); stmt.close(); @@ -409,173 +407,28 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { public HashMap getConfigImposto(Integer puntoVentaId) throws Exception { HashMap cacheConfig = null; - // Verifica se já existe configuração na memoria, caso não exista, realiza busca no banco - if (!mapCacheConfigImposto.containsKey(puntoVentaId.toString())) { - - StringBuilder sql = new StringBuilder(); - - sql.append("SELECT EI.*, ES.NOMBESTADO, EM.NOMBEMPRESA "); - sql.append(" FROM PUNTO_VENTA PV, PARADA PR, CIUDAD CD, EMPRESA_IMPOSTO EI, ESTADO ES, EMPRESA EM "); - sql.append("WHERE PV.PUNTOVENTA_ID = :PUNTOVENTA_ID "); - sql.append(" AND PV.PARADA_ID = PR.PARADA_ID "); - sql.append(" AND PR.CIUDAD_ID = CD.CIUDAD_ID "); - sql.append(" AND CD.ESTADO_ID = EI.ESTADO_ID (+) "); - sql.append(" AND PV.EMPRESA_ID = NVL(EI.EMPRESA_ID, PV.EMPRESA_ID) "); - sql.append(" AND CD.ESTADO_ID = ES.ESTADO_ID "); - sql.append(" AND PV.EMPRESA_ID = EM.EMPRESA_ID "); - sql.append(" AND NVL(EI.ACTIVO, 1) = 1 "); - - - NamedParameterStatement stmt = new NamedParameterStatement(this.getConexao(), sql.toString()); - stmt.setInt("PUNTOVENTA_ID", puntoVentaId); - - ResultSet rs = stmt.executeQuery(); - - if (rs.next()) { - - if (rs.getBigDecimal("ICMS") != null) { - cacheConfig = new HashMap(); - - cacheConfig.put("PORCREDBASEICMS", rs.getBigDecimal("PORCREDBASEICMS")); - cacheConfig.put("PORCREDESTADUAL", rs.getBigDecimal("PORCREDESTADUAL")); - cacheConfig.put("INDTARIFAESTADUAL", rs.getBoolean("INDTARIFAESTADUAL")); - cacheConfig.put("INDSEGUROESTADUAL", rs.getBoolean("INDSEGUROESTADUAL")); - cacheConfig.put("INDTXEMBARQUEESTADUAL", rs.getBoolean("INDTXEMBARQUEESTADUAL")); - cacheConfig.put("INDPEDAGIOESTDUAL", rs.getBoolean("INDPEDAGIOESTDUAL")); - cacheConfig.put("PORCREDMUNICIPAL", rs.getBigDecimal("PORCREDMUNICIPAL")); - cacheConfig.put("INDTARIFAMUNICIPAL", rs.getBoolean("INDTARIFAMUNICIPAL")); - cacheConfig.put("INDSEGUROMUNICIPAL", rs.getBoolean("INDSEGUROMUNICIPAL")); - cacheConfig.put("INDTXEMBARQUEMUNICIPAL", rs.getBoolean("INDTXEMBARQUEMUNICIPAL")); - cacheConfig.put("INDPEDAGIOMUNICIPAL", rs.getBoolean("INDPEDAGIOMUNICIPAL")); - - cacheConfig.put("INDJANEIRO", rs.getBoolean("INDJANEIRO")); - cacheConfig.put("INDFEVEREIRO", rs.getBoolean("INDFEVEREIRO")); - cacheConfig.put("INDMARCO", rs.getBoolean("INDMARCO")); - cacheConfig.put("INDABRIL", rs.getBoolean("INDABRIL")); - cacheConfig.put("INDMAIO", rs.getBoolean("INDMAIO")); - cacheConfig.put("INDJUNHO", rs.getBoolean("INDJUNHO")); - cacheConfig.put("INDJULHO", rs.getBoolean("INDJULHO")); - cacheConfig.put("INDAGOSTO", rs.getBoolean("INDAGOSTO")); - cacheConfig.put("INDSETEMBRO", rs.getBoolean("INDSETEMBRO")); - cacheConfig.put("INDOUTUBRO", rs.getBoolean("INDOUTUBRO")); - cacheConfig.put("INDNOVEMBRO", rs.getBoolean("INDNOVEMBRO")); - cacheConfig.put("INDDEZEMBRO", rs.getBoolean("INDDEZEMBRO")); - - cacheConfig.put("ICMS", rs.getBigDecimal("ICMS")); - cacheConfig.put("PORCREDBASEICMS", rs.getBigDecimal("PORCREDBASEICMS")); - - this.mapCacheConfigImposto.put(puntoVentaId.toString(), cacheConfig); - } - else - { - this.addInfoMsg("Não foi possivel obter a configuração de imposto para o estado: " + rs.getString("NOMBESTADO") + " empresa: " + rs.getString("NOMBEMPRESA")); - - } - - - - }; - rs.close(); - stmt.close(); - + try { + cacheConfig = (HashMap) CalculoImposto.getConfigImpostoByPuntoVenta(this.getConexao(), puntoVentaId); + } catch (Exception e) { + if (e instanceof ExceptionConfiguracao) + this.addInfoMsg(e.getMessage()); + else + throw e; } - else - cacheConfig = mapCacheConfigImposto.get(puntoVentaId.toString()); return cacheConfig; } public BigDecimal getValorImposto(Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio) throws Exception { - - HashMap configImposto = new HashMap(); - - BigDecimal baseCalculo = BigDecimal.ZERO; - BigDecimal icms; - BigDecimal porcRedEstadual; - BigDecimal porcRedMunicipal; - BigDecimal porcRedBaseIcms; - - BigDecimal valorIcms = BigDecimal.ZERO; - - Boolean indTarifaMunicipal; - Boolean indSeguroMunicipal; - Boolean indTxEmbarqueMunicipal; - Boolean indPedagioMunicipal; - Boolean indTarifaEstadual; - Boolean indSeguroEstadual; - Boolean indTxEmbarqueEstadual; - Boolean indPedagioEstadual; - - configImposto = this.getConfigImposto(puntoVentaId); - - if (configImposto == null) - return BigDecimal.ZERO; - - icms = (BigDecimal) configImposto.get("ICMS"); - porcRedBaseIcms = (BigDecimal) configImposto.get("PORCREDBASEICMS"); - - if (indInterestadual.equals("S")) { - porcRedEstadual = (BigDecimal) configImposto.get("PORCREDESTADUAL"); - - indTarifaEstadual = (Boolean) configImposto.get("INDTARIFAESTADUAL"); - indSeguroEstadual = (Boolean) configImposto.get("INDSEGUROESTADUAL"); - indTxEmbarqueEstadual = (Boolean) configImposto.get("INDTXEMBARQUEESTADUAL"); - indPedagioEstadual = (Boolean) configImposto.get("INDPEDAGIOESTDUAL"); - - // System.out.println(" Tarifa: "+ tarifa +" seguro: "+ seguro +" embarque: "+ embarque +" pedagio: "+ pedagio); - - // Criação da base de calculo - baseCalculo = indTarifaEstadual && tarifa != null ? baseCalculo.add(tarifa) : BigDecimal.ZERO; - baseCalculo = indSeguroEstadual && seguro != null ? baseCalculo.add(seguro) : BigDecimal.ZERO; - baseCalculo = indTxEmbarqueEstadual && embarque != null ? baseCalculo.add(embarque) : BigDecimal.ZERO; - baseCalculo = indPedagioEstadual && pedagio != null ? baseCalculo.add(pedagio) : BigDecimal.ZERO; - - // Redução da base de calculo - if (porcRedBaseIcms != null && porcRedBaseIcms.equals(BigDecimal.ZERO)) - // BASE DE CALCULO = BASE DE CALCULO - ((PERCENTUAL DE REDUÇÃO / 100) * BASE DE CALCULO )) - baseCalculo = baseCalculo.subtract(porcRedBaseIcms.divide(BigDecimal.valueOf(100)).multiply(baseCalculo)); - - // Calcula o valor do ICMS - valorIcms = baseCalculo.multiply(icms.divide(BigDecimal.valueOf(100))); - - // Redução estadual - if (porcRedEstadual != null && porcRedEstadual.equals(BigDecimal.ZERO)) - valorIcms = valorIcms.subtract(porcRedEstadual.divide(BigDecimal.valueOf(100)).multiply(valorIcms)); - - // System.out.println("INTER BASE DE CALCULO: "+baseCalculo+" VALOR ICMS: "+ valorIcms); - + try { + return CalculoImposto.getValorImposto(this.getConexao(), puntoVentaId, indInterestadual, tarifa, seguro, embarque, pedagio); + } catch (Exception e) { + if (e instanceof ExceptionConfiguracao) + this.addInfoMsg(e.getMessage()); + else + throw e; } - else { - porcRedMunicipal = (BigDecimal) configImposto.get("PORCREDMUNICIPAL"); - - indTarifaMunicipal = (Boolean) configImposto.get("INDTARIFAMUNICIPAL"); - indSeguroMunicipal = (Boolean) configImposto.get("INDSEGUROMUNICIPAL"); - indTxEmbarqueMunicipal = (Boolean) configImposto.get("INDTXEMBARQUEMUNICIPAL"); - indPedagioMunicipal = (Boolean) configImposto.get("INDPEDAGIOMUNICIPAL"); - - baseCalculo = indTarifaMunicipal && tarifa != null ? baseCalculo.add(tarifa) : BigDecimal.ZERO; - baseCalculo = indSeguroMunicipal && seguro != null ? baseCalculo.add(seguro) : BigDecimal.ZERO; - baseCalculo = indTxEmbarqueMunicipal && embarque != null ? baseCalculo.add(embarque) : BigDecimal.ZERO; - baseCalculo = indPedagioMunicipal && pedagio != null ? baseCalculo.add(pedagio) : BigDecimal.ZERO; - - // Redução da base de calculo - if (porcRedBaseIcms != null && porcRedBaseIcms.equals(BigDecimal.ZERO)) - // BASE DE CALCULO = BASE DE CALCULO - ((PERCENTUAL DE REDUÇÃO / 100) * BASE DE CALCULO )) - baseCalculo = baseCalculo.subtract(porcRedBaseIcms.divide(BigDecimal.valueOf(100)).multiply(baseCalculo)); - - // Calcula o valor do ICMS - valorIcms = baseCalculo.multiply(icms.divide(BigDecimal.valueOf(100))); - - // Redução estadual - if (porcRedMunicipal != null && porcRedMunicipal.equals(BigDecimal.ZERO)) - valorIcms = valorIcms.subtract(porcRedMunicipal.divide(BigDecimal.valueOf(100)).multiply(valorIcms)); - - // System.out.println("MUN BASE DE CALCULO: "+baseCalculo+" VALOR ICMS: "+ valorIcms); - - } - - return valorIcms; - + return BigDecimal.ZERO; } public BigDecimal getValorReceitaBagagem(Integer puntoVentaId) throws SQLException { diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioTaxasLinha.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioTaxasLinha.java new file mode 100644 index 000000000..49ad0a06d --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioTaxasLinha.java @@ -0,0 +1,209 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.relatorios.impl; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import com.rjconsultores.ventaboletos.relatorios.negocio.CalculoImposto; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.ExceptionConfiguracao; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + +/** + * @author Bruno H. G. Gouvêa + * + */ +public class RelatorioTaxasLinha extends Relatorio { + + /** + * @param parametros + * @param conexao + * @throws Exception + */ + public RelatorioTaxasLinha(Map parametros, Connection conexao) throws Exception { + super(parametros, conexao); + // TODO Auto-generated constructor stub + + this.setCustomDataSource(new DataSource(this) { + + public void initDados() throws Exception { + + Connection conexao = this.relatorio.getConexao(); + Map parametros = this.relatorio.getParametros(); + String sql = getSql(); + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql); + + stmt.setInt("TIPO_DATA", (Integer) parametros.get("TIPO_DATA")); + stmt.setDate("DATA_INICIAL", new java.sql.Date(((Date) parametros.get("DATA_INICIAL")).getTime())); + stmt.setDate("DATA_FINAL", new java.sql.Date(((Date) parametros.get("DATA_FINAL")).getTime())); + + if (parametros.get("EMPRESA_ID") != null) + stmt.setInt("EMPRESA_ID", (Integer) parametros.get("EMPRESA_ID")); + else + stmt.setNull("EMPRESA_ID", java.sql.Types.INTEGER); + + if (parametros.get("NUMPUNTOVENTA") != null) + stmt.setString("NUMPUNTOVENTA", (String) parametros.get("NUMPUNTOVENTA")); + else + stmt.setNull("NUMPUNTOVENTA", java.sql.Types.VARCHAR); + + if (parametros.get("ORIGEN_ID") != null) + stmt.setInt("ORIGEN_ID", (Integer) parametros.get("ORIGEN_ID")); + else + stmt.setNull("ORIGEN_ID", java.sql.Types.INTEGER); + + if (parametros.get("DESTINO_ID") != null) + stmt.setInt("DESTINO_ID", (Integer) parametros.get("DESTINO_ID")); + else + stmt.setNull("DESTINO_ID", java.sql.Types.INTEGER); + + this.resultSet = stmt.executeQuery(); + + } + + public Object valueCustomFields(String fieldName) throws Exception { + + // Se não for pra subtrair o ICMS, realiza o calculo e adiciona o mesmo + if (!(Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")) { + BigDecimal valorIcms = BigDecimal.ZERO; + String indInterestadual = this.resultSet.getString("INTERESTADUAL"); + Integer puntoVentaId = this.resultSet.getInt("PUNTOVENTA_ID"); + + try { + if (fieldName.equals("IMPORTETAXAEMBARQUE") && this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") != null && !this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE").equals(BigDecimal.ZERO)) { + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), puntoVentaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), BigDecimal.ZERO); + return this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE").add(valorIcms); + } + else if (fieldName.equals("IMPORTEPEDAGIO") && this.resultSet.getBigDecimal("IMPORTEPEDAGIO") != null && !this.resultSet.getBigDecimal("IMPORTEPEDAGIO").equals(BigDecimal.ZERO)) { + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), puntoVentaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTEPEDAGIO")); + return this.resultSet.getBigDecimal("IMPORTEPEDAGIO").add(valorIcms); + } + else if (fieldName.equals("IMPORTESEGURO") && this.resultSet.getBigDecimal("IMPORTESEGURO") != null && !this.resultSet.getBigDecimal("IMPORTESEGURO").equals(BigDecimal.ZERO)) { + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), puntoVentaId, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTESEGURO"), BigDecimal.ZERO, BigDecimal.ZERO); + return this.resultSet.getBigDecimal("IMPORTESEGURO").add(valorIcms); + } + else if (fieldName.equals("TOTAL_EMBARQUE") && !this.resultSet.getBigDecimal("TOTAL_EMBARQUE").equals(BigDecimal.ZERO)) { + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), puntoVentaId, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_EMBARQUE"), BigDecimal.ZERO, BigDecimal.ZERO); + return this.resultSet.getBigDecimal("TOTAL_EMBARQUE").add(valorIcms); + } + else if (fieldName.equals("TOTAL_PEDAGIO") && !this.resultSet.getBigDecimal("TOTAL_PEDAGIO").equals(BigDecimal.ZERO)) { + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), puntoVentaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_PEDAGIO")); + return this.resultSet.getBigDecimal("TOTAL_PEDAGIO").add(valorIcms); + } + else if (fieldName.equals("TOTAL_SEGURO") && !this.resultSet.getBigDecimal("TOTAL_SEGURO").equals(BigDecimal.ZERO)) { + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), puntoVentaId, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_SEGURO"), BigDecimal.ZERO, BigDecimal.ZERO); + return this.resultSet.getBigDecimal("TOTAL_SEGURO").add(valorIcms); + } + } catch (Exception e) { + if (e instanceof ExceptionConfiguracao) + this.relatorio.addInfoMsg(e.getMessage()); + else + throw e; + } + + } + return null; + } + + }); + } + + /* + * (non-Javadoc) + * + * @see com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio#processaParametros() + */ + @Override + protected void processaParametros() throws Exception { + // TODO Auto-generated method stub + + } + + public HashMap getConfigImposto(Integer puntoVentaId) throws Exception { + HashMap cacheConfig = null; + + try { + cacheConfig = (HashMap) CalculoImposto.getConfigImpostoByPuntoVenta(this.getConexao(), puntoVentaId); + } catch (Exception e) { + if (e instanceof ExceptionConfiguracao) + this.addInfoMsg(e.getMessage()); + else + throw e; + } + + return cacheConfig; + } + + private String getSql() { + + StringBuilder sql = new StringBuilder(); + + sql.append(" SELECT RT.PREFIXO, "); + sql.append(" PO.DESCPARADA CIDADE_ORIGEM, "); + sql.append(" PD.DESCPARADA CIDADE_DESTINO, "); + sql.append(" CJ.IMPORTETAXAEMBARQUE, "); + sql.append(" CJ.IMPORTEPEDAGIO, "); + sql.append(" CJ.IMPORTESEGURO, "); + sql.append(" EM.NOMBEMPRESA, "); + sql.append(" CJ.PUNTOVENTA_ID, "); + sql.append(" PV.NOMBPUNTOVENTA, "); + sql.append(" CASE "); + sql.append(" WHEN CO.ESTADO_ID <> CD.ESTADO_ID THEN "); + sql.append(" 'S' "); + sql.append(" ELSE "); + sql.append(" 'N' "); + sql.append(" END INTERESTADUAL, "); + sql.append(" COUNT(1) TOTAL_VENDIDOS, "); + sql.append(" SUM(CJ.IMPORTETAXAEMBARQUE) TOTAL_EMBARQUE, "); + sql.append(" SUM(CJ.IMPORTEPEDAGIO) TOTAL_PEDAGIO, "); + sql.append(" SUM(CJ.IMPORTESEGURO) TOTAL_SEGURO "); + sql.append(" FROM CORRIDA CR, "); + sql.append(" RUTA RT, "); + sql.append(" PUNTO_VENTA PV, "); + sql.append(" CAJA CJ, "); + sql.append(" PARADA PO, "); + sql.append(" PARADA PD, "); + sql.append(" CIUDAD CO, "); + sql.append(" CIUDAD CD, "); + sql.append(" EMPRESA EM "); + sql.append(" WHERE CR.RUTA_ID = RT.RUTA_ID "); + sql.append(" AND CJ.CORRIDA_ID = CR.CORRIDA_ID "); + sql.append(" AND CJ.FECCORRIDA = CR.FECCORRIDA "); + sql.append(" AND PO.PARADA_ID = CJ.ORIGEN_ID "); + sql.append(" AND PD.PARADA_ID = CJ.DESTINO_ID "); + sql.append(" AND PV.PUNTOVENTA_ID = CJ.PUNTOVENTA_ID "); + sql.append(" AND EM.EMPRESA_ID = CJ.EMPRESACORRIDA_ID "); + sql.append(" AND CO.CIUDAD_ID = PO.CIUDAD_ID "); + sql.append(" AND CD.CIUDAD_ID = PD.CIUDAD_ID "); + sql.append(" AND CJ.INDSTATUSOPERACION = 'F' "); + sql.append(" AND CJ.INDREIMPRESION = 0 "); + sql.append(" AND CJ.INDCANCELACION = 0 "); + sql.append(" AND DECODE(:TIPO_DATA, 1, CJ.FECCORRIDA, 2, CJ.FECHORVENTA) BETWEEN "); + sql.append(" :DATA_INICIAL AND :DATA_FINAL "); + sql.append(" AND EM.EMPRESA_ID = NVL(:EMPRESA_ID, EM.EMPRESA_ID) "); + sql.append(" AND PV.NUMPUNTOVENTA = NVL(:NUMPUNTOVENTA, PV.NUMPUNTOVENTA) "); + sql.append(" AND PO.PARADA_ID = NVL(:ORIGEN_ID, PO.PARADA_ID) "); + sql.append(" AND PD.PARADA_ID = NVL(:DESTINO_ID, PD.PARADA_ID) "); + sql.append(" GROUP BY RT.PREFIXO, "); + sql.append(" PO.DESCPARADA, "); + sql.append(" PD.DESCPARADA, "); + sql.append(" CJ.IMPORTETAXAEMBARQUE, "); + sql.append(" CJ.IMPORTEPEDAGIO, "); + sql.append(" CJ.IMPORTESEGURO, "); + sql.append(" CO.ESTADO_ID, "); + sql.append(" CD.ESTADO_ID, "); + sql.append(" EM.NOMBEMPRESA, "); + sql.append(" CJ.PUNTOVENTA_ID, "); + sql.append(" PV.NOMBPUNTOVENTA "); + sql.append(" ORDER BY EM.NOMBEMPRESA, PO.DESCPARADA "); + + return sql.toString(); + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioTaxasLinha_pt_BR.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioTaxasLinha_pt_BR.properties new file mode 100644 index 000000000..01f6ecc2b --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioTaxasLinha_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=Impressor 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/negocio/CalculoImposto.java b/src/java/com/rjconsultores/ventaboletos/relatorios/negocio/CalculoImposto.java new file mode 100644 index 000000000..538ae5d72 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/negocio/CalculoImposto.java @@ -0,0 +1,207 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.relatorios.negocio; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import com.rjconsultores.ventaboletos.relatorios.utilitarios.ExceptionConfiguracao; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + +/** + * @author Bruno H. G. Gouvêa + * + */ +public class CalculoImposto { + + static Map> mapCacheConfigImposto = new HashMap>(); + + public static Map getConfigImpostoByPuntoVenta(Connection conexao, Integer puntoVentaId) throws SQLException, ExceptionConfiguracao { + + HashMap cacheConfig = null; + + // Verifica se já existe configuração na memoria, caso não exista, realiza busca no banco + if (!mapCacheConfigImposto.containsKey(puntoVentaId.toString())) { + + Boolean isBuscouConfig = false; + + StringBuilder sql = new StringBuilder(); + + sql.append("SELECT EI.*, ES.NOMBESTADO, EM.NOMBEMPRESA "); + sql.append(" FROM PUNTO_VENTA PV, PARADA PR, CIUDAD CD, EMPRESA_IMPOSTO EI, ESTADO ES, EMPRESA EM "); + sql.append("WHERE PV.PUNTOVENTA_ID = :PUNTOVENTA_ID "); + sql.append(" AND PV.PARADA_ID = PR.PARADA_ID "); + sql.append(" AND PR.CIUDAD_ID = CD.CIUDAD_ID "); + sql.append(" AND CD.ESTADO_ID = EI.ESTADO_ID (+) "); + sql.append(" AND PV.EMPRESA_ID = NVL(EI.EMPRESA_ID, PV.EMPRESA_ID) "); + sql.append(" AND CD.ESTADO_ID = ES.ESTADO_ID "); + sql.append(" AND PV.EMPRESA_ID = EM.EMPRESA_ID "); + sql.append(" AND NVL(EI.ACTIVO, 1) = 1 "); + + NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql.toString()); + stmt.setInt("PUNTOVENTA_ID", puntoVentaId); + + ResultSet rs = stmt.executeQuery(); + + if (rs.next()) { + + if (rs.getBigDecimal("ICMS") != null) { + isBuscouConfig = true; + cacheConfig = new HashMap(); + + cacheConfig.put("PORCREDBASEICMS", rs.getBigDecimal("PORCREDBASEICMS")); + cacheConfig.put("PORCREDESTADUAL", rs.getBigDecimal("PORCREDESTADUAL")); + cacheConfig.put("INDTARIFAESTADUAL", rs.getBoolean("INDTARIFAESTADUAL")); + cacheConfig.put("INDSEGUROESTADUAL", rs.getBoolean("INDSEGUROESTADUAL")); + cacheConfig.put("INDTXEMBARQUEESTADUAL", rs.getBoolean("INDTXEMBARQUEESTADUAL")); + cacheConfig.put("INDPEDAGIOESTDUAL", rs.getBoolean("INDPEDAGIOESTDUAL")); + cacheConfig.put("PORCREDMUNICIPAL", rs.getBigDecimal("PORCREDMUNICIPAL")); + cacheConfig.put("INDTARIFAMUNICIPAL", rs.getBoolean("INDTARIFAMUNICIPAL")); + cacheConfig.put("INDSEGUROMUNICIPAL", rs.getBoolean("INDSEGUROMUNICIPAL")); + cacheConfig.put("INDTXEMBARQUEMUNICIPAL", rs.getBoolean("INDTXEMBARQUEMUNICIPAL")); + cacheConfig.put("INDPEDAGIOMUNICIPAL", rs.getBoolean("INDPEDAGIOMUNICIPAL")); + + cacheConfig.put("INDJANEIRO", rs.getBoolean("INDJANEIRO")); + cacheConfig.put("INDFEVEREIRO", rs.getBoolean("INDFEVEREIRO")); + cacheConfig.put("INDMARCO", rs.getBoolean("INDMARCO")); + cacheConfig.put("INDABRIL", rs.getBoolean("INDABRIL")); + cacheConfig.put("INDMAIO", rs.getBoolean("INDMAIO")); + cacheConfig.put("INDJUNHO", rs.getBoolean("INDJUNHO")); + cacheConfig.put("INDJULHO", rs.getBoolean("INDJULHO")); + cacheConfig.put("INDAGOSTO", rs.getBoolean("INDAGOSTO")); + cacheConfig.put("INDSETEMBRO", rs.getBoolean("INDSETEMBRO")); + cacheConfig.put("INDOUTUBRO", rs.getBoolean("INDOUTUBRO")); + cacheConfig.put("INDNOVEMBRO", rs.getBoolean("INDNOVEMBRO")); + cacheConfig.put("INDDEZEMBRO", rs.getBoolean("INDDEZEMBRO")); + + cacheConfig.put("ICMS", rs.getBigDecimal("ICMS")); + cacheConfig.put("PORCREDBASEICMS", rs.getBigDecimal("PORCREDBASEICMS")); + + } + String estado = rs.getString("NOMBESTADO"); + String empresa = rs.getString("NOMBEMPRESA"); + + if(!rs.isClosed()) + rs.close(); + if(!stmt.isClosed()) + stmt.close(); + + if (!isBuscouConfig) + throw new ExceptionConfiguracao("Não foi possivel obter a configuração de imposto para o estado: " + estado + " empresa: " + empresa); + + + }; + + if (!isBuscouConfig) + throw new ExceptionConfiguracao("Não foi possivel obter a configuração de imposto para agência "+puntoVentaId); + + mapCacheConfigImposto.put(puntoVentaId.toString(), cacheConfig); + + } + else + cacheConfig = mapCacheConfigImposto.get(puntoVentaId.toString()); + + return cacheConfig; + + } + + + public static BigDecimal getValorImposto(Connection conexao, Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio) throws Exception { + + HashMap configImposto = new HashMap(); + + BigDecimal baseCalculo = BigDecimal.ZERO; + BigDecimal icms; + BigDecimal porcRedEstadual; + BigDecimal porcRedMunicipal; + BigDecimal porcRedBaseIcms; + + BigDecimal valorIcms = BigDecimal.ZERO; + + Boolean indTarifaMunicipal; + Boolean indSeguroMunicipal; + Boolean indTxEmbarqueMunicipal; + Boolean indPedagioMunicipal; + Boolean indTarifaEstadual; + Boolean indSeguroEstadual; + Boolean indTxEmbarqueEstadual; + Boolean indPedagioEstadual; + + configImposto = (HashMap) getConfigImpostoByPuntoVenta(conexao,puntoVentaId); + + if (configImposto == null) + return BigDecimal.ZERO; + + icms = (BigDecimal) configImposto.get("ICMS"); + porcRedBaseIcms = (BigDecimal) configImposto.get("PORCREDBASEICMS"); + + if (indInterestadual.equals("S")) { + porcRedEstadual = (BigDecimal) configImposto.get("PORCREDESTADUAL"); + + indTarifaEstadual = (Boolean) configImposto.get("INDTARIFAESTADUAL"); + indSeguroEstadual = (Boolean) configImposto.get("INDSEGUROESTADUAL"); + indTxEmbarqueEstadual = (Boolean) configImposto.get("INDTXEMBARQUEESTADUAL"); + indPedagioEstadual = (Boolean) configImposto.get("INDPEDAGIOESTDUAL"); + + // System.out.println(" Tarifa: "+ tarifa +" seguro: "+ seguro +" embarque: "+ embarque +" pedagio: "+ pedagio); + + // Criação da base de calculo + baseCalculo = indTarifaEstadual && tarifa != null ? baseCalculo.add(tarifa) : BigDecimal.ZERO; + baseCalculo = indSeguroEstadual && seguro != null ? baseCalculo.add(seguro) : BigDecimal.ZERO; + baseCalculo = indTxEmbarqueEstadual && embarque != null ? baseCalculo.add(embarque) : BigDecimal.ZERO; + baseCalculo = indPedagioEstadual && pedagio != null ? baseCalculo.add(pedagio) : BigDecimal.ZERO; + + // Redução da base de calculo + if (porcRedBaseIcms != null && porcRedBaseIcms.equals(BigDecimal.ZERO)) + // BASE DE CALCULO = BASE DE CALCULO - ((PERCENTUAL DE REDUÇÃO / 100) * BASE DE CALCULO )) + baseCalculo = baseCalculo.subtract(porcRedBaseIcms.divide(BigDecimal.valueOf(100)).multiply(baseCalculo)); + + // Calcula o valor do ICMS + valorIcms = baseCalculo.multiply(icms.divide(BigDecimal.valueOf(100))); + + // Redução estadual + if (porcRedEstadual != null && porcRedEstadual.equals(BigDecimal.ZERO)) + valorIcms = valorIcms.subtract(porcRedEstadual.divide(BigDecimal.valueOf(100)).multiply(valorIcms)); + + // System.out.println("INTER BASE DE CALCULO: "+baseCalculo+" VALOR ICMS: "+ valorIcms); + + } + else { + porcRedMunicipal = (BigDecimal) configImposto.get("PORCREDMUNICIPAL"); + + indTarifaMunicipal = (Boolean) configImposto.get("INDTARIFAMUNICIPAL"); + indSeguroMunicipal = (Boolean) configImposto.get("INDSEGUROMUNICIPAL"); + indTxEmbarqueMunicipal = (Boolean) configImposto.get("INDTXEMBARQUEMUNICIPAL"); + indPedagioMunicipal = (Boolean) configImposto.get("INDPEDAGIOMUNICIPAL"); + + baseCalculo = indTarifaMunicipal && tarifa != null ? baseCalculo.add(tarifa) : BigDecimal.ZERO; + baseCalculo = indSeguroMunicipal && seguro != null ? baseCalculo.add(seguro) : BigDecimal.ZERO; + baseCalculo = indTxEmbarqueMunicipal && embarque != null ? baseCalculo.add(embarque) : BigDecimal.ZERO; + baseCalculo = indPedagioMunicipal && pedagio != null ? baseCalculo.add(pedagio) : BigDecimal.ZERO; + + // Redução da base de calculo + if (porcRedBaseIcms != null && porcRedBaseIcms.equals(BigDecimal.ZERO)) + // BASE DE CALCULO = BASE DE CALCULO - ((PERCENTUAL DE REDUÇÃO / 100) * BASE DE CALCULO )) + baseCalculo = baseCalculo.subtract(porcRedBaseIcms.divide(BigDecimal.valueOf(100)).multiply(baseCalculo)); + + // Calcula o valor do ICMS + valorIcms = baseCalculo.multiply(icms.divide(BigDecimal.valueOf(100))); + + // Redução estadual + if (porcRedMunicipal != null && porcRedMunicipal.equals(BigDecimal.ZERO)) + valorIcms = valorIcms.subtract(porcRedMunicipal.divide(BigDecimal.valueOf(100)).multiply(valorIcms)); + + // System.out.println("MUN BASE DE CALCULO: "+baseCalculo+" VALOR ICMS: "+ valorIcms); + + } + + return valorIcms; + + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioTaxasLinha.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioTaxasLinha.jrxml new file mode 100644 index 000000000..8bad4edee --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioTaxasLinha.jrxml @@ -0,0 +1,438 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/DataSource.java b/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/DataSource.java index 69cca751d..a9c5223ac 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/DataSource.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/DataSource.java @@ -32,7 +32,9 @@ public class DataSource implements IDataSource { return (valueCustomField != null) ? valueCustomField : this.resultSet.getObject(field.getName()); } catch (Exception e) { + e.printStackTrace(); throw new JRException(e); + } } diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/ExceptionConfiguracao.java b/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/ExceptionConfiguracao.java new file mode 100644 index 000000000..d0907656f --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/utilitarios/ExceptionConfiguracao.java @@ -0,0 +1,14 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.relatorios.utilitarios; + +/** + * @author Bruno H. G. Gouvêa + * + */ +public class ExceptionConfiguracao extends Exception { + public ExceptionConfiguracao(String msg){ + super(msg); + } +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioTaxasLinhaController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioTaxasLinhaController.java new file mode 100644 index 000000000..137398b1d --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioTaxasLinhaController.java @@ -0,0 +1,216 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.web.gui.controladores.relatorios; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Controller; +import org.zkoss.util.resource.Labels; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zul.Checkbox; +import org.zkoss.zul.Comboitem; +import org.zkoss.zul.ComboitemRenderer; +import org.zkoss.zul.Datebox; +import org.zkoss.zul.Radiogroup; + +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.Parada; +import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioAcompanhamentoEquivalentes; +import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioTaxasLinha; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.service.EmpresaService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; +import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar; +import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxParada; +import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxParadaCve; +import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; +import com.rjconsultores.ventaboletos.web.utilerias.MyTextbox; + +/** + * + * @author Administrador + */ +@Controller("relatorioTaxasLinhaController") +@Scope("prototype") +public class RelatorioTaxasLinhaController extends MyGenericForwardComposer { + + @Autowired + private DataSource dataSource; + + @Autowired + private EmpresaService empresaService; + + private List lsEmpresa; + + private MyComboboxParada cmbParadaOrigem; + private MyComboboxParadaCve cmbParadaOrigemCve; + private MyComboboxParada cmbParadaDestino; + private MyComboboxParadaCve cmbParadaDestinoCve; + + private Datebox datInicial; + private Datebox datFinal; + private MyTextbox txtNumPuntoVenta; + private Radiogroup rdGroupTipoData; + private Checkbox chkSubtrairIcms; + + private MyComboboxEstandar cmbEmpresa; + + public void onClick$btnExecutarRelatorio(Event ev) throws Exception { + executarRelatorio(); + } + + /** + * @throws Exception + * + */ + private void executarRelatorio() throws Exception { + + Relatorio relatorio; + Map parametros = new HashMap(); + StringBuilder filtro = new StringBuilder(); + + 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("relatorioTaxasLinhaController.window.title")); + parametros.put("USUARIO", UsuarioLogado.getUsuarioLogado().getUsuarioId().toString()); + parametros.put("TIPO_DATA", Integer.parseInt(rdGroupTipoData.getSelectedItem().getValue())); + parametros.put("NUMPUNTOVENTA", txtNumPuntoVenta.getValue()); + + parametros.put("B_SUBTRAIR_ICMS", chkSubtrairIcms.isChecked()); + + + + filtro.append("Agência: "); + + if( txtNumPuntoVenta.getValue().equals("")) + filtro.append("Todas; "); + else + filtro.append(txtNumPuntoVenta.getValue()+"; "); + + filtro.append(" Tipo de Data: "+( rdGroupTipoData.getSelectedItem().getValue().equals(1)?" Origem;":"Destino;")); + + filtro.append(" Subtrair ICMS: "+( chkSubtrairIcms.isChecked()?" Sim;":"Não;")); + + 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;"); + + + filtro.append(" Origem: "); + Comboitem cbiOrigem = cmbParadaOrigem.getSelectedItem(); + if (cbiOrigem != null) { + Parada origem = (Parada) cbiOrigem.getValue(); + parametros.put("ORIGEN_ID", origem.getParadaId()); + filtro.append(origem.getCveparada()+";"); + } + else + filtro.append("Todas;"); + + filtro.append(" Destino: "); + Comboitem cbiDestino = cmbParadaDestino.getSelectedItem(); + if (cbiDestino != null) { + Parada destino = (Parada) cbiDestino.getValue(); + parametros.put("DESTINO_ID", destino.getParadaId()); + filtro.append(destino.getCveparada()+";"); + } + else + filtro.append("Todos;"); + + + + parametros.put("FILTROS", filtro.toString()); + relatorio = new RelatorioTaxasLinha(parametros, dataSource.getConnection()); + + Map args = new HashMap(); + args.put("relatorio", relatorio); + + openWindow("/component/reportView.zul", + Labels.getLabel("relatorioTaxasLinhaController.window.title"), args, MODAL); + + } + + @Override + public void doAfterCompose(Component comp) throws Exception { + lsEmpresa = empresaService.obtenerTodos(); + + super.doAfterCompose(comp); + + cmbParadaOrigemCve.setItemRenderer(new ComboitemRenderer() { + + @Override + public void render(Comboitem cmbtm, Object o) throws Exception { + Parada parada = (Parada) o; + + cmbtm.setLabel(parada.getCveparada()); + cmbtm.setValue(parada); + + } + }); + + cmbParadaDestinoCve.setItemRenderer(new ComboitemRenderer() { + + @Override + public void render(Comboitem cmbtm, Object o) throws Exception { + Parada parada = (Parada) o; + + cmbtm.setLabel(parada.getCveparada()); + cmbtm.setValue(parada); + + } + }); + + } + + public List getLsEmpresa() { + return lsEmpresa; + } + + public void setLsEmpresa(List lsEmpresa) { + this.lsEmpresa = lsEmpresa; + } + + public void onSelect$cmbParadaOrigemCve(Event ev) { + if (cmbParadaOrigemCve.getSelectedItem() != null) { + cmbParadaOrigem.setComboItemByParada((Parada) cmbParadaOrigemCve.getSelectedItem().getValue()); + } + + } + + public void onSelect$cmbParadaOrigem(Event ev) { + + if (cmbParadaOrigem.getSelectedItem() != null) + cmbParadaOrigemCve.setComboItemByParada((Parada) cmbParadaOrigem.getSelectedItem().getValue()); + + } + + public void onSelect$cmbParadaDestinoCve(Event ev) { + + if (cmbParadaDestinoCve.getSelectedItem() != null) + cmbParadaDestino.setComboItemByParada((Parada) cmbParadaDestinoCve.getSelectedItem().getValue()); + + } + + public void onSelect$cmbParadaDestino(Event ev) { + + if (cmbParadaDestino.getSelectedItem() != null) + cmbParadaDestinoCve.setComboItemByParada((Parada) cmbParadaDestino.getSelectedItem().getValue()); + + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/NamedParameterStatement.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/NamedParameterStatement.java index 4b9c762b8..d56045758 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/utilerias/NamedParameterStatement.java +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/NamedParameterStatement.java @@ -307,6 +307,10 @@ public class NamedParameterStatement { public void close() throws SQLException { statement.close(); } + + public Boolean isClosed() throws SQLException { + return statement.isClosed(); + } /** * Adds the current set of parameters as a batch entry. diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioTaxasLinha.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioTaxasLinha.java new file mode 100644 index 000000000..529ba856a --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioTaxasLinha.java @@ -0,0 +1,25 @@ +package com.rjconsultores.ventaboletos.web.utilerias.menu.item.relatorios; + +import org.zkoss.util.resource.Labels; + +import com.rjconsultores.ventaboletos.web.utilerias.PantallaUtileria; +import com.rjconsultores.ventaboletos.web.utilerias.menu.DefaultItemMenuSistema; + +public class ItemMenuRelatorioTaxasLinha extends DefaultItemMenuSistema { + + public ItemMenuRelatorioTaxasLinha() { + super("indexController.mniRelatorioTaxasLinha.label"); + } + + @Override + public String getClaveMenu() { + return "COM.RJCONSULTORES.ADMINISTRACION.GUI.RELATORIOS.MENU.RELATORIOTAXASLINHA"; + } + + @Override + public void ejecutar() { + PantallaUtileria.openWindow("/gui/relatorios/filtroRelatorioTaxasLinha.zul", + Labels.getLabel("relatorioTaxasLinhaController.window.title"), null,desktop); + + } +} diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index d31bd875c..55fcc7dd6 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -221,6 +221,7 @@ indexController.mniRelatorioPassageirosViajar.label = Passageiros a Viajar indexController.mniRelatorioResumoLinhas.label = Relatório Resumo de Linhas indexController.mniRelatorioAcompanhamentoEquivalentes.label = Relatório Acompanhamento Equivalentes indexController.mniRelatorioLinhasHorario.label = Relatório de Linhas por Horário +indexController.mniRelatorioTaxasLinha.label = Relatório de Taxas por Linha #PARTE REALIZADA POR MANUEL indexController.mnCortesias.label = Cortesias Para Funcionários @@ -356,6 +357,20 @@ relatorioAcompanhamentoEquivalentesController.lbTipoServico.extraordinarios.valu relatorioAcompanhamentoEquivalentesController.lbTipoServico.todos.value = Todos relatorioAcompanhamentoEquivalentesController.lbEmpresa.value = Empresa +#Relatório de Taxas por Linha +relatorioTaxasLinhaController.window.title = Relatório de Taxas por Linha +relatorioTaxasLinhaController.lbEmpresa.value = Empresa +relatorioTaxasLinhaController.lbAte.value = até +relatorioTaxasLinhaController.lbDatInicial.value = Data Inicial +relatorioTaxasLinhaController.lbDatFinal.value = Data Final +relatorioTaxasLinhaController.lbTipoData.value = Tipo de Data +relatorioTaxasLinhaController.lbTipoData.venda.value = Venda +relatorioTaxasLinhaController.lbTipoData.servico.value = Serviço +relatorioTaxasLinhaController.lbChkSubtrairIcms.value = Subtrair ICMS +relatorioTaxasLinhaController.lbPuntoVenta.value = N. Agência +relatorioTaxasLinhaController.lbCidadaOrigem.value = Localidade Origem +relatorioTaxasLinhaController.lbCidadeDestino.value = Localidade Destino +relatorioTaxasLinhaController.lbPuntoVenta.value = Agência diff --git a/web/gui/relatorios/filtroRelatorioTaxasLinha.zul b/web/gui/relatorios/filtroRelatorioTaxasLinha.zul new file mode 100644 index 000000000..517ecb781 --- /dev/null +++ b/web/gui/relatorios/filtroRelatorioTaxasLinha.zul @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +