Relatorio Receita diarias correção no calculo do ICMS

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@30527 d1611594-4594-4d17-8e1d-87c2c4800839
master
julio 2013-09-03 15:53:29 +00:00
parent 77d7142dd4
commit 19d045232b
4 changed files with 49 additions and 191 deletions

View File

@ -121,7 +121,9 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
BigDecimal motivoCancelacionId = this.resultSet.getBigDecimal("MOTIVOCANCELACION_ID");
Integer tipoVentaId = this.resultSet.getInt("TIPOVENTA_ID");
HashMap<String, Object> configImposto = getConfigImposto(puntoVentaId);
Integer estadoId = this.resultSet.getInt("ORIGEM_ESTADO_ID");
HashMap<String, Object> configImposto = getConfigImposto(puntoVentaId, estadoId);
if (configImposto == null) {
return;
}
@ -142,7 +144,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
if ((Boolean) configComissao.get("PEDAGIORECEITA"))
baseCalculo = baseCalculo.add(this.resultSet.getBigDecimal("IMPORTEPEDAGIO"));
System.out.println("configComissao "+configComissao);
System.out.println("configComissao " + configComissao);
// Caso esteje setado na configuração de comissão que o calculo deve ser sobre o liquido, deduz o imposto.
if (configComissao.get("RECEITA") != null && ((String) configComissao.get("RECEITA")).equals("RL") &&
(!tipoVentaId.equals(18) || (tipoVentaId.equals(18) && (Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP"))))
@ -173,7 +175,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
percComissao = isAltaTemporada ? (BigDecimal) configComissao.get("PASSAGEMALTA") : (BigDecimal) configComissao.get("PASSAGEMBAIXA");
if(percComissao==null)
if (percComissao == null)
return;
// VALOR COMISSAO = BASE DE CALCULO * (PERCENTUAL COMISSAO / 100)
valorComissao = baseCalculo.multiply(percComissao.divide(BigDecimal.valueOf(100)));
@ -215,7 +217,6 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
}
else
{
row = new HashMap<String, Object>();
row.put("TOTAL_BILHETES", BigDecimal.ZERO);
row.put("TOTAL_BILHETES_CANC", BigDecimal.ZERO);
@ -252,7 +253,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
{
BigDecimal receitaBagagem = getValorReceitaBagagem(puntoVentaId);
try {
row.put("IMPOSTOS", getValorImposto(puntoVentaId, rs.getString("INTERESTADUAL"), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, receitaBagagem));
row.put("IMPOSTOS", getValorImposto(rs.getInt("ORIGEM_ESTADO_ID"), puntoVentaId, 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.
@ -278,9 +279,11 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
Integer puntoVentaId = this.resultSet.getInt("PUNTOVENTA_ID");
Integer motivoCancelacionId = this.resultSet.getInt("MOTIVOCANCELACION_ID");
Integer tipoVentaId = this.resultSet.getInt("TIPOVENTA_ID");
Integer idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID");
// Inicializa a row atual
Map<String, Object> row = this.getRow(puntoVentaId, this.resultSet);
this.mapDados.put((Integer) row.get("PUNTOVENTA_ID"), (HashMap<String, Object>) row);
row.put("TOTAL_BILHETES", ((BigDecimal) row.get("TOTAL_BILHETES")).add(motivoCancelacionId == null && !tipoVentaId.equals(18) ? BigDecimal.ONE : BigDecimal.ZERO));
@ -302,14 +305,14 @@ 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(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) && (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));
// 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)) {
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((motivoCancelacionId.equals(31) || motivoCancelacionId.equals(32)) && !tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO));
row.put("TOTAL_DEVOL_GAP", ((BigDecimal) row.get("TOTAL_DEVOL_GAP")).add((motivoCancelacionId.equals(31) || motivoCancelacionId.equals(32)) && tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO));
@ -433,11 +436,11 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
}
public HashMap<String, Object> getConfigImposto(Integer puntoVentaId) throws Exception {
public HashMap<String, Object> getConfigImposto(Integer puntoVentaId, Integer estadoId) throws Exception {
HashMap<String, Object> cacheConfig = null;
try {
cacheConfig = (HashMap<String, Object>) CalculoImposto.getConfigImpostoByPuntoVenta(this.getConexao(), puntoVentaId);
cacheConfig = (HashMap<String, Object>) CalculoImposto.getConfigImpostoByEstadoOrigem(this.getConexao(), estadoId, puntoVentaId);
} catch (Exception e) {
if (e instanceof ExceptionConfiguracao)
this.addInfoMsg(e.getMessage());
@ -448,7 +451,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
return cacheConfig;
}
public BigDecimal getValorImposto(Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio, BigDecimal bagagem) throws Exception {
public BigDecimal getValorImposto(Integer estadoId, Integer puntoVentaId, 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);
@ -456,7 +459,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(), puntoVentaId, indInterestadual, tarifa, seguro, embarque, pedagio, bagagem, indBaseTarifa, indBaseSeguro, indBaseEmbarque, indBasePedagio, indBaseBagagem);
return CalculoImposto.getValorImpostoRelatorioReceitaDiaria(this.getConexao(), estadoId, puntoVentaId, indInterestadual, tarifa, seguro, embarque, pedagio, bagagem, indBaseTarifa, indBaseSeguro, indBaseEmbarque, indBasePedagio, indBaseBagagem);
} catch (Exception e) {
if (e instanceof ExceptionConfiguracao)
this.addInfoMsg(e.getMessage());
@ -545,6 +548,8 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
sql.append(" ELSE ");
sql.append(" 'N' ");
sql.append(" END INTERESTADUAL, ");
sql.append(" CO.ESTADO_ID ORIGEM_ESTADO_ID, ");
sql.append(" CD.ESTADO_ID DESTINO_ESTADO_ID, ");
sql.append(" CJ.PRECIOPAGADO, ");
sql.append(" CJ.MOTIVOCANCELACION_ID, ");
sql.append(" CJ.TIPOVENTA_ID, ");

View File

@ -71,30 +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.getValorImpostoByEstadoOrigem(this.relatorio.getConexao(), idEstado, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), BigDecimal.ZERO);
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, 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.getValorImpostoByEstadoOrigem(this.relatorio.getConexao(), idEstado, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTEPEDAGIO"));
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, 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.getValorImpostoByEstadoOrigem(this.relatorio.getConexao(), idEstado, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTESEGURO"), BigDecimal.ZERO, BigDecimal.ZERO);
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, 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.getValorImpostoByEstadoOrigem(this.relatorio.getConexao(), idEstado, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_EMBARQUE"), BigDecimal.ZERO, BigDecimal.ZERO);
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, 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.getValorImpostoByEstadoOrigem(this.relatorio.getConexao(), idEstado, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_PEDAGIO"));
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, 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.getValorImpostoByEstadoOrigem(this.relatorio.getConexao(), idEstado, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_SEGURO"), BigDecimal.ZERO, BigDecimal.ZERO);
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, puntoVentaId, indInterestadual, BigDecimal.ZERO, this.resultSet.getBigDecimal("TOTAL_SEGURO"), BigDecimal.ZERO, BigDecimal.ZERO);
return this.resultSet.getBigDecimal("TOTAL_SEGURO").subtract(valorIcms);
}
} catch (Exception e) {
@ -119,11 +120,11 @@ public class RelatorioTaxasLinha extends Relatorio {
protected void processaParametros() throws Exception {
}
public HashMap<String, Object> getConfigImposto(Integer idEstado) throws Exception {
public HashMap<String, Object> getConfigImposto(Integer idEstado, Integer puntoVentaId) throws Exception {
HashMap<String, Object> cacheConfig = null;
try {
cacheConfig = (HashMap<String, Object>) CalculoImposto.getConfigImpostoByEstadoOrigem(this.getConexao(), idEstado);
cacheConfig = (HashMap<String, Object>) CalculoImposto.getConfigImpostoByEstadoOrigem(this.getConexao(), idEstado, puntoVentaId);
} catch (Exception e) {
if (e instanceof ExceptionConfiguracao)
this.addInfoMsg(e.getMessage());

View File

@ -21,93 +21,7 @@ public class CalculoImposto {
static Map<String, HashMap<String, Object>> mapCacheConfigImposto = new HashMap<String, HashMap<String, Object>>();
public static Map<String, Object> getConfigImpostoByPuntoVenta(Connection conexao, Integer puntoVentaId) throws SQLException, ExceptionConfiguracao {
HashMap<String, Object> 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<String, Object>();
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 (!isBuscouConfig)
throw new ExceptionConfiguracao("Não foi possivel obter a configuração de imposto para o estado: " + estado + " empresa: " + empresa);
}
;
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 agência " + puntoVentaId);
mapCacheConfigImposto.put(puntoVentaId.toString(), cacheConfig);
} else
cacheConfig = mapCacheConfigImposto.get(puntoVentaId.toString());
return cacheConfig;
}
public static BigDecimal getValorImpostoRelatorioReceitaDiaria(Connection conexao, 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 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 {
HashMap<String, Object> configImposto = new HashMap<String, Object>();
BigDecimal baseCalculo = BigDecimal.ZERO;
@ -117,7 +31,9 @@ public class CalculoImposto {
BigDecimal valorIcms = BigDecimal.ZERO;
configImposto = (HashMap<String, Object>) getConfigImpostoByPuntoVenta(conexao, puntoVentaId);
// configImposto = (HashMap<String, Object>) getConfigImpostoByPuntoVenta(conexao, puntoVentaId);
configImposto = (HashMap<String, Object>) getConfigImpostoByEstadoOrigem(conexao, estadoId, puntoVentaId);
if (configImposto == null)
return BigDecimal.ZERO;
@ -152,77 +68,7 @@ public class CalculoImposto {
return valorIcms;
}
public static BigDecimal getValorImposto(Connection conexao, Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio) throws Exception {
HashMap<String, Object> configImposto = new HashMap<String, Object>();
BigDecimal baseCalculo = BigDecimal.ZERO;
BigDecimal icms;
BigDecimal porcRedEstadualMunicipal;
BigDecimal porcRedBaseIcms;
BigDecimal valorIcms = BigDecimal.ZERO;
Boolean indTarifaMunicipal;
Boolean indSeguroMunicipal;
Boolean indTxEmbarqueMunicipal;
Boolean indPedagioMunicipal;
Boolean indTarifaEstadual;
Boolean indSeguroEstadual;
Boolean indTxEmbarqueEstadual;
Boolean indPedagioEstadual;
configImposto = (HashMap<String, Object>) getConfigImpostoByPuntoVenta(conexao, puntoVentaId);
if (configImposto == null)
return BigDecimal.ZERO;
icms = (BigDecimal) configImposto.get("ICMS");
porcRedBaseIcms = (BigDecimal) configImposto.get("PORCREDBASEICMS");
if (indInterestadual.equals("S")) {
porcRedEstadualMunicipal = (BigDecimal) configImposto.get("PORCREDESTADUAL");
indTarifaEstadual = (Boolean) configImposto.get("INDTARIFAESTADUAL");
indSeguroEstadual = (Boolean) configImposto.get("INDSEGUROESTADUAL");
indTxEmbarqueEstadual = (Boolean) configImposto.get("INDTXEMBARQUEESTADUAL");
indPedagioEstadual = (Boolean) configImposto.get("INDPEDAGIOESTDUAL");
// Criação da base de calculo
baseCalculo = indTarifaEstadual && tarifa != null ? baseCalculo.add(tarifa) : baseCalculo;
baseCalculo = indSeguroEstadual && seguro != null ? baseCalculo.add(seguro) : baseCalculo;
baseCalculo = indTxEmbarqueEstadual && embarque != null ? baseCalculo.add(embarque) : baseCalculo;
baseCalculo = indPedagioEstadual && pedagio != null ? baseCalculo.add(pedagio) : baseCalculo;
} else {
porcRedEstadualMunicipal = (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) : baseCalculo;
baseCalculo = indSeguroMunicipal && seguro != null ? baseCalculo.add(seguro) : baseCalculo;
baseCalculo = indTxEmbarqueMunicipal && embarque != null ? baseCalculo.add(embarque) : baseCalculo;
baseCalculo = indPedagioMunicipal && pedagio != null ? baseCalculo.add(pedagio) : baseCalculo;
}
// 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 (porcRedEstadualMunicipal != null && porcRedEstadualMunicipal.equals(BigDecimal.ZERO))
valorIcms = valorIcms.subtract(porcRedEstadualMunicipal.divide(BigDecimal.valueOf(100)).multiply(valorIcms));
return valorIcms;
}
public static Map<String, Object> getConfigImpostoByEstadoOrigem(Connection conexao, Integer idEstado) throws SQLException, ExceptionConfiguracao {
public static Map<String, Object> getConfigImpostoByEstadoOrigem(Connection conexao, Integer idEstado, Integer puntoVentaId) throws SQLException, ExceptionConfiguracao {
HashMap<String, Object> cacheConfig = null;
@ -232,16 +78,22 @@ public class CalculoImposto {
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("FROM PUNTO_VENTA PV, ");
sql.append(" PARADA PR, ");
sql.append(" ESTADO ES, ");
sql.append(" EMPRESA_IMPOSTO EI ");
sql.append(" INNER JOIN EMPRESA EM ");
sql.append(" ON ( EM.EMPRESA_ID = EI.EMPRESA_ID ) ");
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 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 PV.EMPRESA_ID = EI.EMPRESA_ID ");
sql.append(" AND NVL(EI.ACTIVO, 1) = 1 ");
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql.toString());
@ -308,7 +160,7 @@ public class CalculoImposto {
}
public static BigDecimal getValorImpostoByEstadoOrigem(Connection conexao, Integer idEstado, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio) throws Exception {
public static BigDecimal getValorImposto(Connection conexao, Integer idEstado, Integer puntoVentaId, String indInterestadual, BigDecimal tarifa, BigDecimal seguro, BigDecimal embarque, BigDecimal pedagio) throws Exception {
HashMap<String, Object> configImposto = new HashMap<String, Object>();
BigDecimal baseCalculo = BigDecimal.ZERO;
@ -328,7 +180,7 @@ public class CalculoImposto {
Boolean indTxEmbarqueEstadual;
Boolean indPedagioEstadual;
configImposto = (HashMap<String, Object>) getConfigImpostoByEstadoOrigem(conexao, idEstado);
configImposto = (HashMap<String, Object>) getConfigImpostoByEstadoOrigem(conexao, idEstado, puntoVentaId);
if (configImposto == null)
return BigDecimal.ZERO;

View File

@ -7,7 +7,7 @@
<zk xmlns="http://www.zkoss.org/2005/zul">
<window id="winFiltroRelatorioReceitaDiariaAgencia"
apply="${relatorioReceitaDiariaAgenciaController}"
contentStyle="overflow:auto" height="370px" width="550px"
contentStyle="overflow:auto" height="324px" width="550px"
border="normal">
<grid fixedLayout="true">
<columns>