Files
sistema-caja/src/danielcortes/xyz/controllers/InformesSideBarController.java

111 lines
3.8 KiB
Java

/*
* 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.controllers;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.informes.InformeEgresosExcel;
import danielcortes.xyz.informes.InformeLibroDeVentasExcel;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.utils.StringUtils;
import danielcortes.xyz.views.InformesSideBar;
import danielcortes.xyz.views.dialogs.InformeGeneratedConfirmation;
import danielcortes.xyz.views.dialogs.MonthSelectDialog;
import danielcortes.xyz.views.dialogs.TipoEgresoSelectDialog;
import danielcortes.xyz.views.dialogs.XLSFileChooser;
import java.nio.file.Path;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
public class InformesSideBarController {
private InformesSideBar view;
public InformesSideBarController(InformesSideBar view) {
this.view = view;
this.setupViewEvents();
}
public InformesSideBar getView() {
return view;
}
private void setupViewEvents() {
this.view.getInformeLibroDeVentasButton()
.addActionListener(e -> generarInformeLibroDeVentasListener());
this.view.getGenerarEgresosFacturasMateriaPrimaButton()
.addActionListener(e -> generarInformeEgresosListener());
}
private void generarInformeLibroDeVentasListener() {
YearMonth month = new MonthSelectDialog().execute();
if (month == null) {
return;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
String formatedName = month.format(formatter);
String capitalized = StringUtils.capitalize(formatedName);
Path saveFile = new XLSFileChooser(
Configuration.get("base_save_directory") + "Libro " + capitalized).execute();
if (saveFile == null) {
return;
}
InformeLibroDeVentasExcel informe = new InformeLibroDeVentasExcel(month, saveFile);
informe.generarInforme();
new InformeGeneratedConfirmation(saveFile).execute();
}
private void generarInformeEgresosListener() {
TipoEgreso tipoEgreso = new TipoEgresoSelectDialog().execute();
if (tipoEgreso == null) {
return;
}
YearMonth month = new MonthSelectDialog().execute();
if (month == null) {
return;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
String formatedMonth = month.format(formatter);
Path saveFile = new XLSFileChooser(
"Informe Egresos - " + tipoEgreso.getNombre() + " - " + StringUtils
.capitalize(formatedMonth)).execute();
if (saveFile == null) {
return;
}
InformeEgresosExcel informe = new InformeEgresosExcel(tipoEgreso.getId(), month, saveFile);
Path generatedFile = informe.generarInforme();
new InformeGeneratedConfirmation(saveFile).execute();
}
}