335 lines
11 KiB
Plaintext
Executable File
335 lines
11 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
import java.util.ArrayList;
|
|
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 javax.faces.event.AjaxBehaviorEvent;
|
|
|
|
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.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.armas.parametros.ClaseLovController;
|
|
import com.fp.frontend.controller.armas.parametros.TiposArmasExplosivosController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ParametersController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.param.TarmTipoArmaExplosivo;
|
|
import com.fp.persistence.parmas.soli.TarmArmas;
|
|
import com.fp.persistence.pgeneral.gene.TgeneParameters;
|
|
|
|
/**
|
|
* Controlador principal de armas
|
|
* @author dcruz
|
|
*
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class AuxArmasController extends AbstractController<TarmArmas> {
|
|
|
|
|
|
public AuxArmasController() throws Exception {
|
|
super(TarmArmas.class);
|
|
}
|
|
|
|
/**
|
|
* Método que se ejecuta después del constructor
|
|
*/
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
super.startQuery();
|
|
}
|
|
|
|
/**
|
|
* Inicializa valores del controlador
|
|
*/
|
|
private void init() {
|
|
try {
|
|
recperpage = 15; // Cambiar al # reg a mirar.
|
|
// record = new TarmArmas();
|
|
lrecord = new ArrayList<>();
|
|
beanalias = "ARMAS";
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
protected void querydatabaseP(String carma) {
|
|
try {
|
|
DtoQuery dto = this.getDtoQuery(true);
|
|
dto.setOrderby("pk");
|
|
//cc.addField("codigoArma", cArma);
|
|
String sqlActual = " t.codigoarma =(select p.codigoarma from TarmArmas p where p.pk = '"+carma+"')"
|
|
+ " and t.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where t.codigoarma=ta.codigoarma)"
|
|
+ " and t.estado !='DEST' "
|
|
+ " and (t.peso>0 or t.cantidad>0)";//distintas de destruidas y cambio de propietario and t.cregistro=ta.cregistro para el manejo de los explosivos
|
|
|
|
Filter filtroFinal = new Filter();
|
|
filtroFinal.setSql(sqlActual);
|
|
dto.addFiltro(filtroFinal);
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.
|
|
|
|
Request request = this.callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
request.put("queryalias", "ARMASCOMPLETE");
|
|
|
|
Response resp = this.callerhelper.executeQuery(request);
|
|
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
|
this.lrecord = new ArrayList<TarmArmas>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
this.lrecord = (List<TarmArmas>) resp.get(this.beanalias);
|
|
if(!lrecord.isEmpty()){
|
|
record=lrecord.get(0);
|
|
}
|
|
super.postQuery(this.lrecord);
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
public void save() {
|
|
}
|
|
|
|
@Override
|
|
public void update() throws Exception {
|
|
}
|
|
|
|
public void updateAutorizacion()throws Exception {
|
|
super.update();
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public void create() throws Exception {
|
|
}
|
|
|
|
|
|
/**
|
|
* Busca un arma por código
|
|
* @param armaCode
|
|
* @return
|
|
*/
|
|
public static TarmArmas findByPK(String cArma) {
|
|
try {
|
|
AuxArmasController cc = new AuxArmasController();
|
|
cc.init();
|
|
cc.recperpage = 5000;
|
|
cc.querydatabaseP(cArma);
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord.get(0);
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Busca un arma por código
|
|
* @param armaCode
|
|
* @return
|
|
*/
|
|
public static TarmArmas findXCodigo(String armaCode) {
|
|
try {
|
|
|
|
AuxArmasController cc = new AuxArmasController();
|
|
cc.init();
|
|
cc.recperpage = 5000;
|
|
cc.addFilter("pk", armaCode);
|
|
//cc.addFilter("REG", "ESTADOARMA");
|
|
cc.querydatabase();
|
|
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord.get(0);
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Lista de Armas por Registro
|
|
**/
|
|
public static List<TarmArmas> findxRegistro(String registrocode) {
|
|
try {
|
|
AuxArmasController cc = new AuxArmasController();
|
|
cc.init();
|
|
cc.recperpage = 5000;
|
|
cc.addFilter("cregistro", registrocode);
|
|
|
|
cc.querydatabase();
|
|
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
for(TarmArmas item : cc.lrecord){
|
|
TarmTipoArmaExplosivo tarmTipoArmaExplosivo = TiposArmasExplosivosController.findarma(item.getCtipoarmaexplosivo());
|
|
item.modifiedData().put("clase",CatalogDetailController.findxCodigoCodcatalogo( tarmTipoArmaExplosivo.getClase(), tarmTipoArmaExplosivo.getClasecodigo()).getDescription());
|
|
if(tarmTipoArmaExplosivo.getLongitud()!=null && tarmTipoArmaExplosivo.getLongitudcodigo()!=null){
|
|
item.modifiedData().put("longitud",CatalogDetailController.findxCodigoCodcatalogo( tarmTipoArmaExplosivo.getLongitud(), tarmTipoArmaExplosivo.getLongitudcodigo()).getDescription());
|
|
}
|
|
item.modifiedData().put("tipo",CatalogDetailController.findxCodigoCodcatalogo( tarmTipoArmaExplosivo.getTipoarmaexplosivo(), tarmTipoArmaExplosivo.getTipoarmaexplosivocodigo()).getDescription());
|
|
if(tarmTipoArmaExplosivo.getCalibre()!=null && tarmTipoArmaExplosivo.getCalibrecodigo()!=null){
|
|
item.modifiedData().put("calibre",CatalogDetailController.findxCodigoCodcatalogo( tarmTipoArmaExplosivo.getCalibre(), tarmTipoArmaExplosivo.getCalibrecodigo()).getDescription());
|
|
}
|
|
item.modifiedData().put("unidadMedidaCantidad",CatalogDetailController.findxCodigoCodcatalogo(tarmTipoArmaExplosivo.getUnidadmedidapeso(), tarmTipoArmaExplosivo.getUnidadmedidapesocodigo()).getDescription());
|
|
}
|
|
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Abre el LOV de la clase del arma
|
|
*/
|
|
public void openLovClase() {
|
|
Map<String, List<String>> params = new HashMap<String, List<String>>();
|
|
ClaseLovController.openLov(params);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 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 (TarmArmas guardias : lrecord) {
|
|
guardias.getModifiedData().put("seleccionado", valorColocar);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Metodo para obtener el listado de las armas por la serie/lote
|
|
* @param serieLote
|
|
* @return
|
|
*/
|
|
public static List<TarmArmas> findxSerieLote(String serieLote) {
|
|
try {
|
|
AuxArmasController cc = new AuxArmasController();
|
|
cc.init();
|
|
cc.recperpage = 1000;
|
|
cc.addFilter("lote", serieLote);
|
|
cc.querydatabaseFechaMax();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Metodo para obtener los codigos
|
|
*/
|
|
private static String codigos(String parametro){
|
|
TgeneParameters tgeneParameters= ParametersController.find(parametro, "1");
|
|
return tgeneParameters.getTextvalue();
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
protected void querydatabaseFechaMax() {
|
|
try {
|
|
DtoQuery dto = this.getDtoQuery(true);
|
|
dto.setOrderby("pk");
|
|
String codigoEstadoIncautada=codigos("CODIGO.INCAUTADA");
|
|
String codigoEstadoDecomisada=codigos("CODIGO.DECOMISADA");
|
|
String codigoEstadoVendida=codigos("CODIGO.VENDIDA");
|
|
String codigoEstadoMatPrima=codigos("CODIGO.MATERIAPRIMA");
|
|
Filter filtro = new Filter();
|
|
String sql="t.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where t.codigoarma=ta.codigoarma and t.cregistro=ta.cregistro)"//and t.cregistro=ta.cregistro para el manejo de los explosivos
|
|
+ " and t.estado !='DEST' and t.estado !='CDP' and t.estado !='"+codigoEstadoIncautada+"' and t.estado !='"+codigoEstadoDecomisada+"' and t.estado !='"+codigoEstadoVendida+"' and t.estado !='"+codigoEstadoMatPrima+"' ";
|
|
filtro.setSql(sql);
|
|
dto.addFiltro(filtro);
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
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<TarmArmas>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
this.lrecord = (List<TarmArmas>) resp.get(this.beanalias);
|
|
super.postQuery(this.lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Busca un arma por código
|
|
* @param armaCode
|
|
* @return
|
|
*/
|
|
public static TarmArmas findXCodigoArma(String armaCode) {
|
|
try {
|
|
AuxArmasController cc = new AuxArmasController();
|
|
cc.init();
|
|
cc.recperpage = 5000;
|
|
cc.addFilter("codigoarma", armaCode);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord.get(0);
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void querydatabase() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
|
|
}
|