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 PayScale [Serializable] public class PayScale:AuditTrailBase { #region Cache Store private static Cache _cache = new Cache(typeof(PayScale)); #endregion #region Constructor public PayScale() { _gradeID = null; _itemID = 0; _initialAmount = 0; _noOfStep = 0; _effectDate = DateTime.MinValue; _itemType = EnumPayScaleItemType.None; } #endregion #region Properties #region gradeID : ID private ID _gradeID; public ID GradeID { get { return _gradeID; } set { base.OnPropertyChange("gradeID", _gradeID, value); _gradeID = value; } } #endregion #region gradeID : ID private Grade _grade = null; public Grade GradeObj { get { if (_grade == null && !_gradeID.IsUnassigned && _gradeID.Integer > 0) { _grade = Grade.Get(_gradeID); } return _grade; } } #endregion #region itemID : int private int _itemID; public int ItemID { get { return _itemID; } set { base.OnPropertyChange("itemID", _itemID, value); _itemID = value; } } #endregion #region initialAmount : double private double _initialAmount; public double InitialAmount { get { return _initialAmount; } set { base.OnPropertyChange("initialAmount", _initialAmount, value); _initialAmount = value; } } #endregion #region initialAmount : double private double _percentageInc; public double IncPercentage { get { return _percentageInc; } set { base.OnPropertyChange("IncPercentage", _percentageInc, value); _percentageInc = value; } } #endregion #region noOfStep : int private int _noOfStep; public int NoOfStep { get { return _noOfStep; } set { base.OnPropertyChange("noOfStep", _noOfStep, value); _noOfStep = value; } } #endregion #region effectDate : DateTime private DateTime _effectDate; public DateTime EffectDate { get { return _effectDate; } set { base.OnPropertyChange("effectDate", _effectDate, value); _effectDate = value; } } #endregion #region itemType : EnumPayScaleItemType private EnumPayScaleItemType _itemType; public EnumPayScaleItemType ItemType { get { return _itemType; } set { base.OnPropertyChange("itemType", (short)_itemType, (short)value); _itemType = value; } } #endregion #region itemType : EnumPayScaleItemType private string _Description; public string Description { get { if (this.ItemType == EnumPayScaleItemType.Basic) { return "Basic"; } else if (this.ItemType == EnumPayScaleItemType.Allowance) { AllowanceDeduction allowance = AllowanceDeduction.Get(ID.FromInteger(this.ItemID)); if (allowance != null) { return allowance.Name; } else { return "Invalid Allawance."; } } else { return "Unknown"; } } } #endregion #region PayScaleDetails : PayScaleDetails private ObjectsTemplate _details; public ObjectsTemplate PayscaleDetails { get { if (_details == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _details = PayScaleDetail.GetByPayScale(this.ID); } return _details; } set { _details = value; } } #endregion #region Service Factory IPayScaleService : IPayScaleService internal static IPayScaleService Service { get { return Services.Factory.CreateService(typeof(IPayScaleService)); } } #endregion #endregion #region Functions public static PayScale Get(ID nID) { PayScale oPayScale = null; #region Cache Header oPayScale = (PayScale)_cache["Get", nID]; if (oPayScale != null) return oPayScale; #endregion oPayScale = PayScale.Service.Get(nID); #region Cache Footer _cache.Add(oPayScale, "Get", nID); #endregion return oPayScale; } public static PayScale Get(ID nGradeID, ID nAllowID) { PayScale oPayScale = null; #region Cache Header oPayScale = (PayScale)_cache["Get", nGradeID, nAllowID]; if (oPayScale != null) return oPayScale; #endregion oPayScale = PayScale.Service.Get(nGradeID, nAllowID, SystemInformation.CurrentSysInfo.NextPayProcessDate); #region Cache Footer _cache.Add(oPayScale, "Get", nGradeID, nAllowID); #endregion return oPayScale; } public static PayScale GetByGrade(ID nGradeID) { PayScale oPayScale = null; #region Cache Header oPayScale = (PayScale)_cache["GetByGrade", nGradeID]; if (oPayScale != null) return oPayScale; #endregion oPayScale = PayScale.Service.GetByGrade(nGradeID); #region Cache Footer _cache.Add(oPayScale, "GetByGrade", nGradeID); #endregion return oPayScale; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate payScales = _cache["Get"] as ObjectsTemplate; if (payScales != null) return payScales; #endregion try { payScales = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(payScales, "Get"); #endregion return payScales; } public static DateTime? GetMaxEffectDate() { DateTime? dEffectDate = DateTime.MinValue; try { dEffectDate = Service.GetMaxEffectDate(SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } return dEffectDate; } public static ObjectsTemplate GetLatest() { #region Cache Header ObjectsTemplate payScales = _cache["Get"] as ObjectsTemplate; if (payScales != null) return payScales; #endregion try { payScales = Service.GetLatest(SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(payScales, "Get"); #endregion return payScales; } public static ObjectsTemplate GetByAllowance(ID allowID) { #region Cache Header ObjectsTemplate payScales = _cache["GetByAllowance", allowID] as ObjectsTemplate; if (payScales != null) return payScales; #endregion try { payScales = Service.GetByAllowance(allowID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(payScales, "GetByAllowance", allowID); #endregion return payScales; } public ID Save() { return PayScale.Service.Save(this); } public void Delete() { PayScale.Service.Delete(ID); } public static void Delete(ID gradeID) { PayScale.Service.DeleteByGradeID(gradeID); } public static void Save(ObjectsTemplate _NewPayscale) { PayScale.Service.Save(_NewPayscale); } #endregion } #endregion #region IPayScale Service public interface IPayScaleService { PayScale Get(ID id); ObjectsTemplate Get(); ID Save(PayScale item); void Delete(ID id); void DeleteByGradeID(ID id); PayScale Get(ID nGradeID, ID nAllowID, DateTime nextPayProcessDate); ObjectsTemplate GetByAllowance(ID allowID); ObjectsTemplate GetLatest(ID PayrollTypeID); PayScale GetByGrade(ID nID); DateTime? GetMaxEffectDate(ID PayrollTypeID); void Save(ObjectsTemplate _NewPayscale); } #endregion }