373 lines
14 KiB
Plaintext
Executable File
373 lines
14 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
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 javax.faces.event.AjaxBehaviorEvent;
|
|
|
|
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.alfresco.AlfrescoController;
|
|
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.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.pcustomer.gene.TcustPersonDetail;
|
|
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 ReporteControlInventarioController extends AbstractController<AbstractDataTransport> {
|
|
|
|
|
|
/**
|
|
* Fecha a partir de la cual se sacan datos para el reporte
|
|
* */
|
|
private Date fechaFin;
|
|
/**
|
|
* Formato de reporte que se va a generar
|
|
* */
|
|
private String format = "xls";
|
|
/**
|
|
* 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;
|
|
|
|
/**
|
|
* Ruta base del reporte generado en el Alfresco
|
|
* */
|
|
private String xPathLocation;
|
|
|
|
private String institucionCentroControl="";
|
|
private TarmCentroControl centroControl = new TarmCentroControl();
|
|
|
|
/**
|
|
* Clase controladora de reportes
|
|
*/
|
|
@ManagedProperty(value = "#{reportController}")
|
|
private ReportController reportController;
|
|
|
|
/**
|
|
* Clase controladora de funcionalidad del Alfresco
|
|
*/
|
|
@ManagedProperty(value="#{alfrescoController}")
|
|
private AlfrescoController alfrescoController;
|
|
|
|
|
|
public ReporteControlInventarioController() 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.
|
|
lrecord = new ArrayList<AbstractDataTransport>();
|
|
beanalias = "RPRTECONTROLINVENTARIO";
|
|
obtenerCentroControl();
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
// /**
|
|
// * Crea una instancia y marca el registro como nuevo.
|
|
// *
|
|
// * @throws Exception
|
|
// */
|
|
// @Override
|
|
// public void create() throws Exception {
|
|
// super.create();
|
|
// }
|
|
|
|
/**
|
|
* Seleccionado todos los registros de la tabla
|
|
*/
|
|
public void seleccionarTodos(AjaxBehaviorEvent event) {
|
|
try {
|
|
Boolean valorColocar = Boolean.FALSE;
|
|
if(Boolean.valueOf(event.getComponent().getAttributes().get("value") != null ? event.getComponent().getAttributes().get("value").toString() : "false")){
|
|
valorColocar = Boolean.TRUE;
|
|
}
|
|
for (AbstractDataTransport decomisoArmaObj : lrecord) {
|
|
decomisoArmaObj.getModifiedData().put("isSelect", valorColocar);
|
|
}
|
|
} catch (Throwable 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);
|
|
}
|
|
|
|
|
|
/**
|
|
* Genera un reporte de armas a destruir
|
|
*
|
|
*/
|
|
public void generateReport() {
|
|
Calendar fechaActualCldr = Calendar.getInstance();
|
|
Calendar fechaInicioCldr = Calendar.getInstance();
|
|
Calendar fechaFinCldr = Calendar.getInstance();
|
|
// fechaInicioCldr.setTime(fechaInicio);
|
|
fechaFinCldr.setTime(fechaFin);
|
|
|
|
if(fechaActualCldr.compareTo(fechaFinCldr)>=0){
|
|
String filename="controlInventario";
|
|
// 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;
|
|
TcustPersonDetail personaLogObj;
|
|
if(userDetail.getPk().getPersoncode()!=null){
|
|
personaLogObj = PersonDetailController.find(userDetail.getPk().getPersoncode().toString());
|
|
nombreUsuario = personaLogObj.getName();
|
|
}
|
|
else{
|
|
nombreUsuario = "";
|
|
}
|
|
parameters.put("usuario", nombreUsuario);
|
|
parameters.put("fechaInicio", armarFormatoFechaSinHora(fechaInicioCldr));
|
|
// fechaFinCldr.add(Calendar.DAY_OF_MONTH, 1);
|
|
parameters.put("fechaFin", armarFormatoFechaSinHora(fechaFinCldr));
|
|
parameters.put("fechaReporte", armarFormatoFechaConHora(fechaActualCldr));
|
|
|
|
String path;
|
|
|
|
path = "armas/reports/controlInventario";
|
|
parameters.put("idCentroControl", centroControl.getPk());
|
|
// Datos del CENTRO DE CONTROL
|
|
parameters.put("nombreCentroControl", institucionCentroControl);
|
|
// Datos del jefe del centro
|
|
if(centroControl.getPersoncode()!=null){
|
|
TcustPersonDetail jefeCentroObj = PersonDetailController.find(centroControl.getPersoncode().toString());
|
|
String gradoJefeCentro = jefeCentroObj.getMilitarygrade()==null?"": jefeCentroObj.getMilitarygrade() + " - ";
|
|
parameters.put("nombreJefCentro", gradoJefeCentro + jefeCentroObj.getName()==null?"":jefeCentroObj.getName());
|
|
parameters.put("personCodeJefCentro", jefeCentroObj.getPk().getPersoncode()==null?"1001":jefeCentroObj.getPk().getPersoncode());
|
|
}
|
|
xPathLocation= getRutaDocumentoRepBase() + "/cm:"+ Utilidades.obtieneNombreLimpio(institucionCentroControl);
|
|
nombreReporte = "controlInventario.xls";
|
|
//this.reportController.executeXls(path, parameters, format, filename, this.getLoginController());
|
|
InputStream file = this.reportController.jaspertoInputstreamXls(path, parameters, format, filename, this.getLoginController());
|
|
if(!alfrescoController.uploadFile(file, nombreReporte, xPathLocation)){
|
|
xPathLocation=null;
|
|
}
|
|
} catch (Exception ex) {
|
|
MessageHelper.setMessageError(ex);
|
|
}
|
|
|
|
}else{
|
|
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_coninv_fechaMayorAFechaActual"));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retorna la ruta de documento base en donde se almacenará el reporte
|
|
*
|
|
* @return
|
|
*/
|
|
public String getRutaDocumentoRepBase() {
|
|
Calendar calendar = Calendar.getInstance();
|
|
calendar.setTime(new Date());
|
|
StringBuilder ruta = new StringBuilder("cm:Inventario");
|
|
ruta = ruta.append("/cm:A-").append(calendar.get(Calendar.YEAR));
|
|
ruta = ruta.append("/cm:M-").append((calendar.get(Calendar.MONTH)+1) <= 9 ? "0" + (calendar.get(Calendar.MONTH) + 1) : (calendar.get(Calendar.MONTH)+1));
|
|
// nombreReporte = "controlInventario " + calendar.get(Calendar.DAY_OF_MONTH) + "-" + calendar.get(Calendar.MONTH) + " "
|
|
// + calendar.get(Calendar.HOUR_OF_DAY) + "H" + calendar.get(Calendar.MINUTE) + "M.xlsx";
|
|
return ruta.toString();
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
|
|
}
|
|
|
|
// parameters.put("fechaCorte", fechaCorteSB.toString());
|
|
// parameters.put("codArmasDecomisadasLst", actualizarArmasSeleccionadas());
|
|
|
|
public StringBuilder armarFormatoFechaSinHora(Calendar fechaCldr){
|
|
StringBuilder fechaStr= new StringBuilder();
|
|
fechaStr = fechaStr.append((fechaCldr.get(Calendar.DAY_OF_MONTH)) <= 9 ? "0" + (fechaCldr.get(Calendar.DAY_OF_MONTH)) : (fechaCldr.get(Calendar.DAY_OF_MONTH)));
|
|
fechaStr = fechaStr.append("-").append((fechaCldr.get(Calendar.MONTH)+1) <= 9 ? "0" + (fechaCldr.get(Calendar.MONTH) + 1) : (fechaCldr.get(Calendar.MONTH)+1));
|
|
fechaStr = fechaStr.append("-").append(fechaCldr.get(Calendar.YEAR));
|
|
return fechaStr;
|
|
}
|
|
|
|
public StringBuilder armarFormatoFechaConHora(Calendar fechaCldr){
|
|
StringBuilder fechaStr= new StringBuilder();
|
|
fechaStr = fechaStr.append((fechaCldr.get(Calendar.DAY_OF_MONTH)) <= 9 ? "0" + (fechaCldr.get(Calendar.DAY_OF_MONTH)) : (fechaCldr.get(Calendar.DAY_OF_MONTH)));
|
|
fechaStr = fechaStr.append("-").append((fechaCldr.get(Calendar.MONTH)+1) <= 9 ? "0" + (fechaCldr.get(Calendar.MONTH) + 1) : (fechaCldr.get(Calendar.MONTH)+1));
|
|
fechaStr = fechaStr.append("-").append(fechaCldr.get(Calendar.YEAR));
|
|
fechaStr = fechaStr.append(" ").append(fechaCldr.get(Calendar.HOUR_OF_DAY));
|
|
fechaStr = fechaStr.append(":").append((fechaCldr.get(Calendar.MINUTE)) <= 9 ? "0" + (fechaCldr.get(Calendar.MINUTE)) : (fechaCldr.get(Calendar.MINUTE)));
|
|
return fechaStr;
|
|
}
|
|
|
|
/**
|
|
* 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 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 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 TarmCentroControl getCentroControl() {
|
|
return centroControl;
|
|
}
|
|
|
|
public void setCentroControl(TarmCentroControl centroControl) {
|
|
this.centroControl = centroControl;
|
|
}
|
|
|
|
public AlfrescoController getAlfrescoController() {
|
|
return alfrescoController;
|
|
}
|
|
|
|
public void setAlfrescoController(AlfrescoController alfrescoController) {
|
|
this.alfrescoController = alfrescoController;
|
|
}
|
|
|
|
public String getxPathLocation() {
|
|
return xPathLocation;
|
|
}
|
|
|
|
public void setxPathLocation(String xPathLocation) {
|
|
this.xPathLocation = xPathLocation;
|
|
}
|
|
|
|
|
|
|
|
}
|