1408 lines
61 KiB
C#
1408 lines
61 KiB
C#
using System;
|
|
using System.Data;
|
|
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;
|
|
using System.Windows.Forms;
|
|
namespace Payroll.BO
|
|
{
|
|
#region LeaveProcess
|
|
[Serializable]
|
|
public class LeaveProcess : AuditTrailBase
|
|
{
|
|
public event ProcessStatus ProcessStatus;
|
|
public event ProgressStatus ProgressStatus;
|
|
private List<SalaryProcessStatus> _processStatuses;
|
|
#region Cache Store
|
|
private static Cache _cache = new Cache(typeof(LeaveProcess));
|
|
#endregion
|
|
|
|
#region Constructor
|
|
public LeaveProcess()
|
|
{
|
|
_leaveYearID = 0;
|
|
_dProcessDate = DateTime.Now.Date;
|
|
_isYearEnd = false;
|
|
_nProgress = 0;
|
|
_sProcessYearDesc = "";
|
|
_leaveYear = LeaveYear.GetCurrentYear();
|
|
_PayrollTypeID = 0;
|
|
}
|
|
#endregion
|
|
public List<SalaryProcessStatus> ErrorList
|
|
{
|
|
get
|
|
{
|
|
return _processStatuses;
|
|
}
|
|
}
|
|
private void UpdateprocessStatus(string statusString)
|
|
{
|
|
if (ProcessStatus != null) ProcessStatus(statusString);
|
|
}
|
|
private void UpdateProgressStatus(EnumProcessStatus status)
|
|
{
|
|
if (ProgressStatus != null) ProgressStatus(status);
|
|
}
|
|
#region Properties
|
|
#region PayrollTypeID
|
|
private int _PayrollTypeID;
|
|
public int PayrollTypeID
|
|
{
|
|
get { return _PayrollTypeID; }
|
|
set { _PayrollTypeID = value; }
|
|
}
|
|
|
|
|
|
#endregion
|
|
#region LeaveYearID
|
|
private int _leaveYearID;
|
|
public int LeaveYearID
|
|
{
|
|
get { return _leaveYearID; }
|
|
set { _leaveYearID = value; }
|
|
}
|
|
#endregion
|
|
private string _sProcessYearDesc;
|
|
public string ProcessYearDescription
|
|
{
|
|
get { return _sProcessYearDesc; }
|
|
set { _sProcessYearDesc = value; }
|
|
}
|
|
|
|
|
|
#region For The Benifited Year
|
|
public int ForTheBenifitedYear
|
|
{
|
|
get { return _leaveYearID > 0 ? _leaveYearID + 1 : 0; }
|
|
}
|
|
#endregion
|
|
|
|
#region ProcessDate
|
|
private DateTime _dProcessDate;
|
|
public DateTime ProcessDate
|
|
{
|
|
get { return _dProcessDate; }
|
|
set { _dProcessDate = value; }
|
|
}
|
|
#endregion
|
|
private bool _isYearEnd;
|
|
|
|
public bool IsYearEnd
|
|
{
|
|
get { return _isYearEnd; }
|
|
set { _isYearEnd = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
private int _nProgress;
|
|
|
|
private LeaveYear _leaveYear;
|
|
public LeaveYear LeaveYear
|
|
{
|
|
get
|
|
{
|
|
if (_leaveYear == null)
|
|
{
|
|
_leaveYear = Payroll.BO.LeaveYear.Service.Get(ID.FromInteger(_leaveYearID));
|
|
}
|
|
return _leaveYear;
|
|
}
|
|
set
|
|
{
|
|
_leaveYear = value;
|
|
}
|
|
}
|
|
|
|
private ObjectsTemplate<EmpLeaveStatus> _empLeaveStatuss;
|
|
public ObjectsTemplate<EmpLeaveStatus> EmpLeaveStatuss
|
|
{
|
|
get
|
|
{
|
|
return _empLeaveStatuss;
|
|
|
|
}
|
|
set { _empLeaveStatuss = value; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
private ObjectsTemplate<EmpLeaveStatus> _LeaveProcessDetails;
|
|
public ObjectsTemplate<EmpLeaveStatus> LeaveProcessDetails
|
|
{
|
|
get
|
|
{
|
|
return _LeaveProcessDetails;
|
|
}
|
|
set { _LeaveProcessDetails = value; }
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> GetByYearType(int leaveYearID, int leaveId)
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oEmpLeaveStatuss = null;
|
|
|
|
oEmpLeaveStatuss = LeaveProcess.Service.GetByYearType(leaveYearID, leaveId);
|
|
|
|
return oEmpLeaveStatuss;
|
|
}
|
|
|
|
public LeaveProcess Get(int nLeaveProcessId)
|
|
{
|
|
LeaveProcess oLeaveProcess = null;
|
|
#region Cache Header
|
|
oLeaveProcess = (LeaveProcess)_cache["Get", nLeaveProcessId];
|
|
if (oLeaveProcess != null)
|
|
return oLeaveProcess;
|
|
#endregion
|
|
oLeaveProcess = LeaveProcess.Service.Get(ID.FromInteger(nLeaveProcessId));
|
|
|
|
#region Cache Footer
|
|
_cache.Add(oLeaveProcess, "Get", nLeaveProcessId);
|
|
#endregion
|
|
return oLeaveProcess;
|
|
}
|
|
|
|
public static LeaveProcess GetByYearID(int nLeaveProcessYear)
|
|
{
|
|
LeaveProcess oLeaveProcess = null;
|
|
oLeaveProcess = LeaveProcess.Service.Get(nLeaveProcessYear);
|
|
return oLeaveProcess;
|
|
}
|
|
|
|
public static LeaveProcess GetByYearANDPayrollTypeID(int nLeaveProcessYear, int nPayrollTypeid)
|
|
{
|
|
LeaveProcess oLeaveProcess = null;
|
|
oLeaveProcess = LeaveProcess.Service.Get(nLeaveProcessYear, nPayrollTypeid);
|
|
return oLeaveProcess;
|
|
}
|
|
|
|
public static LeaveProcess GetLastProcess()
|
|
{
|
|
LeaveProcess oLeaveProcess = null;
|
|
oLeaveProcess = LeaveProcess.Service.GetLastProcess();
|
|
return oLeaveProcess;
|
|
}
|
|
|
|
public ID Save()
|
|
{
|
|
return LeaveProcess.Service.Save(this);
|
|
}
|
|
|
|
public void Delete()
|
|
{
|
|
LeaveProcess.Service.Delete(this.LeaveYearID);
|
|
}
|
|
|
|
public void DeleteByPayrollTypeID()
|
|
{
|
|
LeaveProcess.Service.Delete(this.LeaveYearID, this.PayrollTypeID);
|
|
}
|
|
|
|
public void UpadteLeaveYearStatus()
|
|
{
|
|
LeaveProcess.Service.UpadteLeaveYearStatus(this);
|
|
}
|
|
|
|
public void DoYearEnd()
|
|
{
|
|
LeaveProcess.Service.DoYearEnd(this);
|
|
}
|
|
|
|
public EmpLeaveStatus GetStatusFromColl(int employeeid, int leaveyearID, int leaveid)
|
|
{
|
|
foreach (EmpLeaveStatus oItem in this.LeaveProcessDetails)
|
|
{
|
|
if (oItem.EmpId == employeeid && oItem.LeaveYearID == leaveyearID && oItem.LeaveId == leaveid)
|
|
return oItem;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
#region New process
|
|
|
|
public void Process(LeaveYear oLeaveYear)
|
|
{
|
|
//ObjectsTemplate<Employee> oEmployees = new ObjectsTemplate<Employee>();
|
|
//Employee oemp1 = Employee.Get("000004");
|
|
//oEmployees.Add(oemp1);
|
|
|
|
ObjectsTemplate<Employee> oEmployees = Employee.GetNew(oLeaveYear.EndDate,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
|
|
UpdateprocessStatus("Collecting Leave Information ....");
|
|
_nProgress = 0;
|
|
|
|
_empLeaveStatuss = new ObjectsTemplate<EmpLeaveStatus>();
|
|
try
|
|
{
|
|
_empLeaveStatuss = this.CurrentYearStatusForPreocess(oEmployees, oLeaveYear, EnumLeaveStatus.Approved);
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
throw new Exception(exp.Message);
|
|
}
|
|
this.EmpLeaveStatuss = _empLeaveStatuss;
|
|
}
|
|
#endregion
|
|
|
|
private void PrepareLeaveStatuses(ObjectsTemplate<LeaveProcessDetail> oLeaveStatuss, DataTable oDT)
|
|
{
|
|
LeaveProcessDetail oStatus = null;
|
|
|
|
foreach (DataRow oRow in oDT.Rows)
|
|
{
|
|
_nProgress += 1;
|
|
oStatus = new LeaveProcessDetail();
|
|
oStatus.EmpId = Convert.ToInt32(oRow["EmpId"]);
|
|
oStatus.LeaveYearID = _leaveYear.ID.Integer;
|
|
oStatus.LeaveId = Convert.ToInt32(oRow["LeaveId"]);
|
|
oStatus.CarryFromPrvYear = Convert.ToInt32(oRow["CarryFromPrvYear"]);
|
|
SetDetails(oStatus, oRow);
|
|
oLeaveStatuss.Add(oStatus);
|
|
}
|
|
}
|
|
|
|
private void SetDetails(LeaveProcessDetail oStatus, DataRow orow)
|
|
{
|
|
LeaveProcessDetail oPrevStatus = null;
|
|
|
|
LeaveParameterDetail oDetail = null;
|
|
Employee oEmp = Employee.Service.Get(ID.FromInteger(oStatus.EmpId));
|
|
LeaveParameter oParameter = new LeaveParameter();
|
|
|
|
oPrevStatus = LeaveProcessDetail.GetYearStatus(_leaveYear.ID.Integer - 1, oStatus.LeaveId, oEmp.ID.Integer);
|
|
double nBalance = 0.0;
|
|
oDetail = oParameter.GetDetailForEmp(oEmp.ID);
|
|
|
|
if (oDetail != null)
|
|
{
|
|
nBalance = (oPrevStatus == null) ? oDetail.MaxDays : (oPrevStatus.YearEndBalance + oDetail.MaxDays);
|
|
nBalance -= Convert.ToDouble(orow["TotalDays"]);
|
|
if (nBalance > 0)
|
|
{
|
|
oStatus.CFDays = (nBalance >= oDetail.MaxCF) ? oDetail.MaxCF : nBalance;
|
|
nBalance = nBalance - oStatus.CFDays;
|
|
oStatus.EncashDays = (nBalance >= oDetail.MaxEncash) ? oDetail.MaxEncash : nBalance;
|
|
nBalance = nBalance - oStatus.EncashDays;
|
|
}
|
|
else
|
|
{
|
|
oStatus.CFDays = 0;
|
|
oStatus.EncashDays = 0;
|
|
}
|
|
oStatus.EncashAmount = 0;
|
|
oStatus.NormalLeaveDays = oDetail.MaxDays;
|
|
oStatus.YearEndBalance = oStatus.CFDays;
|
|
}
|
|
}
|
|
|
|
public bool IsProcessed(int nProcessYear)
|
|
{
|
|
return LeaveProcess.Service.IsProcessed(nProcessYear);
|
|
}
|
|
public ObjectsTemplate<EmpLeaveStatus> CurrentYearStatusForPreocess(ObjectsTemplate<Employee> oEmployees, LeaveYear lYear, EnumLeaveStatus eStatus)
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = null;
|
|
ObjectsTemplate<EmpLeaveStatus> oAllEmpsCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
DateTime operationDate = GlobalFunctions.GetOperationDate();
|
|
LeaveYear oCurrYear = lYear;
|
|
LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
|
|
List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<SetupDetail> setupDetails = SetupDetail.GetParameters(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<LeaveParameter> leaveParamss = LeaveParameter.Get();
|
|
ObjectsTemplate<LeaveParameterDetail> leaveParamDetails = new LeaveParameter().GetAllDetails();
|
|
List<LeaveEntry> oLs = LeaveEntry.GetByLeaveYear(oCurrYear.ID.Integer);
|
|
|
|
ObjectsTemplate<LeaveYear> olYears = LeaveYear.Service.Get();
|
|
LeaveYear ly = EmpLeaveStatus.GetPrvYear(oCurrYear, olYears);
|
|
List<EmpLeaveStatus> oPrevStatus = EmpLeaveStatus.GetByYear(ly == null ? 0 : ly.ID.Integer);
|
|
List<EmpLeaveStatus> oPrevStatuses = oPrevStatus;// EmpLeaveStatus.GetAllPrvYearStatus(oCurrYear.ID.Integer);
|
|
UpdateProgressStatus(EnumProcessStatus.Start);
|
|
int nMax = oEmployees.Count;
|
|
int ncc = 1;
|
|
foreach (Employee oEmp in oEmployees)
|
|
{
|
|
UpdateProgressStatus(EnumProcessStatus.PerformStep);
|
|
UpdateprocessStatus("Collecting Leave Information " + ncc.ToString() + "/" + nMax);
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParamsForReport(oEmp, setupTypes, setupDetails, leaveParamss);
|
|
oCurrYearBalance = EmpLeaveStatus.CurrentYearStatusForProcess(oEmp, operationDate, oAppLeaveParams, oCurrYear, oLs, eStatus, oPrevStatuses, leaveParamDetails, olYears, oPrevStatus);
|
|
foreach (EmpLeaveStatus eSts in oCurrYearBalance)
|
|
oAllEmpsCurrYearBalance.Add(eSts);
|
|
ncc++;
|
|
}
|
|
UpdateProgressStatus(EnumProcessStatus.End);
|
|
return oAllEmpsCurrYearBalance;
|
|
}
|
|
#region Functions
|
|
public static ObjectsTemplate<LeaveProcess> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<LeaveProcess> leaveProcess = _cache["Get"] as ObjectsTemplate<LeaveProcess>;
|
|
if (leaveProcess != null)
|
|
return leaveProcess;
|
|
#endregion
|
|
leaveProcess = LeaveProcess.Service.Get();
|
|
#region Cache Footer
|
|
_cache.Add(leaveProcess, "Get");
|
|
#endregion
|
|
return leaveProcess;
|
|
}
|
|
#endregion
|
|
|
|
#region Service Factory
|
|
internal static ILeaveProcessService Service
|
|
{
|
|
get { return Services.Factory.CreateService<ILeaveProcessService>(typeof(ILeaveProcessService)); }
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Leave Process Detail
|
|
public class EmpLeaveStatus : BasicBaseObject
|
|
{
|
|
#region Cache Store
|
|
private static Cache _cache = new Cache(typeof(EmpLeaveStatus));
|
|
#endregion
|
|
|
|
#region Constructor
|
|
public EmpLeaveStatus()
|
|
{
|
|
|
|
_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;
|
|
_CurrentYearBalance = 0;
|
|
_CurrentYearOpening = 0;
|
|
_ApplyDays = 0;
|
|
}
|
|
#endregion
|
|
|
|
private double _CurrentYearBalance;
|
|
public double CurrentYearBalance
|
|
{
|
|
get { return _CurrentYearBalance; }
|
|
set { _CurrentYearBalance = value; }
|
|
}
|
|
|
|
private double _CurrentYearOpening;
|
|
public double CurrentYearOpening
|
|
{
|
|
get { return _CurrentYearOpening; }
|
|
set { _CurrentYearOpening = value; }
|
|
}
|
|
|
|
#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; }
|
|
}
|
|
|
|
private double _ApplyDays;
|
|
public double ApplyDays
|
|
{
|
|
get { return _ApplyDays; }
|
|
set { _ApplyDays = 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
|
|
|
|
public void UpdateEncashAmount(ObjectsTemplate<EmpLeaveStatus> _oEmpLeaveStatus)
|
|
{
|
|
LeaveProcess.Service.UpdateEncashAmount(_oEmpLeaveStatus);
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> GetByYearType(int leaveYearID, int leaveId)
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oEmpLeaveStatuss = null;
|
|
|
|
oEmpLeaveStatuss = LeaveProcess.Service.GetByYearType(leaveYearID, leaveId);
|
|
|
|
return oEmpLeaveStatuss;
|
|
}
|
|
|
|
public static List<ObjectsTemplate<EmpLeaveStatus>> CurrentYearStatusForReport(ObjectsTemplate<Employee> oemps, LeaveYear lYear)
|
|
{
|
|
List<ObjectsTemplate<EmpLeaveStatus>> obalance = new List<ObjectsTemplate<EmpLeaveStatus>>(); ;
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = null;
|
|
DateTime operationDate = GlobalFunctions.GetOperationDate();
|
|
foreach (Employee oEmployee in oemps)
|
|
{
|
|
oCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
//EmpLeaveStatus oStatus = null;
|
|
|
|
LeaveYear oCurrYear = lYear;
|
|
//LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
|
|
//ObjectsTemplate<EmpLeaveStatus> prvYearStatus =EmpLeaveStatus.GetAllStatus(employeeID);
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParams(oEmployee);
|
|
ObjectsTemplate<Employee> tempEmps = new ObjectsTemplate<Employee>();
|
|
tempEmps.Add(oEmployee);
|
|
oCurrYearBalance = EmpLeaveStatus.CurrentYearStatus(tempEmps, oCurrYear, EnumLeaveStatus.Approved);
|
|
obalance.Add(oCurrYearBalance);
|
|
}
|
|
return obalance;
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatusForView(Employee oEmployee, DateTime operationDate,
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear)
|
|
{
|
|
DateTime dCurrentDate = operationDate;
|
|
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
LeaveParameterDetail oDetail = null;
|
|
|
|
ConfigurationManager oCon = new ConfigurationManager();
|
|
//string Params = ConfigurationManager.GetStringValue("leave", "balance", EnumConfigurationType.Logic);
|
|
foreach (LeaveParameter oItem in oAppLeaveParams)
|
|
{
|
|
EmpLeaveStatus oPrevStatus=new EmpLeaveStatus();
|
|
EmpLeaveStatus oCurrStatus = new EmpLeaveStatus();
|
|
oCurrStatus.EmpId = oEmployee.ID.Integer;
|
|
oCurrStatus.LeaveId = oItem.LeaveId;
|
|
oCurrStatus.LeaveYearID = oCurrYear.ID.Integer;
|
|
|
|
//oDetail = oItem.GetApplicableForEmployee(oEmployee, operationDate,); //8
|
|
if (oDetail != null) oCurrStatus.NormalLeaveDays = oDetail.MaxDays;
|
|
else continue;
|
|
oItem.Details = new ObjectsTemplate<LeaveParameterDetail>();
|
|
oItem.Details.Add(oDetail);
|
|
//oPrevStatus = EmpLeaveStatus.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer);
|
|
#region calculate the opening balance
|
|
|
|
if (oPrevStatus != null)
|
|
{
|
|
oCurrStatus.OpeningBalance = oPrevStatus.CFDays;
|
|
oCurrStatus.CFDays = oPrevStatus.CFDays;
|
|
}
|
|
double nNormalLeavedays = 0;
|
|
if (oEmployee.JoiningDate.Date.Year == oCurrYear.StartDate.Date.Year)
|
|
{
|
|
TimeSpan ts = (oCurrYear.EndDate - oEmployee.JoiningDate);
|
|
double ntemp = oCurrStatus.NormalLeaveDays / 12;
|
|
double nDays = ts.Days;
|
|
nNormalLeavedays = Math.Round((ntemp * (nDays / (double)30.00)));
|
|
}
|
|
else
|
|
{
|
|
nNormalLeavedays = oCurrStatus.NormalLeaveDays;
|
|
}
|
|
|
|
oCurrStatus.NormalLeaveDays = nNormalLeavedays;
|
|
if (oItem.IsForfited)
|
|
{
|
|
if (oCurrYear.StartDate.AddMonths(oItem.ForfitedMonth).Month >= dCurrentDate.Date.Month)
|
|
{
|
|
double nLeaveAvailed = 0;
|
|
oCurrStatus.ForfitedDays = oPrevStatus.YearEndBalance - nLeaveAvailed;
|
|
oCurrStatus.ForfitedDays = (oCurrStatus.ForfitedDays < 0) ? 0 : oCurrStatus.ForfitedDays;
|
|
}
|
|
}
|
|
if (oItem.IsMonthlyBalance)
|
|
oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance + Math.Round(oCurrStatus.NormalLeaveDays / 12 * (dCurrentDate.Date.Month - 1));
|
|
else
|
|
oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance + oCurrStatus.NormalLeaveDays;
|
|
|
|
oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance;
|
|
|
|
//if (oItem.Leave.IsEarnedLeave)
|
|
// oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance;
|
|
//else
|
|
// oCurrStatus.OpeningBalance = (oCurrStatus.OpeningBalance + oCurrStatus.NormalLeaveDays) > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance + oCurrStatus.NormalLeaveDays;
|
|
|
|
#endregion calculate the opening balance
|
|
#region calculate leave availed in current year
|
|
oCurrStatus.LeaveAvailed = LeaveEntry.GetLeaveAmtByType(oEmployee.ID.Integer, oItem.ID.Integer, oCurrYear.ID.Integer, EnumLeaveStatus.Approved); //10
|
|
#endregion calculate leave availed in current year
|
|
#region Calculate Year-End Balance
|
|
oCurrStatus.YearEndBalance = 0;
|
|
if (oItem.Leave.IsBalanceCalculationNeeded == false)
|
|
{
|
|
oCurrStatus.NormalLeaveDays = 0;
|
|
oCurrStatus.OpeningBalance = 0;
|
|
}
|
|
else oCurrStatus.YearEndBalance = oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed);
|
|
#endregion Calculate Year-End Balance
|
|
oCurrYearBalance.Add(oCurrStatus);
|
|
}
|
|
return oCurrYearBalance;
|
|
}
|
|
|
|
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 , GlobalFunctions.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.Monthly)
|
|
{
|
|
if (emp.JoiningDate > oCurrentYear.StartDate)
|
|
ts = dCurrentDate - emp.JoiningDate;
|
|
else
|
|
ts = dCurrentDate - GlobalFunctions.FirstDateOfYear(dCurrentDate);
|
|
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 - GlobalFunctions.FirstDateOfYear(dCurrentDate);
|
|
if (ts.Days > 365)
|
|
nTotalDays = (double) oDetail.MaxDays;
|
|
|
|
}
|
|
//else if (eType == EnumLeaveCalculationType.Prorated)
|
|
//{
|
|
// if (emp.JoiningDate > oCurrentYear.StartDate)
|
|
// {
|
|
// ts = GlobalFunctions.LastDateOfYear(dCurrentDate) - emp.JoiningDate;
|
|
// }
|
|
// else
|
|
// {
|
|
// ts = GlobalFunctions.LastDateOfYear(dCurrentDate) - GlobalFunctions.FirstDateOfYear(dCurrentDate);
|
|
// }
|
|
// nTotalDays = (oDetail.MaxDays / 365) * ts.Days;
|
|
//}
|
|
else if (eType == EnumLeaveCalculationType.Not_Applicable)
|
|
{
|
|
//if (emp.JoiningDate > oCurrentYear.StartDate)
|
|
// ts = GlobalFunctions.LastDateOfYear(dCurrentDate) - emp.JoiningDate;
|
|
//else
|
|
ts = GlobalFunctions.LastDateOfYear(dCurrentDate) - GlobalFunctions.FirstDateOfYear(dCurrentDate);
|
|
nTempDays = oDetail.MaxDays / 12;
|
|
nTotalDays = (double) nTempDays * (ts.Days / 30);
|
|
|
|
}
|
|
else if (eType == EnumLeaveCalculationType.Not_Applicable_With_Prorated)
|
|
{
|
|
if (emp.JoiningDate > oCurrentYear.StartDate)
|
|
ts = GlobalFunctions.LastDateOfYear(dCurrentDate) - emp.JoiningDate;
|
|
else
|
|
ts = GlobalFunctions.LastDateOfYear(dCurrentDate) - GlobalFunctions.FirstDateOfYear(dCurrentDate);
|
|
nTempDays = oDetail.MaxDays / 12;
|
|
nTotalDays = (double) nTempDays * (ts.Days / 30);
|
|
|
|
}
|
|
|
|
return Math.Round(nTotalDays , 0);
|
|
}
|
|
|
|
public static List<EmpLeaveStatus> GetAllPrvYearStatus(int leaveYearID)
|
|
{
|
|
LeaveYear oCurrYear = LeaveYear.Service.Get(ID.FromInteger(leaveYearID));
|
|
LeaveYear oPrvYear = null;
|
|
ObjectsTemplate<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.GetByYear(oPrvYear.ID.Integer);
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatusForProcess(Employee oEmployee, DateTime operationDate,
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear, List<LeaveEntry> oLeaveEntries, EnumLeaveStatus enumLeaveStatus, List<EmpLeaveStatus> oPrevStatuses, List<LeaveParameterDetail> ParamDetails, ObjectsTemplate<LeaveYear> olYears, List<EmpLeaveStatus> oAllPrevStatus)
|
|
{
|
|
DateTime dCurrentDate = operationDate;
|
|
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
LeaveParameterDetail oDetail = null;
|
|
|
|
ConfigurationManager oCon = new ConfigurationManager();
|
|
//string Params = ConfigurationManager.GetStringValue("leave", "balance", EnumConfigurationType.Logic);
|
|
|
|
foreach (LeaveParameter oItem in oAppLeaveParams)
|
|
{
|
|
EmpLeaveStatus oPrevStatus;
|
|
EmpLeaveStatus oCurrStatus = new EmpLeaveStatus();
|
|
oCurrStatus.EmpId = oEmployee.ID.Integer;
|
|
oCurrStatus.LeaveId = oItem.LeaveId;
|
|
oCurrStatus.LeaveYearID = oCurrYear.ID.Integer;
|
|
//ObjectsTemplate<LeaveException> oExceptions = LeaveException.GetByEmpID(oItem.LeaveId, oEmployee.ID.Integer);
|
|
//if (oExceptions.Count > 0)
|
|
//{
|
|
// oCurrStatus.LeaveAvailed = LeaveEntry.GetLeaveAmtByType(oEmployee.ID.Integer, oItem.Leave.ID.Integer, oCurrYear.ID.Integer, EnumLeaveStatus.Approved); //10
|
|
// oCurrStatus.OpeningBalance = oExceptions[0].OpeningBalance + oExceptions[0].MaxDays;
|
|
// oCurrStatus.YearEndBalance = oCurrStatus.OpeningBalance - oCurrStatus.LeaveAvailed;
|
|
//}
|
|
//else
|
|
//{
|
|
|
|
oDetail = oItem.GetApplicableForEmployee(oEmployee, operationDate, ParamDetails);
|
|
if (oDetail != null) oCurrStatus.NormalLeaveDays = 0;
|
|
else continue;
|
|
//oItem.Details = new ObjectsTemplate<LeaveParameterDetail>();
|
|
//oItem.Details.Add(oDetail);
|
|
////need to change
|
|
oPrevStatus = oAllPrevStatus.Find(delegate(EmpLeaveStatus es) { return es.LeaveId == oItem.LeaveId && es.EmpId == oEmployee.ID.Integer; }); //.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer,oCurrYear,olYears);
|
|
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;
|
|
|
|
#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.Integer &&
|
|
o.LeaveID.Integer == oItem.LeaveId &&
|
|
o.LeaveYear == oCurrYear.ID.Integer &&
|
|
(o.LeaveStatus == enumLeaveStatus || o.LeaveStatus == EnumLeaveStatus.Cancel_Request)
|
|
select new { o.ApprovedTotalDays };
|
|
var sum = itemsInCart.ToList().Select(c => c.ApprovedTotalDays).Sum();
|
|
oCurrStatus.LeaveAvailed = Convert.ToDouble(sum);
|
|
}
|
|
#endregion calculate leave availed in current year
|
|
|
|
#region Calculate Year-End Balance
|
|
oCurrStatus.YearEndBalance = 0;
|
|
if (oItem.Leave.IsBalanceCalculationNeeded == false)
|
|
{
|
|
oCurrStatus.NormalLeaveDays = 0;
|
|
oCurrStatus.OpeningBalance = 0;
|
|
}
|
|
else oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed),1);
|
|
if (oCurrStatus.YearEndBalance < 0)
|
|
{
|
|
oCurrStatus.CFDays = 0;
|
|
oCurrStatus.YearEndBalance += oCurrStatus.CurrentYearOpening;
|
|
}
|
|
else
|
|
{
|
|
if (oDetail.MaxCF > 0)
|
|
oCurrStatus.CFDays = oCurrStatus.YearEndBalance > oDetail.MaxCF ? oDetail.MaxCF : oCurrStatus.YearEndBalance;
|
|
else
|
|
oCurrStatus.CFDays = 0;
|
|
oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.CFDays + oCurrStatus.CurrentYearOpening,1);
|
|
}
|
|
if (oItem.MaxAccumulatedDays > 0)
|
|
oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.YearEndBalance,1);
|
|
//}
|
|
#endregion Calculate Year-End Balance
|
|
|
|
if (oItem.Leave.IsBalanceCalculationNeeded)
|
|
{
|
|
oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 1);
|
|
oCurrStatus.OpeningBalance = Math.Round(oCurrStatus.OpeningBalance, 1);
|
|
oCurrYearBalance.Add(oCurrStatus);
|
|
}
|
|
}
|
|
return oCurrYearBalance;
|
|
}
|
|
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatus(Employee oEmployee, DateTime operationDate,
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear, List<LeaveEntry> oLeaveEntries, EnumLeaveStatus enumLeaveStatus, List<EmpLeaveStatus> oPrevStatuses, List<LeaveParameterDetail> ParamDetails, List<LeaveException> oExceptions)
|
|
{
|
|
try
|
|
{
|
|
DateTime dCurrentDate = operationDate;
|
|
DateTime from_Date = DateTime.MinValue;
|
|
DateTime to_Date = DateTime.MinValue;
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
LeaveParameterDetail oDetail = null;
|
|
|
|
ConfigurationManager oCon = new ConfigurationManager();
|
|
string Params = ConfigurationManager.GetStringValue("leave", "balance", EnumConfigurationType.Logic);
|
|
|
|
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;
|
|
//
|
|
int empId = oEmployee.ID.Integer;
|
|
from_Date = GlobalFunctions.FirstDateOfYear(operationDate);
|
|
to_Date = GlobalFunctions.LastDateOfYear(operationDate);
|
|
|
|
ObjectsTemplate<LeaveEntry> les = LeaveEntry.GetByLeaveID(oItem.LeaveId, empId, from_Date, to_Date);
|
|
double countDays = 0;
|
|
foreach (LeaveEntry le in les)
|
|
{
|
|
countDays += le.AppliedTotalDays;
|
|
}
|
|
oCurrStatus.ApplyDays = countDays;
|
|
//
|
|
if (oPrevStatuses != null)
|
|
oPrevStatus = oPrevStatuses.Find(delegate(EmpLeaveStatus el) { return el.LeaveId == oItem.LeaveId && el.EmpId == oEmployee.ID.Integer; }); //EmpLeaveStatus.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer);
|
|
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);
|
|
oDetail = oItem.GetApplicableForEmployee2(oEmployee, operationDate, ParamDetails, oItem.ID);
|
|
if (oLeaveEx != null)
|
|
{
|
|
oCurrStatus.LeaveAvailed = LeaveEntry.GetLeaveAmtByType(oEmployee.ID.Integer, oItem.Leave.ID.Integer, oCurrYear.ID.Integer, EnumLeaveStatus.Approved); //10
|
|
oCurrStatus.OpeningBalance = oLeaveEx.OpeningBalance + oLeaveEx.MaxDays;
|
|
oCurrStatus.YearEndBalance = oCurrStatus.OpeningBalance - oCurrStatus.LeaveAvailed;
|
|
}
|
|
else
|
|
{
|
|
if (oDetail != null) oCurrStatus.NormalLeaveDays = 0;
|
|
else continue;
|
|
//oItem.Details = new ObjectsTemplate<LeaveParameterDetail>();
|
|
//oItem.Details.Add(oDetail);
|
|
oCurrStatus.CurrentYearBalance = 0;
|
|
oCurrStatus.CurrentYearOpening = 0;
|
|
|
|
#region calculate the opening balance new
|
|
|
|
if (oPrevStatus == null)
|
|
oCurrStatus.CurrentYearOpening = 0;
|
|
else
|
|
{
|
|
oCurrStatus.CurrentYearOpening = oPrevStatus.YearEndBalance;
|
|
oCurrStatus.CFDays = oPrevStatus.CFDays;
|
|
}
|
|
#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 (oLeaveEntries == null)
|
|
oCurrStatus.LeaveAvailed = 0;
|
|
else
|
|
{
|
|
var itemsInCart = from o in oLeaveEntries
|
|
where o.EmpID == oEmployee.ID.Integer &&
|
|
o.LeaveID.Integer == oItem.LeaveId &&
|
|
o.LeaveYear == oCurrYear.ID.Integer &&
|
|
(o.LeaveStatus == enumLeaveStatus || o.LeaveStatus == EnumLeaveStatus.Cancel_Request)
|
|
select new { o.ApprovedTotalDays };
|
|
var sum = itemsInCart.ToList().Select(c => c.ApprovedTotalDays).Sum();
|
|
oCurrStatus.LeaveAvailed = Convert.ToDouble(sum);
|
|
}
|
|
#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
|
|
{
|
|
oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed), 1);
|
|
oCurrStatus.YearEndBalance = Math.Round(oCurrStatus.YearEndBalance, 1);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion Calculate Year-End Balance
|
|
|
|
if (oItem.Leave.IsBalanceCalculationNeeded)
|
|
oCurrYearBalance.Add(oCurrStatus);
|
|
}
|
|
return oCurrYearBalance;
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
MessageBox.Show(oEmployee.EmployeeNo);
|
|
throw new Exception(exp.Message);
|
|
}
|
|
return new ObjectsTemplate<EmpLeaveStatus>();
|
|
}
|
|
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatusForPreocess(ObjectsTemplate<Employee> oEmployees, LeaveYear lYear, EnumLeaveStatus eStatus, ProgressBar pgBar)
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = null;
|
|
ObjectsTemplate<EmpLeaveStatus> oAllEmpsCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
DateTime operationDate = GlobalFunctions.GetOperationDate();
|
|
LeaveYear oCurrYear = lYear;
|
|
LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
|
|
List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<SetupDetail> setupDetails = SetupDetail.GetParameters(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<LeaveParameter> leaveParamss = LeaveParameter.Get();
|
|
ObjectsTemplate<LeaveParameterDetail> leaveParamDetails = new LeaveParameter().GetAllDetails();
|
|
List<LeaveEntry> oLs = LeaveEntry.GetByLeaveYear(oCurrYear.ID.Integer);
|
|
List<EmpLeaveStatus> oPrevStatuses = EmpLeaveStatus.GetAllPrvYearStatus(oCurrYear.ID.Integer);
|
|
ObjectsTemplate<LeaveYear> olYears = LeaveYear.Service.Get();
|
|
LeaveYear ly=EmpLeaveStatus.GetPrvYear(oCurrYear,olYears);
|
|
List<EmpLeaveStatus> oPrevStatus = EmpLeaveStatus.GetByYear(ly == null ? 0 : ly.ID.Integer);
|
|
foreach (Employee oEmp in oEmployees)
|
|
{
|
|
pgBar.Value += 1;
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParamsForReport(oEmp, setupTypes, setupDetails, leaveParamss);
|
|
oCurrYearBalance = EmpLeaveStatus.CurrentYearStatusForProcess(oEmp, operationDate, oAppLeaveParams, oCurrYear, oLs, eStatus, oPrevStatuses, leaveParamDetails, olYears, oPrevStatus);
|
|
foreach (EmpLeaveStatus eSts in oCurrYearBalance)
|
|
oAllEmpsCurrYearBalance.Add(eSts);
|
|
}
|
|
|
|
return oAllEmpsCurrYearBalance;
|
|
}
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatusForPreocess(ObjectsTemplate<Employee> oEmployees, LeaveYear lYear, EnumLeaveStatus eStatus)
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = null;
|
|
ObjectsTemplate<EmpLeaveStatus> oAllEmpsCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
DateTime operationDate = GlobalFunctions.GetOperationDate();
|
|
LeaveYear oCurrYear = lYear;
|
|
LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
|
|
List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<SetupDetail> setupDetails = SetupDetail.GetParameters(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<LeaveParameter> leaveParamss = LeaveParameter.Get();
|
|
ObjectsTemplate<LeaveParameterDetail> leaveParamDetails = new LeaveParameter().GetAllDetails();
|
|
List<LeaveEntry> oLs = LeaveEntry.GetByLeaveYear(oCurrYear.ID.Integer);
|
|
List<EmpLeaveStatus> oPrevStatuses = EmpLeaveStatus.GetAllPrvYearStatus(oCurrYear.ID.Integer);
|
|
ObjectsTemplate<LeaveYear> olYears = LeaveYear.Service.Get();
|
|
LeaveYear ly = EmpLeaveStatus.GetPrvYear(oCurrYear, olYears);
|
|
List<EmpLeaveStatus> oPrevStatus = EmpLeaveStatus.GetByYear(ly == null ? 0 : ly.ID.Integer);
|
|
foreach (Employee oEmp in oEmployees)
|
|
{
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParamsForReport(oEmp, setupTypes, setupDetails, leaveParamss);
|
|
oCurrYearBalance = EmpLeaveStatus.CurrentYearStatusForProcess(oEmp, operationDate, oAppLeaveParams, oCurrYear, oLs, eStatus, oPrevStatuses, leaveParamDetails, olYears, oPrevStatus);
|
|
foreach (EmpLeaveStatus eSts in oCurrYearBalance)
|
|
oAllEmpsCurrYearBalance.Add(eSts);
|
|
}
|
|
|
|
return oAllEmpsCurrYearBalance;
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatus(int employeeID, LeaveYear lYear)
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = null;
|
|
|
|
DateTime operationDate = GlobalFunctions.GetOperationDate();
|
|
Employee oEmployee = Employee.Get(ID.FromInteger(employeeID));
|
|
LeaveYear oCurrYear = lYear;
|
|
LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
|
|
//ObjectsTemplate<EmpLeaveStatus> prvYearStatus =EmpLeaveStatus.GetAllStatus(employeeID);
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParams(oEmployee);
|
|
|
|
oCurrYearBalance = EmpLeaveStatus.CurrentYearStatus(oEmployee, operationDate, oAppLeaveParams, oCurrYear);
|
|
return oCurrYearBalance;
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatus(Employee oEmployee, DateTime operationDate,
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams, LeaveYear oCurrYear)
|
|
{
|
|
DateTime dCurrentDate = operationDate;
|
|
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
LeaveParameterDetail oDetail = null;
|
|
|
|
ConfigurationManager oCon = new ConfigurationManager();
|
|
// string Params = ConfigurationManager.GetStringValue("leave", "balance", EnumConfigurationType.Logic);
|
|
foreach (LeaveParameter oItem in oAppLeaveParams)
|
|
{
|
|
EmpLeaveStatus oPrevStatus = new EmpLeaveStatus(); ;
|
|
EmpLeaveStatus oCurrStatus = new EmpLeaveStatus();
|
|
oCurrStatus.EmpId = oEmployee.ID.Integer;
|
|
oCurrStatus.LeaveId = oItem.LeaveId;
|
|
oCurrStatus.LeaveYearID = oCurrYear.ID.Integer;
|
|
|
|
//oDetail = oItem.GetApplicableForEmployee(oEmployee, operationDate); //8
|
|
if (oDetail != null) oCurrStatus.NormalLeaveDays = oDetail.MaxDays;
|
|
else continue;
|
|
oItem.Details = new ObjectsTemplate<LeaveParameterDetail>();
|
|
oItem.Details.Add(oDetail);
|
|
//oPrevStatus = EmpLeaveStatus.GetPrvYearStatus(oCurrYear.ID.Integer, oItem.LeaveId, oEmployee.ID.Integer);
|
|
|
|
#region calculate the opening balance
|
|
|
|
//if (oItem.Leave.IsEarnedLeave)
|
|
//{
|
|
// if (oEmployee.JoiningDate.Year == oCurrYear.StartDate.Year) // Service length Current Year
|
|
// oCurrStatus.OpeningBalance = 0;
|
|
// else if (Math.Abs((oEmployee.JoiningDate.Year - oCurrYear.StartDate.Year)) == 1) // Service length 2nd Year
|
|
// {
|
|
// if (oPrevStatus == null)
|
|
// {
|
|
// if (oEmployee.IsConfirmed == true)
|
|
// {
|
|
// TimeSpan tdate = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(oEmployee.JoiningDate)
|
|
// - oEmployee.JoiningDate;
|
|
|
|
// double ntemp = oDetail.MaxDays / 12;
|
|
// double nDays = tdate.Days;
|
|
// oCurrStatus.OpeningBalance = Math.Round((ntemp * (nDays / (double)30.00)));
|
|
// }
|
|
// else oCurrStatus.OpeningBalance = 0;
|
|
// }
|
|
// else oCurrStatus.OpeningBalance = oPrevStatus.CFDays;
|
|
// }
|
|
// else
|
|
// {
|
|
// if (oPrevStatus != null) oCurrStatus.OpeningBalance = oPrevStatus.CFDays; // Service Length 3rd Year
|
|
// }
|
|
|
|
//}
|
|
//else
|
|
//{
|
|
// if (oEmployee.JoiningDate.Year == oCurrYear.StartDate.Year) // Service length Current Year
|
|
// {
|
|
|
|
// TimeSpan tdate = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(oEmployee.JoiningDate)
|
|
// - oEmployee.JoiningDate;
|
|
// double nDays = tdate.Days;
|
|
// oCurrStatus.OpeningBalance = Math.Round(((double)oDetail.MaxDays / (double)12.00) *
|
|
// (double)((nDays / (double)30.00)));
|
|
|
|
// }
|
|
// else
|
|
// oCurrStatus.OpeningBalance = oDetail.MaxDays;
|
|
// if (oPrevStatus != null) oCurrStatus.OpeningBalance = oPrevStatus.CFDays + oCurrStatus.OpeningBalance;
|
|
//}
|
|
if (oPrevStatus != null)
|
|
{
|
|
oCurrStatus.OpeningBalance = oPrevStatus.CFDays;
|
|
oCurrStatus.CFDays = oPrevStatus.CFDays;
|
|
}
|
|
|
|
if (oItem.IsForfited)
|
|
{
|
|
if (oCurrYear.StartDate.AddMonths(oItem.ForfitedMonth).Month >= dCurrentDate.Date.Month)
|
|
{
|
|
double nLeaveAvailed = 0;
|
|
oCurrStatus.ForfitedDays = oPrevStatus.YearEndBalance - nLeaveAvailed;
|
|
oCurrStatus.ForfitedDays = (oCurrStatus.ForfitedDays < 0) ? 0 : oCurrStatus.ForfitedDays;
|
|
}
|
|
}
|
|
double nNormalLeavedays = 0;
|
|
if (oEmployee.JoiningDate.Date.Year == oCurrYear.StartDate.Date.Year)
|
|
{
|
|
TimeSpan ts = (oCurrYear.EndDate - oEmployee.JoiningDate);
|
|
double ntemp = oCurrStatus.NormalLeaveDays / 12;
|
|
double nDays = ts.Days;
|
|
nNormalLeavedays = Math.Round((ntemp * (nDays / (double)30.00)));
|
|
}
|
|
else
|
|
{
|
|
nNormalLeavedays = oCurrStatus.NormalLeaveDays;
|
|
}
|
|
oCurrStatus.NormalLeaveDays = nNormalLeavedays;
|
|
if (oItem.IsMonthlyBalance)
|
|
oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance + Math.Round(oCurrStatus.NormalLeaveDays / 12 * (dCurrentDate.Date.Month));
|
|
else
|
|
oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance + oCurrStatus.NormalLeaveDays;
|
|
|
|
//if (oItem.Leave.IsEarnedLeave)
|
|
// oCurrStatus.OpeningBalance = oCurrStatus.OpeningBalance > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance;
|
|
//else
|
|
// oCurrStatus.OpeningBalance = (oCurrStatus.OpeningBalance + oCurrStatus.NormalLeaveDays) > oItem.MaxAccumulatedDays ? oItem.MaxAccumulatedDays : oCurrStatus.OpeningBalance + oCurrStatus.NormalLeaveDays;
|
|
|
|
#endregion calculate the opening balance
|
|
|
|
#region calculate leave availed in current year
|
|
oCurrStatus.LeaveAvailed = LeaveEntry.GetLeaveAmtByType(oEmployee.ID.Integer, oItem.ID.Integer, oCurrYear.ID.Integer, EnumLeaveStatus.Approved); //10
|
|
#endregion calculate leave availed in current year
|
|
|
|
#region Calculate Year-End Balance
|
|
oCurrStatus.YearEndBalance = 0;
|
|
if (oItem.Leave.IsBalanceCalculationNeeded == false)
|
|
{
|
|
oCurrStatus.NormalLeaveDays = 0;
|
|
oCurrStatus.OpeningBalance = 0;
|
|
}
|
|
else oCurrStatus.YearEndBalance = oCurrStatus.OpeningBalance - (oCurrStatus.ForfitedDays + oCurrStatus.LeaveAvailed);
|
|
#endregion Calculate Year-End Balance
|
|
|
|
oCurrYearBalance.Add(oCurrStatus);
|
|
}
|
|
return oCurrYearBalance;
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> CurrentYearStatus(ObjectsTemplate<Employee> oEmployees, LeaveYear lYear, EnumLeaveStatus eStatus)
|
|
{
|
|
try
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = null;
|
|
ObjectsTemplate<EmpLeaveStatus> oAllEmpsCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
DateTime operationDate = GlobalFunctions.GetOperationDate();
|
|
LeaveYear oCurrYear = lYear;
|
|
LeaveYear oPrvYear = LeaveYear.LastLeaveYear(oCurrYear);
|
|
List<EnmSetupManagerTranType> setupTypes = SetupDetail.GetTypes(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<SetupDetail> setupDetails = SetupDetail.GetParameters(EnumParameterSetup.Leave);
|
|
ObjectsTemplate<LeaveParameter> leaveParamss = LeaveParameter.Get();
|
|
ObjectsTemplate<LeaveParameterDetail> leaveParamDetails = new LeaveParameter().GetAllDetails();
|
|
List<LeaveEntry> oLs = LeaveEntry.GetByLeaveYear(oCurrYear.ID.Integer);
|
|
List<EmpLeaveStatus> oPrevStatuses = EmpLeaveStatus.GetAllPrvYearStatus(oCurrYear.ID.Integer);
|
|
ObjectsTemplate<LeaveException> oExceptions = LeaveException.Get(lYear.StartDate, lYear.EndDate);
|
|
int nCount = 1;
|
|
foreach (Employee oEmp in oEmployees)
|
|
{
|
|
ObjectsTemplate<LeaveParameter> oAppLeaveParams = LeaveParameter.ApplicableParamsForReport(oEmp, setupTypes, setupDetails, leaveParamss);
|
|
oCurrYearBalance = EmpLeaveStatus.CurrentYearStatus(oEmp, operationDate, oAppLeaveParams, oCurrYear, oLs, eStatus, oPrevStatuses, leaveParamDetails, oExceptions);
|
|
foreach (EmpLeaveStatus eSts in oCurrYearBalance)
|
|
oAllEmpsCurrYearBalance.Add(eSts);
|
|
}
|
|
|
|
return oAllEmpsCurrYearBalance;
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
}
|
|
return new ObjectsTemplate<EmpLeaveStatus>();
|
|
}
|
|
|
|
public static ObjectsTemplate<EmpLeaveStatus> EmpCurrentYearStatus(Employee oEmp)
|
|
{
|
|
LeaveYear oCurrYear = LeaveYear.GetCurrentYear();
|
|
DateTime dCurrentDate = SystemInformation.GetServerDate();
|
|
ObjectsTemplate<EmpLeaveStatus> oCurrYearBalance = new ObjectsTemplate<EmpLeaveStatus>();
|
|
if (oCurrYear == null) return null;
|
|
List<Leave> oLeaves = Leave.Get(EnumStatus.Active);
|
|
EmpLeaveStatus oCurrStatus;
|
|
foreach (Leave oLeave in oLeaves)
|
|
{
|
|
oCurrStatus = new EmpLeaveStatus();
|
|
|
|
oCurrStatus.EmpId = oEmp.ID.Integer;
|
|
oCurrStatus.LeaveId = oLeave.ID.Integer;
|
|
oCurrStatus.LeaveAvailed = LeaveEntry.GetAvailedLeave(oEmp.ID.Integer, oLeave.ID.Integer, oCurrYear.ID.Integer, EnumLeaveStatus.Approved);
|
|
|
|
oCurrYearBalance.Add(oCurrStatus);
|
|
}
|
|
return oCurrYearBalance;
|
|
}
|
|
|
|
public static EmpLeaveStatus GetleaveStatus(ObjectsTemplate<EmpLeaveStatus> leaveBalances, int nLeaveId)
|
|
{
|
|
foreach (EmpLeaveStatus oItem in leaveBalances)
|
|
{
|
|
if (oItem.LeaveId == nLeaveId)
|
|
return oItem;
|
|
}
|
|
return null;
|
|
}
|
|
public static LeaveYear GetPrvYear(LeaveYear oCurrYear, ObjectsTemplate<LeaveYear> olYears)
|
|
{
|
|
//LeaveYear oCurrYear = LeaveYear.Service.Get(ID.FromInteger(leaveYearID));
|
|
LeaveYear oPrvYear = null;
|
|
//ObjectsTemplate<LeaveYear> olYears = LeaveYear.Service.Get();
|
|
foreach (LeaveYear oItem in olYears)
|
|
{
|
|
if (oItem.EndDate.AddDays(1) == oCurrYear.StartDate)
|
|
{
|
|
oPrvYear = oItem;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return oPrvYear;
|
|
}
|
|
public static EmpLeaveStatus GetPrvYearStatus(int leaveYearID, int nLeaveId, int nEmpId, LeaveYear oCurrYear, ObjectsTemplate<LeaveYear> olYears)
|
|
{
|
|
//LeaveYear oCurrYear = LeaveYear.Service.Get(ID.FromInteger(leaveYearID));
|
|
LeaveYear oPrvYear = null;
|
|
//ObjectsTemplate<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 ObjectsTemplate<EmpLeaveStatus> GetByYear(int leaveYearID)
|
|
{
|
|
ObjectsTemplate<EmpLeaveStatus> oEmpLeaveStatuss = null;
|
|
|
|
oEmpLeaveStatuss = LeaveProcess.Service.GetByYear(leaveYearID);
|
|
|
|
return oEmpLeaveStatuss;
|
|
}
|
|
|
|
#region Functions
|
|
|
|
public void SaveStatus(EmpLeaveStatus oEmpLeaveStatus)
|
|
{
|
|
LeaveProcess.Service.SaveStatus(oEmpLeaveStatus);
|
|
}
|
|
|
|
public static void Save(EmpLeaveStatus oEmpLeaveStatus)
|
|
{
|
|
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 ObjectsTemplate<EmpLeaveStatus> GetProcessDetails(int nProcessId)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<EmpLeaveStatus> oEmpLeaveStatuss = _cache["Get"] as ObjectsTemplate<EmpLeaveStatus>;
|
|
if (oEmpLeaveStatuss != null)
|
|
return oEmpLeaveStatuss;
|
|
#endregion
|
|
|
|
return oEmpLeaveStatuss;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
#region ILeaveProcess Service
|
|
public interface ILeaveProcessService
|
|
{
|
|
#region Leave Process
|
|
LeaveProcess Get(ID LeaveProcessId);
|
|
LeaveProcess Get(int LeaveYear);
|
|
LeaveProcess Get(int nLeaveProcessYear, int nPayrollTypeid);
|
|
ObjectsTemplate<LeaveProcess> Get();
|
|
LeaveProcess GetLastProcess();
|
|
ID Save(LeaveProcess oLeaveProcess);
|
|
void UpadteLeaveYearStatus(LeaveProcess oLeaveProcess);
|
|
void Delete(int nProcessYear);
|
|
void Delete(int LeaveYearID, int PayrollTypeID);
|
|
bool IsProcessed(int nProcessYear);
|
|
void DoYearEnd(LeaveProcess oLeaveProcess);
|
|
#endregion
|
|
|
|
#region Leave Process Detail
|
|
EmpLeaveStatus GetProcessDetail(ID id);
|
|
EmpLeaveStatus GetStatus(int empid, int leaveID, int leaveYearID);
|
|
EmpLeaveStatus GetByYear(int ProcessYear, int LeaveId, int EmpId);
|
|
ObjectsTemplate<EmpLeaveStatus> GetByYear(int leaveYearID);
|
|
ObjectsTemplate<EmpLeaveStatus> GetProcessDetails(int ProcessId);
|
|
ID Save(EmpLeaveStatus oEmpLeaveStatus);
|
|
void SaveStatus(EmpLeaveStatus oEmpLeaveStatus);
|
|
void DeleteProcessDetail(ID id);
|
|
void DeleteProcessDetailByID(int nProcessId);
|
|
void DeleteByPayrollType(int nProcessId, int nPayrollTypeId, int nLeaveID);
|
|
ObjectsTemplate<EmpLeaveStatus> GetByYearType(int leaveYearID, int leaveId);
|
|
void SaveStatus(List<EmpLeaveStatus> oEmpLeaveStatus);
|
|
void UpdateEncashAmount(ObjectsTemplate<EmpLeaveStatus> _oEmpLeaveStatus);
|
|
#endregion
|
|
|
|
}
|
|
#endregion
|
|
} |