206 lines
8.2 KiB
Plaintext
Executable File
206 lines
8.2 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
import java.sql.Date;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ManagedProperty;
|
|
import javax.faces.bean.ViewScoped;
|
|
|
|
import org.primefaces.context.RequestContext;
|
|
import org.primefaces.event.SelectEvent;
|
|
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.DtoQuery;
|
|
import com.fp.dto.query.Filter;
|
|
import com.fp.dto.query.SubQuery;
|
|
import com.fp.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.alfresco.AlfrescoController;
|
|
import com.fp.frontend.enums.EnumLovOption;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
|
|
|
|
/**
|
|
* Controlador para listar los documentos habilitantes del sistema
|
|
*
|
|
*/
|
|
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class PermisosAutorizacionesAnularController extends AbstractController<TarmDocumentoHabilitante> {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@ManagedProperty(value = "#{alfrescoController}")
|
|
private AlfrescoController alfrescoController;
|
|
|
|
private TcustPersonDetail tcustPersonDetail;
|
|
|
|
public PermisosAutorizacionesAnularController() throws Exception{
|
|
super(TarmDocumentoHabilitante.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
public void postConstruct() {
|
|
this.init();
|
|
super.startQuery();
|
|
}
|
|
|
|
private void init(){
|
|
this.beanalias = "PERMISOSAUTORIZACIONES";
|
|
this.recperpage = 15;
|
|
this.lrecord = new ArrayList<>();
|
|
}
|
|
|
|
@SuppressWarnings({ "unchecked", "deprecation" })
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
if(!this.getMfilters().containsKey("personcode") || this.getMfilters().get("personcode")==null){
|
|
MessageHelper.setMessageError("SELECCIONE UNA IDENTIFICACI\u00d3N");
|
|
return;
|
|
}
|
|
DtoQuery dto = super.getDtoQuery(Boolean.TRUE);
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
//nombre
|
|
SubQuery snombre= new SubQuery
|
|
("TcustPersonDetail", "name", "nombre", "i.pk.personcode = t.personcode and i.pk.dateto=(select max(dt.pk.dateto) from TcustPersonDetail dt where dt.pk.personcode=t.personcode)");
|
|
dto.addSubQuery(snombre);
|
|
SubQuery snumerodocumento= new SubQuery
|
|
("TcustPersonDetail", "identification", "identification", "i.pk.personcode = t.personcode and i.pk.dateto=(select max(dt.pk.dateto) from TcustPersonDetail dt where dt.pk.personcode=t.personcode)");
|
|
dto.addSubQuery(snumerodocumento);
|
|
SubQuery subqueryCategoriaCodigo= new SubQuery("TgeneCatalogDetail", "description", "description", "i.pk.catalog = (select a.tipotramite from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.tipotramitecodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryCategoriaCodigo);
|
|
|
|
SubQuery subqueryipoAutorizacion= new SubQuery("TgeneCatalogDetail", "description", "descriptionTipoAut", "i.pk.catalog = (select a.tipoautorizacion from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.tipoautorizacioncodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryipoAutorizacion);
|
|
|
|
SubQuery subqueryTipocodigo=new SubQuery("TgeneCatalogDetail", "description", "descriptiontram", "i.pk.catalog = (select a.categoria from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.categoriacodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryTipocodigo);
|
|
SubQuery subqueryUsocodigo=new SubQuery("TgeneCatalogDetail", "description", "descriptionact", "i.pk.catalog = (select a.usoactividad from TarmTramite a where a.pk=t.ctramite)"
|
|
+ "and i.pk.catalogcode=(select a.usoactividadcodigo from TarmTramite a where a.pk=t.ctramite)");
|
|
dto.addSubQuery(subqueryUsocodigo);
|
|
SubQuery subqueryEstadoDoc=new SubQuery("TgeneCatalogDetail", "description", "estadodocumento", "i.pk.catalog = t.estado"
|
|
+ " and i.pk.catalogcode= t.estadocode");
|
|
dto.addSubQuery(subqueryEstadoDoc);
|
|
|
|
dto.setOrderby("t.fechaemision desc");
|
|
//filtro
|
|
Filter filtroFinal = new Filter();
|
|
String sqlFinal= " t.fechaemision is not null ";
|
|
filtroFinal.setSql(sqlFinal);
|
|
dto.addFiltro(filtroFinal);
|
|
|
|
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
|
|
Response resp = callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
lrecord = new ArrayList<>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmDocumentoHabilitante>) resp.get(beanalias);
|
|
java.util.Date fecha2=new java.util.Date();
|
|
fecha2.setHours(0);
|
|
fecha2.setMinutes(0);
|
|
fecha2.setSeconds(0);
|
|
for (TarmDocumentoHabilitante item : lrecord) {
|
|
item.getModifiedData().put("btnanular", Boolean.TRUE);
|
|
java.util.Date fecha1=new java.util.Date(item.getFechaexpiracion().getTime()) ;
|
|
fecha1.setHours(0);
|
|
fecha1.setMinutes(0);
|
|
fecha1.setSeconds(0);
|
|
if(fecha1.getTime()<fecha2.getTime()){
|
|
item.getModifiedData().put("btnanular", Boolean.FALSE);
|
|
}
|
|
}
|
|
super.postQuery(lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public void update() throws Exception{
|
|
record.setEstado("SUS");
|
|
record.setFechacambioexpiracion(record.getFechaexpiracion());
|
|
record.setFechaexpiracion(new Date(new java.util.Date().getTime()));
|
|
super.update();
|
|
}
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
Request request = this.callerhelper.getRequest();
|
|
DtoSave dtosave = super.getDtoSave();
|
|
if(!dtosave.pendingProcess()){
|
|
return;
|
|
}
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
msave.put(this.beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
|
|
request.setSaveTables(msave);
|
|
Response resp = this.callerhelper.executeSave(request);
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
this.postCommit(resp);
|
|
querydatabase();
|
|
MessageHelper.setMessageInfo(resp);
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public static void openLov() {
|
|
Map<String, Object> options = new HashMap<String, Object>();
|
|
// hint: ver EnumLovOption para las opciones del modal
|
|
options.put(EnumLovOption.MODAL.getLabel(), true);
|
|
options.put(EnumLovOption.HEIGHT.getLabel(), 450);
|
|
options.put(EnumLovOption.WIDTH.getLabel(), 700);
|
|
options.put(EnumLovOption.RESIZABLE.getLabel(), true);
|
|
// lovpersona es el nombre de la pagina
|
|
RequestContext.getCurrentInstance().openDialog("/pages/customer/lov/personLov.xhtml", options, null);
|
|
}
|
|
|
|
|
|
/**
|
|
* Maneja la respuesta del Lov de Personas
|
|
* @param event
|
|
* @throws Exception
|
|
*/
|
|
public void onReturnPersonLov(SelectEvent event) throws Exception {
|
|
tcustPersonDetail = (TcustPersonDetail) event.getObject();
|
|
this.getMfilters().put("personcode",tcustPersonDetail.getPk().getPersoncode().toString());
|
|
this.query();
|
|
}
|
|
|
|
public TcustPersonDetail getTcustPersonDetail() {
|
|
return tcustPersonDetail;
|
|
}
|
|
|
|
public void setTcustPersonDetail(TcustPersonDetail tcustPersonDetail) {
|
|
this.tcustPersonDetail = tcustPersonDetail;
|
|
}
|
|
|
|
public AlfrescoController getAlfrescoController() {
|
|
return alfrescoController;
|
|
}
|
|
|
|
public void setAlfrescoController(AlfrescoController alfrescoController) {
|
|
this.alfrescoController = alfrescoController;
|
|
}
|
|
|
|
}
|