Metodos que creaban dialogos a clases
Se separaron estos metodos para mayor claridad en el codigo y mas facil reutilizacion de los dialogos ya que ahora me vi en el caso de que me encontraba utilizando estos metodos en 2 vistas separadas y me vi copiando los metodos de una a otra, pero eso no es bonito! asi que las separe en clases con un solo metodo publico llamado execute el cual devuelve el objeto que se espera recibir o un null en caso de que el usuario cancele el dialogo o ocurra algun error.
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
package danielcortes.xyz.controllers;
|
||||
|
||||
import danielcortes.xyz.data.Configuration;
|
||||
import danielcortes.xyz.data.DAOManager;
|
||||
import danielcortes.xyz.informes.InformeEstadoResultado;
|
||||
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
|
||||
import danielcortes.xyz.models.estado_resultado.EstadoResultadoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.utils.StringUtils;
|
||||
import danielcortes.xyz.views.EstadoResultadoView;
|
||||
import danielcortes.xyz.views.dialogs.InformeGeneratedConfirmation;
|
||||
import danielcortes.xyz.views.dialogs.XLSFileChooser;
|
||||
import danielcortes.xyz.views.listeners.FocusLostListener;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class EstadoResultadoController extends BaseController{
|
||||
public class EstadoResultadoController extends BaseController {
|
||||
private EstadoResultadoView view;
|
||||
private EstadoResultado estadoResultado;
|
||||
private YearMonth mes;
|
||||
@@ -20,11 +27,7 @@ public class EstadoResultadoController extends BaseController{
|
||||
this.updateMonth();
|
||||
}
|
||||
|
||||
public EstadoResultadoView getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
public void update() {
|
||||
this.updateMonth();
|
||||
}
|
||||
|
||||
@@ -36,9 +39,10 @@ public class EstadoResultadoController extends BaseController{
|
||||
this.setupMovementViewEvents();
|
||||
|
||||
this.view.getGuardarButton().addActionListener(e -> EstadoResultadoController.this.guardarListener());
|
||||
this.view.getExportarButton().addActionListener(e -> EstadoResultadoController.this.exportarListener());
|
||||
}
|
||||
|
||||
private void setupUpdateViewEvents(){
|
||||
private void setupUpdateViewEvents() {
|
||||
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());
|
||||
@@ -89,6 +93,22 @@ public class EstadoResultadoController extends BaseController{
|
||||
dao.updateEstadoResultado(this.estadoResultado);
|
||||
}
|
||||
|
||||
private void exportarListener() {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
|
||||
String formatedName = mes.format(formatter);
|
||||
String capitalized = StringUtils.capitalize(formatedName);
|
||||
|
||||
Path saveFile = new XLSFileChooser(Configuration.get("base_save_directory") + "Estado Resultado " + capitalized).execute();
|
||||
|
||||
if(saveFile == null){
|
||||
return;
|
||||
}
|
||||
|
||||
InformeEstadoResultado estadoResultado = new InformeEstadoResultado(this.mes, saveFile);
|
||||
estadoResultado.generarInforme();
|
||||
new InformeGeneratedConfirmation(saveFile).execute();
|
||||
}
|
||||
|
||||
private void updateMonth() {
|
||||
this.mes = this.view.getMonth();
|
||||
this.estadoResultado = DAOManager.getEstadoResultadoDAO().findByMonth(this.mes);
|
||||
@@ -108,8 +128,8 @@ public class EstadoResultadoController extends BaseController{
|
||||
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 ventaNeta = (int) Math.round((double) ventaBruta / 1.19d);
|
||||
int ventaIVA = ventaBruta - ventaNeta;
|
||||
int ventaNetaYExentas = ventaExentas + ventaNeta;
|
||||
|
||||
this.view.getVentaBrutaField().setValue(ventaBruta);
|
||||
@@ -120,21 +140,17 @@ public class EstadoResultadoController extends BaseController{
|
||||
}
|
||||
|
||||
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;
|
||||
int gastoTotal = efectivoFacturaGastosGenerales + efectivoGastoGeneralConBoleta + efectivoGastoGeneralSinRespaldo + cuentaCorrienteBoleta + cuentaCorrienteFactura + cuentaCorrienteSinRespaldo;
|
||||
|
||||
this.view.getGastosGeneralesEfectivoFacturaField().setValue(efectivoFacturaGastosGenerales);
|
||||
this.view.getGastosGeneralesEfectivoBoletaField().setValue(efectivoGastoGeneralConBoleta);
|
||||
@@ -160,7 +176,7 @@ public class EstadoResultadoController extends BaseController{
|
||||
|
||||
int total = costoVenta + remuneraciones + finiquitos + aguinaldo + bonosPersonal
|
||||
+ honorariosContador + arriendo + partime;
|
||||
double porcentajeCostoVenta = (double) costoVenta / (double)ventaBruta * 100d;
|
||||
double porcentajeCostoVenta = (double) costoVenta / (double) ventaBruta * 100d;
|
||||
|
||||
this.view.getGastosOperacionalesCostoVenta().setValue(costoVenta);
|
||||
this.view.getGastosOperacionesPorcentajeCostoVenta().setValue(porcentajeCostoVenta);
|
||||
@@ -285,7 +301,7 @@ public class EstadoResultadoController extends BaseController{
|
||||
int total = oldTotal
|
||||
- (oldCostoVenta + oldRemuneraciones + oldFiniquitos + oldAguinaldo + oldBonos + oldHonorarios + oldArriendo)
|
||||
+ (costoVenta + remuneraciones + finiquitos + aguinaldo + bonos + honorarios + arriendo);
|
||||
double porcentajeCostoVenta = (double) costoVenta / (double)ventaBruta * 100d;
|
||||
double porcentajeCostoVenta = (double) costoVenta / (double) ventaBruta * 100d;
|
||||
|
||||
this.view.getGastosOperacionalesTotal().setValue(total);
|
||||
this.view.getGastosOperacionesPorcentajeCostoVenta().setValue(porcentajeCostoVenta);
|
||||
@@ -294,31 +310,32 @@ public class EstadoResultadoController extends BaseController{
|
||||
}
|
||||
|
||||
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 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;
|
||||
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.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);
|
||||
this.estadoResultado.setPpm(ppm);
|
||||
this.estadoResultado.setIvaFavor(ivaFavor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user