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.Fund { [Serializable] public class PFFinalSettlementService : ServiceTemplate,IPFFinalSettlementService { public PFFinalSettlementService() { } #region Private methods private void MapObject(PFFinalSettlement oFinalSettlement, DataReader oReader) { base.SetObjectID(oFinalSettlement, oReader.GetInt32("FinalSettlementID").Value); //BusinessObject.Factory.SetID(oFinalSettlement, new ID(oReader.Getint("FinalSettlementID"))); oFinalSettlement.MemberID = oReader.GetInt32("MemberID").Value; oFinalSettlement.EmpCode = oReader.GetString("EmpCode"); oFinalSettlement.SettlementDate = oReader.GetDateTime("SettlementDate").Value; oFinalSettlement.TotalPayment = oReader.GetDouble("TotalPayment").Value; oFinalSettlement.PaymentMode = oReader.GetString("PaymentMode"); oFinalSettlement.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oFinalSettlement.CreatedBy = oReader.GetInt32("CreatedBy").Value; oFinalSettlement.ModifiedDate = oReader.GetDateTime("ModifiedDate") != null ? oReader.GetDateTime("ModifiedDate").Value : DateTime.MinValue; oFinalSettlement.ModifiedBy = oReader.GetInt32("ModifiedBy"); oFinalSettlement.GLTranID = oReader.GetInt32("GLTranID").Value; oFinalSettlement.LastAudCPF = oReader.GetDouble("LastAudCPF").GetValueOrDefault(); oFinalSettlement.LastAudEPF = oReader.GetDouble("LastAudEPF").GetValueOrDefault(); oFinalSettlement.LastAudCPFInterest = oReader.GetDouble("LastAudCPFInterest").GetValueOrDefault(); oFinalSettlement.LastAudEPFInterest = oReader.GetDouble("LastAudEPFInterest").GetValueOrDefault(); oFinalSettlement.LastAudCurrentEPFInterest = oReader.GetDouble("LastAudCurrentEPFInterest").GetValueOrDefault(); oFinalSettlement.LastAudCurrentCPFInterest = oReader.GetDouble("LastAudCurrentCPFInterest").GetValueOrDefault(); oFinalSettlement.CurrYearEPF = oReader.GetDouble("CurrYearEPF").GetValueOrDefault(); oFinalSettlement.CurrYearCPF = oReader.GetDouble("CurrYearCPF").GetValueOrDefault(); oFinalSettlement.CurrYearEPFInterest = oReader.GetDouble("CurrYearEPFInterest").GetValueOrDefault(); oFinalSettlement.CurrYearCPFInterest = oReader.GetDouble("CurrYearCPFInterest").GetValueOrDefault(); oFinalSettlement.CurrYearInterestPercent = oReader.GetDouble("CurrYearInterestPercent").GetValueOrDefault(); oFinalSettlement.LoanAmount = oReader.GetInt32("loanAmount").Value; oFinalSettlement.loanPrincipalRecovered = oReader.GetDouble("loanPrincipalRecovered").GetValueOrDefault(); oFinalSettlement.loanInterestRecovered = oReader.GetDouble("loanInterestRecovered").GetValueOrDefault(); oFinalSettlement.loanid = oReader.GetInt32("loanid"); base.SetObjectState(oFinalSettlement, ObjectState.Saved); } private PFFinalSettlement CreateObject(DataReader oReader) { PFFinalSettlement oFinalSettlement = new PFFinalSettlement(); MapObject(oFinalSettlement, oReader); return oFinalSettlement; } private List CreateObjects(IDataReader oReader) { List oFinalSettlements = new List(); DataReader oreader = new DataReader(oReader); while (oReader.Read()) { PFFinalSettlement oItem = CreateObject(oreader); oFinalSettlements.Add(oItem); } return oFinalSettlements; } #endregion Private methods #region Service implementation protected override T CreateObject(DataReader dataReader) { PFFinalSettlement oFinalSettlement = new PFFinalSettlement(); MapObject(oFinalSettlement, dataReader); return oFinalSettlement as T; } public PFFinalSettlement Get(int id) { PFFinalSettlement oFinalSettlement = new PFFinalSettlement(); #region Cache Header oFinalSettlement = new PFFinalSettlement(); if (oFinalSettlement != null) return oFinalSettlement; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FinalSettlementDA.Get(tc, id)); if (dr.Read()) { oFinalSettlement = this.CreateObject(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 oFinalSettlement; } public List GetbyFundType(int fundtypeid) { List oFinalSettlements = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader dataReader = FinalSettlementDA.GetbyFundType(tc,fundtypeid); oFinalSettlements = this.CreateObjects(dataReader); 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 oFinalSettlements; } //public List Get(string sSql) //{ // List oFinalSettlements = new List(); // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dataReader = new DataReader(FinalSettlementDA.Get(tc, sSql)); // while (dataReader.Read()) // { // PFFinalSettlement item = this.CreateObject(dataReader); // oFinalSettlements.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 oFinalSettlements; //} public void Save(PFFinalSettlement oFinalSettlement) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oFinalSettlement.IsNew) { oFinalSettlement.CreatedBy = oFinalSettlement.CreatedBy; oFinalSettlement.CreatedDate = DateTime.Now; int id = tc.GenerateID("FinalSettlement", "FinalSettlementID"); base.SetObjectID(oFinalSettlement, (id)); FinalSettlementDA.Insert(tc, oFinalSettlement); } else { oFinalSettlement.ModifiedBy = oFinalSettlement.ModifiedBy; oFinalSettlement.ModifiedDate = DateTime.Now; FinalSettlementDA.Update(tc, oFinalSettlement); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetFinalSettlement", e); #endregion } } public void SaveWithVoluntary(PFFinalSettlement oFinalSettlement) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oFinalSettlement.IsNew) { oFinalSettlement.CreatedBy = oFinalSettlement.CreatedBy; oFinalSettlement.CreatedDate = DateTime.Now; int id = tc.GenerateID("FinalSettlement", "FinalSettlementID"); base.SetObjectID(oFinalSettlement, (id)); FinalSettlementDA.InsertWithVoluntary(tc, oFinalSettlement); } else { oFinalSettlement.ModifiedBy = oFinalSettlement.ModifiedBy; oFinalSettlement.ModifiedDate = DateTime.Now; FinalSettlementDA.Update(tc, oFinalSettlement); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetFinalSettlement", e); #endregion } } public void SaveWithVoluntary(TransactionContext tc, PFFinalSettlement oFinalSettlement) { try { if (oFinalSettlement.IsNew) { oFinalSettlement.CreatedBy = oFinalSettlement.CreatedBy; oFinalSettlement.CreatedDate = DateTime.Now; int id = tc.GenerateID("FM_FinalSettlement", "FinalSettlementID"); base.SetObjectID(oFinalSettlement, (id)); FinalSettlementDA.InsertWithVoluntary(tc, oFinalSettlement); } else { oFinalSettlement.ModifiedBy = oFinalSettlement.ModifiedBy; oFinalSettlement.ModifiedDate = DateTime.Now; FinalSettlementDA.UpdateWithVoluntary(tc, oFinalSettlement); } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetFinalSettlement", e); #endregion } } internal void Save(TransactionContext tc, PFFinalSettlement oFinalSettlement) { try { if (oFinalSettlement.IsNew) { oFinalSettlement.CreatedBy = oFinalSettlement.CreatedBy; oFinalSettlement.CreatedDate = DateTime.Now; int id = tc.GenerateID("FM_FinalSettlement", "FinalSettlementID"); base.SetObjectID(oFinalSettlement, (id)); FinalSettlementDA.Insert(tc, oFinalSettlement); } else { oFinalSettlement.ModifiedBy = oFinalSettlement.ModifiedBy; oFinalSettlement.ModifiedDate = DateTime.Now; FinalSettlementDA.Update(tc, oFinalSettlement); } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Insert Final settlement: " + e.Message); #endregion } } private List PrepareMemberTran(PFFinalSettlement finalSettlement, Member member) { #region interest receive List items = new List(); MembersTransactionDetail LastYearBalEPFInterest = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EPF_Interest, finalSettlement.LastAudCurrentEPFInterest + finalSettlement.CurrYearEPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Increase, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(LastYearBalEPFInterest); MembersTransactionDetail LastYearBalCPFInterest = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.CPF_Interest, finalSettlement.LastAudCurrentCPFInterest + finalSettlement.CurrYearCPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Increase, finalSettlement.CreatedBy, EnumFundCategory.CPF); items.Add(LastYearBalCPFInterest); #endregion interest receive MembersTransactionDetail EPFWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EFP_WithDrawl, finalSettlement.LastAudEPF + finalSettlement.CurrYearEPF, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(EPFWithDrawl); MembersTransactionDetail CPFWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.CPF_WithDrawl, finalSettlement.LastAudCPF + finalSettlement.CurrYearCPF, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.CPF); items.Add(CPFWithDrawl); MembersTransactionDetail EPFInterestWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EPF_WithDrawl_Interest, finalSettlement.LastAudEPFInterest + finalSettlement.LastAudCurrentEPFInterest + finalSettlement.CurrYearEPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(EPFInterestWithDrawl); MembersTransactionDetail CPFInterestWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EPF_WithDrawl_Interest, finalSettlement.LastAudCPFInterest + finalSettlement.LastAudCurrentCPFInterest + finalSettlement.CurrYearCPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(CPFInterestWithDrawl); return items; } private List PrepareMemberTranWithVoluntary(PFFinalSettlement finalSettlement, Member member) { #region interest receive List items = new List(); //epf_interest MembersTransactionDetail LastYearBalEPFInterest = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EPF_Interest, finalSettlement.LastAudCurrentEPFInterest + finalSettlement.CurrYearEPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Increase, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(LastYearBalEPFInterest); //voluntary_interest MembersTransactionDetail LastYearBalVoluntaryEPFInterest = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.Voluntary_Interest, finalSettlement.LastAudCurrentVoluntaryEPFInterest + finalSettlement.CurrYearVoluntaryEPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Increase, finalSettlement.CreatedBy, EnumFundCategory.Voluntary); items.Add(LastYearBalVoluntaryEPFInterest); //cpf_interest MembersTransactionDetail LastYearBalCPFInterest = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.CPF_Interest, finalSettlement.LastAudCurrentCPFInterest + finalSettlement.CurrYearCPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Increase, finalSettlement.CreatedBy, EnumFundCategory.CPF); items.Add(LastYearBalCPFInterest); #endregion interest receive //epf_withdrawal MembersTransactionDetail EPFWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EFP_WithDrawl, finalSettlement.LastAudEPF + finalSettlement.CurrYearEPF, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(EPFWithDrawl); //voluntary withdrawal MembersTransactionDetail VoluntaryEPFWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.Voluntary_Withdrawal, finalSettlement.LastAudVoluntaryEPF + finalSettlement.CurrYearVoluntaryEPF, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.Voluntary); items.Add(VoluntaryEPFWithDrawl); // cpf withdrawal MembersTransactionDetail CPFWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.CPF_WithDrawl, finalSettlement.LastAudCPF + finalSettlement.CurrYearCPF, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.CPF); items.Add(CPFWithDrawl); //EPF_WithDrawl_Interest MembersTransactionDetail EPFInterestWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EPF_WithDrawl_Interest, finalSettlement.LastAudEPFInterest + finalSettlement.LastAudCurrentEPFInterest + finalSettlement.CurrYearEPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(EPFInterestWithDrawl); //Voluntary_Withdrawal_Interest MembersTransactionDetail VoluntaryEPFInterestWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.Voluntary_Withdrawal_Interest, finalSettlement.LastAudVoluntaryEPFInterest + finalSettlement.LastAudCurrentVoluntaryEPFInterest + finalSettlement.CurrYearVoluntaryEPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.Voluntary); items.Add(VoluntaryEPFInterestWithDrawl); //EPF_WithDrawl_Interest MembersTransactionDetail CPFInterestWithDrawl = new MembersTransactionDetail(member.MemberID, member.FundTypeID , EnumMemberTranType.EPF_WithDrawl_Interest, finalSettlement.LastAudCPFInterest + finalSettlement.LastAudCurrentCPFInterest + finalSettlement.CurrYearCPFInterest, finalSettlement.SettlementDate, EnumTranEffect.Decrease, finalSettlement.CreatedBy, EnumFundCategory.EPF); items.Add(CPFInterestWithDrawl); return items; } public void Save(PFFinalSettlement finalSettlement, Member member, List loanCollection) { TransactionContext tc = null; try { FundType ofundtype = new FundTypeService().Get(member.FundTypeID); if(finalSettlement.SettlementDate < ofundtype.fiscalYearStartDate || finalSettlement.SettlementDate > ofundtype.fiscalYearEndDate) { throw new Exception("Settlement date must be between current fiscal year."); } List mtrans = this.PrepareMemberTran(finalSettlement, member); tc = TransactionContext.Begin(true); Save(tc, finalSettlement, member, mtrans, loanCollection); tc.End(); } catch (ServiceException e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public void SaveWithVoluntary(PFFinalSettlement finalSettlement, Member member, List loanCollection) { TransactionContext tc = null; try { FundType ofundtype = new FundTypeService().Get(member.FundTypeID); if (finalSettlement.SettlementDate < ofundtype.fiscalYearStartDate || finalSettlement.SettlementDate > ofundtype.fiscalYearEndDate) { throw new Exception("Settlement date must be between current fiscal year."); } List mtrans = this.PrepareMemberTranWithVoluntary(finalSettlement, member); //interest and withdrawal transection detail tc = TransactionContext.Begin(true); SaveWithVoluntary(tc, finalSettlement, member, mtrans, loanCollection); tc.End(); } catch (ServiceException e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public void Save(List finalSettlements) { TransactionContext tc = null; try { MemberService memberService = new MemberService(); MembersTransactionDetailsService memberTransactionService = new MembersTransactionDetailsService(); tc = TransactionContext.Begin(true); foreach (PFFinalSettlement item in finalSettlements) { List mtrans = this.PrepareMemberTran(item, item.SettleMemberInfo); Save(tc,item, item.SettleMemberInfo, mtrans, item.SettleMemberLoanInfo); // Save(tc, item, item.member, item.memberTransactionDetails, item.loanCollection, item.glTran); } tc.End(); } catch (ServiceException e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public void Save(TransactionContext tc, PFFinalSettlement finalSettlement, Member member, List memberTransactionDetails, List loanCollection) { try { MemberService memberService = new MemberService(); MembersTransactionDetailsService memberTransactionService = new MembersTransactionDetailsService(); this.Save(tc, finalSettlement); memberService.UpdateSettlement(tc, member); memberTransactionService.SaveBulk(tc, memberTransactionDetails); GLTran glintTran = CreateInterestVoucher(tc, member, finalSettlement, loanCollection); GLTran glTran = CreateFSVoucher(tc, member, finalSettlement, loanCollection); int logCounter = 0; foreach (FMLoan loan in loanCollection) { new FMLoanService().SaveForFinalSettlement(tc, loan); logCounter++; } if(glintTran!=null) new GLTranService().Save(tc, glintTran); new GLTranService().Save(tc, glTran); FinalSettlementDA.UpdateGLTranID(tc, finalSettlement.ID, glTran.ID); } catch (ServiceException e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public void SaveWithVoluntary(TransactionContext tc, PFFinalSettlement finalSettlement, Member member, List memberTransactionDetails, List loanCollection) { try { MemberService memberService = new MemberService(); MembersTransactionDetailsService memberTransactionService = new MembersTransactionDetailsService(); this.SaveWithVoluntary(tc, finalSettlement); memberService.UpdateSettlement(tc, member); memberTransactionService.SaveBulk(tc, memberTransactionDetails); GLTran glintTran = CreateVoluntaryInterestVoucher(tc, member, finalSettlement, loanCollection); GLTran glTran = CreateVoluntaryFSVoucher(tc, member, finalSettlement, loanCollection); int logCounter = 0; foreach (FMLoan loan in loanCollection) { new FMLoanService().SaveForFinalSettlement(tc, loan); logCounter++; } if (glintTran != null) new GLTranService().Save(tc, glintTran); // save voluntary investment voucher new GLTranService().Save(tc, glTran); // final settlement voucher FinalSettlementDA.UpdateGLTranID(tc, finalSettlement.ID, glTran.ID); } catch (ServiceException e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } private GLTran CreateInterestVoucher(TransactionContext tc, Member oMember, PFFinalSettlement oFinalSettlement, List oLoan) { try { GLTran otran =null; if (Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest) == 0) return null; otran = new GLTran(); otran.GlTranDetails = new List(); otran.Description = "Fractional Interest on Settlement of the Member :" + oMember.Name + "(" + oMember.EmpCode + ")"; otran.GLTranType = EnumGLTranType.FinalSettlement; otran.VoucherDate = oFinalSettlement.SettlementDate; otran.CreatedDate = DateTime.Now; otran.FundTypeID = oMember.FundTypeID; #region 1. Get Voucher Setups List activityVoucherSetup = new ActivityVoucherSetupService().GetByProcessType (tc, oMember.FundTypeID, EnumFundProcessType.Final_Settlement_Fractional_Interest); if (activityVoucherSetup.Count == 0) { throw new ServiceException(" There is no voucher setup found for the Final Settlement."); } #endregion #region 6. Interest ( currentYear(2)) if ( Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest) != 0) { ActivityVoucherSetup epfInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.EPF_Interest); if (epfInterestVoucherSetup == null) { throw new ServiceException("EPF Interest Voucher Setup Not Found"); } GL gl6 = new GLService().Get(tc, epfInterestVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl6, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest), 2) , " EPF Interest for Fraction Year", epfInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); ActivityVoucherSetup epfContra = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra && x.ReferenceID == (int) EnumFundCategory.EPF); if (epfContra == null) { throw new ServiceException("EPF Contra head not found in voucher Setup"); } GL gl7 = new GLService().Get(tc, epfContra.GLID); otran.GlTranDetails.Add(CreateDetail(gl7, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest), 2) , " EPF Interest for Fraction Year", epfContra.GLSide, 0, 0)); } if (Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest) != 0) { ActivityVoucherSetup CPFInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.CPF_Interest); if (CPFInterestVoucherSetup == null) { throw new ServiceException("CPF Interest Voucher Setup Not Found"); } GL gl6 = new GLService().Get(tc, CPFInterestVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl6, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest), 2) , " CPF Interest for Fraction Year", CPFInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); ActivityVoucherSetup CPFContra = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra && x.ReferenceID == (int)EnumFundCategory.CPF); if (CPFContra == null) { throw new ServiceException(" CPF Contra head not found in voucher Setup"); } GL gl7 = new GLService().Get(tc, CPFContra.GLID); otran.GlTranDetails.Add(CreateDetail(gl7, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest), 2) , " CPF Interest for Fraction Year", CPFContra.GLSide, 0, 0)); } #endregion otran.CreditAmount = Math.Round(otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Credit).Sum(x => x.Amount),2); otran.DebitAmount =Math.Round (otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Debit).Sum(x => x.Amount),2); return otran; } catch (Exception ex) { throw new ServiceException("Create Voucher is failed Due to " + ex.Message, ex); } } private GLTran CreateVoluntaryInterestVoucher(TransactionContext tc, Member oMember, PFFinalSettlement oFinalSettlement, List oLoan) { try { GLTran otran = null; if (Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest) == 0) return null; otran = new GLTran(); otran.GlTranDetails = new List(); otran.Description = "Fractional Interest on Settlement of the Member :" + oMember.Name + "(" + oMember.EmpCode + ")"; otran.GLTranType = EnumGLTranType.FinalSettlement; otran.VoucherDate = oFinalSettlement.SettlementDate; otran.CreatedDate = DateTime.Now; otran.FundTypeID = oMember.FundTypeID; #region 1. Get Voucher Setups List activityVoucherSetup = new ActivityVoucherSetupService().GetByProcessType (tc, oMember.FundTypeID, EnumFundProcessType.Final_Settlement_Fractional_Interest); if (activityVoucherSetup.Count == 0) { throw new ServiceException(" There is no voucher setup found for the Final Settlement."); } #endregion #region 6. Interest ( currentYear(2)) if (Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest) != 0) { ActivityVoucherSetup epfInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.EPF_Interest); if (epfInterestVoucherSetup == null) { throw new ServiceException("EPF Interest Voucher Setup Not Found"); } GL gl6 = new GLService().Get(tc, epfInterestVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl6, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest), 2) , " EPF Interest for Fraction Year", epfInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); ActivityVoucherSetup epfContra = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra && x.ReferenceID == (int)EnumFundCategory.EPF); if (epfContra == null) { throw new ServiceException("EPF Contra head not found in voucher Setup"); } GL gl7 = new GLService().Get(tc, epfContra.GLID); otran.GlTranDetails.Add(CreateDetail(gl7, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest), 2) , " EPF Interest for Fraction Year", epfContra.GLSide, 0, 0)); } if (Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentVoluntaryEPFInterest) != 0) { ActivityVoucherSetup epfInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Voluntary_EPF); if (epfInterestVoucherSetup == null) { throw new ServiceException("Voluntary EPF Voucher Setup Not Found"); } GL gl8 = new GLService().Get(tc, epfInterestVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl8, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentVoluntaryEPFInterest), 2) , " Voluntary EPF Interest for Fraction Year", epfInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); ActivityVoucherSetup voluntaryEpfInterest = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Voluntary_EPF_Interest); if (voluntaryEpfInterest == null) { throw new ServiceException("Voluntary EPF Interest head not found in voucher Setup"); } GL gl9 = new GLService().Get(tc, voluntaryEpfInterest.GLID); otran.GlTranDetails.Add(CreateDetail(gl9, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentVoluntaryEPFInterest), 2) , " Voluntary EPF Interest for Fraction Year", voluntaryEpfInterest.GLSide, 0, 0)); } if (Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest) != 0) { ActivityVoucherSetup CPFInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.CPF_Interest); if (CPFInterestVoucherSetup == null) { throw new ServiceException("CPF Interest Voucher Setup Not Found"); } GL gl6 = new GLService().Get(tc, CPFInterestVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl6, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest), 2) , " CPF Interest for Fraction Year", CPFInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); ActivityVoucherSetup CPFContra = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra && x.ReferenceID == (int)EnumFundCategory.CPF); if (CPFContra == null) { throw new ServiceException(" CPF Contra head not found in voucher Setup"); } GL gl7 = new GLService().Get(tc, CPFContra.GLID); otran.GlTranDetails.Add(CreateDetail(gl7, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest), 2) , " CPF Interest for Fraction Year", CPFContra.GLSide, 0, 0)); } #endregion otran.CreditAmount = Math.Round( otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Credit).Sum(x => x.Amount),2); otran.DebitAmount = Math.Round( otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Debit).Sum(x => x.Amount),2); return otran; } catch (Exception ex) { throw new ServiceException("Create Voucher is failed Due to " + ex.Message, ex); } } private GLTran CreateFSVoucher(TransactionContext tc, Member oMember, PFFinalSettlement oFinalSettlement, List oLoan) { try { GLTran otran, _interestglTran = null; List _eSlabs = new List(); double netPayable = 0; string glCode = string.Empty; int serviceLength = GlobalFunctions.DateDiff("Y", Convert.ToDateTime(oMember.DOJ), oFinalSettlement.SettlementDate.AddDays(1)); _interestglTran = new GLTran(); otran = new GLTran(); otran.GlTranDetails = new List(); otran.Description = "Settlement of the Member :" + oMember.Name + "(" + oMember.EmpCode + ")"; otran.GLTranType = EnumGLTranType.FinalSettlement; otran.VoucherDate = oFinalSettlement.SettlementDate; otran.CreatedDate = DateTime.Now; otran.FundTypeID = oMember.FundTypeID; #region 1. Get Voucher Setups List activityVoucherSetup = new ActivityVoucherSetupService().GetByProcessType (tc, oMember.FundTypeID, EnumFundProcessType.Final_Settlement_Of_EPF); if (activityVoucherSetup.Count == 0) { throw new ServiceException(" There is no voucher setup found for the Final Settlement."); } #endregion #region 3. EPF Contribution if (oFinalSettlement.LastAudEPF + oFinalSettlement.CurrYearEPF!=0) { ActivityVoucherSetup epfVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.EPF); if (epfVoucherSetup == null) { throw new ServiceException("EPF Voucher Setup Not Found"); } GL gl3 = new GLService().Get(tc, epfVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.LastAudEPF) + Convert.ToDouble(oFinalSettlement.CurrYearEPF),0); otran.GlTranDetails.Add(CreateDetail(gl3, Math.Round(Convert.ToDouble(oFinalSettlement.LastAudEPF) + Convert.ToDouble(oFinalSettlement.CurrYearEPF), 0) , " Member EPF Balance", epfVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 4. CPF Contribution if (oFinalSettlement.LastAudCPF + oFinalSettlement.CurrYearCPF != 0) { double cpfCon = Convert.ToDouble(oFinalSettlement.LastAudCPF) + Convert.ToDouble(oFinalSettlement.CurrYearCPF); ActivityVoucherSetup cpfVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.CPF); if (cpfVoucherSetup == null) { throw new ServiceException("CPF Voucher Setup Not Found"); } GL gl4 = new GLService().Get(tc, cpfVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl4, Math.Round((Convert.ToDouble(oFinalSettlement.LastAudCPF) + Convert.ToDouble(oFinalSettlement.CurrYearCPF)), 0) , " Member CPF Balance", cpfVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); netPayable = netPayable + Math.Round((Convert.ToDouble(oFinalSettlement.LastAudCPF) + Convert.ToDouble(oFinalSettlement.CurrYearCPF)),0); } #endregion #region 5. EPF Interest (Audited Year + currentYear(1)) if (oFinalSettlement.LastAudEPFInterest + oFinalSettlement.CurrYearEPFInterest + oFinalSettlement.LastAudEPFInterest != 0) { ActivityVoucherSetup epfInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.EPF_Interest); if (epfInterestVoucherSetup == null) { throw new ServiceException("EPF Interest Voucher Setup Not Found"); } GL gl5 = new GLService().Get(tc, epfInterestVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest),2); otran.GlTranDetails.Add(CreateDetail(gl5, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest), 2) , " EPF Interest Realize", epfInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 6. CPF Interest (Audited Year + currentYear(2)) if (oFinalSettlement.LastAudCPFInterest + Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest) != 0) { ActivityVoucherSetup cpfInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.CPF_Interest); if(cpfInterestVoucherSetup == null) { throw new ServiceException("CPF Interest Voucher Setup Not Found"); } GL gl6 = new GLService().Get(tc, cpfInterestVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest),2); otran.GlTranDetails.Add(CreateDetail(gl6, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest), 2) , " CPF Interest Realize", cpfInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 7. Loan to Employee double loanAmount = 0; double unpaidAmount = 0; if (oLoan.Count > 0) { List oLoanF = new FMLoanService().GetLoanObjects(tc, oLoan[0].FundTypeID, oMember.ID.ToString(), 0); double InstallAmount = 0.00; double insInterest = 0.00; if (oLoanF[0].LoanSchedules.Count > 0) { InstallAmount = Math.Round(oLoanF[0].LoanSchedules.Where(x => x.PayDate == null).Sum(y => y.InstallmentPrincipal)); insInterest = Math.Round(oLoanF[0].LoanSchedules.Where(x => x.PayDate == null && x.InstallmentInterest> 0).Sum(y => y.InstallmentInterest)); } unpaidAmount = InstallAmount + insInterest; if (InstallAmount != 0) { ActivityVoucherSetup loanVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Loan_Principal); GL gl7 = new GLService().Get(tc, loanVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl7, Convert.ToDouble(InstallAmount) , "Member Loan Realization", loanVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Loan, oLoan[0].ID)); } if (insInterest != 0) { ActivityVoucherSetup loanInterestVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Loan_Interest); GL gl71 = new GLService().Get(tc, loanInterestVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl71, Convert.ToDouble(insInterest) , "Member Loan Interest Realization", loanInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Loan, oLoan[0].ID)); } netPayable = netPayable - unpaidAmount; } #endregion //ActivityVoucherSetup netPayableHead = activityVoucherSetup.FirstOrDefault(x => //x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Bank || x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra //&& x.ReferenceType!=EnumProcessReferenceType.Loan); //GL gl8 = new GLService().Get(tc, netPayableHead.GLID); //if (gl8.UserObjectID == null) // Bank Head //{ // otran.GlTranDetails.Add(CreateDetail(gl8, Convert.ToDouble(netPayable) // , " Net Payable to employee", netPayableHead.GLSide, 0, 0)); //} //else // Ex-Member head with subsidiary //{ // otran.GlTranDetails.Add(CreateDetail(gl8, Convert.ToDouble(netPayable) // , " Net Payable to employee", netPayableHead.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); //} ActivityVoucherSetup bankHead = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Bank); if(bankHead != null) { GL gl8 = new GLService().Get(tc, bankHead.GLID); otran.GlTranDetails.Add(CreateDetail(gl8, Convert.ToDouble(netPayable) , "Net Payable to employee", bankHead.GLSide, 0, 0)); } else { ActivityVoucherSetup exMemberHead = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Ex_Member); if(exMemberHead != null) { GL gl9 = new GLService().Get(tc, exMemberHead.GLID); otran.GlTranDetails.Add(CreateDetail(gl9, Convert.ToDouble(netPayable) , "Net Payable to employee", exMemberHead.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } else { throw new ServiceException("Bank/Ex-Member Head Not Found"); } } //Only For KCCL #region Forfietted Amount //if (chkHasRightsEmployee.Checked == false) //{ // foreach (ESBSlab oslab in _eSlabs) // { // if (serviceLength < oslab.ServiceYear) // { // if ((Convert.ToDecimal(txtCurCPF.Text) + Convert.ToDecimal(txtCPFPrincipal.Text) + Convert.ToDecimal(txtCPFInterest.Text)) != 0) // { // glCode = ConfigurationSettings.AppSettings["CPFForfittedHead"]; // GL gl9 = GL.Get(glCode); // netPayable = netPayable - (Convert.ToDecimal(txtCurCPF.Text) + Convert.ToDecimal(txtCPFPrincipal.Text) + Convert.ToDecimal(txtCPFInterest.Text) + Convert.ToDecimal(txtCurCPFInterest.Text) + Convert.ToDecimal(txtLstCPFInterest.Text)); // otran.GlTranDetails.Add(CreateDetail(gl9, Convert.ToDecimal(txtCPFInterest.Text) + Convert.ToDecimal(txtCPFPrincipal.Text) + Convert.ToDecimal(txtCurCPF.Text) + Convert.ToDecimal(txtCurCPFInterest.Text) + Convert.ToDecimal(txtLstCPFInterest.Text) // , " Forfeited CPF Balance ", EnumTranSide.Credit)); // break; // } // } // } //} #endregion #region 10. Bank (Net Payable) //otran.ChequeNo = txtCheckNo.Text; //otran.ChequeDate = dtpCheckDate.Value; //glCode = ConfigurationSettings.AppSettings["BankHead"]; //string closingBalance = string.Empty; //GL gl11 = GL.Get(glCode); //if (chkHasRightsEmployee.Checked) //{ // otran.GlTranDetails.Add(CreateDetail(gl11, (netPayable + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable + deductAmount) - crDeductAmount).ToString("N2"); //} //else //{ // otran.GlTranDetails.Add(CreateDetail(gl11, (netPayable - dforfeit + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable - dforfeit + deductAmount) - crDeductAmount).ToString("N2"); //} //if (chkBerger.Checked) //{ // glCode = ConfigurationSettings.AppSettings["BergerHead"]; // GL gl12 = GL.Get(glCode); // if (chkHasRightsEmployee.Checked) // { // otran.GlTranDetails.Add(CreateDetail(gl12, (netPayable + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable + deductAmount) - crDeductAmount).ToString("N2"); // } // else // { // otran.GlTranDetails.Add(CreateDetail(gl12, (netPayable - dforfeit + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable - dforfeit + deductAmount) - crDeductAmount).ToString("N2"); // } //} //oRow["ClosingBalance"] = closingBalance; //dtPFStatement.Rows.Add(oRow); #endregion //otran.CreditAmount = otran.GetTotalCreditAmount(); //otran.DebitAmount = otran.GetTotalDebitAmount(); //if (chkBankPayment.Checked == true) //{ // otran.ChequeNo = txtCheckNo.Text; // otran.ChequeDate = dtpCheckDate.Value; //} otran.CreditAmount =Math.Round(otran.GlTranDetails.Where(x=> x.Transide == EnumTranSide.Credit).Sum(x=>x.Amount),2); otran.DebitAmount =Math.Round(otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Debit).Sum(x => x.Amount),2); return otran; } catch (Exception ex) { throw new ServiceException("Create Voucher is failed Due to " + ex.Message, ex); } } private GLTranDetail CreateDetail(GL ogl, double amount, string description, EnumTranSide side, int userObjectID, int userRecordID) { GLTranDetail glTranDetail = new GLTranDetail(); glTranDetail.GL = ogl; if (ogl == null) { throw new Exception("Please check your GLHead !!!"); } else if (ogl != null) { glTranDetail.GLID = ogl.ID; glTranDetail.Amount = Convert.ToDouble(amount); glTranDetail.Description = description; glTranDetail.Transide = side; glTranDetail.OperationalStatus = EnumOperationalStatus.Add; glTranDetail.GLTranUserRecords = new List(); if (ogl.UserObjectID !=null && userObjectID > 0 && userRecordID > 0) { GLTranUserRecord gltur = new GLTranUserRecord(); gltur.GLID = ogl.ID; gltur.UserObject1ID = userObjectID; gltur.UserRecord1ID = userRecordID; gltur.Amount = glTranDetail.Amount; glTranDetail.GLTranUserRecords.Add(gltur); } } return glTranDetail; } public double OutstandingLoanAmount(int loanID) { double outstandingLoan = 0; List _loanCollection = new List(); try { bool isFoundPayDateNull = false; bool isFoundPayDate = false; double paidAmount = 0.0; double unpaidAmount = 0.0; double InsPrincipal = 0.0; double InsInterest = 0.0; double balance = 0; FMLoan loan = new FMLoan(); loan = new FMLoanService().Get(loanID, true, false, false); _loanCollection.Add(loan); foreach (FMLoanSchedule loanSchedule in loan.LoanSchedules) { if (!isFoundPayDateNull || !isFoundPayDate) { if (loanSchedule.PayDate == null) { double InstallAmount = Math.Round(loan.LoanSchedules.Where(x => x.PayDate == null).Sum(y => y.InstallmentPrincipal)); double insInterest = loan.LoanSchedules.Where(x => x.PayDate == null && x.InstallmentInterest > 0).FirstOrDefault().InstallmentInterest; isFoundPayDateNull = true; isFoundPayDate = true; InsPrincipal = InstallAmount; InsInterest = insInterest; unpaidAmount = InstallAmount + insInterest; } else if (isFoundPayDate == false) { double _paidInstallAm = loan.LoanSchedules.Where(x => x.PayDate != null).Sum(y => y.InstallmentPrincipal); double _insInterest = loan.LoanSchedules.Where(x => x.PayDate != null && x.InstallmentInterest > 0).Sum(y => y.InstallmentInterest); isFoundPayDate = true; paidAmount = _paidInstallAm + _insInterest; } } } double LoanEmployee = Convert.ToDouble(loan.PrincipalAmount) - balance; double loanAount = Convert.ToDouble((loan.PrincipalAmount)) - balance; outstandingLoan = Convert.ToDouble(unpaidAmount); } catch (Exception ex) { #region Handle Exception ExceptionLog.Write(ex); throw new ServiceException("Failed to Get IRNotifications: " + ex.Message, ex); #endregion } return outstandingLoan; } public double OutstandingLoanAmount(TransactionContext tc, int loanID) { double outstandingLoan = 0; List _loanCollection = new List(); try { bool isFoundPayDateNull = false; bool isFoundPayDate = false; double paidAmount = 0.0; double unpaidAmount = 0.0; double InsPrincipal = 0.0; double InsInterest = 0.0; double balance = 0; FMLoan loan = new FMLoan(); loan = new FMLoanService().Get(tc, loanID, true, false, false); _loanCollection.Add(loan); foreach (FMLoanSchedule loanSchedule in loan.LoanSchedules) { if (!isFoundPayDateNull || !isFoundPayDate) { if (loanSchedule.PayDate == null) { double InstallAmount = Math.Round(loan.LoanSchedules.Where(x => x.PayDate == null).Sum(y => y.InstallmentPrincipal)); double insInterest = loan.LoanSchedules.Where(x => x.PayDate == null && x.InstallmentInterest > 0).FirstOrDefault().InstallmentInterest; isFoundPayDateNull = true; isFoundPayDate = true; InsPrincipal = InstallAmount; InsInterest = insInterest; unpaidAmount = InstallAmount + insInterest; } else if (isFoundPayDate == false) { double _paidInstallAm = loan.LoanSchedules.Where(x => x.PayDate != null).Sum(y => y.InstallmentPrincipal); double _insInterest = loan.LoanSchedules.Where(x => x.PayDate != null && x.InstallmentInterest > 0).Sum(y => y.InstallmentInterest); isFoundPayDate = true; paidAmount = _paidInstallAm + _insInterest; } } } double LoanEmployee = Convert.ToDouble(loan.PrincipalAmount) - balance; double loanAount = Convert.ToDouble((loan.PrincipalAmount)) - balance; outstandingLoan = unpaidAmount; } catch (Exception ex) { #region Handle Exception ExceptionLog.Write(ex); throw new ServiceException("Failed to Get IRNotifications: " + ex.Message, ex); #endregion } return outstandingLoan; } private GLTran CreateVoluntaryFSVoucher(TransactionContext tc, Member oMember, PFFinalSettlement oFinalSettlement, List oLoan) { try { GLTran otran, _interestglTran = null; List _eSlabs = new List(); double netPayable = 0; string glCode = string.Empty; int serviceLength = GlobalFunctions.DateDiff("Y", Convert.ToDateTime(oMember.DOJ), oFinalSettlement.SettlementDate.AddDays(1)); _interestglTran = new GLTran(); otran = new GLTran(); otran.GlTranDetails = new List(); otran.Description = "Settlement of the Member :" + oMember.Name + "(" + oMember.EmpCode + ")"; otran.GLTranType = EnumGLTranType.FinalSettlement; otran.VoucherDate = oFinalSettlement.SettlementDate; otran.CreatedDate = DateTime.Now; otran.FundTypeID = oMember.FundTypeID; #region 1. Get Voucher Setups List activityVoucherSetup = new ActivityVoucherSetupService().GetByProcessType (tc, oMember.FundTypeID, EnumFundProcessType.Final_Settlement_Of_EPF); if (activityVoucherSetup.Count == 0) { throw new ServiceException(" There is no voucher setup found for the Final Settlement."); } #endregion #region 3. EPF Contribution if (oFinalSettlement.LastAudEPF + oFinalSettlement.CurrYearEPF != 0) { ActivityVoucherSetup epfVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.EPF); if (epfVoucherSetup == null) { throw new ServiceException("EPF Voucher Setup Not Found"); } GL gl3 = new GLService().Get(tc, epfVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.LastAudEPF) + Convert.ToDouble(oFinalSettlement.CurrYearEPF), 2); otran.GlTranDetails.Add(CreateDetail(gl3, Math.Round(Convert.ToDouble(oFinalSettlement.LastAudEPF) + Convert.ToDouble(oFinalSettlement.CurrYearEPF), 2) , " Member EPF Balance", epfVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 3.1 Voluntary EPF Contribution if (oFinalSettlement.LastAudVoluntaryEPF + oFinalSettlement.CurrYearVoluntaryEPF != 0) { ActivityVoucherSetup voluntaryEpfVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Voluntary_EPF); if (voluntaryEpfVoucherSetup == null) { throw new ServiceException("Voluntary EPF Voucher Setup Not Found"); } GL gl31 = new GLService().Get(tc, voluntaryEpfVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.LastAudVoluntaryEPF) + Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPF), 2); otran.GlTranDetails.Add(CreateDetail(gl31, Math.Round(Convert.ToDouble(oFinalSettlement.LastAudVoluntaryEPF) + Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPF), 2) , " Member Voluntary EPF Balance", voluntaryEpfVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 4. CPF Contribution if (oFinalSettlement.LastAudCPF + oFinalSettlement.CurrYearCPF != 0) { double cpfCon = Convert.ToDouble(oFinalSettlement.LastAudCPF) + Convert.ToDouble(oFinalSettlement.CurrYearCPF); ActivityVoucherSetup cpfVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.CPF); if (cpfVoucherSetup == null) { throw new ServiceException("CPF Voucher Setup Not Found"); } GL gl4 = new GLService().Get(tc, cpfVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl4, Math.Round((Convert.ToDouble(oFinalSettlement.LastAudCPF) + Convert.ToDouble(oFinalSettlement.CurrYearCPF)), 2) , " Member CPF Balance", cpfVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); netPayable = netPayable + Math.Round((Convert.ToDouble(oFinalSettlement.LastAudCPF) + Convert.ToDouble(oFinalSettlement.CurrYearCPF)), 2); } #endregion #region 5. EPF Interest (Audited Year + currentYear(1)) if (oFinalSettlement.LastAudEPFInterest + oFinalSettlement.CurrYearEPFInterest + oFinalSettlement.LastAudEPFInterest != 0) { ActivityVoucherSetup epfInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.EPF_Interest); if (epfInterestVoucherSetup == null) { throw new ServiceException("EPF Interest Voucher Setup Not Found"); } GL gl5 = new GLService().Get(tc, epfInterestVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest),2); otran.GlTranDetails.Add(CreateDetail(gl5, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentEPFInterest), 2) , " EPF Interest Realize", epfInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 5.1 Voluntary EPF Interest (Audited Year + currentYear(1)) if (oFinalSettlement.LastAudVoluntaryEPFInterest + oFinalSettlement.CurrYearVoluntaryEPFInterest + oFinalSettlement.LastAudVoluntaryEPFInterest != 0) { ActivityVoucherSetup VolEPFInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Voluntary_EPF_Interest); if (VolEPFInterestVoucherSetup == null) { throw new ServiceException("Voluntary EPF Interest Voucher Setup Not Found"); } GL gl51 = new GLService().Get(tc, VolEPFInterestVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentVoluntaryEPFInterest), 2); otran.GlTranDetails.Add(CreateDetail(gl51, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudVoluntaryEPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentVoluntaryEPFInterest), 2) , " Voluntary EPF Interest Realize", VolEPFInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 6. CPF Interest (Audited Year + currentYear(2)) if (oFinalSettlement.LastAudCPFInterest + Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest) != 0) { ActivityVoucherSetup cpfInterestVoucherSetup = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.CPF_Interest); if (cpfInterestVoucherSetup == null) { throw new ServiceException("CPF Interest Voucher Setup Not Found"); } GL gl6 = new GLService().Get(tc, cpfInterestVoucherSetup.GLID); netPayable = netPayable + Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest),2); otran.GlTranDetails.Add(CreateDetail(gl6, Math.Round(Convert.ToDouble(oFinalSettlement.CurrYearCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCPFInterest) + Convert.ToDouble(oFinalSettlement.LastAudCurrentCPFInterest), 2) , " CPF Interest Realize", cpfInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } #endregion #region 7. Loan to Employee double loanAmount = 0; double unpaidAmount = 0; if (oLoan.Count > 0) { List oLoanF = new FMLoanService().GetLoanObjects(tc, oLoan[0].FundTypeID, oMember.ID.ToString(), 0); double InstallAmount = 0.00; double insInterest = 0.00; if (oLoanF[0].LoanSchedules.Count > 0) { InstallAmount = Math.Round(oLoanF[0].LoanSchedules.Where(x => x.PayDate == null).Sum(y => y.InstallmentPrincipal)); insInterest = Math.Round(oLoanF[0].LoanSchedules.Where(x => x.PayDate == null && x.InstallmentInterest > 0).Sum(y => y.InstallmentInterest)); } unpaidAmount = InstallAmount + insInterest; if (InstallAmount != 0) { ActivityVoucherSetup loanVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Loan_Principal); GL gl7 = new GLService().Get(tc, loanVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl7, Convert.ToDouble(InstallAmount) , "Member Loan Realization", loanVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Loan, oLoan[0].ID)); } if (insInterest != 0) { ActivityVoucherSetup loanInterestVoucherSetup = activityVoucherSetup.Find(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Loan_Interest); GL gl71 = new GLService().Get(tc, loanInterestVoucherSetup.GLID); otran.GlTranDetails.Add(CreateDetail(gl71, Convert.ToDouble(insInterest) , "Member Loan Interest Realization", loanInterestVoucherSetup.GLSide, (int)GlobalFunctions.Fund_UserObject_Loan, oLoan[0].ID)); } netPayable = netPayable - unpaidAmount; } #endregion //ActivityVoucherSetup netPayableHead = activityVoucherSetup.FirstOrDefault(x => //x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Bank || x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra //&& x.ReferenceType!=EnumProcessReferenceType.Loan); //GL gl8 = new GLService().Get(tc, netPayableHead.GLID); //if (gl8.UserObjectID == null) // Bank Head //{ // otran.GlTranDetails.Add(CreateDetail(gl8, Convert.ToDouble(netPayable) // , " Net Payable to employee", netPayableHead.GLSide, 0, 0)); //} //else // Ex-Member head with subsidiary //{ // otran.GlTranDetails.Add(CreateDetail(gl8, Convert.ToDouble(netPayable) // , " Net Payable to employee", netPayableHead.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); //} ActivityVoucherSetup bankHead = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Bank); if (bankHead != null) { GL gl8 = new GLService().Get(tc, bankHead.GLID); otran.GlTranDetails.Add(CreateDetail(gl8, Convert.ToDouble(netPayable) , "Net Payable to employee", bankHead.GLSide, 0, 0)); } else { ActivityVoucherSetup exMemberHead = activityVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Ex_Member); if (exMemberHead != null) { GL gl9 = new GLService().Get(tc, exMemberHead.GLID); otran.GlTranDetails.Add(CreateDetail(gl9, Convert.ToDouble(netPayable) , "Net Payable to employee", exMemberHead.GLSide, (int)GlobalFunctions.Fund_UserObject_Member, oMember.ID)); } else { throw new ServiceException("Bank/Ex-Member Head Not Found"); } } //Only For KCCL #region Forfietted Amount //if (chkHasRightsEmployee.Checked == false) //{ // foreach (ESBSlab oslab in _eSlabs) // { // if (serviceLength < oslab.ServiceYear) // { // if ((Convert.ToDecimal(txtCurCPF.Text) + Convert.ToDecimal(txtCPFPrincipal.Text) + Convert.ToDecimal(txtCPFInterest.Text)) != 0) // { // glCode = ConfigurationSettings.AppSettings["CPFForfittedHead"]; // GL gl9 = GL.Get(glCode); // netPayable = netPayable - (Convert.ToDecimal(txtCurCPF.Text) + Convert.ToDecimal(txtCPFPrincipal.Text) + Convert.ToDecimal(txtCPFInterest.Text) + Convert.ToDecimal(txtCurCPFInterest.Text) + Convert.ToDecimal(txtLstCPFInterest.Text)); // otran.GlTranDetails.Add(CreateDetail(gl9, Convert.ToDecimal(txtCPFInterest.Text) + Convert.ToDecimal(txtCPFPrincipal.Text) + Convert.ToDecimal(txtCurCPF.Text) + Convert.ToDecimal(txtCurCPFInterest.Text) + Convert.ToDecimal(txtLstCPFInterest.Text) // , " Forfeited CPF Balance ", EnumTranSide.Credit)); // break; // } // } // } //} #endregion #region 10. Bank (Net Payable) //otran.ChequeNo = txtCheckNo.Text; //otran.ChequeDate = dtpCheckDate.Value; //glCode = ConfigurationSettings.AppSettings["BankHead"]; //string closingBalance = string.Empty; //GL gl11 = GL.Get(glCode); //if (chkHasRightsEmployee.Checked) //{ // otran.GlTranDetails.Add(CreateDetail(gl11, (netPayable + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable + deductAmount) - crDeductAmount).ToString("N2"); //} //else //{ // otran.GlTranDetails.Add(CreateDetail(gl11, (netPayable - dforfeit + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable - dforfeit + deductAmount) - crDeductAmount).ToString("N2"); //} //if (chkBerger.Checked) //{ // glCode = ConfigurationSettings.AppSettings["BergerHead"]; // GL gl12 = GL.Get(glCode); // if (chkHasRightsEmployee.Checked) // { // otran.GlTranDetails.Add(CreateDetail(gl12, (netPayable + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable + deductAmount) - crDeductAmount).ToString("N2"); // } // else // { // otran.GlTranDetails.Add(CreateDetail(gl12, (netPayable - dforfeit + deductAmount) - crDeductAmount // , " Net Payable to employee", EnumTranSide.Credit)); // closingBalance = ((netPayable - dforfeit + deductAmount) - crDeductAmount).ToString("N2"); // } //} //oRow["ClosingBalance"] = closingBalance; //dtPFStatement.Rows.Add(oRow); #endregion //otran.CreditAmount = otran.GetTotalCreditAmount(); //otran.DebitAmount = otran.GetTotalDebitAmount(); //if (chkBankPayment.Checked == true) //{ // otran.ChequeNo = txtCheckNo.Text; // otran.ChequeDate = dtpCheckDate.Value; //} otran.CreditAmount =Math.Round(otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Credit).Sum(x => x.Amount),2); otran.DebitAmount =Math.Round(otran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Debit).Sum(x => x.Amount),2); return otran; } catch (Exception ex) { throw new ServiceException("Create Voucher is failed Due to " + ex.Message, ex); } } public List GetClearanceNotifications(int regEmpId) { List oFinalSettlementClearance = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FinalSettlementDA.GetClearanceNotifications(tc, regEmpId)); while (oreader.Read()) { FinalSettlementClerance oFileSettlement = new FinalSettlementClerance(); oFileSettlement.EmployeeId = oreader.GetInt32("EMPLOYEEID").Value; oFileSettlement.EmployeeNo = oreader.GetString("EmployeeNo"); oFileSettlement.EmployeeName = oreader.GetString("EmployeeName"); oFileSettlement.ClearanceDate = oreader.GetDateTime("ClearanceDate").HasValue ? oreader.GetDateTime("ClearanceDate").Value : null; oFileSettlement.SendDate = oreader.GetDateTime("SentDate").HasValue ? oreader.GetDateTime("SentDate").Value : null; oFileSettlement.SettlementClearanceStatus = (EnumSettlementClearanceStatus)oreader.GetInt32("SettlementClearanceStatus").GetValueOrDefault(); oFileSettlement.ClearanceStatus = ((EnumSettlementClearanceStatus)oreader.GetInt32("SettlementClearanceStatus").GetValueOrDefault()).ToString(); oFileSettlement.FSHeadID = oreader.GetInt32("FSHeadID", 0); oFileSettlement.FsHeadName = oreader.GetString("Name", null); oFileSettlement.FsHeadDepartment = oreader.GetString("DEPARTMENT", null); oFileSettlement.CompletionDays = oreader.GetInt32("CompletionWorkingDays", 0); oFileSettlement.Remarks = oreader.GetString("Remarks", true, null); oFileSettlement.Amount = oreader.GetDouble("Amount").HasValue ? oreader.GetDouble("Amount").Value : null; oFileSettlement.DeductFromEmp = oreader.GetDouble("DeductFromEmp").HasValue ? oreader.GetDouble("DeductFromEmp").Value : null; oFileSettlement.PaytoEmp = oreader.GetDouble("PaytoEmp").HasValue ? oreader.GetDouble("PaytoEmp").Value : null; oFileSettlement.ClearanceRequired = oreader.GetBoolean("ClearanceRequired", true, false); oFileSettlement.NeedDepartmentApprove = oreader.GetBoolean("NeedDepartmentApprove", true, false); oFileSettlement.DepartmentToApproveBefore = oreader.GetString("DepartmentToApproveBefore", true, null); oFileSettlement.FinalStage = oreader.GetBoolean("FinalStage", true, false); if (oreader.GetInt32("TranType").HasValue) oFileSettlement.TranType = (EnumFSTranType)oreader.GetInt32("TranType"); oFinalSettlementClearance.Add(oFileSettlement); } oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get IRNotifications: " + ex.Message, ex); #endregion } return oFinalSettlementClearance; } public List GetClearanceNotificationsByDepartment(string departmentString) { List oFinalSettlementClearance = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FinalSettlementDA.GetClearanceNotificationsByDepartment(tc, departmentString)); while (oreader.Read()) { FinalSettlementClerance oFileSettlement = new FinalSettlementClerance(); oFileSettlement.EmployeeId = oreader.GetInt32("EMPLOYEEID").Value; oFileSettlement.EmployeeNo = oreader.GetString("EmployeeNo"); oFileSettlement.EmployeeName = oreader.GetString("EmployeeName"); oFileSettlement.ClearanceDate = oreader.GetDateTime("ClearanceDate").HasValue ? oreader.GetDateTime("ClearanceDate").Value : null; oFileSettlement.SendDate = oreader.GetDateTime("SentDate").HasValue ? oreader.GetDateTime("SentDate").Value : null; oFileSettlement.SettlementClearanceStatus = (EnumSettlementClearanceStatus)oreader.GetInt32("SettlementClearanceStatus").GetValueOrDefault(); oFileSettlement.ClearanceStatus = ((EnumSettlementClearanceStatus)oreader.GetInt32("SettlementClearanceStatus").GetValueOrDefault()).ToString(); oFileSettlement.FsHeadName = oreader.GetString("Name", null); oFileSettlement.FsHeadDepartment = oreader.GetString("DEPARTMENT", null); oFileSettlement.CompletionDays = oreader.GetInt32("CompletionWorkingDays", 0); oFileSettlement.MobileNo = oreader.GetString("MOBILENO"); oFileSettlement.ResignedEmployeeNo = oreader.GetString("ResignedEmployeeNo"); oFileSettlement.ResignedEmployeeName = oreader.GetString("ResignedEmployeeName"); oFinalSettlementClearance.Add(oFileSettlement); } oreader.Close(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to Get IRNotifications: " + ex.Message, ex); #endregion } return oFinalSettlementClearance; } public DataTable GetBySearch(string sSearch) { DataTable finalSettlement = new DataTable(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); finalSettlement = FinalSettlementDA.GetBySearch(tc, sSearch); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Load Data", e); #endregion } return finalSettlement; } public DataTable ExtractFromExcel(System.IO.Stream fileStream) { ImportHelper iHelper = new ImportHelper(); DataSet dDataSet = iHelper.Import(ImportHelper.Formats.Excel, fileStream, true); try { return dDataSet.Tables[0].Copy(); } catch (Exception ex) { ExceptionLog.Write(ex); throw new ServiceException("Failed to Load Data", ex); } } public DataTable GetComparedFinalSettlementDataForUpload(DataTable dt, int fundtypeid) { DataTable dtReference = new DataTable(); dt.Columns.Add("memberid", typeof(int)); dt.Columns.Add("fundtypeid", typeof(int)); dt.Columns.Add("epfRef", typeof(double)); dt.Columns.Add("cpfRef", typeof(double)); dt.Columns.Add("epfInterestRef", typeof(double)); dt.Columns.Add("cpfInterestRef", typeof(double)); dt.Columns.Add("LoanPrincipalAdjustRef", typeof(double)); dt.Columns.Add("error", typeof(string)); FundType ftype = new FundTypeService().Get(fundtypeid); List members = new MemberService().GetByFundType(ftype.ID); List osettlements = new PFFinalSettlementService().GetbyFundType(ftype.ID); foreach (DataRow drow in dt.Rows) { string memberNo = drow["MemberNo"].ToString(); Member oMember = members.FirstOrDefault(x => x.EmpCode == memberNo); drow["fundtypeid"] = fundtypeid; if (oMember != null) { drow["memberid"] = oMember.ID; var memExist = osettlements.FirstOrDefault(x => x.MemberID == oMember.ID); if (memExist != null) { drow["error"] = "Already settled in the System"; continue; } FMLoan oLoan = null; double outStandingAmount = 0; drow["error"] = ""; oLoan = new FMLoanService().GetByMemberID(oMember.ID); if(oLoan !=null) outStandingAmount = new FMLoanService().GetLoanOustandingAmount(oLoan.ID); dtReference = new MembersTransactionDetailsService().GetTranAmount(oMember.ID, DateTime.Today, oMember.FundTypeID).Tables[0]; foreach (DataRow item in dtReference.Rows) { drow["epfRef"] = Convert.ToDouble(item["EPF"]); drow["cpfRef"] = Convert.ToDouble(item["CPF"]); drow["epfInterestRef"] = Convert.ToDouble(item["EPFINTEREST"]); drow["cpfInterestRef"] = Convert.ToDouble(item["CPFINTEREST"]); drow["LoanPrincipalAdjustRef"] = outStandingAmount; } } else { drow["error"] = "Member Not Found"; } } return dt; } public List UploadFinalSettlementData(DataTable dt) { List errorOrSuccessList = new List(); List oFinalSettlements = new List(); List oMembersTransactionDetails = new List(); int fundtypeid = 0; string memberNo; int nRow = 0; try { //Prepare Final Settlement List foreach(DataRow row in dt.Rows) { nRow++; fundtypeid = Convert.ToInt32(row["fundtypeid"].ToString()); //Validation of Data if (row["MemberNo"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("MemberNo.", nRow, "(" + row["MemberNo"].ToString() + ")" + "This cannot be empty")); if (row["Name"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Name.", nRow, "(" + row["Name"].ToString() + ")" + "This cannot be empty")); if (row["SettlementDate"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Settlement Date.", nRow, "(" + row["SettlementDate"].ToString() + ")" + "This cannot be empty")); if (row["EPF"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("EPF.", nRow, "(" + row["EPF"].ToString() + ")" + "This cannot be empty")); if (row["EPFInterest"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("EPF Interest.", nRow, "(" + row["EPF Interest"].ToString() + ")" + "This cannot be empty")); if (row["CPF"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("CPF.", nRow, "(" + row["CPF"].ToString() + ")" + "This cannot be empty")); if (row["CPFInterest"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("CPF Interest.", nRow, "(" + row["CPFInterest"].ToString() + ")" + "This cannot be empty")); if (row["LoanPrincipalAdjust"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Loan Principal Adjust.", nRow, "(" + row["LoanPrincipalAdjust"].ToString() + ")" + "This cannot be empty")); if (row["LoanInterestAdjust"].ToString() == string.Empty) errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Loan Interest Adjust.", nRow, "(" + row["LoanInterestAdjust"].ToString() + ")" + "This cannot be empty")); memberNo = row["MemberNo"].ToString(); //Prepare Member Member oMember = new MemberService().Get(memberNo, fundtypeid); oMember.FinalSettlementDate = Convert.ToDateTime(row["SettlementDate"]); oMember.DOL = Convert.ToDateTime(row["SettlementDate"]); oMember.MemberStatus = EnumEmpStatus.Setteled; //Prepare Member Transaction Details //MembersTransactionDetail detail = new MembersTransactionDetail(); //detail.MemberID = oMember.ID; //detail.FundTypeID = fundtypeid; //detail.TranDate = Convert.ToDateTime(row["SettlementDate"]); //detail.Amount = 0; //detail.TranTypeID =(int) EnumMemberTranType.EPF_Settlement_Interest; //detail.Effect = EnumTranEffect.Increase; //detail.Member = oMember; //oMembersTransactionDetails.Add(detail); //detail = new MembersTransactionDetail(); //detail.MemberID = oMember.ID; //detail.FundTypeID = fundtypeid; //detail.TranDate = Convert.ToDateTime(row["SettlementDate"]); //detail.Amount = 0; //detail.TranTypeID = (int)EnumMemberTranType.EPF_Settlement_Interest; //detail.Effect = EnumTranEffect.Increase; //detail.Member = oMember; //oMembersTransactionDetails.Add(detail); //Prepare Loan FMLoan oLoan = new FMLoanService().GetByMemberID(oMember.ID); if (oLoan != null) { oLoan.LoanStatus = EnumFMLoanStatus.Close; //oLoan.TransferLogIDinInt = (int)EnumFMLoanTransferInfo.LoanInfoTransferToPR; oLoan.LoanSchedules.ForEach(item => { if (item.PayDate == null) { oLoan.InstallmentNo = item.SerialNo; item.PayDate = Convert.ToDateTime(row["SettlementDate"]); item.InstallmentInterest = 0; item.InstallmentPrincipal = item.EffectiveBalance; item.InstallmentAmount = item.EffectiveBalance; } }); } //Prepare Final Settlement PFFinalSettlement finalSettlement = new PFFinalSettlement(); finalSettlement.MemberID = oMember.ID; finalSettlement.LoanAmount =oLoan.PrincipalAmount; finalSettlement.EmpCode = oMember.EmpCode; finalSettlement.SettlementDate = Convert.ToDateTime(row["SettlementDate"]); finalSettlement.LastAudEPF = Convert.ToDouble(row["EPF"].ToString()); finalSettlement.LastAudCurrentEPFInterest = Convert.ToDouble(row["EPFInterest"].ToString()); finalSettlement.LastAudCPF = Convert.ToDouble(row["CPF"].ToString()); finalSettlement.LastAudCurrentCPFInterest = Convert.ToDouble(row["CPFInterest"].ToString()); finalSettlement.loanPrincipalRecovered = Convert.ToDouble(row["LoanPrincipalAdjust"].ToString()); finalSettlement.loanInterestRecovered = Convert.ToDouble(row["LoanInterestAdjust"].ToString()); finalSettlement.TotalPayment = (finalSettlement.LastAudEPF + finalSettlement.LastAudCPF + finalSettlement.LastAudCurrentEPFInterest + finalSettlement.LastAudCurrentCPFInterest) -(finalSettlement.loanPrincipalRecovered + finalSettlement.loanInterestRecovered); //Prepare for Save Only finalSettlement.SettleMemberInfo = new Member(); finalSettlement.SettleMemberInfo = oMember; finalSettlement.SettleMemberTransactionInfo = new List(); finalSettlement.SettleMemberTransactionInfo = oMembersTransactionDetails; finalSettlement.SettleMemberLoanInfo = new List (); finalSettlement.SettleMemberLoanInfo.Add(oLoan); oFinalSettlements.Add(finalSettlement); } //Save Final Settlement if(errorOrSuccessList.Count == 0) { Save(oFinalSettlements); } } catch (Exception ex) { ExceptionLog.Write(ex); throw new ServiceException("Failed to Save Data", ex); } return errorOrSuccessList; } #endregion Service implementation } }