Agregadas clases para compatibilidad con sqlite

This commit is contained in:
Daniel Cortes
2018-12-28 18:23:15 -03:00
parent 4e8f31f7b5
commit fe187e4892
25 changed files with 1682 additions and 55 deletions

View File

@@ -11,10 +11,6 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <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" />
<orderEntry type="module-library"> <orderEntry type="module-library">
<library> <library>
<CLASSES> <CLASSES>
@@ -24,5 +20,10 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<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: org.xerial:sqlite-jdbc:3.25.2" level="project" />
<orderEntry type="library" name="Maven: com.github.lgooddatepicker:LGoodDatePicker:10.3.1" level="project" />
</component> </component>
</module> </module>

24
conf Normal file
View File

@@ -0,0 +1,24 @@
# configuracion del sistema de Caja
# configuracion de la base de datos:
# database_type sirve para elegir el sistema de base de datos que utilizara el sistema.
# los valores soportados son:
# - mysql
# - sqlite
database_type = mysql
#database_type = sqlite
# database_uri es la uri de la base de datos con la que se conectara el sistema.
# debe corresponder con el sistema de base de datos seleccionado en database_type
database_uri = jdbc:mysql://localhost/caja?user=root&password=lagging&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#database_uri = jdbc:sqlite:/opt/caja/database.db
# look_and_feel elige el look and feel que intentara utilizar la aplicacion, si el seleccionado no funciona en el sistema operativo se hara fallback a metal.
look_and_feel = javax.swing.plaf.metal.MetalLookAndFeel
#look_and_feel = com.sun.java.swing.plaf.gtk.GTKLookAndFeel
#look_and_feel = com.sun.java.swing.plaf.windows.WindowsLookAndFeel

BIN
database.sqlite Normal file

Binary file not shown.

120
database/sqlite.sql Normal file
View File

@@ -0,0 +1,120 @@
/*
MIT License
Copyright (c) 2018 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.
*/
pragma foreign_keys = ON;
drop table if exists egresos;
drop table if exists tipos_egreso;
drop table if exists ingresos;
drop table if exists tipos_ingreso;
drop table if exists efectivos;
drop table if exists documentos;
drop table if exists caja;
create table caja
(
id integer primary key,
fecha date not null
);
create table tipos_egreso
(
id integer primary key,
nombre text not null
);
create table egresos
(
id integer primary key,
nro text not null,
descripcion text not null,
valor integer not null,
tipo_egreso_id integer not null,
caja_id integer not null,
foreign key (tipo_egreso_id) references tipos_egreso (id) on update cascade on delete restrict,
foreign key (caja_id) references caja (id) on update cascade on delete restrict
);
create table tipos_ingreso
(
id integer primary key,
nombre text not null
);
create table ingresos
(
id integer primary key,
valor integer not null,
nro_inicial text not null,
nro_final text not null,
tipo_ingreso_id integer unsigned not null,
caja_id integer unsigned not null,
foreign key (tipo_ingreso_id) references tipos_ingreso (id) on update cascade on delete restrict,
foreign key (caja_id) references caja (id) on update cascade on delete restrict
);
create table efectivos
(
id integer primary key,
veinte_mil integer not null,
diez_mil integer not null,
cinco_mil integer not null,
dos_mil integer not null,
mil integer not null,
quinientos integer not null,
cien integer not null,
cincuenta integer not null,
diez integer not null,
caja_id integer not null,
foreign key (caja_id) references caja (id) on update cascade on delete restrict
);
create table documentos
(
id integer primary key,
cheques integer not null,
tarjetas integer not null,
caja_id integer not null,
foreign key (caja_id) references caja (id) on update cascade on delete restrict
);
insert into tipos_egreso (nombre)
values ('Factura Materia Prima'),
('Factura Gastos Generales'),
('Gasto Menor Materia Prima'),
('Gasto General Sin Respaldo'),
('Gasto General Con Boleta'),
('Guia Materia Prima'),
('Anticipo Arriendo'),
('Anticipo Personal'),
('Pago Partime'),
('Retiros Gerencia'),
('Otro');
insert into tipos_ingreso (nombre)
values ('Boletas Fiscales'),
('Boletas Manuales'),
('Facturas'),
('Guias')

View File

@@ -32,6 +32,11 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version> <version>8.0.13</version>
</dependency> </dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.25.2</version>
</dependency>
<dependency> <dependency>
<groupId>com.github.lgooddatepicker</groupId> <groupId>com.github.lgooddatepicker</groupId>
<artifactId>LGoodDatePicker</artifactId> <artifactId>LGoodDatePicker</artifactId>

View File

@@ -31,11 +31,11 @@ import danielcortes.xyz.models.caja.MysqlCajaDAO;
import danielcortes.xyz.views.ManagerView; import danielcortes.xyz.views.ManagerView;
import javax.swing.*; import javax.swing.*;
import java.sql.SQLException;
import java.util.Locale; import java.util.Locale;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) throws SQLException {
System.setProperty("awt.useSystemAAFontSettings", "on"); System.setProperty("awt.useSystemAAFontSettings", "on");
System.setProperty("swing.aatext", "true"); System.setProperty("swing.aatext", "true");
@@ -47,6 +47,7 @@ public class Main {
Locale.setDefault(new Locale("es")); Locale.setDefault(new Locale("es"));
CajaDAO cajaDAO = new MysqlCajaDAO(); CajaDAO cajaDAO = new MysqlCajaDAO();
ManagerView view = new ManagerView(); ManagerView view = new ManagerView();
ManagerController managerController = new ManagerController(view, cajaDAO); ManagerController managerController = new ManagerController(view, cajaDAO);

View File

@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2018 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.data;
import java.sql.SQLException;
public interface ConnectionHolder {
public java.sql.Connection getConnection() throws SQLException;
}

View File

@@ -26,13 +26,13 @@ package danielcortes.xyz.data;
import java.sql.*; import java.sql.*;
public class MysqlConnection { public class MysqlConnectionHolder implements ConnectionHolder {
private String databaseURI; private String databaseURI;
public MysqlConnection(){ public MysqlConnectionHolder(){
this.databaseURI = Properties.getInstance().getProperty("database_uri"); this.databaseURI = Properties.getInstance().getProperty("database_uri");
} }
public Connection getConnection() throws SQLException{ public java.sql.Connection getConnection() throws SQLException{
return DriverManager.getConnection(databaseURI); return DriverManager.getConnection(databaseURI);
} }
} }

View File

@@ -0,0 +1,40 @@
/*
* MIT License
*
* Copyright (c) 2018 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.data;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SQLiteConnectionHolder implements ConnectionHolder {
private String databaseURI;
public SQLiteConnectionHolder(){
this.databaseURI = Properties.getInstance().getProperty("database_uri");
}
@Override
public java.sql.Connection getConnection() throws SQLException{
return DriverManager.getConnection(databaseURI);
}
}

View File

@@ -24,7 +24,7 @@
package danielcortes.xyz.models.caja; package danielcortes.xyz.models.caja;
import danielcortes.xyz.data.MysqlConnection; import danielcortes.xyz.data.MysqlConnectionHolder;
import java.sql.*; import java.sql.*;
import java.time.LocalDate; import java.time.LocalDate;
@@ -32,10 +32,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MysqlCajaDAO implements CajaDAO { public class MysqlCajaDAO implements CajaDAO {
private MysqlConnection mysqlConnection; private MysqlConnectionHolder mysqlConnection;
public MysqlCajaDAO() { public MysqlCajaDAO() {
this.mysqlConnection = new MysqlConnection(); this.mysqlConnection = new MysqlConnectionHolder();
} }
@Override @Override

View File

@@ -0,0 +1,168 @@
/*
* MIT License
*
* Copyright (c) 2018 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.caja;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class SQLiteCajaDAO implements CajaDAO {
private SQLiteConnectionHolder connectionHolder;
public SQLiteCajaDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public List<Caja> findAll() {
List<Caja> cajaList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from caja");
ResultSet rs = ps.executeQuery();
cajaList = this.cajasFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return cajaList;
}
@Override
public Caja findById(int id) {
Caja caja = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from caja where id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
caja = this.cajasFromResultSet(rs).get(0);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return caja;
}
@Override
public Caja findByFecha(LocalDate fecha) {
Caja caja = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?");
ps.setObject(1, fecha);
ResultSet rs = ps.executeQuery();
List<Caja> cajaList = this.cajasFromResultSet(rs);
if(cajaList.size() > 0){
caja = cajaList.get(0);
}
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return caja;
}
@Override
public boolean insertCaja(Caja caja) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)");
ps.setObject(1, caja.getFecha());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
caja.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean updateCaja(Caja caja) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?");
ps.setObject(1, caja.getFecha());
ps.setInt(2, caja.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
private List<Caja> cajasFromResultSet(ResultSet rs) throws SQLException {
List<Caja> cajaList = new ArrayList<>();
while (rs.next()) {
Caja caja = new Caja();
caja.setId(rs.getInt("id"));
caja.setFecha(rs.getObject("fecha", LocalDate.class));
cajaList.add(caja);
}
return cajaList;
}
}

View File

@@ -24,7 +24,7 @@
package danielcortes.xyz.models.documentos; package danielcortes.xyz.models.documentos;
import danielcortes.xyz.data.MysqlConnection; import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO;
@@ -37,10 +37,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MysqlDocumentosDAO implements DocumentosDAO { public class MysqlDocumentosDAO implements DocumentosDAO {
private MysqlConnection mysqlConnection; private MysqlConnectionHolder mysqlConnection;
public MysqlDocumentosDAO() { public MysqlDocumentosDAO() {
this.mysqlConnection = new MysqlConnection(); this.mysqlConnection = new MysqlConnectionHolder();
} }
@Override @Override

View File

@@ -0,0 +1,224 @@
/*
* MIT License
*
* Copyright (c) 2018 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.documentos;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO;
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 SQLiteDocumentosDAO implements DocumentosDAO{
private ConnectionHolder connectionHolder;
public SQLiteDocumentosDAO() {
this.connectionHolder = new MysqlConnectionHolder();
}
@Override
public List<Documentos> findAll() {
List<Documentos> documentosList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from documentos");
ResultSet rs = ps.executeQuery();
documentosList = this.documentosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return documentosList;
}
@Override
public Documentos findById(int id) {
Documentos documentos = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from documentos where id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
List<Documentos> documentosList = this.documentosFromResultSet(rs);
if(documentosList.size() > 0){
documentos = documentosList.get(0);
}
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return documentos;
}
@Override
public Documentos findByCaja(Caja caja) {
Documentos documentos = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from documentos where caja_id = ?");
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
List<Documentos> documentosList = this.documentosFromResultSet(rs);
if(documentosList.size() > 0){
documentos = documentosList.get(0);
}
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return documentos;
}
@Override
public boolean insertDocumentos(Documentos documentos) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, caja_id) values (?,?,?)");
ps.setInt(1, documentos.getCheques());
ps.setInt(2, documentos.getTarjetas());
ps.setInt(3, documentos.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
documentos.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean insertDefaultDocumentos(Documentos documentos) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, caja_id) values (0,0,?)");
ps.setInt(1, documentos.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
documentos.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean updateDocumentos(Documentos documentos) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("update documentos set tarjetas = ?, cheques = ?, caja_id = ? where id = ?");
ps.setInt(1, documentos.getTarjetas());
ps.setInt(2, documentos.getCheques());
ps.setInt(3, documentos.getCaja().getId());
ps.setInt(4, documentos.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean deleteDocumentos(Documentos documentos) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("delete from documentos where id = ?");
ps.setInt(1, documentos.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
private List<Documentos> documentosFromResultSet(ResultSet rs) throws SQLException {
List<Documentos> documentosList = new ArrayList<>();
while (rs.next()) {
CajaDAO cajaDAO = new MysqlCajaDAO();
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
Documentos documentos = new Documentos();
documentos.setCaja(caja);
documentos.setId(rs.getInt("id"));
documentos.setCheques(rs.getInt("cheques"));
documentos.setTarjetas(rs.getInt("tarjetas"));
documentosList.add(documentos);
}
return documentosList;
}
}

View File

@@ -24,7 +24,7 @@
package danielcortes.xyz.models.efectivo; package danielcortes.xyz.models.efectivo;
import danielcortes.xyz.data.MysqlConnection; import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO;
@@ -37,10 +37,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MysqlEfectivoDAO implements EfectivoDAO { public class MysqlEfectivoDAO implements EfectivoDAO {
private MysqlConnection mysqlConnection; private MysqlConnectionHolder mysqlConnection;
public MysqlEfectivoDAO() { public MysqlEfectivoDAO() {
this.mysqlConnection = new MysqlConnection(); this.mysqlConnection = new MysqlConnectionHolder();
} }
@Override @Override

View File

@@ -0,0 +1,245 @@
/*
* MIT License
*
* Copyright (c) 2018 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.efectivo;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO;
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 SQLiteEfectivoDAO implements EfectivoDAO{
private ConnectionHolder connectionHolder;
public SQLiteEfectivoDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public List<Efectivo> findAll() {
List<Efectivo> efectivoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos");
ResultSet rs = ps.executeQuery();
efectivoList = this.efectivosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivoList;
}
@Override
public Efectivo findById(int id) {
Efectivo efectivo = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
efectivo = this.efectivosFromResultSet(rs).get(0);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivo;
}
@Override
public Efectivo findByCaja(Caja caja) {
Efectivo efectivo = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
List<Efectivo> efectivoList = this.efectivosFromResultSet(rs);
if (efectivoList.size() > 0) {
efectivo = efectivoList.get(0);
}
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivo;
}
@Override
public boolean insertEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
ps.setInt(4, efectivo.getDosMil());
ps.setInt(5, efectivo.getMil());
ps.setInt(6, efectivo.getQuinientos());
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean insertDefaultEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)");
ps.setInt(1, efectivo.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean updateEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
ps.setInt(4, efectivo.getDosMil());
ps.setInt(5, efectivo.getMil());
ps.setInt(6, efectivo.getQuinientos());
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
ps.setInt(11, efectivo.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean deleteEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?");
ps.setInt(1, efectivo.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
private List<Efectivo> efectivosFromResultSet(ResultSet rs) throws SQLException {
List<Efectivo> efectivoList = new ArrayList<>();
while (rs.next()) {
CajaDAO cajaDAO = new MysqlCajaDAO();
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
Efectivo efectivo = new Efectivo();
efectivo.setCaja(caja);
efectivo.setId(rs.getInt("id"));
efectivo.setVeinteMil(rs.getInt("veinte_mil"));
efectivo.setDiezMil(rs.getInt("diez_mil"));
efectivo.setCincoMil(rs.getInt("cinco_mil"));
efectivo.setDosMil(rs.getInt("dos_mil"));
efectivo.setMil(rs.getInt("mil"));
efectivo.setQuinientos(rs.getInt("quinientos"));
efectivo.setCien(rs.getInt("cien"));
efectivo.setCincuenta(rs.getInt("cincuenta"));
efectivo.setDiez(rs.getInt("diez"));
efectivoList.add(efectivo);
}
return efectivoList;
}
}

View File

@@ -24,7 +24,7 @@
package danielcortes.xyz.models.egreso; package danielcortes.xyz.models.egreso;
import danielcortes.xyz.data.MysqlConnection; import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO;
@@ -40,10 +40,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MysqlEgresoDAO implements EgresoDAO { public class MysqlEgresoDAO implements EgresoDAO {
private MysqlConnection mysqlConnection; private MysqlConnectionHolder mysqlConnection;
public MysqlEgresoDAO(){ public MysqlEgresoDAO(){
this.mysqlConnection = new MysqlConnection(); this.mysqlConnection = new MysqlConnectionHolder();
} }
@Override @Override
@@ -65,6 +65,26 @@ public class MysqlEgresoDAO implements EgresoDAO {
return egresoList; 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 @Override
public List<Egreso> findByCaja(Caja caja) { public List<Egreso> findByCaja(Caja caja) {
List<Egreso> egresoList = new ArrayList<>(); List<Egreso> egresoList = new ArrayList<>();
@@ -85,25 +105,6 @@ public class MysqlEgresoDAO implements EgresoDAO {
return egresoList; 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 @Override
public List<Egreso> findByNro(String nro) { public List<Egreso> findByNro(String nro) {

View File

@@ -0,0 +1,267 @@
/*
* MIT License
*
* Copyright (c) 2018 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.egreso;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO;
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.models.tipo_egreso.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 SQLiteEgresoDAO implements EgresoDAO{
private ConnectionHolder connectionHolder;
public SQLiteEgresoDAO(){
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public List<Egreso> findAll() {
List<Egreso> egresoList = new ArrayList<>();
try {
Connection conn = connectionHolder.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 = connectionHolder.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> findByCaja(Caja caja) {
List<Egreso> egresoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from egresos where caja_id = ?");
ps.setInt(1, caja.getId());
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 = connectionHolder.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 List<Egreso> findByTipoEgreso(TipoEgreso tipoEgreso) {
List<Egreso> egresoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from egresos where tipo_egreso_id = ?");
ps.setInt(1, tipoEgreso.getId());
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 = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into egresos (nro, descripcion, valor, tipo_egreso_id, caja_id) values (?,?,?,?,?)");
ps.setString(1,egreso.getNro());
ps.setString(2,egreso.getDescripcion());
ps.setInt(3,egreso.getValor());
ps.setInt(4,egreso.getTipoEgreso().getId());
ps.setInt(5, egreso.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
egreso.setId(rs.getInt(1));
rs.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean updateEgreso(Egreso egreso) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("update egresos set nro = ?, descripcion = ?, valor = ?, tipo_egreso_id = ?, caja_id = ? where id = ? ");
ps.setString(1,egreso.getNro());
ps.setString(2,egreso.getDescripcion());
ps.setInt(3,egreso.getValor());
ps.setInt(4,egreso.getTipoEgreso().getId());
ps.setInt(5, egreso.getCaja().getId());
ps.setInt(6, 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 = connectionHolder.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(Caja caja) {
int total = 0;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select sum(valor) from egresos where caja_id = ?");
ps.setInt(1, caja.getId());
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()){
int tipoEgresoId = rs.getInt("tipo_egreso_id");
TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO();
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0);
int cajaId = rs.getInt("caja_id");
CajaDAO cajaDAO = new MysqlCajaDAO();
Caja caja = cajaDAO.findById(cajaId);
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.setTipoEgreso(tipoEgreso);
egreso.setCaja(caja);
egresoList.add(egreso);
}
return egresoList;
}
}

View File

@@ -24,7 +24,7 @@
package danielcortes.xyz.models.ingreso; package danielcortes.xyz.models.ingreso;
import danielcortes.xyz.data.MysqlConnection; import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO; import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO; import danielcortes.xyz.models.caja.MysqlCajaDAO;
@@ -40,10 +40,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MysqlIngresoDAO implements IngresoDAO{ public class MysqlIngresoDAO implements IngresoDAO{
private MysqlConnection mysqlConnection; private MysqlConnectionHolder mysqlConnection;
public MysqlIngresoDAO(){ public MysqlIngresoDAO(){
this.mysqlConnection = new MysqlConnection(); this.mysqlConnection = new MysqlConnectionHolder();
} }
@Override @Override

View File

@@ -0,0 +1,244 @@
/*
* MIT License
*
* Copyright (c) 2018 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.ingreso;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO;
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
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 SQLiteIngresoDAO implements IngresoDAO{
private ConnectionHolder connectionHolder;
public SQLiteIngresoDAO(){
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public List<Ingreso> findAll() {
List<Ingreso> ingresosList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from ingresos");
ResultSet rs = ps.executeQuery();
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return ingresosList;
}
@Override
public List<Ingreso> findByCaja(Caja caja) {
List<Ingreso> ingresosList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from ingresos where caja_id = ?");
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return ingresosList;
}
@Override
public List<Ingreso> findById(int id) {
List<Ingreso> ingresosList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from ingresos where id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return ingresosList;
}
@Override
public List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso) {
List<Ingreso> ingresosList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select ingresos.* from ingresos inner join tipos_ingreso on (ingresos.tipo_ingreso_id = tipos_ingreso.id) where ingresos.tipo_ingreso_id = ?");
ps.setInt(1, tipoIngreso.getId());
ResultSet rs = ps.executeQuery();
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return ingresosList;
}
@Override
public boolean insertIngreso(Ingreso ingreso) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into ingresos (valor, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?)");
ps.setInt(1, ingreso.getValor());
ps.setString(2, ingreso.getNroInicial());
ps.setString(3, ingreso.getNroFinal());
ps.setInt(4, ingreso.getTipoIngreso().getId());
ps.setInt(5, ingreso.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
ingreso.setId(rs.getInt(1));
rs.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean updateIngreso(Ingreso ingreso) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("update ingresos set valor = ? , nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?");
ps.setInt(1,ingreso.getValor());
ps.setString(2, ingreso.getNroInicial());
ps.setString(3, ingreso.getNroFinal());
ps.setInt(4, ingreso.getTipoIngreso().getId());
ps.setInt(5, ingreso.getCaja().getId());
ps.setInt(6, ingreso.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean deleteIngreso(Ingreso ingreso) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("delete from ingresos where id = ?");
ps.setInt(1,ingreso.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public int getTotalIngreso(Caja caja) {
int total = 0;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select sum(valor) from ingresos where caja_id = ?");
ps.setInt(1, caja.getId());
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<Ingreso> ingresosFromResultSet(ResultSet rs) throws SQLException {
ArrayList<Ingreso> ingresosList = new ArrayList<>();
while(rs.next()){
int tipoIngresoId = rs.getInt("tipo_ingreso_id");
TipoIngresoDAO tipoEgresoDAO = new MysqlTipoIngresoDAO();
TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0);
int cajaId = rs.getInt("caja_id");
CajaDAO cajaDAO = new MysqlCajaDAO();
Caja caja = cajaDAO.findById(cajaId);
Ingreso ingreso = new Ingreso();
ingreso.setId(rs.getInt("id"));
ingreso.setValor(rs.getInt("valor"));
ingreso.setNroInicial(rs.getString("nro_inicial"));
ingreso.setNroFinal(rs.getString("nro_final"));
ingreso.setTipoIngreso(tipoIngreso);
ingreso.setCaja(caja);
ingresosList.add(ingreso);
}
return ingresosList;
}
}

View File

@@ -24,7 +24,7 @@
package danielcortes.xyz.models.tipo_egreso; package danielcortes.xyz.models.tipo_egreso;
import danielcortes.xyz.data.MysqlConnection; import danielcortes.xyz.data.MysqlConnectionHolder;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@@ -34,10 +34,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MysqlTipoEgresoDAO implements TipoEgresoDAO { public class MysqlTipoEgresoDAO implements TipoEgresoDAO {
private MysqlConnection mysqlConnection; private MysqlConnectionHolder mysqlConnection;
public MysqlTipoEgresoDAO(){ public MysqlTipoEgresoDAO(){
this.mysqlConnection = new MysqlConnection(); this.mysqlConnection = new MysqlConnectionHolder();
} }
@Override @Override

View File

@@ -0,0 +1,128 @@
/*
* MIT License
*
* Copyright (c) 2018 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.tipo_egreso;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
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 SQLiteTipoEgresoDAO implements TipoEgresoDAO{
private ConnectionHolder connectionHolder;
public SQLiteTipoEgresoDAO(){
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public List<TipoEgreso> findAll() {
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
try {
Connection conn = connectionHolder.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 = connectionHolder.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 = connectionHolder.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;
}
}

View File

@@ -24,7 +24,7 @@
package danielcortes.xyz.models.tipo_ingreso; package danielcortes.xyz.models.tipo_ingreso;
import danielcortes.xyz.data.MysqlConnection; import danielcortes.xyz.data.MysqlConnectionHolder;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@@ -34,10 +34,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MysqlTipoIngresoDAO implements TipoIngresoDAO{ public class MysqlTipoIngresoDAO implements TipoIngresoDAO{
private MysqlConnection mysqlConnection; private MysqlConnectionHolder mysqlConnection;
public MysqlTipoIngresoDAO(){ public MysqlTipoIngresoDAO(){
this.mysqlConnection = new MysqlConnection(); this.mysqlConnection = new MysqlConnectionHolder();
} }
@Override @Override

View File

@@ -0,0 +1,128 @@
/*
* MIT License
*
* Copyright (c) 2018 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.tipo_ingreso;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
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 SQLiteTipoIngresoDAO implements TipoIngresoDAO{
private ConnectionHolder connectionHolder;
public SQLiteTipoIngresoDAO(){
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public List<TipoIngreso> findAll() {
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso");
ResultSet rs = ps.executeQuery();
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return tiposIngresoList;
}
@Override
public List<TipoIngreso> findById(int id) {
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where id = ?");
ps.setInt(1,id);
ResultSet rs = ps.executeQuery();
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return tiposIngresoList;
}
@Override
public List<TipoIngreso> findByNombre(String nombre) {
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where nombre = ?");
ps.setString(1,nombre);
ResultSet rs = ps.executeQuery();
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return tiposIngresoList;
}
@Override
public boolean insertTipoIngreso(TipoIngreso tipoEgreso) {
return false;
}
@Override
public boolean updateTipoIngreso(TipoIngreso tipoEgreso) {
return false;
}
@Override
public boolean deleteTipoIngreso(TipoIngreso tipoEgreso) {
return false;
}
private List<TipoIngreso> tiposIngresoFromResultSet(ResultSet rs) throws SQLException {
ArrayList<TipoIngreso> tiposIngresoList = new ArrayList<>();
while(rs.next()){
TipoIngreso tipoIngreso = new TipoIngreso();
tipoIngreso.setId(rs.getInt("id"));
tipoIngreso.setNombre(rs.getString("nombre"));
tiposIngresoList.add(tipoIngreso);
}
return tiposIngresoList;
}
}

View File

@@ -273,14 +273,14 @@ public class ArqueoView {
ingresosField.setText("0"); ingresosField.setText("0");
panel2.add(ingresosField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); panel2.add(ingresosField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
final JLabel label7 = new JLabel(); final JLabel label7 = new JLabel();
label7.setText("Debe Rendir"); label7.setText("Rendido");
panel2.add(label7, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel2.add(label7, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
arqueoField = new JTextField(); arqueoField = new JTextField();
arqueoField.setEditable(false); arqueoField.setEditable(false);
Font arqueoFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, arqueoField.getFont()); Font arqueoFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, arqueoField.getFont());
if (arqueoFieldFont != null) arqueoField.setFont(arqueoFieldFont); if (arqueoFieldFont != null) arqueoField.setFont(arqueoFieldFont);
arqueoField.setText("0"); arqueoField.setText("0");
panel2.add(arqueoField, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); panel2.add(arqueoField, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
ajusteField = new JTextField(); ajusteField = new JTextField();
ajusteField.setEditable(false); ajusteField.setEditable(false);
Font ajusteFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, ajusteField.getFont()); Font ajusteFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, ajusteField.getFont());
@@ -293,13 +293,13 @@ public class ArqueoView {
final JSeparator separator1 = new JSeparator(); final JSeparator separator1 = new JSeparator();
panel2.add(separator1, new GridConstraints(4, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); panel2.add(separator1, new GridConstraints(4, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
final JLabel label9 = new JLabel(); final JLabel label9 = new JLabel();
label9.setText("Rendido"); label9.setText("Debe Rendir");
panel2.add(label9, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel2.add(label9, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
rendidoField = new JTextField(); rendidoField = new JTextField();
Font rendidoFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, rendidoField.getFont()); Font rendidoFieldFont = this.$$$getFont$$$(null, Font.BOLD, -1, rendidoField.getFont());
if (rendidoFieldFont != null) rendidoField.setFont(rendidoFieldFont); if (rendidoFieldFont != null) rendidoField.setFont(rendidoFieldFont);
rendidoField.setText("0"); rendidoField.setText("0");
panel2.add(rendidoField, new GridConstraints(6, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); panel2.add(rendidoField, new GridConstraints(5, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
final JPanel panel3 = new JPanel(); final JPanel panel3 = new JPanel();
panel3.setLayout(new GridLayoutManager(19, 2, new Insets(10, 10, 10, 10), -1, -1)); panel3.setLayout(new GridLayoutManager(19, 2, new Insets(10, 10, 10, 10), -1, -1));
contentPanel.add(panel3, new GridConstraints(0, 0, 3, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); contentPanel.add(panel3, new GridConstraints(0, 0, 3, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));