package com.fp.persistence.pgeneral.charge; import java.io.Serializable; import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.List; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.NoResultException; import javax.persistence.Query; import javax.persistence.Table; import javax.persistence.Transient; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; import com.fp.dto.hb.HibernateBean; /** Clase que implementa la entidad de Hibernate que hace referencia a la tabla TGENESUBPRODUCTCHARGES */ @Entity(name = "TgeneSubProductCharges") @Table(name = "TGENESUBPRODUCTCHARGES") public class TgeneSubProductCharges extends com.fp.dto.AbstractDataTransport implements Serializable, HibernateBean, Cloneable { /** * HashCode asociado con la Instancia */ @Transient private int hashValue = 0; /** * Version de la Clase */ private static final long serialVersionUID = 1L; /** * Clave primaria de la Entidad TgeneSubProductCharges */ @EmbeddedId @GenericGenerator(name = "seq_id", strategy = "com.fp.general.keygen.SubSequenceKey", parameters = { @Parameter(name = "sql", value = "select coalesce(max(RATESEQUENCE),0)+1 from TGENESUBPRODUCTCHARGES " + "where BALANCETYPE=:btype " + "and BALANCEGROUP=:bgroup " + "and MODULECODE=:modulecode " + "and PRODUCTCODE=:productcode " + "and SUBPRODUCTCODE=:subproductcode " + "and STATUSCODE=:statuscode " + "and COMPANYCODE=:companycode " + "and CURRENCYCODE = :currencycode"), @Parameter(name = "type", value = "java.lang.Integer"), @Parameter(name = "param", value = "btype,pk.balancetype;bgroup,pk.balancegroup;modulecode,pk.modulecode;productcode,pk.productcode;subproductcode,pk.subproductcode;statuscode,pk.statuscode;companycode,pk.companycode;currencycode,pk.currencycode"), @Parameter(name = "field", value = "ratesequence") }) @GeneratedValue(generator = "seq_id") private TgeneSubProductChargesKey pk; @Column(name = "CHARGECURRENCYCODE", nullable = true) /** * Codigo de moneda en la que esta expresado el cargo */ private String chargecurrencycode; @Column(name = "RATE", nullable = true) /** * Tasa anual a aplicar */ private BigDecimal rate; @Column(name = "PERCENT", nullable = true) /** * Porcentaje flat a aplicar */ private BigDecimal percent; @Column(name = "MINVALUE", nullable = true) /** * Valor minimo a cobrar */ private BigDecimal minvalue; @Column(name = "MAXVALUE", nullable = true) /** * Valor maximo a cobrar */ private BigDecimal maxvalue; @Column(name = "MINAMOUNT", nullable = false) /** * Monto minimo para buscar el cargo */ private BigDecimal minamount; @Column(name = "MAXAMOUNT", nullable = true) /** * Monto maximo para buscar el cargo */ private BigDecimal maxamount; /** Contructor por defecto */ public TgeneSubProductCharges() { } /** * Contructor de TgeneSubProductCharges * * @param pPk Clave Primaria del entity * @param pMinamount Monto minimo para buscar el cargo */ public TgeneSubProductCharges(TgeneSubProductChargesKey pPk, BigDecimal pMinamount) { this(); this.pk = pPk; this.minamount = pMinamount; } /** * Metodo que entrega datos de la tabla dada la clave primaria. * * @param pEntityManager referencia de la session a obtener datos del bean. * @param pKey Caleve primaria del bean. * @return TgeneSubProductCharges */ public static TgeneSubProductCharges find(EntityManager pEntityManager, TgeneSubProductChargesKey pKey) throws Exception { TgeneSubProductCharges obj = pEntityManager.find(TgeneSubProductCharges.class, pKey); return obj; } /** * Entrega la Clave primaria de TgeneSubProductCharges * * @return El objeto que referencia a la Clave primaria de TgeneSubProductCharges */ public TgeneSubProductChargesKey getPk() { return this.pk; } /** * Fija un nuevo valor a la Clave primaria de TgeneSubProductCharges * * @param pPk El objeto que referencia a la nueva Clave primaria de TgeneSubProductCharges */ public void setPk(TgeneSubProductChargesKey pPk) { this.pk = pPk; } /** * Obtiene el valor de chargecurrencycode * * @return valor de chargecurrencycode */ public String getChargecurrencycode() { return this.chargecurrencycode; } /** * Fija el valor de chargecurrencycode * * @param pChargecurrencycode nuevo Valor de chargecurrencycode */ public void setChargecurrencycode(String pChargecurrencycode) { this.chargecurrencycode = pChargecurrencycode; } /** * Obtiene el valor de rate * * @return valor de rate */ public BigDecimal getRate() { return this.rate; } /** * Fija el valor de rate * * @param pRate nuevo Valor de rate */ public void setRate(BigDecimal pRate) { this.rate = pRate; } /** * Obtiene el valor de percent * * @return valor de percent */ public BigDecimal getPercent() { return this.percent; } /** * Fija el valor de percent * * @param pPercent nuevo Valor de percent */ public void setPercent(BigDecimal pPercent) { this.percent = pPercent; } /** * Obtiene el valor de minvalue * * @return valor de minvalue */ public BigDecimal getMinvalue() { return this.minvalue; } /** * Fija el valor de minvalue * * @param pMinvalue nuevo Valor de minvalue */ public void setMinvalue(BigDecimal pMinvalue) { this.minvalue = pMinvalue; } /** * Obtiene el valor de maxvalue * * @return valor de maxvalue */ public BigDecimal getMaxvalue() { return this.maxvalue; } /** * Fija el valor de maxvalue * * @param pMaxvalue nuevo Valor de maxvalue */ public void setMaxvalue(BigDecimal pMaxvalue) { this.maxvalue = pMaxvalue; } /** * Obtiene el valor de minamount * * @return valor de minamount */ public BigDecimal getMinamount() { return this.minamount; } /** * Fija el valor de minamount * * @param pMinamount nuevo Valor de minamount */ public void setMinamount(BigDecimal pMinamount) { this.minamount = pMinamount; } /** * Obtiene el valor de maxamount * * @return valor de maxamount */ public BigDecimal getMaxamount() { return this.maxamount; } /** * Fija el valor de maxamount * * @param pMaxamount nuevo Valor de maxamount */ public void setMaxamount(BigDecimal pMaxamount) { this.maxamount = pMaxamount; } @Override public boolean equals(Object rhs) { if (rhs == null) { return false; } if (!(rhs instanceof TgeneSubProductCharges)) { return false; } TgeneSubProductCharges that = (TgeneSubProductCharges) rhs; if ((this.getPk() == null) || (that.getPk() == null)) { return false; } return (this.getPk().equals(that.getPk())); } /** * Implementacion del metodo hashCode de la la entidad TgeneSubProductCharges * * @return el hashCode la instancia */ @Override public int hashCode() { if (this.hashValue == 0) { int result = 17; if (this.getPk() == null) { result = super.hashCode(); } else { result = this.getPk().hashCode(); } this.hashValue = result; } return this.hashValue; } /** Implementacion toString */ @Override public String toString() { Field[] fs = this.getClass().getDeclaredFields(); String data = ""; for (Field f : fs) { try { String name = f.getName(); if (f.getType().getName().compareTo("java.util.Set") == 0) { continue; } if ((name.compareTo("hashValue") == 0) || (name.compareTo("serialVersionUID") == 0)) { continue; } data += name + "=" + f.get(this) + ";"; } catch (Exception e) { continue; } } if (data.compareTo("") == 0) { data = super.toString(); } return data; } /** Implementacion de la creacion de un bean en blanco TgeneSubProductCharges */ @Override public Object createInstance() { TgeneSubProductCharges instance = new TgeneSubProductCharges(); instance.setPk(new TgeneSubProductChargesKey()); return instance; } /** * Clona la entidad TgeneSubProductCharges * * @see com.fp.dto.hb.HibernateBean#cloneMe() */ @Override public Object cloneMe() throws CloneNotSupportedException { TgeneSubProductCharges p = (TgeneSubProductCharges) this.clone(); p.setPk((TgeneSubProductChargesKey) this.pk.cloneMe()); return p; } // Metodos manuales. public boolean equalsWithoutSequence(Object rhs) { if (rhs == null) { return false; } if (!(rhs instanceof TgeneSubProductCharges)) { return false; } TgeneSubProductCharges that = (TgeneSubProductCharges) rhs; if ((this.getPk() == null) || (that.getPk() == null)) { return false; } TgeneSubProductChargesKey thispk = this.getPk(); TgeneSubProductChargesKey thatpk = that.getPk(); if (thatpk == null) { return false; } if (!(thatpk instanceof TgeneSubProductChargesKey)) { return false; } if ((thispk.getBalancetype() == null) || (thatpk.getBalancetype() == null)) { return false; } if (!thispk.getBalancetype().equals(thatpk.getBalancetype())) { return false; } if ((thispk.getBalancegroup() == null) || (thatpk.getBalancegroup() == null)) { return false; } if (!thispk.getBalancegroup().equals(thatpk.getBalancegroup())) { return false; } if ((thispk.getModulecode() == null) || (thatpk.getModulecode() == null)) { return false; } if (!thispk.getModulecode().equals(thatpk.getModulecode())) { return false; } if ((thispk.getProductcode() == null) || (thatpk.getProductcode() == null)) { return false; } if (!thispk.getProductcode().equals(thatpk.getProductcode())) { return false; } if ((thispk.getSubproductcode() == null) || (thatpk.getSubproductcode() == null)) { return false; } if (!thispk.getSubproductcode().equals(thatpk.getSubproductcode())) { return false; } if ((thispk.getStatuscode() == null) || (thatpk.getStatuscode() == null)) { return false; } if (!thispk.getStatuscode().equals(thatpk.getStatuscode())) { return false; } if ((thispk.getCompanycode() == null) || (thatpk.getCompanycode() == null)) { return false; } if (!thispk.getCompanycode().equals(thatpk.getCompanycode())) { return false; } if ((thispk.getCurrencycode() == null) || (thatpk.getCurrencycode() == null)) { return false; } if (!thispk.getCurrencycode().equals(thatpk.getCurrencycode())) { return false; } return true; } /** Sentencia que devuelve un registro de TgeneSubProductCharges. */ private static final String HQL_CHARGES_SUBPRODUCT = "from TgeneSubProductCharges tsubpchar " + " where tsubpchar.pk.balancetype = :balancetype " + " and tsubpchar.pk.balancegroup = :balancegroup " + " and tsubpchar.pk.modulecode = :modulecode " + " and tsubpchar.pk.productcode = :productcode " + " and tsubpchar.pk.subproductcode = :subproductcode " + " and tsubpchar.pk.statuscode = :statuscode " + " and tsubpchar.pk.companycode = :companycode " + " and tsubpchar.pk.currencycode = :currencycode " + " and :amount between tsubpchar.minamount and tsubpchar.maxamount "; /** * Metodo que entrega la definicion de cargos definidos por subproducto. * * @param pBalanceType Codigo de tipo de saldo a entregar buscar cargo. * @param pBanceGroup Codigo de tipo grupo de balance a entregar buscar cargo. * @param pModuleCode Codigo de modulo asociado al estatus y producto de la cuenta a buscar el cargo. * @param pProduct Codigo de producto de la cuenta a buscar el cargo. * @param pSubProduct Codigo de sub producto de la cuenta a buscar el cargo. * @param pStatusCode Codigo de estatus de la cuenta a buscar el saldo. * @param pCompany Codigo de compania de la cuenta a buscar le cargo. * @param pCurrency Codigo de moneda de la cuenta a buscar le cargo. * @param pAmount Monto base a obtener el cargo. * @return TgeneSubProductCharges * @throws Exception */ public static final TgeneSubProductCharges find(EntityManager pEntityManager, String pBalanceType, String pBanceGroup, String pModuleCode, String pProduct, String pSubProduct, String pStatusCode, Integer pCompany, String pCurrency, BigDecimal pAmount) throws Exception { TgeneSubProductCharges obj = null; Query qry = pEntityManager.createQuery(TgeneSubProductCharges.HQL_CHARGES_SUBPRODUCT); qry.setParameter("balancetype", pBalanceType); qry.setParameter("balancegroup", pBanceGroup); qry.setParameter("modulecode", pModuleCode); qry.setParameter("productcode", pProduct); qry.setParameter("subproductcode", pSubProduct); qry.setParameter("statuscode", pStatusCode); qry.setParameter("companycode", pCompany); qry.setParameter("currencycode", pCurrency); qry.setParameter("amount", pAmount); try { obj = (TgeneSubProductCharges) qry.getSingleResult(); } catch (NoResultException e) { return obj; } return obj; } /** Sentencia que devuelve un registro de TgeneSubProductCharges. */ private static final String JQL_CHARGES = "from TgeneSubProductCharges tsubpchar " + " where tsubpchar.pk.modulecode = :modulecode " + " and tsubpchar.pk.productcode = :productcode " + " and tsubpchar.pk.subproductcode = :subproductcode "; /** * Metodo que entrega la definicion de cargos definidos por subproducto. * * @param pBalanceType Codigo de tipo de saldo a entregar buscar cargo. * @param pBanceGroup Codigo de tipo grupo de balance a entregar buscar cargo. * @param pModuleCode Codigo de modulo asociado al estatus y producto de la cuenta a buscar el cargo. * @param pProduct Codigo de producto de la cuenta a buscar el cargo. * @param pSubProduct Codigo de sub producto de la cuenta a buscar el cargo. * @param pStatusCode Codigo de estatus de la cuenta a buscar el saldo. * @param pCompany Codigo de compania de la cuenta a buscar le cargo. * @param pCurrency Codigo de moneda de la cuenta a buscar le cargo. * @param pAmount Monto base a obtener el cargo. * @return TgeneSubProductCharges * @throws Exception */ @SuppressWarnings("unchecked") public static final List find(EntityManager pEntityManager, String pModuleCode, String pProduct, String pSubProduct) throws Exception { Query qry = pEntityManager.createQuery(TgeneSubProductCharges.JQL_CHARGES); qry.setParameter("modulecode", pModuleCode); qry.setParameter("productcode", pProduct); qry.setParameter("subproductcode", pSubProduct); return qry.getResultList(); } /** Sentencia que devuelve una lista de TgeneSubProductCharges por compania. */ private static final String HQL_CHARGES_SUBPRODUCT_BY_COMPANY = "from TgeneSubProductCharges tspc " + " where tspc.pk.companycode = :companycode "; /** * Metodo que entrega la definicion de cargos definidos por subproducto. * * @param pCompany Codigo de compania. * @return List * @throws Exception */ @SuppressWarnings(com.fp.common.helper.Constant.VUNCHECKED) public static List findByCompany(EntityManager pEntityManager, Integer pCompany) { List list = null; Query qry = pEntityManager.createQuery(TgeneSubProductCharges.HQL_CHARGES_SUBPRODUCT_BY_COMPANY); qry.setParameter("companycode", pCompany); list = qry.getResultList(); return list; } /** Sentencia que devuelve una lista de TgeneSubProductCharges por compania. */ private static final String JQL_CHARGES_SUBPRODUCT_BY_MODULE = "from TgeneSubProductCharges tsubpchar " + " where tsubpchar.pk.modulecode = :modulecode "; /** * Metodo que entrega la definicion de cargos definidos por subproducto. * * @param pCompany Codigo de compania. * @return List * @throws Exception */ @SuppressWarnings(com.fp.common.helper.Constant.VUNCHECKED) public static List findByModule(EntityManager pEntityManager, String pModuleCode) { List list = null; Query qry = pEntityManager.createQuery(TgeneSubProductCharges.JQL_CHARGES_SUBPRODUCT_BY_MODULE); qry.setParameter("modulecode", pModuleCode); list = qry.getResultList(); return list; } }