leonardo 2015-11-06 19:16:14 +00:00
parent 571f4bbbfc
commit a579c85543
5 changed files with 52 additions and 56 deletions

View File

@ -2,6 +2,8 @@ package com.rjconsultores.integracaoreceitadespesa;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties; import java.util.Properties;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -15,6 +17,25 @@ public class Application {
} }
public Connection getConnection(){
try {
Properties props = Application.getInstance().getApplicationProperties();
String DRIVER = "oracle.jdbc.driver.OracleDriver";
Class.forName(DRIVER);
Connection conn = DriverManager.getConnection(
props.getProperty("url"),
props.getProperty("username").trim(),
props.getProperty("password").trim());
return conn;
} catch (Exception e){
log.error("", e);
return null;
}
}
public static Application getInstance(){ public static Application getInstance(){
if (instance == null){ if (instance == null){
instance = new Application(); instance = new Application();

View File

@ -23,31 +23,27 @@ public class Totalbus {
private static final Logger log = Logger.getLogger(Totalbus.class); private static final Logger log = Logger.getLogger(Totalbus.class);
private static final int DAYS_AGO = -1; private static final int DAYS_AGO = -1;
private static Totalbus instance = null;
private Connection conn; private Connection conn;
private List<PuntoVenta> pontosVenda = new ArrayList<PuntoVenta>(); private List<PuntoVenta> pontosVenda = new ArrayList<PuntoVenta>();
private List<Empresa> empresas = new ArrayList<Empresa>(); private List<Empresa> empresas = new ArrayList<Empresa>();
private Totalbus(){ public Totalbus(Connection con){
try { this.conn = con;
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(); loadEmpresas();
loadPuntosVenta(); loadPuntosVenta();
} catch (Exception e){
log.error("", e);
} }
public List<String> getDespesasReceitas(Integer puntoventaId, Integer empresaId){
List<DespesaReceita> despesasReceitas = getDepositos(puntoventaId, empresaId);
despesasReceitas.addAll(getDespesas(puntoventaId, empresaId));
despesasReceitas.addAll(getReceitas(puntoventaId, empresaId));
List<String> rows = new ArrayList<String>();
for (DespesaReceita item : despesasReceitas){
item.preencheLinha(rows);
}
return rows;
} }
private void loadPuntosVenta(){ private void loadPuntosVenta(){
@ -92,13 +88,6 @@ public class Totalbus {
} }
} }
public static Totalbus getInstance(){
if (instance == null){
instance = new Totalbus();
}
return instance;
}
public Connection getConnection(){ public Connection getConnection(){
return this.conn; return this.conn;
} }
@ -107,13 +96,6 @@ public class Totalbus {
List<DespesaReceita> despesas = new ArrayList<DespesaReceita>(); List<DespesaReceita> despesas = new ArrayList<DespesaReceita>();
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(" select "); sb.append(" select ");
sb.append(" tmp.fechorvta, ");
sb.append(" tmp.empresa, ");
sb.append(" tmp.puntoventaId, ");
sb.append(" sum(tmp.valor), ");
sb.append(" tmp.contacontabil ");
sb.append(" from ( ");
sb.append(" select ");
sb.append(" cd.feccorte AS fechorvta, "); sb.append(" cd.feccorte AS fechorvta, ");
sb.append(" e.empresa_id AS empresa, "); sb.append(" e.empresa_id AS empresa, ");
sb.append(" pv.puntoventa_id AS puntoventaId, "); sb.append(" pv.puntoventa_id AS puntoventaId, ");
@ -137,19 +119,12 @@ public class Totalbus {
} }
sb.append(" and cd.activo = 1 "); sb.append(" and cd.activo = 1 ");
sb.append(" and tee.indtipo = 1 "); sb.append(" and tee.indtipo = 1 ");
sb.append(" and cdp.formapago_id in (1,10) "); //sb.append(" and cd.usuario_id=7061 ");
sb.append(" group by "); sb.append(" group by ");
sb.append(" cd.feccorte, "); sb.append(" cd.feccorte, ");
sb.append(" e.empresa_id, "); sb.append(" e.empresa_id, ");
sb.append(" pv.puntoventa_id, "); sb.append(" pv.puntoventa_id, ");
sb.append(" tee.contacontabil "); sb.append(" tee.contacontabil ");
sb.append(" ) tmp ");
sb.append(" ");
sb.append(" group by ");
sb.append(" tmp.fechorvta, ");
sb.append(" tmp.empresa, ");
sb.append(" tmp.puntoventaId, ");
sb.append(" tmp.contacontabil ");
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -209,6 +184,7 @@ public class Totalbus {
sb.append(" and e.empresa_id = " + empresaId); sb.append(" and e.empresa_id = " + empresaId);
} }
sb.append(" and cd.activo = 1 "); sb.append(" and cd.activo = 1 ");
//sb.append(" and cd.usuario_id=7061 ");
sb.append(" and not exists (select ee.EVENTOEXTRA_ID from evento_extra ee where ev.EVENTOEXTRA_ID = ee.EVENTOEXTRACANC_ID) "); sb.append(" and not exists (select ee.EVENTOEXTRA_ID from evento_extra ee where ev.EVENTOEXTRA_ID = ee.EVENTOEXTRACANC_ID) ");
sb.append(" and ev.EVENTOEXTRACANC_ID is null "); sb.append(" and ev.EVENTOEXTRACANC_ID is null ");
@ -250,6 +226,7 @@ public class Totalbus {
sb.append("from fechamento_cntcorrente fc "); sb.append("from fechamento_cntcorrente fc ");
sb.append("inner join fechamento_cct_deposito fd on fd.fechamentocntcorrente_id = fc.fechamentocntcorrente_id "); 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 "); sb.append("where fc.fecfechamento = :fecha and fd.activo <> 0 and fc.activo <> 0 ");
if (puntoventaId != null){ if (puntoventaId != null){
sb.append("and fc.puntoventa_id = :puntoventaId "); sb.append("and fc.puntoventa_id = :puntoventaId ");
} }
@ -274,6 +251,7 @@ public class Totalbus {
} }
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
Integer codigoReceitaDespesaGlobus = getCodigoReceitaDespesaGlobus();
while (rs.next()){ while (rs.next()){
DespesaReceita deposito = new DespesaReceita(); DespesaReceita deposito = new DespesaReceita();
deposito.setCodigoEmpresa(rs.getInt(2)); deposito.setCodigoEmpresa(rs.getInt(2));
@ -283,6 +261,7 @@ public class Totalbus {
deposito.setLocalArrecadação(rs.getInt(3)); deposito.setLocalArrecadação(rs.getInt(3));
deposito.setValorLançamento(rs.getBigDecimal(4).toString()); deposito.setValorLançamento(rs.getBigDecimal(4).toString());
deposito.setIdentificadorReceitaDespesa("R"); deposito.setIdentificadorReceitaDespesa("R");
deposito.setCodigoReceitaDespesa(codigoReceitaDespesaGlobus);
depositos.add(deposito); depositos.add(deposito);
} }
} catch (Exception e){ } catch (Exception e){

View File

@ -31,7 +31,7 @@ public class DespesaReceita {
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
public DespesaReceita(){ public DespesaReceita(){
setCodigoReceitaDespesa(Totalbus.getInstance().getCodigoReceitaDespesaGlobus());
} }
public void preencheLinha(List<String> rows){ public void preencheLinha(List<String> rows){

View File

@ -16,6 +16,7 @@ import javax.swing.WindowConstants;
import javax.swing.event.MenuEvent; import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener; import javax.swing.event.MenuListener;
import com.rjconsultores.integracaoreceitadespesa.Application;
import com.rjconsultores.integracaoreceitadespesa.Arquivo; import com.rjconsultores.integracaoreceitadespesa.Arquivo;
import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus;
import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceita; import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceita;
@ -102,14 +103,6 @@ public class FrmMain extends javax.swing.JFrame implements MenuListener {
int answer = JOptionPane.showConfirmDialog(null, pnl, "Executar Exportação", JOptionPane.OK_CANCEL_OPTION); int answer = JOptionPane.showConfirmDialog(null, pnl, "Executar Exportação", JOptionPane.OK_CANCEL_OPTION);
if (answer == JOptionPane.OK_OPTION) { if (answer == JOptionPane.OK_OPTION) {
List<DespesaReceita> despesasReceitas = Totalbus.getInstance().getDepositos(pnl.getPuntoventa(), pnl.getEmpresa());
despesasReceitas.addAll(Totalbus.getInstance().getDespesas(pnl.getPuntoventa(), pnl.getEmpresa()));
despesasReceitas.addAll(Totalbus.getInstance().getReceitas(pnl.getPuntoventa(), pnl.getEmpresa()));
List<String> rows = new ArrayList<String>();
for (DespesaReceita item : despesasReceitas){
item.preencheLinha(rows);
}
this.setCursor(new Cursor(Cursor.WAIT_CURSOR)); this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
final JFileChooser fc = new JFileChooser(); final JFileChooser fc = new JFileChooser();
@ -117,8 +110,8 @@ public class FrmMain extends javax.swing.JFrame implements MenuListener {
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile(); File file = fc.getSelectedFile();
Arquivo arquivo = new Arquivo(); Totalbus totalbus = new Totalbus(Application.getInstance().getConnection());
arquivo.GravaArquivo(file.getAbsolutePath(), rows); Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(pnl.getPuntoventa(), pnl.getEmpresa()));
} }
} else { } else {
JOptionPane.showMessageDialog(null, "Operação cancelada pelo usuário"); JOptionPane.showMessageDialog(null, "Operação cancelada pelo usuário");

View File

@ -9,6 +9,7 @@ import javax.swing.WindowConstants;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.rjconsultores.integracaoreceitadespesa.Application;
import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus;
import com.rjconsultores.integracaoreceitadespesa.entidades.Empresa; import com.rjconsultores.integracaoreceitadespesa.entidades.Empresa;
import com.rjconsultores.integracaoreceitadespesa.entidades.PuntoVenta; import com.rjconsultores.integracaoreceitadespesa.entidades.PuntoVenta;
@ -36,6 +37,8 @@ public class PnlPeriodo extends javax.swing.JPanel {
private JLabel lblEmpresa; private JLabel lblEmpresa;
private JComboBox txtEmpresa; private JComboBox txtEmpresa;
private Totalbus totalbus = new Totalbus(Application.getInstance().getConnection());
/** /**
* Auto-generated main method to display this * Auto-generated main method to display this
* JPanel inside a new JFrame. * JPanel inside a new JFrame.
@ -80,7 +83,7 @@ public class PnlPeriodo extends javax.swing.JPanel {
public JComboBox getTxtPuntoventa() { public JComboBox getTxtPuntoventa() {
if (txtPuntoventa == null){ if (txtPuntoventa == null){
txtPuntoventa = new JComboBox(new DefaultComboBoxModel(Totalbus.getInstance().getPontosVenda().toArray())); txtPuntoventa = new JComboBox(new DefaultComboBoxModel(totalbus.getPontosVenda().toArray()));
txtPuntoventa.setBounds(105, 9, 308, 23); txtPuntoventa.setBounds(105, 9, 308, 23);
} }
return txtPuntoventa; return txtPuntoventa;
@ -97,7 +100,7 @@ public class PnlPeriodo extends javax.swing.JPanel {
public JComboBox getTxtEmpresa() { public JComboBox getTxtEmpresa() {
if (txtEmpresa == null){ if (txtEmpresa == null){
txtEmpresa = new JComboBox(new DefaultComboBoxModel(Totalbus.getInstance().getEmpresas().toArray())); txtEmpresa = new JComboBox(new DefaultComboBoxModel(totalbus.getEmpresas().toArray()));
txtEmpresa.setBounds(105, 37, 308, 23); txtEmpresa.setBounds(105, 37, 308, 23);
} }
return txtEmpresa; return txtEmpresa;