diff --git a/dist/Programa Caja.jar b/dist/Programa Caja.jar index 23eba7c..81a0883 100644 Binary files a/dist/Programa Caja.jar and b/dist/Programa Caja.jar differ diff --git a/src/danielcortes/xyz/controllers/CalcularFondoController.java b/src/danielcortes/xyz/controllers/CalcularFondoController.java index 889be8b..a4bdea0 100644 --- a/src/danielcortes/xyz/controllers/CalcularFondoController.java +++ b/src/danielcortes/xyz/controllers/CalcularFondoController.java @@ -6,7 +6,7 @@ import danielcortes.xyz.data.DAOManager; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.calculo_fondo.CalculoFondo; import danielcortes.xyz.views.CalcularFondoView; -import danielcortes.xyz.views.components.FondoTableModel; +import danielcortes.xyz.views.components.table_model.FondoTableModel; import javax.swing.*; import java.awt.event.ActionEvent; diff --git a/src/danielcortes/xyz/controllers/EgresosController.java b/src/danielcortes/xyz/controllers/EgresosController.java index 9ad3d8b..513e66d 100644 --- a/src/danielcortes/xyz/controllers/EgresosController.java +++ b/src/danielcortes/xyz/controllers/EgresosController.java @@ -30,7 +30,7 @@ import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.egreso.Egreso; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; import danielcortes.xyz.views.EgresosView; -import danielcortes.xyz.views.components.EgresosTableModel; +import danielcortes.xyz.views.components.table_model.EgresosTableModel; import javax.swing.*; import java.awt.event.ActionEvent; diff --git a/src/danielcortes/xyz/controllers/IngresosController.java b/src/danielcortes/xyz/controllers/IngresosController.java index 43f3530..56ab081 100644 --- a/src/danielcortes/xyz/controllers/IngresosController.java +++ b/src/danielcortes/xyz/controllers/IngresosController.java @@ -29,7 +29,7 @@ import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.ingreso.Ingreso; import danielcortes.xyz.models.tipo_ingreso.TipoIngreso; import danielcortes.xyz.views.IngresosView; -import danielcortes.xyz.views.components.IngresosTableModel; +import danielcortes.xyz.views.components.table_model.IngresosTableModel; import javax.swing.*; import java.awt.event.ActionEvent; diff --git a/src/danielcortes/xyz/models/caja/Caja.java b/src/danielcortes/xyz/models/caja/Caja.java index ccf07a2..ff519dd 100644 --- a/src/danielcortes/xyz/models/caja/Caja.java +++ b/src/danielcortes/xyz/models/caja/Caja.java @@ -45,4 +45,12 @@ public class Caja { public void setFecha(LocalDate fecha) { this.fecha = fecha; } + + @Override + public String toString() { + return "Caja{" + + "id=" + id + + ", fecha=" + fecha + + '}'; + } } diff --git a/src/danielcortes/xyz/models/documentos/Documentos.java b/src/danielcortes/xyz/models/documentos/Documentos.java index 12268dc..3f89b0c 100644 --- a/src/danielcortes/xyz/models/documentos/Documentos.java +++ b/src/danielcortes/xyz/models/documentos/Documentos.java @@ -72,4 +72,15 @@ public class Documentos { public void setCaja(Caja caja) { this.caja = caja; } + + @Override + public String toString() { + return "Documentos{" + + "id=" + id + + ", cheques=" + cheques + + ", tarjetas=" + tarjetas + + ", retiros=" + retiros + + ", caja=" + caja + + '}'; + } } diff --git a/src/danielcortes/xyz/models/efectivo/Efectivo.java b/src/danielcortes/xyz/models/efectivo/Efectivo.java index a0ab033..6ca3f33 100644 --- a/src/danielcortes/xyz/models/efectivo/Efectivo.java +++ b/src/danielcortes/xyz/models/efectivo/Efectivo.java @@ -126,4 +126,21 @@ public class Efectivo { public void setCaja(Caja caja) { this.caja = caja; } + + @Override + public String toString() { + return "Efectivo{" + + "id=" + id + + ", veinteMil=" + veinteMil + + ", diezMil=" + diezMil + + ", cincoMil=" + cincoMil + + ", dosMil=" + dosMil + + ", mil=" + mil + + ", quinientos=" + quinientos + + ", cien=" + cien + + ", cincuenta=" + cincuenta + + ", diez=" + diez + + ", caja=" + caja + + '}'; + } } diff --git a/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java b/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java index 74afa57..0212925 100644 --- a/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java +++ b/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java @@ -24,6 +24,7 @@ package danielcortes.xyz.models.efectivo; +import danielcortes.xyz.data.Configuration; import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.CajaDAO; @@ -33,8 +34,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; public abstract class EfectivoDAO { + private static final Logger LOGGER = Logger.getLogger(Configuration.class.getName()); + protected ConnectionHolder connectionHolder; public abstract List findAll(); @@ -72,6 +77,8 @@ public abstract class EfectivoDAO { efectivo.setCincuenta(rs.getInt("cincuenta")); efectivo.setDiez(rs.getInt("diez")); + LOGGER.log(Level.FINER, "Se a creo: {0}", efectivo); + efectivoList.add(efectivo); } return efectivoList; diff --git a/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java b/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java index 881ee64..41a345d 100644 --- a/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java +++ b/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java @@ -24,6 +24,7 @@ package danielcortes.xyz.models.efectivo; +import danielcortes.xyz.data.Configuration; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; @@ -33,8 +34,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; public class SQLiteEfectivoDAO extends EfectivoDAO { + private static final Logger LOGGER = Logger.getLogger(Configuration.class.getName()); + public SQLiteEfectivoDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } @@ -43,15 +48,18 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public List findAll() { List efectivoList = new ArrayList<>(); try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("select * from efectivos"); + String query = "select * from efectivos"; + PreparedStatement ps = conn.prepareStatement(query); ResultSet rs = ps.executeQuery(); + LOGGER.log(Level.FINE, "QUERY: {0}", query); + efectivoList = this.efectivosFromResultSet(rs); rs.close(); ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); } return efectivoList; @@ -61,16 +69,19 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public Efectivo findById(int id) { Efectivo efectivo = null; try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?"); + String query = "select * from efectivos where id = ?"; + PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); + LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id}); + efectivo = this.efectivosFromResultSet(rs).get(0); rs.close(); ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); } return efectivo; @@ -80,10 +91,13 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public Efectivo findByCaja(Caja caja) { Efectivo efectivo = null; try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?"); + String query = "select * from efectivos where caja_id = ?"; + PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1, caja.getId()); ResultSet rs = ps.executeQuery(); + LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()}); + List efectivoList = this.efectivosFromResultSet(rs); if (efectivoList.size() > 0) { efectivo = efectivoList.get(0); @@ -92,7 +106,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); } return efectivo; @@ -102,7 +116,8 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public boolean insertEfectivo(Efectivo efectivo) { int updates; try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)"); + String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)"; + PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1, efectivo.getVeinteMil()); ps.setInt(2, efectivo.getDiezMil()); ps.setInt(3, efectivo.getCincoMil()); @@ -113,19 +128,26 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { ps.setInt(8, efectivo.getCincuenta()); ps.setInt(9, efectivo.getDiez()); ps.setInt(10, efectivo.getCaja().getId()); - updates = ps.executeUpdate(); + + LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}] | updates: {11}", new Object[]{query, efectivo.getVeinteMil(), efectivo.getDiezMil(), efectivo.getCincoMil(), efectivo.getDosMil(), efectivo.getMil(), efectivo.getQuinientos(), efectivo.getCien(), efectivo.getCincuenta(), efectivo.getDiez(), efectivo.getCaja().getId(), updates}); + ps.close(); - ps = conn.prepareStatement("select last_insert_rowid()"); + + query = "select last_insert_rowid()"; + ps = conn.prepareStatement(query); ResultSet rs = ps.executeQuery(); + + LOGGER.log(Level.FINE, "QUERY: {0}", query); + rs.next(); efectivo.setId(rs.getInt(1)); rs.close(); ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); return false; } return updates > 0; @@ -135,10 +157,13 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public boolean insertDefaultEfectivo(Efectivo efectivo) { int updates; try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)"); + String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)"; + PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1, efectivo.getCaja().getId()); - updates = ps.executeUpdate(); + + LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}", new Object[]{query, efectivo.getCaja().getId(), updates}); + ps.close(); ps = conn.prepareStatement("select last_insert_rowid()"); @@ -149,7 +174,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); return false; } return updates > 0; @@ -159,7 +184,8 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public boolean updateEfectivo(Efectivo efectivo) { int updates; try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?"); + String query = "update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?"; + PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1, efectivo.getVeinteMil()); ps.setInt(2, efectivo.getDiezMil()); ps.setInt(3, efectivo.getCincoMil()); @@ -171,12 +197,14 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { ps.setInt(9, efectivo.getDiez()); ps.setInt(10, efectivo.getCaja().getId()); ps.setInt(11, efectivo.getId()); - updates = ps.executeUpdate(); + + LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}] | updates: {12}", new Object[]{query, efectivo.getVeinteMil(), efectivo.getDiezMil(), efectivo.getCincoMil(), efectivo.getDosMil(), efectivo.getMil(), efectivo.getQuinientos(), efectivo.getCien(), efectivo.getCincuenta(), efectivo.getDiez(), efectivo.getCaja().getId(), efectivo.getId(), updates}); + ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); return false; } return updates > 0; @@ -186,14 +214,16 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public boolean deleteEfectivo(Efectivo efectivo) { int updates; try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?"); + String query = "delete from efectivos where id = ?"; + PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1, efectivo.getId()); - updates = ps.executeUpdate(); + LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}", new Object[]{query, efectivo.getId(), updates}); + ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); return false; } return updates > 0; @@ -203,9 +233,12 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { public int getTotalEfectivo(Caja caja) { int total = 0; try (Connection conn = connectionHolder.getConnection()) { - PreparedStatement ps = conn.prepareStatement("select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?"); + String query = "select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?"; + PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1, caja.getId()); + LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()}); + ResultSet rs = ps.executeQuery(); rs.next(); total = rs.getInt(1); @@ -213,7 +246,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); } catch (SQLException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, e.toString(), e); } return total; } diff --git a/src/danielcortes/xyz/models/egreso/Egreso.java b/src/danielcortes/xyz/models/egreso/Egreso.java index fc622c1..93ece48 100644 --- a/src/danielcortes/xyz/models/egreso/Egreso.java +++ b/src/danielcortes/xyz/models/egreso/Egreso.java @@ -83,4 +83,16 @@ public class Egreso { public void setCaja(Caja caja) { this.caja = caja; } + + @Override + public String toString() { + return "Egreso{" + + "id=" + id + + ", nro='" + nro + '\'' + + ", descripcion='" + descripcion + '\'' + + ", valor=" + valor + + ", tipoEgreso=" + tipoEgreso + + ", caja=" + caja + + '}'; + } } diff --git a/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java b/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java index ff2eb90..a840572 100644 --- a/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java +++ b/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java @@ -242,6 +242,7 @@ public class InformeLibroDeVentasContent { this.total = total; } + @Override public String toString() { return "InformeLibroDeVentasContent{" + diff --git a/src/danielcortes/xyz/models/ingreso/Ingreso.java b/src/danielcortes/xyz/models/ingreso/Ingreso.java index 86992c2..767113f 100644 --- a/src/danielcortes/xyz/models/ingreso/Ingreso.java +++ b/src/danielcortes/xyz/models/ingreso/Ingreso.java @@ -100,4 +100,18 @@ public class Ingreso { public void setCaja(Caja caja) { this.caja = caja; } + + @Override + public String toString() { + return "Ingreso{" + + "id=" + id + + ", valor=" + valor + + ", nroZInicial='" + nroZInicial + '\'' + + ", nroZFinal='" + nroZFinal + '\'' + + ", nroInicial='" + nroInicial + '\'' + + ", nroFinal='" + nroFinal + '\'' + + ", tipoIngreso=" + tipoIngreso + + ", caja=" + caja + + '}'; + } } diff --git a/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java b/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java index b100130..37e2543 100644 --- a/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java +++ b/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java @@ -82,6 +82,9 @@ public class TipoEgreso { @Override public String toString() { - return this.nombre; + return "TipoEgreso{" + + "id=" + id + + ", nombre='" + nombre + '\'' + + '}'; } } diff --git a/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java b/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java index 6f080ff..d16926d 100644 --- a/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java +++ b/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java @@ -82,6 +82,9 @@ public class TipoIngreso { @Override public String toString() { - return this.nombre; + return "TipoIngreso{" + + "id=" + id + + ", nombre='" + nombre + '\'' + + '}'; } } diff --git a/src/danielcortes/xyz/views/CalcularFondoView.java b/src/danielcortes/xyz/views/CalcularFondoView.java index 2779644..64bc8ba 100644 --- a/src/danielcortes/xyz/views/CalcularFondoView.java +++ b/src/danielcortes/xyz/views/CalcularFondoView.java @@ -26,8 +26,8 @@ package danielcortes.xyz.views; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; -import danielcortes.xyz.views.components.FondoTableModel; import danielcortes.xyz.views.components.NumberFormatedTextField; +import danielcortes.xyz.views.components.table_model.FondoTableModel; import javax.swing.*; import javax.swing.table.TableModel; diff --git a/src/danielcortes/xyz/views/EgresosView.form b/src/danielcortes/xyz/views/EgresosView.form index fae978d..81cb436 100644 --- a/src/danielcortes/xyz/views/EgresosView.form +++ b/src/danielcortes/xyz/views/EgresosView.form @@ -93,7 +93,7 @@ - + diff --git a/src/danielcortes/xyz/views/EgresosView.java b/src/danielcortes/xyz/views/EgresosView.java index ba0c8e0..e84a961 100644 --- a/src/danielcortes/xyz/views/EgresosView.java +++ b/src/danielcortes/xyz/views/EgresosView.java @@ -28,8 +28,9 @@ import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; -import danielcortes.xyz.views.components.EgresosTableModel; +import danielcortes.xyz.views.components.KeySelectionRenderer; import danielcortes.xyz.views.components.NumberFormatedTextField; +import danielcortes.xyz.views.components.table_model.EgresosTableModel; import javax.swing.*; import javax.swing.table.TableRowSorter; @@ -57,6 +58,7 @@ public class EgresosView { private void createUIComponents() { createEgresosTable(); + createTipoCombo(); } private void createEgresosTable() { @@ -68,6 +70,17 @@ public class EgresosView { egresosTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } + private void createTipoCombo() { + this.tipoCombo = new JComboBox<>(); + KeySelectionRenderer renderer = new KeySelectionRenderer(this.tipoCombo) { + @Override + public String getDisplayValue(Object value) { + TipoEgreso tipoEgreso = (TipoEgreso) value; + return tipoEgreso.getNombre(); + } + }; + } + public JPanel getContentPanel() { return contentPanel; } @@ -175,7 +188,6 @@ public class EgresosView { final JLabel label4 = new JLabel(); label4.setText("Tipo"); panel2.add(label4, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - tipoCombo = new JComboBox(); panel2.add(tipoCombo, new GridConstraints(1, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); errorNumero = new JLabel(); errorNumero.setEnabled(true); @@ -243,4 +255,5 @@ public class EgresosView { public JComponent $$$getRootComponent$$$() { return contentPanel; } + } diff --git a/src/danielcortes/xyz/views/IngresosView.form b/src/danielcortes/xyz/views/IngresosView.form index 67c0357..e509364 100644 --- a/src/danielcortes/xyz/views/IngresosView.form +++ b/src/danielcortes/xyz/views/IngresosView.form @@ -47,7 +47,7 @@ - + diff --git a/src/danielcortes/xyz/views/IngresosView.java b/src/danielcortes/xyz/views/IngresosView.java index 22bddf8..3c1a0d1 100644 --- a/src/danielcortes/xyz/views/IngresosView.java +++ b/src/danielcortes/xyz/views/IngresosView.java @@ -28,8 +28,9 @@ import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; import danielcortes.xyz.models.tipo_ingreso.TipoIngreso; -import danielcortes.xyz.views.components.IngresosTableModel; +import danielcortes.xyz.views.components.KeySelectionRenderer; import danielcortes.xyz.views.components.NumberFormatedTextField; +import danielcortes.xyz.views.components.table_model.IngresosTableModel; import javax.swing.*; import javax.swing.table.TableRowSorter; @@ -59,6 +60,7 @@ public class IngresosView { private void createUIComponents() { this.createIngresosTable(); + this.createTipoCombo(); } private void createIngresosTable() { @@ -70,6 +72,17 @@ public class IngresosView { this.ingresosTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } + private void createTipoCombo() { + this.tipoCombo = new JComboBox<>(); + KeySelectionRenderer renderer = new KeySelectionRenderer(this.tipoCombo) { + @Override + public String getDisplayValue(Object value) { + TipoIngreso tipoIngreso = (TipoIngreso) value; + return tipoIngreso.getNombre(); + } + }; + } + public JPanel getContentPanel() { return contentPanel; } @@ -178,7 +191,6 @@ public class IngresosView { final JLabel label1 = new JLabel(); label1.setText("Tipo"); panel2.add(label1, new GridConstraints(0, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - tipoCombo = new JComboBox(); final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel(); tipoCombo.setModel(defaultComboBoxModel1); panel2.add(tipoCombo, new GridConstraints(1, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); @@ -268,4 +280,5 @@ public class IngresosView { public JComponent $$$getRootComponent$$$() { return contentPanel; } + } diff --git a/src/danielcortes/xyz/views/components/EgresosTableModel.java b/src/danielcortes/xyz/views/components/EgresosTableModel.java deleted file mode 100644 index 5c3da53..0000000 --- a/src/danielcortes/xyz/views/components/EgresosTableModel.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.components; - -import danielcortes.xyz.models.egreso.Egreso; - -import javax.swing.table.AbstractTableModel; -import java.text.NumberFormat; -import java.util.ArrayList; - -public class EgresosTableModel extends AbstractTableModel { - private String[] columns; - private ArrayList rows; - private NumberFormat nf; - - - public EgresosTableModel() { - super(); - this.columns = new String[]{"N°", "Descripcion", "Valor", "Tipo"}; - this.rows = new ArrayList<>(); - this.nf = NumberFormat.getIntegerInstance(); - - } - - @Override - public String getColumnName(int col) { - return columns[col]; - } - - @Override - public int getColumnCount() { - return columns.length; - } - - @Override - public int getRowCount() { - return rows.size(); - } - - public void addRow(Egreso egreso) { - rows.add(egreso); - this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); - - } - - public void removeRow(int row) { - this.rows.remove(row); - this.fireTableRowsDeleted(row, row); - } - - public void removeRows() { - int rowCount = getRowCount(); - if (rowCount > 0) { - this.rows.clear(); - this.fireTableRowsDeleted(0, rowCount - 1); - } - } - - public void setEgreso(int editingId, Egreso egreso) { - this.rows.set(editingId, egreso); - this.fireTableRowsUpdated(0, getRowCount() - 1); - } - - @Override - public Object getValueAt(int row, int col) { - switch (col) { - case 0: - return rows.get(row).getNro(); - case 1: - return rows.get(row).getDescripcion(); - case 2: - return nf.format(rows.get(row).getValor()); - case 3: - return rows.get(row).getTipoEgreso(); - } - return null; - } - - public Egreso getEgreso(int row) { - return rows.get(row); - } - -} diff --git a/src/danielcortes/xyz/views/components/FondoTableModel.java b/src/danielcortes/xyz/views/components/FondoTableModel.java deleted file mode 100644 index 75d68a0..0000000 --- a/src/danielcortes/xyz/views/components/FondoTableModel.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.components; - -import danielcortes.xyz.models.calculo_fondo.CalculoFondo; - -import javax.swing.table.AbstractTableModel; -import java.text.NumberFormat; -import java.util.ArrayList; - -public class FondoTableModel extends AbstractTableModel { - - private String[] columns; - private ArrayList rows; - private NumberFormat nf; - - - public FondoTableModel() { - super(); - this.columns = new String[]{"Valor", "Descripcion"}; - this.rows = new ArrayList<>(); - this.nf = NumberFormat.getIntegerInstance(); - - } - - @Override - public String getColumnName(int col) { - return columns[col]; - } - - @Override - public int getColumnCount() { - return columns.length; - } - - @Override - public int getRowCount() { - return rows.size(); - } - - public void addRow(CalculoFondo calculoFondo) { - rows.add(calculoFondo); - this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); - - } - - public void removeRow(int row) { - this.rows.remove(row); - this.fireTableRowsDeleted(row, row); - } - - public void removeRows() { - int rowCount = getRowCount(); - if (rowCount > 0) { - this.rows.clear(); - this.fireTableRowsDeleted(0, rowCount - 1); - } - } - - public void setCalculoFondo(int editingId, CalculoFondo calculoFondo) { - this.rows.set(editingId, calculoFondo); - this.fireTableRowsUpdated(0, getRowCount() - 1); - } - - @Override - public Object getValueAt(int row, int col) { - switch (col) { - case 0: - return nf.format(rows.get(row).getValor()); - case 1: - return rows.get(row).getDescripcion(); - } - return null; - } - - public CalculoFondo getCalculoFondo(int row) { - return rows.get(row); - } -} diff --git a/src/danielcortes/xyz/views/components/IngresosTableModel.java b/src/danielcortes/xyz/views/components/IngresosTableModel.java deleted file mode 100644 index 2970e61..0000000 --- a/src/danielcortes/xyz/views/components/IngresosTableModel.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.components; - -import danielcortes.xyz.models.ingreso.Ingreso; - -import javax.swing.table.AbstractTableModel; -import java.text.NumberFormat; -import java.util.ArrayList; - -public class IngresosTableModel extends AbstractTableModel { - private String[] columns; - private ArrayList rows; - private NumberFormat nf; - - public IngresosTableModel() { - super(); - this.columns = new String[]{"Valor", "N° Z Inicial", "N° Z Final", "N° Inicial", "N° Final", "Tipo"}; - this.rows = new ArrayList<>(); - this.nf = NumberFormat.getIntegerInstance(); - } - - @Override - public String getColumnName(int col) { - return this.columns[col]; - } - - @Override - public int getColumnCount() { - return this.columns.length; - } - - @Override - public int getRowCount() { - return this.rows.size(); - } - - public void addRow(Ingreso ingreso) { - this.rows.add(ingreso); - this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); - } - - public void removeRow(int row) { - this.rows.remove(row); - this.fireTableRowsDeleted(row, row); - } - - public void removeRows() { - int rowCount = getRowCount(); - if (rowCount > 0) { - this.rows.clear(); - this.fireTableRowsDeleted(0, rowCount - 1); - } - } - - @Override - public Object getValueAt(int row, int col) { - switch (col) { - case 0: - return nf.format(this.rows.get(row).getValor()); - case 1: - return this.rows.get(row).getNroZInicial(); - case 2: - return this.rows.get(row).getNroZFinal(); - case 3: - return this.rows.get(row).getNroInicial(); - case 4: - return this.rows.get(row).getNroFinal(); - case 5: - return this.rows.get(row).getTipoIngreso().getNombre(); - } - return null; - } - - public Ingreso getIngreso(int row) { - return this.rows.get(row); - } - - public void setIngreso(int editingId, Ingreso ingreso) { - this.rows.set(editingId, ingreso); - this.fireTableRowsUpdated(getRowCount() - 2, getRowCount() - 1); - } - -}