diff --git a/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java b/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java index a35240da5..b6997536a 100644 --- a/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java @@ -69,4 +69,7 @@ public interface FiscalDAO { public void cancelarRMDBoleto(Connection connection, Date inicio, Date fim, Integer empresaId, Estado estado, Aidf aidf, String folioInicial, String folioFinal, boolean isCancela, boolean isInativa, boolean isECF, boolean isBPR); public List buscarRelatorioRDI(Connection connection, Date inicio, Date fim, Integer empresaId, List estados, boolean isReceitaTerceiros); + + public void limparCache(Connection connection); + } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java index 7b053c088..313ef82c0 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java @@ -396,7 +396,6 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { String vBC = null; String pICMS = null; String vICMS = null; - String pRedBC = null; if (StringUtils.isNotBlank(xml)) { if (tbpe.getInfBPe().getImp().getICMS().getICMS00() != null) { @@ -407,7 +406,6 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { vBC = tbpe.getInfBPe().getImp().getICMS().getICMS20().getVBC(); pICMS = tbpe.getInfBPe().getImp().getICMS().getICMS20().getPICMS(); vICMS = tbpe.getInfBPe().getImp().getICMS().getICMS20().getVICMS(); - pRedBC = tbpe.getInfBPe().getImp().getICMS().getICMS20().getPRedBC(); } if (tbpe.getInfBPe().getInfValorBPe() != null) { @@ -454,7 +452,6 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { aliquotaAnt = aliquota; BigDecimal icms = new BigDecimal(vICMS == null ? "0.0" : vICMS); - BigDecimal outros = new BigDecimal(pRedBC == null ? "0.0" : pRedBC); BigDecimal cp = null; if (isEstadual) { @@ -465,8 +462,8 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { BigDecimal credPres = icms.multiply(cp.divide(BigDecimal.TEN.multiply(BigDecimal.TEN))); BigDecimal icmsRec = icms.subtract(credPres); - - BigDecimal vRedBC = new BigDecimal(pRedBC == null ? "0.0" : pRedBC); + BigDecimal vRedBC = det.getRedBaseCalcIcms(); + BigDecimal outros = isentos.equals(BigDecimal.ZERO) ? BigDecimal.ZERO : passagem.subtract(isentos).subtract(baseCalculo); rdis.add(new FiscalRdi(det.getEstadoOrigem(), tipoViagem, det.getTipoReceita(), tarifa, seguro, taxaEmbarque, pedagio, passagem, isentos, outros, vRedBC, diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java index f060e0465..23f37c081 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java @@ -29,8 +29,10 @@ import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.FiscalDAO; import com.rjconsultores.ventaboletos.entidad.Aidf; +import com.rjconsultores.ventaboletos.entidad.Constante; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.Estado; +import com.rjconsultores.ventaboletos.service.ConstanteService; import com.rjconsultores.ventaboletos.utilerias.DateUtil; import com.rjconsultores.ventaboletos.utilerias.MoneyHelper; import com.rjconsultores.ventaboletos.utilerias.StringHelper; @@ -62,12 +64,12 @@ import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionNaoFiscalVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ItemFiscalVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.SituacaoTributaria; import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; +import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext; @Repository("fiscalDAO") public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO { private static final String DATE_FORMAT_FISCAL = "yyyyMMdd"; private static final String DATE_FORMAT_DMY = "dd/MM/yyyy"; - private static final BigDecimal ZERO = BigDecimal.ZERO; private static final String CODIGO_INDICADOR_CONTR_PREVIDENCIARIA = "00000060"; @@ -1419,6 +1421,32 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return exportacaoECF; } + public void limparCache(Connection connection) { + + ConstanteService constanteService = (ConstanteService) AppContext.getApplicationContext().getBean("constanteService"); + Constante contante = constanteService.buscarPorNomeConstante("LIMPA_CACHE_RELATORIOS"); + String command = null; + if ((contante != null && (StringUtils.isNotBlank(contante.getValorconstante())))) { + command = contante.getValorconstante(); + + PreparedStatement pstmt = null; + try { + pstmt = connection.prepareStatement(command); + pstmt.executeBatch(); + } catch (Exception e) { + log.error("", e); + } finally { + try { + if (pstmt != null && !pstmt.isClosed()) { + pstmt.close(); + } + } catch (Exception e) { + log.error("", e); + } + } + } + } + @Deprecated @Override public List buscarRegistroECFTipoCFC(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { @@ -4034,8 +4062,8 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO for (DetalhadoFiscal det : list) { - BigDecimal passagem = BigDecimal.ZERO; - BigDecimal isentos = BigDecimal.ZERO; + BigDecimal passagem = valorPassagem(det, isReceitaTerceiros); + BigDecimal isentos = valorIsenta(det, isReceitaTerceiros); BigDecimal outros = BigDecimal.ZERO; BigDecimal rbc = BigDecimal.ZERO; BigDecimal baseCalculo = BigDecimal.ZERO; @@ -4045,55 +4073,44 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO BigDecimal credPres = BigDecimal.ZERO; BigDecimal icmsRec = BigDecimal.ZERO; - if (det.getIsenta()) { - isentos = somarTotalBilhete(det, isReceitaTerceiros); + if (det.isInterEstadual()) { + aliquota = det.getTributacaoImportacao() != null ? det.getTributacaoImportacao() : det.getIcmsInterestadual(); } else { - passagem = somarTotalBilhete(det, isReceitaTerceiros); - - if (det.isInterEstadual()) { - aliquota = det.getTributacaoImportacao() != null ? det.getTributacaoImportacao() : det.getIcmsInterestadual(); - } else { - aliquota = det.getTributacaoImportacao() != null ? det.getTributacaoImportacao() : det.getIcmsIntermunicipal(); - } - - if (det.isInterEstadual()) { - cp = det.getPorcRedEstadual() == null ? BigDecimal.ZERO : det.getPorcRedEstadual(); - } else { - cp = det.getPorcRedMunicipal() == null ? BigDecimal.ZERO : det.getPorcRedMunicipal(); - } - - rbc = det.getRedBaseCalcIcms() == null ? BigDecimal.ZERO : det.getRedBaseCalcIcms().divide(UtiliteriasFiscal.CEM); - BigDecimal redutor = passagem.multiply(rbc); - baseCalculo = passagem.subtract(redutor); - icms = baseCalculo.multiply(aliquota.divide(BigDecimal.TEN.multiply(BigDecimal.TEN))); - credPres = icms.multiply(cp.divide(BigDecimal.TEN.multiply(BigDecimal.TEN))); - icmsRec = icms.subtract(credPres); + aliquota = det.getTributacaoImportacao() != null ? det.getTributacaoImportacao() : det.getIcmsIntermunicipal(); } + + if (det.isInterEstadual()) { + cp = det.getPorcRedEstadual() == null ? BigDecimal.ZERO : det.getPorcRedEstadual(); + } else { + cp = det.getPorcRedMunicipal() == null ? BigDecimal.ZERO : det.getPorcRedMunicipal(); + } + + rbc = det.getRedBaseCalcIcms() == null ? BigDecimal.ZERO : det.getRedBaseCalcIcms().divide(UtiliteriasFiscal.CEM); + + BigDecimal tarifa = valorBaseCalculo(det, isReceitaTerceiros); + BigDecimal redutor = tarifa.multiply(rbc); + baseCalculo = tarifa.subtract(redutor); + + icms = baseCalculo.multiply(aliquota.divide(BigDecimal.TEN.multiply(BigDecimal.TEN))); + credPres = icms.multiply(cp.divide(BigDecimal.TEN.multiply(BigDecimal.TEN))); + icmsRec = icms.subtract(credPres); + outros = isentos.equals(BigDecimal.ZERO) ? BigDecimal.ZERO : passagem.subtract(isentos).subtract(baseCalculo); - String tipoViagem = null; - if (det.isInterEstadual()) { - tipoViagem = "IE"; - } else { - tipoViagem = "IM"; - } + String tipoViagem = det.isInterEstadual() ? "IE" : "IM"; + BigDecimal taxaEmbarque = isReceitaTerceiros && det.getTaxaEmbarque() == null ? BigDecimal.ZERO : det.getTaxaEmbarque(); + BigDecimal pedagio = isReceitaTerceiros && det.getPedagio() == null ? BigDecimal.ZERO : det.getPedagio(); + BigDecimal seguro = isReceitaTerceiros && det.getSeguro() == null ? BigDecimal.ZERO : det.getSeguro(); - if (isReceitaTerceiros) { - rdis.add(new FiscalRdi(det.getEstadoOrigem(), tipoViagem, det.getTipoReceita(), det.getTarifa(), - det.getSeguro(), det.getTaxaEmbarque(), det.getPedagio(), passagem, isentos, outros, det.getRedBaseCalcIcms(), - baseCalculo, aliquota, icms, cp, credPres, icmsRec)); - } else { - rdis.add(new FiscalRdi(det.getEstadoOrigem(), tipoViagem, det.getTipoReceita(), det.getTarifa(), - ZERO, ZERO, ZERO, passagem, isentos, outros, det.getRedBaseCalcIcms(), - baseCalculo, aliquota, icms, cp, credPres, icmsRec)); - } + rdis.add(new FiscalRdi(det.getEstadoOrigem(), tipoViagem, det.getTipoReceita(), det.getTarifa(), + seguro, taxaEmbarque, pedagio, passagem, isentos, outros, det.getRedBaseCalcIcms(), + baseCalculo, aliquota, icms, cp, credPres, icmsRec)); } return rdis; } - private BigDecimal somarTotalBilhete(DetalhadoFiscal det, boolean isReceitaTerceiros) { - + private BigDecimal valorBaseCalculo(DetalhadoFiscal det, boolean isReceitaTerceiros) { BigDecimal total = BigDecimal.ZERO; total = total.add(det.getTarifa() == null ? BigDecimal.ZERO : det.getTarifa()); @@ -4109,6 +4126,30 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return total; } + private BigDecimal valorIsenta(DetalhadoFiscal det, boolean isReceitaTerceiros) { + + BigDecimal total = BigDecimal.ZERO; + if (isReceitaTerceiros && (det.isInterEstadual() && !det.getIndTxembarqueEstadual() || !det.isInterEstadual() && !det.getIndTxembarqueMunicipal())) + total = total.add(det.getTaxaEmbarque() == null ? BigDecimal.ZERO : det.getTaxaEmbarque()); + + if (isReceitaTerceiros && (det.isInterEstadual() && !det.getIndPedagioEstdual() || !det.isInterEstadual() && !det.getIndPedagioMunicipal())) + total = total.add(det.getPedagio() == null ? BigDecimal.ZERO : det.getPedagio()); + + if (isReceitaTerceiros && (det.isInterEstadual() && !det.getIndSeguroEstadual() || !det.isInterEstadual() && !det.getIndSeguroMunicipal())) + total = total.add(det.getSeguro() == null ? BigDecimal.ZERO : det.getSeguro()); + + return total; + } + + private BigDecimal valorPassagem(DetalhadoFiscal det, boolean isReceitaTerceiros) { + BigDecimal total = BigDecimal.ZERO; + total = total.add(det.getTarifa() == null ? BigDecimal.ZERO : det.getTarifa()); + total = total.add(det.getTaxaEmbarque() == null ? BigDecimal.ZERO : det.getTaxaEmbarque()); + total = total.add(det.getPedagio() == null ? BigDecimal.ZERO : det.getPedagio()); + total = total.add(det.getSeguro() == null ? BigDecimal.ZERO : det.getSeguro()); + return total; + } + private List montaRelatorioRDI(Connection connection, Date inicio, Date fim, Integer empresaId, String ufs) { List list = new ArrayList(); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java index ee0312be2..448e36603 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java @@ -962,6 +962,8 @@ public class FiscalServiceImpl implements FiscalService { tempo = infoTempo("PRC", begin); log.info("Tempo na busca dos registros " + tempo); tempos.add(tempo); + + fiscalDAO.limparCache(connection); return exportacaoFiscal.gerarArquivoECF(tempos, nomeArquivo, inicio, fim, estado.getCveestado(), empresa.getNombempresa(), listaRegistroECFTipoCFC, listaRegistroECFTipoCCF, listaRegistroECFTipoICF, listaRegistroECFTipoPRC); @@ -1047,6 +1049,8 @@ public class FiscalServiceImpl implements FiscalService { log.info("Total de registros: " + listaRegistroRMDTipoPAR.size()); tempo = infoTempo("BPS", begin); log.info("Tempo na busca dos registros " + tempo); + + fiscalDAO.limparCache(connection); return exportacaoFiscal.gerarArquivoRMD(inicio, fim, nomeArquivo, empresa.getNombempresa(), listaRegistroRMDTipoPAR, listaRegistroRMDTipoRMD, listaRegistroRMDTipoBPS, listaRegistroRMDTipoDBP, listaRegistroRMDTipoSeqBPS); diff --git a/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/FinanceiroSintetico.java b/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/FinanceiroSintetico.java index 4ac8783d6..d7b7c7b1d 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/FinanceiroSintetico.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/FinanceiroSintetico.java @@ -16,12 +16,14 @@ public class FinanceiroSintetico implements Comparable { private BigDecimal difTarifaMaior; private BigDecimal totalOutrasReceitas; private BigDecimal txEmb; + private BigDecimal txConveniencia; private BigDecimal pedagio; private BigDecimal segFacult; private BigDecimal totalTerceiros; private BigDecimal receitaBruta; private BigDecimal devolBPR; private BigDecimal devolGAP; + private BigDecimal devolOCD; private BigDecimal receitaLiquida; private BigDecimal despesas; private BigDecimal pgOCD; @@ -266,4 +268,20 @@ public class FinanceiroSintetico implements Comparable { this.receitaEb = receitaEb; } + public BigDecimal getTxConveniencia() { + return txConveniencia; + } + + public void setTxConveniencia(BigDecimal txConveniencia) { + this.txConveniencia = txConveniencia; + } + + public BigDecimal getDevolOCD() { + return devolOCD; + } + + public void setDevolOCD(BigDecimal devolOCD) { + this.devolOCD = devolOCD; + } + }