Correccion de cosas .w. No estoy seguro que e hecho

This commit is contained in:
Daniel Cortes
2019-01-07 19:32:12 -03:00
parent 3ee8b5c10c
commit cb4ef76861
18 changed files with 1267 additions and 613 deletions

View File

@@ -0,0 +1,215 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package danielcortes.xyz;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.util.Map;
import java.util.HashMap;
import java.io.FileOutputStream;
/**
* A weekly timesheet created using Apache POI.
* Usage:
* TimesheetDemo -xls|xlsx
*
* @author Yegor Kozlov
*/
public class Demo {
private static final String[] titles = {
"Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
"Total\nHrs", "Overtime\nHrs", "Regular\nHrs"
};
private static Object[][] sample_data = {
{"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
{"Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0},
};
public static void main(String[] args) throws Exception {
Workbook wb = new HSSFWorkbook();
Map<String, CellStyle> styles = createStyles(wb);
Sheet sheet = wb.createSheet("Timesheet");
PrintSetup printSetup = sheet.getPrintSetup();
printSetup.setLandscape(true);
sheet.setFitToPage(true);
sheet.setHorizontallyCenter(true);
//title row
Row titleRow = sheet.createRow(0);
titleRow.setHeightInPoints(45);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue("Weekly Timesheet");
titleCell.setCellStyle(styles.get("title"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$L$1"));
//header row
Row headerRow = sheet.createRow(1);
headerRow.setHeightInPoints(40);
Cell headerCell;
for (int i = 0; i < titles.length; i++) {
headerCell = headerRow.createCell(i);
headerCell.setCellValue(titles[i]);
headerCell.setCellStyle(styles.get("header"));
}
int rownum = 2;
for (int i = 0; i < 10; i++) {
Row row = sheet.createRow(rownum++);
for (int j = 0; j < titles.length; j++) {
Cell cell = row.createCell(j);
if(j == 9){
//the 10th cell contains sum over week days, e.g. SUM(C3:I3)
String ref = "C" +rownum+ ":I" + rownum;
cell.setCellFormula("SUM("+ref+")");
cell.setCellStyle(styles.get("formula"));
} else if (j == 11){
cell.setCellFormula("J" +rownum+ "-K" + rownum);
cell.setCellStyle(styles.get("formula"));
} else {
cell.setCellStyle(styles.get("cell"));
}
}
}
//row with totals below
Row sumRow = sheet.createRow(rownum++);
sumRow.setHeightInPoints(35);
Cell cell;
cell = sumRow.createCell(0);
cell.setCellStyle(styles.get("formula"));
cell = sumRow.createCell(1);
cell.setCellValue("Total Hrs:");
cell.setCellStyle(styles.get("formula"));
for (int j = 2; j < 12; j++) {
cell = sumRow.createCell(j);
String ref = (char)('A' + j) + "3:" + (char)('A' + j) + "12";
cell.setCellFormula("SUM(" + ref + ")");
if(j >= 9) cell.setCellStyle(styles.get("formula_2"));
else cell.setCellStyle(styles.get("formula"));
}
rownum++;
sumRow = sheet.createRow(rownum++);
sumRow.setHeightInPoints(25);
cell = sumRow.createCell(0);
cell.setCellValue("Total Regular Hours");
cell.setCellStyle(styles.get("formula"));
cell = sumRow.createCell(1);
cell.setCellFormula("L13");
cell.setCellStyle(styles.get("formula_2"));
sumRow = sheet.createRow(rownum++);
sumRow.setHeightInPoints(25);
cell = sumRow.createCell(0);
cell.setCellValue("Total Overtime Hours");
cell.setCellStyle(styles.get("formula"));
cell = sumRow.createCell(1);
cell.setCellFormula("K13");
cell.setCellStyle(styles.get("formula_2"));
//set sample data
for (int i = 0; i < sample_data.length; i++) {
Row row = sheet.getRow(2 + i);
for (int j = 0; j < sample_data[i].length; j++) {
if(sample_data[i][j] == null) continue;
if(sample_data[i][j] instanceof String) {
row.getCell(j).setCellValue((String)sample_data[i][j]);
} else {
row.getCell(j).setCellValue((Double)sample_data[i][j]);
}
}
}
//finally set column widths, the width is measured in units of 1/256th of a character width
sheet.setColumnWidth(0, 30*256); //30 characters wide
for (int i = 2; i < 9; i++) {
sheet.setColumnWidth(i, 6*256); //6 characters wide
}
sheet.setColumnWidth(10, 10*256); //10 characters wide
// Write the output to a file
String file = "timesheet.xls";
FileOutputStream out = new FileOutputStream(file);
wb.write(out);
out.close();
}
/**
* Create a library of cell styles
*/
private static Map<String, CellStyle> createStyles(Workbook wb){
Map<String, CellStyle> styles = new HashMap<>();
CellStyle style;
Font titleFont = wb.createFont();
titleFont.setFontHeightInPoints((short)18);
titleFont.setBold(true);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(titleFont);
styles.put("title", style);
Font monthFont = wb.createFont();
monthFont.setFontHeightInPoints((short)11);
monthFont.setColor(IndexedColors.WHITE.getIndex());
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(monthFont);
style.setWrapText(true);
styles.put("header", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setWrapText(true);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(BorderStyle.THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
styles.put("cell", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
styles.put("formula", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
styles.put("formula_2", style);
return styles;
}
}

View File

@@ -26,6 +26,7 @@ package danielcortes.xyz;
import danielcortes.xyz.controllers.ManagerController;
import danielcortes.xyz.data.Properties;
import danielcortes.xyz.informes.InformeMensual;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
@@ -38,6 +39,8 @@ import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
import danielcortes.xyz.models.egreso.EgresoDAO;
import danielcortes.xyz.models.egreso.MysqlEgresoDAO;
import danielcortes.xyz.models.egreso.SQLiteEgresoDAO;
import danielcortes.xyz.models.informe.InformeMensualContent;
import danielcortes.xyz.models.informe.SQLiteInformeMensualContentDAO;
import danielcortes.xyz.models.ingreso.IngresoDAO;
import danielcortes.xyz.models.ingreso.MysqlIngresoDAO;
import danielcortes.xyz.models.ingreso.SQLiteIngresoDAO;
@@ -48,14 +51,17 @@ import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import danielcortes.xyz.views.ManagerView;
import org.mariuszgromada.math.mxparser.Expression;
import javax.swing.*;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.List;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
run();
}
private static void run() {
System.setProperty("awt.useSystemAAFontSettings", "on");
System.setProperty("swing.aatext", "true");
@@ -76,7 +82,7 @@ public class Main {
TipoEgresoDAO tipoEgresoDAO = null;
TipoIngresoDAO tipoIngresoDAO = null;
if(Properties.getInstance().getProperty("database_type").equals("mysql")){
if (Properties.getInstance().getProperty("database_type").equals("mysql")) {
cajaDAO = new MysqlCajaDAO();
documentosDAO = new MysqlDocumentosDAO();
efectivoDAO = new MysqlEfectivoDAO();
@@ -84,7 +90,7 @@ public class Main {
ingresoDAO = new MysqlIngresoDAO();
tipoEgresoDAO = new MysqlTipoEgresoDAO();
tipoIngresoDAO = new MysqlTipoIngresoDAO();
}else if(Properties.getInstance().getProperty("database_type").equals("sqlite")){
} else if (Properties.getInstance().getProperty("database_type").equals("sqlite")) {
cajaDAO = new SQLiteCajaDAO();
documentosDAO = new SQLiteDocumentosDAO();
efectivoDAO = new SQLiteEfectivoDAO();
@@ -105,6 +111,10 @@ public class Main {
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void test(){
InformeMensual informeMensual = new InformeMensual(LocalDate.now());
informeMensual.generarInforme();
}
}

View File

@@ -126,17 +126,7 @@ public class ArqueoController {
*/
private void updateResumenEfectivo() {
NumberFormatedTextField efectivoField = this.view.getEfectivoField();
int total = 0;
total += this.efectivo.getDiez();
total += this.efectivo.getCincuenta();
total += this.efectivo.getCien();
total += this.efectivo.getQuinientos();
total += this.efectivo.getMil();
total += this.efectivo.getDosMil();
total += this.efectivo.getCincoMil();
total += this.efectivo.getDiezMil();
total += this.efectivo.getVeinteMil();
int total = efectivoDAO.getTotalEfectivo(this.caja);
efectivoField.setValue(total);
}
@@ -145,10 +135,7 @@ public class ArqueoController {
*/
private void updateResumenDocumentos() {
NumberFormatedTextField documentosField = this.view.getDocumentosField();
int total = 0;
total += this.documentos.getCheques();
total += this.documentos.getTarjetas();
int total = documentosDAO.getTotalDocumentos(this.caja);
documentosField.setValue(total);
}
@@ -164,10 +151,9 @@ public class ArqueoController {
* Calcula los datos de arqueo, rendido y ajuste y los muestra en sus campos correspondientes
*/
private void updateResumenArqueo() {
int totalEfectivo = this.view.getEfectivoField().getValue();
int totalDocumentos = this.view.getDocumentosField().getValue();
int totalEgresos = this.view.getEgresosField().getValue();
int totalEfectivo = efectivoDAO.getTotalEfectivo(this.caja);
int totalDocumentos = documentosDAO.getTotalDocumentos(this.caja);
int totalEgresos = egresoDAO.getTotalEgreso(this.caja);
int totalIngresos = ingresoDAO.getTotalIngreso(this.caja);
int rendido = totalDocumentos + totalEfectivo + totalEgresos;
@@ -253,19 +239,19 @@ public class ArqueoController {
int diezMil = this.view.getDiezMilField().getValue();
int veinteMil = this.view.getVeinteMilField().getValue();
this.efectivo.setDiez(diez);
this.efectivo.setCincuenta(cincuenta);
this.efectivo.setCien(cien);
this.efectivo.setQuinientos(quinientos);
this.efectivo.setMil(mil);
this.efectivo.setDosMil(dosMil);
this.efectivo.setCincoMil(cincoMil);
this.efectivo.setDiezMil(diezMil);
this.efectivo.setVeinteMil(veinteMil);
this.efectivoDAO.updateEfectivo(efectivo);
this.efectivo.setDiez(diez);
this.efectivo.setCincuenta(cincuenta);
this.efectivo.setCien(cien);
this.efectivo.setQuinientos(quinientos);
this.efectivo.setMil(mil);
this.efectivo.setDosMil(dosMil);
this.efectivo.setCincoMil(cincoMil);
this.efectivo.setDiezMil(diezMil);
this.efectivo.setVeinteMil(veinteMil);
this.efectivoDAO.updateEfectivo(efectivo);
this.updateResumenEfectivo();
this.updateResumenArqueo();
this.updateResumenEfectivo();
this.updateResumenArqueo();
}
/**

View File

@@ -290,14 +290,12 @@ public class IngresosController {
private boolean validateInput(String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) {
this.hideErrorMessages();
boolean nroZInicialValidation = this.validateNroZInicial(nroZInicial);
boolean nroZFinalValidation = this.validateNroZFinal(nroZFinal);
boolean nroInicialValidation = this.validateNroInicial(nroInicial);
boolean nroFinalValidation = this.validateNroFinal(nroFinal);
boolean tipoIngresoValidation = this.validateTipoIngreso(tipoIngreso);
boolean cajaValidation = this.validateCaja(caja);
return nroZInicialValidation && nroZFinalValidation && nroInicialValidation && nroFinalValidation && tipoIngresoValidation && cajaValidation;
return nroInicialValidation && nroFinalValidation && tipoIngresoValidation && cajaValidation;
}
/**
@@ -309,50 +307,6 @@ public class IngresosController {
return caja != null;
}
/**
* 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
* @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true
*/
private boolean validateNroZInicial(String nroZInicial){
if (nroZInicial == null) {
this.view.getErrorNroInicial().setText("Hubo un problema con los datos");
this.view.getErrorNroInicial().setVisible(true);
return false;
}
if (nroZInicial.isEmpty()) {
this.view.getErrorNroInicial().setText("El campo esta vacio");
this.view.getErrorNroInicial().setVisible(true);
return false;
}
return true;
}
/**
* 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
* @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true
*/
private boolean validateNroZFinal(String nroZFinal){
if (nroZFinal == null) {
this.view.getErrorNroFinal().setText("Hubo un problema con los datos");
this.view.getErrorNroFinal().setVisible(true);
return false;
}
if (nroZFinal.isEmpty()) {
this.view.getErrorNroFinal().setText("El campo esta vacio");
this.view.getErrorNroFinal().setVisible(true);
return false;
}
return true;
}
/**
* Valida la variable nroInicial contra los casos
* - Es null
@@ -417,8 +371,6 @@ public class IngresosController {
*/
private void hideErrorMessages() {
this.view.getErrorTipoIngreso().setVisible(false);
this.view.getErrorNroZInicial().setVisible(false);
this.view.getErrorNroZFinal().setVisible(false);
this.view.getErrorNroInicial().setVisible(false);
this.view.getErrorNroFinal().setVisible(false);
}

View File

@@ -0,0 +1,130 @@
/*
* 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.informes;
import danielcortes.xyz.models.informe.InformeMensualContent;
import danielcortes.xyz.models.informe.SQLiteInformeMensualContentDAO;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
public class InformeMensual {
private final String[] titles = {"DIA", "FECHA", "FISCALES", "MANUALES", "FACTURAS", "GUIAS", "TOTAL", "ACUMULADO"};
private List<InformeMensualContent> informe;
private Workbook wb;
private Sheet sheet;
private CreationHelper createHelper;
private HashMap<String, CellStyle> styles;
public InformeMensual(LocalDate date){
this.informe = new SQLiteInformeMensualContentDAO().getInformeMensual(date);
this.wb = new HSSFWorkbook();
this.sheet = wb.createSheet();
this.createHelper = wb.getCreationHelper();
this.styles = this.generateStyles();
}
public void generarInforme(){
for (int x = 0; x < informe.size(); x++) {
InformeMensualContent data = informe.get(x);
Row dataRow = sheet.createRow(x + 1);
Date fecha = Date.from(data.getFecha().atStartOfDay(ZoneId.systemDefault()).toInstant());
dataRow.createCell(0).setCellValue(data.getDia());
dataRow.createCell(1).setCellValue(fecha);
dataRow.createCell(2).setCellValue(data.getFiscales());
dataRow.createCell(3).setCellValue(data.getManuales());
dataRow.createCell(4).setCellValue(data.getFacturas());
dataRow.createCell(5).setCellValue(data.getGuias());
dataRow.createCell(6).setCellValue(data.getTotal());
if(x>0){
dataRow.createCell(7).setCellFormula(("H"+(x+1))+("+")+("G"+(x+2)));
}else{
dataRow.createCell(7).setCellFormula(("G"+(x+2)));
}
dataRow.getCell(1).setCellStyle(this.styles.get("date"));
dataRow.getCell(2).setCellStyle(this.styles.get("money"));
dataRow.getCell(3).setCellStyle(this.styles.get("money"));
dataRow.getCell(4).setCellStyle(this.styles.get("money"));
dataRow.getCell(5).setCellStyle(this.styles.get("money"));
dataRow.getCell(6).setCellStyle(this.styles.get("money"));
dataRow.getCell(7).setCellStyle(this.styles.get("money"));
}
Row headers = sheet.createRow(0);
headers.setHeightInPoints(30);
for (int x = 0; x < titles.length; x++) {
headers.createCell(x).setCellValue(titles[x]);
headers.getCell(x).setCellStyle(this.styles.get("header"));
sheet.autoSizeColumn(x);
}
try (OutputStream fileOut = new FileOutputStream("workbook.xls")) {
wb.write(fileOut);
} catch (IOException e) {
e.printStackTrace();
}
}
private HashMap<String, CellStyle> generateStyles(){
CellStyle dateCellStyle = this.wb.createCellStyle();
dateCellStyle.setDataFormat(this.createHelper.createDataFormat().getFormat("d/m/yyyy"));
CellStyle moneyCellStyle = this.wb.createCellStyle();
moneyCellStyle.setDataFormat(this.createHelper.createDataFormat().getFormat("\"$\"#,##0_);(\"$\"#,##0)"));
Font headerFont = this.wb.createFont();
headerFont.setColor(IndexedColors.WHITE.getIndex());
CellStyle headerStyle = this.wb.createCellStyle();
headerStyle.setFont(headerFont);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
headerStyle.setBorderBottom(BorderStyle.THICK);
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
headerStyle.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
HashMap<String, CellStyle> styles = new HashMap<>();
styles.put("date", dateCellStyle);
styles.put("money", moneyCellStyle);
styles.put("header", headerStyle);
return styles;
}
}

View File

@@ -47,6 +47,8 @@ public abstract class DocumentosDAO {
public abstract boolean updateDocumentos(Documentos documentos);
public abstract boolean deleteDocumentos(Documentos documentos);
public abstract int getTotalDocumentos(Caja caja);
protected List<Documentos> documentosFromResultSet(ResultSet rs) throws SQLException {
List<Documentos> documentosList = new ArrayList<>();
while (rs.next()) {

View File

@@ -203,4 +203,24 @@ public class MysqlDocumentosDAO extends DocumentosDAO {
return updates > 0;
}
@Override
public int getTotalDocumentos(Caja caja) {
int total = 0;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select cheques + tarjetas from documentos where caja_id = ?");
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
rs.next();
total = rs.getInt(1);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return total;
}
}

View File

@@ -202,4 +202,25 @@ public class SQLiteDocumentosDAO extends DocumentosDAO {
}
return updates > 0;
}
@Override
public int getTotalDocumentos(Caja caja) {
int total = 0;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select cheques + tarjetas from documentos where caja_id = ?");
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
rs.next();
total = rs.getInt(1);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return total;
}
}

View File

@@ -47,6 +47,8 @@ public abstract class EfectivoDAO {
public abstract boolean updateEfectivo(Efectivo efectivo);
public abstract boolean deleteEfectivo(Efectivo efectivo);
public abstract int getTotalEfectivo(Caja caja);
protected List<Efectivo> efectivosFromResultSet(ResultSet rs) throws SQLException {
List<Efectivo> efectivoList = new ArrayList<>();
while (rs.next()) {

View File

@@ -215,4 +215,24 @@ public class MysqlEfectivoDAO extends EfectivoDAO {
return updates > 0;
}
@Override
public int getTotalEfectivo(Caja caja) {
int total = 0;
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());
ResultSet rs = ps.executeQuery();
rs.next();
total = rs.getInt(1);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return total;
}
}

View File

@@ -215,4 +215,25 @@ public class SQLiteEfectivoDAO extends EfectivoDAO {
}
return updates > 0;
}
@Override
public int getTotalEfectivo(Caja caja) {
int total = 0;
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());
ResultSet rs = ps.executeQuery();
rs.next();
total = rs.getInt(1);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return total;
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.informe;
import java.time.LocalDate;
public class InformeMensualContent {
private int dia;
private LocalDate fecha;
private int fiscales;
private int manuales;
private int facturas;
private int guias;
private int total;
public int getDia() {
return dia;
}
public void setDia(int dia) {
this.dia = dia;
}
public LocalDate getFecha() {
return fecha;
}
public void setFecha(LocalDate fecha) {
this.fecha = fecha;
}
public int getFiscales() {
return fiscales;
}
public void setFiscales(int fiscales) {
this.fiscales = fiscales;
}
public int getManuales() {
return manuales;
}
public void setManuales(int manuales) {
this.manuales = manuales;
}
public int getFacturas() {
return facturas;
}
public void setFacturas(int facturas) {
this.facturas = facturas;
}
public int getGuias() {
return guias;
}
public void setGuias(int guias) {
this.guias = guias;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
@Override
public String toString() {
return "InformeMensualContent{" +
"dia=" + dia +
", fecha=" + fecha +
", fiscales=" + fiscales +
", manuales=" + manuales +
", facturas=" + facturas +
", guias=" + guias +
", total=" + total +
'}';
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.informe;
import java.time.LocalDate;
import java.util.List;
public abstract class InformeMensualContentDAO {
/**
* Genera el contenido del informe mensual
* @param date fecha que esta dentro del mes en el que se necesita el informe
* @return Lista con las columnas principales necesarias para el informe
*/
public abstract List<InformeMensualContent> getInformeMensual(LocalDate date);
}

View File

@@ -0,0 +1,82 @@
/*
* 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.informe;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class SQLiteInformeMensualContentDAO extends InformeMensualContentDAO{
@Override
public List<InformeMensualContent> getInformeMensual(LocalDate date) {
ArrayList<InformeMensualContent> list = new ArrayList<>();
try {
Connection conn = new SQLiteConnectionHolder().getConnection();
String query = "select strftime(\"%w\", caja.fecha) \"dia\"," +
"caja.fecha \"fecha\"," +
"sum(case when ingresos.tipo_ingreso_id = 1 then ingresos.valor else 0 end) as \"fiscales\"," +
"sum(case when ingresos.tipo_ingreso_id = 2 then ingresos.valor else 0 end) as \"manuales\"," +
"sum(case when ingresos.tipo_ingreso_id = 3 then ingresos.valor else 0 end) as \"facturas\"," +
"sum(case when ingresos.tipo_ingreso_id = 4 then ingresos.valor else 0 end) as \"guias\"," +
"sum(ingresos.valor) \"total\" " +
"from caja join ingresos on (caja.id = ingresos.caja_id) " +
"where caja.fecha between date(?) and date(?) " +
"group by caja.fecha " +
"order by caja.fecha ";
PreparedStatement ps = conn.prepareStatement(query);
ps.setString(1, date.withDayOfMonth(1).toString());
ps.setString(2, date.withDayOfMonth(LocalDate.now().lengthOfMonth()).toString());
ResultSet rs = ps.executeQuery();
while(rs.next()){
InformeMensualContent informeMensualContent = new InformeMensualContent();
informeMensualContent.setDia(rs.getInt("dia"));
informeMensualContent.setFecha(LocalDate.parse(rs.getString("fecha")));
informeMensualContent.setFiscales(rs.getInt("fiscales"));
informeMensualContent.setManuales(rs.getInt("manuales"));
informeMensualContent.setFacturas(rs.getInt("facturas"));
informeMensualContent.setGuias(rs.getInt("guias"));
informeMensualContent.setTotal(rs.getInt("total"));
list.add(informeMensualContent);
}
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}