HRM-10/HRM.DA/Service/Fund/MemberInfo/WPPFSettlementService.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

488 lines
20 KiB
C#

using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
using System.Linq;
namespace HRM.DA
{
[Serializable]
public class WPPFSettlementService : ServiceTemplate, IWPPFSettlementService
{
public WPPFSettlementService()
{
}
#region Private methods
private void MapObject(WPPFSettlement oWPPFSettlement, DataReader oReader)
{
base.SetObjectID(oWPPFSettlement, oReader.GetInt32("WPPFSettlementID").Value);
oWPPFSettlement.MemberID = oReader.GetInt32("MemberID").Value;
oWPPFSettlement.GLTranID = oReader.GetInt32("GLTranID").Value;
oWPPFSettlement.GLTranInterestID = oReader.GetInt32("GLTranInterestID").Value;
oWPPFSettlement.SettlementDate = oReader.GetDateTime("SettlementDate").Value;
oWPPFSettlement.WPPFAmount = oReader.GetDecimal("WPPFAmount").Value;
oWPPFSettlement.WPPFInterest = oReader.GetDecimal("WPPFInterest").Value;
oWPPFSettlement.VoucherDate = oReader.GetDateTime("VoucherDate").Value;
oWPPFSettlement.ServiceLength = oReader.GetDecimal("ServiceLength").Value;
oWPPFSettlement.Remarks = oReader.GetString("Remarks").ToString();
oWPPFSettlement.CheckNo = oReader.GetString("CheckNo").ToString();
oWPPFSettlement.CheckDate = oReader.GetDateTime("CheckDate") != null? oReader.GetDateTime("CheckDate").Value : DateTime.MinValue ;
oWPPFSettlement.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oWPPFSettlement.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oWPPFSettlement.ModifiedDate = oReader.GetDateTime("ModifiedDate") != null ? oReader.GetDateTime("ModifiedDate").Value : DateTime.MinValue;
oWPPFSettlement.ModifiedBy = oReader.GetInt32("ModifiedBy") != null ? oReader.GetInt32("ModifiedBy").Value: 0;
base.SetObjectState(oWPPFSettlement, ObjectState.Saved);
}
private WPPFSettlement CreateObject(DataReader oReader)
{
WPPFSettlement oWPPFSettlement = new WPPFSettlement();
MapObject(oWPPFSettlement, oReader);
return oWPPFSettlement;
}
private List<WPPFSettlement> CreateObjects(IDataReader oReader)
{
List<WPPFSettlement> oWPPFSettlements = new List<WPPFSettlement>();
DataReader oreader = new DataReader(oReader);
while (oReader.Read())
{
WPPFSettlement oItem = CreateObject(oreader);
oWPPFSettlements.Add(oItem);
}
return oWPPFSettlements;
}
#endregion Private methods
#region Service implementation
protected override T CreateObject<T>(DataReader dataReader)
{
WPPFSettlement oWPPFSettlement = new WPPFSettlement();
MapObject(oWPPFSettlement, dataReader);
return oWPPFSettlement as T;
}
public WPPFSettlement Get(int id)
{
WPPFSettlement oWPPFSettlement = new WPPFSettlement();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WPPFSettlementDA.Get(tc, id));
if (dr.Read())
{
oWPPFSettlement = this.CreateObject<WPPFSettlement>(dr);
}
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetFinalSettlement", e);
#endregion
}
#region Cache Footer
#endregion
return oWPPFSettlement;
}
public List<WPPFSettlement> GetByMemberID(int memberID)
{
List<WPPFSettlement> oWPPFSettlement = new List<WPPFSettlement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WPPFSettlementDA.GetByMemberID(tc, memberID));
oWPPFSettlement = this.CreateObjects<WPPFSettlement>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetFinalSettlement", e);
#endregion
}
#region Cache Footer
#endregion
return oWPPFSettlement;
}
public List<WPPFSettlement> Get()
{
List<WPPFSettlement> oWPPFSettlements = new List<WPPFSettlement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(WPPFSettlementDA.Get(tc));
while (dataReader.Read())
{
WPPFSettlement item = new WPPFSettlement();
item = this.CreateObject<WPPFSettlement>(dataReader);
oWPPFSettlements.Add(item);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetFinalSettlement", e);
#endregion
}
#region Cache Footer
#endregion
return oWPPFSettlements;
}
public List<WPPFSettlement> Get(DateTime fromDate, DateTime toDate, int fundTypeID)
{
List<WPPFSettlement> oWPPFSettlements = new List<WPPFSettlement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(WPPFSettlementDA.Get(tc, fromDate, toDate, fundTypeID));
while (dataReader.Read())
{
WPPFSettlement item = new WPPFSettlement();
item = this.CreateObject<WPPFSettlement>(dataReader);
oWPPFSettlements.Add(item);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetFinalSettlement", e);
#endregion
}
#region Cache Footer
#endregion
return oWPPFSettlements;
}
public List<WPPFSettlement> Get(string sSql)
{
List<WPPFSettlement> oWPPFSettlements = new List<WPPFSettlement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(WPPFSettlementDA.Get(tc, sSql));
while (dataReader.Read())
{
WPPFSettlement item = this.CreateObject<WPPFSettlement>(dataReader);
oWPPFSettlements.Add(item);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetFinalSettlement", e);
#endregion
}
return oWPPFSettlements;
}
//public void Insert(WPPFSettlement oWPPFSettlement, GLTran glTran, List<MembersTransactionDetails> memberTrans, List<MemberBalaneMonthly> membersMonthlyBalances)
//{
// TransactionContext tc = null;
// Ease.Core.DataAccess.TransactionContext tc1 = null;
// try
// {
// tc = TransactionContext.Begin(true);
// tc1 = Ease.Core.DataAccess.TransactionContext.Begin(true);
// EaseFAS.Service.GLTranService glTranService = new EaseFAS.Service.GLTranService();
// MembersTransactionDetailsService meberTranDetailService = new MembersTransactionDetailsService();
// Ease.Core.Framework.ID glTranID = null;
// glTranID = glTranService.Insert(glTran, tc1);
// if (oWPPFSettlement.IsNew)
// {
// oWPPFSettlement.CreatedBy = User.CurrentUser.ID;
// oWPPFSettlement.CreatedDate = GlobalFunctionDA.ServerDate(tc);
// int id = tc.GenerateID("WPPFSettlement", "WPPFSettlementID");
// base.SetObjectID(oWPPFSettlement, (id));
// oWPPFSettlement.GLTranID = Ease.CoreV35.Model.(glTranID);
// WPPFSettlementDA.Insert(tc, oWPPFSettlement);
// }
// else if (oWPPFSettlement.IsModified)
// {
// oWPPFSettlement.ModifiedBy = User.CurrentUser.ID;
// oWPPFSettlement.ModifiedDate = new PayrollGlobalFunctionservice().GetServerDate().Date;
// WPPFSettlementDA.Update(tc, oWPPFSettlement);
// }
// meberTranDetailService.UploadOpeningTranForGF(tc, memberTrans, membersMonthlyBalances);
// tc.End();
// tc1.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// if (tc1 != null)
// tc1.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException("Failed to Insert GF settlement: " + e.Message);
// #endregion
// }
//}
//public void Insert(WPPFSettlement oWPPFSettlement, GLTran glTran, GLTran glTranInterest, List<MembersTransactionDetails> memberTrans, List<MemberBalaneMonthly> membersMonthlyBalances)
//{
// TransactionContext tc = null;
// Ease.Core.DataAccess.TransactionContext tc1 = null;
// try
// {
// tc = TransactionContext.Begin(true);
// tc1 = Ease.Core.DataAccess.TransactionContext.Begin(true);
// EaseFAS.Service.GLTranService glTranService = new EaseFAS.Service.GLTranService();
// MembersTransactionDetailsService meberTranDetailService = new MembersTransactionDetailsService();
// Ease.Core.Framework.ID glTranID = null;
// Ease.Core.Framework.ID glTranInterestID = null;
// glTranID = glTranService.Insert(glTran, tc1);
// if (glTranInterest != null && glTranInterest.DebitAmount > 0)
// glTranInterestID = glTranService.Insert(glTranInterest, tc1);
// else
// glTranInterestID = Ease.Core.Framework.(0);
// if (oWPPFSettlement.IsNew)
// {
// oWPPFSettlement.CreatedBy = User.CurrentUser.ID;
// oWPPFSettlement.CreatedDate = GlobalFunctionDA.ServerDate(tc);
// int id = tc.GenerateID("WPPFSettlement", "WPPFSettlementID");
// base.SetObjectID(oWPPFSettlement, (id));
// oWPPFSettlement.GLTranID = Ease.CoreV35.Model.(glTranID);
// oWPPFSettlement.GLTranInterestID = Ease.CoreV35.Model.(glTranInterestID);
// WPPFSettlementDA.Insert(tc, oWPPFSettlement);
// }
// else if (oWPPFSettlement.IsModified)
// {
// oWPPFSettlement.ModifiedBy = User.CurrentUser.ID;
// oWPPFSettlement.ModifiedDate = new PayrollGlobalFunctionservice().GetServerDate().Date;
// WPPFSettlementDA.Update(tc, oWPPFSettlement);
// }
// meberTranDetailService.UploadOpeningTranForGF(tc, memberTrans, membersMonthlyBalances);
// tc.End();
// tc1.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// if (tc1 != null)
// tc1.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException("Failed to Insert GF settlement: " + e.Message);
// #endregion
// }
//}
public void Save(WPPFSettlement oWPPFSettlement)
{
TransactionContext tc = null;
try
{
List<ActivityVoucherSetup> activityVoucherSetup = new ActivityVoucherSetupService().GetByProcessType(
oWPPFSettlement.FundTypeID, EnumFundProcessType.Final_Settlement_Of_WPPF);
Member oMember = new MemberService().Get(oWPPFSettlement.MemberID);
UserRecord newItem = new UserRecordService().GetByField1(oMember.EmpCode,
GlobalFunctions.Fund_UserObject_Member, oWPPFSettlement.FundTypeID);
GLTran otran = new GLTran();
otran.VoucherDate = oWPPFSettlement.VoucherDate;
otran.ChequeDate = (DateTime)oWPPFSettlement.SettlementDate;
otran.CreatedDate = DateTime.Now;
otran.CreatedBy = oWPPFSettlement.CreatedBy;
otran.ChequeNo = oWPPFSettlement.CheckNo;
otran.GLTranType = EnumGLTranType.GratuitySettlement;
otran.FundTypeID = oWPPFSettlement.FundTypeID;
otran.Description = "WPPF FinalSettlement :" + oMember.EmpCode;
ActivityVoucherSetup activityVoucher = activityVoucherSetup.FirstOrDefault(x =>
x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Ex_Member);
if (activityVoucher == null)
{
throw new Exception("There is no Ex_Member GL in voucher setup");
}
GL ogl = new GLService().Get(activityVoucher.GLID);
GLTranDetail outGoingMemberGL = new GLTranDetail();
outGoingMemberGL.Transide = activityVoucher.GLSide;
outGoingMemberGL.Amount = (double)oWPPFSettlement.WPPFAmount;
outGoingMemberGL.GLID = ogl.ID;
otran.GlTranDetails = new List<GLTranDetail>();
otran.GlTranDetails.Add(outGoingMemberGL);
if (ogl.UserObjectID != null)
{
GLTranUserRecord orc = new GLTranUserRecord();
orc.Amount = (double?)oWPPFSettlement.WPPFAmount;
orc.UserObject1ID = GlobalFunctions.Fund_UserObject_Loan;
orc.GLID = outGoingMemberGL.GLID;
orc.UserRecord1ID = newItem.ID;
outGoingMemberGL.GLTranUserRecords = new List<GLTranUserRecord>();
outGoingMemberGL.GLTranUserRecords.Add(orc);
}
ActivityVoucherSetup PrincipalSetup = activityVoucherSetup.FirstOrDefault(x =>
x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra);
if (PrincipalSetup == null)
{
// if there is no GL throw exception
throw new Exception("There is no Contra GL found in the setup");
}
ogl = new GLService().Get(PrincipalSetup.GLID);
GLTranDetail bankGL = new GLTranDetail();
bankGL.Transide = PrincipalSetup.GLSide;
bankGL.Amount = (double)oWPPFSettlement.WPPFAmount;
bankGL.GLID = ogl.ID;
otran.GlTranDetails.Add(bankGL);
otran.DebitAmount = otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Debit).Sum(x => x.Amount);
otran.CreditAmount = otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Credit).Sum(x => x.Amount);
oMember.MemberStatus = EnumEmpStatus.Setteled;
oMember.FinalSettlementDate = oWPPFSettlement.SettlementDate;
oMember.DOL = oWPPFSettlement.SettlementDate;
tc = TransactionContext.Begin(true);
int glTranID = new GLTranService().Save(tc, otran);
oWPPFSettlement.GLTranID = glTranID;
if (oWPPFSettlement.IsNew)
{
oWPPFSettlement.CreatedBy = oWPPFSettlement.CreatedBy;
oWPPFSettlement.CreatedDate = DateTime.Now;
int id = tc.GenerateID("FM_WPPFSettlement", "WPPFSettlementID");
base.SetObjectID(oWPPFSettlement, (id));
WPPFSettlementDA.Insert(tc, oWPPFSettlement);
}
else
{
oWPPFSettlement.ModifiedBy = oWPPFSettlement.ModifiedBy;
oWPPFSettlement.ModifiedDate = DateTime.Now;
WPPFSettlementDA.Update(tc, oWPPFSettlement);
}
new MemberService().UpdateSettlement(tc,oMember);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Insert GF settlement: " + e.Message);
#endregion
}
}
public void DeleteSettlement(WPPFSettlement gfSettlement)
{
throw new NotImplementedException();
}
//public void DeleteSettlement(WPPFSettlement gfSettlement)
//{
// int projectID = FM.BO.Common.User.CurrentMasterParam.ID;
// TransactionContext tc = null;
// decimal totalAmount = gfSettlement.WPPFAmount + gfSettlement.WPPFInterest;
// Ease.Core.DataAccess.TransactionContext tc1 = null;
// try
// {
// tc = TransactionContext.Begin(true);
// tc1 = Ease.Core.DataAccess.TransactionContext.Begin(true);
// EaseFAS.Service.GLTranService glTranService = new EaseFAS.Service.GLTranService();
// glTranService.Delete(tc1, Ease.Core.Framework.(gfSettlement.GLTranID));
// MembersTransactionDetailsDA.DeleteGFMemberSettlement(tc, gfSettlement.MemberID, gfSettlement.SettlementDate.Date, gfSettlement.WPPFAmount, projectID);
// MembersTransactionDetailsDA.DeleteGFMemberSettlement(tc, gfSettlement.MemberID, gfSettlement.SettlementDate.Date, gfSettlement.WPPFInterest, projectID);
// MemberBalaneMonthlyDA.DeleteGFSettlementData(tc, gfSettlement.MemberID, gfSettlement.SettlementDate.Date, projectID, totalAmount);
// WPPFSettlementDA.Delete(tc, gfSettlement.ID);
// tc.End();
// tc1.End();
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// if (tc1 != null)
// tc1.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException("Failed to Delete WPPFSettlement" + e.Message);
// #endregion
// }
//}
#endregion Service implementation
}
}