diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c6d594a..5889183 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -10,22 +10,19 @@
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
-
-
+
+
+
+
@@ -89,7 +86,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
-
@@ -251,6 +257,7 @@
+
@@ -276,6 +283,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -284,7 +321,6 @@
-
@@ -298,7 +334,7 @@
-
+
@@ -528,6 +564,9 @@
+
+
+
1545280618093
@@ -858,11 +897,25 @@
1547590232009
-
+
+ 1547620493306
+
+
+
+ 1547620493306
+
+
+ 1547620625508
+
+
+
+ 1547620625508
+
+
-
+
@@ -875,8 +928,9 @@
+
-
+
@@ -1002,8 +1056,6 @@
-
-
@@ -1027,19 +1079,15 @@
-
+
+
+
-
-
-
-
-
-
@@ -1286,13 +1334,6 @@
-
-
-
-
-
-
-
@@ -1333,16 +1374,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1423,7 +1454,7 @@
-
+
@@ -1448,43 +1479,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1515,9 +1509,6 @@
-
-
-
@@ -1527,38 +1518,96 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dist/caja.jar b/dist/caja.jar
index c53b98a..a85846b 100644
Binary files a/dist/caja.jar and b/dist/caja.jar differ
diff --git a/src/danielcortes/xyz/controllers/InformesController.java b/src/danielcortes/xyz/controllers/InformesController.java
index 8686b84..c9d8689 100644
--- a/src/danielcortes/xyz/controllers/InformesController.java
+++ b/src/danielcortes/xyz/controllers/InformesController.java
@@ -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);
diff --git a/src/danielcortes/xyz/informes/InformeEgresosFacturaMateriaPrima.java b/src/danielcortes/xyz/informes/InformeEgresos.java
similarity index 95%
rename from src/danielcortes/xyz/informes/InformeEgresosFacturaMateriaPrima.java
rename to src/danielcortes/xyz/informes/InformeEgresos.java
index 33d8a3d..6c0ee44 100644
--- a/src/danielcortes/xyz/informes/InformeEgresosFacturaMateriaPrima.java
+++ b/src/danielcortes/xyz/informes/InformeEgresos.java
@@ -25,8 +25,9 @@
package danielcortes.xyz.informes;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
-import danielcortes.xyz.models.informes.egresos.InformeEgresosFacturasMateriaPrimaContent;
-import danielcortes.xyz.models.informes.egresos.SQLiteInformeEgresosFacturasMateriaPrimaContentDAO;
+import danielcortes.xyz.models.informes.egresos.InformeEgresosContent;
+import danielcortes.xyz.models.informes.egresos.SQLiteInformeEgresosContentDAO;
+import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.utils.Pair;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
@@ -41,7 +42,7 @@ import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
-public class InformeEgresosFacturaMateriaPrima {
+public class InformeEgresos {
private final String[] titles = {
"FECHA",
"N°",
@@ -49,7 +50,7 @@ public class InformeEgresosFacturaMateriaPrima {
"VALOR"
};
- private List informe;
+ private List informe;
private File saveFile;
//Filas donde se almacenaran los totales
@@ -67,9 +68,9 @@ public class InformeEgresosFacturaMateriaPrima {
private CreationHelper createHelper;
private HashMap styles;
- public InformeEgresosFacturaMateriaPrima(LocalDate date, File saveFile) {
+ public InformeEgresos(int tipoEgresoId, LocalDate date, File saveFile) {
new SQLiteCajaDAO().createCajasForMonth(date);
- this.informe = new SQLiteInformeEgresosFacturasMateriaPrimaContentDAO().getInformeEgresosFactuasMateriaPrima(date);
+ this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(date, tipoEgresoId);
this.saveFile = saveFile;
this.wb = new HSSFWorkbook();
@@ -97,7 +98,7 @@ public class InformeEgresosFacturaMateriaPrima {
int dayEnd;
for (int informeID = 0; informeID < informe.size(); informeID++) {
- InformeEgresosFacturasMateriaPrimaContent data = informe.get(informeID);
+ InformeEgresosContent data = informe.get(informeID);
int cellCounter = 0;
Row dataRow = sheet.createRow(rowCounter);
dataRows.add(dataRow);
diff --git a/src/danielcortes/xyz/models/informes/egresos/InformeEgresosFacturasMateriaPrimaContent.java b/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContent.java
similarity index 94%
rename from src/danielcortes/xyz/models/informes/egresos/InformeEgresosFacturasMateriaPrimaContent.java
rename to src/danielcortes/xyz/models/informes/egresos/InformeEgresosContent.java
index 38d19cf..5991325 100644
--- a/src/danielcortes/xyz/models/informes/egresos/InformeEgresosFacturasMateriaPrimaContent.java
+++ b/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContent.java
@@ -26,7 +26,7 @@ package danielcortes.xyz.models.informes.egresos;
import java.time.LocalDate;
-public class InformeEgresosFacturasMateriaPrimaContent {
+public class InformeEgresosContent {
private LocalDate fecha;
private String nro;
private String descripcion;
@@ -66,7 +66,7 @@ public class InformeEgresosFacturasMateriaPrimaContent {
@Override
public String toString() {
- return "InformeEgresosFacturasMateriaPrimaContent{" +
+ return "InformeEgresosContent{" +
"fecha=" + fecha +
", nro='" + nro + '\'' +
", descripcion='" + descripcion + '\'' +
diff --git a/src/danielcortes/xyz/models/informes/egresos/InformeEgresosFacturasMateriaPrimaContentDAO.java b/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContentDAO.java
similarity index 88%
rename from src/danielcortes/xyz/models/informes/egresos/InformeEgresosFacturasMateriaPrimaContentDAO.java
rename to src/danielcortes/xyz/models/informes/egresos/InformeEgresosContentDAO.java
index e1f3519..73a521e 100644
--- a/src/danielcortes/xyz/models/informes/egresos/InformeEgresosFacturasMateriaPrimaContentDAO.java
+++ b/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContentDAO.java
@@ -27,11 +27,11 @@ package danielcortes.xyz.models.informes.egresos;
import java.time.LocalDate;
import java.util.List;
-public abstract class InformeEgresosFacturasMateriaPrimaContentDAO {
+public abstract class InformeEgresosContentDAO {
/**
* Genera el informe con nombre muy largo
* @param month mes sobre el cual se quiere le informe
* @return lista del objeto que contiene los datos necesarios para el informe
*/
- public abstract List getInformeEgresosFactuasMateriaPrima(LocalDate month);
+ public abstract List getInformeEgresosFactuasMateriaPrima(LocalDate month, int tipoEgresoId);
}
diff --git a/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosFacturasMateriaPrimaContentDAO.java b/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosContentDAO.java
similarity index 84%
rename from src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosFacturasMateriaPrimaContentDAO.java
rename to src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosContentDAO.java
index 81edae5..b93faa7 100644
--- a/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosFacturasMateriaPrimaContentDAO.java
+++ b/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosContentDAO.java
@@ -25,7 +25,6 @@
package danielcortes.xyz.models.informes.egresos;
import danielcortes.xyz.data.SQLiteConnectionHolder;
-import danielcortes.xyz.models.egreso.Egreso;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -35,11 +34,11 @@ import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
-public class SQLiteInformeEgresosFacturasMateriaPrimaContentDAO extends InformeEgresosFacturasMateriaPrimaContentDAO {
- private List list;
+public class SQLiteInformeEgresosContentDAO extends InformeEgresosContentDAO {
+ private List list;
@Override
- public List getInformeEgresosFactuasMateriaPrima(LocalDate date) {
+ public List getInformeEgresosFactuasMateriaPrima(LocalDate date, int tipoEgresoId) {
list = new ArrayList<>();
try {
Connection conn = new SQLiteConnectionHolder().getConnection();
@@ -49,12 +48,13 @@ public class SQLiteInformeEgresosFacturasMateriaPrimaContentDAO extends InformeE
"egresos.descripcion as \"descripcion\",\n" +
"egresos.valor as \"valor\"\n" +
"from egresos inner join caja on egresos.caja_id = caja.id\n" +
- "where caja.fecha between date(?) and date(?) and egresos.tipo_egreso_id = 1\n" +
+ "where caja.fecha between date(?) and date(?) and egresos.tipo_egreso_id = ? \n" +
"order by caja.fecha\n";
PreparedStatement ps = conn.prepareStatement(query);
ps.setString(1, date.withDayOfMonth(1).toString());
ps.setString(2, date.withDayOfMonth(date.lengthOfMonth()).toString());
+ ps.setInt(3, tipoEgresoId);
ResultSet rs = ps.executeQuery();
this.fillInforme(rs);
} catch (SQLException e) {
@@ -65,7 +65,7 @@ public class SQLiteInformeEgresosFacturasMateriaPrimaContentDAO extends InformeE
private void fillInforme(ResultSet rs) throws SQLException {
while (rs.next()) {
- InformeEgresosFacturasMateriaPrimaContent content = new InformeEgresosFacturasMateriaPrimaContent();
+ InformeEgresosContent content = new InformeEgresosContent();
content.setFecha(LocalDate.parse(rs.getString("fecha")));
content.setDescripcion(rs.getString("descripcion"));
content.setNro(rs.getString("nro"));
diff --git a/src/danielcortes/xyz/views/InformesView.form b/src/danielcortes/xyz/views/InformesView.form
index 45e9fca..a0e71be 100644
--- a/src/danielcortes/xyz/views/InformesView.form
+++ b/src/danielcortes/xyz/views/InformesView.form
@@ -1,6 +1,6 @@
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
+
diff --git a/src/danielcortes/xyz/views/InformesView.java b/src/danielcortes/xyz/views/InformesView.java
index ab26a6a..240f21e 100644
--- a/src/danielcortes/xyz/views/InformesView.java
+++ b/src/danielcortes/xyz/views/InformesView.java
@@ -64,30 +64,21 @@ public class InformesView {
*/
private void $$$setupUI$$$() {
contentPanel = new JPanel();
- contentPanel.setLayout(new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), -1, -1));
+ contentPanel.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
final JPanel panel1 = new JPanel();
- panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
+ panel1.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
contentPanel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
panel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Informes Generales"));
generarLibroVentasButton = new JButton();
generarLibroVentasButton.setText("Libro de Ventas Mensual");
panel1.add(generarLibroVentasButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- final JPanel panel2 = new JPanel();
- panel2.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
- contentPanel.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
- panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Egresos"));
GenerarEgresosFacturasMateriaPrimaButton = new JButton();
- GenerarEgresosFacturasMateriaPrimaButton.setText("Facturas Materia Prima");
- panel2.add(GenerarEgresosFacturasMateriaPrimaButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
- final JPanel panel3 = new JPanel();
- panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
- contentPanel.add(panel3, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
+ GenerarEgresosFacturasMateriaPrimaButton.setText("Informe de Egresos");
+ panel1.add(GenerarEgresosFacturasMateriaPrimaButton, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final Spacer spacer1 = new Spacer();
- panel3.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
+ panel1.add(spacer1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
final Spacer spacer2 = new Spacer();
- contentPanel.add(spacer2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
- final Spacer spacer3 = new Spacer();
- contentPanel.add(spacer3, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
+ contentPanel.add(spacer2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
}
/**
diff --git a/src/danielcortes/xyz/views/TipoEgresoSelectDialog.form b/src/danielcortes/xyz/views/TipoEgresoSelectDialog.form
new file mode 100644
index 0000000..f015c17
--- /dev/null
+++ b/src/danielcortes/xyz/views/TipoEgresoSelectDialog.form
@@ -0,0 +1,73 @@
+
+
diff --git a/src/danielcortes/xyz/views/TipoEgresoSelectDialog.java b/src/danielcortes/xyz/views/TipoEgresoSelectDialog.java
new file mode 100644
index 0000000..62b175f
--- /dev/null
+++ b/src/danielcortes/xyz/views/TipoEgresoSelectDialog.java
@@ -0,0 +1,141 @@
+/*
+ * 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.views;
+
+import com.intellij.uiDesigner.core.GridConstraints;
+import com.intellij.uiDesigner.core.GridLayoutManager;
+import com.intellij.uiDesigner.core.Spacer;
+import danielcortes.xyz.models.egreso.Egreso;
+import danielcortes.xyz.models.egreso.SQLiteEgresoDAO;
+import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
+import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.List;
+
+public class TipoEgresoSelectDialog extends JDialog {
+ private JPanel contentPane;
+ private JButton buttonOK;
+ private JButton buttonCancel;
+ private JComboBox tipoEgresoCombo;
+
+ private boolean acepted;
+
+ public TipoEgresoSelectDialog(JComponent parent) {
+ $$$setupUI$$$();
+ setContentPane(contentPane);
+ setModalityType(ModalityType.APPLICATION_MODAL);
+ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+ getRootPane().setDefaultButton(buttonOK);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ buttonCancel.doClick();
+ }
+ });
+
+ contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+
+ buttonOK.addActionListener(e -> onOK());
+ buttonCancel.addActionListener(e -> onCancel());
+
+ pack();
+ setLocationRelativeTo(parent);
+ setVisible(true);
+ }
+
+ private void onOK() {
+ this.acepted = true;
+ dispose();
+ }
+
+ private void onCancel() {
+ this.acepted = false;
+ dispose();
+ }
+
+ public boolean isAcepted() {
+ return this.acepted;
+ }
+
+ public TipoEgreso getTipoEgreso() {
+ return (TipoEgreso) tipoEgresoCombo.getSelectedItem();
+ }
+
+ private void createUIComponents() {
+ createTipoEgresoCombo();
+ }
+
+ private void createTipoEgresoCombo() {
+ List tiposEgreso = new SQLiteTipoEgresoDAO().findAll();
+ tipoEgresoCombo = new JComboBox<>();
+
+ for (TipoEgreso tipoEgreso : tiposEgreso) {
+ tipoEgresoCombo.addItem(tipoEgreso);
+ }
+ }
+
+ /**
+ * Method generated by IntelliJ IDEA GUI Designer
+ * >>> IMPORTANT!! <<<
+ * DO NOT edit this method OR call it in your code!
+ *
+ * @noinspection ALL
+ */
+ private void $$$setupUI$$$() {
+ createUIComponents();
+ contentPane = new JPanel();
+ contentPane.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
+ final JPanel panel1 = new JPanel();
+ panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
+ contentPane.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false));
+ final JPanel panel2 = new JPanel();
+ panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false));
+ panel1.add(panel2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
+ buttonOK = new JButton();
+ buttonOK.setText("OK");
+ panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ buttonCancel = new JButton();
+ buttonCancel.setText("Cancel");
+ panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ final JPanel panel3 = new JPanel();
+ panel3.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
+ contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
+ panel3.add(tipoEgresoCombo, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ final JLabel label1 = new JLabel();
+ label1.setText("Seleccione el Tipo de Egreso:");
+ panel3.add(label1, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ }
+
+ /**
+ * @noinspection ALL
+ */
+ public JComponent $$$getRootComponent$$$() {
+ return contentPane;
+ }
+
+}