using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.Caching; using System.Data.Linq.Mapping; namespace Payroll.BO { #region Loan Parameter [Serializable] public class LoanParameter : AuditTrailBase { public delegate void ItemChanged(); #region Cache Store private static Cache _cache = new Cache(typeof(LoanParameter)); #endregion #region Constructor public LoanParameter() { _loanID = null; _noOfGross = 0; _noOfBasic = 0; _minInstallmentMonth = 0; _maxInstallmentMonth = 0; _minReconcileMonth = 0; _minFlatAmount = 0.0; _maxFlatAmount = 0.0; } #endregion #region Properties #region MinFlatAmount : double private double _minFlatAmount; public double MinFlatAmount { get { return _minFlatAmount; } set { base.OnPropertyChange("MinFlatAmount", _minFlatAmount, value); _minFlatAmount = value; } } #endregion #region MaxFlatAmount : double private double _maxFlatAmount; public double MaxFlatAmount { get { return _maxFlatAmount; } set { base.OnPropertyChange("MaxFlatAmount", _maxFlatAmount, value); _maxFlatAmount = value; } } #endregion #region LoanID : ID private ID _loanID; public ID LoanID { get { return _loanID; } set { base.OnPropertyChange("loanID", _loanID, value); _loanID = value; } } #endregion #region NoOfGross : double private double _noOfGross; public double NoOfGross { get { return _noOfGross; } set { base.OnPropertyChange("noOfGross", _noOfGross, value); _noOfGross = value; } } #endregion #region NoOfBasic : double private double _noOfBasic; public double NoOfBasic { get { return _noOfBasic; } set { base.OnPropertyChange("noOfBasic", _noOfBasic, value); _noOfBasic = value; } } #endregion #region MinInstallmentMonth : int private int _minInstallmentMonth; public int MinInstallmentMonth { get { return _minInstallmentMonth; } set { base.OnPropertyChange("minInstallmentMonth", _minInstallmentMonth, value); _minInstallmentMonth = value; } } #endregion #region MaxInstallmentMonth : int private int _maxInstallmentMonth; public int MaxInstallmentMonth { get { return _maxInstallmentMonth; } set { base.OnPropertyChange("maxInstallmentMonth", _maxInstallmentMonth, value); _maxInstallmentMonth = value; } } #endregion #region MinReconcileMonth : int private int _minReconcileMonth; public int MinReconcileMonth { get { return _minReconcileMonth; } set { base.OnPropertyChange("minReconcileMonth", _minReconcileMonth, value); _minReconcileMonth = value; } } #endregion #region LoanGrades private ObjectsTemplate _loanGrades; public ObjectsTemplate LoadGradesTemp { get { if (_loanGrades == null) { _loanGrades = LoanGrades.Service.GetLoanGrades(this.ID.Integer); //_salaryEmpCostCenters = new ObjectsTemplate(); } return _loanGrades; } set { _loanGrades = value; } } #endregion #region LoanDoc private ObjectsTemplate _loanDocs; public ObjectsTemplate LoadDocsTemp { get { if (_loanDocs == null) { _loanDocs = LoanDoc.Service.GetLoanDoc(this.ID.Integer); } return _loanDocs; } set { _loanDocs = value; } } #endregion #endregion #region Service Factory ILoanParameterService : ILoanParameterService internal static ILoanParameterService Service { get { return Services.Factory.CreateService(typeof(ILoanParameterService)); } } #endregion #region Functions public static LoanParameter GetApplicableParameter(Employee oemployee, ID loanid) { ObjectsTemplate opss = LoanParameter.Get(); LoanParameter oparamter = GetApplicableParameter(oemployee, oemployee.GradeID, opss, loanid); return oparamter; } public static List GetApplicableParameters(Employee employee, ID graId, ObjectsTemplate parameters) { List applicableParams = parameters.FindAll(delegate(LoanParameter param) { return IsApplicable(param, graId, employee); }); return applicableParams; } public static LoanParameter GetApplicableParameter(Employee employee, ID graId, ObjectsTemplate parameters) { foreach (LoanParameter item in parameters) { if (IsApplicable(item, graId, employee) == true) return item; } return null; } public static LoanParameter GetApplicableParameter(Employee employee, ID graId, ObjectsTemplate parameters, ID loanid) { foreach (LoanParameter item in parameters) { if (item.LoanID == loanid) { if (IsApplicable(item, graId, employee) == true) return item; } } return null; } private static bool IsApplicable(LoanParameter param, ID graid, Employee employee) { bool isApplicable = false; foreach (LoanGrades adgrade in param.LoadGradesTemp) { if (adgrade.GradeID.Integer == graid.Integer) { isApplicable = true; } } if (!isApplicable) return false; return true; } public static LoanParameter Get(ID nID) { LoanParameter oLoanParameter = null; #region Cache Header oLoanParameter = (LoanParameter)_cache["Get", nID]; if (oLoanParameter != null) return oLoanParameter; #endregion oLoanParameter = LoanParameter.Service.Get(nID); #region Cache Footer _cache.Add(oLoanParameter, "Get", nID); #endregion return oLoanParameter; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate loanParameters = _cache["Get"] as ObjectsTemplate; if (loanParameters != null) return loanParameters; #endregion try { loanParameters = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(loanParameters, "Get"); #endregion return loanParameters; } public ID Save() { base.SetAuditTrailProperties(); return LoanParameter.Service.Save(this); } public void Delete() { LoanParameter.Service.Delete(ID); } public static ObjectsTemplate GetLoanGrades(int loanParameterID) { ObjectsTemplate oLoanGrades = null; oLoanGrades = Service.GetLoanGrades(loanParameterID); return oLoanGrades; } public static ObjectsTemplate GetLoanDoc(int loanParameterID) { ObjectsTemplate oLoanDoc = null; oLoanDoc = Service.GetLoanDoc(loanParameterID); return oLoanDoc; } #endregion } #endregion #region ILoanParameterService Service public interface ILoanParameterService { LoanParameter Get(ID id); ObjectsTemplate Get(); ID Save(LoanParameter item); void Delete(ID id); ObjectsTemplate GetLoanGrades(int loanParameterID); ObjectsTemplate GetLoanDoc(int loanParameterID); } #endregion }