diff --git a/.idea/dataSources/6e2ee496-6ca2-4cc4-a2b0-4f122e6bfd50.xml b/.idea/dataSources/6e2ee496-6ca2-4cc4-a2b0-4f122e6bfd50.xml
index 0610532..b8ed820 100644
--- a/.idea/dataSources/6e2ee496-6ca2-4cc4-a2b0-4f122e6bfd50.xml
+++ b/.idea/dataSources/6e2ee496-6ca2-4cc4-a2b0-4f122e6bfd50.xml
@@ -12,52 +12,48 @@
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
1
integer|0s
-
+
2
date|0s
1
-
+
id
1
-
+
1
integer|0s
-
+
2
integer|0s
1
-
+
3
- integer|0s
+ text|0s
1
-
+
4
integer|0s
1
-
- 5
- integer|0s
- 0
-
id
1
@@ -73,212 +69,247 @@
1
integer|0s
-
+
2
integer|0s
1
-
+
3
integer|0s
1
-
+
4
integer|0s
1
-
+
5
integer|0s
- 1
+ 0
-
- 6
- integer|0s
- 1
-
-
- 7
- integer|0s
- 1
-
-
- 8
- integer|0s
- 1
-
-
- 9
- integer|0s
- 1
-
-
- 10
- integer|0s
- 1
-
-
- 11
- integer|0s
- 1
-
-
+
id
1
-
+
caja_id
caja
id
restrict
cascade
-
+
1
integer|0s
-
+
2
- text|0s
+ integer|0s
1
-
+
3
- text|0s
+ integer|0s
1
-
+
4
integer|0s
1
-
+
5
integer|0s
1
-
+
6
integer|0s
1
-
+
+ 7
+ integer|0s
+ 1
+
+
+ 8
+ integer|0s
+ 1
+
+
+ 9
+ integer|0s
+ 1
+
+
+ 10
+ integer|0s
+ 1
+
+
+ 11
+ integer|0s
+ 1
+
+
id
1
-
+
+ caja_id
+ caja
+ id
+ restrict
+ cascade
+
+
+ 1
+ integer|0s
+
+
+ 2
+ text|0s
+ 1
+
+
+ 3
+ text|0s
+ 1
+
+
+ 4
+ integer|0s
+ 1
+
+
+ 5
+ integer|0s
+ 1
+
+
+ 6
+ integer|0s
+ 1
+
+
+ id
+ 1
+
+
tipo_egreso_id
tipos_egreso
id
restrict
cascade
-
+
caja_id
caja
id
restrict
cascade
-
+
1
integer|0s
-
+
2
integer|0s
1
-
+
3
text|0s
1
-
+
4
text|0s
1
-
+
5
integer unsigned|0s
1
-
+
6
integer unsigned|0s
1
-
+
7
''
-
+
8
''
-
+
id
1
-
+
tipo_ingreso_id
tipos_ingreso
id
restrict
cascade
-
+
caja_id
caja
id
restrict
cascade
-
+
1
text|0s
-
+
2
text|0s
-
+
3
text|0s
-
+
4
int|0s
-
+
5
text|0s
-
+
1
integer|0s
-
+
2
text|0s
1
-
+
id
1
-
+
1
integer|0s
-
+
2
text|0s
1
-
+
id
1
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ed3a287..ad24798 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,16 +5,23 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
@@ -46,24 +53,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -76,24 +65,36 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -163,18 +164,6 @@
@@ -283,12 +284,19 @@
+
+
+
+
+
+
+
-
+
@@ -302,7 +310,7 @@
-
+
@@ -316,7 +324,7 @@
-
+
@@ -536,14 +544,11 @@
-
-
-
- 1545321626516
-
-
-
- 1545321626516
+
+
+
+
+
1545358591232
@@ -881,11 +886,18 @@
1547787022196
-
+
+ 1547787772304
+
+
+
+ 1547787772304
+
+
-
+
@@ -897,28 +909,29 @@
-
+
-
+
-
+
-
+
-
+
-
+
+
@@ -927,12 +940,11 @@
-
-
-
-
-
-
+
+
+
+
+
@@ -1026,7 +1038,6 @@
-
@@ -1051,194 +1062,14 @@
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1254,13 +1085,6 @@
-
-
-
-
-
-
-
@@ -1390,17 +1214,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -1435,20 +1248,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1462,9 +1261,6 @@
-
-
-
@@ -1519,10 +1315,320 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -1530,8 +1636,6 @@
-
-
@@ -1546,42 +1650,173 @@
-
-
+
+
-
-
+
+
+
-
+
+
-
-
-
-
+
-
-
+
+
-
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/database/sqlite.sql b/database/sqlite.sql
index 7d8eb0b..7cc80e7 100644
--- a/database/sqlite.sql
+++ b/database/sqlite.sql
@@ -117,19 +117,28 @@ values ('Boletas Fiscales'),
('Facturas'),
('Guias');
-/*
- Primera Migracion, se agrega las columnas de nro de z inicial y final para el ingreso.
-*/
+-- Primera Migracion, se agrega las columnas de nro de z inicial y final para el ingreso.
-alter table ingresos add column nro_z_inicial text;
-alter table ingresos add column nro_z_final text;
+alter table ingresos
+ add column nro_z_inicial text;
+alter table ingresos
+ add column nro_z_final text;
-/**
- Segunda migracion, se necesita un tipo de ingresos de boleta exenta
- */
- insert into tipos_ingreso (nombre) values ('Boleta Exenta');
+-- Segunda migracion, se necesita un tipo de ingresos de boleta exenta
+insert into tipos_ingreso (nombre)
+values ('Boleta Exenta');
- /**
- Tercera migracion, necesidad de un campo de retiro en documentos
- */
- alter table documentos add column retiros integer default 0;
+-- Tercera migracion, necesidad de un campo de retiro en documentos
+alter table documentos
+ add column retiros integer default 0;
+
+-- Cuarta migracion, es requerida una tabla en la que se pueda calcular el fondo de la caja
+drop table if exists calculo_fondo;
+create table calculo_fondo
+(
+ id integer primary key,
+ valor integer not null,
+ descripcion text not null,
+ caja_id integer not null,
+ foreign key (caja_id) references caja (id) on update cascade on delete restrict
+);
\ No newline at end of file
diff --git a/dist/caja.jar b/dist/caja.jar
index ef76070..ce4bd7c 100644
Binary files a/dist/caja.jar and b/dist/caja.jar differ
diff --git a/src/danielcortes/xyz/controllers/ArqueoController.java b/src/danielcortes/xyz/controllers/ArqueoController.java
index c1a7396..968754a 100644
--- a/src/danielcortes/xyz/controllers/ArqueoController.java
+++ b/src/danielcortes/xyz/controllers/ArqueoController.java
@@ -26,6 +26,7 @@ package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
import danielcortes.xyz.models.caja.Caja;
+import danielcortes.xyz.models.calculo_fondo.SQLiteCalculoFondoDAO;
import danielcortes.xyz.models.documentos.Documentos;
import danielcortes.xyz.models.documentos.DocumentosDAO;
import danielcortes.xyz.models.efectivo.Efectivo;
@@ -33,15 +34,18 @@ import danielcortes.xyz.models.efectivo.EfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.views.ArqueoView;
+import danielcortes.xyz.views.CalcularFondoView;
import danielcortes.xyz.views.components.NumberFormatedTextField;
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.AbstractAction;
+import javax.swing.JComponent;
+import javax.swing.KeyStroke;
+import java.awt.Color;
import java.awt.event.ActionEvent;
/**
- * Controlador destinado a la vista ArqueoView
- * Maneja su contenido y las acciones que esta realiza.
+ * Controlador destinado a la vista ArqueoView
+ * Maneja su contenido y las acciones que esta realiza.
*/
public class ArqueoController {
private ArqueoView view;
@@ -56,7 +60,6 @@ public class ArqueoController {
/**
* Crea el controlador y ejecuta el metodo que genera los eventos para su vista.
- *
*/
public ArqueoController(ArqueoView view, EfectivoDAO efectivoDAO, DocumentosDAO documentosDAO, IngresoDAO ingresoDAO, EgresoDAO egresoDAO) {
this.view = view;
@@ -70,6 +73,7 @@ public class ArqueoController {
/**
* Actualiza los campos de documentos, efectivo y resumen con los datos de la caja.
+ *
* @param caja Caja para la cual se seleccionaran los datos a mostrar
*/
public void updateCaja(Caja caja) {
@@ -164,10 +168,10 @@ public class ArqueoController {
this.view.getDebeRendirField().setValue(totalIngresos);
this.view.getDiferenciaField().setValue(diferencia);
- if(diferencia < 0) {
- this.view.getDiferenciaField().setForeground(new Color(255,0,0));
- }else{
- this.view.getDiferenciaField().setForeground(new Color(0,0,0));
+ if (diferencia < 0) {
+ this.view.getDiferenciaField().setForeground(new Color(255, 0, 0));
+ } else {
+ this.view.getDiferenciaField().setForeground(new Color(0, 0, 0));
}
}
@@ -176,15 +180,15 @@ public class ArqueoController {
* Setea los eventos de los fields de la vista
*/
private void setUpViewEvents() {
- this.view.getVeinteMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getDiezMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getCincoMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getDosMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getQuinientosField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getCienField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getCincuentaField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getDiezField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
+ this.view.getVeinteMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getDiezMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getCincoMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getDosMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getMilField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getQuinientosField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getCienField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getCincuentaField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getDiezField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getVeinteMilField().getActionMap().put("nextField", new NextAction(this.view.getDiezMilField()));
this.view.getDiezMilField().getActionMap().put("nextField", new NextAction(this.view.getCincoMilField()));
@@ -194,24 +198,26 @@ public class ArqueoController {
this.view.getQuinientosField().getActionMap().put("nextField", new NextAction(this.view.getCienField()));
this.view.getCienField().getActionMap().put("nextField", new NextAction(this.view.getCincuentaField()));
this.view.getCincuentaField().getActionMap().put("nextField", new NextAction(this.view.getDiezField()));
- this.view.getDiezField().getActionMap().put("save", new GuardarEfectivoAction(this));
+ this.view.getDiezField().getActionMap().put("save", new GuardarEfectivoAction());
- this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getTarjetasField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
- this.view.getRetiroField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
+ this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getTarjetasField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getRetiroField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
this.view.getChequesField().getActionMap().put("nextField", new NextAction(this.view.getTarjetasField()));
this.view.getTarjetasField().getActionMap().put("nextField", new NextAction(this.view.getRetiroField()));
- this.view.getRetiroField().getActionMap().put("save", new GuardarDocumentosAction(this));
+ this.view.getRetiroField().getActionMap().put("save", new GuardarDocumentosAction());
- this.view.getGuardarEfectivoButton().addActionListener(e ->{
+ this.view.getGuardarEfectivoButton().addActionListener(e -> {
this.guardarEfectivoActionListener();
});
- this.view.getGuardarDocumentosButton().addActionListener(e ->{
+ this.view.getGuardarDocumentosButton().addActionListener(e -> {
this.guardarEfectivoActionListener();
});
-
+ this.view.getCalcularFondoButton().addActionListener(e -> {
+ this.calcularFondoActionListener();
+ });
}
@@ -219,7 +225,7 @@ public class ArqueoController {
* Llama a los metodos necesarios para guardar los campos de efectivo
* Primero llama a normalizar el input, luego a esconder los mensajes de error, para finalmente llamar a guardar el efectivo
*/
- private void guardarEfectivoActionListener(){
+ private void guardarEfectivoActionListener() {
this.view.getGuardarEfectivoButton().requestFocus();
this.guardarEfectivo();
}
@@ -228,11 +234,18 @@ public class ArqueoController {
* Llama a los metodos necesarios para guardar los documentos
* Primero llama a normalizar el input, luego a esconder los mensajes de error y finalmente a guardar los documentos
*/
- private void guardarDocumentosActionListener(){
+ private void guardarDocumentosActionListener() {
this.view.getGuardarDocumentosButton().requestFocus();
this.guardarDocumentos();
}
+ /**
+ * Lanza la ventana en la que se puede calcular el fondo de la caja.
+ */
+ private void calcularFondoActionListener() {
+ new CalcularFondoController(this.view.getContentPanel(), new CalcularFondoView(), this.caja, new SQLiteCalculoFondoDAO());
+ }
+
/**
* Guarda los datos del detalle de efectivo solo despues de que los campos sean validados, luego de guardar
* llama a updateResumenEfectivo y updateResumenArqueo para actualizar los datos en efectivoField y arqueoField
@@ -282,28 +295,16 @@ public class ArqueoController {
}
private class GuardarEfectivoAction extends AbstractAction {
- ArqueoController controller;
-
- GuardarEfectivoAction(ArqueoController controller){
- this.controller = controller;
- }
-
@Override
public void actionPerformed(ActionEvent e) {
- this.controller.guardarEfectivoActionListener();
+ ArqueoController.this.guardarEfectivoActionListener();
}
}
private class GuardarDocumentosAction extends AbstractAction {
- ArqueoController controller;
-
- GuardarDocumentosAction(ArqueoController controller){
- this.controller = controller;
- }
-
@Override
public void actionPerformed(ActionEvent e) {
- this.controller.guardarDocumentosActionListener();
+ ArqueoController.this.guardarDocumentosActionListener();
}
}
diff --git a/src/danielcortes/xyz/controllers/CalcularFondoController.java b/src/danielcortes/xyz/controllers/CalcularFondoController.java
new file mode 100644
index 0000000..a21c98b
--- /dev/null
+++ b/src/danielcortes/xyz/controllers/CalcularFondoController.java
@@ -0,0 +1,191 @@
+package danielcortes.xyz.controllers;
+
+import danielcortes.xyz.controllers.actions.NextAction;
+import danielcortes.xyz.models.caja.Caja;
+import danielcortes.xyz.models.calculo_fondo.CalculoFondo;
+import danielcortes.xyz.models.calculo_fondo.CalculoFondoDAO;
+import danielcortes.xyz.views.CalcularFondoView;
+import danielcortes.xyz.views.components.FondoTableModel;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+public class CalcularFondoController {
+ private JComponent parent;
+ private CalcularFondoView view;
+ private Caja caja;
+ private CalculoFondoDAO calculoFondoDAO;
+
+ private int editingId;
+ private boolean editing;
+ private CalculoFondo editingCalculoFondo;
+
+ public CalcularFondoController(JComponent parent, CalcularFondoView view, Caja caja, CalculoFondoDAO calculoFondoDAO) {
+ this.view = view;
+ this.parent = parent;
+ this.caja = caja;
+ this.calculoFondoDAO = calculoFondoDAO;
+
+ this.fillTable();
+ this.updateResumen();
+ this.setupViewEvents();
+ this.updateButtonsEnabled();
+ this.showView();
+ }
+
+ private void showView() {
+ JFrame frame = new JFrame("Calculo de Fondo");
+ frame.setContentPane(view.getContentPanel());
+ frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frame.pack();
+ frame.setLocationRelativeTo(this.parent);
+ frame.setVisible(true);
+ }
+
+ private void fillTable() {
+ FondoTableModel tableModel = this.view.getTableModel();
+ tableModel.removeRows();
+ for (CalculoFondo calculoFondo : this.calculoFondoDAO.findByCaja(this.caja)) {
+ tableModel.addRow(calculoFondo);
+ }
+ }
+
+ private void setupViewEvents() {
+ this.view.getValorField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField");
+ this.view.getDescripcionField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "save");
+ this.view.getFondoField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "updateResumen");
+
+ this.view.getValorField().getActionMap().put("nextField", new NextAction(this.view.getDescripcionField()));
+ this.view.getDescripcionField().getActionMap().put("save", new GuardarAction());
+ this.view.getFondoField().getActionMap().put("updateResumen", new UpdateResumenAction());
+
+ this.view.getTable().getSelectionModel().addListSelectionListener(e -> updateButtonsEnabled());
+
+ this.view.getGuardarButton().addActionListener(e -> guardarActionListener());
+ this.view.getEditarButton().addActionListener(e -> editarActionListener());
+ this.view.getEliminarButton().addActionListener(e -> eliminarActionListener());
+
+ this.view.getTable().addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent mouseEvent) {
+ JTable table = (JTable) mouseEvent.getSource();
+ if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) {
+ CalcularFondoController.this.editarActionListener();
+ }
+ }
+ });
+ }
+
+ private void guardarActionListener() {
+ this.normalizeInput();
+
+ int valor = this.view.getValorField().getValue();
+ String descripcion = this.view.getDescripcionField().getText();
+
+
+ if (editing) {
+ this.editarCalculoFondo(valor, descripcion);
+ this.editing = false;
+ } else {
+ this.guardarCalculoFondo(valor, descripcion);
+ }
+
+ this.updateResumen();
+ this.cleanInput();
+ this.resetFocus();
+ }
+
+ private void editarActionListener() {
+ int selectedID = this.view.getTable().getSelectedRow();
+ if (selectedID >= 0) {
+ int selectedModelID = this.view.getTable().getRowSorter().convertRowIndexToModel(selectedID);
+ CalculoFondo calculoFondo = this.view.getTableModel().getCalculoFondo(selectedModelID);
+
+ this.editingId = selectedModelID;
+ this.editingCalculoFondo = calculoFondo;
+ this.editing = true;
+
+ this.view.getValorField().setValue(calculoFondo.getValor());
+ this.view.getDescripcionField().setText(calculoFondo.getDescripcion());
+ }
+ }
+
+ private void eliminarActionListener() {
+ int selectedID = this.view.getTable().getSelectedRow();
+ if (selectedID >= 0) {
+ CalculoFondo calculoFondo = this.view.getTableModel().getCalculoFondo(selectedID);
+ this.view.getTableModel().removeRow(selectedID);
+ this.calculoFondoDAO.deleteCalculoFondo(calculoFondo);
+ this.updateResumen();
+ this.updateButtonsEnabled();
+ this.resetFocus();
+ }
+ }
+
+ private void guardarCalculoFondo(int valor, String descripcion) {
+ CalculoFondo calculoFondo = new CalculoFondo();
+ calculoFondo.setValor(valor);
+ calculoFondo.setDescripcion(descripcion);
+ calculoFondo.setCaja(this.caja);
+ this.calculoFondoDAO.insertCalculoFondo(calculoFondo);
+ this.view.getTableModel().addRow(calculoFondo);
+ }
+
+ private void editarCalculoFondo(int valor, String descripcion) {
+ this.editingCalculoFondo.setValor(valor);
+ this.editingCalculoFondo.setDescripcion(descripcion);
+ this.editingCalculoFondo.setCaja(this.caja);
+ this.calculoFondoDAO.updateCalculoFondo(editingCalculoFondo);
+ this.view.getTableModel().setCalculoFondo(this.editingId, this.editingCalculoFondo);
+ }
+
+ private void updateButtonsEnabled() {
+ if (this.view.getTable().getSelectedRow() >= 0) {
+ this.view.getEliminarButton().setEnabled(true);
+ this.view.getEditarButton().setEnabled(true);
+ } else {
+ this.view.getEliminarButton().setEnabled(false);
+ this.view.getEditarButton().setEnabled(false);
+ }
+ }
+
+ private void updateResumen() {
+ int fondo = this.view.getFondoField().getValue();
+ int suma = this.calculoFondoDAO.getTotalCalculoFondo(this.caja);
+ this.view.getSumaField().setValue(suma);
+ this.view.getDiferenciaField().setValue(suma - fondo);
+ }
+
+ private void cleanInput() {
+ this.view.getValorField().setValue(0);
+ this.view.getDescripcionField().setText("");
+
+ }
+
+ private void normalizeInput() {
+ if (this.view.getDescripcionField().getText() == null) {
+ this.view.getDescripcionField().setText("");
+ }
+
+ this.view.getDescripcionField().setText(this.view.getDescripcionField().getText().trim());
+ }
+
+ private void resetFocus() {
+ this.view.getValorField().requestFocus();
+ }
+
+ private class GuardarAction extends AbstractAction {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ CalcularFondoController.this.guardarActionListener();
+ }
+ }
+
+ private class UpdateResumenAction extends AbstractAction {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ CalcularFondoController.this.updateResumen();
+ }
+ }
+}
diff --git a/src/danielcortes/xyz/models/caja/MysqlCajaDAO.java b/src/danielcortes/xyz/models/caja/MysqlCajaDAO.java
index 03b90d3..b3cf673 100644
--- a/src/danielcortes/xyz/models/caja/MysqlCajaDAO.java
+++ b/src/danielcortes/xyz/models/caja/MysqlCajaDAO.java
@@ -158,7 +158,6 @@ public class MysqlCajaDAO extends CajaDAO {
return updates > 0;
}
-
@Override
public void createCajasForMonth(LocalDate month) {
LocalDate date = month.withDayOfMonth(1);
diff --git a/src/danielcortes/xyz/models/calculo_fondo/CalculoFondo.java b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondo.java
new file mode 100644
index 0000000..c9f4d89
--- /dev/null
+++ b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondo.java
@@ -0,0 +1,76 @@
+/*
+ * 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.models.calculo_fondo;
+
+import danielcortes.xyz.models.caja.Caja;
+
+public class CalculoFondo {
+ private int id;
+ private int valor;
+ private String descripcion;
+ private Caja caja;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getValor() {
+ return valor;
+ }
+
+ public void setValor(int valor) {
+ this.valor = valor;
+ }
+
+ public String getDescripcion() {
+ return descripcion;
+ }
+
+ public void setDescripcion(String descripcion) {
+ this.descripcion = descripcion;
+ }
+
+ public Caja getCaja() {
+ return caja;
+ }
+
+ public void setCaja(Caja caja) {
+ this.caja = caja;
+ }
+
+ @Override
+ public String toString() {
+ return "CalculoFondo{" +
+ "id=" + id +
+ ", valor=" + valor +
+ ", descripcion='" + descripcion + '\'' +
+ ", caja=" + caja +
+ '}';
+ }
+}
diff --git a/src/danielcortes/xyz/models/calculo_fondo/CalculoFondoDAO.java b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondoDAO.java
new file mode 100644
index 0000000..f182dbd
--- /dev/null
+++ b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondoDAO.java
@@ -0,0 +1,63 @@
+/*
+ * 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.models.calculo_fondo;
+
+import danielcortes.xyz.data.ConnectionHolder;
+import danielcortes.xyz.models.caja.Caja;
+import danielcortes.xyz.models.caja.SQLiteCajaDAO;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class CalculoFondoDAO {
+ protected ConnectionHolder connectionHolder;
+
+ public abstract List findAll();
+ public abstract List findByCaja(Caja caja);
+ public abstract CalculoFondo findById(int id);
+
+ public abstract boolean insertCalculoFondo(CalculoFondo calculoFondo);
+ public abstract boolean updateCalculoFondo(CalculoFondo calculoFondo);
+ public abstract boolean deleteCalculoFondo(CalculoFondo calculoFondo);
+
+ public abstract int getTotalCalculoFondo(Caja caja);
+
+ protected List cajasFromResultSet(ResultSet rs) throws SQLException {
+ List calculoFondoList = new ArrayList<>();
+ while (rs.next()) {
+ int caja_id = rs.getInt("caja_id");
+ Caja caja = new SQLiteCajaDAO().findById(caja_id);
+ CalculoFondo calculoFondo = new CalculoFondo();
+ calculoFondo.setId(rs.getInt("id"));
+ calculoFondo.setValor(rs.getInt("valor"));
+ calculoFondo.setDescripcion(rs.getString("descripcion"));
+ calculoFondo.setCaja(caja);
+ calculoFondoList.add(calculoFondo);
+ }
+ return calculoFondoList;
+ }
+}
diff --git a/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java
new file mode 100644
index 0000000..be5b8e6
--- /dev/null
+++ b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java
@@ -0,0 +1,189 @@
+/*
+ * 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.models.calculo_fondo;
+
+import danielcortes.xyz.data.SQLiteConnectionHolder;
+import danielcortes.xyz.models.caja.Caja;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
+ public SQLiteCalculoFondoDAO() {
+ this.connectionHolder = new SQLiteConnectionHolder();
+ }
+
+ @Override
+ public List findAll() {
+ List calculoFondoList = new ArrayList<>();
+ try {
+ Connection conn = connectionHolder.getConnection();
+ PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo");
+ ResultSet rs = ps.executeQuery();
+
+ calculoFondoList = this.cajasFromResultSet(rs);
+
+ rs.close();
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return calculoFondoList;
+ }
+ @Override
+ public List findByCaja(Caja caja) {
+ List calculoFondoList = new ArrayList<>();
+ try {
+ Connection conn = connectionHolder.getConnection();
+ PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo where caja_id = ?");
+ ps.setInt(1, caja.getId());
+
+ ResultSet rs = ps.executeQuery();
+
+ calculoFondoList = this.cajasFromResultSet(rs);
+
+ rs.close();
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return calculoFondoList;
+ }
+
+ @Override
+ public CalculoFondo findById(int id) {
+ CalculoFondo calculoFondo = null;
+ try {
+ Connection conn = connectionHolder.getConnection();
+ PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo where id = ?");
+ ps.setInt(1, id);
+ ResultSet rs = ps.executeQuery();
+
+ calculoFondo = this.cajasFromResultSet(rs).get(0);
+
+ rs.close();
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return calculoFondo;
+ }
+
+ @Override
+ public boolean insertCalculoFondo(CalculoFondo calculoFondo) {
+ int updates;
+ try {
+ Connection conn = connectionHolder.getConnection();
+ PreparedStatement ps = conn.prepareStatement("insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)");
+ ps.setInt(1, calculoFondo.getValor());
+ ps.setString(2, calculoFondo.getDescripcion());
+ ps.setInt(3, calculoFondo.getCaja().getId());
+
+ updates = ps.executeUpdate();
+ ps.close();
+
+ ps = conn.prepareStatement("select last_insert_rowid()");
+ ResultSet rs = ps.executeQuery();
+ rs.next();
+ calculoFondo.setId(rs.getInt(1));
+
+ rs.close();
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return updates > 0;
+ }
+
+ @Override
+ public boolean updateCalculoFondo(CalculoFondo calculoFondo) {
+ int updates;
+ try {
+ Connection conn = connectionHolder.getConnection();
+ PreparedStatement ps = conn.prepareStatement("update calculo_fondo set valor = ?, descripcion = ?, caja_id = ? where id = ?");
+ ps.setInt(1, calculoFondo.getValor());
+ ps.setString(2, calculoFondo.getDescripcion());
+ ps.setInt(3, calculoFondo.getCaja().getId());
+ ps.setInt(4, calculoFondo.getId());
+
+ updates = ps.executeUpdate();
+
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return updates > 0;
+ }
+
+ @Override
+ public boolean deleteCalculoFondo(CalculoFondo calculoFondo) {
+ int updates;
+ try {
+ Connection conn = connectionHolder.getConnection();
+ PreparedStatement ps = conn.prepareStatement("delete from calculo_fondo where id = ?");
+ ps.setInt(1, calculoFondo.getId());
+
+ updates = ps.executeUpdate();
+
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return updates > 0;
+ }
+
+ @Override
+ public int getTotalCalculoFondo(Caja caja) {
+ int sum = 0;
+ try {
+ Connection conn = connectionHolder.getConnection();
+ PreparedStatement ps = conn.prepareStatement("select sum(valor) from calculo_fondo where caja_id = ?");
+ ps.setInt(1, caja.getId());
+
+ ResultSet rs = ps.executeQuery();
+ rs.next();
+ sum = rs.getInt(1);
+
+ ps.close();
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return sum;
+ }
+}
diff --git a/src/danielcortes/xyz/views/ArqueoView.form b/src/danielcortes/xyz/views/ArqueoView.form
index e2a904f..21d7a01 100644
--- a/src/danielcortes/xyz/views/ArqueoView.form
+++ b/src/danielcortes/xyz/views/ArqueoView.form
@@ -3,7 +3,7 @@
-
+
@@ -411,7 +411,25 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/danielcortes/xyz/views/ArqueoView.java b/src/danielcortes/xyz/views/ArqueoView.java
index a8b67c5..600e6ec 100644
--- a/src/danielcortes/xyz/views/ArqueoView.java
+++ b/src/danielcortes/xyz/views/ArqueoView.java
@@ -24,7 +24,6 @@
package danielcortes.xyz.views;
-
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
@@ -53,6 +52,7 @@ public class ArqueoView {
private NumberFormatedTextField rendidoField;
private JButton guardarEfectivoButton;
private JButton guardarDocumentosButton;
+ private JButton calcularFondoButton;
private NumberFormatedTextField diferenciaField;
private NumberFormatedTextField debeRendirField;
private NumberFormatedTextField retiroField;
@@ -129,6 +129,10 @@ public class ArqueoView {
return guardarDocumentosButton;
}
+ public JButton getCalcularFondoButton() {
+ return calcularFondoButton;
+ }
+
public NumberFormatedTextField getDiferenciaField() {
return diferenciaField;
}
@@ -301,6 +305,12 @@ public class ArqueoView {
final JLabel label18 = new JLabel();
label18.setText("Retiro");
panel4.add(label18, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ final JPanel panel5 = new JPanel();
+ panel5.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
+ contentPanel.add(panel5, 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));
+ calcularFondoButton = new JButton();
+ calcularFondoButton.setText("Calcular Fondo");
+ panel5.add(calcularFondoButton, 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 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));
}
diff --git a/src/danielcortes/xyz/views/CalcularFondoView.form b/src/danielcortes/xyz/views/CalcularFondoView.form
new file mode 100644
index 0000000..16ec3bc
--- /dev/null
+++ b/src/danielcortes/xyz/views/CalcularFondoView.form
@@ -0,0 +1,164 @@
+
+
diff --git a/src/danielcortes/xyz/views/CalcularFondoView.java b/src/danielcortes/xyz/views/CalcularFondoView.java
new file mode 100644
index 0000000..a50cac5
--- /dev/null
+++ b/src/danielcortes/xyz/views/CalcularFondoView.java
@@ -0,0 +1,189 @@
+/*
+ * 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 danielcortes.xyz.views.components.FondoTableModel;
+import danielcortes.xyz.views.components.NumberFormatedTextField;
+
+import javax.swing.*;
+import javax.swing.table.TableModel;
+import javax.swing.table.TableRowSorter;
+import java.awt.*;
+
+public class CalcularFondoView {
+ private JPanel contentPanel;
+ private JTable table;
+ private JButton guardarButton;
+ private JButton editarButton;
+ private JButton eliminarButton;
+ private JTextField descripcionField;
+ private NumberFormatedTextField fondoField;
+ private NumberFormatedTextField sumaField;
+ private NumberFormatedTextField diferenciaField;
+ private NumberFormatedTextField valorField;
+
+ private FondoTableModel tableModel;
+
+ public CalcularFondoView() {
+ $$$setupUI$$$();
+ this.fillDefaultsValues();
+ }
+
+
+ public JPanel getContentPanel() {
+ return contentPanel;
+ }
+
+ public JTable getTable() {
+ return table;
+ }
+
+ public JButton getGuardarButton() {
+ return guardarButton;
+ }
+
+ public JButton getEditarButton() {
+ return editarButton;
+ }
+
+ public JButton getEliminarButton() {
+ return eliminarButton;
+ }
+
+ public JTextField getDescripcionField() {
+ return descripcionField;
+ }
+
+ public NumberFormatedTextField getFondoField() {
+ return fondoField;
+ }
+
+ public NumberFormatedTextField getSumaField() {
+ return sumaField;
+ }
+
+ public NumberFormatedTextField getDiferenciaField() {
+ return diferenciaField;
+ }
+
+ public NumberFormatedTextField getValorField() {
+ return valorField;
+ }
+
+ public FondoTableModel getTableModel() {
+ return tableModel;
+ }
+
+ /**
+ * 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();
+ contentPanel = new JPanel();
+ contentPanel.setLayout(new GridLayoutManager(4, 1, new Insets(10, 10, 10, 10), -1, -1));
+ final JScrollPane scrollPane1 = new JScrollPane();
+ contentPanel.add(scrollPane1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
+ scrollPane1.setViewportView(table);
+ final JPanel panel1 = new JPanel();
+ panel1.setLayout(new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), -1, -1));
+ contentPanel.add(panel1, new GridConstraints(3, 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));
+ fondoField = new NumberFormatedTextField();
+ panel1.add(fondoField, new GridConstraints(1, 0, 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 label1 = new JLabel();
+ label1.setText("Fondo");
+ panel1.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ final JLabel label2 = new JLabel();
+ label2.setText("Suma de dinero");
+ panel1.add(label2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ final JLabel label3 = new JLabel();
+ label3.setText("Diferencia");
+ panel1.add(label3, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ sumaField = new NumberFormatedTextField();
+ sumaField.setEditable(false);
+ panel1.add(sumaField, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
+ diferenciaField = new NumberFormatedTextField();
+ diferenciaField.setEditable(false);
+ panel1.add(diferenciaField, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
+ final JPanel panel2 = new JPanel();
+ panel2.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
+ contentPanel.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));
+ valorField = new NumberFormatedTextField();
+ panel2.add(valorField, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
+ descripcionField = new JTextField();
+ panel2.add(descripcionField, new GridConstraints(1, 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 label4 = new JLabel();
+ label4.setText("Valor");
+ panel2.add(label4, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ final JLabel label5 = new JLabel();
+ label5.setText("Descripcion");
+ panel2.add(label5, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ final JPanel panel3 = new JPanel();
+ panel3.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1));
+ contentPanel.add(panel3, new GridConstraints(1, 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));
+ guardarButton = new JButton();
+ guardarButton.setText("Guardar");
+ panel3.add(guardarButton, 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));
+ editarButton = new JButton();
+ editarButton.setText("Editar");
+ panel3.add(editarButton, 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));
+ eliminarButton = new JButton();
+ eliminarButton.setText("Eliminar");
+ panel3.add(eliminarButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
+ }
+
+ /**
+ * @noinspection ALL
+ */
+ public JComponent $$$getRootComponent$$$() {
+ return contentPanel;
+ }
+
+ private void createUIComponents() {
+ this.createTable();
+ }
+
+ private void createTable() {
+ this.tableModel = new FondoTableModel();
+ this.table = new JTable(this.tableModel);
+
+ RowSorter sorter = new TableRowSorter<>(this.tableModel);
+ this.table.setRowSorter(sorter);
+ this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ }
+
+ private void fillDefaultsValues() {
+ this.valorField.setValue(0);
+ this.diferenciaField.setValue(0);
+ this.fondoField.setValue(0);
+ this.sumaField.setValue(0);
+ this.diferenciaField.setValue(0);
+ }
+}
diff --git a/src/danielcortes/xyz/views/components/FondoTableModel.java b/src/danielcortes/xyz/views/components/FondoTableModel.java
new file mode 100644
index 0000000..be25f6c
--- /dev/null
+++ b/src/danielcortes/xyz/views/components/FondoTableModel.java
@@ -0,0 +1,102 @@
+/*
+ * 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 danielcortes.xyz.models.egreso.Egreso;
+
+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 rows.get(row).getValor();
+ case 1:
+ return rows.get(row).getDescripcion();
+ }
+ return null;
+ }
+
+ public CalculoFondo getCalculoFondo(int row){
+ return rows.get(row);
+ }
+}