Mas logs y actualizacion de los to string de las clases y por ello ademas se tuvo que cambiar el como se renderizaban los combobox de los tipo egreso y tipo ingreso

This commit is contained in:
Daniel Cortes
2019-01-20 20:11:57 -03:00
parent e6195786b6
commit 68f8dc029e
22 changed files with 168 additions and 345 deletions

View File

@@ -24,6 +24,7 @@
package danielcortes.xyz.models.efectivo;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
@@ -33,8 +34,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SQLiteEfectivoDAO extends EfectivoDAO {
private static final Logger LOGGER = Logger.getLogger(Configuration.class.getName());
public SQLiteEfectivoDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@@ -43,15 +48,18 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public List<Efectivo> findAll() {
List<Efectivo> efectivoList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select * from efectivos");
String query = "select * from efectivos";
PreparedStatement ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0}", query);
efectivoList = this.efectivosFromResultSet(rs);
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return efectivoList;
@@ -61,16 +69,19 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public Efectivo findById(int id) {
Efectivo efectivo = null;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?");
String query = "select * from efectivos where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
efectivo = this.efectivosFromResultSet(rs).get(0);
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return efectivo;
@@ -80,10 +91,13 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public Efectivo findByCaja(Caja caja) {
Efectivo efectivo = null;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
String query = "select * from efectivos where caja_id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
List<Efectivo> efectivoList = this.efectivosFromResultSet(rs);
if (efectivoList.size() > 0) {
efectivo = efectivoList.get(0);
@@ -92,7 +106,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return efectivo;
@@ -102,7 +116,8 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean insertEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)");
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
@@ -113,19 +128,26 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}] | updates: {11}", new Object[]{query, efectivo.getVeinteMil(), efectivo.getDiezMil(), efectivo.getCincoMil(), efectivo.getDosMil(), efectivo.getMil(), efectivo.getQuinientos(), efectivo.getCien(), efectivo.getCincuenta(), efectivo.getDiez(), efectivo.getCaja().getId(), updates});
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
query = "select last_insert_rowid()";
ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0}", query);
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -135,10 +157,13 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean insertDefaultEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)");
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getCaja().getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}", new Object[]{query, efectivo.getCaja().getId(), updates});
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
@@ -149,7 +174,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -159,7 +184,8 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean updateEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?");
String query = "update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
@@ -171,12 +197,14 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
ps.setInt(11, efectivo.getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}] | updates: {12}", new Object[]{query, efectivo.getVeinteMil(), efectivo.getDiezMil(), efectivo.getCincoMil(), efectivo.getDosMil(), efectivo.getMil(), efectivo.getQuinientos(), efectivo.getCien(), efectivo.getCincuenta(), efectivo.getDiez(), efectivo.getCaja().getId(), efectivo.getId(), updates});
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -186,14 +214,16 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public boolean deleteEfectivo(Efectivo efectivo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?");
String query = "delete from efectivos where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, efectivo.getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}", new Object[]{query, efectivo.getId(), updates});
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -203,9 +233,12 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
public int getTotalEfectivo(Caja caja) {
int total = 0;
try (Connection conn = connectionHolder.getConnection()) {
PreparedStatement ps = conn.prepareStatement("select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?");
String query = "select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?";
PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, caja.getId());
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
ResultSet rs = ps.executeQuery();
rs.next();
total = rs.getInt(1);
@@ -213,7 +246,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}