package com.fp.persistence.pgeneral.score; import java.io.Serializable; import java.lang.reflect.Field; import java.math.BigDecimal; import java.sql.Date; import java.sql.Timestamp; import java.util.List; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.NoResultException; import javax.persistence.Query; import javax.persistence.Table; import javax.persistence.Transient; import com.fp.common.helper.Constant; import com.fp.dto.hb.HibernateBean; /** Clase que implementa la entidad de Hibernate que hace referencia a la tabla TGENESCOREADJUSTMENT */ @Entity(name = "TgeneScoreAdjustment") @Table(name = "TGENESCOREADJUSTMENT") public class TgeneScoreAdjustment 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 TgeneScoreAdjustment */ @EmbeddedId private TgeneScoreAdjustmentKey pk; @Column(name = "DATEFROM", nullable = false) /** * Fecha desde la cual esta vigente el registro con datos de la cuenta. */ private Timestamp datefrom; @Column(name = "MODULECODE", nullable = true) /** * Codigo de modulo */ private String modulecode; @Column(name = "PRODUCTCODE", nullable = true) /** * Codigo de producto */ private String productcode; @Column(name = "SUBPRODUCTCODE", nullable = true) /** * Codigo de subproducto */ private String subproductcode; @Column(name = "CURRENCYCODE", nullable = true) /** * Codigo de moneda */ private String currencycode; @Column(name = "ADJUSTMENTTYPE", nullable = false) /** * null */ private String adjustmenttype; @Column(name = "MANUALPROVISIONPERCENT", nullable = false) /** * Porcentaje de provision constituido. */ private BigDecimal manualprovisionpercent; @Column(name = "JOURNALID", nullable = false) /** * Numero de movimiento */ private String journalid; @Column(name = "FILENAME", nullable = true) /** * Nombre de archivo */ private String filename; @Column(name = "STATUS", nullable = true) /** * Estado del registro */ private String status; /** Contructor por defecto */ public TgeneScoreAdjustment() { } /** * Contructor de TgeneScoreAdjustment * * @param pPk Clave Primaria del entity * @param pDatefrom Fecha desde la cual esta vigente el registro con datos de la cuenta. * @param pAdjustmenttype null * @param pManualprovisionpercent Porcentaje de provision constituido. * @param pJournalid Numero de movimiento */ public TgeneScoreAdjustment(TgeneScoreAdjustmentKey pPk, Timestamp pDatefrom, String pAdjustmenttype, BigDecimal pManualprovisionpercent, String pJournalid) { this(); this.pk = pPk; this.datefrom = pDatefrom; this.adjustmenttype = pAdjustmenttype; this.manualprovisionpercent = pManualprovisionpercent; this.journalid = pJournalid; } /** * 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 TgeneScoreAdjustment */ public static TgeneScoreAdjustment find(EntityManager pEntityManager, TgeneScoreAdjustmentKey pKey) throws Exception { TgeneScoreAdjustment obj = pEntityManager.find(TgeneScoreAdjustment.class, pKey); return obj; } /** * Entrega la Clave primaria de TgeneScoreAdjustment * * @return El objeto que referencia a la Clave primaria de TgeneScoreAdjustment */ public TgeneScoreAdjustmentKey getPk() { return this.pk; } /** * Fija un nuevo valor a la Clave primaria de TgeneScoreAdjustment * * @param pPk El objeto que referencia a la nueva Clave primaria de TgeneScoreAdjustment */ public void setPk(TgeneScoreAdjustmentKey pPk) { this.pk = pPk; } /** * Obtiene el valor de datefrom * * @return valor de datefrom */ public Timestamp getDatefrom() { return this.datefrom; } /** * Fija el valor de datefrom * * @param pDatefrom nuevo Valor de datefrom */ public void setDatefrom(Timestamp pDatefrom) { this.datefrom = pDatefrom; } /** * Obtiene el valor de modulecode * * @return valor de modulecode */ public String getModulecode() { return this.modulecode; } /** * Fija el valor de modulecode * * @param pModulecode nuevo Valor de modulecode */ public void setModulecode(String pModulecode) { this.modulecode = pModulecode; } /** * Obtiene el valor de productcode * * @return valor de productcode */ public String getProductcode() { return this.productcode; } /** * Fija el valor de productcode * * @param pProductcode nuevo Valor de productcode */ public void setProductcode(String pProductcode) { this.productcode = pProductcode; } /** * Obtiene el valor de subproductcode * * @return valor de subproductcode */ public String getSubproductcode() { return this.subproductcode; } /** * Fija el valor de subproductcode * * @param pSubproductcode nuevo Valor de subproductcode */ public void setSubproductcode(String pSubproductcode) { this.subproductcode = pSubproductcode; } /** * Obtiene el valor de currencycode * * @return valor de currencycode */ public String getCurrencycode() { return this.currencycode; } /** * Fija el valor de currencycode * * @param pCurrencycode nuevo Valor de currencycode */ public void setCurrencycode(String pCurrencycode) { this.currencycode = pCurrencycode; } /** * Obtiene el valor de adjustmenttype * * @return valor de adjustmenttype */ public String getAdjustmenttype() { return this.adjustmenttype; } /** * Fija el valor de adjustmenttype * * @param pAdjustmenttype nuevo Valor de adjustmenttype */ public void setAdjustmenttype(String pAdjustmenttype) { this.adjustmenttype = pAdjustmenttype; } /** * Obtiene el valor de manualprovisionpercent * * @return valor de manualprovisionpercent */ public BigDecimal getManualprovisionpercent() { return this.manualprovisionpercent; } /** * Fija el valor de manualprovisionpercent * * @param pManualprovisionpercent nuevo Valor de manualprovisionpercent */ public void setManualprovisionpercent(BigDecimal pManualprovisionpercent) { this.manualprovisionpercent = pManualprovisionpercent; } /** * Obtiene el valor de journalid * * @return valor de journalid */ public String getJournalid() { return this.journalid; } /** * Fija el valor de journalid * * @param pJournalid nuevo Valor de journalid */ public void setJournalid(String pJournalid) { this.journalid = pJournalid; } /** * Obtiene el valor de filename * * @return valor de filename */ public String getFilename() { return this.filename; } /** * Fija el valor de filename * * @param pFilename nuevo Valor de filename */ public void setFilename(String pFilename) { this.filename = pFilename; } /** * Obtiene el valor de status * * @return valor de status */ public String getStatus() { return this.status; } /** * Fija el valor de status * * @param pStatus nuevo Valor de status */ public void setStatus(String pStatus) { this.status = pStatus; } @Override public boolean equals(Object rhs) { if (rhs == null) { return false; } if (!(rhs instanceof TgeneScoreAdjustment)) { return false; } TgeneScoreAdjustment that = (TgeneScoreAdjustment) rhs; if ((this.getPk() == null) || (that.getPk() == null)) { return false; } return (this.getPk().equals(that.getPk())); } /** * Implementacion del metodo hashCode de la la entidad TgeneScoreAdjustment * * @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 TgeneScoreAdjustment */ @Override public Object createInstance() { TgeneScoreAdjustment instance = new TgeneScoreAdjustment(); instance.setPk(new TgeneScoreAdjustmentKey()); return instance; } /** * Clona la entidad TgeneScoreAdjustment * * @see com.fp.dto.hb.HibernateBean#cloneMe() */ @Override public Object cloneMe() throws CloneNotSupportedException { TgeneScoreAdjustment p = (TgeneScoreAdjustment) this.clone(); p.setPk((TgeneScoreAdjustmentKey) this.pk.cloneMe()); return p; } public Object getId() { return this.pk; } /** * * METODOS MANUALES * */ /** * Sentencia para buscar los registros asociados a un scoredate */ private static final String JPQL_ACCOUNT_SCOREDATE = "from TgeneScoreAdjustment tsol " + " where tsol.pk.dateto = :dateto " + " and tsol.pk.companycode = :companycode " + " and tsol.pk.scoredate in (select sh.pk.scoredate from TgeneScoreHeader sh " + " where sh.pk.companycode = :companycode " + " and sh.tabulated = :tabulated " + " and sh.pk.scoredate = :scoredate) "; public static List findbyScoreDate(EntityManager pEntityManager, Integer company, String tabulated, Date scoredate) throws Exception { Query qry = pEntityManager.createQuery(TgeneScoreAdjustment.JPQL_ACCOUNT_SCOREDATE); qry.setParameter("companycode", company); qry.setParameter("dateto", Constant.getDefaultExpiryDate()); qry.setParameter("tabulated", tabulated); qry.setParameter("scoredate", scoredate); return qry.getResultList(); } /* Calificación por archivo */ /** * Sentencia para buscar los registros que tienen el nombre de archivo dado */ private static final String JPQL_FILE = "select distinct t.filename " + " from TgeneScoreAdjustment t " + " where t.pk.companycode = :company" + " and t.filename = :filename"; /** * Método que selecciona los registros que tienen el nombre de archivo dado * * @param pEntityManager Referencia de la session a obtener datos del bean * @param pCompany Código de la compañia * @param pFilename Nombre del archivo * @return Nombre del archivo si existe, de lo contrario null * @throws Exception */ public static String find(EntityManager pEntityManager, Integer pCompany, String pFilename) throws Exception { try { Query qry = pEntityManager.createQuery(TgeneScoreAdjustment.JPQL_FILE); qry.setParameter("company", pCompany); qry.setParameter("filename", pFilename); return (String) qry.getSingleResult(); } catch (NoResultException e) { return null; } } /** * Sentencia para buscar los registros asociados a una entidad financiera dada que no hayan sido procesados */ private static final String JPQL_BANK = "from TgeneScoreAdjustment t " + " where t.pk.companycode = :company "; // + " and t.pk.bank = coalesce(:bank, t.pk.bank) "; // /** // * Método que selecciona los registros asociados a una entidad financiera dada que no hayan sido procesados // * // * @param pEntityManager Referencia de la session a obtener datos del bean // * @param pCompany Nombre de la compañia // * @param pBank Código del banco // * @return Lista de registro de TloanPaymentAccoBank // * @throws Exception // */ // @SuppressWarnings("unchecked") // public static List findByBank(EntityManager pEntityManager, Integer pCompany, String pBank) // throws Exception { // Query qry = pEntityManager.createQuery(JPQL_BANK); // qry.setParameter("company", pCompany); // qry.setParameter("bank", pBank); // // return qry.getResultList(); // } // // /** // * Sentencia para buscar los registros asociados a una cuenta dada que no hayan sido procesados // */ // private static final String JPQL_ACCOUNT = "from TgeneScoreAdjustment t " + " where t.pk.companycode = :company " // + " and t.pk.account = :account " + " and t.status = 'N' " ; // // /** // * Método que selecciona los registros asociados a una cuenta dada que no hayan sido procesados // * // * @param pEntityManager Referencia de la session a obtener datos del bean // * @param pCompany Nombre de la compañia // * @param pAccount Código de la cuenta // * @return Lista de registro de TloanPaymentAccoBank // * @throws Exception // */ // @SuppressWarnings("unchecked") // public static List findByAccount(EntityManager pEntityManager, Integer pCompany, String // pAccount) throws Exception { // Query qry = pEntityManager.createQuery(JPQL_ACCOUNT); // qry.setParameter("company", pCompany); // qry.setParameter("account", pAccount); // // return qry.getResultList(); // } }