diff --git a/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java b/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java index ba35ea50b..2e4200b5c 100644 --- a/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/FiscalDAO.java @@ -15,6 +15,7 @@ import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRM import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoDBP; 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.impressaormd.vo.ImpressaoRMD; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO; @@ -49,6 +50,8 @@ 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); diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java index 18b465bf8..c50da3d05 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/FiscalHibernateDAO.java @@ -41,6 +41,8 @@ import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRM import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoDBP; 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.exportacaofiscal.vo.ExportacaoRMDTipoSeqDBP; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.DetalhadoRMD; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.ImpressaoRMD; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; @@ -1929,6 +1931,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO StringBuilder sb = new StringBuilder(); sb.append(" select"); sb.append(" c.estado_id as cod_participante,"); + sb.append(" ei.codestabelecimento as cod_estabelecimento,"); sb.append(" e.nombempresa as nombempresa,"); sb.append(" es.cveestado as cveestado,"); sb.append(" e.cnpj as cnpj,"); @@ -1942,6 +1945,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO sb.append(" join ciudad c on c.ciudad_id = e.ciudad_id"); sb.append(" join estado es on es.estado_id = c.estado_id"); sb.append(" left join inscricao_estadual ie on ie.empresa_id = e.empresa_id and ie.estado_id = es.estado_id and ie.activo = 1"); + sb.append(" left join empresa_imposto ei on ei.activo = 1 and ei.empresa_id = e.empresa_id and ei.estado_id = es.estado_id"); sb.append(" where e.empresa_id = ?"); try { @@ -1955,6 +1959,7 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO while (rs.next()) { registro = new ExportacaoRMDTipoPAR(); registro.setCodigoParticipante(rs.getInt("cod_participante")); + registro.setCodigoEstabelecimento(rs.getInt("cod_estabelecimento")); registro.setNomeParticipante(rs.getString("nombempresa")); registro.setUfParticipante(rs.getString("cveestado")); registro.setCpfParticipante(rs.getString("cnpj")); @@ -2226,13 +2231,12 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO sb.append(" left join parada pds on pds.parada_id = s.aliasdestino_id"); sb.append(" left join ciudad cds on cds.ciudad_id = pds.ciudad_id"); sb.append(" left join estado eds on eds.estado_id = cds.estado_id"); - sb.append(" join empresa_imposto ei on ei.empresa_id = b.empresacorrida_id and ei.estado_id = eo.estado_id"); - sb.append(" left join empresa_imposto eis on eis.empresa_id = b.empresacorrida_id and eis.estado_id = eos.estado_id"); + sb.append(" join empresa_imposto ei on ei.activo = 1 and ei.empresa_id = b.empresacorrida_id and ei.estado_id = eo.estado_id"); + sb.append(" left join empresa_imposto eis on eis.activo = 1 and eis.empresa_id = b.empresacorrida_id and eis.estado_id = eos.estado_id"); sb.append(" where"); sb.append(" b.activo = 1"); sb.append(" and b.tipoventa_id = 3"); sb.append(" and (b.indstatusboleto like 'V' or b.indstatusboleto like 'C')"); - sb.append(" and (CASE WHEN s.aliasorigen_id IS NULL THEN ei.activo ELSE eis.activo END) = 1"); sb.append(" and b.empresacorrida_id = ?"); sb.append(" and (b.fechorventa >= to_date(?, 'dd/MM/YYYY hh24:mi:ss') and b.fechorventa <= to_date(?, 'dd/MM/YYYY hh24:mi:ss'))"); sb.append(" and (CASE WHEN s.aliasorigen_id IS NULL THEN eo.cveestado ELSE eos.cveestado END) like ?"); @@ -2366,6 +2370,251 @@ public class FiscalHibernateDAO extends HibernateDaoSupport implements FiscalDAO return retorno; } + @Override + public List buscarRegistroRMDSeqTipoBPS(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { + List listaBPS = new ArrayList(); + + StringBuilder sb = new StringBuilder(); + sb.append(" select"); + sb.append(" ei.codestabelecimento as cod_estabelecimento,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN eo.estado_id ELSE eos.estado_id END) as cod_participante,"); + sb.append(" (CASE WHEN b.indstatusboleto like 'C' THEN 1 ELSE 0 END) as cancelado,"); + sb.append(" b.aidf_id,"); + sb.append(" a.acfiscal as num_aidf,"); + sb.append(" a.serie as serie,"); + sb.append(" a.subserie as subserie,"); + sb.append(" b.feccreacion as data_emissao,"); + sb.append(" b.numfoliopreimpreso as num_formulario,"); + sb.append(" b.preciopagado as valor_total,"); + sb.append(" b.rmd_id,"); + sb.append(" r.acfiscal as num_aidf_rmd,"); + sb.append(" r.serie as serie_rmd,"); + sb.append(" r.subserie as subserie_rmd,"); + sb.append(" b.foliormd as num_rmd,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN eo.cveestado ELSE eos.cveestado END) as estado_origem,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN ed.cveestado ELSE eds.cveestado END) as estado_destino,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN co.codibge ELSE cos.codibge END) as municipio_origem,"); + sb.append(" (CASE WHEN ((CASE WHEN s.aliasorigen_id IS NULL THEN eo.cveestado ELSE eos.cveestado END) = (CASE WHEN s.aliasorigen_id IS NULL THEN ed.cveestado ELSE eds.cveestado END)) THEN 5357 ELSE 6357 END) as cod_operacao,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN ei.porcredbaseicms ELSE eis.porcredbaseicms END) as red_base_calc_icms,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN ei.porcredmunicipal ELSE eis.porcredmunicipal END) as porc_red_municipal,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN ei.porcredestadual ELSE eis.porcredestadual END) as porc_red_estadual,"); + sb.append(" (CASE WHEN s.aliasorigen_id IS NULL THEN ei.tributacaoimportacao ELSE eis.tributacaoimportacao END) as tributacao_importacao,"); + sb.append(" (CASE WHEN (nvl((CASE WHEN s.aliasorigen_id IS NULL THEN po.regionmetropolitana_id ELSE pos.regionmetropolitana_id END),-1) = nvl((CASE WHEN s.aliasorigen_id IS NULL THEN pd.regionmetropolitana_id ELSE pds.regionmetropolitana_id END),-2)) THEN 1 ELSE 0 END) as isenta,"); + sb.append(" (nvl(b.preciopagado,0) - nvl(b.importetaxaembarque,0) - nvl(b.importepedagio,0) - nvl(b.importeseguro,0) - nvl(b.importeoutros,0)) as valor_tarifa,"); + sb.append(" b.preciopagado as valor_total,"); + sb.append(" (CASE WHEN nvl(case when s.aliasorigen_id is null then po.regionmetropolitana_id else pos.regionmetropolitana_id end, -1) = nvl(case when s.aliasorigen_id is null then pd.regionmetropolitana_id else pds.regionmetropolitana_id end, -2) THEN 1 ELSE 0 END) as reg_metropolitana"); + sb.append(" from boleto b"); + sb.append(" join empresa e on e.empresa_id = b.empresacorrida_id"); + sb.append(" join parada po on po.parada_id = b.origen_id"); + sb.append(" join ciudad co on co.ciudad_id = po.ciudad_id"); + sb.append(" join estado eo on eo.estado_id = co.estado_id"); + sb.append(" join parada pd on pd.parada_id = b.destino_id"); + sb.append(" join ciudad cd on cd.ciudad_id = pd.ciudad_id"); + sb.append(" join estado ed on ed.estado_id = cd.estado_id"); + sb.append(" left join alias_servico s on s.origen_id = b.origen_id and s.destino_id = b.destino_id and (s.corrida_id = b.corrida_id or s.corrida_id is null) and s.ruta_id = b.ruta_id"); + sb.append(" left join parada pos on pos.parada_id = s.aliasorigen_id"); + sb.append(" left join ciudad cos on cos.ciudad_id = pos.ciudad_id"); + sb.append(" left join estado eos on eos.estado_id = cos.estado_id"); + sb.append(" left join parada pds on pds.parada_id = s.aliasdestino_id"); + sb.append(" left join ciudad cds on cds.ciudad_id = pds.ciudad_id"); + sb.append(" left join estado eds on eds.estado_id = cds.estado_id"); + sb.append(" join empresa_imposto ei on ei.activo = 1 and ei.empresa_id = b.empresacorrida_id and ei.estado_id = eo.estado_id"); + sb.append(" left join empresa_imposto eis on eis.activo = 1 and eis.empresa_id = b.empresacorrida_id and eis.estado_id = eos.estado_id"); + sb.append(" left join aidf a on a.aidf_id = b.aidf_id"); + sb.append(" left join aidf r on r.aidf_id = b.rmd_id"); + sb.append(" where"); + sb.append(" b.activo = 1"); + sb.append(" and b.tipoventa_id = 3"); + sb.append(" and (b.indstatusboleto like 'V' or b.indstatusboleto like 'C')"); + sb.append(" and b.empresacorrida_id = ?"); + sb.append(" and (b.fechorventa >= to_date(?, 'dd/MM/YYYY hh24:mi:ss') and b.fechorventa <= to_date(?, 'dd/MM/YYYY hh24:mi:ss'))"); + sb.append(" and (CASE WHEN s.aliasorigen_id IS NULL THEN eo.cveestado ELSE eos.cveestado END) like ?"); + sb.append(" order by b.fechorventa, b.numfoliopreimpreso, (CASE WHEN ((CASE WHEN s.aliasorigen_id IS NULL THEN eo.cveestado ELSE eos.cveestado END) = (CASE WHEN s.aliasorigen_id IS NULL THEN ed.cveestado ELSE eds.cveestado END)) THEN 5357 ELSE 6357 END), (CASE WHEN s.aliasorigen_id IS NULL THEN ed.cveestado ELSE eds.cveestado END)"); + + try { + PreparedStatement ps = connection.prepareStatement(sb.toString()); + ps.setLong(1, Long.valueOf(empresaId)); + ps.setString(2, DateUtil.getStringDate(inicio, DATE_FORMAT_DMY) + " 00:00:00"); + ps.setString(3, DateUtil.getStringDate(fim, DATE_FORMAT_DMY) + " 23:59:59"); + ps.setString(4, cveestado); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + + ResultSet rs = ps.executeQuery(); + + ExportacaoRMDTipoSeqBPS registroBPR = null; + ExportacaoRMDTipoSeqDBP registroDBP = null; + + Integer numeroInicial = 0; + Integer numeroFinal = 0; + + String dataEmissaoControle = ""; + 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"); + String serieAIDF = rs.getString("serie"); + String subSerieAIDF = rs.getString("subserie"); + Integer numeroAIDFRMD = rs.getInt("num_aidf_rmd"); + String serieAIDFRMD = rs.getString("serie_rmd"); + String subSerieAIDFRMD = rs.getString("subserie_rmd"); + Integer numeroRMD = rs.getInt("num_rmd"); + String dataEmissao = sdf.format(rs.getDate("data_emissao")); + Integer numeroFormulario = rs.getInt("num_formulario"); + String ufDestino = rs.getString("estado_destino"); + Integer cfop = rs.getInt("cod_operacao"); // IM=5357; Serviço IE= 6357 + String ufOrigem = rs.getString("estado_origem"); + 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; + + registroBPR = new ExportacaoRMDTipoSeqBPS(); + registroBPR.setEspecie("BPR"); + registroBPR.setNumeroInicial(numeroInicial); + registroBPR.setCodigoEstabelecimento(codigoEstabelecimento); + registroBPR.setNumeroAIDF(numeroAIDF); + registroBPR.setSerieAIDF(serieAIDF); + registroBPR.setSubSerieAIDF(subSerieAIDF); + registroBPR.setNumeroAIDFRMD(numeroAIDFRMD); + registroBPR.setSerieAIDFRMD(serieAIDFRMD); + registroBPR.setSubSerieAIDFRMD(subSerieAIDFRMD); + registroBPR.setNumeroRMD(numeroRMD); + registroBPR.setDataEmissao(dataEmissao); + + listaBPS.add(registroBPR); + + quantidadeTotal = 0; + quantidadeCancelado = 0; + + totalizador = BigDecimal.ZERO; + } + + quantidadeTotal++; + + if (cancelado) { + quantidadeCancelado++; + } else { + totalizador = MoneyHelper.somar(totalizador, valorTotal); + } + + numeroFinal = numeroFormulario; + + registroBPR.setNumeroFinal(numeroFinal); + + registroBPR.setQuantidadeTotal(quantidadeTotal); + registroBPR.setQuantidadeCancelados(quantidadeCancelado); + registroBPR.setValorTotal(totalizador); + + // DBP + registroDBP = new ExportacaoRMDTipoSeqDBP(ufDestino); + + Integer indice = registroBPR.getListaDBP().indexOf(registroDBP); + + if (indice == -1) { + registroBPR.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 + if (isenta) { + registroDBP.setCodigoSituacaoTribColunaB(40); + } + + // 00 - tributação normal; 20 - tributação com redução na base de calculo; 40 - isentos + if (registroDBP.getCodigoSituacaoTribColunaB() == null) { + registroDBP.setCodigoSituacaoTribColunaB(red_base_calc_icms == null || red_base_calc_icms.compareTo(BigDecimal.ZERO) == 0 ? 0 : 20); + } + + registroDBP.setValorBaseCalculoICMS(BigDecimal.ZERO); + registroDBP.setValorTotal(BigDecimal.ZERO); + registroDBP.setValorICMS(BigDecimal.ZERO); + registroDBP.setValorICMSIsento(BigDecimal.ZERO); + registroDBP.setValorICMSOutros(BigDecimal.ZERO); + } else { + registroDBP = registroBPR.getListaDBP().get(indice); + } + + BigDecimal valorBaseCalculoICMS = BigDecimal.ZERO; + + BigDecimal valorIsenta = BigDecimal.ZERO; + BigDecimal valorIsentaOutros = BigDecimal.ZERO; + + if (rs.getInt("reg_metropolitana") == 1) { + valorIsenta = valorTotal; + valorTotal = BigDecimal.ZERO; + } else { + if (red_base_calc_icms != null) { + valorBaseCalculoICMS = valorTotal.subtract(valorTotal.multiply(red_base_calc_icms.divide(BigDecimal.valueOf(100d)))); + } else { + valorBaseCalculoICMS = valorTotal; + } + } + + registroDBP.setAliquotaICMS(tributacao_importacao); + + if (tributacao_importacao == null) { + tributacao_importacao = BigDecimal.ZERO; + } else { + if (red_base_calc_icms != null) { + BigDecimal porc_red = BigDecimal.ZERO; + + if (rs.getString("estado_origem").equals(rs.getString("estado_destino"))) { + if (porc_red_municipal != null) { + porc_red = porc_red_municipal; + } + } else { + if (porc_red_estadual != null) { + porc_red = porc_red_estadual; + } + } + + BigDecimal porc = tributacao_importacao.subtract(porc_red.divide(BigDecimal.valueOf(100d))); + valorIsentaOutros = valorTotal.multiply(porc); + } + + tributacao_importacao = MoneyHelper.dividir(tributacao_importacao, BigDecimal.valueOf(100d)); + } + + BigDecimal valorICMS = MoneyHelper.multiplicar(valorBaseCalculoICMS, tributacao_importacao); + + registroDBP.setValorBaseCalculoICMS(registroDBP.getValorBaseCalculoICMS().add(valorBaseCalculoICMS)); + registroDBP.setValorTotal(registroDBP.getValorTotal().add(valorTotal)); + registroDBP.setValorICMS(registroDBP.getValorICMS().add(valorICMS)); + registroDBP.setValorICMSIsento(registroDBP.getValorICMSIsento().add(valorIsenta)); + registroDBP.setValorICMSOutros(registroDBP.getValorICMSOutros().add(valorIsentaOutros)); + } + + rs.close(); + ps.close(); + + } 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) { diff --git a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java index b819450b0..086cc0088 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/FiscalServiceImpl.java @@ -52,6 +52,8 @@ import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRM import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoDBP; 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.exportacaofiscal.vo.ExportacaoRMDTipoSeqDBP; import com.rjconsultores.ventaboletos.utilerias.impressaormd.vo.ImpressaoRMD; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalReducaoZVO; import com.rjconsultores.ventaboletos.vo.impressaofiscal.ImportacionFiscalVO; @@ -932,9 +934,11 @@ 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, - listaRegistroRMDTipoDBP); + listaRegistroRMDTipoDBP, listaRegistroRMDTipoSeqBPS); } catch (Exception e) { log.error(e.getMessage(), e); diff --git a/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/ExportacaoFiscal.java b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/ExportacaoFiscal.java index 423b6ab3b..126a5fe86 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/ExportacaoFiscal.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/ExportacaoFiscal.java @@ -31,6 +31,8 @@ import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRM import com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo.ExportacaoRMDTipoDBP; 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.exportacaofiscal.vo.ExportacaoRMDTipoSeqDBP; @Service("exportacaoFiscal") public class ExportacaoFiscal { @@ -418,7 +420,8 @@ public class ExportacaoFiscal { } public File gerarArquivoRMD(final Date dataInicial, final Date dataFinal, String nomeArquivo, final String nomeEmpresa, List listaRegistroRMDTipoPAR, - List listaRegistroRMDTipoRMD, List listaRegistroRMDTipoBPS, List listaRegistroRMDTipoDBP) { + List listaRegistroRMDTipoRMD, List listaRegistroRMDTipoBPS, List listaRegistroRMDTipoDBP, + List listaRegistroRMDTipoSeqBPS) { try { // String nomeArquivo = "fiscal_vendas_manual_" + DateUtil.getStringDate(Calendar.getInstance().getTime(), "yyyyMMddhhmmss"); @@ -429,10 +432,17 @@ public class ExportacaoFiscal { adicionarRegistroRMDTipoCAB(writer, dataInicial, dataFinal, nomeEmpresa, nomeArquivo); adicionarRegistroRMDTipoPAR(writer, listaRegistroRMDTipoPAR); adicionarRegistroRMDTipoRMD(writer, listaRegistroRMDTipoRMD); - adicionarRegistroRMDTipoBPS(writer, listaRegistroRMDTipoBPS); - adicionarRegistroRMDTipoDBP(writer, listaRegistroRMDTipoDBP); +// adicionarRegistroRMDTipoBPS(writer, listaRegistroRMDTipoBPS); +// adicionarRegistroRMDTipoDBP(writer, listaRegistroRMDTipoDBP); + adicionarRegistroRMDTipoSeqBPS(writer, listaRegistroRMDTipoSeqBPS); - int linhas = listaRegistroRMDTipoPAR.size() + listaRegistroRMDTipoRMD.size() + listaRegistroRMDTipoBPS.size() + listaRegistroRMDTipoDBP.size() + 1 + 1; + int linhas = listaRegistroRMDTipoPAR.size() + listaRegistroRMDTipoRMD.size() + 1 + 1; + + for (ExportacaoRMDTipoSeqBPS seq : listaRegistroRMDTipoSeqBPS) { + linhas++; + + linhas = linhas + seq.getListaDBP().size(); + } writer.print("TRA|" + linhas + UtiliteriasFiscal.QUEBRA_LINHA); @@ -465,6 +475,7 @@ public class ExportacaoFiscal { private void adicionarRegistroRMDTipoPAR(PrintWriter writer, List listaRegistroRMDTipoPAR) { for (ExportacaoRMDTipoPAR registro : listaRegistroRMDTipoPAR) { Integer codigoParticipante = registro.getCodigoParticipante(); + Integer codigoEstabelecimento = registro.getCodigoEstabelecimento(); String nomeParticipante = registro.getNomeParticipante(); String ufParticipante = registro.getUfParticipante(); String cpfParticipante = registro.getCpfParticipante(); @@ -477,7 +488,7 @@ public class ExportacaoFiscal { StringBuilder sb = new StringBuilder(); sb.append("PAR").append(SEPARADOR); - sb.append(formataNumerico(codigoParticipante, true, 9)).append(SEPARADOR); + sb.append(formataNumerico(codigoEstabelecimento, true, 9)).append(SEPARADOR); sb.append(formataCaracter(nomeParticipante, false, 60)).append(SEPARADOR); sb.append(formataCaracter(ufParticipante, false, 2)).append(SEPARADOR); sb.append(formataCaracter(cpfParticipante, true, 14)).append(SEPARADOR); @@ -527,7 +538,7 @@ public class ExportacaoFiscal { Integer numeroFormularioAIDF = registro.getNumeroFormularioAIDF(); String dataEmissao = registro.getDataEmissao(); Boolean cancelado = registro.getCancelado(); - Integer codigoParticipante = registro.getCodigoParticipante(); + Integer codigoParticipante = registro.getCodigoEstabelecimento(); // registro.getCodigoParticipante(); Allan/Flávio pediram esta modificação String codigoContabil = registro.getCodigoContabil(); StringBuilder sb = new StringBuilder(); @@ -665,6 +676,103 @@ public class ExportacaoFiscal { writer.print(sb.toString() + UtiliteriasFiscal.QUEBRA_LINHA); } } + + private void adicionarRegistroRMDTipoSeqBPS(PrintWriter writer, List listaRegistroRMDTipoBPS) { + for (ExportacaoRMDTipoSeqBPS registro : listaRegistroRMDTipoBPS) { + Integer codigoEstabelecimento = registro.getCodigoEstabelecimento(); + String especie = registro.getEspecie(); + Integer numeroAIDF = registro.getNumeroAIDF(); + String serieAIDF = registro.getSerieAIDF(); + String subSerieAIDF = registro.getSubSerieAIDF(); + Integer numeroInicial = registro.getNumeroInicial(); + Integer numeroFinal = registro.getNumeroFinal(); + Integer quantidadeCancelados = registro.getQuantidadeCancelados(); + String dataEmissao = registro.getDataEmissao(); + BigDecimal valorTotal = registro.getValorTotal(); + Boolean resumoMovimentoDiario = registro.getResumoMovimentoDiario(); + Integer numeroAIDFRMD = registro.getNumeroAIDFRMD(); + String serieAIDFRMD = registro.getSerieAIDFRMD(); + String subSerieAIDFRMD = registro.getSubSerieAIDFRMD(); + Integer numeroRMD = registro.getNumeroRMD(); + + StringBuilder sb = new StringBuilder(); + sb.append("BPS").append(SEPARADOR); + sb.append(String.format("%04d", codigoEstabelecimento)).append(SEPARADOR); + sb.append(formataCaracter(especie, false, 5)).append(SEPARADOR); + sb.append(formataNumerico(numeroAIDF, true, 25)).append(SEPARADOR); + sb.append(formataCaracter(serieAIDF, false, 3)).append(SEPARADOR); + sb.append(formataCaracter(subSerieAIDF, false, 3)).append(SEPARADOR); + sb.append(formataNumerico(numeroInicial, true, 6)).append(SEPARADOR); + sb.append(formataNumerico(numeroFinal, true, 6)).append(SEPARADOR); + sb.append(formataNumerico(quantidadeCancelados, true, 9)).append(SEPARADOR); + sb.append(formataNumerico(numeroInicial, true, 6)).append(SEPARADOR); + sb.append(formataNumerico(numeroFinal, true, 6)).append(SEPARADOR); + sb.append(formataCaracter(dataEmissao, true, 8)).append(SEPARADOR); + sb.append(formataValor(valorTotal, 15)).append(SEPARADOR); + sb.append(resumoMovimentoDiario == null ? "" : resumoMovimentoDiario ? "S" : "N").append(SEPARADOR); + sb.append(formataNumerico(numeroAIDFRMD, true, 25)).append(SEPARADOR); + sb.append(formataCaracter(serieAIDFRMD, false, 3)).append(SEPARADOR); + sb.append(formataCaracter(subSerieAIDFRMD, false, 3)).append(SEPARADOR); + sb.append(formataNumerico(numeroRMD, true, 6)).append(SEPARADOR); + sb.append(formataValor(valorTotal, 15)).append(SEPARADOR); + sb.append(formataValor(valorTotal, 15)).append(SEPARADOR); + sb.append(formataCaracter(VAZIO, false, 15)).append(SEPARADOR); // Posição 21 + sb.append(formataCaracter(VAZIO, false, 15)).append(SEPARADOR); // Posição 22 + sb.append(formataCaracter(VAZIO, false, 15)).append(SEPARADOR); // Posição 23 + sb.append(formataCaracter(VAZIO, false, 15)).append(SEPARADOR); // Posição 24 + sb.append(formataCaracter(VAZIO, false, 15)).append(SEPARADOR); // Posição 25 + sb.append(formataCaracter(VAZIO, false, 15)).append(SEPARADOR); // Posição 26 + sb.append("").append(SEPARADOR); // Posição 27 + sb.append("01").append(SEPARADOR); + sb.append("01").append(SEPARADOR); + sb.append(formataCaracter(VAZIO, false, 3)).append(SEPARADOR); // Posição 30 + sb.append(formataCaracter(VAZIO, false, 3)).append(SEPARADOR); // Posição 31 + sb.append(formataCaracter(VAZIO, false, 8)); // Posição 32 + + writer.print(sb.toString() + UtiliteriasFiscal.QUEBRA_LINHA); + + adicionarRegistroRMDTipoSeqDBP(writer, registro.getListaDBP()); + } + } + + private void adicionarRegistroRMDTipoSeqDBP(PrintWriter writer, List listaRegistroRMDTipoDBP) { + for (ExportacaoRMDTipoSeqDBP registro : listaRegistroRMDTipoDBP) { + String ufDestino = registro.getUfDestino(); + Integer cfop = registro.getCfop(); // IM=5357; Serviço IE= 6357 + BigDecimal valorTotal = registro.getValorTotal(); + BigDecimal valorBaseCalculoICMS = registro.getValorBaseCalculoICMS(); + BigDecimal aliquotaICMS = registro.getAliquotaICMS(); + BigDecimal valorICMS = registro.getValorICMS(); + BigDecimal valorICMSIsento = registro.getValorICMSIsento(); + BigDecimal valorICMSOutros = registro.getValorICMSOutros(); + Integer codigoSituacaoTribColunaB = registro.getCodigoSituacaoTribColunaB(); // 00 - tributação normal; 20 - tributação com redução na base de calculo; 40 - isentos + String ufOrigem = registro.getUfOrigem(); + Integer municipioestadoOrigem = registro.getMunicipioOrigem(); + + String municipioOrigem = municipioestadoOrigem.toString(); + + if (municipioOrigem.length() > 5) { + municipioOrigem = municipioOrigem.substring(municipioOrigem.length() - 5, municipioOrigem.length()); + } + + StringBuilder sb = new StringBuilder(); + sb.append("DBP").append(SEPARADOR); + sb.append(formataCaracter(ufDestino, true, 2)).append(SEPARADOR); + sb.append(formataNumerico(cfop, true, 4)).append(SEPARADOR); + sb.append(formataValor(valorTotal, 15)).append(SEPARADOR); + sb.append(formataValor(valorBaseCalculoICMS, 15)).append(SEPARADOR); + sb.append(formataValor(aliquotaICMS, 5)).append(SEPARADOR); + sb.append(formataValor(valorICMS, 15)).append(SEPARADOR); + sb.append(formataValor(valorICMSIsento, 15)).append(SEPARADOR); + sb.append(formataValor(valorICMSOutros, 15)).append(SEPARADOR); + sb.append(codigoSituacaoTribColunaB == 0 ? "00" : formataNumerico(codigoSituacaoTribColunaB, true, 2)).append(SEPARADOR); + sb.append(formataCaracter(ufOrigem, true, 2)).append(SEPARADOR); + sb.append(municipioOrigem).append(SEPARADOR); + sb.append(formataCaracter(VAZIO, false, 3)); // Posição 13 + + writer.print(sb.toString() + UtiliteriasFiscal.QUEBRA_LINHA); + } + } private String formataCaracter(String valor, boolean removeMascara, int tamanho) { if (valor == null) { diff --git a/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoPAR.java b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoPAR.java index 1687c3328..913abf6ea 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoPAR.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoPAR.java @@ -2,6 +2,7 @@ package com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo; public class ExportacaoRMDTipoPAR { private Integer codigoParticipante; + private Integer codigoEstabelecimento; private String nomeParticipante; private String ufParticipante; private String cpfParticipante; @@ -105,8 +106,16 @@ public class ExportacaoRMDTipoPAR { this.cep = cep; } + public Integer getCodigoEstabelecimento() { + return codigoEstabelecimento; + } + + public void setCodigoEstabelecimento(Integer codigoEstabelecimento) { + this.codigoEstabelecimento = codigoEstabelecimento; + } + @Override public String toString() { - return "ExportacaoRMDTipoPAR [codigoParticipante=" + codigoParticipante + ", nomeParticipante=" + nomeParticipante + ", ufParticipante=" + ufParticipante + ", cpfParticipante=" + cpfParticipante + ", ieParticipante=" + ieParticipante + ", imParticipante=" + imParticipante + ", logradouro=" + logradouro + ", numero=" + numero + ", complemento=" + complemento + ", bairro=" + bairro + ", cep=" + cep + "]"; + return "ExportacaoRMDTipoPAR [codigoParticipante=" + codigoParticipante + ", codigoEstabelecimento=" + codigoEstabelecimento + ", nomeParticipante=" + nomeParticipante + ", ufParticipante=" + ufParticipante + ", cpfParticipante=" + cpfParticipante + ", ieParticipante=" + ieParticipante + ", imParticipante=" + imParticipante + ", logradouro=" + logradouro + ", numero=" + numero + ", complemento=" + complemento + ", bairro=" + bairro + ", cep=" + cep + "]"; } } diff --git a/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoSeqBPS.java b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoSeqBPS.java new file mode 100644 index 000000000..363c54a9a --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoSeqBPS.java @@ -0,0 +1,176 @@ +package com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +public class ExportacaoRMDTipoSeqBPS { + private Integer codigoEstabelecimento; + private String especie; + private Integer numeroAIDF; + private String serieAIDF; + private String subSerieAIDF; + private Integer numeroInicial; + private Integer numeroFinal; + private Integer quantidadeCancelados; + private String dataEmissao; + private BigDecimal valorTotal; + private Integer numeroAIDFRMD; + private String serieAIDFRMD; + private String subSerieAIDFRMD; + private Integer numeroRMD; + private Integer quantidadeTotal; + private List listaDBP; + + public ExportacaoRMDTipoSeqBPS() { + listaDBP = new ArrayList(0); + + quantidadeTotal = 0; + quantidadeCancelados = 0; + } + + public Integer getCodigoEstabelecimento() { + return codigoEstabelecimento; + } + + public void setCodigoEstabelecimento(Integer codigoEstabelecimento) { + this.codigoEstabelecimento = codigoEstabelecimento; + } + + public String getEspecie() { + return especie; + } + + public void setEspecie(String especie) { + this.especie = especie; + } + + public Integer getNumeroAIDF() { + return numeroAIDF; + } + + public void setNumeroAIDF(Integer numeroAIDF) { + this.numeroAIDF = numeroAIDF; + } + + public String getSerieAIDF() { + return serieAIDF; + } + + public void setSerieAIDF(String serieAIDF) { + this.serieAIDF = serieAIDF; + } + + public String getSubSerieAIDF() { + return subSerieAIDF; + } + + public void setSubSerieAIDF(String subSerieAIDF) { + this.subSerieAIDF = subSerieAIDF; + } + + public Integer getNumeroInicial() { + return numeroInicial; + } + + public void setNumeroInicial(Integer numeroInicial) { + this.numeroInicial = numeroInicial; + } + + public Integer getNumeroFinal() { + return numeroFinal; + } + + public void setNumeroFinal(Integer numeroFinal) { + this.numeroFinal = numeroFinal; + } + + public Integer getQuantidadeCancelados() { + return quantidadeCancelados; + } + + public void setQuantidadeCancelados(Integer quantidadeCancelados) { + this.quantidadeCancelados = quantidadeCancelados; + } + + public String getDataEmissao() { + return dataEmissao; + } + + public void setDataEmissao(String dataEmissao) { + this.dataEmissao = dataEmissao; + } + + public BigDecimal getValorTotal() { + if (quantidadeTotal.intValue() == quantidadeCancelados.intValue()) { + return null; + } + + return valorTotal; + } + + public void setValorTotal(BigDecimal valorTotal) { + this.valorTotal = valorTotal; + } + + public Boolean getResumoMovimentoDiario() { + if (quantidadeTotal.intValue() == quantidadeCancelados.intValue()) { + return null; + } else { + return Boolean.TRUE; + } + } + + public Integer getNumeroAIDFRMD() { + return numeroAIDFRMD; + } + + public void setNumeroAIDFRMD(Integer numeroAIDFRMD) { + this.numeroAIDFRMD = numeroAIDFRMD; + } + + public String getSerieAIDFRMD() { + return serieAIDFRMD; + } + + public void setSerieAIDFRMD(String serieAIDFRMD) { + this.serieAIDFRMD = serieAIDFRMD; + } + + public String getSubSerieAIDFRMD() { + return subSerieAIDFRMD; + } + + public void setSubSerieAIDFRMD(String subSerieAIDFRMD) { + this.subSerieAIDFRMD = subSerieAIDFRMD; + } + + public Integer getNumeroRMD() { + return numeroRMD; + } + + public void setNumeroRMD(Integer numeroRMD) { + this.numeroRMD = numeroRMD; + } + + public Integer getQuantidadeTotal() { + return quantidadeTotal; + } + + public void setQuantidadeTotal(Integer quantidadeTotal) { + this.quantidadeTotal = quantidadeTotal; + } + + public List getListaDBP() { + return listaDBP; + } + + public void setListaDBP(List listaDBP) { + this.listaDBP = listaDBP; + } + + @Override + public String toString() { + return "ExportacaoRMDTipoSeqBPS [codigoEstabelecimento=" + codigoEstabelecimento + ", especie=" + especie + ", numeroAIDF=" + numeroAIDF + ", serieAIDF=" + serieAIDF + ", subSerieAIDF=" + subSerieAIDF + ", numeroInicial=" + numeroInicial + ", numeroFinal=" + numeroFinal + ", quantidadeCancelados=" + quantidadeCancelados + ", dataEmissao=" + dataEmissao + ", valorTotal=" + valorTotal + ", resumoMovimentoDiario=" + getResumoMovimentoDiario() + ", numeroAIDFRMD=" + numeroAIDFRMD + ", serieAIDFRMD=" + serieAIDFRMD + ", subSerieAIDFRMD=" + subSerieAIDFRMD + ", numeroRMD=" + numeroRMD + ", quantidadeTotal=" + quantidadeTotal + "]"; + } +} diff --git a/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoSeqDBP.java b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoSeqDBP.java new file mode 100644 index 000000000..bbed2f3c6 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/utilerias/exportacaofiscal/vo/ExportacaoRMDTipoSeqDBP.java @@ -0,0 +1,139 @@ +package com.rjconsultores.ventaboletos.utilerias.exportacaofiscal.vo; + +import java.math.BigDecimal; + +public class ExportacaoRMDTipoSeqDBP { + private String ufDestino; + private Integer cfop; // IM=5357; Serviço IE= 6357 + private BigDecimal valorTotal; + private BigDecimal valorBaseCalculoICMS; + private BigDecimal aliquotaICMS; + private BigDecimal valorICMS; + private BigDecimal valorICMSIsento; + private BigDecimal valorICMSOutros; + private Integer codigoSituacaoTribColunaB; // 00 - tributação normal; 20 - tributação com redução na base de calculo; 40 - isentos + private String ufOrigem; + private Integer municipioOrigem; + + public ExportacaoRMDTipoSeqDBP(String ufDestino) { + this.ufDestino = ufDestino; + } + + public String getUfDestino() { + return ufDestino; + } + + public void setUfDestino(String ufDestino) { + this.ufDestino = ufDestino; + } + + public Integer getCfop() { + return cfop; + } + + public void setCfop(Integer cfop) { + this.cfop = cfop; + } + + public BigDecimal getValorTotal() { + return valorTotal; + } + + public void setValorTotal(BigDecimal valorTotal) { + this.valorTotal = valorTotal; + } + + public BigDecimal getValorBaseCalculoICMS() { + return valorBaseCalculoICMS; + } + + public void setValorBaseCalculoICMS(BigDecimal valorBaseCalculoICMS) { + this.valorBaseCalculoICMS = valorBaseCalculoICMS; + } + + public BigDecimal getAliquotaICMS() { + return aliquotaICMS; + } + + public void setAliquotaICMS(BigDecimal aliquotaICMS) { + this.aliquotaICMS = aliquotaICMS; + } + + public BigDecimal getValorICMS() { + return valorICMS; + } + + public void setValorICMS(BigDecimal valorICMS) { + this.valorICMS = valorICMS; + } + + public BigDecimal getValorICMSIsento() { + return valorICMSIsento; + } + + public void setValorICMSIsento(BigDecimal valorICMSIsento) { + this.valorICMSIsento = valorICMSIsento; + } + + public BigDecimal getValorICMSOutros() { + return valorICMSOutros; + } + + public void setValorICMSOutros(BigDecimal valorICMSOutros) { + this.valorICMSOutros = valorICMSOutros; + } + + public Integer getCodigoSituacaoTribColunaB() { + return codigoSituacaoTribColunaB; + } + + public void setCodigoSituacaoTribColunaB(Integer codigoSituacaoTribColunaB) { + this.codigoSituacaoTribColunaB = codigoSituacaoTribColunaB; + } + + public String getUfOrigem() { + return ufOrigem; + } + + public void setUfOrigem(String ufOrigem) { + this.ufOrigem = ufOrigem; + } + + public Integer getMunicipioOrigem() { + return municipioOrigem; + } + + public void setMunicipioOrigem(Integer municipioOrigem) { + this.municipioOrigem = municipioOrigem; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((ufDestino == null) ? 0 : ufDestino.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; + ExportacaoRMDTipoSeqDBP other = (ExportacaoRMDTipoSeqDBP) obj; + if (ufDestino == null) { + if (other.ufDestino != null) + return false; + } else if (!ufDestino.equals(other.ufDestino)) + return false; + return true; + } + + @Override + public String toString() { + return "ExportacaoRMDTipoSeqDBP [ufDestino=" + ufDestino + ", cfop=" + cfop + ", valorTotal=" + valorTotal + ", valorBaseCalculoICMS=" + valorBaseCalculoICMS + ", aliquotaICMS=" + aliquotaICMS + ", valorICMS=" + valorICMS + ", valorICMSIsento=" + valorICMSIsento + ", valorICMSOutros=" + valorICMSOutros + ", codigoSituacaoTribColunaB=" + codigoSituacaoTribColunaB + ", ufOrigem=" + ufOrigem + ", municipioOrigem=" + municipioOrigem + "]"; + } +}