Se limpio el modelo de EfectivoDAO
Se llevaron a cabo los mismos pasos que en los previos;
This commit is contained in:
BIN
dist/Programa Caja.jar
vendored
BIN
dist/Programa Caja.jar
vendored
Binary file not shown.
@@ -75,7 +75,7 @@ public class ArqueoController extends BaseController {
|
|||||||
* Rellena los campos del efectivo con la instancia de efectivo que pertenece a la caja
|
* Rellena los campos del efectivo con la instancia de efectivo que pertenece a la caja
|
||||||
*/
|
*/
|
||||||
private void fillEfectivo() {
|
private void fillEfectivo() {
|
||||||
this.efectivo = DAOManager.getEfectivoDAO().findByCaja(this.caja);
|
this.efectivo = DAOManager.getEfectivoDAO().findByCaja(this.caja).orElse(Efectivo.EMPTY);
|
||||||
this.view.getVeinteMilField().setValue(efectivo.getVeinteMil());
|
this.view.getVeinteMilField().setValue(efectivo.getVeinteMil());
|
||||||
this.view.getDiezMilField().setValue(efectivo.getDiezMil());
|
this.view.getDiezMilField().setValue(efectivo.getDiezMil());
|
||||||
this.view.getCincoMilField().setValue(efectivo.getCincoMil());
|
this.view.getCincoMilField().setValue(efectivo.getCincoMil());
|
||||||
|
|||||||
@@ -27,7 +27,13 @@ package danielcortes.xyz.models.documentos;
|
|||||||
import danielcortes.xyz.models.caja.Caja;
|
import danielcortes.xyz.models.caja.Caja;
|
||||||
|
|
||||||
public class Documentos {
|
public class Documentos {
|
||||||
public final static Documentos EMPTY = new Documentos();
|
public final static Documentos EMPTY;
|
||||||
|
|
||||||
|
static{
|
||||||
|
EMPTY = new Documentos();
|
||||||
|
EMPTY.setCaja(Caja.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private int cheques;
|
private int cheques;
|
||||||
private int tarjetas;
|
private int tarjetas;
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ package danielcortes.xyz.models.efectivo;
|
|||||||
import danielcortes.xyz.models.caja.Caja;
|
import danielcortes.xyz.models.caja.Caja;
|
||||||
|
|
||||||
public class Efectivo {
|
public class Efectivo {
|
||||||
|
public final static Efectivo EMPTY;
|
||||||
|
|
||||||
|
static {
|
||||||
|
EMPTY = new Efectivo();
|
||||||
|
EMPTY.setCaja(Caja.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private int veinteMil;
|
private int veinteMil;
|
||||||
|
|||||||
@@ -24,62 +24,25 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.models.efectivo;
|
package danielcortes.xyz.models.efectivo;
|
||||||
|
|
||||||
import danielcortes.xyz.data.ConnectionHolder;
|
|
||||||
import danielcortes.xyz.models.caja.Caja;
|
import danielcortes.xyz.models.caja.Caja;
|
||||||
import danielcortes.xyz.models.caja.CajaDAO;
|
|
||||||
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public abstract class EfectivoDAO {
|
public interface EfectivoDAO {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(EfectivoDAO.class.getName());
|
List<Efectivo> findAll();
|
||||||
|
|
||||||
protected ConnectionHolder connectionHolder;
|
Optional<Efectivo> findById(int id);
|
||||||
|
|
||||||
public abstract List<Efectivo> findAll();
|
Optional<Efectivo> findByCaja(Caja caja);
|
||||||
|
|
||||||
public abstract Efectivo findById(int id);
|
void insertEfectivo(Efectivo efectivo);
|
||||||
|
|
||||||
public abstract Efectivo findByCaja(Caja caja);
|
void insertDefaultEfectivo(Efectivo efectivo);
|
||||||
|
|
||||||
public abstract boolean insertEfectivo(Efectivo efectivo);
|
void updateEfectivo(Efectivo efectivo);
|
||||||
|
|
||||||
public abstract boolean insertDefaultEfectivo(Efectivo efectivo);
|
void deleteEfectivo(Efectivo efectivo);
|
||||||
|
|
||||||
public abstract boolean updateEfectivo(Efectivo efectivo);
|
int getTotalEfectivo(Caja caja);
|
||||||
|
|
||||||
public abstract boolean deleteEfectivo(Efectivo efectivo);
|
|
||||||
|
|
||||||
public abstract int getTotalEfectivo(Caja caja);
|
|
||||||
|
|
||||||
protected List<Efectivo> efectivosFromResultSet(ResultSet rs) throws SQLException {
|
|
||||||
List<Efectivo> efectivoList = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
|
||||||
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
|
||||||
|
|
||||||
Efectivo efectivo = new Efectivo();
|
|
||||||
efectivo.setCaja(caja);
|
|
||||||
efectivo.setId(rs.getInt("id"));
|
|
||||||
efectivo.setVeinteMil(rs.getInt("veinte_mil"));
|
|
||||||
efectivo.setDiezMil(rs.getInt("diez_mil"));
|
|
||||||
efectivo.setCincoMil(rs.getInt("cinco_mil"));
|
|
||||||
efectivo.setDosMil(rs.getInt("dos_mil"));
|
|
||||||
efectivo.setMil(rs.getInt("mil"));
|
|
||||||
efectivo.setQuinientos(rs.getInt("quinientos"));
|
|
||||||
efectivo.setCien(rs.getInt("cien"));
|
|
||||||
efectivo.setCincuenta(rs.getInt("cincuenta"));
|
|
||||||
efectivo.setDiez(rs.getInt("diez"));
|
|
||||||
|
|
||||||
LOGGER.log(Level.FINER, "Se a creo: {0}", efectivo);
|
|
||||||
|
|
||||||
efectivoList.add(efectivo);
|
|
||||||
}
|
|
||||||
return efectivoList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,20 +24,25 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.models.efectivo;
|
package danielcortes.xyz.models.efectivo;
|
||||||
|
|
||||||
|
import danielcortes.xyz.data.ConnectionHolder;
|
||||||
|
import danielcortes.xyz.data.DAOManager;
|
||||||
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
||||||
import danielcortes.xyz.models.caja.Caja;
|
import danielcortes.xyz.models.caja.Caja;
|
||||||
|
import danielcortes.xyz.models.caja.CajaDAO;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class SQLiteEfectivoDAO extends EfectivoDAO {
|
public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(SQLiteEfectivoDAO.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(SQLiteEfectivoDAO.class.getName());
|
||||||
|
private ConnectionHolder connectionHolder;
|
||||||
|
|
||||||
public SQLiteEfectivoDAO() {
|
public SQLiteEfectivoDAO() {
|
||||||
this.connectionHolder = new SQLiteConnectionHolder();
|
this.connectionHolder = new SQLiteConnectionHolder();
|
||||||
@@ -46,17 +51,33 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
|
|||||||
@Override
|
@Override
|
||||||
public List<Efectivo> findAll() {
|
public List<Efectivo> findAll() {
|
||||||
List<Efectivo> efectivoList = new ArrayList<>();
|
List<Efectivo> efectivoList = new ArrayList<>();
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
String query = "select * from efectivos";
|
String query = "select * from efectivos";
|
||||||
PreparedStatement ps = conn.prepareStatement(query);
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
ResultSet rs = ps.executeQuery();
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
CajaDAO cajaDAO = DAOManager.getCajaDAO();
|
||||||
|
while (rs.next()) {
|
||||||
|
//Confio en que la base de datos me entregara un id existente.
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0}", query);
|
Efectivo efectivo = new Efectivo();
|
||||||
|
efectivo.setCaja(caja);
|
||||||
|
efectivo.setId(rs.getInt("id"));
|
||||||
|
efectivo.setVeinteMil(rs.getInt("veinte_mil"));
|
||||||
|
efectivo.setDiezMil(rs.getInt("diez_mil"));
|
||||||
|
efectivo.setCincoMil(rs.getInt("cinco_mil"));
|
||||||
|
efectivo.setDosMil(rs.getInt("dos_mil"));
|
||||||
|
efectivo.setMil(rs.getInt("mil"));
|
||||||
|
efectivo.setQuinientos(rs.getInt("quinientos"));
|
||||||
|
efectivo.setCien(rs.getInt("cien"));
|
||||||
|
efectivo.setCincuenta(rs.getInt("cincuenta"));
|
||||||
|
efectivo.setDiez(rs.getInt("diez"));
|
||||||
|
|
||||||
efectivoList = this.efectivosFromResultSet(rs);
|
efectivoList.add(efectivo);
|
||||||
|
}
|
||||||
rs.close();
|
}
|
||||||
ps.close();
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
@@ -65,58 +86,81 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Efectivo findById(int id) {
|
public Optional<Efectivo> findById(int id) {
|
||||||
Efectivo efectivo = null;
|
Efectivo efectivo = null;
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
String query = "select * from efectivos where id = ?";
|
String query = "select * from efectivos where id = ?";
|
||||||
PreparedStatement ps = conn.prepareStatement(query);
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, id);
|
ps.setInt(1, id);
|
||||||
ResultSet rs = ps.executeQuery();
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
CajaDAO cajaDAO = DAOManager.getCajaDAO();
|
||||||
|
if (rs.next()) {
|
||||||
|
//Confio en que la base de datos me entregara un id existente.
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
|
efectivo = new Efectivo();
|
||||||
|
efectivo.setCaja(caja);
|
||||||
efectivo = this.efectivosFromResultSet(rs).get(0);
|
efectivo.setId(rs.getInt("id"));
|
||||||
|
efectivo.setVeinteMil(rs.getInt("veinte_mil"));
|
||||||
rs.close();
|
efectivo.setDiezMil(rs.getInt("diez_mil"));
|
||||||
ps.close();
|
efectivo.setCincoMil(rs.getInt("cinco_mil"));
|
||||||
|
efectivo.setDosMil(rs.getInt("dos_mil"));
|
||||||
|
efectivo.setMil(rs.getInt("mil"));
|
||||||
|
efectivo.setQuinientos(rs.getInt("quinientos"));
|
||||||
|
efectivo.setCien(rs.getInt("cien"));
|
||||||
|
efectivo.setCincuenta(rs.getInt("cincuenta"));
|
||||||
|
efectivo.setDiez(rs.getInt("diez"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return efectivo;
|
return Optional.ofNullable(efectivo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Efectivo findByCaja(Caja caja) {
|
public Optional<Efectivo> findByCaja(Caja caja) {
|
||||||
Efectivo efectivo = null;
|
Efectivo efectivo = null;
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
if (Caja.EMPTY == caja) {
|
||||||
String query = "select * from efectivos where caja_id = ?";
|
return Optional.ofNullable(efectivo);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
String query = "select * from efectivos where caja_id = ?";
|
||||||
ps.close();
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
ps.setInt(1, caja.getId());
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
efectivo = new Efectivo();
|
||||||
|
efectivo.setCaja(caja);
|
||||||
|
efectivo.setId(rs.getInt("id"));
|
||||||
|
efectivo.setVeinteMil(rs.getInt("veinte_mil"));
|
||||||
|
efectivo.setDiezMil(rs.getInt("diez_mil"));
|
||||||
|
efectivo.setCincoMil(rs.getInt("cinco_mil"));
|
||||||
|
efectivo.setDosMil(rs.getInt("dos_mil"));
|
||||||
|
efectivo.setMil(rs.getInt("mil"));
|
||||||
|
efectivo.setQuinientos(rs.getInt("quinientos"));
|
||||||
|
efectivo.setCien(rs.getInt("cien"));
|
||||||
|
efectivo.setCincuenta(rs.getInt("cincuenta"));
|
||||||
|
efectivo.setDiez(rs.getInt("diez"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return efectivo;
|
return Optional.ofNullable(efectivo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean insertEfectivo(Efectivo efectivo) {
|
public void insertEfectivo(Efectivo efectivo) {
|
||||||
int updates;
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
String query = "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);
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, efectivo.getVeinteMil());
|
ps.setInt(1, efectivo.getVeinteMil());
|
||||||
ps.setInt(2, efectivo.getDiezMil());
|
ps.setInt(2, efectivo.getDiezMil());
|
||||||
ps.setInt(3, efectivo.getCincoMil());
|
ps.setInt(3, efectivo.getCincoMil());
|
||||||
@@ -127,69 +171,43 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
|
|||||||
ps.setInt(8, efectivo.getCincuenta());
|
ps.setInt(8, efectivo.getCincuenta());
|
||||||
ps.setInt(9, efectivo.getDiez());
|
ps.setInt(9, efectivo.getDiez());
|
||||||
ps.setInt(10, efectivo.getCaja().getId());
|
ps.setInt(10, efectivo.getCaja().getId());
|
||||||
updates = ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
LOGGER.log(Level.FINE,
|
try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) {
|
||||||
"QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}] | updates: {11}",
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
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();
|
|
||||||
|
|
||||||
query = "select last_insert_rowid()";
|
|
||||||
ps = conn.prepareStatement(query);
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0}", query);
|
|
||||||
|
|
||||||
rs.next();
|
rs.next();
|
||||||
efectivo.setId(rs.getInt(1));
|
efectivo.setId(rs.getInt(1));
|
||||||
|
}
|
||||||
rs.close();
|
}
|
||||||
ps.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return updates > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean insertDefaultEfectivo(Efectivo efectivo) {
|
public void insertDefaultEfectivo(Efectivo efectivo) {
|
||||||
int updates;
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
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,?)";
|
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);
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, efectivo.getCaja().getId());
|
ps.setInt(1, efectivo.getCaja().getId());
|
||||||
updates = ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}",
|
try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) {
|
||||||
new Object[]{query, efectivo.getCaja().getId(), updates});
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
|
||||||
ps.close();
|
|
||||||
|
|
||||||
ps = conn.prepareStatement("select last_insert_rowid()");
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
rs.next();
|
rs.next();
|
||||||
efectivo.setId(rs.getInt(1));
|
efectivo.setId(rs.getInt(1));
|
||||||
|
}
|
||||||
rs.close();
|
}
|
||||||
ps.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return updates > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateEfectivo(Efectivo efectivo) {
|
public void updateEfectivo(Efectivo efectivo) {
|
||||||
int updates;
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
String query = "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);
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, efectivo.getVeinteMil());
|
ps.setInt(1, efectivo.getVeinteMil());
|
||||||
ps.setInt(2, efectivo.getDiezMil());
|
ps.setInt(2, efectivo.getDiezMil());
|
||||||
ps.setInt(3, efectivo.getCincoMil());
|
ps.setInt(3, efectivo.getCincoMil());
|
||||||
@@ -201,59 +219,44 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
|
|||||||
ps.setInt(9, efectivo.getDiez());
|
ps.setInt(9, efectivo.getDiez());
|
||||||
ps.setInt(10, efectivo.getCaja().getId());
|
ps.setInt(10, efectivo.getCaja().getId());
|
||||||
ps.setInt(11, efectivo.getId());
|
ps.setInt(11, efectivo.getId());
|
||||||
updates = ps.executeUpdate();
|
|
||||||
|
|
||||||
LOGGER.log(Level.FINE,
|
ps.executeUpdate();
|
||||||
"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) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return updates > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteEfectivo(Efectivo efectivo) {
|
public void deleteEfectivo(Efectivo efectivo) {
|
||||||
int updates;
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
String query = "delete from efectivos where id = ?";
|
String query = "delete from efectivos where id = ?";
|
||||||
PreparedStatement ps = conn.prepareStatement(query);
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, efectivo.getId());
|
ps.setInt(1, efectivo.getId());
|
||||||
updates = ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}",
|
|
||||||
new Object[]{query, efectivo.getId(), updates});
|
|
||||||
|
|
||||||
ps.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return updates > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTotalEfectivo(Caja caja) {
|
public int getTotalEfectivo(Caja caja) {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
if (Caja.EMPTY == caja) {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
String query = "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);
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, caja.getId());
|
ps.setInt(1, caja.getId());
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
|
if (rs.next()) {
|
||||||
|
|
||||||
ResultSet rs = ps.executeQuery();
|
|
||||||
rs.next();
|
|
||||||
total = rs.getInt(1);
|
total = rs.getInt(1);
|
||||||
|
}
|
||||||
rs.close();
|
}
|
||||||
ps.close();
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user