fixes bug #7488
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@56157 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
c332489d6e
commit
6e363b1fa8
|
@ -7,14 +7,19 @@ import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
|
||||||
|
|
||||||
import com.rjconsultores.ventaboletos.relatorios.negocio.CalculoImposto;
|
import com.rjconsultores.ventaboletos.relatorios.negocio.CalculoImposto;
|
||||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource;
|
import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource;
|
||||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.ExceptionConfiguracao;
|
import com.rjconsultores.ventaboletos.relatorios.utilitarios.ExceptionConfiguracao;
|
||||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
||||||
|
import com.rjconsultores.ventaboletos.relatorios.utilitarios.RelatorioTaxasLinhaBean;
|
||||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||||
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||||
|
|
||||||
|
@ -24,6 +29,8 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||||
*/
|
*/
|
||||||
public class RelatorioTaxasLinha extends Relatorio {
|
public class RelatorioTaxasLinha extends Relatorio {
|
||||||
|
|
||||||
|
private List<RelatorioTaxasLinhaBean> lsDadosRelatorio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parametros
|
* @param parametros
|
||||||
* @param conexao
|
* @param conexao
|
||||||
|
@ -34,15 +41,19 @@ public class RelatorioTaxasLinha extends Relatorio {
|
||||||
CalculoImposto.limpaCache();
|
CalculoImposto.limpaCache();
|
||||||
|
|
||||||
this.setCustomDataSource(false, new DataSource(this) {
|
this.setCustomDataSource(false, new DataSource(this) {
|
||||||
|
@Override
|
||||||
public void initDados() throws Exception {
|
public void initDados() throws Exception {
|
||||||
Connection conexao = this.relatorio.getConexao();
|
Connection conexao = this.relatorio.getConexao();
|
||||||
Map<String, Object> parametros = this.relatorio.getParametros();
|
Map<String, Object> parametros = this.relatorio.getParametros();
|
||||||
String puntosVentaIds = (String) parametros.get("NUMPUNTOVENTA");
|
String puntosVentaIds = (String) parametros.get("NUMPUNTOVENTA");
|
||||||
|
|
||||||
|
lsDadosRelatorio = new ArrayList<RelatorioTaxasLinhaBean>();
|
||||||
|
|
||||||
String sql = getSql(puntosVentaIds);
|
String sql = getSql(puntosVentaIds);
|
||||||
|
|
||||||
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
|
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
|
||||||
|
|
||||||
|
ResultSet rset1 = null;
|
||||||
|
|
||||||
stmt.setInt("TIPO_DATA", (Integer) parametros.get("TIPO_DATA"));
|
stmt.setInt("TIPO_DATA", (Integer) parametros.get("TIPO_DATA"));
|
||||||
stmt.setTimestamp("DATA_INICIAL", new Timestamp(DateUtil.inicioFecha((Date) parametros.get("DATA_INICIAL")).getTime()));
|
stmt.setTimestamp("DATA_INICIAL", new Timestamp(DateUtil.inicioFecha((Date) parametros.get("DATA_INICIAL")).getTime()));
|
||||||
|
@ -63,68 +74,101 @@ public class RelatorioTaxasLinha extends Relatorio {
|
||||||
else
|
else
|
||||||
stmt.setNull("DESTINO_ID", java.sql.Types.INTEGER);
|
stmt.setNull("DESTINO_ID", java.sql.Types.INTEGER);
|
||||||
|
|
||||||
ResultSet rset = stmt.executeQuery();
|
rset1 = stmt.executeQuery();
|
||||||
|
|
||||||
this.resultSet = rset;
|
|
||||||
|
while (rset1.next()) {
|
||||||
|
// Se não for pra subtrair o ICMS, realiza o calculo e adiciona o mesmo
|
||||||
|
BigDecimal valorIcms = BigDecimal.ZERO;
|
||||||
|
String indInterestadual = rset1.getString("INTERESTADUAL");
|
||||||
|
Integer idEstado = rset1.getInt("ORIGEM_ESTADO_ID");
|
||||||
|
Integer empresaId = rset1.getInt("EMPRESA_ID");
|
||||||
|
|
||||||
|
BigDecimal importeTaxaEmbarque = rset1.getBigDecimal("IMPORTETAXAEMBARQUE") == null ? BigDecimal.ZERO : rset1.getBigDecimal("IMPORTETAXAEMBARQUE");
|
||||||
|
BigDecimal importePedagio = rset1.getBigDecimal("IMPORTEPEDAGIO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("IMPORTEPEDAGIO");
|
||||||
|
BigDecimal importeSeguro = rset1.getBigDecimal("IMPORTESEGURO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("IMPORTESEGURO");
|
||||||
|
|
||||||
}
|
BigDecimal totalEmbarque = rset1.getBigDecimal("TOTAL_EMBARQUE") == null ? BigDecimal.ZERO : rset1.getBigDecimal("TOTAL_EMBARQUE");
|
||||||
|
BigDecimal totalPedagio = rset1.getBigDecimal("TOTAL_PEDAGIO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("TOTAL_PEDAGIO");
|
||||||
public Object valueCustomFields(String fieldName) throws Exception {
|
BigDecimal totalSeguro = rset1.getBigDecimal("TOTAL_SEGURO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("TOTAL_SEGURO");
|
||||||
|
|
||||||
// Se não for pra subtrair o ICMS, realiza o calculo e adiciona o mesmo
|
String prefixo = rset1.getString("PREFIXO") == null ? "" : rset1.getString("PREFIXO");
|
||||||
if ((Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")) {
|
String cidadeOrigem = rset1.getString("CIDADE_ORIGEM") == null ? "" : rset1.getString("CIDADE_ORIGEM");
|
||||||
BigDecimal valorIcms = BigDecimal.ZERO;
|
String cidadeDestino= rset1.getString("CIDADE_DESTINO") == null ? "" : rset1.getString("CIDADE_DESTINO");
|
||||||
String indInterestadual = this.resultSet.getString("INTERESTADUAL");
|
|
||||||
Integer idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID");
|
String nombEmpresa = rset1.getString("NOMBEMPRESA") == null ? "" : rset1.getString("NOMBEMPRESA");
|
||||||
Integer empresaId = this.resultSet.getInt("EMPRESA_ID");
|
String nombPuntoVenta = rset1.getString("NOMBPUNTOVENTA") == null ? "" : rset1.getString("NOMBPUNTOVENTA");
|
||||||
|
BigDecimal embarque_vendidos = rset1.getBigDecimal("EMBARQUE_VENDIDOS") == null ? BigDecimal.ZERO : rset1.getBigDecimal("EMBARQUE_VENDIDOS");
|
||||||
try {
|
BigDecimal pedagio_vendidos = rset1.getBigDecimal("PEDAGIO_VENDIDOS") == null ? BigDecimal.ZERO : rset1.getBigDecimal("PEDAGIO_VENDIDOS");
|
||||||
BigDecimal importeTaxaEmbarque = resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTETAXAEMBARQUE");
|
BigDecimal seguro_vendidos = rset1.getBigDecimal("SEGURO_VENDIDOS") == null ? BigDecimal.ZERO : rset1.getBigDecimal("SEGURO_VENDIDOS");
|
||||||
BigDecimal importePedagio = resultSet.getBigDecimal("IMPORTEPEDAGIO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTEPEDAGIO");
|
|
||||||
BigDecimal importeSeguro = resultSet.getBigDecimal("IMPORTESEGURO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTESEGURO");
|
|
||||||
|
RelatorioTaxasLinhaBean taxasLinha = new RelatorioTaxasLinhaBean();
|
||||||
BigDecimal totalEmbarque = resultSet.getBigDecimal("TOTAL_EMBARQUE") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("TOTAL_EMBARQUE");
|
|
||||||
BigDecimal totalPedagio = resultSet.getBigDecimal("TOTAL_PEDAGIO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("TOTAL_PEDAGIO");
|
if(!importeTaxaEmbarque.equals(BigDecimal.ZERO) && (Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")){
|
||||||
BigDecimal totalSeguro = resultSet.getBigDecimal("TOTAL_SEGURO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("TOTAL_SEGURO");
|
|
||||||
|
|
||||||
if (fieldName.equals("IMPORTETAXAEMBARQUE") && !!importeTaxaEmbarque.equals(BigDecimal.ZERO)) {
|
|
||||||
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, importeTaxaEmbarque, BigDecimal.ZERO);
|
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, importeTaxaEmbarque, BigDecimal.ZERO);
|
||||||
return importeTaxaEmbarque.subtract(valorIcms);
|
importeTaxaEmbarque = importeTaxaEmbarque.subtract(valorIcms);
|
||||||
|
|
||||||
} else if (fieldName.equals("IMPORTEPEDAGIO") && !importePedagio.equals(BigDecimal.ZERO)) {
|
|
||||||
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, importePedagio);
|
|
||||||
return importePedagio.subtract(valorIcms);
|
|
||||||
|
|
||||||
} else if (fieldName.equals("IMPORTESEGURO") && !importeSeguro.equals(BigDecimal.ZERO)) {
|
|
||||||
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, importeSeguro, BigDecimal.ZERO, BigDecimal.ZERO);
|
|
||||||
return importeSeguro.subtract(valorIcms);
|
|
||||||
|
|
||||||
} else if (fieldName.equals("TOTAL_EMBARQUE") && !totalEmbarque.equals(BigDecimal.ZERO)) {
|
|
||||||
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, totalEmbarque, BigDecimal.ZERO, BigDecimal.ZERO);
|
|
||||||
return totalEmbarque.subtract(valorIcms);
|
|
||||||
|
|
||||||
} else if (fieldName.equals("TOTAL_PEDAGIO") && !totalPedagio.equals(BigDecimal.ZERO)) {
|
|
||||||
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, totalPedagio);
|
|
||||||
return totalPedagio.subtract(valorIcms);
|
|
||||||
|
|
||||||
} else if (fieldName.equals("TOTAL_SEGURO") && !totalSeguro.equals(BigDecimal.ZERO)) {
|
|
||||||
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, totalSeguro, BigDecimal.ZERO, BigDecimal.ZERO);
|
|
||||||
return totalSeguro.subtract(valorIcms);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
taxasLinha.setIMPORTETAXAEMBARQUE(importeTaxaEmbarque);
|
||||||
if (e instanceof ExceptionConfiguracao)
|
|
||||||
this.relatorio.addInfoMsg(e.getMessage());
|
if(!importePedagio.equals(BigDecimal.ZERO) && (Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")){
|
||||||
else
|
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, importePedagio);
|
||||||
throw e;
|
importePedagio = importePedagio.subtract(valorIcms);
|
||||||
|
}
|
||||||
|
taxasLinha.setIMPORTEPEDAGIO(importePedagio);
|
||||||
|
|
||||||
|
if(!importeSeguro.equals(BigDecimal.ZERO) && (Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")){
|
||||||
|
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, importeSeguro, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||||
|
importeSeguro = importeSeguro.subtract(valorIcms);
|
||||||
|
}
|
||||||
|
taxasLinha.setIMPORTESEGURO(importeSeguro);
|
||||||
|
|
||||||
|
if(!totalEmbarque.equals(BigDecimal.ZERO) && (Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")){
|
||||||
|
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, totalEmbarque, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||||
|
totalEmbarque = totalEmbarque.subtract(valorIcms);
|
||||||
|
}
|
||||||
|
taxasLinha.setTOTAL_EMBARQUE(totalEmbarque);
|
||||||
|
|
||||||
|
if(!totalPedagio.equals(BigDecimal.ZERO) && (Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")){
|
||||||
|
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, totalPedagio);
|
||||||
|
totalPedagio = totalPedagio.subtract(valorIcms);
|
||||||
|
}
|
||||||
|
taxasLinha.setTOTAL_PEDAGIO(totalPedagio);
|
||||||
|
|
||||||
|
if(!totalSeguro.equals(BigDecimal.ZERO) && (Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")){
|
||||||
|
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, totalSeguro, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||||
|
totalSeguro = totalSeguro.subtract(valorIcms);
|
||||||
|
}
|
||||||
|
taxasLinha.setTOTAL_SEGURO(totalSeguro);
|
||||||
|
|
||||||
|
taxasLinha.setPREFIXO(prefixo);
|
||||||
|
taxasLinha.setCIDADE_ORIGEM(cidadeOrigem);
|
||||||
|
taxasLinha.setCIDADE_DESTINO(cidadeDestino);
|
||||||
|
|
||||||
|
taxasLinha.setNOMBEMPRESA(nombEmpresa);
|
||||||
|
taxasLinha.setNOMBPUNTOVENTA(nombPuntoVenta);
|
||||||
|
|
||||||
|
taxasLinha.setEMBARQUE_VENDIDOS(embarque_vendidos);
|
||||||
|
taxasLinha.setPEDAGIO_VENDIDOS(pedagio_vendidos);
|
||||||
|
taxasLinha.setSEGURO_VENDIDOS(seguro_vendidos);
|
||||||
|
|
||||||
|
lsDadosRelatorio.add(taxasLinha);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (lsDadosRelatorio.size() > 0) {
|
||||||
|
|
||||||
return null;
|
setLsDadosRelatorio(lsDadosRelatorio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLsDadosRelatorio(List<RelatorioTaxasLinhaBean> lsDadosRelatorio) {
|
||||||
|
this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio));
|
||||||
|
this.lsDadosRelatorio = lsDadosRelatorio;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
@ -224,4 +268,4 @@ public class RelatorioTaxasLinha extends Relatorio {
|
||||||
|
|
||||||
return sql.toString();
|
return sql.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue