CEL_Payroll/Payroll.Service/AllowDeduct/Service/ADParameterService.cs

513 lines
17 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 ADParameter Service
[Serializable]
public class ADParameterService : ServiceTemplate, IADParameterService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ADParameter));
#endregion
public ADParameterService() { }
private void MapObject(ADParameter oADParameter, DataReader oReader)
{
base.SetObjectID(oADParameter, oReader.GetID("ADParameterID"));
oADParameter.AllowDeductID = oReader.GetID("ALLOWDEDUCTID");
oADParameter.IsForConfirmOnly = oReader.GetBoolean("isForConfirmOnly").Value;
oADParameter.FlatAmount = oReader.GetDouble("flatAmount").Value;
oADParameter.PercentOfBasic = oReader.GetDouble("percentOfBasic").Value;
oADParameter.PercentOfGross = oReader.GetDouble("percentOfGross").Value;
oADParameter.PercentOfEarnedBasic = oReader.GetDouble("percentOfEarnedBasic").Value;
oADParameter.MinAmount = oReader.GetDouble("minAmount").Value;
oADParameter.MaxAmount = oReader.GetDouble("maxAmount").Value;
oADParameter.IsCurrentlyActive = oReader.GetBoolean("isCurrentlyActive").Value;
oADParameter.TaxablePercentage = oReader.GetDouble("taxablePercentage").Value;
oADParameter.IsTaxable = oReader.GetBoolean("isTaxable").Value;
oADParameter.IsTaxProjection = oReader.GetBoolean("isTaxProjection").Value;
oADParameter.IsDependsOnAttendance = oReader.GetBoolean("isDependsOnAttendance").Value;
oADParameter.IsFractionateApplicable = oReader.GetBoolean("IsFractionateApplicable").Value;
oADParameter.IsDependsOnOTHour = oReader.GetBoolean("isDependsOnOTHour").Value;
oADParameter.ISDEPENDSONSPECIALHOUR = oReader.GetBoolean("ISDEPENDSONSPECIALHOUR").Value;
oADParameter.IsWithException = oReader.GetBoolean("isWithException").Value;
oADParameter.Periodicity = (EnumPeriodicity)oReader.GetInt32("periodicity").Value;
oADParameter.AllowOrDeductType = (EnumAllowOrDeduct)oReader.GetInt32("ALLOWORDEDUCT").Value;
oADParameter.Gender = (EnumGender)oReader.GetInt32("gender").Value;
oADParameter.CreatedBy = oReader.GetID("CreatedBy");
oADParameter.CreatedDate =oReader.GetDateTime("CreationDate")==null?DateTime.MinValue: oReader.GetDateTime("CreationDate").Value;
oADParameter.ModifiedBy = oReader.GetID("ModifiedBy");
oADParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oADParameter.EntitleType = (EnumEntitleType)oReader.GetInt32("EntitleType").Value;
this.SetObjectState(oADParameter, Ease.CoreV35.ObjectState.Saved);
}
private void MapADGradeObject(ADParameter.ADParameterGrade oADGrade, DataReader oReader)
{
base.SetObjectID(oADGrade, oReader.GetID("ADPARAMETERID"));
oADGrade.ADParameterID = oReader.GetID("ADPARAMETERID");
oADGrade.GradeID = oReader.GetID("GRADEID");
this.SetObjectState(oADGrade, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ADParameter oADParameter = new ADParameter();
MapObject(oADParameter, oReader);
return oADParameter as T;
}
protected ObjectsTemplate<ADParameter.ADParameterGrade> CreateADGradeObject(DataReader oReader)
{
ObjectsTemplate<ADParameter.ADParameterGrade> oADGrades = new ObjectsTemplate<ADParameter.ADParameterGrade>();
while (oReader.Read())
{
ADParameter.ADParameterGrade oADGrade = new ADParameter.ADParameterGrade();
MapADGradeObject(oADGrade, oReader);
oADGrades.Add(oADGrade);
}
return oADGrades;
}
protected ADParameter CreateObject(DataReader oReader)
{
ADParameter oADParameter = new ADParameter();
MapObject(oADParameter, oReader);
return oADParameter;
}
public ObjectsTemplate<ADParameter> GetWithDetail(EnumStatus status,ID PayrolltypeID)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get", status] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.Get(tc, status, PayrolltypeID));
aDParameters = this.CreateObjects<ADParameter>(dr);
dr.Close();
tc.End();
foreach (ADParameter oparam in aDParameters)
{
oparam.ADParameterGrades = this.GetGrades(oparam.ID);
ADParameterEmployeeService ads = new ADParameterEmployeeService();
oparam.NotApplicable = ads.GetbyParameter(oparam.ID, EnumADEmpType.NotApplicable);
oparam.Exception = ads.GetbyParameter(oparam.ID, EnumADEmpType.Exception);
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
_cache.Add(aDParameters, "Get", status);
#endregion
return aDParameters;
}
#region Service implementation
public ADParameter Get(ID id,ID PayrolltypeID)
{
ADParameter oADParameter = new ADParameter();
#region Cache Header
oADParameter = _cache["Get", id] as ADParameter;
if (oADParameter != null)
return oADParameter;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ADParameterDA.Get(tc, id, PayrolltypeID));
if (oreader.Read())
{
oADParameter = this.CreateObject<ADParameter>(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
}
#region Cache Footer
_cache.Add(oADParameter, "Get", id);
#endregion
return oADParameter;
}
public ObjectsTemplate<ADParameter.ADParameterGrade> GetGrades(ID nID)
{
#region Cache Header
ObjectsTemplate<ADParameter.ADParameterGrade> aDParameterGrade = _cache["Get", nID] as ObjectsTemplate<ADParameter.ADParameterGrade>;
if (aDParameterGrade != null)
return aDParameterGrade;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetGrades(tc, nID));
aDParameterGrade = this.CreateADGradeObject(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
}
#region Cache Footer
_cache.Add(aDParameterGrade, "Get", nID);
#endregion
return aDParameterGrade;
}
public ObjectsTemplate<ADParameter> GetByPayrolltypeid(EnumStatus status, ID PayrolltypeID)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get",status] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetByPayrolltypeid(tc, status, PayrolltypeID));
aDParameters = this.CreateObjects<ADParameter>(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
}
#region Cache Footer
_cache.Add(aDParameters, "Get",status);
#endregion
return aDParameters;
}
public ObjectsTemplate<ADParameter> Get(EnumStatus status, EnumAllowOrDeduct nType, ID PayrolltypeID)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get",status,nType] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.Get(tc, status, nType, PayrolltypeID));
aDParameters = this.CreateObjects<ADParameter>(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
}
#region Cache Footer
_cache.Add(aDParameters, "Get", status, nType);
#endregion
return aDParameters;
}
public ObjectsTemplate<ADParameter> Get(EnumStatus status, ID nAllowdeducID)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get", status, nAllowdeducID] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.Get(tc, status, nAllowdeducID));
aDParameters = this.CreateObjects<ADParameter>(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
}
#region Cache Footer
_cache.Add(aDParameters, "Get", status, nAllowdeducID);
#endregion
return aDParameters;
}
public ADParameter GetADParamByGradeAndAD(ID gradeID, ID nAllowdeducID)
{
ADParameter aDParameter = new ADParameter();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.GetADParamByGradeAndAD(tc, gradeID, nAllowdeducID));
if (dr.Read())
{
aDParameter = this.CreateObject<ADParameter>(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 aDParameter;
}
public ObjectsTemplate<ADParameter> Get(ID gradeID, EnumEntitleType nEntitleType, EnumAllowOrDeduct nType,ID PayrolltypeID)
{
#region Cache Header
ObjectsTemplate<ADParameter> aDParameters = _cache["Get", gradeID, nEntitleType, nType] as ObjectsTemplate<ADParameter>;
if (aDParameters != null)
return aDParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ADParameterDA.Get(tc, gradeID, nEntitleType, nType,PayrolltypeID));
aDParameters = this.CreateObjects<ADParameter>(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
}
#region Cache Footer
_cache.Add(aDParameters, "Get", gradeID, nEntitleType, nType);
#endregion
return aDParameters;
}
public ID Save(ADParameter oADParameter, ID PayrolltypeID)
{
TransactionContext tc = null;
try
{
ObjectsTemplate<ADParameter.ADParameterGrade> adg = oADParameter.ADParameterGrades;
tc = TransactionContext.Begin(true);
if (oADParameter.IsNew)
{
int id = tc.GenerateID("ADPARAMETERBASIC", "ADParameterID");
base.SetObjectID(oADParameter, ID.FromInteger(id));
ADParameterDA.Insert(tc, oADParameter, PayrolltypeID);
}
else
{
ADParameterDA.Update(tc, oADParameter);
ADParameterDA.DeleteGrade(tc, oADParameter.ID);
ADParameterEmployeeDA.DeletebyAdParamid(tc, oADParameter.ID);
}
foreach (ADParameterEmployee adEmp in oADParameter.ADParameterEmployees)
{
adEmp.ADParameterID = oADParameter.ID;
int id = tc.GenerateID("ADPARAMETEREMPLOYEE", "ADPARAMETEREMPID");
base.SetObjectID(adEmp, ID.FromInteger(id));
adEmp.CreatedBy = oADParameter.CreatedBy;
adEmp.CreatedDate = oADParameter.CreatedDate;
adEmp.ModifiedBy = Payroll.BO.User.CurrentUser.ID;
adEmp.ModifiedDate = DateTime.Today;
ADParameterEmployeeDA.Insert(tc, adEmp);
}
foreach (ADParameter.ADParameterGrade adGrade in adg)
{
adGrade.ADParameterID = oADParameter.ID;
ADParameterDA.Insert(tc, adGrade);
}
tc.End();
return oADParameter.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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ADParameterDA.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 ChangeStatus(ID id, EnumStatus enumStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ADParameterDA.ChangeStatus(tc,id,enumStatus);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}