diff --git a/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java b/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java index 5e180c346..1bf4ed19f 100644 --- a/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java @@ -7,6 +7,7 @@ import java.util.List; import com.rjconsultores.ventaboletos.entidad.Aidf; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; +import com.rjconsultores.ventaboletos.entidad.Estado; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoECFTipoCCF; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoECFTipoCFC; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoECFTipoICF; @@ -16,6 +17,7 @@ import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRM import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoPAR; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoRMD; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoSeqBPS; +import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.ImpressaoRMD; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO; @@ -37,19 +39,19 @@ public interface FiscalDAO { public List buscarRegistroECFTipoCFC(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); public List buscarRegistroECFTipoCFC_Boleto(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); - + public List buscarRegistroECFTipoCCF(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); public List buscarRegistroECFTipoCCF_Boleto(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); - + public List buscarRegistroECFTipoICF(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); public List buscarRegistroECFTipoICF_Boleto(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); - + public List buscarRegistroECFTipoPRC(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); public List buscarRegistroECFTipoPRC_Boleto(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); - + public List buscarRegistroRMDTipoPAR(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); public List buscarRegistroRMDTipoRMD(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); @@ -59,7 +61,7 @@ public interface FiscalDAO { public List buscarRegistroRMDTipoDBP(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); public List buscarRegistroRMDSeqTipoBPS(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado); - + public List getRegistroImpressaoRMDTipoBPR(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado, String rmd, String folio); public List getRegistroImpressaoRMDTipoECF(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado, String rmd, String folio); @@ -68,4 +70,5 @@ public interface FiscalDAO { public void cancelarRMDBoleto(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado, Aidf aidf, String folio); + public List buscarRelatorioRDI(Connection connection, Date inicio, Date fim, Integer empresaId, List estados, boolean isReceitaTerceiros); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java index 743cbb7e3..42969e03d 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java @@ -8,6 +8,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -28,6 +29,7 @@ import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.FiscalDAO; import com.rjconsultores.ventaboletos.entidad.Aidf; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; +import com.rjconsultores.ventaboletos.entidad.Estado; import com.rjconsultores.ventaboletos.utilerias.DateUtil; import com.rjconsultores.ventaboletos.utilerias.MoneyHelper; import com.rjconsultores.ventaboletos.utilerias.StringHelper; @@ -43,6 +45,8 @@ import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRM import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoRMD; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoSeqBPS; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoSeqDBP; +import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.DetalhadoFiscal; +import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.DetalhadoRMD; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.ImpressaoRMD; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; @@ -51,6 +55,7 @@ import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionManualFiscal 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; @Repository("fiscalDAO") public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO { @@ -59,7 +64,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO private static final String DATE_FORMAT_DMY = "dd/MM/yyyy"; private static final String CODIGO_INDICADOR_CONTR_PREVIDENCIARIA = "00000060"; - + private static Logger log = Logger.getLogger(FiscalHibernateDAO.class); @Autowired @@ -78,7 +83,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO } @Override - public List buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId, Integer estadoId, Connection connection, boolean isBoletoHist) throws SQLException { + public List buscaDatosFiscaisECFManual(Date inicio, Date fim, Integer empresaId, Integer estadoId, Connection connection, boolean isBoletoHist) throws SQLException { PreparedStatement stmt = null; ResultSet rset = null; @@ -508,7 +513,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO } private String sqlFiscaisECFCancelados(boolean isEstadoTodos) { - + StringBuilder sql = new StringBuilder(); sql.append("SELECT r4.numserie20 as numImpressora, "); sql.append(" r4.coo as coo, "); @@ -576,7 +581,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO } private String sqlFiscaisECF(boolean isEstadoTodos, boolean isBoletoHist) { - + StringBuilder sql = new StringBuilder(); sql.append("SELECT numImpressora, "); sql.append(" coo, "); @@ -744,7 +749,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO sql.append(" QY.numImpressora, "); sql.append(" QY.coo, "); sql.append(" QY.numItem"); - + return sql.toString(); } @@ -955,18 +960,18 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO public List buscaDatosFiscaisECF(Date inicio, Date fim, Integer empresaId, Integer estadoId, boolean isNormal, boolean isCancelados, boolean isPendencias, Connection connection, boolean isBoletoHist) throws SQLException { if (isNormal) { - return montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECF(isEstadoTodos(estadoId), isBoletoHist), false,true); + return montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECF(isEstadoTodos(estadoId), isBoletoHist), false, true); } else if (isCancelados) { - return montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFCancelados(isEstadoTodos(estadoId)), true,false); + return montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFCancelados(isEstadoTodos(estadoId)), true, false); } else if (isPendencias) { List list = new ArrayList(); - list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasCancelado(isEstadoTodos(estadoId)), false,false)); - list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasDesconto(isEstadoTodos(estadoId)), false,false)); - list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasInconsistente(isEstadoTodos(estadoId)), false,false)); - list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasGratuidade(isEstadoTodos(estadoId)), false,false)); + list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasCancelado(isEstadoTodos(estadoId)), false, false)); + list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasDesconto(isEstadoTodos(estadoId)), false, false)); + list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasInconsistente(isEstadoTodos(estadoId)), false, false)); + list.addAll(montarItensECF(inicio, fim, empresaId, estadoId, connection, sqlFiscaisECFPendenciasGratuidade(isEstadoTodos(estadoId)), false, false)); return list; } @@ -974,9 +979,9 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO } private List montarItensECF(Date inicio, Date fim, Integer empresaId, Integer estadoId, Connection connection, String sql, boolean isDate, boolean isUnion) throws SQLException { - + boolean isEstadoTodos = isEstadoTodos(estadoId); - + PreparedStatement stmt = connection.prepareStatement(sql); stmt.setFetchSize(100); if (isDate) { @@ -985,31 +990,31 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO } else { stmt.setString(1, DateUtil.getStringDate(inicio, DATE_FORMAT_FISCAL)); stmt.setString(2, DateUtil.getStringDate(fim, DATE_FORMAT_FISCAL)); - - if (isUnion){ + + if (isUnion) { stmt.setString(isEstadoTodos ? 4 : 5, DateUtil.getStringDate(inicio, DATE_FORMAT_FISCAL)); - stmt.setString(isEstadoTodos ? 5: 6, DateUtil.getStringDate(fim, DATE_FORMAT_FISCAL)); + stmt.setString(isEstadoTodos ? 5 : 6, DateUtil.getStringDate(fim, DATE_FORMAT_FISCAL)); } } stmt.setInt(3, empresaId); - - if (isUnion){ - stmt.setInt(6, empresaId); + + if (isUnion) { + stmt.setInt(6, empresaId); } - if (!isEstadoTodos){ + if (!isEstadoTodos) { stmt.setInt(4, estadoId); - if (isUnion){ + if (isUnion) { stmt.setInt(8, estadoId); } } - if (!isUnion){ + if (!isUnion) { stmt.setTimestamp(4, new java.sql.Timestamp(DateUtil.inicioFecha(inicio).getTime())); stmt.setTimestamp(5, new java.sql.Timestamp(DateUtil.fimFecha(fim).getTime())); stmt.setInt(6, empresaId); } - + List list = new ArrayList(); ImportacionFiscalVO fiscal = null; String codProduto = null; @@ -1594,7 +1599,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return retorno; } - + @Override public List buscarRegistroECFTipoCCF(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { List retorno = new ArrayList(); @@ -1706,7 +1711,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO if ("30|40|41|50|60".contains(registro.getCodigoSituacaoTribColunaB().toString())) { tributacao_importacao = BigDecimal.ZERO; } - + if (red_base_calc_icms != null) { valorBaseCalculoICMS = valorTotal.subtract(valorTotal.multiply(red_base_calc_icms.divide(BigDecimal.valueOf(100d)))); } else { @@ -1752,7 +1757,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return retorno; } - + @Override public List buscarRegistroECFTipoCCF_Boleto(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { List retorno = new ArrayList(); @@ -1861,7 +1866,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO if ("30|40|41|50|60".contains(registro.getCodigoSituacaoTribColunaB().toString())) { tributacao_importacao = BigDecimal.ZERO; } - + if (red_base_calc_icms != null) { valorBaseCalculoICMS = valorTotal.subtract(valorTotal.multiply(red_base_calc_icms.divide(BigDecimal.valueOf(100d)))); } else { @@ -2050,7 +2055,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO valorICMSIsento = valorTotal; } - + String key = ecf + "|" + datamov + "|" + ufDestino + "|" + cfop.toString() + "|" + codigoSituacaoTribColunaB.toString(); if (group.containsKey(key)) { @@ -2158,7 +2163,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO if (valorTotal.doubleValue() == 0) { continue; } - + BigDecimal red_base_calc_icms = MoneyHelper.instanciar(rs.getBigDecimal("red_base_calc_icms")); BigDecimal porc_red_municipal = MoneyHelper.instanciar(rs.getBigDecimal("porc_red_municipal")); BigDecimal porc_red_estadual = MoneyHelper.instanciar(rs.getBigDecimal("porc_red_estadual")); @@ -2243,7 +2248,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO valorICMSIsento = valorTotal; } - + String key = ecf + "|" + datamov + "|" + ufDestino + "|" + cfop.toString() + "|" + codigoSituacaoTribColunaB.toString(); if (group.containsKey(key)) { @@ -2511,7 +2516,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO if (valorTotal.doubleValue() == 0) { continue; } - + BigDecimal red_base_calc_icms = MoneyHelper.instanciar(rs.getBigDecimal("red_base_calc_icms")); BigDecimal porc_red_municipal = MoneyHelper.instanciar(rs.getBigDecimal("porc_red_municipal")); BigDecimal porc_red_estadual = MoneyHelper.instanciar(rs.getBigDecimal("porc_red_estadual")); @@ -2674,8 +2679,8 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO sb.append(" a.acfiscal as num_aidf,"); sb.append(" a.serie as serie,"); sb.append(" a.subserie as subserie,"); -// sb.append(" b.numfoliosistema as num_bilhete,"); -// sb.append(" b.numfoliopreimpreso as num_formulario,"); + // sb.append(" b.numfoliosistema as num_bilhete,"); + // sb.append(" b.numfoliopreimpreso as num_formulario,"); sb.append(" b.foliormd as num_bilhete,"); sb.append(" b.foliormd as num_formulario,"); sb.append(" trunc(b.feccreacion) as data_emissao,"); @@ -2753,7 +2758,8 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return retorno; } - @Override @Deprecated + @Override + @Deprecated public List buscarRegistroRMDTipoBPS(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { List retorno = new ArrayList(); @@ -2888,7 +2894,8 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return retorno; } - @Override @Deprecated + @Override + @Deprecated public List buscarRegistroRMDTipoDBP(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { List retorno = new ArrayList(); @@ -2992,20 +2999,20 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO if (red_base_calc_icms != null) { valorBaseCalculoICMS = valorTotal.subtract(valorTotal.multiply(red_base_calc_icms.divide(BigDecimal.valueOf(100d)))); } else { -// if (tributacao_importacao != null) { -// if (rs.getString("estado_origem").equals(rs.getString("estado_destino"))) { -// if (porc_red_municipal != null) { -// BigDecimal porc = tributacao_importacao.subtract(tributacao_importacao.multiply(porc_red_municipal.divide(BigDecimal.valueOf(100d)))); -// valorBaseCalculoICMS = valorTotal.multiply(porc.divide(BigDecimal.valueOf(100d))); -// } -// } else { -// if (porc_red_estadual != null) { -// BigDecimal porc = tributacao_importacao.subtract(tributacao_importacao.multiply(porc_red_estadual.divide(BigDecimal.valueOf(100d)))); -// valorBaseCalculoICMS = valorTotal.multiply(porc.divide(BigDecimal.valueOf(100d))); -// } -// } -// } - + // if (tributacao_importacao != null) { + // if (rs.getString("estado_origem").equals(rs.getString("estado_destino"))) { + // if (porc_red_municipal != null) { + // BigDecimal porc = tributacao_importacao.subtract(tributacao_importacao.multiply(porc_red_municipal.divide(BigDecimal.valueOf(100d)))); + // valorBaseCalculoICMS = valorTotal.multiply(porc.divide(BigDecimal.valueOf(100d))); + // } + // } else { + // if (porc_red_estadual != null) { + // BigDecimal porc = tributacao_importacao.subtract(tributacao_importacao.multiply(porc_red_estadual.divide(BigDecimal.valueOf(100d)))); + // valorBaseCalculoICMS = valorTotal.multiply(porc.divide(BigDecimal.valueOf(100d))); + // } + // } + // } + valorBaseCalculoICMS = valorTotal; } } @@ -3129,7 +3136,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO ps.setString(4, cveestado); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); - + ResultSet rs = ps.executeQuery(); ExportacaoRMDTipoSeqBPS registroBPS = null; @@ -3137,15 +3144,15 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO Integer numeroInicial = 0; Integer numeroFinal = 0; - + String dataEmissaoControle = ""; - Integer cfopControle = 0; - + Integer cfopControle = 0; + Integer quantidadeTotal = 0; Integer quantidadeCancelado = 0; - + BigDecimal totalizador = BigDecimal.ZERO; - + while (rs.next()) { Integer codigoEstabelecimento = rs.getInt("cod_estabelecimento"); Integer numeroAIDF = rs.getInt("num_aidf"); @@ -3163,21 +3170,21 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO Integer municipioOrigem = rs.getInt("municipio_origem"); Boolean isenta = (rs.getInt("isenta") == 1); Boolean cancelado = (rs.getInt("cancelado") == 1); - BigDecimal valorTotal = rs.getBigDecimal("valor_total"); - BigDecimal red_base_calc_icms = rs.getBigDecimal("red_base_calc_icms"); - BigDecimal porc_red_municipal = rs.getBigDecimal("porc_red_municipal"); - BigDecimal porc_red_estadual = rs.getBigDecimal("porc_red_estadual"); - BigDecimal tributacao_importacao = rs.getBigDecimal("tributacao_importacao"); - - // BPR - if ((numeroFinal + 1) != numeroFormulario || !dataEmissaoControle.equals(dataEmissao) || !cfopControle.equals(cfop)) { - numeroInicial = numeroFormulario; - dataEmissaoControle = dataEmissao; - cfopControle = cfop; - - registroBPS = new ExportacaoRMDTipoSeqBPS(); + BigDecimal valorTotal = rs.getBigDecimal("valor_total"); + BigDecimal red_base_calc_icms = rs.getBigDecimal("red_base_calc_icms"); + BigDecimal porc_red_municipal = rs.getBigDecimal("porc_red_municipal"); + BigDecimal porc_red_estadual = rs.getBigDecimal("porc_red_estadual"); + BigDecimal tributacao_importacao = rs.getBigDecimal("tributacao_importacao"); + + // BPR + if ((numeroFinal + 1) != numeroFormulario || !dataEmissaoControle.equals(dataEmissao) || !cfopControle.equals(cfop)) { + numeroInicial = numeroFormulario; + dataEmissaoControle = dataEmissao; + cfopControle = cfop; + + registroBPS = new ExportacaoRMDTipoSeqBPS(); registroBPS.setEspecie("BPR"); - registroBPS.setNumeroInicial(numeroInicial); + registroBPS.setNumeroInicial(numeroInicial); registroBPS.setCodigoEstabelecimento(codigoEstabelecimento); registroBPS.setNumeroAIDF(numeroAIDF); registroBPS.setSerieAIDF(serieAIDF); @@ -3188,43 +3195,43 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO registroBPS.setNumeroRMD(numeroRMD); registroBPS.setDataEmissao(dataEmissao); registroBPS.setInfoPadraoBilhetePassagem(CODIGO_INDICADOR_CONTR_PREVIDENCIARIA); - - listaBPS.add(registroBPS); - - quantidadeTotal = 0; - quantidadeCancelado = 0; - - totalizador = BigDecimal.ZERO; - } - quantidadeTotal++; + listaBPS.add(registroBPS); - if (cancelado) { - quantidadeCancelado++; - } else { - totalizador = MoneyHelper.somar(totalizador, valorTotal); - } + quantidadeTotal = 0; + quantidadeCancelado = 0; + + totalizador = BigDecimal.ZERO; + } + + quantidadeTotal++; + + if (cancelado) { + quantidadeCancelado++; + } else { + totalizador = MoneyHelper.somar(totalizador, valorTotal); + } + + numeroFinal = numeroFormulario; + + registroBPS.setNumeroFinal(numeroFinal); - numeroFinal = numeroFormulario; - - registroBPS.setNumeroFinal(numeroFinal); - registroBPS.setQuantidadeTotal(quantidadeTotal); registroBPS.setQuantidadeCancelados(quantidadeCancelado); registroBPS.setValorTotal(totalizador); - + // DBP registroDBP = new ExportacaoRMDTipoSeqDBP(ufDestino); Integer indice = registroBPS.getListaDBP().indexOf(registroDBP); - + if (indice == -1) { registroBPS.getListaDBP().add(registroDBP); - + registroDBP.setCfop(cfop); // IM=5357; Serviço IE= 6357 registroDBP.setUfOrigem(ufOrigem); registroDBP.setMunicipioOrigem(municipioOrigem); - + registroDBP.setCodigoSituacaoTribColunaB(null); // 00 - tributação normal; 20 - tributação com redução na base de calculo; 40 - isentos @@ -3245,7 +3252,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO } else { registroDBP = registroBPS.getListaDBP().get(indice); } - + BigDecimal valorBaseCalculoICMS = BigDecimal.ZERO; BigDecimal valorIsenta = BigDecimal.ZERO; @@ -3302,10 +3309,10 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO } catch (Exception e) { log.error(e.getMessage(), e); } - + return listaBPS; } - + @Override public void cancelarRMDBoleto(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado, Aidf aidf, String folio) { @@ -3528,7 +3535,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO PreparedStatement ps = connection.prepareStatement(sql); ps.setLong(1, Long.valueOf(empresaId)); - + if (isECF) { ps.setString(2, DateUtil.getStringDate(inicio, DATE_FORMAT_FISCAL)); ps.setString(3, DateUtil.getStringDate(fim, DATE_FORMAT_FISCAL)); @@ -3695,13 +3702,13 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO sql.append(" a.serie as serieAidf, "); sql.append(" a.subserie as subSerieAidf, "); sql.append(" trunc(b.fechorventa) as fechorVenta, "); - sql.append(" e.nombempresa as empresa, "); + sql.append(" e.nombempresa as empresa, "); sql.append(" coalesce(ie.cnpj, e.cnpj) as cnpjEmpresa, "); sql.append(" case when ie.logradouro is null "); sql.append(" then (e.logradouro || ', ' || e.numero || ' - ' || e.bairro || ', ' || ce.nombciudad "); sql.append(" || ' - ' || ee.cveestado || ', ' || e.cep ) "); sql.append(" else (ie.logradouro || ', ' || ie.numero || ' - ' || ie.bairro || ', ' || ce.nombciudad "); - sql.append(" || ' - ' || ee.cveestado || ', ' || ie.cep ) end as enderecoEmpresa, "); + sql.append(" || ' - ' || ee.cveestado || ', ' || ie.cep ) end as enderecoEmpresa, "); sql.append(" pv.nombpuntoventa as nombPuntoVenta, "); sql.append(" pv.numpuntoventa as numPuntoVenta, "); sql.append(" ie.numinscricaoestadual as ieEmpresa, "); @@ -3735,7 +3742,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO sql.append(" r2.coo as cooredz, "); sql.append(" epv.cveestado as estadoImpressora "); sql.append("from fiscal_r4 r4 "); - sql.append(" join fiscal_r2 r2 on r4.numserie20 = r2.numserie20 and r4.datamov = r2.datamov "); + sql.append(" join fiscal_r2 r2 on r4.numserie20 = r2.numserie20 and r4.datamov = r2.datamov "); sql.append(" join boleto b on b.boleto_id = r4.boleto_id "); sql.append(" join marca m on b.marca_id = m.marca_id "); sql.append(" join empresa e on e.empresa_id = m.empresa_id "); @@ -3855,4 +3862,494 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return sql.toString(); } + + @Override + public List buscarRelatorioRDI(Connection connection, Date inicio, Date fim, Integer empresaId, List estados, boolean isReceitaTerceiros) { + + String ufs = null; + for (Estado estado : estados) { + if (ufs == null) + ufs = "'" + estado.getCveestado() + "'"; + else + ufs = ufs + ",'" + estado.getCveestado() + "'"; + } + + List list = montaRelatorioRDI(connection, inicio, fim, empresaId, ufs, false); + list.addAll(montaRelatorioRDI(connection, inicio, fim, empresaId, ufs, true)); + + List rdis = calcularRelatorioRDI(list); + return agrupaRdi(rdis); + } + + private List agrupaRdi(List list) { + List aux = new ArrayList(); + + FiscalRdi rdi = null; + for (FiscalRdi detail : list) { + + FiscalRdi atual = new FiscalRdi(detail.getEstado(), detail.getTipoViagem(), detail.getTipoReceita()); + if (!aux.contains(atual)) { + rdi = new FiscalRdi(detail.getEstado(), detail.getTipoViagem(), detail.getTipoReceita()); + aux.add(rdi); + } + + int index = aux.indexOf(atual); + FiscalRdi agr = aux.get(index); + agr.setQuantBilhetes(agr.getQuantBilhetes() == null ? BigDecimal.ZERO : agr.getQuantBilhetes().add(BigDecimal.ONE)); + agr.setTarifa(agr.getTarifa() == null ? BigDecimal.ZERO : agr.getTarifa().add(detail.getTarifa() == null ? BigDecimal.ZERO : detail.getTarifa())); + agr.setSeguro(agr.getSeguro() == null ? BigDecimal.ZERO : agr.getSeguro().add(detail.getSeguro() == null ? BigDecimal.ZERO : detail.getSeguro())); + agr.setTxEmbarque(agr.getTxEmbarque() == null ? BigDecimal.ZERO : agr.getTxEmbarque().add(detail.getTxEmbarque() == null ? BigDecimal.ZERO : detail.getTxEmbarque())); + agr.setPedagio(agr.getPedagio() == null ? BigDecimal.ZERO : agr.getPedagio().add(detail.getPedagio() == null ? BigDecimal.ZERO : detail.getPedagio())); + agr.setPassagem(agr.getPassagem() == null ? BigDecimal.ZERO : agr.getPassagem().add(detail.getPassagem() == null ? BigDecimal.ZERO : detail.getPassagem())); + agr.setIsentos(agr.getIsentos() == null ? BigDecimal.ZERO : agr.getIsentos().add(detail.getIsentos() == null ? BigDecimal.ZERO : detail.getIsentos())); + agr.setOutros(agr.getOutros() == null ? BigDecimal.ZERO : agr.getOutros().add(detail.getOutros() == null ? BigDecimal.ZERO : detail.getOutros())); + agr.setRbc(detail.getRbc() == null ? BigDecimal.ZERO : detail.getRbc()); + agr.setBaseCalculo(agr.getBaseCalculo() == null ? BigDecimal.ZERO : agr.getBaseCalculo().add(detail.getBaseCalculo() == null ? BigDecimal.ZERO : detail.getBaseCalculo())); + agr.setAliquota(detail.getAliquota() == null ? BigDecimal.ZERO : detail.getAliquota()); + agr.setIcms(agr.getIcms() == null ? BigDecimal.ZERO : agr.getIcms().add(detail.getIcms() == null ? BigDecimal.ZERO : detail.getIcms())); + agr.setCp(detail.getCp() == null ? BigDecimal.ZERO : detail.getCp()); + agr.setCredPres(agr.getCredPres() == null ? BigDecimal.ZERO : agr.getCredPres().add(detail.getCredPres() == null ? BigDecimal.ZERO : detail.getCredPres())); + agr.setIcmsRec(agr.getIcmsRec() == null ? BigDecimal.ZERO : agr.getIcmsRec().add(detail.getIcmsRec() == null ? BigDecimal.ZERO : detail.getIcmsRec())); + + aux.set(index, agr); + } + + Collections.sort(aux); + + return aux; + } + + private List calcularRelatorioRDI(List list) { + + List rdis = new ArrayList(); + + for (DetalhadoFiscal det : list) { + + BigDecimal passagem = BigDecimal.ZERO; + BigDecimal isentos = BigDecimal.ZERO; + BigDecimal outros = BigDecimal.ZERO; + BigDecimal rbc = BigDecimal.ZERO; + BigDecimal baseCalculo = BigDecimal.ZERO; + BigDecimal aliquota = BigDecimal.ZERO; + BigDecimal icms = BigDecimal.ZERO; + BigDecimal cp = BigDecimal.ZERO; + BigDecimal credPres = BigDecimal.ZERO; + BigDecimal icmsRec = BigDecimal.ZERO; + + if (det.getIsenta()) { + isentos = somarTotalBilhete(det); + } else { + passagem = somarTotalBilhete(det); + + if (det.isInterEstadual()) { + aliquota = det.getIcmsInterestadual() != null ? det.getIcmsInterestadual() : det.getTributacaoImportacao(); + } else { + aliquota = det.getIcmsIntermunicipal() != null ? det.getIcmsIntermunicipal() : det.getTributacaoImportacao(); + } + + 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 = passagem.subtract(baseCalculo); + + if (icms.compareTo(credPres) == 0) + icmsRec = icms.subtract(credPres); + else + icmsRec = credPres.subtract(icms); + } + outros = isentos.equals(BigDecimal.ZERO) ? BigDecimal.ZERO : passagem.subtract(isentos).subtract(baseCalculo); + + String tipoViagem = null; + if (det.isInterEstadual()) { + tipoViagem = "IE"; + } else { + tipoViagem = "IM"; + } + + 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)); + } + + return rdis; + } + + private BigDecimal somarTotalBilhete(DetalhadoFiscal det) { + + BigDecimal total = BigDecimal.ZERO; + total = total.add(det.getTarifa() == null ? BigDecimal.ZERO : det.getTarifa()); + + if (det.isInterEstadual() && det.getIndTxembarqueEstadual() || !det.isInterEstadual() && det.getIndTxembarqueMunicipal()) + total = total.add(det.getTaxaEmbarque() == null ? BigDecimal.ZERO : det.getTaxaEmbarque()); + + if (det.isInterEstadual() && det.getIndPedagioEstdual() || !det.isInterEstadual() && det.getIndPedagioMunicipal()) + total = total.add(det.getPedagio() == null ? BigDecimal.ZERO : det.getPedagio()); + + if (det.isInterEstadual() && det.getIndSeguroEstadual() || !det.isInterEstadual() && det.getIndSeguroMunicipal()) + 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, boolean isCancelados) { + + List list = new ArrayList(); + try { + + String sql = null; + if (isCancelados) + sql = sqlRelatorioRDICancelados(ufs); + else + sql = sqlRelatorioRDIVendidos(ufs); + + NamedParameterStatement ps = new NamedParameterStatement(connection, sql); + ps.setLong("EMPRESA_ID", Long.valueOf(empresaId)); + + if (!isCancelados) { + ps.setString("STR_INICIO", DateUtil.getStringDate(inicio, DATE_FORMAT_FISCAL)); + ps.setString("STR_FIM", DateUtil.getStringDate(fim, DATE_FORMAT_FISCAL)); + } + + ps.setTimestamp("DATE_INICIO", new java.sql.Timestamp(DateUtil.inicioFecha(inicio).getTime())); + ps.setTimestamp("DATE_FIM", new java.sql.Timestamp(DateUtil.fimFecha(fim).getTime())); + + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + + DetalhadoFiscal df = new DetalhadoFiscal(); + df.setCajaId(rs.getLong("cajaId")); + df.setTipoReceita(rs.getString("tipoReceita")); + df.setNumoperacion(rs.getString("numoperacion")); + df.setEstadoId(rs.getInt("estadoId")); + df.setFechorVenta(rs.getDate("fechorVenta")); + df.setIcmsInterestadual(rs.getBigDecimal("icmsInterestadual")); + df.setIcmsIntermunicipal(rs.getBigDecimal("icmsIntermunicipal")); + df.setEstadoOrigem(rs.getString("estadoOrigem")); + df.setEstadoDestino(rs.getString("estadoDestino")); + df.setMunicipioOrigem(rs.getString("municipioOrigem")); + df.setInterEstadual(rs.getBoolean("isInterEstadual")); + df.setIcmsInterestadual(rs.getBigDecimal("icmsInterestadual")); + df.setRedBaseCalcIcms(rs.getBigDecimal("redBaseCalcIcms")); + df.setPorcRedMunicipal(rs.getBigDecimal("porcRedMunicipal")); + df.setPorcRedEstadual(rs.getBigDecimal("porcRedEstadual")); + df.setTributacaoImportacao(rs.getBigDecimal("tributacaoImportacao")); + df.setIndTarifaMunicipal(rs.getBoolean("indtarifamunicipal")); + df.setIndSeguroMunicipal(rs.getBoolean("indseguromunicipal")); + df.setIndTxembarqueMunicipal(rs.getBoolean("indtxembarquemunicipal")); + df.setIndPedagioMunicipal(rs.getBoolean("indpedagiomunicipal")); + df.setIndTarifaEstadual(rs.getBoolean("indtarifaestadual")); + df.setIndSeguroEstadual(rs.getBoolean("indseguroestadual")); + df.setIndTxembarqueEstadual(rs.getBoolean("indtxembarqueestadual")); + df.setIndPedagioEstdual(rs.getBoolean("indpedagioestdual")); + df.setIsenta(rs.getBoolean("isenta")); + df.setTarifa(rs.getBigDecimal("tarifa")); + df.setTaxaEmbarque(rs.getBigDecimal("taxaEmbarque")); + df.setPedagio(rs.getBigDecimal("pedagio")); + df.setSeguro(rs.getBigDecimal("seguro")); + df.setOutros(rs.getBigDecimal("outros")); + df.setDatamov(rs.getString("datamov")); + list.add(df); + } + + rs.close(); + ps.close(); + + } catch (SQLException e) { + log.error("", e); + } + + return list; + } + + private String sqlRelatorioRDIVendidos(String ufs) { + + StringBuilder sql = new StringBuilder(); + sql.append("select "); + sql.append(" b.caja_id as cajaId, "); + sql.append(" 'REC' as tipoReceita, "); + sql.append(" b.numoperacion as numoperacion, "); + sql.append(" trunc(b.fechorventa) as fechorVenta, "); + sql.append(" coalesce(eos.estado_id, eo.estado_id) as estadoId, "); + sql.append(" coalesce(ei.icms, eo.icms) as icmsInterestadual, "); + sql.append(" ei.icmsim as icmsIntermunicipal, "); + sql.append(" coalesce(eos.cveestado, eo.cveestado) as estadoOrigem, "); + sql.append(" coalesce(eds.cveestado, ed.cveestado) as estadoDestino, "); + sql.append(" coalesce(cos.codibge, co.codibge) as municipioOrigem, "); + sql.append(" case when((coalesce(eos.cveestado, eo.cveestado)) = "); + sql.append(" (coalesce(eds.cveestado, ed.cveestado))) then 0 else 1 end as isInterEstadual, "); + sql.append(" ei.porcredbaseicms as redBaseCalcIcms, "); + sql.append(" ei.porcredmunicipal as porcRedMunicipal, "); + sql.append(" ei.porcredestadual as porcRedEstadual, "); + sql.append(" coalesce(ei.indtarifamunicipal, 0) as indtarifamunicipal, "); + sql.append(" coalesce(ei.indseguromunicipal, 0) as indseguromunicipal, "); + sql.append(" coalesce(ei.indtxembarquemunicipal, 0) as indtxembarquemunicipal, "); + sql.append(" coalesce(ei.indpedagiomunicipal, 0) as indpedagiomunicipal, "); + sql.append(" coalesce(ei.indtarifaestadual, 0) as indtarifaestadual, "); + sql.append(" coalesce(ei.indseguroestadual, 0) as indseguroestadual, "); + sql.append(" coalesce(ei.indtxembarqueestadual, 0) as indtxembarqueestadual, "); + sql.append(" coalesce(ei.indpedagioestdual, 0) as indpedagioestdual, "); + sql.append(" ei.tributacaoimportacao as tributacaoImportacao, "); + sql.append(" case when (coalesce(pos.regionmetropolitana_id, po.regionmetropolitana_id, -1) = "); + sql.append(" coalesce(pds.regionmetropolitana_id, pd.regionmetropolitana_id, -2)) then 1 else 0 end as isenta, "); + sql.append(" coalesce(b.preciopagado, 0) as tarifa, "); + sql.append(" coalesce(b.importetaxaembarque, 0) as taxaEmbarque, "); + sql.append(" coalesce(b.importepedagio, 0) as pedagio, "); + sql.append(" coalesce(b.importeseguro, 0) as seguro, "); + sql.append(" coalesce(b.importeoutros, 0) as outros, "); + sql.append(" r4.datamov as datamov "); + sql.append("from fiscal_r4 r4 "); + sql.append(" join fiscal_r2 r2 on r4.numserie20 = r2.numserie20 and r4.datamov = r2.datamov "); + sql.append(" join caja b on b.caja_id = r4.caja_id "); + sql.append(" join marca m on b.marca_id = m.marca_id "); + sql.append(" join empresa e on e.empresa_id = m.empresa_id "); + sql.append(" join parada po on po.parada_id = b.origen_id "); + sql.append(" join ciudad co on co.ciudad_id = po.ciudad_id "); + sql.append(" join estado eo on eo.estado_id = co.estado_id "); + sql.append(" join parada pd on pd.parada_id = b.destino_id "); + sql.append(" join ciudad cd on cd.ciudad_id = pd.ciudad_id "); + sql.append(" join estado ed on ed.estado_id = cd.estado_id "); + sql.append(" left join alias_servico s on s.origen_id = b.origen_id "); + sql.append(" and s.destino_id = b.destino_id and (s.corrida_id = b.corrida_id or s.corrida_id is null) "); + sql.append(" and s.ruta_id = b.ruta_id "); + sql.append(" left join parada pos on pos.parada_id = s.aliasorigen_id "); + sql.append(" left join ciudad cos on cos.ciudad_id = pos.ciudad_id "); + sql.append(" left join estado eos on eos.estado_id = cos.estado_id "); + sql.append(" left join parada pds on pds.parada_id = s.aliasdestino_id "); + sql.append(" left join ciudad cds on cds.ciudad_id = pds.ciudad_id "); + sql.append(" left join estado eds on eds.estado_id = cds.estado_id "); + sql.append(" join inscricao_estadual ie on e.empresa_id = ie.empresa_id "); + sql.append(" and ie.estado_id = coalesce(eos.estado_id, eo.estado_id) and ie.activo = 1 "); + sql.append(" join empresa_imposto ei on ei.empresa_id = e.empresa_id "); + sql.append(" and ei.estado_id = coalesce(eos.estado_id, eo.estado_id) and ei.activo = 1 "); + sql.append("where b.tipoventa_id <> 3 "); + sql.append(" and e.empresa_id = :EMPRESA_ID "); + sql.append(" and r4.datamov between :STR_INICIO and :STR_FIM "); + sql.append(" and coalesce(eos.cveestado, eo.cveestado) in ( ").append(ufs).append(" ) "); + sql.append(" "); + sql.append("union "); + sql.append(" "); + sql.append("select "); + sql.append(" b.caja_id as cajaId, "); + sql.append(" 'REC' as tipoReceita, "); + sql.append(" b.numoperacion as numoperacion, "); + sql.append(" trunc(b.fechorventa) as fechorVenta, "); + sql.append(" coalesce(eos.estado_id, eo.estado_id) as estadoId, "); + sql.append(" coalesce(ei.icms, eo.icms) as icmsInterestadual, "); + sql.append(" ei.icmsim as icmsIntermunicipal, "); + sql.append(" coalesce(eos.cveestado, eo.cveestado) as estadoOrigem, "); + sql.append(" coalesce(eds.cveestado, ed.cveestado) as estadoDestino, "); + sql.append(" coalesce(cos.codibge, co.codibge) as municipioOrigem, "); + sql.append(" case when((coalesce(eos.cveestado, eo.cveestado)) = "); + sql.append(" (coalesce(eds.cveestado, ed.cveestado))) then 0 else 1 end as isInterEstadual, "); + sql.append(" ei.porcredbaseicms as redBaseCalcIcms, "); + sql.append(" ei.porcredmunicipal as porcRedMunicipal, "); + sql.append(" ei.porcredestadual as porcRedEstadual, "); + sql.append(" coalesce(ei.indtarifamunicipal, 0) as indtarifamunicipal, "); + sql.append(" coalesce(ei.indseguromunicipal, 0) as indseguromunicipal, "); + sql.append(" coalesce(ei.indtxembarquemunicipal, 0) as indtxembarquemunicipal, "); + sql.append(" coalesce(ei.indpedagiomunicipal, 0) as indpedagiomunicipal, "); + sql.append(" coalesce(ei.indtarifaestadual, 0) as indtarifaestadual, "); + sql.append(" coalesce(ei.indseguroestadual, 0) as indseguroestadual, "); + sql.append(" coalesce(ei.indtxembarqueestadual, 0) as indtxembarqueestadual, "); + sql.append(" coalesce(ei.indpedagioestdual, 0) as indpedagioestdual, "); + sql.append(" ei.tributacaoimportacao as tributacaoImportacao, "); + sql.append(" case when (coalesce(pos.regionmetropolitana_id, po.regionmetropolitana_id, -1) = "); + sql.append(" coalesce(pds.regionmetropolitana_id, pd.regionmetropolitana_id, -2)) then 1 else 0 end as isenta, "); + sql.append(" coalesce(b.preciopagado, 0) as tarifa, "); + sql.append(" coalesce(b.importetaxaembarque, 0) as taxaEmbarque, "); + sql.append(" coalesce(b.importepedagio, 0) as pedagio, "); + sql.append(" coalesce(b.importeseguro, 0) as seguro, "); + sql.append(" coalesce(b.importeoutros, 0) as outros, "); + sql.append(" to_char(trunc(b.fechorventa), 'yyyymmdd') as datamov "); + sql.append("from caja b "); + sql.append(" join marca m on b.marca_id = m.marca_id "); + sql.append(" join empresa e on e.empresa_id = m.empresa_id "); + sql.append(" join ciudad ce on ce.ciudad_id = e.ciudad_id "); + sql.append(" join estado ee on ee.estado_id = ce.estado_id "); + sql.append(" join parada po on po.parada_id = b.origen_id "); + sql.append(" join ciudad co on co.ciudad_id = po.ciudad_id "); + sql.append(" join estado eo on eo.estado_id = co.estado_id "); + sql.append(" join parada pd on pd.parada_id = b.destino_id "); + sql.append(" join ciudad cd on cd.ciudad_id = pd.ciudad_id "); + sql.append(" join estado ed on ed.estado_id = cd.estado_id "); + sql.append(" left join alias_servico s on s.origen_id = b.origen_id "); + sql.append(" and s.destino_id = b.destino_id and (s.corrida_id = b.corrida_id or s.corrida_id is null) "); + sql.append(" and s.ruta_id = b.ruta_id "); + sql.append(" left join parada pos on pos.parada_id = s.aliasorigen_id "); + sql.append(" left join ciudad cos on cos.ciudad_id = pos.ciudad_id "); + sql.append(" left join estado eos on eos.estado_id = cos.estado_id "); + sql.append(" left join parada pds on pds.parada_id = s.aliasdestino_id "); + sql.append(" left join ciudad cds on cds.ciudad_id = pds.ciudad_id "); + sql.append(" left join estado eds on eds.estado_id = cds.estado_id "); + sql.append(" join inscricao_estadual ie on e.empresa_id = ie.empresa_id "); + sql.append(" and ie.estado_id = coalesce(eos.estado_id, eo.estado_id) and ie.activo = 1 "); + sql.append(" join empresa_imposto ei on ei.empresa_id = b.empresacorrida_id "); + sql.append(" and ei.estado_id = coalesce(eos.estado_id, eo.estado_id) and ei.activo = 1 "); + sql.append("where b.tipoventa_id = 3 "); + sql.append(" and b.indstatusboleto = 'V' "); + sql.append(" and e.empresa_id = :EMPRESA_ID "); + sql.append(" and b.fechorventa between :DATE_INICIO and :DATE_FIM "); + sql.append(" and coalesce(eos.cveestado, eo.cveestado) in ( ").append(ufs).append(" ) "); + sql.append("order by estadoId, isInterEstadual "); + + return sql.toString(); + } + + private String sqlRelatorioRDICancelados(String ufs) { + + StringBuilder sql = new StringBuilder(); + sql.append("select "); + sql.append(" caj.caja_id as cajaId, "); + sql.append(" 'DEV' as tipoReceita, "); + sql.append(" caj.numoperacion as numoperacion, "); + sql.append(" trunc(caj.fechorventa) as fechorVenta, "); + sql.append(" coalesce(eos.estado_id, eo.estado_id) as estadoId, "); + sql.append(" coalesce(ei.icms, eo.icms) as icmsInterestadual, "); + sql.append(" ei.icmsim as icmsIntermunicipal, "); + sql.append(" coalesce(eos.cveestado, eo.cveestado) as estadoOrigem, "); + sql.append(" coalesce(eds.cveestado, ed.cveestado) as estadoDestino, "); + sql.append(" coalesce(cos.codibge, co.codibge) as municipioOrigem, "); + sql.append(" case when((coalesce(eos.cveestado, eo.cveestado)) = "); + sql.append(" (coalesce(eds.cveestado, ed.cveestado))) then 0 else 1 end as isInterEstadual, "); + sql.append(" ei.porcredbaseicms as redBaseCalcIcms, "); + sql.append(" ei.porcredmunicipal as porcRedMunicipal, "); + sql.append(" ei.porcredestadual as porcRedEstadual, "); + sql.append(" coalesce(ei.indtarifamunicipal, 0) as indtarifamunicipal, "); + sql.append(" coalesce(ei.indseguromunicipal, 0) as indseguromunicipal, "); + sql.append(" coalesce(ei.indtxembarquemunicipal, 0) as indtxembarquemunicipal, "); + sql.append(" coalesce(ei.indpedagiomunicipal, 0) as indpedagiomunicipal, "); + sql.append(" coalesce(ei.indtarifaestadual, 0) as indtarifaestadual, "); + sql.append(" coalesce(ei.indseguroestadual, 0) as indseguroestadual, "); + sql.append(" coalesce(ei.indtxembarqueestadual, 0) as indtxembarqueestadual, "); + sql.append(" coalesce(ei.indpedagioestdual, 0) as indpedagioestdual, "); + sql.append(" ei.tributacaoimportacao as tributacaoImportacao, "); + sql.append(" case when (coalesce(pos.regionmetropolitana_id, po.regionmetropolitana_id, -1) = "); + sql.append(" coalesce(pds.regionmetropolitana_id, pd.regionmetropolitana_id, -2)) then 1 else 0 end as isenta, "); + sql.append(" coalesce(caj.preciopagado, 0) as tarifa, "); + sql.append(" coalesce(caj.importetaxaembarque, 0) as taxaEmbarque, "); + sql.append(" coalesce(caj.importepedagio, 0) as pedagio, "); + sql.append(" coalesce(caj.importeseguro, 0) as seguro, "); + sql.append(" coalesce(caj.importeoutros, 0) as outros, "); + sql.append(" r4.datamov as datamov "); + sql.append("from caja caj "); + sql.append(" inner join caja cajb on (((cajb.feccorrida = caj.feccorrida) or (cajb.feccorrida is null and caj.feccorrida is null)) "); + sql.append(" and ((cajb.numasiento = caj.numasiento) or (cajb.numasiento is null and caj.numasiento is null)) "); + sql.append(" and cajb.numfoliosistema = caj.numfoliosistema and cajb.origen_id = caj.origen_id and cajb.destino_id=caj.destino_id "); + sql.append(" and ((cajb.tipoventa_id not in (5,12,18,81,41,49) "); + sql.append(" and (cajb.indstatusboleto = 'v' or (cajb.indstatusboleto = 'T' and cajb.indreimpresion=0) )) "); + sql.append(" or (cajb.tipoventa_id in (5,12,18,81,41,49) and cajb.indstatusboleto = 'E')) ) "); + sql.append(" inner join fiscal_r4 r4 on r4.caja_id = cajb.caja_id "); + sql.append(" join fiscal_r2 r2 on r4.numserie20 = r2.numserie20 and r4.datamov = r2.datamov "); + sql.append(" join marca m on caj.marca_id = m.marca_id "); + sql.append(" join empresa e on e.empresa_id = m.empresa_id "); + sql.append(" join parada po on po.parada_id = caj.origen_id "); + sql.append(" join ciudad co on co.ciudad_id = po.ciudad_id "); + sql.append(" join estado eo on eo.estado_id = co.estado_id "); + sql.append(" join parada pd on pd.parada_id = caj.destino_id "); + sql.append(" join ciudad cd on cd.ciudad_id = pd.ciudad_id "); + sql.append(" join estado ed on ed.estado_id = cd.estado_id "); + sql.append(" left join alias_servico s on s.origen_id = caj.origen_id "); + sql.append(" and s.destino_id = caj.destino_id and (s.corrida_id = caj.corrida_id or s.corrida_id is null) "); + sql.append(" and s.ruta_id = caj.ruta_id "); + sql.append(" left join parada pos on pos.parada_id = s.aliasorigen_id "); + sql.append(" left join ciudad cos on cos.ciudad_id = pos.ciudad_id "); + sql.append(" left join estado eos on eos.estado_id = cos.estado_id "); + sql.append(" left join parada pds on pds.parada_id = s.aliasdestino_id "); + sql.append(" left join ciudad cds on cds.ciudad_id = pds.ciudad_id "); + sql.append(" left join estado eds on eds.estado_id = cds.estado_id "); + sql.append(" join inscricao_estadual ie on e.empresa_id = ie.empresa_id "); + sql.append(" and ie.estado_id = coalesce(eos.estado_id, eo.estado_id) and ie.activo = 1 "); + sql.append(" join empresa_imposto ei on ei.empresa_id = e.empresa_id "); + sql.append(" and ei.estado_id = coalesce(eos.estado_id, eo.estado_id) and ei.activo = 1 "); + sql.append("where caj.tipoventa_id <> 3 "); + sql.append(" and e.empresa_id = :EMPRESA_ID "); + sql.append(" and caj.fechorventa between :DATE_INICIO and :DATE_FIM "); + sql.append(" and caj.motivocancelacion_id in (31,32,10,37,99,36) "); + sql.append(" and caj.indcancelacion = 1 "); + sql.append(" and caj.indstatusboleto = 'C' "); + sql.append(" and coalesce(eos.cveestado, eo.cveestado) in ( ").append(ufs).append(" ) "); + sql.append(" "); + sql.append("union "); + sql.append(" "); + sql.append("select "); + sql.append(" caj.caja_id as cajaId, "); + sql.append(" 'DEV' as tipoReceita, "); + sql.append(" caj.numoperacion as numoperacion, "); + sql.append(" trunc(caj.fechorventa) as fechorVenta, "); + sql.append(" coalesce(eos.estado_id, eo.estado_id) as estadoId, "); + sql.append(" coalesce(ei.icms, eo.icms) as icmsInterestadual, "); + sql.append(" ei.icmsim as icmsIntermunicipal, "); + sql.append(" coalesce(eos.cveestado, eo.cveestado) as estadoOrigem, "); + sql.append(" coalesce(eds.cveestado, ed.cveestado) as estadoDestino, "); + sql.append(" coalesce(cos.codibge, co.codibge) as municipioOrigem, "); + sql.append(" case when((coalesce(eos.cveestado, eo.cveestado)) = "); + sql.append(" (coalesce(eds.cveestado, ed.cveestado))) then 0 else 1 end as isInterEstadual, "); + sql.append(" ei.porcredbaseicms as redBaseCalcIcms, "); + sql.append(" ei.porcredmunicipal as porcRedMunicipal, "); + sql.append(" ei.porcredestadual as porcRedEstadual, "); + sql.append(" coalesce(ei.indtarifamunicipal, 0) as indtarifamunicipal, "); + sql.append(" coalesce(ei.indseguromunicipal, 0) as indseguromunicipal, "); + sql.append(" coalesce(ei.indtxembarquemunicipal, 0) as indtxembarquemunicipal, "); + sql.append(" coalesce(ei.indpedagiomunicipal, 0) as indpedagiomunicipal, "); + sql.append(" coalesce(ei.indtarifaestadual, 0) as indtarifaestadual, "); + sql.append(" coalesce(ei.indseguroestadual, 0) as indseguroestadual, "); + sql.append(" coalesce(ei.indtxembarqueestadual, 0) as indtxembarqueestadual, "); + sql.append(" coalesce(ei.indpedagioestdual, 0) as indpedagioestdual, "); + sql.append(" ei.tributacaoimportacao as tributacaoImportacao, "); + sql.append(" case when (coalesce(pos.regionmetropolitana_id, po.regionmetropolitana_id, -1) = "); + sql.append(" coalesce(pds.regionmetropolitana_id, pd.regionmetropolitana_id, -2)) then 1 else 0 end as isenta, "); + sql.append(" coalesce(caj.preciopagado, 0) as tarifa, "); + sql.append(" coalesce(caj.importetaxaembarque, 0) as taxaEmbarque, "); + sql.append(" coalesce(caj.importepedagio, 0) as pedagio, "); + sql.append(" coalesce(caj.importeseguro, 0) as seguro, "); + sql.append(" coalesce(caj.importeoutros, 0) as outros, "); + sql.append(" to_char(trunc(caj.fechorventa), 'yyyymmdd') as datamov "); + sql.append("from caja caj "); + sql.append(" inner join caja cajb on (((cajb.feccorrida = caj.feccorrida) or (cajb.feccorrida is null and caj.feccorrida is null)) "); + sql.append(" and ((cajb.numasiento = caj.numasiento) or (cajb.numasiento is null and caj.numasiento is null)) "); + sql.append(" and cajb.numfoliosistema = caj.numfoliosistema and cajb.origen_id = caj.origen_id and cajb.destino_id=caj.destino_id "); + sql.append(" and ((cajb.tipoventa_id not in (5,12,18,81,41,49) "); + sql.append(" and (cajb.indstatusboleto = 'v' or (cajb.indstatusboleto = 'T' and cajb.indreimpresion=0) )) "); + sql.append(" or (cajb.tipoventa_id in (5,12,18,81,41,49) and cajb.indstatusboleto = 'E')) ) "); + sql.append(" join marca m on caj.marca_id = m.marca_id "); + sql.append(" join empresa e on e.empresa_id = m.empresa_id "); + sql.append(" join parada po on po.parada_id = caj.origen_id "); + sql.append(" join ciudad co on co.ciudad_id = po.ciudad_id "); + sql.append(" join estado eo on eo.estado_id = co.estado_id "); + sql.append(" join parada pd on pd.parada_id = caj.destino_id "); + sql.append(" join ciudad cd on cd.ciudad_id = pd.ciudad_id "); + sql.append(" join estado ed on ed.estado_id = cd.estado_id "); + sql.append(" left join alias_servico s on s.origen_id = caj.origen_id "); + sql.append(" and s.destino_id = caj.destino_id and (s.corrida_id = caj.corrida_id or s.corrida_id is null) "); + sql.append(" and s.ruta_id = caj.ruta_id "); + sql.append(" left join parada pos on pos.parada_id = s.aliasorigen_id "); + sql.append(" left join ciudad cos on cos.ciudad_id = pos.ciudad_id "); + sql.append(" left join estado eos on eos.estado_id = cos.estado_id "); + sql.append(" left join parada pds on pds.parada_id = s.aliasdestino_id "); + sql.append(" left join ciudad cds on cds.ciudad_id = pds.ciudad_id "); + sql.append(" left join estado eds on eds.estado_id = cds.estado_id "); + sql.append(" join inscricao_estadual ie on e.empresa_id = ie.empresa_id "); + sql.append(" and ie.estado_id = coalesce(eos.estado_id, eo.estado_id) and ie.activo = 1 "); + sql.append(" join empresa_imposto ei on ei.empresa_id = e.empresa_id "); + sql.append(" and ei.estado_id = coalesce(eos.estado_id, eo.estado_id) and ei.activo = 1 "); + sql.append("where cajb.tipoventa_id <> 3 "); + sql.append(" and e.empresa_id = :EMPRESA_ID "); + sql.append(" and caj.fechorventa between :DATE_INICIO and :DATE_FIM "); + sql.append(" and caj.motivocancelacion_id in (31,32,10,37,99,36) "); + sql.append(" and caj.indcancelacion = 1 "); + sql.append(" and caj.indstatusboleto = 'C' "); + sql.append(" and coalesce(eos.cveestado, eo.cveestado) in ( ").append(ufs).append(" ) "); + sql.append("order by estadoId, isInterEstadual "); + + return sql.toString(); + } } diff --git a/src/com/rjconsultores/ventaboletos/service/FiscalService.java b/src/com/rjconsultores/ventaboletos/service/FiscalService.java index 8a24e71bd..04154f2ee 100644 --- a/src/com/rjconsultores/ventaboletos/service/FiscalService.java +++ b/src/com/rjconsultores/ventaboletos/service/FiscalService.java @@ -10,6 +10,7 @@ import com.rjconsultores.ventaboletos.entidad.Aidf; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida; import com.rjconsultores.ventaboletos.entidad.Estado; +import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.ImpressaoRMD; public interface FiscalService { @@ -54,4 +55,5 @@ public interface FiscalService { public void cancelarRMDBoleto(Date inicio, Date fim, Empresa empresa, Estado estado, Aidf aidf, String folio); + public List buscarRelatorioRDI(Date inicio, Date fim, Empresa empresa, List estados, boolean isReceitaTerceiros); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java index 93837a7df..1e6f2513e 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java @@ -53,6 +53,7 @@ import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRM import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoPAR; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoRMD; import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoSeqBPS; +import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.ImpressaoRMD; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO; @@ -152,6 +153,27 @@ public class FiscalServiceImpl implements FiscalService { return null; } + @Override + public List buscarRelatorioRDI(Date inicio, Date fim, Empresa empresa, List estados, boolean isReceitaTerceiros) { + Connection connection = null; + try { + connection = getConnection(); + return fiscalDAO.buscarRelatorioRDI(connection, inicio, fim, empresa.getEmpresaId(), estados, isReceitaTerceiros); + } catch (Exception e) { + log.error("", e); + } finally { + try { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } catch (SQLException e) { + log.error("error fechar conexão", e); + throw new RuntimeException(e); + } + } + return null; + } + @Override public List getRegistroImpressaoRMDTipoECF(Date inicio, Date fim, Empresa empresa, Estado estado, String rmd, String folio) { Connection connection = null; @@ -879,7 +901,7 @@ public class FiscalServiceImpl implements FiscalService { Long begin = 0L; String tempo = null; - // CFC + // CFC begin = Calendar.getInstance().getTimeInMillis(); log.info("Buscando os registros CFC (ECF)"); List listaRegistroECFTipoCFC = new ArrayList(0); @@ -970,7 +992,7 @@ public class FiscalServiceImpl implements FiscalService { List listaRegistroRMDTipoRMD = fiscalDAO.buscarRegistroRMDTipoRMD(connection, inicio, fim, empresa.getEmpresaId(), estado.getCveestado()); List listaRegistroRMDTipoBPS = fiscalDAO.buscarRegistroRMDTipoBPS(connection, inicio, fim, empresa.getEmpresaId(), estado.getCveestado()); List listaRegistroRMDTipoDBP = fiscalDAO.buscarRegistroRMDTipoDBP(connection, inicio, fim, empresa.getEmpresaId(), estado.getCveestado()); - + List listaRegistroRMDTipoSeqBPS = fiscalDAO.buscarRegistroRMDSeqTipoBPS(connection, inicio, fim, empresa.getEmpresaId(), estado.getCveestado()); return exportacaoFiscal.gerarArquivoRMD(inicio, fim, nomeArquivo, empresa.getNombempresa(), listaRegistroRMDTipoPAR, listaRegistroRMDTipoRMD, listaRegistroRMDTipoBPS, diff --git a/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/DetalhadoFiscal.java b/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/DetalhadoFiscal.java new file mode 100644 index 000000000..0a4bf7e6c --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/DetalhadoFiscal.java @@ -0,0 +1,279 @@ +package com.rjconsultores.ventaboletos.utilerias.fiscal.vo; + +import java.math.BigDecimal; +import java.util.Date; + +public class DetalhadoFiscal { + + private Long cajaId; + private String tipoReceita; + private String numoperacion; + private Integer estadoId; + private Date fechorVenta; + private String estadoOrigem; + private String estadoDestino; + private String municipioOrigem; + private boolean isInterEstadual; + private BigDecimal icmsInterestadual; + private BigDecimal icmsIntermunicipal; + private BigDecimal redBaseCalcIcms; + private BigDecimal porcRedMunicipal; + private BigDecimal porcRedEstadual; + private BigDecimal tributacaoImportacao; + private Boolean indTarifaMunicipal; + private Boolean indSeguroMunicipal; + private Boolean indTxembarqueMunicipal; + private Boolean indPedagioMunicipal; + private Boolean indTarifaEstadual; + private Boolean indSeguroEstadual; + private Boolean indTxembarqueEstadual; + private Boolean indPedagioEstdual; + private Boolean isenta; + private BigDecimal tarifa; + private BigDecimal taxaEmbarque; + private BigDecimal pedagio; + private BigDecimal seguro; + private BigDecimal outros; + private String datamov; + + public Long getCajaId() { + return cajaId; + } + + public void setCajaId(Long cajaId) { + this.cajaId = cajaId; + } + + public String getTipoReceita() { + return tipoReceita; + } + + public void setTipoReceita(String tipoReceita) { + this.tipoReceita = tipoReceita; + } + + public String getNumoperacion() { + return numoperacion; + } + + public void setNumoperacion(String numoperacion) { + this.numoperacion = numoperacion; + } + + public Integer getEstadoId() { + return estadoId; + } + + public void setEstadoId(Integer estadoId) { + this.estadoId = estadoId; + } + + public Date getFechorVenta() { + return fechorVenta; + } + + public void setFechorVenta(Date fechorVenta) { + this.fechorVenta = fechorVenta; + } + + public String getEstadoOrigem() { + return estadoOrigem; + } + + public void setEstadoOrigem(String estadoOrigem) { + this.estadoOrigem = estadoOrigem; + } + + public String getEstadoDestino() { + return estadoDestino; + } + + public void setEstadoDestino(String estadoDestino) { + this.estadoDestino = estadoDestino; + } + + public String getMunicipioOrigem() { + return municipioOrigem; + } + + public void setMunicipioOrigem(String municipioOrigem) { + this.municipioOrigem = municipioOrigem; + } + + public boolean isInterEstadual() { + return isInterEstadual; + } + + public void setInterEstadual(boolean isInterEstadual) { + this.isInterEstadual = isInterEstadual; + } + + public BigDecimal getIcmsInterestadual() { + return icmsInterestadual; + } + + public void setIcmsInterestadual(BigDecimal icmsInterestadual) { + this.icmsInterestadual = icmsInterestadual; + } + + public BigDecimal getIcmsIntermunicipal() { + return icmsIntermunicipal; + } + + public void setIcmsIntermunicipal(BigDecimal icmsIntermunicipal) { + this.icmsIntermunicipal = icmsIntermunicipal; + } + + public BigDecimal getRedBaseCalcIcms() { + return redBaseCalcIcms; + } + + public void setRedBaseCalcIcms(BigDecimal redBaseCalcIcms) { + this.redBaseCalcIcms = redBaseCalcIcms; + } + + public BigDecimal getPorcRedMunicipal() { + return porcRedMunicipal; + } + + public void setPorcRedMunicipal(BigDecimal porcRedMunicipal) { + this.porcRedMunicipal = porcRedMunicipal; + } + + public BigDecimal getPorcRedEstadual() { + return porcRedEstadual; + } + + public void setPorcRedEstadual(BigDecimal porcRedEstadual) { + this.porcRedEstadual = porcRedEstadual; + } + + public BigDecimal getTributacaoImportacao() { + return tributacaoImportacao; + } + + public void setTributacaoImportacao(BigDecimal tributacaoImportacao) { + this.tributacaoImportacao = tributacaoImportacao; + } + + public Boolean getIndTarifaMunicipal() { + return indTarifaMunicipal; + } + + public void setIndTarifaMunicipal(Boolean indTarifaMunicipal) { + this.indTarifaMunicipal = indTarifaMunicipal; + } + + public Boolean getIndSeguroMunicipal() { + return indSeguroMunicipal; + } + + public void setIndSeguroMunicipal(Boolean indSeguroMunicipal) { + this.indSeguroMunicipal = indSeguroMunicipal; + } + + public Boolean getIndTxembarqueMunicipal() { + return indTxembarqueMunicipal; + } + + public void setIndTxembarqueMunicipal(Boolean indTxembarqueMunicipal) { + this.indTxembarqueMunicipal = indTxembarqueMunicipal; + } + + public Boolean getIndPedagioMunicipal() { + return indPedagioMunicipal; + } + + public void setIndPedagioMunicipal(Boolean indPedagioMunicipal) { + this.indPedagioMunicipal = indPedagioMunicipal; + } + + public Boolean getIndTarifaEstadual() { + return indTarifaEstadual; + } + + public void setIndTarifaEstadual(Boolean indTarifaEstadual) { + this.indTarifaEstadual = indTarifaEstadual; + } + + public Boolean getIndSeguroEstadual() { + return indSeguroEstadual; + } + + public void setIndSeguroEstadual(Boolean indSeguroEstadual) { + this.indSeguroEstadual = indSeguroEstadual; + } + + public Boolean getIndTxembarqueEstadual() { + return indTxembarqueEstadual; + } + + public void setIndTxembarqueEstadual(Boolean indTxembarqueEstadual) { + this.indTxembarqueEstadual = indTxembarqueEstadual; + } + + public Boolean getIndPedagioEstdual() { + return indPedagioEstdual; + } + + public void setIndPedagioEstdual(Boolean indPedagioEstdual) { + this.indPedagioEstdual = indPedagioEstdual; + } + + public Boolean getIsenta() { + return isenta; + } + + public void setIsenta(Boolean isenta) { + this.isenta = isenta; + } + + public BigDecimal getTarifa() { + return tarifa; + } + + public void setTarifa(BigDecimal tarifa) { + this.tarifa = tarifa; + } + + public BigDecimal getTaxaEmbarque() { + return taxaEmbarque; + } + + public void setTaxaEmbarque(BigDecimal taxaEmbarque) { + this.taxaEmbarque = taxaEmbarque; + } + + public BigDecimal getPedagio() { + return pedagio; + } + + public void setPedagio(BigDecimal pedagio) { + this.pedagio = pedagio; + } + + public BigDecimal getSeguro() { + return seguro; + } + + public void setSeguro(BigDecimal seguro) { + this.seguro = seguro; + } + + public BigDecimal getOutros() { + return outros; + } + + public void setOutros(BigDecimal outros) { + this.outros = outros; + } + + public String getDatamov() { + return datamov; + } + + public void setDatamov(String datamov) { + this.datamov = datamov; + } + +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/FiscalRdi.java b/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/FiscalRdi.java new file mode 100644 index 000000000..d5978b066 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/utilerias/fiscal/vo/FiscalRdi.java @@ -0,0 +1,294 @@ +package com.rjconsultores.ventaboletos.utilerias.fiscal.vo; + +import java.math.BigDecimal; + +public class FiscalRdi implements Comparable { + + private BigDecimal totalImEstado; + private BigDecimal totalIEEstado; + private BigDecimal receitaEstado; + private BigDecimal devolucaoEstado; + private BigDecimal liquidoEstado; + + private String estado; + private String tipoViagem; + private String tipoReceita; + private BigDecimal quantBilhetes; + private BigDecimal tarifa; + private BigDecimal seguro; + private BigDecimal txEmbarque; + private BigDecimal pedagio; + private BigDecimal passagem; + private BigDecimal isentos; + private BigDecimal outros; + private BigDecimal rbc; + private BigDecimal baseCalculo; + private BigDecimal aliquota; + private BigDecimal icms; + private BigDecimal cp; + private BigDecimal credPres; + private BigDecimal icmsRec; + + public FiscalRdi() { + super(); + } + + public FiscalRdi(String estado, String tipoViagem, String tipoReceita) { + super(); + this.estado = estado; + this.tipoViagem = tipoViagem; + this.tipoReceita = tipoReceita; + } + + public FiscalRdi(String estado, String tipoViagem, String tipoReceita, BigDecimal tarifa, BigDecimal seguro, BigDecimal txEmbarque, BigDecimal pedagio, BigDecimal passagem, BigDecimal isentos, BigDecimal outros, BigDecimal rbc, BigDecimal baseCalculo, BigDecimal aliquota, BigDecimal icms, BigDecimal cp, BigDecimal credPres, BigDecimal icmsRec) { + super(); + this.estado = estado; + this.tipoViagem = tipoViagem; + this.tipoReceita = tipoReceita; + this.tarifa = tarifa; + this.seguro = seguro; + this.txEmbarque = txEmbarque; + this.pedagio = pedagio; + this.passagem = passagem; + this.isentos = isentos; + this.outros = outros; + this.rbc = rbc; + this.baseCalculo = baseCalculo; + this.aliquota = aliquota; + this.icms = icms; + this.cp = cp; + this.credPres = credPres; + this.icmsRec = icmsRec; + } + + public String getEstado() { + return estado; + } + + public void setEstado(String estado) { + this.estado = estado; + } + + public String getTipoViagem() { + return tipoViagem; + } + + public void setTipoViagem(String tipoViagem) { + this.tipoViagem = tipoViagem; + } + + public String getTipoReceita() { + return tipoReceita; + } + + public void setTipoReceita(String tipoReceita) { + this.tipoReceita = tipoReceita; + } + + public BigDecimal getQuantBilhetes() { + return quantBilhetes; + } + + public void setQuantBilhetes(BigDecimal quantBilhetes) { + this.quantBilhetes = quantBilhetes; + } + + public BigDecimal getTarifa() { + return tarifa; + } + + public void setTarifa(BigDecimal tarifa) { + this.tarifa = tarifa; + } + + public BigDecimal getSeguro() { + return seguro; + } + + public void setSeguro(BigDecimal seguro) { + this.seguro = seguro; + } + + public BigDecimal getTxEmbarque() { + return txEmbarque; + } + + public void setTxEmbarque(BigDecimal txEmbarque) { + this.txEmbarque = txEmbarque; + } + + public BigDecimal getPedagio() { + return pedagio; + } + + public void setPedagio(BigDecimal pedagio) { + this.pedagio = pedagio; + } + + public BigDecimal getPassagem() { + return passagem; + } + + public void setPassagem(BigDecimal passagem) { + this.passagem = passagem; + } + + public BigDecimal getIsentos() { + return isentos; + } + + public void setIsentos(BigDecimal isentos) { + this.isentos = isentos; + } + + public BigDecimal getOutros() { + return outros; + } + + public void setOutros(BigDecimal outros) { + this.outros = outros; + } + + public BigDecimal getRbc() { + return rbc; + } + + public void setRbc(BigDecimal rbc) { + this.rbc = rbc; + } + + public BigDecimal getBaseCalculo() { + return baseCalculo; + } + + public void setBaseCalculo(BigDecimal baseCalculo) { + this.baseCalculo = baseCalculo; + } + + public BigDecimal getAliquota() { + return aliquota; + } + + public void setAliquota(BigDecimal aliquota) { + this.aliquota = aliquota; + } + + public BigDecimal getIcms() { + return icms; + } + + public void setIcms(BigDecimal icms) { + this.icms = icms; + } + + public BigDecimal getCp() { + return cp; + } + + public void setCp(BigDecimal cp) { + this.cp = cp; + } + + public BigDecimal getCredPres() { + return credPres; + } + + public void setCredPres(BigDecimal credPres) { + this.credPres = credPres; + } + + public BigDecimal getIcmsRec() { + return icmsRec; + } + + public void setIcmsRec(BigDecimal icmsRec) { + this.icmsRec = icmsRec; + } + + public BigDecimal getTotalImEstado() { + return totalImEstado; + } + + public void setTotalImEstado(BigDecimal totalImEstado) { + this.totalImEstado = totalImEstado; + } + + public BigDecimal getTotalIEEstado() { + return totalIEEstado; + } + + public void setTotalIEEstado(BigDecimal totalIEEstado) { + this.totalIEEstado = totalIEEstado; + } + + public BigDecimal getReceitaEstado() { + return receitaEstado; + } + + public void setReceitaEstado(BigDecimal receitaEstado) { + this.receitaEstado = receitaEstado; + } + + public BigDecimal getDevolucaoEstado() { + return devolucaoEstado; + } + + public void setDevolucaoEstado(BigDecimal devolucaoEstado) { + this.devolucaoEstado = devolucaoEstado; + } + + public BigDecimal getLiquidoEstado() { + return liquidoEstado; + } + + public void setLiquidoEstado(BigDecimal liquidoEstado) { + this.liquidoEstado = liquidoEstado; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((estado == null) ? 0 : estado.hashCode()); + result = prime * result + ((tipoReceita == null) ? 0 : tipoReceita.hashCode()); + result = prime * result + ((tipoViagem == null) ? 0 : tipoViagem.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FiscalRdi other = (FiscalRdi) obj; + if (estado == null) { + if (other.estado != null) + return false; + } else if (!estado.equals(other.estado)) + return false; + if (tipoReceita == null) { + if (other.tipoReceita != null) + return false; + } else if (!tipoReceita.equals(other.tipoReceita)) + return false; + if (tipoViagem == null) { + if (other.tipoViagem != null) + return false; + } else if (!tipoViagem.equals(other.tipoViagem)) + return false; + return true; + } + + @Override + public int compareTo(FiscalRdi o) { + int result = this.estado.compareToIgnoreCase(o.estado); + if (result == 0) { + return this.tipoViagem.compareToIgnoreCase(o.tipoViagem); + } else { + return result; + } + } +} diff --git a/src/com/rjconsultores/ventaboletos/web/utilerias/NamedParameterStatement.java b/src/com/rjconsultores/ventaboletos/web/utilerias/NamedParameterStatement.java new file mode 100644 index 000000000..d56045758 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/web/utilerias/NamedParameterStatement.java @@ -0,0 +1,337 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.web.utilerias; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; +import java.sql.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class NamedParameterStatement { + /** The statement this object is wrapping. */ + private final PreparedStatement statement; + + /** Maps parameter names to arrays of ints which are the parameter indices. */ + private final Map indexMap; + + /** + * Creates a NamedParameterStatement. Wraps a call to c.{@link Connection#prepareStatement(java.lang.String) prepareStatement}. + * + * @param connection + * the database connection + * @param query + * the parameterized query + * @throws SQLException + * if the statement could not be created + */ + public NamedParameterStatement(Connection connection, String query) throws + SQLException { + indexMap = new HashMap(); + String parsedQuery = parse(query, indexMap); + statement = connection.prepareStatement(parsedQuery); + } + + /** + * Parses a query with named parameters. The parameter-index mappings are put into the map, and the parsed query is returned. DO NOT CALL FROM CLIENT CODE. This method is non-private so JUnit code can test it. + * + * @param query + * query to parse + * @param paramMap + * map to hold parameter-index mappings + * @return the parsed query + */ + static final String parse(String query, Map paramMap) { + // I was originally using regular expressions, but they didn't work well for ignoring + // parameter-like strings inside quotes. + int length = query.length(); + StringBuffer parsedQuery = new StringBuffer(length); + boolean inSingleQuote = false; + boolean inDoubleQuote = false; + int index = 1; + + for (int i = 0; i < length; i++) { + char c = query.charAt(i); + if (inSingleQuote) { + if (c == '\'') { + inSingleQuote = false; + } + } else if (inDoubleQuote) { + if (c == '"') { + inDoubleQuote = false; + } + } else { + if (c == '\'') { + inSingleQuote = true; + } else if (c == '"') { + inDoubleQuote = true; + } else if (c == ':' && i + 1 < length && + Character.isJavaIdentifierStart(query.charAt(i + 1))) { + int j = i + 2; + while (j < length && Character.isJavaIdentifierPart(query.charAt(j))) { + j++; + } + String name = query.substring(i + 1, j); + c = '?'; // replace the parameter with a question mark + i += name.length(); // skip past the end if the parameter + + List indexList = (List) paramMap.get(name); + if (indexList == null) { + indexList = new LinkedList(); + paramMap.put(name, indexList); + } + indexList.add(new Integer(index)); + + index++; + } + } + parsedQuery.append(c); + } + + // replace the lists of Integer objects with arrays of ints + for (Iterator itr = paramMap.entrySet().iterator(); itr.hasNext();) { + Map.Entry entry = (Map.Entry) itr.next(); + List list = (List) entry.getValue(); + int[] indexes = new int[list.size()]; + int i = 0; + for (Iterator itr2 = list.iterator(); itr2.hasNext();) { + Integer x = (Integer) itr2.next(); + indexes[i++] = x.intValue(); + } + entry.setValue(indexes); + } + + return parsedQuery.toString(); + } + + /** + * Returns the indexes for a parameter. + * + * @param name + * parameter name + * @return parameter indexes + * @throws IllegalArgumentException + * if the parameter does not exist + */ + private int[] getIndexes(String name) { + int[] indexes = (int[]) indexMap.get(name); + if (indexes == null) { + throw new IllegalArgumentException("Parameter not found: " + name); + } + return indexes; + } + + /** + * Sets a parameter. + * + * @param name + * parameter name + * @param value + * parameter value + * @throws SQLException + * if an error occurred + * @throws IllegalArgumentException + * if the parameter does not exist + * @see PreparedStatement#setObject(int, java.lang.Object) + */ + public void setObject(String name, Object value) throws SQLException { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setObject(indexes[i], value); + } + } + + /** + * Sets a parameter. + * + * @param name + * parameter name + * @param value + * parameter value + * @throws SQLException + * if an error occurred + * @throws IllegalArgumentException + * if the parameter does not exist + * @see PreparedStatement#setString(int, java.lang.String) + */ + public void setString(String name, String value) throws SQLException { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setString(indexes[i], value); + } + } + + /** + * Sets a parameter. + * + * @param name + * parameter name + * @param value + * parameter value + * @throws SQLException + * if an error occurred + * @throws IllegalArgumentException + * if the parameter does not exist + * @see PreparedStatement#setInt(int, int) + */ + public void setInt(String name, int value) throws SQLException { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setInt(indexes[i], value); + } + } + + /** + * Sets a parameter. + * + * @param name + * parameter name + * @param value + * parameter value + * @throws SQLException + * if an error occurred + * @throws IllegalArgumentException + * if the parameter does not exist + * @see PreparedStatement#setInt(int, int) + */ + public void setLong(String name, long value) throws SQLException { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setLong(indexes[i], value); + } + } + + public void setDate(String name, Date value) throws SQLException { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setDate(indexes[i], value); + } + } + + + public void setNull(String name, int sqlType) throws SQLException { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setNull(indexes[i], sqlType); + } + } + + public void setBoolean(String name, Boolean value) throws SQLException { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setBoolean(indexes[i], value); + } + } + + /** + * Sets a parameter. + * + * @param name + * parameter name + * @param value + * parameter value + * @throws SQLException + * if an error occurred + * @throws IllegalArgumentException + * if the parameter does not exist + * @see PreparedStatement#setTimestamp(int, java.sql.Timestamp) + */ + public void setTimestamp(String name, Timestamp value) throws SQLException + { + int[] indexes = getIndexes(name); + for (int i = 0; i < indexes.length; i++) { + statement.setTimestamp(indexes[i], value); + } + } + + /** + * Returns the underlying statement. + * + * @return the statement + */ + public PreparedStatement getStatement() { + return statement; + } + + /** + * Executes the statement. + * + * @return true if the first result is a {@link ResultSet} + * @throws SQLException + * if an error occurred + * @see PreparedStatement#execute() + */ + public boolean execute() throws SQLException { + return statement.execute(); + } + + /** + * Executes the statement, which must be a query. + * + * @return the query results + * @throws SQLException + * if an error occurred + * @see PreparedStatement#executeQuery() + */ + public ResultSet executeQuery() throws SQLException { + return statement.executeQuery(); + } + + /** + * Executes the statement, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement. + * + * @return number of rows affected + * @throws SQLException + * if an error occurred + * @see PreparedStatement#executeUpdate() + */ + public int executeUpdate() throws SQLException { + return statement.executeUpdate(); + } + + /** + * Closes the statement. + * + * @throws SQLException + * if an error occurred + * @see Statement#close() + */ + public void close() throws SQLException { + statement.close(); + } + + public Boolean isClosed() throws SQLException { + return statement.isClosed(); + } + + /** + * Adds the current set of parameters as a batch entry. + * + * @throws SQLException + * if something went wrong + */ + public void addBatch() throws SQLException { + statement.addBatch(); + } + + /** + * Executes all of the batched statements. + * + * See {@link Statement#executeBatch()} for details. + * + * @return update counts for each statement + * @throws SQLException + * if something went wrong + */ + public int[] executeBatch() throws SQLException { + return statement.executeBatch(); + } +}