Para lograrlo se realizo el mismo procedimiento que con el informe de libro de ventas Primero que nada se elmino el objeto de InformeEgresosContent que se tenia porque realmente no aportaba nada, era basicamente lo mismo que el objeto egresos con un campo de fecha añadido y creo que un campo menos. Por lo que se paso a utilizar el objeto de Egresos directamente. Debido a lo anterior no era necesario tener una query especial para juntar los datos, ya que solo eran los egresos de todas las cajas de un tipo en especifico, por lo que solo se hizo una query nueva en el EgresoDAO en el que se satisfacia esta necesidad. Luego fue solo hacer compatible el InformeEgresosToExcel y listo!
116 lines
3.9 KiB
Java
116 lines
3.9 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.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());
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|