|
|
|
|
@@ -48,6 +48,14 @@ public class ArqueoController {
|
|
|
|
|
private IngresoDAO ingresoDAO;
|
|
|
|
|
private EgresoDAO egresoDAO;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Crea el controlador y ejecuta el metodo que genera los eventos para su vista.
|
|
|
|
|
* @param view Vista del arqueo
|
|
|
|
|
* @param efectivoDAO Data access object para el manejo de efectivo
|
|
|
|
|
* @param documentosDAO Data access object para el manejo de documentos
|
|
|
|
|
* @param ingresoDAO Data access object para el manejo de los ingresos
|
|
|
|
|
* @param egresoDAO Data access object para el manejo de los egresos
|
|
|
|
|
*/
|
|
|
|
|
public ArqueoController(ArqueoView view, EfectivoDAO efectivoDAO, DocumentosDAO documentosDAO, IngresoDAO ingresoDAO, EgresoDAO egresoDAO) {
|
|
|
|
|
this.view = view;
|
|
|
|
|
this.efectivoDAO = efectivoDAO;
|
|
|
|
|
@@ -58,17 +66,27 @@ public class ArqueoController {
|
|
|
|
|
this.setUpViewEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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) {
|
|
|
|
|
this.caja = caja;
|
|
|
|
|
fillDocumentos();
|
|
|
|
|
fillEfectivo();
|
|
|
|
|
fillResumen();
|
|
|
|
|
this.fillDocumentos();
|
|
|
|
|
this.fillEfectivo();
|
|
|
|
|
this.fillResumen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Acceso publico para rellenar el resumen
|
|
|
|
|
*/
|
|
|
|
|
public void updateResumen() {
|
|
|
|
|
this.fillResumen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rellena los campos del efectivo con la instancia de efectivo que pertenece a la caja
|
|
|
|
|
*/
|
|
|
|
|
private void fillEfectivo() {
|
|
|
|
|
this.efectivo = this.efectivoDAO.findByCaja(this.caja);
|
|
|
|
|
this.view.getVeinteMilField().setText(String.valueOf(efectivo.getVeinteMil()));
|
|
|
|
|
@@ -82,12 +100,18 @@ public class ArqueoController {
|
|
|
|
|
this.view.getDiezField().setText(String.valueOf(efectivo.getDiez()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rellea los campos de documentos con la instancia de documentos que pertenece a la caja
|
|
|
|
|
*/
|
|
|
|
|
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()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Llama a todos los metodos que llenan y calculan los campos de resumen
|
|
|
|
|
*/
|
|
|
|
|
private void fillResumen() {
|
|
|
|
|
this.updateResumenEfectivo();
|
|
|
|
|
this.updateResumenDocumentos();
|
|
|
|
|
@@ -96,6 +120,9 @@ public class ArqueoController {
|
|
|
|
|
this.updateResumenArqueo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calcula el total de efectivo y lo muestra en el efectivoField
|
|
|
|
|
*/
|
|
|
|
|
private void updateResumenEfectivo() {
|
|
|
|
|
JTextField efectivoField = this.view.getEfectivoField();
|
|
|
|
|
int total = 0;
|
|
|
|
|
@@ -112,6 +139,9 @@ public class ArqueoController {
|
|
|
|
|
efectivoField.setText(String.valueOf(total));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calcula el total de documentos y lo muestra en el documentosField
|
|
|
|
|
*/
|
|
|
|
|
private void updateResumenDocumentos() {
|
|
|
|
|
JTextField documentosField = this.view.getDocumentosField();
|
|
|
|
|
int total = 0;
|
|
|
|
|
@@ -121,16 +151,25 @@ public class ArqueoController {
|
|
|
|
|
documentosField.setText(String.valueOf(total));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtiene el total de ingresos para la caja y lo muestra en el campo ingresosField
|
|
|
|
|
*/
|
|
|
|
|
private void updateResumenIngresos() {
|
|
|
|
|
int total = this.ingresoDAO.getTotalIngreso(this.caja);
|
|
|
|
|
this.view.getIngresosField().setText(String.valueOf(total));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtiene el total de egresos y lo muestra en el campo de egresosField
|
|
|
|
|
*/
|
|
|
|
|
private void updateResumenEgresos() {
|
|
|
|
|
int total = this.egresoDAO.getTotalEgreso(this.caja);
|
|
|
|
|
this.view.getEgresosField().setText(String.valueOf(total));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calcula los datos de arqueo, rendido y ajuste y los muestra en sus campos correspondientes
|
|
|
|
|
*/
|
|
|
|
|
private void updateResumenArqueo() {
|
|
|
|
|
int totalEfectivo = Integer.parseInt(this.view.getEfectivoField().getText());
|
|
|
|
|
int totalDocumentos = Integer.parseInt(this.view.getDocumentosField().getText());
|
|
|
|
|
@@ -152,17 +191,26 @@ public class ArqueoController {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setea los eventos de los botones de guardar
|
|
|
|
|
*/
|
|
|
|
|
private void setUpViewEvents() {
|
|
|
|
|
this.view.getGuardarEfectivoButton().addActionListener(e -> {
|
|
|
|
|
this.normalizeEfectivoInput();
|
|
|
|
|
this.hiddeEfectivoErrorMessages();
|
|
|
|
|
this.guardarEfectivo();
|
|
|
|
|
});
|
|
|
|
|
this.view.getGuardarDocumentosButton().addActionListener(e -> {
|
|
|
|
|
this.normalizeDocumentosInput();
|
|
|
|
|
this.hiddeDocumentosErrorMessages();
|
|
|
|
|
this.guardarDocumentos();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
private void guardarEfectivo() {
|
|
|
|
|
String diez = this.view.getDiezField().getText();
|
|
|
|
|
String cincuenta = this.view.getCincuentaField().getText();
|
|
|
|
|
@@ -191,6 +239,10 @@ public class ArqueoController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Guarda los datos del detalle de documentos solo despues de que los campos sean validados, luego de guardar
|
|
|
|
|
* 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();
|
|
|
|
|
@@ -205,8 +257,11 @@ public class ArqueoController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Llama a las validaciones necesarias para el input de Efectivo
|
|
|
|
|
* @return si es que paso todas las validaciones.
|
|
|
|
|
*/
|
|
|
|
|
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());
|
|
|
|
|
@@ -221,8 +276,11 @@ public class ArqueoController {
|
|
|
|
|
return diezValidation && cincuentaValidation && cienValidation && quinientosValidation && milValidation && dosMilValidation && cincoMilValidation && diezMilValidation && veinteMilValidation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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) {
|
|
|
|
|
this.hiddeDocumentosErrorMessages();
|
|
|
|
|
|
|
|
|
|
boolean tarjetasValidation = validateDocumentosValor(tarjetas, this.view.getErrorTarjetas());
|
|
|
|
|
boolean chequesValidation = validateDocumentosValor(cheques, this.view.getErrorCheques());
|
|
|
|
|
@@ -230,6 +288,15 @@ public class ArqueoController {
|
|
|
|
|
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 validateEfectivoMoneda(String valor, JLabel errorLabel) {
|
|
|
|
|
if (valor == null) {
|
|
|
|
|
errorLabel.setText("Hubo un problema con los datos");
|
|
|
|
|
@@ -258,6 +325,15 @@ public class ArqueoController {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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) {
|
|
|
|
|
@@ -287,6 +363,9 @@ public class ArqueoController {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Esconde los mensajes de error de los campos de efectivo
|
|
|
|
|
*/
|
|
|
|
|
private void hiddeEfectivoErrorMessages() {
|
|
|
|
|
this.view.getErrorDiez().setVisible(false);
|
|
|
|
|
this.view.getErrorCincuenta().setVisible(false);
|
|
|
|
|
@@ -299,11 +378,17 @@ public class ArqueoController {
|
|
|
|
|
this.view.getErrorVeinteMil().setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 efectivo
|
|
|
|
|
*/
|
|
|
|
|
private void normalizeEfectivoInput() {
|
|
|
|
|
this.view.getDiezField().setText(this.view.getDiezField().getText().trim());
|
|
|
|
|
this.view.getCincuentaField().setText(this.view.getCincuentaField().getText().trim());
|
|
|
|
|
@@ -316,6 +401,9 @@ public class ArqueoController {
|
|
|
|
|
this.view.getVeinteMilField().setText(this.view.getVeinteMilField().getText().trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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());
|
|
|
|
|
|