Los informes generados son abiertos automaticamente
El usuario decia que era molesto tener que seleccionar el archivo donde guardar los informes, y luego ser preguntado si queria sobreescribirlo, para que al final le preguntara si queria abrirlo. Para solucionarlo se eliminaron todos esos pasos y ahora el archivo es guardado en un archivo temporal del sistema, es abierto automaticamente y luego es eliminado al cerrar el programa.
This commit is contained in:
BIN
dist/Programa Caja.jar
vendored
BIN
dist/Programa Caja.jar
vendored
Binary file not shown.
@@ -1,20 +1,16 @@
|
||||
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.utils.SaveFile;
|
||||
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;
|
||||
import java.util.Optional;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
public class EstadoResultadoController extends BaseController {
|
||||
|
||||
@@ -121,20 +117,8 @@ public class EstadoResultadoController extends BaseController {
|
||||
}
|
||||
|
||||
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();
|
||||
Workbook wb = new InformeEstadoResultado(this.mes).generarInforme();
|
||||
SaveFile.saveToTempFileAndOpen(wb, "estado_resultado");
|
||||
}
|
||||
|
||||
private void updateMonth() {
|
||||
|
||||
@@ -24,22 +24,16 @@
|
||||
|
||||
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 {
|
||||
@@ -70,23 +64,10 @@ public class InformesSideBarController {
|
||||
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);
|
||||
InformeLibroDeVentasToExcel informe = new InformeLibroDeVentasToExcel(month);
|
||||
Workbook wb = informe.generarInforme();
|
||||
|
||||
SaveFile.save(wb, saveFile);
|
||||
|
||||
new InformeGeneratedConfirmation(saveFile).execute();
|
||||
SaveFile.saveToTempFileAndOpen(wb, "libro_de_ventas");
|
||||
}
|
||||
|
||||
private void generarInformeEgresosListener() {
|
||||
@@ -100,46 +81,22 @@ public class InformesSideBarController {
|
||||
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();
|
||||
SaveFile.saveToTempFileAndOpen(wb, "informe_egresos");
|
||||
}
|
||||
|
||||
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);
|
||||
SaveFile.saveToTempFileAndOpen(wb, "resumen_arqueo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,10 +5,6 @@ import danielcortes.xyz.data.DAOManager;
|
||||
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.utils.StringUtils;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@@ -40,7 +36,6 @@ public class InformeEstadoResultado {
|
||||
private ArrayList<Row> resumenGeneralRows;
|
||||
|
||||
private YearMonth mes;
|
||||
private Path saveFile;
|
||||
|
||||
private EstadoResultado estadoResultado;
|
||||
|
||||
@@ -49,9 +44,8 @@ public class InformeEstadoResultado {
|
||||
private CreationHelper createHelper;
|
||||
private HashMap<String, CellStyle> styles;
|
||||
|
||||
public InformeEstadoResultado(YearMonth mes, Path saveFile) {
|
||||
public InformeEstadoResultado(YearMonth mes) {
|
||||
this.mes = mes;
|
||||
this.saveFile = saveFile;
|
||||
|
||||
this.estadoResultado = DAOManager.getEstadoResultadoDAO().getByMonth(this.mes).orElse(EstadoResultado.EMPTY);
|
||||
|
||||
@@ -422,7 +416,7 @@ public class InformeEstadoResultado {
|
||||
pt.applyBorders(this.sheet);
|
||||
}
|
||||
|
||||
public void generarInforme() {
|
||||
public Workbook generarInforme() {
|
||||
fillTitle();
|
||||
fillVentaData();
|
||||
fillGastosOperacionalesData();
|
||||
@@ -432,11 +426,7 @@ public class InformeEstadoResultado {
|
||||
setStyles();
|
||||
addBorders();
|
||||
|
||||
try (OutputStream fileOut = Files.newOutputStream(this.saveFile)) {
|
||||
wb.write(fileOut);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return wb;
|
||||
}
|
||||
|
||||
private HashMap<String, CellStyle> generateStyles() {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
package danielcortes.xyz.informes;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
@@ -89,7 +88,7 @@ public class InformeLibroDeVentasToExcel {
|
||||
private CreationHelper createHelper;
|
||||
private HashMap<String, CellStyle> styles;
|
||||
|
||||
public InformeLibroDeVentasToExcel(YearMonth mes, Path saveFile) {
|
||||
public InformeLibroDeVentasToExcel(YearMonth mes) {
|
||||
this.mes = mes;
|
||||
this.informe = InformeLibroDeVentas.generate(mes);
|
||||
|
||||
|
||||
@@ -1,18 +1,34 @@
|
||||
package danielcortes.xyz.utils;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
/**
|
||||
* Esta clase se dedicara a contenter los metodos
|
||||
* que guardaran distintos tipos de archivos
|
||||
*/
|
||||
public class SaveFile {
|
||||
public static void save(Workbook wb, Path saveFile){
|
||||
try (OutputStream fileOut = Files.newOutputStream(saveFile)) {
|
||||
wb.write(fileOut);
|
||||
|
||||
/**
|
||||
* Guarda un Workbook en un archivo temporal el cual sera eliminado una vez
|
||||
* que el programa sea cerrado, abre automaticamente el archivo generado
|
||||
* @param wb WorkBook a guardar
|
||||
* @param prefix prefijo para el archivo temporal.
|
||||
*/
|
||||
public static void saveToTempFileAndOpen(Workbook wb, String prefix){
|
||||
try {
|
||||
Path saveFile = Files.createTempFile(prefix, ".xls");
|
||||
saveFile.toFile().deleteOnExit();
|
||||
try (OutputStream out = Files.newOutputStream(saveFile)) {
|
||||
wb.write(out);
|
||||
}
|
||||
Desktop.getDesktop().open(saveFile.toFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user