EchoTex_Payroll/HRM.DA/Service/Fund/Loan/FmLoanService.cs

1357 lines
49 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class FmLoanService : ServiceTemplate //, ILoanService, IFASService
{
public FmLoanService()
{
}
#region Child Schedule function
private void MapLoanSchedule(FmLoanSchedule loanSchedule, DataReader dr)
{
base.SetObjectID(loanSchedule, dr.GetInt32("LoanScheduleID").Value);
loanSchedule.ActivityID = dr.GetInt32("ActivityID").Value;
loanSchedule.CustomerID = dr.GetInt32("CustomerID").Value;
loanSchedule.EffectiveBalance = dr.GetDouble("EffectiveBalance").Value;
loanSchedule.InstallmentAmount = dr.GetDouble("InstallmentAmount").Value;
loanSchedule.InstallmentInterest = dr.GetDouble("InstallmentInterest").Value;
loanSchedule.InstallmentPrincipal = dr.GetDouble("InstallmentPrincipal").Value;
loanSchedule.LoanCategoryID = dr.GetInt32("LoanCategoryID").Value;
loanSchedule.LoanID = dr.GetInt32("LoanID").Value;
loanSchedule.PayDate = dr.GetDateTime("PayDate");
loanSchedule.ScheduledPayDate = dr.GetDateTime("ScheduledPayDate").Value;
loanSchedule.SerialNo = dr.GetInt32("SerialNo").Value;
loanSchedule.CreatedBy = dr.GetInt32("CreatedBy").Value;
loanSchedule.CreatedDate = dr.GetDateTime("CreatedDate").Value;
loanSchedule.ModifiedBy = dr.GetInt32("ModifiedBy");
loanSchedule.ModifiedDate = dr.GetDateTime("ModifiedDate");
loanSchedule.ProjectID = dr.GetInt32("ProjectID").Value;
base.SetObjectState(loanSchedule, Ease.Core.ObjectState.Saved);
}
private FmLoanSchedule CreateSchedules(DataReader dr)
{
FmLoanSchedule loanSchedule = new FmLoanSchedule();
MapLoanSchedule(loanSchedule, dr);
return loanSchedule;
}
private void FillSchedules(FmLoan parent, DataReader dr)
{
while (dr.Read())
{
FmLoanSchedule item = this.CreateSchedules(dr);
parent.LoanSchedules.Add(item);
}
}
internal void LoadSchedule(TransactionContext tc, FmLoan loan)
{
try
{
if (loan != null && loan.ID != null && loan.ID != 0)
{
//Get LoanSchedule
DataReader dr = new DataReader(FmLoanDA.GetSchedules(tc, loan.ID));
FillSchedules(loan, dr);
dr.Close();
}
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region Child LoanCategory
private void MapCategoryObject(LoanCategory loanCategory, DataReader dr)
{
base.SetObjectID(loanCategory, dr.GetInt32("LoanCategoryID").Value);
loanCategory.DefaultInterestRate = dr.GetDouble("DefaultInterestRate").Value;
loanCategory.LoanCategoryCode = dr.GetString("LoanCategoryCode");
loanCategory.Description = dr.GetString("Description");
loanCategory.IsActive = (EnumLoanCategoryStatus)dr.GetInt16("IsActive").Value;
loanCategory.MaxAlowableFlatAmount = dr.GetDouble("MaxAlowableFlatAmount");
loanCategory.MaxInstallment = dr.GetInt32("MaxInstallment").Value;
loanCategory.MinInstallment = dr.GetInt32("MinInstallment").Value;
loanCategory.PercentageofFund = dr.GetDouble("PercentageofFund");
loanCategory.Version = dr.GetInt16("Version").Value;
loanCategory.CreatedBy = dr.GetInt32("CreatedBy").Value;
loanCategory.CreatedDate = dr.GetDateTime("CreatedDate").Value;
loanCategory.ModifiedBy = dr.GetInt32("ModifiedBy");
loanCategory.ModifiedDate = dr.GetDateTime("ModifiedDate");
loanCategory.ProjectID = dr.GetInt32("ProjectID").Value;
base.SetObjectState(loanCategory, Ease.Core.ObjectState.Saved);
}
private LoanCategory CreateCategoryObject(DataReader dr)
{
LoanCategory loanCategory = new LoanCategory();
MapCategoryObject(loanCategory, dr);
return loanCategory;
}
internal void LoadCategory(TransactionContext tc, FmLoan loan)
{
try
{
if (loan != null && loan.LoanCategoryID != null && loan.LoanCategoryID != 0)
{
//Get LoanCategory
LoanCategory loanCategory = null;
DataReader dr = new DataReader(FmLoanDA.GetCategory(tc, loan.LoanCategoryID));
if (dr.Read())
{
loanCategory = this.CreateCategoryObject(dr);
}
dr.Close();
}
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region Child LoanCustomer
//private void MapCustomerObject(LoanCustomer loanCustomer, DataReader dr)
//{
// base.SetObjectID(loanCustomer, dr.GetID("CustomerID"));
// loanCustomer.AccNo = dr.GetString("AccNo");
// loanCustomer.Address = dr.GetString("Address");
// loanCustomer.DateOfBirth = dr.GetDateTime("DateOfBirth").Value;
// loanCustomer.DateOfJoining = dr.GetDateTime("DateOfJoining").Value;
// loanCustomer.EmpCode = dr.GetString("EmpCode");
// loanCustomer.IsMember = dr.GetBoolean("IsMember").Value;
// loanCustomer.MemberShipNo = dr.GetString("MemberShipNo");
// loanCustomer.Name = dr.GetString("Name");
// loanCustomer.CreatedBy = dr.GetID("CreatedBy");
// loanCustomer.CreatedDate = dr.GetDateTime("CreatedDate").Value;
// loanCustomer.ModifiedBy = dr.GetID("ModifiedBy");
// loanCustomer.ModifiedDate = dr.GetDateTime("ModifiedDate");
// loanCustomer.ProjectID = dr.GetID("ProjectID");
// loanCustomer.MemberID = dr.GetID("MemberID");
// loanCustomer.MembershipDate = dr.GetDateTime("MembershipDate").HasValue?dr.GetDateTime("MembershipDate").Value:DateTime.MinValue;
// loanCustomer.Email = dr.GetString("Email");
// base.SetObjectState(loanCustomer, Ease.Core.ObjectState.Saved);
//}
//private LoanCustomer CreateCustomerObject(DataReader dr)
//{
// LoanCustomer loanCustomer = new LoanCustomer();
// MapCustomerObject(loanCustomer, dr);
// return loanCustomer;
//}
//internal void LoadCustomer(TransactionContext tc, Loan loan)
//{
// try
// {
// if (loan != null && loan.ID != null && loan.ID.Integer != 0)
// {
// //Get LoanCustomer
// LoanCustomer loanCustomer = null;
// DataReader dr = new DataReader(LoanDA.GetCustomer(tc, loan.CustomerID));
// if (dr.Read())
// {
// loanCustomer = this.CreateCustomerObject(dr);
// }
// dr.Close();
// }
// }
// catch (Exception e)
// {
// throw e;
// }
//}
#endregion
#region parent Loan Section
private void MapObject(FmLoan loan, DataReader dr)
{
base.SetObjectID(loan, dr.GetInt32("LoanID").Value);
loan.ActivityID = dr.GetInt32("ActivityID").Value;
loan.CustomerID = dr.GetInt32("CustomerID").Value;
loan.Description = dr.GetString("Description");
loan.InstallmentNo = dr.GetInt32("InstallmentNo").Value;
loan.InterestRate = dr.GetDouble("InterestRate") != null ? dr.GetInt32("InterestRate").Value : 0;
loan.IssueDate = dr.GetDateTime("IssueDate").Value;
loan.LoanCategoryID = dr.GetInt32("LoanCategoryID").Value;
loan.LoanNo = dr.GetString("LoanNo");
loan.Remarks = dr.GetString("Remarks");
loan.LoanAccNo = dr.GetString("LoanAccNo");
loan.MemberID = dr.GetInt32("MemberID").Value;
loan.PrincipalAmount = dr.GetDouble("PrincipalAmount").Value;
loan.Status = (EnumLoanStatus)dr.GetInt16("Status").Value;
loan.LoanIssueStatus = (EnumLoanIssueStatus)dr.GetInt16("LoanIssueStatus").Value;
loan.Version = dr.GetInt32("Version") != null ? dr.GetInt32("Version").Value : 0;
loan.CreatedBy = dr.GetInt32("CreatedBy").Value;
loan.CreatedDate = dr.GetDateTime("CreatedDate").Value;
loan.ModifiedBy = dr.GetInt32("ModifiedBy");
loan.ModifiedDate = dr.GetDateTime("ModifiedDate");
loan.ProjectID = dr.GetInt32("ProjectID").Value;
loan.GLTranID = dr.GetInt32("GLTranID").Value;
loan.StartPayBackMonth = dr.GetDateTime("StartPayBackMonth") != null
? dr.GetDateTime("StartPayBackMonth").Value
: DateTime.MinValue;
loan.TransferLogIDinInt = dr.GetInt32("TransferLogID") != null ? dr.GetInt32("TransferLogID").Value : 0;
base.SetObjectState(loan, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
FmLoan loan = new FmLoan();
MapObject(loan, dr);
return loan as T;
}
#endregion
//Add LoanService
//public void UpdateLoanInfos(TransactionContext tc, List<FmLoan> loans, List<LoanReceiver> loanReceivers)
//{
// try
// {
// foreach (FmLoan loan in loans)
// {
// if (loan.IsModified)
// {
// loan.ModifiedBy = FM.BO.Common.User.CurrentUser.ID;
// loan.ModifiedDate = GlobalFunctions.GetServerDate().Date;
// LoanDA.UpdateLoanInfo(tc, loan);
// }
// foreach (FmLoanSchedule loanSchedule in loan.LoanSchedules)
// {
// if (loanSchedule.IsModified)
// {
// loanSchedule.ModifiedBy = FM.BO.Common.User.CurrentUser.ID;
// loanSchedule.ModifiedDate = GlobalFunctions.GetServerDate().Date;
// LoanScheduleDA.UpdateLoanPaid(tc, loanSchedule);
// }
// }
// }
// foreach (LoanReceiver loanRvr in loanReceivers)
// {
// SaveVoucher(tc, loanRvr.iFASTranObject_glTrans, (int)EnumLoanTransactionType.MonthlyInstallmentRealization);
// }
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
//}
#region Service Implementation
#region Insert
//public void Insert(FmLoan loan, int noOfMonth, DateTime fromMonth, double rate)
//{
// FmLoan oloan = new FmLoan();
// oloan = loan;
// string logstring = string.Empty;
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// if (oloan.IsNew)
// {
// if (oloan.LoanCustomer.IsNew)
// {
// int customerID = tc.GenerateID("LoanCustomer", "CustomerID");
// //int customerID = base.GetNewID(tc, "LoanCustomer", "CustomerID");
// base.SetObjectID(oloan.LoanCustomer, ID.FromInteger(customerID));
// oloan.LoanCustomer.CreatedBy = oloan.CreatedBy;
// oloan.LoanCustomer.CreatedDate = oloan.CreatedDate;
// FmLoanDA.Insert(tc, oloan.LoanCustomer);
// oloan.CustomerID = oloan.LoanCustomer.ID;
// }
// else
// {
// oloan.LoanCustomer.ModifiedBy = oloan.ModifiedBy;
// oloan.LoanCustomer.ModifiedDate = oloan.ModifiedDate;
// LoanDA.Update(tc, oloan.LoanCustomer);
// }
// //10-04--23057246-LS001-001
// //oloan.LoanAccNo = GenerateLoanNo(oloan);
// //oloan.LoanNo = oloan.LoanAccNo;
// int id = tc.GenerateID("Loan", "LoanID");
// base.SetObjectID(oloan, ID.FromInteger(id));
// LoanDA.Insert(tc, oloan);
// // SaveUserRecords(tc, oloan.iFASUserObject_helperForSubsidiarysUpload);
// SaveVoucher(tc, oloan.ForVoucher_glTrans , (int)EnumLoanActivity.LoanIssue);
// LoanDA.UpdateGLTranID(tc,oloan.ID.Integer,oloan.ForVoucher_glTrans[0].ID.Integer);
// LoanTransaction loanTransaction = new LoanTransaction();
// loanTransaction = loanTransaction.CreateLoanTransaction(loanTransaction, oloan.CustomerID, oloan.ID, EnumLoanTransactionType.LoanIssue, oloan.PrincipalAmount, null, oloan.IssueDate, oloan.CreatedBy, oloan.CreatedDate);
// int tranId = tc.GenerateID("LoanTransaction", "LoanTransactionID");
// base.SetObjectID(loanTransaction, ID.FromInteger(tranId));
// LoanTransactionDA.Insert(tc, loanTransaction);
// }
// else if (oloan.IsModified)
// {
// if (oloan.LoanCustomer.IsNew)
// {
// int customerID = tc.GenerateID("LoanCustomer", "CustomerID");
// //int customerID = base.GetNewID(tc, "LoanCustomer", "CustomerID");
// base.SetObjectID(oloan.LoanCustomer, ID.FromInteger(customerID));
// oloan.LoanCustomer.CreatedBy = oloan.CreatedBy;
// oloan.LoanCustomer.CreatedDate = oloan.CreatedDate;
// LoanDA.Insert(tc, oloan.LoanCustomer);
// oloan.CustomerID = oloan.LoanCustomer.ID;
// }
// else
// {
// oloan.LoanCustomer.ModifiedBy = oloan.ModifiedBy;
// oloan.LoanCustomer.ModifiedDate = oloan.ModifiedDate;
// LoanDA.Update(tc, oloan.LoanCustomer);
// }
// LoanDA.Update(tc, oloan);
// SaveVoucher(tc, oloan.ForVoucher_glTrans, (int)EnumLoanActivity.LoanIssue);
// LoanDA.UpdateGLTranID(tc, oloan.ID.Integer, oloan.ForVoucher_glTrans[0].ID.Integer);
// }
// LoanDA.DeleteLoanSchedule(tc, oloan.ID);
// foreach (var item in oloan.LoanSchedules)
// {
// item.ProjectID = oloan.ProjectID;
// item.CustomerID = oloan.CustomerID;
// item.LoanID = oloan.ID;
// item.LoanCategoryID = oloan.LoanCategoryID;
// item.CreatedBy = oloan.CreatedBy;
// item.CreatedDate = oloan.CreatedDate;
// int id = tc.GenerateID("LoanSchedule", "LoanScheduleID");
// base.SetObjectID(item, ID.FromInteger(id));
// LoanDA.Insert(tc, item);
// }
// //logstring = oloan.LoanCategoryID.ToString() + "," + oloan.ID.ToString() + "," + oloan.LoanNo.ToString() + "," + oloan.CustomerID.ToString() + "," + oloan.LoanCustomer.EmpCode.ToString() + "," + oloan.CreatedBy.ToString() + "," + oloan.CreatedDate.ToString() + "," + oloan.Activity.ToString();
// LoanLog loanLog = new LoanLog();
// loanLog = loanLog.CreateLog(loanLog, oloan.LoanCategoryID, oloan.ID, oloan.LoanNo, oloan.CustomerID, oloan.LoanCustomer.EmpCode, oloan.CreatedBy, oloan.CreatedDate, oloan.Activity, noOfMonth, fromMonth, rate);
// int logId = tc.GenerateID("LoanLog", "LogID");
// //int logId = base.GetNewID(tc,"LoanLog", "LogID");
// base.SetObjectID(loanLog, ID.FromInteger(logId));
// LoanDA.Insert(tc, loanLog);
// tc.End();
// CacheInfo.ClearCache(typeof(FmLoanService).FullName);
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
//}
public void Save(FmLoan loan)
{
FmLoan oLoan = new FmLoan();
oLoan = loan;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLoan.IsNew)
{
int id = tc.GenerateID("FmLoan", "LoanID");
base.SetObjectID(oLoan, id);
FmLoanDA.Insert(tc, oLoan);
}
else
{
FmLoanDA.Update(tc, oLoan);
}
tc.End();
//return oLoanTransaction.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void SetLoanStatus()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
FmLoanDA.SetLoanStatus(tc);
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 UpdateSchedules(List<FmLoanSchedule> oloanSchedules, EaseFAS.BO.GLTrans otrans)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// foreach (FmLoanSchedule oitem in oloanSchedules)
// {
// LoanDA.UpdateLoanSchedule(tc, oitem);
// }
// Ease.Core.DataAccess.TransactionContext coretc = Ease.Core.DataAccess.TransactionContext.SetConnection(tc.Connection, tc.Transaction);
// EaseFAS.Service.GLTranService oservice = new EaseFAS.Service.GLTranService();
// oservice.Insert(coretc, otrans);
// 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 UpdateLoanIssueStatus(FmLoan oLoan)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
FmLoanDA.UpdateLoanIssueStatus(tc, oLoan);
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 SaveEarlySettlement(FmLoan oloan, LoanLog loanLog)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// if (oloan.IsModified)
// {
// FmLoanDA.UpdateLoanEarlySettle(tc, oloan);
// SaveVoucher(tc, oloan.iFASTranObject_glTrans, (int)EnumLoanActivity.EarlySettlement);
// }
// bool isEarlySettle = true;
// foreach (var item in oloan.LoanSchedules)
// {
// if (oloan.InstallmentNo > item.SerialNo && item.PayDate == GlobalFunctionDA.ServerDate(tc).Date && item.InstallmentInterest == 0 && item.InstallmentAmount == item.EffectiveBalance)
// //if (oloan.InstallmentNo >= item.SerialNo && item.InstallmentInterest == 0 && item.InstallmentAmount == item.EffectiveBalance)
// {
// item.ModifiedBy = FM.BO.Common.User.CurrentUser.ID;
// item.ModifiedDate = GlobalFunctionDA.ServerDate(tc);
// LoanDA.UpdateLoanSchedule(tc, item);
// isEarlySettle = true;
// }
// else if (isEarlySettle && item.PayDate==null)
// {
// LoanDA.DeleteLoanScheduleByID(tc, item.ID);
// }
// }
// int logId = tc.GenerateID("LoanLog", "LogID");
// //int logId = base.GetNewID(tc, "LoanLog", "LogID");
// base.SetObjectID(loanLog, ID.FromInteger(logId));
// LoanDA.Insert(tc, loanLog);
// LoanDA.UpdateGLTranID(tc, oloan.ID.Integer, oloan.ForVoucher_glTrans[0].ID.Integer);
// //SaveVoucher(tc, oloan.ForVoucher_glTrans, (int)EnumLoanActivity.EarlySettlement);
// tc.End();
// CacheInfo.ClearCache(typeof(FmLoanService).FullName);
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
// }
//public void SaveEarlySettlement(TransactionContext tc, FmLoan oloan, LoanLog loanLog)
//{
// try
// {
// if (oloan.IsModified)
// {
// oloan.ModifiedBy = FM.BO.Common.User.CurrentUser.ID;
// oloan.ModifiedDate = GlobalFunctionDA.ServerDate(tc);
// LoanDA.UpdateLoanEarlySettle(tc, oloan);
// }
// bool isEarlySettle = false;
// foreach (var item in oloan.LoanSchedules)
// {
// //DateTime dTime = GlobalFunctionDA.ServerDate(tc).Date;
// if (oloan.InstallmentNo == item.SerialNo && item.PayDate.Value.Date == GlobalFunctionDA.ServerDate(tc).Date && item.InstallmentInterest == 0 && item.InstallmentAmount == item.EffectiveBalance)
// {
// item.ModifiedBy = FM.BO.Common.User.CurrentUser.ID;
// item.ModifiedDate = GlobalFunctionDA.ServerDate(tc);
// LoanDA.UpdateLoanSchedule(tc, item);
// isEarlySettle = true;
// }
// else if (isEarlySettle && item.PayDate == null)
// {
// LoanDA.DeleteLoanScheduleByID(tc, item.ID);
// }
// }
// if (isEarlySettle)
// {
// int logId = base.GetNewID(tc, "LoanLog", "LogID");
// base.SetObjectID(loanLog, ID.FromInteger(logId));
// loanLog.CreatedBy = FM.BO.Common.User.CurrentUser.ID;
// loanLog.CreatedDate = GlobalFunctionDA.ServerDate(tc);
// LoanDA.Insert(tc, loanLog);
// }
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
//}
#endregion
#region GenerateLoanNo
//public string GenerateLoanNo(FmLoan loan)
//{
// string serial = string.Empty;
// string s = string.Empty;
// TransactionContext tc = null;
// try
// {
// //string year = loan.IssueDate.Year.ToString();
// //year = year.Substring(2);
// //string month = loan.IssueDate.Month.ToString();
// //if (month.Length == 1)
// //{
// // month = "0" + month;
// //}
// //s = year + "-" + month + "-";
// s = "PFLOAN";
// if (loan.LoanCustomer != null && loan.LoanCategoryID != null && !loan.LoanCategoryID.IsUnassigned && loan.LoanCategoryID.Integer > 0)
// {
// //s = s + "-" + loan.LoanCustomer.EmpCode.ToString() + "-" + loan.LoanCategory.LoanCategoryCode.ToString() + "-";
// s = s + "//" + loan.LoanCustomer.EmpCode.ToString() + "/";
// }
// tc = TransactionContext.Begin();
// int serialNo = LoanDA.GenerateLoanNo(tc, loan.MemberID, loan.LoanCategoryID);
// tc.End();
// serialNo = serialNo + 1;
// serial = serialNo.ToString();
// if (serial.Length == 1)
// {
// serial = "00" + serial;
// }
// if (serial.Length == 2)
// {
// serial = "0" + serial;
// }
// serial = s + serial;
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
// return serial;
//}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
FmLoanDA.DeleteLoanSchedule(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Delete " + e.Message);
;
#endregion
}
}
#endregion
//#region ISExist Month
//public bool ISValidMonth(Loan loan, DateTime dt)
//{
// bool exists = false;
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin(true);
// exists = LoanDA.ISValidMonth(tc, loan, dt);
// tc.End();
// }
// catch (Exception e)
// {
// throw new ServiceException("Failed to Check by code" + e.Message, e);
// }
// return exists;
//}
//#endregion
#region Get Loan
public FmLoan Get(string LoanNo)
{
FmLoan loan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FmLoanDA.Get(tc, LoanNo));
if (dr.Read())
{
loan = this.CreateObject<FmLoan>(dr);
}
dr.Close();
LoadSchedule(tc, loan);
LoadCategory(tc, loan);
// LoadCustomer(tc, loan);
tc.End();
//tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loan;
}
public FmLoan Get(int loanID, bool isGetSchedule, bool isGetCategory, bool isGetCustomer)
{
FmLoan loan = new FmLoan();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanDA.Get(tc, loanID));
if (dr.Read())
{
loan = this.CreateObject<FmLoan>(dr);
}
dr.Close();
if (isGetSchedule)
{
LoadSchedule(tc, loan);
}
if (isGetCategory)
{
LoadCategory(tc, loan);
}
//if (isGetCustomer)
//{
// LoadCustomer(tc, loan);
//}
tc.End();
//tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loan;
}
#endregion
public bool GetIsUsedUserObjectName(LoanCategory loanCategory)
{
bool found = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(FmLoanDA.Get(tc, loanCategory));
if (dataReader.Read())
found = true;
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return found;
}
#region Get()
public List<FmLoan> Get()
{
List<FmLoan> loans = new List<FmLoan>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FmLoanDA.Get(tc));
loans = this.CreateObjects<FmLoan>(dr);
dr.Close();
foreach (FmLoan loan in loans)
{
LoadSchedule(tc, loan);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loans;
}
public List<FmLoan> Get(int runningLoan, bool isWithSchedule)
{
List<FmLoan> loans = new List<FmLoan>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(FmLoanDA.Get(tc, runningLoan));
loans = this.CreateObjects<FmLoan>(dr);
dr.Close();
if (isWithSchedule)
{
foreach (FmLoan loan in loans)
{
LoadSchedule(tc, loan);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loans;
}
public List<FmLoan> GetNotSendLoan(int runningLoan, bool isWithSchedule)
{
List<FmLoan> loans = new List<FmLoan>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader dr = new DataReader(FmLoanDA.GetNotSendLoan(tc, runningLoan));
loans = this.CreateObjects<FmLoan>(dr);
dr.Close();
if (isWithSchedule)
{
foreach (FmLoan loan in loans)
{
LoadSchedule(tc, loan);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return loans;
}
#endregion
//#region GetBySearch
//public ObjectsTemplate<Loan> GetBySearch(string sSearch)
//{
// #region Cache Header
// ObjectsTemplate<Loan> loans = _cache["GetBySearch", sSearch] as ObjectsTemplate<Loan>;
// if (loans != null)
// return loans;
// #endregion
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// DataReader dr = new DataReader(LoanDA.GetBySearch(tc, sSearch));
// loans = this.CreateObjects<Loan>(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(loans, "GetBySearch", sSearch);
// #endregion
// return loans;
//}
//#endregion
#region GetLoanMember
//public DataTable GetLoanMember(int loanCategoryID, string issueOperator, DateTime issueFromDate, DateTime issueToDate, string collectionOperator, DateTime collectionFromDate, DateTime collectionToDate, EnumLoanStatus status, int memberID, int custID)
//{
// DataSet ds = new DataSet();
// TransactionContext tc = null;
// try
// {
// string subQuery = string.Empty;
// if (loanCategoryID != null && !loanCategoryID.IsUnassigned && loanCategoryID > 0)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" cat.LoanCategoryID = %n", loanCategoryID);
// }
// if (issueOperator != string.Empty && issueOperator != "None" && issueOperator != "" && issueOperator != "<>")
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.IssueDate " + issueOperator + " %d ", issueFromDate);
// }
// if (issueOperator == "<>")
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.IssueDate Between %d AND %d ", issueFromDate, issueToDate);
// }
// //if (collectionOperator != string.Empty && collectionOperator != "None" && collectionOperator != "" && collectionOperator != "<>")
// //{
// // subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.StartPayBackMonth " + collectionOperator + " %d ", collectionFromDate);
// //}
// //if (issueOperator == "<>")
// //{
// // subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.StartPayBackMonth Between %d AND %d ", collectionFromDate, collectionToDate);
// //}
// string statusClause = string.Empty;
// if (status != EnumLoanStatus.All)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.Status = %n", status);
// }
// string memberClause = string.Empty;
// if (custID > 0)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" cust.CustomerID = %n", custID);
// }
// tc = TransactionContext.Begin(true);
// ds = FmLoanDA.GetLoanMember(tc, subQuery, custID);
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// throw new ServiceException(e.Message, e);
// #endregion
// }
// return ds.Tables[0];
//}
#endregion
#region GetLoanList
//public DataTable GetLoanList(EnumLoanStatus status, int memberID)
//{
// DataSet ds = new DataSet();
// TransactionContext tc = null;
// try
// {
// string subQuery = string.Empty;
// string statusClause = string.Empty;
// if (status != EnumLoanStatus.All)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.Status = %n", status);
// }
// string memberClause = string.Empty;
// if (memberID != null && !memberID.IsUnassigned && memberID > 0)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.MemberID = %n", memberID);
// }
// tc = TransactionContext.Begin(true);
// ds = FmLoanDA.GetLoanList(tc, subQuery);
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// throw new ServiceException(e.Message, e);
// #endregion
// }
// return ds.Tables[0];
//}
//public DataTable GetLoanList(int loanCategoryID, string issueOperator, DateTime issueFromDate, DateTime issueToDate, string collectionOperator, DateTime collectionFromDate, DateTime collectionToDate, EnumLoanIssueStatus status, int memberID)
//{
// DataSet ds = new DataSet();
// TransactionContext tc = null;
// try
// {
// string subQuery = string.Empty;
// if (loanCategoryID != null && !loanCategoryID.IsUnassigned && loanCategoryID > 0)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" cat.LoanCategoryID = %n", loanCategoryID);
// }
// if (issueOperator != string.Empty && issueOperator != "None" && issueOperator != "" && issueOperator != "<>")
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.IssueDate " + issueOperator + " %d ", issueFromDate);
// }
// if (issueOperator == "<>")
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.IssueDate Between %d AND %d ", issueFromDate, issueToDate);
// }
// if (collectionOperator != string.Empty && collectionOperator != "None" && collectionOperator != "" && collectionOperator != "<>")
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.StartPayBackMonth " + collectionOperator + " %d ", collectionFromDate);
// }
// //if (issueOperator == "<>")
// //{
// // subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.StartPayBackMonth Between %d AND %d ", collectionFromDate, collectionToDate);
// //}
// string statusClause = string.Empty;
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.LoanIssueStatus = %n", status);
// string memberClause = string.Empty;
// if (memberID != null && !memberID.IsUnassigned && memberID > 0)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" m.MemberID = %n", memberID);
// }
// tc = TransactionContext.Begin(true);
// ds = FmLoanDA.GetLoanList(tc, subQuery);
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// throw new ServiceException(e.Message, e);
// #endregion
// }
// return ds.Tables[0];
//}
//public DataTable GetLoanList(int loanCategoryID, string issueOperator, DateTime issueFromDate, DateTime issueToDate, string collectionOperator, DateTime collectionFromDate, DateTime collectionToDate, EnumLoanStatus status, int memberID)
//{
// DataSet ds = new DataSet();
// TransactionContext tc = null;
// try
// {
// string subQuery = string.Empty;
// if (loanCategoryID != null && !loanCategoryID.IsUnassigned && loanCategoryID > 0)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" cat.LoanCategoryID = %n", loanCategoryID);
// }
// if (issueOperator != string.Empty && issueOperator != "None" && issueOperator != "" && issueOperator != "<>")
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.IssueDate " + issueOperator + " %d ", issueFromDate);
// }
// if (issueOperator == "<>")
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.IssueDate Between %d AND %d ", issueFromDate, issueToDate);
// }
// //if (collectionOperator != string.Empty && collectionOperator != "None" && collectionOperator != "" && collectionOperator != "<>")
// //{
// // subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.StartPayBackMonth " + collectionOperator + " %d ", collectionFromDate);
// //}
// //if (issueOperator == "<>")
// //{
// // subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.StartPayBackMonth Between %d AND %d ", collectionFromDate, collectionToDate);
// //}
// string statusClause = string.Empty;
// if (status != EnumLoanStatus.All)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" issue.Status = %n", status);
// }
// string memberClause = string.Empty;
// if (memberID != null && !memberID.IsUnassigned && memberID > 0)
// {
// subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL(" m.MemberID = %n", memberID);
// }
// tc = TransactionContext.Begin(true);
// ds = FmLoanDA.GetLoanList(tc, subQuery);
// tc.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// throw new ServiceException(e.Message, e);
// #endregion
// }
// return ds.Tables[0];
//}
#endregion
#region GetTable
public DataTable GetTable(DateTime fromDate, DateTime toDate)
{
DataTable dTbl = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dTbl = FmLoanDA.GetTable(tc, fromDate, toDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dTbl;
}
public DataTable GetTable(string smemberId, DateTime fromDate, DateTime toDate)
{
DataTable dTbl = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dTbl = FmLoanDA.GetTable(tc, smemberId, fromDate, toDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dTbl;
}
public DataTable GetLoanInfoByMonth(DateTime scheduleMonth)
{
DataTable dtLoanScheduleInfo = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
dtLoanScheduleInfo = FmLoanDA.GetLoanInfoByMonth(tc, scheduleMonth);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dtLoanScheduleInfo;
}
public DataSet GetLoans()
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
TransactionContext tc = null;
try
{
ConnectionContext cc = new ConnectionContext("serviceHandler1");
tc = TransactionContext.Begin(true, cc);
ds = FmLoanDA.GetLoans(tc);
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to Get Members" + e.Message, e);
}
return ds;
}
#endregion
#endregion
#region IFASService Members
//public void SaveUserRecords(TransactionContext tc, List<HelperForSubsidiaryUpload> subsidiarysUpload)
//{
// UserRecordService userRecordService = new UserRecordService();
// foreach (HelperForSubsidiaryUpload subUpload in subsidiarysUpload)
// {
// if (subUpload.UserRcds.Count > 0)
// {
// foreach (UserRecord userRecord in subUpload.UserRcds)
// {
// _uploadedUserRecordID = userRecordService.Insert(tc, userRecord);
// }
// }
// }
//}
//public void SaveVoucher(TransactionContext tc, EaseFAS.BO.GLTrans glTrans, int systemTranIDinInt)
//{
// EaseFAS.Service.GLTranService glTranService = new EaseFAS.Service.GLTranService();
// Ease.Core.DataAccess.TransactionContext tcore = Ease.Core.DataAccess.TransactionContext.SetConnection(tc.Connection, tc.Transaction);
// glTranService.Insert(tcore, glTrans);
//}
#endregion
internal void Delete(TransactionContext tc, Loan loan)
{
try
{
FmLoanDA.DeleteLoanLog(tc, loan.ID);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
}
}