Resubido todo
This commit is contained in:
163
src/danielcortes/xyz/controllers/ManagerController.java
Normal file
163
src/danielcortes/xyz/controllers/ManagerController.java
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 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.controllers;
|
||||
|
||||
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.documentos.MysqlDocumentosDAO;
|
||||
import danielcortes.xyz.models.efectivo.Efectivo;
|
||||
import danielcortes.xyz.models.efectivo.EfectivoDAO;
|
||||
import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
|
||||
import danielcortes.xyz.models.egreso.EgresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.IngresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.MysqlIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.egreso.MysqlEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
||||
import danielcortes.xyz.views.ArqueoView;
|
||||
import danielcortes.xyz.views.EgresosView;
|
||||
import danielcortes.xyz.views.IngresosView;
|
||||
import danielcortes.xyz.views.ManagerView;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
public class ManagerController {
|
||||
private ManagerView view;
|
||||
private CajaDAO cajaDAO;
|
||||
private DocumentosDAO documentosDAO;
|
||||
private EfectivoDAO efectivoDAO;
|
||||
private EgresoDAO egresoDAO;
|
||||
private IngresoDAO ingresoDAO;
|
||||
private TipoEgresoDAO tipoEgresoDAO;
|
||||
private TipoIngresoDAO tipoIngresoDAO;
|
||||
private IngresosController ingresosController;
|
||||
private EgresosController egresosController;
|
||||
private ArqueoController arqueoController;
|
||||
|
||||
public ManagerController(ManagerView view, CajaDAO cajaDAO, DocumentosDAO documentosDAO, EfectivoDAO efectivoDAO, EgresoDAO egresoDAO, IngresoDAO ingresoDAO, TipoEgresoDAO tipoEgresoDAO, TipoIngresoDAO tipoIngresoDAO) {
|
||||
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();
|
||||
this.pressInitialButton();
|
||||
}
|
||||
|
||||
private void setUpDate(){
|
||||
this.view.getDatePicker().setDateToToday();
|
||||
this.updateCaja();
|
||||
}
|
||||
|
||||
private void setUpViewEvents() {
|
||||
this.view.getEgresosButton().addActionListener(e -> {
|
||||
CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout();
|
||||
layout.show(this.view.getCardPanel(), "EGRESOS");
|
||||
});
|
||||
this.view.getIngresosButton().addActionListener(e -> {
|
||||
CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout();
|
||||
layout.show(this.view.getCardPanel(), "INGRESOS");
|
||||
});
|
||||
|
||||
this.view.getArqueoButton().addActionListener(e -> {
|
||||
this.arqueoController.updateResumen();
|
||||
|
||||
CardLayout layout = (CardLayout) this.view.getCardPanel().getLayout();
|
||||
layout.show(this.view.getCardPanel(), "ARQUEO");
|
||||
});
|
||||
|
||||
this.view.getDatePicker().addDateChangeListener(e -> updateCaja());
|
||||
}
|
||||
|
||||
private void updateCaja(){
|
||||
LocalDate selectedDate = this.view.getDatePicker().getDate();
|
||||
Caja caja = this.cajaDAO.findByFecha(selectedDate);
|
||||
|
||||
if(caja == null){
|
||||
caja = new Caja();
|
||||
caja.setFecha(selectedDate);
|
||||
this.cajaDAO.insertCaja(caja);
|
||||
|
||||
Efectivo efectivo = new Efectivo();
|
||||
efectivo.setCaja(caja);
|
||||
this.efectivoDAO.insertDefaultEfectivo(efectivo);
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
documentos.setCaja(caja);
|
||||
this.documentosDAO.insertDefaultDocumentos(documentos);
|
||||
}
|
||||
|
||||
this.ingresosController.updateCaja(caja);
|
||||
this.egresosController.updateCaja(caja);
|
||||
this.arqueoController.updateCaja(caja);
|
||||
}
|
||||
|
||||
private void loadCardContents() {
|
||||
this.loadEgresosView();
|
||||
this.loadIngresosView();
|
||||
this.loadArqueoView();
|
||||
}
|
||||
|
||||
private void loadIngresosView() {
|
||||
IngresosView ingresosView = new IngresosView();
|
||||
|
||||
this.view.getCardPanel().add(ingresosView.getContentPanel(), "INGRESOS");
|
||||
|
||||
this.ingresosController = new IngresosController(ingresosView, this.ingresoDAO, this.tipoIngresoDAO);
|
||||
}
|
||||
|
||||
private void loadEgresosView() {
|
||||
EgresosView egresosView = new EgresosView();
|
||||
|
||||
this.view.getCardPanel().add(egresosView.getContentPanel(), "EGRESOS");
|
||||
|
||||
this.egresosController = new EgresosController(egresosView, this.egresoDAO, this.tipoEgresoDAO);
|
||||
}
|
||||
|
||||
private void loadArqueoView() {
|
||||
ArqueoView arqueoView = new ArqueoView();
|
||||
|
||||
this.view.getCardPanel().add(arqueoView.getContentPanel(), "ARQUEO");
|
||||
|
||||
this.arqueoController = new ArqueoController(arqueoView, this.efectivoDAO, this.documentosDAO, this.ingresoDAO, this.egresoDAO);
|
||||
}
|
||||
|
||||
private void pressInitialButton() {
|
||||
this.view.getIngresosButton().doClick();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user