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.Windows.Forms; namespace Payroll.BO { #region class BudgetMaster [Serializable] public class BudgetMaster : AuditTrailBase { #region Cache Store private static Cache _cache = new Cache(typeof(BudgetMaster)); #endregion #region Constructor public BudgetMaster() { _basedOn = EnumBasedOnPercent.None; _effectMonth = DateTime.MinValue; _name = string.Empty; _overAllPercentage = 0.0; _toDate = DateTime.MinValue; _individualchanges=null; } #endregion #region Properties #region BasedOn : EnumBasedOnPercent private EnumBasedOnPercent _basedOn; public EnumBasedOnPercent BasedOn { get { return _basedOn; } set { _basedOn = value; } } #endregion #region EffectMonth : DateTime private DateTime _effectMonth; public DateTime EffectMonth { get { return _effectMonth; } set { _effectMonth = value; } } #endregion #region FromDate : DateTime private DateTime _fromDate; public DateTime FromDate { get { return _fromDate; } set { _fromDate = value; } } #endregion #region Name : string private string _name; public string Name { get { return _name; } set { _name = value; } } #endregion #region OverAllPercentage : double private double _overAllPercentage; public double OverAllPercentage { get { return _overAllPercentage; } set { _overAllPercentage = value; } } #endregion #region ToDate : DateTime private DateTime _toDate; public DateTime ToDate { get { return _toDate; } set { _toDate = value; } } #endregion private ObjectsTemplate _budgetGrades; public ObjectsTemplate BudgetGrades { get { if (_budgetGrades == null) { _budgetGrades = new ObjectsTemplate(); if (!this.ID.IsUnassigned) { _budgetGrades = BudgetGrade.Get(this.ID.Integer); // # get by budget master id } } return this._budgetGrades; } set { _budgetGrades = value; } } private ObjectsTemplate _individualchanges; public ObjectsTemplate Individualchanges { get { if (_individualchanges == null) { _individualchanges = new ObjectsTemplate(); if (!this.ID.IsUnassigned) { _individualchanges = BudgetIndivisualChange.Get(this.ID.Integer); // # get by budget master id } } return this._individualchanges; } set { _individualchanges = value; } } private ObjectsTemplate _budgetCCs; public ObjectsTemplate BudgetCCs { get { if (_budgetCCs == null) { _budgetCCs = new ObjectsTemplate(); if (!this.ID.IsUnassigned) { _budgetCCs = BudgetCostCenter.Get(this.ID.Integer); // # get by budget master id } } return _budgetCCs; } set { _budgetCCs = value; } } private ObjectsTemplate _budgetDepts; public ObjectsTemplate BudgetDepartments { get { if (_budgetDepts == null) { _budgetDepts = new ObjectsTemplate(); if (!this.ID.IsUnassigned) { _budgetDepts = BudgetDepartment.Get(this.ID.Integer); // # get by budget master id } } return _budgetDepts; } set { _budgetDepts = value; } } //private ObjectsTemplate _budgetNewJoinerCCs; //public ObjectsTemplate BudgetNewJoinerCCs //{ // get // { // if (_budgetNewJoinerCCs == null && this.ID == null && this.ID.Integer > 0) // { // BudgetNewJoiner b = new BudgetNewJoiner(); // _budgetNewJoinerCCs = b.OBudgetNewJoinerCrGs; //BudgetNewJoinerCrG.Get(); // # get by budget master id // } // return _budgetNewJoinerCCs; // } // set // { // _budgetNewJoinerCCs = value; // } //} private ObjectsTemplate _components; public ObjectsTemplate Components { get { if (_components == null) { _components = new ObjectsTemplate(); if (!this.ID.IsUnassigned) { _components = BudgetComponent.Get(this.ID.Integer); // # get by budget master id } } return _components; } set { _components = value; } } private ObjectsTemplate _newJoiners; public ObjectsTemplate NewJoiners { get { if (_newJoiners == null) { _newJoiners = new ObjectsTemplate(); if (!this.ID.IsUnassigned) { _newJoiners = BudgetNewJoiner.Get(this.ID.Integer); // # get by budget master id } } return _newJoiners; } set { _newJoiners = value; } } private ObjectsTemplate _processMonthly; public ObjectsTemplate BudgetProcessMonthlys { get { if (_processMonthly == null) { _processMonthly = new ObjectsTemplate(); if (!this.ID.IsUnassigned) { _processMonthly = BudgetProcessMonthly.Get(); // # get by budget master id } } return _processMonthly; } set { _processMonthly = value; } } #endregion #region Service Factory IBudgetMasterService : IBudgetMasterService public List getException(DateTime onmonth, Employee oEmployee) { onmonth = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(onmonth); List exceptions = new List(); if (this.Individualchanges != null && this.Individualchanges.Count > 0) exceptions = this.Individualchanges.FindAll(delegate(BudgetIndivisualChange oItem) { return oItem.EmployeeID == oEmployee.ID && onmonth >= Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(oItem.EffectDate); }); return exceptions; } public List GetNewJoiner(DateTime onmonth) { onmonth = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(onmonth); List newJoiners = new List(); if (this.NewJoiners != null && this.NewJoiners.Count > 0) newJoiners = this.NewJoiners.FindAll(delegate(BudgetNewJoiner oItem) { return onmonth >= Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(oItem.FromDate); }); return newJoiners; } public List GetCC(DateTime onmonth) { List CCs = new List(); onmonth = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(onmonth); if (this.BudgetCCs != null && this.BudgetCCs.Count > 0) CCs = this.BudgetCCs.FindAll(delegate(BudgetCostCenter oItem) { return onmonth >= Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(oItem.FromMonth) ; }); return CCs; } public List GetNewJoinerCC(DateTime onmonth) { List newJoinerCCs = new List(); onmonth = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(onmonth); List newJoiners = new List(); if (this.NewJoiners != null && this.NewJoiners.Count > 0) { newJoiners = this.NewJoiners.FindAll(delegate(BudgetNewJoiner oItem) { return onmonth >= Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfMonth(oItem.FromDate); }); foreach(BudgetNewJoiner bnj in newJoiners) { foreach (BudgetNewJoinerCrG bncc in bnj.OBudgetNewJoinerCrGs) { newJoinerCCs.Add(bncc); } } } return newJoinerCCs; } public List GetApplicableParameters(Employee employee, ID graId) { List applicableParams = this.Components.FindAll(delegate(BudgetComponent param) { return IsApplicable(param, graId, employee) ;}); return applicableParams; } private static bool IsApplicable(BudgetComponent param, ID graid, Employee employee) { bool isApplicable = false; foreach (BudgetComponentGrade adgrade in param.OBudgetComponentGrades) { if (adgrade.GradeID.Integer == graid.Integer) { isApplicable = true; } } if (!isApplicable) return false; return true; } internal static IBudgetMasterService Service { get { return Services.Factory.CreateService(typeof(IBudgetMasterService)); } } #endregion #region Function(s) #region Get public static BudgetMaster Get(ID nID) { BudgetMaster oBudgetMaster = null; #region Cache Header oBudgetMaster = (BudgetMaster)_cache["Get", nID]; if (oBudgetMaster != null) return oBudgetMaster; #endregion try { oBudgetMaster = Service.Get(nID, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oBudgetMaster, "Get", nID); #endregion return oBudgetMaster; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oBudgetMasters = _cache["Get"] as ObjectsTemplate; if (oBudgetMasters != null) return oBudgetMasters; #endregion try { oBudgetMasters = Service.Get(SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oBudgetMasters, "Get"); #endregion return oBudgetMasters; } public static ObjectsTemplate Get(DateTime dtFromDate, DateTime dtToDate) { #region Cache Header ObjectsTemplate oBudgetMasters = _cache["Get"] as ObjectsTemplate; if (oBudgetMasters != null) return oBudgetMasters; #endregion try { oBudgetMasters = Service.Get(dtFromDate, dtToDate, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oBudgetMasters, "Get"); #endregion return oBudgetMasters; } #endregion #region Save public ID Save(ProgressBar pbar) { //SetAuditTrailProperties(); return Service.Save(this, pbar, SystemInformation.CurrentSysInfo.PayrollTypeID); } #endregion #region Delete public static void Delete(ID id) { Service.Delete(id, SystemInformation.CurrentSysInfo.PayrollTypeID); } #endregion #endregion } #endregion #region IBudgetMasterService public interface IBudgetMasterService { BudgetMaster Get(ID nID,ID PayrollTypeID); ObjectsTemplate Get(ID PayrollTypeID); ObjectsTemplate Get(DateTime dtFromDate, DateTime dtToDate, ID PayrollTypeID); ID Save(BudgetMaster oBudgetMaster, ProgressBar pbar, ID PayrollTypeID); void Delete(ID nID, ID PayrollTypeID); } #endregion }