/** * @(#) PersistenciaTadremed.java */ package com.tarisan.control; import com.tarisan.data.Taconaut; import com.tarisan.data.Tadremed; import com.tarisan.log.*; import com.tarisan.util.DES; import com.tarisan.util.Utilidades; import com.tarisan.excepcion.ExcepcionTarisan; import java.sql.*; import java.util.Vector; /** * Controla los accesos a la persistencia para la entidad Tadremed. * @author Dpto. Informática. * @version 1.0, 24/09/2003 */ public class PersistenciaTadremed { /** * El objeto Paginacion que controla el número de filas a mostrar por cada página. */ private Paginacion objPaginacion = new Paginacion(); /** * Obtiene el valor del objeto Paginacion para saber que página se está visualizando. * @return El objeto Paginacion. */ public Paginacion getPaginacion() { return objPaginacion; } /** * Selecciona los registros de la tabla TADREMED en función de la sentencia SELECT indicada. * @param sqlSelect La sentencia SELECT de selección. * @param pagina Número de página a mostrar. * @param aCondiciones Array que contiene los parámetros utilizados en la sentencia SELECT. * @return El Vector con los registros seleccionados (todos pertenencientes a la clase Tadremed). * @throws */ public Vector seleccionar(String sqlSelect/*, int pagina*/, Object[] aCondiciones) throws ExcepcionTarisan { /*int elementosPaginacion=1;*/ Vector vResultado = new Vector(); Tadremed tadremed = null; try { Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect, aCondiciones); /*objPaginacion.inicializarPaginacion(rs); if (objPaginacion.getNumeroRegistrosTotales()!=0) { objPaginacion.realizarPaginacion(rs, pagina); */ while(rs.next() /*&& (elementosPaginacion <= Paginacion.getFilasPorPagina())*/) { tadremed = new Tadremed(); tadremed.setFecha(rs.getDate("FECHA")); tadremed.setIrpf(rs.getDouble("IRPF")); tadremed.setImporte(rs.getDouble("IMPORTE")); vResultado.addElement(tadremed); /*if (pagina!=0) //Se quiere realizar la paginacion elementosPaginacion++;*/ } /*}*/ rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " registros de la tabla TADREMED (" + sqlSelect + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TADREMED: " + sqle + " (" + sqlSelect + ")"); throw (ExcepcionTarisan)sqle; } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TADREMED: " + sqle + " (" + sqlSelect + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TADREMED: " + sqle + " (" + sqlSelect + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TADREMED: " + sqle + " (" + sqlSelect + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } return vResultado; } public Vector listado_detalle_irpf(String anio, int medico/*, int intPagina*/) { Vector resul = new Vector(); StringBuffer strSql = new StringBuffer(); Object [] aCondiciones = new Object[1]; String consulta = ""; strSql.append("SELECT FECHA, IRPF, IMPORTE"); strSql.append(" FROM TADREMED"); strSql.append(" WHERE MEDICO=?"); if (!anio.equalsIgnoreCase("")) //la sql tiene dos parametros { if (ParametrosConfiguracion.dataStore.getClass().getName().toUpperCase().indexOf("ORACLE") >= 0) { strSql.append(" AND EXTRACT(YEAR FROM FECHA) = ?"); } else { strSql.append(" AND {fn YEAR(FECHA)} = ?"); } //el array de objetos sera de dos elementos aCondiciones = new Object[2]; aCondiciones[1] = Integer.valueOf(anio); } else //la sql tiene un parametro //el array de objetos sera de un elemento aCondiciones = new Object[1]; strSql.append(" ORDER BY FECHA"); aCondiciones[0] = Integer.valueOf(medico); try { resul = this.seleccionar(strSql.toString()/*, intPagina*/, aCondiciones); consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones); } catch (ExcepcionTarisan e) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de Tamedico_Taprescr (listado_prescripciones): " + e + " (" + consulta + ")"); } return resul; } public Vector ObtenerTotalesIrpf(int medico, String anio) { Vector vResul = new Vector(); Tadremed tadremed = null; /*StringBuffer sqlSelect = new StringBuffer();*/ String consulta = ""; String fechaInicio = "01/01/"+anio; String fechaFin = "31/12/"+anio; try { /*sqlSelect.append("Select SUM(IMPORTE) AS IMPORTE, SUM(IRPF) AS IRPF from TADREMED "); sqlSelect.append("where medico = ?"); sqlSelect.append("AND FECHA BETWEEN " + fechaInicio + " AND " + fechaFin);*/ consulta = "Select SUM(IMPORTE) AS IMPORTE, SUM(IRPF) AS IRPF "; consulta += "from TADREMED "; consulta += "where medico = ? "; consulta += "AND FECHA BETWEEN TO_DATE('" + fechaInicio + "','DD/MM/YYYY') AND TO_DATE('" + fechaFin + "','DD/MM/YYYY')"; Object aCondiciones[] = new Object[1]; aCondiciones[0]=Integer.valueOf(medico); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, consulta, aCondiciones); while(rs.next()) { tadremed = new Tadremed(); tadremed.setIrpfTotal(rs.getDouble("IRPF")); tadremed.setImporteTotal(rs.getDouble("IMPORTE")); vResul.addElement(tadremed); } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); } catch (ExcepcionTarisan e) { LogTarisan.logger.log(NivelLog.ERROR, "ExcepcionTarisan: "+e.toString()); } catch (SQLException e) { LogTarisan.logger.log(NivelLog.ERROR, "Excepcion SQL: "+e.toString()); } return vResul; } }