La palaba get es mas bonita que find
This commit is contained in:
@@ -75,7 +75,7 @@ public class ArqueoController extends BaseController {
|
|||||||
* Rellena los campos del efectivo con la instancia de efectivo que pertenece a la caja
|
* Rellena los campos del efectivo con la instancia de efectivo que pertenece a la caja
|
||||||
*/
|
*/
|
||||||
private void fillEfectivo() {
|
private void fillEfectivo() {
|
||||||
this.efectivo = DAOManager.getEfectivoDAO().findByCaja(this.caja).orElse(Efectivo.EMPTY);
|
this.efectivo = DAOManager.getEfectivoDAO().getByCaja(this.caja).orElse(Efectivo.EMPTY);
|
||||||
this.view.getVeinteMilField().setValue(efectivo.getVeinteMil());
|
this.view.getVeinteMilField().setValue(efectivo.getVeinteMil());
|
||||||
this.view.getDiezMilField().setValue(efectivo.getDiezMil());
|
this.view.getDiezMilField().setValue(efectivo.getDiezMil());
|
||||||
this.view.getCincoMilField().setValue(efectivo.getCincoMil());
|
this.view.getCincoMilField().setValue(efectivo.getCincoMil());
|
||||||
@@ -91,7 +91,7 @@ public class ArqueoController extends BaseController {
|
|||||||
* Rellea los campos de documentos con la instancia de documentos que pertenece a la caja
|
* Rellea los campos de documentos con la instancia de documentos que pertenece a la caja
|
||||||
*/
|
*/
|
||||||
private void fillDocumentos() {
|
private void fillDocumentos() {
|
||||||
this.documentos = DAOManager.getDocumentosDAO().findByCaja(caja).orElse(Documentos.EMPTY);
|
this.documentos = DAOManager.getDocumentosDAO().getByCaja(caja).orElse(Documentos.EMPTY);
|
||||||
this.view.getTarjetasField().setValue(documentos.getTarjetas());
|
this.view.getTarjetasField().setValue(documentos.getTarjetas());
|
||||||
this.view.getChequesField().setValue(documentos.getCheques());
|
this.view.getChequesField().setValue(documentos.getCheques());
|
||||||
this.view.getRetiroField().setValue(documentos.getRetiros());
|
this.view.getRetiroField().setValue(documentos.getRetiros());
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class CalcularFondoController extends BaseController {
|
|||||||
private void fillTable() {
|
private void fillTable() {
|
||||||
FondoTableModel tableModel = this.view.getTableModel();
|
FondoTableModel tableModel = this.view.getTableModel();
|
||||||
tableModel.removeRows();
|
tableModel.removeRows();
|
||||||
for (CalculoFondo calculoFondo : DAOManager.getCalculoFondoDAO().findByCaja(this.caja)) {
|
for (CalculoFondo calculoFondo : DAOManager.getCalculoFondoDAO().getByCaja(this.caja)) {
|
||||||
tableModel.addRow(calculoFondo);
|
tableModel.addRow(calculoFondo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,18 +30,17 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public interface CalculoFondoDAO {
|
public interface CalculoFondoDAO {
|
||||||
|
|
||||||
List<CalculoFondo> findAll();
|
List<CalculoFondo> getAll();
|
||||||
|
|
||||||
List<CalculoFondo> findByCaja(Caja caja);
|
List<CalculoFondo> getByCaja(Caja caja);
|
||||||
|
|
||||||
Optional<CalculoFondo> findById(int id);
|
Optional<CalculoFondo> getById(int id);
|
||||||
|
|
||||||
|
int getTotalCalculoFondo(Caja caja);
|
||||||
|
|
||||||
void insertCalculoFondo(CalculoFondo calculoFondo);
|
void insertCalculoFondo(CalculoFondo calculoFondo);
|
||||||
|
|
||||||
void updateCalculoFondo(CalculoFondo calculoFondo);
|
void updateCalculoFondo(CalculoFondo calculoFondo);
|
||||||
|
|
||||||
void deleteCalculoFondo(CalculoFondo calculoFondo);
|
void deleteCalculoFondo(CalculoFondo calculoFondo);
|
||||||
|
|
||||||
int getTotalCalculoFondo(Caja caja);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CalculoFondo> findAll() {
|
public List<CalculoFondo> getAll() {
|
||||||
List<CalculoFondo> calculoFondoList = new ArrayList<>();
|
List<CalculoFondo> calculoFondoList = new ArrayList<>();
|
||||||
String query = "select * from calculo_fondo";
|
String query = "select * from calculo_fondo";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
@@ -79,7 +79,7 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CalculoFondo> findByCaja(Caja caja) {
|
public List<CalculoFondo> getByCaja(Caja caja) {
|
||||||
List<CalculoFondo> calculoFondoList = new ArrayList<>();
|
List<CalculoFondo> calculoFondoList = new ArrayList<>();
|
||||||
if(Caja.EMPTY == caja){
|
if(Caja.EMPTY == caja){
|
||||||
return calculoFondoList;
|
return calculoFondoList;
|
||||||
@@ -111,7 +111,7 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<CalculoFondo> findById(int id) {
|
public Optional<CalculoFondo> getById(int id) {
|
||||||
CalculoFondo calculoFondo = null;
|
CalculoFondo calculoFondo = null;
|
||||||
String query = "select * from calculo_fondo where id = ?";
|
String query = "select * from calculo_fondo where id = ?";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
@@ -138,6 +138,33 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
|||||||
return Optional.ofNullable(calculoFondo);
|
return Optional.ofNullable(calculoFondo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalCalculoFondo(Caja caja) {
|
||||||
|
int sum = 0;
|
||||||
|
|
||||||
|
if (Caja.EMPTY == caja) {
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
String query = "select sum(valor) from calculo_fondo where caja_id = ?";
|
||||||
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
ps.setInt(1, caja.getId());
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
sum = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertCalculoFondo(CalculoFondo calculoFondo) {
|
public void insertCalculoFondo(CalculoFondo calculoFondo) {
|
||||||
String query = "insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)";
|
String query = "insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)";
|
||||||
@@ -192,32 +219,4 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
|||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTotalCalculoFondo(Caja caja) {
|
|
||||||
int sum = 0;
|
|
||||||
|
|
||||||
if (Caja.EMPTY == caja) {
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
String query = "select sum(valor) from calculo_fondo where caja_id = ?";
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
||||||
ps.setInt(1, caja.getId());
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
|
||||||
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
|
|
||||||
|
|
||||||
if (rs.next()) {
|
|
||||||
sum = rs.getInt(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public interface DocumentosDAO {
|
public interface DocumentosDAO {
|
||||||
|
|
||||||
List<Documentos> findAll();
|
List<Documentos> getAll();
|
||||||
|
|
||||||
Optional<Documentos> findById(int id);
|
Optional<Documentos> getById(int id);
|
||||||
|
|
||||||
Optional<Documentos> findByCaja(Caja caja);
|
Optional<Documentos> getByCaja(Caja caja);
|
||||||
|
|
||||||
|
int getTotalDocumentos(Caja caja);
|
||||||
|
|
||||||
void insertDocumentos(Documentos documentos);
|
void insertDocumentos(Documentos documentos);
|
||||||
|
|
||||||
@@ -43,7 +45,4 @@ public interface DocumentosDAO {
|
|||||||
void updateDocumentos(Documentos documentos);
|
void updateDocumentos(Documentos documentos);
|
||||||
|
|
||||||
void deleteDocumentos(Documentos documentos);
|
void deleteDocumentos(Documentos documentos);
|
||||||
|
|
||||||
int getTotalDocumentos(Caja caja);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Documentos> findAll() {
|
public List<Documentos> getAll() {
|
||||||
List<Documentos> documentosList = new ArrayList<>();
|
List<Documentos> documentosList = new ArrayList<>();
|
||||||
String query = "select * from documentos";
|
String query = "select * from documentos";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
@@ -80,7 +80,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Documentos> findById(int id) {
|
public Optional<Documentos> getById(int id) {
|
||||||
Documentos documentos = null;
|
Documentos documentos = null;
|
||||||
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
@@ -111,7 +111,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Documentos> findByCaja(Caja caja) {
|
public Optional<Documentos> getByCaja(Caja caja) {
|
||||||
Documentos documentos = null;
|
Documentos documentos = null;
|
||||||
|
|
||||||
if (Caja.EMPTY == caja) {
|
if (Caja.EMPTY == caja) {
|
||||||
@@ -141,6 +141,29 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
|
|||||||
return Optional.ofNullable(documentos);
|
return Optional.ofNullable(documentos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalDocumentos(Caja caja) {
|
||||||
|
int total = 0;
|
||||||
|
if (Caja.EMPTY == caja) {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
String query = "select cheques + tarjetas + retiros from documentos where caja_id = ?";
|
||||||
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
ps.setInt(1, caja.getId());
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
total = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertDocumentos(Documentos documentos) {
|
public void insertDocumentos(Documentos documentos) {
|
||||||
String query = "insert into documentos (cheques, tarjetas, retiros, caja_id) values (?,?,?,?)";
|
String query = "insert into documentos (cheques, tarjetas, retiros, caja_id) values (?,?,?,?)";
|
||||||
@@ -213,26 +236,4 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTotalDocumentos(Caja caja) {
|
|
||||||
int total = 0;
|
|
||||||
if (Caja.EMPTY == caja) {
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
String query = "select cheques + tarjetas + retiros from documentos where caja_id = ?";
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
||||||
ps.setInt(1, caja.getId());
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
|
||||||
if (rs.next()) {
|
|
||||||
total = rs.getInt(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public interface EfectivoDAO {
|
public interface EfectivoDAO {
|
||||||
|
|
||||||
List<Efectivo> findAll();
|
List<Efectivo> getAll();
|
||||||
|
|
||||||
Optional<Efectivo> findById(int id);
|
Optional<Efectivo> getById(int id);
|
||||||
|
|
||||||
Optional<Efectivo> findByCaja(Caja caja);
|
Optional<Efectivo> getByCaja(Caja caja);
|
||||||
|
|
||||||
|
int getTotalEfectivo(Caja caja);
|
||||||
|
|
||||||
void insertEfectivo(Efectivo efectivo);
|
void insertEfectivo(Efectivo efectivo);
|
||||||
|
|
||||||
@@ -44,5 +46,4 @@ public interface EfectivoDAO {
|
|||||||
|
|
||||||
void deleteEfectivo(Efectivo efectivo);
|
void deleteEfectivo(Efectivo efectivo);
|
||||||
|
|
||||||
int getTotalEfectivo(Caja caja);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Efectivo> findAll() {
|
public List<Efectivo> getAll() {
|
||||||
List<Efectivo> efectivoList = new ArrayList<>();
|
List<Efectivo> efectivoList = new ArrayList<>();
|
||||||
String query = "select * from efectivos";
|
String query = "select * from efectivos";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
@@ -86,7 +86,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Efectivo> findById(int id) {
|
public Optional<Efectivo> getById(int id) {
|
||||||
Efectivo efectivo = null;
|
Efectivo efectivo = null;
|
||||||
String query = "select * from efectivos where id = ?";
|
String query = "select * from efectivos where id = ?";
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
@@ -122,7 +122,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Efectivo> findByCaja(Caja caja) {
|
public Optional<Efectivo> getByCaja(Caja caja) {
|
||||||
Efectivo efectivo = null;
|
Efectivo efectivo = null;
|
||||||
if (Caja.EMPTY == caja) {
|
if (Caja.EMPTY == caja) {
|
||||||
return Optional.ofNullable(efectivo);
|
return Optional.ofNullable(efectivo);
|
||||||
@@ -156,6 +156,29 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
|||||||
return Optional.ofNullable(efectivo);
|
return Optional.ofNullable(efectivo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalEfectivo(Caja caja) {
|
||||||
|
int total = 0;
|
||||||
|
if (Caja.EMPTY == caja) {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
String query = "select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?";
|
||||||
|
try (Connection conn = connectionHolder.getConnection()) {
|
||||||
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||||
|
ps.setInt(1, caja.getId());
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
total = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e.toString(), e);
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertEfectivo(Efectivo efectivo) {
|
public void insertEfectivo(Efectivo efectivo) {
|
||||||
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)";
|
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)";
|
||||||
@@ -240,26 +263,4 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTotalEfectivo(Caja caja) {
|
|
||||||
int total = 0;
|
|
||||||
if (Caja.EMPTY == caja) {
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
String query = "select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?";
|
|
||||||
try (Connection conn = connectionHolder.getConnection()) {
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
||||||
ps.setInt(1, caja.getId());
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
|
||||||
if (rs.next()) {
|
|
||||||
total = rs.getInt(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, e.toString(), e);
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user