Files
sistema-caja/src/danielcortes/xyz/controllers/InformesSideBarController.java
Daniel Cortes ada25ed373 Nuevo informe!!
Se me olvido hacer check-out a una nueva branch, I tried :c
2019-03-15 23:55:20 -03:00

146 lines
5.0 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.InformeEgresosToExcel;
import danielcortes.xyz.informes.InformeLibroDeVentasToExcel;
import danielcortes.xyz.informes.InformeResumenArqueo;
import danielcortes.xyz.informes.InformeResumenArqueoToExcel;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.utils.SaveFile;
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;
import org.apache.poi.ss.usermodel.Workbook;
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());
this.view.getGenerarResumenArqueoButton()
.addActionListener(e -> generarInformeResumenArqueoListener());
}
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;
}
InformeLibroDeVentasToExcel informe = new InformeLibroDeVentasToExcel(month, saveFile);
Workbook wb = informe.generarInforme();
SaveFile.save(wb, saveFile);
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;
}
InformeEgresosToExcel informe = new InformeEgresosToExcel(tipoEgreso, month);
Workbook wb = informe.generarInforme();
SaveFile.save(wb, saveFile);
new InformeGeneratedConfirmation(saveFile).execute();
}
private void generarInformeResumenArqueoListener() {
System.out.println("Executed");
YearMonth mes = new MonthSelectDialog().execute();
if (mes == null) {
return;
}
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") + "Resumen Arqueo" + capitalized).execute();
if (saveFile == null) {
return;
}
InformeResumenArqueo informe = InformeResumenArqueo.generate(mes);
Workbook wb = new InformeResumenArqueoToExcel(informe).generarInforme();
SaveFile.save(wb, saveFile);
new InformeGeneratedConfirmation(saveFile).execute();
System.out.println(informe);
}
}