diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7f2da99..8837b63 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -10,10 +10,14 @@
+
-
-
+
+
+
+
+
@@ -57,7 +61,7 @@
-
+
@@ -263,7 +262,7 @@
-
+
@@ -276,11 +275,11 @@
-
+
-
+
@@ -383,6 +382,7 @@
+
@@ -517,14 +517,10 @@
-
-
-
- 1545982355969
-
-
-
- 1545982355969
+
+
+
+
1546024676996
@@ -862,7 +858,14 @@
1547962893611
-
+
+ 1547963246363
+
+
+
+ 1547963246364
+
+
@@ -898,7 +901,7 @@
-
+
@@ -928,10 +931,10 @@
-
+
-
+
@@ -1038,7 +1041,6 @@
-
@@ -1063,96 +1065,14 @@
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1271,42 +1191,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -1551,13 +1436,6 @@
-
-
-
-
-
-
-
@@ -1651,9 +1529,17 @@
+
+
+
+
+
+
+
+
-
+
@@ -1661,27 +1547,107 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1703,9 +1669,9 @@
+
-
@@ -1782,7 +1748,7 @@
- org.apache.poi:poi:4.0.1
+ forms_rt
diff --git a/dist/Programa Caja.jar b/dist/Programa Caja.jar
index 42dc59e..ff01140 100644
Binary files a/dist/Programa Caja.jar and b/dist/Programa Caja.jar differ
diff --git a/dist/logging.properties b/dist/logging.properties
new file mode 100644
index 0000000..cc52969
--- /dev/null
+++ b/dist/logging.properties
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+#handlers= java.util.logging.ConsoleHandler
+handlers= java.util.logging.FileHandler
+
+java.util.logging.FileHandler.level = ALL
+java.util.logging.FileHandler.pattern = logs.xml
+java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+
+#java.util.logging.ConsoleHandler.level = ALL
+#java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
+
+danielcortes.level= FINE
\ No newline at end of file
diff --git a/src/danielcortes/xyz/Main.java b/src/danielcortes/xyz/Main.java
index 1d65e59..f84eca6 100644
--- a/src/danielcortes/xyz/Main.java
+++ b/src/danielcortes/xyz/Main.java
@@ -29,7 +29,9 @@ import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.views.ManagerView;
import javax.swing.*;
+import java.util.Arrays;
import java.util.Locale;
+import java.util.logging.*;
public class Main {
public static void main(String[] args) {
@@ -37,7 +39,7 @@ public class Main {
}
private static void run() {
- setSystemProperties();
+ setUpSystemProperties();
ManagerView view = new ManagerView();
ManagerController managerController = new ManagerController(view);
@@ -56,7 +58,7 @@ public class Main {
}
- private static void setSystemProperties() {
+ private static void setUpSystemProperties() {
System.setProperty("awt.useSystemAAFontSettings", "on");
System.setProperty("swing.aatext", "true");
@@ -67,8 +69,6 @@ public class Main {
}
Locale.setDefault(new Locale("es"));
-
}
-
}
diff --git a/src/danielcortes/xyz/data/Configuration.java b/src/danielcortes/xyz/data/Configuration.java
index 7e5f08e..ac21142 100644
--- a/src/danielcortes/xyz/data/Configuration.java
+++ b/src/danielcortes/xyz/data/Configuration.java
@@ -27,21 +27,29 @@ package danielcortes.xyz.data;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class Configuration {
+ private static final Logger LOGGER = Logger.getLogger( Configuration.class.getName() );
+
private static final Properties config;
static {
config = new Properties();
try {
+ LOGGER.log(Level.INFO, "Leyendo y llenando el objeto de properties");
+
FileInputStream in = new FileInputStream("conf.properties");
config.load(in);
in.close();
- } catch (IOException e) {
- System.err.println("Couldn't load properties! The application will close");
- e.printStackTrace();
+ LOGGER.log(Level.INFO, "El objeto de properties se a llenado correctamente");
+
+ } catch (IOException e) {
+ LOGGER.log(Level.SEVERE, e.toString(), e);
+ System.exit(1);
}
}
diff --git a/src/danielcortes/xyz/data/SQLiteConnectionHolder.java b/src/danielcortes/xyz/data/SQLiteConnectionHolder.java
index 25188c2..b8a7c79 100644
--- a/src/danielcortes/xyz/data/SQLiteConnectionHolder.java
+++ b/src/danielcortes/xyz/data/SQLiteConnectionHolder.java
@@ -27,8 +27,13 @@ package danielcortes.xyz.data;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class SQLiteConnectionHolder implements ConnectionHolder {
+ private static final Logger LOGGER = Logger.getLogger( Configuration.class.getName() );
+
+
private String databaseURI;
public SQLiteConnectionHolder() {
@@ -42,8 +47,9 @@ public class SQLiteConnectionHolder implements ConnectionHolder {
try {
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection(databaseURI);
+ LOGGER.log(Level.FINER, "Creada conexion a base de datos SQLITE");
} catch (ClassNotFoundException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
System.exit(133);
}
diff --git a/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java b/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java
index 7eca09a..e1004bc 100644
--- a/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java
+++ b/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java
@@ -24,6 +24,7 @@
package danielcortes.xyz.models.caja;
+import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.documentos.Documentos;
import danielcortes.xyz.models.documentos.DocumentosDAO;
@@ -39,8 +40,12 @@ import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class SQLiteCajaDAO extends CajaDAO {
+ private static final Logger LOGGER = Logger.getLogger( Configuration.class.getName() );
+
public SQLiteCajaDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@@ -49,15 +54,18 @@ public class SQLiteCajaDAO extends CajaDAO {
public List findAll() {
List cajaList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
+ String query = "select * from caja";
PreparedStatement ps = conn.prepareStatement("select * from caja");
ResultSet rs = ps.executeQuery();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}", query);
+
cajaList = this.cajasFromResultSet(rs);
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
}
return cajaList;
@@ -67,18 +75,19 @@ public class SQLiteCajaDAO extends CajaDAO {
public Caja findById(int id) {
Caja caja = null;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("select * from caja where id = ?");
-
+ String query = "select * from caja where id = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, id);
-
ResultSet rs = ps.executeQuery();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}, con id = {1}", new Object[]{query, id});
+
caja = this.cajasFromResultSet(rs).get(0);
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
}
return caja;
}
@@ -87,12 +96,14 @@ public class SQLiteCajaDAO extends CajaDAO {
public Caja findByFecha(LocalDate fecha) {
Caja caja = null;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?");
+ String query = "select * from caja where fecha = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setString(1, fecha.toString());
-
ResultSet rs = ps.executeQuery();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}, con fecha = {1}", new Object[]{query, fecha});
+
List cajaList = this.cajasFromResultSet(rs);
if (cajaList.size() > 0) {
@@ -102,7 +113,7 @@ public class SQLiteCajaDAO extends CajaDAO {
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
}
return caja;
}
@@ -111,22 +122,30 @@ public class SQLiteCajaDAO extends CajaDAO {
public boolean insertCaja(Caja caja) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)");
-
+ String query = "insert into caja (fecha) values (?)";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setString(1, caja.getFecha().toString());
-
updates = ps.executeUpdate();
+
+
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}, con fecha = {1}", new Object[]{query, caja.getFecha().toString()});
+
ps.close();
+
+ query = "select last_insert_rowid()";
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
+
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}", new Object[]{query});
+
rs.next();
caja.setId(rs.getInt(1));
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -136,15 +155,17 @@ public class SQLiteCajaDAO extends CajaDAO {
public boolean updateCaja(Caja caja) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?");
+ String query = "update caja set fecha = ? where id = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setString(1, caja.getFecha().toString());
ps.setInt(2, caja.getId());
-
updates = ps.executeUpdate();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}, con fecha = {1} y id = {2}", new Object[]{query, caja.getFecha(), caja.getId()});
+
ps.close();
- } catch (SQLException e) {
- e.printStackTrace();
+ } catch (SQLException e) {
+ LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -155,6 +176,8 @@ public class SQLiteCajaDAO extends CajaDAO {
LocalDate date = month.withDayOfMonth(1);
LocalDate endDate = date.withDayOfMonth(date.lengthOfMonth()).plusDays(1);
+ LOGGER.log(Level.FINE, "Se intentara crear las cajas para un mes para las fechas entre {0} y {1}", new Object[]{date, endDate});
+
while (date.isBefore(endDate)) {
if (this.findByFecha(date) != null) {
date = date.plusDays(1);
@@ -177,6 +200,5 @@ public class SQLiteCajaDAO extends CajaDAO {
date = date.plusDays(1);
}
-
}
}
diff --git a/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java
index de47be9..1a79cbd 100644
--- a/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java
+++ b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java
@@ -24,6 +24,7 @@
package danielcortes.xyz.models.calculo_fondo;
+import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
@@ -33,8 +34,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
+ private static final Logger LOGGER = Logger.getLogger(Configuration.class.getName());
+
public SQLiteCalculoFondoDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@@ -43,15 +48,18 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
public List findAll() {
List calculoFondoList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo");
+ String query = "select * from calculo_fondo";
+ PreparedStatement ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}", query);
+
calculoFondoList = this.cajasFromResultSet(rs);
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
}
return calculoFondoList;
}
@@ -60,17 +68,19 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
public List findByCaja(Caja caja) {
List calculoFondoList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo where caja_id = ?");
+ String query = "select * from calculo_fondo where caja_id = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, caja.getId());
-
ResultSet rs = ps.executeQuery();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0} con caja_id = {1}", new Object[]{query, caja.getId()});
+
calculoFondoList = this.cajasFromResultSet(rs);
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
}
return calculoFondoList;
}
@@ -79,16 +89,19 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
public CalculoFondo findById(int id) {
CalculoFondo calculoFondo = null;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo where id = ?");
+ String query = "select * from calculo_fondo where id = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0} con id = {1}", new Object[]{query, id});
+
calculoFondo = this.cajasFromResultSet(rs).get(0);
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
}
return calculoFondo;
}
@@ -97,23 +110,28 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
public boolean insertCalculoFondo(CalculoFondo calculoFondo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)");
+ String query = "insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, calculoFondo.getValor());
ps.setString(2, calculoFondo.getDescripcion());
ps.setInt(3, calculoFondo.getCaja().getId());
updates = ps.executeUpdate();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0} con valor = {1}, descripcion = {2}, caja_id = {3}. se realizaron {4} updates", new Object[]{query, calculoFondo.getValor(), calculoFondo.getDescripcion(), calculoFondo.getCaja().getId(), updates});
+
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0}", query);
+
rs.next();
calculoFondo.setId(rs.getInt(1));
rs.close();
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -123,17 +141,19 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
public boolean updateCalculoFondo(CalculoFondo calculoFondo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("update calculo_fondo set valor = ?, descripcion = ?, caja_id = ? where id = ?");
+ String query = "update calculo_fondo set valor = ?, descripcion = ?, caja_id = ? where id = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, calculoFondo.getValor());
ps.setString(2, calculoFondo.getDescripcion());
ps.setInt(3, calculoFondo.getCaja().getId());
ps.setInt(4, calculoFondo.getId());
updates = ps.executeUpdate();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0} con valor = {1}, descripcion = {2}, caja_id = {3}, id = {4}. se realizaron {5} updates", new Object[]{query, calculoFondo.getValor(), calculoFondo.getDescripcion(), calculoFondo.getCaja().getId(), calculoFondo.getId(), updates});
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -143,14 +163,16 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
public boolean deleteCalculoFondo(CalculoFondo calculoFondo) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("delete from calculo_fondo where id = ?");
+ String query = "delete from calculo_fondo where id = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, calculoFondo.getId());
-
updates = ps.executeUpdate();
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0} con id = {1}. Se realizaron {2} updates", new Object[]{query, calculoFondo.getId(), updates});
+
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
}
return updates > 0;
@@ -160,16 +182,19 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
public int getTotalCalculoFondo(Caja caja) {
int sum = 0;
try (Connection conn = connectionHolder.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("select sum(valor) from calculo_fondo where caja_id = ?");
+ String query = "select sum(valor) from calculo_fondo where caja_id = ?";
+ PreparedStatement ps = conn.prepareStatement(query);
ps.setInt(1, caja.getId());
-
ResultSet rs = ps.executeQuery();
+
+ LOGGER.log(Level.FINE, "Se ejecuta query: {0} con caja_id = {1}", new Object[]{query, caja.getId()});
+
rs.next();
sum = rs.getInt(1);
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ LOGGER.log(Level.SEVERE, e.toString(), e);
}
return sum;
}