daniel.zauli 2016-05-19 17:10:55 +00:00
parent c332489d6e
commit 6e363b1fa8
1 changed files with 98 additions and 54 deletions

View File

@ -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,16 +41,20 @@ 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()));
stmt.setTimestamp("DATA_FINAL", new Timestamp(DateUtil.fimFecha((Date) parametros.get("DATA_FINAL")).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 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;
}
public Object valueCustomFields(String fieldName) throws Exception {
while (rset1.next()) {
// Se não for pra subtrair o ICMS, realiza o calculo e adiciona o mesmo // 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; BigDecimal valorIcms = BigDecimal.ZERO;
String indInterestadual = this.resultSet.getString("INTERESTADUAL"); String indInterestadual = rset1.getString("INTERESTADUAL");
Integer idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID"); Integer idEstado = rset1.getInt("ORIGEM_ESTADO_ID");
Integer empresaId = this.resultSet.getInt("EMPRESA_ID"); Integer empresaId = rset1.getInt("EMPRESA_ID");
try { BigDecimal importeTaxaEmbarque = rset1.getBigDecimal("IMPORTETAXAEMBARQUE") == null ? BigDecimal.ZERO : rset1.getBigDecimal("IMPORTETAXAEMBARQUE");
BigDecimal importeTaxaEmbarque = resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"); BigDecimal importePedagio = rset1.getBigDecimal("IMPORTEPEDAGIO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("IMPORTEPEDAGIO");
BigDecimal importePedagio = resultSet.getBigDecimal("IMPORTEPEDAGIO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTEPEDAGIO"); BigDecimal importeSeguro = rset1.getBigDecimal("IMPORTESEGURO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("IMPORTESEGURO");
BigDecimal importeSeguro = resultSet.getBigDecimal("IMPORTESEGURO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("IMPORTESEGURO");
BigDecimal totalEmbarque = resultSet.getBigDecimal("TOTAL_EMBARQUE") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("TOTAL_EMBARQUE"); BigDecimal totalEmbarque = rset1.getBigDecimal("TOTAL_EMBARQUE") == null ? BigDecimal.ZERO : rset1.getBigDecimal("TOTAL_EMBARQUE");
BigDecimal totalPedagio = resultSet.getBigDecimal("TOTAL_PEDAGIO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("TOTAL_PEDAGIO"); BigDecimal totalPedagio = rset1.getBigDecimal("TOTAL_PEDAGIO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("TOTAL_PEDAGIO");
BigDecimal totalSeguro = resultSet.getBigDecimal("TOTAL_SEGURO") == null ? BigDecimal.ZERO : resultSet.getBigDecimal("TOTAL_SEGURO"); BigDecimal totalSeguro = rset1.getBigDecimal("TOTAL_SEGURO") == null ? BigDecimal.ZERO : rset1.getBigDecimal("TOTAL_SEGURO");
if (fieldName.equals("IMPORTETAXAEMBARQUE") && !!importeTaxaEmbarque.equals(BigDecimal.ZERO)) { 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");
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");
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); valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, importeTaxaEmbarque, BigDecimal.ZERO);
return importeTaxaEmbarque.subtract(valorIcms); importeTaxaEmbarque = importeTaxaEmbarque.subtract(valorIcms);
}
taxasLinha.setIMPORTETAXAEMBARQUE(importeTaxaEmbarque);
} else if (fieldName.equals("IMPORTEPEDAGIO") && !importePedagio.equals(BigDecimal.ZERO)) { 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); valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, importePedagio);
return importePedagio.subtract(valorIcms); importePedagio = importePedagio.subtract(valorIcms);
}
taxasLinha.setIMPORTEPEDAGIO(importePedagio);
} else if (fieldName.equals("IMPORTESEGURO") && !importeSeguro.equals(BigDecimal.ZERO)) { 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); valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, importeSeguro, BigDecimal.ZERO, BigDecimal.ZERO);
return importeSeguro.subtract(valorIcms); importeSeguro = importeSeguro.subtract(valorIcms);
}
taxasLinha.setIMPORTESEGURO(importeSeguro);
} else if (fieldName.equals("TOTAL_EMBARQUE") && !totalEmbarque.equals(BigDecimal.ZERO)) { 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); valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, totalEmbarque, BigDecimal.ZERO, BigDecimal.ZERO);
return totalEmbarque.subtract(valorIcms); totalEmbarque = totalEmbarque.subtract(valorIcms);
}
taxasLinha.setTOTAL_EMBARQUE(totalEmbarque);
} else if (fieldName.equals("TOTAL_PEDAGIO") && !totalPedagio.equals(BigDecimal.ZERO)) { 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); valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, totalPedagio);
return totalPedagio.subtract(valorIcms); totalPedagio = totalPedagio.subtract(valorIcms);
}
taxasLinha.setTOTAL_PEDAGIO(totalPedagio);
} else if (fieldName.equals("TOTAL_SEGURO") && !totalSeguro.equals(BigDecimal.ZERO)) { 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); valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, empresaId, indInterestadual, BigDecimal.ZERO, totalSeguro, BigDecimal.ZERO, BigDecimal.ZERO);
return totalSeguro.subtract(valorIcms); totalSeguro = totalSeguro.subtract(valorIcms);
} }
} catch (Exception e) { taxasLinha.setTOTAL_SEGURO(totalSeguro);
if (e instanceof ExceptionConfiguracao)
this.relatorio.addInfoMsg(e.getMessage()); taxasLinha.setPREFIXO(prefixo);
else taxasLinha.setCIDADE_ORIGEM(cidadeOrigem);
throw e; 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);
} }
} }
return null;
}
}); });
} }
public void setLsDadosRelatorio(List<RelatorioTaxasLinhaBean> lsDadosRelatorio) {
this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio));
this.lsDadosRelatorio = lsDadosRelatorio;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *