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

482 lines
14 KiB
C#

using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using HRM.BO;
namespace HRM.DA
{
#region LoanSchedule Service
public class LoanScheduleService : ServiceTemplate, ILoanScheduleService
{
public LoanScheduleService()
{
}
private void MapObject(LoanSchedule oLoanSchedule, DataReader oReader)
{
base.SetObjectID(oLoanSchedule, oReader.GetInt32("LoanScheduleID").Value);
oLoanSchedule.LoanIssueID =oReader.GetInt32("LOANISSUEID").Value;
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").Value;
oLoanSchedule.EmployeeID =oReader.GetInt32("EmployeeID").Value ;
oLoanSchedule.PaymentMode = (EnumLoanPaymentMode)(oReader.GetInt32("PaymentMode").Value);
oLoanSchedule.InterestRate = oReader.GetDouble("InterestRate").Value;
this.SetObjectState(oLoanSchedule, Ease.Core.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(int id)
{
LoanSchedule oLoanSchedule = new LoanSchedule();
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
}
return oLoanSchedule;
}
public List<LoanSchedule> Get()
{
List<LoanSchedule> loanSchedules = new List<LoanSchedule>();
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
}
return loanSchedules;
}
public List<LoanSchedule> GetUnpaidSechedule(DateTime monthDate)
{
List<LoanSchedule> loanSchedules = new List<LoanSchedule>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanScheduleDA.GetUnpaidSechedule(tc, monthDate));
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
}
return loanSchedules;
}
public List<LoanSchedule> GetByIssueIDAndMonth(int nIssueID, DateTime dateTime)
{
List<LoanSchedule> loanSchedules = new List<LoanSchedule>();
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
}
return loanSchedules;
}
public DataSet GetLoanPaymentDue(DateTime dFromDate, DateTime dToDate, int payrollTypeID)
{
DataSet loanSchedules = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
loanSchedules = LoanScheduleDA.GetLoanPaymentDue(tc, dFromDate, dToDate, 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 DataSet GetAllActiveLoan(string sEmps, int payrollTypeID)
{
DataSet loanSchedules = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
loanSchedules = LoanScheduleDA.GetAllActiveLoan(tc, sEmps, 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 DataSet GetCurrentMonthDueLoan(string sEmps, int payrollTypeID, int loanID)
{
DataSet loanSchedules = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
loanSchedules = LoanScheduleDA.GetCurrentMonthDueLoan(tc, sEmps, payrollTypeID, 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 loanSchedules;
}
public DataSet GetScheduleForSalary(DateTime monthDate, int 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 List<LoanSchedule> GetByIssueID(int nIssueID)
{
List<LoanSchedule> loanSchedules = new List<LoanSchedule>();
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
}
return loanSchedules;
}
public int Save(LoanSchedule oLoanSchedule)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLoanSchedule.IsNew)
{
int id = tc.GenerateID("LoanSchedule", "LoanScheduleID");
base.SetObjectID(oLoanSchedule, 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 UpdateSchedules(List<LoanSchedule> oLoanSchedules)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (LoanSchedule item in oLoanSchedules)
{
item.ClosingBalance = item.OpeningBalance - item.InstallmentPrincipal + item.InstallmentInterest;
LoanScheduleDA.UpdateAmount(tc, item);
}
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 SaveList(List<LoanSchedule> items)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (var loanSchedule in items)
{
if (loanSchedule.IsNew)
{
int id = tc.GenerateID("LoanSchedule", "LoanScheduleID");
base.SetObjectID(loanSchedule, id);
LoanScheduleDA.Insert(tc, loanSchedule);
}
else
{
LoanScheduleDA.Update(tc, loanSchedule);
}
}
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 Delete(int 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,
int 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
}