using System; using System.Collections.Generic; using System.Linq; using System.Data; using Ease.Core.Model; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace HRM.BO { #region EmployeeGradeSalary public class EmployeeGradeSalary : AuditTrailBase { #region Constructor public EmployeeGradeSalary() { EmployeeID = 0; TillDate = DateTime.MinValue; EffectDate = DateTime.MinValue; BasicSalary = 0; GradeID = 0; GrossSalary = 0; PayScaleDetailID = 0; ArrearType = EnumArrearType.NotPresent; GradeSalaryTypeID = 0; //Employee = null; //Grade = null; //PayScaleDetail = null; FractionofFromTo = 1; } #endregion #region Properties public int EmployeeID { get; set; } public DateTime? TillDate { get; set; } public DateTime EffectDate { get; set; } public double BasicSalary { get; set; } public int GradeID { get; set; } public double GrossSalary { get; set; } public double? Increment { get; set; } public int PayScaleDetailID { get; set; } public EnumArrearType ArrearType { get; set; } public int GradeSalaryTypeID { get; set; } public GradeSalaryChangeType gradeSalaryType { get; set; } public double FractionofFromTo { get; set; } public int EmployeeSerial { get; set; } public Employee Employee { get; set; } public Grade Grade { get; set; } public PayScaleDetail PayScaleDetail { get; set; } public EmployeeGradeSalary GetClone() { EmployeeGradeSalary oItem = new EmployeeGradeSalary(); oItem.EmployeeID = this.EmployeeID; oItem.TillDate = this.TillDate; oItem.EffectDate = this.EffectDate; oItem.BasicSalary = this.BasicSalary; oItem.GradeID = this.GradeID; oItem.GrossSalary = this.GrossSalary; oItem.Increment = this.Increment; oItem.PayScaleDetailID = this.PayScaleDetailID; oItem.ArrearType = this.ArrearType; oItem.GradeSalaryTypeID = this.GradeSalaryTypeID; oItem.FractionofFromTo = this.FractionofFromTo; oItem.EmployeeSerial = this.EmployeeSerial; return oItem; } public List ADParameters { get; set; } //public List ADParameters //{ // get // { // if (_adPrameters == null) // { // throw new ServiceException("Allowance Deduction Parameter Not yet set"); // } // return _adPrameters; // } // set // { // _adPrameters = value; // } //} //private List _errorList; //public List ErrorList //{ // get { return _errorList; } // set { _errorList = value; } //} //#region Service Factory IEmployeeGradeSalaryService : IEmployeeGradeSalaryService //internal static IEmployeeGradeSalaryService Service //{ // get { return Services.Factory.CreateService(typeof(IEmployeeGradeSalaryService)); } //} //#endregion #endregion public static void PrepareDataForCurrentSalary(DateTime salaryMonth, Employee employee, List gradeSalaries) { DateTime calculateMonth = salaryMonth; DateTime Upto = GlobalFunctions.LastDateOfMonth(calculateMonth); DateTime empJoiningDate = employee.JoiningDate; 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(empJoiningDate > item.EffectDate ? empJoiningDate : item.EffectDate, (DateTime)item.TillDate); else item.FractionofFromTo = GlobalFunctions.GetFraction(empJoiningDate > item.EffectDate ? empJoiningDate : item.EffectDate, Upto); total = total + item.FractionofFromTo; } } public static void PrepareDataForMaternityLeaveReturnCurrentSalary(Employee employee, List gradeSalaries, DateTime returnDate, DateTime salaryMonth) { DateTime from = returnDate; DateTime toDate = salaryMonth; gradeSalaries[gradeSalaries.Count - 1].TillDate = toDate; if (employee.EndOfContractDate != null && employee.EndOfContractDate != DateTime.MinValue) if (employee.EndOfContractDate < toDate) gradeSalaries[gradeSalaries.Count - 1].TillDate = employee.EndOfContractDate; foreach (EmployeeGradeSalary item in gradeSalaries) { if (item.ArrearType == EnumArrearType.NotPresent) { if (item.EffectDate < GlobalFunctions.FirstDateOfMonth(toDate)) { item.EffectDate = GlobalFunctions.FirstDateOfMonth(toDate); } } item.FractionofFromTo = GlobalFunctions.GetFraction(from > item.EffectDate ? from : item.EffectDate, item.TillDate != null ? (DateTime)item.TillDate : toDate); // total = total + item.FractionofFromTo; } } //public static List GetMonthlySalary(List gradesalaries, ID employeeID, DateTime effectDateFrom, DateTime effectDateTo) //{ // List employeeGradeSalarys = null; ; // List lists = new List(); // try // { // employeeGradeSalarys = gradesalaries.FindAll((delegate(EmployeeGradeSalary item) { return item.EmployeeID.Integer == employeeID.Integer; })); // // employeeGradeSalarys = Service.Get(employeeID.Integer); // int preID = 0; // for (DateTime date = effectDateFrom; date <= effectDateTo; date = date.AddMonths(1)) // { // List empGradeSalarys = null; // List emptempGradeSalarys = null; // EmployeeGradeSalary empGradeSalary = null; // empGradeSalarys = employeeGradeSalarys.Where(o => o.EffectDate <= date).ToList(); // emptempGradeSalarys = employeeGradeSalarys.Where(o => o.EffectDate == date).ToList(); // if (empGradeSalarys.Count > 0) // { // dynamic obj = empGradeSalarys.Select(e => new // { // id = e.ID.Integer, // EmployeeID = e.EmployeeID, // SalaryMonth = Global.DateFunctions.PayrollLastDateOfMonth(date), // GradeID = e.GradeID, // BasicSalary = e.BasicSalary, // EventCount = emptempGradeSalarys.Count // //IsSpecial=(e.GradeSalaryTypeID.Integer==23 && preID!=e.ID.Integer)?true:false // }).OrderByDescending(x => x.BasicSalary).FirstOrDefault(); // //dynamic obj = new { EmployeeID = empGradeSalary.EmployeeID, SalaryMonth = Global.DateFunctions.PayrollLastDateOfMonth(date), // // GradeID = empGradeSalary.GradeID, // // BasicSalary = empGradeSalary.BasicSalary // //}; // //preID = obj.GetType().GetProperty("id").GetValue(obj, null); // lists.Add(obj); // } // } // return lists; // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } //} //public static List GetMonthlySalary(List gradesalaries, List omonthlySalarys, ID employeeID, DateTime effectDateFrom, DateTime effectDateTo) //{ // List employeeGradeSalarys = null; ; // SalaryMonthly omonthlySalary = null; // List lists = new List(); // try // { // employeeGradeSalarys = gradesalaries.FindAll((delegate(EmployeeGradeSalary item) { return item.EmployeeID.Integer == employeeID.Integer; })); // // employeeGradeSalarys = Service.Get(employeeID.Integer); // int preID = 0; // bool flag = false; // int gid = 0; // for (DateTime date = effectDateFrom; date <= effectDateTo; date = date.AddMonths(1)) // { // List empGradeSalarys = null; // List emptempGradeSalarys = null; // EmployeeGradeSalary fracGradeSalary = null; // EmployeeGradeSalary empGradeSalary = null; // omonthlySalary = omonthlySalarys.FirstOrDefault(x => x.EmployeeID == employeeID && x.SalaryMonth == Global.DateFunctions.PayrollLastDateOfMonth(date)); // empGradeSalarys = employeeGradeSalarys.Where(o => o.EffectDate <= date).ToList(); // emptempGradeSalarys = employeeGradeSalarys.Where(o => o.EffectDate == date).ToList(); // fracGradeSalary = employeeGradeSalarys.Where(o => o.EffectDate > PayrollPayrollGlobalFunctions.PayrollFirstDateOfMonth(date) && o.EffectDate <= PayrollPayrollGlobalFunctions.PayrollLastDateOfMonth(date)).ToList().OrderByDescending(x => x.BasicSalary).FirstOrDefault(); ; // EmployeeGradeSalary prevEmpGradeSalary1 = empGradeSalarys.OrderByDescending(x => x.BasicSalary).FirstOrDefault(); // if (gid == 0 && prevEmpGradeSalary1 !=null) // { // gid = prevEmpGradeSalary1.GradeID.Integer; // } // if (!flag && date.Month==Payroll.BO.SystemInformation.CurrentSysInfo.NextPayProcessDate.Month) //return from IA in current month // { // List empLifecycle = EmpLifeCycle.Get(employeeID, date); // if(empLifecycle.Count>0) // { // bool isIAReturn = false; // isIAReturn = empLifecycle.Any(x => x.StatusDetailID.Integer == 33 && x.EffectDate.Year == date.Year && x.EffectDate.Month == date.Month); // if (isIAReturn) // { // flag = true; // } // } // } // if(omonthlySalary!=null) // { // flag = true; // if (fracGradeSalary == null || !(fracGradeSalary!=null && gid==26 && fracGradeSalary.GradeID.Integer==16)) // { // SalaryMonthlyDetail sd = omonthlySalary.GetDetail(EnumSalaryGroup.Arrear, EnumSalaryItemCode.Basic_Salary, (int)EnumSalaryItemCode.Basic_Salary); // //SalaryMonthlyDetail arrearAllo = omonthlySalary.GetDetail(EnumSalaryGroup.Gross, EnumSalaryItemCode.Allowance, 64); // dynamic obj = new // { // id = omonthlySalary.ID.Integer, // EmployeeID = omonthlySalary.EmployeeID, // SalaryMonth = omonthlySalary.SalaryMonth, // GradeID = omonthlySalary.GradeID, // BasicSalary = omonthlySalary.GetDetail(EnumSalaryGroup.Gross, EnumSalaryItemCode.Basic_Salary, (int)EnumSalaryItemCode.Basic_Salary).ChangedAmount + // (sd != null ? sd.ChangedAmount : 0) , // EventCount = omonthlySalarys.Count // //IsSpecial=(e.GradeSalaryTypeID.Integer==23 && preID!=e.ID.Integer)?true:false // }; // //dynamic obj = new { EmployeeID = empGradeSalary.EmployeeID, SalaryMonth = Global.DateFunctions.PayrollLastDateOfMonth(date), // // GradeID = empGradeSalary.GradeID, // // BasicSalary = empGradeSalary.BasicSalary // //}; // //preID = obj.GetType().GetProperty("id").GetValue(obj, null); // lists.Add(obj); // gid = omonthlySalary.GradeID.Integer; // } // else // { // EmployeeGradeSalary prevEmpGradeSalary = empGradeSalarys.Where(o => o.EffectDate < fracGradeSalary.EffectDate).OrderByDescending(x => x.BasicSalary).FirstOrDefault(); // TimeSpan ts = fracGradeSalary.EffectDate - PayrollPayrollGlobalFunctions.PayrollFirstDateOfMonth(date); // dynamic obj = new // { // id = prevEmpGradeSalary.ID.Integer, // EmployeeID = prevEmpGradeSalary.EmployeeID, // SalaryMonth = Global.DateFunctions.PayrollLastDateOfMonth(date), // GradeID = prevEmpGradeSalary.GradeID, // BasicSalary =prevEmpGradeSalary.BasicSalary/30* ts.Days, // EventCount = omonthlySalarys.Count // //IsSpecial=(e.GradeSalaryTypeID.Integer==23 && preID!=e.ID.Integer)?true:false // }; // lists.Add(obj); // obj = new // { // id = fracGradeSalary.ID.Integer, // EmployeeID = fracGradeSalary.EmployeeID, // SalaryMonth = Global.DateFunctions.PayrollLastDateOfMonth(date), // GradeID = fracGradeSalary.GradeID, // BasicSalary = fracGradeSalary.BasicSalary / 30 * (30-ts.Days), // EventCount = omonthlySalarys.Count // //IsSpecial=(e.GradeSalaryTypeID.Integer==23 && preID!=e.ID.Integer)?true:false // }; // lists.Add(obj); // } // } // else if (empGradeSalarys.Count > 0 && flag) // { // dynamic obj = empGradeSalarys.Select(e => new // { // id = e.ID.Integer, // EmployeeID = e.EmployeeID, // SalaryMonth = Global.DateFunctions.PayrollLastDateOfMonth(date), // GradeID = e.GradeID, // BasicSalary = e.BasicSalary, // EventCount = emptempGradeSalarys.Count // //IsSpecial=(e.GradeSalaryTypeID.Integer==23 && preID!=e.ID.Integer)?true:false // }).OrderByDescending(x => x.BasicSalary).FirstOrDefault(); // //dynamic obj = new { EmployeeID = empGradeSalary.EmployeeID, SalaryMonth = Global.DateFunctions.PayrollLastDateOfMonth(date), // // GradeID = empGradeSalary.GradeID, // // BasicSalary = empGradeSalary.BasicSalary // //}; // //preID = obj.GetType().GetProperty("id").GetValue(obj, null); // lists.Add(obj); // } // } // return lists; // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } //} public List process() { List itemstoSave = new List(); //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 = PayrollPayrollGlobalFunctions.PayrollFirstDateOfMonth(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 // if (User.CurrentUser.LogInPayrollTypeID.Integer == 1) // { // List 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.EffectDate >= SystemInformation.CurrentSysInfo.LastPayProcessDate) continue; // item = (EmployeeGradeSalary)arrerItem.Clone(); // item.SetState(ObjectState.New); // item.EffectDate = (count == 1) ? 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); // } // } // else // { // 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 List process(EmployeeGradeSalary lastgs) { List itemstoSave = new List(); //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 = PayrollPayrollGlobalFunctions.PayrollFirstDateOfMonth(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 // if (User.CurrentUser.LogInPayrollTypeID.Integer == 1) // { // List 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.EffectDate >= SystemInformation.CurrentSysInfo.LastPayProcessDate) continue; // item = (EmployeeGradeSalary)arrerItem.Clone(); // item.SetState(ObjectState.New); // item.EffectDate = (count == 1) ? 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); // } // } // else // { // 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; } } #endregion #region IEmployeeGradeSalary Service public interface IEmployeeGradeSalaryService { List Get(); EmployeeGradeSalary GetMax(int employeeID, EnumArrearType type); List Get(int employeeID); EmployeeGradeSalary Get(int employeeid, DateTime effectdate, EnumArrearType type); EmployeeGradeSalary GetBasicOnDateBAT(int employeeid, DateTime effectDate); List Get(DateTime effectdate, EnumArrearType type); EmployeeGradeSalary Get(int employeeid, DateTime effectdate, int payrollTypeID); EmployeeGradeSalary GetPeviousSalary(int employeeid, int GradeSalaryID); // List GetbyTillDate(int employeeID, DateTime tillDateFrom, DateTime tillDateTo); List GetbyEffectDate(int employeeID, DateTime effectDateFrom, DateTime effectDateTo); //specially for salary process // List GetCurrMonthSalaryItems(DateTime nextPayProcessDate); List GetArrearItems(int payrollTypeID); List GetArrearPaidItems(int employeeid, DateTime tillDateFrom, int payrollTypeID); void DeleteFrom(int employeeID, DateTime fromDate); void Delete(EmployeeGradeSalary gradeSalary); //void Delete(EmployeeGradeSalary updateItem, EmployeeGradeSalary deletedItem); void DeleteAll(); void Delete(int pkid); void Save(List itemsToSave); DataSet GetEmpBasicGrade(DateTime dEffectDate, DateTime dEffectDate2, int payrollTypeID); DataSet GetEmpPrvBasicGrade(DateTime effectDate, int payrollTypeID); DataSet GetmultipleTilldatedemp(int payrollTypeID); DataTable GetSalaryHistory(int employeeID); } #endregion }