383 lines
15 KiB
C#
383 lines
15 KiB
C#
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using HRM.BO;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
public class EmployeeConfirmationService : ServiceTemplate
|
|||
|
{
|
|||
|
#region Map Functions
|
|||
|
|
|||
|
private void MapObject(EmployeeConfirmation oEmployeeConfirmation, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oEmployeeConfirmation, oReader.GetInt32("EmpConfirmID").Value);
|
|||
|
oEmployeeConfirmation.EmployeeID = oReader.GetInt32("EmployeeID", 0);
|
|||
|
oEmployeeConfirmation.Month = oReader.GetInt32("Month").Value;
|
|||
|
oEmployeeConfirmation.ConfirmDate = oReader.GetDateTime("ConfirmDate").GetValueOrDefault();
|
|||
|
oEmployeeConfirmation.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|||
|
oEmployeeConfirmation.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oEmployeeConfirmation.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|||
|
oEmployeeConfirmation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
this.SetObjectState(oEmployeeConfirmation, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader dr)
|
|||
|
{
|
|||
|
EmployeeConfirmation oEmployeeConfirmation = new EmployeeConfirmation();
|
|||
|
MapObject(oEmployeeConfirmation, dr);
|
|||
|
return oEmployeeConfirmation as T;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region IEmployeeConfirmationService Members
|
|||
|
|
|||
|
public EmployeeConfirmation Get(int nID)
|
|||
|
{
|
|||
|
EmployeeConfirmation oEmployeeConfirmation = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(EmployeeConfirmationDA.Get(tc, nID));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oEmployeeConfirmation = this.CreateObject<EmployeeConfirmation>(oreader);
|
|||
|
}
|
|||
|
|
|||
|
oreader.Close();
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oEmployeeConfirmation;
|
|||
|
}
|
|||
|
|
|||
|
public EmployeeConfirmation GetByEmployeeID(int ID)
|
|||
|
{
|
|||
|
EmployeeConfirmation oEmployeeConfirmation = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(EmployeeConfirmationDA.GetByEmployeeID(tc, ID));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oEmployeeConfirmation = this.CreateObject<EmployeeConfirmation>(oreader);
|
|||
|
}
|
|||
|
|
|||
|
if (oEmployeeConfirmation != null)
|
|||
|
oEmployeeConfirmation =
|
|||
|
(new EmployeeService()).GetAllEmps(tc).Where(obj =>
|
|||
|
obj.ID == oEmployeeConfirmation.EmployeeID && obj.IsConfirmed).Any()
|
|||
|
? null
|
|||
|
: oEmployeeConfirmation;
|
|||
|
|
|||
|
oreader.Close();
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oEmployeeConfirmation;
|
|||
|
}
|
|||
|
|
|||
|
public List<EmployeeConfirmation> Get()
|
|||
|
{
|
|||
|
List<EmployeeConfirmation> employeeConfirmations = new List<EmployeeConfirmation>();
|
|||
|
List<EmployeeConfirmation> finalList = new List<EmployeeConfirmation>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(EmployeeConfirmationDA.Get(tc));
|
|||
|
employeeConfirmations = this.CreateObjects<EmployeeConfirmation>(dr);
|
|||
|
|
|||
|
List<Employee> oEmployees = (new EmployeeService()).GetAllEmps(tc);
|
|||
|
if (employeeConfirmations != null)
|
|||
|
{
|
|||
|
foreach (EmployeeConfirmation item in employeeConfirmations)
|
|||
|
{
|
|||
|
if (!oEmployees.Where(obj => obj.ID == item.EmployeeID && obj.IsConfirmed).Any())
|
|||
|
finalList.Add(item);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
dr.Close();
|
|||
|
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return finalList;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public DataTable GetUpComingConfirmation(DateTime upcomingMonth)
|
|||
|
{
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
DataTable otab;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
otab = EmployeeConfirmationDA.GetUpComingConfirmation(tc, upcomingMonth);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return otab;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public List<EmployeeConfirmation> GetByDateRange(DateTime dtFromDate, DateTime dtToDate, int payrollType)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
List<EmployeeConfirmation> employeeConfirmations = new List<EmployeeConfirmation>();
|
|||
|
DataTable dataTable = EmployeeConfirmationDA.GetByDateRange(tc, dtFromDate, dtToDate, payrollType);
|
|||
|
|
|||
|
foreach (DataRow item in dataTable.Rows)
|
|||
|
{
|
|||
|
EmployeeConfirmation employeeConfirmation = new EmployeeConfirmation();
|
|||
|
employeeConfirmation.ID = Convert.ToInt32(item["EmpConfirmID"].ToString());
|
|||
|
employeeConfirmation.EmployeeID = Convert.ToInt32(item["EmployeeID"].ToString());
|
|||
|
employeeConfirmation.Month = Convert.ToInt32(item["Month"].ToString());
|
|||
|
employeeConfirmation.ConfirmDate = Convert.ToDateTime(item["ConfirmDate"].ToString());
|
|||
|
employeeConfirmation.EmployeeName = item["EmpName"].ToString();
|
|||
|
employeeConfirmation.EmployeeNo = item["EMPLOYEENO"].ToString();
|
|||
|
employeeConfirmation.JoiningDate = Convert.ToDateTime(item["JOININGDATE"].ToString());
|
|||
|
employeeConfirmations.Add(employeeConfirmation);
|
|||
|
}
|
|||
|
return employeeConfirmations;
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
{
|
|||
|
tc.HandleError();
|
|||
|
tc = null;
|
|||
|
}
|
|||
|
ExceptionLog.Write(e);
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
if (tc != null)
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public int Save(EmployeeConfirmation employeeConfirmation)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
EmployeeService empservice = new EmployeeService();
|
|||
|
if (employeeConfirmation.IsNew)
|
|||
|
{
|
|||
|
EmployeeConfirmationDA.DeleteByEmployeeID(tc, employeeConfirmation.EmployeeID);
|
|||
|
|
|||
|
int id = tc.GenerateID("EmpConfirmation", "EmpConfirmID");
|
|||
|
base.SetObjectID(employeeConfirmation, id);
|
|||
|
EmployeeConfirmationDA.Insert(tc, employeeConfirmation);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
EmployeeConfirmationDA.Update(tc, employeeConfirmation);
|
|||
|
}
|
|||
|
|
|||
|
tc.End();
|
|||
|
return employeeConfirmation.ID;
|
|||
|
}
|
|||
|
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Delete(int id)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
EmployeeConfirmationDA.Delete(tc, id);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public List<EmployeeConfirmation> GetByDateRange(DateTime dStart, DateTime dEnd, int userID, int PayrollTypeID)
|
|||
|
{
|
|||
|
List<EmployeeConfirmation> employeeConfirmations = new List<EmployeeConfirmation>();
|
|||
|
try
|
|||
|
{
|
|||
|
List<Employee> oEmployees = (new EmployeeService()).GetAllEmps();
|
|||
|
List<EmployeeConfirmation> tempEmpConfirmation = (new EmployeeConfirmationService()).Get()
|
|||
|
.Where(item => item.ConfirmDate >= dStart && item.ConfirmDate <= dEnd).ToList();
|
|||
|
if (tempEmpConfirmation != null)
|
|||
|
{
|
|||
|
if (PayrollTypeID != 0)
|
|||
|
{
|
|||
|
foreach (EmployeeConfirmation item in tempEmpConfirmation)
|
|||
|
{
|
|||
|
if (oEmployees.Where(obj => obj.ID == item.EmployeeID && !obj.IsConfirmed).Any())
|
|||
|
employeeConfirmations.Add(item);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
foreach (EmployeeConfirmation item in tempEmpConfirmation)
|
|||
|
{
|
|||
|
if (oEmployees.Where(obj =>
|
|||
|
obj.ID == item.EmployeeID && !obj.IsConfirmed && obj.PayrollTypeID == PayrollTypeID)
|
|||
|
.Any())
|
|||
|
employeeConfirmations.Add(item);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (ServiceException e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
|
|||
|
return employeeConfirmations;
|
|||
|
}
|
|||
|
|
|||
|
public bool IsWaitingForConfirmation(DateTime NextPayProcessDate, int UserID, int PayrollTypeid)
|
|||
|
{
|
|||
|
List<Employee> oAllEmployees = (new EmployeeService()).GetAllEmps();
|
|||
|
List<EmployeeConfirmation> oEmpConfirms = GetByDateRange(
|
|||
|
PayrollGlobalFunctions.PayrollFirstDateOfMonth(NextPayProcessDate),
|
|||
|
PayrollGlobalFunctions.PayrollLastDateOfMonth(NextPayProcessDate), UserID, PayrollTypeid);
|
|||
|
|
|||
|
if (oEmpConfirms != null)
|
|||
|
return true;
|
|||
|
|
|||
|
//**** 6 Month Auto Confirm Logic***************
|
|||
|
//List<Employee> oUnConfirmedEmployee = oAllEmployees.Where(obj => obj.Status == EnumEmployeeStatus.Live &&
|
|||
|
// obj.PayrollTypeID == Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID &&
|
|||
|
// obj.IsConfirmed == false &&
|
|||
|
// obj.JoiningDate.AddMonths(6) >= PayrollGlobalFunctions.PayrollFirstDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate) &&
|
|||
|
// obj.JoiningDate.AddMonths(6) <= PayrollGlobalFunctions.PayrollLastDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate) &&
|
|||
|
// EmployeeConfirmation.GetByEmployeeID(obj.ID)==null).ToList();
|
|||
|
//if (oUnConfirmedEmployee != null)
|
|||
|
// return true;
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public List<Employee> GetEmployeesWaitingForConfirmation(int payrolltypeid, DateTime NextPayProcessMonth,
|
|||
|
int UserID, int PayrollTypeID)
|
|||
|
{
|
|||
|
List<Employee> oUnConfirmedEmployees = new List<Employee>();
|
|||
|
List<Employee> oAllEmployees = (new EmployeeService()).GetAllEmps();
|
|||
|
List<EmployeeConfirmation> oEmpConfirms = GetByDateRange(
|
|||
|
PayrollGlobalFunctions.PayrollFirstDateOfMonth(NextPayProcessMonth),
|
|||
|
PayrollGlobalFunctions.PayrollLastDateOfMonth(NextPayProcessMonth), UserID, payrolltypeid);
|
|||
|
if (oEmpConfirms == null) return oUnConfirmedEmployees;
|
|||
|
foreach (EmployeeConfirmation item in oEmpConfirms)
|
|||
|
{
|
|||
|
Employee empTemp = oAllEmployees.Where(obj => obj.ID == item.EmployeeID && obj.IsConfirmed == false)
|
|||
|
.SingleOrDefault();
|
|||
|
if (empTemp != null) oUnConfirmedEmployees.Add(empTemp);
|
|||
|
}
|
|||
|
|
|||
|
//**** 6 Month Auto Confirm Logic***************
|
|||
|
//List<Employee> oUnConfirmedEmployee = oAllEmployees.Where(obj => obj.Status == EnumEmployeeStatus.Live &&
|
|||
|
// obj.PayrollTypeID == Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID &&
|
|||
|
// obj.IsConfirmed == false &&
|
|||
|
// obj.JoiningDate.AddMonths(6) >= PayrollGlobalFunctions.PayrollFirstDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate) &&
|
|||
|
// obj.JoiningDate.AddMonths(6) <= PayrollGlobalFunctions.PayrollLastDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate) &&
|
|||
|
// EmployeeConfirmation.GetByEmployeeID(obj.ID)==null).ToList();
|
|||
|
//if (oUnConfirmedEmployee != null)
|
|||
|
// return true;
|
|||
|
|
|||
|
return oUnConfirmedEmployees;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|