diff --git a/dist/local-release/Programa Caja.jar b/dist/local-release/Programa Caja.jar index 8223546..1550071 100644 Binary files a/dist/local-release/Programa Caja.jar and b/dist/local-release/Programa Caja.jar differ diff --git a/src/danielcortes/xyz/informes/InformeEgresos.java b/src/danielcortes/xyz/informes/InformeEgresos.java index dcf4381..f089f2b 100644 --- a/src/danielcortes/xyz/informes/InformeEgresos.java +++ b/src/danielcortes/xyz/informes/InformeEgresos.java @@ -111,6 +111,7 @@ public class InformeEgresos { dataRow.createCell(cellCounter++).setCellValue(data.getDescripcion()); dataRow.createCell(cellCounter).setCellValue(data.getValor()); + // Comprueba si es que el siguiente elemento en la lista de informe es del siguiente dia, si es asi, agrega una linea con los totales diarios. if (informeID + 1 >= informe.size() || !data.getFecha().equals(informe.get(informeID + 1).getFecha())) { totalRows.add(sheet.createRow(rowCounter + 1)); diff --git a/src/danielcortes/xyz/informes/InformeLibroDeVentas.java b/src/danielcortes/xyz/informes/InformeLibroDeVentas.java index dc57477..c94f498 100644 --- a/src/danielcortes/xyz/informes/InformeLibroDeVentas.java +++ b/src/danielcortes/xyz/informes/InformeLibroDeVentas.java @@ -66,9 +66,12 @@ public class InformeLibroDeVentas { private final String[] dias = {"Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"}; private ArrayList informe; - private int informeSize; private Path saveFile; + private ArrayList dataRows; + private Row footerRow; + private ArrayList headerRows; + private Workbook wb; private Sheet sheet; private CreationHelper createHelper; @@ -78,9 +81,11 @@ public class InformeLibroDeVentas { new SQLiteCajaDAO().createCajasForMonth(date); this.informe = new ArrayList<>(DAOManager.getLibroDeVentasContentDAO().getInformeMensual(date)); - this.informeSize = this.informe.size(); this.saveFile = saveFile; + this.dataRows = new ArrayList<>(); + this.headerRows = new ArrayList<>(); + this.wb = new HSSFWorkbook(); this.sheet = wb.createSheet(); this.createHelper = wb.getCreationHelper(); @@ -96,6 +101,9 @@ public class InformeLibroDeVentas { Row titles = sheet.createRow(0); Row subtitles = sheet.createRow(1); + headerRows.add(titles); + headerRows.add(subtitles); + for (int x = 0; x < this.titles.length; x++) { titles.createCell(x).setCellValue(this.titles[x]); } @@ -106,63 +114,62 @@ public class InformeLibroDeVentas { } private void fillData() { - int x = 2; + int rowCounter = 2; for (InformeLibroDeVentasContent data : this.informe) { - int y = 0; - Row dataRow = sheet.createRow(x); - + int cellCounter = 0; + Row dataRow = sheet.createRow(rowCounter); + dataRows.add(dataRow); Date fecha = Date.from(data.getFecha().atStartOfDay(ZoneId.systemDefault()).toInstant()); - dataRow.createCell(y++).setCellValue(this.dias[data.getDia()]); - dataRow.createCell(y++).setCellValue(fecha); + dataRow.createCell(cellCounter++).setCellValue(this.dias[data.getDia()]); + dataRow.createCell(cellCounter++).setCellValue(fecha); - 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()); + dataRow.createCell(cellCounter++).setCellValue(data.getManualesInicial() == null ? "0" : data.getManualesInicial()); + dataRow.createCell(cellCounter++).setCellValue(data.getManualesFinal() == null ? "0" : data.getManualesFinal()); + dataRow.createCell(cellCounter++).setCellValue(data.getManuales()); - dataRow.createCell(y++).setCellValue(data.getFiscalesZInicial() == null ? "0" : data.getFiscalesZInicial()); - dataRow.createCell(y++).setCellValue(data.getFiscalesZFinal() == null ? "0" : data.getFiscalesZFinal()); - dataRow.createCell(y++).setCellValue(data.getFiscalesInicial() == null ? "0" : data.getFiscalesInicial()); - dataRow.createCell(y++).setCellValue(data.getFiscalesFinal() == null ? "0" : data.getFiscalesFinal()); - dataRow.createCell(y++).setCellValue(data.getFiscales()); + dataRow.createCell(cellCounter++).setCellValue(data.getFiscalesZInicial() == null ? "0" : data.getFiscalesZInicial()); + dataRow.createCell(cellCounter++).setCellValue(data.getFiscalesZFinal() == null ? "0" : data.getFiscalesZFinal()); + dataRow.createCell(cellCounter++).setCellValue(data.getFiscalesInicial() == null ? "0" : data.getFiscalesInicial()); + dataRow.createCell(cellCounter++).setCellValue(data.getFiscalesFinal() == null ? "0" : data.getFiscalesFinal()); + dataRow.createCell(cellCounter++).setCellValue(data.getFiscales()); - dataRow.createCell(y++).setCellValue(data.getExentasInicial() == null ? "0" : data.getExentasInicial()); - dataRow.createCell(y++).setCellValue(data.getExentasFinal() == null ? "0" : data.getExentasFinal()); - dataRow.createCell(y++).setCellValue(data.getExentas()); + dataRow.createCell(cellCounter++).setCellValue(data.getExentasInicial() == null ? "0" : data.getExentasInicial()); + dataRow.createCell(cellCounter++).setCellValue(data.getExentasFinal() == null ? "0" : data.getExentasFinal()); + dataRow.createCell(cellCounter++).setCellValue(data.getExentas()); - dataRow.createCell(y++).setCellValue(data.getSubTotal()); + dataRow.createCell(cellCounter++).setCellValue(data.getSubTotal()); - dataRow.createCell(y++).setCellValue(data.getFacturasInicial() == null ? "0" : data.getFacturasInicial()); - dataRow.createCell(y++).setCellValue(data.getFacturasFinal() == null ? "0" : data.getFacturasFinal()); - dataRow.createCell(y++).setCellValue(data.getFacturas()); + dataRow.createCell(cellCounter++).setCellValue(data.getFacturasInicial() == null ? "0" : data.getFacturasInicial()); + dataRow.createCell(cellCounter++).setCellValue(data.getFacturasFinal() == null ? "0" : data.getFacturasFinal()); + dataRow.createCell(cellCounter++).setCellValue(data.getFacturas()); - dataRow.createCell(y++).setCellValue(data.getGuiasInicial() == null ? "0" : data.getGuiasInicial()); - dataRow.createCell(y++).setCellValue(data.getGuiasFinal() == null ? "0" : data.getGuiasFinal()); - dataRow.createCell(y++).setCellValue(data.getGuias()); + dataRow.createCell(cellCounter++).setCellValue(data.getGuiasInicial() == null ? "0" : data.getGuiasInicial()); + dataRow.createCell(cellCounter++).setCellValue(data.getGuiasFinal() == null ? "0" : data.getGuiasFinal()); + dataRow.createCell(cellCounter++).setCellValue(data.getGuias()); - dataRow.createCell(y++).setCellValue(data.getTotal()); + dataRow.createCell(cellCounter++).setCellValue(data.getTotal()); - if (x == 2) { - dataRow.createCell(y).setCellFormula(("U" + (x + 1))); + if (rowCounter == 2) { + dataRow.createCell(cellCounter).setCellFormula(("U" + (rowCounter + 1))); } else { - dataRow.createCell(y).setCellFormula(("U" + (x + 1)) + ("+") + ("V" + (x))); + dataRow.createCell(cellCounter).setCellFormula(("U" + (rowCounter + 1)) + ("+") + ("V" + (rowCounter))); } - x++; + rowCounter++; } } private void fillTotales() { - int row = 2 + this.informeSize; - Row totalesRow = sheet.createRow(row); + int row = 2 + this.informe.size(); + this.footerRow = sheet.createRow(row); - totalesRow.createCell(0).setCellValue("TOTALES"); - - totalesRow.createCell(4).setCellFormula("SUM(E" + 3 + ":E" + row + ")"); - totalesRow.createCell(9).setCellFormula("SUM(J" + 3 + ":J" + row + ")"); - totalesRow.createCell(12).setCellFormula("SUM(M" + 3 + ":M" + row + ")"); - totalesRow.createCell(16).setCellFormula("SUM(Q" + 3 + ":Q" + row + ")"); - totalesRow.createCell(19).setCellFormula("SUM(T" + 3 + ":T" + row + ")"); + this.footerRow.createCell(0).setCellValue("TOTALES"); + this.footerRow.createCell(4).setCellFormula("SUM(E" + 3 + ":E" + row + ")"); + this.footerRow.createCell(9).setCellFormula("SUM(J" + 3 + ":J" + row + ")"); + this.footerRow.createCell(12).setCellFormula("SUM(M" + 3 + ":M" + row + ")"); + this.footerRow.createCell(16).setCellFormula("SUM(Q" + 3 + ":Q" + row + ")"); + this.footerRow.createCell(19).setCellFormula("SUM(T" + 3 + ":T" + row + ")"); } private void joinCells() { @@ -215,21 +222,16 @@ public class InformeLibroDeVentas { private void setStyles() { //Estilos para los 2 filas de titulos - Iterator cellIterator = this.sheet.getRow(0).cellIterator(); - while (cellIterator.hasNext()) { - Cell cell = cellIterator.next(); - cell.setCellStyle(this.styles.get("header")); - } - - cellIterator = this.sheet.getRow(1).cellIterator(); - while (cellIterator.hasNext()) { - Cell cell = cellIterator.next(); - cell.setCellStyle(this.styles.get("header")); + for(Row header: headerRows){ + Iterator cellIterator = header.cellIterator(); + while (cellIterator.hasNext()) { + Cell cell = cellIterator.next(); + cell.setCellStyle(this.styles.get("header")); + } } //Estilos para las celdas de los datos - for (int x = 2; x < this.informeSize + 2; x++) { - Row row = this.sheet.getRow(x); + for (Row row: dataRows) { int y = 0; //Primeras Celdas @@ -273,23 +275,22 @@ public class InformeLibroDeVentas { //Estilos para los totales del footer - Row footerRow = this.sheet.getRow(33); for (int x = 0; x < 23; x++) { - footerRow.getCell(x, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellStyle(this.styles.get("footer")); + this.footerRow.getCell(x, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellStyle(this.styles.get("footer")); } - footerRow.getCell(4).setCellStyle(this.styles.get("footer_money")); - footerRow.getCell(9).setCellStyle(this.styles.get("footer_money")); - footerRow.getCell(12).setCellStyle(this.styles.get("footer_money")); - footerRow.getCell(16).setCellStyle(this.styles.get("footer_money")); - footerRow.getCell(19).setCellStyle(this.styles.get("footer_money")); + this.footerRow.getCell(4).setCellStyle(this.styles.get("footer_money")); + this.footerRow.getCell(9).setCellStyle(this.styles.get("footer_money")); + this.footerRow.getCell(12).setCellStyle(this.styles.get("footer_money")); + this.footerRow.getCell(16).setCellStyle(this.styles.get("footer_money")); + this.footerRow.getCell(19).setCellStyle(this.styles.get("footer_money")); //Setea la altura para todas las filas - this.sheet.getRow(0).setHeightInPoints(20); - this.sheet.getRow(1).setHeightInPoints(30); - this.sheet.getRow(33).setHeightInPoints(20); + this.headerRows.get(0).setHeightInPoints(20); + this.headerRows.get(1).setHeightInPoints(30); + this.footerRow.setHeightInPoints(20); - for (int x = 2; x < 32; x++) { - this.sheet.getRow(x).setHeightInPoints(15); + for (Row row: dataRows) { + row.setHeightInPoints(15); } //Coloca el ancho como automatico en todas las columnas