CEL_Payroll/Payroll.Service/Leave/Service/LeaveEntryService.cs

1264 lines
46 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region Leave Entry Service
[Serializable]
class LeaveEntryService : ServiceTemplate, ILeaveEntryService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(LeaveEntry));
public LeaveEntryService() { }
private void MapObject(LeaveEntry oLeaveEntry, DataReader dr)
{
//this.SetObjectID(oLeaveEntry, ID.FromInteger(dr.GetInt32("TranId")));
base.SetObjectID(oLeaveEntry, dr.GetID("TranId"));
oLeaveEntry.EmpID = dr.GetInt32("EmpId").Value;
oLeaveEntry.EmpGradeId = dr.GetInt32("EmpGradeId").Value;
oLeaveEntry.LeaveYear = dr.GetInt32("LeaveYear").Value;
oLeaveEntry.AppliedParamId = dr.GetInt32("AppParamId").Value;
oLeaveEntry.AppliedLeaveDate = dr.GetDateTime("AppLeaveDate").Value;
oLeaveEntry.AppliedFromDate = dr.GetDateTime("AppFromDate").Value;
oLeaveEntry.AppliedToDate = dr.GetDateTime("AppToDate").Value;
oLeaveEntry.AppliedTotalDays = dr.GetDouble("AppTotalDays").Value;
oLeaveEntry.ApprovedParamId = dr.GetInt32("AprParamId").Value;
oLeaveEntry.ApprovedLeaveDate = dr.GetDateTime("AprLeaveDate").Value;
oLeaveEntry.ApprovedFromDate = dr.GetDateTime("AprFromDate").Value;
oLeaveEntry.ApprovedToDate = dr.GetDateTime("AprToDate").Value;
oLeaveEntry.ApprovedTotalDays = dr.GetDouble("AprTotalDays").Value;
oLeaveEntry.ApprovedBy = dr.GetID("ApprovedBy");
oLeaveEntry.Remarks = dr.GetString("Remarks");
//oLeaveEntry.UserId = dr.GetInt32("UserId");
oLeaveEntry.IsDrafted = dr.GetInt32("IsDrafted").Value;
oLeaveEntry.IsAvailed = dr.GetInt32("IsAvailed").Value;
oLeaveEntry.EntryDate = dr.GetDateTime("EntryDate").Value;
// oLeaveEntry.LeaveName= dr.GetString("Description");
oLeaveEntry.LeaveStatus = (EnumLeaveStatus)dr.GetInt32("LeaveStatus").Value;
oLeaveEntry.LeaveDayPeriod = dr.GetString("DayPeriod");
//transectional properties
oLeaveEntry.ErnLeaveRemarks = dr.GetString("ErnLeaveRemarks");
oLeaveEntry.LeaveID = dr.GetID("LeaveID");
oLeaveEntry.SbuID = dr.GetID("SbuID");
oLeaveEntry.DepartmentID = dr.GetID("DepartmentID");
oLeaveEntry.FunctionID = dr.GetID("FunctionID");
oLeaveEntry.LocationID = dr.GetID("LocationID");
oLeaveEntry.DesignationID = dr.GetID("DesignationID");
oLeaveEntry.WorkingDate = dr.GetDateTime("WorkingDate")==null? dr.GetDateTime("WorkingDate"): dr.GetDateTime("WorkingDate").Value;
// avail properties
//oLeaveEntry.AvailFromDate = dr.GetDateTime("AvailFromDate").Value ;
//oLeaveEntry.AvailToDate = dr.GetDateTime("AvailToDate").Value ;
//oLeaveEntry.AvailRemarks = dr.GetString("AvailRemarks");
oLeaveEntry.AvailedBy = dr.GetID("AvailedBy");
//oLeaveEntry.AvailTotalDays = dr.GetDouble("AvailTotalDays").Value ;
this.SetObjectState(oLeaveEntry, Ease.CoreV35.ObjectState.Saved);
//this.SetObjectState(oLeaveEntry, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
LeaveEntry oLeaveEntry = new LeaveEntry();
MapObject(oLeaveEntry, dr);
return oLeaveEntry as T;
}
LeaveEntry CreateObject(DataReader dr)
{
LeaveEntry oLeaveEntry = new LeaveEntry();
MapObject(oLeaveEntry, dr);
return oLeaveEntry;
}
#endregion
#region Service Implementation
public LeaveEntry Get(ID id)
{
LeaveEntry oLeaveEntry = new LeaveEntry();
#region Cache Header
oLeaveEntry = (LeaveEntry)_cache["Get", id.Integer];
if (oLeaveEntry != null)
{
return oLeaveEntry;
}
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, id.Integer));
if (dr.Read())
{
oLeaveEntry = this.CreateObject<LeaveEntry>(dr);
}
dr.Close();
tc.End();
}
catch (Exception ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException("Failed to Get Leave Information" + ex.Message, ex);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntry, "Get", id.Integer);
#endregion
return oLeaveEntry;
}
/* Uswed for WFTraversPath */
public LeaveEntry Get(TransactionContext tc, ID id)
{
LeaveEntry oLeaveEntry = new LeaveEntry();
#region Cache Header
oLeaveEntry = (LeaveEntry)_cache["Get", id.Integer];
if (oLeaveEntry != null)
{
return oLeaveEntry;
}
#endregion
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, id.Integer));
if (dr.Read())
{
oLeaveEntry = this.CreateObject<LeaveEntry>(dr);
}
dr.Close();
tc.End();
}
catch (Exception ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException("Failed to Get Leave Information" + ex.Message, ex);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntry, "Get", id.Integer);
#endregion
return oLeaveEntry;
}
public ObjectsTemplate<LeaveEntry> GetByLeaveID(int nLeaveID, int nEmpID, DateTime fromDate, DateTime toDate)
{
#region Cache Header
ObjectsTemplate<LeaveEntry> oLeaveEntrys = _cache["Get"] as ObjectsTemplate<LeaveEntry>;
if (oLeaveEntrys != null)
return oLeaveEntrys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetByLeaveID(tc, nLeaveID, nEmpID, fromDate, toDate));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntrys, "Get", nLeaveID, nEmpID, fromDate, toDate);
#endregion
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> Get(string empIds, int leaveYear, EnumLeaveStatus leaveStatus)
{
#region Cache Header
ObjectsTemplate<LeaveEntry> oLeaveEntrys = _cache["Get"] as ObjectsTemplate<LeaveEntry>;
if (oLeaveEntrys != null)
return oLeaveEntrys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, empIds, leaveYear, (int)leaveStatus));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntrys, "Get", empIds, leaveYear);
#endregion
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> Get(DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, fromDate, toDate, (int)leaveStatus));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> Get(DateTime attnDate)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, attnDate));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public bool IsExist(Employee oEmployee, DateTime fromDate, DateTime toDate)
{
TransactionContext tc = null;
bool IsExist = false;
try
{
tc = TransactionContext.Begin();
IsExist = LeaveEntryDA.IsExist(tc, oEmployee, fromDate, toDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return IsExist;
}
public ObjectsTemplate<LeaveEntry> Get(string empIds, DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, empIds, fromDate, toDate, (int)leaveStatus));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> GetPending(int empId, int leaveID, EnumLeaveStatus leaveStatus)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetPending(tc, empId, leaveID, (int)leaveStatus));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> Get(int empId, int leaveYearID)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, empId, leaveYearID));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> GetByLeaveYear(int nLeaveYear)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetByLeaveYear(tc, nLeaveYear));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> Get(string empIds, DateTime fromDate, DateTime toDate, string leaveStatuss)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, empIds, fromDate, toDate, leaveStatuss));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> Get(string empIds, DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus, string sortExpresion)
{
ObjectsTemplate<LeaveEntry> oLeaveEntrys = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.Get(tc, empIds, fromDate, toDate, (int)leaveStatus, sortExpresion));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> GetForAdminPanel(ID employeeID)
{
#region Cache Header
ObjectsTemplate<LeaveEntry> oLeaveEntrys = _cache["Get"] as ObjectsTemplate<LeaveEntry>;
if (oLeaveEntrys != null)
return oLeaveEntrys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetForAdminPanel(tc, employeeID.Integer));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntrys, "GetForAdminPanel");
#endregion
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> GetEmployeeWiseLeaveDetailReport(int empId, DateTime fromDate, DateTime toDate, int leaveType)
{
#region Cache Header
ObjectsTemplate<LeaveEntry> oLeaveEntrys = _cache["Get"] as ObjectsTemplate<LeaveEntry>;
if (oLeaveEntrys != null)
return oLeaveEntrys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetEmployeeWiseLeaveDetailReport(tc, empId, fromDate, toDate, leaveType));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntrys, "GetEmployeeWiseLeaveDetailReport");
#endregion
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> GetEmployeeWiseLeaveDetailReport(int empId, DateTime fromDate, DateTime toDate)
{
#region Cache Header
ObjectsTemplate<LeaveEntry> oLeaveEntrys = _cache["Get"] as ObjectsTemplate<LeaveEntry>;
if (oLeaveEntrys != null)
return oLeaveEntrys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetEmployeeWiseLeaveDetailReport(tc, empId, fromDate, toDate));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntrys, "GetEmployeeWiseLeaveDetailReport");
#endregion
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> GetEmployeeWiseLeaveDetailReport(string empIds, DateTime fromDate, DateTime toDate, int leaveType)
{
#region Cache Header
ObjectsTemplate<LeaveEntry> oLeaveEntrys = _cache["Get"] as ObjectsTemplate<LeaveEntry>;
if (oLeaveEntrys != null)
return oLeaveEntrys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
if (string.IsNullOrEmpty(empIds))
{
oLeaveEntrys = new ObjectsTemplate<LeaveEntry>();
}
else
{
DataReader dr = new DataReader(LeaveEntryDA.GetEmployeeWiseLeaveDetailReport(tc, empIds, fromDate, toDate, leaveType));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntrys, "GetEmployeeWiseLeaveDetailReport");
#endregion
return oLeaveEntrys;
}
public ObjectsTemplate<LeaveEntry> GetEmployeeWiseLeaveDetailReport(string empIds, DateTime fromDate, DateTime toDate)
{
#region Cache Header
ObjectsTemplate<LeaveEntry> oLeaveEntrys = _cache["Get"] as ObjectsTemplate<LeaveEntry>;
if (oLeaveEntrys != null)
return oLeaveEntrys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
if (string.IsNullOrEmpty(empIds))
{
oLeaveEntrys = new ObjectsTemplate<LeaveEntry>();
}
else
{
DataReader dr = new DataReader(LeaveEntryDA.GetEmployeeWiseLeaveDetailReport(tc, empIds, fromDate, toDate));
oLeaveEntrys = this.CreateObjects<LeaveEntry>(dr);
dr.Close();
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(oLeaveEntrys, "GetEmployeeWiseLeaveDetailReport");
#endregion
return oLeaveEntrys;
}
public int GetEmployeeLeaveBalance(int empId, int leaveYear, int leaveType)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
int amount = LeaveEntryDA.GetEmployeeLeaveBalance(tc, empId, leaveYear, leaveType);
tc.End();
return amount;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
}
public double GetLeaveAmtByType(int empId, int leaveId, int leaveYear, EnumLeaveStatus leaveStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
double amount = LeaveEntryDA.GetLeaveAmtByType(tc, empId, leaveId, leaveYear, (int)leaveStatus);
tc.End();
return amount;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
}
public double GetAvailedLeave(int empId, int leaveId, int leaveYear, EnumLeaveStatus leaveStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
double amount = LeaveEntryDA.GetAvailedLeave(tc, empId, leaveId, leaveYear, (int)leaveStatus);
tc.End();
return amount;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
}
public double GetTotalLeaveAmountInYear(int empId, int leaveYearId, int leaveID, EnumLeaveStatus leaveStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
double amount = LeaveEntryDA.GetTotalLeaveAmountInYear(tc, empId, leaveYearId, leaveID, leaveStatus);
tc.End();
return amount;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
}
public double GetAmountOnFromDate(int empId, int leaveYearId, int leaveID, EnumLeaveStatus leaveStatus, DateTime startdate, DateTime enddate)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
double amount = LeaveEntryDA.GetAmountOnFromDate(tc, empId, leaveYearId, leaveID, leaveStatus, startdate, enddate);
tc.End();
return amount;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
}
#region Old Code
/*
public double GetSubmittedAmt(int empId, int leaveParamId, int leaveYear)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
return LeaveEntryDA.GetSubmittedAmt(tc, empId, leaveParamId, leaveYear);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetLeaveEntrys", e);
#endregion
}
return 0;
}
public double GetApprovedAmt(int empId, int leaveParamId, int leaveYear)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
return LeaveEntryDA.GetApprovedAmt(tc, empId, leaveParamId, leaveYear);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetLeaveEntrys", e);
#endregion
}
return 0;
}
public double GetAvailedAmt(int empId, int leaveParamId, int leaveYear)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
return LeaveEntryDA.GetAvailedAmt(tc, empId, leaveParamId, leaveYear);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetLeaveEntrys", e);
#endregion
}
return 0;
}
*/
#endregion
public ID Save(LeaveEntry oLeaveEntry)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
oLeaveEntry.ApprovedTotalDays = oLeaveEntry.AppliedTotalDays;
if (oLeaveEntry.IsNew)
{
this.SetObjectID(oLeaveEntry, ID.FromInteger(LeaveEntryDA.GetNewID(tc)));
LeaveEntryDA.Insert(tc, oLeaveEntry);
Payroll.Service.DailyAttnProcessService oAtt = new Payroll.Service.DailyAttnProcessService();
int nDays = (int)((oLeaveEntry.ApprovedToDate.Date.Ticks - oLeaveEntry.ApprovedFromDate.Date.Ticks) / TimeSpan.TicksPerDay) + 1;
for (int i = 1; i <= nDays; i++)
{
oAtt.UpdateLeave(tc, ID.FromInteger(oLeaveEntry.EmpID), oLeaveEntry.LeaveID, oLeaveEntry.ApprovedFromDate, 1);
oLeaveEntry.ApprovedFromDate = oLeaveEntry.ApprovedFromDate.AddDays(1);
}
}
else
{
LeaveEntryDA.Update(tc, oLeaveEntry);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oLeaveEntry.ID;
}
public void SaveLeaveEntry(LeaveEntry oLeaveEntry)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLeaveEntry.IsNew)
{
this.SetObjectID(oLeaveEntry, ID.FromInteger(LeaveEntryDA.GetNewID(tc)));
///LeaveEntryDA.DeleteDummyEntry(tc, oLeaveEntry);
LeaveEntryDA.Insert(tc, oLeaveEntry);
}
//else
//{
// LeaveEntryDA.Update(tc, oLeaveEntry);
//}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
//return oLeaveEntry.ID;
}
public void SaveLeaveEntry(ObjectsTemplate<LeaveEntry> oLeaveEntry)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
//if (oLeaveEntry.IsNew)
//{
foreach (LeaveEntry le in oLeaveEntry)
{
this.SetObjectID(le, ID.FromInteger(LeaveEntryDA.GetNewID(tc)));
///LeaveEntryDA.DeleteDummyEntry(tc, oLeaveEntry);
LeaveEntryDA.Insert(tc, le);
}
//}
//else
//{
// LeaveEntryDA.Update(tc, oLeaveEntry);
//}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
//return oLeaveEntry.ID;
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LeaveEntryDA.Delete(tc, id.Integer);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeleteByLeaveYear(int nYear)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LeaveEntryDA.DeleteByLeaveYear(tc, nYear);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void UpdateStatus(TransactionContext tc, LeaveEntry oItem)
{
try
{
LeaveEntryDA.UpdateLeaveStatus(tc, oItem);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Delete Leave Information" + e.Message, e);
#endregion
}
}
public DataTable GetYearEndData(int leaveYear)
{
DataTable oDT = new DataTable();
oDT.Columns.Add("LeaveId", typeof(Int32));
oDT.Columns.Add("EmpId", typeof(Int32));
oDT.Columns.Add("TotalDays", typeof(double));
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetYearEndData(tc, leaveYear));
//DataReader dr = new DataReader(dr);
while (dr.Read())
{
DataRow oRow = oDT.NewRow();
oRow["LeaveId"] = dr.GetInt32("LeaveId");
oRow["EmpId"] = dr.GetInt32("EmpId");
oRow["TotalDays"] = dr.GetDouble("TotalDays");
oDT.Rows.Add(oRow);
}
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oDT;
}
public bool IsEntered(DateTime year)
{
bool res = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
res = LeaveEntryDA.IsEntered(tc, year);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Entry Information" + e.Message, e);
#endregion
}
return res;
}
public DataTable GetAvailedLeave(DateTime stDate, DateTime endDate, string empIds)
{
DataTable oDT = new DataTable();
oDT.Columns.Add("EmpId", typeof(Int32));
oDT.Columns.Add("LeaveId", typeof(Int32));
oDT.Columns.Add("OrgId", typeof(Int32));
oDT.Columns.Add("Organization", typeof(System.String));
oDT.Columns.Add("MonthCode", typeof(Int32));
oDT.Columns.Add("TotalDays", typeof(double));
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetAvailedLeave(tc, stDate, endDate, empIds));
while (dr.Read())
{
DataRow oRow = oDT.NewRow();
oRow["LeaveId"] = dr.GetInt32("LeaveId");
oRow["EmpId"] = dr.GetInt32("EmpId");
oRow["OrgId"] = dr.GetInt32("OrgId");
oRow["Organization"] = dr.GetString("Organization");
oRow["MonthCode"] = 0;
oRow["TotalDays"] = dr.GetDouble("TotalDays");
oDT.Rows.Add(oRow);
}
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oDT;
}
public DataTable GetTotalLeaveAmountInYear(int leaveYear, EnumLeaveStatus leaveStatus)
{
DataTable oDT = new DataTable();
oDT.Columns.Add("EmpId", typeof(Int32));
oDT.Columns.Add("LeaveId", typeof(Int32));
oDT.Columns.Add("Days", typeof(Int32));
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetTotalLeaveAmountInYear(tc, leaveYear, leaveStatus));
while (dr.Read())
{
DataRow oRow = oDT.NewRow();
oRow["LeaveId"] = dr.GetInt32("LeaveId");
oRow["Empid"] = dr.GetInt32("Empid");
oRow["Days"] = dr.GetInt32("Days");
oDT.Rows.Add(oRow);
}
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
return oDT;
}
public DataSet GetLeaveReport(int empId, DateTime fromDate, DateTime toDate)
{
DataSet oSet;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oSet = LeaveEntryDA.GetLeaveReport(tc, empId, fromDate, toDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Report" + e.Message, e);
#endregion
}
return oSet;
}
public DataSet GetAvailedLeave(int empId, DateTime fromDate, DateTime toDate)
{
DataSet oSet;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oSet = LeaveEntryDA.GetAvailedLeave(tc, empId, fromDate, toDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Report" + e.Message, e);
#endregion
}
return oSet;
}
public DataSet GetRecord(string empIds, DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus)
{
DataSet ds = new DataSet();
DataTable oDT = new DataTable();
oDT.Columns.Add("TranID", typeof(System.Int64));
oDT.Columns.Add("Remarks", typeof(System.String));
oDT.Columns.Add("Description", typeof(System.String));
oDT.Columns.Add("AppLeaveDate", typeof(System.String));
oDT.Columns.Add("AprFromDate", typeof(System.String));
oDT.Columns.Add("AprToDate", typeof(System.String));
oDT.Columns.Add("AprTotalDays", typeof(System.String));
oDT.Columns.Add("LeaveStatus", typeof(System.String));
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LeaveEntryDA.GetRecord(tc, empIds, fromDate, toDate, (int)leaveStatus));
while (dr.Read())
{
DataRow oRow = oDT.NewRow();
oRow["TranID"] = dr.GetDouble("TranID");
oRow["Remarks"] = dr.GetString("Remarks");
oRow["AprFromDate"] = Convert.ToDateTime(dr.GetString("AprFromDate")).ToString("dd MMM yyyy");
oRow["AprToDate"] = Convert.ToDateTime(dr.GetString("AprToDate")).ToString("dd MMM yyyy");
oRow["AprTotalDays"] = dr.GetString("AprTotalDays");
oRow["Description"] = dr.GetString("Description");
oRow["AppLeaveDate"] = Convert.ToDateTime(dr.GetString("AppLeaveDate")).ToString("dd MMM yyyy");
short x = (short)dr.GetInt16("LeaveStatus");
switch (x)
{
case 0:
oRow["LeaveStatus"] = "Drafted";
break;
case 1:
oRow["LeaveStatus"] = "Pending";
break;
case 2:
oRow["LeaveStatus"] = "Approved";
break;
case 3:
oRow["LeaveStatus"] = "reverted";
break;
case 4:
oRow["LeaveStatus"] = "Declined";
break;
case 5:
oRow["LeaveStatus"] = "Approved";
break;
case 6:
oRow["LeaveStatus"] = "Approved";
break;
case 9:
oRow["LeaveStatus"] = "Requested for Cancel";
break;
case 10:
oRow["LeaveStatus"] = "Cancelled";
break;
}
oDT.Rows.Add(oRow);
}
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Leave Information" + e.Message, e);
#endregion
}
ds.Tables.Add(oDT);
return ds;
}
//public DataSet GetEmployeeWiseLeaveReport(ID empId, DateTime fromDate, DateTime toDate)
//{
// DataSet oSet;
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// oSet = LeaveEntryDA.GetEmployeeWiseLeaveReport(tc, empId, fromDate, toDate);
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException("Failed to Get Report", e);
// #endregion
// }
// return oSet;
//}
public DataSet GetReport(string query)
{
DataSet oSet;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oSet = LeaveEntryDA.GetReport(tc, query);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Report" + e.Message, e);
#endregion
}
return oSet;
}
#region methods for WorkFlow
internal protected static void UpdateForWF(TransactionContext tc, LeaveEntry leaveEntry)
{
LeaveEntryDA.Update(tc, leaveEntry);
}
#endregion
#endregion
}
#endregion
}