Generalizado el informe de egresos para que cree el necesitado segun su id

This commit is contained in:
Daniel Cortes
2019-01-16 23:50:39 -03:00
parent 0e0ffd96d2
commit 7b3a1148a1
11 changed files with 468 additions and 219 deletions

View File

@@ -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);

View File

@@ -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",
"",
@@ -49,7 +50,7 @@ public class InformeEgresosFacturaMateriaPrima {
"VALOR"
};
private List<InformeEgresosFacturasMateriaPrimaContent> informe;
private List<InformeEgresosContent> informe;
private File saveFile;
//Filas donde se almacenaran los totales
@@ -67,9 +68,9 @@ public class InformeEgresosFacturaMateriaPrima {
private CreationHelper createHelper;
private HashMap<String, CellStyle> 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);

View File

@@ -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 + '\'' +

View File

@@ -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<InformeEgresosFacturasMateriaPrimaContent> getInformeEgresosFactuasMateriaPrima(LocalDate month);
public abstract List<InformeEgresosContent> getInformeEgresosFactuasMateriaPrima(LocalDate month, int tipoEgresoId);
}

View File

@@ -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<InformeEgresosFacturasMateriaPrimaContent> list;
public class SQLiteInformeEgresosContentDAO extends InformeEgresosContentDAO {
private List<InformeEgresosContent> list;
@Override
public List<InformeEgresosFacturasMateriaPrimaContent> getInformeEgresosFactuasMateriaPrima(LocalDate date) {
public List<InformeEgresosContent> 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"));

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.InformesView">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="419" height="356"/>
@@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="ae41b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="ae41b" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -24,51 +24,26 @@
<text value="Libro de Ventas Mensual"/>
</properties>
</component>
</children>
</grid>
<grid id="7ae6d" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="etched" title="Egresos"/>
<children>
<component id="b9812" class="javax.swing.JButton" binding="GenerarEgresosFacturasMateriaPrimaButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Facturas Materia Prima"/>
<text value="Informe de Egresos"/>
</properties>
</component>
</children>
</grid>
<grid id="a924" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="1a8f0">
<vspacer id="91971">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</vspacer>
</children>
</grid>
<vspacer id="215a5">
<hspacer id="c47e8">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="d7cdc">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</hspacer>
</children>
</grid>
</form>

View File

@@ -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));
}
/**

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.TipoEgresoSelectDialog">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="247" height="134"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="OK"/>
</properties>
</component>
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="695a6" class="javax.swing.JComboBox" binding="tipoEgresoCombo" custom-create="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="373b9" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Seleccione el Tipo de Egreso:"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@@ -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<TipoEgreso> 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<TipoEgreso> 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;
}
}