diff --git a/database/create.sql b/database/create.sql index 93e530a..8363e76 100644 --- a/database/create.sql +++ b/database/create.sql @@ -64,6 +64,8 @@ create table ingresos ( id int(10) unsigned primary key auto_increment, valor int(10) not null, + nro_inicial varchar(191) not null, + nro_final varchar(191) not null, tipo_ingreso_id int(10) unsigned not null, caja_id int(10) unsigned not null, foreign key fk_tipo_ingreso (tipo_ingreso_id) references tipos_ingreso (id) on update cascade on delete restrict, diff --git a/src/main/java/danielcortes/xyz/controllers/ArqueoController.java b/src/main/java/danielcortes/xyz/controllers/ArqueoController.java index e6db12d..021ddbe 100644 --- a/src/main/java/danielcortes/xyz/controllers/ArqueoController.java +++ b/src/main/java/danielcortes/xyz/controllers/ArqueoController.java @@ -34,6 +34,7 @@ import danielcortes.xyz.models.ingreso.IngresoDAO; import danielcortes.xyz.views.ArqueoView; import javax.swing.*; +import java.awt.*; public class ArqueoController { @@ -71,7 +72,7 @@ public class ArqueoController { private void fillEfectivo() { this.efectivo = this.efectivoDAO.findByCaja(this.caja); this.view.getVeinteMilField().setText(String.valueOf(efectivo.getVeinteMil())); - this.view.getDiezField().setText(String.valueOf(efectivo.getDiezMil())); + this.view.getDiezMilField().setText(String.valueOf(efectivo.getDiezMil())); this.view.getCincoMilField().setText(String.valueOf(efectivo.getCincoMil())); this.view.getDosMilField().setText(String.valueOf(efectivo.getDosMil())); this.view.getMilField().setText(String.valueOf(efectivo.getMil())); @@ -142,6 +143,11 @@ public class ArqueoController { this.view.getArqueoField().setText(String.valueOf(arqueo)); this.view.getAjusteField().setText(String.valueOf(ajuste)); + if(ajuste < 0) { + this.view.getAjusteField().setForeground(new Color(255,0,0)); + }else{ + this.view.getAjusteField().setForeground(new Color(0,0,0)); + } } diff --git a/src/main/java/danielcortes/xyz/controllers/IngresosController.java b/src/main/java/danielcortes/xyz/controllers/IngresosController.java index 6afd639..181aa44 100644 --- a/src/main/java/danielcortes/xyz/controllers/IngresosController.java +++ b/src/main/java/danielcortes/xyz/controllers/IngresosController.java @@ -90,6 +90,8 @@ public class IngresosController { this.view.getIngresosTable().getSelectionModel().addListSelectionListener(e -> onSelectTableRowListener()); this.view.getGuardarButton().addActionListener(e -> guardarActionListener()); this.view.getValorField().addActionListener(e -> guardarActionListener()); + this.view.getNroInicialField().addActionListener(e -> guardarActionListener()); + this.view.getNroFinalField().addActionListener(e -> guardarActionListener()); this.view.getEliminarButton().addActionListener(e -> eliminarActionListener()); this.view.getEditarButton().addActionListener(e -> editarActionListener()); @@ -115,12 +117,17 @@ public class IngresosController { private void guardarActionListener() { this.normalizeInputs(); String valor = this.view.getValorField().getText(); + String nroInicial = this.view.getNroInicialField().getText(); + String nroFinal = this.view.getNroFinalField().getText(); TipoIngreso tipoIngreso = (TipoIngreso) this.view.getTipoCombo().getSelectedItem(); + System.out.println(nroInicial); + System.out.println(nroFinal); + if(editing) { - this.editarIngreso(valor, tipoIngreso, this.caja); + this.editarIngreso(valor, nroInicial, nroFinal, tipoIngreso, this.caja); } else { - this.guardarIngreso(valor, tipoIngreso, this.caja); + this.guardarIngreso(valor, nroInicial, nroFinal, tipoIngreso, this.caja); } this.resetFocus(); } @@ -147,6 +154,8 @@ public class IngresosController { this.view.getTipoCombo().setSelectedItem(ingreso.getTipoIngreso()); this.view.getValorField().setText(String.valueOf(ingreso.getValor())); + this.view.getNroInicialField().setText(String.valueOf(ingreso.getNroInicial())); + this.view.getNroFinalField().setText(String.valueOf(ingreso.getNroFinal())); } } @@ -170,12 +179,14 @@ public class IngresosController { } } - private void guardarIngreso(String valor, TipoIngreso tipoIngreso, Caja caja){ - if(this.validateInput(valor, tipoIngreso, caja)){ + private void guardarIngreso(String valor, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){ + if(this.validateInput(valor, nroInicial, nroFinal, tipoIngreso, caja)){ Ingreso ingreso = new Ingreso(); ingreso.setTipoIngreso(tipoIngreso); ingreso.setCaja(caja); ingreso.setValor(Integer.valueOf(valor)); + ingreso.setNroInicial(nroInicial); + ingreso.setNroFinal(nroFinal); this.ingresoDAO.insertIngreso(ingreso); this.view.getIngresosTableModel().addRow(ingreso); @@ -185,10 +196,12 @@ public class IngresosController { } } - private void editarIngreso(String valor, TipoIngreso tipoIngreso, Caja caja){ - if(this.validateInput(valor, tipoIngreso, caja)){ + private void editarIngreso(String valor, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){ + if(this.validateInput(valor, nroInicial, nroFinal, tipoIngreso, caja)){ this.editingIngreso.setTipoIngreso(tipoIngreso); this.editingIngreso.setValor(Integer.valueOf(valor)); + this.editingIngreso.setNroInicial(nroInicial); + this.editingIngreso.setNroFinal(nroFinal); this.ingresoDAO.updateIngreso(this.editingIngreso); this.view.getIngresosTableModel().setIngreso(this.editingId, this.editingIngreso); this.updateTotalIngresos(); @@ -197,10 +210,12 @@ public class IngresosController { } } - private boolean validateInput(String valor, TipoIngreso tipoIngreso, Caja caja) { + private boolean validateInput(String valor, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) { this.hideErrorMessages(); boolean valorValidation = this.validateValor(valor); + boolean nroInicialValidation = this.validateNroInicial(nroInicial); + boolean nroFinalValidation = this.validateNroFinal(nroFinal); boolean tipoIngresoValidation = this.validateTipoIngreso(tipoIngreso); boolean cajaValidation = this.validateCaja(caja); @@ -241,6 +256,36 @@ public class IngresosController { } + private boolean validateNroInicial(String nroInicial){ + if (nroInicial == null) { + this.view.getErrorNroInicial().setText("Hubo un problema con los datos"); + this.view.getErrorNroInicial().setVisible(true); + return false; + } + + if (nroInicial.isEmpty()) { + this.view.getErrorNroInicial().setText("El campo esta vacio"); + this.view.getErrorNroInicial().setVisible(true); + return false; + } + return true; + } + + private boolean validateNroFinal(String nroFinal){ + if (nroFinal == null) { + this.view.getErrorNroFinal().setText("Hubo un problema con los datos"); + this.view.getErrorNroFinal().setVisible(true); + return false; + } + + if (nroFinal.isEmpty()) { + this.view.getErrorNroFinal().setText("El campo esta vacio"); + this.view.getErrorNroFinal().setVisible(true); + return false; + } + return true; + } + private boolean validateTipoIngreso(TipoIngreso tipoIngreso) { if (tipoIngreso == null) { this.view.getErrorTipoIngreso().setText("Hubo un problema con los datos"); @@ -253,15 +298,21 @@ public class IngresosController { private void hideErrorMessages() { this.view.getErrorTipoIngreso().setVisible(false); this.view.getErrorValor().setVisible(false); + this.view.getErrorNroInicial().setVisible(false); + this.view.getErrorNroFinal().setVisible(false); } private void clearInputs() { this.view.getTipoCombo().setSelectedIndex(0); this.view.getValorField().setText(""); + this.view.getNroInicialField().setText(""); + this.view.getNroFinalField().setText(""); } private void normalizeInputs(){ this.view.getValorField().setText(this.view.getValorField().getText().trim()); + this.view.getNroInicialField().setText(this.view.getNroInicialField().getText().trim()); + this.view.getNroFinalField().setText(this.view.getNroFinalField().getText().trim()); } private void resetFocus(){ diff --git a/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java b/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java index 78e2b3c..e85f390 100644 --- a/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java +++ b/src/main/java/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java @@ -152,7 +152,6 @@ public class MysqlEfectivoDAO implements EfectivoDAO { ps.setInt(1, efectivo.getCaja().getId()); updates = ps.executeUpdate(); - System.out.println(updates); ps.close(); ps = conn.prepareStatement("select last_insert_id()"); diff --git a/src/main/java/danielcortes/xyz/models/ingreso/Ingreso.java b/src/main/java/danielcortes/xyz/models/ingreso/Ingreso.java index 34b95bd..1df8f89 100644 --- a/src/main/java/danielcortes/xyz/models/ingreso/Ingreso.java +++ b/src/main/java/danielcortes/xyz/models/ingreso/Ingreso.java @@ -30,22 +30,11 @@ import danielcortes.xyz.models.tipo_ingreso.TipoIngreso; public class Ingreso { private int id; private int valor; + private String nroInicial; + private String nroFinal; private TipoIngreso tipoIngreso; private Caja caja; - public Ingreso(int id, int valor, TipoIngreso tipoIngreso ) { - this.id = id; - this.valor = valor; - this.tipoIngreso = tipoIngreso; - } - - public Ingreso( int valor, TipoIngreso tipoIngreso) { - this.valor = valor; - this.tipoIngreso = tipoIngreso; - } - - public Ingreso(){} - public int getId() { return id; } @@ -54,14 +43,6 @@ public class Ingreso { this.id = id; } - public TipoIngreso getTipoIngreso() { - return tipoIngreso; - } - - public void setTipoIngreso(TipoIngreso tipoIngreso) { - this.tipoIngreso = tipoIngreso; - } - public int getValor() { return valor; } @@ -70,6 +51,30 @@ public class Ingreso { this.valor = valor; } + public String getNroInicial() { + return nroInicial; + } + + public void setNroInicial(String nroInicial) { + this.nroInicial = nroInicial; + } + + public String getNroFinal() { + return nroFinal; + } + + public void setNroFinal(String nroFinal) { + this.nroFinal = nroFinal; + } + + public TipoIngreso getTipoIngreso() { + return tipoIngreso; + } + + public void setTipoIngreso(TipoIngreso tipoIngreso) { + this.tipoIngreso = tipoIngreso; + } + public Caja getCaja() { return caja; } diff --git a/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java b/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java index 55896ce..bdb40e3 100644 --- a/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java +++ b/src/main/java/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java @@ -130,10 +130,12 @@ public class MysqlIngresoDAO implements IngresoDAO{ int updates; try { Connection conn = mysqlConnection.getConnection(); - PreparedStatement ps = conn.prepareStatement("insert into ingresos (valor, tipo_ingreso_id, caja_id) values (?,?,?)"); + PreparedStatement ps = conn.prepareStatement("insert into ingresos (valor, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?)"); ps.setInt(1, ingreso.getValor()); - ps.setInt(2, ingreso.getTipoIngreso().getId()); - ps.setInt(3, ingreso.getCaja().getId()); + ps.setString(2, ingreso.getNroInicial()); + ps.setString(3, ingreso.getNroFinal()); + ps.setInt(4, ingreso.getTipoIngreso().getId()); + ps.setInt(5, ingreso.getCaja().getId()); updates = ps.executeUpdate(); ps.close(); @@ -157,11 +159,13 @@ public class MysqlIngresoDAO implements IngresoDAO{ int updates; try { Connection conn = mysqlConnection.getConnection(); - PreparedStatement ps = conn.prepareStatement("update ingresos set valor = ? , tipo_ingreso_id = ?, caja_id = ? where id = ?"); + PreparedStatement ps = conn.prepareStatement("update ingresos set valor = ? , nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?"); ps.setInt(1,ingreso.getValor()); - ps.setInt(2, ingreso.getTipoIngreso().getId()); - ps.setInt(3, ingreso.getCaja().getId()); - ps.setInt(4, ingreso.getId()); + ps.setString(2, ingreso.getNroInicial()); + ps.setString(3, ingreso.getNroFinal()); + ps.setInt(4, ingreso.getTipoIngreso().getId()); + ps.setInt(5, ingreso.getCaja().getId()); + ps.setInt(6, ingreso.getId()); updates = ps.executeUpdate(); @@ -227,6 +231,8 @@ public class MysqlIngresoDAO implements IngresoDAO{ ingreso.setId(rs.getInt("id")); ingreso.setValor(rs.getInt("valor")); + ingreso.setNroInicial(rs.getString("nro_inicial")); + ingreso.setNroFinal(rs.getString("nro_final")); ingreso.setTipoIngreso(tipoIngreso); ingreso.setCaja(caja); diff --git a/src/main/java/danielcortes/xyz/views/ArqueoView.form b/src/main/java/danielcortes/xyz/views/ArqueoView.form index a8fc555..7d79918 100644 --- a/src/main/java/danielcortes/xyz/views/ArqueoView.form +++ b/src/main/java/danielcortes/xyz/views/ArqueoView.form @@ -1,9 +1,9 @@
diff --git a/src/main/java/danielcortes/xyz/views/ArqueoView.java b/src/main/java/danielcortes/xyz/views/ArqueoView.java index d955c42..7cbbcc1 100644 --- a/src/main/java/danielcortes/xyz/views/ArqueoView.java +++ b/src/main/java/danielcortes/xyz/views/ArqueoView.java @@ -26,6 +26,7 @@ package danielcortes.xyz.views; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; import javax.swing.*; import javax.swing.border.TitledBorder; @@ -204,7 +205,7 @@ public class ArqueoView { */ private void $$$setupUI$$$() { contentPanel = new JPanel(); - contentPanel.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1)); + contentPanel.setLayout(new GridLayoutManager(4, 2, new Insets(0, 0, 0, 0), -1, -1)); final JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayoutManager(5, 2, new Insets(10, 10, 10, 10), -1, -1)); contentPanel.add(panel1, 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)); @@ -235,7 +236,7 @@ public class ArqueoView { errorTarjetas.setVisible(false); panel1.add(errorTarjetas, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JPanel panel2 = new JPanel(); - panel2.setLayout(new GridLayoutManager(6, 2, new Insets(10, 10, 10, 10), -1, -1)); + panel2.setLayout(new GridLayoutManager(7, 2, new Insets(10, 10, 10, 10), -1, -1)); contentPanel.add(panel2, new GridConstraints(1, 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(), "Resumen")); final JLabel label3 = new JLabel(); @@ -268,21 +269,27 @@ public class ArqueoView { panel2.add(ingresosField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label7 = new JLabel(); label7.setText("Arqueo"); - panel2.add(label7, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + panel2.add(label7, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); arqueoField = new JTextField(); arqueoField.setEditable(false); + Font arqueoFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, arqueoField.getFont()); + if (arqueoFieldFont != null) arqueoField.setFont(arqueoFieldFont); arqueoField.setText("0"); - panel2.add(arqueoField, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + panel2.add(arqueoField, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); ajusteField = new JTextField(); ajusteField.setEditable(false); + Font ajusteFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, ajusteField.getFont()); + if (ajusteFieldFont != null) ajusteField.setFont(ajusteFieldFont); ajusteField.setText("0"); - panel2.add(ajusteField, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); + panel2.add(ajusteField, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label8 = new JLabel(); label8.setText("Ajuste "); - panel2.add(label8, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + panel2.add(label8, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JSeparator separator1 = new JSeparator(); + panel2.add(separator1, new GridConstraints(4, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); final JPanel panel3 = new JPanel(); panel3.setLayout(new GridLayoutManager(19, 2, new Insets(10, 10, 10, 10), -1, -1)); - contentPanel.add(panel3, new GridConstraints(0, 0, 2, 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)); + contentPanel.add(panel3, new GridConstraints(0, 0, 3, 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.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Detalle Efectivo", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, this.$$$getFont$$$(null, -1, -1, panel3.getFont()))); final JLabel label9 = new JLabel(); label9.setText("$20000"); @@ -386,6 +393,10 @@ public class ArqueoView { errorDiez.setText("Error"); errorDiez.setVisible(false); panel3.add(errorDiez, new GridConstraints(17, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + contentPanel.add(spacer1, new GridConstraints(2, 1, 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(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); } /** diff --git a/src/main/java/danielcortes/xyz/views/IngresosView.form b/src/main/java/danielcortes/xyz/views/IngresosView.form index ec4b06e..70cea4f 100644 --- a/src/main/java/danielcortes/xyz/views/IngresosView.form +++ b/src/main/java/danielcortes/xyz/views/IngresosView.form @@ -29,7 +29,7 @@ -