Resubido todo

This commit is contained in:
Daniel Cortes
2018-12-29 01:15:35 -03:00
parent 29d7f910d7
commit 7e94207da3
91 changed files with 10525 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
/*
* MIT License
*
* Copyright (c) 2018 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.efectivo;
import danielcortes.xyz.models.caja.Caja;
public class Efectivo {
private int id;
private int veinteMil;
private int diezMil;
private int cincoMil;
private int dosMil;
private int mil;
private int quinientos;
private int cien;
private int cincuenta;
private int diez;
private Caja caja;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVeinteMil() {
return veinteMil;
}
public void setVeinteMil(int veinteMil) {
this.veinteMil = veinteMil;
}
public int getDiezMil() {
return diezMil;
}
public void setDiezMil(int diezMil) {
this.diezMil = diezMil;
}
public int getCincoMil() {
return cincoMil;
}
public void setCincoMil(int cincoMil) {
this.cincoMil = cincoMil;
}
public int getDosMil() {
return dosMil;
}
public void setDosMil(int dosMil) {
this.dosMil = dosMil;
}
public int getMil() {
return mil;
}
public void setMil(int mil) {
this.mil = mil;
}
public int getQuinientos() {
return quinientos;
}
public void setQuinientos(int quinientos) {
this.quinientos = quinientos;
}
public int getCien() {
return cien;
}
public void setCien(int cien) {
this.cien = cien;
}
public int getCincuenta() {
return cincuenta;
}
public void setCincuenta(int cincuenta) {
this.cincuenta = cincuenta;
}
public int getDiez() {
return diez;
}
public void setDiez(int diez) {
this.diez = diez;
}
public Caja getCaja() {
return caja;
}
public void setCaja(Caja caja) {
this.caja = caja;
}
}

View File

@@ -0,0 +1,73 @@
/*
* MIT License
*
* Copyright (c) 2018 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.efectivo;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public abstract class EfectivoDAO {
protected ConnectionHolder connectionHolder;
public abstract List<Efectivo> findAll();
public abstract Efectivo findById(int id);
public abstract Efectivo findByCaja(Caja caja);
public abstract boolean insertEfectivo(Efectivo efectivo);
public abstract boolean insertDefaultEfectivo(Efectivo efectivo);
public abstract boolean updateEfectivo(Efectivo efectivo);
public abstract boolean deleteEfectivo(Efectivo efectivo);
protected List<Efectivo> efectivosFromResultSet(ResultSet rs) throws SQLException {
List<Efectivo> efectivoList = new ArrayList<>();
while (rs.next()) {
CajaDAO cajaDAO = new MysqlCajaDAO();
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
Efectivo efectivo = new Efectivo();
efectivo.setCaja(caja);
efectivo.setId(rs.getInt("id"));
efectivo.setVeinteMil(rs.getInt("veinte_mil"));
efectivo.setDiezMil(rs.getInt("diez_mil"));
efectivo.setCincoMil(rs.getInt("cinco_mil"));
efectivo.setDosMil(rs.getInt("dos_mil"));
efectivo.setMil(rs.getInt("mil"));
efectivo.setQuinientos(rs.getInt("quinientos"));
efectivo.setCien(rs.getInt("cien"));
efectivo.setCincuenta(rs.getInt("cincuenta"));
efectivo.setDiez(rs.getInt("diez"));
efectivoList.add(efectivo);
}
return efectivoList;
}
}

View File

@@ -0,0 +1,218 @@
/*
* MIT License
*
* Copyright (c) 2018 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.efectivo;
import danielcortes.xyz.data.MysqlConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.MysqlCajaDAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class MysqlEfectivoDAO extends EfectivoDAO {
public MysqlEfectivoDAO() {
this.connectionHolder = new MysqlConnectionHolder();
}
@Override
public List<Efectivo> findAll() {
List<Efectivo> efectivoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos");
ResultSet rs = ps.executeQuery();
efectivoList = this.efectivosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivoList;
}
@Override
public Efectivo findById(int id) {
Efectivo efectivo = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
efectivo = this.efectivosFromResultSet(rs).get(0);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivo;
}
@Override
public Efectivo findByCaja(Caja caja) {
Efectivo efectivo = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
List<Efectivo> efectivoList = this.efectivosFromResultSet(rs);
if (efectivoList.size() > 0) {
efectivo = efectivoList.get(0);
}
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivo;
}
@Override
public boolean insertEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
ps.setInt(4, efectivo.getDosMil());
ps.setInt(5, efectivo.getMil());
ps.setInt(6, efectivo.getQuinientos());
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_id()");
ResultSet rs = ps.executeQuery();
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean insertDefaultEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("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,?)");
ps.setInt(1, efectivo.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_id()");
ResultSet rs = ps.executeQuery();
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean updateEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
ps.setInt(4, efectivo.getDosMil());
ps.setInt(5, efectivo.getMil());
ps.setInt(6, efectivo.getQuinientos());
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
ps.setInt(11, efectivo.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean deleteEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?");
ps.setInt(1, efectivo.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
}

View File

@@ -0,0 +1,218 @@
/*
* MIT License
*
* Copyright (c) 2018 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.efectivo;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class SQLiteEfectivoDAO extends EfectivoDAO {
public SQLiteEfectivoDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
@Override
public List<Efectivo> findAll() {
List<Efectivo> efectivoList = new ArrayList<>();
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos");
ResultSet rs = ps.executeQuery();
efectivoList = this.efectivosFromResultSet(rs);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivoList;
}
@Override
public Efectivo findById(int id) {
Efectivo efectivo = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
efectivo = this.efectivosFromResultSet(rs).get(0);
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivo;
}
@Override
public Efectivo findByCaja(Caja caja) {
Efectivo efectivo = null;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
ps.setInt(1, caja.getId());
ResultSet rs = ps.executeQuery();
List<Efectivo> efectivoList = this.efectivosFromResultSet(rs);
if (efectivoList.size() > 0) {
efectivo = efectivoList.get(0);
}
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return efectivo;
}
@Override
public boolean insertEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
ps.setInt(4, efectivo.getDosMil());
ps.setInt(5, efectivo.getMil());
ps.setInt(6, efectivo.getQuinientos());
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean insertDefaultEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("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,?)");
ps.setInt(1, efectivo.getCaja().getId());
updates = ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select last_insert_rowid()");
ResultSet rs = ps.executeQuery();
rs.next();
efectivo.setId(rs.getInt(1));
rs.close();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean updateEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?");
ps.setInt(1, efectivo.getVeinteMil());
ps.setInt(2, efectivo.getDiezMil());
ps.setInt(3, efectivo.getCincoMil());
ps.setInt(4, efectivo.getDosMil());
ps.setInt(5, efectivo.getMil());
ps.setInt(6, efectivo.getQuinientos());
ps.setInt(7, efectivo.getCien());
ps.setInt(8, efectivo.getCincuenta());
ps.setInt(9, efectivo.getDiez());
ps.setInt(10, efectivo.getCaja().getId());
ps.setInt(11, efectivo.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
@Override
public boolean deleteEfectivo(Efectivo efectivo) {
int updates;
try {
Connection conn = connectionHolder.getConnection();
PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?");
ps.setInt(1, efectivo.getId());
updates = ps.executeUpdate();
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return updates > 0;
}
}