From 8303cdd25c1189a733ffb806b5c09182418c7aa7 Mon Sep 17 00:00:00 2001 From: leonardo Date: Wed, 20 Mar 2019 14:27:34 +0000 Subject: [PATCH] =?UTF-8?q?13559:=20ADM=20=E2=80=93=20Gera=C3=A7=C3=A3o=20?= =?UTF-8?q?de=20informa=C3=A7=C3=B5es=20RecDespDiv=20e=20DepBco=20(parte?= =?UTF-8?q?=202)=20fixes=20bug#13559=20dev:valdevir=20qua:Juliane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/Integracion/IntegracaoReceitaDespesa/trunk/IntegracaoReceitaDespesa@90970 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../BGMApplication.java | 12 +- .../IntegracaoReceitaDespesaException.java | 13 ++ .../dao/Totalbus.java | 126 +++++++++++++++++- .../entidades/DespesaReceita.java | 46 +++---- .../entidades/DespesaReceitaComporte.java | 54 ++++++++ 5 files changed, 219 insertions(+), 32 deletions(-) create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java diff --git a/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java b/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java index 9d208da46..7b8c373df 100644 --- a/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java +++ b/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java @@ -30,6 +30,7 @@ public class BGMApplication { private static final int TAMANHO_BUFFER = 4096; // 4kb + private boolean isReceitasDespesasComporte; private BGMApplication(){ @@ -71,7 +72,12 @@ public class BGMApplication { return props; } - public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM) throws IllegalArgumentException{ + public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte) throws IllegalArgumentException, IntegracaoReceitaDespesaException{ + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM); + } + + public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM) throws IllegalArgumentException, IntegracaoReceitaDespesaException{ if (empresaId == null){ throw new IllegalArgumentException("o parâmetro empesaId é obrigatório!"); } @@ -79,7 +85,7 @@ public class BGMApplication { throw new IllegalArgumentException("o parâmetro puntoVentaId é obrigatório!"); } excluirArquivosZip(diretorio); - Totalbus totalbus = new Totalbus(con); + Totalbus totalbus = new Totalbus(con, isReceitasDespesasComporte); if (totalbus.isConstanteBloqueioMenorQueData(empresaId, dataFinal)){ totalbus.updateDataBloqueio(empresaId, dataFinal); } @@ -116,6 +122,8 @@ public class BGMApplication { compactarArquivos(files, fileZip); return fileZip; + } catch (IntegracaoReceitaDespesaException e){ + throw e; } catch (Exception e) { log.error("", e); return ""; diff --git a/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java b/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java new file mode 100644 index 000000000..7c1e71722 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java @@ -0,0 +1,13 @@ +package com.rjconsultores.integracaoreceitadespesa; + +public class IntegracaoReceitaDespesaException extends Exception{ + + /** + * + */ + private static final long serialVersionUID = -5422391379643449955L; + + public IntegracaoReceitaDespesaException(String message) { + super(message); + } +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java b/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java index d121a48e8..5eaab8e76 100644 --- a/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java +++ b/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java @@ -14,7 +14,9 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import com.rjconsultores.integracaoreceitadespesa.IntegracaoReceitaDespesaException; import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceita; +import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceitaComporte; import com.rjconsultores.integracaoreceitadespesa.entidades.Empresa; import com.rjconsultores.integracaoreceitadespesa.entidades.PuntoVenta; @@ -28,21 +30,28 @@ public class Totalbus { private List pontosVenda = new ArrayList(); private List empresas = new ArrayList(); + private Boolean isReceitasDespesasComporte = false; + private DecimalFormat df = new DecimalFormat("#0.00"); - public Totalbus(Connection con) { + public Totalbus(Connection con, Boolean isReceitasDespesasComporte) { this.conn = con; + this.isReceitasDespesasComporte = isReceitasDespesasComporte; loadEmpresas(); loadPuntosVenta(); } - public List getDespesasReceitas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) { + public List getDespesasReceitas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException{ log.debug("gerando depósitos..."); List despesasReceitas = getDepositos(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM); log.debug("gerando despesas..."); despesasReceitas.addAll(getDespesas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); log.debug("gerando despesas cartão..."); - despesasReceitas.addAll(getDespesaCartaoDebCred(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + if (!isReceitasDespesasComporte){ + despesasReceitas.addAll(getDespesaCartaoDebCred(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + } else { + despesasReceitas.addAll(getDespesaCartaoDebCredComporte(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + } log.debug("gerando receitas..."); despesasReceitas.addAll(getReceitas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); @@ -116,7 +125,7 @@ public class Totalbus { return this.conn; } - public List getDespesaCartaoDebCred(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) { + public List getDespesaCartaoDebCred(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException{ List despesas = new ArrayList(); StringBuilder sb = new StringBuilder(); sb.append(" select "); @@ -185,6 +194,7 @@ public class Totalbus { } } catch (Exception e) { log.error(e.toString(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Despesas Cartão Crédito/Débito"); } finally { try { rs.close(); @@ -200,13 +210,106 @@ public class Totalbus { return despesas; } + public List getDespesaCartaoDebCredComporte(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException{ + List despesas = new ArrayList(); + StringBuilder sb = new StringBuilder(); + sb.append(" select "); + sb.append(" cd.feccorte AS fechorvta, "); + sb.append(" e.empresa_id AS empresa, "); + sb.append(" pv.puntoventa_id AS puntoventaId, "); + sb.append(" sum(cdp.importe) AS valor, "); + sb.append(" tee.contacontabil AS contacontabil, "); + sb.append(" pv.numpuntoventa AS numpuntoventa, "); + sb.append(" ev.tipoeventoextra_id, "); + sb.append(" cdp.formapago_id as formapagoId, "); + sb.append(" ct.numautorizacion as numautorizacion, "); + sb.append(" pte.numsitef as numeroEstabelecimento "); + sb.append(" from "); + sb.append(" caja_diversos cd "); + sb.append(" left join evento_extra ev on ev.eventoextra_id = cd.eventoextra_id "); + sb.append(" left join empresa e on e.empresa_id = ev.empresa_id "); + sb.append(" left join punto_venta pv on pv.puntoventa_id = cd.puntoventa_id "); + sb.append(" left join caja_diversos_pago cdp on cdp.cajadiversos_id = cd.cajadiversos_id "); + sb.append(" left join tipo_evento_extra tee on tee.tipoeventoextra_id = ev.tipoeventoextra_id "); + sb.append(" left join ptovta_integra pi on e.empresa_id = pi.empresa_id and pi.puntoventa_id = pv.puntoventa_id "); + sb.append(" left join caja_tarjeta ct on ct.cajatarjeta_id = cdp.cajatarjeta_id "); + sb.append(" left join ptovta_empresa pte on pte.puntoventa_id = pv.puntoventa_id and pte.empresa_id = e.empresa_id "); + sb.append(" where "); + sb.append(" cd.feccorte = ? "); + adicionaFiltroQuery(puntoVentaId, sb, " and cd.puntoventa_id = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + adicionaFiltroQuery(empresaId, sb, " and e.empresa_id = ", empresaId != null); + sb.append(" and cd.activo = 1 "); + sb.append(" and cdp.formapago_id in (2,3) "); + sb.append(" group by "); + sb.append(" cd.feccorte, "); + sb.append(" e.empresa_id, "); + sb.append(" pv.puntoventa_id, "); + sb.append(" tee.contacontabil, "); + sb.append(" pv.numpuntoventa, ev.tipoeventoextra_id, "); + sb.append(" cdp.formapago_id, "); + sb.append(" ct.numautorizacion, "); + sb.append(" pte.numsitef "); + + PreparedStatement stmt = null; + ResultSet rs = null; + + Date fecha = fechaParam; + if (fechaParam == null) { + fecha = getData(); + } + + try { + stmt = getConnection().prepareStatement(sb.toString()); + stmt.setDate(1, new java.sql.Date(fecha.getTime())); + rs = stmt.executeQuery(); + + while (rs.next()) { + DespesaReceitaComporte despesa = new DespesaReceitaComporte(); + despesa.setCodigoEmpresa(rs.getInt(2)); + despesa.setCodigoReceitaDespesa(rs.getString(5)); + despesa.setDataLancamento(rs.getDate(1)); + despesa.setDataMovimento(rs.getDate(1)); + despesa.setLocalArrecadacao(rs.getString(6)); + if (rs.getBigDecimal(4).signum() == -1) { + despesa.setIdentificadorReceitaDespesa("R"); + despesa.setValorLancamento(df.format(rs.getBigDecimal(4).multiply(new BigDecimal(-1)))); + } else { + despesa.setIdentificadorReceitaDespesa("D"); + despesa.setValorLancamento(df.format(rs.getBigDecimal(4))); + } + if (incluiTipoPagamentoTurismoBGM) { + despesa.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id")); + } + despesa.setFormaPagamentoId(rs.getString("formapagoId")); + despesa.setCodigoAutorizacao(rs.getString("numautorizacion")); + despesa.setNumeroEstabelecimento(rs.getString("numeroEstabelecimento")); + despesas.add(despesa); + } + } catch (Exception e) { + log.error(e.toString(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Despesas Cartão Crédito/Débito"); + } finally { + try { + rs.close(); + } catch (Exception ignore) { + log.error("", ignore); + } + try { + stmt.close(); + } catch (Exception ignore) { + log.error("", ignore); + } + } + return despesas; + } + private void adicionaFiltroQuery(final Integer valor, StringBuilder sb, String filtroSQL, Boolean adicionar) { if (adicionar) { sb.append(filtroSQL + valor); } } - public List getReceitas(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) { + public List getReceitas(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { List despesas = new ArrayList(); StringBuilder sb = new StringBuilder(); sb.append(" select "); @@ -275,6 +378,7 @@ public class Totalbus { } } catch (Exception e) { log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Receitas"); } finally { try { rs.close(); @@ -290,7 +394,7 @@ public class Totalbus { return despesas; } - public List getDespesas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) { + public List getDespesas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { List despesas = new ArrayList(); StringBuilder sb = new StringBuilder(); sb.append(" select "); @@ -350,6 +454,7 @@ public class Totalbus { } } catch (Exception e) { log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Despesas"); } finally { try { rs.close(); @@ -365,7 +470,7 @@ public class Totalbus { return despesas; } - public List getDepositos(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) { + public List getDepositos(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { List depositos = new ArrayList(); StringBuilder strFechamentos = new StringBuilder(); @@ -439,6 +544,7 @@ public class Totalbus { log.debug("Total depósitos: " + soma); } catch (Exception e) { log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Depósitos"); } finally { try { pstmtFechamentos.close(); @@ -568,4 +674,10 @@ public class Totalbus { public void setEmpresas(List empresas) { this.empresas = empresas; } + + public void setIsReceitasDespesasComporte(Boolean isReceitasDespesasComporte) { + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + } + + } diff --git a/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java index 2d5e80ac3..3fdd2c8b4 100644 --- a/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java +++ b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java @@ -7,29 +7,29 @@ import java.util.List; import org.apache.commons.lang.StringUtils; public class DespesaReceita { - private String dataLancamento; // DD/MM/YYYY - private String codigoEmpresa; // 011 003 Numérico - private final String codigoFilial = "001"; // 014 003 Numérico - private String localArrecadação; // 017 005 Alfanumérico - private final String numeroDaGuia = " "; // 022 025 Alfanumérico - private String dataMovimento; // 047 010 Alfanumérico - private final String usuarioGlobus = "TOTALBUS ";// 057 015 Alfanumérico - private final String turno = "01";// 072 002 Numérico - private String codigoReceitaDespesa;// 074 010 Numérico CONSTANTE CODIGO_RECEITA_DESPESA_GLOBUS - private String identificadorReceitaDespesa;// 084 001 Alfanumérico - private String valorLancamento;// 085 013 Numérico - private final String numeroContratoTurismo = "0000000000";// 098 010 Numérico - private final String numeroReciboTurismo = " ";// 108 010 Alfanumérico - private final String formaPagamentoTurismo = "00";// 118 002 Numérico - private String tipoPagamentoTurismo = "00";// 120 002 Numérico - private String descricaoDetalhada = " ";// 122 100 Alfanumérico - private final String documentoVenda = "000000";// 222 6 Numérico - private final String tipoDocumentoVenda = " ";// 228 1 Alfanumérico - private final String numerodocumentoCPG = "0000000000";// 229 10 Numérico - private final String finalLinha = "*";// 239 1 Alfanumérico - private String formaPagamentoId = "";// 240 Numérico + protected String dataLancamento; // DD/MM/YYYY + protected String codigoEmpresa; // 011 003 Numérico + protected final String codigoFilial = "001"; // 014 003 Numérico + protected String localArrecadação; // 017 005 Alfanumérico + protected final String numeroDaGuia = " "; // 022 025 Alfanumérico + protected String dataMovimento; // 047 010 Alfanumérico + protected final String usuarioGlobus = "TOTALBUS ";// 057 015 Alfanumérico + protected final String turno = "01";// 072 002 Numérico + protected String codigoReceitaDespesa;// 074 010 Numérico CONSTANTE CODIGO_RECEITA_DESPESA_GLOBUS + protected String identificadorReceitaDespesa;// 084 001 Alfanumérico + protected String valorLancamento;// 085 013 Numérico + protected final String numeroContratoTurismo = "0000000000";// 098 010 Numérico + protected final String numeroReciboTurismo = " ";// 108 010 Alfanumérico + protected final String formaPagamentoTurismo = "00";// 118 002 Numérico + protected String tipoPagamentoTurismo = "00";// 120 002 Numérico + protected String descricaoDetalhada = " ";// 122 100 Alfanumérico + protected final String documentoVenda = "000000";// 222 6 Numérico + protected final String tipoDocumentoVenda = " ";// 228 1 Alfanumérico + protected final String numerodocumentoCPG = "0000000000";// 229 10 Numérico + protected final String finalLinha = "*";// 239 1 Alfanumérico + protected String formaPagamentoId = "";// 240 Numérico - private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + protected SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); public DespesaReceita() { @@ -118,7 +118,7 @@ public class DespesaReceita { this.formaPagamentoId = formaPagamentoId; } - private String truncStr(String str, int size) { + protected String truncStr(String str, int size) { if (str.length() > size) { return str.substring(0, size - 1); } diff --git a/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java new file mode 100644 index 000000000..c33303789 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java @@ -0,0 +1,54 @@ +package com.rjconsultores.integracaoreceitadespesa.entidades; + +import java.util.List; + +import org.apache.commons.lang.StringUtils; + +public class DespesaReceitaComporte extends DespesaReceita { + + protected String numeroEstabelecimento; + protected String codigoAutorizacao; + + @Override + public void preencheLinha(List rows) { + StringBuilder sb = new StringBuilder(); + sb.append(dataLancamento); + sb.append(codigoEmpresa); + sb.append(codigoFilial); + sb.append(localArrecadação.toUpperCase()); + sb.append(numeroDaGuia); + sb.append(dataMovimento); + sb.append(usuarioGlobus); + sb.append(turno); + sb.append(codigoReceitaDespesa); + sb.append(identificadorReceitaDespesa.toUpperCase()); + sb.append(valorLancamento); + sb.append(numeroContratoTurismo); + sb.append(numeroReciboTurismo); + sb.append(getFormaPagamentoTurismo()); + sb.append(getTipoPagamentoTurismo()); + sb.append(descricaoDetalhada); + sb.append(numeroEstabelecimento); + sb.append(codigoAutorizacao); + sb.append(formaPagamentoId); + sb.append(finalLinha); + sb.append(System.getProperty("line.separator")); + rows.add(sb.toString()); + } + + public String getNumeroEstabelecimento() { + return numeroEstabelecimento; + } + + public void setNumeroEstabelecimento(String numeroEstabelecimento) { + this.numeroEstabelecimento = StringUtils.leftPad(numeroEstabelecimento != null ? numeroEstabelecimento : "", 10, "0"); + } + + public String getCodigoAutorizacao() { + return codigoAutorizacao; + } + + public void setCodigoAutorizacao(String codigoAutorizacao) { + this.codigoAutorizacao = StringUtils.rightPad(codigoAutorizacao != null ? truncStr(codigoAutorizacao, 22) : "", 22, " "); + } +}