Generalizado el informe de egresos para que cree el necesitado segun su id
This commit is contained in:
@@ -24,11 +24,13 @@
|
||||
|
||||
package danielcortes.xyz.controllers;
|
||||
|
||||
import danielcortes.xyz.informes.InformeEgresosFacturaMateriaPrima;
|
||||
import danielcortes.xyz.informes.InformeEgresos;
|
||||
import danielcortes.xyz.informes.InformeLibroDeVentas;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.utils.StringUtils;
|
||||
import danielcortes.xyz.views.MonthSelectDialog;
|
||||
import danielcortes.xyz.views.InformesView;
|
||||
import danielcortes.xyz.views.TipoEgresoSelectDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
@@ -48,45 +50,53 @@ public class InformesController {
|
||||
|
||||
private void setupViewEvents() {
|
||||
this.view.getInformeLibroDeVentasButton().addActionListener(e -> generarInformeLibroDeVentasListener());
|
||||
this.view.getGenerarEgresosFacturasMateriaPrimaButton().addActionListener(e -> generarInformeEgresosFacturasMateriaPrima());
|
||||
this.view.getGenerarEgresosFacturasMateriaPrimaButton().addActionListener(e -> generarInformeEgresosListener());
|
||||
}
|
||||
|
||||
private void generarInformeLibroDeVentasListener() {
|
||||
LocalDate month = askForMonth();
|
||||
if (month != null) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
||||
|
||||
String formatedName = month.format(formatter);
|
||||
String capitalized = StringUtils.toUpperCase(formatedName);
|
||||
|
||||
File saveFile = askForFile("Libro " + capitalized);
|
||||
|
||||
if (saveFile != null) {
|
||||
InformeLibroDeVentas informe = new InformeLibroDeVentas(month, saveFile);
|
||||
File generatedFile = informe.generarInforme();
|
||||
|
||||
this.showConfirmation(generatedFile);
|
||||
}
|
||||
if (month == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
||||
String formatedName = month.format(formatter);
|
||||
String capitalized = StringUtils.toUpperCase(formatedName);
|
||||
|
||||
File saveFile = askForFile("Libro " + capitalized);
|
||||
if (saveFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
InformeLibroDeVentas informe = new InformeLibroDeVentas(month, saveFile);
|
||||
File generatedFile = informe.generarInforme();
|
||||
|
||||
this.showConfirmation(generatedFile);
|
||||
}
|
||||
|
||||
private void generarInformeEgresosFacturasMateriaPrima() {
|
||||
LocalDate month = askForMonth();
|
||||
if (month != null) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
||||
|
||||
String formatedName = month.format(formatter);
|
||||
String capitalized = StringUtils.toUpperCase(formatedName);
|
||||
|
||||
File saveFile = askForFile("Egresos Materia Prima " + capitalized);
|
||||
|
||||
if (saveFile != null) {
|
||||
InformeEgresosFacturaMateriaPrima informe = new InformeEgresosFacturaMateriaPrima(month, saveFile);
|
||||
File generatedFile = informe.generarInforme();
|
||||
|
||||
this.showConfirmation(generatedFile);
|
||||
}
|
||||
private void generarInformeEgresosListener() {
|
||||
TipoEgreso tipoEgreso = askForTipoEgreso();
|
||||
if (tipoEgreso == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalDate month = askForMonth();
|
||||
if (month == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
||||
String formatedMonth = month.format(formatter);
|
||||
|
||||
File saveFile = askForFile("Informe Egresos: " + tipoEgreso.getNombre() + " - " + StringUtils.toUpperCase(formatedMonth));
|
||||
if (saveFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
InformeEgresos informe = new InformeEgresos(tipoEgreso.getId(), month, saveFile);
|
||||
File generatedFile = informe.generarInforme();
|
||||
|
||||
this.showConfirmation(generatedFile);
|
||||
}
|
||||
|
||||
private LocalDate askForMonth() {
|
||||
@@ -98,6 +108,15 @@ public class InformesController {
|
||||
}
|
||||
}
|
||||
|
||||
private TipoEgreso askForTipoEgreso() {
|
||||
TipoEgresoSelectDialog tipoEgresoSelectDialog = new TipoEgresoSelectDialog(this.view.getContentPanel());
|
||||
if (tipoEgresoSelectDialog.isAcepted()) {
|
||||
return tipoEgresoSelectDialog.getTipoEgreso();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private File askForFile(String suggestedName) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
|
||||
Reference in New Issue
Block a user