372 lines
14 KiB
Plaintext
Executable File
372 lines
14 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.funcionalidad;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
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.ManagedProperty;
|
|
import javax.faces.bean.ViewScoped;
|
|
import javax.faces.context.FacesContext;
|
|
|
|
import org.primefaces.event.SelectEvent;
|
|
|
|
import com.fp.dto.AbstractDataTransport;
|
|
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.pcustomer.lov.PersonLovController;
|
|
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.param.TarmCentroControl;
|
|
import com.fp.persistence.parmas.param.TarmCentroControlJur;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonAddress;
|
|
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
|
import com.fp.persistence.pgeneral.safe.TsafeUserDetail;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @author Andres Cevallos
|
|
* Clase Controladora la cual genera el reporte de armas
|
|
*/
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class ReporteArmasController extends AbstractController<AbstractDataTransport> {
|
|
|
|
public ReporteArmasController() throws Exception {
|
|
super(AbstractDataTransport.class);
|
|
// TODO Auto-generated constructor stub
|
|
}
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
public Date fecha;
|
|
private TcustPersonDetail customerperson;
|
|
private List<TgeneCatalogDetail> lestados;
|
|
@ManagedProperty(value = "#{reportController}")
|
|
private ReportController reportController;
|
|
private TsafeUserDetail userDetail;
|
|
private String institucionCentroControl="";
|
|
private TarmCentroControl centroControl = new TarmCentroControl();
|
|
private Date fechainicial;
|
|
private Date fechafinal;
|
|
private String filtro="";
|
|
private String estado;
|
|
private String serieLote;
|
|
|
|
public String getInstitucionCentroControl() {
|
|
return institucionCentroControl;
|
|
}
|
|
|
|
public void setInstitucionCentroControl(String institucionCentroControl) {
|
|
this.institucionCentroControl = institucionCentroControl;
|
|
}
|
|
|
|
|
|
|
|
|
|
public TsafeUserDetail getUserDetail() {
|
|
return userDetail;
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setUserDetail(TsafeUserDetail userDetail) {
|
|
this.userDetail = userDetail;
|
|
}
|
|
|
|
|
|
|
|
|
|
public ReportController getReportController() {
|
|
return reportController;
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setReportController(ReportController reportController) {
|
|
this.reportController = reportController;
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
// Inicializa autoconsulta
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
|
|
this.lrecord = new ArrayList<>();
|
|
this.beanalias = "REPORTE";
|
|
lestados = CatalogDetailController.find("ESTADOARMA");
|
|
userDetail=(TsafeUserDetail)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");
|
|
estado="";
|
|
obtenerCentroControl();
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Metodo que se debe ejecutar cuando es una transaccion de tipo verificar armas
|
|
* @throws Exception
|
|
*/
|
|
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();
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void querydatabase() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Abre el Lov de Persona
|
|
*/
|
|
public void openPersonLov() {
|
|
Map<String, List<String>> params = new HashMap<>();
|
|
PersonLovController.openLov(params);
|
|
}
|
|
|
|
/**
|
|
* Carga los datos que se devuelven en el Lov de personas
|
|
* @param event
|
|
* @throws Exception
|
|
*/
|
|
public void onReturnPersonLov(SelectEvent event) throws Exception {
|
|
setCustomerperson( (TcustPersonDetail) event.getObject());
|
|
|
|
}
|
|
/**
|
|
* Graba los registros en la base de datos
|
|
*/
|
|
@Override
|
|
public void save() {
|
|
|
|
|
|
}
|
|
|
|
public void generarReporte(){
|
|
if(fechainicial.getTime()>fechafinal.getTime()){
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_fechafinal"));
|
|
return;
|
|
}
|
|
String gradoUsuario ="";
|
|
filtro=" ";
|
|
String path = "armas/reports/reporteArmas";
|
|
if(customerperson!=null){
|
|
filtro=" and tarma.cregistro in "
|
|
+ " (select regarma.cregistro from tarmregistroarmas regarma where regarma.personcode='"+customerperson.getPk().getPersoncode()+"')";
|
|
}
|
|
if(estado!=null && !estado.equals("")){
|
|
if(estado.equals("APTA")){
|
|
filtro+=" and tarma.carma in (select carma from tarmarmapruebas p "
|
|
+ " where p.carmaprueba=(select max(prue.carmaprueba)"
|
|
+ " from tarmarmapruebas prue where prue.apruebaevaluacion='Y' and prue.carma in(select codar.carma from tarmarmas codar"
|
|
+ " where codar.codigoarma =(select ar.codigoarma from tarmarmas ar where carma=tarma.carma) ))) ";
|
|
//"and pru.apruebaevaluacion='Y'";
|
|
}
|
|
else{
|
|
filtro+=" and tarma.estado='"+estado+"' ";
|
|
}
|
|
}
|
|
|
|
//Fija parametros del report.
|
|
HashMap<String, Object> parameters = new HashMap<>();
|
|
parameters.put("pathLogoIzquierda", "repo:/maia/1/image/comandoconjunto");
|
|
parameters.put("pathLogoDerecha", "repo:/maia/1/image/selloarmas");
|
|
// parameters.put("fechaCorte", (new SimpleDateFormat("dd-MM-yyyy")).format(fechaCorte).toString());
|
|
// parameters.put("gradoUsuario",gradoUsuario);
|
|
try {
|
|
|
|
//Usuario logueado en la aplicacion
|
|
String nombreUsuario;
|
|
if(userDetail.getPk().getPersoncode()!=null){
|
|
nombreUsuario = PersonDetailController.find(userDetail.getPk().getPersoncode().toString()).getName();
|
|
parameters.put("personcode", userDetail.getPk().getPersoncode());
|
|
}
|
|
else{
|
|
nombreUsuario = "";
|
|
}
|
|
//filtro = "where tarma.personcode='1138'";
|
|
parameters.put("filtro", filtro);
|
|
SimpleDateFormat fechatxt=new SimpleDateFormat("yyyy-MM-dd");
|
|
parameters.put("fechainicial", fechatxt.format(fechainicial));
|
|
parameters.put("fechafinal", fechatxt.format(fechafinal));
|
|
parameters.put("usuario", nombreUsuario);
|
|
parameters.put("unidadmilitar", institucionCentroControl);
|
|
// parameters.put("tecnicoAlmacenamiento",MsgControlArmas.getProperty("tecnicoAlmacenamiento")+" "+institucionCentroControl);
|
|
// parameters.put("jefe",MsgControlArmas.getProperty("jefe")+" "+institucionCentroControl);
|
|
String format="xlsx";
|
|
String filename= MsgControlArmas.getProperty("lbl_nombreexcel");
|
|
//Fecha actual
|
|
Calendar fechaActualCldr = Calendar.getInstance();
|
|
StringBuilder fechaActualSB = new StringBuilder();
|
|
fechaActualSB = fechaActualSB.append((fechaActualCldr.get(Calendar.DAY_OF_MONTH)) <= 9 ? "0" + (fechaActualCldr.get(Calendar.DAY_OF_MONTH)) : (fechaActualCldr.get(Calendar.DAY_OF_MONTH)));
|
|
fechaActualSB = fechaActualSB.append("-").append((fechaActualCldr.get(Calendar.MONTH)+1) <= 9 ? "0" + (fechaActualCldr.get(Calendar.MONTH) + 1) : (fechaActualCldr.get(Calendar.MONTH)+1));
|
|
fechaActualSB = fechaActualSB.append("-").append(fechaActualCldr.get(Calendar.YEAR));
|
|
fechaActualSB = fechaActualSB.append(" ").append(fechaActualCldr.get(Calendar.HOUR_OF_DAY));
|
|
fechaActualSB = fechaActualSB.append(":").append((fechaActualCldr.get(Calendar.MINUTE)) <= 9 ? "0" + (fechaActualCldr.get(Calendar.MINUTE)) : (fechaActualCldr.get(Calendar.MINUTE)));
|
|
parameters.put("lugarfecha", fechaActualSB.toString());
|
|
// parameters.put("transaccion",numeroTransaccionEnvioConvertido);
|
|
parameters.put("codigoQR", "PRUEBAARMAS"+fechaActualSB.toString());
|
|
|
|
// format = CatalogDetailController.findxCodigoCodcatalogo(tipoReporte, "TIPOREPORTE").getLegalcode();
|
|
this.reportController.executeXls(path, parameters, format, filename, this.getLoginController());
|
|
// this.reportController.execute(path, parameters, null, filename, this.getLoginController());
|
|
// xpathflujo = generarXpath();
|
|
|
|
// alfrescoController.uploadFile(file,numeroTransaccionEnvioConvertido+".pdf",xpathflujo);
|
|
// iniciarFlujo(xpathflujo+"/cm:"+numeroTransaccionEnvioConvertido+ ".pdf");//="cm:Decomiso/cm:A-2014/cm:M-10/cm:ENV-000000319/cm:ENV-000000319.pdf"
|
|
} catch (Exception ex) {
|
|
MessageHelper.setMessageError(ex);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public void generarReporteHistorico(){
|
|
if(fechainicial.getTime()>fechafinal.getTime()){
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_fechafinal"));
|
|
return;
|
|
}
|
|
String gradoUsuario ="";
|
|
String path = "armas/reports/reporteHistoricoArmas.jrxml";
|
|
filtro="";
|
|
if(serieLote!=null && serieLote.trim().length()>0){
|
|
filtro=" and tarma.lote='"+serieLote+"' ";
|
|
}
|
|
//Fija parametros del report.
|
|
HashMap<String, Object> parameters = new HashMap<>();
|
|
parameters.put("pathLogoIzquierda", "repo:/maia/1/image/comandoconjunto");
|
|
parameters.put("pathLogoDerecha", "repo:/maia/1/image/selloarmas");
|
|
try {
|
|
//Usuario logueado en la aplicacion
|
|
String nombreUsuario;
|
|
if(userDetail.getPk().getPersoncode()!=null){
|
|
nombreUsuario = PersonDetailController.find(userDetail.getPk().getPersoncode().toString()).getName();
|
|
parameters.put("personcode", userDetail.getPk().getPersoncode());
|
|
}
|
|
else{
|
|
nombreUsuario = "";
|
|
}
|
|
//filtro = "where tarma.personcode='1138'";
|
|
parameters.put("filtro", filtro);
|
|
SimpleDateFormat fechatxt=new SimpleDateFormat("dd/MM/yyyy");
|
|
parameters.put("fechainicial", fechatxt.format(fechainicial));
|
|
parameters.put("fechafinal", fechatxt.format(fechafinal));
|
|
parameters.put("usuario", nombreUsuario);
|
|
parameters.put("unidadmilitar", institucionCentroControl);
|
|
String format="xlsx";
|
|
String filename= MsgControlArmas.getProperty("lbl_nombreexcelhistorico");
|
|
//Fecha actual
|
|
Calendar fechaActualCldr = Calendar.getInstance();
|
|
StringBuilder fechaActualSB = new StringBuilder();
|
|
fechaActualSB = fechaActualSB.append((fechaActualCldr.get(Calendar.DAY_OF_MONTH)) <= 9 ? "0" + (fechaActualCldr.get(Calendar.DAY_OF_MONTH)) : (fechaActualCldr.get(Calendar.DAY_OF_MONTH)));
|
|
fechaActualSB = fechaActualSB.append("-").append((fechaActualCldr.get(Calendar.MONTH)+1) <= 9 ? "0" + (fechaActualCldr.get(Calendar.MONTH) + 1) : (fechaActualCldr.get(Calendar.MONTH)+1));
|
|
fechaActualSB = fechaActualSB.append("-").append(fechaActualCldr.get(Calendar.YEAR));
|
|
fechaActualSB = fechaActualSB.append(" ").append(fechaActualCldr.get(Calendar.HOUR_OF_DAY));
|
|
fechaActualSB = fechaActualSB.append(":").append((fechaActualCldr.get(Calendar.MINUTE)) <= 9 ? "0" + (fechaActualCldr.get(Calendar.MINUTE)) : (fechaActualCldr.get(Calendar.MINUTE)));
|
|
parameters.put("lugarfecha", fechaActualSB.toString());
|
|
this.reportController.executeXls(path, parameters, format, filename, this.getLoginController());
|
|
} catch (Exception ex) {
|
|
MessageHelper.setMessageError(ex);
|
|
}
|
|
}
|
|
|
|
|
|
/* (non-Javadoc)
|
|
* @see com.fp.frontend.controller.AbstractController#postCommit(com.fp.dto.Response)
|
|
*/
|
|
|
|
public Date getFecha() {
|
|
return fecha;
|
|
}
|
|
|
|
public void setFecha(Date fecha) {
|
|
this.fecha = fecha;
|
|
}
|
|
|
|
public TcustPersonDetail getCustomerperson() {
|
|
return customerperson;
|
|
}
|
|
|
|
public void setCustomerperson(TcustPersonDetail customerperson) {
|
|
this.customerperson = customerperson;
|
|
}
|
|
|
|
public List<TgeneCatalogDetail> getLestados() {
|
|
return lestados;
|
|
}
|
|
|
|
public void setLestados(List<TgeneCatalogDetail> lestados) {
|
|
this.lestados = lestados;
|
|
}
|
|
|
|
public Date getFechainicial() {
|
|
return fechainicial;
|
|
}
|
|
|
|
public void setFechainicial(Date fechainicial) {
|
|
this.fechainicial = fechainicial;
|
|
}
|
|
|
|
public Date getFechafinal() {
|
|
return fechafinal;
|
|
}
|
|
|
|
public void setFechafinal(Date fechafinal) {
|
|
this.fechafinal = fechafinal;
|
|
}
|
|
|
|
public String getEstado() {
|
|
return estado;
|
|
}
|
|
|
|
public void setEstado(String estado) {
|
|
this.estado = estado;
|
|
}
|
|
|
|
public String getSerieLote() {
|
|
return serieLote;
|
|
}
|
|
|
|
public void setSerieLote(String serieLote) {
|
|
this.serieLote = serieLote;
|
|
}
|
|
|
|
} |