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 { [Serializable] public class OvertimeProcess { private ObjectsTemplate _EmpOvertimes = null; private ObjectsTemplate _OtProcess = null; public OvertimeProcess() { } public ObjectsTemplate ProcessData { get { return _OtProcess; } } public ObjectsTemplate GetTerms(ID nEmpID) { Employee oEmp = Employee.Get(nEmpID); if (oEmp != null && !oEmp.ID.IsUnassigned && oEmp.ID.Integer > 0 && !oEmp.GradeID.IsUnassigned && oEmp.GradeID.Integer > 0) { return GetTerms(oEmp); } return null; } public ObjectsTemplate GetTerms(Employee oEmp) { ObjectsTemplate terms = null; if (oEmp != null && !oEmp.ID.IsUnassigned && oEmp.ID.Integer > 0 && !oEmp.GradeID.IsUnassigned && oEmp.GradeID.Integer > 0) { ObjectsTemplate termParams = TermParameter.GetByGradeID(oEmp.GradeID); if (termParams != null) { terms = new ObjectsTemplate(); foreach (TermParameter param in termParams) { if (!terms.Exists(delegate(Term trm) { return trm.ID.Integer == param.Term.ID.Integer; })) { terms.Add(param.Term); } } } } return terms; } public ObjectsTemplate GetTermParameters(Employee oEmp) { if (oEmp != null && !oEmp.ID.IsUnassigned && oEmp.ID.Integer > 0 && !oEmp.GradeID.IsUnassigned && oEmp.GradeID.Integer > 0) { ObjectsTemplate termParams = TermParameter.GetByGradeID(oEmp.GradeID); return termParams; } return null; } public ObjectsTemplate GetTermParameters(ID nEmpID) { Employee oEmp = Employee.Get(nEmpID); return GetTermParameters(oEmp); } public void Process() { TermParameter.EntryType = ConfigurationManager.GetStringValue("overtime", "entrytype", EnumConfigurationType.Logic); bool calOnEarnedBasic = ConfigurationManager.GetBoolValue("overtime", "earnedbasic", EnumConfigurationType.Logic); int basicOnMonth = ConfigurationManager.GetIntValue("overtime", "basicondate", EnumConfigurationType.Logic); if (basicOnMonth == 0) basicOnMonth = 1; int ncount = 0; try { _OtProcess = new ObjectsTemplate(); _EmpOvertimes = EmployeeOverTime.Get(SystemInformation.CurrentSysInfo.NextPayProcessDate, Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID); double basicSalary = 0; if (_EmpOvertimes != null && _EmpOvertimes.Count > 0) { foreach (EmployeeOverTime ot in _EmpOvertimes) { //if (ot.EmployeeID.Integer != 2602) //{ // ncount++; // continue; //} //DateTime basicDate = new DateTime(ot.OTMonth.Year, ot.OTMonth.Month, basicOnMonth); //if (ncount == 139) //{ // ncount = ncount; //} DateTime basicDate = GlobalFunctions.LastDateOfMonth(ot.OTMonth); if (calOnEarnedBasic == false) { EmployeeGradeSalary gs = EmployeeGradeSalary.Get(ot.EmployeeID, basicDate, EnumArrearType.NotPresent); if (gs == null) gs = EmployeeGradeSalary.Get(ot.EmployeeID, GlobalFunctions.LastDateOfMonth(ot.OTMonth), EnumArrearType.ToCalculate); if (gs == null) { if (ot.Employee.BasicSalary == 0) { throw new ServiceException(" Basic salary not found for the employee:" + ot.Employee.Name + "( " + ot.Employee.EmployeeNo + ") on month" + ot.OTMonth.ToString("MMM yyyy")); } else { //DateTime dMonth = SystemInformation.CurrentSysInfo.NextPayProcessDate; //if(ot.Employee.JoiningDate.Month == SystemInformation.CurrentSysInfo.NextPayProcessDate.Month && // ot.Employee.JoiningDate.Month == SystemInformation.CurrentSysInfo.NextPayProcessDate.Month) // dMonth =ot.Employee.JoiningDate; basicSalary = ot.Employee.BasicSalary; } } //else basicSalary = gs.BasicSalary * GlobalFunctions.GetFractinalOfMonth(gs.EffectDate); // doesn't need to fractionate, cause it is not base on earned basic; else basicSalary = gs.BasicSalary; //else basicSalary = ot.Employee.BasicSalary; // for redisha back process } else { SalaryMonthly salary = SalaryMonthly.Get(ot.EmployeeID, GlobalFunctions.LastDateOfMonth(ot.OTMonth)); if (salary == null) { EmployeeGradeSalary gs = EmployeeGradeSalary.Get(ot.EmployeeID, GlobalFunctions.LastDateOfMonth(ot.OTMonth), EnumArrearType.NotPresent); if (gs == null) gs = EmployeeGradeSalary.Get(ot.EmployeeID, GlobalFunctions.LastDateOfMonth(ot.OTMonth), EnumArrearType.ToCalculate); if (gs == null) { if (ot.Employee.BasicSalary == 0) { throw new ServiceException(" Basic salary not found for the employee:" + ot.Employee.Name + "( " + ot.Employee.EmployeeNo + ") on month" + ot.OTMonth.ToString("MMM yyyy")); } else basicSalary = ot.Employee.BasicSalary;//* GlobalFunctions.GetFractinalOfMonth(ot.Employee.JoiningDate); } else basicSalary = gs.BasicSalary; //else basicSalary = gs.BasicSalary * GlobalFunctions.GetFractinalOfMonth(gs.EffectDate); } else { EmployeeGradeSalary gs = EmployeeGradeSalary.Get(ot.EmployeeID, basicDate, EnumArrearType.NotPresent); if (gs != null) { if (gs.GradeID.Integer == 2) { EmployeeGradeSalary gs2 = EmployeeGradeSalary.Get(ot.EmployeeID, gs.EffectDate.AddDays(-1), EnumArrearType.NotPresent); if (gs2 != null) { basicSalary = gs2.BasicSalary; } } else { basicSalary = gs.BasicSalary; } } else basicSalary = salary.ThisMonthBasic; //salary.GetGrossAmount(EnumSalaryItemCode.Basic_Salary, (int)EnumSalaryItemCode.Basic_Salary); } } _OtProcess.Add(CreateObject(ot, basicSalary)); ncount++; } } } catch { ncount = ncount; } } public ObjectsTemplate Process(Employee oEmp) { _OtProcess = new ObjectsTemplate(); _EmpOvertimes = EmployeeOverTime.GetByEmpID(oEmp.ID, SystemInformation.CurrentSysInfo.NextPayProcessDate); if (_EmpOvertimes != null && _EmpOvertimes.Count > 0) { foreach (EmployeeOverTime ot in _EmpOvertimes) { _OtProcess.Add(CreateObject(ot, ot.Employee.BasicSalary)); } OTProcess.Save(_OtProcess); } return _OtProcess; } public OTProcess ProcessArrear(OTProcess process, Double nBasic) { OTProcess oNewProcess = CreateObject(process.EmpOverTime, nBasic); process.Amount = oNewProcess.Amount - process.Amount; return process; } private OTProcess CreateObject(EmployeeOverTime ot, Double nBasic) { OTProcess process = new OTProcess(); if (ot.EmployeeID.Integer == 341) { int a = 0; } process.EmployeeID = ot.EmployeeID; process.EmpOverTimeID = ot.ID; process.MonthDate = GlobalFunctions.LastDateOfMonth(ot.MonthDate); process.OTMonth = GlobalFunctions.LastDateOfMonth(ot.OTMonth); process.TermID = ot.TermID; process.TermParameterID = ot.TermParameterID; double nHour = 0; //switch (TermParameter.EntryType.ToUpper()) //{ // case "MINUTE": // nHour = Math.Floor(ot.OTHours); // nHour += (ot.OTHours - nHour) / 100 * 60; // break; // default: // nHour = Math.Floor(ot.OTHours); // nHour += (ot.OTHours - nHour) / 100 * 60; // break; //} //process.TotalHour = nHour; process.TotalHour = ot.OTHours; process.Amount = ot.OTHours;// ot.TermParam.GetPayableAmount(ot, nBasic); process.PayrollTypeID = Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID; return process; } } }