Exportação Fiscal : ECF e RMD (issue 8120)

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@62946 d1611594-4594-4d17-8e1d-87c2c4800839
master
alberto 2016-11-28 20:00:45 +00:00
parent 372a84c767
commit ca641ffaaf
3 changed files with 193 additions and 57 deletions

View File

@ -1847,6 +1847,131 @@ public class FiscalHibernateDAO implements FiscalDAO {
public List<ExportacaoRMDTipoBPS> buscarRegistroRMDTipoBPS(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { public List<ExportacaoRMDTipoBPS> buscarRegistroRMDTipoBPS(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) {
List<ExportacaoRMDTipoBPS> retorno = new ArrayList<ExportacaoRMDTipoBPS>(); List<ExportacaoRMDTipoBPS> retorno = new ArrayList<ExportacaoRMDTipoBPS>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
StringBuilder sb = new StringBuilder();
sb.append(" select");
sb.append(" ce.estado_id 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(" 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(" r.acfiscal as num_aidf_rmd,");
sb.append(" r.serie as serie_rmd,");
sb.append(" r.subserie as subserie_rmd,");
sb.append(" r.docfiscal as num_rmd");
sb.append(" from boleto b");
sb.append(" join empresa e on e.empresa_id = b.empresacorrida_id");
sb.append(" join ciudad ce on ce.ciudad_id = e.ciudad_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(" 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 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(" join aidf a on a.serie = substr(b.numseriepreimpresa, 1, 3) and a.estado_id = (CASE WHEN s.aliasorigen_id IS NULL THEN eo.estado_id ELSE eos.estado_id END)");
sb.append(" 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.feccorrida >= ? and b.feccorrida >= ?)");
sb.append(" and (CASE WHEN s.aliasorigen_id IS NULL THEN eo.cveestado ELSE eos.cveestado END) like ?");
sb.append(" order by r.docfiscal, b.numfoliopreimpreso");
try {
PreparedStatement ps = connection.prepareStatement(sb.toString());
ps.setLong(1, Long.valueOf(empresaId));
ps.setDate(2, new java.sql.Date(inicio.getTime()));
ps.setDate(3, new java.sql.Date(fim.getTime()));
ps.setString(4, cveestado);
ResultSet rs = ps.executeQuery();
Map<String, ExportacaoRMDTipoBPS> group = new HashMap<String, ExportacaoRMDTipoBPS>();
ExportacaoRMDTipoBPS registro = null;
Integer numeroInicial = null;
Integer numeroFinal = null;
while (rs.next()) {
String key = rs.getInt("num_rmd") + "|" + rs.getInt("num_formulario");
if (group.containsKey(key)) {
registro = group.get(key);
numeroInicial = rs.getInt("num_formulario");
numeroFinal = rs.getInt("num_formulario");
if (numeroInicial.intValue() > registro.getNumeroInicial().intValue()) {
numeroInicial = registro.getNumeroInicial();
}
if (numeroFinal.intValue() < registro.getNumeroFinal().intValue()) {
numeroFinal = registro.getNumeroFinal();
}
} else {
registro = new ExportacaoRMDTipoBPS();
registro.setCodigoEstabelecimento(rs.getInt("cod_estabelecimento"));
registro.setEspecie("BPR");
registro.setNumeroAIDF(rs.getInt("num_aidf"));
registro.setSerieAIDF(rs.getString("serie"));
registro.setSubSerieAIDF(rs.getString("subserie"));
registro.setNumeroAIDFRMD(rs.getInt("num_aidf_rmd"));
registro.setSerieAIDFRMD(rs.getString("serie_rmd"));
registro.setSubSerieAIDFRMD(rs.getString("subserie_rmd"));
registro.setNumeroRMD(rs.getInt("num_rmd"));
registro.setDataEmissao(sdf.format(rs.getDate("data_emissao")));
registro.setQuantidadeTotal(0);
registro.setQuantidadeCancelados(0);
registro.setValorTotal(BigDecimal.ZERO);
registro.setResumoMovimentoDiario(null);
numeroInicial = rs.getInt("num_formulario");
numeroFinal = rs.getInt("num_formulario");
}
registro.setNumeroInicial(numeroInicial);
registro.setNumeroFinal(numeroFinal);
registro.setQuantidadeTotal(registro.getQuantidadeTotal() + 1);
registro.setQuantidadeCancelados(registro.getQuantidadeCancelados() + rs.getInt("cancelado"));
if (rs.getInt("cancelado") == 0) {
registro.setValorTotal(registro.getValorTotal().add(rs.getBigDecimal("valor_total")));
}
group.put(key, registro);
}
for (Map.Entry<String, ExportacaoRMDTipoBPS> entry : group.entrySet()) {
registro = entry.getValue();
if (registro.getQuantidadeTotal().intValue() == registro.getQuantidadeCancelados().intValue()) {
registro.setValorTotal(null);
} else {
registro.setResumoMovimentoDiario(Boolean.TRUE);
}
retorno.add(registro);
}
rs.close();
ps.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return retorno; return retorno;
} }

View File

@ -397,21 +397,22 @@ public class ExportacaoFiscal {
} }
private void adicionarRegistroRMDTipoBPS(PrintWriter writer, List<ExportacaoRMDTipoBPS> listaRegistroRMDTipoBPS) { private void adicionarRegistroRMDTipoBPS(PrintWriter writer, List<ExportacaoRMDTipoBPS> listaRegistroRMDTipoBPS) {
Integer codigoEstabelecimento = 8; for (ExportacaoRMDTipoBPS registro : listaRegistroRMDTipoBPS) {
String especie = "BPR"; Integer codigoEstabelecimento = registro.getCodigoEstabelecimento();
Integer numeroAIDF = 114034303; String especie = registro.getEspecie();
String serieAIDF = "F"; Integer numeroAIDF = registro.getNumeroAIDF();
String subSerieAIDF = ""; String serieAIDF = registro.getSerieAIDF();
String numeroInicial = "039384"; String subSerieAIDF = registro.getSubSerieAIDF();
String numeroFinal = "039386"; Integer numeroInicial = registro.getNumeroInicial();
Integer quantidadeCancelados = 0; Integer numeroFinal = registro.getNumeroFinal();
String dataEmissao = "20160501"; Integer quantidadeCancelados = registro.getQuantidadeCancelados();
BigDecimal valorTotal = new BigDecimal("114.82"); String dataEmissao = registro.getDataEmissao();
Boolean resumoMovimentoDiario = Boolean.TRUE; BigDecimal valorTotal = registro.getValorTotal();
Integer numeroAIDFRMD = 114034303; Boolean resumoMovimentoDiario = registro.getResumoMovimentoDiario();
String serieAIDFRMD = "F"; Integer numeroAIDFRMD = registro.getNumeroAIDFRMD();
String subSerieAIDFRMD = ""; String serieAIDFRMD = registro.getSerieAIDFRMD();
Integer numeroRMD = 2723; String subSerieAIDFRMD = registro.getSubSerieAIDFRMD();
Integer numeroRMD = registro.getNumeroRMD();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("BPS").append(SEPARADOR); sb.append("BPS").append(SEPARADOR);
@ -420,14 +421,14 @@ public class ExportacaoFiscal {
sb.append(formataNumerico(numeroAIDF, true, 25)).append(SEPARADOR); sb.append(formataNumerico(numeroAIDF, true, 25)).append(SEPARADOR);
sb.append(formataCaracter(serieAIDF, false, 3)).append(SEPARADOR); sb.append(formataCaracter(serieAIDF, false, 3)).append(SEPARADOR);
sb.append(formataCaracter(subSerieAIDF, false, 3)).append(SEPARADOR); sb.append(formataCaracter(subSerieAIDF, false, 3)).append(SEPARADOR);
sb.append(formataCaracter(numeroInicial, true, 6)).append(SEPARADOR); sb.append(formataNumerico(numeroInicial, true, 6)).append(SEPARADOR);
sb.append(formataCaracter(numeroFinal, true, 6)).append(SEPARADOR); sb.append(formataNumerico(numeroFinal, true, 6)).append(SEPARADOR);
sb.append(formataNumerico(quantidadeCancelados, true, 9)).append(SEPARADOR); sb.append(formataNumerico(quantidadeCancelados, true, 9)).append(SEPARADOR);
sb.append(formataCaracter(numeroInicial, true, 6)).append(SEPARADOR); sb.append(formataNumerico(numeroInicial, true, 6)).append(SEPARADOR);
sb.append(formataCaracter(numeroFinal, true, 6)).append(SEPARADOR); sb.append(formataNumerico(numeroFinal, true, 6)).append(SEPARADOR);
sb.append(formataCaracter(dataEmissao, true, 8)).append(SEPARADOR); sb.append(formataCaracter(dataEmissao, true, 8)).append(SEPARADOR);
sb.append(formataValor(valorTotal, 15)).append(SEPARADOR); sb.append(formataValor(valorTotal, 15)).append(SEPARADOR);
sb.append(resumoMovimentoDiario ? "S" : "N").append(SEPARADOR); sb.append(resumoMovimentoDiario == null ? "" : resumoMovimentoDiario ? "S" : "N").append(SEPARADOR);
sb.append(formataNumerico(numeroAIDFRMD, true, 25)).append(SEPARADOR); sb.append(formataNumerico(numeroAIDFRMD, true, 25)).append(SEPARADOR);
sb.append(formataCaracter(serieAIDFRMD, false, 3)).append(SEPARADOR); sb.append(formataCaracter(serieAIDFRMD, false, 3)).append(SEPARADOR);
sb.append(formataCaracter(subSerieAIDFRMD, false, 3)).append(SEPARADOR); sb.append(formataCaracter(subSerieAIDFRMD, false, 3)).append(SEPARADOR);
@ -449,6 +450,7 @@ public class ExportacaoFiscal {
writer.print(sb.toString() + UtiliteriasFiscal.QUEBRA_LINHA); writer.print(sb.toString() + UtiliteriasFiscal.QUEBRA_LINHA);
} }
}
private void adicionarRegistroRMDTipoDBP(PrintWriter writer, List<ExportacaoRMDTipoBPS> listaRegistroRMDTipoBPS) { private void adicionarRegistroRMDTipoDBP(PrintWriter writer, List<ExportacaoRMDTipoBPS> listaRegistroRMDTipoBPS) {
String ufDestino = "MA"; String ufDestino = "MA";

View File

@ -8,8 +8,8 @@ public class ExportacaoRMDTipoBPS {
private Integer numeroAIDF; private Integer numeroAIDF;
private String serieAIDF; private String serieAIDF;
private String subSerieAIDF; private String subSerieAIDF;
private String numeroInicial; private Integer numeroInicial;
private String numeroFinal; private Integer numeroFinal;
private Integer quantidadeCancelados; private Integer quantidadeCancelados;
private String dataEmissao; private String dataEmissao;
private BigDecimal valorTotal; private BigDecimal valorTotal;
@ -18,6 +18,7 @@ public class ExportacaoRMDTipoBPS {
private String serieAIDFRMD; private String serieAIDFRMD;
private String subSerieAIDFRMD; private String subSerieAIDFRMD;
private Integer numeroRMD; private Integer numeroRMD;
private Integer quantidadeTotal;
public ExportacaoRMDTipoBPS() { public ExportacaoRMDTipoBPS() {
@ -63,19 +64,19 @@ public class ExportacaoRMDTipoBPS {
this.subSerieAIDF = subSerieAIDF; this.subSerieAIDF = subSerieAIDF;
} }
public String getNumeroInicial() { public Integer getNumeroInicial() {
return numeroInicial; return numeroInicial;
} }
public void setNumeroInicial(String numeroInicial) { public void setNumeroInicial(Integer numeroInicial) {
this.numeroInicial = numeroInicial; this.numeroInicial = numeroInicial;
} }
public String getNumeroFinal() { public Integer getNumeroFinal() {
return numeroFinal; return numeroFinal;
} }
public void setNumeroFinal(String numeroFinal) { public void setNumeroFinal(Integer numeroFinal) {
this.numeroFinal = numeroFinal; this.numeroFinal = numeroFinal;
} }
@ -143,6 +144,14 @@ public class ExportacaoRMDTipoBPS {
this.numeroRMD = numeroRMD; this.numeroRMD = numeroRMD;
} }
public Integer getQuantidadeTotal() {
return quantidadeTotal;
}
public void setQuantidadeTotal(Integer quantidadeTotal) {
this.quantidadeTotal = quantidadeTotal;
}
@Override @Override
public String toString() { public String toString() {
return "ExportacaoRMDTipoBPS [codigoEstabelecimento=" + codigoEstabelecimento + ", especie=" + especie + ", numeroAIDF=" + numeroAIDF + ", serieAIDF=" + serieAIDF + ", subSerieAIDF=" + subSerieAIDF + ", numeroInicial=" + numeroInicial + ", numeroFinal=" + numeroFinal + ", quantidadeCancelados=" + quantidadeCancelados + ", dataEmissao=" + dataEmissao + ", valorTotal=" + valorTotal + ", resumoMovimentoDiario=" + resumoMovimentoDiario + ", numeroAIDFRMD=" + numeroAIDFRMD + ", serieAIDFRMD=" + serieAIDFRMD + ", subSerieAIDFRMD=" + subSerieAIDFRMD + ", numeroRMD=" + numeroRMD + "]"; return "ExportacaoRMDTipoBPS [codigoEstabelecimento=" + codigoEstabelecimento + ", especie=" + especie + ", numeroAIDF=" + numeroAIDF + ", serieAIDF=" + serieAIDF + ", subSerieAIDF=" + subSerieAIDF + ", numeroInicial=" + numeroInicial + ", numeroFinal=" + numeroFinal + ", quantidadeCancelados=" + quantidadeCancelados + ", dataEmissao=" + dataEmissao + ", valorTotal=" + valorTotal + ", resumoMovimentoDiario=" + resumoMovimentoDiario + ", numeroAIDFRMD=" + numeroAIDFRMD + ", serieAIDFRMD=" + serieAIDFRMD + ", subSerieAIDFRMD=" + subSerieAIDFRMD + ", numeroRMD=" + numeroRMD + "]";