Separando un poco las clases de los modelos
This commit is contained in:
@@ -38,7 +38,7 @@ public class Properties {
|
||||
private Properties() {
|
||||
try {
|
||||
this.props = new java.util.Properties();
|
||||
FileInputStream in = new FileInputStream("conf");
|
||||
FileInputStream in = new FileInputStream("conf.properties");
|
||||
this.props.load(in);
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -24,13 +24,32 @@
|
||||
|
||||
package danielcortes.xyz.models.caja;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface CajaDAO {
|
||||
List<Caja> findAll();
|
||||
Caja findById(int id);
|
||||
Caja findByFecha(LocalDate fecha);
|
||||
boolean insertCaja(Caja caja);
|
||||
boolean updateCaja(Caja caja);
|
||||
public abstract class CajaDAO {
|
||||
protected ConnectionHolder connectionHolder;
|
||||
|
||||
public abstract List<Caja> findAll();
|
||||
public abstract Caja findById(int id);
|
||||
public abstract Caja findByFecha(LocalDate fecha);
|
||||
public abstract boolean insertCaja(Caja caja);
|
||||
public abstract boolean updateCaja(Caja caja);
|
||||
|
||||
protected 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(LocalDate.parse(rs.getString("fecha")));
|
||||
cajaList.add(caja);
|
||||
}
|
||||
return cajaList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,18 +31,17 @@ import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlCajaDAO implements CajaDAO {
|
||||
private MysqlConnectionHolder mysqlConnection;
|
||||
public class MysqlCajaDAO extends CajaDAO {
|
||||
|
||||
public MysqlCajaDAO() {
|
||||
this.mysqlConnection = new MysqlConnectionHolder();
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Caja> findAll() {
|
||||
List<Caja> cajaList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -61,7 +60,7 @@ public class MysqlCajaDAO implements CajaDAO {
|
||||
public Caja findById(int id) {
|
||||
Caja caja = null;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja where id = ?");
|
||||
|
||||
ps.setInt(1, id);
|
||||
@@ -83,7 +82,7 @@ public class MysqlCajaDAO implements CajaDAO {
|
||||
public Caja findByFecha(LocalDate fecha) {
|
||||
Caja caja = null;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?");
|
||||
|
||||
ps.setObject(1, fecha);
|
||||
@@ -92,7 +91,7 @@ public class MysqlCajaDAO implements CajaDAO {
|
||||
|
||||
List<Caja> cajaList = this.cajasFromResultSet(rs);
|
||||
|
||||
if(cajaList.size() > 0){
|
||||
if (cajaList.size() > 0) {
|
||||
caja = cajaList.get(0);
|
||||
}
|
||||
|
||||
@@ -109,7 +108,7 @@ public class MysqlCajaDAO implements CajaDAO {
|
||||
public boolean insertCaja(Caja caja) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)");
|
||||
ps.setObject(1, caja.getFecha());
|
||||
|
||||
@@ -135,7 +134,7 @@ public class MysqlCajaDAO implements CajaDAO {
|
||||
public boolean updateCaja(Caja caja) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?");
|
||||
ps.setObject(1, caja.getFecha());
|
||||
ps.setInt(2, caja.getId());
|
||||
@@ -150,15 +149,4 @@ public class MysqlCajaDAO implements CajaDAO {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,17 +30,12 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteCajaDAO implements CajaDAO {
|
||||
private SQLiteConnectionHolder connectionHolder;
|
||||
|
||||
public SQLiteCajaDAO() {
|
||||
public class SQLiteCajaDAO extends CajaDAO {
|
||||
public SQLiteCajaDAO () {
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
|
||||
@@ -157,16 +152,4 @@ public class SQLiteCajaDAO implements CajaDAO {
|
||||
}
|
||||
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(LocalDate.parse(rs.getString("fecha")));
|
||||
cajaList.add(caja);
|
||||
}
|
||||
return cajaList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,43 @@
|
||||
|
||||
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.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface DocumentosDAO {
|
||||
List<Documentos> findAll();
|
||||
Documentos findById(int id);
|
||||
Documentos findByCaja(Caja caja);
|
||||
public abstract class DocumentosDAO {
|
||||
protected ConnectionHolder connectionHolder;
|
||||
|
||||
boolean insertDocumentos(Documentos documentos);
|
||||
boolean insertDefaultDocumentos(Documentos documentos);
|
||||
boolean updateDocumentos(Documentos documentos);
|
||||
boolean deleteDocumentos(Documentos documentos);
|
||||
public abstract List<Documentos> findAll();
|
||||
public abstract Documentos findById(int id);
|
||||
public abstract Documentos findByCaja(Caja caja);
|
||||
|
||||
public abstract boolean insertDocumentos(Documentos documentos);
|
||||
public abstract boolean insertDefaultDocumentos(Documentos documentos);
|
||||
public abstract boolean updateDocumentos(Documentos documentos);
|
||||
public abstract boolean deleteDocumentos(Documentos documentos);
|
||||
|
||||
protected 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,18 +36,17 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
private MysqlConnectionHolder mysqlConnection;
|
||||
public class MysqlDocumentosDAO extends DocumentosDAO {
|
||||
|
||||
public MysqlDocumentosDAO() {
|
||||
this.mysqlConnection = new MysqlConnectionHolder();
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Documentos> findAll() {
|
||||
List<Documentos> documentosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from documentos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -66,7 +65,7 @@ public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
public Documentos findById(int id) {
|
||||
Documentos documentos = null;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from documentos where id = ?");
|
||||
ps.setInt(1, id);
|
||||
|
||||
@@ -90,7 +89,7 @@ public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
public Documentos findByCaja(Caja caja) {
|
||||
Documentos documentos = null;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from documentos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
|
||||
@@ -114,7 +113,7 @@ public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
public boolean insertDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -142,7 +141,7 @@ public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
public boolean insertDefaultDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, caja_id) values (0,0,?)");
|
||||
ps.setInt(1, documentos.getCaja().getId());
|
||||
|
||||
@@ -168,7 +167,7 @@ public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
public boolean updateDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -189,7 +188,7 @@ public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
public boolean deleteDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from documentos where id = ?");
|
||||
ps.setInt(1, documentos.getId());
|
||||
|
||||
@@ -204,20 +203,4 @@ public class MysqlDocumentosDAO implements DocumentosDAO {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteDocumentosDAO implements DocumentosDAO{
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
public class SQLiteDocumentosDAO extends DocumentosDAO {
|
||||
public SQLiteDocumentosDAO() {
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
@@ -204,21 +202,4 @@ public class SQLiteDocumentosDAO implements DocumentosDAO{
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
private List<Documentos> documentosFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Documentos> documentosList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,50 @@
|
||||
|
||||
package danielcortes.xyz.models.efectivo;
|
||||
|
||||
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.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface EfectivoDAO {
|
||||
List<Efectivo> findAll();
|
||||
Efectivo findById(int id);
|
||||
Efectivo findByCaja(Caja caja);
|
||||
public abstract class EfectivoDAO {
|
||||
protected ConnectionHolder connectionHolder;
|
||||
|
||||
boolean insertEfectivo(Efectivo efectivo);
|
||||
boolean insertDefaultEfectivo(Efectivo efectivo);
|
||||
boolean updateEfectivo(Efectivo efectivo);
|
||||
boolean deleteEfectivo(Efectivo efectivo);
|
||||
public abstract List<Efectivo> findAll();
|
||||
public abstract Efectivo findById(int id);
|
||||
public abstract Efectivo findByCaja(Caja caja);
|
||||
|
||||
public abstract boolean insertEfectivo(Efectivo efectivo);
|
||||
public abstract boolean insertDefaultEfectivo(Efectivo efectivo);
|
||||
public abstract boolean updateEfectivo(Efectivo efectivo);
|
||||
public abstract boolean deleteEfectivo(Efectivo efectivo);
|
||||
|
||||
protected 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,18 +36,16 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
private MysqlConnectionHolder mysqlConnection;
|
||||
|
||||
public class MysqlEfectivoDAO extends EfectivoDAO {
|
||||
public MysqlEfectivoDAO() {
|
||||
this.mysqlConnection = new MysqlConnectionHolder();
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Efectivo> findAll() {
|
||||
List<Efectivo> efectivoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from efectivos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -67,7 +65,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
public Efectivo findById(int id) {
|
||||
Efectivo efectivo = null;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -88,7 +86,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
public Efectivo findByCaja(Caja caja) {
|
||||
Efectivo efectivo = null;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -112,7 +110,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
public boolean insertEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -147,7 +145,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
public boolean insertDefaultEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
|
||||
@@ -173,7 +171,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
public boolean updateEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -202,7 +200,7 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
public boolean deleteEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?");
|
||||
ps.setInt(1, efectivo.getId());
|
||||
|
||||
@@ -217,27 +215,4 @@ public class MysqlEfectivoDAO implements EfectivoDAO {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteEfectivoDAO implements EfectivoDAO{
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
public class SQLiteEfectivoDAO extends EfectivoDAO {
|
||||
public SQLiteEfectivoDAO() {
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
@@ -217,28 +215,4 @@ public class SQLiteEfectivoDAO implements EfectivoDAO{
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
private List<Efectivo> efectivosFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Efectivo> efectivoList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,23 +24,57 @@
|
||||
|
||||
package danielcortes.xyz.models.egreso;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.egreso.Egreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface EgresoDAO {
|
||||
List<Egreso> findAll();
|
||||
List<Egreso> findById(int id);
|
||||
List<Egreso> findByCaja(Caja caja);
|
||||
List<Egreso> findByNro(String nro);
|
||||
List<Egreso> findByTipoEgreso(TipoEgreso tipoEgreso);
|
||||
public abstract class EgresoDAO {
|
||||
protected ConnectionHolder connectionHolder;
|
||||
|
||||
boolean insertEgreso(Egreso egreso);
|
||||
boolean updateEgreso(Egreso egreso);
|
||||
boolean deleteEgreso(Egreso egreso);
|
||||
public abstract List<Egreso> findAll();
|
||||
public abstract List<Egreso> findById(int id);
|
||||
public abstract List<Egreso> findByCaja(Caja caja);
|
||||
public abstract List<Egreso> findByNro(String nro);
|
||||
public abstract List<Egreso> findByTipoEgreso(TipoEgreso tipoEgreso);
|
||||
|
||||
int getTotalEgreso(Caja caja);
|
||||
public abstract boolean insertEgreso(Egreso egreso);
|
||||
public abstract boolean updateEgreso(Egreso egreso);
|
||||
public abstract boolean deleteEgreso(Egreso egreso);
|
||||
|
||||
public abstract int getTotalEgreso(Caja caja);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,18 +39,17 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlEgresoDAO implements EgresoDAO {
|
||||
private MysqlConnectionHolder mysqlConnection;
|
||||
public class MysqlEgresoDAO extends EgresoDAO {
|
||||
|
||||
public MysqlEgresoDAO(){
|
||||
this.mysqlConnection = new MysqlConnectionHolder();
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Egreso> findAll() {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -69,7 +68,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public List<Egreso> findById(int id) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where id = ?");
|
||||
ps.setInt(1,id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -89,7 +88,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public List<Egreso> findByCaja(Caja caja) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -110,7 +109,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public List<Egreso> findByNro(String nro) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where nro = ?");
|
||||
ps.setString(1, nro);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -130,7 +129,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public List<Egreso> findByTipoEgreso(TipoEgreso tipoEgreso) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where tipo_egreso_id = ?");
|
||||
ps.setInt(1, tipoEgreso.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -150,7 +149,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public boolean insertEgreso(Egreso egreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -179,7 +178,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public boolean updateEgreso(Egreso egreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -203,7 +202,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public boolean deleteEgreso(Egreso egreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from egresos where id = ? ");
|
||||
ps.setInt(1, egreso.getId());
|
||||
|
||||
@@ -222,7 +221,7 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
public int getTotalEgreso(Caja caja) {
|
||||
int total = 0;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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();
|
||||
@@ -239,28 +238,4 @@ public class MysqlEgresoDAO implements EgresoDAO {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteEgresoDAO implements EgresoDAO{
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
public class SQLiteEgresoDAO extends EgresoDAO {
|
||||
public SQLiteEgresoDAO(){
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
@@ -238,30 +236,4 @@ public class SQLiteEgresoDAO implements EgresoDAO{
|
||||
}
|
||||
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 SQLiteTipoEgresoDAO();
|
||||
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0);
|
||||
|
||||
int cajaId = rs.getInt("caja_id");
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,18 +25,55 @@
|
||||
|
||||
package danielcortes.xyz.models.ingreso;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
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.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface IngresoDAO {
|
||||
List<Ingreso> findAll();
|
||||
List<Ingreso> findByCaja(Caja caja);
|
||||
List<Ingreso> findById(int id);
|
||||
List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso);
|
||||
boolean insertIngreso(Ingreso ingreso);
|
||||
boolean updateIngreso(Ingreso ingreso);
|
||||
boolean deleteIngreso(Ingreso ingreso);
|
||||
int getTotalIngreso(Caja caja);
|
||||
public abstract class IngresoDAO {
|
||||
protected ConnectionHolder connectionHolder;
|
||||
|
||||
public abstract List<Ingreso> findAll();
|
||||
public abstract List<Ingreso> findByCaja(Caja caja);
|
||||
public abstract List<Ingreso> findById(int id);
|
||||
public abstract List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso);
|
||||
|
||||
public abstract boolean insertIngreso(Ingreso ingreso);
|
||||
public abstract boolean updateIngreso(Ingreso ingreso);
|
||||
public abstract boolean deleteIngreso(Ingreso ingreso);
|
||||
|
||||
public abstract int getTotalIngreso(Caja caja);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,18 +39,17 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlIngresoDAO implements IngresoDAO{
|
||||
private MysqlConnectionHolder mysqlConnection;
|
||||
public class MysqlIngresoDAO extends IngresoDAO {
|
||||
|
||||
public MysqlIngresoDAO(){
|
||||
this.mysqlConnection = new MysqlConnectionHolder();
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findAll() {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -69,7 +68,7 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
public List<Ingreso> findByCaja(Caja caja) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -89,7 +88,7 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
public List<Ingreso> findById(int id) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos where id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -109,7 +108,7 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
public List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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();
|
||||
@@ -129,7 +128,7 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
public boolean insertIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -158,7 +157,7 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
public boolean updateIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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());
|
||||
@@ -182,7 +181,7 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
public boolean deleteIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from ingresos where id = ?");
|
||||
ps.setInt(1,ingreso.getId());
|
||||
updates = ps.executeUpdate();
|
||||
@@ -199,7 +198,7 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
public int getTotalIngreso(Caja caja) {
|
||||
int total = 0;
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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();
|
||||
@@ -216,28 +215,4 @@ public class MysqlIngresoDAO implements IngresoDAO{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteIngresoDAO implements IngresoDAO{
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
public class SQLiteIngresoDAO extends IngresoDAO {
|
||||
public SQLiteIngresoDAO(){
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
@@ -216,29 +214,4 @@ public class SQLiteIngresoDAO implements IngresoDAO{
|
||||
}
|
||||
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 SQLiteTipoIngresoDAO();
|
||||
TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0);
|
||||
|
||||
int cajaId = rs.getInt("caja_id");
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,22 +33,21 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlTipoEgresoDAO implements TipoEgresoDAO {
|
||||
private MysqlConnectionHolder mysqlConnection;
|
||||
public class MysqlTipoEgresoDAO extends TipoEgresoDAO {
|
||||
|
||||
public MysqlTipoEgresoDAO(){
|
||||
this.mysqlConnection = new MysqlConnectionHolder();
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoEgreso> findAll() {
|
||||
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tipoEgresoList = this.TipoEgresoFromResultSet(rs);
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -59,17 +58,16 @@ public class MysqlTipoEgresoDAO implements TipoEgresoDAO {
|
||||
return tipoEgresoList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<TipoEgreso> findById(int id) {
|
||||
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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);
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -84,12 +82,12 @@ public class MysqlTipoEgresoDAO implements TipoEgresoDAO {
|
||||
public List<TipoEgreso> findByNombre(String nombre) {
|
||||
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
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);
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -114,15 +112,4 @@ public class MysqlTipoEgresoDAO implements TipoEgresoDAO {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteTipoEgresoDAO implements TipoEgresoDAO{
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
public class SQLiteTipoEgresoDAO extends TipoEgresoDAO {
|
||||
public SQLiteTipoEgresoDAO(){
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
@@ -49,7 +47,7 @@ public class SQLiteTipoEgresoDAO implements TipoEgresoDAO{
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tipoEgresoList = this.TipoEgresoFromResultSet(rs);
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -69,7 +67,7 @@ public class SQLiteTipoEgresoDAO implements TipoEgresoDAO{
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tipoEgresoList = this.TipoEgresoFromResultSet(rs);
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -89,7 +87,7 @@ public class SQLiteTipoEgresoDAO implements TipoEgresoDAO{
|
||||
ps.setString(1, nombre);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tipoEgresoList = this.TipoEgresoFromResultSet(rs);
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -115,14 +113,4 @@ public class SQLiteTipoEgresoDAO implements TipoEgresoDAO{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,13 +48,32 @@
|
||||
|
||||
package danielcortes.xyz.models.tipo_egreso;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
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);
|
||||
public abstract class TipoEgresoDAO {
|
||||
protected ConnectionHolder connectionHolder;
|
||||
|
||||
public abstract List<TipoEgreso> findAll();
|
||||
public abstract List<TipoEgreso> findById(int id);
|
||||
public abstract List<TipoEgreso> findByNombre(String nombre);
|
||||
|
||||
public abstract boolean insertTipoEgreso(TipoEgreso tipoEgreso);
|
||||
public abstract boolean updateTipoEgreso(TipoEgreso tipoEgreso);
|
||||
public abstract boolean deleteTipoEgreso(TipoEgreso tipoEgreso);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,18 +33,16 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlTipoIngresoDAO implements TipoIngresoDAO{
|
||||
private MysqlConnectionHolder mysqlConnection;
|
||||
|
||||
public class MysqlTipoIngresoDAO extends TipoIngresoDAO {
|
||||
public MysqlTipoIngresoDAO(){
|
||||
this.mysqlConnection = new MysqlConnectionHolder();
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoIngreso> findAll() {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -63,7 +61,7 @@ public class MysqlTipoIngresoDAO implements TipoIngresoDAO{
|
||||
public List<TipoIngreso> findById(int id) {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where id = ?");
|
||||
ps.setInt(1,id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -83,7 +81,7 @@ public class MysqlTipoIngresoDAO implements TipoIngresoDAO{
|
||||
public List<TipoIngreso> findByNombre(String nombre) {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = mysqlConnection.getConnection();
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where nombre = ?");
|
||||
ps.setString(1,nombre);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
@@ -113,16 +111,4 @@ public class MysqlTipoIngresoDAO implements TipoIngresoDAO{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteTipoIngresoDAO implements TipoIngresoDAO{
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
public class SQLiteTipoIngresoDAO extends TipoIngresoDAO {
|
||||
public SQLiteTipoIngresoDAO(){
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
@@ -115,14 +113,4 @@ public class SQLiteTipoIngresoDAO implements TipoIngresoDAO{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,31 @@
|
||||
|
||||
package danielcortes.xyz.models.tipo_ingreso;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface TipoIngresoDAO {
|
||||
List<TipoIngreso> findAll();
|
||||
List<TipoIngreso> findById(int id);
|
||||
List<TipoIngreso> findByNombre(String nombre);
|
||||
boolean insertTipoIngreso(TipoIngreso tipoEgreso);
|
||||
boolean updateTipoIngreso(TipoIngreso tipoEgreso);
|
||||
boolean deleteTipoIngreso(TipoIngreso tipoEgreso);
|
||||
public abstract class TipoIngresoDAO {
|
||||
protected ConnectionHolder connectionHolder;
|
||||
public abstract List<TipoIngreso> findAll();
|
||||
public abstract List<TipoIngreso> findById(int id);
|
||||
public abstract List<TipoIngreso> findByNombre(String nombre);
|
||||
|
||||
public abstract boolean insertTipoIngreso(TipoIngreso tipoEgreso);
|
||||
public abstract boolean updateTipoIngreso(TipoIngreso tipoEgreso);
|
||||
public abstract boolean deleteTipoIngreso(TipoIngreso tipoEgreso);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user