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 { #region LeaveProcessDetail [Serializable] public class LeaveProcessDetail : UpdateAuditTrail { #region Cache Store private static Cache _cache = new Cache(typeof(LeaveProcessDetail)); #endregion #region Constructor public LeaveProcessDetail() { _nProcessId = 0; _nEmpId = 0; _leaveYearID = 0; _nLeaveId = 0; _carryFromPrvYear = 0; _nCFDays = 0; _nEncashDays = 0; _nEncashAmount = 0; _nNormalLeaveDays = 0; _nYearEndBalance = 0; _nleaveavailed = 0; _nOpeningBalance = 0; _nForFitedDays = 0; } #endregion #region Properties #region ProcessId private int _nProcessId; public int ProcessId { get { return _nProcessId; } set { _nProcessId = value; } } #endregion #region EmpId private int _nEmpId; public int EmpId { get { return _nEmpId; } set { _nEmpId = value; } } #endregion #region ProcessDate private int _leaveYearID; public int LeaveYearID { get { return _leaveYearID; } set { _leaveYearID = value; } } #endregion #region LeaveId private int _nLeaveId; public int LeaveId { get { return _nLeaveId; } set { _nLeaveId = value; } } #endregion #region ForBenifitedYear private double _carryFromPrvYear; public double CarryFromPrvYear { get { return _carryFromPrvYear; } set { _carryFromPrvYear = value; } } #endregion #region CFDays private double _nCFDays; public double CFDays { get { return _nCFDays; } set { _nCFDays = value; } } #endregion #region EncashDays private double _nEncashDays; public double EncashDays { get { return _nEncashDays; } set { _nEncashDays = value; } } #endregion #region EncashAmount private double _nEncashAmount; public double EncashAmount { get { return _nEncashAmount; } set { _nEncashAmount = value; } } #endregion #region NormalLeaveDays private double _nNormalLeaveDays; public double NormalLeaveDays { get { return _nNormalLeaveDays; } set { _nNormalLeaveDays = value; } } public double ClosingBalance { get { return _nYearEndBalance; } } #endregion #region YearEndBalance private double _nYearEndBalance; public double YearEndBalance { get { return _nYearEndBalance; } set { _nYearEndBalance = value; } } #endregion #region Leave Availed private double _nleaveavailed; public double LeaveAvailed { get { return _nleaveavailed; } set { _nleaveavailed = value; } } #endregion #region Emp Opening Balance private double _nOpeningBalance; public double OpeningBalance { get { return _nOpeningBalance; } set { _nOpeningBalance = value; } } #endregion #region Forfited Days private double _nForFitedDays; public double ForfitedDays { get { return _nForFitedDays; } set { _nForFitedDays = value; } } #endregion private Leave _oLeave; public Leave Leave { get { if ( _nLeaveId != 0) { _oLeave = new Leave().Get(ID.FromInteger(_nLeaveId)); } return _oLeave; } } #endregion //private EmpLeaveStatus _empLeaveStatus; //public EmpLeaveStatus EmpLeaveStatus //{ // get // { // //if (_empLeaveStatuss == null) // //{ // // _empLeaveStatuss = EmpLeaveStatus(); // //} // return _empLeaveStatus; // } // set { _empLeaveStatus = value; } //} public static ObjectsTemplate CurrentYearStatus(int nEmpId) { LeaveParameter oLeaveParameter=new LeaveParameter(); LeaveYear oCurrYear = LeaveYear.GetCurrentYear(); DateTime dCurrentDate = SystemInformation.GetServerDate(); if (oCurrYear == null) return null; Employee oEmployee = Employee.Service.Get(ID.FromInteger(nEmpId)); ObjectsTemplate oLeaveParameters = LeaveParameter.Get(true);//Should get all active leave params. // oLeaveParameters = oLeaveParameter.ApplicableParams(oEmployee); if (oLeaveParameters == null) return null; ObjectsTemplate oAppLeaveParams = null; LeaveParameterDetail oDetail = null; ObjectsTemplate oCurrYearBalance = new ObjectsTemplate(); oAppLeaveParams = LeaveParameter.ApplicableParams(oEmployee); if (oAppLeaveParams == null) return null; foreach (LeaveParameter oItem in oAppLeaveParams) { LeaveProcessDetail oPrevStatus; LeaveProcessDetail oCurrStatus = new LeaveProcessDetail(); oCurrStatus.EmpId = nEmpId; oCurrStatus.LeaveId = oItem.LeaveId; if (oItem.Leave.ApplicableFor ==oEmployee.Gender || oItem.Leave.ApplicableFor == EnumGender.Other) { // oDetail = oItem.Details.GetApplicableForEmployee(oEmployee, oCurrYear); oPrevStatus = LeaveProcessDetail.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer); if (oPrevStatus != null) { if (oItem.IsForfited) { if (oCurrYear.StartDate.AddMonths(oItem.ForfitedMonth).Month >= dCurrentDate.Date.Month) { double nLeaveAvailed =0;//LeaveEntry.GetAvailedLeave(); oCurrStatus.ForfitedDays = oPrevStatus.YearEndBalance - nLeaveAvailed; oCurrStatus.ForfitedDays = (oCurrStatus.ForfitedDays < 0) ? 0 : oCurrStatus.ForfitedDays; } } } if (oDetail != null) oCurrStatus.NormalLeaveDays = oDetail.MaxDays; else continue; //block for property chage by ashek //if (oItem.IsMonthlyBalance && oDetail.EligibleMonth>0) // oCurrStatus.NormalLeaveDays =Math.Round(oCurrStatus.NormalLeaveDays / oDetail.EligibleMonth * oDetail.MonthPassed); oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance + oCurrStatus.NormalLeaveDays; oCurrStatus.LeaveAvailed = LeaveEntry.GetLeaveAmtByType(oEmployee.ID.Integer, oItem.ID.Integer, oCurrYear.ID.Integer, EnumLeaveStatus.Approved); oCurrStatus.YearEndBalance = oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed); if (!oItem.Leave.IsBalanceCalculationNeeded && oCurrStatus.LeaveAvailed ==0) { oCurrStatus.NormalLeaveDays = 0; oCurrStatus.YearEndBalance = 0; oCurrStatus.OpeningBalance = 0; } //if (oCurrStatus.YearEndBalance < 0) Math.Abs(oCurrStatus.YearEndBalance); if (oCurrStatus.ClosingBalance != 0 || oCurrStatus.OpeningBalance !=0) oCurrYearBalance.Add(oCurrStatus); } } return oCurrYearBalance; } public static ObjectsTemplate CurrentYearStatus(int nEmpId, int nLeaveID) { LeaveYear oCurrYear = LeaveYear.GetCurrentYear(); if (oCurrYear == null) return null; Employee oEmployee = Employee.Service.Get(ID.FromInteger(nEmpId)); ObjectsTemplate oLeaveParameters = new ObjectsTemplate(); LeaveParameterDetail oDetail = null; ObjectsTemplate oCurrYearBalance = new ObjectsTemplate(); // oLeaveParameters = LeaveParameter.Get(oEmployee.SBUID, oEmployee.LocationID, oEmployee.FunctionId,nLeaveID); foreach (LeaveParameter oItem in oLeaveParameters) { LeaveProcessDetail oPrevStatus; LeaveProcessDetail oCurrStatus = new LeaveProcessDetail(); oCurrStatus.EmpId = nEmpId; oCurrStatus.LeaveId = oItem.LeaveId; if (oItem.Leave.ApplicableFor == oEmployee.Gender || oItem.Leave.ApplicableFor == EnumGender.Other) { oDetail = oItem.GetDetailForEmp(oEmployee.ID); oPrevStatus = LeaveProcessDetail.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer); if (oPrevStatus != null) oCurrStatus.YearEndBalance = oPrevStatus.CFDays; if (oDetail != null) { oCurrStatus.NormalLeaveDays = oDetail.MaxDays; } else { continue; } oCurrStatus.LeaveAvailed = LeaveEntry.GetLeaveAmtByType(oEmployee.ID.Integer, oItem.ID.Integer, oCurrYear.ID.Integer, EnumLeaveStatus.Approved); oCurrYearBalance.Add(oCurrStatus); } } return oCurrYearBalance; } public static LeaveProcessDetail GetYearStatus(int nYear, int nLeaveId, int nEmpId) { return LeaveProcessDetail.Service.GetByYear(nYear, nLeaveId, nEmpId); } public static LeaveProcessDetail GetPrvYearStatus(int leaveYearID, int nLeaveId, int nEmpId) { LeaveYear oCurrYear = LeaveYear.Service.Get(ID.FromInteger(leaveYearID)); LeaveYear oPrvYear=null; ObjectsTemplate olYears = LeaveYear.Service.Get(); foreach (LeaveYear oItem in olYears) { if (oItem.EndDate.AddDays(1) == oCurrYear.StartDate) { oPrvYear= oItem; break; } } if (oPrvYear == null) return null; return LeaveProcessDetail.Service.GetStatus(nEmpId, nLeaveId, oPrvYear.ID.Integer); } #region Functions public LeaveProcessDetail Get(ID nTranId) { LeaveProcessDetail oLeaveProcessDetail = null; #region Cache Header oLeaveProcessDetail = (LeaveProcessDetail)_cache["Get", nTranId]; if (oLeaveProcessDetail != null) return oLeaveProcessDetail; #endregion oLeaveProcessDetail = LeaveProcessDetail.Service.Get(nTranId); #region Cache Footer _cache.Add(oLeaveProcessDetail, "Get", nTranId); #endregion return oLeaveProcessDetail; } public LeaveProcessDetail GetStatus(int empid, int leaveID, int leaveYearID) { LeaveProcessDetail oLeaveProcessDetail = null; #region Cache Header oLeaveProcessDetail = (LeaveProcessDetail)_cache["Get", empid, leaveID, leaveYearID]; if (oLeaveProcessDetail != null) return oLeaveProcessDetail; #endregion oLeaveProcessDetail = LeaveProcessDetail.Service.GetStatus(empid,leaveID,leaveYearID); #region Cache Footer _cache.Add(oLeaveProcessDetail, "Get", empid, leaveID, leaveYearID); #endregion return oLeaveProcessDetail; } public static ObjectsTemplate GetByYear(int leaveYearID) { ObjectsTemplate oLeaveProcessDetails = new ObjectsTemplate(); oLeaveProcessDetails = LeaveProcessDetail.Service.GetByYear(leaveYearID); return oLeaveProcessDetails; } public ID Save() { return LeaveProcessDetail.Service.Save(this); } public void SaveStatus(LeaveProcessDetail oLeaveProcessDetail) { LeaveProcessDetail.Service.SaveStatus(oLeaveProcessDetail); } public void Delete() { LeaveProcessDetail.Service.Delete(ID); } public void Delete(int nProcessId) { LeaveProcessDetail.Service.Delete(nProcessId); } #endregion #region Functions public static ObjectsTemplate Get(int nProcessId) { #region Cache Header ObjectsTemplate oLeaveProcessDetails = _cache["Get"] as ObjectsTemplate; if (oLeaveProcessDetails != null) return oLeaveProcessDetails; #endregion oLeaveProcessDetails = LeaveProcessDetail.Service.Get(nProcessId); #region Cache Footer _cache.Add(oLeaveProcessDetails, "Get", nProcessId); #endregion return oLeaveProcessDetails; } public static ObjectsTemplate GetAllStatus(int empId) { #region Cache Header ObjectsTemplate oLeaveProcessDetails = _cache["Get"] as ObjectsTemplate; if (oLeaveProcessDetails != null) return oLeaveProcessDetails; #endregion oLeaveProcessDetails = LeaveProcessDetail.Service.GetAllStatus(empId); #region Cache Footer _cache.Add(oLeaveProcessDetails, "Get", empId); #endregion return oLeaveProcessDetails; } public static void Save(ObjectsTemplate oLeaveProcessDetails) { foreach (LeaveProcessDetail oItem in oLeaveProcessDetails) oItem.Save(); } #endregion #region Service Factory internal static ILeaveProcessDetailService Service { get { return Services.Factory.CreateService(typeof(ILeaveProcessDetailService)); } } #endregion } #endregion #region ILeaveProcessDetail Service public interface ILeaveProcessDetailService { LeaveProcessDetail Get(ID id); LeaveProcessDetail GetStatus(int empid, int leaveID, int leaveYearID); LeaveProcessDetail GetByYear(int ProcessYear, int LeaveId, int EmpId); ObjectsTemplate GetByYear(int leaveYearID); ObjectsTemplate Get(int ProcessId); ObjectsTemplate GetAllStatus(int empId); ID Save(LeaveProcessDetail oLeaveProcessDetail); LeaveProcessDetail GetStatusFromColl(int employeeid, int leaveyearID, int leaveid); void SaveStatus(LeaveProcessDetail oLeaveProcessDetail); void Delete(ID id); void Delete(int nProcessId); } #endregion }