1716 lines
74 KiB
Plaintext
Executable File
1716 lines
74 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.parametros;
|
||
|
||
|
||
import java.io.File;
|
||
import java.io.FileInputStream;
|
||
import java.io.IOException;
|
||
import java.io.InputStream;
|
||
import java.io.OutputStream;
|
||
import java.io.PrintWriter;
|
||
import java.math.BigDecimal;
|
||
import java.util.ArrayList;
|
||
import java.util.Calendar;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.Iterator;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Map.Entry;
|
||
|
||
import javax.annotation.PostConstruct;
|
||
import javax.faces.application.FacesMessage;
|
||
import javax.faces.bean.ManagedBean;
|
||
import javax.faces.bean.ManagedProperty;
|
||
import javax.faces.bean.ViewScoped;
|
||
import javax.faces.context.FacesContext;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
import org.apache.poi.ss.usermodel.Cell;
|
||
import org.apache.poi.ss.usermodel.Row;
|
||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||
import org.primefaces.event.FileUploadEvent;
|
||
import org.primefaces.model.UploadedFile;
|
||
|
||
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.dto.query.SubQuery;
|
||
import com.fp.dto.save.DtoSave;
|
||
import com.fp.frontend.controller.AbstractController;
|
||
import com.fp.frontend.controller.armas.funcionalidad.ArmaExcell;
|
||
import com.fp.frontend.controller.armas.funcionalidad.RegistroArmController;
|
||
import com.fp.frontend.controller.armas.funcionalidad.TotalArmasController;
|
||
import com.fp.frontend.controller.armas.solicitud.ArmasController;
|
||
import com.fp.frontend.controller.armas.solicitud.DocumentoHabilitanteController;
|
||
import com.fp.frontend.controller.pcustomer.PersonAddressController;
|
||
import com.fp.frontend.controller.pcustomer.PersonDetailController;
|
||
import com.fp.frontend.controller.pgeneral.gene.CantonController;
|
||
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
||
import com.fp.frontend.controller.pgeneral.gene.CityController;
|
||
import com.fp.frontend.controller.pgeneral.gene.CountryController;
|
||
import com.fp.frontend.controller.pgeneral.gene.ProvinceController;
|
||
import com.fp.frontend.helper.MessageHelper;
|
||
import com.fp.frontend.utility.MsgControlArmas;
|
||
import com.fp.frontend.utility.Utilidades;
|
||
import com.fp.persistence.parmas.fun.TarmInventarioSubidoPorPersona;
|
||
import com.fp.persistence.parmas.fun.TarmInventarioSubidoPorPersonaKey;
|
||
import com.fp.persistence.parmas.fun.TarmRegistroArmas;
|
||
import com.fp.persistence.parmas.fun.TarmTotalPersona;
|
||
//import com.fp.persistence.parmas.param.TarmComercianteCupo;
|
||
import com.fp.persistence.parmas.param.TarmTipoArmaExplosivo;
|
||
import com.fp.persistence.parmas.param.TarmUnidadTipo;
|
||
import com.fp.persistence.parmas.soli.TarmArmas;
|
||
import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante;
|
||
import com.fp.persistence.pcustomer.gene.TcustPersonAddress;
|
||
import com.fp.persistence.pcustomer.gene.TcustPersonDetail;
|
||
import com.fp.persistence.pgeneral.gene.TgeneCanton;
|
||
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
|
||
import com.fp.persistence.pgeneral.gene.TgeneCity;
|
||
import com.fp.persistence.pgeneral.gene.TgeneCountry;
|
||
import com.fp.persistence.pgeneral.gene.TgeneProvince;
|
||
import com.fp.persistence.pgeneral.safe.TsafeUserDetail;
|
||
|
||
|
||
|
||
/**
|
||
* @author Andres Cevallos
|
||
* Clase Controladora para la entidad TarmArma
|
||
* Incluye metodo de consulta para la busqueda de persona y registro
|
||
*/
|
||
@SuppressWarnings("serial")
|
||
@ManagedBean
|
||
@ViewScoped
|
||
public class IngresoInventarioController extends AbstractController<TarmArmas> {
|
||
|
||
//Variabgles globales
|
||
private Integer personcode;
|
||
|
||
private Boolean descargar;
|
||
private String csolicitud;
|
||
InputStream filei;
|
||
|
||
//Datos generales
|
||
private TgeneCatalogDetail tipoDocumento;
|
||
private TcustPersonDetail detallesPersona;
|
||
|
||
Date fechaActual;
|
||
private List<TgeneCatalogDetail> tiposRegistro;
|
||
private TgeneCatalogDetail tipoRegistro;
|
||
|
||
//Detalle del material
|
||
//Pais
|
||
private List<TgeneCountry> lpaises;
|
||
private TgeneCountry pais;
|
||
//private String pais;
|
||
|
||
//Provincia
|
||
private List<TgeneProvince> lprovincias;
|
||
private String codigoProvincia;
|
||
|
||
//Canton
|
||
private List<TgeneCanton> lcantones;
|
||
private String codigoCanton;
|
||
|
||
//Ciudad
|
||
private List<TgeneCity> lciudades;
|
||
private TgeneCity ciudad;
|
||
|
||
//Registro armas
|
||
TarmRegistroArmas registro=new TarmRegistroArmas();
|
||
|
||
//Variables de las armas
|
||
private TcustPersonDetail usuario;
|
||
private TcustPersonAddress direccion;
|
||
private List<Row> listaFilas;
|
||
private List<String> listaErrores;
|
||
// private List<TarmComercianteCupo> cuposArmas;
|
||
|
||
//private BigDecimal pesoTotal;
|
||
private TarmTipoArmaExplosivo tipoArmaExplosivo;
|
||
private List<ArmaExcell> listaArmas;
|
||
private ArmaExcell armaexcell;
|
||
|
||
private List<ArmaExcell> laexel;
|
||
private List<TarmArmas> armas=new ArrayList<TarmArmas>();
|
||
private List<TarmTotalPersona> totalesPersoan=new ArrayList<TarmTotalPersona>();
|
||
|
||
//Aeropuertos
|
||
List<TgeneCatalogDetail> laeropuertos=new ArrayList<>();
|
||
|
||
@ManagedProperty(value = "#{personAddressController}")
|
||
private PersonAddressController personAddressController;
|
||
|
||
// @ManagedProperty(value = "#{comercianteCupoController}")
|
||
// private ComercianteCupoController comercianteCupoController;
|
||
|
||
@ManagedProperty(value = "#{registroArmController}")
|
||
private RegistroArmController registroArmasController;
|
||
|
||
@ManagedProperty(value = "#{totalArmasController}")
|
||
private TotalArmasController totalPersonaController;
|
||
|
||
@ManagedProperty(value = "#{inventarioSubidoController}")
|
||
private InventarioSubidoController inventarioSubidoController;
|
||
|
||
private List<TarmDocumentoHabilitante> ldocumentospersona;
|
||
|
||
private String clase;
|
||
public IngresoInventarioController() throws Exception {
|
||
super(TarmArmas.class);
|
||
}
|
||
|
||
/**
|
||
* Metodo invocado despues de instanciar el controlador
|
||
*/
|
||
@PostConstruct
|
||
private void postconstruct() {
|
||
this.init();
|
||
// Inicializa autoconsulta
|
||
super.startQuery();
|
||
}
|
||
|
||
/**
|
||
* Incializa variables del controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
||
*/
|
||
private void init() {
|
||
try {
|
||
this.recperpage = 15; // Cambiar al # reg a mirar.
|
||
this.lrecord = new ArrayList<>();
|
||
this.record=new TarmArmas();
|
||
this.beanalias = "ARMAS";
|
||
this.create();
|
||
|
||
//Globales
|
||
descargar=false;
|
||
csolicitud=null;
|
||
|
||
//Datos generales
|
||
//Obteniendo los datos del usuario logueado
|
||
TsafeUserDetail tsafeUserDetail=(TsafeUserDetail)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TSAFEUSERDETAIL");
|
||
usuario=PersonDetailController.find(tsafeUserDetail.getPk().getPersoncode().toString());
|
||
|
||
//Obteniendo los datos de la persona
|
||
detallesPersona= PersonDetailController.find(String.valueOf(usuario.getPk().getPersoncode()));
|
||
|
||
//Tipo de documento
|
||
tipoDocumento = CatalogDetailController.findxCodigoCodcatalogo(detallesPersona.getIdentificationcatalog(),detallesPersona.getIdentificationcatalogcode());
|
||
|
||
//Fecha actual
|
||
this.fechaActual=Calendar.getInstance().getTime();
|
||
|
||
//Tipos de registro
|
||
List<TgeneCatalogDetail>tiposRegistroAux = CatalogDetailController.find("TIPOREGISTRO", "REG");
|
||
tiposRegistro = new ArrayList<TgeneCatalogDetail>();
|
||
for(TgeneCatalogDetail tipoReg : tiposRegistroAux){
|
||
if(tipoReg.getPk().getCatalog().equalsIgnoreCase("PRO")){
|
||
tiposRegistro.add(tipoReg);
|
||
}
|
||
}
|
||
|
||
//Detalle del material
|
||
lpaises=CountryController.find();
|
||
registro.setFechasolicitud(new java.sql.Date((new Date()).getTime()));
|
||
|
||
//Obteniendo la direccion de la persona
|
||
String tipoDireccion="";
|
||
|
||
if(detallesPersona!=null){
|
||
switch(detallesPersona.getIdentificationcatalog()){
|
||
case "CED":
|
||
tipoDireccion = "1";
|
||
break;
|
||
case "RUC":
|
||
tipoDireccion= "2";
|
||
break;
|
||
default:
|
||
tipoDireccion= "";
|
||
break;
|
||
}
|
||
}
|
||
//direccion= personAddressController.findByPersonCode(usuario.getPk().getPersoncode().toString());
|
||
direccion= personAddressController.findPrincipal(String.valueOf(usuario.getPk().getPersoncode().toString())) ;
|
||
|
||
|
||
//Imprtacion
|
||
this.lprovincias=ProvinceController.find("EC");
|
||
|
||
//Armas
|
||
listaErrores = new ArrayList<String>();
|
||
|
||
//Controlador de totales
|
||
// this.totalPersonaController=new TotalPersonaController();
|
||
// this.totalPersonaController.create();
|
||
// this.totalPersonaController.setLrecord(new ArrayList<TarmTotalPersona>());
|
||
|
||
RegistroArmController registroArmas = new RegistroArmController();
|
||
registroArmas.init();
|
||
registroArmas.setRecperpage(3000000);
|
||
registroArmas.addFilter("personcode", tsafeUserDetail.getPk().getPersoncode().toString());
|
||
registroArmas.query();
|
||
this.addFilter("estado", "REG");
|
||
filtro(registroArmas.getLrecord());
|
||
|
||
//Obteniendo los aeropuertos
|
||
this.laeropuertos=CatalogDetailController.find("AEROPUERTOS");
|
||
|
||
} catch (Exception e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
/* (non-Javadoc)
|
||
* @see com.fp.frontend.controller.AbstractController#querydatabase()
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@Override
|
||
public void querydatabase() {
|
||
try {
|
||
|
||
DtoQuery dto = super.getDtoQuery(true);
|
||
SubQuery subqueryMarca= new SubQuery("TgeneCatalogDetail","description","marca","i.pk.catalog=t.marca and i.pk.catalogcode=t.marcacodigo");
|
||
dto.addSubQuery(subqueryMarca);
|
||
SubQuery subqueryColor= new SubQuery("TgeneCatalogDetail","description","color","i.pk.catalog=t.color and i.pk.catalogcode=t.colorcodigo");
|
||
dto.addSubQuery(subqueryColor);
|
||
SubQuery subqueryEstado= new SubQuery("TgeneCatalogDetail","description","estado","i.pk.catalog=t.estado and i.pk.catalogcode=t.estadocodigo");
|
||
dto.addSubQuery(subqueryEstado);
|
||
SubQuery subqueryClase= new SubQuery("TarmTipoArmaExplosivo","clase","cclase","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryClase);
|
||
SubQuery subqueryClaseCodigo= new SubQuery("TarmTipoArmaExplosivo","clasecodigo","cclasecodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryClaseCodigo);
|
||
SubQuery subqueryLongitud= new SubQuery("TarmTipoArmaExplosivo","longitud","clongitud","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryLongitud);
|
||
SubQuery subqueryLongitudCodigo= new SubQuery("TarmTipoArmaExplosivo","longitudcodigo","clongitudcodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryLongitudCodigo);
|
||
SubQuery subqueryCalibre= new SubQuery("TarmTipoArmaExplosivo","calibre","ccalibre","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryCalibre);
|
||
SubQuery subqueryCalibreCodigo= new SubQuery("TarmTipoArmaExplosivo","calibrecodigo","ccalibrecodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryCalibreCodigo);
|
||
SubQuery subqueryTipoArma= new SubQuery("TarmTipoArmaExplosivo","tipoarmaexplosivo","ctipoarmaexplosivo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryTipoArma);
|
||
SubQuery subqueryTipoArmaCodigo= new SubQuery("TarmTipoArmaExplosivo","tipoarmaexplosivocodigo","ctipoarmaexplosivocodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryTipoArmaCodigo);
|
||
SubQuery subqueryUnidad= new SubQuery("TarmTipoArmaExplosivo","unidadmedidapeso","cunidadmedidapeso","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryUnidad);
|
||
SubQuery subqueryUnidadCodigo= new SubQuery("TarmTipoArmaExplosivo","unidadmedidapesocodigo","cunidadmedidapesocodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryUnidadCodigo);
|
||
|
||
Filter filtrofecha=new Filter();
|
||
filtrofecha.setSql("t.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where t.codigoarma=ta.codigoarma and t.cregistro=ta.cregistro) and t.estado !='DEST' and t.estado !='CDP'");
|
||
dto.addFiltro(filtrofecha);
|
||
dto.setOrderby("pk");
|
||
String sql=csolicitud;
|
||
if(csolicitud!=null){
|
||
Filter filtro = new Filter();
|
||
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);
|
||
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);
|
||
}
|
||
}
|
||
|
||
/* (non-Javadoc)
|
||
* @see com.fp.frontend.controller.AbstractController#querydatabase()
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
public void querydatabaseMarcaSerie(String cregistro,String marca, String serie) {
|
||
try {
|
||
|
||
DtoQuery dto = super.getDtoQuery(true);
|
||
SubQuery subqueryMarca= new SubQuery("TgeneCatalogDetail","description","marca","i.pk.catalog=t.marca and i.pk.catalogcode=t.marcacodigo");
|
||
dto.addSubQuery(subqueryMarca);
|
||
SubQuery subqueryColor= new SubQuery("TgeneCatalogDetail","description","color","i.pk.catalog=t.color and i.pk.catalogcode=t.colorcodigo");
|
||
dto.addSubQuery(subqueryColor);
|
||
SubQuery subqueryEstado= new SubQuery("TgeneCatalogDetail","description","estado","i.pk.catalog=t.estado and i.pk.catalogcode=t.estadocodigo");
|
||
dto.addSubQuery(subqueryEstado);
|
||
SubQuery subqueryClase= new SubQuery("TarmTipoArmaExplosivo","clase","cclase","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryClase);
|
||
SubQuery subqueryClaseCodigo= new SubQuery("TarmTipoArmaExplosivo","clasecodigo","cclasecodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryClaseCodigo);
|
||
SubQuery subqueryLongitud= new SubQuery("TarmTipoArmaExplosivo","longitud","clongitud","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryLongitud);
|
||
SubQuery subqueryLongitudCodigo= new SubQuery("TarmTipoArmaExplosivo","longitudcodigo","clongitudcodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryLongitudCodigo);
|
||
SubQuery subqueryCalibre= new SubQuery("TarmTipoArmaExplosivo","calibre","ccalibre","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryCalibre);
|
||
SubQuery subqueryCalibreCodigo= new SubQuery("TarmTipoArmaExplosivo","calibrecodigo","ccalibrecodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryCalibreCodigo);
|
||
SubQuery subqueryTipoArma= new SubQuery("TarmTipoArmaExplosivo","tipoarmaexplosivo","ctipoarmaexplosivo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryTipoArma);
|
||
SubQuery subqueryTipoArmaCodigo= new SubQuery("TarmTipoArmaExplosivo","tipoarmaexplosivocodigo","ctipoarmaexplosivocodigo","i.pk=t.ctipoarmaexplosivo");// and i.clase='" + clase + "' and i.tipoarmaexplosivo='" + tipoArmaExplosivo + "'");
|
||
dto.addSubQuery(subqueryTipoArmaCodigo);
|
||
SubQuery subqueryUnidad= new SubQuery("TarmTipoArmaExplosivo","unidadmedidapeso","cunidadmedidapeso","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryUnidad);
|
||
SubQuery subqueryUnidadCodigo= new SubQuery("TarmTipoArmaExplosivo","unidadmedidapesocodigo","cunidadmedidapesocodigo","i.pk=t.ctipoarmaexplosivo");
|
||
dto.addSubQuery(subqueryUnidadCodigo);
|
||
|
||
|
||
Filter filtrofecha=new Filter();
|
||
filtrofecha.setSql("t.fecharegistro=(select max(ta.fecharegistro) from TarmArmas ta where t.codigoarma=ta.codigoarma and t.cregistro=ta.cregistro) "
|
||
+ " and t.estado !='DEST' and t.estado !='CDP' and t.lote " + (serie==null?" is null":("= '" + serie + "'")) + " and t.cregistro= '"
|
||
+ cregistro + "' and t.marca " + (marca==null?" is null":("= '" + marca + "'")));
|
||
dto.addFiltro(filtrofecha);
|
||
dto.setOrderby("pk");
|
||
/* String sql=csolicitud;
|
||
if(csolicitud!=null){
|
||
Filter filtro = new Filter();
|
||
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);
|
||
request.put("queryalias", "ARMASCOMPLETE");*/
|
||
|
||
Request request = 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);
|
||
if(!lrecord.isEmpty()){
|
||
record=lrecord.get(0);
|
||
}
|
||
super.postQuery(this.lrecord);
|
||
}
|
||
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
@SuppressWarnings("unchecOked")
|
||
protected void querydatabaseSimple() {
|
||
try {
|
||
DtoQuery dto = super.getDtoQuery(true);
|
||
|
||
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
||
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
|
||
|
||
//se discrima las armas que sean distintas de destruidas y cambio de propietario
|
||
Filter filtro = new Filter();
|
||
String sql=" t.estado !='DEST' and t.estado !='CDP'";
|
||
filtro.setSql(sql);
|
||
dto.addFiltro(filtro);
|
||
|
||
Request request = callerhelper.getRequest();
|
||
request.setQueryTables(mtables);
|
||
|
||
Response resp = callerhelper.executeQuery(request);
|
||
|
||
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
|
||
lrecord = new ArrayList<TarmArmas>();
|
||
MessageHelper.setMessageError(resp);
|
||
} else {
|
||
lrecord = (List<TarmArmas>) resp.get(beanalias);
|
||
if(!lrecord.isEmpty()){
|
||
record=lrecord.get(0);
|
||
}
|
||
super.postQuery(lrecord);
|
||
}
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Metodo para armar el registro
|
||
* @param lsolicitud
|
||
*/
|
||
public void filtro(List<TarmRegistroArmas> lsolicitud){
|
||
|
||
for(TarmRegistroArmas soli : lsolicitud){
|
||
if(csolicitud==null){
|
||
csolicitud="(cregistro="+soli.getPk();
|
||
}
|
||
else{
|
||
csolicitud+=" or cregistro="+soli.getPk();
|
||
}
|
||
}
|
||
csolicitud+=")";
|
||
|
||
}
|
||
|
||
/* (non-Javadoc)
|
||
* @see com.fp.frontend.controller.AbstractController#save()
|
||
*/
|
||
@Override
|
||
public void save(){
|
||
try {
|
||
Request request = this.callerhelper.getRequest();
|
||
|
||
DtoSave dtosave = super.getDtoSave(true);
|
||
dtosave.setPosition(2);
|
||
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
||
msave.put(this.beanalias, dtosave);
|
||
|
||
registroArmasController.clearAll();
|
||
DtoSave dtosaveregistroarma = registroArmasController.getDtoSave(true);
|
||
dtosaveregistroarma.setPosition(1);
|
||
msave.put(registroArmasController.getBeanalias(), dtosaveregistroarma);
|
||
|
||
totalPersonaController.clearAll();
|
||
DtoSave dtosavetotalper = totalPersonaController.getDtoSave(true);
|
||
dtosavetotalper.setPosition(3);
|
||
msave.put(totalPersonaController.getBeanalias(), dtosavetotalper);
|
||
|
||
DtoSave dtoInventarioSubido = inventarioSubidoController.getDtoSave(true);
|
||
dtoInventarioSubido.setPosition(4);
|
||
msave.put(inventarioSubidoController.getBeanalias(), dtoInventarioSubido);
|
||
|
||
request.setSaveTables(msave);
|
||
request.getModifiedData().put("LISTAARMAS", this.armas);
|
||
request.getModifiedData().put("LISTATOTALES", this.totalesPersoan);
|
||
request.getModifiedData().put("REGISTRO", this.registro);
|
||
|
||
Response resp = this.callerhelper.executeSave(request);
|
||
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
||
this.postCommit(resp);
|
||
this.registroArmasController.postCommit(resp);
|
||
this.totalPersonaController.postCommit(resp);
|
||
this.inventarioSubidoController.postCommit(resp);
|
||
//this.totalPersonaController.postCommit(resp);
|
||
MessageHelper.setMessageInfo(resp);
|
||
} else {
|
||
MessageHelper.setMessageError(resp);
|
||
}
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void postCommit(Response response) throws Exception {
|
||
super.postCommitGeneric(response, beanalias);
|
||
}
|
||
|
||
|
||
/**
|
||
* Metodo que carga y valida el contenido de un archivo excel con información de armas
|
||
* @param event
|
||
*/
|
||
public void cargarArchivo(FileUploadEvent event){
|
||
|
||
HashMap<String, TarmTotalPersona> mapaTotalesTemporales = new HashMap<>();
|
||
int f1=0;
|
||
try {
|
||
// Verifico si ya se hizo una carga de inventario previa para al clase seleccionada
|
||
List<TarmInventarioSubidoPorPersona> inventarioPrevioIngresadoLst = InventarioSubidoController.findXPersonaYClase(this.usuario.getPk().getPersoncode().toString(), clase);
|
||
if(inventarioPrevioIngresadoLst!=null){
|
||
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_inventarioCargadoPreviamente"));
|
||
return;
|
||
}else{
|
||
TarmInventarioSubidoPorPersonaKey pkInventarioSubidoObj = new TarmInventarioSubidoPorPersonaKey();
|
||
pkInventarioSubidoObj.setPersoncode(this.usuario.getPk().getPersoncode());
|
||
pkInventarioSubidoObj.setClase(clase);
|
||
TarmInventarioSubidoPorPersona inventarioSubidoObj = new TarmInventarioSubidoPorPersona();
|
||
inventarioSubidoObj.setPk(pkInventarioSubidoObj);
|
||
java.util.Date today = new java.util.Date();
|
||
java.sql.Timestamp fechaReporte = new java.sql.Timestamp(today.getTime());
|
||
inventarioSubidoObj.setFechacarga(fechaReporte);
|
||
inventarioSubidoObj.setIsnew(Boolean.TRUE);
|
||
inventarioSubidoController.update(inventarioSubidoObj);
|
||
}
|
||
|
||
//Completando los datos del registro
|
||
this.registro.setPersoncode(this.usuario.getPk().getPersoncode());
|
||
this.registro.setTiporegistrocodigo("TIPOREGISTRO");
|
||
this.registro.setFechasolicitud(new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
|
||
//Inicializando las listas
|
||
listaFilas=new ArrayList<Row>();
|
||
listaArmas= new ArrayList<ArmaExcell>();
|
||
listaErrores= new ArrayList<String>();
|
||
//caraga el excel
|
||
UploadedFile selectedFile = event.getFile();
|
||
InputStream archivo=selectedFile.getInputstream();
|
||
XSSFWorkbook libro = new XSSFWorkbook(archivo);
|
||
XSSFSheet hoja = libro.getSheetAt(0);
|
||
//Iterando sobre las filas
|
||
int cont=0;
|
||
Iterator<Row> rowIterator = hoja.iterator();
|
||
//Cargando el contenido de las celdas a una lista de objetos
|
||
while(rowIterator.hasNext()) {
|
||
cont++;
|
||
Row row = rowIterator.next();
|
||
if(cont>1){
|
||
Cell numero=row.getCell(0);
|
||
Cell serie=row.getCell(1);
|
||
Cell clase=row.getCell(2);
|
||
Cell longitud=row.getCell(3);
|
||
Cell tipo=row.getCell(4);
|
||
Cell calibre=row.getCell(5);
|
||
Cell color=row.getCell(6);
|
||
Cell marca=row.getCell(7);
|
||
Cell cantidad=row.getCell(8);
|
||
Cell umcantidad=row.getCell(9);
|
||
Cell peso=row.getCell(10);
|
||
Cell umpeso=row.getCell(11);
|
||
Boolean filaEnBlanco=false;
|
||
if(this.celdaVacia(numero) && this.celdaVacia(serie) && this.celdaVacia(clase)
|
||
&& this.celdaVacia(longitud) && this.celdaVacia(tipo) && this.celdaVacia(calibre)
|
||
&& this.celdaVacia(color) && this.celdaVacia(marca) && this.celdaVacia(cantidad)
|
||
&& this.celdaVacia(umcantidad) && this.celdaVacia(peso) && this.celdaVacia(umpeso)){
|
||
filaEnBlanco=true;
|
||
}else{
|
||
listaFilas.add(row);
|
||
}
|
||
if(!filaEnBlanco){
|
||
//arma la lista de las armas en un dto aniade en la lista listaArmas
|
||
armarlistaArmasExcel(numero, serie, clase, longitud, tipo, calibre, color, marca, cantidad, umcantidad, peso, umpeso, row);
|
||
}
|
||
}
|
||
}
|
||
//Verificando las filas duplicadas en el archivo
|
||
verificarFilasDuplicadas(listaArmas);
|
||
if(this.registro.getTiporegistro().equals("PRO")){
|
||
//Verificando las filas duplicadas en la BD
|
||
verificarArmasExistentesEnBaseDeDatos(listaArmas, this.usuario.getPk().getPersoncode());
|
||
}
|
||
Boolean contieneSerie=false;
|
||
//RECORRE LA LISTA DE LAS ARMAS y valida el CUPO DEL ARMA
|
||
//Validando los campos requeridos que estan vacios
|
||
recorreListaArmasExcel(contieneSerie,f1,mapaTotalesTemporales);
|
||
//Seteando los atributos de las armas y totales si no hay ningun error
|
||
if(listaErrores.isEmpty()){
|
||
for (int i = 0; i < listaArmas.size(); i++) {
|
||
if(!listaArmas.get(i).getCamposIncompletos() && !listaArmas.get(i).getDuplicada() && listaArmas.get(i).getExisteCatalogo()
|
||
&& listaArmas.get(i).getExisteTARMTIPOARMAEXPLOSIVO()){ //&& !listaArmas.get(i).getCupoInsuficiente()
|
||
//Marca
|
||
if(listaArmas.get(i).getCatalogoMarca()!=null){
|
||
listaArmas.get(i).getArma().setMarcacodigo("MARCA");
|
||
listaArmas.get(i).getArma().setMarca(listaArmas.get(i).getCatalogoMarca().getPk().getCatalog());
|
||
}
|
||
//Color
|
||
if(listaArmas.get(i).getCatalogoColor()!=null){
|
||
listaArmas.get(i).getArma().setColorcodigo("COLOR");
|
||
listaArmas.get(i).getArma().setColor(listaArmas.get(i).getCatalogoColor().getPk().getCatalog());
|
||
}
|
||
//Unidad medida cantidad
|
||
if(listaArmas.get(i).getTipoArmaExplosivo()!=null){
|
||
listaArmas.get(i).getArma().setUnidadmedidacantidadcodigo("UNIDADMEDIDA");
|
||
Double doubleNum=0.0;
|
||
//Cargando el catalodo del tipo de unidad de medida
|
||
if(listaArmas.get(i).getUnidadMedidaCantidad()!=null && !listaArmas.get(i).getUnidadMedidaCantidad().isEmpty()){
|
||
listaArmas.get(i).getArma().setUnidadmedidacantidad(listaArmas.get(i).getUnidadMedidaCantidad());
|
||
doubleNum=Double.parseDouble(listaArmas.get(i).getTextoCantidad());
|
||
//Cantidad
|
||
Integer intNum=(int)doubleNum.doubleValue();
|
||
listaArmas.get(i).getArma().setCantidad(intNum);
|
||
}else if(listaArmas.get(i).getUnidadMedidaPeso()!=null && !listaArmas.get(i).getUnidadMedidaPeso().isEmpty()){
|
||
listaArmas.get(i).getArma().setUnidadmedidacantidad(listaArmas.get(i).getUnidadMedidaPeso());
|
||
doubleNum=Double.parseDouble(listaArmas.get(i).getTextoPeso());
|
||
//Peso
|
||
listaArmas.get(i).getArma().setPeso(new BigDecimal(doubleNum));
|
||
}
|
||
}
|
||
//Estado DEL ARMA
|
||
listaArmas.get(i).getArma().setEstado("REG");
|
||
listaArmas.get(i).getArma().setEstadocodigo("ESTADOARMA");
|
||
if(direccion!=null){
|
||
//Codigo de pais
|
||
listaArmas.get(i).getArma().setCountrycode(direccion.getCountrycode());
|
||
//Codigo de provincia
|
||
listaArmas.get(i).getArma().setProvincecode(direccion.getProvincecode());
|
||
//Codigo de canton
|
||
listaArmas.get(i).getArma().setCantoncode(direccion.getCantoncode());
|
||
//Codigo de parroquia
|
||
listaArmas.get(i).getArma().setParroquiacode(direccion.getParroquiacode());
|
||
//Codigo de ciudad
|
||
listaArmas.get(i).getArma().setCitycode(direccion.getCitycode());
|
||
}
|
||
//Lote
|
||
listaArmas.get(i).getArma().setLote(listaArmas.get(i).getSerie());
|
||
//Peso
|
||
if(listaArmas.get(i).getTextoPeso()!=null && !listaArmas.get(i).getTextoPeso().isEmpty()){
|
||
listaArmas.get(i).getArma().setPeso(BigDecimal.valueOf(Double.parseDouble(listaArmas.get(i).getTextoPeso())));
|
||
}
|
||
//Direccion
|
||
listaArmas.get(i).getArma().setDireccion(direccion.getAddress());
|
||
|
||
//Fecha de registro
|
||
listaArmas.get(i).getArma().setFecharegistro(new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
|
||
|
||
//Tipo de arma explosivo
|
||
if(listaArmas.get(i).getTipoArmaExplosivo()!=null){
|
||
listaArmas.get(i).getArma().setCtipoarmaexplosivo(listaArmas.get(i).getTipoArmaExplosivo().getPk());
|
||
}
|
||
armas.add(listaArmas.get(i).getArma());
|
||
}
|
||
}
|
||
//Se rrecorre el mapa HashMap<String, TarmTotalPersona> mapaTotalesTemporales
|
||
for (TarmTotalPersona value : mapaTotalesTemporales.values()) {
|
||
totalesPersoan.add(value);
|
||
}
|
||
save();
|
||
}
|
||
} catch (Exception e) {
|
||
MessageHelper.setMessageError(e);
|
||
}finally{
|
||
if (!listaErrores.isEmpty()) {
|
||
listaArmas.clear();
|
||
MessageHelper.setMessageError("ERRORES ENCONTRADOS DENTRO DEL ARCHIVO EXCEL: ");// + errores.toString());
|
||
descargar=true;
|
||
}else{
|
||
MessageHelper.setMessageInfo("ARCHIVO CARGADO EXITOSAMENTE");
|
||
descargar=false;
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* Metodo para cargar los valores del EXCEL EN UNA CLASE DTO(ArmaExcell )
|
||
* @param numero * @param serie * @param clase * @param longitud * @param tipo * @param calibre
|
||
* @param color * @param marca * @param cantidad * @param umcantidad * @param peso * @param umpeso * @param row
|
||
*/
|
||
public void armarlistaArmasExcel(Cell numero,Cell serie,Cell clase,Cell longitud,Cell tipo,Cell calibre,Cell color,Cell marca,
|
||
Cell cantidad,Cell umcantidad,Cell peso,Cell umpeso,Row row){
|
||
ArmaExcell arma=new ArmaExcell();
|
||
arma.setTextoNumero(Utilidades.setearValorCelda(numero));//Numero
|
||
arma.setSerie(Utilidades.setearValorCelda(serie));//Serie
|
||
arma.setClase(Utilidades.setearValorCelda(clase));//Clase
|
||
arma.setLongitud(Utilidades.setearValorCelda(longitud));//Longitud
|
||
arma.setTipo(Utilidades.setearValorCelda(tipo));//Tipo
|
||
arma.setCalibre(Utilidades.setearValorCelda(calibre));//Calibre
|
||
arma.setColor(Utilidades.setearValorCelda(color));//Color
|
||
arma.setMarca(Utilidades.setearValorCelda(marca));//Marca
|
||
arma.setTextoCantidad(Utilidades.setearValorCelda(cantidad));//Cantidad
|
||
arma.setUnidadMedidaCantidad(Utilidades.setearValorCelda(umcantidad));//U. Medida Cantidad
|
||
arma.setTextoPeso(Utilidades.setearValorCelda(peso));//Peso
|
||
arma.setUnidadMedidaPeso(Utilidades.setearValorCelda(umpeso));//U. Medida Peso
|
||
|
||
// El ingreso de inventario sera para todas las clases excepto armas de fuego y armas no letales
|
||
if(!arma.getClase().equalsIgnoreCase("ARMA DE FUEGO") && !arma.getClase().equalsIgnoreCase("ARMAS NO LETALES")){
|
||
listaArmas.add(arma);
|
||
}else {
|
||
listaErrores.add("Fila "+row.getRowNum()+": "+"Columna clase: "+MsgControlArmas.getProperty("msg_inventarioNoArmasFuegoNiNoLetales"));
|
||
return;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Metodo que verifica si existen filas duplicadas en el archivo de excell
|
||
* @param listaArmas
|
||
*/
|
||
private void verificarFilasDuplicadas(List<ArmaExcell> listaArmas){
|
||
for (int i = 0; i < listaArmas.size()-1; i++) {
|
||
for (int j = i+1; j < listaArmas.size(); j++) {
|
||
if(!this.registro.getTiporegistro().equalsIgnoreCase("IMP") && ((listaArmas.get(i).getSerie().equalsIgnoreCase(listaArmas.get(j).getSerie()))
|
||
&& listaArmas.get(i).getClase().equalsIgnoreCase(listaArmas.get(j).getClase())
|
||
&& listaArmas.get(i).getTipo().equalsIgnoreCase(listaArmas.get(j).getTipo())
|
||
&& (!listaArmas.get(i).getClase().toLowerCase().equalsIgnoreCase("arma de fuego")
|
||
|| (listaArmas.get(i).getClase().toLowerCase().equalsIgnoreCase("arma de fuego") && listaArmas.get(j).getClase().toLowerCase().equalsIgnoreCase("arma de fuego"))
|
||
&& listaArmas.get(i).getCalibre().equalsIgnoreCase(listaArmas.get(j).getCalibre()))
|
||
&& listaArmas.get(i).getMarca().equalsIgnoreCase(listaArmas.get(j).getMarca()))){
|
||
listaArmas.get(j).setDuplicada(true);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @param listaArmas
|
||
* @throws Exception
|
||
*/
|
||
@SuppressWarnings("static-access")
|
||
private void verificarArmasExistentesEnBaseDeDatos(List<ArmaExcell> listaArmas, Integer codigoPersona) throws Exception{
|
||
TgeneCatalogDetail codigoClase = new TgeneCatalogDetail();
|
||
TgeneCatalogDetail codigoMarca = new TgeneCatalogDetail();
|
||
TgeneCatalogDetail codigoTipo = new TgeneCatalogDetail();
|
||
TgeneCatalogDetail codigoCalibre = new TgeneCatalogDetail();
|
||
String codigoSerie;
|
||
List<TarmRegistroArmas> lstRegistroArmas = registroArmasController.findxPersoncode(String.valueOf(codigoPersona));
|
||
if(lstRegistroArmas==null || listaArmas==null || lstRegistroArmas.isEmpty() || listaArmas.isEmpty()){
|
||
return;
|
||
}
|
||
for (int i = 0; i < listaArmas.size(); i++) {
|
||
codigoClase=CatalogDetailController.findByCatalogcodeDescrption("CLASE", listaArmas.get(i).getClase());
|
||
codigoTipo=CatalogDetailController.findByCatalogcodeDescrption("TIPOARMAEXPLOSIVO", listaArmas.get(i).getTipo());
|
||
codigoMarca=CatalogDetailController.findByCatalogcodeDescrption("MARCA", listaArmas.get(i).getMarca());
|
||
codigoSerie = this.registro.getTiporegistro().equalsIgnoreCase("IMP")?null:listaArmas.get(i).getSerie();
|
||
codigoCalibre=listaArmas.get(i).getClase().toLowerCase().equalsIgnoreCase("arma de fuego")?CatalogDetailController.findByCatalogcodeDescrption("CALIBRE",listaArmas.get(i).getCalibre()):null;
|
||
|
||
if((codigoClase==null && (listaArmas.get(i).getClase()!=null && !listaArmas.get(i).getClase().trim().isEmpty())) || (codigoTipo==null && (listaArmas.get(i).getTipo()!=null && !listaArmas.get(i).getTipo().trim().isEmpty()))
|
||
|| (codigoMarca==null && (listaArmas.get(i).getMarca()!=null && !listaArmas.get(i).getMarca().trim().isEmpty())) || (codigoSerie==null && (listaArmas.get(i).getSerie()!=null && !listaArmas.get(i).getSerie().trim().isEmpty()))
|
||
|| (codigoCalibre==null && (listaArmas.get(i).getCalibre()!=null && !listaArmas.get(i).getCalibre().trim().isEmpty()))
|
||
|| listaArmas.get(i).getClase()==null || listaArmas.get(i).getMarca()==null || listaArmas.get(i).getCalibre()==null
|
||
|| listaArmas.get(i).getClase().isEmpty() || listaArmas.get(i).getMarca().isEmpty() || listaArmas.get(i).getCalibre().isEmpty()){
|
||
continue;
|
||
}
|
||
for(TarmRegistroArmas registroArmas :lstRegistroArmas){
|
||
List<TarmArmas> lstArmasEncontradas = findByMarcaSerie(String.valueOf(registroArmas.getPk()),codigoMarca.getPk().getCatalog(), codigoSerie);
|
||
if(lstArmasEncontradas!=null){
|
||
for(TarmArmas armas:lstArmasEncontradas){
|
||
TarmTipoArmaExplosivo tipoArma = TiposArmasExplosivosController.findarma(armas.getCtipoarmaexplosivo());
|
||
if(tipoArma.getClase().equalsIgnoreCase(codigoClase.getPk().getCatalog()) && codigoCalibre!=null?tipoArma.getCalibre().equalsIgnoreCase(codigoCalibre.getPk().getCatalog()):true && tipoArma.getTipoarmaexplosivo().equalsIgnoreCase(codigoTipo.getPk().getCatalog())){
|
||
listaArmas.get(i).setDuplicada(true);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* Metodo que recorre la lista de las armas con los valores cargados del EXCEL
|
||
* @param contieneSerie
|
||
* @param f1
|
||
* @param mapaTotalesTemporales
|
||
*/
|
||
public void recorreListaArmasExcel(Boolean contieneSerie, int f1,HashMap<String, TarmTotalPersona> mapaTotalesTemporales){
|
||
for (int i = 0; i < listaArmas.size(); i++) {
|
||
Integer fila=i+1;
|
||
f1=i;
|
||
Boolean campoCantidad=false;
|
||
//0-Datos duplicados
|
||
if(listaArmas.get(i).getDuplicada()){
|
||
listaErrores.add("Fila "+fila.toString()+": "+MsgControlArmas.getProperty("msg_datosDuplicados"));
|
||
}
|
||
//1-Serie
|
||
//Validando que si el tipo de registro es de importacion
|
||
//las armas no contengan numero de serie
|
||
if(this.registro.getTiporegistro().equalsIgnoreCase("IMP") && (listaArmas.get(i).getSerie()!=null) && !contieneSerie){
|
||
contieneSerie=true;
|
||
listaErrores.add(MsgControlArmas.getProperty("msg_archivoImportacionSerie"));
|
||
}
|
||
if(!this.registro.getTiporegistro().equalsIgnoreCase("IMP") && (listaArmas.get(i).getSerie()==null || listaArmas.get(i).getSerie().trim().isEmpty())){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 1: "+MsgControlArmas.getProperty("msg_serieVacia"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
}
|
||
//2-Clase
|
||
if(listaArmas.get(i).getClase()==null || listaArmas.get(i).getClase().trim().isEmpty()){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 2: "+MsgControlArmas.getProperty("msg_claseVacia"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
|
||
//3-Validando que cuando la clase sea ARMA DE FUEGO la longitud no este vacia
|
||
}else if(listaArmas.get(i).getClase().equalsIgnoreCase("ARMA DE FUEGO")
|
||
&& (listaArmas.get(i).getLongitud()==null || listaArmas.get(i).getLongitud().trim().isEmpty())){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 3: "+MsgControlArmas.getProperty("msg_longitudVacia"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
|
||
//Validando que cuando la clase no sea ARMA DE FUEGO la longitud este vacia
|
||
}else if(!listaArmas.get(i).getClase().equalsIgnoreCase("ARMA DE FUEGO")
|
||
&& (listaArmas.get(i).getLongitud()!=null && !listaArmas.get(i).getLongitud().trim().isEmpty())){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 3: "+MsgControlArmas.getProperty("msg_longitudNoVacia"));
|
||
}
|
||
//Carga de catalogos
|
||
TgeneCatalogDetail catalogoClase=CatalogDetailController.findByCatalogcodeDescrption("CLASE", listaArmas.get(i).getClase());
|
||
listaArmas.get(i).setCatalogoClase(catalogoClase);
|
||
if(catalogoClase!=null && catalogoClase.getPk()!=null && catalogoClase.getPk().getCatalog()!=null && !clase.contains(catalogoClase.getPk().getCatalog())){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 2: "+" No tiene permiso para cargar "+catalogoClase.getDescription());
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
}else if(catalogoClase==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 2: "+" No tiene ingresado una Clase V\u00e1lida ");
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
}
|
||
TgeneCatalogDetail catalogoLongitud=CatalogDetailController.findByCatalogcodeDescrption("LONGITUD", listaArmas.get(i).getLongitud());
|
||
listaArmas.get(i).setCatalogoLongitud(catalogoLongitud);
|
||
TgeneCatalogDetail catalogoTipoArma=CatalogDetailController.findByCatalogcodeDescrption("TIPOARMAEXPLOSIVO", listaArmas.get(i).getTipo());
|
||
listaArmas.get(i).setCatalogoTipoArma(catalogoTipoArma);
|
||
TgeneCatalogDetail catalogoCalibre=CatalogDetailController.findByCatalogcodeDescrption("CALIBRE", listaArmas.get(i).getCalibre());
|
||
listaArmas.get(i).setCatalogoCalibre(catalogoCalibre);
|
||
TgeneCatalogDetail catalogoColor=CatalogDetailController.findByCatalogcodeDescrption("COLOR", listaArmas.get(i).getColor());
|
||
listaArmas.get(i).setCatalogoColor(catalogoColor);
|
||
TgeneCatalogDetail catalogoMarca=CatalogDetailController.findByCatalogcodeDescrption("MARCA", listaArmas.get(i).getMarca());
|
||
listaArmas.get(i).setCatalogoMarca(catalogoMarca);
|
||
TarmUnidadTipo tipoUnidadSeleccionada =null;// new TarmUnidadTipo();
|
||
if(catalogoClase!=null){
|
||
//Obteniendo la configuracion de TARMUNIDADTIPO
|
||
if(!(listaArmas.get(i).getUnidadMedidaCantidad()==null || listaArmas.get(i).getUnidadMedidaCantidad().isEmpty()) && !(listaArmas.get(i).getUnidadMedidaPeso()==null || listaArmas.get(i).getUnidadMedidaPeso().isEmpty())){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 9,11: "+MsgControlArmas.getProperty("msg_unidadMedidaSoloUna"));
|
||
}
|
||
String unidadMedidaIngresada = (listaArmas.get(i).getUnidadMedidaCantidad()==null || listaArmas.get(i).getUnidadMedidaCantidad().isEmpty())?listaArmas.get(i).getUnidadMedidaPeso():listaArmas.get(i).getUnidadMedidaCantidad();
|
||
String columnaUnidadMedidaError = (listaArmas.get(i).getUnidadMedidaCantidad()==null || listaArmas.get(i).getUnidadMedidaCantidad().isEmpty())?"Columna 11":"Columna 9";
|
||
if (listaArmas.get(i).getCatalogoTipoArma() == null) {
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 5: El Tipo de Arma Explosivo no existe en el Cat<61>logo. Revise los espacios entre cada palabra y que este bien escrito.");
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
tipoUnidadSeleccionada=null;
|
||
}else {
|
||
tipoUnidadSeleccionada= UnidadTipoController.findByClaseAndClasecode(catalogoClase.getPk().getCatalog(), catalogoClase.getPk().getCatalogcode(),listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog(), unidadMedidaIngresada);
|
||
}
|
||
if(tipoUnidadSeleccionada!=null && tipoUnidadSeleccionada.getPk().getUnidadmedidapeso()!=null && !tipoUnidadSeleccionada.getPk().getUnidadmedidapeso().isEmpty()){
|
||
if(tipoUnidadSeleccionada.getPk().getUnidadmedidapeso().equalsIgnoreCase("UNIDAD") || tipoUnidadSeleccionada.getPk().getUnidadmedidapeso().equalsIgnoreCase("UNIDADES")){
|
||
campoCantidad=true;
|
||
}else if(tipoUnidadSeleccionada.getPk().getUnidadmedidapeso().equalsIgnoreCase("KG")){
|
||
campoCantidad=false;
|
||
}
|
||
}
|
||
else if (tipoUnidadSeleccionada==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+ columnaUnidadMedidaError + ": " +MsgControlArmas.getProperty("msg_unidadMedidaNoExiste"));
|
||
}
|
||
}
|
||
//4-Tipo
|
||
if(listaArmas.get(i).getTipo()==null || listaArmas.get(i).getTipo().trim().isEmpty()){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 4: "+MsgControlArmas.getProperty("msg_tipoVacio"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
}
|
||
//5-Calibre
|
||
if(listaArmas.get(i).getClase()!=null && !listaArmas.get(i).getClase().isEmpty()
|
||
&& listaArmas.get(i).getClase().equalsIgnoreCase("ARMA DE FUEGO")
|
||
&& (listaArmas.get(i).getCalibre()==null || listaArmas.get(i).getCalibre().trim().isEmpty())){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 5: "+MsgControlArmas.getProperty("msg_calibreVacio"));
|
||
}
|
||
//Marca
|
||
if(listaArmas.get(i).getMarca()==null || listaArmas.get(i).getMarca().trim().isEmpty()){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 7: "+MsgControlArmas.getProperty("msg_marcaVacia"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
}
|
||
if(campoCantidad){
|
||
//Cantidad
|
||
if((listaArmas.get(i).getTextoCantidad()==null || listaArmas.get(i).getTextoCantidad().trim().isEmpty()) && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 8: "+MsgControlArmas.getProperty("msg_cantidadVacia"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
|
||
}else if(listaFilas.get(i).getCell(8).getCellType()!=Cell.CELL_TYPE_NUMERIC && tipoUnidadSeleccionada!=null){
|
||
//Verificando el tipo de dato numerico
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 8: "+MsgControlArmas.getProperty("msg_cantidadValorNumerico"));
|
||
}
|
||
|
||
//U. Medida Cantidad
|
||
if((listaArmas.get(i).getUnidadMedidaCantidad()==null || listaArmas.get(i).getUnidadMedidaCantidad().trim().isEmpty()) && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 9: "+MsgControlArmas.getProperty("msg_unidadMedidaCantidadVacia"));
|
||
}
|
||
|
||
//Peso
|
||
if((listaArmas.get(i).getTextoPeso()!=null && !listaArmas.get(i).getTextoPeso().trim().isEmpty()) && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 10: "+MsgControlArmas.getProperty("msg_pesoNoVacio"));
|
||
}
|
||
|
||
//U. Medida Peso
|
||
if((listaArmas.get(i).getUnidadMedidaPeso()!=null && !listaArmas.get(i).getUnidadMedidaPeso().trim().isEmpty()) && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 11: "+MsgControlArmas.getProperty("msg_unidadMedidaPesoNoVacia"));
|
||
}
|
||
//Validando que cuando la clase NO sea ARMA DE FUEGO, MUNICION,
|
||
//Explosivos, Accesorios, Fuegos Pirotecnicos, Sustancia Quimica, Armas no Letales
|
||
//la cantidad y unidad de medida cantidad esten vacios
|
||
//y el peso y unidad de medida peso NO esten vacios
|
||
}else if(listaArmas.get(i).getClase()!=null && !listaArmas.get(i).getClase().isEmpty()){
|
||
//Cantidad
|
||
if((listaArmas.get(i).getTextoCantidad()!=null && !listaArmas.get(i).getTextoCantidad().trim().isEmpty()) && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 8: "+MsgControlArmas.getProperty("msg_cantidadNoVacia"));
|
||
}
|
||
//U. Medida Cantidad
|
||
if(listaArmas.get(i).getUnidadMedidaCantidad()!=null && !listaArmas.get(i).getUnidadMedidaCantidad().trim().isEmpty() && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 9: "+MsgControlArmas.getProperty("msg_unidadMedidaCantidadNoVacia"));
|
||
}
|
||
//Peso
|
||
if((listaArmas.get(i).getTextoPeso()==null || listaArmas.get(i).getTextoPeso().trim().isEmpty()) && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 10: "+MsgControlArmas.getProperty("msg_pesoVacio"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
|
||
}else if(listaFilas.get(i).getCell(10).getCellType()!=Cell.CELL_TYPE_NUMERIC && tipoUnidadSeleccionada!=null){
|
||
//Verificando el tipo de dato numerico
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 10: "+MsgControlArmas.getProperty("msg_pesoValorNumerico"));
|
||
}
|
||
//U. Medida Peso
|
||
if((listaArmas.get(i).getUnidadMedidaPeso()==null || listaArmas.get(i).getUnidadMedidaPeso().trim().isEmpty()) && tipoUnidadSeleccionada!=null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 11: "+MsgControlArmas.getProperty("msg_unidadMedidaPesoVacia"));
|
||
listaArmas.get(i).setCamposIncompletos(true);
|
||
}
|
||
}
|
||
//Verificando que no existan problemas en el arma proveniente del archivo EXCEL
|
||
//para validar entonces los datos en la base de datos
|
||
if(!listaArmas.get(i).getCamposIncompletos() && !listaArmas.get(i).getDuplicada()){
|
||
//Verificando los datos en los catalogos
|
||
//Verificando la existencia de la clase en el catalogo
|
||
if(catalogoClase==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 2: "+MsgControlArmas.getProperty("msg_calibreNoExisteCatalogo"));
|
||
listaArmas.get(i).setExisteCatalogo(false);
|
||
}else{
|
||
listaArmas.get(i).setExisteCatalogo(true);
|
||
}
|
||
//Verificando la existencia de la longitud en el catalogo
|
||
if(catalogoLongitud==null){
|
||
listaArmas.get(i).setExisteCatalogo(false);
|
||
if(listaArmas.get(i).getClase().toLowerCase().equalsIgnoreCase("arma de fuego")){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 3: "+MsgControlArmas.getProperty("msg_longitudNoExisteCatalogo"));
|
||
}
|
||
}else{
|
||
listaArmas.get(i).setExisteCatalogo(true);
|
||
}
|
||
//Verificando la existencia del tipo de arma en el catalogo
|
||
if(catalogoTipoArma==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 4: "+MsgControlArmas.getProperty("msg_noExisteTipoArmaCatalogo"));
|
||
listaArmas.get(i).setExisteCatalogo(false);
|
||
}else{
|
||
listaArmas.get(i).setExisteCatalogo(true);
|
||
}
|
||
//Verificando la existencia del calibre en el catalogo
|
||
if(catalogoCalibre==null){
|
||
listaArmas.get(i).setExisteCatalogo(false);
|
||
if(listaArmas.get(i).getClase().toLowerCase().equalsIgnoreCase("arma de fuego")){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 5: "+MsgControlArmas.getProperty("msg_calibreNoExisteCatalogo"));
|
||
}
|
||
}else{
|
||
listaArmas.get(i).setExisteCatalogo(true);
|
||
}
|
||
//Verificando la existencia del color en el catalogo
|
||
if(listaArmas.get(i).getColor()!=null && !listaArmas.get(i).getColor().isEmpty()){
|
||
if(catalogoColor==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 6: "+MsgControlArmas.getProperty("msg_colorNoExisteCatalogo"));
|
||
listaArmas.get(i).setExisteCatalogo(false);
|
||
}else{
|
||
listaArmas.get(i).setExisteCatalogo(true);
|
||
}
|
||
}
|
||
//Verificando la existencia de la marca en el catalogo
|
||
if(catalogoMarca==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Columna 7: "+MsgControlArmas.getProperty("msg_marcaNoExisteCatalogo"));
|
||
listaArmas.get(i).setExisteCatalogo(false);
|
||
}else{
|
||
listaArmas.get(i).setExisteCatalogo(true);
|
||
}
|
||
//Validacio 4- Verificando que exista la combinacion clase, longitud, tipo arma y calibre
|
||
//en la tabla TARMTIPOARMAEXPLOSIVO
|
||
if(listaArmas.get(i).getClase().toLowerCase().equalsIgnoreCase("arma de fuego")){
|
||
if(catalogoClase!=null && catalogoLongitud!=null && catalogoTipoArma!=null && catalogoCalibre!=null && tipoUnidadSeleccionada!=null){
|
||
tipoArmaExplosivo=TiposArmasExplosivosController.findByClaseLongitudCalibreTipoArma(catalogoLongitud.getPk().getCatalog(),
|
||
catalogoCalibre.getPk().getCatalog(), catalogoClase.getPk().getCatalog(), catalogoTipoArma.getPk().getCatalog(),tipoUnidadSeleccionada.getPk().getUnidadmedidapeso());
|
||
|
||
if(tipoArmaExplosivo==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Registro no encontrado: "+listaArmas.get(i).getClase()+", "+listaArmas.get(i).getLongitud()+", "+listaArmas.get(i).getTipo()+", "+listaArmas.get(i).getCalibre());
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(false);
|
||
}else{
|
||
listaArmas.get(i).setTipoArmaExplosivo(tipoArmaExplosivo);
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(true);
|
||
}
|
||
}else{
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Registro no encontrado la combinaci\u00f3n del Tipo Arma Explosivo");
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(false);
|
||
}
|
||
}else{
|
||
if(catalogoCalibre!=null && catalogoCalibre.getDescription()!=null && !catalogoCalibre.getDescription().equals("")){
|
||
// Caso donde existe calibre
|
||
if(catalogoClase!=null && catalogoTipoArma!=null && tipoUnidadSeleccionada!=null){
|
||
tipoArmaExplosivo=TiposArmasExplosivosController.findByClaseCalibreTipoArma(catalogoClase.getPk().getCatalog(), catalogoCalibre.getPk().getCatalog(), catalogoTipoArma.getPk().getCatalog(),tipoUnidadSeleccionada.getPk().getUnidadmedidapeso());
|
||
if(tipoArmaExplosivo==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Registro no encontrado: "+listaArmas.get(i).getClase()+", "+listaArmas.get(i).getTipo());
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(false);
|
||
}else{
|
||
listaArmas.get(i).setTipoArmaExplosivo(tipoArmaExplosivo);
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(true);
|
||
}
|
||
}else{
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Registro no encontrado la combinaci\u00f3n del Tipo Arma Explosivo ");
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(false);
|
||
}
|
||
}
|
||
else{
|
||
// Caso donde no existe calibre
|
||
if(catalogoClase!=null && catalogoTipoArma!=null && tipoUnidadSeleccionada!=null){
|
||
tipoArmaExplosivo=TiposArmasExplosivosController.findByClaseTipo(catalogoClase.getPk().getCatalog(), catalogoTipoArma.getPk().getCatalog(),tipoUnidadSeleccionada.getPk().getUnidadmedidapeso());
|
||
if(tipoArmaExplosivo==null){
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Registro no encontrado: "+listaArmas.get(i).getClase()+", "+listaArmas.get(i).getTipo());
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(false);
|
||
}else{
|
||
listaArmas.get(i).setTipoArmaExplosivo(tipoArmaExplosivo);
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(true);
|
||
}
|
||
}else{
|
||
listaErrores.add("Fila "+fila.toString()+": "+"Registro no encontrado la combinaci\u00f3n del Tipo Arma Explosivo ");
|
||
listaArmas.get(i).setExisteTARMTIPOARMAEXPLOSIVO(false);
|
||
}
|
||
}
|
||
|
||
}
|
||
if(listaArmas.get(i).getCatalogoClase()!=null && listaArmas.get(i).getCatalogoTipoArma()!=null && listaArmas.get(i).getCatalogoMarca()!=null){
|
||
TarmArmas armaBD;
|
||
//Si el tipo de registro es de Importacion, el arma se persiste como nueva
|
||
//no se busca en la base de datos
|
||
if(this.registro.getTiporegistro().equalsIgnoreCase("IMP")){
|
||
listaArmas.get(i).setExisteBaseDatos(false);
|
||
armaBD=new TarmArmas();
|
||
armaBD.setIsnew(true);
|
||
}else{
|
||
//Verificando que el arma exista en la base de datos
|
||
//si el tipo de registro es de produccion
|
||
armaBD=ArmasController.findBySerieMarca(listaArmas.get(i).getSerie(), listaArmas.get(i).getCatalogoMarca().getPk().getCatalog());
|
||
if(armaBD==null){
|
||
listaArmas.get(i).setExisteBaseDatos(false);
|
||
armaBD=new TarmArmas();
|
||
armaBD.setIsnew(true);
|
||
}else{
|
||
List<TarmTipoArmaExplosivo> listaExplosivos=TiposArmasExplosivosController.findByClaseTipoAll(listaArmas.get(i).getCatalogoClase().getPk().getCatalog(),
|
||
listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog());
|
||
if(listaExplosivos==null){
|
||
listaArmas.get(i).setExisteBaseDatos(false);
|
||
}else{
|
||
listaArmas.get(i).setExisteBaseDatos(false);
|
||
for (TarmTipoArmaExplosivo explosivo : listaExplosivos) {
|
||
if(explosivo.getPk().equalsIgnoreCase(armaBD.getCtipoarmaexplosivo())){
|
||
listaArmas.get(i).setExisteBaseDatos(true);
|
||
armaBD.setIsnew(false);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
listaArmas.get(i).setArma(armaBD);
|
||
String unidadTipoIngresada = campoCantidad?listaArmas.get(i).getUnidadMedidaCantidad():listaArmas.get(i).getUnidadMedidaPeso();
|
||
// CARGA EL CUPO ***** //persona,clase,tipoarmaexplosivo
|
||
// List<TarmComercianteCupo> cupo =ComercianteCupoController.findByPersonCode(usuario.getPk().getPersoncode().toString(),
|
||
// listaArmas.get(i).getCatalogoClase().getPk().getCatalog(), listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog(),
|
||
// unidadTipoIngresada);
|
||
//
|
||
// if(cupo!=null && !cupo.isEmpty() && cupo.get(0).getTiporegistro().equalsIgnoreCase(this.registro.getTiporegistro())){
|
||
//metodo de los TOTALES SETEADOS EN UN MAPA
|
||
cupoArmasExplosivos(i, mapaTotalesTemporales, fila,tipoUnidadSeleccionada);
|
||
// }else{
|
||
// if(cupo==null || cupo.isEmpty()){
|
||
// listaErrores.add("Fila "+fila.toString()+": Cupo no asignado para "+listaArmas.get(i).getClase()+".");
|
||
// }
|
||
// else{
|
||
// listaErrores.add("Fila "+fila.toString()+": Cupo no disponible para "+listaArmas.get(i).getClase()+".");
|
||
// }
|
||
// listaArmas.get(i).setCupoInsuficiente(true);
|
||
// }
|
||
}
|
||
}
|
||
tipoUnidadSeleccionada = null;
|
||
}
|
||
}
|
||
|
||
public void cupoArmasExplosivos(int i,HashMap<String, TarmTotalPersona> mapaTotalesTemporales,Integer fila,TarmUnidadTipo tipoUnidadSeleccionada){
|
||
|
||
BigDecimal saldoPasaraaAnterior = new BigDecimal(0);
|
||
TarmTotalPersona totalPersona=null;
|
||
|
||
if(mapaTotalesTemporales.get(usuario.getPk().getPersoncode().toString()+ "|" + listaArmas.get(i).getCatalogoClase().getPk().getCatalog()
|
||
+ "|" + listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog())==null){
|
||
totalPersona =TotalPersonaController.findMaxFecha(listaArmas.get(i).getCatalogoClase().getPk().getCatalog(),
|
||
listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog(), usuario.getPk().getPersoncode().toString(),
|
||
tipoUnidadSeleccionada.getPk().getUnidadmedidapeso());
|
||
if(totalPersona==null){
|
||
totalPersona=new TarmTotalPersona();
|
||
totalPersona.setTotal(new BigDecimal(0));
|
||
}else{
|
||
saldoPasaraaAnterior = (totalPersona==null?new BigDecimal(0):totalPersona.getTotal());
|
||
}
|
||
BigDecimal peso = (listaArmas==null || listaArmas.get(i).getTextoPeso()==null || listaArmas.get(i).getTextoPeso().isEmpty())?new BigDecimal(0.0):new BigDecimal(Double.parseDouble(listaArmas.get(i).getTextoPeso()));
|
||
BigDecimal cantidad = (listaArmas==null || listaArmas.get(i).getTextoCantidad()==null || listaArmas.get(i).getTextoCantidad().isEmpty())?new BigDecimal(0.0):new BigDecimal(Double.parseDouble(listaArmas.get(i).getTextoCantidad()));
|
||
totalPersona.setCantidadmovimiento(cantidad.add(peso));
|
||
totalPersona.setTotal(new BigDecimal(0));//saldoPasaraaAnterior.add((listaArmas==null || listaArmas.get(i).getTextoCantidad()==null)?new BigDecimal(0):new BigDecimal(Double.parseDouble(listaArmas.get(i).getTextoCantidad()))));
|
||
Double suma=0.0;
|
||
//Cantidad
|
||
if(listaArmas.get(i).getUnidadMedidaCantidad()!=null && !listaArmas.get(i).getUnidadMedidaCantidad().isEmpty()){
|
||
listaArmas.get(i).setCantidad(Double.parseDouble(listaArmas.get(i).getTextoCantidad()));
|
||
totalPersona.setUnidadmedidapeso(listaArmas.get(i).getUnidadMedidaCantidad());
|
||
//suma eltotal anterior + la cantidad a ingresar
|
||
suma=saldoPasaraaAnterior.doubleValue()+listaArmas.get(i).getCantidad();
|
||
totalPersona.setTotal(new BigDecimal(suma));
|
||
//Peso
|
||
}else if(listaArmas.get(i).getUnidadMedidaPeso()!=null && !listaArmas.get(i).getUnidadMedidaPeso().isEmpty()){
|
||
listaArmas.get(i).setPeso(Double.parseDouble(listaArmas.get(i).getTextoPeso()));
|
||
totalPersona.setUnidadmedidapeso(listaArmas.get(i).getUnidadMedidaPeso());
|
||
//suma eltotal anterior + la cantidad a ingresar
|
||
suma=saldoPasaraaAnterior.doubleValue()+listaArmas.get(i).getPeso();
|
||
totalPersona.setTotal(new BigDecimal(suma));
|
||
}
|
||
}
|
||
else{//existe la combinacion
|
||
totalPersona = mapaTotalesTemporales.get(usuario.getPk().getPersoncode().toString()+ "|" + listaArmas.get(i).getCatalogoClase().getPk().getCatalog()+ "|" + listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog());
|
||
BigDecimal peso = (listaArmas==null || listaArmas.get(i).getTextoPeso()==null || listaArmas.get(i).getTextoPeso().isEmpty())?new BigDecimal(0.0):new BigDecimal(Double.parseDouble(listaArmas.get(i).getTextoPeso()));
|
||
BigDecimal cantidad = (listaArmas==null || listaArmas.get(i).getTextoCantidad()==null || listaArmas.get(i).getTextoCantidad().isEmpty())?new BigDecimal(0.0):new BigDecimal(Double.parseDouble(listaArmas.get(i).getTextoCantidad()));
|
||
totalPersona.setCantidadmovimiento(cantidad.add(peso).add(totalPersona.getCantidadmovimiento()));
|
||
totalPersona.setTotal(totalPersona.getSaldoanterior().add(totalPersona.getCantidadmovimiento()));//saldoPasaraaAnterior.add((listaArmas==null || listaArmas.get(i).getTextoCantidad()==null)?new BigDecimal(0):new BigDecimal(Double.parseDouble(listaArmas.get(i).getTextoCantidad()))));
|
||
saldoPasaraaAnterior=totalPersona.getSaldoanterior();
|
||
}
|
||
totalPersona.setPk(null);
|
||
totalPersona.setPersoncodigo(usuario.getPk().getPersoncode());
|
||
totalPersona.setClase(listaArmas.get(i).getCatalogoClase().getPk().getCatalog());
|
||
totalPersona.setClasecodigo("CLASE");
|
||
totalPersona.setTipoarmaexplosivo(listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog());
|
||
totalPersona.setTipoarmaexplosivocodigo("TIPOARMAEXPLOSIVO");
|
||
totalPersona.setIngresoegreso("ING");
|
||
totalPersona.setCarma(listaArmas.get(i).getArma().getPk());
|
||
totalPersona.setIngresoegresocodigo("ESINGRESOEGRESO");
|
||
totalPersona.setUnidadmedidapesocodigo("UNIDADMEDIDA");
|
||
totalPersona.setFecha(new java.sql.Timestamp(new Date().getTime()));
|
||
totalPersona.setSaldoanterior(saldoPasaraaAnterior==null?new BigDecimal(0):saldoPasaraaAnterior);
|
||
totalPersona.setIsnew(true);
|
||
//Verificando si el usuario tiene cupo disponible para el arma
|
||
|
||
//mapa con el nuevo total por clase tipo unidad
|
||
mapaTotalesTemporales.put(usuario.getPk().getPersoncode().toString()+ "|" + listaArmas.get(i).getCatalogoClase().getPk().getCatalog()+ "|" + listaArmas.get(i).getCatalogoTipoArma().getPk().getCatalog(),totalPersona);
|
||
listaArmas.get(i).setTotalPersona(totalPersona);
|
||
//Verificando que el la suma del total con la cantidad de armas
|
||
//no sea mayor que el cupo
|
||
// if(totalPersona.getTotal().doubleValue()>cupoMaximo){
|
||
// listaErrores.add("Fila "+fila.toString()+": Cupo no disponible para "+listaArmas.get(i).getClase());
|
||
// listaArmas.get(i).setCupoInsuficiente(true);
|
||
// }else{
|
||
// //Actualizando el valor del total y del total anterior
|
||
// listaArmas.get(i).getTotalPersona().setSaldoanterior(listaArmas.get(i).getTotalPersona().getSaldoanterior());
|
||
// listaArmas.get(i).getTotalPersona().setTotal(totalPersona.getTotal());
|
||
// }
|
||
}
|
||
|
||
/**
|
||
* Metodo que indica cuando una celda esta vacia
|
||
* @param celda
|
||
* @return
|
||
*/
|
||
public Boolean celdaVacia(Cell celda){
|
||
Boolean vacia=false;
|
||
if(celda==null || celda.getCellType()==Cell.CELL_TYPE_BLANK || (celda.getCellType()==Cell.CELL_TYPE_STRING && celda.getStringCellValue().isEmpty())){
|
||
vacia=true;
|
||
}
|
||
return vacia;
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @param codigopersona
|
||
* @return
|
||
*/
|
||
public static TarmArmas findBySerieMarca(String serie, String marca) {
|
||
try {
|
||
IngresoInventarioController cc = new IngresoInventarioController();
|
||
cc.init();
|
||
cc.recperpage = 300;
|
||
cc.addFilter("lote", serie);
|
||
cc.addFilter("marca", marca);
|
||
cc.querydatabaseSimple();
|
||
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
||
return cc.lrecord.get(0);
|
||
}
|
||
return null;
|
||
} catch (Throwable e) {
|
||
MessageHelper.setMessageError(e);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
*
|
||
* Metodo para encontrar por marca y tipoarmaexplosivo
|
||
* @param marca
|
||
* @param tipoArmaExplosivo
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
public static List<TarmArmas> findByMarcaSerie(String cregistro,String marca, String serie) throws Exception {
|
||
|
||
IngresoInventarioController cc = new IngresoInventarioController();
|
||
//cc.init();
|
||
cc.recperpage = 300;
|
||
cc.querydatabaseMarcaSerie(cregistro,marca, serie );
|
||
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
||
return cc.lrecord;
|
||
}
|
||
return null;
|
||
|
||
}
|
||
|
||
@SuppressWarnings("finally")
|
||
public File generarArchivoError(Long key){
|
||
if(listaErrores.isEmpty()){
|
||
|
||
//MessageHelper.setMessageInfo("ARCHIVO SUBIDO CORRECTAMENTE");
|
||
return null;
|
||
}
|
||
PrintWriter escribir=null;
|
||
File archivo = null;
|
||
try {
|
||
archivo = File.createTempFile("errorlog"+key,".txt");
|
||
escribir = new PrintWriter(archivo);
|
||
|
||
|
||
for(String err : listaErrores){
|
||
System.out.println(err);
|
||
|
||
|
||
escribir.print(err+"\r\n");
|
||
}
|
||
//escribir.close();
|
||
limpiar();
|
||
|
||
|
||
|
||
}
|
||
catch (IOException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
finally{
|
||
escribir.flush();
|
||
escribir.close();
|
||
return archivo;
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* Llama a la construccion del metodo para recargar
|
||
*/
|
||
public void descargarArchivo(){
|
||
|
||
Long key=new Date().getTime();
|
||
File archivoTemporal=generarArchivoError(key);
|
||
if(archivoTemporal==null)
|
||
return;
|
||
try {
|
||
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
|
||
response.addHeader("Content-disposition", "attachment; filename=errorlog"+key+".txt");
|
||
OutputStream out = response.getOutputStream();
|
||
InputStream inputStream = new FileInputStream(archivoTemporal.getAbsolutePath());
|
||
|
||
int read = 0;
|
||
byte[] bytes = new byte[1024];
|
||
|
||
while ((read = inputStream.read(bytes)) != -1) {
|
||
out.write(bytes, 0, read);
|
||
}
|
||
|
||
inputStream.close();
|
||
out.flush();
|
||
|
||
FacesContext.getCurrentInstance().responseComplete();
|
||
|
||
|
||
} catch (Exception e) {
|
||
// TODO: handle exception
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Limpia las los valores en las listas
|
||
*/
|
||
public void limpiar(){
|
||
try {
|
||
create();
|
||
while(lrecord.iterator().hasNext()){
|
||
record =lrecord.get(0);
|
||
remove();
|
||
}
|
||
listaArmas = new ArrayList<ArmaExcell>();
|
||
} catch (Exception e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Carga las listas de cantones y limpia la lista de ciudades
|
||
*/
|
||
public void seleccionarProvincia(){
|
||
try {
|
||
codigoProvincia=this.record.getProvincecode();
|
||
lcantones = CantonController.find("EC", record.getProvincecode());
|
||
lciudades = new ArrayList<>();
|
||
} catch (Exception e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Carga las listas de ciudades
|
||
*/
|
||
public void seleccionarCanton(){
|
||
try {
|
||
codigoCanton = this.record.getCantoncode();
|
||
lciudades = CityController.find("EC", record.getProvincecode(), record.getCantoncode());
|
||
} catch (Exception e) {
|
||
MessageHelper.setMessageError(e);
|
||
}
|
||
}
|
||
|
||
|
||
public void cargarDocumentosHabilitantes(String categoria){
|
||
ldocumentospersona= new ArrayList<>();
|
||
List<TarmDocumentoHabilitante> listadocum=DocumentoHabilitanteController.findpersoncodeInventario(usuario.getPk().getPersoncode().toString(),categoria);
|
||
//Forma n<>mero 1 (Uso de Maps).
|
||
Map<Long, TarmDocumentoHabilitante> mapPersonas = new HashMap<Long, TarmDocumentoHabilitante>(listadocum.size());
|
||
for(TarmDocumentoHabilitante p : listadocum) {
|
||
mapPersonas.put(p.getCtramite(), p);
|
||
}
|
||
//Agrego cada elemento del map a una nueva lista y muestro cada elemento.
|
||
System.out.println("Lista sin repetidos:");
|
||
for(Entry<Long, TarmDocumentoHabilitante> p : mapPersonas.entrySet()) {
|
||
// Se cargan las categorias diferentes a armas de fuego y armas no letales
|
||
// if(!p.getValue().getModifiedData().get("clase").toString().contains("0010000001")||!p.getValue().getModifiedData().get("clase").toString().contains("0010000008")){
|
||
ldocumentospersona.add(p.getValue());
|
||
// }
|
||
}
|
||
// ldocumentospersona =DocumentoHabilitanteController.findpersoncode(usuario.getPk().getPersoncode().toString(),categoria);
|
||
}
|
||
|
||
public void cambioTipoRegistro(){
|
||
if(registro.getTiporegistro()!=null){
|
||
cargarDocumentosHabilitantes("4");//4 Fabrica, 5Fabricante
|
||
}else{
|
||
ldocumentospersona=new ArrayList<>();
|
||
}
|
||
}
|
||
|
||
public List<TgeneCanton> getLcantones() {
|
||
return lcantones;
|
||
}
|
||
|
||
public void setLcantones(List<TgeneCanton> lcantones) {
|
||
this.lcantones = lcantones;
|
||
}
|
||
public String getCodigoProvincia() {
|
||
return codigoProvincia;
|
||
}
|
||
|
||
public void setCodigoProvincia(String codigoProvincia) {
|
||
this.codigoProvincia = codigoProvincia;
|
||
}
|
||
|
||
public String getCodigoCanton() {
|
||
return codigoCanton;
|
||
}
|
||
|
||
public void setCodigoCanton(String codigoCanton) {
|
||
this.codigoCanton = codigoCanton;
|
||
}
|
||
|
||
public String getCodigoCiudad() {
|
||
return codigoCiudad;
|
||
}
|
||
|
||
public void setCodigoCiudad(String codigoCiudad) {
|
||
this.codigoCiudad = codigoCiudad;
|
||
}
|
||
|
||
String codigoCiudad;
|
||
public void codigoCiudad(){
|
||
|
||
|
||
}
|
||
|
||
public void addPersoncodeFilter(String personcode) {
|
||
super.addFilter("pk.personcode", personcode);
|
||
}
|
||
|
||
public List<ArmaExcell> getLarmexcell() {
|
||
return listaArmas;
|
||
}
|
||
|
||
public void setLarmexcell(List<ArmaExcell> larmexcell) {
|
||
this.listaArmas = larmexcell;
|
||
}
|
||
|
||
public ArmaExcell getArmaexcell() {
|
||
return armaexcell;
|
||
}
|
||
|
||
public void setArmaexcell(ArmaExcell armaexcell) {
|
||
this.armaexcell = armaexcell;
|
||
}
|
||
|
||
public TarmTipoArmaExplosivo getTipoarmexplosivo() {
|
||
return tipoArmaExplosivo;
|
||
}
|
||
|
||
public void setTipoarmexplosivo(TarmTipoArmaExplosivo tipoarmexplosivo) {
|
||
this.tipoArmaExplosivo = tipoarmexplosivo;
|
||
}
|
||
|
||
public List<ArmaExcell> getLaexel() {
|
||
return laexel;
|
||
}
|
||
|
||
public void setLaexel(List<ArmaExcell> laexel) {
|
||
this.laexel = laexel;
|
||
}
|
||
|
||
public TcustPersonDetail getDetallesPersona() {
|
||
return detallesPersona;
|
||
}
|
||
|
||
public void setDetallesPersona(TcustPersonDetail detallesPersona) {
|
||
this.detallesPersona = detallesPersona;
|
||
}
|
||
|
||
public TcustPersonDetail getUsuario() {
|
||
return usuario;
|
||
}
|
||
|
||
public void setUsuario(TcustPersonDetail usuario) {
|
||
this.usuario = usuario;
|
||
}
|
||
|
||
public List<Row> getListaFilas() {
|
||
return listaFilas;
|
||
}
|
||
|
||
public void setListaFilas(List<Row> listaFilas) {
|
||
this.listaFilas = listaFilas;
|
||
}
|
||
|
||
public List<String> getListaErrores() {
|
||
return listaErrores;
|
||
}
|
||
|
||
public void setListaErrores(List<String> listaErrores) {
|
||
this.listaErrores = listaErrores;
|
||
}
|
||
|
||
public TarmTipoArmaExplosivo getTipoArmaExplosivo() {
|
||
return tipoArmaExplosivo;
|
||
}
|
||
|
||
public void setTipoArmaExplosivo(TarmTipoArmaExplosivo tipoArmaExplosivo) {
|
||
this.tipoArmaExplosivo = tipoArmaExplosivo;
|
||
}
|
||
|
||
public List<ArmaExcell> getListaArmas() {
|
||
return listaArmas;
|
||
}
|
||
|
||
public void setListaArmas(List<ArmaExcell> listaArmas) {
|
||
this.listaArmas = listaArmas;
|
||
}
|
||
|
||
public PersonAddressController getPersonAddressController() {
|
||
return personAddressController;
|
||
}
|
||
|
||
public void setPersonAddressController(
|
||
PersonAddressController personAddressController) {
|
||
this.personAddressController = personAddressController;
|
||
}
|
||
|
||
public InputStream getFilei() {
|
||
return filei;
|
||
}
|
||
|
||
public void setFilei(InputStream filei) {
|
||
this.filei = filei;
|
||
}
|
||
|
||
public String getCsolicitud() {
|
||
return csolicitud;
|
||
}
|
||
|
||
public void setCsolicitud(String csolicitud) {
|
||
this.csolicitud = csolicitud;
|
||
}
|
||
|
||
public TcustPersonAddress getDireccion() {
|
||
return direccion;
|
||
}
|
||
|
||
public void setDireccion(TcustPersonAddress direccion) {
|
||
this.direccion = direccion;
|
||
}
|
||
|
||
// public List<TarmComercianteCupo> getCuposArmas() {
|
||
// return cuposArmas;
|
||
// }
|
||
//
|
||
// public void setCuposArmas(List<TarmComercianteCupo> cuposArmas) {
|
||
// this.cuposArmas = cuposArmas;
|
||
// }
|
||
|
||
// public ComercianteCupoController getComercianteCupoController() {
|
||
// return comercianteCupoController;
|
||
// }
|
||
//
|
||
// public void setComercianteCupoController(
|
||
// ComercianteCupoController comercianteCupoController) {
|
||
// this.comercianteCupoController = comercianteCupoController;
|
||
// }
|
||
|
||
public Boolean getDescargar() {
|
||
return descargar;
|
||
}
|
||
|
||
public void setDescargar(Boolean descargar) {
|
||
this.descargar = descargar;
|
||
}
|
||
|
||
public RegistroArmController getRegistroArmasController() {
|
||
return registroArmasController;
|
||
}
|
||
|
||
public void setRegistroArmasController(
|
||
RegistroArmController registroArmasController) {
|
||
this.registroArmasController = registroArmasController;
|
||
}
|
||
|
||
|
||
public TotalArmasController getTotalPersonaController() {
|
||
return totalPersonaController;
|
||
}
|
||
|
||
public void setTotalPersonaController(
|
||
TotalArmasController totalPersonaController) {
|
||
this.totalPersonaController = totalPersonaController;
|
||
}
|
||
|
||
public TgeneCountry getPais() {
|
||
return pais;
|
||
}
|
||
|
||
public void setPais(TgeneCountry pais) {
|
||
this.pais = pais;
|
||
}
|
||
|
||
public List<TgeneCity> getLciudades() {
|
||
return lciudades;
|
||
}
|
||
|
||
public void setLciudades(List<TgeneCity> lciudades) {
|
||
this.lciudades = lciudades;
|
||
}
|
||
|
||
public TgeneCity getCiudad() {
|
||
return ciudad;
|
||
}
|
||
|
||
public void setCiudad(TgeneCity ciudad) {
|
||
this.ciudad = ciudad;
|
||
}
|
||
|
||
public List<TarmArmas> getArmas() {
|
||
return armas;
|
||
}
|
||
|
||
public void setArmas(List<TarmArmas> armas) {
|
||
this.armas = armas;
|
||
}
|
||
|
||
public List<TarmTotalPersona> getTotalesPersoan() {
|
||
return totalesPersoan;
|
||
}
|
||
|
||
public void setTotalesPersoan(List<TarmTotalPersona> totalesPersoan) {
|
||
this.totalesPersoan = totalesPersoan;
|
||
}
|
||
|
||
public TgeneCatalogDetail getTipoDocumento() {
|
||
return tipoDocumento;
|
||
}
|
||
|
||
public void setTipoDocumento(TgeneCatalogDetail tipoDocumento) {
|
||
this.tipoDocumento = tipoDocumento;
|
||
}
|
||
|
||
public Date getFechaActual() {
|
||
return fechaActual;
|
||
}
|
||
|
||
public void setFechaActual(Date fechaActual) {
|
||
this.fechaActual = fechaActual;
|
||
}
|
||
|
||
public List<TgeneCatalogDetail> getTiposRegistro() {
|
||
return tiposRegistro;
|
||
}
|
||
|
||
public void setTiposRegistro(List<TgeneCatalogDetail> tiposRegistro) {
|
||
this.tiposRegistro = tiposRegistro;
|
||
}
|
||
|
||
public TgeneCatalogDetail getTipoRegistro() {
|
||
return tipoRegistro;
|
||
}
|
||
|
||
public void setTipoRegistro(TgeneCatalogDetail tipoRegistro) {
|
||
this.tipoRegistro = tipoRegistro;
|
||
}
|
||
|
||
public List<TgeneCountry> getLpaises() {
|
||
return lpaises;
|
||
}
|
||
|
||
public void setLpaises(List<TgeneCountry> lpaises) {
|
||
this.lpaises = lpaises;
|
||
}
|
||
|
||
public List<TgeneProvince> getLprovincias() {
|
||
return lprovincias;
|
||
}
|
||
|
||
public void setLprovincias(List<TgeneProvince> lprovincias) {
|
||
this.lprovincias = lprovincias;
|
||
}
|
||
|
||
public TarmRegistroArmas getRegistro() {
|
||
return registro;
|
||
}
|
||
|
||
public void setRegistro(TarmRegistroArmas registro) {
|
||
this.registro = registro;
|
||
}
|
||
|
||
public List<TgeneCatalogDetail> getLaeropuertos() {
|
||
return laeropuertos;
|
||
}
|
||
|
||
public void setLaeropuertos(List<TgeneCatalogDetail> laeropuertos) {
|
||
this.laeropuertos = laeropuertos;
|
||
}
|
||
|
||
public List<TarmDocumentoHabilitante> getLdocumentospersona() {
|
||
return ldocumentospersona;
|
||
}
|
||
|
||
public void setLdocumentospersona(
|
||
List<TarmDocumentoHabilitante> ldocumentospersona) {
|
||
this.ldocumentospersona = ldocumentospersona;
|
||
}
|
||
|
||
public String getClase() {
|
||
return clase;
|
||
}
|
||
|
||
public void setClase(String clase) {
|
||
this.clase = clase;
|
||
}
|
||
|
||
public Integer getPersoncode() {
|
||
return personcode;
|
||
}
|
||
|
||
public void setPersoncode(Integer personcode) {
|
||
this.personcode = personcode;
|
||
}
|
||
|
||
public InventarioSubidoController getInventarioSubidoController() {
|
||
return inventarioSubidoController;
|
||
}
|
||
|
||
public void setInventarioSubidoController(
|
||
InventarioSubidoController inventarioSubidoController) {
|
||
this.inventarioSubidoController = inventarioSubidoController;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|