package com.fp.frontend.controller.armas.solicitud; import java.util.Calendar; 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.ManagedProperty; import javax.faces.bean.ViewScoped; import javax.faces.context.FacesContext; import org.primefaces.event.SelectEvent; import com.fp.dto.AbstractDataTransport; import com.fp.dto.Response; import com.fp.frontend.controller.AbstractController; import com.fp.frontend.controller.ReportController; import com.fp.frontend.controller.armas.parametros.CentroControlArmasController; import com.fp.frontend.controller.armas.parametros.TarmCentroControlJurController; 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.controller.security.LoginController; import com.fp.frontend.helper.MessageHelper; import com.fp.frontend.utility.MsgControlArmas; import com.fp.frontend.utility.Utilidades; import com.fp.persistence.parmas.param.TarmCentroControl; import com.fp.persistence.parmas.param.TarmCentroControlJur; import com.fp.persistence.pcustomer.gene.TcustPersonAddress; import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail; import com.fp.persistence.pgeneral.safe.TsafeUserDetail; /** * Clase controladora de reporte de liquidacion economica * * @author Christian Pazmino. * @version 2.1 */ @SuppressWarnings("serial") @ManagedBean @ViewScoped public class ReporteSancionesController extends AbstractController { /** * Fecha a partir de la cual se sacan datos para el reporte * */ private Date fechaInicio; /** * Fecha a partir de la cual se sacan datos para el reporte * */ private Date fechaFin; /** * Formato de reporte que se va a generar * */ private Date fechaDecomiso; private String format = "pdf"; /** * Usuario actual logueado en el sistema * */ private TsafeUserDetail userDetail; /** * Nombre del reporte generado en el Alfresco * */ private String nombreReporte; /** * Id del centro de control seleccionado por el usuario * */ private String idCentroControl; /** * Id del tipo de tramite */ private String idAutorizacion; private String idIdentificacion; private String numeroDocumento; /** * Id del tipo de tramite */ private String idControl; private Boolean habilitar; /** * Lista de centros de control de armas */ // private List centroControlList; private List tipoDocumentoList; private List centroControlList; private List autorizacionList; private List controlList; private String institucionCentroControl=""; private TarmCentroControl centroControl = new TarmCentroControl(); /** * Clase controladora de reportes */ @ManagedProperty(value = "#{reportController}") private ReportController reportController; @ManagedProperty(value = "#{logincontroller}") private LoginController logincontroller; public ReporteSancionesController() throws Exception { super(AbstractDataTransport.class); // TODO Auto-generated constructor stub } @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 { userDetail=(TsafeUserDetail)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL"); recperpage = 10000; // Cambiar al # reg a mirar. beanalias = "RPRTEAUTORIZACIONES"; // centroControlList = CentroControlArmasController.findAll(); centroControlList = CatalogDetailController.find("TIPODEFALTA"); autorizacionList = CatalogDetailController.find("USOACTIVIDAD"); tipoDocumentoList = CatalogDetailController.find("IDENTIFICATION"); controlList = CatalogDetailController.find("NOMBREINSTITUCION"); this.habilitar = true; } catch (Exception e) { MessageHelper.setMessageError(e); } } @SuppressWarnings("unchecked") @Override protected void querydatabase() { } /** * Metodo para reconsultar en base a una nueva fecha de corte seleccionada */ public void cambioFechaDeCorte(SelectEvent event){ querydatabase(); } @Override public void postCommit(Response response) throws Exception { super.postCommitGeneric(response, beanalias); } /** * * */ public void habilitarfechadecomiso(){ if (this.idAutorizacion.equals( "6")){ this.habilitar = false; } else { this.habilitar = true; this.fechaDecomiso = null; } } /** * Genera un reporte de armas a destruir * */ public void generateReport() { if(this.fechaInicio!=null || this.fechaFin!=null || this.fechaDecomiso!=null ) { if(this.fechaInicio!=null && this.fechaFin!=null ) { if(this.fechaInicio.getTime() > this.fechaFin.getTime()){ MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_liqeco_fechaInicioMayorAFechaFin1")); return; } } if(this.fechaInicio!=null && this.fechaFin==null ) { if(this.fechaInicio.getTime() > new Date().getTime()){ MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_liqeco_fechaInicioMayorAFechaActual")); return; } } if(this.fechaInicio==null && this.fechaFin!=null ) { if(this.fechaFin.getTime() > new Date().getTime()){ MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_liqeco_fechaFinMayorAFechaActual")); return; } } if(this.fechaDecomiso!=null ) { if(this.fechaDecomiso.getTime() > new Date().getTime()){ MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_liqeco_fechaDecomisoMayorAFechaActual")); return; } } } String path = ""; if (this.idAutorizacion.equals( "1")){ path = "armas/reports/sancionesa"; } if (this.idAutorizacion.equals( "6")){ path = "armas/reports/sancionesp"; } Calendar fechaActualCldr = Calendar.getInstance(); //String path = "armas/reports/autorizaciones"; String filename="sanciones"; String nombreUsuario=""; // Fija parametros del report. HashMap parameters = new HashMap<>(); if(userDetail.getPk().getPersoncode()!=null){ nombreUsuario = PersonDetailController.find(userDetail.getPk().getPersoncode().toString()).getName(); } else{ nombreUsuario = ""; } // institucionCentroControl parameters.put("pathLogoIzquierda", "repo:/maia/1/image/comandoconjunto"); parameters.put("pathLogoDerecha", "repo:/maia/1/image/selloarmas"); //parameters.put("unidadmilitar", "hola"); parameters.put("lugarFecha", Utilidades.armarFormatoFechaConHora(fechaActualCldr)); parameters.put("usuario", nombreUsuario); parameters.put("numeroDocumento"," ".equalsIgnoreCase(numeroDocumento)?null:numeroDocumento); parameters.put("Pcentro", "TODOS".equalsIgnoreCase(idControl)?null:idControl); //centro de control parameters.put("Pcausa_sancion","TODOS".equalsIgnoreCase(idCentroControl)?null:idCentroControl); // estado //parameters.put("idAutorizacion", "TODOS".equalsIgnoreCase(idAutorizacion)?null:idAutorizacion); // tipo de auturizacion parameters.put("Ptidentificacion", "TODOS".equalsIgnoreCase(idIdentificacion)?null:idIdentificacion); // tipo de identificacion parameters.put("fechaInicio", this.fechaInicio==null?null:Utilidades.armarFormatoFechaSinHora(this.fechaInicio)); parameters.put("fechaFin", this.fechaFin==null?null:Utilidades.armarFormatoFechaSinHora(this.fechaFin)); parameters.put("fechaDecomiso", this.fechaDecomiso==null?null:Utilidades.armarFormatoFechaSinHora(this.fechaDecomiso)); TgeneCatalogDetail obj = CatalogDetailController.findCatalogo("NOMBREINSTITUCION", idControl); parameters.put("tipocentro", "TODOS".equalsIgnoreCase(idControl)?"TODOS":obj.getDescription()) ; //centro de control detalle TgeneCatalogDetail obj2 = CatalogDetailController.findCatalogo("IDENTIFICATION", idIdentificacion); parameters.put("pdocumento", "TODOS".equalsIgnoreCase(idIdentificacion)?"TODOS":obj2.getDescription()) ; //tipo documento detalle TgeneCatalogDetail obj3 = CatalogDetailController.findCatalogo("TIPOAUTORIZACION", idAutorizacion); parameters.put("pautorizacion", "TODOS".equalsIgnoreCase(idAutorizacion)?"TODOS":obj3.getDescription()) ; //tipo autorizacion detalle TgeneCatalogDetail obj4 = CatalogDetailController.findCatalogo("TIPODEFALTA", idCentroControl); parameters.put("psancion", "TODOS".equalsIgnoreCase(idCentroControl)?"TODOS":obj4.getDescription()) ; //causa sancion detalle try{ this.reportController.executeXls(path, parameters, format, filename, this.getLoginController()); } catch (Exception ex) { MessageHelper.setMessageError(ex); } } private void obtenerCentroControl() throws Exception { TsafeUserDetail tsafeUserDetail = (TsafeUserDetail) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL"); PersonAddressController personAddressController = new PersonAddressController(); TcustPersonAddress tcustPersonAddres=personAddressController.findPrincipal(tsafeUserDetail.getPk().getPersoncode().toString()); TarmCentroControlJur centroControlJur= TarmCentroControlJurController.findxProvincia(tcustPersonAddres.getProvincecode()); centroControl= CentroControlArmasController.findPorCodigo(centroControlJur.getCcentrocontrol()); institucionCentroControl = CatalogDetailController.findxCodigoCodcatalogo( centroControl.getNombreinstitucion(), centroControl.getNombreinstitucioncodigo()).getDescription(); } /** * Método para el inicio de flujo. Guardar el reporte creado para su posterior aprobacion en otras instancias del flujo */ @Override public void save(){ } public Date getFechaInicio() { return fechaInicio; } public void setFechaInicio(Date fechaInicio) { this.fechaInicio = fechaInicio; } public Date getFechaDecomiso() { return fechaDecomiso; } public void setFechaDecomiso(Date fechaDecomiso) { this.fechaDecomiso = fechaDecomiso; } public Date getFechaFin() { return fechaFin; } public void setFechaFin(Date fechaFin) { this.fechaFin = fechaFin; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public TsafeUserDetail getUserDetail() { return userDetail; } public void setUserDetail(TsafeUserDetail userDetail) { this.userDetail = userDetail; } public String getNombreReporte() { return nombreReporte; } public void setNombreReporte(String nombreReporte) { this.nombreReporte = nombreReporte; } public String getIdCentroControl() { return idCentroControl; } public void setIdCentroControl(String idCentroControl) { this.idCentroControl = idCentroControl; } public String getIdAutorizacion() { return idAutorizacion; } public void setIdAutorizacion(String idAutorizacion) { this.idAutorizacion = idAutorizacion; } //idIdentificacion public String getIdIdentificacion() { return idIdentificacion; } public void setIdIdentificacion(String idIdentificacion) { this.idIdentificacion = idIdentificacion; } //public List getCentroControlList() { // return centroControlList; //} //public void setCentroControlList(List centroControlList) { //this.centroControlList = centroControlList; //} public List getCentroControlList() { return centroControlList; } public void setCentroControlList(List centroControlList) { this.centroControlList = centroControlList; } /*CFLORES*/ public List getTipoDocumentoList() { return tipoDocumentoList; } public void getTipoDocumentoList(List tipoDocumentoList) { this.tipoDocumentoList = tipoDocumentoList; } /**/ public List getAutorizacionList() { return autorizacionList; } public void setAutorizacionList(List autorizacionList) { this.autorizacionList = autorizacionList; } /*cflores*/ public List getControlList() { return controlList; } public void setControlList(List controlList) { this.controlList = controlList; } public String getIdControl() { return idControl; } public void setIdControl(String idControl) { this.idControl = idControl; } public void setHabilitar(Boolean habilitar) { this.habilitar = habilitar; } public Boolean getHabilitar() { return habilitar; } public String getNumeroDocumento() { return numeroDocumento; } public void setNumeroDocumento(String numeroDocumento) { this.numeroDocumento = numeroDocumento; } /**/ public ReportController getReportController() { return reportController; } public void setReportController(ReportController reportController) { this.reportController = reportController; } public String getInstitucionCentroControl() { return institucionCentroControl; } public void setInstitucionCentroControl(String institucionCentroControl) { this.institucionCentroControl = institucionCentroControl; } public LoginController getLogincontroller() { return logincontroller; } public void setLogincontroller(LoginController logincontroller) { this.logincontroller = logincontroller; } public TarmCentroControl getCentroControl() { return centroControl; } public void setCentroControl(TarmCentroControl centroControl) { this.centroControl = centroControl; } }