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 com.fp.dto.Request; import com.fp.dto.Response; import com.fp.dto.query.DtoQuery; import com.fp.dto.query.SubQuery; import com.fp.dto.save.DtoSave; import com.fp.frontend.controller.AbstractController; import com.fp.frontend.controller.pcustomer.PersonAddressController; import com.fp.frontend.controller.pcustomer.PersonDetailController; import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController; import com.fp.frontend.helper.MessageHelper; 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.pcustomer.gene.TcustPersonDetail; import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail; @ManagedBean @ViewScoped public class TarmSolicitudDocumentoController extends AbstractController { List documentos; // String csolicitud; @ManagedProperty(value = "#{personAddressController}") private PersonAddressController personAddressController; public TarmSolicitudDocumentoController() throws Exception { super(TarmSolicitudDocumento.class); // TODO Auto-generated constructor stub } /** * */ private static final long serialVersionUID = -1407102577264256543L; @PostConstruct private void postconstruct() { this.init(); // Inicializa autoconsulta // super.startQuery(); } /** * Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador. */ private void init() { try { recperpage = 15; // Cambiar al # reg a mirar. lrecord = new ArrayList<>(); beanalias = "DOCUMENTOSCONTROLLER"; } catch (Exception e) { MessageHelper.setMessageError(e); } } /** * Crea una instancia de TgeneTransactionProcess y marca el registro como nuevo. * * @throws Exception */ @Override public void create() throws Exception { super.create(); } @SuppressWarnings("unchecked") @Override protected void querydatabase() { try { //Quemando el codigo de solicitud // this.csolicitud="1"; DtoQuery dto = this.getDtoQuery(); 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()){ for (TarmSolicitudDocumento doc : lrecord) { doc.put("seleccionado", Boolean.FALSE); } record=lrecord.get(0); } super.postQuery(lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } private DtoQuery getDtoQuery() throws Exception{ DtoQuery dto = super.getDtoQuery(Boolean.TRUE); SubQuery subQueryNumeroDoc = new SubQuery("TarmDocumentoHabilitante", "numerodocumento", "numerodocumento", "i.pk=t.pk.cdocumento"); dto.addSubQuery(subQueryNumeroDoc); SubQuery subQueryFechaEmision = new SubQuery("TarmDocumentoHabilitante", "fechaemision", "fechaemision", "i.pk=t.pk.cdocumento"); dto.addSubQuery(subQueryFechaEmision); SubQuery subQueryFechaExpiracion = new SubQuery("TarmDocumentoHabilitante", "fechaexpiracion", "fechaexpiracion", "i.pk=t.pk.cdocumento"); dto.addSubQuery(subQueryFechaExpiracion); // SubQuery subQueryTipoTramite= new SubQuery("TgeneCatalogDetail","description","tipoTramite" ,"i.pk.catalog= (select o.tipotramite from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento )) " + " and i.pk.catalogcode=(select o.tipotramitecodigo from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento ))"); dto.addSubQuery(subQueryTipoTramite); SubQuery subQueryTramite= new SubQuery("TgeneCatalogDetail","description","tramite" ,"i.pk.catalog= (select o.tipoautorizacion from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento )) " + " and i.pk.catalogcode=(select o.tipoautorizacioncodigo from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento ))"); dto.addSubQuery(subQueryTramite); SubQuery subQueryCategoria= new SubQuery("TgeneCatalogDetail","description","categoria" ,"i.pk.catalog= (select o.categoria from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento )) " + " and i.pk.catalogcode=(select o.categoriacodigo from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento ))"); dto.addSubQuery(subQueryCategoria); SubQuery subQueryUsoActivid = new SubQuery("TgeneCatalogDetail","description","usoactividad","i.pk.catalog= (select o.usoactividad from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento )) " + " and i.pk.catalogcode=(select o.usoactividadcodigo from TarmTramite o where o.pk=(select p.ctramite from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento ))"); dto.addSubQuery(subQueryUsoActivid); SubQuery subQueryEstado = new SubQuery("TgeneCatalogDetail","description","estado","i.pk.catalog= (select p.estado from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento ) " + " and i.pk.catalogcode=(select p.estadocode from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento )"); dto.addSubQuery(subQueryEstado); // SubQuery subQueryFechaEmision = new SubQuery("TarmDocumentoHabilitante","fechaemision","fechaemision","i.pk=t.pk.cdocumento"); // dto.addSubQuery(subQueryFechaEmision); // SubQuery subQueryFechaCaducidad = new SubQuery("TarmDocumentoHabilitante","fechaexpiracion","fechaexpiracion","i.pk=t.pk.cdocumento"); // dto.addSubQuery(subQueryFechaCaducidad); //arma SubQuery subcodigoArma= new SubQuery("TarmArmas","pk","carma" ,"i.pk= (select p.carma from TarmDocumentoHabilitante p where p.pk=t.pk.cdocumento)"); dto.addSubQuery(subcodigoArma); SubQuery subQueryClase= new SubQuery("TgeneCatalogDetail","description","clase" ,"i.pk.catalog= (select o.clase from TarmTipoArmaExplosivo o where o.pk=(select p.ctipoarmaexplosivo from TarmArmas p where p.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento))) " + " and i.pk.catalogcode=(select o.clasecodigo from TarmTipoArmaExplosivo o where o.pk=(select p.ctipoarmaexplosivo from TarmArmas p where p.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento))) "); dto.addSubQuery(subQueryClase); SubQuery subQueryTipo= new SubQuery("TgeneCatalogDetail","description","tipoarmaexplosivo" ,"i.pk.catalog= (select o.tipoarmaexplosivo from TarmTipoArmaExplosivo o where o.pk=(select p.ctipoarmaexplosivo from TarmArmas p where p.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento))) " + " and i.pk.catalogcode=(select o.tipoarmaexplosivocodigo from TarmTipoArmaExplosivo o where o.pk=(select p.ctipoarmaexplosivo from TarmArmas p where p.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento))) "); dto.addSubQuery(subQueryTipo); SubQuery subQueryMarca= new SubQuery("TarmArmas","marca","marca" ,"i.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento) "); dto.addSubQuery(subQueryMarca); SubQuery subQueryCalibre= new SubQuery("TgeneCatalogDetail","description","calibre" ,"i.pk.catalog= (select o.calibre from TarmTipoArmaExplosivo o where o.pk=(select p.ctipoarmaexplosivo from TarmArmas p where p.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento))) " + " and i.pk.catalogcode=(select o.calibrecodigo from TarmTipoArmaExplosivo o where o.pk=(select p.ctipoarmaexplosivo from TarmArmas p where p.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento))) "); dto.addSubQuery(subQueryCalibre); SubQuery subQueryLote= new SubQuery("TarmArmas","lote","lote" ,"i.pk=(select q.carma from TarmDocumentoHabilitante q where q.pk=t.pk.cdocumento) "); dto.addSubQuery(subQueryLote); return dto; } @Override public void save() { try { DtoSave dtosave = super.getDtoSave(); dtosave.setReturnpk(true); // Para que el core devuelva el pk de los registros nuevos. HashMap msave = new HashMap(); Request request = callerhelper.getRequest(); msave.put(beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla. request.setSaveTables(msave); Response resp = callerhelper.executeSave(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) { this.postCommit(resp); MessageHelper.setMessageInfo(resp); } else { MessageHelper.setMessageError(resp); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } @Override public void postCommit(Response response) throws Exception { super.postCommitGeneric(response, beanalias); } /** * Devueleve el tipo de tramite de un documento * @param documento * @return */ public String tipoTramite(TarmSolicitudDocumento documento){ String tipo=""; String codigoSolicitud; try { TarmDocumentoHabilitante documentoHabilitante= DocumentoHabilitanteController.find(String.valueOf(documento.getPk().getCdocumento())); codigoSolicitud = documentoHabilitante.getCsolicitud(); //Obteniendo la solicitud TarmSolicitud solicitud= SolicitudArmasController.find(codigoSolicitud); if(solicitud!=null){ TarmTramite tramite=TarmTramiteController.find(solicitud.getCtramite().toString()); if(tramite!=null && tramite.getTipotramite()!=null && !tramite.getTipotramite().isEmpty() && tramite.getTipotramitecodigo()!=null && !tramite.getTipotramitecodigo().isEmpty()){ TgeneCatalogDetail catalogoTipoTramite= CatalogDetailController.findxCodigoCodcatalogo(tramite.getTipotramite(), tramite.getTipotramitecodigo()); if(catalogoTipoTramite!=null){ tipo=catalogoTipoTramite.getDescription(); } } } } catch (Exception e) { MessageHelper.setMessageError(e); } return tipo; } public String tramite(TarmSolicitudDocumento documento) { String tipo=""; String codigoSolicitud; try { TarmDocumentoHabilitante documentoHabilitante= DocumentoHabilitanteController.find(String.valueOf(documento.getPk().getCdocumento())); codigoSolicitud = documentoHabilitante.getCsolicitud(); //Obteniendo la solicitud TarmSolicitud solicitud= SolicitudArmasController.find(codigoSolicitud); if(solicitud!=null){ TarmTramite tramite=TarmTramiteController.find(solicitud.getCtramite().toString()); if(tramite!=null && tramite.getTipoautorizacion()!=null && !tramite.getTipoautorizacion().isEmpty() && tramite.getTipoautorizacioncodigo()!=null && !tramite.getTipoautorizacioncodigo().isEmpty()){ TgeneCatalogDetail catalogoTramite= CatalogDetailController.findxCodigoCodcatalogo(tramite.getTipoautorizacion(), tramite.getTipoautorizacioncodigo()); if(catalogoTramite!=null){ tipo=catalogoTramite.getDescription(); } } } } catch (Exception e) { MessageHelper.setMessageError(e); } return tipo; } /** * Devueleve la categoria de un documento * @param documento * @return */ public String categoria(TarmSolicitudDocumento documento){ String categoria=""; String codigoSolicitud; try { TarmDocumentoHabilitante documentoHabilitante= DocumentoHabilitanteController.find(String.valueOf(documento.getPk().getCdocumento())); codigoSolicitud = documentoHabilitante.getCsolicitud(); //Obteniendo la solicitud TarmSolicitud solicitud= SolicitudArmasController.find(codigoSolicitud); if(solicitud!=null){ TarmTramite tramite=TarmTramiteController.find(solicitud.getCtramite().toString()); if(tramite!=null && tramite.getCategoria()!=null && !tramite.getCategoria().isEmpty() && tramite.getCategoriacodigo()!=null && !tramite.getCategoriacodigo().isEmpty()){ TgeneCatalogDetail catalogoCategoria= CatalogDetailController.findxCodigoCodcatalogo(tramite.getCategoria(), tramite.getCategoriacodigo()); if(catalogoCategoria!=null){ categoria=catalogoCategoria.getDescription(); } } } } catch (Exception e) { MessageHelper.setMessageError(e); } return categoria; } /** * Devueleve la categoria de un documento * @param documento * @return */ public String usoActividad(TarmSolicitudDocumento documento){ String usoActividad=""; String codigoSolicitud; try { TarmDocumentoHabilitante documentoHabilitante= DocumentoHabilitanteController.find(String.valueOf(documento.getPk().getCdocumento())); codigoSolicitud = documentoHabilitante.getCsolicitud(); //Obteniendo la solicitud TarmSolicitud solicitud= SolicitudArmasController.find(codigoSolicitud); if(solicitud!=null){ TarmTramite tramite=TarmTramiteController.find(solicitud.getCtramite().toString()); if(tramite!=null && tramite.getUsoactividad()!=null && !tramite.getUsoactividad().isEmpty() && tramite.getUsoactividadcodigo()!=null && !tramite.getUsoactividadcodigo().isEmpty()){ TgeneCatalogDetail catalogoUso= CatalogDetailController.findxCodigoCodcatalogo(tramite.getUsoactividad(), tramite.getUsoactividadcodigo()); if(catalogoUso!=null){ usoActividad=catalogoUso.getDescription(); } } } } catch (Exception e) { MessageHelper.setMessageError(e); } return usoActividad; } /** * Devueleve la categoria de un documento * @param documento * @return */ public String ubicacion(TarmSolicitudDocumento documento){ String ubicacion=""; try { //Obteniendo el documento habilitante TarmDocumentoHabilitante documentoHabilitante=DocumentoHabilitanteController.find(documento.getPk().getCdocumento().toString()); TcustPersonDetail detallesPersona=PersonDetailController.find(String.valueOf(documentoHabilitante.getPersoncode().toString())); if(detallesPersona!=null){ String tipoDireccion=""; switch(detallesPersona.getIdentificationcatalog()){ case "CED": tipoDireccion = "1"; break; case "RUC": tipoDireccion= "2"; break; default: tipoDireccion= ""; break; } // personAddressController.findPersonaPorDireccionTipoCatalogo(String.valueOf(documentoHabilitante.getPersoncode()), tipoDireccion); personAddressController.findPrincipal(String.valueOf(documentoHabilitante.getPersoncode())) ; if(personAddressController.getLprovinces()!=null && !personAddressController.getLprovinces().isEmpty()){ ubicacion=personAddressController.getLprovinces().get(0).getDescription(); } } } catch (Exception e) { MessageHelper.setMessageError(e); } return ubicacion; } /** * Devuelve las armas de un documento * @param documento * @return */ public TarmArmas armas(TarmSolicitudDocumento documento){ try { TarmDocumentoHabilitante documentoHabilitante=DocumentoHabilitanteController.find(documento.getPk().getCdocumento().toString()); return ArmasController.findPorCodigo(documentoHabilitante.getCarma()); }catch (Exception e) { return null; } } /** * M\u00e9todo para encontrar por solicitud * @param solicitudCode * @return List */ public static List findPorSolicitud(String solicitudCode) { try { TarmSolicitudDocumentoController cc = new TarmSolicitudDocumentoController(); cc.init(); cc.recperpage = 300; cc.addFilter("pk.csolicitud", solicitudCode); cc.querydatabase(); if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) { return cc.lrecord; } return null; } catch (Throwable e) { MessageHelper.setMessageError(e); return null; } } public List getDocumentos() { return documentos; } public void setDocumentos(List documentos) { this.documentos = documentos; } public PersonAddressController getPersonAddressController() { return personAddressController; } public void setPersonAddressController( PersonAddressController personAddressController) { this.personAddressController = personAddressController; } }