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-87c2c4800839master
parent
372a84c767
commit
ca641ffaaf
|
@ -1847,6 +1847,131 @@ public class FiscalHibernateDAO implements FiscalDAO {
|
|||
public List<ExportacaoRMDTipoBPS> buscarRegistroRMDTipoBPS(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -397,21 +397,22 @@ public class ExportacaoFiscal {
|
|||
}
|
||||
|
||||
private void adicionarRegistroRMDTipoBPS(PrintWriter writer, List<ExportacaoRMDTipoBPS> listaRegistroRMDTipoBPS) {
|
||||
Integer codigoEstabelecimento = 8;
|
||||
String especie = "BPR";
|
||||
Integer numeroAIDF = 114034303;
|
||||
String serieAIDF = "F";
|
||||
String subSerieAIDF = "";
|
||||
String numeroInicial = "039384";
|
||||
String numeroFinal = "039386";
|
||||
Integer quantidadeCancelados = 0;
|
||||
String dataEmissao = "20160501";
|
||||
BigDecimal valorTotal = new BigDecimal("114.82");
|
||||
Boolean resumoMovimentoDiario = Boolean.TRUE;
|
||||
Integer numeroAIDFRMD = 114034303;
|
||||
String serieAIDFRMD = "F";
|
||||
String subSerieAIDFRMD = "";
|
||||
Integer numeroRMD = 2723;
|
||||
for (ExportacaoRMDTipoBPS 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);
|
||||
|
@ -420,14 +421,14 @@ public class ExportacaoFiscal {
|
|||
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(formataCaracter(numeroInicial, true, 6)).append(SEPARADOR);
|
||||
sb.append(formataCaracter(numeroFinal, true, 6)).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(formataCaracter(numeroInicial, true, 6)).append(SEPARADOR);
|
||||
sb.append(formataCaracter(numeroFinal, true, 6)).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 ? "S" : "N").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);
|
||||
|
@ -449,6 +450,7 @@ public class ExportacaoFiscal {
|
|||
|
||||
writer.print(sb.toString() + UtiliteriasFiscal.QUEBRA_LINHA);
|
||||
}
|
||||
}
|
||||
|
||||
private void adicionarRegistroRMDTipoDBP(PrintWriter writer, List<ExportacaoRMDTipoBPS> listaRegistroRMDTipoBPS) {
|
||||
String ufDestino = "MA";
|
||||
|
|
|
@ -8,8 +8,8 @@ public class ExportacaoRMDTipoBPS {
|
|||
private Integer numeroAIDF;
|
||||
private String serieAIDF;
|
||||
private String subSerieAIDF;
|
||||
private String numeroInicial;
|
||||
private String numeroFinal;
|
||||
private Integer numeroInicial;
|
||||
private Integer numeroFinal;
|
||||
private Integer quantidadeCancelados;
|
||||
private String dataEmissao;
|
||||
private BigDecimal valorTotal;
|
||||
|
@ -18,6 +18,7 @@ public class ExportacaoRMDTipoBPS {
|
|||
private String serieAIDFRMD;
|
||||
private String subSerieAIDFRMD;
|
||||
private Integer numeroRMD;
|
||||
private Integer quantidadeTotal;
|
||||
|
||||
public ExportacaoRMDTipoBPS() {
|
||||
|
||||
|
@ -63,19 +64,19 @@ public class ExportacaoRMDTipoBPS {
|
|||
this.subSerieAIDF = subSerieAIDF;
|
||||
}
|
||||
|
||||
public String getNumeroInicial() {
|
||||
public Integer getNumeroInicial() {
|
||||
return numeroInicial;
|
||||
}
|
||||
|
||||
public void setNumeroInicial(String numeroInicial) {
|
||||
public void setNumeroInicial(Integer numeroInicial) {
|
||||
this.numeroInicial = numeroInicial;
|
||||
}
|
||||
|
||||
public String getNumeroFinal() {
|
||||
public Integer getNumeroFinal() {
|
||||
return numeroFinal;
|
||||
}
|
||||
|
||||
public void setNumeroFinal(String numeroFinal) {
|
||||
public void setNumeroFinal(Integer numeroFinal) {
|
||||
this.numeroFinal = numeroFinal;
|
||||
}
|
||||
|
||||
|
@ -143,6 +144,14 @@ public class ExportacaoRMDTipoBPS {
|
|||
this.numeroRMD = numeroRMD;
|
||||
}
|
||||
|
||||
public Integer getQuantidadeTotal() {
|
||||
return quantidadeTotal;
|
||||
}
|
||||
|
||||
public void setQuantidadeTotal(Integer quantidadeTotal) {
|
||||
this.quantidadeTotal = quantidadeTotal;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 + "]";
|
||||
|
|
Loading…
Reference in New Issue