avance en los test
This commit is contained in:
@@ -110,7 +110,16 @@ public class CajasController {
|
||||
|
||||
Efectivo efectivo = new Efectivo();
|
||||
efectivo.setCaja(c);
|
||||
DAOManager.getEfectivoDAO().insertDefault(efectivo);
|
||||
efectivo.setDiez(0);
|
||||
efectivo.setCincuenta(0);
|
||||
efectivo.setCien(0);
|
||||
efectivo.setQuinientos(0);
|
||||
efectivo.setMil(0);
|
||||
efectivo.setDosMil(0);
|
||||
efectivo.setCincoMil(0);
|
||||
efectivo.setDiezMil(0);
|
||||
efectivo.setVeinteMil(0);
|
||||
DAOManager.getEfectivoDAO().insert(efectivo);
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
documentos.setTarjetas(0);
|
||||
|
||||
@@ -124,6 +124,12 @@ public class SQLiteCajaDAO implements CajaDAO {
|
||||
@Override
|
||||
public void insert(Caja caja) {
|
||||
log.debug("Se intentara insertar la caja " + caja);
|
||||
|
||||
if(caja == Caja.EMPTY){
|
||||
log.debug("La caja era Caja.EMPTY, no se puede insertar");
|
||||
return;
|
||||
}
|
||||
|
||||
String query = "insert into caja (fecha, fondo) values (?, ?)";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
|
||||
@@ -28,7 +28,6 @@ import danielcortes.xyz.models.caja.Caja;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CalculoFondo {
|
||||
|
||||
private int id;
|
||||
private int valor;
|
||||
private String descripcion;
|
||||
|
||||
@@ -79,7 +79,6 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
||||
return calculoFondoList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<CalculoFondo> getByCaja(Caja caja) {
|
||||
log.debug("Se intentara conseguir todos los calculos fondo de la caja " + caja);
|
||||
@@ -172,6 +171,11 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
||||
public void insert(CalculoFondo calculoFondo) {
|
||||
log.debug("Se intentara insertar el calculoFondo " + calculoFondo);
|
||||
|
||||
if(calculoFondo.getCaja() == Caja.EMPTY){
|
||||
log.error("El calculo fondo tiene una caja EMPTY, no se insertara");
|
||||
return;
|
||||
}
|
||||
|
||||
String query = "insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
@@ -197,6 +201,12 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
|
||||
@Override
|
||||
public void update(CalculoFondo calculoFondo) {
|
||||
log.debug("Se intentara actualizar el CalculoFondo " + calculoFondo);
|
||||
|
||||
if (calculoFondo.getCaja() == Caja.EMPTY) {
|
||||
log.error("El calculo fondo tiene una caja EMPTY, no se actualizara");
|
||||
return;
|
||||
}
|
||||
|
||||
String query = "update calculo_fondo set valor = ?, descripcion = ?, caja_id = ? where id = ?";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
|
||||
@@ -32,12 +32,14 @@ public interface EfectivoDAO {
|
||||
|
||||
/**
|
||||
* Obtiene todos los Efectivo
|
||||
*
|
||||
* @return Una lista con los Efectivo
|
||||
*/
|
||||
List<Efectivo> getAll();
|
||||
|
||||
/**
|
||||
* Obtiene un Efectivo por su id
|
||||
*
|
||||
* @param id Id del Efectivo
|
||||
* @return Un Optional que puede contener un Efectivo o puede estar vacio
|
||||
*/
|
||||
@@ -45,6 +47,7 @@ public interface EfectivoDAO {
|
||||
|
||||
/**
|
||||
* Obtiene un Efectivo por su Caja
|
||||
*
|
||||
* @param caja Caja a la que pertence el Efectivo
|
||||
* @return Un Optional que puede contener un Efectivo o puede estar vacio
|
||||
*/
|
||||
@@ -52,6 +55,7 @@ public interface EfectivoDAO {
|
||||
|
||||
/**
|
||||
* Obtiene la suma de los valores de los Efectivo pertencientes a una Caja
|
||||
*
|
||||
* @param caja Caja a la que pertenecen los Efectivo a sumar
|
||||
* @return La suma de los valores de Efectivo
|
||||
*/
|
||||
@@ -59,24 +63,21 @@ public interface EfectivoDAO {
|
||||
|
||||
/**
|
||||
* Guarda un Efectivo, le agrega un id a la instancia
|
||||
*
|
||||
* @param efectivo Efectivo a guardar
|
||||
*/
|
||||
void insert(Efectivo efectivo);
|
||||
|
||||
/**
|
||||
* Guarda un Efectivo con valores por defecto, le agrega un id a la instancia
|
||||
* @param efectivo Instancia de efectivo a guardar
|
||||
*/
|
||||
void insertDefault(Efectivo efectivo);
|
||||
|
||||
/**
|
||||
* Actualiza un Efectivo
|
||||
*
|
||||
* @param efectivo Efectivo a guardar
|
||||
*/
|
||||
void update(Efectivo efectivo);
|
||||
|
||||
/**
|
||||
* Elimina un Efectivo
|
||||
*
|
||||
* @param efectivo Efectivo a eliminar
|
||||
*/
|
||||
void delete(Efectivo efectivo);
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
|
||||
private static final Logger log = LogManager.getLogger(SQLiteEfectivoDAO.class);
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
@@ -158,7 +159,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("Error al intentar conseguir un Efectivo perteneciente a la caja " + caja );
|
||||
log.error("Error al intentar conseguir un Efectivo perteneciente a la caja " + caja);
|
||||
}
|
||||
|
||||
log.debug("Se obtuvo el efectivo " + efectivo);
|
||||
@@ -223,27 +224,6 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
log.debug("Se inserto el efectivo " + efectivo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertDefault(Efectivo efectivo) {
|
||||
log.debug("Se intentara insertar el efectivo por default " + efectivo);
|
||||
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
ps.setInt(1, efectivo.getCaja().getId());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) {
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
rs.next();
|
||||
efectivo.setId(rs.getInt(1));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("Error al insertar el efectivo por default " + efectivo, e);
|
||||
}
|
||||
log.debug("Se inserto el efectivo por default " + efectivo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Efectivo efectivo) {
|
||||
log.debug("Se intentara actualizar el efectivo " + efectivo);
|
||||
|
||||
Reference in New Issue
Block a user