Agregada una ventana para realizar el calculo del fondo de la caja, es wip, falta la aprobacion del jefe jajaj

This commit is contained in:
Daniel Cortes
2019-01-18 18:43:53 -03:00
parent 30de826ee2
commit 5a9455eb4b
15 changed files with 1744 additions and 467 deletions

View File

@@ -12,52 +12,48 @@
<collation id="4" parent="1" name="NOCASE"/>
<collation id="5" parent="1" name="RTRIM"/>
<table id="6" parent="2" name="caja"/>
<table id="7" parent="2" name="documentos"/>
<table id="8" parent="2" name="efectivos"/>
<table id="9" parent="2" name="egresos"/>
<table id="10" parent="2" name="ingresos"/>
<table id="11" parent="2" name="sqlite_master">
<table id="7" parent="2" name="calculo_fondo"/>
<table id="8" parent="2" name="documentos"/>
<table id="9" parent="2" name="efectivos"/>
<table id="10" parent="2" name="egresos"/>
<table id="11" parent="2" name="ingresos"/>
<table id="12" parent="2" name="sqlite_master">
<System>1</System>
</table>
<table id="12" parent="2" name="tipos_egreso"/>
<table id="13" parent="2" name="tipos_ingreso"/>
<column id="14" parent="6" name="id">
<table id="13" parent="2" name="tipos_egreso"/>
<table id="14" parent="2" name="tipos_ingreso"/>
<column id="15" parent="6" name="id">
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="15" parent="6" name="fecha">
<column id="16" parent="6" name="fecha">
<Position>2</Position>
<DataType>date|0s</DataType>
<NotNull>1</NotNull>
</column>
<key id="16" parent="6">
<key id="17" parent="6">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>
<column id="17" parent="7" name="id">
<column id="18" parent="7" name="id">
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="18" parent="7" name="cheques">
<column id="19" parent="7" name="valor">
<Position>2</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="19" parent="7" name="tarjetas">
<column id="20" parent="7" name="descripcion">
<Position>3</Position>
<DataType>integer|0s</DataType>
<DataType>text|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="20" parent="7" name="caja_id">
<column id="21" parent="7" name="caja_id">
<Position>4</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="21" parent="7" name="retiros">
<Position>5</Position>
<DataType>integer|0s</DataType>
<DefaultExpression>0</DefaultExpression>
</column>
<key id="22" parent="7">
<ColNames>id</ColNames>
<Primary>1</Primary>
@@ -73,212 +69,247 @@
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="25" parent="8" name="veinte_mil">
<column id="25" parent="8" name="cheques">
<Position>2</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="26" parent="8" name="diez_mil">
<column id="26" parent="8" name="tarjetas">
<Position>3</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="27" parent="8" name="cinco_mil">
<column id="27" parent="8" name="caja_id">
<Position>4</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="28" parent="8" name="dos_mil">
<column id="28" parent="8" name="retiros">
<Position>5</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
<DefaultExpression>0</DefaultExpression>
</column>
<column id="29" parent="8" name="mil">
<Position>6</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="30" parent="8" name="quinientos">
<Position>7</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="31" parent="8" name="cien">
<Position>8</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="32" parent="8" name="cincuenta">
<Position>9</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="33" parent="8" name="diez">
<Position>10</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="34" parent="8" name="caja_id">
<Position>11</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<key id="35" parent="8">
<key id="29" parent="8">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>
<foreign-key id="36" parent="8">
<foreign-key id="30" parent="8">
<ColNames>caja_id</ColNames>
<RefTableName>caja</RefTableName>
<RefColNames>id</RefColNames>
<OnDelete>restrict</OnDelete>
<OnUpdate>cascade</OnUpdate>
</foreign-key>
<column id="37" parent="9" name="id">
<column id="31" parent="9" name="id">
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="38" parent="9" name="nro">
<column id="32" parent="9" name="veinte_mil">
<Position>2</Position>
<DataType>text|0s</DataType>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="39" parent="9" name="descripcion">
<column id="33" parent="9" name="diez_mil">
<Position>3</Position>
<DataType>text|0s</DataType>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="40" parent="9" name="valor">
<column id="34" parent="9" name="cinco_mil">
<Position>4</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="41" parent="9" name="tipo_egreso_id">
<column id="35" parent="9" name="dos_mil">
<Position>5</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="42" parent="9" name="caja_id">
<column id="36" parent="9" name="mil">
<Position>6</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<key id="43" parent="9">
<column id="37" parent="9" name="quinientos">
<Position>7</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="38" parent="9" name="cien">
<Position>8</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="39" parent="9" name="cincuenta">
<Position>9</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="40" parent="9" name="diez">
<Position>10</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="41" parent="9" name="caja_id">
<Position>11</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<key id="42" parent="9">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>
<foreign-key id="44" parent="9">
<foreign-key id="43" parent="9">
<ColNames>caja_id</ColNames>
<RefTableName>caja</RefTableName>
<RefColNames>id</RefColNames>
<OnDelete>restrict</OnDelete>
<OnUpdate>cascade</OnUpdate>
</foreign-key>
<column id="44" parent="10" name="id">
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="45" parent="10" name="nro">
<Position>2</Position>
<DataType>text|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="46" parent="10" name="descripcion">
<Position>3</Position>
<DataType>text|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="47" parent="10" name="valor">
<Position>4</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="48" parent="10" name="tipo_egreso_id">
<Position>5</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="49" parent="10" name="caja_id">
<Position>6</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<key id="50" parent="10">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>
<foreign-key id="51" parent="10">
<ColNames>tipo_egreso_id</ColNames>
<RefTableName>tipos_egreso</RefTableName>
<RefColNames>id</RefColNames>
<OnDelete>restrict</OnDelete>
<OnUpdate>cascade</OnUpdate>
</foreign-key>
<foreign-key id="45" parent="9">
<foreign-key id="52" parent="10">
<ColNames>caja_id</ColNames>
<RefTableName>caja</RefTableName>
<RefColNames>id</RefColNames>
<OnDelete>restrict</OnDelete>
<OnUpdate>cascade</OnUpdate>
</foreign-key>
<column id="46" parent="10" name="id">
<column id="53" parent="11" name="id">
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="47" parent="10" name="valor">
<column id="54" parent="11" name="valor">
<Position>2</Position>
<DataType>integer|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="48" parent="10" name="nro_inicial">
<column id="55" parent="11" name="nro_inicial">
<Position>3</Position>
<DataType>text|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="49" parent="10" name="nro_final">
<column id="56" parent="11" name="nro_final">
<Position>4</Position>
<DataType>text|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="50" parent="10" name="tipo_ingreso_id">
<column id="57" parent="11" name="tipo_ingreso_id">
<Position>5</Position>
<DataType>integer unsigned|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="51" parent="10" name="caja_id">
<column id="58" parent="11" name="caja_id">
<Position>6</Position>
<DataType>integer unsigned|0s</DataType>
<NotNull>1</NotNull>
</column>
<column id="52" parent="10" name="nro_z_inicial">
<column id="59" parent="11" name="nro_z_inicial">
<Position>7</Position>
<DefaultExpression>&apos;&apos;</DefaultExpression>
</column>
<column id="53" parent="10" name="nro_z_final">
<column id="60" parent="11" name="nro_z_final">
<Position>8</Position>
<DefaultExpression>&apos;&apos;</DefaultExpression>
</column>
<key id="54" parent="10">
<key id="61" parent="11">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>
<foreign-key id="55" parent="10">
<foreign-key id="62" parent="11">
<ColNames>tipo_ingreso_id</ColNames>
<RefTableName>tipos_ingreso</RefTableName>
<RefColNames>id</RefColNames>
<OnDelete>restrict</OnDelete>
<OnUpdate>cascade</OnUpdate>
</foreign-key>
<foreign-key id="56" parent="10">
<foreign-key id="63" parent="11">
<ColNames>caja_id</ColNames>
<RefTableName>caja</RefTableName>
<RefColNames>id</RefColNames>
<OnDelete>restrict</OnDelete>
<OnUpdate>cascade</OnUpdate>
</foreign-key>
<column id="57" parent="11" name="type">
<column id="64" parent="12" name="type">
<Position>1</Position>
<DataType>text|0s</DataType>
</column>
<column id="58" parent="11" name="name">
<column id="65" parent="12" name="name">
<Position>2</Position>
<DataType>text|0s</DataType>
</column>
<column id="59" parent="11" name="tbl_name">
<column id="66" parent="12" name="tbl_name">
<Position>3</Position>
<DataType>text|0s</DataType>
</column>
<column id="60" parent="11" name="rootpage">
<column id="67" parent="12" name="rootpage">
<Position>4</Position>
<DataType>int|0s</DataType>
</column>
<column id="61" parent="11" name="sql">
<column id="68" parent="12" name="sql">
<Position>5</Position>
<DataType>text|0s</DataType>
</column>
<column id="62" parent="12" name="id">
<column id="69" parent="13" name="id">
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="63" parent="12" name="nombre">
<column id="70" parent="13" name="nombre">
<Position>2</Position>
<DataType>text|0s</DataType>
<NotNull>1</NotNull>
</column>
<key id="64" parent="12">
<key id="71" parent="13">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>
<column id="65" parent="13" name="id">
<column id="72" parent="14" name="id">
<Position>1</Position>
<DataType>integer|0s</DataType>
</column>
<column id="66" parent="13" name="nombre">
<column id="73" parent="14" name="nombre">
<Position>2</Position>
<DataType>text|0s</DataType>
<NotNull>1</NotNull>
</column>
<key id="67" parent="13">
<key id="74" parent="14">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>

871
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

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

BIN
dist/caja.jar vendored

Binary file not shown.

View File

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

View File

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

View File

@@ -158,7 +158,6 @@ public class MysqlCajaDAO extends CajaDAO {
return updates > 0;
}
@Override
public void createCajasForMonth(LocalDate month) {
LocalDate date = month.withDayOfMonth(1);

View File

@@ -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 +
'}';
}
}

View File

@@ -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<CalculoFondo> findAll();
public abstract List<CalculoFondo> 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<CalculoFondo> cajasFromResultSet(ResultSet rs) throws SQLException {
List<CalculoFondo> 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;
}
}

View File

@@ -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<CalculoFondo> findAll() {
List<CalculoFondo> 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<CalculoFondo> findByCaja(Caja caja) {
List<CalculoFondo> 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;
}
}

View File

@@ -3,7 +3,7 @@
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="642" height="837"/>
<xy x="20" y="20" width="662" height="597"/>
</constraints>
<properties/>
<border type="none">
@@ -411,7 +411,25 @@
</grid>
</children>
</grid>
<vspacer id="d3dd4">
<grid id="13313" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="155de" class="javax.swing.JButton" binding="calcularFondoButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Calcular Fondo"/>
</properties>
</component>
</children>
</grid>
<vspacer id="28d89">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>

View File

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

View File

@@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.CalcularFondoView">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="601" height="443"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="79b71">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6871a" class="javax.swing.JTable" binding="table" custom-create="true" default-binding="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<grid id="6aceb" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d65ec" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="fondoField">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="5b2bc" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Fondo"/>
</properties>
</component>
<component id="35a61" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Suma de dinero"/>
</properties>
</component>
<component id="7ded1" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Diferencia"/>
</properties>
</component>
<component id="a2a23" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="sumaField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
<component id="2745a" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="diferenciaField">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
</children>
</grid>
<grid id="53f2b" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d4f55" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="valorField">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="ed6eb" class="javax.swing.JTextField" binding="descripcionField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="8d847" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Valor"/>
</properties>
</component>
<component id="214a7" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Descripcion"/>
</properties>
</component>
</children>
</grid>
<grid id="e7db6" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="b5709" class="javax.swing.JButton" binding="guardarButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Guardar"/>
</properties>
</component>
<component id="c9575" class="javax.swing.JButton" binding="editarButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Editar"/>
</properties>
</component>
<component id="982ca" class="javax.swing.JButton" binding="eliminarButton" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Eliminar"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

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

View File

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