133 lines
4.2 KiB
Plaintext
Executable File
133 lines
4.2 KiB
Plaintext
Executable File
package com.fp.viaticos.rules.query.solicitud;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.List;
|
|
|
|
import javax.persistence.NoResultException;
|
|
import javax.persistence.Query;
|
|
|
|
import com.fp.bpm.query.QueryJsf;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.QueryRequest;
|
|
import com.fp.dto.rules.QueryRule;
|
|
import com.fp.persistence.commondb.PersistenceHelper;
|
|
import com.fp.persistence.commondb.exception.CommondbException;
|
|
import com.fp.persistence.pviaticos.hra.Empleado;
|
|
import com.fp.persistence.pviaticos.hra.EmpleadoJpql;
|
|
import com.fp.persistence.pviaticos.solicitud.ViaSolicitud;
|
|
|
|
public class ConsultaEstadoSolicitud extends QueryRule {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
private static String query="select coalesce(sum(val_importe),0) from VIA.via_sol_liquidacion where cod_solicitud = :codSolicitud and cod_tipo = :codTipo";
|
|
private static String queryNomRespDirFin ="SELECT em.apellidos||' '||em.nombres AS NOMBRE FROM HRA.vwdatosempleados em WHERE UPPER(EM.USUARIO_WEB)="
|
|
+ "(SELECT ciu.cod_usuario FROM MAIADE.via_ciudad_usuario ciu where ciu.cod_actividad_catalog='TESORERIA' and ciu.cod_ciudad_catalog = :codLocalidad)";
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
public QueryRequest process(QueryRequest pQrequest) throws Exception {
|
|
Response response = pQrequest.getResponse();
|
|
QueryJsf query = new QueryJsf();
|
|
query.execute(pQrequest);
|
|
|
|
List<Object> estadosSolicitud = (List<Object>) response
|
|
.get("VIASOLICITUDCONSULTA");
|
|
|
|
this.completeInfoSolicitud(estadosSolicitud);
|
|
return pQrequest;
|
|
}
|
|
|
|
|
|
/**
|
|
* Completa la información de los integrantes
|
|
*
|
|
* @param objeto
|
|
*/
|
|
private void completeInfoSolicitud(List<Object> objetos) throws Exception {
|
|
if (objetos == null || objetos.isEmpty()) {
|
|
return;
|
|
}
|
|
for (Object obj : objetos) {
|
|
|
|
ViaSolicitud solicitud = (ViaSolicitud) obj;
|
|
EmpleadoJpql e = new EmpleadoJpql();
|
|
Empleado emp = e.find(solicitud.getCod_empleado());
|
|
|
|
solicitud.modifiedData.put("nombrefuncionario", emp.getNombre());
|
|
|
|
if (solicitud.getCod_jefe() != null) {
|
|
Empleado jefe = e.find(solicitud.getCod_jefe());
|
|
if (jefe != null) {
|
|
solicitud.modifiedData.put("nombrejefe", jefe.getNombreJefe());
|
|
solicitud.modifiedData.put("cargojefe", jefe.getNombreCargoJefe());
|
|
}
|
|
}else
|
|
{
|
|
if (emp != null) {
|
|
solicitud.modifiedData.put("nombrejefe", emp.getNombreJefe());
|
|
solicitud.modifiedData.put("cargojefe", emp.getNombreCargo());
|
|
}
|
|
}
|
|
|
|
if (solicitud.getCod_responsable() != null) {
|
|
|
|
Empleado responsable = e.find(solicitud.getCod_responsable());
|
|
if (responsable != null) {
|
|
solicitud.modifiedData.put("nombreresponsable",responsable.getNombreResponsableUnidad());
|
|
solicitud.modifiedData.put("cargoresponsable",responsable.getNombreCargoResponsableUnidad());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (emp != null) {
|
|
solicitud.modifiedData.put("nombreresponsable", emp.getNombreResponsableUnidad());
|
|
solicitud.modifiedData.put("cargoresponsable", emp.getNombreCargoResponsableUnidad());
|
|
}
|
|
}
|
|
|
|
solicitud.modifiedData.put("gastos",this.getGastos(solicitud));
|
|
solicitud.modifiedData.put("nomResDirFin", this.getNomRespDirFin(emp)==null?"":this.getNomRespDirFin(emp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Método para obtener el nombre del responsable de la Dirección Financiera
|
|
* @param empleado
|
|
* @return
|
|
* @throws CommondbException
|
|
*/
|
|
private String getNomRespDirFin(Empleado empleado) throws CommondbException
|
|
{
|
|
String value = null;
|
|
Query qry = PersistenceHelper.getEntityManager().createNativeQuery(queryNomRespDirFin);
|
|
qry.setParameter("codLocalidad", empleado.getCodigoLocalidad());
|
|
try{
|
|
value = (String)qry.getSingleResult();
|
|
}catch(NoResultException ex){
|
|
value = null;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
|
|
/**
|
|
* Método para obtener los gastos totalizados por solicitud y tipo de documento
|
|
* @param solicitud
|
|
* @return
|
|
* @throws CommondbException
|
|
*/
|
|
private BigDecimal getGastos(ViaSolicitud solicitud) throws CommondbException
|
|
{
|
|
Query qry = PersistenceHelper.getEntityManager().createNativeQuery(query);
|
|
|
|
qry.setParameter("codSolicitud", solicitud.getPk().getCod_solicitud());
|
|
qry.setParameter("codTipo", solicitud.getPk().getCod_tipo());
|
|
|
|
return (BigDecimal)qry.getSingleResult();
|
|
}
|
|
|
|
|
|
}
|