EchoTex_Payroll/HRM.DA/Service/Basic/PayScaleService.cs

420 lines
12 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using HRM.BO;
namespace HRM.DA
{
public class PayScaleService : ServiceTemplate, IPayScaleService
{
public PayScaleService()
{
}
private void MapObject(PayScale oPayScale, DataReader oReader)
{
base.SetObjectID(oPayScale, oReader.GetInt32("PAYSCALEID").Value);
oPayScale.GradeID = oReader.GetInt32("GradeID", 0);
oPayScale.ItemID = oReader.GetInt32("ALLOWANCEID").Value;
oPayScale.InitialAmount = oReader.GetDouble("INITIALAMOUNT").Value;
oPayScale.IncPercentage = oReader.GetDouble("PercentageInc").Value;
oPayScale.NoOfStep = oReader.GetInt32("NOOFSLABS").Value;
oPayScale.EffectDate = oReader.GetDateTime("EffectDate").Value;
oPayScale.ItemType = (EnumPayScaleItemType)oReader.GetInt32("Type").Value;
this.SetObjectState(oPayScale, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PayScale oPayScale = new PayScale();
MapObject(oPayScale, oReader);
return oPayScale as T;
}
#region Service implementation
public PayScale Get(int id)
{
PayScale oPayScale = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PayScaleDA.Get(tc, id));
if (oreader.Read())
{
oPayScale = this.CreateObject<PayScale>(oreader);
oPayScale.PayscaleDetails = (new PayScaleDetailService()).GetByPayScale(tc, oPayScale.ID);
}
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 oPayScale;
}
public PayScale Get(int nGradeID, int nAllowID, DateTime nextPayProcessDate)
{
PayScale oPayScale = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PayScaleDA.Get(tc, nGradeID, nAllowID, nextPayProcessDate));
if (oreader.Read())
{
oPayScale = this.CreateObject<PayScale>(oreader);
oPayScale.PayscaleDetails = (new PayScaleDetailService()).GetByPayScale(tc, oPayScale.ID);
}
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 oPayScale;
}
public PayScale GetByGrade(int nGradeID)
{
PayScale oPayScale = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PayScaleDA.GetByGrade(tc, nGradeID));
if (oreader.Read())
{
oPayScale = this.CreateObject<PayScale>(oreader);
oPayScale.PayscaleDetails = (new PayScaleDetailService()).GetByPayScale(tc, oPayScale.ID);
}
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 oPayScale;
}
public DateTime? GetMaxEffectDate(int payrollTypeID)
{
TransactionContext tc = null;
DateTime? dMaxEffectDate = DateTime.MinValue;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PayScaleDA.GetMaxEffectDate(tc, payrollTypeID));
if (oreader.Read())
{
dMaxEffectDate = oreader.GetDateTime(0);
}
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 dMaxEffectDate;
}
public List<PayScale> GetByAllowance(int nAllowID)
{
List<PayScale> payScales = new List<PayScale>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PayScaleDA.GetByAllowance(tc, nAllowID));
payScales = this.CreateObjects<PayScale>(dr);
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 payScales;
}
public List<PayScale> Get()
{
List<PayScale> payScales = new List<PayScale>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PayScaleDA.Get(tc));
payScales = this.CreateObjects<PayScale>(dr);
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 payScales;
}
public List<PayScale> GetLatest(int payrollTypeID)
{
List<PayScale> payScales = new List<PayScale>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PayScaleDA.GetLatest(tc, payrollTypeID));
payScales = this.CreateObjects<PayScale>(dr);
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 payScales;
}
public int Save(PayScale oPayScale)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPayScale.IsNew)
{
int id = tc.GenerateID("PayScale", "PAYSCALEID");
base.SetObjectID(oPayScale, id);
PayScaleDA.Insert(tc, oPayScale);
}
else
{
PayScaleDA.Update(tc, oPayScale);
PayScaleDetailDA.DeleteByPayScaleID(tc, oPayScale.ID);
}
foreach (PayScaleDetail detail in oPayScale.PayscaleDetails)
{
detail.PayscaleID = oPayScale.ID;
int id = tc.GenerateID("PAYSCALEITEM", "PAYSCALEITEMID");
base.SetObjectID(detail, id);
detail.GradeID = oPayScale.GradeID;
detail.AllowanceID = oPayScale.ItemID;
PayScaleDetailDA.Insert(tc, detail);
}
tc.End();
return oPayScale.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(TransactionContext tc, PayScale oPayScale)
{
try
{
if (oPayScale.IsNew)
{
int id = tc.GenerateID("PayScale", "PAYSCALEID");
base.SetObjectID(oPayScale, id);
PayScaleDA.Insert(tc, oPayScale);
}
else
{
PayScaleDA.Update(tc, oPayScale);
PayScaleDetailDA.DeleteByPayScaleID(tc, oPayScale.ID);
}
foreach (PayScaleDetail detail in oPayScale.PayscaleDetails)
{
detail.PayscaleID = oPayScale.ID;
int id = tc.GenerateID("PAYSCALEITEM", "PAYSCALEITEMID");
base.SetObjectID(detail, id);
detail.GradeID = oPayScale.GradeID;
detail.AllowanceID = oPayScale.ItemID;
PayScaleDetailDA.Insert(tc, detail);
}
return oPayScale.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);
PayScaleDA.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 void Save(List<PayScale> newPayscale)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (PayScale scale in newPayscale)
{
this.Save(tc, scale);
}
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 DeleteByGradeID(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PayScaleDA.DeleteByGrade(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
}
}
#endregion
}
}