First!! :3 Existe una pequeña base de proyecto por ahora
This commit is contained in:
19
caja.iml
Normal file
19
caja.iml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.13" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.github.lgooddatepicker:LGoodDatePicker:10.3.1" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
28
database/create.sql
Normal file
28
database/create.sql
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
drop table if exists egresos;
|
||||||
|
drop table if exists tipos_egreso;
|
||||||
|
|
||||||
|
create table egresos(
|
||||||
|
id int(10) unsigned primary key auto_increment,
|
||||||
|
nro varchar(191) not null,
|
||||||
|
descripcion varchar(191) not null,
|
||||||
|
valor int(10) not null,
|
||||||
|
tipo_id int(10) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
create table tipos_egreso(
|
||||||
|
id int(10) unsigned primary key auto_increment,
|
||||||
|
nombre varchar(191) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into tipos_egreso (nombre) values
|
||||||
|
('Guia Materia Prima'),
|
||||||
|
('Factura Materia Prima'),
|
||||||
|
('Factura Gastos Generales'),
|
||||||
|
('Pago Partime'),
|
||||||
|
('Gasto Menor Materia Prima'),
|
||||||
|
('Gasto General Sin Respaldo'),
|
||||||
|
('Gasto General Con Boleta'),
|
||||||
|
('Anticipo Arriendo'),
|
||||||
|
('Anticipo Personal'),
|
||||||
|
('Retiros Gerencia'),
|
||||||
|
('Otro');
|
||||||
40
pom.xml
Normal file
40
pom.xml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>danielcortes.xyz</groupId>
|
||||||
|
<artifactId>caja</artifactId>
|
||||||
|
<version>0.1</version>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>8</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.13</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.lgooddatepicker</groupId>
|
||||||
|
<artifactId>LGoodDatePicker</artifactId>
|
||||||
|
<version>10.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
|
|
||||||
38
src/main/java/danielcortes/xyz/Main.java
Normal file
38
src/main/java/danielcortes/xyz/Main.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package danielcortes.xyz;
|
||||||
|
|
||||||
|
import danielcortes.xyz.controllers.CajaController;
|
||||||
|
import danielcortes.xyz.models.EgresoDAO;
|
||||||
|
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||||
|
import danielcortes.xyz.models.mysql.MysqlEgresoDAO;
|
||||||
|
import danielcortes.xyz.models.mysql.MysqlTipoEgresoDAO;
|
||||||
|
import danielcortes.xyz.views.CajaView;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
private static final String lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel(lookAndFeel);
|
||||||
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CajaView view = new CajaView();
|
||||||
|
JFrame frame = new JFrame("Caja");
|
||||||
|
frame.setContentPane(view.getUI());
|
||||||
|
frame.setContentPane(view.contentPanel);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setSize(1300,700);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
EgresoDAO egresoDAO = new MysqlEgresoDAO();
|
||||||
|
TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO();
|
||||||
|
CajaController cajaController = new CajaController(view, egresoDAO, tipoEgresoDAO);
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package danielcortes.xyz.controllers;
|
||||||
|
|
||||||
|
import danielcortes.xyz.models.Egreso;
|
||||||
|
import danielcortes.xyz.models.EgresoDAO;
|
||||||
|
import danielcortes.xyz.models.TipoEgreso;
|
||||||
|
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||||
|
import danielcortes.xyz.views.CajaView;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class CajaController {
|
||||||
|
private CajaView view;
|
||||||
|
private EgresoDAO egresoDAO;
|
||||||
|
private TipoEgresoDAO tipoEgresoDAO;
|
||||||
|
|
||||||
|
public CajaController(CajaView view, EgresoDAO egresoDAO, TipoEgresoDAO tipoEgresoDAO){
|
||||||
|
this.view = view;
|
||||||
|
this.egresoDAO = egresoDAO;
|
||||||
|
this.tipoEgresoDAO = tipoEgresoDAO;
|
||||||
|
this.setUpViewEvents();
|
||||||
|
this.fillEgresosTable();
|
||||||
|
this.fillEgresosTipo();
|
||||||
|
this.updateTotalEgresos();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillEgresosTipo() {
|
||||||
|
JComboBox<TipoEgreso> tipoCombo = view.getTipoCombo();
|
||||||
|
for(TipoEgreso tipoEgreso : this.tipoEgresoDAO.findAll()){
|
||||||
|
tipoCombo.addItem(tipoEgreso);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillEgresosTable() {
|
||||||
|
for(Egreso egreso: this.egresoDAO.findAll()){
|
||||||
|
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(egreso.getTipo()).get(0);
|
||||||
|
view.getEgresosTableModel().addRow(new String[]{
|
||||||
|
egreso.getNro(),
|
||||||
|
egreso.getDescripcion(),
|
||||||
|
String.valueOf(egreso.getValor()),
|
||||||
|
tipoEgreso.getNombre()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpViewEvents(){
|
||||||
|
this.view.getGuardarButton().addActionListener(e -> {
|
||||||
|
String nro = this.view.getNroField().getText();
|
||||||
|
String descripcion = this.view.getDescripcionField().getText();
|
||||||
|
String valor = this.view.getValorField().getText();
|
||||||
|
TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem();
|
||||||
|
this.addToTable(nro, descripcion, valor, tipo.getNombre());
|
||||||
|
this.createEgreso(nro, descripcion, valor, tipo.getId());
|
||||||
|
this.updateTotalEgresos();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToTable(String nro, String descripcion, String valor, String tipo){
|
||||||
|
view.getEgresosTableModel().addRow(new String[]{nro,descripcion,valor,tipo});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTotalEgresos(){
|
||||||
|
int total = this.egresoDAO.getTotalEgreso();
|
||||||
|
this.view.getTotalEgresosField().setText(String.valueOf(total));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createEgreso(String nro, String descripcion, String valor, int tipo){
|
||||||
|
Egreso egreso = new Egreso();
|
||||||
|
egreso.setValor(Integer.valueOf(valor));
|
||||||
|
egreso.setDescripcion(descripcion);
|
||||||
|
egreso.setNro(nro);
|
||||||
|
egreso.setTipo(tipo);
|
||||||
|
egresoDAO.insertEgreso(egreso);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
24
src/main/java/danielcortes/xyz/data/MysqlConnection.java
Normal file
24
src/main/java/danielcortes/xyz/data/MysqlConnection.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package danielcortes.xyz.data;
|
||||||
|
|
||||||
|
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class MysqlConnection {
|
||||||
|
private MysqlDataSource dataSource;
|
||||||
|
|
||||||
|
public MysqlConnection(){
|
||||||
|
this.dataSource = new MysqlDataSource();
|
||||||
|
this.configureDataSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureDataSource(){
|
||||||
|
this.dataSource.setUser("root");
|
||||||
|
this.dataSource.setPassword("lagging");
|
||||||
|
this.dataSource.setServerName("localhost");
|
||||||
|
this.dataSource.setDatabaseName("caja");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() throws SQLException{
|
||||||
|
return this.dataSource.getConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
67
src/main/java/danielcortes/xyz/models/Egreso.java
Normal file
67
src/main/java/danielcortes/xyz/models/Egreso.java
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package danielcortes.xyz.models;
|
||||||
|
|
||||||
|
public class Egreso {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String nro;
|
||||||
|
private String descripcion;
|
||||||
|
private int valor;
|
||||||
|
private int tipo;
|
||||||
|
|
||||||
|
public Egreso(int id, String nro, String descripcion, int valor, int tipo) {
|
||||||
|
this.id = id;
|
||||||
|
this.nro = nro;
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
this.valor = valor;
|
||||||
|
this.tipo = tipo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Egreso(String nro, String descripcion, int valor, int tipo) {
|
||||||
|
this.nro = nro;
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
this.valor = valor;
|
||||||
|
this.tipo = tipo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Egreso(){}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNro() {
|
||||||
|
return nro;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNro(String nro) {
|
||||||
|
this.nro = nro;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescripcion() {
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescripcion(String descripcion) {
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValor() {
|
||||||
|
return valor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValor(int valor) {
|
||||||
|
this.valor = valor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTipo() {
|
||||||
|
return tipo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTipo(int tipo) {
|
||||||
|
this.tipo = tipo;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/main/java/danielcortes/xyz/models/EgresoDAO.java
Normal file
14
src/main/java/danielcortes/xyz/models/EgresoDAO.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package danielcortes.xyz.models;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface EgresoDAO {
|
||||||
|
List<Egreso> findAll();
|
||||||
|
List<Egreso> findById(int id);
|
||||||
|
List<Egreso> findByNro(String nro);
|
||||||
|
boolean insertEgreso(Egreso egreso);
|
||||||
|
boolean updateEgreso(Egreso egreso);
|
||||||
|
boolean deleteEgreso(Egreso egreso);
|
||||||
|
int getTotalEgreso();
|
||||||
|
|
||||||
|
}
|
||||||
33
src/main/java/danielcortes/xyz/models/TipoEgreso.java
Normal file
33
src/main/java/danielcortes/xyz/models/TipoEgreso.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package danielcortes.xyz.models;
|
||||||
|
|
||||||
|
public class TipoEgreso {
|
||||||
|
private int id;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public TipoEgreso(int id, String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TipoEgreso(){}
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombre(String nombre) {
|
||||||
|
this.nombre = nombre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return this.nombre;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/main/java/danielcortes/xyz/models/TipoEgresoDAO.java
Normal file
12
src/main/java/danielcortes/xyz/models/TipoEgresoDAO.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package danielcortes.xyz.models;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface TipoEgresoDAO {
|
||||||
|
List<TipoEgreso> findAll();
|
||||||
|
List<TipoEgreso> findById(int id);
|
||||||
|
List<TipoEgreso> findByNombre(String nombre);
|
||||||
|
boolean insertTipoEgreso(TipoEgreso tipoEgreso);
|
||||||
|
boolean updateTipoEgreso(TipoEgreso tipoEgreso);
|
||||||
|
boolean deleteTipoEgreso(TipoEgreso tipoEgreso);
|
||||||
|
}
|
||||||
172
src/main/java/danielcortes/xyz/models/mysql/MysqlEgresoDAO.java
Normal file
172
src/main/java/danielcortes/xyz/models/mysql/MysqlEgresoDAO.java
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
package danielcortes.xyz.models.mysql;
|
||||||
|
|
||||||
|
import danielcortes.xyz.data.MysqlConnection;
|
||||||
|
import danielcortes.xyz.models.Egreso;
|
||||||
|
import danielcortes.xyz.models.EgresoDAO;
|
||||||
|
|
||||||
|
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 MysqlEgresoDAO implements EgresoDAO {
|
||||||
|
private MysqlConnection mysqlConnection;
|
||||||
|
|
||||||
|
public MysqlEgresoDAO(){
|
||||||
|
this.mysqlConnection = new MysqlConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Egreso> findAll() {
|
||||||
|
List<Egreso> egresoList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select * from egresos");
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
egresoList = this.EgresosFromResultSet(rs);
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return egresoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Egreso> findById(int id) {
|
||||||
|
List<Egreso> egresoList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select * from egresos where id = ?");
|
||||||
|
ps.setInt(1,id);
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
egresoList = this.EgresosFromResultSet(rs);
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return egresoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Egreso> findByNro(String nro) {
|
||||||
|
List<Egreso> egresoList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select * from egresos where nro = ?");
|
||||||
|
ps.setString(1, nro);
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
egresoList = this.EgresosFromResultSet(rs);
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return egresoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean insertEgreso(Egreso egreso) {
|
||||||
|
int updates;
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("insert into egresos (nro, descripcion, valor, tipo_id) values (?,?,?,?)");
|
||||||
|
ps.setString(1,egreso.getNro());
|
||||||
|
ps.setString(2,egreso.getDescripcion());
|
||||||
|
ps.setInt(3,egreso.getValor());
|
||||||
|
ps.setInt(4,egreso.getTipo());
|
||||||
|
updates = ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return updates > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateEgreso(Egreso egreso) {
|
||||||
|
int updates;
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("update egresos set nro = ?, descripcion = ?, valor = ?, tipo_id = ? where id = ? ");
|
||||||
|
ps.setString(1,egreso.getNro());
|
||||||
|
ps.setString(2,egreso.getDescripcion());
|
||||||
|
ps.setInt(3,egreso.getValor());
|
||||||
|
ps.setInt(4,egreso.getTipo());
|
||||||
|
ps.setInt(5, egreso.getId());
|
||||||
|
updates = ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return updates > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteEgreso(Egreso egreso) {
|
||||||
|
int updates;
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("delete from egresos where id = ? ");
|
||||||
|
ps.setInt(1, egreso.getId());
|
||||||
|
updates = ps.executeUpdate();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return updates > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalEgreso() {
|
||||||
|
int total = 0;
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select sum(valor) from egresos");
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
rs.next();
|
||||||
|
total = rs.getInt(1);
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<Egreso> EgresosFromResultSet(ResultSet rs) throws SQLException {
|
||||||
|
ArrayList<Egreso> egresoList = new ArrayList<>();
|
||||||
|
while(rs.next()){
|
||||||
|
Egreso egreso = new Egreso();
|
||||||
|
egreso.setId(rs.getInt("id"));
|
||||||
|
egreso.setNro(rs.getString("nro"));
|
||||||
|
egreso.setDescripcion(rs.getString("descripcion"));
|
||||||
|
egreso.setValor(rs.getInt("valor"));
|
||||||
|
egreso.setTipo(rs.getInt("tipo_id"));
|
||||||
|
egresoList.add(egreso);
|
||||||
|
}
|
||||||
|
return egresoList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package danielcortes.xyz.models.mysql;
|
||||||
|
|
||||||
|
import danielcortes.xyz.data.MysqlConnection;
|
||||||
|
import danielcortes.xyz.models.Egreso;
|
||||||
|
import danielcortes.xyz.models.TipoEgreso;
|
||||||
|
import danielcortes.xyz.models.TipoEgresoDAO;
|
||||||
|
|
||||||
|
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 MysqlTipoEgresoDAO implements TipoEgresoDAO {
|
||||||
|
private MysqlConnection mysqlConnection;
|
||||||
|
|
||||||
|
public MysqlTipoEgresoDAO(){
|
||||||
|
this.mysqlConnection = new MysqlConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TipoEgreso> findAll() {
|
||||||
|
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso");
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
tipoEgresoList = this.TipoEgresoFromResultSet(rs);
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return tipoEgresoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TipoEgreso> findById(int id) {
|
||||||
|
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where id = ?");
|
||||||
|
ps.setInt(1, id);
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
tipoEgresoList = this.TipoEgresoFromResultSet(rs);
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return tipoEgresoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TipoEgreso> findByNombre(String nombre) {
|
||||||
|
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Connection conn = mysqlConnection.getConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where nombre = ?");
|
||||||
|
ps.setString(1, nombre);
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
tipoEgresoList = this.TipoEgresoFromResultSet(rs);
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return tipoEgresoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean insertTipoEgreso(TipoEgreso tipoEgreso) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateTipoEgreso(TipoEgreso tipoEgreso) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteTipoEgreso(TipoEgreso tipoEgreso) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TipoEgreso> TipoEgresoFromResultSet(ResultSet rs) throws SQLException {
|
||||||
|
ArrayList<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||||
|
while(rs.next()){
|
||||||
|
TipoEgreso tipoEgreso = new TipoEgreso();
|
||||||
|
tipoEgreso.setId(rs.getInt("id"));
|
||||||
|
tipoEgreso.setNombre(rs.getString("nombre"));
|
||||||
|
tipoEgresoList.add(tipoEgreso);
|
||||||
|
}
|
||||||
|
return tipoEgresoList;
|
||||||
|
}
|
||||||
|
}
|
||||||
129
src/main/java/danielcortes/xyz/views/CajaView.form
Normal file
129
src/main/java/danielcortes/xyz/views/CajaView.form
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="danielcortes.xyz.views.CajaView">
|
||||||
|
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="15" left="15" bottom="15" right="15"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="1074" height="403"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="9047a" binding="egresosPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
|
<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="etched" title="Egresos"/>
|
||||||
|
<children>
|
||||||
|
<component id="d8e90" 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="696ee" class="javax.swing.JTextField" binding="valorField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" 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="da489" 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>
|
||||||
|
<component id="f50cf" 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="Valor"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="1af5c" class="javax.swing.JTextField" binding="nroField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" 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="c5b18" 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="N°"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5602d" class="javax.swing.JComboBox" binding="tipoCombo">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="daec8" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="3" 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="Tipo"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<scrollpane id="65bec">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="5" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="c0fff" class="javax.swing.JTable" binding="egresosTable" custom-create="true">
|
||||||
|
<constraints/>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</scrollpane>
|
||||||
|
<component id="c5738" class="javax.swing.JButton" binding="guardarButton" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="4" 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="Añadir"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2b8d0" class="javax.swing.JTextField" binding="totalEgresosField">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="4" 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>
|
||||||
|
<editable value="false"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3442d" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Total Egresos:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<inspectionSuppressions>
|
||||||
|
<suppress inspection="FormSpellChecking"/>
|
||||||
|
</inspectionSuppressions>
|
||||||
|
</form>
|
||||||
64
src/main/java/danielcortes/xyz/views/CajaView.java
Normal file
64
src/main/java/danielcortes/xyz/views/CajaView.java
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package danielcortes.xyz.views;
|
||||||
|
|
||||||
|
import danielcortes.xyz.models.TipoEgreso;
|
||||||
|
import danielcortes.xyz.views.components.EgresosTableModel;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.plaf.basic.BasicComboBoxRenderer;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class CajaView {
|
||||||
|
public JPanel contentPanel;
|
||||||
|
private JPanel egresosPanel;
|
||||||
|
private JTable egresosTable;
|
||||||
|
private JButton guardarButton;
|
||||||
|
private JTextField valorField;
|
||||||
|
private JTextField descripcionField;
|
||||||
|
private JTextField nroField;
|
||||||
|
private JTextField totalEgresosField;
|
||||||
|
private JComboBox<TipoEgreso> tipoCombo;
|
||||||
|
|
||||||
|
private EgresosTableModel egresosTableModel;
|
||||||
|
|
||||||
|
private void createUIComponents() {
|
||||||
|
createEgresosTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createEgresosTable() {
|
||||||
|
egresosTableModel = new EgresosTableModel();
|
||||||
|
egresosTable = new JTable(egresosTableModel);
|
||||||
|
egresosTable.setAutoCreateRowSorter(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel getUI() {
|
||||||
|
return contentPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getGuardarButton() {
|
||||||
|
return guardarButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTextField getValorField() {
|
||||||
|
return valorField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTextField getDescripcionField() {
|
||||||
|
return descripcionField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTextField getNroField() {
|
||||||
|
return nroField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JTextField getTotalEgresosField() {
|
||||||
|
return totalEgresosField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JComboBox<TipoEgreso> getTipoCombo() {
|
||||||
|
return tipoCombo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EgresosTableModel getEgresosTableModel() {
|
||||||
|
return egresosTableModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package danielcortes.xyz.views.components;
|
||||||
|
|
||||||
|
public class EgresosTableModel extends TableModel{
|
||||||
|
private String[] columns;
|
||||||
|
|
||||||
|
public EgresosTableModel(){
|
||||||
|
super();
|
||||||
|
this.columns = new String[]{"N°", "Descripcion", "Valor", "Tipo"};
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColumnName(int col) {
|
||||||
|
return columns[col];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColumnCount() {
|
||||||
|
return columns.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package danielcortes.xyz.views.components;
|
||||||
|
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public abstract class TableModel extends AbstractTableModel {
|
||||||
|
private ArrayList<String[]> rows = new ArrayList<>();
|
||||||
|
public int getRowCount() {
|
||||||
|
return rows.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRow(String[] data){
|
||||||
|
rows.add(data);
|
||||||
|
this.fireTableRowsInserted(0,getRowCount()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValueAt(int row, int col) {
|
||||||
|
return rows.get(row)[col];
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/main/resources/data.template.json
Normal file
10
src/main/resources/data.template.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"egresos": [
|
||||||
|
{
|
||||||
|
"nro": "1",
|
||||||
|
"descripcion": "2",
|
||||||
|
"valor": 123,
|
||||||
|
"tipo": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user