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.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
|
||||
|
||||
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.relatorios.utilitarios.RelatorioTaxasLinhaBean;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||
|
||||
|
@ -24,6 +29,8 @@ import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
|||
*/
|
||||
public class RelatorioTaxasLinha extends Relatorio {
|
||||
|
||||
private List<RelatorioTaxasLinhaBean> lsDadosRelatorio;
|
||||
|
||||
/**
|
||||
* @param parametros
|
||||
* @param conexao
|
||||
|
@ -34,16 +41,20 @@ public class RelatorioTaxasLinha extends Relatorio {
|
|||
CalculoImposto.limpaCache();
|
||||
|
||||
this.setCustomDataSource(false, new DataSource(this) {
|
||||
|
||||
@Override
|
||||
public void initDados() throws Exception {
|
||||
Connection conexao = this.relatorio.getConexao();
|
||||
Map<String, Object> parametros = this.relatorio.getParametros();
|
||||
String puntosVentaIds = (String) parametros.get("NUMPUNTOVENTA");
|
||||
|
||||
lsDadosRelatorio = new ArrayList<RelatorioTaxasLinhaBean>();
|
||||
|
||||
String sql = getSql(puntosVentaIds);
|
||||
|
||||
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
|
||||
|
||||
ResultSet rset1 = null;
|
||||
|
||||
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_FINAL", new Timestamp(DateUtil.fimFecha((Date) parametros.get("DATA_FINAL")).getTime()));
|
||||
|
@ -63,68 +74,101 @@ public class RelatorioTaxasLinha extends Relatorio {
|
|||
else
|
||||
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");
|
||||
|
||||
public Object valueCustomFields(String fieldName) throws Exception {
|
||||
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");
|
||||
|
||||
// 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 idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID");
|
||||
Integer empresaId = this.resultSet.getInt("EMPRESA_ID");
|
||||
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");
|
||||
BigDecimal totalSeguro = rset1.getBigDecimal("TOTAL_SEGURO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("TOTAL_SEGURO");
|
||||
|
||||
try {
|
||||
BigDecimal importeTaxaEmbarque = resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTETAXAEMBARQUE");
|
||||
BigDecimal importePedagio = resultSet.getBigDecimal("IMPORTEPEDAGIO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTEPEDAGIO");
|
||||
BigDecimal importeSeguro = resultSet.getBigDecimal("IMPORTESEGURO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTESEGURO");
|
||||
String prefixo = rset1.getString("PREFIXO") == null ? "" : rset1.getString("PREFIXO");
|
||||
String cidadeOrigem = rset1.getString("CIDADE_ORIGEM") == null ? "" : rset1.getString("CIDADE_ORIGEM");
|
||||
String cidadeDestino= rset1.getString("CIDADE_DESTINO") == null ? "" : rset1.getString("CIDADE_DESTINO");
|
||||
|
||||
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");
|
||||
BigDecimal totalSeguro = resultSet.getBigDecimal("TOTAL_SEGURO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("TOTAL_SEGURO");
|
||||
String nombEmpresa = rset1.getString("NOMBEMPRESA") == null ? "" : rset1.getString("NOMBEMPRESA");
|
||||
String nombPuntoVenta = rset1.getString("NOMBPUNTOVENTA") == null ? "" : rset1.getString("NOMBPUNTOVENTA");
|
||||
BigDecimal embarque_vendidos = rset1.getBigDecimal("EMBARQUE_VENDIDOS") == null ? BigDecimal.ZERO : rset1.getBigDecimal("EMBARQUE_VENDIDOS");
|
||||
BigDecimal pedagio_vendidos = rset1.getBigDecimal("PEDAGIO_VENDIDOS") == null ? BigDecimal.ZERO : rset1.getBigDecimal("PEDAGIO_VENDIDOS");
|
||||
BigDecimal seguro_vendidos = rset1.getBigDecimal("SEGURO_VENDIDOS") == null ? BigDecimal.ZERO : rset1.getBigDecimal("SEGURO_VENDIDOS");
|
||||
|
||||
if (fieldName.equals("IMPORTETAXAEMBARQUE") && !!importeTaxaEmbarque.equals(BigDecimal.ZERO)) {
|
||||
|
||||
RelatorioTaxasLinhaBean taxasLinha = new RelatorioTaxasLinhaBean();
|
||||
|
||||
if(!importeTaxaEmbarque.equals(BigDecimal.ZERO) && (Boolean) this.relatorio.getParametros().get("B_SUBTRAIR_ICMS")){
|
||||
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, importeTaxaEmbarque, BigDecimal.ZERO);
|
||||
return 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);
|
||||
|
||||
importeTaxaEmbarque = importeTaxaEmbarque.subtract(valorIcms);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e instanceof ExceptionConfiguracao)
|
||||
this.relatorio.addInfoMsg(e.getMessage());
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
taxasLinha.setIMPORTETAXAEMBARQUE(importeTaxaEmbarque);
|
||||
|
||||
return null;
|
||||
if(!importePedagio.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, importePedagio);
|
||||
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) {
|
||||
|
||||
setLsDadosRelatorio(lsDadosRelatorio);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void setLsDadosRelatorio(List<RelatorioTaxasLinhaBean> lsDadosRelatorio) {
|
||||
this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio));
|
||||
this.lsDadosRelatorio = lsDadosRelatorio;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue