diff --git a/dist/Programa Caja.jar b/dist/Programa Caja.jar index 2419e7a..110c7f6 100644 Binary files a/dist/Programa Caja.jar and b/dist/Programa Caja.jar differ diff --git a/src/danielcortes/xyz/controllers/ArqueoController.java b/src/danielcortes/xyz/controllers/ArqueoController.java index 968754a..cdf5e88 100644 --- a/src/danielcortes/xyz/controllers/ArqueoController.java +++ b/src/danielcortes/xyz/controllers/ArqueoController.java @@ -37,10 +37,8 @@ import danielcortes.xyz.views.ArqueoView; import danielcortes.xyz.views.CalcularFondoView; import danielcortes.xyz.views.components.NumberFormatedTextField; -import javax.swing.AbstractAction; -import javax.swing.JComponent; -import javax.swing.KeyStroke; -import java.awt.Color; +import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; /** diff --git a/src/danielcortes/xyz/controllers/EgresosController.java b/src/danielcortes/xyz/controllers/EgresosController.java index 58bb8fb..513eb04 100644 --- a/src/danielcortes/xyz/controllers/EgresosController.java +++ b/src/danielcortes/xyz/controllers/EgresosController.java @@ -34,7 +34,9 @@ import danielcortes.xyz.views.EgresosView; import danielcortes.xyz.views.components.EgresosTableModel; import javax.swing.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; /** * Controlador el cual esta orientado a manejar la vista de EgresosView @@ -53,9 +55,9 @@ public class EgresosController { /** * Crea el controlador * Al inicial ejecuta: - * - Metodo que genera los eventos para la vista. - * - Metodo que llena los tipos de egresos en la vista. - * - Actualiza el estado de los botones. + * - Metodo que genera los eventos para la vista. + * - Metodo que llena los tipos de egresos en la vista. + * - Actualiza el estado de los botones. */ public EgresosController(EgresosView view, EgresoDAO egresoDAO, TipoEgresoDAO tipoEgresoDAO) { this.view = view; @@ -68,6 +70,7 @@ public class EgresosController { /** * Getter! + * * @return */ public EgresoDAO getEgresoDAO() { @@ -76,6 +79,7 @@ public class EgresosController { /** * Getter + * * @return */ public TipoEgresoDAO getTipoEgresoDAO() { @@ -85,7 +89,7 @@ public class EgresosController { /** * Guarda la caja entregada y actualiza los datos de la tabla de egresos y actualiza el field con el total de egresos. */ - public void updateCaja(Caja caja){ + public void updateCaja(Caja caja) { this.caja = caja; this.fillEgresosTable(); this.updateTotalEgresos(); @@ -114,11 +118,11 @@ public class EgresosController { /** * Asigna todos los eventos para la vista de egresos. - * - Cuando se apreta el boton de guardar o se apreta enter en los fields de descripcion, nro, valor y tipo - * Se llama al metodo guardarActionListener. - * - Cuando se apreta el boton de eliminar se llama al metodos eliminarActionListener - * - Cuando se presiona editar o se realizan 2 clicks en la tabla de egresos se llama a editarActionListener - * - Cuando se selecciona una fila en la tabla se llama a updateButtonsEnabled + * - Cuando se apreta el boton de guardar o se apreta enter en los fields de descripcion, nro, valor y tipo + * Se llama al metodo guardarActionListener. + * - Cuando se apreta el boton de eliminar se llama al metodos eliminarActionListener + * - Cuando se presiona editar o se realizan 2 clicks en la tabla de egresos se llama a editarActionListener + * - Cuando se selecciona una fila en la tabla se llama a updateButtonsEnabled */ private void setUpViewEvents() { this.view.getNroField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), "nextField"); @@ -151,7 +155,6 @@ public class EgresosController { * Primero llama a normalizar los inputs y a ocultar los mensajes de error * Luego si es que esta colocada la flag de editing se llama al metodo editarEgreso y si no, se llama a guardarEgreso * Al terminar esto, se llama a resetear el focus en los inputs y a actualizar el total de egresos - * */ private void guardarActionListener() { this.normalizeInputs(); @@ -162,9 +165,9 @@ public class EgresosController { int valor = this.view.getValorField().getValue(); TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem(); - if(editing){ + if (editing) { this.editarEgreso(nro, descripcion, valor, tipo, this.caja); - }else { + } else { this.guardarEgreso(nro, descripcion, valor, tipo, this.caja); } this.resetFocus(); @@ -274,6 +277,7 @@ public class EgresosController { /** * llama a los metodos necesarios para validar los inputs entregados + * * @return true cuando todas las validaciones retoran true, si no, false */ private boolean validateInput(String nro, String descripcion, TipoEgreso tipoEgreso, Caja caja) { @@ -288,9 +292,10 @@ public class EgresosController { /** * Valida la variable nro contra los casos - * - Es null - * - Esta vacio - * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * - Es null + * - Esta vacio + * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * * @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true */ private boolean validateNro(String nro) { @@ -312,9 +317,10 @@ public class EgresosController { /** * Valida la variable descripcion contra los casos - * - Es null - * - Esta vacio - * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * - Es null + * - Esta vacio + * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * * @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true */ private boolean validateDescripcion(String descripcion) { @@ -334,8 +340,9 @@ public class EgresosController { /** * Valida la variable tipoEgreso contra los casos - * - Es null - * Cuando este caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * - Es null + * Cuando este caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * * @return Si este caso es true se retornara false, si no, se retorna true */ private boolean validateTipoEgreso(TipoEgreso tipoEgreso) { @@ -349,10 +356,11 @@ public class EgresosController { /** * Valida la variable caja contra los casos - * - Es null + * - Es null + * * @return Si este caso es true se retornara false, si no, se retorna true */ - private boolean validateCaja(Caja caja){ + private boolean validateCaja(Caja caja) { return caja != null; } @@ -379,7 +387,7 @@ public class EgresosController { /** * Ejecuta trim sobre todos los campos de texto */ - private void normalizeInputs(){ + private void normalizeInputs() { this.view.getNroField().setText(this.view.getNroField().getText().trim()); this.view.getDescripcionField().setText(this.view.getDescripcionField().getText().trim()); @@ -392,9 +400,10 @@ public class EgresosController { this.view.getNroField().requestFocus(); } - private class GuardarAction extends AbstractAction{ + private class GuardarAction extends AbstractAction { EgresosController controller; - GuardarAction(EgresosController controller){ + + GuardarAction(EgresosController controller) { this.controller = controller; } diff --git a/src/danielcortes/xyz/controllers/InformesController.java b/src/danielcortes/xyz/controllers/InformesController.java index 75be1dc..5af8ef3 100644 --- a/src/danielcortes/xyz/controllers/InformesController.java +++ b/src/danielcortes/xyz/controllers/InformesController.java @@ -28,8 +28,8 @@ import danielcortes.xyz.informes.InformeEgresos; import danielcortes.xyz.informes.InformeLibroDeVentas; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; import danielcortes.xyz.utils.StringUtils; -import danielcortes.xyz.views.MonthSelectDialog; import danielcortes.xyz.views.InformesView; +import danielcortes.xyz.views.MonthSelectDialog; import danielcortes.xyz.views.TipoEgresoSelectDialog; import javax.swing.*; @@ -153,7 +153,7 @@ public class InformesController { } } - private Path processFilePath(String pathString){ + private Path processFilePath(String pathString) { Path path; if (!pathString.endsWith(".xls")) { @@ -162,7 +162,7 @@ public class InformesController { try { path = Paths.get(pathString); - }catch (InvalidPathException e){ + } catch (InvalidPathException e) { e.printStackTrace(); JOptionPane.showMessageDialog( diff --git a/src/danielcortes/xyz/controllers/IngresosController.java b/src/danielcortes/xyz/controllers/IngresosController.java index 480e8ed..7d3a81f 100644 --- a/src/danielcortes/xyz/controllers/IngresosController.java +++ b/src/danielcortes/xyz/controllers/IngresosController.java @@ -33,7 +33,9 @@ import danielcortes.xyz.views.IngresosView; import danielcortes.xyz.views.components.IngresosTableModel; import javax.swing.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; /** * Controlador el cual esta orientado a manejar la vista de IngresosView @@ -74,6 +76,7 @@ public class IngresosController { /** * Getter!!! + * * @return */ public TipoIngresoDAO getTipoIngresoDAO() { @@ -83,7 +86,7 @@ public class IngresosController { /** * Guarda la caja ingresada y actualiza el contenido de la tabla de ingresos y el campo de total de ingresos */ - public void updateCaja(Caja caja){ + public void updateCaja(Caja caja) { this.caja = caja; this.fillIngresosTable(); this.updateTotalIngresos(); @@ -113,7 +116,7 @@ public class IngresosController { /** * Genera los eventos para los distintos componentes de la vista * - Cuando se presiona el boton de guardar o se apreta enter en los fields de valor, nro inicial, - * nro final y tipo se llama a guardarActionListener + * nro final y tipo se llama a guardarActionListener * - Cuando se presiona el boton de eliminar se llama al eliminarActionListener * - Cuando se selecciona una fila en la tabla se llama a updateButtonsEnabled * - Cuando se presiona el boton de editar o se hace doble click sobre una fila de la tabla se llama a editarActionListener @@ -165,7 +168,7 @@ public class IngresosController { String nroFinal = this.view.getNroFinalField().getText(); TipoIngreso tipoIngreso = (TipoIngreso) this.view.getTipoCombo().getSelectedItem(); - if(editing) { + if (editing) { this.editarIngreso(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, this.caja); } else { this.guardarIngreso(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, this.caja); @@ -180,7 +183,7 @@ public class IngresosController { */ private void eliminarActionListener() { int selectedId = this.view.getIngresosTable().getSelectedRow(); - if(selectedId >= 0){ + if (selectedId >= 0) { Ingreso ingreso = this.view.getIngresosTableModel().getIngreso(selectedId); this.view.getIngresosTableModel().removeRow(selectedId); this.ingresoDAO.deleteIngreso(ingreso); @@ -200,7 +203,7 @@ public class IngresosController { int selectedID = this.view.getIngresosTable().getSelectedRow(); int selectedModelID = this.view.getIngresosTable().getRowSorter().convertRowIndexToModel(selectedID); - if(selectedModelID >= 0) { + if (selectedModelID >= 0) { Ingreso ingreso = this.view.getIngresosTableModel().getIngreso(selectedModelID); this.editingId = selectedModelID; @@ -219,7 +222,7 @@ public class IngresosController { /** * Obtiene el total de ingresos de la caja y lo coloca en el el field totalingresos */ - private void updateTotalIngresos(){ + private void updateTotalIngresos() { int total = this.ingresoDAO.getTotalIngreso(this.caja); this.view.getTotalIngresoField().setValue(total); } @@ -230,10 +233,10 @@ public class IngresosController { * Si es asi, son habilidatos, si no, de deshabilitan */ private void updateButtonsEnabled() { - if(this.view.getIngresosTable().getSelectedRow()>=0){ + if (this.view.getIngresosTable().getSelectedRow() >= 0) { this.view.getEliminarButton().setEnabled(true); this.view.getEditarButton().setEnabled(true); - }else{ + } else { this.view.getEliminarButton().setEnabled(false); this.view.getEditarButton().setEnabled(false); } @@ -243,8 +246,8 @@ public class IngresosController { * Guarda un ingreso tras llamar a validar el input * Luego de guardar agrega a la tabla el ingreso, llama a limpiar los campos de input y a actualizar el total de ingresos */ - private void guardarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){ - if(this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){ + private void guardarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) { + if (this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)) { Ingreso ingreso = new Ingreso(); ingreso.setTipoIngreso(tipoIngreso); ingreso.setCaja(caja); @@ -265,10 +268,9 @@ public class IngresosController { /** * Edita el ingreso tras llamar a validar el input * Tras esto actualiza el ingreso en la tabla, llama a actualizar el total de ingresos, a limpiar los campos de input y a desactivar la flag de editing. - * */ - private void editarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){ - if(this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){ + private void editarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) { + if (this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)) { this.editingIngreso.setTipoIngreso(tipoIngreso); this.editingIngreso.setValor(valor); this.editingIngreso.setNroZInicial(nroZInicial); @@ -285,6 +287,7 @@ public class IngresosController { /** * Llama a los metodos necesarios para validar el input + * * @return true cuando todas las validaciones retoran true, si no, false */ private boolean validateInput(String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) { @@ -300,7 +303,8 @@ public class IngresosController { /** * Valida la variable caja este caso - * - Es null + * - Es null + * * @return Si este caso es true se retornara false, si no, se retorna true */ private boolean validateCaja(Caja caja) { @@ -309,12 +313,13 @@ public class IngresosController { /** * Valida la variable nroInicial contra los casos - * - Es null - * - Esta vacio - * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * - Es null + * - Esta vacio + * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * * @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true */ - private boolean validateNroInicial(String nroInicial){ + private boolean validateNroInicial(String nroInicial) { if (nroInicial == null) { this.view.getErrorNroInicial().setText("Hubo un problema con los datos"); this.view.getErrorNroInicial().setVisible(true); @@ -331,12 +336,13 @@ public class IngresosController { /** * Valida la variable nroFinal contra los casos - * - Es null - * - Esta vacio - * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * - Es null + * - Esta vacio + * Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente + * * @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true */ - private boolean validateNroFinal(String nroFinal){ + private boolean validateNroFinal(String nroFinal) { if (nroFinal == null) { this.view.getErrorNroFinal().setText("Hubo un problema con los datos"); this.view.getErrorNroFinal().setVisible(true); @@ -353,8 +359,9 @@ public class IngresosController { /** * Valida la variable caja este caso - * - Es null - * Cuando sea true, colocara un mensaje de error en el jlabel correspondiente + * - Es null + * Cuando sea true, colocara un mensaje de error en el jlabel correspondiente + * * @return Si este caso es true se retornara false, si no, se retorna true */ private boolean validateTipoIngreso(TipoIngreso tipoIngreso) { @@ -391,7 +398,7 @@ public class IngresosController { /** * Ejecuta un trim sobre todos los jtextfield */ - private void normalizeInputs(){ + private void normalizeInputs() { this.view.getNroZInicialField().setText(this.view.getNroZInicialField().getText().trim()); this.view.getNroZFinalField().setText(this.view.getNroZFinalField().getText().trim()); this.view.getNroInicialField().setText(this.view.getNroInicialField().getText().trim()); @@ -401,14 +408,14 @@ public class IngresosController { /** * Le pide focus al tipo combo */ - private void resetFocus(){ + private void resetFocus() { this.view.getValorField().requestFocus(); } - private class NextAction extends AbstractAction{ + private class NextAction extends AbstractAction { JComponent next; - NextAction(JComponent next){ + NextAction(JComponent next) { this.next = next; } @@ -418,9 +425,10 @@ public class IngresosController { } } - private class GuardarAction extends AbstractAction{ + private class GuardarAction extends AbstractAction { IngresosController controller; - GuardarAction(IngresosController controller){ + + GuardarAction(IngresosController controller) { this.controller = controller; } diff --git a/src/danielcortes/xyz/controllers/ManagerController.java b/src/danielcortes/xyz/controllers/ManagerController.java index 9da0372..a344e3e 100644 --- a/src/danielcortes/xyz/controllers/ManagerController.java +++ b/src/danielcortes/xyz/controllers/ManagerController.java @@ -63,12 +63,12 @@ public class ManagerController { * Crea el controlador * Necesita todos las interfaces DAO para poder asignarselos a sus vistas, * esto con el objetivo que sean facilmente intercambiables. - * + *

* Llama a los metodos que: - * - Cargan el contenido del CardLayout - * - Selecciona una fecha inicial - * - Genera los eventos de la vista - * - Presiona el boton de la vista inicial + * - Cargan el contenido del CardLayout + * - Selecciona una fecha inicial + * - Genera los eventos de la vista + * - Presiona el boton de la vista inicial */ public ManagerController(ManagerView view, CajaDAO cajaDAO, DocumentosDAO documentosDAO, EfectivoDAO efectivoDAO, EgresoDAO egresoDAO, IngresoDAO ingresoDAO, TipoEgresoDAO tipoEgresoDAO, TipoIngresoDAO tipoIngresoDAO) { this.view = view; @@ -88,7 +88,7 @@ public class ManagerController { /** * Coloca la fecha actual en el datepicker y luego llama a actualizar las cajas de las vistas */ - private void setUpDate(){ + private void setUpDate() { this.view.getDatePicker().setDateToToday(); this.updateCaja(); } @@ -123,11 +123,11 @@ public class ManagerController { /** * Llama a update caja con la fecha seleccionada en el datepicker en los controladores del manager. */ - private void updateCaja(){ + private void updateCaja() { LocalDate selectedDate = this.view.getDatePicker().getDate(); Caja caja = this.cajaDAO.findByFecha(selectedDate); - if(caja == null){ + if (caja == null) { caja = new Caja(); caja.setFecha(selectedDate); this.cajaDAO.insertCaja(caja); diff --git a/src/danielcortes/xyz/controllers/actions/NextAction.java b/src/danielcortes/xyz/controllers/actions/NextAction.java index fe2f51f..90b409d 100644 --- a/src/danielcortes/xyz/controllers/actions/NextAction.java +++ b/src/danielcortes/xyz/controllers/actions/NextAction.java @@ -30,7 +30,7 @@ import java.awt.event.ActionEvent; public class NextAction extends AbstractAction { private JComponent next; - public NextAction(JComponent next){ + public NextAction(JComponent next) { this.next = next; } diff --git a/src/danielcortes/xyz/data/Configuration.java b/src/danielcortes/xyz/data/Configuration.java index d36e2d1..7e5f08e 100644 --- a/src/danielcortes/xyz/data/Configuration.java +++ b/src/danielcortes/xyz/data/Configuration.java @@ -45,7 +45,7 @@ public class Configuration { } } - public static String get(String key){ + public static String get(String key) { return config.getProperty(key); } } diff --git a/src/danielcortes/xyz/data/ConnectionHolder.java b/src/danielcortes/xyz/data/ConnectionHolder.java index eca1429..97c5ebe 100644 --- a/src/danielcortes/xyz/data/ConnectionHolder.java +++ b/src/danielcortes/xyz/data/ConnectionHolder.java @@ -27,5 +27,5 @@ package danielcortes.xyz.data; import java.sql.SQLException; public interface ConnectionHolder { - public java.sql.Connection getConnection() throws SQLException; + java.sql.Connection getConnection() throws SQLException; } diff --git a/src/danielcortes/xyz/informes/InformeEgresos.java b/src/danielcortes/xyz/informes/InformeEgresos.java index e8c003b..dcf4381 100644 --- a/src/danielcortes/xyz/informes/InformeEgresos.java +++ b/src/danielcortes/xyz/informes/InformeEgresos.java @@ -27,22 +27,22 @@ package danielcortes.xyz.informes; import danielcortes.xyz.models.caja.SQLiteCajaDAO; import danielcortes.xyz.models.informes.egresos.InformeEgresosContent; import danielcortes.xyz.models.informes.egresos.SQLiteInformeEgresosContentDAO; -import danielcortes.xyz.models.tipo_egreso.TipoEgreso; import danielcortes.xyz.utils.Pair; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.PropertyTemplate; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.time.LocalDate; import java.time.ZoneId; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; public class InformeEgresos { private final String[] titles = { @@ -193,7 +193,7 @@ public class InformeEgresos { this.totalFinal.getCell(3).setCellStyle(this.styles.get("total_final")); //Estilo para las filas de datos - for(Row row: this.dataRows){ + for (Row row : this.dataRows) { row.getCell(0).setCellStyle(this.styles.get("date")); row.getCell(1).setCellStyle(this.styles.get("regular")); row.getCell(2).setCellStyle(this.styles.get("regular")); @@ -201,7 +201,7 @@ public class InformeEgresos { } //Estilo para las filas de totales - for(Row row: this.totalRows){ + for (Row row : this.totalRows) { row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellStyle(this.styles.get("not_so_gray")); row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellStyle(this.styles.get("not_so_gray")); row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellStyle(this.styles.get("not_so_gray")); @@ -212,10 +212,10 @@ public class InformeEgresos { //Setea el alto de las filas this.sheet.getRow(0).setHeightInPoints(30); this.totalFinal.setHeightInPoints(20); - for(Row row: this.dataRows){ + for (Row row : this.dataRows) { row.setHeightInPoints(15); } - for(Row row: this.totalRows){ + for (Row row : this.totalRows) { row.setHeightInPoints(18); } @@ -227,7 +227,7 @@ public class InformeEgresos { sheet.autoSizeColumn(3); } - private HashMap generateStyles(){ + private HashMap generateStyles() { Font font = this.wb.createFont(); font.setBold(true); font.setColor(IndexedColors.WHITE.getIndex()); @@ -285,7 +285,7 @@ public class InformeEgresos { setStyles(); addBorders(); - try (OutputStream fileOut = Files.newOutputStream(this.saveFile)){ + try (OutputStream fileOut = Files.newOutputStream(this.saveFile)) { wb.write(fileOut); return this.saveFile; } catch (IOException e) { diff --git a/src/danielcortes/xyz/informes/InformeLibroDeVentas.java b/src/danielcortes/xyz/informes/InformeLibroDeVentas.java index deb373c..5040252 100644 --- a/src/danielcortes/xyz/informes/InformeLibroDeVentas.java +++ b/src/danielcortes/xyz/informes/InformeLibroDeVentas.java @@ -32,8 +32,6 @@ import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.PropertyTemplate; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; @@ -90,7 +88,7 @@ public class InformeLibroDeVentas { this.styles = this.generateStyles(); } - private void sortInforme(){ + private void sortInforme() { this.informe.sort(Comparator.comparing(InformeLibroDeVentasContent::getFecha)); } @@ -110,7 +108,7 @@ public class InformeLibroDeVentas { private void fillData() { int x = 2; - for(InformeLibroDeVentasContent data : this.informe){ + for (InformeLibroDeVentasContent data : this.informe) { int y = 0; Row dataRow = sheet.createRow(x); @@ -119,7 +117,7 @@ public class InformeLibroDeVentas { dataRow.createCell(y++).setCellValue(this.dias[data.getDia()]); dataRow.createCell(y++).setCellValue(fecha); - dataRow.createCell(y++).setCellValue(data.getManualesInicial() == null ? "0": data.getManualesInicial()); + dataRow.createCell(y++).setCellValue(data.getManualesInicial() == null ? "0" : data.getManualesInicial()); dataRow.createCell(y++).setCellValue(data.getManualesFinal() == null ? "0" : data.getManualesFinal()); dataRow.createCell(y++).setCellValue(data.getManuales()); @@ -178,7 +176,7 @@ public class InformeLibroDeVentas { } private void freezeCells() { - this.sheet.createFreezePane(2,2); + this.sheet.createFreezePane(2, 2); } private void addBorders() { diff --git a/src/danielcortes/xyz/models/caja/CajaDAO.java b/src/danielcortes/xyz/models/caja/CajaDAO.java index 6de63b3..e40890f 100644 --- a/src/danielcortes/xyz/models/caja/CajaDAO.java +++ b/src/danielcortes/xyz/models/caja/CajaDAO.java @@ -25,7 +25,6 @@ package danielcortes.xyz.models.caja; import danielcortes.xyz.data.ConnectionHolder; -import danielcortes.xyz.data.SQLiteConnectionHolder; import java.sql.ResultSet; import java.sql.SQLException; @@ -37,9 +36,13 @@ public abstract class CajaDAO { protected ConnectionHolder connectionHolder; public abstract List 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); public abstract void createCajasForMonth(LocalDate month); diff --git a/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java b/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java index 602b4a7..7eca09a 100644 --- a/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java +++ b/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java @@ -41,15 +41,14 @@ import java.util.ArrayList; import java.util.List; public class SQLiteCajaDAO extends CajaDAO { - public SQLiteCajaDAO () { + public SQLiteCajaDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } @Override public List findAll() { List cajaList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from caja"); ResultSet rs = ps.executeQuery(); @@ -57,18 +56,17 @@ public class SQLiteCajaDAO extends CajaDAO { 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(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from caja where id = ?"); ps.setInt(1, id); @@ -79,7 +77,6 @@ public class SQLiteCajaDAO extends CajaDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -89,8 +86,7 @@ public class SQLiteCajaDAO extends CajaDAO { @Override public Caja findByFecha(LocalDate fecha) { Caja caja = null; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?"); ps.setString(1, fecha.toString()); @@ -99,13 +95,12 @@ public class SQLiteCajaDAO extends CajaDAO { List cajaList = this.cajasFromResultSet(rs); - if(cajaList.size() > 0){ + if (cajaList.size() > 0) { caja = cajaList.get(0); } rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -115,8 +110,7 @@ public class SQLiteCajaDAO extends CajaDAO { @Override public boolean insertCaja(Caja caja) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)"); ps.setString(1, caja.getFecha().toString()); @@ -131,7 +125,6 @@ public class SQLiteCajaDAO extends CajaDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -142,8 +135,7 @@ public class SQLiteCajaDAO extends CajaDAO { @Override public boolean updateCaja(Caja caja) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?"); ps.setString(1, caja.getFecha().toString()); ps.setInt(2, caja.getId()); @@ -151,7 +143,6 @@ public class SQLiteCajaDAO extends CajaDAO { updates = ps.executeUpdate(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -164,8 +155,8 @@ public class SQLiteCajaDAO extends CajaDAO { LocalDate date = month.withDayOfMonth(1); LocalDate endDate = date.withDayOfMonth(date.lengthOfMonth()).plusDays(1); - while(date.isBefore(endDate)) { - if(this.findByFecha(date) != null){ + while (date.isBefore(endDate)) { + if (this.findByFecha(date) != null) { date = date.plusDays(1); continue; } diff --git a/src/danielcortes/xyz/models/calculo_fondo/CalculoFondoDAO.java b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondoDAO.java index f182dbd..1bb87f1 100644 --- a/src/danielcortes/xyz/models/calculo_fondo/CalculoFondoDAO.java +++ b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondoDAO.java @@ -37,11 +37,15 @@ public abstract class CalculoFondoDAO { protected ConnectionHolder connectionHolder; public abstract List findAll(); + public abstract List findByCaja(Caja caja); + public abstract CalculoFondo findById(int id); public abstract boolean insertCalculoFondo(CalculoFondo calculoFondo); + public abstract boolean updateCalculoFondo(CalculoFondo calculoFondo); + public abstract boolean deleteCalculoFondo(CalculoFondo calculoFondo); public abstract int getTotalCalculoFondo(Caja caja); diff --git a/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java index be5b8e6..de47be9 100644 --- a/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java +++ b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java @@ -42,8 +42,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { @Override public List findAll() { List calculoFondoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo"); ResultSet rs = ps.executeQuery(); @@ -51,17 +50,16 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } return calculoFondoList; } + @Override public List findByCaja(Caja caja) { List calculoFondoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo where caja_id = ?"); ps.setInt(1, caja.getId()); @@ -71,7 +69,6 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -81,8 +78,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { @Override public CalculoFondo findById(int id) { CalculoFondo calculoFondo = null; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from calculo_fondo where id = ?"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); @@ -91,7 +87,6 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -101,8 +96,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { @Override public boolean insertCalculoFondo(CalculoFondo calculoFondo) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)"); ps.setInt(1, calculoFondo.getValor()); ps.setString(2, calculoFondo.getDescripcion()); @@ -118,7 +112,6 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -129,8 +122,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { @Override public boolean updateCalculoFondo(CalculoFondo calculoFondo) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("update calculo_fondo set valor = ?, descripcion = ?, caja_id = ? where id = ?"); ps.setInt(1, calculoFondo.getValor()); ps.setString(2, calculoFondo.getDescripcion()); @@ -140,7 +132,6 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { updates = ps.executeUpdate(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -151,15 +142,13 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { @Override public boolean deleteCalculoFondo(CalculoFondo calculoFondo) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("delete from calculo_fondo where id = ?"); ps.setInt(1, calculoFondo.getId()); updates = ps.executeUpdate(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -170,8 +159,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { @Override public int getTotalCalculoFondo(Caja caja) { int sum = 0; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select sum(valor) from calculo_fondo where caja_id = ?"); ps.setInt(1, caja.getId()); @@ -180,7 +168,6 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO { sum = rs.getInt(1); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/danielcortes/xyz/models/documentos/DocumentosDAO.java b/src/danielcortes/xyz/models/documentos/DocumentosDAO.java index cbb20cc..6a6e0ee 100644 --- a/src/danielcortes/xyz/models/documentos/DocumentosDAO.java +++ b/src/danielcortes/xyz/models/documentos/DocumentosDAO.java @@ -38,12 +38,17 @@ public abstract class DocumentosDAO { protected ConnectionHolder connectionHolder; public abstract List 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); public abstract int getTotalDocumentos(Caja caja); diff --git a/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java b/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java index e3e3894..aa73976 100644 --- a/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java +++ b/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java @@ -24,11 +24,8 @@ package danielcortes.xyz.models.documentos; -import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; -import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.SQLiteCajaDAO; import java.sql.Connection; import java.sql.PreparedStatement; @@ -45,8 +42,7 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public List findAll() { List documentosList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from documentos"); ResultSet rs = ps.executeQuery(); @@ -54,7 +50,6 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -64,21 +59,19 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public Documentos findById(int id) { Documentos documentos = null; - try { - Connection conn = connectionHolder.getConnection(); + 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){ + if (documentosList.size() > 0) { documentos = documentosList.get(0); } rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -88,21 +81,19 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public Documentos findByCaja(Caja caja) { Documentos documentos = null; - try { - Connection conn = connectionHolder.getConnection(); + 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){ + if (documentosList.size() > 0) { documentos = documentosList.get(0); } rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -112,8 +103,7 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public boolean insertDocumentos(Documentos documentos) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, retiros, caja_id) values (?,?,?,?)"); ps.setInt(1, documentos.getCheques()); ps.setInt(2, documentos.getTarjetas()); @@ -130,7 +120,6 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -141,8 +130,7 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public boolean insertDefaultDocumentos(Documentos documentos) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, retiros, caja_id) values (0,0,0,?)"); ps.setInt(1, documentos.getCaja().getId()); @@ -156,7 +144,6 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -167,8 +154,7 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public boolean updateDocumentos(Documentos documentos) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("update documentos set tarjetas = ?, cheques = ?, retiros = ?, caja_id = ? where id = ?"); ps.setInt(1, documentos.getTarjetas()); ps.setInt(2, documentos.getCheques()); @@ -178,7 +164,6 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { updates = ps.executeUpdate(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -189,15 +174,13 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public boolean deleteDocumentos(Documentos documentos) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + 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; @@ -208,8 +191,7 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { @Override public int getTotalDocumentos(Caja caja) { int total = 0; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select cheques + tarjetas + retiros from documentos where caja_id = ?"); ps.setInt(1, caja.getId()); @@ -219,7 +201,6 @@ public class SQLiteDocumentosDAO extends DocumentosDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java b/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java index 21abb7d..74afa57 100644 --- a/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java +++ b/src/danielcortes/xyz/models/efectivo/EfectivoDAO.java @@ -38,12 +38,17 @@ public abstract class EfectivoDAO { protected ConnectionHolder connectionHolder; public abstract List 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); public abstract int getTotalEfectivo(Caja caja); diff --git a/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java b/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java index 3ff255c..881ee64 100644 --- a/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java +++ b/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java @@ -24,11 +24,8 @@ package danielcortes.xyz.models.efectivo; -import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; -import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.SQLiteCajaDAO; import java.sql.Connection; import java.sql.PreparedStatement; @@ -45,8 +42,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public List findAll() { List efectivoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from efectivos"); ResultSet rs = ps.executeQuery(); @@ -54,7 +50,6 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -65,8 +60,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public Efectivo findById(int id) { Efectivo efectivo = null; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); @@ -75,7 +69,6 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -86,8 +79,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public Efectivo findByCaja(Caja caja) { Efectivo efectivo = null; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?"); ps.setInt(1, caja.getId()); ResultSet rs = ps.executeQuery(); @@ -99,7 +91,6 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } @@ -110,8 +101,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public boolean insertEfectivo(Efectivo efectivo) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + 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()); @@ -134,7 +124,6 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -145,8 +134,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public boolean insertDefaultEfectivo(Efectivo efectivo) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + 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()); @@ -160,7 +148,6 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -171,8 +158,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public boolean updateEfectivo(Efectivo efectivo) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + 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()); @@ -189,7 +175,6 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { updates = ps.executeUpdate(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); return false; @@ -200,15 +185,13 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public boolean deleteEfectivo(Efectivo efectivo) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + 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; @@ -219,8 +202,7 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { @Override public int getTotalEfectivo(Caja caja) { int total = 0; - try { - Connection conn = connectionHolder.getConnection(); + 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()); @@ -230,7 +212,6 @@ public class SQLiteEfectivoDAO extends EfectivoDAO { rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/danielcortes/xyz/models/egreso/EgresoDAO.java b/src/danielcortes/xyz/models/egreso/EgresoDAO.java index 21141e8..7843efc 100644 --- a/src/danielcortes/xyz/models/egreso/EgresoDAO.java +++ b/src/danielcortes/xyz/models/egreso/EgresoDAO.java @@ -41,20 +41,26 @@ public abstract class EgresoDAO { protected ConnectionHolder connectionHolder; public abstract List findAll(); + public abstract List findById(int id); + public abstract List findByCaja(Caja caja); + public abstract List findByNro(String nro); + public abstract List findByTipoEgreso(TipoEgreso tipoEgreso); 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 egresosFromResultSet(ResultSet rs) throws SQLException { ArrayList egresoList = new ArrayList<>(); - while(rs.next()){ + while (rs.next()) { int tipoEgresoId = rs.getInt("tipo_egreso_id"); TipoEgresoDAO tipoEgresoDAO = new SQLiteTipoEgresoDAO(); TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0); diff --git a/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java b/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java index bead990..7c321cb 100644 --- a/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java +++ b/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java @@ -24,14 +24,9 @@ package danielcortes.xyz.models.egreso; -import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; -import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.SQLiteCajaDAO; -import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; -import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO; import java.sql.Connection; import java.sql.PreparedStatement; @@ -41,15 +36,14 @@ import java.util.ArrayList; import java.util.List; public class SQLiteEgresoDAO extends EgresoDAO { - public SQLiteEgresoDAO(){ + public SQLiteEgresoDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } @Override public List findAll() { List egresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from egresos"); ResultSet rs = ps.executeQuery(); @@ -67,10 +61,9 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public List findById(int id) { List egresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from egresos where id = ?"); - ps.setInt(1,id); + ps.setInt(1, id); ResultSet rs = ps.executeQuery(); egresoList = this.egresosFromResultSet(rs); @@ -87,8 +80,7 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public List findByCaja(Caja caja) { List egresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from egresos where caja_id = ?"); ps.setInt(1, caja.getId()); ResultSet rs = ps.executeQuery(); @@ -107,8 +99,7 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public List findByNro(String nro) { List egresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from egresos where nro = ?"); ps.setString(1, nro); ResultSet rs = ps.executeQuery(); @@ -127,8 +118,7 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public List findByTipoEgreso(TipoEgreso tipoEgreso) { List egresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + 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(); @@ -147,13 +137,12 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public boolean insertEgreso(Egreso egreso) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + 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.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(); @@ -176,13 +165,12 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public boolean updateEgreso(Egreso egreso) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + 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.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()); @@ -200,8 +188,7 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public boolean deleteEgreso(Egreso egreso) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("delete from egresos where id = ? "); ps.setInt(1, egreso.getId()); @@ -219,8 +206,7 @@ public class SQLiteEgresoDAO extends EgresoDAO { @Override public int getTotalEgreso(Caja caja) { int total = 0; - try { - Connection conn = connectionHolder.getConnection(); + 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(); diff --git a/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContentDAO.java b/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContentDAO.java index 73a521e..87e3667 100644 --- a/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContentDAO.java +++ b/src/danielcortes/xyz/models/informes/egresos/InformeEgresosContentDAO.java @@ -24,12 +24,17 @@ package danielcortes.xyz.models.informes.egresos; +import danielcortes.xyz.data.ConnectionHolder; + import java.time.LocalDate; import java.util.List; public abstract class InformeEgresosContentDAO { + protected ConnectionHolder connectionHolder; + /** * Genera el informe con nombre muy largo + * * @param month mes sobre el cual se quiere le informe * @return lista del objeto que contiene los datos necesarios para el informe */ diff --git a/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosContentDAO.java b/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosContentDAO.java index b93faa7..b252141 100644 --- a/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosContentDAO.java +++ b/src/danielcortes/xyz/models/informes/egresos/SQLiteInformeEgresosContentDAO.java @@ -37,11 +37,14 @@ import java.util.List; public class SQLiteInformeEgresosContentDAO extends InformeEgresosContentDAO { private List list; + public SQLiteInformeEgresosContentDAO() { + this.connectionHolder = new SQLiteConnectionHolder(); + } + @Override public List getInformeEgresosFactuasMateriaPrima(LocalDate date, int tipoEgresoId) { list = new ArrayList<>(); - try { - Connection conn = new SQLiteConnectionHolder().getConnection(); + try (Connection conn = connectionHolder.getConnection()) { String query = "select caja.fecha as \"fecha\",\n" + "egresos.nro as \"nro\",\n" + diff --git a/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java b/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java index 2cc8ac9..ff2eb90 100644 --- a/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java +++ b/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContent.java @@ -135,7 +135,7 @@ public class InformeLibroDeVentasContent { } public void setFiscalesInicial(String fiscalesInicial) { - this.fiscalesInicial = fiscalesInicial; + this.fiscalesInicial = fiscalesInicial; } public String getFiscalesFinal() { diff --git a/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContentDAO.java b/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContentDAO.java index 4e232d8..dccae99 100644 --- a/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContentDAO.java +++ b/src/danielcortes/xyz/models/informes/libro_de_ventas/InformeLibroDeVentasContentDAO.java @@ -48,12 +48,17 @@ package danielcortes.xyz.models.informes.libro_de_ventas; +import danielcortes.xyz.data.ConnectionHolder; + import java.time.LocalDate; import java.util.Collection; public abstract class InformeLibroDeVentasContentDAO { + protected ConnectionHolder connectionHolder; + /** * Genera el contenido del informes mensual + * * @param date fecha que esta dentro del mes en el que se necesita el informes * @return Lista con las columnas principales necesarias para el informes */ diff --git a/src/danielcortes/xyz/models/informes/libro_de_ventas/SQLiteInformeLibroDeVentasContentDAO.java b/src/danielcortes/xyz/models/informes/libro_de_ventas/SQLiteInformeLibroDeVentasContentDAO.java index 166b585..a312969 100644 --- a/src/danielcortes/xyz/models/informes/libro_de_ventas/SQLiteInformeLibroDeVentasContentDAO.java +++ b/src/danielcortes/xyz/models/informes/libro_de_ventas/SQLiteInformeLibroDeVentasContentDAO.java @@ -48,7 +48,6 @@ package danielcortes.xyz.models.informes.libro_de_ventas; -import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.utils.NaturalOrderComparator; import java.sql.Connection; @@ -56,7 +55,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDate; -import java.util.*; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasContentDAO { private HashMap map; @@ -67,8 +68,7 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo @Override public Collection getInformeMensual(LocalDate date) { - try { - Connection conn = new SQLiteConnectionHolder().getConnection(); + try (Connection conn = connectionHolder.getConnection()) { String queryTotales = "select " + "caja.id as \"caja\",\n" + @@ -110,7 +110,6 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/danielcortes/xyz/models/ingreso/IngresoDAO.java b/src/danielcortes/xyz/models/ingreso/IngresoDAO.java index 683d990..939652f 100644 --- a/src/danielcortes/xyz/models/ingreso/IngresoDAO.java +++ b/src/danielcortes/xyz/models/ingreso/IngresoDAO.java @@ -42,19 +42,24 @@ public abstract class IngresoDAO { protected ConnectionHolder connectionHolder; public abstract List findAll(); + public abstract List findByCaja(Caja caja); + public abstract List findById(int id); + public abstract List 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 ingresosFromResultSet(ResultSet rs) throws SQLException { ArrayList ingresosList = new ArrayList<>(); - while(rs.next()){ + while (rs.next()) { int tipoIngresoId = rs.getInt("tipo_ingreso_id"); TipoIngresoDAO tipoEgresoDAO = new SQLiteTipoIngresoDAO(); TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0); diff --git a/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java b/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java index 9884afd..01ec2bb 100644 --- a/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java +++ b/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java @@ -24,14 +24,9 @@ package danielcortes.xyz.models.ingreso; -import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import danielcortes.xyz.models.caja.Caja; -import danielcortes.xyz.models.caja.CajaDAO; -import danielcortes.xyz.models.caja.SQLiteCajaDAO; -import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO; import danielcortes.xyz.models.tipo_ingreso.TipoIngreso; -import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO; import java.sql.Connection; import java.sql.PreparedStatement; @@ -41,15 +36,14 @@ import java.util.ArrayList; import java.util.List; public class SQLiteIngresoDAO extends IngresoDAO { - public SQLiteIngresoDAO(){ + public SQLiteIngresoDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } @Override public List findAll() { List ingresosList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from ingresos"); ResultSet rs = ps.executeQuery(); @@ -67,8 +61,7 @@ public class SQLiteIngresoDAO extends IngresoDAO { @Override public List findByCaja(Caja caja) { List ingresosList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from ingresos where caja_id = ?"); ps.setInt(1, caja.getId()); ResultSet rs = ps.executeQuery(); @@ -87,8 +80,7 @@ public class SQLiteIngresoDAO extends IngresoDAO { @Override public List findById(int id) { List ingresosList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from ingresos where id = ?"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); @@ -107,8 +99,7 @@ public class SQLiteIngresoDAO extends IngresoDAO { @Override public List findByTipoIngreso(TipoIngreso tipoIngreso) { List ingresosList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + 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(); @@ -127,8 +118,7 @@ public class SQLiteIngresoDAO extends IngresoDAO { @Override public boolean insertIngreso(Ingreso ingreso) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("insert into ingresos (valor, nro_z_inicial, nro_z_final, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?,?,?)"); ps.setInt(1, ingreso.getValor()); ps.setString(2, ingreso.getNroZInicial()); @@ -158,10 +148,9 @@ public class SQLiteIngresoDAO extends IngresoDAO { @Override public boolean updateIngreso(Ingreso ingreso) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("update ingresos set valor = ?, nro_z_inicial = ?, nro_z_final = ?, nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?"); - ps.setInt(1,ingreso.getValor()); + ps.setInt(1, ingreso.getValor()); ps.setString(2, ingreso.getNroZInicial()); ps.setString(3, ingreso.getNroZFinal()); ps.setString(4, ingreso.getNroInicial()); @@ -184,10 +173,9 @@ public class SQLiteIngresoDAO extends IngresoDAO { @Override public boolean deleteIngreso(Ingreso ingreso) { int updates; - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("delete from ingresos where id = ?"); - ps.setInt(1,ingreso.getId()); + ps.setInt(1, ingreso.getId()); updates = ps.executeUpdate(); ps.close(); conn.close(); @@ -201,8 +189,7 @@ public class SQLiteIngresoDAO extends IngresoDAO { @Override public int getTotalIngreso(Caja caja) { int total = 0; - try { - Connection conn = connectionHolder.getConnection(); + 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(); diff --git a/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java b/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java index 6445581..091ad2f 100644 --- a/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java +++ b/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java @@ -24,7 +24,6 @@ package danielcortes.xyz.models.tipo_egreso; -import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import java.sql.Connection; @@ -35,15 +34,14 @@ import java.util.ArrayList; import java.util.List; public class SQLiteTipoEgresoDAO extends TipoEgresoDAO { - public SQLiteTipoEgresoDAO(){ + public SQLiteTipoEgresoDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } @Override public List findAll() { List tipoEgresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso"); ResultSet rs = ps.executeQuery(); @@ -61,8 +59,7 @@ public class SQLiteTipoEgresoDAO extends TipoEgresoDAO { @Override public List findById(int id) { List tipoEgresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where id = ?"); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); @@ -81,8 +78,7 @@ public class SQLiteTipoEgresoDAO extends TipoEgresoDAO { @Override public List findByNombre(String nombre) { List tipoEgresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where nombre = ?"); ps.setString(1, nombre); ResultSet rs = ps.executeQuery(); diff --git a/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java b/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java index 53fc11e..b100130 100644 --- a/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java +++ b/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java @@ -61,7 +61,8 @@ public class TipoEgreso { this.nombre = nombre; } - public TipoEgreso(){} + public TipoEgreso() { + } public String getNombre() { return nombre; @@ -80,7 +81,7 @@ public class TipoEgreso { } @Override - public String toString(){ + public String toString() { return this.nombre; } } diff --git a/src/danielcortes/xyz/models/tipo_egreso/TipoEgresoDAO.java b/src/danielcortes/xyz/models/tipo_egreso/TipoEgresoDAO.java index 2589668..db2bc7c 100644 --- a/src/danielcortes/xyz/models/tipo_egreso/TipoEgresoDAO.java +++ b/src/danielcortes/xyz/models/tipo_egreso/TipoEgresoDAO.java @@ -59,16 +59,20 @@ public abstract class TipoEgresoDAO { protected ConnectionHolder connectionHolder; public abstract List findAll(); + public abstract List findById(int id); + public abstract List findByNombre(String nombre); public abstract boolean insertTipoEgreso(TipoEgreso tipoEgreso); + public abstract boolean updateTipoEgreso(TipoEgreso tipoEgreso); + public abstract boolean deleteTipoEgreso(TipoEgreso tipoEgreso); List tipoEgresoFromResultSet(ResultSet rs) throws SQLException { ArrayList tipoEgresoList = new ArrayList<>(); - while(rs.next()){ + while (rs.next()) { TipoEgreso tipoEgreso = new TipoEgreso(); tipoEgreso.setId(rs.getInt("id")); tipoEgreso.setNombre(rs.getString("nombre")); diff --git a/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java b/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java index 00396e6..261a3af 100644 --- a/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java +++ b/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java @@ -24,7 +24,6 @@ package danielcortes.xyz.models.tipo_ingreso; -import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import java.sql.Connection; @@ -35,15 +34,14 @@ import java.util.ArrayList; import java.util.List; public class SQLiteTipoIngresoDAO extends TipoIngresoDAO { - public SQLiteTipoIngresoDAO(){ + public SQLiteTipoIngresoDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } @Override public List findAll() { List tiposIngresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso"); ResultSet rs = ps.executeQuery(); @@ -61,10 +59,9 @@ public class SQLiteTipoIngresoDAO extends TipoIngresoDAO { @Override public List findById(int id) { List tiposIngresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where id = ?"); - ps.setInt(1,id); + ps.setInt(1, id); ResultSet rs = ps.executeQuery(); tiposIngresoList = this.tiposIngresoFromResultSet(rs); @@ -81,17 +78,15 @@ public class SQLiteTipoIngresoDAO extends TipoIngresoDAO { @Override public List findByNombre(String nombre) { List tiposIngresoList = new ArrayList<>(); - try { - Connection conn = connectionHolder.getConnection(); + try (Connection conn = connectionHolder.getConnection()) { PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where nombre = ?"); - ps.setString(1,nombre); + ps.setString(1, nombre); ResultSet rs = ps.executeQuery(); tiposIngresoList = this.tiposIngresoFromResultSet(rs); rs.close(); ps.close(); - conn.close(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/danielcortes/xyz/models/tipo_ingreso/TipoIngresoDAO.java b/src/danielcortes/xyz/models/tipo_ingreso/TipoIngresoDAO.java index 5f6345a..89a907a 100644 --- a/src/danielcortes/xyz/models/tipo_ingreso/TipoIngresoDAO.java +++ b/src/danielcortes/xyz/models/tipo_ingreso/TipoIngresoDAO.java @@ -33,17 +33,22 @@ import java.util.List; public abstract class TipoIngresoDAO { protected ConnectionHolder connectionHolder; + public abstract List findAll(); + public abstract List findById(int id); + public abstract List findByNombre(String nombre); public abstract boolean insertTipoIngreso(TipoIngreso tipoEgreso); + public abstract boolean updateTipoIngreso(TipoIngreso tipoEgreso); + public abstract boolean deleteTipoIngreso(TipoIngreso tipoEgreso); List tiposIngresoFromResultSet(ResultSet rs) throws SQLException { ArrayList tiposIngresoList = new ArrayList<>(); - while(rs.next()){ + while (rs.next()) { TipoIngreso tipoIngreso = new TipoIngreso(); tipoIngreso.setId(rs.getInt("id")); tipoIngreso.setNombre(rs.getString("nombre")); diff --git a/src/danielcortes/xyz/utils/NaturalOrderComparator.java b/src/danielcortes/xyz/utils/NaturalOrderComparator.java index d99e76a..8323c8f 100644 --- a/src/danielcortes/xyz/utils/NaturalOrderComparator.java +++ b/src/danielcortes/xyz/utils/NaturalOrderComparator.java @@ -22,7 +22,7 @@ package danielcortes.xyz.utils; -import java.util.*; +import java.util.Comparator; public class NaturalOrderComparator implements Comparator { int compareRight(String a, String b) { diff --git a/src/danielcortes/xyz/utils/Pair.java b/src/danielcortes/xyz/utils/Pair.java index 5b9e79b..9e6038a 100644 --- a/src/danielcortes/xyz/utils/Pair.java +++ b/src/danielcortes/xyz/utils/Pair.java @@ -26,7 +26,7 @@ package danielcortes.xyz.utils; import java.util.Objects; -public class Pair { +public class Pair { private final L left; private final R right; @@ -35,8 +35,13 @@ public class Pair { this.right = right; } - public L getLeft() { return left; } - public R getRight() { return right; } + public L getLeft() { + return left; + } + + public R getRight() { + return right; + } @Override public boolean equals(Object o) { diff --git a/src/danielcortes/xyz/utils/StringUtils.java b/src/danielcortes/xyz/utils/StringUtils.java index 7ac7c52..848db29 100644 --- a/src/danielcortes/xyz/utils/StringUtils.java +++ b/src/danielcortes/xyz/utils/StringUtils.java @@ -25,7 +25,7 @@ package danielcortes.xyz.utils; public class StringUtils { - public static String capitalize(String string){ + public static String capitalize(String string) { return string.substring(0, 1).toUpperCase() + string.substring(1); } } diff --git a/src/danielcortes/xyz/views/MonthSelectDialog.java b/src/danielcortes/xyz/views/MonthSelectDialog.java index 1c9ae4c..c2831f7 100644 --- a/src/danielcortes/xyz/views/MonthSelectDialog.java +++ b/src/danielcortes/xyz/views/MonthSelectDialog.java @@ -31,12 +31,11 @@ import danielcortes.xyz.views.components.YearSpinnerModel; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.time.LocalDate; import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; public class MonthSelectDialog extends JDialog { private JPanel contentPane; @@ -90,7 +89,7 @@ public class MonthSelectDialog extends JDialog { public LocalDate getMonth() { int year = Integer.valueOf((String) yearSpinner.getValue()); - int month = this.months.indexOf((String) this.monthCombo.getSelectedItem()) + 1; + int month = this.months.indexOf(this.monthCombo.getSelectedItem()) + 1; LocalDate monthDate = LocalDate.of(year, month, 1); return monthDate; diff --git a/src/danielcortes/xyz/views/TipoEgresoSelectDialog.java b/src/danielcortes/xyz/views/TipoEgresoSelectDialog.java index 3ebff1a..5c76928 100644 --- a/src/danielcortes/xyz/views/TipoEgresoSelectDialog.java +++ b/src/danielcortes/xyz/views/TipoEgresoSelectDialog.java @@ -26,15 +26,14 @@ package danielcortes.xyz.views; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; -import com.intellij.uiDesigner.core.Spacer; -import danielcortes.xyz.models.egreso.Egreso; -import danielcortes.xyz.models.egreso.SQLiteEgresoDAO; import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.List; public class TipoEgresoSelectDialog extends JDialog { diff --git a/src/danielcortes/xyz/views/components/EgresosTableModel.java b/src/danielcortes/xyz/views/components/EgresosTableModel.java index 153ff21..5c3da53 100644 --- a/src/danielcortes/xyz/views/components/EgresosTableModel.java +++ b/src/danielcortes/xyz/views/components/EgresosTableModel.java @@ -36,7 +36,7 @@ public class EgresosTableModel extends AbstractTableModel { private NumberFormat nf; - public EgresosTableModel(){ + public EgresosTableModel() { super(); this.columns = new String[]{"N°", "Descripcion", "Valor", "Tipo"}; this.rows = new ArrayList<>(); @@ -61,31 +61,31 @@ public class EgresosTableModel extends AbstractTableModel { public void addRow(Egreso egreso) { rows.add(egreso); - this.fireTableRowsInserted(getRowCount()-1, getRowCount()-1); + this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); } - public void removeRow(int row){ + public void removeRow(int row) { this.rows.remove(row); - this.fireTableRowsDeleted(row,row); + this.fireTableRowsDeleted(row, row); } - public void removeRows(){ + public void removeRows() { int rowCount = getRowCount(); - if(rowCount > 0){ + if (rowCount > 0) { this.rows.clear(); - this.fireTableRowsDeleted(0, rowCount-1); + this.fireTableRowsDeleted(0, rowCount - 1); } } public void setEgreso(int editingId, Egreso egreso) { this.rows.set(editingId, egreso); - this.fireTableRowsUpdated(0,getRowCount()-1); + this.fireTableRowsUpdated(0, getRowCount() - 1); } @Override public Object getValueAt(int row, int col) { - switch (col){ + switch (col) { case 0: return rows.get(row).getNro(); case 1: @@ -98,7 +98,7 @@ public class EgresosTableModel extends AbstractTableModel { return null; } - public Egreso getEgreso(int row){ + public Egreso getEgreso(int row) { return rows.get(row); } diff --git a/src/danielcortes/xyz/views/components/FondoTableModel.java b/src/danielcortes/xyz/views/components/FondoTableModel.java index 8bdbba9..75d68a0 100644 --- a/src/danielcortes/xyz/views/components/FondoTableModel.java +++ b/src/danielcortes/xyz/views/components/FondoTableModel.java @@ -37,7 +37,7 @@ public class FondoTableModel extends AbstractTableModel { private NumberFormat nf; - public FondoTableModel(){ + public FondoTableModel() { super(); this.columns = new String[]{"Valor", "Descripcion"}; this.rows = new ArrayList<>(); @@ -62,31 +62,31 @@ public class FondoTableModel extends AbstractTableModel { public void addRow(CalculoFondo calculoFondo) { rows.add(calculoFondo); - this.fireTableRowsInserted(getRowCount()-1, getRowCount()-1); + this.fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); } - public void removeRow(int row){ + public void removeRow(int row) { this.rows.remove(row); - this.fireTableRowsDeleted(row,row); + this.fireTableRowsDeleted(row, row); } - public void removeRows(){ + public void removeRows() { int rowCount = getRowCount(); - if(rowCount > 0){ + if (rowCount > 0) { this.rows.clear(); - this.fireTableRowsDeleted(0, rowCount-1); + this.fireTableRowsDeleted(0, rowCount - 1); } } public void setCalculoFondo(int editingId, CalculoFondo calculoFondo) { this.rows.set(editingId, calculoFondo); - this.fireTableRowsUpdated(0,getRowCount()-1); + this.fireTableRowsUpdated(0, getRowCount() - 1); } @Override public Object getValueAt(int row, int col) { - switch (col){ + switch (col) { case 0: return nf.format(rows.get(row).getValor()); case 1: @@ -95,7 +95,7 @@ public class FondoTableModel extends AbstractTableModel { return null; } - public CalculoFondo getCalculoFondo(int row){ + public CalculoFondo getCalculoFondo(int row) { return rows.get(row); } } diff --git a/src/danielcortes/xyz/views/components/IngresosTableModel.java b/src/danielcortes/xyz/views/components/IngresosTableModel.java index 85f7c4f..2970e61 100644 --- a/src/danielcortes/xyz/views/components/IngresosTableModel.java +++ b/src/danielcortes/xyz/views/components/IngresosTableModel.java @@ -37,7 +37,7 @@ public class IngresosTableModel extends AbstractTableModel { public IngresosTableModel() { super(); - this.columns = new String[]{"Valor","N° Z Inicial", "N° Z Final", "N° Inicial", "N° Final", "Tipo"}; + this.columns = new String[]{"Valor", "N° Z Inicial", "N° Z Final", "N° Inicial", "N° Final", "Tipo"}; this.rows = new ArrayList<>(); this.nf = NumberFormat.getIntegerInstance(); } diff --git a/src/danielcortes/xyz/views/components/NumberFormatedTextField.java b/src/danielcortes/xyz/views/components/NumberFormatedTextField.java index 6420160..687ccad 100644 --- a/src/danielcortes/xyz/views/components/NumberFormatedTextField.java +++ b/src/danielcortes/xyz/views/components/NumberFormatedTextField.java @@ -29,10 +29,7 @@ import org.mariuszgromada.math.mxparser.Expression; import javax.swing.*; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; import java.text.NumberFormat; -import java.text.ParseException; /** * Crea un JTextField que formatea automaticamente su texto como un integer el cual se puede obtener @@ -59,7 +56,7 @@ public class NumberFormatedTextField extends JTextField { /** * Guarda el integer entregado y lo muestra en el campo. */ - public void setValue(int value){ + public void setValue(int value) { this.value = value; this.setText(nf.format(value)); } @@ -67,11 +64,11 @@ public class NumberFormatedTextField extends JTextField { /** * Llama a readValue por un bug seguramente relacionado con el focus listener: * - No actualizaba el valor al momento de hacer requestfocus a otro componente, probablemente porque no alcanza - * a realizarse la accion antes que ocurra la siguiente - * + * a realizarse la accion antes que ocurra la siguiente + *

* Fuerza a que se lea el valor en el textfield antes de retornarlo */ - public int getValue(){ + public int getValue() { this.readValue(); return this.value; } @@ -80,14 +77,14 @@ public class NumberFormatedTextField extends JTextField { * Lee el valor en el texto, ejecuta la operacion matematica que en caso que exista una y la almacena en el valor * Si la operacion matematica es invalida, almacenara un 0 */ - private void readValue(){ + private void readValue() { String currentText = this.getText(); - String stripedDots = currentText.replace(".", ""); + String stripedDots = currentText.replace(".", ""); Expression expression = new Expression(stripedDots); - if(expression.checkSyntax()){ + if (expression.checkSyntax()) { this.value = (int) Math.floor(expression.calculate()); - }else{ + } else { this.value = 0; } } @@ -95,11 +92,11 @@ public class NumberFormatedTextField extends JTextField { /** * Formatea el value y lo muestra en el field */ - private void formatText(){ + private void formatText() { this.setText(nf.format(this.value)); } - private class FieldFocusListener implements FocusListener{ + private class FieldFocusListener implements FocusListener { /** * Selecciona todo al momento de ganar foco */