Se limpio el modelo de Ingreso
Ademas se me habia olvidado chequear si es que el resto del programa seguia funcionando, y no, no lo hacia, corregi los errores presentes;
This commit is contained in:
BIN
dist/Programa Caja.jar
vendored
BIN
dist/Programa Caja.jar
vendored
Binary file not shown.
@@ -14,6 +14,7 @@ import danielcortes.xyz.views.listeners.FocusLostListener;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.YearMonth;
|
import java.time.YearMonth;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EstadoResultadoController extends BaseController {
|
public class EstadoResultadoController extends BaseController {
|
||||||
|
|
||||||
@@ -138,9 +139,12 @@ public class EstadoResultadoController extends BaseController {
|
|||||||
|
|
||||||
private void updateMonth() {
|
private void updateMonth() {
|
||||||
this.mes = this.view.getMonth();
|
this.mes = this.view.getMonth();
|
||||||
this.estadoResultado = DAOManager.getEstadoResultadoDAO().getByMonth(this.mes);
|
Optional<EstadoResultado> optional = DAOManager.getEstadoResultadoDAO().getByMonth(this.mes);
|
||||||
if (estadoResultado == null) {
|
|
||||||
this.estadoResultado = EstadoResultado.emptyEstadoResultado;
|
if (optional.isPresent()) {
|
||||||
|
this.estadoResultado = optional.get();
|
||||||
|
} else {
|
||||||
|
this.estadoResultado = new EstadoResultado();
|
||||||
this.estadoResultado.setMes(this.mes);
|
this.estadoResultado.setMes(this.mes);
|
||||||
DAOManager.getEstadoResultadoDAO().insertEstadoResultado(estadoResultado);
|
DAOManager.getEstadoResultadoDAO().insertEstadoResultado(estadoResultado);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class IngresosController extends BaseController {
|
|||||||
private void fillIngresosTable() {
|
private void fillIngresosTable() {
|
||||||
IngresosTableModel ingresosTableModel = this.view.getIngresosTableModel();
|
IngresosTableModel ingresosTableModel = this.view.getIngresosTableModel();
|
||||||
ingresosTableModel.removeRows();
|
ingresosTableModel.removeRows();
|
||||||
for (Ingreso ingreso : DAOManager.getIngresoDAO().findByCaja(this.caja)) {
|
for (Ingreso ingreso : DAOManager.getIngresoDAO().getByCaja(this.caja)) {
|
||||||
ingresosTableModel.addRow(ingreso);
|
ingresosTableModel.addRow(ingreso);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class InformeEstadoResultado {
|
|||||||
this.mes = mes;
|
this.mes = mes;
|
||||||
this.saveFile = saveFile;
|
this.saveFile = saveFile;
|
||||||
|
|
||||||
this.estadoResultado = DAOManager.getEstadoResultadoDAO().getByMonth(this.mes);
|
this.estadoResultado = DAOManager.getEstadoResultadoDAO().getByMonth(this.mes).orElse(EstadoResultado.EMPTY);
|
||||||
|
|
||||||
this.wb = new HSSFWorkbook();
|
this.wb = new HSSFWorkbook();
|
||||||
this.sheet = wb.createSheet();
|
this.sheet = wb.createSheet();
|
||||||
|
|||||||
@@ -4,27 +4,11 @@ import java.time.YearMonth;
|
|||||||
|
|
||||||
public class EstadoResultado {
|
public class EstadoResultado {
|
||||||
|
|
||||||
public static final EstadoResultado emptyEstadoResultado;
|
public static final EstadoResultado EMPTY;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
emptyEstadoResultado = new EstadoResultado();
|
EMPTY = new EstadoResultado();
|
||||||
emptyEstadoResultado.costoVenta = 0;
|
EMPTY.setMes(YearMonth.of(0,1));
|
||||||
emptyEstadoResultado.cuentaCorrienteBoleta = 0;
|
|
||||||
emptyEstadoResultado.cuentaCorrienteFactura = 0;
|
|
||||||
emptyEstadoResultado.cuentaCorrienteSinRespaldo = 0;
|
|
||||||
emptyEstadoResultado.remuneraciones = 0;
|
|
||||||
emptyEstadoResultado.finiquitos = 0;
|
|
||||||
emptyEstadoResultado.aguinaldo = 0;
|
|
||||||
emptyEstadoResultado.bonosPersonal = 0;
|
|
||||||
emptyEstadoResultado.honorariosContador = 0;
|
|
||||||
emptyEstadoResultado.arriendo = 0;
|
|
||||||
emptyEstadoResultado.agua = 0;
|
|
||||||
emptyEstadoResultado.luz = 0;
|
|
||||||
emptyEstadoResultado.gas = 0;
|
|
||||||
emptyEstadoResultado.telefono = 0;
|
|
||||||
emptyEstadoResultado.otroServicio = 0;
|
|
||||||
emptyEstadoResultado.ppm = 0d;
|
|
||||||
emptyEstadoResultado.ivaFavor = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|||||||
@@ -25,84 +25,41 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.models.ingreso;
|
package danielcortes.xyz.models.ingreso;
|
||||||
|
|
||||||
import danielcortes.xyz.data.ConnectionHolder;
|
|
||||||
import danielcortes.xyz.models.caja.Caja;
|
import danielcortes.xyz.models.caja.Caja;
|
||||||
import danielcortes.xyz.models.caja.CajaDAO;
|
|
||||||
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
|
|
||||||
import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
|
|
||||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.YearMonth;
|
import java.time.YearMonth;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public abstract class IngresoDAO {
|
public interface IngresoDAO {
|
||||||
|
List<Ingreso> getAll();
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(IngresoDAO.class.getName());
|
List<Ingreso> getByCaja(Caja caja);
|
||||||
|
|
||||||
protected ConnectionHolder connectionHolder;
|
Optional<Ingreso> getById(int id);
|
||||||
|
|
||||||
public abstract List<Ingreso> findAll();
|
List<Ingreso> getByTipoIngreso(TipoIngreso tipoIngreso);
|
||||||
|
|
||||||
public abstract List<Ingreso> findByCaja(Caja caja);
|
int getTotalIngreso(Caja caja);
|
||||||
|
|
||||||
public abstract List<Ingreso> findById(int id);
|
int getTotalIngresoMes(YearMonth mes);
|
||||||
|
|
||||||
public abstract List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso);
|
int getTotalExentasMes(YearMonth mes);
|
||||||
|
|
||||||
public abstract boolean insertIngreso(Ingreso ingreso);
|
int getTotalIngresoEnCajaPorTipo(Caja caja, TipoIngreso tipoIngreso);
|
||||||
|
|
||||||
public abstract boolean updateIngreso(Ingreso ingreso);
|
Optional<String> getPrimerNroInicialDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso);
|
||||||
|
|
||||||
public abstract boolean deleteIngreso(Ingreso ingreso);
|
Optional<String> getUltimoNroFinalDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso);
|
||||||
|
|
||||||
public abstract int getTotalIngreso(Caja caja);
|
Optional<String> getPrimerNroZInicialDeCaja(Caja caja);
|
||||||
|
|
||||||
public abstract int getTotalIngresoMes(YearMonth mes);
|
Optional<String> getUltimoNroZFinalDeCaja(Caja caja);
|
||||||
|
|
||||||
public abstract int getTotalExentasMes(YearMonth mes);
|
void insertIngreso(Ingreso ingreso);
|
||||||
|
|
||||||
public abstract int getTotalIngresoEnCajaPorTipo(Caja caja, TipoIngreso tipoIngreso);
|
void updateIngreso(Ingreso ingreso);
|
||||||
|
|
||||||
public abstract Optional<String> getPrimerNroInicialDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso);
|
void deleteIngreso(Ingreso ingreso);
|
||||||
|
|
||||||
public abstract Optional<String> getUltimoNroFinalDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso);
|
|
||||||
|
|
||||||
public abstract Optional<String> getPrimerNroZInicialDeCaja(Caja caja);
|
|
||||||
|
|
||||||
public abstract Optional<String> getUltimoNroZFinalDeCaja(Caja caja);
|
|
||||||
|
|
||||||
List<Ingreso> ingresosFromResultSet(ResultSet rs) throws SQLException {
|
|
||||||
ArrayList<Ingreso> ingresosList = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
int tipoIngresoId = rs.getInt("tipo_ingreso_id");
|
|
||||||
TipoIngresoDAO tipoEgresoDAO = new SQLiteTipoIngresoDAO();
|
|
||||||
TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0);
|
|
||||||
|
|
||||||
int cajaId = rs.getInt("caja_id");
|
|
||||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
|
||||||
Caja caja = cajaDAO.getById(cajaId).get();
|
|
||||||
|
|
||||||
Ingreso ingreso = new Ingreso();
|
|
||||||
|
|
||||||
ingreso.setId(rs.getInt("id"));
|
|
||||||
ingreso.setValor(rs.getInt("valor"));
|
|
||||||
ingreso.setNroZInicial(rs.getString("nro_z_inicial"));
|
|
||||||
ingreso.setNroZFinal(rs.getString("nro_z_final"));
|
|
||||||
ingreso.setNroInicial(rs.getString("nro_inicial"));
|
|
||||||
ingreso.setNroFinal(rs.getString("nro_final"));
|
|
||||||
ingreso.setTipoIngreso(tipoIngreso);
|
|
||||||
ingreso.setCaja(caja);
|
|
||||||
|
|
||||||
LOGGER.log(Level.FINER, "Se a creado: {0}", ingreso);
|
|
||||||
|
|
||||||
ingresosList.add(ingreso);
|
|
||||||
}
|
|
||||||
return ingresosList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,13 @@
|
|||||||
|
|
||||||
package danielcortes.xyz.models.ingreso;
|
package danielcortes.xyz.models.ingreso;
|
||||||
|
|
||||||
|
import danielcortes.xyz.data.ConnectionHolder;
|
||||||
|
import danielcortes.xyz.data.DAOManager;
|
||||||
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
import danielcortes.xyz.data.SQLiteConnectionHolder;
|
||||||
import danielcortes.xyz.models.caja.Caja;
|
import danielcortes.xyz.models.caja.Caja;
|
||||||
|
import danielcortes.xyz.models.caja.CajaDAO;
|
||||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||||
|
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -39,24 +43,46 @@ 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 SQLiteIngresoDAO extends IngresoDAO {
|
public class SQLiteIngresoDAO implements IngresoDAO {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(SQLiteIngresoDAO.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(SQLiteIngresoDAO.class.getName());
|
||||||
|
private ConnectionHolder connectionHolder;
|
||||||
|
|
||||||
public SQLiteIngresoDAO() {
|
public SQLiteIngresoDAO() {
|
||||||
this.connectionHolder = new SQLiteConnectionHolder();
|
this.connectionHolder = new SQLiteConnectionHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Ingreso> findAll() {
|
public List<Ingreso> getAll() {
|
||||||
List<Ingreso> ingresosList = new ArrayList<>();
|
List<Ingreso> ingresosList = new ArrayList<>();
|
||||||
String query = "select * from ingresos";
|
String query = "select * from ingresos";
|
||||||
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0}", query);
|
TipoIngresoDAO tipoIngresoDAO = DAOManager.getTipoIngresoDAO();
|
||||||
ingresosList = this.ingresosFromResultSet(rs);
|
CajaDAO cajaDAO = DAOManager.getCajaDAO();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
TipoIngreso tipoIngreso = tipoIngresoDAO.findById(rs.getInt("tipo_ingreso_id")).get(0);
|
||||||
|
|
||||||
|
//Confio en que la base de datos me dara un id existente
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
||||||
|
|
||||||
|
Ingreso ingreso = new Ingreso();
|
||||||
|
|
||||||
|
ingreso.setId(rs.getInt("id"));
|
||||||
|
ingreso.setValor(rs.getInt("valor"));
|
||||||
|
ingreso.setNroZInicial(rs.getString("nro_z_inicial"));
|
||||||
|
ingreso.setNroZFinal(rs.getString("nro_z_final"));
|
||||||
|
ingreso.setNroInicial(rs.getString("nro_inicial"));
|
||||||
|
ingreso.setNroFinal(rs.getString("nro_final"));
|
||||||
|
ingreso.setTipoIngreso(tipoIngreso);
|
||||||
|
ingreso.setCaja(caja);
|
||||||
|
|
||||||
|
ingresosList.add(ingreso);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -67,15 +93,34 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Ingreso> findByCaja(Caja caja) {
|
public List<Ingreso> getByCaja(Caja caja) {
|
||||||
List<Ingreso> ingresosList = new ArrayList<>();
|
List<Ingreso> ingresosList = new ArrayList<>();
|
||||||
|
if (Caja.EMPTY == caja) {
|
||||||
|
return ingresosList;
|
||||||
|
}
|
||||||
|
|
||||||
String query = "select * from ingresos where caja_id = ?";
|
String query = "select * from ingresos where caja_id = ?";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, caja.getId());
|
ps.setInt(1, caja.getId());
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
|
TipoIngresoDAO tipoIngresoDAO = DAOManager.getTipoIngresoDAO();
|
||||||
ingresosList = this.ingresosFromResultSet(rs);
|
while (rs.next()) {
|
||||||
|
TipoIngreso tipoIngreso = tipoIngresoDAO.findById(rs.getInt("tipo_ingreso_id")).get(0);
|
||||||
|
|
||||||
|
Ingreso ingreso = new Ingreso();
|
||||||
|
|
||||||
|
ingreso.setId(rs.getInt("id"));
|
||||||
|
ingreso.setValor(rs.getInt("valor"));
|
||||||
|
ingreso.setNroZInicial(rs.getString("nro_z_inicial"));
|
||||||
|
ingreso.setNroZFinal(rs.getString("nro_z_final"));
|
||||||
|
ingreso.setNroInicial(rs.getString("nro_inicial"));
|
||||||
|
ingreso.setNroFinal(rs.getString("nro_final"));
|
||||||
|
ingreso.setTipoIngreso(tipoIngreso);
|
||||||
|
ingreso.setCaja(caja);
|
||||||
|
|
||||||
|
ingresosList.add(ingreso);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -85,35 +130,71 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Ingreso> findById(int id) {
|
public Optional<Ingreso> getById(int id) {
|
||||||
List<Ingreso> ingresosList = new ArrayList<>();
|
Ingreso ingreso = null;
|
||||||
String query = "select * from ingresos where id = ?";
|
String query = "select * from ingresos where id = ?";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, id);
|
ps.setInt(1, id);
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, id});
|
TipoIngresoDAO tipoIngresoDAO = DAOManager.getTipoIngresoDAO();
|
||||||
|
CajaDAO cajaDAO = DAOManager.getCajaDAO();
|
||||||
|
|
||||||
ingresosList = this.ingresosFromResultSet(rs);
|
if (rs.next()) {
|
||||||
|
TipoIngreso tipoIngreso = tipoIngresoDAO.findById(rs.getInt("tipo_ingreso_id")).get(0);
|
||||||
|
|
||||||
|
//Confio en que la base de datos me dara un id existente
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
||||||
|
|
||||||
|
ingreso = new Ingreso();
|
||||||
|
|
||||||
|
ingreso.setId(rs.getInt("id"));
|
||||||
|
ingreso.setValor(rs.getInt("valor"));
|
||||||
|
ingreso.setNroZInicial(rs.getString("nro_z_inicial"));
|
||||||
|
ingreso.setNroZFinal(rs.getString("nro_z_final"));
|
||||||
|
ingreso.setNroInicial(rs.getString("nro_inicial"));
|
||||||
|
ingreso.setNroFinal(rs.getString("nro_final"));
|
||||||
|
ingreso.setTipoIngreso(tipoIngreso);
|
||||||
|
ingreso.setCaja(caja);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
}
|
||||||
|
} catch (
|
||||||
|
SQLException e) {
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
return ingresosList;
|
return Optional.ofNullable(ingreso);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso) {
|
public List<Ingreso> getByTipoIngreso(TipoIngreso tipoIngreso) {
|
||||||
List<Ingreso> ingresosList = new ArrayList<>();
|
List<Ingreso> ingresosList = new ArrayList<>();
|
||||||
String query = "select ingresos.* from ingresos inner join tipos_ingreso on (ingresos.tipo_ingreso_id = tipos_ingreso.id) where ingresos.tipo_ingreso_id = ?";
|
String query = "select ingresos.* from ingresos inner join tipos_ingreso on (ingresos.tipo_ingreso_id = tipos_ingreso.id) where ingresos.tipo_ingreso_id = ?";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
ps.setInt(1, tipoIngreso.getId());
|
ps.setInt(1, tipoIngreso.getId());
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}",
|
CajaDAO cajaDAO = DAOManager.getCajaDAO();
|
||||||
new Object[]{query, tipoIngreso.getId()});
|
|
||||||
ingresosList = this.ingresosFromResultSet(rs);
|
while (rs.next()) {
|
||||||
|
//Confio en que la base de datos me dara un id existente
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
Caja caja = cajaDAO.getById(rs.getInt("caja_id")).get();
|
||||||
|
|
||||||
|
Ingreso ingreso = new Ingreso();
|
||||||
|
|
||||||
|
ingreso.setId(rs.getInt("id"));
|
||||||
|
ingreso.setValor(rs.getInt("valor"));
|
||||||
|
ingreso.setNroZInicial(rs.getString("nro_z_inicial"));
|
||||||
|
ingreso.setNroZFinal(rs.getString("nro_z_final"));
|
||||||
|
ingreso.setNroInicial(rs.getString("nro_inicial"));
|
||||||
|
ingreso.setNroFinal(rs.getString("nro_final"));
|
||||||
|
ingreso.setTipoIngreso(tipoIngreso);
|
||||||
|
ingreso.setCaja(caja);
|
||||||
|
|
||||||
|
ingresosList.add(ingreso);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -122,95 +203,13 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
return ingresosList;
|
return ingresosList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean insertIngreso(Ingreso ingreso) {
|
|
||||||
int updates;
|
|
||||||
String query = "insert into ingresos (valor, nro_z_inicial, nro_z_final, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?,?,?)";
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
||||||
ps.setInt(1, ingreso.getValor());
|
|
||||||
ps.setString(2, ingreso.getNroZInicial());
|
|
||||||
ps.setString(3, ingreso.getNroZFinal());
|
|
||||||
ps.setString(4, ingreso.getNroInicial());
|
|
||||||
ps.setString(5, ingreso.getNroFinal());
|
|
||||||
ps.setInt(6, ingreso.getTipoIngreso().getId());
|
|
||||||
ps.setInt(7, ingreso.getCaja().getId());
|
|
||||||
updates = ps.executeUpdate();
|
|
||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7}] | updates: {8}",
|
|
||||||
new Object[]{query, ingreso.getValor(), ingreso.getNroZInicial(),
|
|
||||||
ingreso.getNroZFinal(),
|
|
||||||
ingreso.getNroInicial(), ingreso.getNroFinal(), ingreso.getTipoIngreso().getId(),
|
|
||||||
ingreso.getCaja().getId(), updates});
|
|
||||||
}
|
|
||||||
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) {
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
|
||||||
rs.next();
|
|
||||||
ingreso.setId(rs.getInt(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return updates > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateIngreso(Ingreso ingreso) {
|
|
||||||
int updates;
|
|
||||||
String query = "update ingresos set valor = ?, nro_z_inicial = ?, nro_z_final = ?, nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?";
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
||||||
ps.setInt(1, ingreso.getValor());
|
|
||||||
ps.setString(2, ingreso.getNroZInicial());
|
|
||||||
ps.setString(3, ingreso.getNroZFinal());
|
|
||||||
ps.setString(4, ingreso.getNroInicial());
|
|
||||||
ps.setString(5, ingreso.getNroFinal());
|
|
||||||
ps.setInt(6, ingreso.getTipoIngreso().getId());
|
|
||||||
ps.setInt(7, ingreso.getCaja().getId());
|
|
||||||
ps.setInt(8, ingreso.getId());
|
|
||||||
updates = ps.executeUpdate();
|
|
||||||
|
|
||||||
LOGGER
|
|
||||||
.log(Level.FINE,
|
|
||||||
"QUERY: {0} | values: [{1},{2},{3},{4},{5},{6},{7},{8}] | updates: {9}",
|
|
||||||
new Object[]{query, ingreso.getValor(), ingreso.getNroZInicial(),
|
|
||||||
ingreso.getNroZFinal(), ingreso.getNroInicial(), ingreso.getNroFinal(),
|
|
||||||
ingreso.getTipoIngreso().getId(), ingreso.getCaja().getId(), ingreso.getId(),
|
|
||||||
updates});
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return updates > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deleteIngreso(Ingreso ingreso) {
|
|
||||||
int updates;
|
|
||||||
String query = "delete from ingresos where id = ?";
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
||||||
ps.setInt(1, ingreso.getId());
|
|
||||||
updates = ps.executeUpdate();
|
|
||||||
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1} | updates: {2}",
|
|
||||||
new Object[]{query, ingreso.getId(), updates});
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return updates > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTotalIngreso(Caja caja) {
|
public int getTotalIngreso(Caja caja) {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
if (Caja.EMPTY == caja) {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
String query = "select sum(valor) from ingresos where caja_id = ?";
|
String query = "select sum(valor) from ingresos where caja_id = ?";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
@@ -276,11 +275,10 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTotalIngresoEnCajaPorTipo(Caja caja, TipoIngreso tipoIngreso) {
|
public int getTotalIngresoEnCajaPorTipo(Caja caja, TipoIngreso tipoIngreso) {
|
||||||
if (caja == Caja.EMPTY) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
if (caja == Caja.EMPTY) {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
String query = "select sum(valor) from ingresos where caja_id = ? and tipo_ingreso_id = ?";
|
String query = "select sum(valor) from ingresos where caja_id = ? and tipo_ingreso_id = ?";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
@@ -300,12 +298,12 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getPrimerNroInicialDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso) {
|
public Optional<String> getPrimerNroInicialDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso) {
|
||||||
if (caja == Caja.EMPTY) {
|
|
||||||
return Optional.of("0");
|
|
||||||
}
|
|
||||||
|
|
||||||
String nroInicial = null;
|
String nroInicial = null;
|
||||||
|
|
||||||
|
if (caja == Caja.EMPTY) {
|
||||||
|
return Optional.ofNullable(nroInicial);
|
||||||
|
}
|
||||||
|
|
||||||
String query = "select nro_inicial from ingresos where caja_id = ? and tipo_ingreso_id = ? order by nro_inicial asc limit 1";
|
String query = "select nro_inicial from ingresos where caja_id = ? and tipo_ingreso_id = ? order by nro_inicial asc limit 1";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
@@ -325,10 +323,11 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getUltimoNroFinalDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso) {
|
public Optional<String> getUltimoNroFinalDeCajaDeTipo(Caja caja, TipoIngreso tipoIngreso) {
|
||||||
if (caja == Caja.EMPTY) {
|
|
||||||
return Optional.of("0");
|
|
||||||
}
|
|
||||||
String nroFinal = null;
|
String nroFinal = null;
|
||||||
|
if (caja == Caja.EMPTY) {
|
||||||
|
return Optional.ofNullable(nroFinal);
|
||||||
|
}
|
||||||
|
|
||||||
String query = "select nro_final from ingresos where caja_id = ? and tipo_ingreso_id = ? order by nro_inicial desc limit 1";
|
String query = "select nro_final from ingresos where caja_id = ? and tipo_ingreso_id = ? order by nro_inicial desc limit 1";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
@@ -349,10 +348,12 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getPrimerNroZInicialDeCaja(Caja caja) {
|
public Optional<String> getPrimerNroZInicialDeCaja(Caja caja) {
|
||||||
if (caja == Caja.EMPTY) {
|
|
||||||
return Optional.of("0");
|
|
||||||
}
|
|
||||||
String nroZInicial = null;
|
String nroZInicial = null;
|
||||||
|
|
||||||
|
if (caja == Caja.EMPTY) {
|
||||||
|
return Optional.ofNullable(nroZInicial);
|
||||||
|
}
|
||||||
|
|
||||||
String query = "select nro_z_inicial from ingresos where caja_id = ? and tipo_ingreso_id = 1 order by nro_inicial desc limit 1";
|
String query = "select nro_z_inicial from ingresos where caja_id = ? and tipo_ingreso_id = 1 order by nro_inicial desc limit 1";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
@@ -372,10 +373,10 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getUltimoNroZFinalDeCaja(Caja caja) {
|
public Optional<String> getUltimoNroZFinalDeCaja(Caja caja) {
|
||||||
if (caja == Caja.EMPTY) {
|
|
||||||
return Optional.of("0");
|
|
||||||
}
|
|
||||||
String nroZFinal = null;
|
String nroZFinal = null;
|
||||||
|
if (caja == Caja.EMPTY) {
|
||||||
|
return Optional.ofNullable(nroZFinal);
|
||||||
|
}
|
||||||
String query = "select nro_z_final from ingresos where caja_id = ? and tipo_ingreso_id = 1 order by nro_inicial desc limit 1";
|
String query = "select nro_z_final from ingresos where caja_id = ? and tipo_ingreso_id = 1 order by nro_inicial desc limit 1";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
@@ -393,4 +394,62 @@ public class SQLiteIngresoDAO extends IngresoDAO {
|
|||||||
return Optional.ofNullable(nroZFinal);
|
return Optional.ofNullable(nroZFinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertIngreso(Ingreso ingreso) {
|
||||||
|
String query = "insert into ingresos (valor, nro_z_inicial, nro_z_final, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?,?,?)";
|
||||||
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
ps.setInt(1, ingreso.getValor());
|
||||||
|
ps.setString(2, ingreso.getNroZInicial());
|
||||||
|
ps.setString(3, ingreso.getNroZFinal());
|
||||||
|
ps.setString(4, ingreso.getNroInicial());
|
||||||
|
ps.setString(5, ingreso.getNroFinal());
|
||||||
|
ps.setInt(6, ingreso.getTipoIngreso().getId());
|
||||||
|
ps.setInt(7, ingreso.getCaja().getId());
|
||||||
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) {
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
rs.next();
|
||||||
|
ingreso.setId(rs.getInt(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateIngreso(Ingreso ingreso) {
|
||||||
|
String query = "update ingresos set valor = ?, nro_z_inicial = ?, nro_z_final = ?, nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?";
|
||||||
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
ps.setInt(1, ingreso.getValor());
|
||||||
|
ps.setString(2, ingreso.getNroZInicial());
|
||||||
|
ps.setString(3, ingreso.getNroZFinal());
|
||||||
|
ps.setString(4, ingreso.getNroInicial());
|
||||||
|
ps.setString(5, ingreso.getNroFinal());
|
||||||
|
ps.setInt(6, ingreso.getTipoIngreso().getId());
|
||||||
|
ps.setInt(7, ingreso.getCaja().getId());
|
||||||
|
ps.setInt(8, ingreso.getId());
|
||||||
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteIngreso(Ingreso ingreso) {
|
||||||
|
String query = "delete from ingresos where id = ?";
|
||||||
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
ps.setInt(1, ingreso.getId());
|
||||||
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user