package com.fp.frontend.controller.armas.solicitud; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; import javax.faces.bean.ViewScoped; import javax.faces.event.AjaxBehaviorEvent; import org.primefaces.context.RequestContext; 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.pgeneral.gene.CatalogDetailController; import com.fp.frontend.helper.MessageHelper; import com.fp.frontend.utility.MsgControlArmas; import com.fp.persistence.parmas.inte.TarmColadeImpresion; import com.fp.persistence.parmas.param.TarmTramite; import com.fp.persistence.parmas.soli.TarmArmas; import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante; import com.fp.persistence.parmas.soli.TarmSolicitud; import com.fp.persistence.parmas.soli.TarmSolicitudDocumento; import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail; @SuppressWarnings("serial") @ManagedBean @ViewScoped public class VerificacionReimpresion extends AbstractController { /* * Variable que indica si se seleciona el check o no */ private Boolean verifica = false; /** * Variable que indica si se ha seleccionado un registro */ private boolean esCola = false; /** * Hailita el boton del flujo */ private boolean btnFlujo = false; /* * Variable que almacena el código de solicitud */ private String csolicitud; /* * Bean de tipo TarmSolicitud */ private TarmSolicitud solicitud = new TarmSolicitud(); @ManagedProperty(value = "#{docHabilitanteController}") private DocumentoHabilitanteController docHabilitanteController; @ManagedProperty(value = "#{solicitudController}") private SolicitudController solicitudController; @ManagedProperty(value = "#{recepcionArmasController}") private RecepcionArmasController recepcionArmasController; @ManagedProperty(value = "#{colaImpresionController}") private ColaImpresionController colaImpresionController; /** * Constructor * @throws Exception */ public VerificacionReimpresion() throws Exception { super(TarmSolicitudDocumento.class); } /** * Método invocado después de instanciar el controlador * @throws Exception */ @PostConstruct private void postconstruct() throws Exception { // Inicializa autoconsulta this.pasteBpmScreenParameters(); super.startQuery(); if(super.getMfilters().get("csolicitud")==null || super.getMfilters().get("csolicitud").isEmpty()){ MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_noexistesolicitud")); return; } csolicitud=super.getMfilters().get("csolicitud"); this.getMfilters().clear(); //this.getMfilters().put("pk.csolicitud", csolicitud); this.solicitud= SolicitudController.findSolicitudxcodsolicitud(csolicitud); this.getMfilelds().put("numerosolicitud", this.solicitud.getNumerosolicitud()); this.init(); } /** * Incializa variables del controlador, cuando se está utilizando una página que utliza el controlador. */ private void init() { try { this.recperpage = 10; // Cambiar al # reg a mirar. this.lrecord = new ArrayList<>(); this.beanalias = "VERIFICARDOCUMENTOS"; querydatabase(); } catch (Exception e) { MessageHelper.setMessageError(e); } } /* (non-Javadoc) * @see com.fp.frontend.controller.AbstractController#querydatabase() */ @SuppressWarnings("unchecked") @Override protected void querydatabase() { try { Request request = this.callerhelper.getRequest(); DtoQuery dto = super.getDtoQuery(true); Filter filtroSinImpresionSolicitud=new Filter(); filtroSinImpresionSolicitud.setSql("(t.chkimpresion='N' or t.chkimpresion is null) and t.pk.csolicitud = '" + this.solicitud.getPk() + "'"); dto.addFiltro(filtroSinImpresionSolicitud); dto.setOrderby("t.pk"); // En en string van todos los campos de orden ("t.pk, t.nombre, t.cpais"). SubQuery qry = new SubQuery("TarmSolicitud", "ccentrocontrol", "ccentrocontrol", "i.pk = t.pk.csolicitud"); dto.addSubQuery(qry); SubQuery qry2 = new SubQuery("TgeneCatalogDetail", "description", "tramitedesc", "i.pk.catalog = (select a.tipotramite from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento))) "// t.pk.csolicitud + " and " + "i.pk.catalogcode = (select a.tipotramitecodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))"); dto.addSubQuery(qry2); SubQuery qry3 = new SubQuery("TgeneCatalogDetail", "description", "categoriadesc", "i.pk.catalog = (select a.categoria from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))" + " and " + "i.pk.catalogcode = (select a.categoriacodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))"); dto.addSubQuery(qry3); SubQuery qry4 = new SubQuery("TgeneCatalogDetail", "description", "usoactdesc", "i.pk.catalog = (select a.usoactividad from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))" + " and " + "i.pk.catalogcode = (select a.usoactividadcodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))"); dto.addSubQuery(qry4); //ubicacion SubQuery qryUbicacion = new SubQuery("TgeneProvince", "description", "ubicaciondesc", "i.pk.countrycode = 'EC'" + " and " + "i.pk.provincecode = (select a.provincecode from TcustPersonAddress a where a.pk.personcode =(select o.personcode from TarmDocumentoHabilitante o where o.pk= t.pk.cdocumento )" + " and a.principal='Y'" + " and a.pk.dateto = to_date('2999-12-31', 'YYYY-MM-DD') )");// dto.addSubQuery(qryUbicacion); //TarmSolicitudDocumento SubQuery qry5 = new SubQuery("TarmDocumentoHabilitante", "fechaemision", "fechaemision", "i.pk= t.pk.cdocumento"); dto.addSubQuery(qry5); SubQuery qry6 = new SubQuery("TarmDocumentoHabilitante", "fechaexpiracion", "fechaexpiracion", "i.pk= t.pk.cdocumento"); dto.addSubQuery(qry6); SubQuery qry61 = new SubQuery("TarmDocumentoHabilitante", "estado ", "estado1", "i.pk= t.pk.cdocumento"); dto.addSubQuery(qry61); SubQuery qry611 = new SubQuery("TarmDocumentoHabilitante", "estadocode ", "estado11", "i.pk= t.pk.cdocumento"); dto.addSubQuery(qry611); SubQuery qry7 = new SubQuery("TgeneCatalogDetail", "description", "estado", "i.pk.catalog = (select a.estado from TarmDocumentoHabilitante a where a.pk= t.pk.cdocumento) and " + "i.pk.catalogcode = (select a.estadocode from TarmDocumentoHabilitante a where a.pk= t.pk.cdocumento)"); dto.addSubQuery(qry7); SubQuery qry8 = new SubQuery("TarmDocumentoHabilitante", "carma", "carma", "i.pk = t.pk.cdocumento and i.pk= t.pk.cdocumento"); dto.addSubQuery(qry8); SubQuery qry9 = new SubQuery("TarmDocumentoHabilitante", "codigoarma", "codigoarma", "i.pk= t.pk.cdocumento"); dto.addSubQuery(qry9); SubQuery qry10 = new SubQuery("TgeneCatalogDetail", "description", "tipoautorizacion", "i.pk.catalog = (select a.tipoautorizacion from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = t.pk.csolicitud)) and " + "i.pk.catalogcode = (select a.tipoautorizacioncodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = t.pk.csolicitud))"); dto.addSubQuery(qry10); HashMap mtables = new HashMap(); mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla. request.setQueryTables(mtables); request.put("querytype", "P"); request.put("queryalias", "VDOCUMENTO"); Response resp = this.callerhelper.executeQuery(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) { this.lrecord = new ArrayList(); MessageHelper.setMessageError(resp); } else { this.lrecord = (List) resp.get(this.beanalias); this.completaArmas(); super.postQuery(this.lrecord); lista(); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } /** * Verifica la selección del documento según el check de * reimpresion */ public void lista(){ for (TarmSolicitudDocumento solicituddoc : lrecord) { if(solicituddoc.getChkimpresion()!= null && solicituddoc.getChkimpresion().equals("Y")){ solicituddoc.getModifiedData().put("verificador", Boolean.TRUE); }else{ solicituddoc.getModifiedData().put("verificador", Boolean.FALSE); } } } /* (non-Javadoc) * @see com.fp.frontend.controller.AbstractController#save() */ @Override public void save(){ try { if(!validaSeleccion()){ MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_reimpresion")); return; } this.actualizaVerificado(); Request request = this.callerhelper.getRequest(); DtoSave dtosave = super.getDtoSave(); dtosave.setPosition(2); // if(!dtosave.pendingProcess()){ // return; // } //En caso de que los documentos sean de tipo de cola de impresion enviaColaImpresion(); DtoSave dtosacola = colaImpresionController.getDtoSave(); dtosacola.setReturnpk(true); dtosacola.setPosition(1); HashMap msave = new HashMap(); msave.put(this.beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla. msave.put(colaImpresionController.getBeanalias(), dtosacola); request.setSaveTables(msave); Response resp = this.callerhelper.executeSave(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) { btnFlujo=Boolean.TRUE; this.postCommit(resp); this.colaImpresionController.postCommit(resp); MessageHelper.setMessageInfo(resp); } else { MessageHelper.setMessageError(resp); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } /** * Selecciona los registros para establecer si el registro se reimprime o no. */ public void seleccionarTodos(AjaxBehaviorEvent event) { try { Boolean valorColocar = Boolean.FALSE; if(Boolean.valueOf(event.getComponent().getAttributes().get("value") != null ? event.getComponent().getAttributes().get("value").toString() : "false")){ valorColocar = Boolean.TRUE; } for (TarmSolicitudDocumento solicituddoc : lrecord) { solicituddoc.getModifiedData().put("verificador", valorColocar); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } /** * Actualiza la selección del documento según el check de * reimpresion * @throws Exception */ public void actualizaVerificado() throws Exception{ for (TarmSolicitudDocumento solicituddoc : lrecord) { if(solicituddoc.getModifiedData().get("verificador").equals(Boolean.TRUE)){ solicituddoc.setChkimpresion("Y"); }else { solicituddoc.setChkimpresion("N"); } record=solicituddoc; super.update(); } } /** * */ @SuppressWarnings("unchecked") protected void querydatabaseDocumentos() { try { DtoQuery dto = super.getDtoQuery(true); if(csolicitud !=null ) { dto.addFiltro(new Filter("pk.csolicitud", csolicitud)); } //solicitudTramite = TarmSolicitudTramiteController.findPorCSolicitud(codigoSolicitud); solicitud = ValidacionTramiteLibreTransitoController.findPorSolicitudSimple(csolicitud); HashMap mtables = new HashMap(); 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) resp.get(beanalias); if (lrecord != null && !lrecord.isEmpty()) { record = lrecord.get(0); seleccionarDocumentos(); } super.postQuery(lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } /** * Método que asigna la selección del documento según el check de * reimpresion * * @throws Exception */ @SuppressWarnings("unused") private void seleccionarDocumentos() throws Exception { for (int i = 0; i < lrecord.size(); i++) { TarmSolicitudDocumento docSeleccionada = lrecord.get(i); if (docSeleccionada.getVerificado().equalsIgnoreCase("Y")) { docSeleccionada.modifiedData().put("seleccion", Boolean.TRUE); } else { docSeleccionada.modifiedData().put("seleccion", Boolean.FALSE); } } } /** * Método que completa la información del arma para los registros de la * tabla TarmSolicitudDocumento */ public void completaArmas(){ for(int i=0;idocumentosEnColaList = ColaImpresionController.findByDocumentoEstado(habilitante.getPk().toString(),"PIMPR"); if(documentosEnColaList==null || documentosEnColaList.size()==0){ esCola=true; TarmColadeImpresion colaimpr = new TarmColadeImpresion(); colaimpr.setCdocumento(habilitante.getPk()); colaimpr.setEstadoimpresion("PIMPR"); colaimpr.setEstadoimpresioncode("ESTADOIMPRESION"); colaimpr.setFecharegistro(habilitante.getFechaemision()); colaimpr.setIsnew(Boolean.TRUE); colaImpresionController.update(colaimpr); } } } } } public Boolean getVerifica() { return verifica; } public void setVerifica(Boolean verifica) { this.verifica = verifica; } public SolicitudController getSolicitudController() { return solicitudController; } public void setSolicitudController(SolicitudController solicitudController) { this.solicitudController = solicitudController; } public String getCsolicitud() { return csolicitud; } public void setCsolicitud(String csolicitud) { this.csolicitud = csolicitud; } public RecepcionArmasController getRecepcionArmasController() { return recepcionArmasController; } public void setRecepcionArmasController( RecepcionArmasController recepcionArmasController) { this.recepcionArmasController = recepcionArmasController; } public DocumentoHabilitanteController getDocHabilitanteController() { return docHabilitanteController; } public void setDocHabilitanteController( DocumentoHabilitanteController docHabilitanteController) { this.docHabilitanteController = docHabilitanteController; } public ColaImpresionController getColaImpresionController() { return colaImpresionController; } public void setColaImpresionController( ColaImpresionController colaImpresionController) { this.colaImpresionController = colaImpresionController; } public boolean isBtnFlujo() { return btnFlujo; } public void setBtnFlujo(boolean btnFlujo) { this.btnFlujo = btnFlujo; } public boolean isEsCola() { return esCola; } public void setEsCola(boolean esCola) { this.esCola = esCola; } }