diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java index ccf8dc8ea..775f23f59 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java @@ -43,17 +43,17 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { public Object valueCustomFields(String fieldName) throws Exception { if (fieldName.equals("RECEITA_TOTAL")) { BigDecimal gap = BigDecimal.ZERO; - if ((Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")) { - gap = ((BigDecimal) this.getByName("RECEITA_TARIFA_GAP")).add((BigDecimal) this.getByName("RECEITA_SEGURO_GAP")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE_GAP")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL_GAP")); - } - return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")).add(gap); + + gap = ((BigDecimal) this.getByName("RECEITA_TARIFA_GAP")).add((BigDecimal) this.getByName("RECEITA_SEGURO_GAP")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE_GAP")).add((BigDecimal) this.getByName("RECEITA_PEDAGIO_GAP")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL_GAP")); + + return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).add((BigDecimal) this.getByName("RECEITA_PEDAGIO")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")).add(gap); } else if (fieldName.equals("RECEITA_LIQUIDA")) { BigDecimal gap = BigDecimal.ZERO; - if ((Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")) - gap = ((BigDecimal) this.getByName("RECEITA_TARIFA_GAP")).add((BigDecimal) this.getByName("RECEITA_SEGURO_GAP")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE_GAP")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL_GAP")); - return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")).subtract((BigDecimal) this.getByName("IMPOSTOS")).add(gap); + gap = ((BigDecimal) this.getByName("RECEITA_TARIFA_GAP")).add((BigDecimal) this.getByName("RECEITA_SEGURO_GAP")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE_GAP")).add((BigDecimal) this.getByName("RECEITA_PEDAGIO_GAP")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL_GAP")); + + return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).add((BigDecimal) this.getByName("RECEITA_PEDAGIO")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")).subtract((BigDecimal) this.getByName("IMPOSTOS")).add(gap); } else if (fieldName.equals("DIFERENCA_COMISSAO")) { return ((BigDecimal) this.getByName("VALOR_COMISSAO")).subtract((BigDecimal) this.getByName("ANTECIPACAO")); @@ -129,7 +129,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { Integer estadoId = this.resultSet.getInt("ORIGEM_ESTADO_ID"); - HashMap configImposto = getConfigImposto(puntoVentaId, estadoId); + HashMap configImposto = getConfigImposto((Integer) rowOrigem.get("EMPRESA_ID"), estadoId); if (configImposto == null) { return; } @@ -212,15 +212,15 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { rowDestino.put("ESTADO_ID", configComissao.get("ESTADO_ID")); rowDestino.put("TIPO_AGENCIA", configComissao.get("TIPO_AGENCIA")); - mapDados.put(puntoVentaId+"-"+rowOrigem.get("EMPRESA_ID"), (HashMap) rowDestino); + mapDados.put(puntoVentaId + "-" + rowOrigem.get("EMPRESA_ID"), (HashMap) rowDestino); } } protected Map getRow(Integer puntoVentaId, Integer empresaId, ResultSet rs) throws SQLException { Map row; - if (mapDados.containsKey(puntoVentaId.toString()+"-"+empresaId.toString())) { - row = mapDados.get(puntoVentaId.toString()+"-"+empresaId.toString()); + if (mapDados.containsKey(puntoVentaId.toString() + "-" + empresaId.toString())) { + row = mapDados.get(puntoVentaId.toString() + "-" + empresaId.toString()); } else { @@ -251,7 +251,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { row.put("CVEESTADO", rs.getString("CVEESTADO")); row.put("NUMPUNTOVENTA", rs.getString("NUMPUNTOVENTA")); row.put("EMPRESA", rs.getString("NOMBEMPRESA")); - row.put("EMPRESA_ID", rs.getString("EMPRESA_ID")); + row.put("EMPRESA_ID", rs.getInt("EMPRESA_ID")); row.put("NOMBPUNTOVENTA", rs.getString("NOMBPUNTOVENTA")); row.put("EMPRESAPUNTOVENTA_ID", rs.getInt("EMPRESAPUNTOVENTA_ID")); row.put("ESTADO_ID", rs.getBigDecimal("ESTADO_ID")); @@ -262,7 +262,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { { BigDecimal receitaBagagem = getValorReceitaBagagem(puntoVentaId, empresaId); try { - row.put("IMPOSTOS", getValorImposto(rs.getInt("ORIGEM_ESTADO_ID"), puntoVentaId, rs.getString("INTERESTADUAL"), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, receitaBagagem)); + row.put("IMPOSTOS", getValorImposto(rs.getInt("ORIGEM_ESTADO_ID"), rs.getInt("EMPRESA_ID"), rs.getString("INTERESTADUAL"), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, receitaBagagem)); } catch (Exception e) { // Este erro não é tratado pois existem demais pontos no relatorio que fazem esta chamada com os mesmos parametros e fazer o tratamento correto. @@ -292,13 +292,13 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { Integer idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID"); // Inicializa a row atual - Map row = this.getRow(puntoVentaId,empresaId, this.resultSet); + Map row = this.getRow(puntoVentaId, empresaId, this.resultSet); - this.mapDados.put(row.get("PUNTOVENTA_ID")+"-"+empresaId.toString(), (HashMap) row); + this.mapDados.put(row.get("PUNTOVENTA_ID") + "-" + empresaId.toString(), (HashMap) row); row.put("TOTAL_BILHETES", ((BigDecimal) row.get("TOTAL_BILHETES")).add(motivoCancelacionId == 0 && !tipoVentaId.equals(18) ? BigDecimal.ONE : BigDecimal.ZERO)); row.put("TOTAL_BILHETES_GAP", ((BigDecimal) row.get("TOTAL_BILHETES_GAP")).add(motivoCancelacionId == 0 && tipoVentaId.equals(18) ? BigDecimal.ONE : BigDecimal.ZERO)); - row.put("TOTAL_BILHETES_CANC", ((BigDecimal) row.get("TOTAL_BILHETES_CANC")).add(motivoCancelacionId != 0 ? BigDecimal.ONE : BigDecimal.ZERO)); + row.put("TOTAL_BILHETES_CANC", ((BigDecimal) row.get("TOTAL_BILHETES_CANC")).add(motivoCancelacionId == 31 || motivoCancelacionId == 32 ? BigDecimal.ONE : BigDecimal.ZERO)); if (motivoCancelacionId == 0) { @@ -315,18 +315,41 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { 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("IMPOSTOS", ((BigDecimal) row.get("IMPOSTOS")).add(!tipoVentaId.equals(18) || (tipoVentaId.equals(18) && (Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")) ? getValorImposto(idEstado, puntoVentaId, this.resultSet.getString("INTERESTADUAL"), this.resultSet.getBigDecimal("PRECIOPAGADO"), this.resultSet.getBigDecimal("IMPORTESEGURO"), this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), this.resultSet.getBigDecimal("IMPORTEPEDAGIO"), BigDecimal.ZERO) : BigDecimal.ZERO)); + row.put("IMPOSTOS", ((BigDecimal) row.get("IMPOSTOS")).add(!tipoVentaId.equals(18) || ((tipoVentaId.equals(18) && this.resultSet.getInt("INDREIMPRESION") == 1)) ? getValorImposto(idEstado, empresaId, this.resultSet.getString("INTERESTADUAL"), this.resultSet.getBigDecimal("PRECIOPAGADO"), this.resultSet.getBigDecimal("IMPORTESEGURO"), this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), this.resultSet.getBigDecimal("IMPORTEPEDAGIO"), BigDecimal.ZERO) : 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")))) this.setRowComissao(row); } - else { - // Verificia se a devolução é pra ser contabilizada na agência de destino ou de origem da venda - if (((Integer) this.relatorio.getParametros().get("ISDEVOLUCAODESTINO") == 1) || (((Integer) this.relatorio.getParametros().get("ISDEVOLUCAODESTINO")).equals(0) && this.resultSet.getInt("POSSUI_CANC") == 1)) { - row.put("TOTAL_DEVOL", ((BigDecimal) row.get("TOTAL_DEVOL")).add(!tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); - row.put("TOTAL_DEVOL_GAP", ((BigDecimal) row.get("TOTAL_DEVOL_GAP")).add(tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); - } + //Deduz os cancelamentos e os registros de impressão dao GAP + if (motivoCancelacionId == 31 || motivoCancelacionId == 10 || ((tipoVentaId.equals(18) && this.resultSet.getInt("INDREIMPRESION") == 1)) ) { + + row.put("RECEITA_TARIFA", ((BigDecimal) row.get("RECEITA_TARIFA")).subtract(!tipoVentaId.equals(18) && !tipoVentaId.equals(39) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); + row.put("RECEITA_TARIFA_GAP", ((BigDecimal) row.get("RECEITA_TARIFA_GAP")).subtract((tipoVentaId.equals(18) || tipoVentaId.equals(39)) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); + row.put("RECEITA_SEGURO", ((BigDecimal) row.get("RECEITA_SEGURO")).subtract(!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")).subtract(((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")).subtract(!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")).subtract((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")).subtract(!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")).subtract((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")).subtract(!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")).subtract((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTEPEDAGIO") != null ? this.resultSet.getBigDecimal("IMPORTEPEDAGIO") : BigDecimal.ZERO)); + row.put("RECEITA_EMBARQUE", ((BigDecimal) row.get("RECEITA_EMBARQUE")).subtract(!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")).subtract((tipoVentaId.equals(18) || tipoVentaId.equals(39)) && this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") != null ? this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") : BigDecimal.ZERO)); + row.put("IMPOSTOS", ((BigDecimal) row.get("IMPOSTOS")).subtract(!tipoVentaId.equals(18) || ((tipoVentaId.equals(18) && this.resultSet.getInt("INDREIMPRESION") == 1)) ? getValorImposto(idEstado, empresaId, this.resultSet.getString("INTERESTADUAL"), this.resultSet.getBigDecimal("PRECIOPAGADO"), this.resultSet.getBigDecimal("IMPORTESEGURO"), this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), this.resultSet.getBigDecimal("IMPORTEPEDAGIO"), BigDecimal.ZERO) : BigDecimal.ZERO)); + + + + } + + if (motivoCancelacionId == 32) { + + // Verificia se a devolução é pra ser contabilizada na agência de destino ou de origem da venda + //if (((Integer) this.relatorio.getParametros().get("ISDEVOLUCAODESTINO") == 1) || (((Integer) this.relatorio.getParametros().get("ISDEVOLUCAODESTINO")).equals(0) && this.resultSet.getInt("POSSUI_CANC") == 1)) { + row.put("TOTAL_DEVOL", ((BigDecimal) row.get("TOTAL_DEVOL")).add(!tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO").add(this.resultSet.getBigDecimal("IMPORTESEGURO")).add(this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE")).add(this.resultSet.getBigDecimal("IMPORTEPEDAGIO")).add(this.resultSet.getBigDecimal("IMPORTEOUTROS")) : BigDecimal.ZERO)); + row.put("TOTAL_DEVOL_GAP", ((BigDecimal) row.get("TOTAL_DEVOL_GAP")).add(tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO").add(this.resultSet.getBigDecimal("IMPORTESEGURO")).add(this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE")).add(this.resultSet.getBigDecimal("IMPORTEPEDAGIO")).add(this.resultSet.getBigDecimal("IMPORTEOUTROS")) : BigDecimal.ZERO)); + + //} } } @@ -446,11 +469,11 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { } - public HashMap getConfigImposto(Integer puntoVentaId, Integer estadoId) throws Exception { + public HashMap getConfigImposto(Integer empresaId, Integer estadoId) throws Exception { HashMap cacheConfig = null; try { - cacheConfig = (HashMap) CalculoImposto.getConfigImpostoByEstadoOrigem(this.getConexao(), estadoId, puntoVentaId); + cacheConfig = (HashMap) CalculoImposto.getConfigImpostoByEstadoOrigem(this.getConexao(), estadoId, empresaId); } catch (Exception e) { if (e instanceof ExceptionConfiguracao) this.addInfoMsg(e.getMessage()); @@ -461,7 +484,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { return cacheConfig; } - public BigDecimal getValorImposto(Integer estadoId, Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio, BigDecimal bagagem) throws Exception { + public BigDecimal getValorImposto(Integer estadoId, Integer empresaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio, BigDecimal bagagem) throws Exception { try { Integer tipoBaseCalculo = (Integer) this.getParametros().get("BASE_CALCULO_IMPOSTO"); Boolean indBaseTarifa = (tipoBaseCalculo == 1 || tipoBaseCalculo == 2 ? true : false); @@ -469,7 +492,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { Boolean indBaseEmbarque = (tipoBaseCalculo == 1 || tipoBaseCalculo == 4 ? true : false); Boolean indBasePedagio = (tipoBaseCalculo == 1 || tipoBaseCalculo == 5 ? true : false); Boolean indBaseBagagem = (tipoBaseCalculo == 1 || tipoBaseCalculo == 6 ? true : false); - return CalculoImposto.getValorImpostoRelatorioReceitaDiaria(this.getConexao(), estadoId, puntoVentaId, indInterestadual, tarifa, seguro, embarque, pedagio, bagagem, indBaseTarifa, indBaseSeguro, indBaseEmbarque, indBasePedagio, indBaseBagagem); + return CalculoImposto.getValorImpostoRelatorioReceitaDiaria(this.getConexao(), estadoId, empresaId, indInterestadual, tarifa, seguro, embarque, pedagio, bagagem, indBaseTarifa, indBaseSeguro, indBaseEmbarque, indBasePedagio, indBaseBagagem); } catch (Exception e) { if (e instanceof ExceptionConfiguracao) this.addInfoMsg(e.getMessage()); @@ -569,6 +592,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { sql.append(" CJ.IMPORTETAXAEMBARQUE, "); sql.append(" CJ.IMPORTEOUTROS, "); sql.append(" CJ.IMPORTEPEDAGIO, "); + sql.append(" CJ.INDREIMPRESION, "); sql.append(" CJ.FECCORRIDA, "); sql.append(" (SELECT 1 "); sql.append(" FROM CAJA CJD "); @@ -613,11 +637,11 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { sql.append(" AND PO.CIUDAD_ID = CO.CIUDAD_ID "); sql.append(" AND PD.CIUDAD_ID = CD.CIUDAD_ID "); sql.append(" AND CJ.INDSTATUSOPERACION = 'F' "); - sql.append(" AND CJ.INDREIMPRESION = 0 "); + sql.append(" AND ((CJ.TIPOVENTA_ID <> 18 AND CJ.INDREIMPRESION = 0) OR (CJ.TIPOVENTA_ID = 18)) "); sql.append(" AND PV.TIPOPTOVTA_ID = NVL(:TIPOPTOVTA_ID, PV.TIPOPTOVTA_ID) "); sql.append(" AND TP.TIPOPTOVTA_ID = PV.TIPOPTOVTA_ID "); sql.append(" AND EC.EMPRESA_ID = NVL(:EMPRESA_ID, EC.EMPRESA_ID) "); - // sql.append(" AND ES.ESTADO_ID = NVL(:ESTADO_ID, ES.ESTADO_ID) "); + sql.append(" AND ((INSTR(:NUMPUNTOVENTA, ',' || TRIM(PV.NUMPUNTOVENTA) || ',') > 0 AND "); sql.append(" :ISNUMPUNTOVENTATODOS = 'N') OR (:ISNUMPUNTOVENTATODOS = 'S')) "); sql.append(" AND ((INSTR(:ESTADO_ID, ',' || TRIM(ES.ESTADO_ID) || ',') > 0 AND "); diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioTaxasLinha.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioTaxasLinha.java index 259f3453a..bc0f41b52 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioTaxasLinha.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioTaxasLinha.java @@ -71,31 +71,31 @@ public class RelatorioTaxasLinha extends Relatorio { BigDecimal valorIcms = BigDecimal.ZERO; String indInterestadual = this.resultSet.getString("INTERESTADUAL"); Integer idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID"); - 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(), idEstado, puntoVentaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), BigDecimal.ZERO); + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, this.resultSet.getInt("EMPRESA_ID"), indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), BigDecimal.ZERO); return this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE").subtract(valorIcms); } else if (fieldName.equals("IMPORTEPEDAGIO") && this.resultSet.getBigDecimal("IMPORTEPEDAGIO") != null && !this.resultSet.getBigDecimal("IMPORTEPEDAGIO").equals(BigDecimal.ZERO)) { - valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTEPEDAGIO")); + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, this.resultSet.getInt("EMPRESA_ID"), indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTEPEDAGIO")); return this.resultSet.getBigDecimal("IMPORTEPEDAGIO").subtract(valorIcms); } else if (fieldName.equals("IMPORTESEGURO") && this.resultSet.getBigDecimal("IMPORTESEGURO") != null && !this.resultSet.getBigDecimal("IMPORTESEGURO").equals(BigDecimal.ZERO)) { - valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTESEGURO"), BigDecimal.ZERO, BigDecimal.ZERO); + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, this.resultSet.getInt("EMPRESA_ID"), indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTESEGURO"), BigDecimal.ZERO, BigDecimal.ZERO); return this.resultSet.getBigDecimal("IMPORTESEGURO").subtract(valorIcms); } else if (fieldName.equals("TOTAL_EMBARQUE") && !this.resultSet.getBigDecimal("TOTAL_EMBARQUE").equals(BigDecimal.ZERO)) { - valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_EMBARQUE"), BigDecimal.ZERO, BigDecimal.ZERO); + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, this.resultSet.getInt("EMPRESA_ID"), indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_EMBARQUE"), BigDecimal.ZERO, BigDecimal.ZERO); return this.resultSet.getBigDecimal("TOTAL_EMBARQUE").subtract(valorIcms); } else if (fieldName.equals("TOTAL_PEDAGIO") && !this.resultSet.getBigDecimal("TOTAL_PEDAGIO").equals(BigDecimal.ZERO)) { - valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_PEDAGIO")); + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, this.resultSet.getInt("EMPRESA_ID"), indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_PEDAGIO")); return this.resultSet.getBigDecimal("TOTAL_PEDAGIO").subtract(valorIcms); } else if (fieldName.equals("TOTAL_SEGURO") && !this.resultSet.getBigDecimal("TOTAL_SEGURO").equals(BigDecimal.ZERO)) { - valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_SEGURO"), BigDecimal.ZERO, BigDecimal.ZERO); + valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, this.resultSet.getInt("EMPRESA_ID"), indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_SEGURO"), BigDecimal.ZERO, BigDecimal.ZERO); return this.resultSet.getBigDecimal("TOTAL_SEGURO").subtract(valorIcms); } } catch (Exception e) { @@ -145,6 +145,7 @@ public class RelatorioTaxasLinha extends Relatorio { sql.append(" CJ.IMPORTEPEDAGIO, "); sql.append(" CJ.IMPORTESEGURO, "); sql.append(" EM.NOMBEMPRESA, "); + sql.append(" EM.EMPRESA_ID, "); sql.append(" CJ.PUNTOVENTA_ID, "); sql.append(" PV.NOMBPUNTOVENTA, "); sql.append(" SUM(CASE WHEN CJ.IMPORTETAXAEMBARQUE>0 THEN 1 ELSE 0 END) EMBARQUE_VENDIDOS, "); @@ -171,9 +172,7 @@ public class RelatorioTaxasLinha extends Relatorio { sql.append(" CIUDAD CD, "); sql.append(" EMPRESA EM "); sql.append(" WHERE CR.RUTA_ID = RT.RUTA_ID "); - sql.append(" AND (CJ.IMPORTETAXAEMBARQUE>0 OR CJ.IMPORTEPEDAGIO>0 OR CJ.IMPORTESEGURO>0) "); - 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 "); @@ -205,6 +204,7 @@ public class RelatorioTaxasLinha extends Relatorio { sql.append(" CO.ESTADO_ID, "); sql.append(" CD.ESTADO_ID, "); sql.append(" EM.NOMBEMPRESA, "); + sql.append(" EM.EMPRESA_ID, "); sql.append(" CJ.PUNTOVENTA_ID, "); sql.append(" PV.NOMBPUNTOVENTA "); sql.append(" ORDER BY EM.NOMBEMPRESA, PO.DESCPARADA "); diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/negocio/CalculoImposto.java b/src/java/com/rjconsultores/ventaboletos/relatorios/negocio/CalculoImposto.java index 58700e66d..459342189 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/negocio/CalculoImposto.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/negocio/CalculoImposto.java @@ -21,7 +21,7 @@ public class CalculoImposto { static Map> mapCacheConfigImposto = new HashMap>(); - public static BigDecimal getValorImpostoRelatorioReceitaDiaria(Connection conexao, Integer estadoId, Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio, BigDecimal bagagem, Boolean indBaseTarifa, Boolean indBaseSeguro, Boolean indBaseEmbarque, Boolean indBasePedagio, Boolean indBaseBagagem) throws Exception { + public static BigDecimal getValorImpostoRelatorioReceitaDiaria(Connection conexao, Integer estadoId, Integer empresaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio, BigDecimal bagagem, Boolean indBaseTarifa, Boolean indBaseSeguro, Boolean indBaseEmbarque, Boolean indBasePedagio, Boolean indBaseBagagem) throws Exception { HashMap configImposto = new HashMap(); BigDecimal baseCalculo = BigDecimal.ZERO; @@ -33,7 +33,7 @@ public class CalculoImposto { // configImposto = (HashMap) getConfigImpostoByPuntoVenta(conexao, puntoVentaId); - configImposto = (HashMap) getConfigImpostoByEstadoOrigem(conexao, estadoId, puntoVentaId); + configImposto = (HashMap) getConfigImpostoByEstadoOrigem(conexao, estadoId, empresaId); if (configImposto == null) return BigDecimal.ZERO; @@ -68,7 +68,7 @@ public class CalculoImposto { return valorIcms; } - public static Map getConfigImpostoByEstadoOrigem(Connection conexao, Integer idEstado, Integer puntoVentaId) throws SQLException, ExceptionConfiguracao { + public static Map getConfigImpostoByEstadoOrigem(Connection conexao, Integer idEstado, Integer empresaId) throws SQLException, ExceptionConfiguracao { HashMap cacheConfig = null; @@ -88,7 +88,7 @@ public class CalculoImposto { sql.append(" LEFT JOIN CIUDAD CD "); sql.append(" ON ( CD.ESTADO_ID = EI.ESTADO_ID ) "); sql.append(" WHERE ES.ESTADO_ID = :ORIGEM_ESTADO_ID "); - sql.append(" AND EI.EMPRESA_ID = 25 "); + sql.append(" AND EI.EMPRESA_ID = :EMPRESA_ID "); sql.append(" AND PV.PARADA_ID = PR.PARADA_ID "); sql.append(" AND PR.CIUDAD_ID = CD.CIUDAD_ID "); sql.append(" AND PV.EMPRESA_ID = NVL(EI.EMPRESA_ID, PV.EMPRESA_ID) "); @@ -98,7 +98,7 @@ public class CalculoImposto { NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql.toString()); stmt.setInt("ORIGEM_ESTADO_ID", idEstado); - + stmt.setInt("EMPRESA_ID", empresaId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { @@ -165,7 +165,7 @@ public class CalculoImposto { } - public static BigDecimal getValorImposto(Connection conexao, Integer idEstado, Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio) throws Exception { + public static BigDecimal getValorImposto(Connection conexao, Integer idEstado, Integer empresaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio) throws Exception { HashMap configImposto = new HashMap(); BigDecimal baseCalculo = BigDecimal.ZERO; @@ -185,7 +185,7 @@ public class CalculoImposto { Boolean indTxEmbarqueEstadual; Boolean indPedagioEstadual; - configImposto = (HashMap) getConfigImpostoByEstadoOrigem(conexao, idEstado, puntoVentaId); + configImposto = (HashMap) getConfigImpostoByEstadoOrigem(conexao, idEstado, empresaId); if (configImposto == null) return BigDecimal.ZERO; diff --git a/src/java/versionADM.info b/src/java/versionADM.info index 583add0a7..5dae6e56c 100644 --- a/src/java/versionADM.info +++ b/src/java/versionADM.info @@ -1 +1 @@ -ADM_20130913_1RC234 +ADM_20130916_1RC235