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;
|
package danielcortes.xyz.controllers;
|
||||||
|
|
||||||
import danielcortes.xyz.data.Configuration;
|
|
||||||
import danielcortes.xyz.data.DAOManager;
|
import danielcortes.xyz.data.DAOManager;
|
||||||
import danielcortes.xyz.informes.InformeEstadoResultado;
|
import danielcortes.xyz.informes.InformeEstadoResultado;
|
||||||
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
|
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
|
||||||
import danielcortes.xyz.models.estado_resultado.EstadoResultadoDAO;
|
import danielcortes.xyz.models.estado_resultado.EstadoResultadoDAO;
|
||||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
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.EstadoResultadoView;
|
||||||
import danielcortes.xyz.views.dialogs.InformeGeneratedConfirmation;
|
|
||||||
import danielcortes.xyz.views.dialogs.XLSFileChooser;
|
|
||||||
import danielcortes.xyz.views.listeners.FocusLostListener;
|
import danielcortes.xyz.views.listeners.FocusLostListener;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.YearMonth;
|
import java.time.YearMonth;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
public class EstadoResultadoController extends BaseController {
|
public class EstadoResultadoController extends BaseController {
|
||||||
|
|
||||||
@@ -121,20 +117,8 @@ public class EstadoResultadoController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void exportarListener() {
|
private void exportarListener() {
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
|
Workbook wb = new InformeEstadoResultado(this.mes).generarInforme();
|
||||||
String formatedName = mes.format(formatter);
|
SaveFile.saveToTempFileAndOpen(wb, "estado_resultado");
|
||||||
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() {
|
private void updateMonth() {
|
||||||
|
|||||||
@@ -24,22 +24,16 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.controllers;
|
package danielcortes.xyz.controllers;
|
||||||
|
|
||||||
import danielcortes.xyz.data.Configuration;
|
|
||||||
import danielcortes.xyz.informes.InformeEgresosToExcel;
|
import danielcortes.xyz.informes.InformeEgresosToExcel;
|
||||||
import danielcortes.xyz.informes.InformeLibroDeVentasToExcel;
|
import danielcortes.xyz.informes.InformeLibroDeVentasToExcel;
|
||||||
import danielcortes.xyz.informes.InformeResumenArqueo;
|
import danielcortes.xyz.informes.InformeResumenArqueo;
|
||||||
import danielcortes.xyz.informes.InformeResumenArqueoToExcel;
|
import danielcortes.xyz.informes.InformeResumenArqueoToExcel;
|
||||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||||
import danielcortes.xyz.utils.SaveFile;
|
import danielcortes.xyz.utils.SaveFile;
|
||||||
import danielcortes.xyz.utils.StringUtils;
|
|
||||||
import danielcortes.xyz.views.InformesSideBar;
|
import danielcortes.xyz.views.InformesSideBar;
|
||||||
import danielcortes.xyz.views.dialogs.InformeGeneratedConfirmation;
|
|
||||||
import danielcortes.xyz.views.dialogs.MonthSelectDialog;
|
import danielcortes.xyz.views.dialogs.MonthSelectDialog;
|
||||||
import danielcortes.xyz.views.dialogs.TipoEgresoSelectDialog;
|
import danielcortes.xyz.views.dialogs.TipoEgresoSelectDialog;
|
||||||
import danielcortes.xyz.views.dialogs.XLSFileChooser;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.YearMonth;
|
import java.time.YearMonth;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
public class InformesSideBarController {
|
public class InformesSideBarController {
|
||||||
@@ -70,23 +64,10 @@ public class InformesSideBarController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
|
InformeLibroDeVentasToExcel informe = new InformeLibroDeVentasToExcel(month);
|
||||||
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();
|
Workbook wb = informe.generarInforme();
|
||||||
|
|
||||||
SaveFile.save(wb, saveFile);
|
SaveFile.saveToTempFileAndOpen(wb, "libro_de_ventas");
|
||||||
|
|
||||||
new InformeGeneratedConfirmation(saveFile).execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generarInformeEgresosListener() {
|
private void generarInformeEgresosListener() {
|
||||||
@@ -100,46 +81,22 @@ public class InformesSideBarController {
|
|||||||
return;
|
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);
|
InformeEgresosToExcel informe = new InformeEgresosToExcel(tipoEgreso, month);
|
||||||
Workbook wb = informe.generarInforme();
|
Workbook wb = informe.generarInforme();
|
||||||
SaveFile.save(wb, saveFile);
|
|
||||||
|
|
||||||
new InformeGeneratedConfirmation(saveFile).execute();
|
SaveFile.saveToTempFileAndOpen(wb, "informe_egresos");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generarInformeResumenArqueoListener() {
|
private void generarInformeResumenArqueoListener() {
|
||||||
System.out.println("Executed");
|
|
||||||
YearMonth mes = new MonthSelectDialog().execute();
|
YearMonth mes = new MonthSelectDialog().execute();
|
||||||
if (mes == null) {
|
if (mes == null) {
|
||||||
return;
|
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);
|
InformeResumenArqueo informe = InformeResumenArqueo.generate(mes);
|
||||||
Workbook wb = new InformeResumenArqueoToExcel(informe).generarInforme();
|
Workbook wb = new InformeResumenArqueoToExcel(informe).generarInforme();
|
||||||
SaveFile.save(wb, saveFile);
|
|
||||||
|
|
||||||
new InformeGeneratedConfirmation(saveFile).execute();
|
SaveFile.saveToTempFileAndOpen(wb, "resumen_arqueo");
|
||||||
System.out.println(informe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ import danielcortes.xyz.data.DAOManager;
|
|||||||
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
|
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
|
||||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||||
import danielcortes.xyz.utils.StringUtils;
|
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.YearMonth;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -40,7 +36,6 @@ public class InformeEstadoResultado {
|
|||||||
private ArrayList<Row> resumenGeneralRows;
|
private ArrayList<Row> resumenGeneralRows;
|
||||||
|
|
||||||
private YearMonth mes;
|
private YearMonth mes;
|
||||||
private Path saveFile;
|
|
||||||
|
|
||||||
private EstadoResultado estadoResultado;
|
private EstadoResultado estadoResultado;
|
||||||
|
|
||||||
@@ -49,9 +44,8 @@ public class InformeEstadoResultado {
|
|||||||
private CreationHelper createHelper;
|
private CreationHelper createHelper;
|
||||||
private HashMap<String, CellStyle> styles;
|
private HashMap<String, CellStyle> styles;
|
||||||
|
|
||||||
public InformeEstadoResultado(YearMonth mes, Path saveFile) {
|
public InformeEstadoResultado(YearMonth mes) {
|
||||||
this.mes = mes;
|
this.mes = mes;
|
||||||
this.saveFile = saveFile;
|
|
||||||
|
|
||||||
this.estadoResultado = DAOManager.getEstadoResultadoDAO().getByMonth(this.mes).orElse(EstadoResultado.EMPTY);
|
this.estadoResultado = DAOManager.getEstadoResultadoDAO().getByMonth(this.mes).orElse(EstadoResultado.EMPTY);
|
||||||
|
|
||||||
@@ -422,7 +416,7 @@ public class InformeEstadoResultado {
|
|||||||
pt.applyBorders(this.sheet);
|
pt.applyBorders(this.sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generarInforme() {
|
public Workbook generarInforme() {
|
||||||
fillTitle();
|
fillTitle();
|
||||||
fillVentaData();
|
fillVentaData();
|
||||||
fillGastosOperacionalesData();
|
fillGastosOperacionalesData();
|
||||||
@@ -432,11 +426,7 @@ public class InformeEstadoResultado {
|
|||||||
setStyles();
|
setStyles();
|
||||||
addBorders();
|
addBorders();
|
||||||
|
|
||||||
try (OutputStream fileOut = Files.newOutputStream(this.saveFile)) {
|
return wb;
|
||||||
wb.write(fileOut);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, CellStyle> generateStyles() {
|
private HashMap<String, CellStyle> generateStyles() {
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.informes;
|
package danielcortes.xyz.informes;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.YearMonth;
|
import java.time.YearMonth;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
@@ -89,7 +88,7 @@ public class InformeLibroDeVentasToExcel {
|
|||||||
private CreationHelper createHelper;
|
private CreationHelper createHelper;
|
||||||
private HashMap<String, CellStyle> styles;
|
private HashMap<String, CellStyle> styles;
|
||||||
|
|
||||||
public InformeLibroDeVentasToExcel(YearMonth mes, Path saveFile) {
|
public InformeLibroDeVentasToExcel(YearMonth mes) {
|
||||||
this.mes = mes;
|
this.mes = mes;
|
||||||
this.informe = InformeLibroDeVentas.generate(mes);
|
this.informe = InformeLibroDeVentas.generate(mes);
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,34 @@
|
|||||||
package danielcortes.xyz.utils;
|
package danielcortes.xyz.utils;
|
||||||
|
|
||||||
|
import java.awt.Desktop;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
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 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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user