Se reescribio el informe de ventas mensual

Primeramente, se tenia por objetivo reescribir el informe para que este
fuera mas claro y para lograrlo se penso en que en vez de realizar 2
querys grandes en las que se tomaban todos los datos necesarios y se
mapeaban  un objeto el cual se añadia a un array, se realizaran
multiples querys separadas, en las que se irian obteniendo los datos
individualmente y sean juntados en un objeto.

Para esto se debio reescribir parte de SQLiteIngresoDAO, por una parte,
para añadir las querys que obtenian los numeros de boletas y de Z en una
caja para un tipo de ingreso en ademas de la query para obtener el total de
ingresos por un tipo de ingreso en un mes.

Junto con esto, al toparme con un bug, reescribi el como se realizaban
las querys en todo el objeto DAO, dado a que creia que se debia a un
problema donde no se estaban cerrando bien los ResultSets y los
PreparedStatement, aunque al final no fue eso y era simplemente el que
no habia un resultado en la query que se habia realizado.

A partir de aca no sabria bien como describir lo que se realizo, pero se
puede resumir en que encontre redundante el tener 2 paquetes de informe
y un objeto DAO para generar el informe cuando realmente no lo era,
siendo mas un "builder" creo .w.

Por lo que separe todo eso y lo deje en 3 objetos, el LibroDeVentas, el
cual contiene la instancia de un dia de informe, el InformLibroDeVentas,
el cual es un wraper para un hashmap que contiene el libro de ventas y
ademas tiene el metodo que genera el libro, y finalmente el
InformeLibroDeVentasToExcel, el cual pasa el informe a un archivo excel
para la lectura del usuario final.

Finalmente separe el que se guardara el informe automaticamente al
generarlo. para ello cree un objeto aparte, el cual tendra metodos
estaticos para todos los objetos que tenga que guardar eventulamente,
por ahora como solo necesito guardar un Workbook, eso es lo que guarda.

Creo que eso seria todo :3
This commit is contained in:
Daniel Cortes
2019-03-06 01:22:12 -03:00
parent 537c64e85c
commit 0a98bee777
22 changed files with 453 additions and 355 deletions

BIN
dist/Programa Caja.jar vendored

Binary file not shown.

View File

@@ -2,7 +2,7 @@ package danielcortes.xyz.controllers;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.informes.InformeEstadoResultadoExcel;
import danielcortes.xyz.informes.InformeEstadoResultado;
import danielcortes.xyz.models.estado_resultado.EstadoResultado;
import danielcortes.xyz.models.estado_resultado.EstadoResultadoDAO;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
@@ -131,7 +131,7 @@ public class EstadoResultadoController extends BaseController {
return;
}
InformeEstadoResultadoExcel estadoResultado = new InformeEstadoResultadoExcel(this.mes, saveFile);
InformeEstadoResultado estadoResultado = new InformeEstadoResultado(this.mes, saveFile);
estadoResultado.generarInforme();
new InformeGeneratedConfirmation(saveFile).execute();
}

View File

@@ -25,9 +25,10 @@
package danielcortes.xyz.controllers;
import danielcortes.xyz.data.Configuration;
import danielcortes.xyz.informes.InformeEgresosExcel;
import danielcortes.xyz.informes.InformeLibroDeVentasExcel;
import danielcortes.xyz.informes.InformeEgresos;
import danielcortes.xyz.informes.InformeLibroDeVentasToExcel;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.utils.SaveFile;
import danielcortes.xyz.utils.StringUtils;
import danielcortes.xyz.views.InformesSideBar;
import danielcortes.xyz.views.dialogs.InformeGeneratedConfirmation;
@@ -37,6 +38,7 @@ import danielcortes.xyz.views.dialogs.XLSFileChooser;
import java.nio.file.Path;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import org.apache.poi.ss.usermodel.Workbook;
public class InformesSideBarController {
@@ -75,8 +77,10 @@ public class InformesSideBarController {
return;
}
InformeLibroDeVentasExcel informe = new InformeLibroDeVentasExcel(month, saveFile);
informe.generarInforme();
InformeLibroDeVentasToExcel informe = new InformeLibroDeVentasToExcel(month, saveFile);
Workbook wb = informe.generarInforme();
SaveFile.save(wb, saveFile);
new InformeGeneratedConfirmation(saveFile).execute();
}
@@ -102,7 +106,7 @@ public class InformesSideBarController {
return;
}
InformeEgresosExcel informe = new InformeEgresosExcel(tipoEgreso.getId(), month, saveFile);
InformeEgresos informe = new InformeEgresos(tipoEgreso.getId(), month, saveFile);
Path generatedFile = informe.generarInforme();
new InformeGeneratedConfirmation(saveFile).execute();

View File

@@ -38,8 +38,6 @@ import danielcortes.xyz.models.estado_resultado.EstadoResultadoDAO;
import danielcortes.xyz.models.estado_resultado.SQLiteEstadoResultadoDAO;
import danielcortes.xyz.models.informes.egresos.InformeEgresosContentDAO;
import danielcortes.xyz.models.informes.egresos.SQLiteInformeEgresosContentDAO;
import danielcortes.xyz.models.informes.libro_de_ventas.InformeLibroDeVentasContentDAO;
import danielcortes.xyz.models.informes.libro_de_ventas.SQLiteInformeLibroDeVentasContentDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.models.ingreso.SQLiteIngresoDAO;
import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
@@ -57,7 +55,6 @@ public class DAOManager {
private static final EfectivoDAO efectivoDAO;
private static final EgresoDAO egresoDAO;
private static final InformeEgresosContentDAO egresosContentDAO;
private static final InformeLibroDeVentasContentDAO libroDeVentasContentDAO;
private static final IngresoDAO ingresoDAO;
private static final TipoEgresoDAO tipoEgresoDAO;
private static final TipoIngresoDAO tipoIngresoDAO;
@@ -71,7 +68,6 @@ public class DAOManager {
efectivoDAO = new SQLiteEfectivoDAO();
egresoDAO = new SQLiteEgresoDAO();
egresosContentDAO = new SQLiteInformeEgresosContentDAO();
libroDeVentasContentDAO = new SQLiteInformeLibroDeVentasContentDAO();
ingresoDAO = new SQLiteIngresoDAO();
tipoEgresoDAO = new SQLiteTipoEgresoDAO();
tipoIngresoDAO = new SQLiteTipoIngresoDAO();
@@ -103,10 +99,6 @@ public class DAOManager {
return egresosContentDAO;
}
public static InformeLibroDeVentasContentDAO getLibroDeVentasContentDAO() {
return libroDeVentasContentDAO;
}
public static IngresoDAO getIngresoDAO() {
return ingresoDAO;
}

View File

@@ -0,0 +1,90 @@
package danielcortes.xyz.informes;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.HashMap;
public class InformeLibroDeVentas{
HashMap<LocalDate, LibroDeVentas> informe;
private InformeLibroDeVentas(){}
public LibroDeVentas get(LocalDate localDate){
return informe.get(localDate);
}
public int size(){
return informe.size();
}
private void put(LocalDate date, LibroDeVentas libroDeVentas){
this.informe.put(date, libroDeVentas);
}
public static InformeLibroDeVentas generate(YearMonth mes) {
InformeLibroDeVentas informeLibroDeVentas = new InformeLibroDeVentas();
informeLibroDeVentas.informe = new HashMap<>();
LocalDate currentDate = mes.atDay(1);
LocalDate endDatePlusOne = mes.atEndOfMonth().plusDays(1);
CajaDAO cajaDAO = DAOManager.getCajaDAO();
IngresoDAO ingresoDAO = DAOManager.getIngresoDAO();
TipoIngresoDAO tipoIngresoDAO = DAOManager.getTipoIngresoDAO();
TipoIngreso boletaFiscal = tipoIngresoDAO.findByNombre("Boletas Fiscales").get(0);
TipoIngreso boletaManual = tipoIngresoDAO.findByNombre("Boletas Manuales").get(0);
TipoIngreso boletaExenta = tipoIngresoDAO.findByNombre("Boleta Exenta").get(0);
TipoIngreso factura = tipoIngresoDAO.findByNombre("Facturas").get(0);
TipoIngreso guias = tipoIngresoDAO.findByNombre("Guias").get(0);
while (currentDate.isBefore(endDatePlusOne)) {
Caja caja = cajaDAO.getByFecha(currentDate).orElse(Caja.EMPTY);
LibroDeVentas data = new LibroDeVentas();
informeLibroDeVentas.put(currentDate, data);
data.setDia(currentDate.getDayOfWeek().getValue());
data.setFecha(currentDate);
data.setManuales(ingresoDAO.getTotalIngresoEnCajaPorTipo(caja, boletaManual));
data.setManualesInicial(
ingresoDAO.getPrimerNroInicialDeCajaDeTipo(caja, boletaManual).orElse("0"));
data.setManualesFinal(
ingresoDAO.getUltimoNroFinalDeCajaDeTipo(caja, boletaManual).orElse("0"));
data.setFiscales(ingresoDAO.getTotalIngresoEnCajaPorTipo(caja, boletaFiscal));
data.setFiscalesInicial(
ingresoDAO.getPrimerNroInicialDeCajaDeTipo(caja, boletaFiscal).orElse("0"));
data.setFiscalesFinal(
ingresoDAO.getUltimoNroFinalDeCajaDeTipo(caja, boletaFiscal).orElse("0"));
data.setFiscalesZInicial(ingresoDAO.getPrimerNroZInicialDeCaja(caja).orElse("0"));
data.setFiscalesZFinal(ingresoDAO.getUltimoNroZFinalDeCaja(caja).orElse("0"));
data.setExentas(ingresoDAO.getTotalIngresoEnCajaPorTipo(caja, boletaExenta));
data.setExentasInicial(
ingresoDAO.getPrimerNroInicialDeCajaDeTipo(caja, boletaExenta).orElse("0"));
data.setExentasFinal(
ingresoDAO.getUltimoNroFinalDeCajaDeTipo(caja, boletaExenta).orElse("0"));
data.setFacturas(ingresoDAO.getTotalIngresoEnCajaPorTipo(caja, factura));
data.setFacturasInicial(
ingresoDAO.getPrimerNroInicialDeCajaDeTipo(caja, factura).orElse("0"));
data.setFacturasFinal(ingresoDAO.getUltimoNroFinalDeCajaDeTipo(caja, factura).orElse("0"));
data.setGuias(ingresoDAO.getTotalIngresoEnCajaPorTipo(caja, guias));
data.setGuiasInicial(ingresoDAO.getPrimerNroInicialDeCajaDeTipo(caja, guias).orElse("0"));
data.setGuiasFinal(ingresoDAO.getUltimoNroFinalDeCajaDeTipo(caja, guias).orElse("0"));
currentDate = currentDate.plusDays(1);
}
return informeLibroDeVentas;
}
}

View File

@@ -24,17 +24,11 @@
package danielcortes.xyz.informes;
import danielcortes.xyz.data.DAOManager;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
import danielcortes.xyz.models.informes.libro_de_ventas.InformeLibroDeVentasContent;
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.YearMonth;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -55,7 +49,7 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.PropertyTemplate;
public class InformeLibroDeVentasExcel {
public class InformeLibroDeVentasToExcel {
private final String[] titles = {
"", "",
@@ -79,11 +73,12 @@ public class InformeLibroDeVentasExcel {
"TOTAL", "ACUMULADO", ""
};
private final String[] dias = {"Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes",
"Sabado"};
private final String[] dias = {"Lunes", "Martes", "Miercoles", "Jueves", "Viernes",
"Sabado", "Domingo"};
private ArrayList<InformeLibroDeVentasContent> informe;
private Path saveFile;
private YearMonth mes;
private InformeLibroDeVentas informe;
private ArrayList<Row> dataRows;
private Row footerRow;
@@ -94,11 +89,9 @@ public class InformeLibroDeVentasExcel {
private CreationHelper createHelper;
private HashMap<String, CellStyle> styles;
public InformeLibroDeVentasExcel(YearMonth mes, Path saveFile) {
new SQLiteCajaDAO().createCajasForMonth(mes);
this.informe = new ArrayList<>(DAOManager.getLibroDeVentasContentDAO().generateInformeMensual(mes));
this.saveFile = saveFile;
public InformeLibroDeVentasToExcel(YearMonth mes, Path saveFile) {
this.mes = mes;
this.informe = InformeLibroDeVentas.generate(mes);
this.dataRows = new ArrayList<>();
this.headerRows = new ArrayList<>();
@@ -110,10 +103,6 @@ public class InformeLibroDeVentasExcel {
this.styles = this.generateStyles();
}
private void sortInforme() {
this.informe.sort(Comparator.comparing(InformeLibroDeVentasContent::getFecha));
}
private void fillHeaders() {
Row titles = sheet.createRow(0);
Row subtitles = sheet.createRow(1);
@@ -133,13 +122,17 @@ public class InformeLibroDeVentasExcel {
private void fillData() {
int rowCounter = 2;
for (InformeLibroDeVentasContent data : this.informe) {
int cellCounter = 0;
LocalDate currentDate = this.mes.atDay(1);
LocalDate endDatePlusOne = this.mes.atEndOfMonth().plusDays(1);
while (currentDate.isBefore(endDatePlusOne)) {
LibroDeVentas data = this.informe.get(currentDate);
Row dataRow = sheet.createRow(rowCounter);
dataRows.add(dataRow);
Date fecha = Date.from(data.getFecha().atStartOfDay(ZoneId.systemDefault()).toInstant());
dataRow.createCell(cellCounter++).setCellValue(this.dias[data.getDia()]);
int cellCounter = 0;
dataRow.createCell(cellCounter++).setCellValue(this.dias[data.getDia() - 1]);
dataRow.createCell(cellCounter++).setCellValue(fecha);
dataRow.createCell(cellCounter++)
@@ -164,7 +157,8 @@ public class InformeLibroDeVentasExcel {
.setCellValue(data.getExentasFinal() == null ? "0" : data.getExentasFinal());
dataRow.createCell(cellCounter++).setCellValue(data.getExentas());
dataRow.createCell(cellCounter++).setCellValue(data.getSubTotal());
dataRow.createCell(cellCounter++).setCellFormula(
"E" + (rowCounter + 1) + "+J" + (rowCounter + 1) + "+M" + (rowCounter + 1));
dataRow.createCell(cellCounter++)
.setCellValue(data.getFacturasInicial() == null ? "0" : data.getFacturasInicial());
@@ -187,6 +181,7 @@ public class InformeLibroDeVentasExcel {
.setCellFormula(("U" + (rowCounter + 1)) + ("+") + ("V" + (rowCounter)));
}
rowCounter++;
currentDate = currentDate.plusDays(1);
}
}
@@ -328,8 +323,7 @@ public class InformeLibroDeVentasExcel {
}
}
public void generarInforme() {
sortInforme();
public Workbook generarInforme() {
fillData();
fillHeaders();
fillTotales();
@@ -338,13 +332,10 @@ public class InformeLibroDeVentasExcel {
setStyles();
addBorders();
try (OutputStream fileOut = Files.newOutputStream(this.saveFile)) {
wb.write(fileOut);
} catch (IOException e) {
e.printStackTrace();
}
return wb;
}
private HashMap<String, CellStyle> generateStyles() {
Font font = this.wb.createFont();
font.setBold(true);

View File

@@ -46,11 +46,11 @@
* SOFTWARE.
*/
package danielcortes.xyz.models.informes.libro_de_ventas;
package danielcortes.xyz.informes;
import java.time.LocalDate;
public class InformeLibroDeVentasContent {
public class LibroDeVentas {
private int dia;
private LocalDate fecha;
@@ -65,7 +65,6 @@ public class InformeLibroDeVentasContent {
private String exentasInicial;
private String exentasFinal;
private int exentas;
private int subTotal;
private String facturasInicial;
private String facturasFinal;
private int facturas;
@@ -99,7 +98,6 @@ public class InformeLibroDeVentasContent {
}
public String getManualesFinal() {
return manualesFinal;
}
@@ -179,14 +177,6 @@ public class InformeLibroDeVentasContent {
this.exentas = exentas;
}
public int getSubTotal() {
return subTotal;
}
public void setSubTotal(int sub_total) {
this.subTotal = sub_total;
}
public String getFacturasInicial() {
return facturasInicial;
}
@@ -243,10 +233,9 @@ public class InformeLibroDeVentasContent {
this.total = total;
}
@Override
public String toString() {
return "InformeLibroDeVentasContent{" +
return "LibroDeVentas{" +
"dia=" + dia +
", fecha=" + fecha +
", manualesInicial='" + manualesInicial + '\'' +
@@ -260,7 +249,6 @@ public class InformeLibroDeVentasContent {
", exentasInicial='" + exentasInicial + '\'' +
", exentasFinal='" + exentasFinal + '\'' +
", exentas=" + exentas +
", subTotal=" + subTotal +
", facturasInicial='" + facturasInicial + '\'' +
", facturasFinal='" + facturasFinal + '\'' +
", facturas=" + facturas +

View File

@@ -27,11 +27,16 @@ package danielcortes.xyz.models.caja;
import java.time.LocalDate;
public class Caja {
public final static Caja EMPTY = new Caja();
private int id;
private LocalDate fecha;
private int fondo;
public Caja(){
}
public int getId() {
return id;
}

View File

@@ -1,37 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.models.informes.libro_de_ventas;
import danielcortes.xyz.data.ConnectionHolder;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.HashMap;
public abstract class InformeLibroDeVentasContentDAO {
protected ConnectionHolder connectionHolder;
public abstract HashMap<LocalDate, InformeLibroDeVentasContent> generateInformeMensual(YearMonth mes);
}

View File

@@ -1,72 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.models.informes.libro_de_ventas;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.HashMap;
import java.util.logging.Logger;
public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasContentDAO {
private static final Logger LOGGER = Logger
.getLogger(SQLiteInformeLibroDeVentasContentDAO.class.getName());
public SQLiteInformeLibroDeVentasContentDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public HashMap<LocalDate, InformeLibroDeVentasContent> generateInformeMensual(YearMonth date) {
HashMap<LocalDate, InformeLibroDeVentasContent> informe = new HashMap<>();
return informe;
}
}

View File

@@ -37,6 +37,7 @@ import java.sql.SQLException;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -66,6 +67,15 @@ public abstract class IngresoDAO {
public abstract int getTotalExentasMes(YearMonth mes);
public abstract int getTotalIngresoEnCajaPorTipo(Caja caja, TipoIngreso tipoIngreso);
public abstract Optional<String> getPrimerNroInicialDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso);
public abstract Optional<String> getUltimoNroFinalDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso);
public abstract Optional<String> getPrimerNroZInicialDeCaja(Caja caja);
public abstract Optional<String> getUltimoNroZFinalDeCaja(Caja caja);
List<Ingreso> ingresosFromResultSet(ResultSet rs) throws SQLException {
ArrayList<Ingreso> ingresosList = new ArrayList<>();

View File

@@ -35,6 +35,7 @@ import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -49,38 +50,34 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public List<Ingreso> findAll() {
List<Ingreso> ingresosList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
String query = "select * from ingresos";
PreparedStatement ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery();
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
try (ResultSet rs = ps.executeQuery()) {
LOGGER.log(Level.FINE, "QUERY: {0}", query);
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return ingresosList;
}
@Override
public List<Ingreso> findByCaja(Caja caja) {
List<Ingreso> ingresosList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
String query = "select * from ingresos where caja_id = ?";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
try (ResultSet rs = ps.executeQuery()) {
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
}
}
} catch (SQLException e) {
e.printStackTrace();
}
@@ -90,18 +87,16 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public List<Ingreso> findById(int id) {
List<Ingreso> ingresosList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
String query = "select * from ingresos where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
try (ResultSet rs = ps.executeQuery()) {
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
@@ -111,18 +106,16 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso) {
List<Ingreso> ingresosList = new ArrayList<>();
try (Connection conn = connectionHolder.getConnection()) {
String query = "select ingresos.* from ingresos inner join tipos_ingreso on (ingresos.tipo_ingreso_id = tipos_ingreso.id) where ingresos.tipo_ingreso_id = ?";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, tipoIngreso.getId());
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, tipoIngreso.getId()});
try (ResultSet rs = ps.executeQuery()) {
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}",
new Object[]{query, tipoIngreso.getId()});
ingresosList = this.ingresosFromResultSet(rs);
rs.close();
ps.close();
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
@@ -132,9 +125,9 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public boolean insertIngreso(Ingreso ingreso) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
String query = "insert into ingresos (valor, nro_z_inicial, nro_z_final, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?,?,?)";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, ingreso.getValor());
ps.setString(2, ingreso.getNroZInicial());
ps.setString(3, ingreso.getNroZFinal());
@@ -145,18 +138,18 @@ public class SQLiteIngresoDAO extends IngresoDAO {
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7}] | updates: {8}",
new Object[]{query, ingreso.getValor(), ingreso.getNroZInicial(), ingreso.getNroZFinal(),
new Object[]{query, ingreso.getValor(), ingreso.getNroZInicial(),
ingreso.getNroZFinal(),
ingreso.getNroInicial(), ingreso.getNroFinal(), ingreso.getTipoIngreso().getId(),
ingreso.getCaja().getId(), updates});
}
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) {
try (ResultSet rs = ps.executeQuery()) {
rs.next();
ingreso.setId(rs.getInt(1));
rs.close();
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
@@ -167,9 +160,9 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public boolean updateIngreso(Ingreso ingreso) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
String query = "update ingresos set valor = ?, nro_z_inicial = ?, nro_z_final = ?, nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, ingreso.getValor());
ps.setString(2, ingreso.getNroZInicial());
ps.setString(3, ingreso.getNroZFinal());
@@ -181,13 +174,13 @@ public class SQLiteIngresoDAO extends IngresoDAO {
updates = ps.executeUpdate();
LOGGER
.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8}] | updates: {9}",
.log(Level.FINE,
"QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8}] | updates: {9}",
new Object[]{query, ingreso.getValor(), ingreso.getNroZInicial(),
ingreso.getNroZFinal(), ingreso.getNroInicial(), ingreso.getNroFinal(),
ingreso.getTipoIngreso().getId(), ingreso.getCaja().getId(), ingreso.getId(),
updates});
ps.close();
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
@@ -198,16 +191,16 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public boolean deleteIngreso(Ingreso ingreso) {
int updates;
try (Connection conn = connectionHolder.getConnection()) {
String query = "delete from ingresos where id = ?";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, ingreso.getId());
updates = ps.executeUpdate();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}",
new Object[]{query, ingreso.getId(), updates});
ps.close();
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
return false;
@@ -218,19 +211,16 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public int getTotalIngreso(Caja caja) {
int total = 0;
try (Connection conn = connectionHolder.getConnection()) {
String query = "select sum(valor) from ingresos where caja_id = ?";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
rs.next();
try (ResultSet rs = ps.executeQuery()) {
if(rs.next()){
total = rs.getInt(1);
rs.close();
ps.close();
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
@@ -240,23 +230,21 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public int getTotalIngresoMes(YearMonth mes) {
int total = 0;
try (Connection conn = connectionHolder.getConnection()) {
LocalDate start = mes.atDay(1);
LocalDate end = mes.atEndOfMonth();
String query =
"select sum(valor) from ingresos inner join caja on (ingresos.caja_id == caja.id) where caja.fecha between ? and ? and ingresos.tipo_ingreso_id != 5";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
LocalDate start = mes.atDay(1);
LocalDate end = mes.atEndOfMonth();
ps.setString(1, start.toString());
ps.setString(2, end.toString());
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}, {2}", new Object[]{query, start, end});
rs.next();
try (ResultSet rs = ps.executeQuery()) {
if(rs.next()){
total = rs.getInt(1);
rs.close();
ps.close();
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
@@ -266,26 +254,143 @@ public class SQLiteIngresoDAO extends IngresoDAO {
@Override
public int getTotalExentasMes(YearMonth mes) {
int total = 0;
try (Connection conn = connectionHolder.getConnection()) {
LocalDate start = mes.atDay(1);
LocalDate end = mes.atEndOfMonth();
String query =
"select sum(valor) from ingresos inner join caja on (ingresos.caja_id == caja.id) where caja.fecha between ? and ? and ingresos.tipo_ingreso_id = 5";
PreparedStatement ps = conn.prepareStatement(query);
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
LocalDate start = mes.atDay(1);
LocalDate end = mes.atEndOfMonth();
ps.setString(1, start.toString());
ps.setString(2, end.toString());
ResultSet rs = ps.executeQuery();
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}, {2}", new Object[]{query, start, end});
rs.next();
try (ResultSet rs = ps.executeQuery()) {
if(rs.next()){
total = rs.getInt(1);
rs.close();
ps.close();
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}
@Override
public int getTotalIngresoEnCajaPorTipo(Caja caja, TipoIngreso tipoIngreso) {
if (caja == Caja.EMPTY) {
return 0;
}
int total = 0;
String query = "select sum(valor) from ingresos where caja_id = ? and tipo_ingreso_id = ?";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
ps.setInt(2, tipoIngreso.getId());
try (ResultSet rs = ps.executeQuery()) {
if(rs.next()){
total = rs.getInt(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}
@Override
public Optional<String> getPrimerNroInicialDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso) {
if (caja == Caja.EMPTY) {
return Optional.of("0");
}
String nroInicial = null;
String query = "select nro_inicial from ingresos where caja_id = ? and tipo_ingreso_id = ? order by nro_inicial asc limit 1";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
ps.setInt(2, tipoIngreso.getId());
try (ResultSet rs = ps.executeQuery()) {
if(rs.next()) {
nroInicial = rs.getString(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return Optional.ofNullable(nroInicial);
}
@Override
public Optional<String> getUltimoNroFinalDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso) {
if (caja == Caja.EMPTY) {
return Optional.of("0");
}
String nroFinal = null;
String query = "select nro_final from ingresos where caja_id = ? and tipo_ingreso_id = ? order by nro_inicial desc limit 1";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
ps.setInt(2, tipoIngreso.getId());
try (ResultSet rs = ps.executeQuery()) {
if(rs.next()){
nroFinal = rs.getString(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
e.printStackTrace();
}
return Optional.ofNullable(nroFinal);
}
@Override
public Optional<String> getPrimerNroZInicialDeCaja(Caja caja) {
if (caja == Caja.EMPTY) {
return Optional.of("0");
}
String nroZInicial = null;
String query = "select nro_z_inicial from ingresos where caja_id = ? and tipo_ingreso_id = 1 order by nro_inicial desc limit 1";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
try (ResultSet rs = ps.executeQuery()) {
if(rs.next()){
nroZInicial = rs.getString(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
e.printStackTrace();
}
return Optional.ofNullable(nroZInicial);
}
@Override
public Optional<String> getUltimoNroZFinalDeCaja(Caja caja) {
if (caja == Caja.EMPTY) {
return Optional.of("0");
}
String nroZFinal = null;
String query = "select nro_z_final from ingresos where caja_id = ? and tipo_ingreso_id = 1 order by nro_inicial desc limit 1";
try (Connection conn = connectionHolder.getConnection()) {
try(PreparedStatement ps = conn.prepareStatement(query)){
ps.setInt(1, caja.getId());
try(ResultSet rs = ps.executeQuery()){
if(rs.next()){
nroZFinal = rs.getString(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
e.printStackTrace();
}
return Optional.ofNullable(nroZFinal);
}
}

View File

@@ -0,0 +1,18 @@
package danielcortes.xyz.utils;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.poi.ss.usermodel.Workbook;
public class SaveFile {
public static void save(Workbook wb, Path saveFile){
try (OutputStream fileOut = Files.newOutputStream(saveFile)) {
wb.write(fileOut);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -64,13 +64,6 @@ public class ArqueoView {
private NumberFormatedTextField debeRendirField;
private NumberFormatedTextField retiroField;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
public JPanel getContentPanel() {
return contentPanel;
}
@@ -159,6 +152,13 @@ public class ArqueoView {
return retiroField;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
* call it in your code!
@@ -487,4 +487,5 @@ public class ArqueoView {
public JComponent $$$getRootComponent$$$() {
return contentPanel;
}
}

View File

@@ -13,13 +13,6 @@ public class BaseLayout {
private JPanel sidePanel;
private JPanel mainPanel;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
public JPanel getContentPanel() {
return contentPanel;
}
@@ -32,6 +25,13 @@ public class BaseLayout {
return mainPanel;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
* call it in your code!
@@ -63,4 +63,5 @@ public class BaseLayout {
public JComponent $$$getRootComponent$$$() {
return contentPanel;
}
}

View File

@@ -46,13 +46,6 @@ public class CajasView {
private JToggleButton arqueoButton;
private DatePicker datePicker;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
public JToggleButton getEgresosButton() {
return egresosButton;
}
@@ -77,6 +70,13 @@ public class CajasView {
return cardPanel;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
* call it in your code!

View File

@@ -67,13 +67,6 @@ public class EgresosView {
private EgresosTableModel egresosTableModel;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
private void createUIComponents() {
createEgresosTable();
createTipoCombo();
@@ -152,6 +145,13 @@ public class EgresosView {
return errorTipoEgreso;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
* call it in your code!

View File

@@ -18,6 +18,7 @@ import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.SpinnerModel;
public class EstadoResultadoView {
@@ -762,7 +763,7 @@ public class EstadoResultadoView {
SpinnerModel model = new YearSpinnerModel();
this.yearSpinner = new JSpinner();
this.yearSpinner.setModel(model);
((JSpinner.DefaultEditor) this.yearSpinner.getEditor()).getTextField().setEditable(true);
((DefaultEditor) this.yearSpinner.getEditor()).getTextField().setEditable(true);
}
private void createMonthCombo() {

View File

@@ -41,13 +41,6 @@ public class InformesSideBar {
private JButton estadoResultadoButton;
private JButton volverButton;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
public JPanel getContentPanel() {
return contentPanel;
}
@@ -68,6 +61,13 @@ public class InformesSideBar {
return volverButton;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
* call it in your code!

View File

@@ -70,13 +70,6 @@ public class IngresosView {
private IngresosTableModel ingresosTableModel;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
private void createUIComponents() {
this.createIngresosTable();
this.createTipoCombo();
@@ -171,6 +164,13 @@ public class IngresosView {
return errorNroZInicial;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
* call it in your code!

View File

@@ -16,13 +16,6 @@ public class MainSideBar {
private JButton cajasButton;
private JPanel buttonPanel;
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
public JPanel getContentPanel() {
return contentPanel;
}
@@ -39,6 +32,13 @@ public class MainSideBar {
return cajasButton;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer >>> IMPORTANT!! <<< DO NOT edit this method OR
* call it in your code!

View File

@@ -41,6 +41,7 @@ import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.KeyStroke;
import javax.swing.SpinnerModel;
@@ -120,7 +121,7 @@ public class MonthSelectDialog extends JDialog {
SpinnerModel model = new YearSpinnerModel();
this.yearSpinner = new JSpinner();
this.yearSpinner.setModel(model);
((JSpinner.DefaultEditor) this.yearSpinner.getEditor()).getTextField().setEditable(true);
((DefaultEditor) this.yearSpinner.getEditor()).getTextField().setEditable(true);
}
private void createMonthCombo() {