diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f7c39dc..b819e41 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -11,11 +11,13 @@
-
+
+
+
@@ -71,64 +73,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
@@ -334,7 +279,7 @@
-
+
@@ -360,7 +305,7 @@
-
+
@@ -542,7 +487,8 @@
-
+
+
1545280618093
@@ -747,11 +693,18 @@
1546736429914
-
+
+ 1546737934935
+
+
+
+ 1546737934935
+
+
-
+
@@ -764,9 +717,8 @@
-
-
+
@@ -855,7 +807,6 @@
-
@@ -880,7 +831,8 @@
-
+
+
@@ -1294,10 +1246,109 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -1312,50 +1363,32 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1372,146 +1405,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/dist/caja.jar b/dist/caja.jar
index a119c3d..d5af263 100644
Binary files a/dist/caja.jar and b/dist/caja.jar differ
diff --git a/dist/database.sqlite b/dist/database.sqlite
index 2c7ba86..6f21ed7 100644
Binary files a/dist/database.sqlite and b/dist/database.sqlite differ
diff --git a/src/danielcortes/xyz/controllers/ArqueoController.java b/src/danielcortes/xyz/controllers/ArqueoController.java
index 6450290..3592df2 100644
--- a/src/danielcortes/xyz/controllers/ArqueoController.java
+++ b/src/danielcortes/xyz/controllers/ArqueoController.java
@@ -107,8 +107,8 @@ public class ArqueoController {
*/
private void fillDocumentos() {
this.documentos = this.documentosDAO.findByCaja(caja);
- this.view.getTarjetasField().setText(String.valueOf(documentos.getTarjetas()));
- this.view.getChequesField().setText(String.valueOf(documentos.getCheques()));
+ this.view.getTarjetasField().setValue(documentos.getTarjetas());
+ this.view.getChequesField().setValue(documentos.getCheques());
}
/**
@@ -197,6 +197,7 @@ public class ArqueoController {
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.getGuardarEfectivoButton().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()));
@@ -207,16 +208,15 @@ public class ArqueoController {
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.getGuardarEfectivoButton().getActionMap().put("save", new GuardarEfectivoAction(this));
this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
this.view.getTarjetasField().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("save", new GuardarDocumentosAction(this));
+ this.view.getGuardarDocumentosButton().getActionMap().put("save", new GuardarDocumentosAction(this));
-
- this.view.getGuardarEfectivoButton().addActionListener(e -> guardarEfectivoActionListener());
- this.view.getGuardarDocumentosButton().addActionListener(e -> guardarDocumentosActionListener());
}
/**
@@ -233,8 +233,7 @@ public class ArqueoController {
* Primero llama a normalizar el input, luego a esconder los mensajes de error y finalmente a guardar los documentos
*/
private void guardarDocumentosActionListener(){
- this.normalizeDocumentosInput();
- this.hiddeDocumentosErrorMessages();
+ this.view.getGuardarDocumentosButton().requestFocus();
this.guardarDocumentos();
}
@@ -273,87 +272,20 @@ public class ArqueoController {
* llama a updateResumenDocumentos y updateResumenArqueo para actualizar los datos de documentosField y arqueoField
*/
private void guardarDocumentos() {
- String tarjetas = this.view.getTarjetasField().getText();
- String cheques = this.view.getChequesField().getText();
+ int tarjetas = this.view.getTarjetasField().getValue();
+ int cheques = this.view.getChequesField().getValue();
- if (this.validateDocumentosInput(tarjetas, cheques)) {
- this.documentos.setTarjetas(Integer.valueOf(tarjetas));
- this.documentos.setCheques(Integer.valueOf(cheques));
- this.documentosDAO.updateDocumentos(documentos);
+ this.documentos.setTarjetas(tarjetas);
+ this.documentos.setCheques(cheques);
+ this.documentosDAO.updateDocumentos(documentos);
- this.updateResumenDocumentos();
- this.updateResumenArqueo();
- }
+ this.updateResumenDocumentos();
+ this.updateResumenArqueo();
}
- /**
- * Llama a las validaciones necesarias el input de Documentos
- * @return si es que todas las validaciones fueron correctas
- */
- private boolean validateDocumentosInput(String tarjetas, String cheques) {
-
- boolean tarjetasValidation = validateDocumentosValor(tarjetas, this.view.getErrorTarjetas());
- boolean chequesValidation = validateDocumentosValor(cheques, this.view.getErrorCheques());
-
- return tarjetasValidation && chequesValidation;
- }
-
- /**
- * Valida el valor entregado contra las siguientes pruebas
- * - Es null
- * - Esta vacio
- * - Los caracteres no son solamente digitos
- * - El largo es mayor que diez
- * Setea un mensaje de error correspondiente en el errorLabel entregado.
- * @return cuando cualquiera de los casos anteriores sea true se retorna falso, si no retorna true.
- */
- private boolean validateDocumentosValor(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;
- }
-
- /**
- * Esconde los mensajes de error en los campos de documentos
- */
- private void hiddeDocumentosErrorMessages(){
- this.view.getErrorTarjetas().setVisible(false);
- this.view.getErrorCheques().setVisible(false);
- }
-
- /**
- * Ejecuta trim sobre todos los campos de documentos
- */
- private void normalizeDocumentosInput() {
- this.view.getChequesField().setText(this.view.getChequesField().getText().trim());
- this.view.getTarjetasField().setText(this.view.getTarjetasField().getText().trim());
- }
-
- private class GuardarEfectivoAction extends AbstractAction{
+ private class GuardarEfectivoAction extends AbstractAction {
ArqueoController controller;
+
GuardarEfectivoAction(ArqueoController controller){
this.controller = controller;
}
@@ -364,8 +296,9 @@ public class ArqueoController {
}
}
- private class GuardarDocumentosAction extends AbstractAction{
+ private class GuardarDocumentosAction extends AbstractAction {
ArqueoController controller;
+
GuardarDocumentosAction(ArqueoController controller){
this.controller = controller;
}
diff --git a/src/danielcortes/xyz/views/ArqueoView.form b/src/danielcortes/xyz/views/ArqueoView.form
index ed369a9..78cca37 100644
--- a/src/danielcortes/xyz/views/ArqueoView.form
+++ b/src/danielcortes/xyz/views/ArqueoView.form
@@ -335,7 +335,7 @@
-
+
@@ -345,52 +345,42 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
@@ -399,16 +389,6 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/src/danielcortes/xyz/views/ArqueoView.java b/src/danielcortes/xyz/views/ArqueoView.java
index c148659..fe0b69c 100644
--- a/src/danielcortes/xyz/views/ArqueoView.java
+++ b/src/danielcortes/xyz/views/ArqueoView.java
@@ -45,16 +45,14 @@ public class ArqueoView {
private NumberFormatedTextField cienField;
private NumberFormatedTextField cincuentaField;
private NumberFormatedTextField diezField;
- private JTextField chequesField;
- private JTextField tarjetasField;
+ private NumberFormatedTextField chequesField;
+ private NumberFormatedTextField tarjetasField;
private NumberFormatedTextField efectivoField;
private NumberFormatedTextField documentosField;
private NumberFormatedTextField egresosField;
private NumberFormatedTextField rendidoField;
private JButton guardarEfectivoButton;
private JButton guardarDocumentosButton;
- private JLabel errorCheques;
- private JLabel errorTarjetas;
private NumberFormatedTextField diferenciaField;
private NumberFormatedTextField debeRendirField;
@@ -98,11 +96,11 @@ public class ArqueoView {
return diezField;
}
- public JTextField getChequesField() {
+ public NumberFormatedTextField getChequesField() {
return chequesField;
}
- public JTextField getTarjetasField() {
+ public NumberFormatedTextField getTarjetasField() {
return tarjetasField;
}
@@ -130,14 +128,6 @@ public class ArqueoView {
return guardarDocumentosButton;
}
- public JLabel getErrorCheques() {
- return errorCheques;
- }
-
- public JLabel getErrorTarjetas() {
- return errorTarjetas;
- }
-
public NumberFormatedTextField getDiferenciaField() {
return diferenciaField;
}
@@ -282,34 +272,24 @@ public class ArqueoView {
guardarEfectivoButton.setText("Guardar");
panel3.add(guardarEfectivoButton, new GridConstraints(9, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
final JPanel panel4 = new JPanel();
- panel4.setLayout(new GridLayoutManager(5, 2, new Insets(10, 10, 10, 10), -1, -1));
+ panel4.setLayout(new GridLayoutManager(3, 2, new Insets(10, 10, 10, 10), -1, -1));
panel2.add(panel4, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
panel4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Detalle Documentos", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, this.$$$getFont$$$(null, -1, -1, panel4.getFont())));
- chequesField = new JTextField();
- chequesField.setText("0");
+ chequesField = new NumberFormatedTextField();
+ chequesField.setText("");
panel4.add(chequesField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
final JLabel label16 = new JLabel();
label16.setText("Tarjetas de Credito");
- panel4.add(label16, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- tarjetasField = new JTextField();
- tarjetasField.setText("0");
- panel4.add(tarjetasField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
+ panel4.add(label16, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ tarjetasField = new NumberFormatedTextField();
+ tarjetasField.setText("");
+ panel4.add(tarjetasField, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
guardarDocumentosButton = new JButton();
guardarDocumentosButton.setText("Guardar");
- panel4.add(guardarDocumentosButton, new GridConstraints(4, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- errorCheques = new JLabel();
- errorCheques.setForeground(new Color(-65536));
- errorCheques.setText("Error");
- errorCheques.setVisible(false);
- panel4.add(errorCheques, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ panel4.add(guardarDocumentosButton, new GridConstraints(2, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label17 = new JLabel();
label17.setText("Cheques al Dia");
panel4.add(label17, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- errorTarjetas = new JLabel();
- errorTarjetas.setForeground(new Color(-65536));
- errorTarjetas.setText("Error");
- errorTarjetas.setVisible(false);
- panel4.add(errorTarjetas, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
contentPanel.add(spacer1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
}
diff --git a/src/danielcortes/xyz/views/components/NumberFormatedTextField.java b/src/danielcortes/xyz/views/components/NumberFormatedTextField.java
index 16bac11..1bf98a3 100644
--- a/src/danielcortes/xyz/views/components/NumberFormatedTextField.java
+++ b/src/danielcortes/xyz/views/components/NumberFormatedTextField.java
@@ -32,10 +32,20 @@ import java.awt.event.KeyEvent;
import java.text.NumberFormat;
import java.text.ParseException;
+/**
+ * Crea un JTextField que formatea automaticamente su texto como un integer el cual se puede obtener
+ * con el metodo getValue. Ademas de tener comportamientos especiales:
+ * - Al ganar foco se selecciona todo el texto.
+ * - Al perder foco formatea el texto como numero.
+ * - Solo se pueden ingresar 9 digitos.
+ */
public class NumberFormatedTextField extends JTextField {
private int value;
private NumberFormat nf;
+ /**
+ * Crea una instacia del objeto
+ */
public NumberFormatedTextField() {
super();
@@ -45,15 +55,29 @@ public class NumberFormatedTextField extends JTextField {
this.addKeyListener(new FieldKeyAdapter());
}
+ /**
+ * Guarda el integer entregado y lo muestra en el campo.
+ */
public void setValue(int value){
this.value = value;
this.setText(nf.format(value));
}
+ /**
+ * Llama a readValue por un bug seguramente relacionado con el focus listener:
+ * - No actualizaba el valor al momento de hacer requestfocus a otro componente, probablemente porque no alcanza
+ * a realizarse la accion antes que ocurra la siguiente
+ *
+ * Fuerza a que se lea el valor en el textfield antes de retornarlo
+ */
public int getValue(){
+ this.readValue();
return this.value;
}
+ /**
+ * Lee el valor en el texto y lo almacena en la instancia
+ */
private void readValue(){
try {
String currentText = this.getText();
@@ -65,6 +89,9 @@ public class NumberFormatedTextField extends JTextField {
}
}
+ /**
+ * Formatea el value y lo muestra en el field
+ */
private void formatText(){
this.setText(nf.format(this.value));
}