leonardo 2016-03-23 18:56:21 +00:00
parent 202bea1cd3
commit 132ec5bef7
1 changed files with 48 additions and 47 deletions

View File

@ -306,14 +306,14 @@ public class Totalbus {
public List<DespesaReceita> getDepositos(Integer puntoventaId, Integer empresaId, Date fechaParam){ public List<DespesaReceita> getDepositos(Integer puntoventaId, Integer empresaId, Date fechaParam){
List<DespesaReceita> depositos = new ArrayList<DespesaReceita>(); List<DespesaReceita> depositos = new ArrayList<DespesaReceita>();
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
sb.append("select fdep.fechamentodeposito_id, fdep.valor, fdep.numdeposito, fdep.FECCREACION "); // sb.append("select fdep.fechamentodeposito_id, fdep.valor, fdep.numdeposito, fdep.FECCREACION, fdep.fecha_deposito ");
sb.append("from fechamento_deposito fdep "); // sb.append("from fechamento_deposito fdep ");
sb.append("where trunc(FECCREACION) = :fecha and fdep.activo = 1 "); // sb.append("where trunc(FECCREACION) = :fecha and fdep.activo = 1 ");
StringBuilder strFechamentos = new StringBuilder(); StringBuilder strFechamentos = new StringBuilder();
strFechamentos.append("Select fc.fecfechamento, fc.empresa_id, pv.numpuntoventa, fd.valor_pago, ec.numagencia, ec.numconta, if.CODIGO, ec.numintegracion "); strFechamentos.append("Select sum(fdep.valor), fdep.numdeposito, fdep.fecha_deposito, fc.empresa_id, pv.numpuntoventa, ec.numagencia, ec.numconta, if.CODIGO, ec.numintegracion ");
strFechamentos.append(" from fechamento_deposito fdep "); strFechamentos.append(" from fechamento_deposito fdep ");
strFechamentos.append(" join fechamento_cct_deposito fd on fd.fechamentodeposito_id = fdep.fechamentodeposito_id "); strFechamentos.append(" join fechamento_cct_deposito fd on fd.fechamentodeposito_id = fdep.fechamentodeposito_id ");
strFechamentos.append(" join fechamento_cntcorrente fc on fc.fechamentocntcorrente_id = fd.fechamentocntcorrente_id "); strFechamentos.append(" join fechamento_cntcorrente fc on fc.fechamentocntcorrente_id = fd.fechamentocntcorrente_id ");
@ -321,7 +321,7 @@ public class Totalbus {
strFechamentos.append(" join empresa_contabancaria ec on ec.EMPRESACONTABANCARIA_ID = fdep.EMPRESACONTABANCARIA_ID "); strFechamentos.append(" join empresa_contabancaria ec on ec.EMPRESACONTABANCARIA_ID = fdep.EMPRESACONTABANCARIA_ID ");
strFechamentos.append(" join INSTI_FINANCEIRA if on if.INSTIFINANCEIRA_ID = EC.INSTIFINANCEIRA_ID "); strFechamentos.append(" join INSTI_FINANCEIRA if on if.INSTIFINANCEIRA_ID = EC.INSTIFINANCEIRA_ID ");
strFechamentos.append(" join EMPRESA e on e.empresa_id = fc.empresa_id "); strFechamentos.append(" join EMPRESA e on e.empresa_id = fc.empresa_id ");
strFechamentos.append(" where fd.fechamentodeposito_id = :fechamentodepositoId and fd.activo <> 0 and fc.activo <> 0 "); strFechamentos.append(" where trunc(fdep.feccreacion) = :fecha and fd.activo = 1 and fc.activo = 1 ");
if (puntoventaId != null && !puntoventaId.equals(-1)){ if (puntoventaId != null && !puntoventaId.equals(-1)){
strFechamentos.append(" and fc.puntoventa_id = " + puntoventaId); strFechamentos.append(" and fc.puntoventa_id = " + puntoventaId);
@ -329,73 +329,74 @@ public class Totalbus {
if (empresaId != null){ if (empresaId != null){
strFechamentos.append(" and fc.empresa_id = " + empresaId); strFechamentos.append(" and fc.empresa_id = " + empresaId);
} }
strFechamentos.append(" group by fdep.numdeposito, fdep.fecha_deposito, fc.empresa_id, pv.numpuntoventa, ec.numagencia, ec.numconta, if.CODIGO, ec.numintegracion ");
Date fecha = fechaParam; Date fecha = fechaParam;
if(fechaParam == null){ if(fechaParam == null){
fecha = getData(); fecha = getData();
} }
PreparedStatement pstmt = null; //PreparedStatement pstmt = null;
ResultSet rs = null; //ResultSet rs = null;
try{
pstmt = getConnection().prepareStatement(sb.toString());
pstmt.setDate(1, new java.sql.Date(fecha.getTime()));
rs = pstmt.executeQuery(); // pstmt = getConnection().prepareStatement(sb.toString());
// pstmt.setDate(1, new java.sql.Date(fecha.getTime()));
//
// rs = pstmt.executeQuery();
Integer codigoReceitaDespesaGlobus = getCodigoReceitaDespesaGlobus(); Integer codigoReceitaDespesaGlobus = getCodigoReceitaDespesaGlobus();
SimpleDateFormat sdf = new SimpleDateFormat("MM/yy"); SimpleDateFormat sdf = new SimpleDateFormat("MM/yy");
PreparedStatement pstmtFechamentos = getConnection().prepareStatement(strFechamentos.toString()); PreparedStatement pstmtFechamentos = null;
ResultSet rsFechamentos = null;
BigDecimal soma = BigDecimal.ZERO; BigDecimal soma = BigDecimal.ZERO;
try{
// while (rs.next()){
pstmtFechamentos = getConnection().prepareStatement(strFechamentos.toString());
pstmtFechamentos.setDate(1, new java.sql.Date(fecha.getTime()));
while (rs.next()){ rsFechamentos = pstmtFechamentos.executeQuery();
pstmtFechamentos.setInt(1, rs.getInt(1));
ResultSet rsFechamentos = pstmtFechamentos.executeQuery();
Integer empId = null;
Integer pvId = null;
String banco = "" ;
String agencia = "";
String contaCorrente = "";
String numDep = " Dep: " + rs.getString(3);
String valor = " R$ " + df.format(rs.getBigDecimal(2));
String ref = " Ref: ";
Integer codRecDesp = null;
Boolean podeAdicionar = false;
while (rsFechamentos.next()){ while (rsFechamentos.next()){
podeAdicionar = true; Integer empId = null;
if (empId == null ){ empId = rsFechamentos.getInt(2); } Integer pvId = null;
if (banco.isEmpty()){banco = "Bco: " + DespesaReceita.lpad(rsFechamentos.getString(7), "0", 3);} String banco = "" ;
if (pvId == null){ pvId = rsFechamentos.getInt(3); } String agencia = "";
if (agencia.isEmpty()){ agencia = " Ag: " + rsFechamentos.getString(5); } String contaCorrente = "";
if (contaCorrente.isEmpty()){ contaCorrente = " C/C: " + rsFechamentos.getString(6); } String numDep = " Dep: " + rsFechamentos.getString(2);
ref += ref.length() <= 6 ? sdf.format(rsFechamentos.getDate(1)) : ", " + sdf.format(rsFechamentos.getDate(1)); String valor = " R$ " + df.format(rsFechamentos.getBigDecimal(1));
if (codRecDesp == null){ codRecDesp = rsFechamentos.getInt(8); } String ref = " Ref: ";
} Integer codRecDesp = null;
if (empId == null ){ empId = rsFechamentos.getInt(4); }
if (banco.isEmpty()){banco = "Bco: " + DespesaReceita.lpad(rsFechamentos.getString(8), "0", 3);}
if (pvId == null){ pvId = rsFechamentos.getInt(5); }
if (agencia.isEmpty()){ agencia = " Ag: " + rsFechamentos.getString(6); }
if (contaCorrente.isEmpty()){ contaCorrente = " C/C: " + rsFechamentos.getString(7); }
//ref += ref.length() <= 6 ? sdf.format(rsFechamentos.getDate(3)) : ", " + sdf.format(rsFechamentos.getDate(3));
if (codRecDesp == null){ codRecDesp = rsFechamentos.getInt(9); }
if (podeAdicionar){ // se não tiver dados da subquery não é um depósito válido.
DespesaReceita deposito = new DespesaReceita(); DespesaReceita deposito = new DespesaReceita();
deposito.setCodigoEmpresa(empId); deposito.setCodigoEmpresa(empId);
deposito.setDataLancamento(rs.getDate(4)); deposito.setDataLancamento(rsFechamentos.getDate(3));
deposito.setDataMovimento(rs.getDate(4)); deposito.setDataMovimento(rsFechamentos.getDate(3));
deposito.setLocalArrecadação(pvId); deposito.setLocalArrecadação(pvId);
deposito.setValorLancamento(df.format(rs.getBigDecimal(2))); deposito.setValorLancamento(df.format(rsFechamentos.getBigDecimal(1)));
deposito.setIdentificadorReceitaDespesa("D"); deposito.setIdentificadorReceitaDespesa("D");
deposito.setCodigoReceitaDespesa(codRecDesp); deposito.setCodigoReceitaDespesa(codRecDesp);
deposito.setDescricaoDetalhada(banco + agencia + contaCorrente + numDep + valor + ref); deposito.setDescricaoDetalhada(banco + agencia + contaCorrente + numDep + valor);
depositos.add(deposito); depositos.add(deposito);
soma = soma.add(rs.getBigDecimal(2)); soma = soma.add(rsFechamentos.getBigDecimal(1));
} }
}
log.debug("Total depósitos: " + soma); log.debug("Total depósitos: " + soma);
} catch (Exception e){ } catch (Exception e){
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} finally { } finally {
try { rs.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); } try { pstmtFechamentos.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { pstmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); } try { rsFechamentos.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
} }
return depositos; return depositos;
} }