package com.fp.frontend.controller.armas.solicitud; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import com.fp.dto.Request; import com.fp.dto.Response; import com.fp.dto.query.DtoQuery; import com.fp.dto.query.Filter; import com.fp.dto.query.SubQuery; import com.fp.dto.save.DtoSave; import com.fp.frontend.controller.AbstractController; import com.fp.frontend.controller.pcustomer.PersonDetailController; import com.fp.frontend.helper.MessageHelper; import com.fp.persistence.parmas.ins.TarmPlanificacionTramite; import com.fp.persistence.parmas.param.TarmTramite; import com.fp.persistence.parmas.soli.TarmDocumentoHabilitante; import com.fp.persistence.parmas.soli.TarmSolicitudTramite; import com.fp.persistence.pcustomer.gene.TcustPersonDetail; @SuppressWarnings("serial") @ManagedBean @ViewScoped public class PlanificacionTramiteController extends AbstractController { /** * */ private static final long serialVersionUID = 1L; private Long cplanificacion; public String Periodo; public PlanificacionTramiteController() throws Exception { super(TarmPlanificacionTramite.class); // TODO Auto-generated constructor stub } @PostConstruct private void postconstruct() { this.init(); super.startQuery(); } private void init() { try { recperpage = 15; // Cambiar al # reg a mirar. lrecord = new ArrayList<>(); beanalias = "PLANIFICACIONTRAMITECONTROLLER"; } catch (Exception e) { MessageHelper.setMessageError(e); } } @Override public void query() throws Exception { // TODO Auto-generated method stub MessageHelper.setMessageError("msg_notQuery"); super.query(); } @Override public void create() throws Exception { super.create(); } @SuppressWarnings("unchecked") @Override protected void querydatabase() { try { DtoQuery dto = super.getDtoQuery(true); HashMap mtables = new HashMap(); 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(); MessageHelper.setMessageError(resp); } else { lrecord = (List) resp.get(beanalias); if(!lrecord.isEmpty()){ record=lrecord.get(0); } super.postQuery(lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } /** * Busca las inspecciones solo para la Tarea de Aprobacion */ @SuppressWarnings("unchecked") protected void querydatabaseAprobacion() { try { DtoQuery dto = super.getDtoQuery(true); // //Nombre/Razon social SubQuery subqueryNombre= new SubQuery("TcustPersonDetail","name","nombre", "i.pk.personcode=(select o.personcode from TarmDocumentoHabilitante o where o.pk=t.cdocumento) and" + " i.pk.dateto = to_date('2999-12-31', 'YYYY-MM-DD')"); dto.addSubQuery(subqueryNombre); SubQuery subqueryNDocumento=new SubQuery("TcustPersonDetail","identification","nodocumento", "i.pk.personcode=(select o.personcode from TarmDocumentoHabilitante o where o.pk=t.cdocumento) and" + " i.pk.dateto = to_date('2999-12-31', 'YYYY-MM-DD')"); dto.addSubQuery(subqueryNDocumento); // //datos del tramite // //Tipo de tramite SubQuery subqueryTipoTramite= new SubQuery("TgeneCatalogDetail","description","tipotramite","i.pk.catalog= (select o.tipotramite from TarmTramite o where o.pk=t.ctramite) and" + " i.pk.catalogcode=(select o.tipotramitecodigo from TarmTramite o where o.pk=t.ctramite)"); dto.addSubQuery(subqueryTipoTramite); SubQuery subqueryTramite= new SubQuery("TgeneCatalogDetail","description","tipoautorizacion","i.pk.catalog= (select o.tipoautorizacion from TarmTramite o where o.pk=t.ctramite) and" + " i.pk.catalogcode=(select o.tipoautorizacioncodigo from TarmTramite o where o.pk=t.ctramite) "); dto.addSubQuery(subqueryTramite); // //Uso/Actividad SubQuery subqueryUsoActividad= new SubQuery("TgeneCatalogDetail","description","usoactividad","i.pk.catalog= (select o.usoactividad from TarmTramite o where o.pk=t.ctramite) and" + " i.pk.catalogcode=(select o.usoactividadcodigo from TarmTramite o where o.pk=t.ctramite)"); dto.addSubQuery(subqueryUsoActividad); // //Categoria SubQuery subqueryCategoria= new SubQuery("TgeneCatalogDetail","description","categoria","i.pk.catalog= (select o.categoria from TarmTramite o where o.pk=t.ctramite) and" + " i.pk.catalogcode=(select o.categoriacodigo from TarmTramite o where o.pk=t.ctramite)"); dto.addSubQuery(subqueryCategoria); SubQuery subqueryCodTramite=new SubQuery("TarmDocumentoHabilitante", "fechaexpiracion", "fechacaducidad", "i.pk= t.cdocumento"); dto.addSubQuery(subqueryCodTramite); //Filtro de codigo de planificacion if(this.cplanificacion!=null){ dto.addFiltro(new Filter("cplanificacion", this.cplanificacion.toString())); } HashMap mtables = new HashMap(); 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(); MessageHelper.setMessageError(resp); } else { lrecord = (List) resp.get(beanalias); if(!lrecord.isEmpty()){ record=lrecord.get(0); for (TarmPlanificacionTramite inspeccion : this.lrecord) { Calendar calendario=Calendar.getInstance(); SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy"); Integer dia=calendario.get(Calendar.DAY_OF_MONTH); Integer mes=calendario.get(Calendar.MONTH); Integer anno=calendario.get(Calendar.YEAR); //Fecha actual java.util.Date fechaActual=sdf.parse(dia.toString()+"-"+mes.toString()+"-"+anno.toString()); //Fecha expiracion calendario.setTime((Date)inspeccion.getModifiedData().get("fechacaducidad")); dia=calendario.get(Calendar.DAY_OF_MONTH); mes=calendario.get(Calendar.MONTH); anno=calendario.get(Calendar.YEAR); java.util.Date fechaExpiracion=sdf.parse(dia.toString()+"-"+mes.toString()+"-"+anno.toString()); //Asignando el estado del tramite Caducada o Vigente if(fechaExpiracion.compareTo(fechaActual)<0){ inspeccion.getModifiedData().put("estado", "Caducada"); }else{ inspeccion.getModifiedData().put("estado", "Vigente"); } inspeccion.getModifiedData().put("presupuesto", inspeccion.getPresupuesto()); inspeccion.getModifiedData().put("inspectores", this.record.getInspectores()); // } } } super.postQuery(lrecord); } } catch (Throwable e) { MessageHelper.setMessageError(e); } } @Override public void save() { try { DtoSave dtosave = super.getDtoSave(); dtosave.setReturnpk(true); // Para que el core devuelva el pk de los registros nuevos. HashMap msave = new HashMap(); Request request = callerhelper.getRequest(); msave.put(beanalias, dtosave); // adicionar metadata de mantenimiento para cada tabla. request.setSaveTables(msave); Response resp = callerhelper.executeSave(request); if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) { this.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); } @Override public void update() throws Exception { try { if(this.record.getMes().equalsIgnoreCase("Enero")){ this.record.setMesnumero(0L); }else if(this.record.getMes().equalsIgnoreCase("Febrero")){ this.record.setMesnumero(1L); }else if(this.record.getMes().equalsIgnoreCase("Marzo")){ this.record.setMesnumero(2L); }else if(this.record.getMes().equalsIgnoreCase("Abril")){ this.record.setMesnumero(3L); }else if(this.record.getMes().equalsIgnoreCase("Mayo")){ this.record.setMesnumero(4L); }else if(this.record.getMes().equalsIgnoreCase("Junio")){ this.record.setMesnumero(5L); }else if(this.record.getMes().equalsIgnoreCase("Julio")){ this.record.setMesnumero(6L); }else if(this.record.getMes().equalsIgnoreCase("Agosto")){ this.record.setMesnumero(7L); }else if(this.record.getMes().equalsIgnoreCase("Spetiembre")){ this.record.setMesnumero(8L); }else if(this.record.getMes().equalsIgnoreCase("Octubre")){ this.record.setMesnumero(9L); }else if(this.record.getMes().equalsIgnoreCase("Noviembre")){ this.record.setMesnumero(10L); }else if(this.record.getMes().equalsIgnoreCase("Diciembre")){ this.record.setMesnumero(11L); } // this.record.setPeriodo("hola1"); super.update(); //ordenarPorMesNombre(); } catch (Exception e) { MessageHelper.setMessageError(e); } } /** * Busca las las inspecciones de una planificacion dado su codigo * @param codigoSolicitud * @return */ public static List findPorCodigoPlanificacion(Long cplanificacion) { try { PlanificacionTramiteController cc = new PlanificacionTramiteController(); cc.init(); cc.recperpage = 300; cc.addFilter("cplanificacion", cplanificacion.toString()); cc.querydatabase(); if (cc.lrecord != null) { return cc.lrecord; } return null; } catch (Throwable e) { MessageHelper.setMessageError(e); return null; } } /** * Metodo apara actualizar el registro * @throws Exception */ public void actualizar(TarmPlanificacionTramite planificacionTramite) throws Exception{ record=planificacionTramite; super.update(); } public Long getCplanificacion() { return cplanificacion; } public void setCplanificacion(Long cplanificacion) { this.cplanificacion = cplanificacion; } public static long getSerialversionuid() { return serialVersionUID; } public String getPeriodo() { return Periodo; } public void setPeriodo(String Periodo) { this.Periodo = Periodo; } }