Nuevo informe!!

Se me olvido hacer check-out a una nueva branch, I tried :c
This commit is contained in:
Daniel Cortes
2019-03-15 23:55:20 -03:00
parent 7adffc835e
commit ada25ed373
7 changed files with 441 additions and 8 deletions

BIN
dist/Programa Caja.jar vendored

Binary file not shown.

View File

@@ -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);
}
}

View File

@@ -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<LocalDate, ResumenArqueo> 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();
}
}

View File

@@ -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<Row> dataRow;
private Row totalesRow;
private Workbook wb;
private Sheet sheet;
private CreationHelper createHelper;
private HashMap<String, CellStyle> 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<String, CellStyle> 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<String, CellStyle> 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;
}
}

View File

@@ -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 +
'}';
}
}

View File

@@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="ae41b" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="ae41b" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -34,12 +34,12 @@
</component>
<vspacer id="91971">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="354cd" class="javax.swing.JButton" binding="estadoResultadoButton" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Estado Resultado"/>
@@ -47,12 +47,20 @@
</component>
<component id="95688" class="javax.swing.JButton" binding="volverButton" default-binding="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Volver"/>
</properties>
</component>
<component id="42dc7" class="javax.swing.JButton" binding="generarResumenArqueoButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Resumen Arqueo"/>
</properties>
</component>
</children>
</grid>
</children>

View File

@@ -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,18 +106,25 @@ 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));