260 lines
9.0 KiB
Plaintext
Executable File
260 lines
9.0 KiB
Plaintext
Executable File
package com.fp.frontend.controller.armas.solicitud;
|
|
|
|
import java.util.ArrayList;
|
|
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 javax.faces.event.AjaxBehaviorEvent;
|
|
|
|
import com.fp.common.logger.APPLogger;
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.query.DtoQuery;
|
|
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.CantonController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CatalogDetailController;
|
|
import com.fp.frontend.controller.pgeneral.gene.CityController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ParroquiaController;
|
|
import com.fp.frontend.controller.pgeneral.gene.ProvinceController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.parmas.soli.TarmAgenciaSucursal;
|
|
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.TgeneParroquia;
|
|
import com.fp.persistence.pgeneral.gene.TgeneProvince;
|
|
|
|
/**
|
|
* Controlador que maneja la entidad de {@link TarmAgenciaSucursal}
|
|
* @author dcruz
|
|
*
|
|
*/
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class AgenciaSucursalController extends
|
|
AbstractController<TarmAgenciaSucursal> {
|
|
|
|
private List<TgeneCatalogDetail> estadoAgencias;
|
|
private List<TgeneCatalogDetail> tipoAgencias;
|
|
private List<TgeneProvince> lprovincias;
|
|
private List<TgeneCanton> lcantones;
|
|
private List<TgeneParroquia> lparroquias;
|
|
private List<TgeneCity> lcities;
|
|
|
|
private static final long serialVersionUID = 4621335239110508027L;
|
|
|
|
public AgenciaSucursalController() throws Exception{
|
|
super(TarmAgenciaSucursal.class);
|
|
}
|
|
|
|
@PostConstruct
|
|
public void postConstruct() {
|
|
this.init();
|
|
super.startQuery();
|
|
}
|
|
|
|
private void init(){
|
|
this.beanalias = "AGENCIASUCURSAL";
|
|
this.lrecord = new ArrayList<>();
|
|
this.recperpage = 15;
|
|
this.estadoAgencias = CatalogDetailController.find("ESTADOAGENCIA");
|
|
this.tipoAgencias = CatalogDetailController.find("TIPOAGENCIA");
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
protected void querydatabase() {
|
|
try {
|
|
DtoQuery dto = this.getDtoQuery();
|
|
HashMap<String, DtoQuery> mtables = new HashMap<String, DtoQuery>();
|
|
mtables.put(beanalias, dto);//se puede aniadir mas tablas
|
|
Request request = callerhelper.getRequest();
|
|
request.setQueryTables(mtables);
|
|
Response response = callerhelper.executeQuery(request);
|
|
if(response.getResponseCode().compareTo(Response.RESPONSE_OK) != 0){
|
|
this.lrecord = new ArrayList<>();
|
|
MessageHelper.setMessageError(response);
|
|
} else{
|
|
this.lrecord = (List<TarmAgenciaSucursal>) response.get(beanalias);
|
|
this.postQuery(lrecord);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void save() {
|
|
try {
|
|
DtoSave dto = super.getDtoSave();
|
|
if(!dto.pendingProcess()){
|
|
return;
|
|
}
|
|
dto.setReturnpk(Boolean.TRUE);
|
|
HashMap<String, DtoSave> msaves = new HashMap<String, DtoSave>();
|
|
msaves.put(beanalias, dto);
|
|
Request request = callerhelper.getRequest();
|
|
request.setSaveTables(msaves);
|
|
Response response = callerhelper.executeSave(request);
|
|
if(response.getResponseCode().compareTo(Response.RESPONSE_OK) == 0){
|
|
this.postCommit(response);
|
|
MessageHelper.setMessageInfo(response);
|
|
} else{
|
|
MessageHelper.setMessageError(response);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public DtoQuery getDtoQuery() throws Exception {
|
|
DtoQuery dto = super.getDtoQuery(Boolean.TRUE);
|
|
SubQuery subQueryTipo = new SubQuery("TgeneCatalogDetail", "description", "ntipo", "i.pk.catalog=t.tipo and i.pk.catalogcode=t.tipocodigo");
|
|
dto.addSubQuery(subQueryTipo);
|
|
SubQuery subQueryEstado = new SubQuery("TgeneCatalogDetail", "description", "nestado", "i.pk.catalog=t.estado and i.pk.catalogcode=t.estadocodigo");
|
|
dto.addSubQuery(subQueryEstado);
|
|
SubQuery subQueryProvincia = new SubQuery("TgeneProvince", "description", "nprovincia", "i.pk.provincecode=t.provincecode and i.pk.countrycode=t.countrycode");
|
|
dto.addSubQuery(subQueryProvincia);
|
|
SubQuery subQueryCanton = new SubQuery("TgeneCanton", "description", "ncanton", "i.pk.countrycode=t.countrycode and i.pk.provincecode=t.provincecode and i.pk.cantoncode=t.cantoncode");
|
|
dto.addSubQuery(subQueryCanton);
|
|
SubQuery subQueryParroquia = new SubQuery("TgeneParroquia", "description", "nparroquia", "i.pk.countrycode=t.countrycode and i.pk.provincecode=t.provincecode and i.pk.cantoncode=t.cantoncode and i.pk.parroquiacode=t.parroquiacode");
|
|
dto.addSubQuery(subQueryParroquia);
|
|
SubQuery subQueryCiudad = new SubQuery("TgeneCity", "description", "nciudad", "i.pk.countrycode=t.countrycode and i.pk.provincecode=t.provincecode and i.pk.cantoncode=t.cantoncode and i.pk.citycode=t.citycode");
|
|
dto.addSubQuery(subQueryCiudad);
|
|
return dto;
|
|
}
|
|
|
|
public void loadEdit() {
|
|
lprovincias = ProvinceController.find(record.getCountrycode());
|
|
lcantones = CantonController.find(record.getCountrycode(), record.getProvincecode());
|
|
lparroquias = ParroquiaController.find(record.getCountrycode(), record.getProvincecode(), record.getCantoncode());
|
|
lcities = CityController.find(record.getCountrycode(), record.getProvincecode(), record.getCantoncode());
|
|
}
|
|
|
|
@Override
|
|
public void create() throws Exception {
|
|
super.create();
|
|
this.record.setCountrycode("EC");
|
|
this.record.setTipocodigo("TIPOAGENCIA");
|
|
this.record.setEstadocodigo("ESTADOAGENCIA");
|
|
this.record.setFautorizacion(new Date());
|
|
if(this.record.isnew){
|
|
this.record.setEstado("REG");
|
|
}
|
|
this.lprovincias = ProvinceController.find(record.getCountrycode());
|
|
this.executeProvince();
|
|
}
|
|
|
|
/**
|
|
* Método para el evento change del combo provincias
|
|
*/
|
|
public void executeProvince() {
|
|
if ((record.getCountrycode() != null) && (record.getCountrycode().compareTo("") != 0)) {
|
|
lcantones = CantonController.find(record.getCountrycode(), record.getProvincecode());
|
|
lparroquias = new ArrayList<>();
|
|
lcities = new ArrayList<>();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Método para el evento change del combo cantones
|
|
*/
|
|
public void executeCanton() {
|
|
if ((record.getCountrycode() != null) && (record.getCountrycode().compareTo("") != 0)) {
|
|
lparroquias = ParroquiaController.find(record.getCountrycode(), record.getProvincecode(), record.getCantoncode());
|
|
lcities = CityController.find(record.getCountrycode(), record.getProvincecode(), record.getCantoncode());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Seleccionado todos los registros de la tabla
|
|
*/
|
|
public void seleccionarTodos(AjaxBehaviorEvent event) {
|
|
try {
|
|
Boolean valorColocar = Boolean.FALSE;
|
|
if(Boolean.valueOf(event.getComponent().getAttributes().get("value") != null ? event.getComponent().getAttributes().get("value").toString() : "false")){
|
|
valorColocar = Boolean.TRUE;
|
|
}
|
|
for (TarmAgenciaSucursal agenciaSucursal : lrecord) {
|
|
agenciaSucursal.getModifiedData().put("seleccionado", valorColocar);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public static TarmAgenciaSucursal find(String cagencia) {
|
|
TarmAgenciaSucursal agenciaSucursal = null;
|
|
try {
|
|
AgenciaSucursalController cc = new AgenciaSucursalController();
|
|
cc.addFilter("pk", cagencia);
|
|
cc.init();
|
|
cc.recperpage = 300;
|
|
cc.query();
|
|
if ((cc.lrecord != null) && !cc.lrecord.isEmpty()) {
|
|
agenciaSucursal = cc.lrecord.get(0);
|
|
}
|
|
return agenciaSucursal;
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
return agenciaSucursal;
|
|
}
|
|
}
|
|
|
|
public List<TgeneCatalogDetail> getEstadoAgencias() {
|
|
return estadoAgencias;
|
|
}
|
|
|
|
public void setEstadoAgencias(List<TgeneCatalogDetail> estadoAgencias) {
|
|
this.estadoAgencias = estadoAgencias;
|
|
}
|
|
|
|
public List<TgeneCatalogDetail> getTipoAgencias() {
|
|
return tipoAgencias;
|
|
}
|
|
|
|
public void setTipoAgencias(List<TgeneCatalogDetail> tipoAgencias) {
|
|
this.tipoAgencias = tipoAgencias;
|
|
}
|
|
|
|
public List<TgeneProvince> getLprovincias() {
|
|
return lprovincias;
|
|
}
|
|
|
|
public void setLprovincias(List<TgeneProvince> lprovincias) {
|
|
this.lprovincias = lprovincias;
|
|
}
|
|
|
|
public List<TgeneCanton> getLcantones() {
|
|
return lcantones;
|
|
}
|
|
|
|
public void setLcantones(List<TgeneCanton> lcantones) {
|
|
this.lcantones = lcantones;
|
|
}
|
|
|
|
public List<TgeneParroquia> getLparroquias() {
|
|
return lparroquias;
|
|
}
|
|
|
|
public void setLparroquias(List<TgeneParroquia> lparroquias) {
|
|
this.lparroquias = lparroquias;
|
|
}
|
|
|
|
public List<TgeneCity> getLcities() {
|
|
return lcities;
|
|
}
|
|
|
|
public void setLcities(List<TgeneCity> lcities) {
|
|
this.lcities = lcities;
|
|
}
|
|
|
|
}
|