diff --git a/caja.iml b/caja.iml
index bb76540..213a563 100644
--- a/caja.iml
+++ b/caja.iml
@@ -15,5 +15,14 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/danielcortes/xyz/Main.java b/src/main/java/danielcortes/xyz/Main.java
index 814b148..0e8d026 100644
--- a/src/main/java/danielcortes/xyz/Main.java
+++ b/src/main/java/danielcortes/xyz/Main.java
@@ -54,8 +54,8 @@ public class Main {
JFrame frame = new JFrame("Caja");
frame.setContentPane(view.getContentPanel());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(780, 450);
- //frame.pack();
+ //frame.setSize(780, 450);
+ frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
diff --git a/src/main/java/danielcortes/xyz/controllers/ArqueoController.java b/src/main/java/danielcortes/xyz/controllers/ArqueoController.java
index cd36051..5ad5b40 100644
--- a/src/main/java/danielcortes/xyz/controllers/ArqueoController.java
+++ b/src/main/java/danielcortes/xyz/controllers/ArqueoController.java
@@ -24,53 +24,203 @@
package danielcortes.xyz.controllers;
+import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.efectivo.Efectivo;
import danielcortes.xyz.models.efectivo.EfectivoDAO;
+import danielcortes.xyz.models.egreso.EgresoDAO;
+import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.views.ArqueoView;
-import java.util.ArrayList;
-import java.util.List;
+import javax.swing.*;
+
public class ArqueoController {
private ArqueoView view;
private EfectivoDAO efectivoDAO;
+ private Caja caja;
+ private Efectivo efectivo;
+ private IngresoDAO ingresoDAO;
+ private EgresoDAO egresoDAO;
- public ArqueoController(ArqueoView view, EfectivoDAO efectivoDAO) {
+ public ArqueoController(ArqueoView view, EfectivoDAO efectivoDAO, IngresoDAO ingresoDAO, EgresoDAO egresoDAO) {
this.view = view;
this.efectivoDAO = efectivoDAO;
-// this.fillEfectivo();
-// this.fillDocumentos();
-// this.fillDocumentos();
+ this.ingresoDAO = ingresoDAO;
+ this.egresoDAO = egresoDAO;
+
+ this.setUpViewEvents();
}
+ public void updateCaja(Caja caja) {
+ this.caja = caja;
+ fillDocumentos();
+ fillEfectivo();
+ fillResumen();
+ }
- private void fillEfectivo(){
- List efectivoList = this.efectivoDAO.findAll();
- if(efectivoList.size() > 0) {
- Efectivo efectivo = efectivoList.get(0);
- this.view.getVeinteMilField().setText(String.valueOf(efectivo.getVeinteMil()));
- this.view.getDiezField().setText(String.valueOf(efectivo.getDiezMil()));
- this.view.getCincoMilField().setText(String.valueOf(efectivo.getCincoMil()));
- this.view.getDosMilField().setText(String.valueOf(efectivo.getDosMil()));
- this.view.getMilField().setText(String.valueOf(efectivo.getMil()));
- this.view.getQuinientosField().setText(String.valueOf(efectivo.getQuinientos()));
- this.view.getCienField().setText(String.valueOf(efectivo.getCien()));
- this.view.getCincuentaField().setText(String.valueOf(efectivo.getCincuenta()));
- this.view.getDiezField().setText(String.valueOf(efectivo.getDiez()));
+ public void updateResumen() {
+ this.fillResumen();
+ }
+
+ private void fillEfectivo() {
+ this.efectivo = this.efectivoDAO.findByCaja(this.caja);
+ this.view.getVeinteMilField().setText(String.valueOf(efectivo.getVeinteMil()));
+ this.view.getDiezField().setText(String.valueOf(efectivo.getDiezMil()));
+ this.view.getCincoMilField().setText(String.valueOf(efectivo.getCincoMil()));
+ this.view.getDosMilField().setText(String.valueOf(efectivo.getDosMil()));
+ this.view.getMilField().setText(String.valueOf(efectivo.getMil()));
+ this.view.getQuinientosField().setText(String.valueOf(efectivo.getQuinientos()));
+ this.view.getCienField().setText(String.valueOf(efectivo.getCien()));
+ this.view.getCincuentaField().setText(String.valueOf(efectivo.getCincuenta()));
+ this.view.getDiezField().setText(String.valueOf(efectivo.getDiez()));
+ }
+
+ private void fillDocumentos() {
+
+ }
+
+ private void fillResumen() {
+ this.updateResumenEfectivo();
+ this.updateResumenDocumentos();
+ this.updateResumenIngresos();
+ this.updateResumenEgresos();
+ this.updateResumenArqueo();
+ }
+
+ private void updateResumenEfectivo() {
+ JTextField efectivoField = this.view.getEfectivoField();
+ int total = 0;
+ total += this.efectivo.getDiez();
+ total += this.efectivo.getCincuenta();
+ total += this.efectivo.getCien();
+ total += this.efectivo.getQuinientos();
+ total += this.efectivo.getMil();
+ total += this.efectivo.getDosMil();
+ total += this.efectivo.getCincoMil();
+ total += this.efectivo.getDiezMil();
+ total += this.efectivo.getVeinteMil();
+
+ efectivoField.setText(String.valueOf(total));
+ }
+
+ private void updateResumenDocumentos() {
+
+ }
+
+ private void updateResumenIngresos() {
+ int total = this.ingresoDAO.getTotalIngreso(this.caja);
+ this.view.getIngresosField().setText(String.valueOf(total));
+ }
+
+ private void updateResumenEgresos() {
+ int total = this.egresoDAO.getTotalEgreso(this.caja);
+ this.view.getEgresosField().setText(String.valueOf(total));
+ }
+
+ private void updateResumenArqueo() {
+
+ }
+
+ private void setUpViewEvents() {
+ this.view.getGuardarEfectivoButton().addActionListener(e -> {
+ this.normalizeEfectivoInput();
+ this.guardarEfectivo();
+ });
+ }
+
+ private void guardarEfectivo() {
+ String diez = this.view.getDiezField().getText();
+ String cincuenta = this.view.getCincuentaField().getText();
+ String cien = this.view.getCienField().getText();
+ String quinientos = this.view.getQuinientosField().getText();
+ String mil = this.view.getMilField().getText();
+ String dosMil = this.view.getDosMilField().getText();
+ String cincoMil = this.view.getCincoMilField().getText();
+ String diezMil = this.view.getDiezMilField().getText();
+ String veinteMil = this.view.getVeinteMilField().getText();
+
+ if (this.validateEfectivoInput(diez, cincuenta, cien, quinientos, mil, dosMil, cincoMil, diezMil, veinteMil)) {
+ this.efectivo.setDiez(Integer.valueOf(diez));
+ this.efectivo.setCincuenta(Integer.valueOf(cincuenta));
+ this.efectivo.setCien(Integer.valueOf(cien));
+ this.efectivo.setQuinientos(Integer.valueOf(quinientos));
+ this.efectivo.setMil(Integer.valueOf(mil));
+ this.efectivo.setDosMil(Integer.valueOf(dosMil));
+ this.efectivo.setCincoMil(Integer.valueOf(cincoMil));
+ this.efectivo.setDiezMil(Integer.valueOf(diezMil));
+ this.efectivo.setVeinteMil(Integer.valueOf(veinteMil));
+ this.efectivoDAO.updateEfectivo(efectivo);
+
+ this.updateResumenEfectivo();
}
}
- private void fillResumen(){
- List efectivoList = this.efectivoDAO.findAll();
- if(efectivoList.size() > 0) {
- Efectivo efectivo = efectivoList.get(0);
- int total = this.efectivoDAO.getTotalEfectivo(efectivo);
- this.view.getEfectivoField().setText(String.valueOf(total));
- }
+ private boolean validateEfectivoInput(String diez, String cincuenta, String cien, String quinientos, String mil, String dosMil, String cincoMil, String diezMil, String veinteMil) {
+ this.hiddeEfectivoErrorMessages();
+
+ boolean diezValidation = validateEfectivoMoneda(diez, this.view.getErrorDiez());
+ boolean cincuentaValidation = validateEfectivoMoneda(cincuenta, this.view.getErrorCincuenta());
+ boolean cienValidation = validateEfectivoMoneda(cien, this.view.getErrorCien());
+ boolean quinientosValidation = validateEfectivoMoneda(quinientos, this.view.getErrorQuinientos());
+ boolean milValidation = validateEfectivoMoneda(mil, this.view.getErrorMil());
+ boolean dosMilValidation = validateEfectivoMoneda(dosMil, this.view.getErrorDosMil());
+ boolean cincoMilValidation = validateEfectivoMoneda(cincoMil, this.view.getErrorCincoMil());
+ boolean diezMilValidation = validateEfectivoMoneda(diezMil, this.view.getErrorDiezMil());
+ boolean veinteMilValidation = validateEfectivoMoneda(veinteMil, this.view.getErrorVeinteMil());
+
+ return diezValidation && cincuentaValidation && cienValidation && quinientosValidation && milValidation && dosMilValidation && cincoMilValidation && diezMilValidation && veinteMilValidation;
}
- private void fillDocumentos(){
+ private boolean validateEfectivoMoneda(String valor, JLabel errorLabel) {
+ if (valor == null) {
+ errorLabel.setText("Hubo un problema con los datos");
+ errorLabel.setVisible(true);
+ return false;
+ }
+ if (valor.isEmpty()) {
+ errorLabel.setText("El campo esta vacio");
+ errorLabel.setVisible(true);
+ return false;
+ }
+
+ if (!valor.chars().allMatch(Character::isDigit)) {
+ errorLabel.setText("Deben ser numeros");
+ errorLabel.setVisible(true);
+ return false;
+ }
+
+ if (valor.length() > 10) {
+ errorLabel.setText("El numero ingresado es demasiado largo");
+ errorLabel.setVisible(true);
+ return false;
+ }
+
+ return true;
+ }
+
+ private void hiddeEfectivoErrorMessages() {
+ this.view.getErrorDiez().setVisible(false);
+ this.view.getErrorCincuenta().setVisible(false);
+ this.view.getErrorCien().setVisible(false);
+ this.view.getErrorQuinientos().setVisible(false);
+ this.view.getErrorMil().setVisible(false);
+ this.view.getErrorDosMil().setVisible(false);
+ this.view.getErrorCincoMil().setVisible(false);
+ this.view.getErrorDiezMil().setVisible(false);
+ this.view.getErrorVeinteMil().setVisible(false);
+ }
+
+ private void normalizeEfectivoInput() {
+ this.view.getDiezField().setText(this.view.getDiezField().getText().trim());
+ this.view.getCincuentaField().setText(this.view.getCincuentaField().getText().trim());
+ this.view.getCienField().setText(this.view.getCienField().getText().trim());
+ this.view.getQuinientosField().setText(this.view.getQuinientosField().getText().trim());
+ this.view.getMilField().setText(this.view.getMilField().getText().trim());
+ this.view.getDosMilField().setText(this.view.getDosMilField().getText().trim());
+ this.view.getCincoMilField().setText(this.view.getCincoMilField().getText().trim());
+ this.view.getDiezMilField().setText(this.view.getDiezMilField().getText().trim());
+ this.view.getVeinteMilField().setText(this.view.getVeinteMilField().getText().trim());
}
}
diff --git a/src/main/java/danielcortes/xyz/controllers/EgresosController.java b/src/main/java/danielcortes/xyz/controllers/EgresosController.java
index 7729124..797c5f5 100644
--- a/src/main/java/danielcortes/xyz/controllers/EgresosController.java
+++ b/src/main/java/danielcortes/xyz/controllers/EgresosController.java
@@ -113,10 +113,13 @@ public class EgresosController {
}
private void guardarActionListener() {
+ this.normalizeInputs();
+
String nro = this.view.getNroField().getText();
String descripcion = this.view.getDescripcionField().getText();
String valor = this.view.getValorField().getText();
TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem();
+
if(editing){
this.editarEgreso(nro, descripcion, valor, tipo, this.caja);
}else {
@@ -303,6 +306,13 @@ public class EgresosController {
this.view.getDescripcionField().setText("");
}
+ private void normalizeInputs(){
+ this.view.getValorField().setText(this.view.getValorField().getText().trim());
+ this.view.getNroField().setText(this.view.getNroField().getText().trim());
+ this.view.getDescripcionField().setText(this.view.getDescripcionField().getText().trim());
+
+ }
+
private void resetFocus() {
this.view.getNroField().requestFocus();
}
diff --git a/src/main/java/danielcortes/xyz/controllers/IngresosController.java b/src/main/java/danielcortes/xyz/controllers/IngresosController.java
index 75741ea..6afd639 100644
--- a/src/main/java/danielcortes/xyz/controllers/IngresosController.java
+++ b/src/main/java/danielcortes/xyz/controllers/IngresosController.java
@@ -113,6 +113,7 @@ public class IngresosController {
}
private void guardarActionListener() {
+ this.normalizeInputs();
String valor = this.view.getValorField().getText();
TipoIngreso tipoIngreso = (TipoIngreso) this.view.getTipoCombo().getSelectedItem();
@@ -259,6 +260,10 @@ public class IngresosController {
this.view.getValorField().setText("");
}
+ private void normalizeInputs(){
+ this.view.getValorField().setText(this.view.getValorField().getText().trim());
+ }
+
private void resetFocus(){
this.view.getTipoCombo().requestFocus();
}
diff --git a/src/main/java/danielcortes/xyz/controllers/ManagerController.java b/src/main/java/danielcortes/xyz/controllers/ManagerController.java
index 468da88..61a2536 100644
--- a/src/main/java/danielcortes/xyz/controllers/ManagerController.java
+++ b/src/main/java/danielcortes/xyz/controllers/ManagerController.java
@@ -26,6 +26,7 @@ package danielcortes.xyz.controllers;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
+import danielcortes.xyz.models.efectivo.Efectivo;
import danielcortes.xyz.models.efectivo.EfectivoDAO;
import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
@@ -57,10 +58,16 @@ public class ManagerController {
this.view = view;
this.cajaDAO = cajaDAO;
this.loadCardContents();
+ this.setUpDate();
this.setUpViewEvents();
this.pressInitialButton();
}
+ private void setUpDate(){
+ this.view.getDatePicker().setDateToToday();
+ this.updateCaja();
+ }
+
private void setUpViewEvents() {
this.view.getEgresosButton().addActionListener(e -> {
CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout();
@@ -72,23 +79,32 @@ public class ManagerController {
});
this.view.getArqueoButton().addActionListener(e -> {
+ this.arqueoController.updateResumen();
+
CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout();
layout.show(this.view.getCardPanel(), "ARQUEO");
});
- this.view.getDatePicker().addDateChangeListener(e -> {
- LocalDate selectedDate = this.view.getDatePicker().getDate();
- Caja caja = this.cajaDAO.findByFecha(selectedDate);
- if(caja == null){
- caja = new Caja();
- caja.setFecha(selectedDate);
- this.cajaDAO.insertCaja(caja);
- }
- this.ingresosController.updateCaja(caja);
- this.egresosController.updateCaja(caja);
-// this.arqueoController.updateCaja(caja);
+ this.view.getDatePicker().addDateChangeListener(e -> updateCaja());
+ }
- });
+ private void updateCaja(){
+ LocalDate selectedDate = this.view.getDatePicker().getDate();
+ Caja caja = this.cajaDAO.findByFecha(selectedDate);
+ if(caja == null){
+ caja = new Caja();
+ caja.setFecha(selectedDate);
+ this.cajaDAO.insertCaja(caja);
+
+ EfectivoDAO efectivoDAO = new MysqlEfectivoDAO();
+ Efectivo efectivo = new Efectivo();
+ efectivo.setCaja(caja);
+ efectivoDAO.insertDefaultEfectivo(efectivo);
+
+ }
+ this.ingresosController.updateCaja(caja);
+ this.egresosController.updateCaja(caja);
+ this.arqueoController.updateCaja(caja);
}
private void loadCardContents() {
@@ -120,10 +136,12 @@ public class ManagerController {
private void loadArqueoView() {
ArqueoView arqueoView = new ArqueoView();
EfectivoDAO efectivoDAO = new MysqlEfectivoDAO();
+ EgresoDAO egresoDAO = new MysqlEgresoDAO();
+ IngresoDAO ingresoDAO = new MysqlIngresoDAO();
this.view.getCardPanel().add(arqueoView.getContentPanel(), "ARQUEO");
- this.arqueoController = new ArqueoController(arqueoView, efectivoDAO);
+ this.arqueoController = new ArqueoController(arqueoView, efectivoDAO, ingresoDAO, egresoDAO);
}
private void pressInitialButton() {
diff --git a/src/main/java/danielcortes/xyz/models/efectivo/Efectivo.java b/src/main/java/danielcortes/xyz/models/efectivo/Efectivo.java
index 65a49c8..6261226 100644
--- a/src/main/java/danielcortes/xyz/models/efectivo/Efectivo.java
+++ b/src/main/java/danielcortes/xyz/models/efectivo/Efectivo.java
@@ -24,6 +24,8 @@
package danielcortes.xyz.models.efectivo;
+import danielcortes.xyz.models.caja.Caja;
+
public class Efectivo {
private int id;
private int veinteMil;
@@ -35,6 +37,7 @@ public class Efectivo {
private int cien;
private int cincuenta;
private int diez;
+ private Caja caja;
public int getId() {
return id;
@@ -115,4 +118,12 @@ public class Efectivo {
public void setDiez(int diez) {
this.diez = diez;
}
+
+ public Caja getCaja() {
+ return caja;
+ }
+
+ public void setCaja(Caja caja) {
+ this.caja = caja;
+ }
}
diff --git a/src/main/java/danielcortes/xyz/models/efectivo/EfectivoDAO.java b/src/main/java/danielcortes/xyz/models/efectivo/EfectivoDAO.java
index aa3904b..a4f13c4 100644
--- a/src/main/java/danielcortes/xyz/models/efectivo/EfectivoDAO.java
+++ b/src/main/java/danielcortes/xyz/models/efectivo/EfectivoDAO.java
@@ -24,13 +24,17 @@
package danielcortes.xyz.models.efectivo;
+import danielcortes.xyz.models.caja.Caja;
+
import java.util.List;
public interface EfectivoDAO {
List findAll();
Efectivo findById(int id);
+ Efectivo findByCaja(Caja caja);
+
boolean insertEfectivo(Efectivo efectivo);
+ boolean insertDefaultEfectivo(Efectivo efectivo);
boolean updateEfectivo(Efectivo efectivo);
boolean deleteEfectivo(Efectivo efectivo);
- int getTotalEfectivo(Efectivo efectivo);
}
diff --git a/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java b/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java
index b93f6dd..5b8ad34 100644
--- a/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java
+++ b/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java
@@ -25,6 +25,9 @@
package danielcortes.xyz.models.efectivo;
import danielcortes.xyz.data.MysqlConnection;
+import danielcortes.xyz.models.caja.Caja;
+import danielcortes.xyz.models.caja.CajaDAO;
+import danielcortes.xyz.models.caja.MysqlCajaDAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -45,7 +48,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
List efectivoList = new ArrayList<>();
try {
Connection conn = mysqlConnection.getConnection();
- PreparedStatement ps = conn.prepareStatement("select * from efectivo");
+ PreparedStatement ps = conn.prepareStatement("select * from efectivos");
ResultSet rs = ps.executeQuery();
efectivoList = this.efectivosFromResultSet(rs);
@@ -81,12 +84,36 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
return efectivo;
}
+ @Override
+ public Efectivo findByCaja(Caja caja) {
+ Efectivo efectivo = null;
+ try {
+ Connection conn = mysqlConnection.getConnection();
+ PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
+ ps.setInt(1, caja.getId());
+ ResultSet rs = ps.executeQuery();
+
+ List efectivoList = this.efectivosFromResultSet(rs);
+ if(efectivoList.size() > 0) {
+ efectivo = efectivoList.get(0);
+ }
+
+ rs.close();
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ return efectivo;
+ }
+
@Override
public boolean insertEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = mysqlConnection.getConnection();
- PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez) values (?,?,?,?,?,?,?,?,?)");
+ PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
@@ -96,6 +123,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
+ ps.setInt(10, efectivo.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
@@ -115,12 +143,39 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
return updates > 0;
}
+ @Override
+ public boolean insertDefaultEfectivo(Efectivo efectivo) {
+ int updates;
+ try {
+ Connection conn = mysqlConnection.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,?)");
+ ps.setInt(1, efectivo.getCaja().getId());
+
+ updates = ps.executeUpdate();
+ System.out.println(updates);
+ ps.close();
+
+ ps = conn.prepareStatement("select last_insert_id()");
+ ResultSet rs = ps.executeQuery();
+ rs.next();
+ efectivo.setId(rs.getInt(1));
+
+ rs.close();
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return updates > 0;
+ }
+
@Override
public boolean updateEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = mysqlConnection.getConnection();
- PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ? where id = ?");
+ PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
@@ -130,7 +185,8 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
- ps.setInt(10, efectivo.getId());
+ ps.setInt(10, efectivo.getCaja().getId());
+ ps.setInt(11, efectivo.getId());
updates = ps.executeUpdate();
@@ -162,31 +218,14 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
return updates > 0;
}
- @Override
- public int getTotalEfectivo(Efectivo efectivo) {
- int total = 0;
- try {
- Connection conn = mysqlConnection.getConnection();
- PreparedStatement ps = conn.prepareStatement("select (veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez) as total from efectivos where id = ?");
- ps.setInt(1, efectivo.getId());
- ResultSet rs = ps.executeQuery();
-
- rs.next();
- total = rs.getInt(1);
-
- rs.close();
- ps.close();
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return total;
- }
-
private List efectivosFromResultSet(ResultSet rs) throws SQLException {
List efectivoList = new ArrayList<>();
while (rs.next()) {
+ CajaDAO cajaDAO = new MysqlCajaDAO();
+ Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
+
Efectivo efectivo = new Efectivo();
+ efectivo.setCaja(caja);
efectivo.setId(rs.getInt("id"));
efectivo.setVeinteMil(rs.getInt("veinte_mil"));
efectivo.setDiezMil(rs.getInt("diez_mil"));
diff --git a/src/main/java/danielcortes/xyz/views/ArqueoView.form b/src/main/java/danielcortes/xyz/views/ArqueoView.form
index f4ee880..3f83ac9 100644
--- a/src/main/java/danielcortes/xyz/views/ArqueoView.form
+++ b/src/main/java/danielcortes/xyz/views/ArqueoView.form
@@ -1,16 +1,16 @@