Se creo una fila en la tabla de cajas en la que se almacena el fondo de esta, la cual sera mostrada en la vista de calcular fondo, donde sera actualizada segun diga el usuario

This commit is contained in:
Daniel Cortes
2019-02-20 14:06:58 -03:00
parent 08da94aba4
commit e7eb6513dd
14 changed files with 101 additions and 78 deletions

View File

@@ -1,6 +1,5 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.calculo_fondo.CalculoFondo;
@@ -8,12 +7,10 @@ import danielcortes.xyz.views.CalcularFondoView;
import danielcortes.xyz.views.components.table_model.FondoTableModel;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class CalcularFondoController extends BaseController{
private JComponent parent;
private CalcularFondoView view;
private Caja caja;
@@ -21,25 +18,15 @@ public class CalcularFondoController extends BaseController{
private boolean editing;
private CalculoFondo editingCalculoFondo;
public CalcularFondoController(JComponent parent, CalcularFondoView view, Caja caja) {
public CalcularFondoController(CalcularFondoView view, Caja caja) {
this.view = view;
this.parent = parent;
this.caja = caja;
this.fillTable();
this.fillResumen();
this.updateResumen();
this.setupViewEvents();
this.updateButtonsEnabled();
this.showView();
}
private void showView() {
JFrame frame = new JFrame("Calculo de Fondo: " + Configuration.get("nombre_caja"));
frame.setContentPane(view.getContentPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(this.parent);
frame.setVisible(true);
}
private void fillTable() {
@@ -50,6 +37,20 @@ public class CalcularFondoController extends BaseController{
}
}
private void fillResumen() {
this.view.getFondoField().setValue(this.caja.getFondo());
}
private void updateResumen() {
this.caja.setFondo(this.view.getFondoField().getValue());
int suma = DAOManager.getCalculoFondoDAO().getTotalCalculoFondo(this.caja);
this.view.getSumaField().setValue(suma);
this.view.getDepositoField().setValue(suma - this.caja.getFondo());
DAOManager.getCajaDAO().updateCaja(this.caja);
}
private void setupViewEvents() {
moveTo(this.view.getValorField(), this.view.getDescripcionField());
doAction(this.view.getDescripcionField(), "save", KeyStroke.getKeyStroke("ENTER"), e -> this.guardarActionListener());
@@ -142,12 +143,6 @@ public class CalcularFondoController extends BaseController{
}
}
private void updateResumen() {
int fondo = this.view.getFondoField().getValue();
int suma = DAOManager.getCalculoFondoDAO().getTotalCalculoFondo(this.caja);
this.view.getSumaField().setValue(suma);
this.view.getDepositoField().setValue(suma - fondo);
}
private void cleanInput() {
this.view.getValorField().setValue(0);
@@ -166,11 +161,4 @@ public class CalcularFondoController extends BaseController{
private void resetFocus() {
this.view.getValorField().requestFocus();
}
private class UpdateResumenAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
CalcularFondoController.this.updateResumen();
}
}
}