400 lines
11 KiB
Plaintext
Executable File
400 lines
11 KiB
Plaintext
Executable File
package com.fp.frontend.controller.pgeneral.gene;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.bean.ManagedBean;
|
|
import javax.faces.bean.ManagedProperty;
|
|
import javax.faces.bean.ViewScoped;
|
|
|
|
import org.primefaces.event.SelectEvent;
|
|
import org.primefaces.event.TabChangeEvent;
|
|
|
|
import com.fp.dto.AbstractDataTransport;
|
|
import com.fp.dto.Request;
|
|
import com.fp.dto.Response;
|
|
import com.fp.dto.save.DtoSave;
|
|
import com.fp.frontend.controller.AbstractController;
|
|
import com.fp.frontend.controller.pgeneral.acco.AccountStatusController;
|
|
import com.fp.frontend.controller.pgeneral.lov.BalanceTypeLovController;
|
|
import com.fp.frontend.controller.pgeneral.product.ModuleController;
|
|
import com.fp.frontend.controller.pgeneral.product.ProductController;
|
|
import com.fp.frontend.controller.pgeneral.product.SubProductController;
|
|
import com.fp.frontend.helper.MessageHelper;
|
|
import com.fp.persistence.pgeneral.acco.TgeneAccountStatus;
|
|
import com.fp.persistence.pgeneral.gene.TgeneBalanceType;
|
|
import com.fp.persistence.pgeneral.gene.TgeneCurrency;
|
|
import com.fp.persistence.pgeneral.product.TgeneModule;
|
|
import com.fp.persistence.pgeneral.product.TgeneProduct;
|
|
import com.fp.persistence.pgeneral.product.TgeneSubProduct;
|
|
|
|
/**
|
|
* Clase controladora de definicion de cargos generales y cargos por subproducto.
|
|
*
|
|
* @author Jorge Vaca.
|
|
* @version 2.1
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
@ManagedBean
|
|
@ViewScoped
|
|
public class ChargesDefinitionController extends AbstractController<AbstractDataTransport> {
|
|
|
|
public ChargesDefinitionController() throws Exception {
|
|
super(AbstractDataTransport.class);
|
|
}
|
|
|
|
@ManagedProperty(value = "#{chargesController}")
|
|
private ChargesController charges;
|
|
|
|
@ManagedProperty(value = "#{subProductChargesController}")
|
|
private SubProductChargesController subproduct;
|
|
|
|
/**
|
|
* Id del tab activo.
|
|
*/
|
|
private String tabid = "charges";
|
|
|
|
/**
|
|
* Atributo lista de objetos TgeneModule
|
|
*/
|
|
private List<TgeneModule> lmodules;
|
|
|
|
/**
|
|
* Lista de estatus de cuentas asociados a un modulo.
|
|
*/
|
|
private List<TgeneAccountStatus> laccountstatus;
|
|
|
|
/**
|
|
* Atributo para la lista de objetos TgeneCurrency
|
|
*/
|
|
private List<TgeneCurrency> lcurrency;
|
|
|
|
/**
|
|
* Atributo V/F render button
|
|
*/
|
|
private boolean active;
|
|
|
|
/**
|
|
* Lista de productos pertenecientes a un modulo.
|
|
*/
|
|
private List<TgeneProduct> lproduct;
|
|
/**
|
|
* Lista de subproductos pertenecientes al producto.
|
|
*/
|
|
private List<TgeneSubProduct> lsubproduct;
|
|
|
|
@PostConstruct
|
|
private void postconstruct() {
|
|
this.init();
|
|
// Inicializa autoconsulta
|
|
super.startQuery();
|
|
|
|
}
|
|
|
|
/**
|
|
* Incializa el controlador, cuando se esta utilizando una pagina que utliza el controlador.
|
|
*/
|
|
private void init() {
|
|
try {
|
|
this.lmodules = ModuleController.find();
|
|
this.lcurrency = CurrencyController.find();
|
|
} catch (Exception e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
public void onTabChange(TabChangeEvent event) throws Exception {
|
|
this.tabid = event.getTab().getId();
|
|
if(this.tabid.equals("charges")){
|
|
this.active = false;
|
|
}else{
|
|
this.active = true;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public void query() {
|
|
try {
|
|
if(this.tabid.equals("charges") ){
|
|
this.charges.query();
|
|
}else {
|
|
this.subproduct.query();
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void next() {
|
|
try {
|
|
try {
|
|
if(this.tabid.equals("charges") ){
|
|
this.charges.next();
|
|
}else {
|
|
this.subproduct.next();
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void previous() {
|
|
try {
|
|
if(this.tabid.equals("charges") ){
|
|
this.charges.previous();
|
|
}else {
|
|
this.subproduct.previous();
|
|
}
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void save(){
|
|
try {
|
|
Request request = this.callerhelper.getRequest();
|
|
HashMap<String, DtoSave> msave = new HashMap<String, DtoSave>();
|
|
|
|
DtoSave dtosaveprod = this.charges.getDtoSave();
|
|
if(dtosaveprod.pendingProcess()){
|
|
dtosaveprod.setReturnpk(true);
|
|
msave.put(this.charges.getBeanalias(), dtosaveprod); // adicionar metadata de mantenimiento para cada tabla.
|
|
}
|
|
DtoSave dtosavesubpro = this.subproduct.getDtoSave();
|
|
if(dtosavesubpro.pendingProcess()){
|
|
dtosavesubpro.setReturnpk(true);
|
|
msave.put(this.subproduct.getBeanalias(), dtosavesubpro); // adicionar metadata de mantenimiento para cada tabla.
|
|
}
|
|
|
|
request.setSaveTables(msave);
|
|
Response resp = this.callerhelper.executeSave(request);
|
|
if (resp.getResponseCode().compareTo(Response.RESPONSE_OK) == 0) {
|
|
this.charges.postCommit(resp);
|
|
this.subproduct.postCommit(resp);
|
|
MessageHelper.setMessageInfo(resp);
|
|
} else {
|
|
MessageHelper.setMessageError(resp);
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
MessageHelper.setMessageError(e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void querydatabase() {
|
|
}
|
|
|
|
@Override
|
|
public void postCommit(Response response) throws Exception {
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Actualzia el campo modulecode en cada controlador que esta inyectado. La actualizacion se realiza cuando cambia el modulo en la pantalla.
|
|
* @throws Exception
|
|
*/
|
|
public void updatemodule() throws Exception {
|
|
String modulecode = super.getMfilters().get("pk.modulecode");
|
|
this.charges.addFilter("pk.modulecode", modulecode);
|
|
this.subproduct.addFilter("pk.modulecode", modulecode);
|
|
this.subproduct.addFilter("pk.productcode", null);
|
|
this.subproduct.addFilter("pk.subproductcode", null);
|
|
this.getProducts();
|
|
laccountstatus = AccountStatusController.find(modulecode);
|
|
this.charges.setLrecord(null);
|
|
}
|
|
|
|
/**
|
|
* Refresca la lista de productos dado un codigo de modulo.
|
|
* @param modulecode Codigo de modulo.
|
|
* @throws Exception
|
|
*/
|
|
public void getProducts() {
|
|
try{
|
|
if(super.getMfilters().get("pk.modulecode")!=null){
|
|
this.lproduct = ProductController.find(super.getMfilters().get("pk.modulecode"));
|
|
this.lsubproduct = new ArrayList<>();
|
|
this.subproduct.setLrecord(null);
|
|
}else{
|
|
this.lproduct = new ArrayList<>();
|
|
this.lsubproduct = new ArrayList<>();
|
|
this.subproduct.setLrecord(null);
|
|
}
|
|
}catch(Exception ex){
|
|
MessageHelper.setMessageError(ex);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Refresca lista de subproductos, dado el codigo de modulo y de producto.
|
|
* @param modulecode Codigo de modulo.
|
|
* @param productcode Codigo de producto.
|
|
* @throws Exception
|
|
*/
|
|
public void getSubProducts() {
|
|
try{
|
|
if(super.getMfilters().get("pk.productcode")!=null){
|
|
this.subproduct.addFilter("pk.productcode", super.getMfilters().get("pk.productcode"));
|
|
this.lsubproduct = SubProductController.find( super.getMfilters().get("pk.modulecode"), super.getMfilters().get("pk.productcode"));
|
|
this.subproduct.setLrecord(null);
|
|
}else{
|
|
this.lsubproduct = new ArrayList<>();
|
|
this.subproduct.addFilter("pk.productcode", null);
|
|
}
|
|
|
|
}catch(Exception ex){
|
|
MessageHelper.setMessageError(ex);
|
|
}
|
|
}
|
|
|
|
public void refreshSubProduct(){
|
|
if(super.getMfilters().get("pk.subproductcode")!=null){
|
|
this.subproduct.addFilter("pk.subproductcode", super.getMfilters().get("pk.subproductcode"));
|
|
}else{
|
|
this.subproduct.addFilter("pk.subproductcode", null);
|
|
this.subproduct.setLrecord(null);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Lov de tipos de saldo.
|
|
*/
|
|
public void openBalancetypeLov() {
|
|
Map<String, List<String>> params = new HashMap<>();
|
|
List<String> l = new ArrayList<>();
|
|
l.add(super.getMfilters().get("pk.modulecode").toString());
|
|
|
|
params.put("modulecode", l);
|
|
List<String> lcat = new ArrayList<>();
|
|
lcat.add("CHARGES");
|
|
params.put("category", lcat);
|
|
BalanceTypeLovController.openLov(params);
|
|
}
|
|
|
|
/**
|
|
* Fija datos del tipo de saldo al cerrar el lov.
|
|
* @param event
|
|
* @throws Exception
|
|
*/
|
|
public void onReturnBalancetypeLovCharges(SelectEvent event) throws Exception {
|
|
TgeneBalanceType t = (TgeneBalanceType) event.getObject();
|
|
this.charges.getRecord().getPk().setBalancetype(t.getPk().getBalancetype());
|
|
this.charges.getRecord().getPk().setBalancegroup(t.getPk().getBalancegroup());
|
|
}
|
|
|
|
/**
|
|
* Fija datos del tipo de saldo al cerrar el lov.
|
|
* @param event
|
|
* @throws Exception
|
|
*/
|
|
public void onReturnBalancetypeLovSub(SelectEvent event) throws Exception {
|
|
TgeneBalanceType t = (TgeneBalanceType) event.getObject();
|
|
this.subproduct.getRecord().getPk().setBalancetype(t.getPk().getBalancetype());
|
|
this.subproduct.getRecord().getPk().setBalancegroup(t.getPk().getBalancegroup());
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: lmodules
|
|
* @return List<TgeneModule>
|
|
*/
|
|
public List<TgeneModule> getLmodules() {
|
|
return this.lmodules;
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: charges
|
|
* @return ChargesController
|
|
*/
|
|
public ChargesController getCharges() {
|
|
return this.charges;
|
|
}
|
|
|
|
/**
|
|
* Fija el valor de: charges
|
|
* @param charges Valor a fijar en el atributo.
|
|
*/
|
|
|
|
public void setCharges(ChargesController charges) {
|
|
this.charges = charges;
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: subproduct
|
|
* @return SubProductChargesController
|
|
*/
|
|
public SubProductChargesController getSubproduct() {
|
|
return this.subproduct;
|
|
}
|
|
|
|
/**
|
|
* Fija el valor de: subproduct
|
|
* @param subproduct Valor a fijar en el atributo.
|
|
*/
|
|
|
|
public void setSubproduct(SubProductChargesController subproduct) {
|
|
this.subproduct = subproduct;
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: laccountstatus
|
|
* @return List<TgeneAccountStatus>
|
|
*/
|
|
public List<TgeneAccountStatus> getLaccountstatus() {
|
|
return this.laccountstatus;
|
|
}
|
|
|
|
|
|
/**
|
|
* Entrega el valor de: lcurrency
|
|
* @return List<TgeneCurrency>
|
|
*/
|
|
public List<TgeneCurrency> getLcurrency() {
|
|
return this.lcurrency;
|
|
}
|
|
|
|
/**
|
|
* Entrega V/F si es activo
|
|
* @return active
|
|
*/
|
|
public boolean isActive() {
|
|
return active;
|
|
}
|
|
|
|
/**
|
|
* Fina V/F si es activo o no
|
|
* @param active
|
|
*/
|
|
public void setActive(boolean active) {
|
|
this.active = active;
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: lproduct
|
|
* @return List<TgeneProduct>
|
|
*/
|
|
public List<TgeneProduct> getLproduct() {
|
|
return lproduct;
|
|
}
|
|
|
|
/**
|
|
* Entrega el valor de: lsubproduct
|
|
* @return List<TgeneSubProduct>
|
|
*/
|
|
public List<TgeneSubProduct> getLsubproduct() {
|
|
return lsubproduct;
|
|
}
|
|
}
|