diff --git a/dist/Programa Caja.jar b/dist/Programa Caja.jar index e2aa040..e2eb484 100644 Binary files a/dist/Programa Caja.jar and b/dist/Programa Caja.jar differ diff --git a/src/danielcortes/xyz/controllers/InformesSideBarController.java b/src/danielcortes/xyz/controllers/InformesSideBarController.java index 03dcde6..b2a9bac 100644 --- a/src/danielcortes/xyz/controllers/InformesSideBarController.java +++ b/src/danielcortes/xyz/controllers/InformesSideBarController.java @@ -27,6 +27,8 @@ package danielcortes.xyz.controllers; import danielcortes.xyz.data.Configuration; import danielcortes.xyz.informes.InformeEgresosToExcel; import danielcortes.xyz.informes.InformeLibroDeVentasToExcel; +import danielcortes.xyz.informes.InformeResumenArqueo; +import danielcortes.xyz.informes.InformeResumenArqueoToExcel; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; import danielcortes.xyz.utils.SaveFile; import danielcortes.xyz.utils.StringUtils; @@ -58,6 +60,8 @@ public class InformesSideBarController { .addActionListener(e -> generarInformeLibroDeVentasListener()); this.view.getGenerarEgresosFacturasMateriaPrimaButton() .addActionListener(e -> generarInformeEgresosListener()); + this.view.getGenerarResumenArqueoButton() + .addActionListener(e -> generarInformeResumenArqueoListener()); } private void generarInformeLibroDeVentasListener() { @@ -112,4 +116,30 @@ public class InformesSideBarController { new InformeGeneratedConfirmation(saveFile).execute(); } + + private void generarInformeResumenArqueoListener() { + System.out.println("Executed"); + YearMonth mes = new MonthSelectDialog().execute(); + if (mes == null) { + return; + } + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy"); + String formatedName = mes.format(formatter); + String capitalized = StringUtils.capitalize(formatedName); + + Path saveFile = new XLSFileChooser( + Configuration.get("base_save_directory") + "Resumen Arqueo" + capitalized).execute(); + + if (saveFile == null) { + return; + } + + InformeResumenArqueo informe = InformeResumenArqueo.generate(mes); + Workbook wb = new InformeResumenArqueoToExcel(informe).generarInforme(); + SaveFile.save(wb, saveFile); + + new InformeGeneratedConfirmation(saveFile).execute(); + System.out.println(informe); + } } diff --git a/src/danielcortes/xyz/informes/InformeResumenArqueo.java b/src/danielcortes/xyz/informes/InformeResumenArqueo.java new file mode 100644 index 0000000..2b4c981 --- /dev/null +++ b/src/danielcortes/xyz/informes/InformeResumenArqueo.java @@ -0,0 +1,89 @@ +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.documentos.Documentos; +import danielcortes.xyz.models.documentos.DocumentosDAO; +import danielcortes.xyz.models.efectivo.EfectivoDAO; +import danielcortes.xyz.models.egreso.EgresoDAO; +import danielcortes.xyz.models.ingreso.IngresoDAO; +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.HashMap; + +public class InformeResumenArqueo { + + private HashMap informe; + private YearMonth mes; + + private InformeResumenArqueo(){} + + public ResumenArqueo get(LocalDate localDate) { + return informe.get(localDate); + } + + private void put(LocalDate localDate, ResumenArqueo resumenArqueo) { + informe.put(localDate, resumenArqueo); + } + + public int size(){ + return informe.size(); + } + + public YearMonth getMes(){ + return mes; + } + + public static InformeResumenArqueo generate(YearMonth mes){ + InformeResumenArqueo informeResumenArqueo = new InformeResumenArqueo(); + informeResumenArqueo.informe = new HashMap<>(); + informeResumenArqueo.mes = mes; + + LocalDate currentDate = mes.atDay(1); + LocalDate endDatePlusOne = mes.atEndOfMonth().plusDays(1); + + CajaDAO cajaDAO = DAOManager.getCajaDAO(); + EfectivoDAO efectivoDAO = DAOManager.getEfectivoDAO(); + EgresoDAO egresoDAO = DAOManager.getEgresoDAO(); + IngresoDAO ingresoDAO = DAOManager.getIngresoDAO(); + DocumentosDAO documentosDAO = DAOManager.getDocumentosDAO(); + + while (currentDate.isBefore(endDatePlusOne)) { + ResumenArqueo resumenArqueo = new ResumenArqueo(); + Caja caja = cajaDAO.getByFecha(currentDate).orElse(Caja.EMPTY); + Documentos documentos = documentosDAO.getByCaja(caja).orElse(Documentos.EMPTY); + + int efectivo = efectivoDAO.getTotalEfectivo(caja); + int cheques = documentos.getCheques(); + int tarjetasCredito = documentos.getTarjetas(); + int retiros = documentos.getRetiros(); + int egresos = egresoDAO.getTotalEgreso(caja); + int debeRendir = ingresoDAO.getTotalIngreso(caja); + + resumenArqueo.setEfectivo(efectivo); + resumenArqueo.setCheques(cheques); + resumenArqueo.setTarjetaCredito(tarjetasCredito); + resumenArqueo.setRetiros(retiros); + resumenArqueo.setEgresos(egresos); + resumenArqueo.setDebeRendir(debeRendir); + + informeResumenArqueo.put(currentDate, resumenArqueo); + currentDate = currentDate.plusDays(1); + } + + return informeResumenArqueo; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for(LocalDate localDate: informe.keySet()){ + sb.append(localDate); + sb.append(":"); + sb.append(informe.get(localDate)); + sb.append("\n"); + } + return sb.toString(); + } +} diff --git a/src/danielcortes/xyz/informes/InformeResumenArqueoToExcel.java b/src/danielcortes/xyz/informes/InformeResumenArqueoToExcel.java new file mode 100644 index 0000000..672ff03 --- /dev/null +++ b/src/danielcortes/xyz/informes/InformeResumenArqueoToExcel.java @@ -0,0 +1,224 @@ +package danielcortes.xyz.informes; + +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.BorderExtent; +import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.CreationHelper; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.PropertyTemplate; + +public class InformeResumenArqueoToExcel { + + private final String[] dias = { + "LUNES", "MARTES", "MIERCOLES", "JUEVES", "VIERNES", "SABADO", "DOMINGO" + }; + private InformeResumenArqueo informe; + + private Row titles; + private ArrayList dataRow; + private Row totalesRow; + + private Workbook wb; + private Sheet sheet; + private CreationHelper createHelper; + private HashMap styles; + + public InformeResumenArqueoToExcel(InformeResumenArqueo informe) { + this.informe = informe; + this.wb = new HSSFWorkbook(); + this.sheet = wb.createSheet(); + this.createHelper = wb.getCreationHelper(); + + this.dataRow = new ArrayList<>(); + + this.styles = this.generateStyles(); + } + + private void fillHeaders() { + this.titles = sheet.createRow(0); + int currentCell = 0; + this.titles.createCell(currentCell++).setCellValue("Dia"); + this.titles.createCell(currentCell++).setCellValue("Fecha"); + this.titles.createCell(currentCell++).setCellValue("Efectivo"); + this.titles.createCell(currentCell++).setCellValue("Cheques"); + this.titles.createCell(currentCell++).setCellValue("T Credito"); + this.titles.createCell(currentCell++).setCellValue("Retiros"); + this.titles.createCell(currentCell++).setCellValue("Egresos"); + this.titles.createCell(currentCell++).setCellValue("Rendido"); + this.titles.createCell(currentCell++).setCellValue("Debe Rendir"); + this.titles.createCell(currentCell).setCellValue("Diferencia"); + } + + private void fillData() { + int currentRow = 1; + + LocalDate currentDay = this.informe.getMes().atDay(1); + LocalDate endDayPlusOne = this.informe.getMes().atEndOfMonth().plusDays(1); + + while (currentDay.isBefore(endDayPlusOne)) { + int currentCell = 0; + + Row row = sheet.createRow(currentRow++); + ResumenArqueo informe = this.informe.get(currentDay); + + row.createCell(currentCell++).setCellValue(this.dias[currentDay.getDayOfWeek().getValue()-1]); + Date fecha = Date.from(currentDay.atStartOfDay(ZoneId.systemDefault()).toInstant()); + row.createCell(currentCell++).setCellValue(fecha); + row.createCell(currentCell++).setCellValue(informe.getEfectivo()); + row.createCell(currentCell++).setCellValue(informe.getCheques()); + row.createCell(currentCell++).setCellValue(informe.getTarjetaCredito()); + row.createCell(currentCell++).setCellValue(informe.getRetiros()); + row.createCell(currentCell++).setCellValue(informe.getEgresos()); + row.createCell(currentCell++).setCellFormula("SUM(C" + currentRow + ":G" + currentRow + ")"); + row.createCell(currentCell++).setCellValue(informe.getDebeRendir()); + row.createCell(currentCell++).setCellFormula("H" + currentRow + "-I" + currentRow); + + dataRow.add(row); + currentDay = currentDay.plusDays(1); + } + } + + private void fillTotal() { + int lastRow = dataRow.size() + 1; + int currentRow = dataRow.size() + 1; + int currentCell = 0; + totalesRow = sheet.createRow(currentRow); + + totalesRow.createCell(currentCell++).setCellValue("Totales"); + totalesRow.createCell(currentCell++); + totalesRow.createCell(currentCell++).setCellFormula("SUM(C2:C" + lastRow + ")"); + totalesRow.createCell(currentCell++).setCellFormula("SUM(D2:D" + lastRow + ")"); + totalesRow.createCell(currentCell++).setCellFormula("SUM(E2:E" + lastRow + ")"); + totalesRow.createCell(currentCell++).setCellFormula("SUM(F2:F" + lastRow + ")"); + totalesRow.createCell(currentCell++).setCellFormula("SUM(G2:G" + lastRow + ")"); + totalesRow.createCell(currentCell++).setCellFormula("SUM(H2:H" + lastRow + ")"); + totalesRow.createCell(currentCell++).setCellFormula("SUM(I2:I" + lastRow + ")"); + totalesRow.createCell(currentCell++).setCellFormula("SUM(J2:J" + lastRow + ")"); + } + + private void setStyles() { + this.titles.cellIterator().forEachRemaining( + (cell) -> cell.setCellStyle(this.styles.get("header")) + ); + + this.totalesRow.cellIterator().forEachRemaining( + (cell) -> cell.setCellStyle(this.styles.get("total")) + ); + + for(Row row: this.dataRow){ + int currentCell = 0; + row.getCell(currentCell++).setCellStyle(this.styles.get("not_so_gray")); + row.getCell(currentCell++).setCellStyle(this.styles.get("date")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + row.getCell(currentCell++).setCellStyle(this.styles.get("money")); + } + + for(int x = 0; x < 10; x++){ + this.sheet.autoSizeColumn(x); + } + + for(int x = 0; x < dataRow.size() + 2; x++) { + this.sheet.getRow(x).setHeightInPoints(15); + } + } + + private void addBorders() { + int size = dataRow.size() + 2; + PropertyTemplate pt = new PropertyTemplate(); + pt.drawBorders(new CellRangeAddress(0, size - 1, 0, 9), BorderStyle.THIN, BorderExtent.ALL); + pt.applyBorders(this.sheet); + } + + private void freezeCells() { + this.sheet.createFreezePane(2, 1); + } + + public Workbook generarInforme() { + fillHeaders(); + fillData(); + fillTotal(); + setStyles(); + addBorders(); + freezeCells(); + + return this.wb; + } + + public HashMap generateStyles() { + Font font = this.wb.createFont(); + font.setBold(true); + font.setColor(IndexedColors.WHITE.getIndex()); + + CellStyle regularStyle = this.wb.createCellStyle(); + + CellStyle grayStyle = this.wb.createCellStyle(); + grayStyle.setFont(font); + grayStyle.setVerticalAlignment(VerticalAlignment.CENTER); + grayStyle.setFillForegroundColor(IndexedColors.GREY_80_PERCENT.getIndex()); + grayStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + CellStyle notSoGrayStyle = this.wb.createCellStyle(); + notSoGrayStyle.setFont(font); + notSoGrayStyle.setVerticalAlignment(VerticalAlignment.CENTER); + notSoGrayStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); + notSoGrayStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + CellStyle dateStyle = this.wb.createCellStyle(); + dateStyle.cloneStyleFrom(notSoGrayStyle); + dateStyle.setDataFormat(this.createHelper.createDataFormat().getFormat("dd/mm/yyyy")); + + CellStyle moneyStyle = this.wb.createCellStyle(); + moneyStyle + .setDataFormat( + this.createHelper.createDataFormat().getFormat("[$$-340A]#,##0;[RED][$$-340A] -#,##0")); + + CellStyle headerStyle = this.wb.createCellStyle(); + headerStyle.cloneStyleFrom(notSoGrayStyle); + headerStyle.setAlignment(HorizontalAlignment.CENTER); + + CellStyle totalStyle = this.wb.createCellStyle(); + totalStyle.cloneStyleFrom(notSoGrayStyle); + totalStyle + .setDataFormat( + this.createHelper.createDataFormat().getFormat("[$$-340A]#,##0;[RED][$$-340A] -#,##0")); + + CellStyle totalFinalStyle = this.wb.createCellStyle(); + totalFinalStyle.cloneStyleFrom(notSoGrayStyle); + totalFinalStyle + .setDataFormat( + this.createHelper.createDataFormat().getFormat("[$$-340A]#,##0;[RED][$$-340A] -#,##0")); + + HashMap styles = new HashMap<>(); + styles.put("regular", regularStyle); + styles.put("gray", grayStyle); + styles.put("not_so_gray", notSoGrayStyle); + styles.put("date", dateStyle); + styles.put("money", moneyStyle); + styles.put("header", headerStyle); + styles.put("total", totalStyle); + styles.put("total_final", totalFinalStyle); + + return styles; + } + +} diff --git a/src/danielcortes/xyz/informes/ResumenArqueo.java b/src/danielcortes/xyz/informes/ResumenArqueo.java new file mode 100644 index 0000000..fd5671a --- /dev/null +++ b/src/danielcortes/xyz/informes/ResumenArqueo.java @@ -0,0 +1,70 @@ +package danielcortes.xyz.informes; + +public class ResumenArqueo { + private int efectivo; + private int cheques; + private int tarjetaCredito; + private int retiros; + private int egresos; + private int debeRendir; + + public int getEfectivo() { + return efectivo; + } + + public void setEfectivo(int efectivo) { + this.efectivo = efectivo; + } + + public int getCheques() { + return cheques; + } + + public void setCheques(int cheques) { + this.cheques = cheques; + } + + public int getTarjetaCredito() { + return tarjetaCredito; + } + + public void setTarjetaCredito(int tarjetaCredito) { + this.tarjetaCredito = tarjetaCredito; + } + + public int getRetiros() { + return retiros; + } + + public void setRetiros(int retiros) { + this.retiros = retiros; + } + + public int getEgresos() { + return egresos; + } + + public void setEgresos(int egresos) { + this.egresos = egresos; + } + + public int getDebeRendir() { + return debeRendir; + } + + public void setDebeRendir(int debeRendir) { + this.debeRendir = debeRendir; + } + + @Override + public String toString() { + return "ResumenArqueo{" + + "efectivo=" + efectivo + + ", cheques=" + cheques + + ", tarjetaCredito=" + tarjetaCredito + + ", retiros=" + retiros + + ", egresos=" + egresos + + ", debeRendir=" + debeRendir + + '}'; + } +} diff --git a/src/danielcortes/xyz/views/InformesSideBar.form b/src/danielcortes/xyz/views/InformesSideBar.form index aaa32ac..d1edfe8 100644 --- a/src/danielcortes/xyz/views/InformesSideBar.form +++ b/src/danielcortes/xyz/views/InformesSideBar.form @@ -8,7 +8,7 @@ - + @@ -34,12 +34,12 @@ - + - + @@ -47,12 +47,20 @@ - + + + + + + + + + diff --git a/src/danielcortes/xyz/views/InformesSideBar.java b/src/danielcortes/xyz/views/InformesSideBar.java index e86acd4..f317a2b 100644 --- a/src/danielcortes/xyz/views/InformesSideBar.java +++ b/src/danielcortes/xyz/views/InformesSideBar.java @@ -39,6 +39,7 @@ public class InformesSideBar { private JPanel contentPanel; private JButton GenerarEgresosFacturasMateriaPrimaButton; private JButton estadoResultadoButton; + private JButton generarResumenArqueoButton; private JButton volverButton; public JPanel getContentPanel() { @@ -57,6 +58,10 @@ public class InformesSideBar { return estadoResultadoButton; } + public JButton getGenerarResumenArqueoButton() { + return generarResumenArqueoButton; + } + public JButton getVolverButton() { return volverButton; } @@ -78,7 +83,7 @@ public class InformesSideBar { contentPanel = new JPanel(); contentPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); final JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayoutManager(5, 1, new Insets(10, 10, 10, 10), -1, -1)); + panel1.setLayout(new GridLayoutManager(6, 1, new Insets(10, 10, 10, 10), -1, -1)); contentPanel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, @@ -101,21 +106,28 @@ public class InformesSideBar { GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final Spacer spacer1 = new Spacer(); - panel1.add(spacer1, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, + panel1.add(spacer1, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); estadoResultadoButton = new JButton(); estadoResultadoButton.setText("Estado Resultado"); - panel1.add(estadoResultadoButton, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, + panel1.add(estadoResultadoButton, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); volverButton = new JButton(); volverButton.setText("Volver"); - panel1.add(volverButton, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, + panel1.add(volverButton, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + generarResumenArqueoButton = new JButton(); + generarResumenArqueoButton.setText("Resumen Arqueo"); + panel1.add(generarResumenArqueoButton, + new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, + GridConstraints.FILL_HORIZONTAL, + GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, + GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } /**