EchoTex_Payroll/HRM.DA/Service/Claim/ClaimPaymentNewService.cs
2024-10-14 10:01:49 +06:00

368 lines
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
using Ease.Core.DataAccess;
using HRM.BO;
using Ease.Core.Utility;
using Ease.Core.Model;
namespace Payroll.Service
{
public class ClaimPaymentNewService : ServiceTemplate, IClaimPaymentNewService
{
#region Constructor
public ClaimPaymentNewService()
{
}
#endregion
#region Map Object
private void MapObject(ClaimPaymentNew oClaimPaymentNewNew, DataReader oReader)
{
base.SetObjectID(oClaimPaymentNewNew, oReader.GetInt32("ClaimPaymentNewID").Value);
oClaimPaymentNewNew.PaymentIssueDate = oReader.GetDateTime("PaymentIssueDate").Value;
oClaimPaymentNewNew.Name = oReader.GetString("Name");
oClaimPaymentNewNew.Remarks = oReader.GetString("Remarks");
oClaimPaymentNewNew.Amount = oReader.GetDouble("Amount").Value;
oClaimPaymentNewNew.WFStatus = (enumwfStatus)oReader.GetInt32("WFStatus").Value;
oClaimPaymentNewNew.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oClaimPaymentNewNew.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oClaimPaymentNewNew.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : oReader.GetInt32("ModifiedBy").Value;
oClaimPaymentNewNew.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oClaimPaymentNewNew, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ClaimPaymentNew oClaimPaymentNewNew = new ClaimPaymentNew();
MapObject(oClaimPaymentNewNew, oReader);
return oClaimPaymentNewNew as T;
}
protected ClaimPaymentNew CreateObject(DataReader oReader)
{
ClaimPaymentNew oClaimPaymentNewNew = new ClaimPaymentNew();
MapObject(oClaimPaymentNewNew, oReader);
return oClaimPaymentNewNew;
}
#endregion
#region Service implementation
public ClaimPaymentNew Get(int id)
{
ClaimPaymentNew oClaimPaymentNew = new ClaimPaymentNew();
//#region Cache Header
//oClaimPaymentNew = _cache["Get", id] as ClaimPaymentNew;
//if (oClaimPaymentNew != null)
// return oClaimPaymentNew;
//#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ClaimPaymentNewDA.Get(tc, id));
if (oreader.Read())
{
oClaimPaymentNew = this.CreateObject<ClaimPaymentNew>(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 oClaimPaymentNew;
}
public ClaimPaymentNew GetByClaimIDs(string _claimIds)
{
ClaimPaymentNew oClaimPaymentNew = new ClaimPaymentNew();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ClaimPaymentNewDA.GetByClaimIDs(tc, _claimIds));
if (oreader.Read())
{
oClaimPaymentNew = this.CreateObject<ClaimPaymentNew>(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 oClaimPaymentNew;
}
public List<ClaimPaymentNew> Get(EnumStatus status, int payrollTypeID)
{
#region Cache Header
List<ClaimPaymentNew> attnNationalHolidays = null;
//if (attnNationalHolidays != null)
// return attnNationalHolidays;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimPaymentNewDA.Get(tc, status, payrollTypeID));
attnNationalHolidays = this.CreateObjects<ClaimPaymentNew>(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 attnNationalHolidays;
}
public List<ClaimPaymentNew> Get(DateTime fromDate, DateTime todate, int payrollTypeID)
{
#region Cache Header
List<ClaimPaymentNew> attnNationalHolidays = null;
//if (attnNationalHolidays != null)
// return attnNationalHolidays;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimPaymentNewDA.Get(tc, fromDate,todate, payrollTypeID));
attnNationalHolidays = this.CreateObjects<ClaimPaymentNew>(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 attnNationalHolidays;
}
public void Save(List<ClaimPaymentNew> oClaimPaymentNews)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int ClaimPaymentNewID = tc.GenerateID("ClaimPaymentNew", "ClaimPaymentNewID");
int ClaimPaymentNewGradesID = tc.GenerateID("ClaimPaymentNewGrades", "ClaimPaymentNewGradesID");
foreach (ClaimPaymentNew oClaimPaymentNew in oClaimPaymentNews)
{
if (oClaimPaymentNew.IsNew)
{
base.SetObjectID(oClaimPaymentNew, ClaimPaymentNewID);
ClaimPaymentNewDA.Insert(tc, oClaimPaymentNew);
ClaimPaymentNewID++;
}
else
{
ClaimPaymentNewDA.Update(tc, oClaimPaymentNew);
ClaimPaymentNewDA.DeleteChild(tc, oClaimPaymentNew.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 int Save(ClaimPaymentNew oClaimPaymentNew)
{
string claimRequisitionIDs = string.Empty;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oClaimPaymentNew.IsNew)
{
int id = tc.GenerateID("ClaimPaymentNew", "ClaimPaymentNewID");
base.SetObjectID(oClaimPaymentNew, id);
ClaimPaymentNewDA.Insert(tc, oClaimPaymentNew);
}
else
{
ClaimPaymentNewDA.Update(tc, oClaimPaymentNew);
ClaimPaymentNewDA.DeleteChild(tc, oClaimPaymentNew.ID);
}
foreach (ClaimPaymentDetail item in oClaimPaymentNew.ClaimPaymentDetails)
{
int id = tc.GenerateID("ClaimPaymentDetail", "ClaimPaymentDetailID");
base.SetObjectID(item,id);
item.ClaimPaymentID = oClaimPaymentNew.ID;
//ClaimPaymentNew.InsertChild(tc, item); // need to add
if (claimRequisitionIDs == string.Empty)
{
claimRequisitionIDs = item.ClaimID.ToString();
}
else
{
claimRequisitionIDs = claimRequisitionIDs + "," + item.ClaimID.ToString();
}
}
// ClaimRequisitionDA.UpdateClaimRwquisitionItemStatus(tc, claimRequisitionIDs,oClaimPaymentNew.PaymentIssueDate); // need to add
tc.End();
return oClaimPaymentNew.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<ClaimPaymentDetail> GetClaimPaymentDetails(int ID)
{
List<ClaimPaymentDetail> oClaimPaymentDetails = new List<ClaimPaymentDetail>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimPaymentNewDA.GetChild(tc, ID));
oClaimPaymentDetails = this.CreateChilds(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 oClaimPaymentDetails;
}
private List<ClaimPaymentDetail> CreateChilds(DataReader oReader)
{
List<ClaimPaymentDetail> oClaimPaymentGrades = new List<ClaimPaymentDetail>();
ClaimPaymentDetail oClaimPaymentGrade;
while (oReader.Read())
{
oClaimPaymentGrade = new ClaimPaymentDetail();
oClaimPaymentGrade = CreateChild(oReader);
oClaimPaymentGrades.Add(oClaimPaymentGrade);
}
return oClaimPaymentGrades;
}
private ClaimPaymentDetail CreateChild(DataReader oReader)
{
ClaimPaymentDetail oClaimPaymentGrades = new ClaimPaymentDetail();
MapChildObject(oClaimPaymentGrades, oReader);
return oClaimPaymentGrades;
}
private void MapChildObject(ClaimPaymentDetail oClaimPaymentGrade, DataReader oReader)
{
base.SetObjectID(oClaimPaymentGrade, oReader.GetInt32("ClaimPaymentDetailID").Value);
oClaimPaymentGrade.ClaimID = oReader.GetInt32("ClaimID") == null ? 0 : oReader.GetInt32("ClaimID").Value;
oClaimPaymentGrade.ClaimPaymentID = oReader.GetInt32("ClaimPaymentNewID") == null ? 0 : oReader.GetInt32("ClaimPaymentNewID").Value;
//oClaimPaymentGrade.CreatedBy = oReader.GetString("CreatedBy") == null ? null : ID.FromInteger(oReader.GetInt32("CreatedBy").Value);
//oClaimPaymentGrade.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
//oClaimPaymentGrade.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : ID.FromInteger(oReader.GetInt32("ModifiedBy").Value);
//oClaimPaymentGrade.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oClaimPaymentGrade, Ease.Core.ObjectState.Saved);
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ClaimPaymentNewDA.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
}
}
#endregion
public List<ClaimPaymentNew> Get()
{
List<ClaimPaymentNew> oClaimPaymentNews = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimPaymentNewDA.Get(tc));
oClaimPaymentNews = this.CreateObjects<ClaimPaymentNew>(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 oClaimPaymentNews;
}
}
}