Se a cambiado la organizacion de las ventanas y se creo la vista de estado resultado junto con su modelo
This commit is contained in:
281
src/danielcortes/xyz/controllers/EstadoResultadoController.java
Normal file
281
src/danielcortes/xyz/controllers/EstadoResultadoController.java
Normal file
@@ -0,0 +1,281 @@
|
||||
package danielcortes.xyz.controllers;
|
||||
|
||||
import danielcortes.xyz.data.DAOManager;
|
||||
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
|
||||
import danielcortes.xyz.models.estado_resultado.EstadoResultadoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.views.EstadoResultadoView;
|
||||
import danielcortes.xyz.views.listeners.FocusLostListener;
|
||||
|
||||
import java.time.YearMonth;
|
||||
|
||||
public class EstadoResultadoController {
|
||||
private EstadoResultadoView view;
|
||||
private EstadoResultado estadoResultado;
|
||||
private YearMonth mes;
|
||||
|
||||
public EstadoResultadoController(EstadoResultadoView view) {
|
||||
this.view = view;
|
||||
this.setupViewEvents();
|
||||
this.updateMonth();
|
||||
}
|
||||
|
||||
private void setupViewEvents() {
|
||||
this.view.getMonthCombo().addActionListener(e -> this.updateMonth());
|
||||
this.view.getYearSpinner().addChangeListener(e -> this.updateMonth());
|
||||
|
||||
this.view.getGastosGeneralesCuentaCorrienteFactura().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosGenerales());
|
||||
this.view.getGastosGeneralesCuentaCorrienteBoleta().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosGenerales());
|
||||
this.view.getGastosGeneralesCuentaCorrienteSinRespaldo().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosGenerales());
|
||||
|
||||
this.view.getServiciosAgua().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateServicios());
|
||||
this.view.getServiciosLuz().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateServicios());
|
||||
this.view.getServiciosGas().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateServicios());
|
||||
this.view.getServiciosTelefono().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateServicios());
|
||||
this.view.getServiciosOtro().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateServicios());
|
||||
|
||||
this.view.getGastosOperacionalesCostoVenta().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosOperacionales());
|
||||
this.view.getGastosOperacionalesRemuneraciones().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosOperacionales());
|
||||
this.view.getGastosOperacionalesFiniquitos().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosOperacionales());
|
||||
this.view.getGastosOperacionalesAguinaldo().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosOperacionales());
|
||||
this.view.getGastosOperacionalesBonos().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosOperacionales());
|
||||
this.view.getGastosOperacionalesHonorariosContador().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosOperacionales());
|
||||
this.view.getGastosOperacionalesArriendo().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateGastosOperacionales());
|
||||
|
||||
this.view.getResumenIVAFavor().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateResumen());
|
||||
this.view.getResumenPPM().addFocusListener((FocusLostListener) e -> EstadoResultadoController.this.updateResumen());
|
||||
|
||||
this.view.getGuardarButton().addActionListener(e -> EstadoResultadoController.this.guardarListener());
|
||||
}
|
||||
|
||||
private void guardarListener() {
|
||||
EstadoResultadoDAO dao = DAOManager.getEstadoResultadoDAO();
|
||||
dao.updateEstadoResultado(this.estadoResultado);
|
||||
}
|
||||
|
||||
private void updateMonth() {
|
||||
this.mes = this.view.getMonth();
|
||||
this.estadoResultado = DAOManager.getEstadoResultadoDAO().findByMonth(this.mes);
|
||||
if (estadoResultado == null) {
|
||||
this.estadoResultado = EstadoResultado.emptyEstadoResultado;
|
||||
this.estadoResultado.setMes(this.mes);
|
||||
DAOManager.getEstadoResultadoDAO().insertEstadoResultado(estadoResultado);
|
||||
}
|
||||
|
||||
this.fillVentas();
|
||||
this.fillGastosGenerales();
|
||||
this.fillServicios();
|
||||
this.fillGastosOperacionales();
|
||||
this.fillResumen();
|
||||
}
|
||||
|
||||
private void fillVentas() {
|
||||
int ventaBruta = DAOManager.getIngresoDAO().getTotalIngresoMes(this.mes);
|
||||
int ventaExentas = DAOManager.getIngresoDAO().getTotalExentasMes(this.mes);
|
||||
int ventaIVA = (int) Math.round((double) ventaBruta * .19d);
|
||||
int ventaNeta = ventaBruta - ventaIVA;
|
||||
int ventaNetaYExentas = ventaExentas + ventaNeta;
|
||||
|
||||
this.view.getVentaBrutaField().setValue(ventaBruta);
|
||||
this.view.getVentaIVAField().setValue(ventaIVA);
|
||||
this.view.getVentaNetaField().setValue(ventaNeta);
|
||||
this.view.getVentaExentasField().setValue(ventaExentas);
|
||||
this.view.getVentasNetaExentasField().setValue(ventaNetaYExentas);
|
||||
}
|
||||
|
||||
private void fillGastosGenerales() {
|
||||
TipoEgreso facturaMateriaPrima = DAOManager.getTipoEgresoDAO().findByNombre("Factura Materia Prima").get(0);
|
||||
TipoEgreso facturaGastosGenerales = DAOManager.getTipoEgresoDAO().findByNombre("Factura Gastos Generales").get(0);
|
||||
TipoEgreso gastoGeneralConBoleta = DAOManager.getTipoEgresoDAO().findByNombre("Gasto General Con Boleta").get(0);
|
||||
TipoEgreso gastoMenorMateriaPrima = DAOManager.getTipoEgresoDAO().findByNombre("Gasto Menor Materia Prima").get(0);
|
||||
TipoEgreso gastoGeneralSinRespaldo = DAOManager.getTipoEgresoDAO().findByNombre("Gasto General Sin Respaldo").get(0);
|
||||
|
||||
int cuentaCorrienteFactura = this.estadoResultado.getCuentaCorrienteFactura();
|
||||
int cuentaCorrienteBoleta = this.estadoResultado.getCuentaCorrienteBoleta();
|
||||
int cuentaCorrienteSinRespaldo = this.estadoResultado.getCuentaCorrienteSinRespaldo();
|
||||
int efectivoFacturaMateriaPrima = DAOManager.getEgresoDAO().getTotalEgresoMesPorTipo(this.mes, facturaMateriaPrima);
|
||||
int efectivoFacturaGastosGenerales = DAOManager.getEgresoDAO().getTotalEgresoMesPorTipo(this.mes, facturaGastosGenerales);
|
||||
int efectivoGastoGeneralConBoleta = DAOManager.getEgresoDAO().getTotalEgresoMesPorTipo(this.mes, gastoGeneralConBoleta);
|
||||
int efectivoGastoMenorMateriaPrima = DAOManager.getEgresoDAO().getTotalEgresoMesPorTipo(this.mes, gastoMenorMateriaPrima);
|
||||
int efectivoGastoGeneralSinRespaldo = DAOManager.getEgresoDAO().getTotalEgresoMesPorTipo(this.mes, gastoGeneralSinRespaldo);
|
||||
int gastoTotal = efectivoFacturaMateriaPrima + efectivoFacturaGastosGenerales + efectivoGastoGeneralConBoleta + efectivoGastoMenorMateriaPrima + efectivoGastoGeneralSinRespaldo + cuentaCorrienteBoleta + cuentaCorrienteFactura + cuentaCorrienteSinRespaldo;
|
||||
|
||||
this.view.getGastosGeneralesEfectivoFacturaField().setValue(efectivoFacturaGastosGenerales + efectivoFacturaMateriaPrima);
|
||||
this.view.getGastosGeneralesEfectivoBoletaField().setValue(efectivoGastoGeneralConBoleta + efectivoGastoMenorMateriaPrima);
|
||||
this.view.getGastosGeneralesEfectivoSinRespaldo().setValue(efectivoGastoGeneralSinRespaldo);
|
||||
this.view.getGastosGeneralesCuentaCorrienteFactura().setValue(cuentaCorrienteFactura);
|
||||
this.view.getGastosGeneralesCuentaCorrienteBoleta().setValue(cuentaCorrienteBoleta);
|
||||
this.view.getGastosGeneralesCuentaCorrienteSinRespaldo().setValue(cuentaCorrienteSinRespaldo);
|
||||
this.view.getGastosGeneralesTotal().setValue(gastoTotal);
|
||||
}
|
||||
|
||||
private void fillGastosOperacionales() {
|
||||
TipoEgreso tipoPagoPartime = DAOManager.getTipoEgresoDAO().findByNombre("Pago Partime").get(0);
|
||||
|
||||
int costosVenta = this.estadoResultado.getCostoVenta();
|
||||
int remuneraciones = this.estadoResultado.getRemuneraciones();
|
||||
int finiquitos = this.estadoResultado.getFiniquitos();
|
||||
int aguinaldo = this.estadoResultado.getAguinaldo();
|
||||
int bonosPersonal = this.estadoResultado.getBonosPersonal();
|
||||
int honorariosContador = this.estadoResultado.getHonorariosContador();
|
||||
int arriendo = this.estadoResultado.getArriendo();
|
||||
int partime = DAOManager.getEgresoDAO().getTotalEgresoMesPorTipo(this.mes, tipoPagoPartime);
|
||||
|
||||
int total = costosVenta + remuneraciones + finiquitos + aguinaldo + bonosPersonal
|
||||
+ honorariosContador + arriendo + partime;
|
||||
|
||||
this.view.getGastosOperacionalesCostoVenta().setValue(costosVenta);
|
||||
this.view.getGastosOperacionalesRemuneraciones().setValue(remuneraciones);
|
||||
this.view.getGastosOperacionalesFiniquitos().setValue(finiquitos);
|
||||
this.view.getGastosOperacionalesAguinaldo().setValue(aguinaldo);
|
||||
this.view.getGastosOperacionalesBonos().setValue(bonosPersonal);
|
||||
this.view.getGastosOperacionalesHonorariosContador().setValue(honorariosContador);
|
||||
this.view.getGastosOperacionalesArriendo().setValue(arriendo);
|
||||
this.view.getGastosOperacionalesPartime().setValue(partime);
|
||||
|
||||
this.view.getGastosOperacionalesTotal().setValue(total);
|
||||
}
|
||||
|
||||
private void fillServicios() {
|
||||
int agua = this.estadoResultado.getAgua();
|
||||
int luz = this.estadoResultado.getLuz();
|
||||
int gas = this.estadoResultado.getGas();
|
||||
int telefono = this.estadoResultado.getTelefono();
|
||||
int otro = this.estadoResultado.getOtroServicio();
|
||||
|
||||
int total = agua + luz + gas + telefono + otro;
|
||||
|
||||
this.view.getServiciosAgua().setValue(agua);
|
||||
this.view.getServiciosLuz().setValue(luz);
|
||||
this.view.getServiciosGas().setValue(gas);
|
||||
this.view.getServiciosTelefono().setValue(telefono);
|
||||
this.view.getServiciosOtro().setValue(telefono);
|
||||
this.view.getServiciosTotal().setValue(total);
|
||||
}
|
||||
|
||||
private void fillResumen() {
|
||||
double ppm = this.estadoResultado.getPpm();
|
||||
int aFavor = this.estadoResultado.getIvaFavor();
|
||||
|
||||
this.view.getResumenPPM().setValue(ppm);
|
||||
this.view.getResumenIVAFavor().setValue(aFavor);
|
||||
|
||||
this.updateResumen();
|
||||
}
|
||||
|
||||
private void updateGastosGenerales() {
|
||||
int oldCuentaCorrienteFactura = this.estadoResultado.getCuentaCorrienteFactura();
|
||||
int oldCuentaCorrienteBoleta = this.estadoResultado.getCuentaCorrienteBoleta();
|
||||
int oldCuentaCorrienteSinRespaldo = this.estadoResultado.getCuentaCorrienteSinRespaldo();
|
||||
int oldTotal = this.view.getGastosGeneralesTotal().getValue();
|
||||
|
||||
int cuentaCorrienteFactura = this.view.getGastosGeneralesCuentaCorrienteFactura().getValue();
|
||||
int cuentaCorrienteBoleta = this.view.getGastosGeneralesCuentaCorrienteBoleta().getValue();
|
||||
int cuentaCorrienteSinRespaldo = this.view.getGastosGeneralesCuentaCorrienteSinRespaldo().getValue();
|
||||
|
||||
this.estadoResultado.setCuentaCorrienteFactura(cuentaCorrienteFactura);
|
||||
this.estadoResultado.setCuentaCorrienteBoleta(cuentaCorrienteBoleta);
|
||||
this.estadoResultado.setCuentaCorrienteSinRespaldo(cuentaCorrienteSinRespaldo);
|
||||
|
||||
int total = oldTotal
|
||||
- (oldCuentaCorrienteFactura + oldCuentaCorrienteBoleta + oldCuentaCorrienteSinRespaldo)
|
||||
+ (cuentaCorrienteFactura + cuentaCorrienteBoleta + cuentaCorrienteSinRespaldo);
|
||||
|
||||
this.view.getGastosGeneralesTotal().setValue(total);
|
||||
|
||||
this.updateResumen();
|
||||
}
|
||||
|
||||
private void updateServicios() {
|
||||
int oldAgua = this.estadoResultado.getAgua();
|
||||
int oldLuz = this.estadoResultado.getLuz();
|
||||
int oldGas = this.estadoResultado.getGas();
|
||||
int oldTelefono = this.estadoResultado.getTelefono();
|
||||
int oldOtro = this.estadoResultado.getOtroServicio();
|
||||
int oldTotal = this.view.getServiciosTotal().getValue();
|
||||
|
||||
int agua = this.view.getServiciosAgua().getValue();
|
||||
int luz = this.view.getServiciosLuz().getValue();
|
||||
int gas = this.view.getServiciosGas().getValue();
|
||||
int telefono = this.view.getServiciosTelefono().getValue();
|
||||
int otro = this.view.getServiciosOtro().getValue();
|
||||
|
||||
this.estadoResultado.setAgua(agua);
|
||||
this.estadoResultado.setLuz(luz);
|
||||
this.estadoResultado.setGas(gas);
|
||||
this.estadoResultado.setTelefono(telefono);
|
||||
this.estadoResultado.setOtroServicio(otro);
|
||||
|
||||
int total = oldTotal
|
||||
- (oldAgua + oldLuz + oldGas + oldTelefono + oldOtro)
|
||||
+ (agua + luz + gas + telefono + otro);
|
||||
|
||||
this.view.getServiciosTotal().setValue(total);
|
||||
|
||||
this.updateResumen();
|
||||
}
|
||||
|
||||
private void updateGastosOperacionales() {
|
||||
int oldCostoVenta = this.estadoResultado.getCostoVenta();
|
||||
int oldRemuneraciones = this.estadoResultado.getRemuneraciones();
|
||||
int oldFiniquitos = this.estadoResultado.getFiniquitos();
|
||||
int oldAguinaldo = this.estadoResultado.getAguinaldo();
|
||||
int oldBonos = this.estadoResultado.getBonosPersonal();
|
||||
int oldHonorarios = this.estadoResultado.getHonorariosContador();
|
||||
int oldArriendo = this.estadoResultado.getArriendo();
|
||||
int oldTotal = this.view.getGastosOperacionalesTotal().getValue();
|
||||
|
||||
int costoVenta = this.view.getGastosOperacionalesCostoVenta().getValue();
|
||||
int remuneraciones = this.view.getGastosOperacionalesRemuneraciones().getValue();
|
||||
int finiquitos = this.view.getGastosOperacionalesFiniquitos().getValue();
|
||||
int aguinaldo = this.view.getGastosOperacionalesAguinaldo().getValue();
|
||||
int bonos = this.view.getGastosOperacionalesBonos().getValue();
|
||||
int honorarios = this.view.getGastosOperacionalesHonorariosContador().getValue();
|
||||
int arriendo = this.view.getGastosOperacionalesArriendo().getValue();
|
||||
|
||||
this.estadoResultado.setCostoVenta(costoVenta);
|
||||
this.estadoResultado.setRemuneraciones(remuneraciones);
|
||||
this.estadoResultado.setFiniquitos(finiquitos);
|
||||
this.estadoResultado.setAguinaldo(aguinaldo);
|
||||
this.estadoResultado.setBonosPersonal(bonos);
|
||||
this.estadoResultado.setHonorariosContador(honorarios);
|
||||
this.estadoResultado.setArriendo(arriendo);
|
||||
|
||||
int total = oldTotal
|
||||
- (oldCostoVenta + oldRemuneraciones + oldFiniquitos + oldAguinaldo + oldBonos + oldHonorarios + oldArriendo)
|
||||
+ (costoVenta + remuneraciones + finiquitos + aguinaldo + bonos + honorarios + arriendo);
|
||||
|
||||
this.view.getGastosOperacionalesTotal().setValue(total);
|
||||
|
||||
this.updateResumen();
|
||||
}
|
||||
|
||||
private void updateResumen() {
|
||||
int bruto = this.view.getVentaBrutaField().getValue();
|
||||
int totalGastosOperacionales = this.view.getGastosOperacionalesTotal().getValue();
|
||||
int totalGastosGenerales = this.view.getGastosGeneralesTotal().getValue();
|
||||
int totalServicios = this.view.getServiciosTotal().getValue();
|
||||
int netoExentas = this.view.getVentasNetaExentasField().getValue();
|
||||
int iva = this.view.getVentaIVAField().getValue();
|
||||
double ppm = this.view.getResumenPPM().getValue();
|
||||
int ivaFavor = this.view.getResumenIVAFavor().getValue();
|
||||
|
||||
int utilidad = bruto - totalGastosGenerales - totalGastosOperacionales - totalServicios;
|
||||
int ppmMes = (int) Math.round(ppm * (double)netoExentas / 100d);
|
||||
int IVAPPM = iva + ppmMes;
|
||||
int aPagar = IVAPPM - ivaFavor;
|
||||
int resultado = utilidad - aPagar;
|
||||
|
||||
|
||||
this.view.getResumenUtilidad().setValue(utilidad);
|
||||
this.view.getResumenPPMMes().setValue(ppmMes);
|
||||
this.view.getResumenIVAMes().setValue(iva);
|
||||
this.view.getResumenIVAPPM().setValue(IVAPPM);
|
||||
this.view.getResumenAPagar().setValue(aPagar);
|
||||
this.view.getResumenResultado().setValue(resultado);
|
||||
|
||||
this.estadoResultado.setPpm(ppm);
|
||||
this.estadoResultado.setIvaFavor(ivaFavor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user