235 lines
8.9 KiB
Plaintext
Executable File
235 lines
8.9 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ViewScoped;
|
|
|
|
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.pcustomer.PersonDetailController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.frontend.utility.Utilidades;
|
|
import com.fp.persistence.parmas.soli.TarmArmas;
|
|
import com.fp.persistence.parmas.soli.TarmSolicitudArmas;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
|
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class TarmSolicitudArmasController extends AbstractController<TarmSolicitudArmas> {
|
|
|
|
String csolicitud;
|
|
String aprobada;
|
|
String porDevolucion;
|
|
|
|
private List<TarmArmas> lArmas=new ArrayList<TarmArmas>();
|
|
|
|
public TarmSolicitudArmasController() throws Exception {
|
|
super(TarmSolicitudArmas.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
super.startQuery();
|
|
}
|
|
|
|
private void init() {
|
|
try {
|
|
recperpage = 100; // Cambiar al # reg a mirar.
|
|
lrecord = new ArrayList<>();
|
|
beanalias = "TARMSOLICITUDARMASCONTROLLER";
|
|
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
|
|
if (csolicitud!=null) {
|
|
dto.addFiltro(new Filter("pk.csolicitud",csolicitud));
|
|
}
|
|
|
|
if(porDevolucion!=null){
|
|
dto.addFiltro(new Filter("pordevolucion",porDevolucion));
|
|
}
|
|
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(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) {
|
|
lrecord = new ArrayList<TarmSolicitudArmas>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmSolicitudArmas>) resp.get(beanalias);
|
|
if(!lrecord.isEmpty()){
|
|
record=lrecord.get(0);
|
|
|
|
lArmas.clear();
|
|
|
|
//Obteniendo los datos de las armas
|
|
for(TarmSolicitudArmas solicitudArmas:lrecord){
|
|
TarmArmas tarmArma = new TarmArmas();
|
|
tarmArma = ArmasController.findPorCodigo(solicitudArmas.getPk().getCarma());
|
|
lArmas.add(tarmArma);
|
|
solicitudArmas.modifiedData().put("clase", tarmArma==null || tarmArma.getModifiedData().get("clase")==null?"":tarmArma.getModifiedData().get("clase"));
|
|
solicitudArmas.modifiedData().put("tipo", tarmArma==null || tarmArma.getModifiedData().get("tipo")==null?"":tarmArma.getModifiedData().get("tipo"));
|
|
solicitudArmas.modifiedData().put("calibre", tarmArma==null || tarmArma.getModifiedData().get("calibre")==null?"":Utilidades.formatearDecimalesEnTexto(tarmArma.getModifiedData().get("calibre").toString(), "#.000"));
|
|
solicitudArmas.modifiedData().put("modelo", tarmArma==null || tarmArma.getModelo()==null || tarmArma.getModelo().isEmpty()?"":tarmArma.getModelo());
|
|
solicitudArmas.modifiedData().put("marca",tarmArma==null || tarmArma.getMarca()==null || tarmArma.getMarca().isEmpty() || tarmArma.getMarcacodigo()==null || tarmArma.getMarcacodigo().isEmpty()?"":CatalogDetailController.findxCodigoCodcatalogo( tarmArma.getMarca(), tarmArma.getMarcacodigo()).getDescription());
|
|
solicitudArmas.modifiedData().put("color",tarmArma==null || tarmArma.getColor()==null || tarmArma.getColor().isEmpty() || tarmArma.getColorcodigo()==null || tarmArma.getColorcodigo().isEmpty()?"":CatalogDetailController.findxCodigoCodcatalogo( tarmArma.getColor(), tarmArma.getColorcodigo()).getDescription());
|
|
solicitudArmas.modifiedData().put("carma",tarmArma==null?"":tarmArma.getPk());
|
|
solicitudArmas.modifiedData().put("seriecannon",tarmArma==null || tarmArma.getSeriecanon()==null || tarmArma.getSeriecanon().isEmpty()?"":tarmArma.getSeriecanon());
|
|
solicitudArmas.modifiedData().put("estado", tarmArma==null || tarmArma.getEstado()==null || tarmArma.getEstado().isEmpty() || tarmArma.getEstadocodigo()==null || tarmArma.getEstadocodigo().isEmpty()?"":CatalogDetailController.findxCodigoCodcatalogo( tarmArma.getEstado(), tarmArma.getEstadocodigo()).getDescription());
|
|
solicitudArmas.modifiedData().put("cantidad",tarmArma==null || tarmArma.getCantidad()==null?"":tarmArma.getCantidad());
|
|
solicitudArmas.modifiedData().put("unidadmedida",tarmArma==null || tarmArma.getUnidadmedidacantidad()==null?"":tarmArma.getUnidadmedidacantidad());
|
|
solicitudArmas.modifiedData().put("lote",tarmArma==null || tarmArma.getLote()==null?"":tarmArma.getLote());
|
|
solicitudArmas.modifiedData().put("modelo",tarmArma==null || tarmArma.getModelo()==null?"":tarmArma.getModelo());
|
|
solicitudArmas.modifiedData().put("peso",tarmArma==null || tarmArma.getPeso()==null?"":tarmArma.getPeso());
|
|
}
|
|
|
|
|
|
}
|
|
super.postQuery(lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
private void querydatabaseCountArmas() {
|
|
try {
|
|
DtoQuery dto = super.getDtoQuery(true);
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put("TARMSOLICITUDARMASCONTROLLER", 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) {
|
|
lrecord = new ArrayList<TarmSolicitudArmas>();
|
|
MessageHelper.setMessageError(resp);
|
|
} else {
|
|
lrecord = (List<TarmSolicitudArmas>) resp.get("TARMSOLICITUDARMASCONTROLLER");
|
|
super.postQuery(lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public static List<TarmSolicitudArmas> findPorSolicitud(Integer personcode) {
|
|
try {
|
|
TarmSolicitudArmasController cc = new TarmSolicitudArmasController();
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.addFilter("personcode", personcode.toString());
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* M\u00e9todo para calcular el n\u00famero de armas de una solicitud. Recibe codigo de solicitud
|
|
* @param cSolicitud
|
|
* */
|
|
public static Integer getNumeroArmasPorSolicitud(String cSolicitud){
|
|
TarmSolicitudArmasController solicitudArmasController;
|
|
try {
|
|
solicitudArmasController = new TarmSolicitudArmasController();
|
|
solicitudArmasController.addFilter("pk.csolicitud", cSolicitud);
|
|
solicitudArmasController.setRecperpage(15000);
|
|
solicitudArmasController.querydatabaseCountArmas();
|
|
return solicitudArmasController.lrecord.size();
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* M\u00e9todo para encontrar por solicitud
|
|
* @param solicitudCode
|
|
* @return
|
|
*/
|
|
public static List<TarmSolicitudArmas> findPorCSolicitud(String solicitudCode) {
|
|
try {
|
|
TarmSolicitudArmasController cc = new TarmSolicitudArmasController();
|
|
cc.init();
|
|
cc.recperpage = 30000;
|
|
cc.addFilter("pk.csolicitud", solicitudCode);
|
|
cc.querydatabase();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
return cc.lrecord;
|
|
}
|
|
return null;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public String getCsolicitud() {
|
|
return csolicitud;
|
|
}
|
|
|
|
public void setCsolicitud(String csolicitud) {
|
|
this.csolicitud = csolicitud;
|
|
}
|
|
|
|
public String getAprobada() {
|
|
return aprobada;
|
|
}
|
|
|
|
public void setAprobada(String aprobada) {
|
|
this.aprobada = aprobada;
|
|
}
|
|
|
|
public List<TarmArmas> getlArmas() {
|
|
return lArmas;
|
|
}
|
|
|
|
public void setlArmas(List<TarmArmas> lArmas) {
|
|
this.lArmas = lArmas;
|
|
}
|
|
|
|
public String getPorDevolucion() {
|
|
return porDevolucion;
|
|
}
|
|
|
|
public void setPorDevolucion(String porDevolucion) {
|
|
this.porDevolucion = porDevolucion;
|
|
}
|
|
|
|
|
|
|
|
}
|