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() {
|
private void updateCaja() {
|
||||||
LocalDate selectedDate = this.view.getDatePicker().getDate();
|
LocalDate selectedDate = this.view.getDatePicker().getDate();
|
||||||
Caja caja = DAOManager.getCajaDAO().findByFecha(selectedDate);
|
Caja caja = DAOManager.getCajaDAO().getByFecha(selectedDate).orElseGet(() -> {
|
||||||
|
Caja c = new Caja();
|
||||||
if (caja == null) {
|
c.setFecha(selectedDate);
|
||||||
caja = new Caja();
|
DAOManager.getCajaDAO().insert(c);
|
||||||
caja.setFecha(selectedDate);
|
|
||||||
DAOManager.getCajaDAO().insertCaja(caja);
|
|
||||||
|
|
||||||
Efectivo efectivo = new Efectivo();
|
Efectivo efectivo = new Efectivo();
|
||||||
efectivo.setCaja(caja);
|
efectivo.setCaja(c);
|
||||||
DAOManager.getEfectivoDAO().insertDefaultEfectivo(efectivo);
|
DAOManager.getEfectivoDAO().insertDefaultEfectivo(efectivo);
|
||||||
|
|
||||||
Documentos documentos = new Documentos();
|
Documentos documentos = new Documentos();
|
||||||
documentos.setCaja(caja);
|
documentos.setCaja(c);
|
||||||
DAOManager.getDocumentosDAO().insertDefaultDocumentos(documentos);
|
DAOManager.getDocumentosDAO().insertDefaultDocumentos(documentos);
|
||||||
}
|
return c;
|
||||||
|
});
|
||||||
|
|
||||||
this.ingresosController.updateCaja(caja);
|
this.ingresosController.updateCaja(caja);
|
||||||
this.egresosController.updateCaja(caja);
|
this.egresosController.updateCaja(caja);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class CalcularFondoController extends BaseController{
|
|||||||
this.view.getSumaField().setValue(suma);
|
this.view.getSumaField().setValue(suma);
|
||||||
this.view.getDepositoField().setValue(suma - this.caja.getFondo());
|
this.view.getDepositoField().setValue(suma - this.caja.getFondo());
|
||||||
|
|
||||||
DAOManager.getCajaDAO().updateCaja(this.caja);
|
DAOManager.getCajaDAO().update(this.caja);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupViewEvents() {
|
private void setupViewEvents() {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import danielcortes.xyz.views.dialogs.TipoEgresoSelectDialog;
|
|||||||
import danielcortes.xyz.views.dialogs.XLSFileChooser;
|
import danielcortes.xyz.views.dialogs.XLSFileChooser;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDate;
|
import java.time.YearMonth;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class InformesSideBarController {
|
public class InformesSideBarController {
|
||||||
@@ -57,12 +57,12 @@ public class InformesSideBarController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void generarInformeLibroDeVentasListener() {
|
private void generarInformeLibroDeVentasListener() {
|
||||||
LocalDate month = new MonthSelectDialog().execute();
|
YearMonth month = new MonthSelectDialog().execute();
|
||||||
if (month == null) {
|
if (month == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
|
||||||
String formatedName = month.format(formatter);
|
String formatedName = month.format(formatter);
|
||||||
String capitalized = StringUtils.capitalize(formatedName);
|
String capitalized = StringUtils.capitalize(formatedName);
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public class InformesSideBarController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDate month = new MonthSelectDialog().execute();
|
YearMonth month = new MonthSelectDialog().execute();
|
||||||
if (month == null) {
|
if (month == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDate;
|
import java.time.YearMonth;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -70,9 +70,9 @@ public class InformeEgresos {
|
|||||||
private CreationHelper createHelper;
|
private CreationHelper createHelper;
|
||||||
private HashMap<String, CellStyle> styles;
|
private HashMap<String, CellStyle> styles;
|
||||||
|
|
||||||
public InformeEgresos(int tipoEgresoId, LocalDate date, Path saveFile) {
|
public InformeEgresos(int tipoEgresoId, YearMonth mes, Path saveFile) {
|
||||||
new SQLiteCajaDAO().createCajasForMonth(date);
|
new SQLiteCajaDAO().createCajasForMonth(mes);
|
||||||
this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(date, tipoEgresoId);
|
this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(mes, tipoEgresoId);
|
||||||
this.saveFile = saveFile;
|
this.saveFile = saveFile;
|
||||||
|
|
||||||
this.wb = new HSSFWorkbook();
|
this.wb = new HSSFWorkbook();
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDate;
|
import java.time.YearMonth;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -77,10 +77,10 @@ public class InformeLibroDeVentas {
|
|||||||
private CreationHelper createHelper;
|
private CreationHelper createHelper;
|
||||||
private HashMap<String, CellStyle> styles;
|
private HashMap<String, CellStyle> styles;
|
||||||
|
|
||||||
public InformeLibroDeVentas(LocalDate date, Path saveFile) {
|
public InformeLibroDeVentas(YearMonth mes, Path saveFile) {
|
||||||
new SQLiteCajaDAO().createCajasForMonth(date);
|
new SQLiteCajaDAO().createCajasForMonth(mes);
|
||||||
|
|
||||||
this.informe = new ArrayList<>(DAOManager.getLibroDeVentasContentDAO().getInformeMensual(date));
|
this.informe = new ArrayList<>(DAOManager.getLibroDeVentasContentDAO().getInformeMensual(mes));
|
||||||
this.saveFile = saveFile;
|
this.saveFile = saveFile;
|
||||||
|
|
||||||
this.dataRows = new ArrayList<>();
|
this.dataRows = new ArrayList<>();
|
||||||
|
|||||||
@@ -24,44 +24,24 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.models.caja;
|
package danielcortes.xyz.models.caja;
|
||||||
|
|
||||||
import danielcortes.xyz.data.ConnectionHolder;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.time.YearMonth;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.Optional;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public abstract class CajaDAO {
|
public interface CajaDAO {
|
||||||
private static final Logger LOGGER = Logger.getLogger(CajaDAO.class.getName());
|
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;
|
package danielcortes.xyz.models.caja;
|
||||||
|
|
||||||
|
import danielcortes.xyz.data.DAOManager;
|
||||||
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
||||||
import danielcortes.xyz.models.documentos.Documentos;
|
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.Efectivo;
|
||||||
import danielcortes.xyz.models.efectivo.EfectivoDAO;
|
|
||||||
import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.YearMonth;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
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 static final Logger LOGGER = Logger.getLogger(SQLiteCajaDAO.class.getName());
|
||||||
|
|
||||||
|
private SQLiteConnectionHolder connectionHolder;
|
||||||
|
|
||||||
public SQLiteCajaDAO() {
|
public SQLiteCajaDAO() {
|
||||||
this.connectionHolder = new SQLiteConnectionHolder();
|
this.connectionHolder = new SQLiteConnectionHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Caja> findAll() {
|
public List<Caja> getAll() {
|
||||||
List<Caja> cajaList = new ArrayList<>();
|
List<Caja> cajaList = new ArrayList<>();
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
String query = "select * from caja";
|
String query = "select * from caja";
|
||||||
@@ -59,7 +60,13 @@ public class SQLiteCajaDAO extends CajaDAO {
|
|||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0}", new Object[]{query});
|
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();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -71,7 +78,7 @@ public class SQLiteCajaDAO extends CajaDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Caja findById(int id) {
|
public Optional<Caja> getById(int id) {
|
||||||
Caja caja = null;
|
Caja caja = null;
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
String query = "select * from caja where id = ?";
|
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});
|
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();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
return caja;
|
return Optional.ofNullable(caja);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Caja findByFecha(LocalDate fecha) {
|
public Optional<Caja> getByFecha(LocalDate fecha) {
|
||||||
Caja caja = null;
|
Caja caja = null;
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
String query = "select * from caja where fecha = ?";
|
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});
|
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, fecha});
|
||||||
|
|
||||||
List<Caja> cajaList = this.cajasFromResultSet(rs);
|
while (rs.next()) {
|
||||||
|
caja = new Caja();
|
||||||
if (cajaList.size() > 0) {
|
caja.setId(rs.getInt("id"));
|
||||||
caja = cajaList.get(0);
|
caja.setFecha(LocalDate.parse(rs.getString("fecha")));
|
||||||
|
caja.setFondo(rs.getInt("fondo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
rs.close();
|
||||||
@@ -114,20 +127,19 @@ public class SQLiteCajaDAO extends CajaDAO {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
return caja;
|
return Optional.ofNullable(caja);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean insertCaja(Caja caja) {
|
public void insert(Caja caja) {
|
||||||
int updates;
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
String query = "insert into caja (fecha, fondo) values (?, ?)";
|
String query = "insert into caja (fecha, fondo) values (?, ?)";
|
||||||
PreparedStatement ps = conn.prepareStatement(query);
|
PreparedStatement ps = conn.prepareStatement(query);
|
||||||
ps.setString(1, caja.getFecha().toString());
|
ps.setString(1, caja.getFecha().toString());
|
||||||
ps.setInt(2, caja.getFondo());
|
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();
|
ps.close();
|
||||||
|
|
||||||
@@ -144,65 +156,72 @@ public class SQLiteCajaDAO extends CajaDAO {
|
|||||||
ps.close();
|
ps.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return updates > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateCaja(Caja caja) {
|
public void insert(List<Caja> cajas){
|
||||||
int updates;
|
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()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
String query = "update caja set fecha = ?, fondo = ? where id = ?";
|
String query = "update caja set fecha = ?, fondo = ? where id = ?";
|
||||||
PreparedStatement ps = conn.prepareStatement(query);
|
PreparedStatement ps = conn.prepareStatement(query);
|
||||||
ps.setString(1, caja.getFecha().toString());
|
ps.setString(1, caja.getFecha().toString());
|
||||||
ps.setInt(2, caja.getFondo());
|
ps.setInt(2, caja.getFondo());
|
||||||
ps.setInt(3, caja.getId());
|
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();
|
ps.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return updates > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createCajasForMonth(LocalDate month) {
|
public void createCajasForMonth(YearMonth mes) {
|
||||||
LocalDate date = month.withDayOfMonth(1);
|
LocalDate startDate = mes.atDay(1);
|
||||||
LocalDate endDate = date.withDayOfMonth(date.lengthOfMonth()).plusDays(1);
|
LocalDate endDatePlusOne = mes.atEndOfMonth().plusDays(1);
|
||||||
int count = 0;
|
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)) {
|
startDate = startDate.plusDays(1);
|
||||||
if (this.findByFecha(date) != null) {
|
}
|
||||||
date = date.plusDays(1);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Caja caja = new Caja();
|
this.insert(cajas);
|
||||||
caja.setFecha(date);
|
|
||||||
this.insertCaja(caja);
|
|
||||||
|
|
||||||
|
for(Caja caja: cajas){
|
||||||
Efectivo efectivo = new Efectivo();
|
Efectivo efectivo = new Efectivo();
|
||||||
EfectivoDAO efectivoDAO = new SQLiteEfectivoDAO();
|
|
||||||
efectivo.setCaja(caja);
|
efectivo.setCaja(caja);
|
||||||
efectivoDAO.insertDefaultEfectivo(efectivo);
|
DAOManager.getEfectivoDAO().insertDefaultEfectivo(efectivo);
|
||||||
|
|
||||||
Documentos documentos = new Documentos();
|
Documentos documentos = new Documentos();
|
||||||
DocumentosDAO documentosDAO = new SQLiteDocumentosDAO();
|
|
||||||
documentos.setCaja(caja);
|
documentos.setCaja(caja);
|
||||||
documentosDAO.insertDefaultDocumentos(documentos);
|
DAOManager.getDocumentosDAO().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});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ public abstract class CalculoFondoDAO {
|
|||||||
|
|
||||||
public abstract int getTotalCalculoFondo(Caja caja);
|
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<>();
|
List<CalculoFondo> calculoFondoList = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
int caja_id = rs.getInt("caja_id");
|
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 calculoFondo = new CalculoFondo();
|
||||||
calculoFondo.setId(rs.getInt("id"));
|
calculoFondo.setId(rs.getInt("id"));
|
||||||
calculoFondo.setValor(rs.getInt("valor"));
|
calculoFondo.setValor(rs.getInt("valor"));
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
|
|||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0}", query);
|
LOGGER.log(Level.FINE, "QUERY: {0}", query);
|
||||||
|
|
||||||
calculoFondoList = this.cajasFromResultSet(rs);
|
calculoFondoList = this.calculoFondoFromResultSet(rs);
|
||||||
|
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.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()});
|
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
|
||||||
|
|
||||||
calculoFondoList = this.cajasFromResultSet(rs);
|
calculoFondoList = this.calculoFondoFromResultSet(rs);
|
||||||
|
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -95,7 +95,7 @@ public class SQLiteCalculoFondoDAO extends CalculoFondoDAO {
|
|||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
|
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();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public abstract class DocumentosDAO {
|
|||||||
List<Documentos> documentosList = new ArrayList<>();
|
List<Documentos> documentosList = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
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 documentos = new Documentos();
|
||||||
documentos.setCaja(caja);
|
documentos.setCaja(caja);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public abstract class EfectivoDAO {
|
|||||||
List<Efectivo> efectivoList = new ArrayList<>();
|
List<Efectivo> efectivoList = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
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 efectivo = new Efectivo();
|
||||||
efectivo.setCaja(caja);
|
efectivo.setCaja(caja);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public abstract class EgresoDAO {
|
|||||||
|
|
||||||
int cajaId = rs.getInt("caja_id");
|
int cajaId = rs.getInt("caja_id");
|
||||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||||
Caja caja = cajaDAO.findById(cajaId);
|
Caja caja = cajaDAO.getById(cajaId).get();
|
||||||
|
|
||||||
Egreso egreso = new Egreso();
|
Egreso egreso = new Egreso();
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ package danielcortes.xyz.models.informes.egresos;
|
|||||||
|
|
||||||
import danielcortes.xyz.data.ConnectionHolder;
|
import danielcortes.xyz.data.ConnectionHolder;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.YearMonth;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class InformeEgresosContentDAO {
|
public abstract class InformeEgresosContentDAO {
|
||||||
@@ -35,8 +35,8 @@ public abstract class InformeEgresosContentDAO {
|
|||||||
/**
|
/**
|
||||||
* Genera el informe con nombre muy largo
|
* 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
|
* @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.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.YearMonth;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -46,7 +47,7 @@ public class SQLiteInformeEgresosContentDAO extends InformeEgresosContentDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<InformeEgresosContent> getInformeEgresosFactuasMateriaPrima(LocalDate date, int tipoEgresoId) {
|
public List<InformeEgresosContent> getInformeEgresosFactuasMateriaPrima(YearMonth mes, int tipoEgresoId) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
|
||||||
@@ -59,12 +60,12 @@ public class SQLiteInformeEgresosContentDAO extends InformeEgresosContentDAO {
|
|||||||
"order by caja.fecha;";
|
"order by caja.fecha;";
|
||||||
|
|
||||||
PreparedStatement ps = conn.prepareStatement(query);
|
PreparedStatement ps = conn.prepareStatement(query);
|
||||||
ps.setString(1, date.withDayOfMonth(1).toString());
|
ps.setString(1, mes.atDay(1).toString());
|
||||||
ps.setString(2, date.withDayOfMonth(date.lengthOfMonth()).toString());
|
ps.setString(2, mes.atEndOfMonth().toString());
|
||||||
ps.setInt(3, tipoEgresoId);
|
ps.setInt(3, tipoEgresoId);
|
||||||
ResultSet rs = ps.executeQuery();
|
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);
|
this.fillInforme(rs);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@@ -22,35 +22,11 @@
|
|||||||
* SOFTWARE.
|
* 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;
|
package danielcortes.xyz.models.informes.libro_de_ventas;
|
||||||
|
|
||||||
import danielcortes.xyz.data.ConnectionHolder;
|
import danielcortes.xyz.data.ConnectionHolder;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.YearMonth;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public abstract class InformeLibroDeVentasContentDAO {
|
public abstract class InformeLibroDeVentasContentDAO {
|
||||||
@@ -59,8 +35,8 @@ public abstract class InformeLibroDeVentasContentDAO {
|
|||||||
/**
|
/**
|
||||||
* Genera el contenido del informes mensual
|
* 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
|
* @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.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.YearMonth;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -72,7 +73,7 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<InformeLibroDeVentasContent> getInformeMensual(LocalDate date) {
|
public Collection<InformeLibroDeVentasContent> getInformeMensual(YearMonth date) {
|
||||||
this.map = new HashMap<>();
|
this.map = new HashMap<>();
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
String queryTotales =
|
String queryTotales =
|
||||||
@@ -91,11 +92,11 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo
|
|||||||
"where caja.fecha between date(?) and date(?) " +
|
"where caja.fecha between date(?) and date(?) " +
|
||||||
"group by caja.fecha;";
|
"group by caja.fecha;";
|
||||||
PreparedStatement ps = conn.prepareStatement(queryTotales);
|
PreparedStatement ps = conn.prepareStatement(queryTotales);
|
||||||
ps.setString(1, date.withDayOfMonth(1).toString());
|
ps.setString(1, date.atDay(1).toString());
|
||||||
ps.setString(2, date.withDayOfMonth(date.lengthOfMonth()).toString());
|
ps.setString(2, date.atEndOfMonth().toString());
|
||||||
ResultSet rs = ps.executeQuery();
|
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);
|
this.fillTotalesFromResultSet(rs);
|
||||||
|
|
||||||
@@ -111,11 +112,11 @@ public class SQLiteInformeLibroDeVentasContentDAO extends InformeLibroDeVentasCo
|
|||||||
"from caja join ingresos on (caja.id = ingresos.caja_id) " +
|
"from caja join ingresos on (caja.id = ingresos.caja_id) " +
|
||||||
"where caja.fecha between date(?) and date(?);";
|
"where caja.fecha between date(?) and date(?);";
|
||||||
ps = conn.prepareStatement(queryNumeros);
|
ps = conn.prepareStatement(queryNumeros);
|
||||||
ps.setString(1, date.withDayOfMonth(1).toString());
|
ps.setString(1, date.atDay(1).toString());
|
||||||
ps.setString(2, date.withDayOfMonth(date.lengthOfMonth()).toString());
|
ps.setString(2, date.atEndOfMonth().toString());
|
||||||
rs = ps.executeQuery();
|
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);
|
this.fillBoletasFromResultSet(rs);
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public abstract class IngresoDAO {
|
|||||||
|
|
||||||
int cajaId = rs.getInt("caja_id");
|
int cajaId = rs.getInt("caja_id");
|
||||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||||
Caja caja = cajaDAO.findById(cajaId);
|
Caja caja = cajaDAO.getById(cajaId).get();
|
||||||
|
|
||||||
Ingreso ingreso = new Ingreso();
|
Ingreso ingreso = new Ingreso();
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.YearMonth;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MonthSelectDialog extends JDialog {
|
public class MonthSelectDialog extends JDialog {
|
||||||
@@ -69,7 +70,7 @@ public class MonthSelectDialog extends JDialog {
|
|||||||
pack();
|
pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate execute() {
|
public YearMonth execute() {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
if (this.isAcepted()) {
|
if (this.isAcepted()) {
|
||||||
return this.getMonth();
|
return this.getMonth();
|
||||||
@@ -92,12 +93,11 @@ public class MonthSelectDialog extends JDialog {
|
|||||||
return this.acepted;
|
return this.acepted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalDate getMonth() {
|
private YearMonth getMonth() {
|
||||||
int year = Integer.valueOf((String) yearSpinner.getValue());
|
int year = Integer.valueOf((String) yearSpinner.getValue());
|
||||||
int month = this.months.indexOf(this.monthCombo.getSelectedItem()) + 1;
|
int month = this.months.indexOf(this.monthCombo.getSelectedItem()) + 1;
|
||||||
|
|
||||||
LocalDate monthDate = LocalDate.of(year, month, 1);
|
return YearMonth.of(year, month);
|
||||||
return monthDate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user