CEL_Payroll/Payroll.Service/Loan/Service/LoanScheduleService.cs

362 lines
11 KiB
C#
Raw 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 LoanSchedule Service
[Serializable]
public class LoanScheduleService : ServiceTemplate, ILoanScheduleService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(LoanSchedule));
#endregion
public LoanScheduleService() { }
private void MapObject(LoanSchedule oLoanSchedule, DataReader oReader)
{
base.SetObjectID(oLoanSchedule, oReader.GetID("LoanScheduleID"));
oLoanSchedule.LoanIssueID = oReader.GetID("LOANISSUEID");
oLoanSchedule.ScheduleNo = oReader.GetInt32("scheduleNo").Value;
oLoanSchedule.OpeningBalance = oReader.GetDouble("OpeningBalance").Value;
oLoanSchedule.InstallmentPrincipal = oReader.GetDouble("INSTALLMENTPRINCIPAL").Value;
oLoanSchedule.InstallmentInterest = oReader.GetDouble("INSTALLMENTINTEREST").Value;
oLoanSchedule.DueInstallmentDate = oReader.GetDateTime("DUEINSTALLMENTDATE").Value;
oLoanSchedule.PaymentDate = oReader.GetDateTime("PAYMENTDATE");
oLoanSchedule.Days = oReader.GetInt32("DAYS").Value;
oLoanSchedule.CalculatedDate = oReader.GetDateTime("CALCULATEDDATE").Value;
oLoanSchedule.ActualInterest = oReader.GetDouble("ACTUALINTEREST").Value;
oLoanSchedule.ClosingBalance = oReader.GetDouble("ClosingBalance").HasValue ? oReader.GetDouble("ClosingBalance").Value : 0;
oLoanSchedule.EmployeeID = oReader.GetID("EmployeeID");
oLoanSchedule.PaymentMode = (EnumLoanPaymentMode)(oReader.GetInt32("PaymentMode").HasValue ? oReader.GetInt32("PaymentMode").Value : 0);
oLoanSchedule.InterestRate = oReader.GetDouble("InterestRate").Value;
this.SetObjectState(oLoanSchedule, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LoanSchedule oLoanSchedule = new LoanSchedule();
MapObject(oLoanSchedule, oReader);
return oLoanSchedule as T;
}
protected LoanSchedule CreateObject(DataReader oReader)
{
LoanSchedule oLoanSchedule = new LoanSchedule();
MapObject(oLoanSchedule, oReader);
return oLoanSchedule;
}
#region Service implementation
public LoanSchedule Get(ID id)
{
LoanSchedule oLoanSchedule = new LoanSchedule();
#region Cache Header
oLoanSchedule = _cache["Get", id] as LoanSchedule;
if (oLoanSchedule != null)
return oLoanSchedule;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanScheduleDA.Get(tc, id));
if (oreader.Read())
{
oLoanSchedule = this.CreateObject<LoanSchedule>(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(oLoanSchedule, "Get", id);
#endregion
return oLoanSchedule;
}
public DataSet GetScheduleForSalary(DateTime monthDate, ID payrollTypeID)
{
DataSet loanSchedules = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
loanSchedules = LoanScheduleDA.GetScheduleForSalary(tc, monthDate, payrollTypeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loanSchedules;
}
public ObjectsTemplate<LoanSchedule> Get()
{
#region Cache Header
ObjectsTemplate<LoanSchedule> loanSchedules = _cache["Get"] as ObjectsTemplate<LoanSchedule>;
if (loanSchedules != null)
return loanSchedules;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanScheduleDA.Get(tc));
loanSchedules = this.CreateObjects<LoanSchedule>(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(loanSchedules, "Get");
#endregion
return loanSchedules;
}
public ObjectsTemplate<LoanSchedule> GetByIssueIDAndMonth(ID nIssueID, DateTime dateTime)
{
#region Cache Header
ObjectsTemplate<LoanSchedule> loanSchedules = _cache["GetByIssueIDAndMonth", nIssueID, dateTime] as ObjectsTemplate<LoanSchedule>;
if (loanSchedules != null)
return loanSchedules;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanScheduleDA.GetByIssueIDAndMonth(tc, nIssueID, dateTime));
loanSchedules = this.CreateObjects<LoanSchedule>(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(loanSchedules, "GetByIssueIDAndMonth", nIssueID, dateTime);
#endregion
return loanSchedules;
}
public DataSet GetLoanPaymentDue(DateTime dFromDate, DateTime dToDate)
{
DataSet loanSchedules = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
loanSchedules = LoanScheduleDA.GetLoanPaymentDue(tc, dFromDate, dToDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loanSchedules;
}
public ObjectsTemplate<LoanSchedule> GetByIssueID(ID nIssueID)
{
#region Cache Header
ObjectsTemplate<LoanSchedule> loanSchedules = _cache["GetByIssueID"] as ObjectsTemplate<LoanSchedule>;
if (loanSchedules != null)
return loanSchedules;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanScheduleDA.GetByIssueID(tc,nIssueID));
loanSchedules = this.CreateObjects<LoanSchedule>(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(loanSchedules, "GetByIssueID",nIssueID);
#endregion
return loanSchedules;
}
public ID Save(LoanSchedule oLoanSchedule)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLoanSchedule.IsNew)
{
int id = tc.GenerateID("LoanSchedule", "LoanScheduleID");
base.SetObjectID(oLoanSchedule, ID.FromInteger(id));
LoanScheduleDA.Insert(tc, oLoanSchedule);
}
else
{
LoanScheduleDA.Update(tc, oLoanSchedule);
}
tc.End();
return oLoanSchedule.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);
LoanScheduleDA.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 UpdatePaymentDate(TransactionContext tc,
ID loanSheduleId, DateTime paymentdate, EnumLoanPaymentMode mode)
{
try
{
tc = TransactionContext.Begin(true);
LoanScheduleDA.UpdatePaymentDate(tc, loanSheduleId , paymentdate, mode);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public DataSet GetByEmpIDANDLoanID(int EmpID, int LoanID)
{
DataSet oLoanAmounts = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oLoanAmounts = LoanScheduleDA.GetByEmpIDANDLoanID(tc, EmpID, LoanID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oLoanAmounts;
}
#endregion
}
#endregion
}