154 lines
6.3 KiB
C#
154 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Ease.Core.DataAccess;
|
|
using HRM.DA;
|
|
using HRM.BO;
|
|
using HRM.BO.Fund;
|
|
using Ease.Core.Model;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class YearEndService : ServiceTemplate, IYearEndService
|
|
{
|
|
protected override T CreateObject<T>(DataReader dataReader)
|
|
{
|
|
YearEnd yearEnd = new YearEnd();
|
|
return yearEnd as T;
|
|
}
|
|
|
|
#region IYearEndService Members
|
|
|
|
public void UndoYearEnd(int GLtranID, FundType oFundType)
|
|
{
|
|
try
|
|
{
|
|
TransactionContext tc = null;
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
GLTranService oservice = new GLTranService();
|
|
oservice.Delete(tc, GLtranID);
|
|
|
|
if (oFundType.ProfitDistributionDuration == EnumProfitDistributionDuration.Monthly)
|
|
oFundType.LastProfitDistributionMonth = oFundType.LastProfitDistributionMonth.AddMonths(-1);
|
|
if (oFundType.ProfitDistributionDuration == EnumProfitDistributionDuration.Half_Yearly)
|
|
oFundType.LastProfitDistributionMonth = oFundType.LastProfitDistributionMonth.AddMonths(-6);
|
|
if (oFundType.ProfitDistributionDuration == EnumProfitDistributionDuration.Yearly)
|
|
oFundType.LastProfitDistributionMonth = oFundType.LastProfitDistributionMonth.AddMonths(-12);
|
|
oFundType.LastProfitDistributionMonth = GlobalFunctions.LastDateOfMonth(oFundType.LastProfitDistributionMonth);
|
|
oFundType.CurrentMonth =GlobalFunctions.LastDateOfMonth(oFundType.LastProfitDistributionMonth);
|
|
new FundTypeService().UpdateProfitDistributedMonth(tc,oFundType.LastProfitDistributionMonth, oFundType.CurrentMonth, oFundType.ID); // undo year-End Date
|
|
tc.End();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("failed to Undo YearEnd: " + ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
public void UndoDistribute(int GLtranID, FundType oFundType)
|
|
{
|
|
try
|
|
{
|
|
TransactionContext tc = null;
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
new GLTranService().Delete(tc, GLtranID);
|
|
new MembersTransactionDetailsService().DeleteYearEndInterestTran(tc, oFundType.LastProfitDistributionMonth, oFundType.ID);
|
|
tc.End();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("failed to Undo YearEnd: " + ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
|
|
public void DoYearEnd(FundType oFundType, GLTran oTran)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
GLTranService orv = new GLTranService();
|
|
bool yearEndAlreadyDone = orv.VoucherExist(EnumGLTranType.YearEndVoucher,
|
|
GlobalFunctions.FirstDateOfMonth(oFundType.LastProfitDistributionMonth.AddDays(1)),
|
|
oFundType.NextProfitDistributionMonth, oFundType.ID);
|
|
// bool voucherAfterYearEnd = orv.VoucherExist(EnumGLTranType.YearEndVoucher, GlobalFunctions.FirstDateOfMonth(oFundType.LastProfitDistributionMonth), oFundType.LastProfitDistributionMonth, oFundType.ID);
|
|
|
|
if (yearEndAlreadyDone == true)
|
|
{
|
|
throw new Exception("Year-End is already completed. (Profit/Losss)");
|
|
}
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
GLTranService oservice = new GLTranService();
|
|
|
|
new GLTranService().Save(tc, oTran);
|
|
if (oFundType.ProfitDistributionDuration == EnumProfitDistributionDuration.Monthly)
|
|
oFundType.LastProfitDistributionMonth= oFundType.LastProfitDistributionMonth.AddMonths(1);
|
|
if (oFundType.ProfitDistributionDuration == EnumProfitDistributionDuration.Half_Yearly)
|
|
oFundType.LastProfitDistributionMonth = oFundType.LastProfitDistributionMonth.AddMonths(6);
|
|
if (oFundType.ProfitDistributionDuration == EnumProfitDistributionDuration.Yearly)
|
|
oFundType.LastProfitDistributionMonth = oFundType.LastProfitDistributionMonth.AddMonths(12);
|
|
|
|
oFundType.LastProfitDistributionMonth = GlobalFunctions.LastDateOfMonth(oFundType.LastProfitDistributionMonth);
|
|
oFundType.CurrentMonth = GlobalFunctions.LastDateOfMonth(oFundType.CurrentMonth.AddMonths(1));
|
|
|
|
new FundTypeService().UpdateProfitDistributedMonth(tc, oFundType.LastProfitDistributionMonth, oFundType.CurrentMonth, oFundType.ID);
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new Exception("Save failed : " + e.Message, e);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void DoDistributeDivident(FundType oFundType, GLTran oTran, List<MembersTransactionDetail> membertransactions)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
GLTranService orv = new GLTranService();
|
|
bool yearEndAlreadyDone = orv.VoucherExist(EnumGLTranType.DividendDistribution, GlobalFunctions.FirstDateOfMonth(oFundType.LastProfitDistributionMonth), oFundType.LastProfitDistributionMonth, oFundType.ID);
|
|
|
|
if (yearEndAlreadyDone == true)
|
|
{
|
|
throw new Exception("Devident is already distributed. (Profit/Losss)");
|
|
}
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
new GLTranService().Save(tc, oTran);
|
|
new MembersTransactionDetailsService().SaveBulk(tc, membertransactions);
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new Exception("Save failed : " + e.Message, e);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IFASService Members
|
|
|
|
public void SaveVoucher(TransactionContext tc, List<GLTran> glTrans, int investActivitiesInInt)
|
|
{
|
|
GLTranService glTranService = new GLTranService();
|
|
if (glTrans != null)
|
|
{
|
|
foreach (GLTran glTran in glTrans)
|
|
{
|
|
glTranService.Save(tc, glTran);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|