368 lines
13 KiB
C#
368 lines
13 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 HRM.DA;
|
|
using HRM.BO.Fund;
|
|
using System.Linq;
|
|
|
|
|
|
namespace HRM.DA.Fund
|
|
{
|
|
[Serializable]
|
|
public class GFSettlementService : ServiceTemplate, IGFSettlementService
|
|
{
|
|
public GFSettlementService()
|
|
{
|
|
}
|
|
|
|
#region Private methods
|
|
|
|
private void MapObject(GFSettlement oGFSettlement, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oGFSettlement, oReader.GetInt32("GFSettlementID").Value);
|
|
oGFSettlement.MemberID = oReader.GetInt32("MemberID").Value;
|
|
oGFSettlement.GLTranID = oReader.GetInt32("GLTranID").Value;
|
|
oGFSettlement.GLTranInterestID = oReader.GetInt32("GLTranInterestID").Value;
|
|
oGFSettlement.SettlementDate = oReader.GetDateTime("SettlementDate").Value;
|
|
oGFSettlement.GFAmount = oReader.GetDecimal("GFAmount").Value;
|
|
oGFSettlement.GFInterest = oReader.GetDecimal("GFInterest").Value;
|
|
oGFSettlement.SeparationMode = oReader.GetInt32("SeperationMode").HasValue ? oReader.GetInt32("SeperationMode") : 0;
|
|
oGFSettlement.ExitNoticeDate = oReader.GetDateTime("ExitNoticeDate").HasValue ? oReader.GetDateTime("ExitNoticeDate") : DateTime.MinValue;
|
|
oGFSettlement.LastWorkingDay = oReader.GetDateTime("LastWorkingDay").HasValue ? oReader.GetDateTime("LastWorkingDay") : DateTime.MinValue;
|
|
oGFSettlement.TerminationEffectiveDate = oReader.GetDateTime("TerminationEffectiveDate").HasValue ? oReader.GetDateTime("TerminationEffectiveDate") : DateTime.MinValue;
|
|
oGFSettlement.NoticePeriodEndDate = oReader.GetDateTime("NoticePeriodEndDate").HasValue ? oReader.GetDateTime("NoticePeriodEndDate") : DateTime.MinValue;
|
|
oGFSettlement.NoticePeriodRequired = oReader.GetInt32("NoticePeriodRequired").HasValue ? oReader.GetInt32("NoticePeriodRequired") : -1;
|
|
oGFSettlement.NoticePeriodGiven = oReader.GetInt32("NoticePeriodGiven").HasValue ? oReader.GetInt32("NoticePeriodGiven") : -1;
|
|
oGFSettlement.LengthOfService = oReader.GetDecimal("LengthOfService").HasValue ? oReader.GetDecimal("LengthOfService") : -1;
|
|
oGFSettlement.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oGFSettlement.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|
oGFSettlement.ModifiedDate = oReader.GetDateTime("ModifiedDate") != null
|
|
? oReader.GetDateTime("ModifiedDate").Value
|
|
: DateTime.MinValue; //oReader.GetDateTime("ModifiedDate");
|
|
oGFSettlement.ModifiedBy = oReader.GetInt32("ModifiedBy") != null
|
|
? oReader.GetInt32("ModifiedBy").Value : (0); // oReader.GetInt32("ModifiedBy");
|
|
base.SetObjectState(oGFSettlement, ObjectState.Saved);
|
|
}
|
|
|
|
private GFSettlement CreateObject(DataReader oReader)
|
|
{
|
|
GFSettlement oGFSettlement = new GFSettlement();
|
|
MapObject(oGFSettlement, oReader);
|
|
return oGFSettlement;
|
|
}
|
|
|
|
private List<GFSettlement> CreateObjects(IDataReader oReader)
|
|
{
|
|
List<GFSettlement> oGFSettlements = new List<GFSettlement>();
|
|
DataReader oreader = new DataReader(oReader);
|
|
while (oReader.Read())
|
|
{
|
|
GFSettlement oItem = CreateObject(oreader);
|
|
oGFSettlements.Add(oItem);
|
|
}
|
|
|
|
return oGFSettlements;
|
|
}
|
|
|
|
#endregion Private methods
|
|
|
|
|
|
#region Service implementation
|
|
|
|
protected override T CreateObject<T>(DataReader dataReader)
|
|
{
|
|
GFSettlement oGFSettlement = new GFSettlement();
|
|
|
|
MapObject(oGFSettlement, dataReader);
|
|
|
|
return oGFSettlement as T;
|
|
}
|
|
|
|
public GFSettlement Get(int id)
|
|
{
|
|
GFSettlement oGFSettlement = new GFSettlement();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(GFSettlementDA.Get(tc, id));
|
|
if (dr.Read())
|
|
{
|
|
oGFSettlement = this.CreateObject<GFSettlement>(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 oGFSettlement;
|
|
}
|
|
|
|
public GFSettlement GetByMemberID(int memberID)
|
|
{
|
|
GFSettlement oGFSettlement = new GFSettlement();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(GFSettlementDA.GetByMemberID(tc, memberID));
|
|
if (dr.Read())
|
|
{
|
|
oGFSettlement = this.CreateObject<GFSettlement>(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 oGFSettlement;
|
|
}
|
|
|
|
public List<GFSettlement> Get(DateTime fromDate, DateTime toDate, int fundTypeID)
|
|
{
|
|
List<GFSettlement> oGFSettlements = new List<GFSettlement>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dataReader = new DataReader(GFSettlementDA.Get(tc, fromDate, toDate, fundTypeID));
|
|
while (dataReader.Read())
|
|
{
|
|
GFSettlement item = new GFSettlement();
|
|
item = this.CreateObject<GFSettlement>(dataReader);
|
|
item.Member = new MemberService().Get(item.MemberID);
|
|
oGFSettlements.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 oGFSettlements;
|
|
}
|
|
|
|
public List<GFSettlement> Get()
|
|
{
|
|
List<GFSettlement> oGFSettlements = new List<GFSettlement>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dataReader = new DataReader(GFSettlementDA.Get(tc));
|
|
while (dataReader.Read())
|
|
{
|
|
GFSettlement item = new GFSettlement();
|
|
item = this.CreateObject<GFSettlement>(dataReader);
|
|
oGFSettlements.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 oGFSettlements;
|
|
}
|
|
|
|
public List<GFSettlement> Get(string sSql)
|
|
{
|
|
List<GFSettlement> oGFSettlements = new List<GFSettlement>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dataReader = new DataReader(GFSettlementDA.Get(tc, sSql));
|
|
while (dataReader.Read())
|
|
{
|
|
GFSettlement item = this.CreateObject<GFSettlement>(dataReader);
|
|
oGFSettlements.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 oGFSettlements;
|
|
}
|
|
|
|
public void Save(GFSettlement item, Member member)
|
|
{
|
|
GFSettlement gFSettlement = new GFSettlement();
|
|
gFSettlement = item;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
|
|
//voucher setup
|
|
List<ActivityVoucherSetup> activityVoucherSetup = new ActivityVoucherSetupService().GetByProcessType(
|
|
item.FundTypeID, EnumFundProcessType.Final_Settlement_Of_GF);
|
|
Member oMember = new MemberService().Get(item.MemberID);
|
|
UserRecord newItem = new UserRecordService().GetByField1(oMember.EmpCode,
|
|
GlobalFunctions.Fund_UserObject_Member, item.FundTypeID);
|
|
|
|
GLTran otran = new GLTran();
|
|
otran.VoucherDate = item.VoucherDate;
|
|
otran.ChequeDate = (DateTime)item.SettlementDate;
|
|
otran.CreatedDate = DateTime.Now;
|
|
otran.CreatedBy = item.CreatedBy;
|
|
otran.ChequeNo = item.CheckNo;
|
|
otran.GLTranType = EnumGLTranType.GratuitySettlement;
|
|
otran.FundTypeID = item.FundTypeID;
|
|
otran.Description = "GF 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)item.GFAmount;
|
|
outGoingMemberGL.GLID = ogl.ID;
|
|
otran.GlTranDetails = new List<GLTranDetail>();
|
|
otran.GlTranDetails.Add(outGoingMemberGL);
|
|
if (ogl.UserObjectID != null)
|
|
{
|
|
GLTranUserRecord orc = new GLTranUserRecord();
|
|
orc.Amount = (double?)item.GFAmount;
|
|
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)item.GFAmount;
|
|
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);
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
if (gFSettlement.IsNew)
|
|
{
|
|
int id = tc.GenerateID("FM_GFSettlement", "GFSETTLEMENTID");
|
|
base.SetObjectID(gFSettlement, id);
|
|
GFSettlementDA.Insert(tc, gFSettlement);
|
|
}
|
|
else
|
|
{
|
|
GFSettlementDA.Update(tc, gFSettlement);
|
|
}
|
|
new GLTranService().Save(tc, otran);
|
|
new MemberService().UpdateSettlement(tc, member);
|
|
tc.End();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|
|
#endregion Service implementation
|
|
}
|
|
} |