311 lines
14 KiB
C#
311 lines
14 KiB
C#
|
|
using Ease.Core.DataAccess;
|
|||
|
|
using Ease.Core.Model;
|
|||
|
|
using Ease.Core.Utility;
|
|||
|
|
using HRM.BO;
|
|||
|
|
using HRM.DA.DA.Fund.VoucherSetup;
|
|||
|
|
using NPOI.SS.Formula.Functions;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using static HRM.BO.WPPFFundDistribution;
|
|||
|
|
using static iTextSharp.text.pdf.AcroFields;
|
|||
|
|
|
|||
|
|
namespace HRM.DA.Service.Fund.MemberInfo
|
|||
|
|
{
|
|||
|
|
public class WPPFFundDistributionService : ServiceTemplate, IWPPFFundDistributionService
|
|||
|
|
{
|
|||
|
|
public WPPFFundDistributionService()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void MapObject(WPPFFundDistribution oFundDistribution, DataReader oReader)
|
|||
|
|
{
|
|||
|
|
SetObjectID(oFundDistribution, oReader.GetInt32("FundDistributionID").Value);
|
|||
|
|
oFundDistribution.FiscalDate = oReader.GetDateTime("FiscalDate").Value;
|
|||
|
|
oFundDistribution.ReceivedFund = oReader.GetDouble("ReceivedFund").Value;
|
|||
|
|
oFundDistribution.ReceivedFundGLID = oReader.GetInt32("ReceivedFundGLID").Value;
|
|||
|
|
oFundDistribution.ParticipationFund = oReader.GetDouble("ParticipationFund").Value;
|
|||
|
|
oFundDistribution.ParticipationFundGLID = oReader.GetInt32("ParticipationFundGLID").Value;
|
|||
|
|
oFundDistribution.CompanyWelfareFund = oReader.GetDouble("CompanyWelfareFund").Value;
|
|||
|
|
oFundDistribution.CompanyWelfareFundGLID = oReader.GetInt32("CompanyWelfareFundGLID").Value;
|
|||
|
|
oFundDistribution.GovernmentWelfareFund = oReader.GetDouble("GovernmentWelfareFund").Value;
|
|||
|
|
oFundDistribution.GovernmentWelfareFundGLID = oReader.GetInt32("GovernmentWelfareFundGLID").Value;
|
|||
|
|
oFundDistribution.FundTypeID = oReader.GetInt32("FundTypeID").Value;
|
|||
|
|
oFundDistribution.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|||
|
|
oFundDistribution.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|||
|
|
oFundDistribution.ModifiedBy = oReader.GetInt32("ModifiedBy");
|
|||
|
|
oFundDistribution.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
|
oFundDistribution.GLTranID = oReader.GetInt32("GLTranID")==null? 0 : oReader.GetInt32("GLTranID").Value;
|
|||
|
|
oFundDistribution.VoucherDate = oReader.GetDateTime("VoucherDate") == null ? DateTime.MinValue : oReader.GetDateTime("VoucherDate").Value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
|
{
|
|||
|
|
WPPFFundDistribution oFundDistribution = new WPPFFundDistribution();
|
|||
|
|
MapObject(oFundDistribution, oReader);
|
|||
|
|
return oFundDistribution as T;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<WPPFFundDistribution> GetAllFundDistributions(int fundTypeID)
|
|||
|
|
{
|
|||
|
|
List<WPPFFundDistribution> fundDistributions = new List<WPPFFundDistribution>();
|
|||
|
|
TransactionContext tc = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
tc = TransactionContext.Begin();
|
|||
|
|
DataReader dr = new DataReader(WPPFFundDistributionDA.GetAllFundDistributions(tc, fundTypeID));
|
|||
|
|
fundDistributions = CreateObjects<WPPFFundDistribution>(dr);
|
|||
|
|
dr.Close();
|
|||
|
|
tc.End();
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
#region Handle Exception
|
|||
|
|
|
|||
|
|
if (tc != null)
|
|||
|
|
tc.HandleError();
|
|||
|
|
ExceptionLog.Write(e);
|
|||
|
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
return fundDistributions;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public WPPFFundDistribution Get(int id)
|
|||
|
|
{
|
|||
|
|
WPPFFundDistribution fundDistribution = new WPPFFundDistribution();
|
|||
|
|
TransactionContext tc = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
tc = TransactionContext.Begin();
|
|||
|
|
DataReader dr = new DataReader(WPPFFundDistributionDA.Get(tc, id));
|
|||
|
|
while (dr.Read())
|
|||
|
|
{
|
|||
|
|
fundDistribution = CreateObject<WPPFFundDistribution>(dr);
|
|||
|
|
}
|
|||
|
|
dr.Close();
|
|||
|
|
tc.End();
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
#region Handle Exception
|
|||
|
|
|
|||
|
|
if (tc != null)
|
|||
|
|
tc.HandleError();
|
|||
|
|
ExceptionLog.Write(e);
|
|||
|
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
return fundDistribution;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Update(WPPFFundDistribution fundDistribution)
|
|||
|
|
{
|
|||
|
|
TransactionContext tc = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
tc = TransactionContext.Begin();
|
|||
|
|
WPPFFundDistributionDA.Update(tc, fundDistribution);
|
|||
|
|
tc.End();
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
#region Handle Exception
|
|||
|
|
|
|||
|
|
if (tc != null)
|
|||
|
|
tc.HandleError();
|
|||
|
|
ExceptionLog.Write(e);
|
|||
|
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Delete(int id)
|
|||
|
|
{
|
|||
|
|
TransactionContext tc = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
WPPFFundDistribution wPPFFund = this.Get(id);
|
|||
|
|
tc = TransactionContext.Begin(true);
|
|||
|
|
if(wPPFFund.GLTranID > 0)
|
|||
|
|
{
|
|||
|
|
new GLTranService().Delete(tc, wPPFFund.GLTranID);
|
|||
|
|
}
|
|||
|
|
WPPFFundDistributionDA.Delete(tc, id);
|
|||
|
|
tc.End();
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
#region Handle Exception
|
|||
|
|
|
|||
|
|
if (tc != null)
|
|||
|
|
tc.HandleError();
|
|||
|
|
ExceptionLog.Write(e);
|
|||
|
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//public void Save(WPPFFundDistribution oWPPFFundDistribution)
|
|||
|
|
//{
|
|||
|
|
// TransactionContext tc = null;
|
|||
|
|
// try
|
|||
|
|
// {
|
|||
|
|
// tc = TransactionContext.Begin();
|
|||
|
|
// if (oWPPFFundDistribution.IsNew)
|
|||
|
|
// {
|
|||
|
|
// WPPFFundDistributionDA.Insert(tc, oWPPFFundDistribution);
|
|||
|
|
// }
|
|||
|
|
// else
|
|||
|
|
// {
|
|||
|
|
// WPPFFundDistributionDA.Update(tc, oWPPFFundDistribution);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// List<GLTranDetail> gLTDlist = new List<GLTranDetail>();
|
|||
|
|
// //received dr
|
|||
|
|
// GLTranDetail gLTDReceive = new GLTranDetail(oWPPFFundDistribution.ReceivedFundGLID, EnumTranSide.Debit, (double)oWPPFFundDistribution.ReceivedFund, "WPPF Fund Destribution Received");
|
|||
|
|
// gLTDlist.Add(gLTDReceive);
|
|||
|
|
// //Participation cr
|
|||
|
|
// GLTranDetail gLTDParticipation = new GLTranDetail(oWPPFFundDistribution.ParticipationFundGLID, EnumTranSide.Credit, (double)oWPPFFundDistribution.ParticipationFundGLID, "WPPF Fund Destribution Participation");
|
|||
|
|
// gLTDlist.Add(gLTDParticipation);
|
|||
|
|
// //company cr
|
|||
|
|
// GLTranDetail gLTDCWF = new GLTranDetail(oWPPFFundDistribution.CompanyWelfareFundGLID, EnumTranSide.Credit, (double)oWPPFFundDistribution.CompanyWelfareFund, "WPPF Fund Destribution Company Welfare");
|
|||
|
|
// gLTDlist.Add(gLTDCWF);
|
|||
|
|
// //Govt cr
|
|||
|
|
// GLTranDetail gLTDGovt = new GLTranDetail(oWPPFFundDistribution.GovernmentWelfareFundGLID, EnumTranSide.Credit, (double)oWPPFFundDistribution.GovernmentWelfareFund, "WPPF Fund Destribution Govt Welfare");
|
|||
|
|
// gLTDlist.Add(gLTDCWF);
|
|||
|
|
|
|||
|
|
// GLTran gLTran = new GLTran();
|
|||
|
|
// gLTran.GlTranDetails = gLTDlist;
|
|||
|
|
// gLTran.GLTranType = EnumGLTranType.WPPFFundDistribution;
|
|||
|
|
// gLTran.Description = "WPPF Fund Distribution ";
|
|||
|
|
// gLTran.VoucherDate = oWPPFFundDistribution.CreatedDate;
|
|||
|
|
// gLTran.CreatedDate = DateTime.Now;
|
|||
|
|
// gLTran.CreatedBy = oWPPFFundDistribution.CreatedBy;
|
|||
|
|
// gLTran.FundTypeID = oWPPFFundDistribution.FundTypeID;
|
|||
|
|
|
|||
|
|
// new GLTranService().Save(tc,gLTran);
|
|||
|
|
// tc.End();
|
|||
|
|
// }
|
|||
|
|
// catch (Exception e)
|
|||
|
|
// {
|
|||
|
|
// #region Handle Exception
|
|||
|
|
|
|||
|
|
// if (tc != null)
|
|||
|
|
// tc.HandleError();
|
|||
|
|
// ExceptionLog.Write(e);
|
|||
|
|
// throw new ServiceException(e.Message, e);
|
|||
|
|
|
|||
|
|
// #endregion
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
public void DistributeParticipantFund(int fundGL, int memberGL, List<Member> members, double distributeAmount, double amountToDistribute, DateTime voucherDate, int fundTypeID, CurrentUser currentUser)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
//Fund GL
|
|||
|
|
List<GLTranDetail> gLTranDetailsList = new List<GLTranDetail>();
|
|||
|
|
GLTranDetail fundGLTran = new GLTranDetail(fundGL, EnumTranSide.Debit, distributeAmount, "WPPF Perticipation Fund");
|
|||
|
|
gLTranDetailsList.Add(fundGLTran);
|
|||
|
|
//member
|
|||
|
|
GLTranDetail memberGLTran = new GLTranDetail(memberGL, EnumTranSide.Credit, 0, "WPPF Perticipation Member's");
|
|||
|
|
//double amountToDistribute = Math.Round(distributeAmount / members.Count, 2);
|
|||
|
|
if (memberGLTran.GLTranUserRecords == null)
|
|||
|
|
{
|
|||
|
|
memberGLTran.GLTranUserRecords = new List<GLTranUserRecord>();
|
|||
|
|
}
|
|||
|
|
List<UserRecord> orecords = new UserRecordService().Get(GlobalFunctions.Fund_UserObject_Member, fundTypeID);
|
|||
|
|
UserRecord userRecord = new UserRecord();
|
|||
|
|
GLTranUserRecord gLTranUserRecord;
|
|||
|
|
foreach (Member member in members)
|
|||
|
|
{
|
|||
|
|
userRecord = orecords.FirstOrDefault(x => x.Field1 == member.EmpCode);
|
|||
|
|
gLTranUserRecord = new GLTranUserRecord(memberGL, 0, 0, GlobalFunctions.Fund_UserObject_Member, userRecord.ID, amountToDistribute);
|
|||
|
|
memberGLTran.GLTranUserRecords.Add(gLTranUserRecord);
|
|||
|
|
}
|
|||
|
|
memberGLTran.Amount =Math.Round((double)memberGLTran.GLTranUserRecords.Sum(x => x.Amount),2);
|
|||
|
|
|
|||
|
|
gLTranDetailsList.Add(memberGLTran);
|
|||
|
|
|
|||
|
|
GLTran gLTran = new GLTran();
|
|||
|
|
gLTran.GlTranDetails = gLTranDetailsList;
|
|||
|
|
gLTran.GLTranType = EnumGLTranType.WPPFFundDistribution;
|
|||
|
|
gLTran.Description = "WPPF Fund Distribution to Members " ;
|
|||
|
|
gLTran.VoucherDate = voucherDate;
|
|||
|
|
gLTran.CreatedDate = DateTime.Now;
|
|||
|
|
gLTran.CreatedBy = currentUser.UserID;
|
|||
|
|
gLTran.FundTypeID = fundTypeID;
|
|||
|
|
gLTran.DebitAmount = Math.Round(gLTran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Debit).Sum(x => x.Amount));
|
|||
|
|
gLTran.CreditAmount = Math.Round(gLTran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Credit).Sum(x => x.Amount));
|
|||
|
|
|
|||
|
|
new GLTranService().Save(gLTran);
|
|||
|
|
}catch(Exception e)
|
|||
|
|
{
|
|||
|
|
#region Handle Exception
|
|||
|
|
ExceptionLog.Write(e);
|
|||
|
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public void Save(WPPFFundDistribution oWPPFFundDistribution)
|
|||
|
|
{
|
|||
|
|
TransactionContext tc = null;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
List<GLTranDetail> gLTDlist = new List<GLTranDetail>();
|
|||
|
|
//received dr
|
|||
|
|
GLTranDetail gLTDReceive = new GLTranDetail(oWPPFFundDistribution.ReceivedFundGLID, EnumTranSide.Debit, (double)oWPPFFundDistribution.ReceivedFund, "WPPF Fund Destribution Received");
|
|||
|
|
gLTDlist.Add(gLTDReceive);
|
|||
|
|
//Participation cr
|
|||
|
|
GLTranDetail gLTDParticipation = new GLTranDetail(oWPPFFundDistribution.ParticipationFundGLID, EnumTranSide.Credit, (double)oWPPFFundDistribution.ParticipationFund, "WPPF Fund Destribution Participation");
|
|||
|
|
gLTDlist.Add(gLTDParticipation);
|
|||
|
|
//company cr
|
|||
|
|
GLTranDetail gLTDCWF = new GLTranDetail(oWPPFFundDistribution.CompanyWelfareFundGLID, EnumTranSide.Credit, (double)oWPPFFundDistribution.CompanyWelfareFund, "WPPF Fund Destribution Company Welfare");
|
|||
|
|
gLTDlist.Add(gLTDCWF);
|
|||
|
|
//Govt cr
|
|||
|
|
GLTranDetail gLTDGovt = new GLTranDetail(oWPPFFundDistribution.GovernmentWelfareFundGLID, EnumTranSide.Credit, (double)oWPPFFundDistribution.GovernmentWelfareFund, "WPPF Fund Destribution Govt Welfare");
|
|||
|
|
gLTDlist.Add(gLTDGovt);
|
|||
|
|
|
|||
|
|
GLTran gLTran = new GLTran();
|
|||
|
|
gLTran.GlTranDetails = gLTDlist;
|
|||
|
|
gLTran.GLTranType = EnumGLTranType.WPPFFundDistribution;
|
|||
|
|
gLTran.Description = "WPPF Fund Distribution ";
|
|||
|
|
gLTran.VoucherDate = oWPPFFundDistribution.VoucherDate;
|
|||
|
|
gLTran.CreatedDate = DateTime.Now;
|
|||
|
|
gLTran.CreatedBy = oWPPFFundDistribution.CreatedBy;
|
|||
|
|
gLTran.FundTypeID = oWPPFFundDistribution.FundTypeID;
|
|||
|
|
gLTran.DebitAmount = gLTran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Debit).Sum(x => x.Amount);
|
|||
|
|
gLTran.CreditAmount = gLTran.GlTranDetails.Where(x => x.Transide == EnumTranSide.Credit).Sum(x => x.Amount);
|
|||
|
|
|
|||
|
|
tc = TransactionContext.Begin(true);
|
|||
|
|
oWPPFFundDistribution.GLTranID = new GLTranService().Save(tc, gLTran);
|
|||
|
|
|
|||
|
|
if (oWPPFFundDistribution.IsNew)
|
|||
|
|
{
|
|||
|
|
WPPFFundDistributionDA.Insert(tc, oWPPFFundDistribution);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
WPPFFundDistributionDA.Update(tc, oWPPFFundDistribution);
|
|||
|
|
}
|
|||
|
|
tc.End();
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
#region Handle Exception
|
|||
|
|
|
|||
|
|
if (tc != null)
|
|||
|
|
tc.HandleError();
|
|||
|
|
ExceptionLog.Write(e);
|
|||
|
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|