EchoTex_Payroll/HRM.BO/Leave/LeaveProcess.cs

1531 lines
73 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.Core;
using Ease.Core.Model;
using System.Data;
namespace HRM.BO
{
#region LeaveProcess
public class LeaveProcess : AuditTrailBase
{
#region Constructor
public LeaveProcess()
{
//_leaveYearID = 0;
//_dProcessDate = DateTime.Now.Date;
//_isYearEnd = false;
//_nProgress = 0;
//_sProcessYearDesc = "";
//_leaveYear = LeaveYear.GetCurrentYear();
//_PayrollTypeID = 0;
}
#endregion
#region Properties
public int PayrollTypeID { get; set; }
public int LeaveYearID { get; set; }
public string ProcessYearDescription { get; set; }
public int ForTheBenifitedYear
{
get { return LeaveYearID > 0 ? LeaveYearID + 1 : 0; }
}
public DateTime ProcessDate { get; set; }
public bool IsYearEnd { get; set; }
#endregion
private int _nProgress;
public LeaveYear LeaveYear { get; set; }
//private LeaveYear _leaveYear;
//public LeaveYear LeaveYear
//{
// get
// {
// if (_leaveYear == null)
// {
// _leaveYear = Payroll.BO.LeaveYear.Service.Get(ID.FromInteger(_leaveYearID));
// }
// return _leaveYear;
// }
// set
// {
// _leaveYear = value;
// }
//}
public List<EmpLeaveStatus> EmpLeaveStatuss { get; set; }
#endregion
}
#region Leave Process Detail
public class EmpLeaveStatus : BasicBaseObject
{
#region Constructor
public EmpLeaveStatus()
{
_ApplyDays = 0;
//_nProcessId = 0;
//_nEmpId = 0;
//_leaveYearID = 0;
//_nLeaveId = 0;
//_carryFromPrvYear = 0;
this.CFDays = 0;
this.EncashDays = 0;
this.EncashAmount = 0;
this.NormalLeaveDays = 0;
this.YearEndBalance = 0;
//_nleaveavailed = 0;
//_nOpeningBalance = 0;
this.ForfitedDays = 0;
this.CurrentYearBalance = 0;
this.CurrentYearOpening = 0;
this.LateLeaveAdjustmentConsumed = 0;
this.LateLeaveAdjustmentCF = 0;
this.EligibleParamDetail = null;
}
#endregion
public double CurrentYearBalance { get; set; }
public double CurrentYearOpening { get; set; }
#region Properties
public string empNoView { get; set; }
public string empNameView { get; set; }
public string LeaveNameView { get; set; }
public int ProcessId { get; set; }
public int EmpId { get; set; }
public int LeaveYearID { get; set; }
public int LeaveId { get; set; }
public double CarryFromPrvYear { get; set; }
public double CFDays { get; set; }
public double EncashDays { get; set; }
public double LateLeaveAdjustmentConsumed { get; set; }
public double LateLeaveAdjustmentCF { get; set; }
public double EncashAmount { get; set; }
private double _ApplyDays;
public double ApplyDays
{
get { return _ApplyDays; }
set { _ApplyDays = value; }
}
#region NormalLeaveDays
public double NormalLeaveDays { get; set; }
public double ClosingBalance
{
get
{
return YearEndBalance;
}
}
#endregion
public double YearEndBalance { get; set; }
public double LeaveAvailed { get; set; }
public double OpeningBalance { get; set; }
public double ForfitedDays { get; set; }
public Leave Leave { get; set; }
public LeaveParameter LeaveParameter { get; set; }
public LeaveParameterDetail EligibleParamDetail { get; set; }
//public static List<EmpLeaveStatus> CurrentYearStatus(Employee oEmployee, DateTime operationDate,
// List<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear, List<LeaveEntry> aviledLeaveSum, List<EmpLeaveStatus> oPrevStatuses, List<LeaveParameterDetail> ParamDetails, List<Leave> _oLeaves, List<DailyAttnProcess> DaProcess)
//{
// List<EmpLeaveStatus> oCurrYearBalance = null;
// try
// {
// Leave oLeave = null;
// DateTime dCurrentDate;
// if (oCurrYear != null)
// {
// dCurrentDate = operationDate > oCurrYear.EndDate ? oCurrYear.EndDate : operationDate;
// }
// else
// {
// dCurrentDate = operationDate;
// }
// oCurrYearBalance = new List<EmpLeaveStatus>();
// LeaveParameterDetail oDetail = null;
// double lateAttendanceAdjustmentConsumeDays = 0; //GetLateAttendanceAdjustmentConsumeDays(DaProcess);
// //ConfigurationManager oCon = new ConfigurationManager();
// double totalAttendanceAdjustmentConsumeDays = lateAttendanceAdjustmentConsumeDays;
// double remainingTotalAttnConsumedDays = totalAttendanceAdjustmentConsumeDays;
// foreach (LeaveParameter oItem in oAppLeaveParams)
// {
// EmpLeaveStatus oPrevStatus = null;
// EmpLeaveStatus oCurrStatus = new EmpLeaveStatus();
// oCurrStatus.EmpId = oEmployee.ID;
// oLeave = _oLeaves.Where(o => o.ID == oItem.LeaveId).FirstOrDefault();
// oCurrStatus.LeaveId = oItem.LeaveId;
// oCurrStatus.LeaveYearID = oCurrYear.ID;
// if (oPrevStatuses != null)
// oPrevStatus = oPrevStatuses.Find(delegate (EmpLeaveStatus el) { return el.LeaveId == oItem.LeaveId && el.EmpId == oEmployee.ID.Integer; });
// oDetail = oItem.GetApplicableForEmployee(oEmployee, operationDate, ParamDetails, oItem.ID);
// if (oDetail != null) oCurrStatus.NormalLeaveDays = oDetail.MaxDays;
// else continue;
// oCurrStatus.CurrentYearBalance = 0;
// oCurrStatus.CurrentYearOpening = 0;
// #region calculate the opening balance new
// if (oPrevStatus == null)
// oCurrStatus.CurrentYearOpening = 0;
// else
// oCurrStatus.CurrentYearOpening = oPrevStatus.YearEndBalance;
// #endregion
// #region calculate the current year balance
// if (oItem.ApplicableFor == LeaveApplicableType.Confirmed)
// {
// if (oEmployee.IsConfirmed == true)
// {
// oCurrStatus.CurrentYearBalance = Math.Round(GetCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, oPrevStatus, oDetail, oCurrYear), 1);
// }
// else oCurrStatus.CurrentYearBalance = 0;
// }
// else
// {
// oCurrStatus.CurrentYearBalance = Math.Round(GetCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, oPrevStatus, oDetail, oCurrYear), 1);
// }
// #endregion
// oCurrStatus.OpeningBalance = oCurrStatus.CurrentYearBalance + oCurrStatus.CurrentYearOpening;
// #region calculate leave availed in current year
// if (aviledLeaveSum == null)
// oCurrStatus.LeaveAvailed = 0;
// else
// {
// LeaveEntry avl = aviledLeaveSum.Find(delegate (LeaveEntry el) { return el.LeaveID == oItem.LeaveId && el.EmpID == oEmployee.ID; });
// if (avl != null)
// oCurrStatus.LeaveAvailed = Convert.ToDouble(avl.ApprovedTotalDays);
// }
// #endregion calculate leave availed in current year
// #region Calculate Year-End Balance
// oCurrStatus.YearEndBalance = 0;
// if (oItem.MaxAccumulatedDays > 0)
// {
// double maxaccumulationDays = oItem.MaxAccumulatedDays;
// if (oLeave.IsEarnedLeave)
// {
// TimeSpan ts = operationDate - oEmployee.JoiningDate;
// double y = Math.Round((double)ts.Days / 365, 2);
// if (y < 11)
// {
// maxaccumulationDays = 42;
// }
// else if (y < 26)
// {
// maxaccumulationDays = 56;
// }
// else
// {
// maxaccumulationDays = 70;
// }
// }
// //oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance;
// oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance > maxaccumulationDays ? maxaccumulationDays : oCurrStatus.OpeningBalance;
// oCurrStatus.OpeningBalance = Math.Round(oCurrStatus.OpeningBalance, 1);
// }
// if (oLeave.IsBalanceCalculationNeeded == false)
// {
// oCurrStatus.NormalLeaveDays = 0;
// oCurrStatus.OpeningBalance = 0;
// }
// else
// {
// if (oItem.CalculationType == EnumLeaveCalculationType.Hourly || oItem.CalculationType == EnumLeaveCalculationType.Hourly_Prorated)
// {
// double consumed = oCurrStatus.LeaveAvailed;
// int fullpart = (int)consumed;
// int fracpart3 = 0;
// int openfracpart3 = 0;
// int yeFrac = 0;
// int yefullpart = 0;
// string yeBalance;
// if (consumed - fullpart > 0)
// {
// double fracpart = Math.Round(consumed - fullpart, 2);
// if (fracpart > .59)
// {
// fracpart = fracpart - .6;
// fullpart = fullpart + 1;
// string a = (fullpart + "." + (int)((decimal)fracpart * 100));
// oCurrStatus.LeaveAvailed = Math.Round(Convert.ToDouble(a), 2);
// }
// string ss = fracpart.ToString().Substring(2);
// if (ss.Length == 1)
// {
// fracpart3 = Convert.ToInt16(ss + "0");
// }
// double opening = oCurrStatus.OpeningBalance;
// int openfullpart = (int)opening;
// if (opening - openfullpart > 0)
// {
// double openfracpart = Math.Round(opening - openfullpart, 2);
// string openss = openfracpart.ToString().Substring(2);
// if (openss.Length == 1)
// {
// openfracpart3 = Convert.ToInt16(ss + "0");
// }
// if (openfracpart3 < fracpart3)
// {
// yeFrac = (openfracpart3 + 60) - fracpart3;
// yefullpart = (openfullpart - 1) - fullpart;
// }
// else
// {
// yeFrac = openfracpart3 - fracpart3;
// yefullpart = openfullpart - fullpart;
// }
// yeBalance = (yefullpart + "." + yeFrac);
// oCurrStatus.YearEndBalance = Math.Round(Convert.ToDouble(yeBalance), 2);
// }
// else
// {
// yeFrac = (int)(((decimal)0.60 - (decimal)fracpart) * 100);
// yefullpart = (openfullpart - 1) - fullpart;
// yeBalance = (yefullpart + "." + yeFrac);
// oCurrStatus.YearEndBalance = Math.Round(Convert.ToDouble(yeBalance), 2);
// }
// }
// else
// {
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 2);
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 2);
// }
// }
// else
// {
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 1);
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 1);
// }
// //if (oLeave.AutoLeaveReason == true)
// //{
// // if (!isLateAttnAdjustFullyUsed)
// // {
// // totalLeaveBalance = oCurrStatus.YearEndBalance;
// // if (leaveIndex >= totalAttendanceAdjustmentConsumeDays)
// // {
// // isLateAttnAdjustFullyUsed = true;
// // }
// // if (totalLeaveBalance >= remainingTotalAttnConsumedDays && totalLeaveBalance != 0)
// // {
// // oCurrStatus.LateLeaveAdjustmentConsumed = remainingTotalAttnConsumedDays;
// // remainingTotalAttnConsumedDays = 0;
// // isLateAttnAdjustFullyUsed = true;
// // }
// // else if (totalLeaveBalance < remainingTotalAttnConsumedDays && totalLeaveBalance != 0)
// // {
// // remainingTotalAttnConsumedDays = remainingTotalAttnConsumedDays - totalLeaveBalance;
// // leaveIndex += totalLeaveBalance;
// // oCurrStatus.LateLeaveAdjustmentConsumed = totalLeaveBalance;
// // }
// // }
// //}
// }
// #endregion Calculate Year-End Balance
// //if (oLeave.IsBalanceCalculationNeeded)
// oCurrYearBalance.Add(oCurrStatus);
// }
// return oCurrYearBalance;
// }
// catch (Exception exp)
// {
// throw new Exception(exp.Message);
// }
// return oCurrYearBalance;
//}
//private Leave _oLeave;
//public Leave Leave
//{
// get
// {
// if (_nLeaveId != 0)
// {
// _oLeave = new Leave().Get(ID.FromInteger(_nLeaveId));
// }
// return _oLeave;
// }
//}
#endregion
//public void UpdateEncashAmount(List<EmpLeaveStatus> _oEmpLeaveStatus)
//{
// LeaveProcess.Service.UpdateEncashAmount(_oEmpLeaveStatus);
//}
//public static List<EmpLeaveStatus> GetByYearType(int leaveYearID, int leaveId)
//{
// List<EmpLeaveStatus> oEmpLeaveStatuss = null;
// oEmpLeaveStatuss = LeaveProcess.Service.GetByYearType(leaveYearID, leaveId);
// return oEmpLeaveStatuss;
//}
//public static DataSet GetEmpAllLeaveRelatedInfo(ID employeeID)
//{
// DataSet oDataSet = new DataSet();
// try
// {
// oDataSet = LeaveProcess.Service.GetEmpAllLeaveRelatedInfo(employeeID);
// }
// catch (ServiceException e)
// {
// throw new Exception(e.Message, e);
// }
// return oDataSet;
//}
//public static DataTable EmpCurrentYearStatus(Employee oemp)
//{
// DataTable dtLeaveBalance = new DataTable();
// dtLeaveBalance.Columns.Add("LeaveName", typeof(string));
// dtLeaveBalance.Columns.Add("LeaveTaken", typeof(string));
// Leave oLeave = null;
// List<Leave> _leaves = null;
// DataRow odr = null;
// LeaveYear oCurrentLeaveYear = null;
// LeaveYear oPreviousLeaveYear = null;
// DateTime operationDate = DateTime.MinValue;
// List<EnmSetupManagerTranType> setupTypes = null;
// List<SetupDetail> oSetupDetails = null;
// SetupDetail setupDetail = null;
// List<LeaveParameter> oLeaveParams = null;
// LeaveParameter leaveParam = null;
// List<LeaveParameterDetail> oLeaveParamDetails = null;
// LeaveParameterDetail leaveParamDetail = null;
// List<LeaveEntry> oLeaveEntrys = null;
// List<EmpLeaveStatus> oPrevStatuses = null;
// EmpLeaveStatus prevStatuses = null;
// LeaveEntry leaveEntry = null;
// DataSet dsLeaveInfos = null;
// List<EmpLeaveStatus> oCurrYearBalance = null;
// dsLeaveInfos = GetEmpAllLeaveRelatedInfo(oemp.ID);
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["Leave"].Rows.Count > 0)
// {
// _leaves = new List<Leave>();
// foreach (DataRow drItem in dsLeaveInfos.Tables["Leave"].Rows)
// {
// oLeave = new Leave();
// oLeave.SetObjectID(Convert.ToInt32(drItem["LeaveID"]));
// oLeave.Code = drItem["Code"].ToString();
// oLeave.Description = drItem["Description"].ToString();
// oLeave.ApplicableFor = (EnumGender)Convert.ToInt32(drItem["ApplicableFor"]);
// oLeave.IsBalanceCalculationNeeded = Convert.ToBoolean(drItem["IsBalanceCalRequired"]);
// oLeave.AutoLeaveReason = Convert.ToBoolean(drItem["AutoLeaveReason"]);
// oLeave.PayrollTypeID = Ease.CoreV35.Model.ID.FromInteger(Convert.ToInt32(drItem["PayrollTypeID"]));
// oLeave.Sequence = Convert.ToInt32(drItem["SequenceNo"]);
// if (Convert.ToInt32(drItem["PayrollTypeID"]) == SystemInformation.CurrentSysInfo.PayrollTypeID.Integer)
// _leaves.Add(oLeave);
// }
// _leaves = _leaves.OrderBy(o => o.Sequence).ToObjectsTemplate();
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["OperationDate"].Rows.Count > 0)
// {
// foreach (DataRow drItem in dsLeaveInfos.Tables["OperationDate"].Rows)
// {
// operationDate = Convert.ToDateTime(drItem["sysdate"]);
// }
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["CurrentLeaveYear"].Rows.Count > 0)
// {
// foreach (DataRow drItem in dsLeaveInfos.Tables["CurrentLeaveYear"].Rows)
// {
// oCurrentLeaveYear = new LeaveYear();
// oCurrentLeaveYear.SetObjectID(Convert.ToInt32(drItem["LeaveYearID"]));
// oCurrentLeaveYear.Name = Convert.ToString(drItem["Name"]);
// oCurrentLeaveYear.StartDate = Convert.ToDateTime(drItem["StartDate"]);
// oCurrentLeaveYear.EndDate = Convert.ToDateTime(drItem["EndDate"]);
// oCurrentLeaveYear.IsCurrent = Convert.ToBoolean(drItem["IsCurrent"]);
// oCurrentLeaveYear.IsEnded = Convert.ToBoolean(drItem["IsEnded"]);
// }
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["LeaveSetupTypes"].Rows.Count > 0)
// {
// setupTypes = new List<EnmSetupManagerTranType>();
// foreach (DataRow drItem in dsLeaveInfos.Tables["LeaveSetupTypes"].Rows)
// {
// setupTypes.Add((EnmSetupManagerTranType)Convert.ToInt32(drItem[0]));
// }
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["LeaveSetupDetails"].Rows.Count > 0)
// {
// oSetupDetails = new List<SetupDetail>();
// foreach (DataRow drItem in dsLeaveInfos.Tables["LeaveSetupDetails"].Rows)
// {
// setupDetail = new SetupDetail();
// setupDetail.SetObjectID(Convert.ToInt32(drItem["DetailID"]));
// setupDetail.SetupID = ID.FromInteger(Convert.ToInt32(drItem["SetupID"]));
// setupDetail.TranID = ID.FromInteger(Convert.ToInt32(drItem["TranID"])); ;
// setupDetail.TranType = (EnmSetupManagerTranType)Convert.ToInt32(drItem["tranType"]);
// oSetupDetails.Add(setupDetail);
// }
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["LeaveParameter"].Rows.Count > 0)
// {
// oLeaveParams = new List<LeaveParameter>();
// foreach (DataRow drItem in dsLeaveInfos.Tables["LeaveParameter"].Rows)
// {
// leaveParam = new LeaveParameter();
// leaveParam.SetObjectID(Convert.ToInt32(drItem["LeaveParamId"]));
// leaveParam.LeaveId = Convert.ToInt32(drItem["LeaveId"]);
// leaveParam.MaxAccumulatedDays = Convert.ToDouble(drItem["AccumulatedLeave"]);
// leaveParam.IsActive = Convert.ToBoolean(drItem["IsActive"]);
// leaveParam.ApplicableFor = (LeaveApplicableType)Convert.ToInt32(drItem["ApplicableFor"]);
// leaveParam.ForfitedMonth = Convert.ToInt32(drItem["FortifiedMonth"]);
// leaveParam.AllowAdvance = Convert.ToBoolean(drItem["AllowAdvance"]);
// leaveParam.IgnoreHoliday = Convert.ToBoolean(drItem["IgnoreHolidays"]);
// leaveParam.CalculationType = (EnumLeaveCalculationType)Convert.ToInt32(drItem["MonthlyBalance"]);
// leaveParam.IsForfited = Convert.ToBoolean(drItem["IsForfited"]);
// oLeave = _leaves.Where(o => o.ID.Integer == leaveParam.LeaveId).FirstOrDefault();
// if (oLeave != null && (oLeave.Code == "AL" || oLeave.Code == "CL" || oLeave.Code == "ML") && Convert.ToInt32(drItem["PayrollTypeID"]) == SystemInformation.CurrentSysInfo.PayrollTypeID.Integer)
// {
// leaveParam.LeaveId = oLeave.ID.Integer;
// oLeaveParams.Add(leaveParam);
// }
// }
// oLeaveParams = oLeaveParams.OrderBy(o => o.Leave.Sequence).ToObjectsTemplate();
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["LeaveParamDetail"].Rows.Count > 0)
// {
// oLeaveParamDetails = new List<LeaveParameterDetail>();
// foreach (DataRow drItem in dsLeaveInfos.Tables["LeaveParamDetail"].Rows)
// {
// leaveParamDetail = new LeaveParameterDetail();
// leaveParamDetail.SetObjectID(Convert.ToInt32(drItem["ID"]));
// leaveParamDetail.LeaveParamId = Convert.ToInt32(drItem["LeaveParamId"]);
// leaveParamDetail.MaxDays = Convert.ToDouble(drItem["MaxDays"]);
// leaveParamDetail.MaxGrndDays = Convert.ToDouble(drItem["MaxGrndDays"]);
// leaveParamDetail.MaxCF = Convert.ToDouble(drItem["MaxCF"]);
// leaveParamDetail.MaxEncash = Convert.ToDouble(drItem["MaxEncash"]);
// leaveParamDetail.Year = Convert.ToInt32(drItem["Year"]);
// oLeaveParamDetails.Add(leaveParamDetail);
// }
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["AllAvailedLeave"].Rows.Count > 0)
// {
// oLeaveEntrys = new List<LeaveEntry>();
// foreach (DataRow drItem in dsLeaveInfos.Tables["AllAvailedLeave"].Rows)
// {
// leaveEntry = new LeaveEntry();
// leaveEntry.LeaveYear = Convert.ToInt32(drItem["LeaveYear"]);
// leaveEntry.LeaveID = ID.FromInteger(Convert.ToInt32(drItem["LeaveID"]));
// leaveEntry.EmpID = Convert.ToInt32(drItem["EmpId"]);
// leaveEntry.ApprovedTotalDays = Convert.ToDouble(drItem["AprTotalDays"]);
// oLeaveEntrys.Add(leaveEntry);
// }
// }
// if (dsLeaveInfos != null && dsLeaveInfos.Tables["PreviousYearStatus"].Rows.Count > 0)
// {
// oPrevStatuses = new List<EmpLeaveStatus>();
// foreach (DataRow drItem in dsLeaveInfos.Tables["PreviousYearStatus"].Rows)
// {
// prevStatuses = new EmpLeaveStatus();
// prevStatuses.SetObjectID(Convert.ToInt32(drItem["TranId"]));
// prevStatuses.ProcessId = Convert.ToInt32(drItem["ProcessId"]);
// prevStatuses.EmpId = Convert.ToInt32(drItem["EmpId"]);
// prevStatuses.LeaveYearID = Convert.ToInt32(drItem["LEAVEYEARID"]);
// prevStatuses.LeaveId = Convert.ToInt32(drItem["LeaveId"]);
// prevStatuses.YearEndBalance = Convert.ToDouble(drItem["YearEndBalance"]);
// oPrevStatuses.Add(prevStatuses);
// }
// }
// List<LeaveParameter> oAppLeaveParams = new List<LeaveParameter>();
// LeaveParameter oAppLeaveParam = null;
// Leave lv = null;
// foreach (LeaveParameter lparam in oLeaveParams)
// {
// oAppLeaveParam = new LeaveParameter();
// lv = _leaves.Where(o => o.ID.Integer == lparam.LeaveId).FirstOrDefault();
// oAppLeaveParam = LeaveParameter.ApplicableParam(oemp, setupTypes, oSetupDetails, lparam, lv);
// if (oAppLeaveParam != null && !oAppLeaveParam.ID.IsUnassigned)
// oAppLeaveParams.Add(oAppLeaveParam);
// }
// List<DailyAttnProcess> _dailyAttnProcess = DailyAttnProcess.Get(oCurrentLeaveYear.StartDate.Date, oCurrentLeaveYear.EndDate.Date);
// _dailyAttnProcess = _dailyAttnProcess.Where(o => o.EmployeeID == oemp.ID).ToObjectsTemplate();
// oCurrYearBalance = EmpLeaveStatus.CurrentYearStatus(oemp, operationDate, oAppLeaveParams, oCurrentLeaveYear, oLeaveEntrys, oPrevStatuses, oLeaveParamDetails, _leaves,_dailyAttnProcess);
// foreach (EmpLeaveStatus eSts in oCurrYearBalance)
// {
// oLeave = _leaves.Where(o => o.ID.Integer == eSts.LeaveId).FirstOrDefault();
// if (oLeave != null && (oLeave.Code == "AL" || oLeave.Code == "CL" || oLeave.Code == "ML"))
// {
// odr = dtLeaveBalance.NewRow();
// odr["LeaveName"] = oLeave.Description;
// odr["LeaveTaken"] = eSts.ClosingBalance - eSts.LateLeaveAdjustmentConsumed;
// dtLeaveBalance.Rows.Add(odr);
// }
// }
// return dtLeaveBalance;
//}
//public static List<LeaveParameter> ApplicableParamsForReport(Employee oEmp, List<EnmSetupManagerTranType> setupTypes, List<SetupDetail> details, List<LeaveParameter> leaveParamss)
//{
// List<int> leaveParamIds = SetupManager.ApplicableParametersForReport(oEmp, setupTypes, details);
// //ObjectsTemplate<LeaveParameter> leaveParamss = LeaveParameter.Get();
// List<LeaveParameter> leaveParams = new List<LeaveParameter>();
// foreach (LeaveParameter lparam in leaveParamss)
// {
// if (lparam.Leave.ApplicableFor != (EnumGender)oEmp.Gender && lparam.Leave.ApplicableFor != EnumGender.Other && lparam.Leave.ApplicableFor != EnumGender.None)
// {
// continue;
// }
// bool found = false;
// foreach (int id in leaveParamIds)
// {
// if (id == lparam.ID)
// {
// found = true;
// break;
// }
// }
// if (found)
// {
// switch (lparam.ApplicableFor)
// {
// case LeaveApplicableType.Probetionary:
// if (!oEmp.IsConfirmed)
// {
// leaveParams.Add(lparam);
// }
// break;
// case LeaveApplicableType.Confirmed:
// if (oEmp.IsConfirmed)
// {
// leaveParams.Add(lparam);
// }
// break;
// case LeaveApplicableType.Regardless:
// leaveParams.Add(lparam);
// break;
// default:
// break;
// }
// }
// }
// return leaveParams;
//}
//private static double GetCurrentYearDays(EnumLeaveCalculationType eType, Employee emp, DateTime dCurrentDate, EmpLeaveStatus oPreviousStatus, LeaveParameterDetail oDetail, LeaveYear oCurrentYear)
//{
// double nTotalDays = 0;
// TimeSpan ts = new TimeSpan();
// double nTempDays = 0;
// if (eType == EnumLeaveCalculationType.Daily)
// {
// List<DailyAttnProcess> oAttnProcess = new List<DailyAttnProcess>();
// List<DailyAttnProcess> oPresentRecords = new List<DailyAttnProcess>();
// oAttnProcess = DailyAttnProcess.Get(emp.ID, PayrollPayrollGlobalFunctions.FirstDateOfYear(dCurrentDate), dCurrentDate);
// oPresentRecords = oAttnProcess.FindAll(delegate(DailyAttnProcess oitem) { return oitem.AttenType == EnumAttendanceType.Present; });
// if (oPresentRecords.Count > 0)
// nTotalDays = (double)oPresentRecords.Count / 18;
// }
// else if (eType == EnumLeaveCalculationType.Hourly)
// {
// if (emp.GrandFather.Leave)
// {
// nTotalDays = oDetail.MaxGrndDays;
// }
// else
// {
// nTotalDays = oDetail.MaxDays;
// }
// }
// else if (eType == EnumLeaveCalculationType.Hourly_Prorated)
// {
// if (emp.JoiningDate > oCurrentYear.StartDate)
// ts = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(dCurrentDate) - emp.JoiningDate;
// else
// ts = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(dCurrentDate) - Ease.CoreV35.Utility.Global.DateFunctions.FirstDateOfYear(dCurrentDate);
// if (emp.GrandFather != null && emp.GrandFather.Leave)
// {
// if (emp.JoiningDate > oCurrentYear.StartDate)
// {
// nTempDays = oDetail.MaxGrndDays / 365;
// }
// else
// {
// nTempDays = oDetail.MaxGrndDays / ts.Days;
// }
// }
// else
// {
// if (emp.JoiningDate > oCurrentYear.StartDate)
// {
// nTempDays = oDetail.MaxDays / 365;
// }
// else
// {
// nTempDays = oDetail.MaxDays / ts.Days;
// }
// }
// nTotalDays = (double)nTempDays * ts.Days;
// nTotalDays = Math.Floor(nTotalDays);
// }
// else if (eType == EnumLeaveCalculationType.Monthly)
// {
// if (emp.JoiningDate > oCurrentYear.StartDate)
// ts = dCurrentDate - emp.JoiningDate;
// else
// ts = dCurrentDate - PayrollPayrollGlobalFunctions.FirstDateOfYear(dCurrentDate);
// if (emp.GrandFather.Leave)
// {
// nTempDays = oDetail.MaxGrndDays / 12;
// }
// else
// {
// nTempDays = oDetail.MaxDays / 12;
// }
// nTotalDays = (double)nTempDays * (ts.Days / 30);
// }
// else if (eType == EnumLeaveCalculationType.Yearly)
// {
// if (emp.JoiningDate > oCurrentYear.StartDate)
// ts = dCurrentDate - emp.JoiningDate;
// else
// ts = dCurrentDate - PayrollPayrollGlobalFunctions.FirstDateOfYear(dCurrentDate);
// if (emp.GrandFather.Leave)
// {
// if (ts.Days > 365)
// nTotalDays = (double)oDetail.MaxGrndDays;
// }
// else
// {
// if (ts.Days > 365)
// nTotalDays = (double)oDetail.MaxDays;
// }
// }
// else if (eType == EnumLeaveCalculationType.Not_Applicable)
// {
// if (emp.JoiningDate > oCurrentYear.StartDate)
// ts = PayrollPayrollGlobalFunctions.LastDateOfYear(dCurrentDate) - emp.JoiningDate;
// else
// ts = PayrollPayrollGlobalFunctions.LastDateOfYear(dCurrentDate) - PayrollPayrollGlobalFunctions.FirstDateOfYear(dCurrentDate);
// if (emp.GrandFather != null && emp.GrandFather.Leave)
// {
// nTotalDays = oDetail.MaxGrndDays;
// }
// else
// {
// nTotalDays = oDetail.MaxDays;
// }
// }
// else if (eType == EnumLeaveCalculationType.Not_Applicable_With_Prorated)
// {
// if (emp.JoiningDate > oCurrentYear.StartDate)
// ts = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(dCurrentDate) - emp.JoiningDate;
// else
// ts = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(dCurrentDate) - Ease.CoreV35.Utility.Global.DateFunctions.FirstDateOfYear(dCurrentDate);
// if (emp.GrandFather != null && emp.GrandFather.Leave)
// {
// nTempDays = oDetail.MaxGrndDays / 12;
// }
// else
// {
// nTempDays = oDetail.MaxDays / 12;
// }
// nTotalDays = (double)nTempDays * (ts.Days / 30);
// nTotalDays = Math.Round(nTotalDays);
// }
// return Math.Round(nTotalDays, 1);
//}
//public static List<EmpLeaveStatus> GetAllPrvYearStatus(LeaveYear oCurrYear, List<LeaveYear> olYears, int leaveYearID)
//{
// LeaveYear oPrvYear = null;
// foreach (LeaveYear oItem in olYears)
// {
// if (oItem.EndDate.AddDays(1) == oCurrYear.StartDate)
// {
// oPrvYear = oItem;
// break;
// }
// }
// if (oPrvYear == null)
// return null;
// return LeaveProcess.Service.GetByYear(oPrvYear.ID);
//}
//private static double GetLateAttendanceAdjustmentConsumeDays(List<DailyAttnProcess> _daProcess)
//{
// double lateAttnAdjustConsumeDays = 0;
// double _0to14 = 0;
// double _15to29 = 0;
// double _30to1_59 = 0;
// double _2_0to4_30 = 0;
// List<DailyAttnProcess> daProcess0to14mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Nine_0am_to_Nine_14am).ToObjectsTemplate();
// List<DailyAttnProcess> daProcess15to29mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Nine_15am_to_Nine_29am).ToObjectsTemplate();
// List<DailyAttnProcess> daProcess30to1_59mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Nine_30am_to_Ten_59am).ToObjectsTemplate();
// List<DailyAttnProcess> daProcess2to4_30mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Eleven_0am_to_One_30pm).ToObjectsTemplate();
// _0to14 = Math.Abs(daProcess0to14mins.Count / 10);
// _0to14 = _0to14 / 2;
// _15to29 = Math.Abs(daProcess15to29mins.Count / 3);
// _15to29 = _15to29 / 2;
// _30to1_59 = Math.Abs(daProcess30to1_59mins.Count / 3);
// _2_0to4_30 = Math.Abs(daProcess2to4_30mins.Count / 2);
// lateAttnAdjustConsumeDays = _0to14 + _15to29 + _30to1_59 + _2_0to4_30;
// return lateAttnAdjustConsumeDays;
//}
//private static double GetLateAttendanceAdjustmentCFDays(List<DailyAttnProcess> _daProcess)
//{
// double lateAttnAdjustDays = 0;
// List<DailyAttnProcess> daProcess0to14mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Nine_0am_to_Nine_14am).ToObjectsTemplate();
// List<DailyAttnProcess> daProcess15to29mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Nine_15am_to_Nine_29am).ToObjectsTemplate();
// List<DailyAttnProcess> daProcess30to1_59mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Nine_30am_to_Ten_59am).ToObjectsTemplate();
// List<DailyAttnProcess> daProcess2to4_30mins = _daProcess.Where(o => o.LateAttendanceType == EnumLateAttendanceType.Eleven_0am_to_One_30pm).ToObjectsTemplate();
// lateAttnAdjustDays = (daProcess0to14mins.Count % 10);
// lateAttnAdjustDays += (daProcess15to29mins.Count % 3);
// lateAttnAdjustDays += (daProcess30to1_59mins.Count % 3);
// lateAttnAdjustDays += (daProcess2to4_30mins.Count % 2);
// return lateAttnAdjustDays;
//}
//public static List<EmpLeaveStatus> CurrentYearStatus(Employee oEmployee, DateTime operationDate,
// List<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear, List<LeaveEntry> aviledLeaveSum, List<EmpLeaveStatus> oPrevStatuses, List<LeaveParameterDetail> ParamDetails, List<Leave> _oLeaves, List<DailyAttnProcess> DaProcess)
//{
// List<EmpLeaveStatus> oCurrYearBalance = null;
// try
// {
// Leave oLeave = null;
// bool isLateAttnAdjustFullyUsed = false;
// DateTime dCurrentDate = operationDate > oCurrYear.EndDate ? oCurrYear.EndDate : operationDate;
// oCurrYearBalance = new List<EmpLeaveStatus>();
// LeaveParameterDetail oDetail = null;
// double lateAttendanceAdjustmentConsumeDays = GetLateAttendanceAdjustmentConsumeDays(DaProcess);
// //double lateAttendanceAdjustmentCFDays = GetLateAttendanceAdjustmentCFDays(DaProcess);
// ConfigurationManager oCon = new ConfigurationManager();
// double totalLeaveBalance = 0;
// double leaveIndex = 0;
// double totalAttendanceAdjustmentConsumeDays = lateAttendanceAdjustmentConsumeDays;
// double remainingTotalAttnConsumedDays = totalAttendanceAdjustmentConsumeDays;
// foreach (LeaveParameter oItem in oAppLeaveParams)
// {
// EmpLeaveStatus oPrevStatus = null;
// EmpLeaveStatus oCurrStatus = new EmpLeaveStatus();
// oCurrStatus.EmpId = oEmployee.ID.Integer;
// oLeave = _oLeaves.Where(o => o.ID.Integer == oItem.LeaveId).FirstOrDefault();
// oCurrStatus.LeaveId = oItem.LeaveId;
// oCurrStatus.LeaveYearID = oCurrYear.ID.Integer;
// if (oPrevStatuses != null)
// oPrevStatus = oPrevStatuses.Find(delegate(EmpLeaveStatus el) { return el.LeaveId == oItem.LeaveId && el.EmpId == oEmployee.ID.Integer; });
// oDetail = oItem.GetApplicableForEmployee(oEmployee, operationDate, ParamDetails, oItem.ID);
// if (oDetail != null) oCurrStatus.NormalLeaveDays = 0;
// else continue;
// oCurrStatus.CurrentYearBalance = 0;
// oCurrStatus.CurrentYearOpening = 0;
// #region calculate the opening balance new
// if (oPrevStatus == null)
// oCurrStatus.CurrentYearOpening = 0;
// else
// oCurrStatus.CurrentYearOpening = oPrevStatus.YearEndBalance;
// #endregion
// #region calculate the current year balance
// if (oItem.ApplicableFor == LeaveApplicableType.Confirmed)
// {
// if (oEmployee.IsConfirmed == true)
// {
// oCurrStatus.CurrentYearBalance = Math.Round(GetCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, oPrevStatus, oDetail, oCurrYear), 1);
// }
// else oCurrStatus.CurrentYearBalance = 0;
// }
// else
// {
// oCurrStatus.CurrentYearBalance = Math.Round(GetCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, oPrevStatus, oDetail, oCurrYear), 1);
// }
// #endregion
// oCurrStatus.OpeningBalance = oCurrStatus.CurrentYearBalance + oCurrStatus.CurrentYearOpening;
// #region calculate leave availed in current year
// if (aviledLeaveSum == null)
// oCurrStatus.LeaveAvailed = 0;
// else
// {
// LeaveEntry avl = aviledLeaveSum.Find(delegate(LeaveEntry el) { return el.LeaveID.Integer == oItem.LeaveId && el.EmpID == oEmployee.ID.Integer; });
// if (avl != null)
// oCurrStatus.LeaveAvailed = Convert.ToDouble(avl.ApprovedTotalDays);
// }
// #endregion calculate leave availed in current year
// #region Calculate Year-End Balance
// oCurrStatus.YearEndBalance = 0;
// if (oItem.MaxAccumulatedDays > 0)
// {
// oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance;
// oCurrStatus.OpeningBalance = Math.Round(oCurrStatus.OpeningBalance, 1);
// }
// if (oLeave.IsBalanceCalculationNeeded == false)
// {
// oCurrStatus.NormalLeaveDays = 0;
// oCurrStatus.OpeningBalance = 0;
// }
// else
// {
// if (oItem.CalculationType == EnumLeaveCalculationType.Hourly || oItem.CalculationType == EnumLeaveCalculationType.Hourly_Prorated)
// {
// double consumed = oCurrStatus.LeaveAvailed;
// int fullpart = (int)consumed;
// int fracpart3 = 0;
// int openfracpart3 = 0;
// int yeFrac = 0;
// int yefullpart = 0;
// string yeBalance;
// if (consumed - fullpart > 0)
// {
// double fracpart = Math.Round(consumed - fullpart, 2);
// if (fracpart > .59)
// {
// fracpart = fracpart - .6;
// fullpart = fullpart + 1;
// string a = (fullpart + "." + (int)((decimal)fracpart*100));
// oCurrStatus.LeaveAvailed = Math.Round(Convert.ToDouble(a), 2);
// }
// string ss = fracpart.ToString().Substring(2);
// if (ss.Length == 1)
// {
// fracpart3 = Convert.ToInt16(ss + "0");
// }
// double opening = oCurrStatus.OpeningBalance;
// int openfullpart = (int)opening;
// if (opening - openfullpart > 0)
// {
// double openfracpart = Math.Round(opening - openfullpart, 2);
// string openss = openfracpart.ToString().Substring(2);
// if (openss.Length == 1)
// {
// openfracpart3 = Convert.ToInt16(ss + "0");
// }
// if (openfracpart3 < fracpart3)
// {
// yeFrac = (openfracpart3 + 60) - fracpart3;
// yefullpart = (openfullpart - 1) - fullpart;
// }
// else
// {
// yeFrac = openfracpart3 - fracpart3;
// yefullpart = openfullpart - fullpart;
// }
// yeBalance = (yefullpart + "." + yeFrac);
// oCurrStatus.YearEndBalance = Math.Round(Convert.ToDouble(yeBalance), 2);
// }
// else
// {
// yeFrac = (int)(((decimal)0.60 - (decimal)fracpart) * 100);
// yefullpart = (openfullpart - 1) - fullpart;
// yeBalance = (yefullpart + "." + yeFrac);
// oCurrStatus.YearEndBalance = Math.Round(Convert.ToDouble(yeBalance), 2);
// }
// }
// else
// {
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 2);
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 2);
// }
// }
// else
// {
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 1);
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 1);
// }
// if (oLeave.AutoLeaveReason == true)
// {
// if (!isLateAttnAdjustFullyUsed)
// {
// totalLeaveBalance = oCurrStatus.YearEndBalance;
// if (leaveIndex >= totalAttendanceAdjustmentConsumeDays)
// {
// isLateAttnAdjustFullyUsed = true;
// }
// if (totalLeaveBalance >= remainingTotalAttnConsumedDays && totalLeaveBalance != 0)
// {
// oCurrStatus.LateLeaveAdjustmentConsumed = remainingTotalAttnConsumedDays;
// remainingTotalAttnConsumedDays = 0;
// isLateAttnAdjustFullyUsed = true;
// }
// else if (totalLeaveBalance < remainingTotalAttnConsumedDays && totalLeaveBalance != 0)
// {
// remainingTotalAttnConsumedDays = remainingTotalAttnConsumedDays - totalLeaveBalance;
// leaveIndex += totalLeaveBalance;
// oCurrStatus.LateLeaveAdjustmentConsumed = totalLeaveBalance;
// }
// }
// }
// }
// #endregion Calculate Year-End Balance
// if (oLeave.IsBalanceCalculationNeeded)
// oCurrYearBalance.Add(oCurrStatus);
// }
// return oCurrYearBalance;
// }
// catch (Exception exp)
// {
// throw new Exception(exp.Message);
// }
// return oCurrYearBalance;
//}
//public static List<EmpLeaveStatus> CurrentYearStatusForPreocess(List<Employee> oEmployees, LeaveYear lYear)
//{
// List<EmpLeaveStatus> oAllEmpsCurrYearBalance = null;
// try
// {
// List<EmpLeaveStatus> oCurrYearBalance = null;
// DateTime operationDate = PayrollPayrollGlobalFunctions.GetOperationDate();
// LeaveYear oCurrYear = lYear;
// oCurrYear.EndDate = operationDate;
// oAllEmpsCurrYearBalance = new List<EmpLeaveStatus>();
// LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
// List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(EnumParameterSetup.Leave);
// List<SetupDetail> setupDetails = SetupDetail.GetParameters(EnumParameterSetup.Leave);
// List<LeaveParameter> leaveParamss = LeaveParameter.Get();
// List<BATBGrandFatherTaging> gfs = BATBGrandFatherTaging.Get(oEmployees.CommaSeparatedIDs());
// List<LeaveParameterDetail> leaveParamDetails = new LeaveParameter().GetAllDetails();
// List<LeaveEntry> oLs = null;
// if (oEmployees.Count == 1)
// oLs = LeaveEntry.Service.GetSumOfAvailedLeave(oEmployees[0].ID.Integer, oCurrYear.ID.Integer);
// else oLs = LeaveEntry.Service.GetSumOfAvailedLeave(oCurrYear.ID.Integer);
// List<EmpLeaveStatus> oPrevStatuses = EmpLeaveStatus.GetAllPrvYearStatus(oCurrYear.ID.Integer);
// BATBGrandFatherTaging gf = null;
// foreach (Employee oEmp in oEmployees)
// {
// gf = gfs.FirstOrDefault(o => o.EmployeeID == oEmp.ID.Integer);
// if (gf != null)
// {
// oEmp.GrandFather = gf;
// }
// else
// {
// oEmp.GrandFather = new BATBGrandFatherTaging();
// }
// if (oEmp.Status == EnumEmployeeStatus.Discontinued)
// {
// oCurrYear.EndDate = (DateTime)oEmp.EndOfContractDate;
// }
// else
// {
// operationDate = oCurrYear.EndDate;
// }
// List<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParams(oEmp, setupTypes, setupDetails, leaveParamss);
// oCurrYearBalance = EmpLeaveStatus.CurrentYearStatusForProcess(oEmp, operationDate, oAppLeaveParams, oCurrYear, oLs, oPrevStatuses, leaveParamDetails);
// foreach (EmpLeaveStatus eSts in oCurrYearBalance)
// oAllEmpsCurrYearBalance.Add(eSts);
// }
// }
// catch (Exception exp)
// {
// }
// return oAllEmpsCurrYearBalance;
//}
//public static List<EmpLeaveStatus> CurrentYearStatusForProcess(Employee oEmployee, DateTime operationDate,
// List<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear, List<LeaveEntry> aviledLeaveSum, List<EmpLeaveStatus> oPrevStatuses, List<LeaveParameterDetail> ParamDetails)
//{
// List<EmpLeaveStatus> oCurrYearBalance = null;
// try
// {
// DateTime dCurrentDate = operationDate;
// oCurrYearBalance = new List<EmpLeaveStatus>();
// LeaveParameterDetail oDetail = null;
// ConfigurationManager oCon = new ConfigurationManager();
// foreach (LeaveParameter oItem in oAppLeaveParams)
// {
// EmpLeaveStatus oPrevStatus = null;
// EmpLeaveStatus oCurrStatus = new EmpLeaveStatus();
// oCurrStatus.EmpId = oEmployee.ID.Integer;
// oCurrStatus.LeaveId = oItem.LeaveId;
// oCurrStatus.LeaveYearID = oCurrYear.ID.Integer;
// if (oPrevStatuses != null)
// oPrevStatus = oPrevStatuses.Find(delegate(EmpLeaveStatus el) { return el.LeaveId == oItem.LeaveId && el.EmpId == oEmployee.ID.Integer; });
// oDetail = oItem.GetApplicableForEmployee(oEmployee, operationDate, ParamDetails, oItem.ID);
// if (oDetail != null) oCurrStatus.NormalLeaveDays = 0;
// else continue;
// oCurrStatus.CurrentYearBalance = 0;
// oCurrStatus.CurrentYearOpening = 0;
// #region calculate the opening balance new
// if (oPrevStatus == null)
// oCurrStatus.CurrentYearOpening = 0;
// else
// oCurrStatus.CurrentYearOpening = oPrevStatus.YearEndBalance > oDetail.MaxCF ? oDetail.MaxCF : oPrevStatus.YearEndBalance;
// #endregion
// #region calculate the current year balance
// if (oItem.ApplicableFor == LeaveApplicableType.Confirmed)
// {
// if (oEmployee.IsConfirmed == true)
// {
// oCurrStatus.CurrentYearBalance = Math.Round(GetCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, oPrevStatus, oDetail, oCurrYear), 1);
// }
// else oCurrStatus.CurrentYearBalance = 0;
// }
// else
// {
// oCurrStatus.CurrentYearBalance = Math.Round(GetCurrentYearDays(oItem.CalculationType, oEmployee, dCurrentDate, oPrevStatus, oDetail, oCurrYear), 1);
// }
// #endregion
// oCurrStatus.OpeningBalance = oCurrStatus.CurrentYearBalance + oCurrStatus.CurrentYearOpening;
// #region calculate leave availed in current year
// if (aviledLeaveSum == null)
// oCurrStatus.LeaveAvailed = 0;
// else
// {
// LeaveEntry avl = aviledLeaveSum.Find(delegate(LeaveEntry el) { return el.LeaveID.Integer == oItem.LeaveId && el.EmpID == oEmployee.ID.Integer; });
// if (avl != null)
// oCurrStatus.LeaveAvailed = Convert.ToDouble(avl.ApprovedTotalDays);
// }
// #endregion calculate leave availed in current year
// #region Calculate Year-End Balance
// oCurrStatus.YearEndBalance = 0;
// if (oItem.MaxAccumulatedDays > 0)
// {
// oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance;
// oCurrStatus.OpeningBalance = Math.Round(oCurrStatus.OpeningBalance, 1);
// }
// if (oItem.Leave.IsBalanceCalculationNeeded == false)
// {
// oCurrStatus.NormalLeaveDays = 0;
// oCurrStatus.OpeningBalance = 0;
// }
// else
// {
// if (oItem.CalculationType == EnumLeaveCalculationType.Hourly)
// {
// double consumed = oCurrStatus.LeaveAvailed;
// int fullpart = (int)consumed;
// int fracpart3 = 0;
// int openfracpart3 = 0;
// int yeFrac = 0;
// int yefullpart = 0;
// string yeBalance;
// if (consumed - fullpart > 0)
// {
// double fracpart = Math.Round(consumed - fullpart, 2);
// string ss = fracpart.ToString().Substring(2);
// if (ss.Length == 1)
// {
// fracpart3 = Convert.ToInt16(ss + "0");
// }
// double opening = oCurrStatus.OpeningBalance;
// int openfullpart = (int)opening;
// if (opening - openfullpart > 0)
// {
// double openfracpart = Math.Round(opening - openfullpart, 2);
// string openss = openfracpart.ToString().Substring(2);
// if (openss.Length == 1)
// {
// openfracpart3 = Convert.ToInt16(ss + "0");
// }
// if (openfracpart3 < fracpart3)
// {
// yeFrac = (openfracpart3 + 60) - fracpart3;
// yefullpart = (openfullpart - 1) - fullpart;
// }
// else
// {
// yeFrac = openfracpart3 - fracpart3;
// yefullpart = openfullpart - fullpart;
// }
// yeBalance = (yefullpart + "." + yeFrac);
// oCurrStatus.YearEndBalance = Math.Round(Convert.ToDouble(yeBalance), 2);
// }
// else
// {
// yeFrac = (int)((0.60 - fracpart) * 100);
// yefullpart = (openfullpart - 1) - fullpart;
// yeBalance = (yefullpart + "." + yeFrac);
// oCurrStatus.YearEndBalance = Math.Round(Convert.ToDouble(yeBalance), 2);
// }
// }
// else
// {
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 2);
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 2);
// }
// }
// else
// {
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 1);
// oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 1);
// }
// }
// #endregion Calculate Year-End Balance
// if (oCurrStatus.YearEndBalance < oDetail.MaxEncash)
// {
// oCurrStatus.EncashDays = oCurrStatus.YearEndBalance;
// oCurrStatus.YearEndBalance = 0;
// }
// else
// {
// oCurrStatus.EncashDays = oDetail.MaxEncash;
// oCurrStatus.YearEndBalance = oCurrStatus.YearEndBalance - oDetail.MaxEncash;
// }
// if (oItem.CalculationType == EnumLeaveCalculationType.Hourly || oItem.CalculationType == EnumLeaveCalculationType.Hourly_Prorated)
// {
// oCurrStatus.EncashAmount = Math.Round(oEmployee.BasicSalary * oCurrStatus.EncashDays / 208);
// }
// if (oItem.Leave.IsBalanceCalculationNeeded)
// oCurrYearBalance.Add(oCurrStatus);
// }
// return oCurrYearBalance;
// }
// catch (Exception exp)
// {
// throw new Exception(exp.Message);
// }
// return oCurrYearBalance;
//}
//public static List<EmpLeaveStatus> CurrentYearStatus(List<Employee> oEmployees, LeaveYear lYear)
//{
// List<EmpLeaveStatus> oAllEmpsCurrYearBalance = null;
// try
// {
// List<EmpLeaveStatus> oCurrYearBalance = null;
// DateTime operationDate = PayrollPayrollGlobalFunctions.GetOperationDate();
// LeaveYear oCurrYear = lYear;
// oAllEmpsCurrYearBalance = new List<EmpLeaveStatus>();
// LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
// List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(EnumParameterSetup.Leave);
// List<SetupDetail> setupDetails = SetupDetail.GetParameters(EnumParameterSetup.Leave);
// List<LeaveParameter> leaveParamss = LeaveParameter.Get();
// leaveParamss = leaveParamss.OrderBy(o => o.Leave.Sequence).ToList().ToObjectsTemplate();
// List<BATBGrandFatherTaging> gfs = BATBGrandFatherTaging.Get(oEmployees.CommaSeparatedIDs());
// List<LeaveParameterDetail> leaveParamDetails = new LeaveParameter().GetAllDetails();
// List<LeaveEntry> oLs = null;
// if (oEmployees.Count == 1)
// oLs = LeaveEntry.Service.GetSumOfAvailedLeave(oEmployees[0].ID.Integer, oCurrYear.ID.Integer);
// else oLs = LeaveEntry.Service.GetSumOfAvailedLeave(oCurrYear.ID.Integer);
// List<EmpLeaveStatus> oPrevStatuses = EmpLeaveStatus.GetAllPrvYearStatus(oCurrYear.ID.Integer);
// BATBGrandFatherTaging gf = null;
// List<DailyAttnProcess> _dailyAttnProcess = DailyAttnProcess.Get(oCurrYear.StartDate.Date, oCurrYear.EndDate.Date);
// List<DailyAttnProcess> _dailyAttnProcessEmp = null;
// List<Leave> _leaves = Leave.Get(); ;
// foreach (Employee oEmp in oEmployees)
// {
// gf = gfs.FirstOrDefault(o => o.EmployeeID == oEmp.ID.Integer);
// if (gf != null)
// {
// oEmp.GrandFather = gf;
// }
// else
// {
// oEmp.GrandFather = new BATBGrandFatherTaging();
// }
// List<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParams(oEmp, setupTypes, setupDetails, leaveParamss);
// _dailyAttnProcessEmp = _dailyAttnProcess.Where(o => o.EmployeeID == oEmp.ID).ToObjectsTemplate();
// oCurrYearBalance = EmpLeaveStatus.CurrentYearStatus(oEmp, operationDate, oAppLeaveParams, oCurrYear, oLs, oPrevStatuses, leaveParamDetails, _leaves, _dailyAttnProcessEmp);
// foreach (EmpLeaveStatus eSts in oCurrYearBalance)
// oAllEmpsCurrYearBalance.Add(eSts);
// }
// }
// catch (Exception exp)
// {
// }
// return oAllEmpsCurrYearBalance;
//}
//public static EmpLeaveStatus GetleaveStatus(List<EmpLeaveStatus> leaveBalances, int nLeaveId)
//{
// foreach (EmpLeaveStatus oItem in leaveBalances)
// {
// if (oItem.LeaveId == nLeaveId)
// return oItem;
// }
// return null;
//}
//public static EmpLeaveStatus GetPrvYearStatus(int leaveYearID, int nLeaveId, int nEmpId)
//{
// LeaveYear oCurrYear = LeaveYear.Service.Get(ID.FromInteger(leaveYearID));
// LeaveYear oPrvYear = null;
// List<LeaveYear> 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 LeaveProcess.Service.GetStatus(nEmpId, nLeaveId, oPrvYear.ID.Integer);
//}
//public static List<EmpLeaveStatus> GetByYear(int leaveYearID)
//{
// List<EmpLeaveStatus> oEmpLeaveStatuss = null;
// oEmpLeaveStatuss = LeaveProcess.Service.GetByYear(leaveYearID);
// return oEmpLeaveStatuss;
//}
//public static List<EmpLeaveStatus> GetByEmpIDs(string empIds, int leaveYearID)
//{
// List<EmpLeaveStatus> oEmpLeaveStatuss = null;
// oEmpLeaveStatuss = LeaveProcess.Service.GetByEmpIDs(empIds, leaveYearID);
// return oEmpLeaveStatuss;
//}
//#region Functions
//public void SaveStatus(EmpLeaveStatus oEmpLeaveStatus)
//{
// LeaveProcess.Service.SaveStatus(oEmpLeaveStatus);
//}
//public static ID Save(EmpLeaveStatus oEmpLeaveStatus)
//{
// return LeaveProcess.Service.Save(oEmpLeaveStatus);
//}
//public void SaveStatus(List<EmpLeaveStatus> oEmpLeaveStatus)
//{
// LeaveProcess.Service.SaveStatus(oEmpLeaveStatus);
//}
//public void DeleteProcessDetailByID(int nProcessId)
//{
// LeaveProcess.Service.DeleteProcessDetailByID(nProcessId);
//}
//public void DeleteByPayrollType(int nProcessId, int nPayrollTypeId, int nLeaveID)
//{
// LeaveProcess.Service.DeleteByPayrollType(nProcessId, nPayrollTypeId, nLeaveID);
//}
//#endregion
//#region Collection of EmpLeaveStatus
//public string GetEmpIDs()
//{
// string ids = string.Empty;
// return ids;
//}
//#endregion
//#region Functions
//public static List<EmpLeaveStatus> GetProcessDetails(int nProcessId)
//{
// #region Cache Header
// List<EmpLeaveStatus> oEmpLeaveStatuss = _cache["Get"] as List<EmpLeaveStatus>;
// if (oEmpLeaveStatuss != null)
// return oEmpLeaveStatuss;
// #endregion
// return oEmpLeaveStatuss;
//}
//#endregion
//public List<EmpLeaveStatus> CurrentYearStatusForEncash(List<Employee> oEmployees, LeaveYear lYear, EnumLeaveStatus eStatus, DateTime operationDate)
//{
// try
// {
// List<EmpLeaveStatus> oCurrYearBalance = null;
// List<EmpLeaveStatus> oAllEmpsCurrYearBalance = new List<EmpLeaveStatus>();
// LeaveYear oCurrYear = lYear;
// LeaveYear oPrvYear = new ILeaveYearService().LastLeaveYear(oCurrYear);
// }
// catch (Exception exp)
// {
// }
// return null;
//}
}
#endregion
#region ILeaveProcess Service
public interface ILeaveProcessService
{
#region Leave Process
DataSet GetEmpAllLeaveRelatedInfo(int employeeID);
LeaveProcess Get(int LeaveProcessId);
LeaveProcess Get(int nLeaveProcessYear, int nPayrollTypeid);
List<EmpLeaveStatus> GetLeaveBalance(int leaveYearID, int payrollTypeID, string EmpIDsIn, int? empID = null);
List<LeaveHistory> GetRecord(string empIds, DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus);
List<LeaveProcess> Get();
LeaveProcess GetLastProcess();
void UpadteLeaveYearStatus(LeaveProcess oLeaveProcess);
bool IsProcessed(int nProcessYear, int payrolltypeid);
void DoYearEnd(LeaveProcess oLeaveProcess);
void UnDoYearEnd(int leaveyearid, int payrolltypeid);
#endregion
#region Leave Process Detail
EmpLeaveStatus GetProcessDetail(int id);
EmpLeaveStatus GetStatus(int empid, int leaveID, int leaveYearID);
EmpLeaveStatus GetByYear(int ProcessYear, int LeaveId, int EmpId);
List<EmpLeaveStatus> GetByYear(int leaveYearID);
List<EmpLeaveStatus> GetProcessDetails(int ProcessId);
int Save(EmpLeaveStatus oEmpLeaveStatus);
void SaveStatus(EmpLeaveStatus oEmpLeaveStatus);
void DeleteProcessDetail(int id);
void DeleteProcessDetailByID(int nProcessId);
void DeleteByPayrollType(int nProcessId, int nPayrollTypeId, int nLeaveID);
List<EmpLeaveStatus> GetByYearType(int leaveYearID, int leaveId);
void SaveStatus(List<EmpLeaveStatus> oEmpLeaveStatus);
void UpdateEncashAmount(List<EmpLeaveStatus> _oEmpLeaveStatus);
#endregion
//List<EmpLeaveStatus> CurrentYearStatusOptimized(Employee oEmployee, DateTime operationDate, int presentAttnCount,
//List<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear, List<LeaveEntry> oLeaveEntries, EnumLeaveStatus enumLeaveStatus, List<EmpLeaveStatus> oPrevStatuses, List<LeaveParameterDetail> ParamDetails, List<LeaveException> oExceptions, List<AttnNationalHoliday> oNationalHolidays);
List<EmpLeaveStatus> GetByEmpIDs(string empIds, int leaveYearID);
List<LeaveDetailsMonthWiseDTO> GetMonthWiseLeaveRegister(string empIds, int leaveYearId, int leaveId, EnumLeaveStatus leaveStatus, DateTime leaveFromMonth, DateTime leaveToMonth);
List<EmpLeaveStatus> CurrentYearStatus(List<Employee> employees, LeaveYear leaveYear, int payrollTypeId);
double GetSettlementEarnLeaveBalance(Employee emp, DateTime balanceDate);
public List<EmpLeaveStatus> CurrentYearStatusForEncash(List<Employee> oEmployees, LeaveYear lYear, EnumLeaveStatus eStatus, DateTime operationDate, int payrolltypeId);
}
#endregion
public class LeaveDetailsMonthWiseDTO
{
public string EmpNo { get; set; }
public string Name { get; set; }
public string JoiningDate { get; set; }
public string Designation { get; set; }
//public string Department { get; set; }
//public string CostCenter { get; set; }
public string LeaveName { get; set; }
public string FromDate { get; set; }
public string ToDate { get; set; }
public double Consumed { get; set; }
public bool isLFA { get; set; }
public bool isHalfDay { get; set; }
public string Remarks { get; set; }
public string EmpNoEmpName
{
get { return EmpNo + "-" + Name; }
}
}
}