Movida la necesidad de pasaar los objetos dao atravez de los constructores de las clases y se consiguen a travez de una clase estatica la que los crea previamente y simplemente los entrega a la clase que lo pide.

Supongo que dara mayor flexibilidad a cuando se quiera cambiar a un orm o cambiar la conexion a otra base de datos
This commit is contained in:
Daniel Cortes
2019-01-20 02:41:33 -03:00
parent b14222c875
commit e2e2412d3a
13 changed files with 659 additions and 534 deletions

View File

@@ -26,20 +26,6 @@ package danielcortes.xyz;
import danielcortes.xyz.controllers.ManagerController;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
import danielcortes.xyz.models.documentos.DocumentosDAO;
import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO;
import danielcortes.xyz.models.efectivo.EfectivoDAO;
import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
import danielcortes.xyz.models.egreso.SQLiteEgresoDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.models.ingreso.SQLiteIngresoDAO;
import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import danielcortes.xyz.views.ManagerView;
import javax.swing.*;
@@ -51,6 +37,26 @@ public class Main {
}
private static void run() {
setSystemProperties();
ManagerView view = new ManagerView();
ManagerController managerController = new ManagerController(view);
executeView(view.getContentPanel());
}
private static void executeView(JComponent view) {
JFrame frame = new JFrame("Caja: " + Configuration.get("nombre_caja"));
frame.setContentPane(view);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void setSystemProperties() {
System.setProperty("awt.useSystemAAFontSettings", "on");
System.setProperty("swing.aatext", "true");
@@ -62,25 +68,7 @@ public class Main {
Locale.setDefault(new Locale("es"));
CajaDAO cajaDAO = new SQLiteCajaDAO();
DocumentosDAO documentosDAO = new SQLiteDocumentosDAO();
EfectivoDAO efectivoDAO = new SQLiteEfectivoDAO();
EgresoDAO egresoDAO = new SQLiteEgresoDAO();
IngresoDAO ingresoDAO = new SQLiteIngresoDAO();
TipoEgresoDAO tipoEgresoDAO = new SQLiteTipoEgresoDAO();
TipoIngresoDAO tipoIngresoDAO = new SQLiteTipoIngresoDAO();
ManagerView view = new ManagerView();
ManagerController managerController = new ManagerController(view, cajaDAO, documentosDAO, efectivoDAO, egresoDAO, ingresoDAO, tipoEgresoDAO, tipoIngresoDAO);
JFrame frame = new JFrame("Caja: " + Configuration.get("nombre_caja"));
frame.setContentPane(view.getContentPanel());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setSize(780, 450);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}

View File

@@ -25,14 +25,10 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
import danielcortes.xyz.data.DAOManager;
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;
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;
@@ -51,21 +47,11 @@ public class ArqueoController {
private Efectivo efectivo;
private Documentos documentos;
private EfectivoDAO efectivoDAO;
private DocumentosDAO documentosDAO;
private IngresoDAO ingresoDAO;
private EgresoDAO egresoDAO;
/**
* 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) {
public ArqueoController(ArqueoView view) {
this.view = view;
this.efectivoDAO = efectivoDAO;
this.documentosDAO = documentosDAO;
this.ingresoDAO = ingresoDAO;
this.egresoDAO = egresoDAO;
this.setUpViewEvents();
}
@@ -92,7 +78,7 @@ public class ArqueoController {
* 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.efectivo = DAOManager.getEfectivoDAO().findByCaja(this.caja);
this.view.getVeinteMilField().setValue(efectivo.getVeinteMil());
this.view.getDiezMilField().setValue(efectivo.getDiezMil());
this.view.getCincoMilField().setValue(efectivo.getCincoMil());
@@ -108,7 +94,7 @@ public class ArqueoController {
* 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.documentos = DAOManager.getDocumentosDAO().findByCaja(caja);
this.view.getTarjetasField().setValue(documentos.getTarjetas());
this.view.getChequesField().setValue(documentos.getCheques());
this.view.getRetiroField().setValue(documentos.getRetiros());
@@ -129,7 +115,7 @@ public class ArqueoController {
*/
private void updateResumenEfectivo() {
NumberFormatedTextField efectivoField = this.view.getEfectivoField();
int total = efectivoDAO.getTotalEfectivo(this.caja);
int total = DAOManager.getEfectivoDAO().getTotalEfectivo(this.caja);
efectivoField.setValue(total);
}
@@ -138,7 +124,7 @@ public class ArqueoController {
*/
private void updateResumenDocumentos() {
NumberFormatedTextField documentosField = this.view.getDocumentosField();
int total = documentosDAO.getTotalDocumentos(this.caja);
int total = DAOManager.getDocumentosDAO().getTotalDocumentos(this.caja);
documentosField.setValue(total);
}
@@ -146,7 +132,7 @@ public class ArqueoController {
* Obtiene el total de egresos y lo muestra en el campo de egresosField
*/
private void updateResumenEgresos() {
int total = this.egresoDAO.getTotalEgreso(this.caja);
int total = DAOManager.getEgresoDAO().getTotalEgreso(this.caja);
this.view.getEgresosField().setValue(total);
}
@@ -154,10 +140,10 @@ public class ArqueoController {
* Calcula los datos de arqueo, rendido y ajuste y los muestra en sus campos correspondientes
*/
private void updateResumenArqueo() {
int totalEfectivo = efectivoDAO.getTotalEfectivo(this.caja);
int totalDocumentos = documentosDAO.getTotalDocumentos(this.caja);
int totalEgresos = egresoDAO.getTotalEgreso(this.caja);
int totalIngresos = ingresoDAO.getTotalIngreso(this.caja);
int totalEfectivo = DAOManager.getEfectivoDAO().getTotalEfectivo(this.caja);
int totalDocumentos = DAOManager.getDocumentosDAO().getTotalDocumentos(this.caja);
int totalEgresos = DAOManager.getEgresoDAO().getTotalEgreso(this.caja);
int totalIngresos = DAOManager.getIngresoDAO().getTotalIngreso(this.caja);
int rendido = totalDocumentos + totalEfectivo + totalEgresos;
int diferencia = rendido - totalIngresos;
@@ -241,7 +227,7 @@ public class ArqueoController {
* 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());
new CalcularFondoController(this.view.getContentPanel(), new CalcularFondoView(), this.caja);
}
/**
@@ -268,7 +254,7 @@ public class ArqueoController {
this.efectivo.setCincoMil(cincoMil);
this.efectivo.setDiezMil(diezMil);
this.efectivo.setVeinteMil(veinteMil);
this.efectivoDAO.updateEfectivo(efectivo);
DAOManager.getEfectivoDAO().updateEfectivo(efectivo);
this.updateResumenEfectivo();
this.updateResumenArqueo();
@@ -286,7 +272,7 @@ public class ArqueoController {
this.documentos.setTarjetas(tarjetas);
this.documentos.setCheques(cheques);
this.documentos.setRetiros(retiros);
this.documentosDAO.updateDocumentos(documentos);
DAOManager.getDocumentosDAO().updateDocumentos(documentos);
this.updateResumenDocumentos();
this.updateResumenArqueo();

View File

@@ -2,9 +2,9 @@ package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.DAOManager;
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;
@@ -17,17 +17,15 @@ 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) {
public CalcularFondoController(JComponent parent, CalcularFondoView view, Caja caja) {
this.view = view;
this.parent = parent;
this.caja = caja;
this.calculoFondoDAO = calculoFondoDAO;
this.fillTable();
this.updateResumen();
@@ -48,7 +46,7 @@ public class CalcularFondoController {
private void fillTable() {
FondoTableModel tableModel = this.view.getTableModel();
tableModel.removeRows();
for (CalculoFondo calculoFondo : this.calculoFondoDAO.findByCaja(this.caja)) {
for (CalculoFondo calculoFondo : DAOManager.getCalculoFondoDAO().findByCaja(this.caja)) {
tableModel.addRow(calculoFondo);
}
}
@@ -117,7 +115,7 @@ public class CalcularFondoController {
if (selectedID >= 0) {
CalculoFondo calculoFondo = this.view.getTableModel().getCalculoFondo(selectedID);
this.view.getTableModel().removeRow(selectedID);
this.calculoFondoDAO.deleteCalculoFondo(calculoFondo);
DAOManager.getCalculoFondoDAO().deleteCalculoFondo(calculoFondo);
this.updateResumen();
this.updateButtonsEnabled();
this.resetFocus();
@@ -129,7 +127,7 @@ public class CalcularFondoController {
calculoFondo.setValor(valor);
calculoFondo.setDescripcion(descripcion);
calculoFondo.setCaja(this.caja);
this.calculoFondoDAO.insertCalculoFondo(calculoFondo);
DAOManager.getCalculoFondoDAO().insertCalculoFondo(calculoFondo);
this.view.getTableModel().addRow(calculoFondo);
}
@@ -137,7 +135,7 @@ public class CalcularFondoController {
this.editingCalculoFondo.setValor(valor);
this.editingCalculoFondo.setDescripcion(descripcion);
this.editingCalculoFondo.setCaja(this.caja);
this.calculoFondoDAO.updateCalculoFondo(editingCalculoFondo);
DAOManager.getCalculoFondoDAO().updateCalculoFondo(editingCalculoFondo);
this.view.getTableModel().setCalculoFondo(this.editingId, this.editingCalculoFondo);
}
@@ -153,7 +151,7 @@ public class CalcularFondoController {
private void updateResumen() {
int fondo = this.view.getFondoField().getValue();
int suma = this.calculoFondoDAO.getTotalCalculoFondo(this.caja);
int suma = DAOManager.getCalculoFondoDAO().getTotalCalculoFondo(this.caja);
this.view.getSumaField().setValue(suma);
this.view.getDepositoField().setValue(suma - fondo);
}

View File

@@ -25,11 +25,10 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.egreso.Egreso;
import danielcortes.xyz.models.egreso.EgresoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
import danielcortes.xyz.views.EgresosView;
import danielcortes.xyz.views.components.EgresosTableModel;
@@ -44,8 +43,6 @@ import java.awt.event.MouseEvent;
*/
public class EgresosController {
private EgresosView view;
private EgresoDAO egresoDAO;
private TipoEgresoDAO tipoEgresoDAO;
private Caja caja;
private int editingId;
@@ -59,33 +56,13 @@ public class EgresosController {
* - Metodo que llena los tipos de egresos en la vista.
* - Actualiza el estado de los botones.
*/
public EgresosController(EgresosView view, EgresoDAO egresoDAO, TipoEgresoDAO tipoEgresoDAO) {
public EgresosController(EgresosView view) {
this.view = view;
this.egresoDAO = egresoDAO;
this.tipoEgresoDAO = tipoEgresoDAO;
this.setUpViewEvents();
this.fillTipoEgresoCombo();
this.updateButtonsEnabled();
}
/**
* Getter!
*
* @return
*/
public EgresoDAO getEgresoDAO() {
return egresoDAO;
}
/**
* Getter
*
* @return
*/
public TipoEgresoDAO getTipoEgresoDAO() {
return tipoEgresoDAO;
}
/**
* Guarda la caja entregada y actualiza los datos de la tabla de egresos y actualiza el field con el total de egresos.
*/
@@ -100,7 +77,7 @@ public class EgresosController {
*/
private void fillTipoEgresoCombo() {
JComboBox<TipoEgreso> tipoCombo = view.getTipoCombo();
for (TipoEgreso tipoEgreso : this.tipoEgresoDAO.findAll()) {
for (TipoEgreso tipoEgreso : DAOManager.getTipoEgresoDAO().findAll()) {
tipoCombo.addItem(tipoEgreso);
}
}
@@ -111,7 +88,7 @@ public class EgresosController {
private void fillEgresosTable() {
EgresosTableModel egresosTableModel = view.getEgresosTableModel();
egresosTableModel.removeRows();
for (Egreso egreso : this.egresoDAO.findByCaja(this.caja)) {
for (Egreso egreso : DAOManager.getEgresoDAO().findByCaja(this.caja)) {
egresosTableModel.addRow(egreso);
}
}
@@ -182,7 +159,7 @@ public class EgresosController {
if (selectedID >= 0) {
Egreso egreso = this.view.getEgresosTableModel().getEgreso(selectedID);
this.view.getEgresosTableModel().removeRow(selectedID);
this.egresoDAO.deleteEgreso(egreso);
DAOManager.getEgresoDAO().deleteEgreso(egreso);
this.updateTotalEgresos();
this.updateButtonsEnabled();
this.resetFocus();
@@ -219,7 +196,7 @@ public class EgresosController {
* Obtiene el total de egresos y los coloca en el campo de totalEgresosField.
*/
private void updateTotalEgresos() {
int total = this.egresoDAO.getTotalEgreso(this.caja);
int total = DAOManager.getEgresoDAO().getTotalEgreso(this.caja);
this.view.getTotalEgresosField().setValue(total);
}
@@ -249,7 +226,7 @@ public class EgresosController {
egreso.setNro(nro);
egreso.setTipoEgreso(tipo);
egreso.setCaja(caja);
egresoDAO.insertEgreso(egreso);
DAOManager.getEgresoDAO().insertEgreso(egreso);
this.view.getEgresosTableModel().addRow(egreso);
this.updateTotalEgresos();
this.clearInputs();
@@ -263,11 +240,11 @@ public class EgresosController {
*/
private void editarEgreso(String nro, String descripcion, int valor, TipoEgreso tipo, Caja caja) {
if (this.validateInput(nro, descripcion, tipo, caja)) {
this.editingEgreso.setValor(Integer.valueOf(valor));
this.editingEgreso.setValor(valor);
this.editingEgreso.setDescripcion(descripcion);
this.editingEgreso.setNro(nro);
this.editingEgreso.setTipoEgreso(tipo);
egresoDAO.updateEgreso(this.editingEgreso);
DAOManager.getEgresoDAO().updateEgreso(this.editingEgreso);
this.view.getEgresosTableModel().setEgreso(this.editingId, this.editingEgreso);
this.updateTotalEgresos();
this.clearInputs();

View File

@@ -24,11 +24,10 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.ingreso.Ingreso;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import danielcortes.xyz.views.IngresosView;
import danielcortes.xyz.views.components.IngresosTableModel;
@@ -43,8 +42,6 @@ import java.awt.event.MouseEvent;
*/
public class IngresosController {
private IngresosView view;
private IngresoDAO ingresoDAO;
private TipoIngresoDAO tipoIngresoDAO;
private Caja caja;
private int editingId;
@@ -58,30 +55,13 @@ public class IngresosController {
* - Metodo que genera los eventos para la vista
* - Metodo que actualiza el estado de los botones
*/
public IngresosController(IngresosView view, IngresoDAO ingresoDAO, TipoIngresoDAO tipoIngresoDAO) {
public IngresosController(IngresosView view) {
this.view = view;
this.ingresoDAO = ingresoDAO;
this.tipoIngresoDAO = tipoIngresoDAO;
this.fillTipoIngresoCombo();
this.setupViewEvents();
this.updateButtonsEnabled();
}
/**
* Getter!!
*/
public IngresoDAO getIngresoDAO() {
return ingresoDAO;
}
/**
* Getter!!!
*
* @return
*/
public TipoIngresoDAO getTipoIngresoDAO() {
return tipoIngresoDAO;
}
/**
* Guarda la caja ingresada y actualiza el contenido de la tabla de ingresos y el campo de total de ingresos
@@ -97,7 +77,7 @@ public class IngresosController {
*/
private void fillTipoIngresoCombo() {
JComboBox<TipoIngreso> tipoCombo = this.view.getTipoCombo();
for (TipoIngreso tipo : this.tipoIngresoDAO.findAll()) {
for (TipoIngreso tipo : DAOManager.getTipoIngresoDAO().findAll()) {
tipoCombo.addItem(tipo);
}
}
@@ -108,7 +88,7 @@ public class IngresosController {
private void fillIngresosTable() {
IngresosTableModel ingresosTableModel = this.view.getIngresosTableModel();
ingresosTableModel.removeRows();
for (Ingreso ingreso : this.ingresoDAO.findByCaja(this.caja)) {
for (Ingreso ingreso : DAOManager.getIngresoDAO().findByCaja(this.caja)) {
ingresosTableModel.addRow(ingreso);
}
}
@@ -186,7 +166,7 @@ public class IngresosController {
if (selectedId >= 0) {
Ingreso ingreso = this.view.getIngresosTableModel().getIngreso(selectedId);
this.view.getIngresosTableModel().removeRow(selectedId);
this.ingresoDAO.deleteIngreso(ingreso);
DAOManager.getIngresoDAO().deleteIngreso(ingreso);
this.updateTotalIngresos();
this.updateButtonsEnabled();
}
@@ -223,7 +203,7 @@ public class IngresosController {
* Obtiene el total de ingresos de la caja y lo coloca en el el field totalingresos
*/
private void updateTotalIngresos() {
int total = this.ingresoDAO.getTotalIngreso(this.caja);
int total = DAOManager.getIngresoDAO().getTotalIngreso(this.caja);
this.view.getTotalIngresoField().setValue(total);
}
@@ -257,7 +237,7 @@ public class IngresosController {
ingreso.setNroInicial(nroInicial);
ingreso.setNroFinal(nroFinal);
this.ingresoDAO.insertIngreso(ingreso);
DAOManager.getIngresoDAO().insertIngreso(ingreso);
this.view.getIngresosTableModel().addRow(ingreso);
this.clearInputs();
@@ -277,7 +257,7 @@ public class IngresosController {
this.editingIngreso.setNroZFinal(nroZFinal);
this.editingIngreso.setNroInicial(nroInicial);
this.editingIngreso.setNroFinal(nroFinal);
this.ingresoDAO.updateIngreso(this.editingIngreso);
DAOManager.getIngresoDAO().updateIngreso(this.editingIngreso);
this.view.getIngresosTableModel().setIngreso(this.editingId, this.editingIngreso);
this.updateTotalIngresos();
this.clearInputs();

View File

@@ -24,16 +24,10 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.documentos.Documentos;
import danielcortes.xyz.models.documentos.DocumentosDAO;
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.models.tipo_egreso.TipoEgresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import danielcortes.xyz.views.*;
import java.awt.*;
@@ -51,14 +45,6 @@ public class ManagerController {
private ArqueoController arqueoController;
private InformesController informesController;
private CajaDAO cajaDAO;
private DocumentosDAO documentosDAO;
private EfectivoDAO efectivoDAO;
private EgresoDAO egresoDAO;
private IngresoDAO ingresoDAO;
private TipoEgresoDAO tipoEgresoDAO;
private TipoIngresoDAO tipoIngresoDAO;
/**
* Crea el controlador
* Necesita todos las interfaces DAO para poder asignarselos a sus vistas,
@@ -70,15 +56,8 @@ public class ManagerController {
* - Genera los eventos de la vista
* - Presiona el boton de la vista inicial
*/
public ManagerController(ManagerView view, CajaDAO cajaDAO, DocumentosDAO documentosDAO, EfectivoDAO efectivoDAO, EgresoDAO egresoDAO, IngresoDAO ingresoDAO, TipoEgresoDAO tipoEgresoDAO, TipoIngresoDAO tipoIngresoDAO) {
public ManagerController(ManagerView view) {
this.view = view;
this.cajaDAO = cajaDAO;
this.documentosDAO = documentosDAO;
this.efectivoDAO = efectivoDAO;
this.egresoDAO = egresoDAO;
this.ingresoDAO = ingresoDAO;
this.tipoEgresoDAO = tipoEgresoDAO;
this.tipoIngresoDAO = tipoIngresoDAO;
this.loadCardContents();
this.setUpDate();
this.setUpViewEvents();
@@ -125,20 +104,20 @@ public class ManagerController {
*/
private void updateCaja() {
LocalDate selectedDate = this.view.getDatePicker().getDate();
Caja caja = this.cajaDAO.findByFecha(selectedDate);
Caja caja = DAOManager.getCajaDAO().findByFecha(selectedDate);
if (caja == null) {
caja = new Caja();
caja.setFecha(selectedDate);
this.cajaDAO.insertCaja(caja);
DAOManager.getCajaDAO().insertCaja(caja);
Efectivo efectivo = new Efectivo();
efectivo.setCaja(caja);
this.efectivoDAO.insertDefaultEfectivo(efectivo);
DAOManager.getEfectivoDAO().insertDefaultEfectivo(efectivo);
Documentos documentos = new Documentos();
documentos.setCaja(caja);
this.documentosDAO.insertDefaultDocumentos(documentos);
DAOManager.getDocumentosDAO().insertDefaultDocumentos(documentos);
}
this.ingresosController.updateCaja(caja);
@@ -164,7 +143,7 @@ public class ManagerController {
this.view.getCardPanel().add(ingresosView.getContentPanel(), "INGRESOS");
this.ingresosController = new IngresosController(ingresosView, this.ingresoDAO, this.tipoIngresoDAO);
this.ingresosController = new IngresosController(ingresosView);
}
/**
@@ -175,7 +154,7 @@ public class ManagerController {
this.view.getCardPanel().add(egresosView.getContentPanel(), "EGRESOS");
this.egresosController = new EgresosController(egresosView, this.egresoDAO, this.tipoEgresoDAO);
this.egresosController = new EgresosController(egresosView);
}
/**
@@ -186,7 +165,7 @@ public class ManagerController {
this.view.getCardPanel().add(arqueoView.getContentPanel(), "ARQUEO");
this.arqueoController = new ArqueoController(arqueoView, this.efectivoDAO, this.documentosDAO, this.ingresoDAO, this.egresoDAO);
this.arqueoController = new ArqueoController(arqueoView);
}
private void loadInformesView() {

View File

@@ -0,0 +1,112 @@
/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.data;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
import danielcortes.xyz.models.calculo_fondo.CalculoFondoDAO;
import danielcortes.xyz.models.calculo_fondo.SQLiteCalculoFondoDAO;
import danielcortes.xyz.models.documentos.DocumentosDAO;
import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO;
import danielcortes.xyz.models.efectivo.EfectivoDAO;
import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
import danielcortes.xyz.models.egreso.SQLiteEgresoDAO;
import danielcortes.xyz.models.informes.egresos.InformeEgresosContentDAO;
import danielcortes.xyz.models.informes.egresos.SQLiteInformeEgresosContentDAO;
import danielcortes.xyz.models.informes.libro_de_ventas.InformeLibroDeVentasContentDAO;
import danielcortes.xyz.models.informes.libro_de_ventas.SQLiteInformeLibroDeVentasContentDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.models.ingreso.SQLiteIngresoDAO;
import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
public class DAOManager {
private static final CajaDAO cajaDAO;
private static final CalculoFondoDAO calculoFondoDAO;
private static final DocumentosDAO documentosDAO;
private static final EfectivoDAO efectivoDAO;
private static final EgresoDAO egresoDAO;
private static final InformeEgresosContentDAO egresosContentDAO;
private static final InformeLibroDeVentasContentDAO libroDeVentasContentDAO;
private static final IngresoDAO ingresoDAO;
private static final TipoEgresoDAO tipoEgresoDAO;
private static final TipoIngresoDAO tipoIngresoDAO;
static {
cajaDAO = new SQLiteCajaDAO();
calculoFondoDAO = new SQLiteCalculoFondoDAO();
documentosDAO = new SQLiteDocumentosDAO();
efectivoDAO = new SQLiteEfectivoDAO();
egresoDAO = new SQLiteEgresoDAO();
egresosContentDAO = new SQLiteInformeEgresosContentDAO();
libroDeVentasContentDAO = new SQLiteInformeLibroDeVentasContentDAO();
ingresoDAO = new SQLiteIngresoDAO();
tipoEgresoDAO = new SQLiteTipoEgresoDAO();
tipoIngresoDAO = new SQLiteTipoIngresoDAO();
}
public static CajaDAO getCajaDAO() {
return cajaDAO;
}
public static CalculoFondoDAO getCalculoFondoDAO() {
return calculoFondoDAO;
}
public static DocumentosDAO getDocumentosDAO() {
return documentosDAO;
}
public static EfectivoDAO getEfectivoDAO() {
return efectivoDAO;
}
public static EgresoDAO getEgresoDAO() {
return egresoDAO;
}
public static InformeEgresosContentDAO getEgresosContentDAO() {
return egresosContentDAO;
}
public static InformeLibroDeVentasContentDAO getLibroDeVentasContentDAO() {
return libroDeVentasContentDAO;
}
public static IngresoDAO getIngresoDAO() {
return ingresoDAO;
}
public static TipoEgresoDAO getTipoEgresoDAO() {
return tipoEgresoDAO;
}
public static TipoIngresoDAO getTipoIngresoDAO() {
return tipoIngresoDAO;
}
}

View File

@@ -24,9 +24,9 @@
package danielcortes.xyz.informes;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
import danielcortes.xyz.models.informes.libro_de_ventas.InformeLibroDeVentasContent;
import danielcortes.xyz.models.informes.libro_de_ventas.SQLiteInformeLibroDeVentasContentDAO;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -77,7 +77,7 @@ public class InformeLibroDeVentas {
public InformeLibroDeVentas(LocalDate date, Path saveFile) {
new SQLiteCajaDAO().createCajasForMonth(date);
this.informe = new ArrayList<>(new SQLiteInformeLibroDeVentasContentDAO().getInformeMensual(date));
this.informe = new ArrayList<>(DAOManager.getLibroDeVentasContentDAO().getInformeMensual(date));
this.informeSize = this.informe.size();
this.saveFile = saveFile;

View File

@@ -48,6 +48,7 @@
package danielcortes.xyz.models.informes.libro_de_ventas;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.utils.NaturalOrderComparator;
import java.sql.Connection;
@@ -63,6 +64,7 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo
private HashMap<Integer, InformeLibroDeVentasContent> map;
public SQLiteInformeLibroDeVentasContentDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
this.map = new HashMap<>();
}

View File

@@ -25,6 +25,10 @@ package danielcortes.xyz.utils;
import java.util.Comparator;
public class NaturalOrderComparator implements Comparator {
static char charAt(String s, int i) {
return i >= s.length() ? 0 : s.charAt(i);
}
int compareRight(String a, String b) {
int bias = 0, ia = 0, ib = 0;
@@ -121,8 +125,4 @@ public class NaturalOrderComparator implements Comparator {
++ib;
}
}
static char charAt(String s, int i) {
return i >= s.length() ? 0 : s.charAt(i);
}
}

View File

@@ -53,14 +53,6 @@ public class NumberFormatedTextField extends JTextField {
this.addFocusListener(new FieldFocusListener());
}
/**
* 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
@@ -73,6 +65,14 @@ public class NumberFormatedTextField extends JTextField {
return this.value;
}
/**
* Guarda el integer entregado y lo muestra en el campo.
*/
public void setValue(int value) {
this.value = value;
this.setText(nf.format(value));
}
/**
* Lee el valor en el texto, ejecuta la operacion matematica que en caso que exista una y la almacena en el valor
* Si la operacion matematica es invalida, almacenara un 0