package com.fp.frontend.controller.armas.solicitud; import java.util.ArrayList; import java.util.Date; 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.ViewScoped; 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.frontend.controller.AbstractController; import com.fp.frontend.controller.armas.funcionalidad.RegistroArmController; import com.fp.frontend.controller.pcustomer.PersonDetailController; import com.fp.frontend.controller.pcustomer.lov.PersonLovController; 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.soli.TarmArmas; import com.fp.persistence.pcustomer.gene.TcustPersonDetail; /** * Controlador principal de la funcionalidad de consulta de armas * @author Christian Pazmino * */ @SuppressWarnings("serial") @ManagedBean @ViewScoped public class ConsultaArmasController extends AbstractController { // @ManagedProperty(value = "#{registroArmController}") // private RegistroArmController registroArmas; /** * 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; public ConsultaArmasController() 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 { fechaActual = new Date(); recperpage = 15; // Cambiar al # reg a mirar. lrecord = new ArrayList<>(); beanalias = "ARMAS"; filtroPersona = ""; } 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()); } } @Override public void save() { } // public RegistroArmController getRegistroArmas() { // return registroArmas; // } // // // public void setRegistroArmas(RegistroArmController registroArmas) { // this.registroArmas = registroArmas; // } 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; } /** * Abre el lov de persona */ public void openPersonLov() { Map> params = new HashMap<>(); PersonLovController.openLov(params); } /** * Maneja la respuesta del Lov de Personas * @param event * @throws Exception */ public void onReturnPersonLov(SelectEvent event) throws Exception { TcustPersonDetail personaDetailSelecionada = (TcustPersonDetail) event.getObject(); razonSocial=personaDetailSelecionada.getName(); numeroDocumento=personaDetailSelecionada.getIdentification(); filtroPersona = " and t.cregistro in (select i.pk from TarmRegistroArmas i where i.personcode ="+personaDetailSelecionada.getPk().getPersoncode()+")"; // List registroArmasList = RegistroArmController.findxPersoncode(personaDetailSelecionada.getPk().getPersoncode().toString()); // if(registroArmasList!=null && registroArmasList.size()>0){ // filtroPersona = " and t.cregistro in ("; // for(TarmRegistroArmas regArmaObj : registroArmasList){ // filtroPersona+=regArmaObj.getPk().toString() + ","; // } // filtroPersona=filtroPersona.substring(0, filtroPersona.length()-1); // filtroPersona+=")"; // }else{ // filtroPersona = " and t.cregistro = -10023"; // } querydatabase(); } /** * 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"); } }