/* * 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.ingreso; import danielcortes.xyz.data.ConnectionHolder; 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.TipoIngresoDAO; import java.sql.ResultSet; import java.sql.SQLException; import java.time.YearMonth; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; public abstract class IngresoDAO { private static final Logger LOGGER = Logger.getLogger(IngresoDAO.class.getName()); protected ConnectionHolder connectionHolder; public abstract List findAll(); public abstract List findByCaja(Caja caja); public abstract List findById(int id); public abstract List findByTipoIngreso(TipoIngreso tipoIngreso); public abstract boolean insertIngreso(Ingreso ingreso); public abstract boolean updateIngreso(Ingreso ingreso); public abstract boolean deleteIngreso(Ingreso ingreso); public abstract int getTotalIngreso(Caja caja); public abstract int getTotalIngresoMes(YearMonth mes); public abstract int getTotalExentasMes(YearMonth mes); List ingresosFromResultSet(ResultSet rs) throws SQLException { ArrayList 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; } }