package com.fp.frontend.controller.armas.solicitud; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.context.FacesContext; 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.frontend.controller.AbstractController; import com.fp.frontend.controller.armas.funcionalidad.RegistroArmController; import com.fp.frontend.controller.pcustomer.PersonDetailController; import com.fp.frontend.controller.pgeneral.gene.CantonController; import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController; import com.fp.frontend.controller.pgeneral.gene.CityController; import com.fp.frontend.controller.pgeneral.gene.CountryController; import com.fp.frontend.controller.pgeneral.gene.ParroquiaController; import com.fp.frontend.controller.pgeneral.gene.ProvinceController; import com.fp.frontend.helper.MessageHelper; import com.fp.persistence.parmas.fun.TarmRegistroArmas; 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.pcustomer.gene.TcustPersonDetail; import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail; import com.fp.persistence.pgeneral.safe.TsafeUserDetail; /** * Controlador principal de la funcionalidad de armas Registradas * * @author H.Y Sinfo * */ @SuppressWarnings("serial") @ManagedBean @ViewScoped public class ArticuloRegistradoController extends AbstractController{ /** * Tipo documento */ private String tipoDoc; /** * Número documento */ private String numDoc; /** * Nombre/razón social */ private String nombreRazon; /** * Longitud arma */ private String longitud; /** * Calibre arma */ private String calibre; /** * Clase arma */ private String clase; /** * Tipo de arma */ private String tipoarma; /** * unidad medida peso */ private String unidadmedidapeso; /** * Bandera que indica que en realidad existe luego del ingreso de datos un tipo * de arma explosivo válido */ private boolean existeTipoArmaExplosivo; /** * Bandera que escifica que se deba verificar que exista un arma explosivo * válida */ private boolean verificaArmaExplosivo = Boolean.TRUE; /** * Bloquea la unidad de cantidad */ private boolean bloquearUnidadCantidad = Boolean.TRUE; /** * Bloquea la unidad de peso */ private boolean bloquearUnidadPeso = Boolean.TRUE; private Date fechaActual; private String razonSocial; private String numeroDocumento; private String filtroPersona; private String descategoria; private String usoActividad; /** * Usuario actual logueado en el sistema * */ private TsafeUserDetail userDetail; public ArticuloRegistradoController() throws Exception { super(TarmArmas.class); } /** * Método que se ejecuta después del constructor */ @PostConstruct private void postconstruct() { this.init(); } /** * Inicializa valores del controlador */ private void init() { try { userDetail=(TsafeUserDetail)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL"); fechaActual = new Date(); recperpage = 15; // Cambiar al # reg a mirar. lrecord = new ArrayList<>(); beanalias = "ARMAS"; filtroPersona = " and t.cregistro in (select i.pk from TarmRegistroArmas i where i.personcode =" + userDetail.getPk().getPersoncode() + ")"; if(userDetail.getPk().getPersoncode()!=null){ razonSocial = PersonDetailController.find(userDetail.getPk().getPersoncode().toString()).getName(); numeroDocumento=PersonDetailController.find(userDetail.getPk().getPersoncode().toString()).getIdentification(); } else{ razonSocial = ""; numeroDocumento=""; } } catch (Exception e) { MessageHelper.setMessageError(e); } } @SuppressWarnings("unchecked") protected void querydatabase() { try { DtoQuery dto = this.getDtoQuery(); dto.setOrderby("pk"); Filter filtro = new Filter(); String sql = "t.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where t.codigoarma=ta.codigoarma) and t.estado !='DEST' and t.estado!='VEND' and t.estado!='MING' and t.estado!='DUPL' and t.estado!='CUSTEM' and t.estado !='CDP'" + " and (t.peso>0 or t.cantidad>0) " + filtroPersona;// filtro.setSql(sql); dto.addFiltro(filtro); HashMap mtables = new HashMap(); mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla. Request request = this.callerhelper.getRequest(); request.setQueryTables(mtables); 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); for (TarmArmas armasObj : lrecord) { TarmRegistroArmas registroArmasObj = RegistroArmController .findByCodigo(armasObj.getCregistro().toString()); if (registroArmasObj != null && registroArmasObj.getPersoncode() != null) { TcustPersonDetail propietarioObj = PersonDetailController .find(registroArmasObj.getPersoncode().toString()); if (propietarioObj.getIdentificationcatalog() != null && propietarioObj.getIdentificationcatalogcode() != null) { armasObj.getModifiedData() .put("tipoDocumento", CatalogDetailController .findxCodigoCodcatalogo(propietarioObj.getIdentificationcatalog(), propietarioObj.getIdentificationcatalogcode()) .getDescription()); } armasObj.getModifiedData().put("noDocumento", propietarioObj.getIdentification()); armasObj.getModifiedData().put("nombrerazonsocial", propietarioObj.getName()); armasObj.getModifiedData().put("paisorigencode", registroArmasObj.getPaisorigen()); if (armasObj.getModifiedData().get("cclase") != null) { armasObj.getModifiedData().put("clase", CatalogDetailController .findxCodigoCodcatalogo(armasObj.getModifiedData().get("cclase").toString(), armasObj.getModifiedData().get("cclasecodigo").toString()) .getDescription()); } if (armasObj.getModifiedData().get("ctipoarmaexplosivo") != null) { armasObj.getModifiedData().put("tipoarmaexplosivo", CatalogDetailController.findxCodigoCodcatalogo( armasObj.getModifiedData().get("ctipoarmaexplosivo").toString(), armasObj.getModifiedData().get("ctipoarmaexplosivocodigo").toString()) .getDescription()); } if (armasObj.getModifiedData().get("ccalibre") != null) { armasObj.getModifiedData().put("calibre", CatalogDetailController .findxCodigoCodcatalogo(armasObj.getModifiedData().get("ccalibre").toString(), armasObj.getModifiedData().get("ccalibrecodigo").toString()) .getDescription()); } } } super.postQuery(this.lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } @Override public void next() throws Exception { // TODO Auto-generated method stub super.next(); } /** * Retorna un {@link DtoQuery} con los atributos a presentarse * * @return * @throws Exception */ private DtoQuery getDtoQuery() throws Exception { DtoQuery dto = super.getDtoQuery(true); SubQuery subqueryMarca = new SubQuery("TgeneCatalogDetail", "description", "marca", "i.pk.catalog=t.marca and i.pk.catalogcode=t.marcacodigo"); dto.addSubQuery(subqueryMarca); SubQuery subqueryColor = new SubQuery("TgeneCatalogDetail", "description", "color", "i.pk.catalog=t.color and i.pk.catalogcode=t.colorcodigo"); dto.addSubQuery(subqueryColor); SubQuery subqueryEstado = new SubQuery("TgeneCatalogDetail", "description", "estado", "i.pk.catalog=t.estado and i.pk.catalogcode=t.estadocodigo"); dto.addSubQuery(subqueryEstado); SubQuery subqueryClase = new SubQuery("TarmTipoArmaExplosivo", "clase", "cclase", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryClase); SubQuery subqueryClaseCodigo = new SubQuery("TarmTipoArmaExplosivo", "clasecodigo", "cclasecodigo", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryClaseCodigo); SubQuery subqueryLongitud = new SubQuery("TarmTipoArmaExplosivo", "longitud", "clongitud", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryLongitud); SubQuery subqueryLongitudCodigo = new SubQuery("TarmTipoArmaExplosivo", "longitudcodigo", "clongitudcodigo", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryLongitudCodigo); SubQuery subqueryCalibre = new SubQuery("TarmTipoArmaExplosivo", "calibre", "ccalibre", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryCalibre); SubQuery subqueryCalibreCodigo = new SubQuery("TarmTipoArmaExplosivo", "calibrecodigo", "ccalibrecodigo", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryCalibreCodigo); SubQuery subqueryTipoArma = new SubQuery("TarmTipoArmaExplosivo", "tipoarmaexplosivo", "ctipoarmaexplosivo", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryTipoArma); SubQuery subqueryTipoArmaCodigo = new SubQuery("TarmTipoArmaExplosivo", "tipoarmaexplosivocodigo", "ctipoarmaexplosivocodigo", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryTipoArmaCodigo); SubQuery subqueryUnidad = new SubQuery("TarmTipoArmaExplosivo", "unidadmedidapeso", "cunidadmedidapeso", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryUnidad); SubQuery subqueryUnidadCodigo = new SubQuery("TarmTipoArmaExplosivo", "unidadmedidapesocodigo", "cunidadmedidapesocodigo", "i.pk=t.ctipoarmaexplosivo"); dto.addSubQuery(subqueryUnidadCodigo); SubQuery subqueryUnidadMedida = new SubQuery("TgeneCatalogDetail", "description", "unidadmedida", "i.pk.catalog=t.unidadmedidacantidad and i.pk.catalogcode=t.unidadmedidacantidadcodigo"); dto.addSubQuery(subqueryUnidadMedida); SubQuery subquerycpersoncode = new SubQuery("TarmRegistroArmas", "personcode", "personcode", "i.pk=t.cregistro"); dto.addSubQuery(subquerycpersoncode); SubQuery subqueryFechaemiperm = new SubQuery("TarmDocumentoHabilitante", "fechaemision", "fechaemision", // " i.personcode=(select r.personcode from TarmRegistroArmas r where r.pk = // t.cregistro) and i.carma = t.pk and "+ " i.pk=(select max(doc.pk) from TarmDocumentoHabilitante doc where doc.personcode=(select r.personcode from TarmRegistroArmas r where r.pk = t.cregistro)" + " and doc.carma in (select arm1.pk from TarmArmas arm1 where arm1.codigoarma in (select arm.codigoarma from TarmArmas arm where arm.pk=t.pk)))"); dto.addSubQuery(subqueryFechaemiperm); SubQuery subqueryFechaexpperm = new SubQuery("TarmDocumentoHabilitante", "fechaexpiracion", "fechaexpiracion", // " i.personcode=(select r.personcode from TarmRegistroArmas r where r.pk = // t.cregistro) and i.carma = t.pk and "+ " i.pk=(select max(doc.pk) from TarmDocumentoHabilitante doc where doc.personcode=(select r.personcode from TarmRegistroArmas r where r.pk = t.cregistro) " + "and doc.carma in (select arm1.pk from TarmArmas arm1 where arm1.codigoarma in (select arm.codigoarma from TarmArmas arm where arm.pk=t.pk)))"); dto.addSubQuery(subqueryFechaexpperm); return dto; } /** * Método que se ejecuta al abrir el LOV de visualizar item seleccionado * * @throws Exception */ public void loadEdit() throws Exception { verificaArmaExplosivo = Boolean.TRUE; record.getModifiedData().put("provincia", ProvinceController.getDescProvByCodigo(record.getCountrycode(), record.getProvincecode())); record.getModifiedData().put("canton", CantonController.getDescCantonByCodigo(record.getCountrycode(), record.getProvincecode(), record.getCantoncode())); record.getModifiedData().put("ciudad", CityController.getDescCiudadByCodigo(record.getCountrycode(), record.getProvincecode(), record.getCantoncode(), record.getCitycode())); record.getModifiedData().put("parroquia", ParroquiaController.getDescParroquiaByCodigo(record.getCountrycode(), record.getProvincecode(), record.getCantoncode(), record.getParroquiacode())); if (record.getModifiedData().get("paisorigencode") != null) { record.getModifiedData().put("paisorigen", CountryController .findcountry(record.getModifiedData().get("paisorigencode").toString()).getDescription()); } if (record.getColor() != null) { record.getModifiedData().put("colorD", CatalogDetailController .findxCodigoCodcatalogo(record.getColor(), record.getColorcodigo()).getDescription()); } /* Aumentado */ TarmDocumentoHabilitante documento = DocumentoHabilitanteController .findxarma(record.getCodigoarma().toString()); TarmTramite tramite = TarmTramiteController.find(documento.getCtramite().toString()); TgeneCatalogDetail catalogo = CatalogDetailController.findxCodigoCodcatalogo(tramite.getCategoria(), tramite.getCategoriacodigo()); descategoria = catalogo.getDescription(); TgeneCatalogDetail uso = CatalogDetailController.findxCodigoCodcatalogo(tramite.getUsoactividad(), tramite.getUsoactividadcodigo()); usoActividad = uso.getDescription(); } @Override public void save() { } public String getTipoDoc() { return tipoDoc; } public void setTipoDoc(String tipoDoc) { this.tipoDoc = tipoDoc; } public String getNumDoc() { return numDoc; } public void setNumDoc(String numDoc) { this.numDoc = numDoc; } public String getNombreRazon() { return nombreRazon; } public void setNombreRazon(String nombreRazon) { this.nombreRazon = nombreRazon; } public String getLongitud() { return longitud; } public void setLongitud(String longitud) { this.longitud = longitud; } public String getCalibre() { return calibre; } public void setCalibre(String calibre) { this.calibre = calibre; } public String getClase() { return clase; } public void setClase(String clase) { this.clase = clase; } public String getTipoarma() { return tipoarma; } public void setTipoarma(String tipoarma) { this.tipoarma = tipoarma; } public String getUnidadmedidapeso() { return unidadmedidapeso; } public void setUnidadmedidapeso(String unidadmedidapeso) { this.unidadmedidapeso = unidadmedidapeso; } public boolean isExisteTipoArmaExplosivo() { return existeTipoArmaExplosivo; } public void setExisteTipoArmaExplosivo(boolean existeTipoArmaExplosivo) { this.existeTipoArmaExplosivo = existeTipoArmaExplosivo; } public boolean isVerificaArmaExplosivo() { return verificaArmaExplosivo; } public void setVerificaArmaExplosivo(boolean verificaArmaExplosivo) { this.verificaArmaExplosivo = verificaArmaExplosivo; } public boolean isBloquearUnidadCantidad() { return bloquearUnidadCantidad; } public void setBloquearUnidadCantidad(boolean bloquearUnidadCantidad) { this.bloquearUnidadCantidad = bloquearUnidadCantidad; } public boolean isBloquearUnidadPeso() { return bloquearUnidadPeso; } public void setBloquearUnidadPeso(boolean bloquearUnidadPeso) { this.bloquearUnidadPeso = bloquearUnidadPeso; } public Date getFechaActual() { return fechaActual; } public void setFechaActual(Date fechaActual) { this.fechaActual = fechaActual; } public String getRazonSocial() { return razonSocial; } public void setRazonSocial(String razonSocial) { this.razonSocial = razonSocial; } public String getNumeroDocumento() { return numeroDocumento; } public void setNumeroDocumento(String numeroDocumento) { this.numeroDocumento = numeroDocumento; } public String getDescategoria() { return descategoria; } public void setDescategoria(String descategoria) { this.descategoria = descategoria; } public String getUsoActividad() { return usoActividad; } public void setUsoActividad(String usoActividad) { this.usoActividad = usoActividad; } /** * Metodo que genera el reporte para el registro seleccionado * * @param event * @throws Exception */ public void imprimir() { System.out.println("Imprimir un reporte en PDF.. Pendiente implementar"); } public String retornaDatosArma(String codArma, int opc) { String resp = ""; try { if (codArma!=null) { TarmDocumentoHabilitante documento = DocumentoHabilitanteController.findxarma(codArma); if (documento.getCtramite()!=null) { TarmTramite tramite = TarmTramiteController.find(documento.getCtramite().toString()); if (opc == 1) { TgeneCatalogDetail catalogo = CatalogDetailController.findxCodigoCodcatalogo(tramite.getCategoria(), tramite.getCategoriacodigo()); resp = catalogo.getDescription(); } if (opc == 2) { TgeneCatalogDetail uso = CatalogDetailController.findxCodigoCodcatalogo(tramite.getUsoactividad(), tramite.getUsoactividadcodigo()); resp = uso.getDescription(); } } } } catch (Exception e) { resp=""; MessageHelper.setMessageError(e); } return resp; } }