Agregada una ventana para realizar el calculo del fondo de la caja, es wip, falta la aprobacion del jefe jajaj

This commit is contained in:
Daniel Cortes
2019-01-18 18:43:53 -03:00
parent 30de826ee2
commit 5a9455eb4b
15 changed files with 1744 additions and 467 deletions

View File

@@ -26,6 +26,7 @@ package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.calculo_fondo.SQLiteCalculoFondoDAO;
import danielcortes.xyz.models.documentos.Documentos;
import danielcortes.xyz.models.documentos.DocumentosDAO;
import danielcortes.xyz.models.efectivo.Efectivo;
@@ -33,15 +34,18 @@ import danielcortes.xyz.models.efectivo.EfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.views.ArqueoView;
import danielcortes.xyz.views.CalcularFondoView;
import danielcortes.xyz.views.components.NumberFormatedTextField;
import javax.swing.*;
import java.awt.*;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import java.awt.Color;
import java.awt.event.ActionEvent;
/**
* Controlador destinado a la vista ArqueoView
* Maneja su contenido y las acciones que esta realiza.
* Controlador destinado a la vista ArqueoView
* Maneja su contenido y las acciones que esta realiza.
*/
public class ArqueoController {
private ArqueoView view;
@@ -56,7 +60,6 @@ public class ArqueoController {
/**
* Crea el controlador y ejecuta el metodo que genera los eventos para su vista.
*
*/
public ArqueoController(ArqueoView view, EfectivoDAO efectivoDAO, DocumentosDAO documentosDAO, IngresoDAO ingresoDAO, EgresoDAO egresoDAO) {
this.view = view;
@@ -70,6 +73,7 @@ public class ArqueoController {
/**
* Actualiza los campos de documentos, efectivo y resumen con los datos de la caja.
*
* @param caja Caja para la cual se seleccionaran los datos a mostrar
*/
public void updateCaja(Caja caja) {
@@ -164,10 +168,10 @@ public class ArqueoController {
this.view.getDebeRendirField().setValue(totalIngresos);
this.view.getDiferenciaField().setValue(diferencia);
if(diferencia < 0) {
this.view.getDiferenciaField().setForeground(new Color(255,0,0));
}else{
this.view.getDiferenciaField().setForeground(new Color(0,0,0));
if (diferencia < 0) {
this.view.getDiferenciaField().setForeground(new Color(255, 0, 0));
} else {
this.view.getDiferenciaField().setForeground(new Color(0, 0, 0));
}
}
@@ -176,15 +180,15 @@ public class ArqueoController {
* Setea los eventos de los fields de la vista
*/
private void setUpViewEvents() {
this.view.getVeinteMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getDiezMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getCincoMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getDosMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getQuinientosField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getCienField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getCincuentaField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getDiezField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
this.view.getVeinteMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getDiezMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getCincoMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getDosMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getQuinientosField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getCienField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getCincuentaField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getDiezField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getVeinteMilField().getActionMap().put("nextField", new NextAction(this.view.getDiezMilField()));
this.view.getDiezMilField().getActionMap().put("nextField", new NextAction(this.view.getCincoMilField()));
@@ -194,24 +198,26 @@ public class ArqueoController {
this.view.getQuinientosField().getActionMap().put("nextField", new NextAction(this.view.getCienField()));
this.view.getCienField().getActionMap().put("nextField", new NextAction(this.view.getCincuentaField()));
this.view.getCincuentaField().getActionMap().put("nextField", new NextAction(this.view.getDiezField()));
this.view.getDiezField().getActionMap().put("save", new GuardarEfectivoAction(this));
this.view.getDiezField().getActionMap().put("save", new GuardarEfectivoAction());
this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getTarjetasField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getRetiroField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getTarjetasField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getRetiroField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getChequesField().getActionMap().put("nextField", new NextAction(this.view.getTarjetasField()));
this.view.getTarjetasField().getActionMap().put("nextField", new NextAction(this.view.getRetiroField()));
this.view.getRetiroField().getActionMap().put("save", new GuardarDocumentosAction(this));
this.view.getRetiroField().getActionMap().put("save", new GuardarDocumentosAction());
this.view.getGuardarEfectivoButton().addActionListener(e ->{
this.view.getGuardarEfectivoButton().addActionListener(e -> {
this.guardarEfectivoActionListener();
});
this.view.getGuardarDocumentosButton().addActionListener(e ->{
this.view.getGuardarDocumentosButton().addActionListener(e -> {
this.guardarEfectivoActionListener();
});
this.view.getCalcularFondoButton().addActionListener(e -> {
this.calcularFondoActionListener();
});
}
@@ -219,7 +225,7 @@ public class ArqueoController {
* Llama a los metodos necesarios para guardar los campos de efectivo
* Primero llama a normalizar el input, luego a esconder los mensajes de error, para finalmente llamar a guardar el efectivo
*/
private void guardarEfectivoActionListener(){
private void guardarEfectivoActionListener() {
this.view.getGuardarEfectivoButton().requestFocus();
this.guardarEfectivo();
}
@@ -228,11 +234,18 @@ public class ArqueoController {
* Llama a los metodos necesarios para guardar los documentos
* Primero llama a normalizar el input, luego a esconder los mensajes de error y finalmente a guardar los documentos
*/
private void guardarDocumentosActionListener(){
private void guardarDocumentosActionListener() {
this.view.getGuardarDocumentosButton().requestFocus();
this.guardarDocumentos();
}
/**
* Lanza la ventana en la que se puede calcular el fondo de la caja.
*/
private void calcularFondoActionListener() {
new CalcularFondoController(this.view.getContentPanel(), new CalcularFondoView(), this.caja, new SQLiteCalculoFondoDAO());
}
/**
* Guarda los datos del detalle de efectivo solo despues de que los campos sean validados, luego de guardar
* llama a updateResumenEfectivo y updateResumenArqueo para actualizar los datos en efectivoField y arqueoField
@@ -282,28 +295,16 @@ public class ArqueoController {
}
private class GuardarEfectivoAction extends AbstractAction {
ArqueoController controller;
GuardarEfectivoAction(ArqueoController controller){
this.controller = controller;
}
@Override
public void actionPerformed(ActionEvent e) {
this.controller.guardarEfectivoActionListener();
ArqueoController.this.guardarEfectivoActionListener();
}
}
private class GuardarDocumentosAction extends AbstractAction {
ArqueoController controller;
GuardarDocumentosAction(ArqueoController controller){
this.controller = controller;
}
@Override
public void actionPerformed(ActionEvent e) {
this.controller.guardarDocumentosActionListener();
ArqueoController.this.guardarDocumentosActionListener();
}
}

View File

@@ -0,0 +1,191 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.calculo_fondo.CalculoFondo;
import danielcortes.xyz.models.calculo_fondo.CalculoFondoDAO;
import danielcortes.xyz.views.CalcularFondoView;
import danielcortes.xyz.views.components.FondoTableModel;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class CalcularFondoController {
private JComponent parent;
private CalcularFondoView view;
private Caja caja;
private CalculoFondoDAO calculoFondoDAO;
private int editingId;
private boolean editing;
private CalculoFondo editingCalculoFondo;
public CalcularFondoController(JComponent parent, CalcularFondoView view, Caja caja, CalculoFondoDAO calculoFondoDAO) {
this.view = view;
this.parent = parent;
this.caja = caja;
this.calculoFondoDAO = calculoFondoDAO;
this.fillTable();
this.updateResumen();
this.setupViewEvents();
this.updateButtonsEnabled();
this.showView();
}
private void showView() {
JFrame frame = new JFrame("Calculo de Fondo");
frame.setContentPane(view.getContentPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(this.parent);
frame.setVisible(true);
}
private void fillTable() {
FondoTableModel tableModel = this.view.getTableModel();
tableModel.removeRows();
for (CalculoFondo calculoFondo : this.calculoFondoDAO.findByCaja(this.caja)) {
tableModel.addRow(calculoFondo);
}
}
private void setupViewEvents() {
this.view.getValorField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
this.view.getDescripcionField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getFondoField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "updateResumen");
this.view.getValorField().getActionMap().put("nextField", new NextAction(this.view.getDescripcionField()));
this.view.getDescripcionField().getActionMap().put("save", new GuardarAction());
this.view.getFondoField().getActionMap().put("updateResumen", new UpdateResumenAction());
this.view.getTable().getSelectionModel().addListSelectionListener(e -> updateButtonsEnabled());
this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
this.view.getEditarButton().addActionListener(e -> editarActionListener());
this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
this.view.getTable().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
JTable table = (JTable) mouseEvent.getSource();
if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) {
CalcularFondoController.this.editarActionListener();
}
}
});
}
private void guardarActionListener() {
this.normalizeInput();
int valor = this.view.getValorField().getValue();
String descripcion = this.view.getDescripcionField().getText();
if (editing) {
this.editarCalculoFondo(valor, descripcion);
this.editing = false;
} else {
this.guardarCalculoFondo(valor, descripcion);
}
this.updateResumen();
this.cleanInput();
this.resetFocus();
}
private void editarActionListener() {
int selectedID = this.view.getTable().getSelectedRow();
if (selectedID >= 0) {
int selectedModelID = this.view.getTable().getRowSorter().convertRowIndexToModel(selectedID);
CalculoFondo calculoFondo = this.view.getTableModel().getCalculoFondo(selectedModelID);
this.editingId = selectedModelID;
this.editingCalculoFondo = calculoFondo;
this.editing = true;
this.view.getValorField().setValue(calculoFondo.getValor());
this.view.getDescripcionField().setText(calculoFondo.getDescripcion());
}
}
private void eliminarActionListener() {
int selectedID = this.view.getTable().getSelectedRow();
if (selectedID >= 0) {
CalculoFondo calculoFondo = this.view.getTableModel().getCalculoFondo(selectedID);
this.view.getTableModel().removeRow(selectedID);
this.calculoFondoDAO.deleteCalculoFondo(calculoFondo);
this.updateResumen();
this.updateButtonsEnabled();
this.resetFocus();
}
}
private void guardarCalculoFondo(int valor, String descripcion) {
CalculoFondo calculoFondo = new CalculoFondo();
calculoFondo.setValor(valor);
calculoFondo.setDescripcion(descripcion);
calculoFondo.setCaja(this.caja);
this.calculoFondoDAO.insertCalculoFondo(calculoFondo);
this.view.getTableModel().addRow(calculoFondo);
}
private void editarCalculoFondo(int valor, String descripcion) {
this.editingCalculoFondo.setValor(valor);
this.editingCalculoFondo.setDescripcion(descripcion);
this.editingCalculoFondo.setCaja(this.caja);
this.calculoFondoDAO.updateCalculoFondo(editingCalculoFondo);
this.view.getTableModel().setCalculoFondo(this.editingId, this.editingCalculoFondo);
}
private void updateButtonsEnabled() {
if (this.view.getTable().getSelectedRow() >= 0) {
this.view.getEliminarButton().setEnabled(true);
this.view.getEditarButton().setEnabled(true);
} else {
this.view.getEliminarButton().setEnabled(false);
this.view.getEditarButton().setEnabled(false);
}
}
private void updateResumen() {
int fondo = this.view.getFondoField().getValue();
int suma = this.calculoFondoDAO.getTotalCalculoFondo(this.caja);
this.view.getSumaField().setValue(suma);
this.view.getDiferenciaField().setValue(suma - fondo);
}
private void cleanInput() {
this.view.getValorField().setValue(0);
this.view.getDescripcionField().setText("");
}
private void normalizeInput() {
if (this.view.getDescripcionField().getText() == null) {
this.view.getDescripcionField().setText("");
}
this.view.getDescripcionField().setText(this.view.getDescripcionField().getText().trim());
}
private void resetFocus() {
this.view.getValorField().requestFocus();
}
private class GuardarAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
CalcularFondoController.this.guardarActionListener();
}
}
private class UpdateResumenAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
CalcularFondoController.this.updateResumen();
}
}
}