diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 8acaae7..00909e7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -10,12 +10,26 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -59,17 +73,7 @@
-
-
-
-
-
-
-
-
-
-
-
+
@@ -274,7 +283,7 @@
-
+
@@ -328,7 +337,7 @@
-
+
@@ -527,14 +536,8 @@
-
-
-
- 1545961761749
-
-
-
- 1545961761749
+
+
1545972598937
@@ -872,16 +875,17 @@
1547936758813
-
+
+ 1547938456336
+
+
+
+ 1547938456336
+
+
-
-
-
-
-
-
@@ -906,9 +910,15 @@
+
+
+
+
+
+
-
+
@@ -921,9 +931,8 @@
-
-
+
@@ -931,7 +940,7 @@
-
+
@@ -942,7 +951,7 @@
-
+
@@ -958,7 +967,7 @@
-
+
@@ -966,18 +975,18 @@
-
-
+
+
-
-
+
+
-
+
@@ -1049,7 +1058,6 @@
-
@@ -1074,395 +1082,14 @@
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1477,44 +1104,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1663,16 +1252,7 @@
-
-
-
-
-
-
-
-
-
-
+
@@ -1693,13 +1273,7 @@
-
-
-
-
-
-
-
+
@@ -1779,8 +1353,279 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dist/Programa Caja.jar b/dist/Programa Caja.jar
index 7519279..2419e7a 100644
Binary files a/dist/Programa Caja.jar and b/dist/Programa Caja.jar differ
diff --git a/dist/conf.properties b/dist/conf.properties
index 7d09ff9..719e6ec 100644
--- a/dist/conf.properties
+++ b/dist/conf.properties
@@ -3,17 +3,12 @@
# 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
+# los valores soportados son:
# - 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
+# por ahora soporte solo a sqlite asi que debe ser la uri correspondiente
-#database_uri = jdbc:mysql://localhost/caja?user=root&password=lagging&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
database_uri = jdbc:sqlite:rodriguez.dat
diff --git a/src/danielcortes/xyz/Main.java b/src/danielcortes/xyz/Main.java
index 6fe5ab6..f853018 100644
--- a/src/danielcortes/xyz/Main.java
+++ b/src/danielcortes/xyz/Main.java
@@ -25,29 +25,23 @@
package danielcortes.xyz;
import danielcortes.xyz.controllers.ManagerController;
-import danielcortes.xyz.data.Properties;
+import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.models.caja.CajaDAO;
-import danielcortes.xyz.models.caja.MysqlCajaDAO;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
import danielcortes.xyz.models.documentos.DocumentosDAO;
-import danielcortes.xyz.models.documentos.MysqlDocumentosDAO;
import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO;
import danielcortes.xyz.models.efectivo.EfectivoDAO;
-import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
-import danielcortes.xyz.models.egreso.MysqlEgresoDAO;
import danielcortes.xyz.models.egreso.SQLiteEgresoDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
-import danielcortes.xyz.models.ingreso.MysqlIngresoDAO;
import danielcortes.xyz.models.ingreso.SQLiteIngresoDAO;
-import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
-import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import danielcortes.xyz.views.ManagerView;
+
import javax.swing.*;
import java.util.Locale;
@@ -61,7 +55,7 @@ public class Main {
System.setProperty("swing.aatext", "true");
try {
- UIManager.setLookAndFeel(Properties.getInstance().getProperty("look_and_feel"));
+ UIManager.setLookAndFeel(Configuration.get("look_and_feel"));
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
@@ -69,36 +63,18 @@ public class Main {
Locale.setDefault(new Locale("es"));
- CajaDAO cajaDAO = null;
- DocumentosDAO documentosDAO = null;
- EfectivoDAO efectivoDAO = null;
- EgresoDAO egresoDAO = null;
- IngresoDAO ingresoDAO = null;
- TipoEgresoDAO tipoEgresoDAO = null;
- TipoIngresoDAO tipoIngresoDAO = null;
-
- if (Properties.getInstance().getProperty("database_type").equals("mysql")) {
- cajaDAO = new MysqlCajaDAO();
- documentosDAO = new MysqlDocumentosDAO();
- efectivoDAO = new MysqlEfectivoDAO();
- egresoDAO = new MysqlEgresoDAO();
- ingresoDAO = new MysqlIngresoDAO();
- tipoEgresoDAO = new MysqlTipoEgresoDAO();
- tipoIngresoDAO = new MysqlTipoIngresoDAO();
- } else if (Properties.getInstance().getProperty("database_type").equals("sqlite")) {
- cajaDAO = new SQLiteCajaDAO();
- documentosDAO = new SQLiteDocumentosDAO();
- efectivoDAO = new SQLiteEfectivoDAO();
- egresoDAO = new SQLiteEgresoDAO();
- ingresoDAO = new SQLiteIngresoDAO();
- tipoEgresoDAO = new SQLiteTipoEgresoDAO();
- tipoIngresoDAO = new SQLiteTipoIngresoDAO();
- }
+ CajaDAO cajaDAO = new SQLiteCajaDAO();
+ DocumentosDAO documentosDAO = new SQLiteDocumentosDAO();
+ EfectivoDAO efectivoDAO = new SQLiteEfectivoDAO();
+ EgresoDAO egresoDAO = new SQLiteEgresoDAO();
+ IngresoDAO ingresoDAO = new SQLiteIngresoDAO();
+ TipoEgresoDAO tipoEgresoDAO = new SQLiteTipoEgresoDAO();
+ TipoIngresoDAO tipoIngresoDAO = new SQLiteTipoIngresoDAO();
ManagerView view = new ManagerView();
ManagerController managerController = new ManagerController(view, cajaDAO, documentosDAO, efectivoDAO, egresoDAO, ingresoDAO, tipoEgresoDAO, tipoIngresoDAO);
- JFrame frame = new JFrame("Caja: " + Properties.getInstance().getProperty("nombre_caja"));
+ JFrame frame = new JFrame("Caja: " + Configuration.get("nombre_caja"));
frame.setContentPane(view.getContentPanel());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
diff --git a/src/danielcortes/xyz/controllers/CalcularFondoController.java b/src/danielcortes/xyz/controllers/CalcularFondoController.java
index 12ecc3d..7ced179 100644
--- a/src/danielcortes/xyz/controllers/CalcularFondoController.java
+++ b/src/danielcortes/xyz/controllers/CalcularFondoController.java
@@ -1,7 +1,7 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.controllers.actions.NextAction;
-import danielcortes.xyz.data.Properties;
+import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.calculo_fondo.CalculoFondo;
import danielcortes.xyz.models.calculo_fondo.CalculoFondoDAO;
@@ -37,7 +37,7 @@ public class CalcularFondoController {
}
private void showView() {
- JFrame frame = new JFrame("Calculo de Fondo: " + Properties.getInstance().getProperty("nombre_caja"));
+ JFrame frame = new JFrame("Calculo de Fondo: " + Configuration.get("nombre_caja"));
frame.setContentPane(view.getContentPanel());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
diff --git a/src/danielcortes/xyz/controllers/ManagerController.java b/src/danielcortes/xyz/controllers/ManagerController.java
index 0f2dd35..9da0372 100644
--- a/src/danielcortes/xyz/controllers/ManagerController.java
+++ b/src/danielcortes/xyz/controllers/ManagerController.java
@@ -28,22 +28,14 @@ import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.documentos.Documentos;
import danielcortes.xyz.models.documentos.DocumentosDAO;
-import danielcortes.xyz.models.documentos.MysqlDocumentosDAO;
import danielcortes.xyz.models.efectivo.Efectivo;
import danielcortes.xyz.models.efectivo.EfectivoDAO;
-import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
-import danielcortes.xyz.models.ingreso.MysqlIngresoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
-import danielcortes.xyz.models.egreso.MysqlEgresoDAO;
-import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
-import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
-import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import danielcortes.xyz.views.*;
-import javax.swing.*;
import java.awt.*;
import java.time.LocalDate;
diff --git a/src/danielcortes/xyz/data/Properties.java b/src/danielcortes/xyz/data/Configuration.java
similarity index 78%
rename from src/danielcortes/xyz/data/Properties.java
rename to src/danielcortes/xyz/data/Configuration.java
index 492a5ed..d36e2d1 100644
--- a/src/danielcortes/xyz/data/Properties.java
+++ b/src/danielcortes/xyz/data/Configuration.java
@@ -26,27 +26,26 @@ package danielcortes.xyz.data;
import java.io.FileInputStream;
import java.io.IOException;
+import java.util.Properties;
-public class Properties {
- private static Properties ourInstance = new Properties();
- public static java.util.Properties getInstance() {
- return ourInstance.props;
- }
+public class Configuration {
+ private static final Properties config;
- private java.util.Properties props;
+ static {
+ config = new Properties();
- private Properties() {
try {
- this.props = new java.util.Properties();
FileInputStream in = new FileInputStream("conf.properties");
- this.props.load(in);
+ config.load(in);
in.close();
} catch (IOException e) {
- System.err.println("Couldn't load properties");
+ System.err.println("Couldn't load properties! The application will close");
+
e.printStackTrace();
}
}
-
-
+ public static String get(String key){
+ return config.getProperty(key);
+ }
}
diff --git a/src/danielcortes/xyz/data/MysqlConnectionHolder.java b/src/danielcortes/xyz/data/MysqlConnectionHolder.java
deleted file mode 100644
index bf5352c..0000000
--- a/src/danielcortes/xyz/data/MysqlConnectionHolder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.data;
-
-import java.sql.*;
-
-public class MysqlConnectionHolder implements ConnectionHolder {
- private String databaseURI;
- public MysqlConnectionHolder(){
- this.databaseURI = Properties.getInstance().getProperty("database_uri");
- }
-
- public java.sql.Connection getConnection() throws SQLException{
- return DriverManager.getConnection(databaseURI);
- }
-}
diff --git a/src/danielcortes/xyz/data/SQLiteConnectionHolder.java b/src/danielcortes/xyz/data/SQLiteConnectionHolder.java
index f2e6d1f..0271245 100644
--- a/src/danielcortes/xyz/data/SQLiteConnectionHolder.java
+++ b/src/danielcortes/xyz/data/SQLiteConnectionHolder.java
@@ -24,17 +24,19 @@
package danielcortes.xyz.data;
+import java.sql.Connection;
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");
+
+ public SQLiteConnectionHolder() {
+ this.databaseURI = Configuration.get("database_uri");
}
@Override
- public java.sql.Connection getConnection() throws SQLException{
+ public Connection getConnection() throws SQLException {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
diff --git a/src/danielcortes/xyz/models/caja/MysqlCajaDAO.java b/src/danielcortes/xyz/models/caja/MysqlCajaDAO.java
deleted file mode 100644
index b3cf673..0000000
--- a/src/danielcortes/xyz/models/caja/MysqlCajaDAO.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.models.caja;
-
-import danielcortes.xyz.data.MysqlConnectionHolder;
-import danielcortes.xyz.models.documentos.Documentos;
-import danielcortes.xyz.models.documentos.DocumentosDAO;
-import danielcortes.xyz.models.documentos.MysqlDocumentosDAO;
-import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO;
-import danielcortes.xyz.models.efectivo.Efectivo;
-import danielcortes.xyz.models.efectivo.EfectivoDAO;
-import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
-import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
-
-import java.sql.*;
-import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.List;
-
-public class MysqlCajaDAO extends CajaDAO {
-
- public MysqlCajaDAO() {
- this.connectionHolder = new MysqlConnectionHolder();
- }
-
- @Override
- public List findAll() {
- List 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 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_id()");
- 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;
- }
-
- @Override
- public void createCajasForMonth(LocalDate month) {
- LocalDate date = month.withDayOfMonth(1);
- LocalDate endDate = date.withDayOfMonth(date.lengthOfMonth());
-
- while(date.isBefore(endDate)) {
- if(this.findByFecha(date) != null){
- date = date.plusDays(1);
- continue;
- }
-
- Caja caja = new Caja();
- caja.setFecha(date);
- this.insertCaja(caja);
-
- Efectivo efectivo = new Efectivo();
- EfectivoDAO efectivoDAO = new MysqlEfectivoDAO();
- efectivo.setCaja(caja);
- efectivoDAO.insertDefaultEfectivo(efectivo);
-
- Documentos documentos = new Documentos();
- DocumentosDAO documentosDAO = new MysqlDocumentosDAO();
- documentos.setCaja(caja);
- documentosDAO.insertDefaultDocumentos(documentos);
-
- date = date.plusDays(1);
- }
-
- }
-}
diff --git a/src/danielcortes/xyz/models/documentos/DocumentosDAO.java b/src/danielcortes/xyz/models/documentos/DocumentosDAO.java
index ebcc0b4..cbb20cc 100644
--- a/src/danielcortes/xyz/models/documentos/DocumentosDAO.java
+++ b/src/danielcortes/xyz/models/documentos/DocumentosDAO.java
@@ -25,10 +25,9 @@
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 danielcortes.xyz.models.caja.SQLiteCajaDAO;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -52,7 +51,7 @@ public abstract class DocumentosDAO {
protected List documentosFromResultSet(ResultSet rs) throws SQLException {
List documentosList = new ArrayList<>();
while (rs.next()) {
- CajaDAO cajaDAO = new MysqlCajaDAO();
+ CajaDAO cajaDAO = new SQLiteCajaDAO();
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
Documentos documentos = new Documentos();
diff --git a/src/danielcortes/xyz/models/documentos/MysqlDocumentosDAO.java b/src/danielcortes/xyz/models/documentos/MysqlDocumentosDAO.java
deleted file mode 100644
index 3968a46..0000000
--- a/src/danielcortes/xyz/models/documentos/MysqlDocumentosDAO.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.models.documentos;
-
-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 MysqlDocumentosDAO extends DocumentosDAO {
-
- public MysqlDocumentosDAO() {
- this.connectionHolder = new MysqlConnectionHolder();
- }
-
- @Override
- public List findAll() {
- List 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 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 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_id()");
- 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_id()");
- 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;
- }
-
- @Override
- public int getTotalDocumentos(Caja caja) {
- int total = 0;
- try {
- Connection conn = connectionHolder.getConnection();
- PreparedStatement ps = conn.prepareStatement("select cheques + tarjetas from documentos 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;
- }
-}
diff --git a/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java b/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java
index 2387c93..21abb7d 100644
--- a/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java
+++ b/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java
@@ -25,10 +25,9 @@
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 danielcortes.xyz.models.caja.SQLiteCajaDAO;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -52,7 +51,7 @@ public abstract class EfectivoDAO {
protected List efectivosFromResultSet(ResultSet rs) throws SQLException {
List efectivoList = new ArrayList<>();
while (rs.next()) {
- CajaDAO cajaDAO = new MysqlCajaDAO();
+ CajaDAO cajaDAO = new SQLiteCajaDAO();
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
Efectivo efectivo = new Efectivo();
diff --git a/src/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java b/src/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java
deleted file mode 100644
index 1ca8fe2..0000000
--- a/src/danielcortes/xyz/models/efectivo/MysqlEfectivoDAO.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.models.efectivo;
-
-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 MysqlEfectivoDAO extends EfectivoDAO {
- public MysqlEfectivoDAO() {
- this.connectionHolder = new MysqlConnectionHolder();
- }
-
- @Override
- public List findAll() {
- List 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 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_id()");
- 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_id()");
- 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;
- }
-
- @Override
- public int getTotalEfectivo(Caja caja) {
- int total = 0;
- try {
- Connection conn = connectionHolder.getConnection();
- PreparedStatement ps = conn.prepareStatement("select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos 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;
- }
-}
diff --git a/src/danielcortes/xyz/models/egreso/EgresoDAO.java b/src/danielcortes/xyz/models/egreso/EgresoDAO.java
index 04607f8..21141e8 100644
--- a/src/danielcortes/xyz/models/egreso/EgresoDAO.java
+++ b/src/danielcortes/xyz/models/egreso/EgresoDAO.java
@@ -27,9 +27,8 @@ 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.caja.SQLiteCajaDAO;
+import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
@@ -57,11 +56,11 @@ public abstract class EgresoDAO {
ArrayList egresoList = new ArrayList<>();
while(rs.next()){
int tipoEgresoId = rs.getInt("tipo_egreso_id");
- TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO();
+ TipoEgresoDAO tipoEgresoDAO = new SQLiteTipoEgresoDAO();
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0);
int cajaId = rs.getInt("caja_id");
- CajaDAO cajaDAO = new MysqlCajaDAO();
+ CajaDAO cajaDAO = new SQLiteCajaDAO();
Caja caja = cajaDAO.findById(cajaId);
Egreso egreso = new Egreso();
diff --git a/src/danielcortes/xyz/models/egreso/MysqlEgresoDAO.java b/src/danielcortes/xyz/models/egreso/MysqlEgresoDAO.java
deleted file mode 100644
index fd8fc07..0000000
--- a/src/danielcortes/xyz/models/egreso/MysqlEgresoDAO.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.models.egreso;
-
-import danielcortes.xyz.data.MysqlConnectionHolder;
-import danielcortes.xyz.models.caja.Caja;
-import danielcortes.xyz.models.caja.CajaDAO;
-import danielcortes.xyz.models.caja.MysqlCajaDAO;
-import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
-import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
-import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class MysqlEgresoDAO extends EgresoDAO {
-
- public MysqlEgresoDAO(){
- this.connectionHolder = new MysqlConnectionHolder();
- }
-
- @Override
- public List findAll() {
- List 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 findById(int id) {
- List 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 findByCaja(Caja caja) {
- List 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 findByNro(String nro) {
- List 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 findByTipoEgreso(TipoEgreso tipoEgreso) {
- List 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_id()");
- 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;
- }
-
-}
diff --git a/src/danielcortes/xyz/models/ingreso/IngresoDAO.java b/src/danielcortes/xyz/models/ingreso/IngresoDAO.java
index 826ac93..683d990 100644
--- a/src/danielcortes/xyz/models/ingreso/IngresoDAO.java
+++ b/src/danielcortes/xyz/models/ingreso/IngresoDAO.java
@@ -28,8 +28,8 @@ 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.caja.SQLiteCajaDAO;
+import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
@@ -56,11 +56,11 @@ public abstract class IngresoDAO {
ArrayList ingresosList = new ArrayList<>();
while(rs.next()){
int tipoIngresoId = rs.getInt("tipo_ingreso_id");
- TipoIngresoDAO tipoEgresoDAO = new MysqlTipoIngresoDAO();
+ TipoIngresoDAO tipoEgresoDAO = new SQLiteTipoIngresoDAO();
TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0);
int cajaId = rs.getInt("caja_id");
- CajaDAO cajaDAO = new MysqlCajaDAO();
+ CajaDAO cajaDAO = new SQLiteCajaDAO();
Caja caja = cajaDAO.findById(cajaId);
Ingreso ingreso = new Ingreso();
diff --git a/src/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java b/src/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java
deleted file mode 100644
index 28ec8fe..0000000
--- a/src/danielcortes/xyz/models/ingreso/MysqlIngresoDAO.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.models.ingreso;
-
-import danielcortes.xyz.data.MysqlConnectionHolder;
-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 MysqlIngresoDAO extends IngresoDAO {
-
- public MysqlIngresoDAO(){
- this.connectionHolder = new MysqlConnectionHolder();
- }
-
- @Override
- public List findAll() {
- List 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 findByCaja(Caja caja) {
- List 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 findById(int id) {
- List 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 findByTipoIngreso(TipoIngreso tipoIngreso) {
- List 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_id()");
- 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;
- }
-
-}
diff --git a/src/danielcortes/xyz/models/tipo_egreso/MysqlTipoEgresoDAO.java b/src/danielcortes/xyz/models/tipo_egreso/MysqlTipoEgresoDAO.java
deleted file mode 100644
index 41aa45b..0000000
--- a/src/danielcortes/xyz/models/tipo_egreso/MysqlTipoEgresoDAO.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.models.tipo_egreso;
-
-import danielcortes.xyz.data.MysqlConnectionHolder;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class MysqlTipoEgresoDAO extends TipoEgresoDAO {
-
- public MysqlTipoEgresoDAO(){
- this.connectionHolder = new MysqlConnectionHolder();
- }
-
- @Override
- public List findAll() {
- List 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 findById(int id) {
- List 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 findByNombre(String nombre) {
- List 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;
- }
-}
diff --git a/src/danielcortes/xyz/models/tipo_ingreso/MysqlTipoIngresoDAO.java b/src/danielcortes/xyz/models/tipo_ingreso/MysqlTipoIngresoDAO.java
deleted file mode 100644
index 5b1919e..0000000
--- a/src/danielcortes/xyz/models/tipo_ingreso/MysqlTipoIngresoDAO.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2018-2019 Daniel Cortes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package danielcortes.xyz.models.tipo_ingreso;
-
-import danielcortes.xyz.data.MysqlConnectionHolder;
-
-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 MysqlTipoIngresoDAO extends TipoIngresoDAO {
- public MysqlTipoIngresoDAO(){
- this.connectionHolder = new MysqlConnectionHolder();
- }
-
- @Override
- public List findAll() {
- List 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 findById(int id) {
- List 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 findByNombre(String nombre) {
- List 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;
- }
-}