Limpiado modelo de caja
Como consecuencia esto llevo a modificar otras clases que la utilizaban ya que se decidieron cambiar un par de cosas en su API - Quitar el que los metodos de update e insert retornaran un booleano, realmente no era algo necesario y no se estaba utilizando. - Remplazar el retornar una Caja por retornar un Optional<Caja> en los metodos de getByFecha y getById, con el fin eliminar un poco los chequeos de nulls - El metodo de cajasFromResultSet fue eliminado ya que no lo veia necesario ya que operaba generaba una List con las cajas obtenidas por el ResultSet y los de los 2 metodos que la invocaban, solo uno de ellos necesitaba una lista, el otro solo obtenia el primero de la lista y continuaba. - Cambie el necesitar un LocalDate en el metodo que genera las cajas para un mes, por un objeto con logico para esta situacion, el cual es YearMonth, esto tuvo como consecuencia la mayoria de los cambios fuera de esta clase. - Renombre los metodos para que tuvieran nombres mas agradables para mi, esto es lo otro que hizo cambiar muchas otras clases.
This commit is contained in:
BIN
dist/Programa Caja.jar
vendored
BIN
dist/Programa Caja.jar
vendored
Binary file not shown.
@@ -103,21 +103,20 @@ public class CajasController {
|
||||
*/
|
||||
private void updateCaja() {
|
||||
LocalDate selectedDate = this.view.getDatePicker().getDate();
|
||||
Caja caja = DAOManager.getCajaDAO().findByFecha(selectedDate);
|
||||
|
||||
if (caja == null) {
|
||||
caja = new Caja();
|
||||
caja.setFecha(selectedDate);
|
||||
DAOManager.getCajaDAO().insertCaja(caja);
|
||||
Caja caja = DAOManager.getCajaDAO().getByFecha(selectedDate).orElseGet(() -> {
|
||||
Caja c = new Caja();
|
||||
c.setFecha(selectedDate);
|
||||
DAOManager.getCajaDAO().insert(c);
|
||||
|
||||
Efectivo efectivo = new Efectivo();
|
||||
efectivo.setCaja(caja);
|
||||
efectivo.setCaja(c);
|
||||
DAOManager.getEfectivoDAO().insertDefaultEfectivo(efectivo);
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
documentos.setCaja(caja);
|
||||
documentos.setCaja(c);
|
||||
DAOManager.getDocumentosDAO().insertDefaultDocumentos(documentos);
|
||||
}
|
||||
return c;
|
||||
});
|
||||
|
||||
this.ingresosController.updateCaja(caja);
|
||||
this.egresosController.updateCaja(caja);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CalcularFondoController extends BaseController{
|
||||
this.view.getSumaField().setValue(suma);
|
||||
this.view.getDepositoField().setValue(suma - this.caja.getFondo());
|
||||
|
||||
DAOManager.getCajaDAO().updateCaja(this.caja);
|
||||
DAOManager.getCajaDAO().update(this.caja);
|
||||
}
|
||||
|
||||
private void setupViewEvents() {
|
||||
|
||||
@@ -36,7 +36,7 @@ import danielcortes.xyz.views.dialogs.TipoEgresoSelectDialog;
|
||||
import danielcortes.xyz.views.dialogs.XLSFileChooser;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class InformesSideBarController {
|
||||
@@ -57,12 +57,12 @@ public class InformesSideBarController {
|
||||
}
|
||||
|
||||
private void generarInformeLibroDeVentasListener() {
|
||||
LocalDate month = new MonthSelectDialog().execute();
|
||||
YearMonth month = new MonthSelectDialog().execute();
|
||||
if (month == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
|
||||
String formatedName = month.format(formatter);
|
||||
String capitalized = StringUtils.capitalize(formatedName);
|
||||
|
||||
@@ -84,7 +84,7 @@ public class InformesSideBarController {
|
||||
return;
|
||||
}
|
||||
|
||||
LocalDate month = new MonthSelectDialog().execute();
|
||||
YearMonth month = new MonthSelectDialog().execute();
|
||||
if (month == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ 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.Date;
|
||||
@@ -70,9 +70,9 @@ public class InformeEgresos {
|
||||
private CreationHelper createHelper;
|
||||
private HashMap<String, CellStyle> styles;
|
||||
|
||||
public InformeEgresos(int tipoEgresoId, LocalDate date, Path saveFile) {
|
||||
new SQLiteCajaDAO().createCajasForMonth(date);
|
||||
this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(date, tipoEgresoId);
|
||||
public InformeEgresos(int tipoEgresoId, YearMonth mes, Path saveFile) {
|
||||
new SQLiteCajaDAO().createCajasForMonth(mes);
|
||||
this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(mes, tipoEgresoId);
|
||||
this.saveFile = saveFile;
|
||||
|
||||
this.wb = new HSSFWorkbook();
|
||||
|
||||
@@ -36,7 +36,7 @@ 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.*;
|
||||
|
||||
@@ -77,10 +77,10 @@ public class InformeLibroDeVentas {
|
||||
private CreationHelper createHelper;
|
||||
private HashMap<String, CellStyle> styles;
|
||||
|
||||
public InformeLibroDeVentas(LocalDate date, Path saveFile) {
|
||||
new SQLiteCajaDAO().createCajasForMonth(date);
|
||||
public InformeLibroDeVentas(YearMonth mes, Path saveFile) {
|
||||
new SQLiteCajaDAO().createCajasForMonth(mes);
|
||||
|
||||
this.informe = new ArrayList<>(DAOManager.getLibroDeVentasContentDAO().getInformeMensual(date));
|
||||
this.informe = new ArrayList<>(DAOManager.getLibroDeVentasContentDAO().getInformeMensual(mes));
|
||||
this.saveFile = saveFile;
|
||||
|
||||
this.dataRows = new ArrayList<>();
|
||||
|
||||
@@ -24,44 +24,24 @@
|
||||
|
||||
package danielcortes.xyz.models.caja;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.time.YearMonth;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class CajaDAO {
|
||||
private static final Logger LOGGER = Logger.getLogger(CajaDAO.class.getName());
|
||||
public interface CajaDAO {
|
||||
List<Caja> getAll();
|
||||
|
||||
protected ConnectionHolder connectionHolder;
|
||||
Optional<Caja> getById(int id);
|
||||
|
||||
public abstract List<Caja> findAll();
|
||||
Optional<Caja> getByFecha(LocalDate fecha);
|
||||
|
||||
public abstract Caja findById(int id);
|
||||
void insert(Caja caja);
|
||||
|
||||
public abstract Caja findByFecha(LocalDate fecha);
|
||||
void insert(List<Caja> cajas);
|
||||
|
||||
public abstract boolean insertCaja(Caja caja);
|
||||
void update(Caja caja);
|
||||
|
||||
public abstract boolean updateCaja(Caja caja);
|
||||
void createCajasForMonth(YearMonth month);
|
||||
|
||||
public abstract void createCajasForMonth(LocalDate month);
|
||||
|
||||
List<Caja> cajasFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Caja> cajaList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
Caja caja = new Caja();
|
||||
caja.setId(rs.getInt("id"));
|
||||
caja.setFecha(LocalDate.parse(rs.getString("fecha")));
|
||||
caja.setFondo(rs.getInt("fondo"));
|
||||
cajaList.add(caja);
|
||||
|
||||
LOGGER.log(Level.FINER, "Se a creo: {0}", caja);
|
||||
}
|
||||
return cajaList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,33 +24,34 @@
|
||||
|
||||
package danielcortes.xyz.models.caja;
|
||||
|
||||
import danielcortes.xyz.data.DAOManager;
|
||||
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
||||
import danielcortes.xyz.models.documentos.Documentos;
|
||||
import danielcortes.xyz.models.documentos.DocumentosDAO;
|
||||
import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO;
|
||||
import danielcortes.xyz.models.efectivo.Efectivo;
|
||||
import danielcortes.xyz.models.efectivo.EfectivoDAO;
|
||||
import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
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;
|
||||
|
||||
public class SQLiteCajaDAO extends CajaDAO {
|
||||
public class SQLiteCajaDAO implements CajaDAO {
|
||||
private static final Logger LOGGER = Logger.getLogger(SQLiteCajaDAO.class.getName());
|
||||
|
||||
private SQLiteConnectionHolder connectionHolder;
|
||||
|
||||
public SQLiteCajaDAO() {
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Caja> findAll() {
|
||||
public List<Caja> getAll() {
|
||||
List<Caja> cajaList = new ArrayList<>();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
String query = "select * from caja";
|
||||
@@ -59,7 +60,13 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0}", new Object[]{query});
|
||||
|
||||
cajaList = this.cajasFromResultSet(rs);
|
||||
while (rs.next()) {
|
||||
Caja caja = new Caja();
|
||||
caja.setId(rs.getInt("id"));
|
||||
caja.setFecha(LocalDate.parse(rs.getString("fecha")));
|
||||
caja.setFondo(rs.getInt("fondo"));
|
||||
cajaList.add(caja);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -71,7 +78,7 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Caja findById(int id) {
|
||||
public Optional<Caja> getById(int id) {
|
||||
Caja caja = null;
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
String query = "select * from caja where id = ?";
|
||||
@@ -81,18 +88,23 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
|
||||
|
||||
caja = this.cajasFromResultSet(rs).get(0);
|
||||
while (rs.next()) {
|
||||
caja = new Caja();
|
||||
caja.setId(rs.getInt("id"));
|
||||
caja.setFecha(LocalDate.parse(rs.getString("fecha")));
|
||||
caja.setFondo(rs.getInt("fondo"));
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
return caja;
|
||||
return Optional.ofNullable(caja);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Caja findByFecha(LocalDate fecha) {
|
||||
public Optional<Caja> getByFecha(LocalDate fecha) {
|
||||
Caja caja = null;
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
String query = "select * from caja where fecha = ?";
|
||||
@@ -103,10 +115,11 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, fecha});
|
||||
|
||||
List<Caja> cajaList = this.cajasFromResultSet(rs);
|
||||
|
||||
if (cajaList.size() > 0) {
|
||||
caja = cajaList.get(0);
|
||||
while (rs.next()) {
|
||||
caja = new Caja();
|
||||
caja.setId(rs.getInt("id"));
|
||||
caja.setFecha(LocalDate.parse(rs.getString("fecha")));
|
||||
caja.setFondo(rs.getInt("fondo"));
|
||||
}
|
||||
|
||||
rs.close();
|
||||
@@ -114,20 +127,19 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
} catch (SQLException e) {
|
||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
return caja;
|
||||
return Optional.ofNullable(caja);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertCaja(Caja caja) {
|
||||
int updates;
|
||||
public void insert(Caja caja) {
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
String query = "insert into caja (fecha, fondo) values (?, ?)";
|
||||
PreparedStatement ps = conn.prepareStatement(query);
|
||||
ps.setString(1, caja.getFecha().toString());
|
||||
ps.setInt(2, caja.getFondo());
|
||||
updates = ps.executeUpdate();
|
||||
ps.executeUpdate();
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}, {2} | updates: {3}", new Object[]{query, caja.getFecha(), caja.getFondo(), updates});
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}, {2}", new Object[]{query, caja.getFecha(), caja.getFondo()});
|
||||
|
||||
ps.close();
|
||||
|
||||
@@ -144,65 +156,72 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateCaja(Caja caja) {
|
||||
int updates;
|
||||
public void insert(List<Caja> cajas){
|
||||
String query = "insert into caja (fecha, fondo) values (?, ?)";
|
||||
try (Connection conn = connectionHolder.getConnection();PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
for(Caja caja: cajas){
|
||||
ps.setString(1, caja.getFecha().toString());
|
||||
ps.setInt(2, caja.getFondo());
|
||||
ps.addBatch();
|
||||
}
|
||||
ps.executeBatch();
|
||||
} catch (SQLException e) {
|
||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Caja caja) {
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
String query = "update caja set fecha = ?, fondo = ? where id = ?";
|
||||
PreparedStatement ps = conn.prepareStatement(query);
|
||||
ps.setString(1, caja.getFecha().toString());
|
||||
ps.setInt(2, caja.getFondo());
|
||||
ps.setInt(3, caja.getId());
|
||||
updates = ps.executeUpdate();
|
||||
ps.executeUpdate();
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}, {2}, {3} | updates: {4}", new Object[]{query, caja.getFecha(), caja.getFondo(), caja.getId(), updates});
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}, {2}, {3}", new Object[]{query, caja.getFecha(), caja.getFondo(), caja.getId()});
|
||||
|
||||
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createCajasForMonth(LocalDate month) {
|
||||
LocalDate date = month.withDayOfMonth(1);
|
||||
LocalDate endDate = date.withDayOfMonth(date.lengthOfMonth()).plusDays(1);
|
||||
int count = 0;
|
||||
public void createCajasForMonth(YearMonth mes) {
|
||||
LocalDate startDate = mes.atDay(1);
|
||||
LocalDate endDatePlusOne = mes.atEndOfMonth().plusDays(1);
|
||||
List<Caja> cajas = new ArrayList<>();
|
||||
|
||||
LOGGER.log(Level.FINE, "Se intentara crear las cajas no existentes para las fechas entre {0} y {1}", new Object[]{date, endDate});
|
||||
while (startDate.isBefore(endDatePlusOne)) {
|
||||
if (this.getByFecha(startDate).isPresent()){
|
||||
startDate = startDate.plusDays(1);
|
||||
}else{
|
||||
Caja caja = new Caja();
|
||||
caja.setFecha(startDate);
|
||||
cajas.add(caja);
|
||||
|
||||
while (date.isBefore(endDate)) {
|
||||
if (this.findByFecha(date) != null) {
|
||||
date = date.plusDays(1);
|
||||
continue;
|
||||
startDate = startDate.plusDays(1);
|
||||
}
|
||||
|
||||
Caja caja = new Caja();
|
||||
caja.setFecha(date);
|
||||
this.insertCaja(caja);
|
||||
|
||||
Efectivo efectivo = new Efectivo();
|
||||
EfectivoDAO efectivoDAO = new SQLiteEfectivoDAO();
|
||||
efectivo.setCaja(caja);
|
||||
efectivoDAO.insertDefaultEfectivo(efectivo);
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
DocumentosDAO documentosDAO = new SQLiteDocumentosDAO();
|
||||
documentos.setCaja(caja);
|
||||
documentosDAO.insertDefaultDocumentos(documentos);
|
||||
|
||||
date = date.plusDays(1);
|
||||
count++;
|
||||
}
|
||||
|
||||
LOGGER.log(Level.FINE, "Terminado de intentar crear las cajas y se crearon {2}", new Object[]{date, endDate, count});
|
||||
this.insert(cajas);
|
||||
|
||||
for(Caja caja: cajas){
|
||||
Efectivo efectivo = new Efectivo();
|
||||
efectivo.setCaja(caja);
|
||||
DAOManager.getEfectivoDAO().insertDefaultEfectivo(efectivo);
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
documentos.setCaja(caja);
|
||||
DAOManager.getDocumentosDAO().insertDefaultDocumentos(documentos);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,11 +54,11 @@ public abstract class CalculoFondoDAO {
|
||||
|
||||
public abstract int getTotalCalculoFondo(Caja caja);
|
||||
|
||||
protected List<CalculoFondo> cajasFromResultSet(ResultSet rs) throws SQLException {
|
||||
protected List<CalculoFondo> calculoFondoFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<CalculoFondo> calculoFondoList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
int caja_id = rs.getInt("caja_id");
|
||||
Caja caja = new SQLiteCajaDAO().findById(caja_id);
|
||||
Caja caja = new SQLiteCajaDAO().getById(caja_id).get();
|
||||
CalculoFondo calculoFondo = new CalculoFondo();
|
||||
calculoFondo.setId(rs.getInt("id"));
|
||||
calculoFondo.setValor(rs.getInt("valor"));
|
||||
|
||||
@@ -53,7 +53,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0}", query);
|
||||
|
||||
calculoFondoList = this.cajasFromResultSet(rs);
|
||||
calculoFondoList = this.calculoFondoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -74,7 +74,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
|
||||
|
||||
calculoFondoList = this.cajasFromResultSet(rs);
|
||||
calculoFondoList = this.calculoFondoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -95,7 +95,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
|
||||
|
||||
calculoFondo = this.cajasFromResultSet(rs).get(0);
|
||||
calculoFondo = this.calculoFondoFromResultSet(rs).get(0);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class DocumentosDAO {
|
||||
List<Documentos> documentosList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
|
||||
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
documentos.setCaja(caja);
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class EfectivoDAO {
|
||||
List<Efectivo> efectivoList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
|
||||
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
||||
|
||||
Efectivo efectivo = new Efectivo();
|
||||
efectivo.setCaja(caja);
|
||||
|
||||
@@ -74,7 +74,7 @@ public abstract class EgresoDAO {
|
||||
|
||||
int cajaId = rs.getInt("caja_id");
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(cajaId);
|
||||
Caja caja = cajaDAO.getById(cajaId).get();
|
||||
|
||||
Egreso egreso = new Egreso();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ package danielcortes.xyz.models.informes.egresos;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class InformeEgresosContentDAO {
|
||||
@@ -35,8 +35,8 @@ public abstract class InformeEgresosContentDAO {
|
||||
/**
|
||||
* Genera el informe con nombre muy largo
|
||||
*
|
||||
* @param month mes sobre el cual se quiere le informe
|
||||
* @param mes mes sobre el cual se quiere le informe
|
||||
* @return lista del objeto que contiene los datos necesarios para el informe
|
||||
*/
|
||||
public abstract List<InformeEgresosContent> getInformeEgresosFactuasMateriaPrima(LocalDate month, int tipoEgresoId);
|
||||
public abstract List<InformeEgresosContent> getInformeEgresosFactuasMateriaPrima(YearMonth mes, int tipoEgresoId);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
@@ -46,7 +47,7 @@ public class SQLiteInformeEgresosContentDAO extends InformeEgresosContentDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InformeEgresosContent> getInformeEgresosFactuasMateriaPrima(LocalDate date, int tipoEgresoId) {
|
||||
public List<InformeEgresosContent> getInformeEgresosFactuasMateriaPrima(YearMonth mes, int tipoEgresoId) {
|
||||
list = new ArrayList<>();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
|
||||
@@ -59,12 +60,12 @@ public class SQLiteInformeEgresosContentDAO extends InformeEgresosContentDAO {
|
||||
"order by caja.fecha;";
|
||||
|
||||
PreparedStatement ps = conn.prepareStatement(query);
|
||||
ps.setString(1, date.withDayOfMonth(1).toString());
|
||||
ps.setString(2, date.withDayOfMonth(date.lengthOfMonth()).toString());
|
||||
ps.setString(1, mes.atDay(1).toString());
|
||||
ps.setString(2, mes.atEndOfMonth().toString());
|
||||
ps.setInt(3, tipoEgresoId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3}]", new Object[]{date.withDayOfMonth(1), date.withDayOfMonth(date.lengthOfMonth()), tipoEgresoId});
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3}]", new Object[]{mes.atDay(1), mes.atEndOfMonth(), tipoEgresoId});
|
||||
|
||||
this.fillInforme(rs);
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -22,35 +22,11 @@
|
||||
* 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.ConnectionHolder;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class InformeLibroDeVentasContentDAO {
|
||||
@@ -59,8 +35,8 @@ public abstract class InformeLibroDeVentasContentDAO {
|
||||
/**
|
||||
* Genera el contenido del informes mensual
|
||||
*
|
||||
* @param date fecha que esta dentro del mes en el que se necesita el informes
|
||||
* @param mes el que se necesita el informes
|
||||
* @return Lista con las columnas principales necesarias para el informes
|
||||
*/
|
||||
public abstract Collection<InformeLibroDeVentasContent> getInformeMensual(LocalDate date);
|
||||
public abstract Collection<InformeLibroDeVentasContent> getInformeMensual(YearMonth mes);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -72,7 +73,7 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<InformeLibroDeVentasContent> getInformeMensual(LocalDate date) {
|
||||
public Collection<InformeLibroDeVentasContent> getInformeMensual(YearMonth date) {
|
||||
this.map = new HashMap<>();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
String queryTotales =
|
||||
@@ -91,11 +92,11 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo
|
||||
"where caja.fecha between date(?) and date(?) " +
|
||||
"group by caja.fecha;";
|
||||
PreparedStatement ps = conn.prepareStatement(queryTotales);
|
||||
ps.setString(1, date.withDayOfMonth(1).toString());
|
||||
ps.setString(2, date.withDayOfMonth(date.lengthOfMonth()).toString());
|
||||
ps.setString(1, date.atDay(1).toString());
|
||||
ps.setString(2, date.atEndOfMonth().toString());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2}]", new Object[]{queryTotales, date.withDayOfMonth(1), date.withDayOfMonth(date.lengthOfMonth())});
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2}]", new Object[]{queryTotales, date.atDay(1), date.atEndOfMonth()});
|
||||
|
||||
this.fillTotalesFromResultSet(rs);
|
||||
|
||||
@@ -111,11 +112,11 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo
|
||||
"from caja join ingresos on (caja.id = ingresos.caja_id) " +
|
||||
"where caja.fecha between date(?) and date(?);";
|
||||
ps = conn.prepareStatement(queryNumeros);
|
||||
ps.setString(1, date.withDayOfMonth(1).toString());
|
||||
ps.setString(2, date.withDayOfMonth(date.lengthOfMonth()).toString());
|
||||
ps.setString(1, date.atDay(1).toString());
|
||||
ps.setString(2, date.atEndOfMonth().toString());
|
||||
rs = ps.executeQuery();
|
||||
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2}]", new Object[]{queryNumeros, date.withDayOfMonth(1), date.withDayOfMonth(date.lengthOfMonth())});
|
||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2}]", new Object[]{queryNumeros, date.atDay(1), date.atEndOfMonth()});
|
||||
|
||||
this.fillBoletasFromResultSet(rs);
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class IngresoDAO {
|
||||
|
||||
int cajaId = rs.getInt("caja_id");
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(cajaId);
|
||||
Caja caja = cajaDAO.getById(cajaId).get();
|
||||
|
||||
Ingreso ingreso = new Ingreso();
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MonthSelectDialog extends JDialog {
|
||||
@@ -69,7 +70,7 @@ public class MonthSelectDialog extends JDialog {
|
||||
pack();
|
||||
}
|
||||
|
||||
public LocalDate execute() {
|
||||
public YearMonth execute() {
|
||||
setVisible(true);
|
||||
if (this.isAcepted()) {
|
||||
return this.getMonth();
|
||||
@@ -92,12 +93,11 @@ public class MonthSelectDialog extends JDialog {
|
||||
return this.acepted;
|
||||
}
|
||||
|
||||
private LocalDate getMonth() {
|
||||
private YearMonth getMonth() {
|
||||
int year = Integer.valueOf((String) yearSpinner.getValue());
|
||||
int month = this.months.indexOf(this.monthCombo.getSelectedItem()) + 1;
|
||||
|
||||
LocalDate monthDate = LocalDate.of(year, month, 1);
|
||||
return monthDate;
|
||||
return YearMonth.of(year, month);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user