using HRM.BO; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using System.Linq; using HRM.Service; using System.Data; namespace HRM.DA { #region EmpLeaveStatus Service public class EmpLeaveStatusService : ServiceTemplate//, ILeaveProcessService { public EmpLeaveStatusService() { } //#region Private functions and declaration ////Cache _cache = new Cache(typeof(EmpLeaveStatus)); private void MapObject(EmpLeaveStatus oEmpLeaveStatus, DataReader oReader) { //this.SetObjectID(oEmpLeaveStatus,ID.FromInteger(oReader.GetInt32("TranId"))); base.SetObjectID(oEmpLeaveStatus, oReader.GetInt32("TranId").Value); oEmpLeaveStatus.ProcessId = oReader.GetInt32("ProcessId").Value; oEmpLeaveStatus.EmpId = oReader.GetInt32("EmpId").Value; oEmpLeaveStatus.LeaveYearID = oReader.GetInt32("LEAVEYEARID").Value; oEmpLeaveStatus.LeaveId = oReader.GetInt32("LeaveId").Value; //oEmpLeaveStatus.GradeId = oReader.GetInt32("GradeId"); //oEmpLeaveStatus.ParamId = oReader.GetInt32("ParamId"); oEmpLeaveStatus.CarryFromPrvYear = oReader.GetDouble("CarryFromPrvYear").Value; oEmpLeaveStatus.CFDays = oReader.GetDouble("CFDays").Value; oEmpLeaveStatus.EncashDays = oReader.GetDouble("EncashDays").Value; oEmpLeaveStatus.EncashAmount = oReader.GetDouble("EncashAmount").Value; oEmpLeaveStatus.NormalLeaveDays = oReader.GetDouble("NormalLeaveDays").Value; oEmpLeaveStatus.YearEndBalance = oReader.GetDouble("YearEndBalance").Value; oEmpLeaveStatus.LeaveAvailed = oReader.GetDouble("LEAVEAVAILED").Value; oEmpLeaveStatus.OpeningBalance = oReader.GetDouble("OPENINGBALANCE").Value; oEmpLeaveStatus.ForfitedDays = oReader.GetDouble("FORFITEDDAYS").Value; //this.SetObjectState(oEmpLeaveStatus, ObjectState.Saved); this.SetObjectState(oEmpLeaveStatus, Ease.Core.ObjectState.Saved); } //private EmpLeaveStatus CreateObject(NullHandler oReader) protected override T CreateObject(DataReader oReader) { EmpLeaveStatus oEmpLeaveStatus = new EmpLeaveStatus(); MapObject(oEmpLeaveStatus, oReader); return oEmpLeaveStatus as T; } protected EmpLeaveStatus CreateObject(DataReader oReader) { EmpLeaveStatus oEmpLeaveStatus = new EmpLeaveStatus(); MapObject(oEmpLeaveStatus, oReader); return oEmpLeaveStatus; } //#endregion //#region Service implementation private List CurrentYearStatusOptimized(Employee oEmployee, DateTime operationDate, int presentAttnCount, List oAppLeaveParams, LeaveYear oCurrYear, List oLeaveEntries, EnumLeaveStatus enumLeaveStatus, List oPrevStatuses, List ParamDetails, List oExceptions, List oNationalHolidays, DateTime NextPayProcessDate) { try { DateTime dCurrentDate = operationDate; DateTime from_Date = DateTime.MinValue; DateTime to_Date = DateTime.MinValue; List oCurrYearBalance = new List(); LeaveParameterDetail oDetail = null; foreach (LeaveParameter oItem in oAppLeaveParams) { EmpLeaveStatus oPrevStatus = null; EmpLeaveStatus oCurrStatus = new EmpLeaveStatus(); oCurrStatus.EmpId = oEmployee.ID; oCurrStatus.LeaveId = oItem.LeaveId; oCurrStatus.LeaveYearID = oCurrYear.ID; // int empId = oEmployee.ID; from_Date = Global.DateFunctions.FirstDateOfYear(operationDate); to_Date = Global.DateFunctions.LastDateOfYear(operationDate); if (oItem.LeaveId == 5) { #region old code //DateTime SelectedMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).LastDateOfMonth(); //from_Date = new DateTime(to_Date.Year - 2, oEmployee.JoiningDate.Month, oEmployee.JoiningDate.Day); //DataSet ds = new DailyAttnProcessService().GetEarnedLeaveOpening(oEmployee.ID, oItem.LeaveId, from_Date, to_Date); //int dCurrectedDay = 0; //if (DateTime.DaysInMonth(SelectedMonth.Year, SelectedMonth.Month) < oEmployee.JoiningDate.Day) // dCurrectedDay = DateTime.DaysInMonth(SelectedMonth.Year, SelectedMonth.Month); //else // dCurrectedDay = oEmployee.JoiningDate.Day; //DateTime JoiningDateBefore2YearsFromCurrentYear = new DateTime(SelectedMonth.Year, SelectedMonth.Month, dCurrectedDay).AddYears(-2);// new DateTime(DateTime.Today.Year- 2, item.JoiningDate.Month, item.JoiningDate.Day);// SelectedMonth.FirstDateOfMonth().AddYears(-2); //DateTime FirstYearStartDate = JoiningDateBefore2YearsFromCurrentYear; //DateTime FirstYearEndDate = JoiningDateBefore2YearsFromCurrentYear.AddYears(1).AddDays(-1); //DateTime LastYearStartDate = JoiningDateBefore2YearsFromCurrentYear.AddYears(1); //DateTime LastYearEndDate = JoiningDateBefore2YearsFromCurrentYear.AddYears(2).AddDays(-1); //double secondYearLeaveAvailed = new LeaveEntryService().Get(oEmployee.ID, LastYearStartDate, LastYearEndDate, EnumLeaveStatus.Approved).Sum(x => x.ApprovedTotalDays); ////List les = LeaveEncashment.GetByEmpIDs(oEmployee.ID.Integer.ToString(), FirstYearStartDate, FirstYearEndDate); //if (ds != null && ds.Tables.Count > 0) //{ // foreach (DataRow dr in ds.Tables[0].Rows) // { // oCurrStatus.OpeningBalance = Convert.ToDouble(dr[0].ToString()); // oCurrStatus.LeaveAvailed = Convert.ToDouble(dr[1].ToString()); //secondYearLeaveAvailed; // oCurrStatus.EncashDays = 0;// les==null?0:les.Sum(x=> Math.Round(x.EncashmentDays)); // oCurrStatus.YearEndBalance = oCurrStatus.OpeningBalance - (oCurrStatus.LeaveAvailed + oCurrStatus.EncashDays); // } //} #endregion DateTime dtTo = oCurrYear.EndDate < DateTime.Today ? oCurrYear.EndDate : DateTime.Today; DateTime dtAvailed = oEmployee.JoiningDate; LeaveYear ly = new LeaveYearService().LastLeaveYear(oCurrYear); while (dtAvailed < ly.StartDate) { dtAvailed = dtAvailed.AddYears(1); } DataTable dt = new LeaveService().GetELInfo(oEmployee.ID, oEmployee.JoiningDate, dtTo, dtAvailed); if (dt != null) { foreach (DataRow dr in dt.Rows) { if (dr[0].ToString() == "Leave Availed this") { oCurrStatus.LeaveAvailed = Convert.ToDouble(dr[1].ToString()); } else if (dr[0].ToString() == "Present Days") { oCurrStatus.OpeningBalance = Convert.ToDouble(dr[1].ToString()); oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance == 0 ? 0 : oCurrStatus.OpeningBalance / 18; } else if (dr[0].ToString() == "Encash Days") { oCurrStatus.OpeningBalance -= Convert.ToDouble(dr[1].ToString()); } else if (dr[0].ToString() == "Leave Availed") { oCurrStatus.NormalLeaveDays = Convert.ToDouble(dr[1].ToString()); } } oCurrStatus.OpeningBalance -= oCurrStatus.NormalLeaveDays; oCurrStatus.OpeningBalance = Math.Round(oCurrStatus.OpeningBalance, 2); oCurrStatus.OpeningBalance = oItem.MaxAccumulatedDays < oCurrStatus.OpeningBalance ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance; oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - oCurrStatus.LeaveAvailed, 2); } oCurrYearBalance.Add(oCurrStatus); } else { //List les = LeaveEntry.GetByLeaveID(oItem.LeaveId, empId, from_Date, to_Date); List les = oLeaveEntries.Where(le => le.LeaveID == oItem.LeaveId && le.EmpID == empId && le.ApprovedFromDate >= from_Date && le.ApprovedFromDate <= to_Date && le.ApprovedTotalDays > 0) .OrderByDescending(x => x.ApprovedFromDate) .ToList(); //double countDays = 0; //foreach (LeaveEntry le in les) //{ // countDays += le.AppliedTotalDays; //} //oCurrStatus.ApplyDays = countDays; oCurrStatus.ApplyDays = les.Sum(x => x.AppliedTotalDays); // if (oPrevStatuses != null) { oPrevStatus = oPrevStatuses.FirstOrDefault(el => el.LeaveId == oItem.LeaveId && el.EmpId == oEmployee.ID); //EmpLeaveStatus.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer); } oDetail = new LeaveParameterService().GetApplicableForEmployee2(oEmployee, operationDate, ParamDetails, oItem.ID); //LeaveException oLeaveEx = oExceptions.Find(delegate(LeaveException el) { return el.LeaveID == oItem.LeaveId && el.EmployeeID == oEmployee.ID.Integer; }); //EmpLeaveStatus.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer); LeaveException oLeaveEx = oExceptions.FirstOrDefault(el => el.LeaveID == oItem.LeaveId && el.EmployeeID == oEmployee.ID); //EmpLeaveStatus.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer); if (oLeaveEx != null) { oCurrStatus.LeaveAvailed = oLeaveEntries.Where(le => le.LeaveID == oItem.LeaveId && le.EmpID == empId && le.LeaveYearId == oCurrYear.ID && le.ApprovedTotalDays > 0 && le.LeaveStatus == EnumLeaveStatus.Approved) .Sum(x => x.ApprovedTotalDays); oCurrStatus.OpeningBalance = oLeaveEx.OpeningBalance + oLeaveEx.MaxDays; oCurrStatus.YearEndBalance = oCurrStatus.OpeningBalance - oCurrStatus.LeaveAvailed; } else { #region From Master if (oDetail != null) oCurrStatus.NormalLeaveDays = 0; else continue; //oItem.Details = new List(); //oItem.Details.Add(oDetail); #region calculate the current year balance if (oItem.ApplicableFor == LeaveApplicableType.Confirmed) { // No Fraction For Echo if (oEmployee.IsConfirmed == true) { oCurrStatus.CurrentYearBalance = Math.Round(GetOptimizedCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, presentAttnCount, oDetail, oCurrYear), 0); } else oCurrStatus.CurrentYearBalance = 0; } else { // No Fraction For Echo oCurrStatus.CurrentYearBalance = Math.Round(GetOptimizedCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, presentAttnCount, oDetail, oCurrYear), 0); } #endregion #region calculate leave availed in current year if (oLeaveEntries == null) oCurrStatus.LeaveAvailed = 0; else { var itemsInCart = from o in oLeaveEntries where o.EmpID == oEmployee.ID && o.LeaveID == oItem.LeaveId && o.LeaveYearId == oCurrYear.ID && (o.LeaveStatus == enumLeaveStatus || o.LeaveStatus == EnumLeaveStatus.Cancel_Request) select new { o.ApprovedTotalDays }; oCurrStatus.LeaveAvailed = itemsInCart.ToList().Select(c => c.ApprovedTotalDays).Sum(); } #endregion #region calculate the opening balance new //oCurrStatus.CurrentYearOpening = oPrevStatus == null ? 0 : oPrevStatus.YearEndBalance; oCurrStatus.CurrentYearOpening = oPrevStatus == null ? 0 : Math.Round(oPrevStatus.CFDays); oCurrStatus.OpeningBalance = oCurrStatus.CurrentYearBalance + oCurrStatus.CurrentYearOpening; if (oItem.MaxAccumulatedDays > 0) { // No Fraction For Echo oCurrStatus.OpeningBalance = Math.Round(oCurrStatus.OpeningBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance, 0); //,1); } #endregion #region Calculate Year-End Balance oCurrStatus.YearEndBalance = 0; #region COMPENSATORY LEAVE based on Nation Holiday if (oItem.LeaveId == 7) { List oEmpDailAttnProcesses = new DailyAttnProcessService().Get(oEmployee.ID, NextPayProcessDate.FirstDateOfMonth(), NextPayProcessDate.LastDateOfMonth()); double nDays = 0; foreach (DailyAttnProcess dp in oEmpDailAttnProcesses) { if (dp.InTime != DateTime.MinValue) { AttnNationalHoliday nh = oNationalHolidays.Find(x => dp.AttnDate >= x.FromDate && dp.AttnDate <= x.ToDate); if (nh != null) nDays++; } } oCurrStatus.OpeningBalance = nDays; } #endregion if (oItem.Leave.IsBalanceCalculationNeeded == false) { oCurrStatus.NormalLeaveDays = 0; oCurrStatus.OpeningBalance = 0; } else { // No Fraction For Echo oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 0); // 1); } #endregion #endregion #region From Echotex desktop App #endregion } if (oItem.Leave.IsBalanceCalculationNeeded) { if (oDetail.MaxCF > 0) { oCurrStatus.CFDays = oCurrStatus.YearEndBalance > oDetail.MaxCF ? oDetail.MaxCF : oCurrStatus.YearEndBalance; } oCurrYearBalance.Add(oCurrStatus); } } } return oCurrYearBalance; } catch (Exception exp) { //MessageBox.Show(oEmployee.EmployeeNo); throw new Exception(exp.Message); } } private static double GetOptimizedCurrentYearDays(EnumLeaveCalculationType eType, Employee emp, DateTime dCurrentDate, int presentAttnCount, LeaveParameterDetail oDetail, LeaveYear oCurrentYear) { double nTotalDays = 0; TimeSpan ts = new TimeSpan(); if (eType == EnumLeaveCalculationType.Daily) { if (presentAttnCount > 0) { nTotalDays = (double)presentAttnCount / 18; } } else if (eType == EnumLeaveCalculationType.Monthly) { ts = (dCurrentDate - ((emp.JoiningDate > oCurrentYear.StartDate) ? emp.JoiningDate : Global.DateFunctions.FirstDateOfYear(dCurrentDate))) .Add(TimeSpan.FromDays(1)); nTotalDays = (oDetail.MaxDays * ts.Days) / 365; } else if (eType == EnumLeaveCalculationType.Yearly) { ts = (dCurrentDate - ((emp.JoiningDate > oCurrentYear.StartDate) ? emp.JoiningDate : Global.DateFunctions.FirstDateOfYear(dCurrentDate))) .Add(TimeSpan.FromDays(1)); if (ts.Days > 365) { nTotalDays = (double)oDetail.MaxDays; } // Else '0' , What?????????????????? } else if (eType == EnumLeaveCalculationType.Not_Applicable) { ts = (Global.DateFunctions.LastDateOfYear(dCurrentDate) - Global.DateFunctions.FirstDateOfYear(dCurrentDate)).Add(TimeSpan.FromDays(1)); nTotalDays = (oDetail.MaxDays * ts.Days) / 365; } else if (eType == EnumLeaveCalculationType.Not_Applicable_With_Prorated) { ts = (Global.DateFunctions.LastDateOfYear(dCurrentDate) - ((emp.JoiningDate > oCurrentYear.StartDate) ? emp.JoiningDate : Global.DateFunctions.FirstDateOfYear(dCurrentDate))) .Add(TimeSpan.FromDays(1)); nTotalDays = (oDetail.MaxDays * ts.Days) / 365; } return Math.Round(nTotalDays, 0); } public List CurrentYearStatus(List oEmployees, LeaveYear lYear, DateTime operationDate, EnumLeaveStatus eStatus, DateTime NextPayProcessDate) { try { //UpdateprocessStatus("Collecting Leave Information ...."); if (operationDate.Date > lYear.EndDate) operationDate = lYear.EndDate.Date; DateTime oEmpOperationDate; List oCurrYearBalance = null; List oAllEmpsCurrYearBalance = new List(); LeaveYear oCurrYear = lYear; LeaveYear oPrvYear = new LeaveYearService().LastLeaveYear(oCurrYear); List setupTypes = new SetupDetailService().GetTypes(EnumParameterSetup.Leave); List setupDetails = new SetupDetailService().GetParameters(EnumParameterSetup.Leave); List leaveParamss = new LeaveParameterService().Get(); List leaveParamDetails = new LeaveParameterService().GetDetails(); List oLs = new LeaveEntryService().Get(oEmployees.CommaSeparatedIDs(), oCurrYear.ID, EnumLeaveStatus.Approved);// LeaveEntry.GetByLeaveYear(oCurrYear.ID.Integer); List oPrevStatuses = new LeaveProcessService().GetByYear(oPrvYear.ID); List oExceptions = new LeaveExceptionService().Get(lYear.StartDate, lYear.EndDate); DataTable oYearlyDailyAttnProcess = new DailyAttnProcessService().GetTypeWiseAttnCount(oEmployees.CommaSeparatedIDs(), Global.DateFunctions.FirstDateOfYear(operationDate), Global.DateFunctions.LastDateOfYear(operationDate), EnumAttendanceType.Present, EnumAttendanceType.Early, EnumAttendanceType.Late, EnumAttendanceType.Delay, EnumAttendanceType.OutSideDuty, EnumAttendanceType.HalfDay); List oNationalHolidays = new AttnNationalHolidayService().GetByMonth(oCurrYear.StartDate, oCurrYear.EndDate); DataRow dRow = null; int presentCount = 0; int nMax = oEmployees.Count; int ncc = 0; //UpdateProgressStatus(EnumProcessStatus.Start); foreach (Employee oEmp in oEmployees) { //UpdateProgressStatus(EnumProcessStatus.PerformStep); int nCount = ++ncc; if (nCount == 98) nCount = 98; //UpdateprocessStatus("Collecting Leave Information " + (nCount).ToString() + "/" + nMax); oEmpOperationDate = operationDate; if (oEmp.EndOfContractDate != null) { if (oEmp.EndOfContractDate < lYear.StartDate) continue; if (oEmp.EndOfContractDate.Value < operationDate) { oEmpOperationDate = oEmp.EndOfContractDate.Value; } } dRow = oYearlyDailyAttnProcess.AsEnumerable().FirstOrDefault(x => Convert.ToInt32(x["EmployeeID"].ToString()) == oEmp.ID); presentCount = dRow != null ? Convert.ToInt32(dRow["Count"].ToString()) : 0; List oAppLeaveParams = new LeaveParameterService().ApplicableParamsForReport(oEmp, setupTypes, setupDetails, leaveParamss); oCurrYearBalance = new EmpLeaveStatusService().CurrentYearStatusOptimized(oEmp, operationDate, presentCount, oAppLeaveParams, oCurrYear, oLs, eStatus, oPrevStatuses, leaveParamDetails, oExceptions, oNationalHolidays , NextPayProcessDate); foreach (EmpLeaveStatus eSts in oCurrYearBalance) { oAllEmpsCurrYearBalance.Add(eSts); } } //UpdateProgressStatus(EnumProcessStatus.End); //ProcessStatus = null; //ProgressStatus = null; return oAllEmpsCurrYearBalance; } catch (Exception exp) { // Nothing } return new List(); } //public EmpLeaveStatus Get(int id) //{ // EmpLeaveStatus oEmpLeaveStatus = new EmpLeaveStatus(); // #region Cache Header // oEmpLeaveStatus = (EmpLeaveStatus)_cache["Get", id]; // if (oEmpLeaveStatus != null) // return oEmpLeaveStatus; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader oreader = new DataReader(EmpLeaveStatusDA.Get(tc, id)); // if (oreader.Read()) // { // oEmpLeaveStatus = CreateObject(oreader); // } // oreader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Employee Leave Status", e); // #endregion // } // #region Cache Footer // _cache.Add(oEmpLeaveStatus, "Get", id); // #endregion // return oEmpLeaveStatus; //} //public EmpLeaveStatus GetStatus(int empid, int leaveID, int leaveYearID) //{ // EmpLeaveStatus oEmpLeaveStatus = new EmpLeaveStatus(); // #region Cache Header // oEmpLeaveStatus = (EmpLeaveStatus)_cache["Get", empid, leaveID, leaveYearID]; // if (oEmpLeaveStatus != null) // return oEmpLeaveStatus; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader oreader = new DataReader(EmpLeaveStatusDA.GetStatus(tc, empid, leaveID, leaveYearID)); // if (oreader.Read()) // { // oEmpLeaveStatus = CreateObject(oreader); // } // oreader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Employee Leave Status", e); // #endregion // } // #region Cache Footer // _cache.Add(oEmpLeaveStatus, "Get", empid, leaveID, leaveYearID); // #endregion // return oEmpLeaveStatus; //} //public EmpLeaveStatus GetByYear(int leaveyearID, int LeaveId, int EmpId) //{ // EmpLeaveStatus oEmpLeaveStatus = null; // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader oreader = new DataReader(EmpLeaveStatusDA.GetByYear(tc, leaveyearID, LeaveId, EmpId)); // if (oreader.Read()) // { // oEmpLeaveStatus = CreateObject(oreader); // } // oreader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Employee Leave Status", e); // #endregion // } // return oEmpLeaveStatus; //} //public List GetByYear(int leaveyearID) //{ // #region Cache Header // List empLeaveStatuss = _cache["Get", leaveyearID] as List; // if (empLeaveStatuss != null) // return empLeaveStatuss; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader oreader = new DataReader(EmpLeaveStatusDA.GetByYear(tc, leaveyearID)); // empLeaveStatuss = this.CreateObjects(oreader); // oreader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Employee Leave Status", e); // #endregion // } // #region Cache Footer // _cache.Add(empLeaveStatuss, "Get", leaveyearID); // #endregion // return empLeaveStatuss; //} //public List Get(int nProcessId) //{ // #region Cache Header // List empLeaveStatuss = _cache["Get", nProcessId] as List; // if (empLeaveStatuss != null) // return empLeaveStatuss; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader oReader = new DataReader(EmpLeaveStatusDA.GetByProcessId(tc, nProcessId)); // empLeaveStatuss = this.CreateObjects(oReader); // oReader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Employee Leave Status", e); // #endregion // } // #region Cache Footer // _cache.Add(empLeaveStatuss, "Get", nProcessId); // #endregion // return empLeaveStatuss; //} //public List GetAllStatus(int empId) //{ // #region Cache Header // List empLeaveStatuss = _cache["Get", empId] as List; // if (empLeaveStatuss != null) // return empLeaveStatuss; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader oReader = new DataReader(EmpLeaveStatusDA.GetAllStatus(tc, empId)); // empLeaveStatuss = this.CreateObjects(oReader); // oReader.Close(); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get Employee Leave Status", e); // #endregion // } // #region Cache Footer // _cache.Add(empLeaveStatuss, "Get", empId); // #endregion // return empLeaveStatuss; //} //public ID Insert(EmpLeaveStatus oEmpLeaveStatus) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // if (oEmpLeaveStatus.IsNew) // { // int id = tc.GenerateID("EmpLeaveStatus", "TranId"); // base.SetObjectID(oEmpLeaveStatus, ID.FromInteger(id)); // EmpLeaveStatusDA.Insert(tc, oEmpLeaveStatus); // } // else // EmpLeaveStatusDA.Update(tc, oEmpLeaveStatus); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Insert Employee Leave Status", e); // #endregion // } // return oEmpLeaveStatus.ID; //} //public void SaveStatus(EmpLeaveStatus oEmpLeaveStatus) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // if (oEmpLeaveStatus.IsNew) // { // // this.SetObjectID(oEmpLeaveStatus, ID.FromInteger(EmpLeaveStatusDA.GetNewID(tc))); // EmpLeaveStatusDA.Insert(tc, oEmpLeaveStatus); // } // //else // // EmpLeaveStatusDA.Update(tc, oEmpLeaveStatus); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Insert Employee Leave Status", e); // #endregion // } //} //internal void SaveAtProcessing(bool IsUpdate, int ProcessId, List oEmpLeaveStatuss, TransactionContext tc) //{ // foreach (EmpLeaveStatus oItem in oEmpLeaveStatuss) // { // if (IsUpdate) EmpLeaveStatusDA.Update(tc, oItem); // else // { // this.SetObjectID(oItem, ID.FromInteger(EmpLeaveStatusDA.GetNewID(tc))); // oItem.ProcessId = ProcessId; // EmpLeaveStatusDA.Insert(tc, oItem); // } // } //} //public void Delete(int id) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // EmpLeaveStatusDA.Delete(tc, id); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Delete Employee Leave Status", e); // #endregion // } //} //public void Delete(int nProcessId) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // EmpLeaveStatusDA.DeleteByProcessId(tc, nProcessId); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Delete Employee Leave Status", e); // #endregion // } //} //#endregion public DataTable CurrentYearStatusOptimized(string sEmpIDs, LeaveYear lYear, EnumLeaveStatus eStatus, DateTime NextPayProcessDate) { DataTable dTEmpLeave = new DataTable(); dTEmpLeave.Columns.Add("Leave", typeof(System.String)); dTEmpLeave.Columns.Add("Opening", typeof(System.String)); dTEmpLeave.Columns.Add("Availed", typeof(System.String)); dTEmpLeave.Columns.Add("Balance", typeof(System.String)); dTEmpLeave.Columns.Add("EmpNo", typeof(System.String)); dTEmpLeave.Columns.Add("Name", typeof(System.String)); dTEmpLeave.Columns.Add("Designation", typeof(System.String)); dTEmpLeave.Columns.Add("Division", typeof(System.String)); dTEmpLeave.Columns.Add("Department", typeof(System.String)); dTEmpLeave.Columns.Add("Unit", typeof(System.String)); dTEmpLeave.Columns.Add("CFDays", typeof(System.String)); dTEmpLeave.Columns.Add("Floor", typeof(System.String)); dTEmpLeave.Columns.Add("Section", typeof(System.String)); dTEmpLeave.Columns.Add("Line", typeof(System.String)); try { DataTable dtEmpBasicInfo = new EmployeeService().GetAllEmpBasicInfo(sEmpIDs) .Tables[0] .AsEnumerable() .OrderBy(x => Convert.ToInt32(x["EmployeeID"].ToString())) .CopyToDataTable(); List oCurrYearBalance = null; List oAllEmpsCurrYearBalance = new List(); DateTime operationDate = GlobalFunctionDA.GetOperationDate(); if (operationDate.Date > lYear.EndDate.Date) { operationDate = lYear.EndDate.Date; } DateTime oEmpOperationDate; DataTable oYearlyDailyAttnProcess = new DailyAttnProcessService().GetTypeWiseAttnCount(sEmpIDs, Global.DateFunctions.FirstDateOfYear(operationDate), Global.DateFunctions.LastDateOfYear(operationDate), EnumAttendanceType.Present, EnumAttendanceType.Early, EnumAttendanceType.Late, EnumAttendanceType.Delay, EnumAttendanceType.HalfDay, EnumAttendanceType.OutSideDuty) .AsEnumerable() .OrderBy(x => Convert.ToInt32(x["EmployeeID"].ToString())) .CopyToDataTable(); LeaveYear oCurrYear = lYear; LeaveYear oPrvYear = new LeaveYearService().LastLeaveYear(oCurrYear); List setupTypes = new SetupDetailService().GetTypes(EnumParameterSetup.Leave); List setupDetails = new SetupDetailService().GetParameters(EnumParameterSetup.Leave); List leaveParamss = new LeaveParameterService().Get(); List leaveParamDetails = new LeaveParameterService().GetDetails(); List oLs = new LeaveEntryService().GetByLeaveYear(oCurrYear.ID); List oPrevStatuses = new LeaveProcessService().GetByYear(oPrvYear.ID); List oExceptions = new LeaveExceptionService().Get(lYear.StartDate, lYear.EndDate); Queue oEmployees = new Queue(new EmployeeService().GetByEmpIDs(sEmpIDs).OrderBy(x => x.ID)); List oNationalHolidays = new AttnNationalHolidayService().GetByMonth(oCurrYear.StartDate, oCurrYear.EndDate); List leaveTypes = new LeaveService().GetAll(); foreach (DataRow drBasic in dtEmpBasicInfo.Rows) { Employee oEmp = null; int presentCount = 0; if (oEmployees.Any() && oEmployees.Peek().ID == Convert.ToInt32(drBasic["EmployeeID"].ToString())) { oEmp = oEmployees.Dequeue(); } else { continue; } oEmpOperationDate = operationDate; if (oEmp.EndOfContractDate != null) { if (oEmp.EndOfContractDate < lYear.StartDate) continue; if (oEmp.EndOfContractDate.Value < operationDate) { oEmpOperationDate = oEmp.EndOfContractDate.Value; } } DataRow dRow = oYearlyDailyAttnProcess.AsEnumerable().FirstOrDefault(x => Convert.ToInt32(x["EmployeeID"].ToString()) == Convert.ToInt32(drBasic["EmployeeID"].ToString())); presentCount = dRow != null ? Convert.ToInt32(dRow["Count"].ToString()) : 0; List oAppLeaveParams = new LeaveParameterService().ApplicableParamsForReportOptimized(oEmp, setupTypes, setupDetails, leaveParamss, leaveTypes); oCurrYearBalance = new EmpLeaveStatusService().CurrentYearStatusOptimized(oEmp, oEmpOperationDate, presentCount, oAppLeaveParams, oCurrYear, oLs, eStatus, oPrevStatuses, leaveParamDetails, oExceptions, oNationalHolidays, NextPayProcessDate); DataRow oRow = null; foreach (EmpLeaveStatus eSts in oCurrYearBalance) { eSts.Leave = leaveTypes.Find(l => l.ID == eSts.LeaveId); oRow = dTEmpLeave.NewRow(); if (drBasic != null) { oRow["EmpNo"] = drBasic["EmployeeNo"]; oRow["Name"] = drBasic["Name"]; oRow["Designation"] = drBasic["Designation"]; oRow["Department"] = drBasic["Department"]; oRow["Floor"] = drBasic["Floor"]; oRow["Section"] = drBasic["Section"]; oRow["Line"] = drBasic["Line"]; oRow["Unit"] = string.Empty; } oRow["Leave"] = eSts.Leave.Description; oRow["Opening"] = eSts.OpeningBalance.ToString(); oRow["Availed"] = eSts.LeaveAvailed.ToString(); oRow["Balance"] = eSts.ClosingBalance.ToString(); dTEmpLeave.Rows.Add(oRow); } } return dTEmpLeave; } catch (Exception) { } return dTEmpLeave; } public DataTable CurrentYearStatusForEncashment(string sEmpIDs, LeaveYear lYear, EnumLeaveStatus eStatus, DateTime EncashMonth) { DataTable dTEmpLeave = new DataTable(); dTEmpLeave.Columns.Add("EmpName", typeof(System.String)); dTEmpLeave.Columns.Add("JoiningDate", typeof(System.String)); dTEmpLeave.Columns.Add("EmpNo", typeof(System.String)); dTEmpLeave.Columns.Add("Designation", typeof(System.String)); dTEmpLeave.Columns.Add("AccountNo", typeof(System.String)); dTEmpLeave.Columns.Add("TINNo", typeof(System.String)); dTEmpLeave.Columns.Add("Department", typeof(System.String)); dTEmpLeave.Columns.Add("Floor", typeof(System.String)); dTEmpLeave.Columns.Add("Section", typeof(System.String)); dTEmpLeave.Columns.Add("Line", typeof(System.String)); dTEmpLeave.Columns.Add("CC", typeof(System.String)); dTEmpLeave.Columns.Add("CCCode", typeof(System.String)); dTEmpLeave.Columns.Add("Grade", typeof(System.String)); dTEmpLeave.Columns.Add("Gross", typeof(System.String)); dTEmpLeave.Columns.Add("Present", typeof(System.String)); dTEmpLeave.Columns.Add("Holiday", typeof(System.String)); dTEmpLeave.Columns.Add("Abcent", typeof(System.String)); dTEmpLeave.Columns.Add("CL", typeof(System.String)); dTEmpLeave.Columns.Add("SL", typeof(System.String)); dTEmpLeave.Columns.Add("SPL", typeof(System.String)); dTEmpLeave.Columns.Add("COM", typeof(System.String)); dTEmpLeave.Columns.Add("PL", typeof(System.String)); dTEmpLeave.Columns.Add("ML", typeof(System.String)); dTEmpLeave.Columns.Add("LWOP", typeof(System.String)); dTEmpLeave.Columns.Add("EL", typeof(System.String)); dTEmpLeave.Columns.Add("ELDays", typeof(System.String)); dTEmpLeave.Columns.Add("ELPayment", typeof(System.String)); dTEmpLeave.Columns.Add("TDSAIT", typeof(System.String)); dTEmpLeave.Columns.Add("Net", typeof(double)); dTEmpLeave.Columns.Add("Remarks", typeof(System.String)); dTEmpLeave.Columns.Add("Signature", typeof(System.String)); dTEmpLeave.Columns.Add("NetSum", typeof(string)); dTEmpLeave.Columns.Add("EnjoyedLeave", typeof(double)); dTEmpLeave.Columns.Add("EncashmentFromDate", typeof(System.DateTime)); dTEmpLeave.Columns.Add("EncashmentToDate", typeof(System.DateTime)); dTEmpLeave.Columns.Add("LeaveBalance", typeof(double)); try { DataTable dtEmpBasicInfo = new EmployeeService().GetAllEmpBasicInfo(sEmpIDs) .Tables[0] .AsEnumerable() .OrderBy(x => Convert.ToInt32(x["EmployeeID"].ToString())) .CopyToDataTable(); List leaveEncashments = new LeaveEncashmentService().GetByEmpIDs(sEmpIDs, lYear.ID, EncashMonth); //List oCurrYearBalance = null; //List oAllEmpsCurrYearBalance = new List(); //DateTime operationDate = GlobalFunctions.GetOperationDate(); //if (operationDate.Date > lYear.EndDate.Date) //{ // operationDate = lYear.EndDate.Date; //} //DateTime oEmpOperationDate; //DataTable oYearlyDailyAttnProcess = DailyAttnProcess.GetTypeWiseAttnCount(sEmpIDs, operationDate.FirstDateOfYear(), operationDate.LastDateOfYear(), EnumAttendanceType.Present, EnumAttendanceType.Early, EnumAttendanceType.Late, EnumAttendanceType.Delay, EnumAttendanceType.HalfDay, EnumAttendanceType.OutSideDuty) // .AsEnumerable() // .OrderBy(x => Convert.ToInt32(x["EmployeeID"].ToString())) // .CopyToDataTable(); LeaveYear oCurrYear = lYear; //LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear); //List setupTypes = SetupDetail.GetTypes(EnumParameterSetup.Leave); //List setupDetails = SetupDetail.GetParameters(EnumParameterSetup.Leave); //List leaveParamss = LeaveParameter.Get(); //List leaveParamDetails = new LeaveParameter().GetAllDetails(); //List oLs = LeaveEntry.GetByLeaveYear(oCurrYear.ID.Integer); //List oPrevStatuses = EmpLeaveStatus.GetAllPrvYearStatus(oCurrYear.ID.Integer); //List oExceptions = LeaveException.Get(lYear.StartDate, lYear.EndDate); Queue oEmployees = new Queue(new EmployeeService().GetByEmpIDs(sEmpIDs).OrderBy(x => x.ID)); double net = 0; foreach (DataRow drBasic in dtEmpBasicInfo.Rows) { //Employee oEmp = null; ////int presentCount = 0; //if (oEmployees.Any() && oEmployees.Peek().ID.Integer == Convert.ToInt32(drBasic["EmployeeID"].ToString())) //{ // oEmp = oEmployees.Dequeue(); //} //else //{ // continue; //} LeaveEncashment le = leaveEncashments.Where(x => x.EmployeeID == Convert.ToInt32(drBasic["EmployeeID"].ToString())).FirstOrDefault(); if (le == null) { continue; } //oEmpOperationDate = operationDate; //if (oEmp.EndOfContractDate != null) //{ // if (oEmp.EndOfContractDate < lYear.StartDate) // continue; // if (oEmp.EndOfContractDate.Value < operationDate) // { // oEmpOperationDate = oEmp.EndOfContractDate.Value; // } //} //DataRow dRow = oYearlyDailyAttnProcess.AsEnumerable().FirstOrDefault(x => Convert.ToInt32(x["EmployeeID"].ToString()) == Convert.ToInt32(drBasic["EmployeeID"].ToString())); //presentCount = dRow != null ? Convert.ToInt32(dRow["Count"].ToString()) : 0; //List oAppLeaveParams = LeaveParameter.ApplicableParamsForReportOptimized(oEmp, setupTypes, setupDetails, leaveParamss); //oCurrYearBalance = EmpLeaveStatus.CurrentYearStatusOptimized(oEmp, oEmpOperationDate, presentCount, oAppLeaveParams, oCurrYear, oLs, eStatus, oPrevStatuses, leaveParamDetails, oExceptions); DataRow oRow = null; oRow = dTEmpLeave.NewRow(); net = 0; if (drBasic != null) { oRow["EmpNo"] = drBasic["EmployeeNo"]; oRow["EmpName"] = drBasic["Name"]; oRow["Designation"] = drBasic["Designation"]; oRow["Department"] = drBasic["Department"]; oRow["Floor"] = drBasic["Floor"]; oRow["Section"] = drBasic["Section"]; oRow["Line"] = drBasic["Line"]; //oRow["Unit"] = string.Empty; oRow["JoiningDate"] = Convert.ToDateTime(drBasic["JoiningDate"].ToString()).ToString("dd MMM yyyy"); oRow["AccountNo"] = drBasic["ACCOUNTNO"]; oRow["TINNo"] = drBasic["TINNO"]; oRow["CC"] = ""; oRow["CCCode"] = ""; oRow["Grade"] = drBasic["GradeName"]; oRow["Gross"] = le.GrossSalary.ToString("N2"); //Convert.ToDouble(drBasic["GROSSSALARY"].ToString()).ToString("N2"); oRow["Present"] = le.presentDays.ToString();/*le.PresentDays.ToString();*/ oRow["Holiday"] = le.holiDays.ToString();/*le.HoliDays.ToString();*/ oRow["Abcent"] = le.absentDays.ToString();/*le.AbsentDays.ToString();*/ oRow["ELDays"] = le.EncashmentDays.ToString("N2"); oRow["ELPayment"] = le.Amount.ToString("N2"); oRow["TDSAIT"] = le.TaxAmount.ToString("N2"); oRow["CL"] = "0"; oRow["SL"] = "0"; oRow["SPL"] = "0"; oRow["COM"] = "0"; oRow["PL"] = "0"; oRow["ML"] = "0"; oRow["LWOP"] = "0"; oRow["EL"] = "0"; oRow["Net"] = le.Amount; oRow["EnjoyedLeave"] = le.enjoyedLeave;/*le.EnjoyedLeave;*/ oRow["EncashmentFromDate"] = le.EncashmentFromDate; oRow["EncashmentToDate"] = le.EncashmentToDate; oRow["LeaveBalance"] = le.LeaveBalance; } //foreach (EmpLeaveStatus eSts in oCurrYearBalance) //{ // switch (eSts.Leave.Code) // { // case "CL": // oRow["CL"] = eSts.ClosingBalance.ToString(); // break; // case "SL": // oRow["SL"] = eSts.ClosingBalance.ToString(); // break; // case "SPL": // oRow["SPL"] = eSts.ClosingBalance.ToString(); // break; // case "COM": // oRow["COM"] = eSts.ClosingBalance.ToString(); // break; // case "PL": // oRow["PL"] = eSts.ClosingBalance.ToString(); // break; // case "ML": // oRow["ML"] = eSts.ClosingBalance.ToString(); // break; // case "LWOP": // oRow["LWOP"] = eSts.ClosingBalance.ToString(); // break; // case "EL": // oRow["EL"] = eSts.ClosingBalance.ToString(); // break; // default: // break; // } //} dTEmpLeave.Rows.Add(oRow); } return dTEmpLeave; } catch (Exception ex) { } return dTEmpLeave; } } #endregion }