CEL_Payroll/Payroll.Service/Loan/Service/LoanIssueService.cs

866 lines
26 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 LoanIssue Service
[Serializable]
public class LoanIssueService : ServiceTemplate, ILoanIssueService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(LoanIssue));
#endregion
public LoanIssueService() { }
private void MapObject(LoanIssue oLoanIssue, DataReader oReader)
{
base.SetObjectID(oLoanIssue, oReader.GetID("LoanIssueID"));
oLoanIssue.LoanID = oReader.GetID("loanID");
oLoanIssue.LoanNo = oReader.GetString("loanNo");
oLoanIssue.EmployeeID = oReader.GetID("employeeID");
oLoanIssue.LoanAmount = oReader.GetDouble("loanAmount").Value;
oLoanIssue.IssueDate = oReader.GetDateTime("issueDate").Value;
oLoanIssue.NoOfInstallments = oReader.GetInt32("noOfInstallments").Value;
oLoanIssue.InstallmentPrincipal = oReader.GetDouble("installmentPrincipal").Value;
oLoanIssue.InterestRate = oReader.GetDouble("interestRate").Value;
oLoanIssue.StartPaybackMonthDate = oReader.GetDateTime("startPaybackMonthDate").Value;
oLoanIssue.WFStatus = (enumwfStatus)oReader.GetInt32("WFStatus").Value;
//oLoanIssue.RemainInstallment = oReader.GetDouble("remainInstallment").Value;
//oLoanIssue.RemainInterest = oReader.GetDouble("remainInterest").Value;
//oLoanIssue.RemNoInstallment = oReader.GetDouble("remNoInstallment").Value;
oLoanIssue.CreatedBy = oReader.GetID("CreatedBy");
oLoanIssue.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oLoanIssue.ModifiedBy = oReader.GetID("ModifiedBy");
oLoanIssue.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oLoanIssue.AverageInterestRate = oReader.GetBoolean("AverageInterestRate").GetValueOrDefault();
this.SetObjectState(oLoanIssue, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LoanIssue oLoanIssue = new LoanIssue();
MapObject(oLoanIssue, oReader);
return oLoanIssue as T;
}
protected LoanIssue CreateObject(DataReader oReader)
{
LoanIssue oLoanIssue = new LoanIssue();
MapObject(oLoanIssue, oReader);
return oLoanIssue;
}
#region Service implementation
public LoanIssue Get(ID id)
{
LoanIssue oLoanIssue = new LoanIssue();
#region Cache Header
oLoanIssue = _cache["Get", id] as LoanIssue;
if (oLoanIssue != null)
return oLoanIssue;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanIssueDA.Get(tc, id));
if (oreader.Read())
{
oLoanIssue = this.CreateObject<LoanIssue>(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(oLoanIssue, "Get", id);
#endregion
return oLoanIssue;
}
public LoanIssue GetExistingLoan(ID nLoanID, ID nEmpID)
{
LoanIssue oLoanIssue = new LoanIssue();
#region Cache Header
oLoanIssue = _cache["GetExistingLoan", nLoanID, nEmpID] as LoanIssue;
if (oLoanIssue != null)
return oLoanIssue;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanIssueDA.GetExistingLoan(tc, nLoanID, nEmpID));
if (oreader.Read())
{
oLoanIssue = this.CreateObject<LoanIssue>(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(oLoanIssue, "GetExistingLoan", nLoanID, nEmpID);
#endregion
return oLoanIssue;
}
public LoanIssue GetExistingAllLoan(ID nLoanID, ID nEmpID)
{
LoanIssue oLoanIssue = new LoanIssue();
#region Cache Header
oLoanIssue = _cache["GetExistingLoan", nLoanID, nEmpID] as LoanIssue;
if (oLoanIssue != null)
return oLoanIssue;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanIssueDA.GetExistingAllLoan(tc, nLoanID, nEmpID));
if (oreader.Read())
{
oLoanIssue = this.CreateObject<LoanIssue>(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(oLoanIssue, "GetExistingLoan", nLoanID, nEmpID);
#endregion
return oLoanIssue;
}
public ObjectsTemplate<LoanIssue> GetExistingLoan(ID nEmpID)
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["GetExistingLoan", nEmpID] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.GetExistingLoan(tc, nEmpID));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "GetExistingLoan", nEmpID);
#endregion
return loanIssues;
}
public ObjectsTemplate<LoanIssue> GetByDueInstallmentDate(DateTime dateTime, string sEmpID)
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["Get", dateTime, sEmpID] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.GetByDueInstallmentDate(tc, dateTime, sEmpID));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "Get", dateTime, sEmpID);
#endregion
return loanIssues;
}
public ObjectsTemplate<LoanIssue> GetByDueInstallmentDate(DateTime dateTime)
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["Get", dateTime] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.GetByDueInstallmentDate(tc, dateTime));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "Get", dateTime);
#endregion
return loanIssues;
}
public ObjectsTemplate<LoanIssue> Get(DateTime dateTime)
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["Get", dateTime] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.Get(tc, dateTime));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "Get", dateTime);
#endregion
return loanIssues;
}
public ObjectsTemplate<LoanIssue> Get(DateTime dateTime, DateTime dateTime2)
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["Get", dateTime, dateTime2] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.Get(tc, dateTime, dateTime2));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "Get", dateTime, dateTime2);
#endregion
return loanIssues;
}
public ObjectsTemplate<LoanIssue> Get(string employeeNo)
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["Get", employeeNo] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.Get(tc, employeeNo));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "Get", employeeNo);
#endregion
return loanIssues;
}
public ObjectsTemplate<LoanIssue> GetByLoanID(ID nLoanID)
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["Get", nLoanID] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.GetByLoanID(tc, nLoanID));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "Get", nLoanID);
#endregion
return loanIssues;
}
public ObjectsTemplate<LoanIssue> GetAllExistingLoan(string LoanIDs)
{
ObjectsTemplate<LoanIssue> loanIssues = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.GetAllExistingLoan(tc, LoanIDs));
loanIssues = this.CreateObjects<LoanIssue>(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 loanIssues;
}
public ObjectsTemplate<LoanIssue> GetAllExistingLoan(int EmpID, string sLaonIDs)
{
ObjectsTemplate<LoanIssue> loanIssues = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.GetAllExistingLoan(tc, EmpID, sLaonIDs));
loanIssues = this.CreateObjects<LoanIssue>(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 loanIssues;
}
public ObjectsTemplate<LoanIssue> GetAllExistingLoan(string LoanIDs, DateTime month)
{
ObjectsTemplate<LoanIssue> loanIssues = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.GetAllExistingLoan(tc, LoanIDs, month));
loanIssues = this.CreateObjects<LoanIssue>(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 loanIssues;
}
public DataSet GetIssuedLoanIDs(int EmpID)
{
DataSet loanIDs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
loanIDs = LoanIssueDA.GetIssuedLoanIDs(tc, EmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loanIDs;
}
public DataSet GetIssuedLoans(int EmpID)
{
DataSet loanIDs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
loanIDs = LoanIssueDA.GetIssuedLoans(tc, EmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loanIDs;
}
public ObjectsTemplate<LoanIssue> Get()
{
#region Cache Header
ObjectsTemplate<LoanIssue> loanIssues = _cache["Get"] as ObjectsTemplate<LoanIssue>;
if (loanIssues != null)
return loanIssues;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanIssueDA.Get(tc));
loanIssues = this.CreateObjects<LoanIssue>(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(loanIssues, "Get");
#endregion
return loanIssues;
}
public ID Save(LoanIssue oLoanIssue)
{
TransactionContext tc = null;
int id = 0;
try
{
tc = TransactionContext.Begin(true);
if (oLoanIssue.IsNew)
{
id = tc.GenerateID("LoanIssue", "LoanIssueID");
base.SetObjectID(oLoanIssue, ID.FromInteger(id));
LoanIssueDA.Insert(tc, oLoanIssue);
}
else
{
LoanIssueDA.Update(tc, oLoanIssue);
}
LoanScheduleDA.Delete(tc, oLoanIssue.ID);
foreach (LoanSchedule schedule in oLoanIssue.Schedules)
{
schedule.LoanIssueID = oLoanIssue.ID;
schedule.EmployeeID = oLoanIssue.EmployeeID;
id = tc.GenerateID("LOANSCHEDULE", "LoanScheduleID");
base.SetObjectID(schedule, ID.FromInteger(id));
LoanScheduleDA.Insert(tc, schedule);
}
LoanEmployeeDocService dlsrv = new LoanEmployeeDocService();
dlsrv.DeletebyIssueid(tc, oLoanIssue.ID);
foreach (LoanEmployeeDoc oitem in oLoanIssue.IssueDocks)
{
LoanEmployeeDocService srv = new LoanEmployeeDocService();
oitem.LoanIssueID = oLoanIssue.ID;
srv.Save(tc, oitem);
}
tc.End();
return oLoanIssue.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID Save2(LoanIssue oLoanIssue)
{
TransactionContext tc = null;
int id = 0;
try
{
tc = TransactionContext.Begin(true);
if (oLoanIssue.IsNew)
{
id = tc.GenerateID("LoanIssue", "LoanIssueID");
base.SetObjectID(oLoanIssue, ID.FromInteger(id));
LoanIssueDA.Insert(tc, oLoanIssue);
}
else
{
LoanIssueDA.Update(tc, oLoanIssue);
}
LoanScheduleDA.Delete2(tc, oLoanIssue.ID);
foreach (LoanSchedule schedule in oLoanIssue.Schedules)
{
schedule.LoanIssueID = oLoanIssue.ID;
schedule.EmployeeID = oLoanIssue.EmployeeID;
this.SetObjectID(schedule, ID.FromInteger(LoanScheduleDA.GetNewID(tc, "LOANSCHEDULE", "LoanScheduleID")));
LoanScheduleDA.Insert(tc, schedule);
}
LoanEmployeeDocService dlsrv = new LoanEmployeeDocService();
dlsrv.DeletebyIssueid(tc, oLoanIssue.ID);
foreach (LoanEmployeeDoc oitem in oLoanIssue.IssueDocks)
{
LoanEmployeeDocService srv = new LoanEmployeeDocService();
oitem.LoanIssueID = oLoanIssue.ID;
srv.Save(tc, oitem);
}
tc.End();
return oLoanIssue.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);
LoanIssueDA.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 UpdateAvgIntStatus(ObjectsTemplate<LoanIssue> lis)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (LoanIssue li in lis)
{
LoanIssueDA.UpdateAvgIntStatus(tc, li);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public LoanIssue GetByLoanAndEmployeeIdAndLoanNumber(ID LoanId, ID EmployeeId, string loanNumber)
{
TransactionContext tc = null;
ObjectsTemplate<LoanIssue> allLoans = new ObjectsTemplate<LoanIssue>();
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(LoanIssueDA.GetByLoanAndEmployeeIdAndLoanNumber(tc, LoanId, EmployeeId, loanNumber));
allLoans = this.CreateObjects<LoanIssue>(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
}
if (allLoans.Count == 1)
{
return allLoans[0];
}
else return null;
}
public ObjectsTemplate<LoanIssue> GetByEmployeeIdAndLoanNumber(ID id, string loanNumber)
{
TransactionContext tc = null;
ObjectsTemplate<LoanIssue> allLoans;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(LoanIssueDA.GetByEmployeeIdAndLoanNumber(id, loanNumber, tc));
allLoans = this.CreateObjects<LoanIssue>(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 allLoans;
}
#endregion
}
#endregion
}