347 lines
12 KiB
Java
347 lines
12 KiB
Java
package com.tarisan.control;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.util.Vector;
|
|
|
|
import com.tarisan.data.Taliquimedi;
|
|
import com.tarisan.excepcion.ExcepcionTarisan;
|
|
import com.tarisan.log.LogTarisan;
|
|
import com.tarisan.log.NivelLog;
|
|
import com.tarisan.util.Utilidades;
|
|
|
|
public class PersistenciaTaliquimedi {
|
|
|
|
/**
|
|
* El objeto <code>Paginacion</code> que controla el número de filas a mostrar por cada página.
|
|
*/
|
|
private Paginacion objPaginacion = new Paginacion();
|
|
|
|
/**
|
|
* Obtiene el valor del objeto <code>Paginacion</code> para saber que página se está visualizando.
|
|
* @return El objeto <code>Paginacion</code>
|
|
*/
|
|
public Paginacion getPaginacion()
|
|
{
|
|
return objPaginacion;
|
|
}
|
|
|
|
/**
|
|
* Selecciona los registros de la tabla ttactmed 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 parametros utilizados en la sentencia SELECT.
|
|
* @return El Vector con los registros seleccionados (todos pertenencientes a la clase <code>ttactmed</code>).
|
|
* @throws
|
|
*/
|
|
public Vector seleccionar(String sqlSelect, int pagina, Object[] aCondiciones) throws ExcepcionTarisan
|
|
{
|
|
|
|
int elementosPaginacion=1;
|
|
|
|
Vector vResultado = new Vector();
|
|
Taliquimedi taliquimedi = 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()))*/
|
|
{
|
|
taliquimedi = new Taliquimedi();
|
|
taliquimedi.setMedico(rs.getInt("MEDICO"));
|
|
taliquimedi.setMedico_origen(rs.getInt("MEDICO_ORIGEN"));
|
|
taliquimedi.setMes(rs.getString("MES"));
|
|
taliquimedi.setAnio(rs.getString("año"));
|
|
taliquimedi.setFecha_factura(rs.getDate("FECHA_FACTURA"));
|
|
taliquimedi.setFactura(rs.getInt("FACTURA"));
|
|
taliquimedi.setEspecialidad(rs.getInt("ESPECIALIDAD"));
|
|
taliquimedi.setDesc_esp(rs.getString("DESC_ESP"));
|
|
taliquimedi.setActo(rs.getInt("ACTO"));
|
|
taliquimedi.setDescripcion(rs.getString("DESCRIPCION"));
|
|
taliquimedi.setPrecio(rs.getDouble("PRECIO"));
|
|
taliquimedi.setCantidad(rs.getInt("CANTIDAD"));
|
|
taliquimedi.setImporte(rs.getDouble("IMPORTE"));
|
|
vResultado.addElement(taliquimedi);
|
|
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 TALIQUIMEDI (" + sqlSelect + ")");
|
|
|
|
|
|
}
|
|
|
|
catch (ExcepcionTarisan sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw (ExcepcionTarisan)sqle;
|
|
}
|
|
catch(SQLException sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Exception sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Throwable sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
|
|
}
|
|
|
|
return vResultado;
|
|
}
|
|
|
|
public Vector seleccionar_res_todas_liqui(String sqlSelect, Object[] aCondiciones, String retencion) throws ExcepcionTarisan
|
|
{
|
|
|
|
Vector vResultado = new Vector();
|
|
|
|
try
|
|
{
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect, aCondiciones);
|
|
|
|
if (retencion=="S"){
|
|
while(rs.next())
|
|
{
|
|
vResultado.addElement(rs.getString("FECHA"));
|
|
vResultado.addElement(rs.getInt("IMPORTE"));
|
|
vResultado.addElement(rs.getInt("TOTAL"));
|
|
vResultado.addElement(rs.getInt("IRPF"));
|
|
}
|
|
}else{
|
|
while(rs.next())
|
|
{
|
|
vResultado.addElement(rs.getString("FECHA"));
|
|
vResultado.addElement(rs.getInt("IMPORTE"));
|
|
vResultado.addElement(rs.getInt("TOTAL"));
|
|
}
|
|
}
|
|
rs.close();
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " registros de la tabla TALIQUIMEDI (" + sqlSelect + ")");
|
|
|
|
}
|
|
|
|
catch (ExcepcionTarisan sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw (ExcepcionTarisan)sqle;
|
|
}
|
|
catch(SQLException sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Exception sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Throwable sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
|
|
}
|
|
|
|
return vResultado;
|
|
}
|
|
|
|
|
|
public Vector listado_fechas_liquidaciones(int medico) throws SQLException
|
|
{
|
|
Vector vresul = new Vector();
|
|
String sql="";
|
|
|
|
sql = "select mes||'/'||año as fecha from taliquimedi where medico = "+medico+" group by año, mes order by año desc, mes desc";
|
|
|
|
try {
|
|
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet resultado = ParametrosConfiguracion.dataStore.seleccionar(conexion, sql);
|
|
|
|
while (resultado.next())
|
|
{
|
|
vresul.addElement(resultado.getString("FECHA"));
|
|
};
|
|
conexion.close();
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de las fechas de liquidación: " + e + " (" + sql + ")");
|
|
}
|
|
|
|
return vresul;
|
|
}
|
|
|
|
public boolean tiene_retencion(int medico) throws SQLException
|
|
{
|
|
boolean retencion = false;
|
|
String sql="";
|
|
|
|
sql = "Select cla, medico_origen from ttmedico, taliquimedi where ttmedico.medico = " + medico + " and ttmedico.medico = taliquimedi.medico";
|
|
|
|
try {
|
|
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet resultado = ParametrosConfiguracion.dataStore.seleccionar(conexion, sql);
|
|
if(resultado.next())
|
|
{
|
|
if(resultado.getString("cla").indexOf("M") == 0)
|
|
{
|
|
retencion = true;
|
|
LogTarisan.logger.log(NivelLog.INFO, "\nSi tiene retencion 219\n");
|
|
}
|
|
};
|
|
conexion.close();
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de la existencia de retención de IRP: " + e + " (" + sql + ")");
|
|
}
|
|
|
|
return retencion;
|
|
}
|
|
|
|
public boolean tiene_retencion_por_taliquimedico(int medico) throws SQLException
|
|
{
|
|
boolean retencion = false;
|
|
String sql="";
|
|
|
|
sql = "Select cla, medico_origen from ttmedico, taliquimedi where taliquimedi.medico = " + medico + " and ttmedico.medico = taliquimedi.medico_origen";
|
|
|
|
try {
|
|
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet resultado = ParametrosConfiguracion.dataStore.seleccionar(conexion, sql);
|
|
if(resultado.next())
|
|
{
|
|
if(resultado.getString("cla").indexOf("M") == 0)
|
|
{
|
|
retencion = true;
|
|
LogTarisan.logger.log(NivelLog.INFO, "\nSi tiene retencion 219\n");
|
|
}
|
|
};
|
|
conexion.close();
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de la existencia de retención de IRP: " + e + " (" + sql + ")");
|
|
}
|
|
|
|
return retencion;
|
|
}
|
|
|
|
public Vector listado_resumen_todas_liquidaciones_con_retencion(int medico)
|
|
{
|
|
Vector resul = null;
|
|
StringBuffer strSql = new StringBuffer();
|
|
String retencion = "S";
|
|
|
|
Object [] aCondiciones = new Object[1];
|
|
String consulta = "";
|
|
|
|
strSql.append("Select concat(concat(mes, '/'),año) as FECHA, sum(importe) as IMPORTE, (sum(importe)*0.15) as IRPF, (sum(importe)-(sum(importe)*0.15)) as TOTAL");
|
|
strSql.append(" from taliquimedi where medico = ?");
|
|
strSql.append(" group by mes, año");
|
|
strSql.append(" order by mes, año");
|
|
|
|
aCondiciones[0] = Integer.valueOf(medico);
|
|
|
|
try {
|
|
resul = this.seleccionar_res_todas_liqui(strSql.toString(), aCondiciones, retencion);
|
|
consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones);
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI (listado_resumen_todas_liquidaciones_con_retencion): " + e + " (" + consulta + ")");
|
|
}
|
|
|
|
return resul;
|
|
}
|
|
|
|
public Vector listado_resumen_todas_liquidaciones_sin_retencion(int medico)
|
|
{
|
|
Vector resul = null;
|
|
StringBuffer strSql = new StringBuffer();
|
|
String retencion = "N";
|
|
|
|
Object [] aCondiciones = new Object[1];
|
|
String consulta = "";
|
|
|
|
strSql.append("Select concat(concat(mes, '/'),año) as FECHA, sum(importe) as IMPORTE, sum(importe) as TOTAL");
|
|
strSql.append(" from taliquimedi where medico = ?");
|
|
strSql.append(" group by mes, año");
|
|
strSql.append(" order by mes, año");
|
|
|
|
aCondiciones[0] = Integer.valueOf(medico);
|
|
|
|
try {
|
|
resul = this.seleccionar_res_todas_liqui(strSql.toString(), aCondiciones, retencion);
|
|
consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones);
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI (listado_resumen_todas_liquidaciones_sin_retencion): " + e + " (" + consulta + ")");
|
|
}
|
|
|
|
return resul;
|
|
}
|
|
|
|
public int obtener_medico_origen(int med) throws SQLException
|
|
{
|
|
int medico = 0;
|
|
String sql="";
|
|
|
|
sql = "select medico_origen from taliquimedi where medico = " + med;
|
|
|
|
try {
|
|
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet resultado = ParametrosConfiguracion.dataStore.seleccionar(conexion, sql);
|
|
if(resultado.next())
|
|
{
|
|
medico = resultado.getInt("medico_origen");
|
|
};
|
|
conexion.close();
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la select de la obtención del médico de origen: " + e + " (" + sql + ")");
|
|
}
|
|
|
|
return medico;
|
|
}
|
|
|
|
public Vector listado_detalle_liquidaciones_medicos(int medico, String mes, int pagina)
|
|
{
|
|
Vector resul = null;
|
|
StringBuffer strSql = new StringBuffer();
|
|
String retencion = "N";
|
|
|
|
Object [] aCondiciones = new Object[2];
|
|
String consulta = "";
|
|
|
|
strSql.append("Select *");
|
|
strSql.append(" from taliquimedi where medico = ?");
|
|
strSql.append(" and concat(concat(mes,'/'),año) = ?");
|
|
strSql.append(" order by concat(concat(mes,'/'),año), acto");
|
|
|
|
aCondiciones[0] = Integer.valueOf(medico);
|
|
aCondiciones[1] = new String(mes);
|
|
|
|
try {
|
|
resul = this.seleccionar(strSql.toString(), pagina, aCondiciones);
|
|
consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones);
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TALIQUIMEDI (listado_detalle_liquidaciones_medicos): " + e + " (" + consulta + ")");
|
|
}
|
|
|
|
return resul;
|
|
}
|
|
}
|