196 lines
5.9 KiB
Java
196 lines
5.9 KiB
Java
package com.rjconsultores.integracaoreceitadespesa.dao;
|
||
|
||
import java.sql.Connection;
|
||
import java.sql.DriverManager;
|
||
import java.sql.PreparedStatement;
|
||
import java.sql.ResultSet;
|
||
import java.util.ArrayList;
|
||
import java.util.Calendar;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Properties;
|
||
|
||
import org.apache.log4j.Logger;
|
||
|
||
import com.rjconsultores.integracaoreceitadespesa.Application;
|
||
import com.rjconsultores.integracaoreceitadespesa.entidades.DepositoBean;
|
||
import com.rjconsultores.integracaoreceitadespesa.entidades.Empresa;
|
||
import com.rjconsultores.integracaoreceitadespesa.entidades.PuntoVenta;
|
||
|
||
|
||
public class Totalbus {
|
||
|
||
private static final Logger log = Logger.getLogger(Totalbus.class);
|
||
|
||
private static Totalbus instance = null;
|
||
|
||
private Connection conn;
|
||
|
||
private List<PuntoVenta> pontosVenda = new ArrayList<PuntoVenta>();
|
||
private List<Empresa> empresas = new ArrayList<Empresa>();
|
||
|
||
private Totalbus(){
|
||
try {
|
||
Properties props = Application.getInstance().getApplicationProperties();
|
||
|
||
String DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||
|
||
Class.forName(DRIVER);
|
||
this.conn = DriverManager.getConnection(
|
||
props.getProperty("url"),
|
||
props.getProperty("username").trim(),
|
||
props.getProperty("password").trim());
|
||
|
||
loadEmpresas();
|
||
loadPuntosVenta();
|
||
|
||
} catch (Exception e){
|
||
log.error("", e);
|
||
}
|
||
}
|
||
|
||
private void loadPuntosVenta(){
|
||
PreparedStatement pstmt = null;
|
||
ResultSet rs = null;
|
||
|
||
try{
|
||
pstmt = getConnection().prepareStatement("Select puntoventa_id, nombpuntoventa from punto_venta order by nombpuntoventa");
|
||
rs = pstmt.executeQuery();
|
||
while (rs.next()){
|
||
PuntoVenta puntoVenta = new PuntoVenta();
|
||
puntoVenta.codigo = rs.getInt(1);
|
||
puntoVenta.nombpuntoventa = rs.getString(2);
|
||
pontosVenda.add(puntoVenta);
|
||
}
|
||
} catch (Exception e){
|
||
log.error("", e);
|
||
} finally {
|
||
try { rs.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
try { pstmt.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
}
|
||
}
|
||
|
||
private void loadEmpresas(){
|
||
PreparedStatement pstmt = null;
|
||
ResultSet rs = null;
|
||
|
||
try{
|
||
pstmt = getConnection().prepareStatement("Select empresa_id, nombempresa from empresa order by nombempresa");
|
||
rs = pstmt.executeQuery();
|
||
while (rs.next()){
|
||
Empresa empresa = new Empresa();
|
||
empresa.codigo = rs.getInt(1);
|
||
empresa.nombempresa = rs.getString(2);
|
||
empresas.add(empresa);
|
||
}
|
||
} catch (Exception e){
|
||
log.error("", e);
|
||
} finally {
|
||
try { rs.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
try { pstmt.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
}
|
||
}
|
||
|
||
public static Totalbus getInstance(){
|
||
if (instance == null){
|
||
instance = new Totalbus();
|
||
}
|
||
return instance;
|
||
}
|
||
|
||
public Connection getConnection(){
|
||
return this.conn;
|
||
}
|
||
|
||
public List<DepositoBean> getDepositos(Integer puntoventaId, Integer empresaId){
|
||
List<DepositoBean> depositos = new ArrayList<DepositoBean>();
|
||
StringBuilder sb = new StringBuilder();
|
||
sb.append("Select fc.fecfechamento, fc.empresa_id, fc.puntoventa_id, fd.valor_pago, ");
|
||
sb.append("(select valorconstante from constante where nombconstante = 'CODIGO_RECEITA_DESPESA_GLOBUS') as codigoReceitaDespesa ");
|
||
sb.append("from fechamento_cntcorrente fc ");
|
||
sb.append("inner join fechamento_cct_deposito fd on fd.fechamentocntcorrente_id = fc.fechamentocntcorrente_id ");
|
||
sb.append("where fc.fecfechamento = :fecha and fd.activo <> 0 and fc.activo <> 0 ");
|
||
if (puntoventaId != null){
|
||
sb.append("and fc.puntoventa_id = :puntoventaId ");
|
||
}
|
||
if (empresaId != null){
|
||
sb.append("and fc.empresa_id = :empresaId ");
|
||
}
|
||
|
||
Calendar cal = Calendar.getInstance();
|
||
cal.setTime(new Date());
|
||
cal.add(Calendar.DAY_OF_MONTH, -3);
|
||
Date fecha = cal.getTime();
|
||
|
||
PreparedStatement pstmt = null;
|
||
ResultSet rs = null;
|
||
|
||
try{
|
||
pstmt = getConnection().prepareStatement(sb.toString());
|
||
pstmt.setDate(1, new java.sql.Date(fecha.getTime()));
|
||
if (puntoventaId != null){
|
||
pstmt.setInt(2, puntoventaId);
|
||
}
|
||
if (empresaId != null){
|
||
pstmt.setInt(3, empresaId);
|
||
}
|
||
|
||
rs = pstmt.executeQuery();
|
||
while (rs.next()){
|
||
DepositoBean deposito = new DepositoBean();
|
||
deposito.setCodigoEmpresa(rs.getInt(2));
|
||
deposito.setCodigoReceitaDespesa(rs.getInt(5));
|
||
deposito.setDataLancamento(rs.getDate(1));
|
||
deposito.setDataMovimento(rs.getDate(1));
|
||
deposito.setLocalArrecada<EFBFBD><EFBFBD>o(rs.getInt(3));
|
||
deposito.setValorLan<EFBFBD>amento(rs.getBigDecimal(4).toString());
|
||
depositos.add(deposito);
|
||
}
|
||
} catch (Exception e){
|
||
log.error("", e);
|
||
} finally {
|
||
try { rs.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
try { pstmt.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
}
|
||
return depositos;
|
||
}
|
||
|
||
public Integer getCodigoReceitaDespesaGlobus(){
|
||
StringBuilder sb = new StringBuilder();
|
||
sb.append("Select valorconstante from constante where nombconstante = 'CODIGO_RECEITA_DESPESA_GLOBUS' ");
|
||
PreparedStatement pstmt = null;
|
||
ResultSet rs = null;
|
||
Integer result = null;
|
||
try{
|
||
pstmt = getConnection().prepareStatement(sb.toString());
|
||
rs = pstmt.executeQuery();
|
||
if (rs.next()){
|
||
result = rs.getInt(1);
|
||
}
|
||
} catch (Exception e){
|
||
log.error("", e);
|
||
} finally {
|
||
try { rs.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
try { pstmt.close(); } catch (Exception ignore) { log.error("", ignore); }
|
||
}
|
||
return result;
|
||
|
||
}
|
||
|
||
public List<PuntoVenta> getPontosVenda() {
|
||
return pontosVenda;
|
||
}
|
||
|
||
public void setPontosVenda(List<PuntoVenta> pontosVenda) {
|
||
this.pontosVenda = pontosVenda;
|
||
}
|
||
|
||
public List<Empresa> getEmpresas() {
|
||
return empresas;
|
||
}
|
||
|
||
public void setEmpresas(List<Empresa> empresas) {
|
||
this.empresas = empresas;
|
||
}
|
||
}
|