maia_modificado/.svn/pristine/e4/e4d9fd078cfd91a9716f9210ec6...

560 lines
20 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.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;
import org.primefaces.context.RequestContext;
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.pgeneral.gene.CatalogDetailController;
import com.fp.frontend.helper.MessageHelper;
import com.fp.frontend.utility.MsgControlArmas;
import com.fp.persistence.parmas.inte.TarmColadeImpresion;
import com.fp.persistence.parmas.param.TarmTramite;
import com.fp.persistence.parmas.soli.TarmArmas;
import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante;
import com.fp.persistence.parmas.soli.TarmSolicitud;
import com.fp.persistence.parmas.soli.TarmSolicitudDocumento;
import com.fp.persistence.pgeneral.gene.TgeneCatalogDetail;
@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class VerificacionReimpresion extends AbstractController<TarmSolicitudDocumento> {
/*
* Variable que indica si se seleciona el check o no
*/
private Boolean verifica = false;
/**
* Variable que indica si se ha seleccionado un registro
*/
private boolean esCola = false;
/**
* Hailita el boton del flujo
*/
private boolean btnFlujo = false;
/*
* Variable que almacena el c&oacute;digo de solicitud
*/
private String csolicitud;
/*
* Bean de tipo TarmSolicitud
*/
private TarmSolicitud solicitud = new TarmSolicitud();
@ManagedProperty(value = "#{docHabilitanteController}")
private DocumentoHabilitanteController docHabilitanteController;
@ManagedProperty(value = "#{solicitudController}")
private SolicitudController solicitudController;
@ManagedProperty(value = "#{recepcionArmasController}")
private RecepcionArmasController recepcionArmasController;
@ManagedProperty(value = "#{colaImpresionController}")
private ColaImpresionController colaImpresionController;
/**
* Constructor
* @throws Exception
*/
public VerificacionReimpresion() throws Exception {
super(TarmSolicitudDocumento.class);
}
/**
* M&eacute;todo invocado despu&eacute;s de instanciar el controlador
* @throws Exception
*/
@PostConstruct
private void postconstruct() throws Exception {
// Inicializa autoconsulta
this.pasteBpmScreenParameters();
super.startQuery();
if(super.getMfilters().get("csolicitud")==null || super.getMfilters().get("csolicitud").isEmpty()){
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_noexistesolicitud"));
return;
}
csolicitud=super.getMfilters().get("csolicitud");
this.getMfilters().clear();
//this.getMfilters().put("pk.csolicitud", csolicitud);
this.solicitud= SolicitudController.findSolicitudxcodsolicitud(csolicitud);
this.getMfilelds().put("numerosolicitud", this.solicitud.getNumerosolicitud());
this.init();
}
/**
* Incializa variables del controlador, cuando se est&aacute; utilizando una p&aacute;gina que utliza el controlador.
*/
private void init() {
try {
this.recperpage = 10; // Cambiar al # reg a mirar.
this.lrecord = new ArrayList<>();
this.beanalias = "VERIFICARDOCUMENTOS";
querydatabase();
} catch (Exception e) {
MessageHelper.setMessageError(e);
}
}
/* (non-Javadoc)
* @see com.fp.frontend.controller.AbstractController#querydatabase()
*/
@SuppressWarnings("unchecked")
@Override
protected void querydatabase() {
try {
Request request = this.callerhelper.getRequest();
DtoQuery dto = super.getDtoQuery(true);
Filter filtroSinImpresionSolicitud=new Filter();
filtroSinImpresionSolicitud.setSql("(t.chkimpresion='N' or t.chkimpresion is null) and t.pk.csolicitud = '" + this.solicitud.getPk() + "'");
dto.addFiltro(filtroSinImpresionSolicitud);
dto.setOrderby("t.pk"); // En en string van todos los campos de orden ("t.pk, t.nombre, t.cpais").
SubQuery qry = new SubQuery("TarmSolicitud", "ccentrocontrol", "ccentrocontrol", "i.pk = t.pk.csolicitud");
dto.addSubQuery(qry);
SubQuery qry2 = new SubQuery("TgeneCatalogDetail", "description", "tramitedesc",
"i.pk.catalog = (select a.tipotramite from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento))) "// t.pk.csolicitud
+ " and "
+ "i.pk.catalogcode = (select a.tipotramitecodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))");
dto.addSubQuery(qry2);
SubQuery qry3 = new SubQuery("TgeneCatalogDetail", "description", "categoriadesc",
"i.pk.catalog = (select a.categoria from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))"
+ " and "
+ "i.pk.catalogcode = (select a.categoriacodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))");
dto.addSubQuery(qry3);
SubQuery qry4 = new SubQuery("TgeneCatalogDetail", "description", "usoactdesc",
"i.pk.catalog = (select a.usoactividad from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))"
+ " and "
+ "i.pk.catalogcode = (select a.usoactividadcodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = (select o.csolicitud from TarmDocumentoHabilitante o where o.pk=t.pk.cdocumento)))");
dto.addSubQuery(qry4);
//ubicacion
SubQuery qryUbicacion = new SubQuery("TgeneProvince", "description", "ubicaciondesc",
"i.pk.countrycode = 'EC'"
+ " and "
+ "i.pk.provincecode = (select a.provincecode from TcustPersonAddress a where a.pk.personcode =(select o.personcode from TarmDocumentoHabilitante o where o.pk= t.pk.cdocumento )"
+ " and a.principal='Y'"
+ " and a.pk.dateto = to_date('2999-12-31', 'YYYY-MM-DD') )");//
dto.addSubQuery(qryUbicacion);
//TarmSolicitudDocumento
SubQuery qry5 = new SubQuery("TarmDocumentoHabilitante", "fechaemision", "fechaemision", "i.pk= t.pk.cdocumento");
dto.addSubQuery(qry5);
SubQuery qry6 = new SubQuery("TarmDocumentoHabilitante", "fechaexpiracion", "fechaexpiracion", "i.pk= t.pk.cdocumento");
dto.addSubQuery(qry6);
SubQuery qry61 = new SubQuery("TarmDocumentoHabilitante", "estado ", "estado1", "i.pk= t.pk.cdocumento");
dto.addSubQuery(qry61);
SubQuery qry611 = new SubQuery("TarmDocumentoHabilitante", "estadocode ", "estado11", "i.pk= t.pk.cdocumento");
dto.addSubQuery(qry611);
SubQuery qry7 = new SubQuery("TgeneCatalogDetail", "description", "estado",
"i.pk.catalog = (select a.estado from TarmDocumentoHabilitante a where a.pk= t.pk.cdocumento) and "
+ "i.pk.catalogcode = (select a.estadocode from TarmDocumentoHabilitante a where a.pk= t.pk.cdocumento)");
dto.addSubQuery(qry7);
SubQuery qry8 = new SubQuery("TarmDocumentoHabilitante", "carma", "carma", "i.pk = t.pk.cdocumento and i.pk= t.pk.cdocumento");
dto.addSubQuery(qry8);
SubQuery qry9 = new SubQuery("TarmDocumentoHabilitante", "codigoarma", "codigoarma", "i.pk= t.pk.cdocumento");
dto.addSubQuery(qry9);
SubQuery qry10 = new SubQuery("TgeneCatalogDetail", "description", "tipoautorizacion",
"i.pk.catalog = (select a.tipoautorizacion from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = t.pk.csolicitud)) and "
+ "i.pk.catalogcode = (select a.tipoautorizacioncodigo from TarmTramite a where a.pk = (select s.ctramite from TarmSolicitud s where s.pk = t.pk.csolicitud))");
dto.addSubQuery(qry10);
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
mtables.put(this.beanalias, dto); // permite adicionar mas de una tabla.
request.setQueryTables(mtables);
request.put("querytype", "P");
request.put("queryalias", "VDOCUMENTO");
Response resp = this.callerhelper.executeQuery(request);
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
this.lrecord = new ArrayList<TarmSolicitudDocumento>();
MessageHelper.setMessageError(resp);
} else {
this.lrecord = (List<TarmSolicitudDocumento>) resp.get(this.beanalias);
this.completaArmas();
super.postQuery(this.lrecord);
lista();
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
/**
* Verifica la selecci&oacute;n del documento seg&uacute;n el check de
* reimpresion
*/
public void lista(){
for (TarmSolicitudDocumento solicituddoc : lrecord) {
if(solicituddoc.getChkimpresion()!= null && solicituddoc.getChkimpresion().equals("Y")){
solicituddoc.getModifiedData().put("verificador", Boolean.TRUE);
}else{
solicituddoc.getModifiedData().put("verificador", Boolean.FALSE);
}
}
}
/* (non-Javadoc)
* @see com.fp.frontend.controller.AbstractController#save()
*/
@Override
public void save(){
try {
if(!validaSeleccion()){
MessageHelper.setMessageError(MsgControlArmas.getProperty("msg_error_reimpresion"));
return;
}
this.actualizaVerificado();
Request request = this.callerhelper.getRequest();
DtoSave dtosave = super.getDtoSave();
dtosave.setPosition(2);
// if(!dtosave.pendingProcess()){
// return;
// }
//En caso de que los documentos sean de tipo de cola de impresion
enviaColaImpresion();
DtoSave dtosacola = colaImpresionController.getDtoSave();
dtosacola.setReturnpk(true);
dtosacola.setPosition(1);
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
msave.put(this.beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla.
msave.put(colaImpresionController.getBeanalias(), dtosacola);
request.setSaveTables(msave);
Response resp = this.callerhelper.executeSave(request);
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
btnFlujo=Boolean.TRUE;
this.postCommit(resp);
this.colaImpresionController.postCommit(resp);
MessageHelper.setMessageInfo(resp);
} else {
MessageHelper.setMessageError(resp);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
/**
* Selecciona los registros para establecer si el registro se reimprime o no.
*/
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 (TarmSolicitudDocumento solicituddoc : lrecord) {
solicituddoc.getModifiedData().put("verificador", valorColocar);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
/**
* Actualiza la selecci&oacute;n del documento seg&uacute;n el check de
* reimpresion
* @throws Exception
*/
public void actualizaVerificado() throws Exception{
for (TarmSolicitudDocumento solicituddoc : lrecord) {
if(solicituddoc.getModifiedData().get("verificador").equals(Boolean.TRUE)){
solicituddoc.setChkimpresion("Y");
}else {
solicituddoc.setChkimpresion("N");
}
record=solicituddoc;
super.update();
}
}
/**
*
*/
@SuppressWarnings("unchecked")
protected void querydatabaseDocumentos() {
try {
DtoQuery dto = super.getDtoQuery(true);
if(csolicitud !=null )
{
dto.addFiltro(new Filter("pk.csolicitud", csolicitud));
}
//solicitudTramite = TarmSolicitudTramiteController.findPorCSolicitud(codigoSolicitud);
solicitud = ValidacionTramiteLibreTransitoController.findPorSolicitudSimple(csolicitud);
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
mtables.put(beanalias, dto); // permite adicionar mas de una tabla.
Request request = callerhelper.getRequest();
request.setQueryTables(mtables);
Response resp = callerhelper.executeQuery(request);
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) != 0) {
lrecord = new ArrayList<TarmSolicitudDocumento>();
MessageHelper.setMessageError(resp);
} else {
lrecord = (List<TarmSolicitudDocumento>) resp.get(beanalias);
if (lrecord != null && !lrecord.isEmpty()) {
record = lrecord.get(0);
seleccionarDocumentos();
}
super.postQuery(lrecord);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
/**
* M&eacute;todo que asigna la selecci&oacute;n del documento seg&uacute;n el check de
* reimpresion
*
* @throws Exception
*/
@SuppressWarnings("unused")
private void seleccionarDocumentos() throws Exception {
for (int i = 0; i < lrecord.size(); i++) {
TarmSolicitudDocumento docSeleccionada = lrecord.get(i);
if (docSeleccionada.getVerificado().equalsIgnoreCase("Y")) {
docSeleccionada.modifiedData().put("seleccion", Boolean.TRUE);
} else {
docSeleccionada.modifiedData().put("seleccion", Boolean.FALSE);
}
}
}
/**
* M&eacute;todo que completa la informaci&oacute;n del arma para los registros de la
* tabla TarmSolicitudDocumento
*/
public void completaArmas(){
for(int i=0;i<this.lrecord.size();i++){
if(lrecord.get(i).getModifiedData().get("carma")!=null)
{
TarmArmas arm=ArmasController.findxCodigo(lrecord.get(i).getModifiedData().get("carma").toString());
try {
lrecord.get(i).getModifiedData().put("codigoarma", arm.getCodigoarma()==null?"": arm.getCodigoarma());
} catch (Exception e) {
e.printStackTrace();
}
try {
lrecord.get(i).getModifiedData().put("clasearma", arm.modifiedData.get("clase")==null?"": arm.modifiedData.get("clase").toString());
} catch (Exception e) {
e.printStackTrace();
}
try {
lrecord.get(i).getModifiedData().put("tipoarma",arm.modifiedData.get("tipo")==null?"": arm.modifiedData.get("tipo").toString());
} catch (Exception e) {
e.printStackTrace();
}
try {
lrecord.get(i).getModifiedData().put("marcaarma", arm.modifiedData.get("marca")==null?"": arm.modifiedData.get("marca").toString());
} catch (Exception e) {
e.printStackTrace();
}
try {
lrecord.get(i).getModifiedData().put("calibrearma",arm.modifiedData.get("calibre")==null?"": arm.modifiedData.get("calibre").toString());
} catch (Exception e) {
e.printStackTrace();
}
try {
lrecord.get(i).getModifiedData().put("seriearma",arm.getLote()==null?"":arm.getLote());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/**
* Metodo para finalizar la tarea del flujo
*/
public void completarTarea() {
try {
Request request = callerhelper.getRequest();
// limpiar request para finalizar la tarea.
super.cleanRequest(request);
//request.modifiedData().put("csolicitud", this.solicitud.getPk());
request.modifiedData().put("TID", tid);
if(esCola){
request.modifiedData().put("BPMStatus", bpmDataStatus == null ? "A" : bpmDataStatus);
}
else{
request.modifiedData().put("BPMStatus", bpmDataStatus == null ? "D" : bpmDataStatus);
}
// A,D,R
request.modifiedData().put("BPMObs", bpmDataComment == null ? "OK" : bpmDataComment);
Response resp = callerhelper.executeSave(request);
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
MessageHelper.setMessageInfo(resp);
btnFlujo=Boolean.FALSE;
RequestContext.getCurrentInstance().execute("Maia.refreshusertasks()");
} else {
MessageHelper.setMessageError(resp);
}
} catch (Throwable e) {
MessageHelper.setMessageError(e);
}
}
/**
* Valida que se haya seleccionado documento
* @return
*/
private boolean validaSeleccion(){
for(TarmSolicitudDocumento documento:this.lrecord){ //modifiedData['verificador']
if(documento.getModifiedData().get("verificador")!=null && documento.getModifiedData().get("verificador").toString().equals("true")){
return true;
}
}
return false;
}
/**
* M&eacute;todo que envia cada registro a la cola de impresi&oacute;n cuando el
* tipo de autorizaci&oacute;n es PERMISO
* @throws Exception
*/
public void enviaColaImpresion() throws Exception{
for(TarmSolicitudDocumento documento:this.lrecord){
if(documento.getModifiedData().get("verificador").equals(Boolean.TRUE)){
TarmDocumentoHabilitante habilitante = DocumentoHabilitanteController.findPorCDocumento(documento.getPk().getCdocumento().toString());
TarmTramite tramite = TarmTramiteController.findSimple(String.valueOf(habilitante.getCtramite()));
if(tramite == null || tramite.getTipoarchivo()==null || tramite.getTipoarchivo().isEmpty() || tramite.getTipoarchivocodigo()==null || tramite.getTipoarchivocodigo().isEmpty() ){
throw new Exception();
}
TgeneCatalogDetail tipoArchivoTramite = CatalogDetailController.findxCodigoCodcatalogo(tramite.getTipoarchivo(), tramite.getTipoarchivocodigo());
if( "CARNET".equalsIgnoreCase(tipoArchivoTramite.getDescription())){//
// Verifico si el documento se encuentra en cola de impresion
List<TarmColadeImpresion>documentosEnColaList = ColaImpresionController.findByDocumentoEstado(habilitante.getPk().toString(),"PIMPR");
if(documentosEnColaList==null || documentosEnColaList.size()==0){
esCola=true;
TarmColadeImpresion colaimpr = new TarmColadeImpresion();
colaimpr.setCdocumento(habilitante.getPk());
colaimpr.setEstadoimpresion("PIMPR");
colaimpr.setEstadoimpresioncode("ESTADOIMPRESION");
colaimpr.setFecharegistro(habilitante.getFechaemision());
colaimpr.setIsnew(Boolean.TRUE);
colaImpresionController.update(colaimpr);
}
}
}
}
}
public Boolean getVerifica() {
return verifica;
}
public void setVerifica(Boolean verifica) {
this.verifica = verifica;
}
public SolicitudController getSolicitudController() {
return solicitudController;
}
public void setSolicitudController(SolicitudController solicitudController) {
this.solicitudController = solicitudController;
}
public String getCsolicitud() {
return csolicitud;
}
public void setCsolicitud(String csolicitud) {
this.csolicitud = csolicitud;
}
public RecepcionArmasController getRecepcionArmasController() {
return recepcionArmasController;
}
public void setRecepcionArmasController(
RecepcionArmasController recepcionArmasController) {
this.recepcionArmasController = recepcionArmasController;
}
public DocumentoHabilitanteController getDocHabilitanteController() {
return docHabilitanteController;
}
public void setDocHabilitanteController(
DocumentoHabilitanteController docHabilitanteController) {
this.docHabilitanteController = docHabilitanteController;
}
public ColaImpresionController getColaImpresionController() {
return colaImpresionController;
}
public void setColaImpresionController(
ColaImpresionController colaImpresionController) {
this.colaImpresionController = colaImpresionController;
}
public boolean isBtnFlujo() {
return btnFlujo;
}
public void setBtnFlujo(boolean btnFlujo) {
this.btnFlujo = btnFlujo;
}
public boolean isEsCola() {
return esCola;
}
public void setEsCola(boolean esCola) {
this.esCola = esCola;
}
}