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; using Ease.CoreV35.Utility; using System.Data; namespace Payroll.BO { #region EmployeeGradeSalary [Serializable] public class EmployeeGradeSalary : AuditTrailBase { #region Cache Store private static Cache _cache = new Cache(typeof(EmployeeGradeSalary)); #endregion #region Constructor public EmployeeGradeSalary() { _employeeID = null; _tillDate = DateTime.MinValue; _effectDate = DateTime.MinValue; _basicSalary = 0; _gradeID = null; _grossSalary = 0; _payScaleDetailID = null; _arrearType = EnumArrearType.NotPresent; _gradeSalaryTypeID = null; _employee = null; _grade = null; _PayScaleDetail = null; _fractionofFromTo = 1; _actualbasicSalary = 0; } #endregion #region Properties #region EmployeeID : ID private ID _employeeID; public ID EmployeeID { get { return _employeeID; } set { base.OnPropertyChange("EmployeeID", _employeeID, value); _employeeID = value; } } #endregion #region tillDate : DateTime private DateTime? _tillDate; public DateTime? TillDate { get { return _tillDate; } set { base.OnPropertyChange("tillDate", _tillDate, value); _tillDate = value; } } #endregion #region effectDate : DateTime private DateTime _effectDate; public DateTime EffectDate { get { return _effectDate; } set { base.OnPropertyChange("effectDate", _effectDate, value); _effectDate = value; } } #endregion #region basicSalary : double private double _basicSalary; public double BasicSalary { get { return _basicSalary; } set { base.OnPropertyChange("basicSalary", _basicSalary, value); _basicSalary = value; } } #endregion #region basicSalary : double private double _actualbasicSalary; public double ActualBasicSalary { get { return _actualbasicSalary; } set { _actualbasicSalary = value; } } #endregion #region GradeID : ID private ID _gradeID; public ID GradeID { get { return _gradeID; } set { base.OnPropertyChange("GradeID", _gradeID, value); _gradeID = value; } } #endregion #region grossSalary : double private double _grossSalary; public double GrossSalary { get { return _grossSalary; } set { base.OnPropertyChange("grossSalary", _grossSalary, value); _grossSalary = value; } } #endregion #region PayScaleID : ID private ID _payScaleDetailID; public ID PayScaleDetailID { get { return _payScaleDetailID; } set { base.OnPropertyChange("PayScaleDetailID", _payScaleDetailID, value); _payScaleDetailID = value; } } #endregion #region arrearType : EnumArrearType private EnumArrearType _arrearType; public EnumArrearType ArrearType { get { return _arrearType; } set { base.OnPropertyChange("arrearType",(short) _arrearType, (short)value); _arrearType = value; } } #endregion #region GradeSalaryTypeID : ID private ID _gradeSalaryTypeID; public ID GradeSalaryTypeID { get { return _gradeSalaryTypeID; } set { base.OnPropertyChange("GradeSalaryTypeID", _gradeSalaryTypeID, value); _gradeSalaryTypeID = value; } } #endregion #region Grade Salary Type private GradeSalaryChangeType _gradeSalaryType; public GradeSalaryChangeType gradeSalaryType { get { if (_gradeSalaryTypeID.Integer > 0 && _gradeSalaryType == null) { _gradeSalaryType = new GradeSalaryChangeType(); _gradeSalaryType = GradeSalaryChangeType.Get(_gradeSalaryTypeID); } return this._gradeSalaryType; } set { _gradeSalaryType = value; } } #endregion #region from & To date Fractionate : double private double _fractionofFromTo; public double FractionofFromTo { get { return _fractionofFromTo; } set { _fractionofFromTo = value; } } #endregion #region ArrearAmount : double private int _employeeSerial; public int EmployeeSerial { get { return _employeeSerial; } set { base.OnPropertyChange("EmployeeSerial", _employeeSerial, value); _employeeSerial = value; } } #endregion #region employee : Employee private Employee _employee; public Employee Employee { get { if (_employeeID.Integer > 0 && _employee == null) { _employee = new Employee(); _employee = Employee.Get(_employeeID); } return this._employee; } set { _employee = value; } } #endregion #region grade : Grade private Grade _grade; public Grade Grade { get { if (_gradeID.Integer > 0 && _grade == null) { _grade = new Grade(); _grade = Grade.Get(_gradeID); } return this._grade; } set { _grade = value; } } private EmpLifeCycle _EmpLifeCycle; public EmpLifeCycle EmpLifeCycle { get { return this._EmpLifeCycle; } set { _EmpLifeCycle = value; } } #endregion private ObjectsTemplate _errorList; public ObjectsTemplate ErrorList { get { return _errorList; } set { _errorList = value; } } #region Allowance Deduction Parameter : ADParameters private ObjectsTemplate _adPrameters; public ObjectsTemplate ADParameters { get { if (_adPrameters == null) { throw new ServiceException("Allowance Deduction Parameter Not yet set"); } return _adPrameters; } set { _adPrameters = value; } } #endregion #region PayScaleDetail : PayScaleDetail private PayScaleDetail _PayScaleDetail; public PayScaleDetail PayScaleDetail { get { if ( _PayScaleDetail == null && !this._payScaleDetailID.IsUnassigned) { _PayScaleDetail = new PayScaleDetail(); _PayScaleDetail = PayScaleDetail.Get(_payScaleDetailID); } return this._PayScaleDetail; } set { _PayScaleDetail = value; } } #endregion //#region OPI Parameter : OpiParameters //private ObjectsTemplate _opiParameter; //public ObjectsTemplate OpiParameters //{ // get // { // if (_opiParameter == null) // { // throw new ServiceException("OPI Parameter Not yet set"); // } // return _opiParameter; // } // set // { // _opiParameter = value; // } //} //#endregion //#region gradeSalaryChangeType : GradeSalaryChangeType //private GradeSalaryChangeType _gradeSalaryChangeType; //public GradeSalaryChangeType GradeSalaryChangeType //{ // get // { // if (_GradeSalaryChangeTypeID.Integer > 0 && _GradeSalaryChangeType == null) // { // _GradeSalaryChangeType = new GradeSalaryChangeType(); // _GradeSalaryChangeType = _GradeSalaryChangeType.Get(_GradeSalaryChangeTypeID.Integer); // } // return this._gradeSalaryChangeType; // } // set // { // _GradeSalaryChangeType = value; // } //} //#endregion #region Service Factory IEmployeeGradeSalaryService : IEmployeeGradeSalaryService internal static IEmployeeGradeSalaryService Service { get { return Services.Factory.CreateService(typeof(IEmployeeGradeSalaryService)); } } #endregion #endregion #region Functions public static EmployeeGradeSalary Get(ID employeeid, DateTime effectdate, EnumArrearType type) { EmployeeGradeSalary oEmployeeGradeSalary = null; oEmployeeGradeSalary = EmployeeGradeSalary.Service.Get(employeeid, effectdate, type); return oEmployeeGradeSalary; } public static EmployeeGradeSalary Get(ID employeeid, DateTime effectdate) { EmployeeGradeSalary oEmployeeGradeSalary = null; oEmployeeGradeSalary = EmployeeGradeSalary.Service.Get(employeeid, effectdate,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); return oEmployeeGradeSalary; } public static EmployeeGradeSalary GetBasicOnDate(ID employeeid, DateTime effectdate) { EmployeeGradeSalary oEmployeeGradeSalary = null; oEmployeeGradeSalary = EmployeeGradeSalary.Service.Get(employeeid, effectdate, EnumArrearType.NotPresent); return oEmployeeGradeSalary; } public static ObjectsTemplate GetBasicOnDate(DateTime effectdate) { ObjectsTemplate oEmployeeGradeSalary = null; oEmployeeGradeSalary = EmployeeGradeSalary.Service.Get(effectdate, EnumArrearType.NotPresent); return oEmployeeGradeSalary; } public static DataSet GetEmpBasicGrade(DateTime dEffectDate, DateTime dEffectDate2) { DataSet ds = null; try { ds = Service.GetEmpBasicGrade(dEffectDate, dEffectDate2,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetmultipleTilldatedemp() { DataSet ds = null; try { ds = Service.GetmultipleTilldatedemp(); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetmultipleTilldatedemp(string sEmpIDs) { DataSet ds = null; try { ds = Service.GetmultipleTilldatedemp(sEmpIDs); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetOldGrd(string sEmpIDs) { DataSet ds = null; try { ds = Service.GetOldGrd(sEmpIDs); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetEmpPrvBasicGrade(DateTime effectDate) { DataSet ds = null; try { ds = Service.GetEmpPrvBasicGrade(effectDate,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public void SetObjectID(int IdValue) { this.SetID(ID.FromInteger(IdValue)); } /// /// retrive grade salary data from data base /// /// int /// effect date wise max grade salary public static EmployeeGradeSalary GetMax(int employeeID, EnumArrearType type) { EmployeeGradeSalary oEmployeeGradeSalary = null; oEmployeeGradeSalary = EmployeeGradeSalary.Service.GetMax(employeeID, type); return oEmployeeGradeSalary; } /// /// retrive grade salary data from data base /// /// int, employeeid /// datetime /// effect date wise max grade salary public static ObjectsTemplate Get(int employeeId) { ObjectsTemplate employeeGradeSalarys = null; try { employeeGradeSalarys = Service.Get(employeeId); } catch (ServiceException e) { throw new Exception(e.Message, e); } return employeeGradeSalarys; } public static ObjectsTemplate GetbyEffectDate(ID employeeID, DateTime effectDateFrom, DateTime effectDateTo) { ObjectsTemplate employeeGradeSalarys = null; ; try { employeeGradeSalarys = Service.GetbyEffectDate(employeeID, effectDateFrom, effectDateTo); } catch (ServiceException e) { throw new Exception(e.Message, e); } return employeeGradeSalarys; } public static ObjectsTemplate GetCurrMonthSalaryItems(DateTime nextPayProcessDate) { ObjectsTemplate employeeGradeSalarys = null; ; try { employeeGradeSalarys = Service.GetCurrMonthSalaryItems(nextPayProcessDate); } catch (ServiceException e) { throw new Exception(e.Message, e); } return employeeGradeSalarys; } public static ObjectsTemplate GetArrearItems() { ObjectsTemplate employeeGradeSalarys = null; ; try { employeeGradeSalarys = Service.GetArrearItems(); } catch (ServiceException e) { throw new Exception(e.Message, e); } return employeeGradeSalarys; } public static ObjectsTemplate Get() { ObjectsTemplate employeeGradeSalarys = null; ; try { employeeGradeSalarys = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } return employeeGradeSalarys; } public static ObjectsTemplate Get( ObjectsTemplate gradeSalaryItems, ID employeeid) { ObjectsTemplate employeeGradeSalarys = new ObjectsTemplate(); try { foreach (EmployeeGradeSalary item in gradeSalaryItems) { if (item.EmployeeID == employeeid) { employeeGradeSalarys.Add(item); } } } catch (ServiceException e) { throw new Exception(e.Message, e); } return employeeGradeSalarys; } public void Save() { ObjectsTemplate ocyclies = new ObjectsTemplate(); ObjectsTemplate itemsToSave= process(); if (this.EmpLifeCycle != null) { ID nID = this.EmpLifeCycle.StatusDetailID; EnumEmployeeStatus eStatus = this.EmpLifeCycle.Status; string sDescription = this.EmpLifeCycle.Description; foreach (EmployeeGradeSalary item in itemsToSave) { item.EmpLifeCycle = new EmpLifeCycle(); item.EmpLifeCycle.EmployeeID = item.EmployeeID; item.EmpLifeCycle.GradeID = item.GradeID; item.EmpLifeCycle.EffectDate = item.EffectDate; item.EmpLifeCycle.BasicSalary = item.BasicSalary; item.EmpLifeCycle.Description = sDescription; item.EmpLifeCycle.StatusDetailID = nID; item.EmpLifeCycle.Status = eStatus; ocyclies.Add(item.EmpLifeCycle); } } EmpLifeCycle lifeCycle = new EmpLifeCycle(); lifeCycle.Save(ocyclies); //update audit-trail //foreach (EmployeeGradeSalary item in itemsToSave) // item.SetAuditTrailProperties(); //EmployeeGradeSalary.Service.Save(itemsToSave); } public ObjectsTemplate process() { ObjectsTemplate itemstoSave = new ObjectsTemplate(); EmployeeGradeSalary item; GradeSalaryChangeType effecttype = GradeSalaryChangeType.Get(this.GradeSalaryTypeID); // get the last (max on date) grade salary item grade salary item from the database EmployeeGradeSalary lastgs = EmployeeGradeSalary.GetMax(this.EmployeeID.Integer, EnumArrearType.NotPresent); if (lastgs == null) // true is first time entry for the employee { // if effect date befor the last payprocess date, a arrear item need to prepare if (this.EffectDate <= SystemInformation.CurrentSysInfo.LastPayProcessDate) { //Create an arrear item item = (EmployeeGradeSalary)this.Clone(); item.ArrearType = EnumArrearType.ToCalculate; // arrear item till date must be last payprocess date item.TillDate = SystemInformation.CurrentSysInfo.LastPayProcessDate; itemstoSave.Add(item); item = (EmployeeGradeSalary)this.Clone(); //Normal item effect-date should be first date of the month and it will continue to next change item.EffectDate =GlobalFunctions.FirstDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate); item.TillDate = null; item.ArrearType = EnumArrearType.NotPresent; itemstoSave.Add(item); } else itemstoSave.Add(this); } else { if (this.EffectDate > SystemInformation.CurrentSysInfo.LastPayProcessDate) { lastgs.TillDate = this.EffectDate.AddDays(-1); itemstoSave.Add(lastgs); itemstoSave.Add(this); } else { #region do reverse process // // do reverse engineering // ObjectsTemplate savedItems = // EmployeeGradeSalary.Service.GetbyTillDate(this.EmployeeID.Integer, this.EffectDate, SystemInformation.CurrentSysInfo.LastPayProcessDate); // DateTime tempEffectDate = this.EffectDate; // #region Do reverse engineering // int count = 1; // foreach (EmployeeGradeSalary arrerItem in savedItems) // { // //do not consider arrear to calculate item // // because current save process will delete arrear calculate items first. // if (arrerItem.ArrearType == EnumArrearType.ToCalculate) continue; //// if (arrerItem.ArrearType == EnumArrearType.Paid) continue; // if (arrerItem.EffectDate >= SystemInformation.CurrentSysInfo.LastPayProcessDate) continue; // item =(EmployeeGradeSalary) arrerItem.Clone(); // item.SetState(ObjectState.New); // item.EffectDate = (this.EffectDate >arrerItem.EffectDate)? this.EffectDate : arrerItem.EffectDate; // item.ArrearType = EnumArrearType.ToCalculate; // item.GradeID = this.GradeID; // item.BasicSalary = this.BasicSalary; // item.GrossSalary = this.GrossSalary; // item.PayScaleDetailID = this.PayScaleDetailID; // item.GradeSalaryTypeID = this.GradeSalaryTypeID; // item.TillDate = (arrerItem.TillDate == null) ? // SystemInformation.CurrentSysInfo.LastPayProcessDate : (DateTime)arrerItem.TillDate; // if (arrerItem.TillDate == null) // { // arrerItem.TillDate = SystemInformation.CurrentSysInfo.LastPayProcessDate; // itemstoSave.Add(arrerItem); // } // itemstoSave.Add(item); // count = count + 1; // } // #endregion // if (itemstoSave.Count == 0) // { // item = (EmployeeGradeSalary)this.Clone(); // item.ArrearType = EnumArrearType.ToCalculate; // // arrear item till date must be last payprocess date // item.TillDate = SystemInformation.CurrentSysInfo.LastPayProcessDate; // itemstoSave.Add(item); // } lastgs.TillDate = SystemInformation.CurrentSysInfo.LastPayProcessDate; itemstoSave.Add(lastgs); item = (EmployeeGradeSalary)this.Clone(); item.ArrearType = EnumArrearType.ToCalculate; item.TillDate = SystemInformation.CurrentSysInfo.LastPayProcessDate; itemstoSave.Add(item); // update current item effect date this.EffectDate = SystemInformation.CurrentSysInfo.LastPayProcessDate.AddDays(1); itemstoSave.Add(this); #endregion } } foreach (EmployeeGradeSalary oitem in itemstoSave) oitem.SetAuditTrailProperties(); return itemstoSave; } public static void PrepareDataForCurrentSalary(Employee employee, ObjectsTemplate gradeSalaries) { DateTime calculateMonth = SystemInformation.CurrentSysInfo.NextPayProcessDate; DateTime Upto = GlobalFunctions.LastDateOfMonth(calculateMonth); gradeSalaries[gradeSalaries.Count - 1].TillDate = calculateMonth; if (employee.EndOfContractDate != null && employee.EndOfContractDate != DateTime.MinValue) if (employee.EndOfContractDate < Upto) gradeSalaries[gradeSalaries.Count-1].TillDate = employee.EndOfContractDate; double total = 0; foreach (EmployeeGradeSalary item in gradeSalaries) { if (item.ArrearType == EnumArrearType.NotPresent) if(item.EffectDate < GlobalFunctions.FirstDateOfMonth(calculateMonth)) item.EffectDate = GlobalFunctions.FirstDateOfMonth(calculateMonth); if(item.TillDate!=null) item.FractionofFromTo = GlobalFunctions.GetFraction(item.EffectDate, (DateTime)item.TillDate); else item.FractionofFromTo = GlobalFunctions.GetFraction(item.EffectDate, Upto); total = total + item.FractionofFromTo; } } public void Delete() { //EmployeeGradeSalary updatedItem = null; //if (this.ArrearType != EnumArrearType.ToCalculate) //{ // updatedItem = EmployeeGradeSalary.Get(this.EmployeeID, // this.EffectDate.AddDays(-1), EnumArrearType.NotPresent); //} //if (updatedItem != null) //{ // updatedItem.TillDate = null; // updatedItem.SetAuditTrailProperties(); // EmployeeGradeSalary.Service.Delete(updatedItem, this); //} //else //{ EmployeeGradeSalary.Service.Delete(this); //} } public void DeleteAll() { EmployeeGradeSalary.Service.DeleteAll(); } #endregion } #endregion #region IEmployeeGradeSalary Service public interface IEmployeeGradeSalaryService { ObjectsTemplate Get(); EmployeeGradeSalary GetMax(int employeeID, EnumArrearType type); ObjectsTemplate Get(int employeeID); EmployeeGradeSalary Get(ID employeeid, DateTime effectdate, EnumArrearType type); ObjectsTemplate Get(DateTime effectdate, EnumArrearType type); EmployeeGradeSalary Get(ID employeeid, DateTime effectdate, int payrollTypeID); ObjectsTemplate GetbyTillDate(int employeeID, DateTime tillDateFrom, DateTime tillDateTo); ObjectsTemplate GetbyEffectDate(ID employeeID, DateTime effectDateFrom, DateTime effectDateTo); //specially for salary process ObjectsTemplate GetCurrMonthSalaryItems(DateTime nextPayProcessDate); ObjectsTemplate GetArrearItems(); ObjectsTemplate GetArrearPaidItems(ID employeeid, DateTime tillDateFrom); void DeleteFrom(int employeeID, DateTime fromDate); void Delete(EmployeeGradeSalary gradeSalary); //void Delete(EmployeeGradeSalary updateItem, EmployeeGradeSalary deletedItem); void DeleteAll(); void Save(ObjectsTemplate itemsToSave); DataSet GetEmpBasicGrade(DateTime dEffectDate, DateTime dEffectDate2, int payrollTypeID); DataSet GetEmpPrvBasicGrade(DateTime effectDate, int payrollTypeID); DataSet GetmultipleTilldatedemp(); DataSet GetmultipleTilldatedemp(string sEmpIDs); DataSet GetOldGrd(string sEmpIDs); } #endregion }