HRM-10/HRM.UI/Controllers/FundAdmin/FundController.cs

3901 lines
154 KiB
C#
Raw Normal View History

2026-11-03 13:06:00 +06:00
using HRM.BO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System;
using Microsoft.AspNetCore.Authorization;
using HRM.DA;
using System.Data;
using Ease.Core.DataAccess;
using HRM.BO.Configuration;
using Microsoft.Extensions.Configuration;
using System.IO;
using System.Text;
using Member = HRM.BO.Member;
using System.Configuration;
using Ease.Core.Model;
using HRM.BO.Fund;
using Microsoft.Reporting.Map.WebForms.BingMaps;
using System.Threading.Tasks;
using HRM.Report;
using Microsoft.Extensions.Caching.Memory;
using System.Linq;
using FM.DA;
using static iTextSharp.text.pdf.AcroFields;
using System.Collections;
using NPOI.SS.Formula.Functions;
using System.Reflection;
using Google.Protobuf.WellKnownTypes;
using Newtonsoft.Json.Linq;
namespace HRM.UI
{
[ApiController]
[Route("api/Fund")]
[Authorize]
public class FundController : ControllerBase
{
public FundController(
IFundTypeService fundTypeService,
IGLService glService,
IMemberService memberService,
IUserObjectService userObjectService,
IFundBankService fundBankService,
IUserRecordService userRecordService,
IProjectProcessService projectProcessService,
IFMLoanCategoryService loanCategoryService,
IInvestmentCategoryService investmentCategoryService,
ITrusteeInfoService trusteeInfoService,
IActivityVoucherSetupService activityVoucherSetupService,
IInvestmentService investmentService,
IFundBranchService fundBranchService,
IInvestmentScheduleService investmentScheduleService,
IFMLoanService fmLoanService,
IFMLoanScheduleService fmLoanScheduleService,
IPFFinalSettlementService finalSettlementService,
IMembersTransactionDetailsService membersTransactionDetailsService,
IRDReportService reportService,
INewInvestmentService newInvestmentService,
IRDReportRowService reportRowService,
ILoanApplicationService loanApplicationService,
IPFWithdrawalRequestService pfWithdrawalRequestService,
IESBSlabService eSBSlabService,
IGFSettlementService gFSettlementService,
IWPPFFundDistributionService wppfFundDistributionService,
IMemoryCache cache,
IGLTranService gLTranService,
IYearEndService yearEndService,
IRowSumCalcItemService rowSumCalcItemService,
IWPPFSettlementService wPPFSettlementService,
IFMLoanAttachmentService fMLoanAttachmentService,
IFundUserPermissionService fundUserPermissionService
)
{
this._fundTypeService = fundTypeService;
this._gLService = glService;
this._memberService = memberService;
this._userObjectService = userObjectService;
this._fundBankService = fundBankService;
this._userRecordService = userRecordService;
this._trusteeInfoService = trusteeInfoService;
this._projectProcessService = projectProcessService;
this._loanCategoryService = loanCategoryService;
this._investmentCategoryService = investmentCategoryService;
this._activityVoucherSetupService = activityVoucherSetupService;
this._investmentService = investmentService;
this._fundBranchService = fundBranchService;
this._investmentScheduleService = investmentScheduleService;
this._fmLoanService = fmLoanService;
this._fmLoanScheduleService = fmLoanScheduleService;
this._finalSettlementService = finalSettlementService;
this._membersTransactionDetailsService = membersTransactionDetailsService;
this._newInvestmentService = newInvestmentService;
this._rDReportService = reportService;
this._rRDReportRowService = reportRowService;
this._loanApplicationService = loanApplicationService;
this._pfWithdrawalRequestService = pfWithdrawalRequestService;
this._eSBSlabService = eSBSlabService;
this._gFSettlementService = gFSettlementService;
this._wppfFundDistributionService = wppfFundDistributionService;
this._cache = cache;
this._glTranService = gLTranService;
this._yearEndService = yearEndService;
this._rowSumCalcItemService = rowSumCalcItemService;
this._wPPFSettlementService = wPPFSettlementService;
this._fmLoanAttachmentService = fMLoanAttachmentService;
this._fundUserPermissionService = fundUserPermissionService; // <-- assign
}
private readonly IFundTypeService _fundTypeService;
private readonly IGLService _gLService;
private readonly IMemberService _memberService;
private readonly IUserObjectService _userObjectService;
private readonly IUserRecordService _userRecordService;
private readonly IFundBankService _fundBankService;
private readonly ITrusteeInfoService _trusteeInfoService;
private readonly IProjectProcessService _projectProcessService;
private readonly IFMLoanCategoryService _loanCategoryService;
private readonly IInvestmentCategoryService _investmentCategoryService;
private readonly IActivityVoucherSetupService _activityVoucherSetupService;
private readonly IInvestmentService _investmentService;
private readonly IFundBranchService _fundBranchService;
private readonly IInvestmentScheduleService _investmentScheduleService;
private readonly IFMLoanService _fmLoanService;
private readonly IFMLoanScheduleService _fmLoanScheduleService;
private readonly IPFFinalSettlementService _finalSettlementService;
private readonly IMembersTransactionDetailsService _membersTransactionDetailsService;
private readonly INewInvestmentService _newInvestmentService;
private readonly IRDReportService _rDReportService;
private readonly IRDReportRowService _rRDReportRowService;
private readonly ILoanApplicationService _loanApplicationService;
private readonly IPFWithdrawalRequestService _pfWithdrawalRequestService;
private readonly IESBSlabService _eSBSlabService;
private readonly IGFSettlementService _gFSettlementService;
private readonly IWPPFFundDistributionService _wppfFundDistributionService;
private readonly IMemoryCache _cache;
private readonly IGLTranService _glTranService;
private readonly IYearEndService _yearEndService;
private readonly IRowSumCalcItemService _rowSumCalcItemService;
private readonly IWPPFSettlementService _wPPFSettlementService;
private readonly IFMLoanAttachmentService _fmLoanAttachmentService;
private readonly IFundUserPermissionService _fundUserPermissionService;
[HttpGet("getAllFundTypes")]
public ActionResult GetAllFundTypes()
{
List<FundType> items = new List<FundType>();
try
{
items = _fundTypeService.GetAllFundTypes();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
//[HttpGet("getAllGL")]
//public ActionResult GetAllGL()
//{
// List<GL> items = new List<GL>();
// try
// {
// items = _gLService.GetByTier(4);
// }
// catch (Exception ex)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
// }
// return Ok(items);
//}
[HttpGet("getAllGLByFundType/{fundTypeID}")]
public ActionResult GetAllGLByFundType(int fundTypeID)
{
List<GL> items = new List<GL>();
try
{
items = _gLService.GetByTier(4, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
//[HttpGet("getAllMembers")]
//public ActionResult GetAllMembers()
//{
// List<Member> items = new List<Member>();
// try
// {
// items = _memberService.Get();
// }
// catch (Exception ex)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
// }
// return Ok(items);
//}
[HttpGet("getMember/{memberID}")]
public ActionResult GetMember(int memberID)
{
Member items = new Member();
try
{
items = _memberService.Get(memberID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getAllMembersByFundType/{fundTypeID}")]
public ActionResult GetAllMembersByFundType(int fundTypeID)
{
List<Member> items = new List<Member>();
try
{
items = _memberService.GetByFundType(fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("getSearchMembers")]
public ActionResult GetSearchMembers(dynamic data)
{
List<Member> items = new List<Member>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
string empCode = item["empCode"].ToObject<string>();
string name = (string)item["name"].ToObject<string>();
bool isMembershipDate = (bool)item["isMembershipDate"].ToObject<bool>();
DateTime membershipFromDate = (DateTime)item["membershipFromDate"].ToObject<DateTime>();
DateTime membershipToDate = (DateTime)item["membershipToDate"].ToObject<DateTime>();
bool isJoiningDate = (bool)item["isJoiningDate"].ToObject<bool>();
DateTime joiningFromDate = (DateTime)item["joiningFromDate"].ToObject<DateTime>();
DateTime joiningToDate = (DateTime)item["joiningToDate"].ToObject<DateTime>();
int statusID = (int)item["statusID"].ToObject<int>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
try
{
items = _memberService.GetSearchMembers(empCode, name, isMembershipDate, membershipFromDate, membershipToDate, isJoiningDate, joiningFromDate, joiningToDate, statusID, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getGLByFundTypeID/{fundTypeID}")]
public ActionResult GetGLByFundTypeID(int fundTypeID)
{
List<GL> items = new List<GL>();
try
{
items = _gLService.GetGLByFundTypeID(fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("deleteGL")]
public ActionResult DeleteGL(dynamic data)
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int id = item["id"].ToObject<int>();
try
{
_gLService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("deleteGLwithReference")]
public ActionResult deleteGLwithReference(GLTran otran)
{
try
{
new GLTranService().DeleteWithReference(otran.ID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getGLByID/{id}")]
public ActionResult GetGLByID(int id)
{
GL item = new GL();
try
{
item = _gLService.Get(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpPost]
[Route("saveGL")]
public ActionResult SaveGL(GL data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (data.IsNew)
{
data.CreatedBy = currentUser.UserID;
data.CreatedDate = DateTime.Now;
}
else
{
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Today;
}
try
{
int GLID = 0;
GLID = _gLService.Save(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getUserObjectByFundTypeID/{id}")]
public ActionResult GetUserObjectByFundTypeID(int id)
{
List<UserObject> items = new List<UserObject>();
UserObject member = new UserObject();
member.ID = GlobalFunctions.Fund_UserObject_Member;
member.Name = "Member";
member.FundTypeID = id;
items.Add(member);
UserObject Loan = new UserObject();
Loan.ID = GlobalFunctions.Fund_UserObject_Loan;
Loan.Name = "Loan";
Loan.FundTypeID = id;
items.Add(Loan);
UserObject Investment = new UserObject();
Investment.ID = GlobalFunctions.Fund_UserObject_Investment;
Investment.Name = "Investment";
Investment.FundTypeID = id;
items.Add(Investment);
try
{
// items = _userObjectService.GetUserObjectByFundTypeID(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getUserRecordByUserObjectID/{id}/{fundtypeid}")]
public ActionResult GetUserRecordByUserObjectID(int id, int fundtypeid)
{
List<UserRecord> items = new List<UserRecord>();
try
{
items = _userRecordService.GetUserRecordByUserObjectID(id, fundtypeid);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getGLByUserObjectID/{id}/{fundTypeID}")]
public ActionResult GetGLByUserObjectID(int id, int fundTypeID)
{
List<GL> items = new List<GL>();
try
{
items = _gLService.GetGLByUserObjectID(id, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getFundBanks")]
public ActionResult GetFundBanks()
{
List<FundBank> items = new List<FundBank>();
try
{
items = _fundBankService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getFundBankByID/{id}")]
public ActionResult GetFundBankByID(int id)
{
FundBank item = new FundBank();
try
{
item = _fundBankService.Get(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpPost]
[Route("saveFundBankObject")]
public ActionResult SaveFundBankObject(FundBank obj)
{
int ans;
try
{
var isNew = obj.ID <= 0;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (isNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Today;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
ans = _fundBankService.Save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(ans);
}
[HttpGet("deleteFundBankObject/{id}")]
public ActionResult DeleteObject(int id)
{
try
{
this._fundBankService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("saveFundBranch")]
public ActionResult SaveFundBranch(FundBranch obj)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
try
{
_fundBranchService.Save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getBranch")]
public ActionResult GetBranch()
{
List<FundBranch> branches = new List<FundBranch>();
try
{
branches = _fundBranchService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(branches);
}
[HttpGet("getBranchByFundTypeID/{fundTypeID}")]
public ActionResult GetBranchByFundTypeID(int fundTypeID)
{
List<FundBranch> branches = new List<FundBranch>();
try
{
branches = _fundBranchService.GetBranchByFundTypeID(fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(branches);
}
[HttpGet("deleteFundBranch/{id}")]
public ActionResult DeleteFundBranch(int id)
{
try
{
this._fundBranchService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("saveInvestment")]
public ActionResult SaveInvestment(InvestmentCategory obj)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
try
{
_investmentCategoryService.Save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getInvestmentCategory")]
public ActionResult GetInvestmentCategory()
{
List<InvestmentCategory> InvestmentCategory = new List<InvestmentCategory>();
try
{
InvestmentCategory = _investmentCategoryService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(InvestmentCategory);
}
[HttpGet("deleteInvestmentCategory/{id}")]
public ActionResult DeleteInvestmentCategory(int id)
{
try
{
this._investmentCategoryService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("saveLoanCategory")]
public ActionResult SaveLoanCategory(FMLoanCategory obj)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
try
{
_loanCategoryService.Save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getLoanCategory")]
public ActionResult GetLoanCategory()
{
List<FMLoanCategory> loanCategory = new List<FMLoanCategory>();
try
{
loanCategory = _loanCategoryService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanCategory);
}
[HttpGet("deleteLoanCategory/{id}")]
public ActionResult DeleteLoanCategory(int id)
{
try
{
this._loanCategoryService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("saveTrustee")]
public ActionResult SaveTrustee(TrusteeInfo obj)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
try
{
_trusteeInfoService.Save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getTrusteeList")]
public ActionResult GetTrusteeList()
{
List<TrusteeInfo> trusteeList = new List<TrusteeInfo>();
try
{
trusteeList = _trusteeInfoService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(trusteeList);
}
[HttpGet("deleteTrustee/{id}")]
public ActionResult DeleteTrustee(int id)
{
try
{
_trusteeInfoService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpGet("getMembersByFundTypeID/{id}")]
public ActionResult GetMembersByFundTypeID(int id)
{
List<TrusteeInfo> trusteeInfos = new List<TrusteeInfo>();
try
{
trusteeInfos = _trusteeInfoService.GetByFundType(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(trusteeInfos);
}
[HttpGet("getAllProjectProcessByFundTypeID/{id}")]
public ActionResult GetAllProjectProcessByFundTypeID(int id)
{
List<ProjectProcess> item = new List<ProjectProcess>();
try
{
item = _projectProcessService.GetByFundType(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpGet("getAllLoanCategory/{id}")]
public ActionResult GetAllLoanCategory(int id)
{
List<FMLoanCategory> item = new List<FMLoanCategory>();
try
{
item = _loanCategoryService.GetByFundType(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpGet("getAllInvestmentCategory/{id}")]
public ActionResult GetAllInvestmentCategory(int id)
{
List<InvestmentCategory> item = new List<InvestmentCategory>();
try
{
item = _investmentCategoryService.GetByFundType(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpGet("getAllActivityVoucherSetupsIDOnly/{id}")]
public ActionResult getAllActivityVoucherSetupsIDOnly(int id)
{
DataTable items = new DataTable();
try
{
items = _activityVoucherSetupService.GetProcessIDsByFundType(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getActivityVoucherSetupsByProcessID/{id}")]
public ActionResult getActivityVoucherSetupsByProcessID(int id)
{
List<ActivityVoucherSetup> items = new List<ActivityVoucherSetup>();
try
{
items = _activityVoucherSetupService.GetByProcessID(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("deleteActivityVoucherSetupById/{id}")]
public ActionResult deleteActivityVoucherSetupById(int id)
{
try
{
_activityVoucherSetupService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("deleteActivityVoucherSetupByProcessID/{id}")]
public ActionResult deleteActivityVoucherSetupByProcessID(int id)
{
try
{
_activityVoucherSetupService.DeleteByProcessID(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveActivityVoucherSetup")]
public ActionResult saveActivityVoucherSetup(List<ActivityVoucherSetup> items)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
foreach (ActivityVoucherSetup item in items)
{
if (item.IsNew)
{
item.CreatedBy = currentUser.UserID;
item.CreatedDate = DateTime.Now;
}
else
{
item.ModifiedBy = currentUser.UserID;
item.ModifiedDate = DateTime.Today;
}
_activityVoucherSetupService.Save(item);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getInvestInfo")]
public ActionResult GetInvestInfo(dynamic data)
{
List<InvestmentInfo> items = new List<InvestmentInfo>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
int investmentCategoryID = (int)item["investmentCategoryID"].ToObject<int>();
int investmentStatusID = (int)item["investmentStatusID"].ToObject<int>();
try
{
string sSearch = "";
if (investmentCategoryID > 0)
{
sSearch = GlobalFunctions.TagSQL(sSearch, "CategoryID= " + investmentCategoryID);
}
if (investmentStatusID > 0)
{
sSearch = GlobalFunctions.TagSQL(sSearch, "CurrentStatus= " + investmentStatusID);
}
items = _investmentService.GetBySearch(sSearch, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("getAccrualInvestmentInfo")]
public ActionResult GetAccrualInvestmentInfo(dynamic data)
{
List<InvestmentInfo> items = new List<InvestmentInfo>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
int investmentCategoryID = (int)item["investmentCategoryID"].ToObject<int>();
int investmentStatusID = (int)item["investmentStatusID"].ToObject<int>();
DateTime processMonth = (DateTime)item["processMonth"].ToObject<DateTime>();
try
{
string sSearch = "";
if (investmentCategoryID > 0)
{
sSearch = GlobalFunctions.TagSQL(sSearch, "CategoryID= " + investmentCategoryID);
}
if (investmentStatusID > 0)
{
sSearch = GlobalFunctions.TagSQL(sSearch, "CurrentStatus= " + investmentStatusID);
}
items = _investmentService.GetAccrualInfo(sSearch, fundTypeID, processMonth);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getAllBranch")]
public ActionResult GetAllBranch()
{
List<FundBranch> items = new List<FundBranch>();
try
{
items = _fundBranchService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getBranchByBankID/{bankID}")]
public ActionResult GetBranchByBankID(int bankID)
{
List<FundBranch> items = new List<FundBranch>();
try
{
items = _fundBranchService.GetBranchByBankID(bankID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getAllInvestmentSchedules")]
public ActionResult GetAllInvestmentSchedules()
{
List<InvestmentSchedule> items = new List<InvestmentSchedule>();
try
{
items = _investmentScheduleService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("deleteInvestmentInfo/{id}")]
public ActionResult deleteInvestmentInfo(int id)
{
try
{
_investmentService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getTrusteesByFundType/{id}")]
public ActionResult GetTrusteesByFundType(int id)
{
List<TrusteeInfo> item = new List<TrusteeInfo>();
try
{
item = _trusteeInfoService.GetByFundType(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpGet("getFundBanksByFundTypeID/{fundTypeID}")]
public ActionResult GetFundBanksByFundTypeID(int fundTypeID)
{
List<FundBank> item = new List<FundBank>();
try
{
item = _fundBankService.GetByFundTypeID(fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpPost]
[Route("saveInvestmentInfo")]
public ActionResult SaveInvestmentInfo(InvestmentInfo item)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
if (item.IsNew)
{
item.CreatedBy = currentUser.UserID;
item.CreatedDate = DateTime.Now;
}
else
{
item.ModifiedBy = currentUser.UserID;
item.ModifiedDate = DateTime.Now;
}
foreach (InvestmentSchedule row1 in item.InvestmentSchedules)
{
if (row1.IsNew)
{
row1.CreatedBy = currentUser.UserID;
row1.CreatedDate = DateTime.Now;
}
else
{
row1.ModifiedBy = currentUser.UserID;
row1.ModifiedDate = DateTime.Now;
}
}
foreach (InvestmentSignatory row2 in item.InvestmentSignatorys)
{
if (row2.IsNew)
{
row2.CreatedBy = currentUser.UserID;
row2.CreatedDate = DateTime.Now;
}
else
{
row2.ModifiedBy = currentUser.UserID;
row2.ModifiedDate = DateTime.Now;
}
}
_investmentService.Save(item);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveInvestmentRenewal")]
public ActionResult SaveInvestmentRenewal(InvestmentInfo item)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
if (item.IsNew)
{
item.CreatedBy = currentUser.UserID;
item.CreatedDate = DateTime.Now;
}
else
{
item.ModifiedBy = currentUser.UserID;
item.ModifiedDate = DateTime.Now;
}
foreach (InvestmentSchedule row1 in item.InvestmentSchedules)
{
if (row1.IsNew)
{
row1.CreatedBy = currentUser.UserID;
row1.CreatedDate = DateTime.Now;
}
else
{
row1.ModifiedBy = currentUser.UserID;
row1.ModifiedDate = DateTime.Now;
}
}
foreach (InvestmentSignatory row2 in item.InvestmentSignatorys)
{
if (row2.IsNew)
{
row2.CreatedBy = currentUser.UserID;
row2.CreatedDate = DateTime.Now;
}
else
{
row2.ModifiedBy = currentUser.UserID;
row2.ModifiedDate = DateTime.Now;
}
}
_investmentService.SaveInvestmentRenewal(item);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getMonthlyInterestAmount")]
public ActionResult GetMonthlyInterestAmount(InvestmentInfo data)
{
InvestmentInfo item = null;
try
{
List<FundType> ofundType = new FundTypeService().GetAllFundTypes();
DateTime lastProcessDate = ofundType.Find(x => x.ID == data.FundTypeID).CurrentMonth;
item = _investmentService.GetMonthlyInterestAmount(data, lastProcessDate);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpPost]
[Route("saveMonthlyBenifitsAccrual")]
public ActionResult SaveMonthlyBenifitsAccrual(InvestmentInfo data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
if (data.IsNew)
{
data.CreatedBy = currentUser.UserID;
data.CreatedDate = DateTime.Now;
}
else
{
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Now;
}
_investmentService.SaveMonthlyBenifitsAccrual(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveInvestmentEncashment")]
public ActionResult SaveInvestmentEncashment(InvestmentInfo data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
if (data.IsNew)
{
data.CreatedBy = currentUser.UserID;
data.CreatedDate = DateTime.Now;
}
else
{
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Now;
}
_investmentService.SaveInvestmentEncashment(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveInvestmentLiquidation")]
public ActionResult SaveInvestmentLiquidation(InvestmentInfo data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
if (data.IsNew)
{
data.CreatedBy = currentUser.UserID;
data.CreatedDate = DateTime.Now;
}
else
{
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Now;
}
_investmentService.SaveInvestmentLiquidation(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getInvestmentInfoByDateAndStatus")]
public ActionResult GetInvestmentInfoByDateAndStatus(dynamic data)
{
List<InvestmentInfo> items = new List<InvestmentInfo>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
int investmentStatusID = (int)item["investmentStatusID"].ToObject<int>();
try
{
string sSearch = "";
if (fromDate != null && toDate != null)
{
sSearch = SQLParser.MakeSQL("Where IssueDate between %d And %d ", fromDate, toDate);
}
if (investmentStatusID > 0)
{
sSearch = GlobalFunctions.TagSQL(sSearch, "CurrentStatus= " + investmentStatusID);
}
items = _investmentService.GetBySearch(sSearch, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("getInvestmentInfoByMatureDateAndStatus")]
public ActionResult getInvestmentInfoByMatureDateAndStatus(dynamic data)
{
List<InvestmentInfo> items = new List<InvestmentInfo>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
int investmentStatusID = (int)item["investmentStatusID"].ToObject<int>();
try
{
string sSearch = "";
if (fromDate != null && toDate != null)
{
sSearch = SQLParser.MakeSQL("Where MatureDate between %d And %d ", fromDate, toDate);
}
if (investmentStatusID > 0)
{
sSearch = GlobalFunctions.TagSQL(sSearch, "CurrentStatus= " + investmentStatusID);
}
items = _investmentService.GetByMatureDateAndStatus(sSearch, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("getLoanList")]
public ActionResult GetLoanList(dynamic data)
{
DataTable items = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
string memberID = (string)item["memberID"].ToObject<string>();
int loanCategoryID = (int)item["loanCategoryID"].ToObject<int>();
int loanStatusID = (int)item["loanStatusID"].ToObject<int>();
bool isIssueDate = (bool)item["isIssueDate"].ToObject<bool>();
DateTime issueFromDate = (DateTime)item["issueFromDate"].ToObject<DateTime>();
DateTime issueToDate = (DateTime)item["issueToDate"].ToObject<DateTime>();
try
{
items = _fmLoanService.GetLoanList(fundTypeID, memberID, loanCategoryID, loanStatusID, isIssueDate, issueFromDate, issueToDate);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("createLoanSchedule")]
public ActionResult CreateLoanSchedule(FMLoan data)
{
List<FMLoanSchedule> item = null;
try
{
item = _fmLoanScheduleService.CreateSchedule(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpPost]
[Route("generateLoanNo")]
public ActionResult GenerateLoanNo(FMLoan data)
{
string loanNo = string.Empty;
try
{
loanNo = _fmLoanService.GenerateLoanNo(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanNo);
}
[HttpPost]
[Route("saveLoan")]
public ActionResult SaveLoan(FMLoan data)
{
string loanNo = string.Empty;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
if (data.IsNew)
{
data.CreatedBy = currentUser.UserID;
data.CreatedDate = DateTime.Now;
}
else
{
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Now;
}
_fmLoanService.Save(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanNo);
}
[HttpPost]
[Route("deleteLoan")]
public ActionResult DeleteLoan(LoanIssue loan)
{
string loanNo = string.Empty;
try
{
_fmLoanService.Delete(loan.ID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanNo);
}
[HttpGet("getLoanByID/{id}")]
public ActionResult GetLoanByID(int id)
{
FMLoan items = new FMLoan();
try
{
items = _fmLoanService.Get(id, true, true, true);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getLoanSchedulesByID/{id}")]
public ActionResult GetLoanSchedulesByID(int id)
{
List<FMLoanSchedule> items = new List<FMLoanSchedule>();
try
{
items = _fmLoanScheduleService.GetByLoanID(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("GetLoanAttachmentByLoanID/{loanID}")]
public ActionResult GetLoanAttachmentByLoanID(int loanID)
{
FMLoanAttachment item;
try
{
item = _fmLoanAttachmentService.GetByLoanID(loanID);
return Ok(item);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
[HttpPost]
[Route("getFinalSettlement")]
public ActionResult GetFinalSettlement(dynamic data)
{
List<Member> oMembers = new List<Member>();
DataTable dataTable = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
string memberIDs = (string)item["memberIDs"].ToObject<string>();
try
{
string sSearch = "";
if (fundTypeID > 0)
{
sSearch += SQLParser.MakeSQL("WHERE M.FundTypeID = %n ", fundTypeID);
}
if (fromDate != DateTime.MinValue && toDate != DateTime.MinValue)
{
sSearch += SQLParser.MakeSQL("AND F.SETTLEMENTDATE BETWEEN %d AND %d ", fromDate, toDate);
}
if (memberIDs != string.Empty)
{
sSearch += SQLParser.MakeSQL("AND M.MemberID in (%q)", memberIDs);
}
dataTable = _finalSettlementService.GetBySearch(sSearch);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dataTable);
}
[HttpPost]
[Route("getMemberTransactionAmount")]
public ActionResult GetMemberTransactionAmount(dynamic data)
{
DataTable dataTable = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime date = (DateTime)item["date"].ToObject<DateTime>();
int memberID = (int)item["memberID"].ToObject<int>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
try
{
dataTable = _membersTransactionDetailsService.GetTranAmount(memberID, date, fundTypeID).Tables[0];
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dataTable);
}
[HttpPost]
[Route("getMemberVoluntaryTransactionAmount")]
public ActionResult GetMemberVoluntaryTransactionAmount(dynamic data)
{
DataTable dataTable = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime date = (DateTime)item["date"].ToObject<DateTime>();
int memberID = (int)item["memberID"].ToObject<int>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
try
{
dataTable = _membersTransactionDetailsService.GetVoluntaryTranAmount(memberID, date, fundTypeID).Tables[0];
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dataTable);
}
[HttpPost]
[Route("getMemberTransactionAmountForCalculate")]
public ActionResult GetMemberTransactionAmountForCalculate(dynamic data)
{
DataTable dataTable = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
FundType oFundType = (FundType)item["oFundType"].ToObject<FundType>();
int memberID = (int)item["memberID"].ToObject<int>();
try
{
dataTable = _membersTransactionDetailsService.GetTranAmountForCalculate(memberID, GlobalFunctions.FirstDateOfMonth(oFundType.LastProfitDistributionMonth.AddMonths(1)), GlobalFunctions.LastDateOfMonth(oFundType.CurrentMonth), oFundType.ID).Tables[0];
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dataTable);
}
[HttpPost]
[Route("getMemberTotalTransactionAmountWithVoluntary")]
public ActionResult GetMemberTotalTransactionAmountWithVoluntary(dynamic data)
{
DataTable dataTable = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
FundType oFundType = (FundType)item["oFundType"].ToObject<FundType>();
int memberID = (int)item["memberID"].ToObject<int>();
try
{
dataTable = _membersTransactionDetailsService.GetTranAmountWithVoluntary(memberID, GlobalFunctions.FirstDateOfMonth(oFundType.LastProfitDistributionMonth.AddMonths(1)), GlobalFunctions.LastDateOfMonth(oFundType.CurrentMonth), oFundType.ID).Tables[0];
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dataTable);
}
[HttpPost]
[Route("saveFinalSettlement")]
public ActionResult SaveFinalSettlement(dynamic data)
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
PFFinalSettlement finalSettlement = (PFFinalSettlement)item["finalSettlement"].ToObject<PFFinalSettlement>();
Member member = (Member)item["member"].ToObject<Member>();
List<MembersTransactionDetail> membersTransactionDetails = (List<MembersTransactionDetail>)item["membersTransactionDetails"].ToObject<List<MembersTransactionDetail>>();
List<FMLoan> loan = (List<FMLoan>)item["loan"].ToObject<List<FMLoan>>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
finalSettlement.CreatedBy = currentUser.UserID;
finalSettlement.CreatedDate = DateTime.Now;
try
{
_finalSettlementService.Save(finalSettlement, member, loan);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveVoluntaryFinalSettlement")]
public ActionResult SaveVoluntaryFinalSettlement(dynamic data)
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
PFFinalSettlement finalSettlement = (PFFinalSettlement)item["finalSettlement"].ToObject<PFFinalSettlement>();
Member member = (Member)item["member"].ToObject<Member>();
List<MembersTransactionDetail> membersTransactionDetails = (List<MembersTransactionDetail>)item["membersTransactionDetails"].ToObject<List<MembersTransactionDetail>>();
List<FMLoan> loan = (List<FMLoan>)item["loan"].ToObject<List<FMLoan>>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
finalSettlement.CreatedBy = currentUser.UserID;
finalSettlement.CreatedDate = DateTime.Now;
try
{
_finalSettlementService.SaveWithVoluntary(finalSettlement, member, loan);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getLoanObjects")]
public ActionResult getLoanObjects(dynamic data)
{
List<FMLoan> items = new List<FMLoan>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
string memberID = (string)item["memberID"].ToObject<string>();
int loanStatusID = (int)item["loanStatusID"].ToObject<int>();
try
{
items = _fmLoanService.GetLoanObjects(fundTypeID, memberID, loanStatusID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getLoanOutstandingAmount/{id}")]
public ActionResult getLoanOutstandingAmount(int id)
{
double x;
try
{
x = _finalSettlementService.OutstandingLoanAmount(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(x);
}
[HttpPost]
[Route("updateFundTypeCurrentDate")]
public ActionResult UpdateFundTypeCurrentDate(dynamic data)
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
FundType fundType = (FundType)item["fundType"].ToObject<FundType>();
try
{
_fundTypeService.Update(fundType);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(fundType);
}
[HttpPost]
[Route("getProfitedMembers")]
public ActionResult GetProfitedMembers(dynamic data)
{
List<Member> items = new List<Member>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime date = (DateTime)item["date"].ToObject<DateTime>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
FundType oftype = new FundTypeService().Get(fundTypeID);
DateTime profitMonthStart = date;
if (oftype.ProfitDistributionDuration == EnumProfitDistributionDuration.Monthly)
{
profitMonthStart = GlobalExtensions.FirstDateOfMonth(date);
}
else if (oftype.ProfitDistributionDuration == EnumProfitDistributionDuration.Half_Yearly)
{
profitMonthStart = GlobalExtensions.FirstDateOfMonth(date.AddMonths(-5));
}
else
profitMonthStart = GlobalExtensions.FirstDateOfMonth(date.AddMonths(-11));
try
{
items = _memberService.GetMembersJoinTransaction(profitMonthStart,
date, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getRDReports/{fundTypeID}")]
public ActionResult GetRDRepots(int fundTypeID)
{
List<RDReport> items = new List<RDReport>();
try
{
items = _rDReportService.GetByFundTypeID(fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("saveRDReport")]
public ActionResult SaveRDReport(dynamic data)
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)items["fundTypeID"].ToObject<int>();
RDReport obj = (RDReport)items["rdReport"].ToObject<RDReport>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
try
{
_rDReportService.Save(obj, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("deleteRDReportObject/{id}")]
public ActionResult DeleteRDReport(int id)
{
try
{
_rDReportService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getNewInvestment")]
public ActionResult getNewInvestment(dynamic data)
{
NewInvestment items = new NewInvestment();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime date = (DateTime)item["date"].ToObject<DateTime>();
try
{
items = _newInvestmentService.GetByTranMonth(date);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("getNewInvestmentFromConfig")]
public ActionResult getNewInvestmentFromConfig(dynamic data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
NewInvestment items = new NewInvestment();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime date = (DateTime)item["date"].ToObject<DateTime>();
try
{
items = _newInvestmentService.GetFromConfig(currentUser.UserID, date);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getByRDReportID/{reportID}")]
public ActionResult GetByRDReportID(int reportID)
{
List<RDReportRow> items = new List<RDReportRow>();
try
{
items = _rRDReportRowService.GetByReoprtID(reportID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
//[HttpGet("getRowSumCalcItemByRDReportRowID/{reportRowID}")]
//public ActionResult GetRowSumCalcItemByRDReportRowID(int reportRowID)
//{
// List<RowSumCalcItem> items = new List<RowSumCalcItem>();
// try
// {
// items = _rowSumCalcItemService.GetByRowID(reportRowID);
// }
// catch (Exception ex)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
// }
// return Ok(items);
//}
[HttpGet("getByRDReportIDAndFundTypeID/{reportID}/{fundTypeID}")]
public ActionResult GetByRDReportIDAndFundTypeID(int reportID, int fundTypeID)
{
List<RDReportRow> items = new List<RDReportRow>();
try
{
items = _rRDReportRowService.GetByReoprtIDAndFundTypeID(reportID, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("saveReportRow")]
public ActionResult SaveReportRow(dynamic data)
{
try
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
RDReportRow obj = (RDReportRow)items["reportRow"].ToObject<RDReportRow>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
_rRDReportRowService.Save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("deleteRDReportRowObject/{id}")]
public ActionResult DeleteRDReportRow(int id)
{
try
{
_rRDReportRowService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveNewInvestment")]
public ActionResult SaveNewInvestment(NewInvestment data)
{
//CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
//try
//{
// if (data.IsNew)
// {
// data.CreatedBy = currentUser.UserID;
// data.CreatedDate = DateTime.Now;
// }
// else
// {
// data.ModifiedBy = currentUser.UserID;
// data.ModifiedDate = DateTime.Now;
// }
// _newInvestmentService.Save(data);
// MailSender mailSender = new MailSender();
// EmailSettings emailSettings = new EmailSettings();
// var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
// IConfiguration Configuration = builder.Build();
// Configuration.GetSection("EmailSettings").Bind(emailSettings);
// List<Member> members = new List<Member>();
// members.Add(new MemberService().Get(Configuration.GetSection("Approver")["ApproverOneId"]));
// members.Add(new MemberService().Get(Configuration.GetSection("Approver")["ApproverOneId"]));
// foreach (Member member in members)
// {
// mailSender.AddTo(member.Email);
// mailSender.Subject = "PF Deposit Request";
// StringBuilder sb = new StringBuilder();
// sb.AppendLine("Dear " + member.Name + "," + "<br/>");
// sb.AppendLine("A PF Deposit has been requested and sent to you for approval.<br/>Please log on to the Self Service application to approve." + "<br/>");
// mailSender.Body = sb.ToString();
// mailSender.SendMail(emailSettings);
// }
//}
//catch (Exception ex)
//{
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
//}
return Ok();
}
[HttpPost]
[Route("getLoanApplication")]
public ActionResult GetLoanApplication(dynamic data)
{
List<LoanApplication> loanApplications = new List<LoanApplication>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)item["FromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["ToDate"].ToObject<DateTime>();
int fundTypeID = item["fundTypeID"].ToObject<int>();
try
{
loanApplications = _loanApplicationService.GetAllByDate(fromDate, toDate, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanApplications);
}
[HttpPost]
[Route("updateLoanApplicationByTrustee")]
public ActionResult UpdateLoanApplicationByTrustee(LoanApplication data)
{
try
{
_loanApplicationService.UpdateLoanApproveByTrustees(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("updateLoanDepositByHr")]
public ActionResult UpdateLoanDepositByHr(dynamic data)
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
DateTime bankTransactionDate = (DateTime)item["bankTransactionDate"].ToObject<DateTime>();
LoanApplication oLoanApplication = (LoanApplication)item["loanApplication"].ToObject<LoanApplication>();
FMLoan loan = new FMLoan();
try
{
loan = _fmLoanService.GetLoanForLoanApplicationDeposit(oLoanApplication.MemberID, oLoanApplication.NoOfInstallment, (double)oLoanApplication.LoanAmount, fromDate, toDate);
//Send Mail
if (loan != null)
{
if ((bankTransactionDate.Day >= 11 && bankTransactionDate.Day <= 15) || (bankTransactionDate.Day >= 25 && bankTransactionDate.Day <= 30))
{
oLoanApplication.DepositDate = bankTransactionDate;
_loanApplicationService.UpdateLoanDepositByHr(oLoanApplication);
Member oMember = _memberService.Get(oLoanApplication.MemberID);
MailSender mailSender = new MailSender();
EmailSettings emailSettings = new EmailSettings();
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
IConfiguration Configuration = builder.Build();
Configuration.GetSection("EmailSettings").Bind(emailSettings);
mailSender.AddTo(oMember.Email);
mailSender.Subject = "Summary of your loan to Bank Account";
StringBuilder sb = new StringBuilder();
sb.AppendLine("Dear " + oMember.Name + "," + "<br/>");
sb.AppendLine("<pre>");
sb.AppendLine("The loan amount has been disbursed to your bank account today. The onward deduction will be as follows:<br/>" +
$"<br/>ID : {oMember.EmpCode}" +
$"<br/>Name : {oMember.Name}" +
$"<br/>Loan disbursed : {oLoanApplication.LoanAmount}" +
$"<br/>Total Interest : {loan.ToBeToatalInterest}" +
$"<br/>Total Repayment : {loan.ToBeTotal}" +
$"<br/>Monthly Installment : {oLoanApplication.InstallmentAmount}" +
$"<br/>Total Installment : {loan.InstallmentNo}" +
$"<br/>Deduction Month starts from : {loan.StartPayBackMonth.ToString("dd MMM yyyy")}" +
$"<br/>Deduction Month End : {loan.LastSchedulePayDate.ToString("dd MMM yyyy")}" +
"<br/><br/>");
mailSender.Body = sb.ToString();
mailSender.SendMail(emailSettings);
}
else
{
throw new Exception("No transaction found between 11-15 or 25-30 of the month.");
}
}
else
{
throw new Exception("No transaction found. Please Issue the Loan first");
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getLoanBySettleStatus")]
public ActionResult GetLoanBySettleStatus(dynamic data)
{
List<FMLoan> items = new List<FMLoan>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
int settleStatusID = (int)item["settleStatusID"].ToObject<int>();
try
{
items = _fmLoanService.GetBySettlementStatus(fromDate, toDate, settleStatusID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("updateLoanSettleStatus")]
public ActionResult UpdateLoanSettleStatus(FMLoan data)
{
try
{
_fmLoanService.UpdateEarlySettlement(data);
//Send Mail
Member oMember = new MemberService().Get(data.MemberID);
MailSender mailSender = new MailSender();
EmailSettings emailSettings = new EmailSettings();
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
IConfiguration Configuration = builder.Build();
Configuration.GetSection("EmailSettings").Bind(emailSettings);
//mailSender.AddTo(oMember.Email);
if (data.SettleStatus == EnumLoanSettleStatus.Checked)
{
mailSender.Subject = "Loan Settlement Request Checked";
StringBuilder sb = new StringBuilder();
sb.AppendLine("Dear " + oMember.Name + "," + "<br/>");
sb.AppendLine("Your Loan Settlement Request has been checked by Admin HR. Please log on to the Self Service application to Deposit." + "<br/>" + " Please go to " + ConfigurationSettings.AppSettings["WebAddress"] + " for details." + "<br/><br/>");
mailSender.Body = sb.ToString();
//mailSender.SendMail(emailSettings);
}
else if (data.SettleStatus == EnumLoanSettleStatus.Settled)
{
mailSender.Subject = "Loan Settlement Request Checked";
StringBuilder sb = new StringBuilder();
sb.AppendLine("Dear " + oMember.Name + "," + "<br/>");
sb.AppendLine("Your Loan Settlement Request has been Settled by Admin HR on date " + DateTime.Today.ToString("dd MMM yyyy") + ". Upon settling the current loan, eligibility to apply for another loan will be granted after a one - month waiting period." + " <br/>" + "Please go to " + ConfigurationSettings.AppSettings["WebAddress"] + " for details." + "<br/><br/>");
mailSender.Body = sb.ToString();
//mailSender.SendMail(emailSettings);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("DoLoanSettleStatus")]
public ActionResult DoLoanSettleStatus(FMLoan data)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Today;
_fmLoanService.DoLoanEarlySettlement(data);
//Send Mail
//Member oMember = new MemberService().Get(data.MemberID);
//MailSender mailSender = new MailSender();
//EmailSettings emailSettings = new EmailSettings();
//var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
//IConfiguration Configuration = builder.Build();
//Configuration.GetSection("EmailSettings").Bind(emailSettings);
//mailSender.AddTo(oMember.Email);
//if (data.SettleStatus == EnumLoanSettleStatus.Checked)
//{
// mailSender.Subject = "Loan Settlement Request Checked";
// StringBuilder sb = new StringBuilder();
// sb.AppendLine("Dear " + oMember.Name + "," + "<br/>");
// sb.AppendLine("Your Loan Settlement Request has been checked by Admin HR. Please log on to the Self Service application to Deposit." + "<br/>" + " Please go to " + ConfigurationSettings.AppSettings["WebAddress"] + " for details." + "<br/><br/>");
// mailSender.Body = sb.ToString();
// //mailSender.SendMail(emailSettings);
//}
//else if (data.SettleStatus == EnumLoanSettleStatus.Settled)
//{
// mailSender.Subject = "Loan Settlement Request Checked";
// StringBuilder sb = new StringBuilder();
// sb.AppendLine("Dear " + oMember.Name + "," + "<br/>");
// sb.AppendLine("Your Loan Settlement Request has been Settled by Admin HR on date " + DateTime.Today.ToString("dd MMM yyyy") + ". Upon settling the current loan, eligibility to apply for another loan will be granted after a one - month waiting period." + " <br/>" + "Please go to " + ConfigurationSettings.AppSettings["WebAddress"] + " for details." + "<br/><br/>");
// mailSender.Body = sb.ToString();
// //mailSender.SendMail(emailSettings);
//}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getMembersEPFCPF")]
public ActionResult GetMembersEPFCPF(dynamic data)
{
DataTable dt = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime operationDate = (DateTime)item["operationDate"].ToObject<DateTime>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
int memberID = (int)item["memberID"].ToObject<int>();
try
{
dt = _membersTransactionDetailsService.GetMembersEPFCPF(memberID, operationDate, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dt);
}
[HttpPost]
[Route("saveWithdrawal")]
public ActionResult SaveWithdrawal(List<MembersTransactionDetail> data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
foreach (MembersTransactionDetail item in data)
{
if (item.IsNew)
{
item.CreatedBy = currentUser.UserID;
item.CreatedDate = DateTime.Now;
}
else
{
item.ModifiedBy = currentUser.UserID;
item.ModifiedDate = DateTime.Now;
}
}
_membersTransactionDetailsService.SaveWithdrawal(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getESBSList/{id}")]
public ActionResult GetESBSList(int id)
{
List<BO.Fund.ESBSlab> items = new List<BO.Fund.ESBSlab>();
try
{
items = _eSBSlabService.GetByFundTypeID(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("saveESBSLabObject")]
public ActionResult SaveESBSLAbObject(dynamic data)
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
HRM.BO.Fund.ESBSlab obj = (HRM.BO.Fund.ESBSlab)items["esbsLab"].ToObject<HRM.BO.Fund.ESBSlab>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
try
{
_eSBSlabService.save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("deleteESBSLab/{id}")]
public ActionResult DeleteESBSLab(int id)
{
try
{
_eSBSlabService.delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("getAllRequestByDateRange")]
public ActionResult GetAllRequestByDateRange(dynamic data)
{
List<PFWithdrawalRequest> oPFWithdrawalRequest = new List<PFWithdrawalRequest>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
int statusID = (int)item["statusID"].ToObject<int>();
try
{
oPFWithdrawalRequest = _pfWithdrawalRequestService.GetAllRequestByDateRange(fromDate, toDate, statusID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oPFWithdrawalRequest);
}
[HttpPost]
[Route("getPfWithdrawalDetails")]
public ActionResult GetPfWithdrawalDetails(dynamic data)
{
DataTable pfWithdrawalDetailsTable = new DataTable();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int memberID = (int)item["memberID"].ToObject<int>();
try
{
// Define columns for the DataTable
pfWithdrawalDetailsTable.Columns.Add("Description", typeof(string));
pfWithdrawalDetailsTable.Columns.Add("epfContribution", typeof(string));
pfWithdrawalDetailsTable.Columns.Add("cpfContribution", typeof(string));
pfWithdrawalDetailsTable.Columns.Add("total", typeof(string));
pfWithdrawalDetailsTable.Columns.Add("IsRequestPending", typeof(bool));
// Get member details
Member omember = new MemberService().Get(memberID);
DateTime memDate = (DateTime)omember.MembershipDate;
TimeSpan timeDifference = DateTime.Now - Convert.ToDateTime(omember.DOJ);
int membershipDuration = (int)timeDifference.TotalDays;
// Static descriptions
List<string> staticDescriptions = new List<string>
{
"A. Audited Closing Balance",
"B. Contribution During the Year",
"C. PF Loan Outstanding Balance",
"D. Total Amount",
"E. Transfer to Lapses & forfeiture A/C",
"F. Net Amount Payable"
};
// Initialize arrays for contributions and totals
double[] epfContributionArr = new double[6];
double[] cpfContributionArr = new double[6];
double[] total = new double[6];
// Get pending request count
int pendingRequestCount = _pfWithdrawalRequestService.PFWithdrawalRequestCount(memberID);
// Populate the contribution arrays
epfContributionArr[0] = _membersTransactionDetailsService.GetDashboardMemberAuditedOwnBalance(memberID);
cpfContributionArr[0] = _membersTransactionDetailsService.GetDashboardMemberAuditedOwnBalance(memberID);
total[0] = epfContributionArr[0] + cpfContributionArr[0];
epfContributionArr[1] = _membersTransactionDetailsService.GetDashboardMemberUnAuditedOwnBalance(memberID);
cpfContributionArr[1] = _membersTransactionDetailsService.GetDashboardMemberUnAuditedCompanyBalance(memberID);
total[1] = epfContributionArr[1] + cpfContributionArr[1];
total[2] = _fmLoanService.GetLoanOustandingAmount(memberID);
// Populate the DataTable rows
for (int i = 0; i < 6; i++)
{
DataRow row = pfWithdrawalDetailsTable.NewRow();
row["Description"] = staticDescriptions[i];
if (i <= 1)
{
row["epfContribution"] = epfContributionArr[i].ToString("N2");
row["cpfContribution"] = cpfContributionArr[i].ToString("N2");
row["total"] = total[i].ToString("N2");
row["IsRequestPending"] = pendingRequestCount > 0;
}
else
{
row["epfContribution"] = string.Empty;
row["cpfContribution"] = string.Empty;
switch (i)
{
case 2:
row["total"] = total[2].ToString("N2");
break;
case 3:
total[3] = total[0] + total[1] - total[2];
row["total"] = total[3].ToString("N2");
break;
case 4:
total[4] = (membershipDuration < 365 * 2) ? cpfContributionArr[0] + cpfContributionArr[1] : 0;
row["total"] = total[4].ToString("N2");
break;
default:
row["total"] = (total[3] - total[4]).ToString("N2");
break;
}
}
pfWithdrawalDetailsTable.Rows.Add(row);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(pfWithdrawalDetailsTable);
}
[HttpPost]
[Route("updatePFWithdrawalRequestByTrustee")]
public ActionResult UpdatePFWithdrawalRequestByTrustee(PFWithdrawalRequest data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
if (data.IsNew)
{
data.CreatedBy = currentUser.UserID;
data.CreatedDate = DateTime.Now;
}
else
{
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Now;
}
_pfWithdrawalRequestService.UpdatePFWRApproveByTrustees(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("updatePFWithdrawalRequest")]
public ActionResult UpdatePFWithdrawalRequest(PFWithdrawalRequest data)
{
//CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
//try
//{
// if (data.IsNew)
// {
// data.CreatedBy = currentUser.UserID;
// data.CreatedDate = DateTime.Now;
// }
// else
// {
// data.ModifiedBy = currentUser.UserID;
// data.ModifiedDate = DateTime.Now;
// }
// _pfWithdrawalRequestService.Update(data);
// MailSender mailSender = new MailSender();
// EmailSettings emailSettings = new EmailSettings();
// var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
// IConfiguration Configuration = builder.Build();
// Configuration.GetSection("EmailSettings").Bind(emailSettings);
// if (data.Status == EnumPFWithdrawalStatus.Settled)
// {
// Member oMember = new MemberService().Get(data.RequestMemberID);
// mailSender.AddTo(oMember.Email);
// mailSender.Subject = "PF Membership Withdrawal";
// StringBuilder sb = new StringBuilder();
// sb.AppendLine("Dear " + oMember.Name + "," + "<br/>");
// sb.AppendLine("Your request for PF(Provident Fund) Membership Withdrawal has been approved and transaction has been completed." + " < br /> " + " Please go to " + ConfigurationSettings.AppSettings["WebAddress"] + " for details." + " < br />< br /> ");
// mailSender.Body = sb.ToString();
// // mailSender.SendMail(emailSettings);
// }
// else if (data.Status == EnumPFWithdrawalStatus.Checked)
// {
// List<Member> TrusteesList = new List<Member>();
// Member Trustee = new MemberService().Get(ConfigurationSettings.AppSettings["Trustee"]);
// Member SecondTrustee = new MemberService().Get(ConfigurationSettings.AppSettings["SecondTrustee"]);
// TrusteesList.Add(Trustee);
// TrusteesList.Add(SecondTrustee);
// foreach (Member item in TrusteesList)
// {
// Task.Run(() =>
// {
// mailSender.AddTo(item.Email);
// mailSender.Subject = "PF Membership Withdrawal";
// StringBuilder sb = new StringBuilder();
// sb.AppendLine("Dear " + item.Name + "," + "<br/>");
// sb.AppendLine("Your PF Membership Withdrawal request has been Rejected by Admin HR." + "<br/>" + " Please go to " + ConfigurationSettings.AppSettings["WebAddress"] + " for details." + "<br/><br/>");
// mailSender.Body = sb.ToString();
// //mailSender.SendMail(emailSettings);
// });
// }
// }
// else if (data.Status == EnumPFWithdrawalStatus.Rejected)
// {
// Member oMember = new MemberService().Get(data.RequestMemberID);
// mailSender.AddTo(oMember.Email);
// mailSender.Subject = "PF Membership Withdrawal";
// StringBuilder sb = new StringBuilder();
// sb.AppendLine("Dear " + oMember.Name + "," + "<br/>");
// sb.AppendLine("Your PF Membership Withdrawal request has been Rejected by Admin HR." + "<br/>" + " Please go to " + ConfigurationSettings.AppSettings["WebAddress"] + " for details." + "<br/><br/>");
// mailSender.Body = sb.ToString();
// //mailSender.SendMail(emailSettings);
// }
//}
//catch (Exception ex)
//{
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
//}
return Ok();
}
[HttpGet("getLoanByMemberID/{id}")]
public ActionResult GetLoanByMemberID(int id)
{
List<FMLoan> items = new List<FMLoan>();
try
{
items = _fmLoanService.GetLoansByMemberID(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[Route("UpdateLoanScheduleAmount")]
public ActionResult UpdateLoanScheduleAmount(List<FMLoanSchedule> items)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
items.ForEach(x =>
{
x.ModifiedBy = currentUser.UserID;
x.ModifiedDate = DateTime.Today;
});
try
{
_fmLoanScheduleService.UpdateSchedules(items);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
[HttpPost]
[Route("saveLoanScheduleList")]
public ActionResult SaveLoanSchedule(List<FMLoanSchedule> items)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
items.ForEach(x =>
{
x.ModifiedBy = currentUser.UserID;
x.ModifiedDate = DateTime.Today;
});
try
{
foreach (FMLoanSchedule item in items)
{
_fmLoanScheduleService.Save(item);
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("getGratuityServiceLength")]
public ActionResult GetGratuityServiceLength(dynamic data)
{
GFSettlement gFSettlement = new GFSettlement();
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
Member member = (Member)items["member"].ToObject<Member>();
DateTime endDate = (DateTime)items["settlementDate"].ToObject<DateTime>();
DateTime startDate = member.DOJ;
gFSettlement.ServiceYear = endDate.Year - startDate.Year;
gFSettlement.ServiceMonth = endDate.Month - startDate.Month;
gFSettlement.ServiceDay = endDate.Day - startDate.Day;
if (gFSettlement.ServiceDay < 0)
{
gFSettlement.ServiceMonth--;
// Get the number of days in the previous month
int previousMonthDays = DateTime.DaysInMonth(endDate.Year, endDate.Month == 1 ? 12 : endDate.Month - 1);
gFSettlement.ServiceDay += previousMonthDays;
}
if (gFSettlement.ServiceMonth < 0)
{
gFSettlement.ServiceYear--;
gFSettlement.ServiceMonth += 12;
}
return Ok(gFSettlement);
}
[HttpPost]
[Route("getGratuityAmount")]
public ActionResult GetGratuityAmount(dynamic data)
{
GFSettlement gFSettlement = new GFSettlement();
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
Member member = (Member)items["member"].ToObject<Member>();
DateTime endDate = (DateTime)items["settlementDate"].ToObject<DateTime>();
DateTime startDate = member.DOJ;
int years = endDate.Year - startDate.Year;
int months = endDate.Month - startDate.Month;
int days = endDate.Day - startDate.Day;
if (days < 0)
{
months--;
// Get the number of days in the previous month
int daysInPreviousMonth = DateTime.DaysInMonth(
endDate.Year,
endDate.Month == 1 ? 12 : endDate.Month - 1
);
days += daysInPreviousMonth;
}
if (months < 0)
{
years--;
months += 12;
}
if (months > 5 || (months == 5 && days > 29))
{
years++;
}
else if (months == 5 && days == 29)
{
// The code doesn't specify any action for this case
}
else if (months == 5 && days == 29)
{
years--;
}
double gfEligibleAmount = 0;
double lastBasic = Math.Round(member.CurrentBasic, 2, MidpointRounding.AwayFromZero);
if (years >= 5 && years < 10)
{
gfEligibleAmount = lastBasic * 1 * years;
}
else if (years < 5)
{
gfEligibleAmount = 0;
}
else if (years >= 10)
{
gfEligibleAmount = lastBasic * 1.5 * years;
}
else
{
gfEligibleAmount = 0;
}
gfEligibleAmount = Math.Round(gfEligibleAmount, 2, MidpointRounding.AwayFromZero);
return Ok(gfEligibleAmount);
}
[HttpPost]
[Route("saveGFSettlement")]
public ActionResult SaveGFSettlement(dynamic data)
{
try
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
GFSettlement finalSettlement = new GFSettlement();
finalSettlement = (GFSettlement)item["gfSettlement"].ToObject<GFSettlement>();
Member member = (Member)item["member"].ToObject<Member>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (finalSettlement.IsNew)
{
finalSettlement.CreatedBy = currentUser.UserID;
finalSettlement.CreatedDate = DateTime.Now;
}
else
{
finalSettlement.ModifiedBy = currentUser.UserID;
finalSettlement.ModifiedDate = DateTime.Today;
}
_gFSettlementService.Save(finalSettlement, member);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getGFSettlement")]
public ActionResult GetGFSettlement()
{
List<GFSettlement> items = new List<GFSettlement>();
try
{
items = _gFSettlementService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost("getGFSettlementByDate")]
public ActionResult GetGFSettlementByDate(dynamic data)
{
List<GFSettlement> items = new List<GFSettlement>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
try
{
items = _gFSettlementService.Get(fromDate, toDate, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("saveMember")]
public ActionResult SaveMember(Member obj)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (obj.IsNew)
{
obj.CreatedBy = currentUser.UserID;
obj.CreatedDate = DateTime.Now;
}
else
{
obj.ModifiedBy = currentUser.UserID;
obj.ModifiedDate = DateTime.Today;
}
try
{
_memberService.Save(obj);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getFundDistributionByFundType/{id}")]
public ActionResult GetFundDistributionByFundType(int id)
{
List<WPPFFundDistribution> items = new List<WPPFFundDistribution>();
try
{
items = _wppfFundDistributionService.GetAllFundDistributions(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("deleteFundDistributionByID/{id}")]
public ActionResult DeleteFundDistributionByID(int id)
{
try
{
_wppfFundDistributionService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveFundDistribution")]
public ActionResult SaveFundDistribution(dynamic data)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
WPPFFundDistribution wPPFFundDistribution = (WPPFFundDistribution)item["WPPFFundDistributions"].ToObject<WPPFFundDistribution>();
if (wPPFFundDistribution.IsNew)
{
wPPFFundDistribution.CreatedDate = DateTime.Now;
wPPFFundDistribution.CreatedBy = currentUser.UserID;
}
else
{
wPPFFundDistribution.ModifiedDate = DateTime.Now;
wPPFFundDistribution.ModifiedBy = currentUser.UserID;
}
_wppfFundDistributionService.Save(wPPFFundDistribution);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("SaveWPPFSettlement")]
public ActionResult SaveWPPFSettlement(WPPFSettlement wPPFSettlement)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
if (wPPFSettlement.IsNew)
{
wPPFSettlement.CreatedDate = DateTime.Now;
wPPFSettlement.CreatedBy = currentUser.UserID;
}
else
{
wPPFSettlement.ModifiedDate = DateTime.Now;
wPPFSettlement.ModifiedBy = currentUser.UserID;
}
_wPPFSettlementService.Save(wPPFSettlement);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost("getWPPFFinalSettlement")]
public ActionResult GetWPPFFinalSettlement(dynamic data)
{
try
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
List<WPPFSettlement> items = new List<WPPFSettlement>();
items = _wPPFSettlementService.Get(fromDate, toDate, fundTypeID);
return Ok(items);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
[HttpPost]
[Route("distributeParticipantFund")]
public ActionResult DistributeParticipantFund(dynamic data)
{
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime voucherDate = (DateTime)item["voucherDate"].ToObject<DateTime>();
double distributeAmount = (double)item["distributionAmount"].ToObject<double>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
int fundGL = (int)item["fundGLID"].ToObject<int>();
int memberGL = (int)item["memberGLID"].ToObject<int>();
double amountToDistribute = (double)item["amountToDistribute"].ToObject<double>();
JArray selectedMembersArray = (JArray)item["selectedMembers"];
List<Member> members = selectedMembersArray.ToObject<List<Member>>();
_wppfFundDistributionService.DistributeParticipantFund(fundGL, memberGL, members, distributeAmount, amountToDistribute, voucherDate, fundTypeID, currentUser);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost("calculatePLOnDate")]
public ActionResult CalculatePLOnDate(dynamic data)
{
double pl = 0;
try
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int fundtypeid = (int)items["fundtypeid"].ToObject<int>();
pl = new GLTranService().CalcualteProfitLoss(currentUser.UserID, fundtypeid);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
return Ok(pl);
}
[HttpPost]
[Route("gfVoucherReport")]
public ActionResult GFVoucherReport(dynamic data)
{
byte[] bytes = null;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
string reportType = (string)items["reportType"].ToObject<string>();
string cacheKey = "_glTran";
try
{
if (_cache.TryGetValue(cacheKey, out GLTran _glTran))
{
bytes = new FundReports().makePLVoucherReport(_glTran, payrollTypeId, reportType);
}
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
return Ok(bytes);
}
[HttpPost]
[Route("getJournalVoucher")]
public ActionResult GetJournalVoucher(dynamic data)
{
List<GLTran> items = new List<GLTran>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)item["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)item["toDate"].ToObject<DateTime>();
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
int glID = (int)item["glID"].ToObject<int>();
try
{
items = _glTranService.GetGlTransForSearch(fromDate, toDate, glID, fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost]
[Route("journalVoucherReport")]
public ActionResult JournalVoucherReport(dynamic data)
{
byte[] bytes = null;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
string reportType = (string)items["reportType"].ToObject<string>();
int fundTypeID = (int)items["fundTypeID"].ToObject<int>();
GLTran gLTran = (GLTran)items["glTran"].ToObject<GLTran>();
try
{
bytes = new FundReports().makeJournalVoucherReport(gLTran, fundTypeID, reportType);
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
return Ok(bytes);
}
[HttpPost]
[Route("saveGLTran")]
public ActionResult SaveGLTran(GLTran data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int voucherNo = 0;
if (data.IsNew)
{
data.CreatedBy = currentUser.UserID;
data.CreatedDate = DateTime.Now;
}
else
{
data.ModifiedBy = currentUser.UserID;
data.ModifiedDate = DateTime.Today;
}
try
{
voucherNo = _glTranService.Save(data);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(voucherNo);
}
[HttpPost]
[Route("compareFSUploadData")]
2026-11-08 10:49:54 +06:00
//[AllowAnonymous]
2026-11-03 13:06:00 +06:00
public ActionResult CompareFSUploadData()
{
// var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
var fdata = Request.Form.Files["excelfile"];
int fundtypeid = Convert.ToInt32(Request.Form["fundtypeid"]);
DataTable dt = new DataTable();
try
{
using (var ms = new MemoryStream())
{
fdata.CopyTo(ms);
dt = _finalSettlementService.ExtractFromExcel(ms);
}
dt = _finalSettlementService.GetComparedFinalSettlementDataForUpload(dt, fundtypeid);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dt);
}
[HttpPost]
[Route("uploadFinalSettlementData")]
public ActionResult UploadFinalSettlementData(dynamic data)
{
List<UploadErrorOrSuccess> errorOrSuccessList;
try
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DataTable datas = (DataTable)items.ToObject<DataTable>();
errorOrSuccessList = _finalSettlementService.UploadFinalSettlementData(datas);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(errorOrSuccessList);
}
[HttpPost("saveProfitLossDistribution")]
public ActionResult SaveForProfitLossDistribution(dynamic data)
{
try
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundtypeid = (int)items["fundtypeid"].ToObject<int>();
int yearendgltranID = (int)items["pltranid"].ToObject<int>();
double distributableAmount = (double)items["distributableAmount"].ToObject<double>();
double distributePercentOnBal = (double)items["distributeonBalPercent"].ToObject<double>();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
_glTranService.DistributeProfit(currentUser.UserID, fundtypeid, distributableAmount, distributePercentOnBal, yearendgltranID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("updateMemberContributionDataFromPayroll")]
public ActionResult UpdateMemberContributionDataFromPayroll(dynamic data)
{
//Variable
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)items["fundTypeID"].ToObject<int>();
DataTable _uplodedData = (DataTable)items["dataTable"].ToObject<DataTable>();
DateTime month = (DateTime)items["month"].ToObject<DateTime>();
int nRow = 0;
double TotalAmount = 0;
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int _userID = currentUser.UserID;
//Objects
List<Member> oMembers = new List<Member>();
List<Member> memberList = new List<Member>();
List<MembersTransactionDetail> membertrans = new List<MembersTransactionDetail>();
GLTran voucher = new GLTran();
List<GLTranDetail> voucherDetails = new List<GLTranDetail>();
List<GL> gls = new GLService().GetbyFundType(fundTypeID);
List<ActivityVoucherSetup> oActivityVoucherSetups = new ActivityVoucherSetupService().GetByProcessType(fundTypeID, EnumFundProcessType.Monthly_Contribution); // fundProcessType
List<UploadErrorOrSuccess> _errorOrSuccessList = new List<UploadErrorOrSuccess>();
List<Designation> odesignations = new DesignationService().GetAll();
DateTime voucherDate = DateTime.Today;
try
{
oMembers = new MemberService().GetByFundType(fundTypeID);
foreach (DataRow dr in _uplodedData.Rows)
{
Member tempMember = new Member();
nRow = nRow + 1;
double tempAmount = 0;
if (Convert.ToString(dr["employeeno"]) != string.Empty)
{
Member findMember = oMembers.Find(x => x.EmpCode == Convert.ToString(dr["employeeno"]));
if (findMember != null)
tempMember = findMember;
else
{
tempMember.EmpCode = Convert.ToString(dr["employeeno"]);
tempMember.FundTypeID = fundTypeID;
tempMember.MemberStatus = EnumEmpStatus.Live;
}
}
else _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee No.", nRow, "(" + dr["employeeno"].ToString() + ")" + "This cannot be empty"));
if (Convert.ToString(dr["name"]) != string.Empty)
{
tempMember.Name = Convert.ToString(dr["name"]);
}
else _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee Name.", nRow, "(" + dr["name"].ToString() + ")" + "This cannot be empty"));
if (Convert.ToString(dr["designationid"]) != string.Empty)
{
tempMember.Designation = odesignations.Find(x => x.ID == Convert.ToInt32(dr["designationid"]))?.Name;
}
if (Convert.ToDateTime(dr["joiningdate"]).ToString() != string.Empty)
{
tempMember.DOJ = Convert.ToDateTime(dr["joiningdate"]);
}
else _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Joining Date.", nRow, "(" + Convert.ToDateTime(dr["joiningdate"]).ToString() + ")" + "This cannot be empty"));
if (Convert.ToDateTime(dr["pfmembershipdt"]).ToString() != string.Empty)
{
tempMember.MembershipDate = Convert.ToDateTime(dr["pfmembershipdt"]);
}
else _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("PF MembershipDate.", nRow, "This row cannot be empty"));
if (Convert.ToDouble(dr["basicsalary"]).ToString() != string.Empty)
{
tempMember.CurrentBasic = Convert.ToDouble(dr["basicsalary"]);
}
else _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Basic Salary.", nRow, "This row cannot be empty"));
if (Convert.ToDateTime(dr["birthdate"]).ToString() != string.Empty)
{
tempMember.DOB = Convert.ToDateTime(dr["birthdate"]);
}
else _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Birthdate.", nRow, "This row cannot be empty"));
//Fill User Record Information
UserRecord oUserRecord = new UserRecordService().GetByField1(tempMember.EmpCode, GlobalFunctions.Fund_UserObject_Member, fundTypeID);
if (oUserRecord != null)
{
tempMember.userRecord = new UserRecord();
tempMember.userRecord = oUserRecord;
tempMember.userRecord.Field2 = tempMember.Name; // Name Will Update If Name Spelling Changes
}
else
{
tempMember.userRecord = new UserRecord(GlobalFunctions.Fund_UserObject_Member, fundTypeID,
tempMember.EmpCode, tempMember.Name, "");
}
DateTime effectDate = GlobalFunctions.LastDateOfMonth(month);
voucherDate = effectDate;
voucher.FundTypeID = fundTypeID;
voucher.ChequeDate = voucherDate;
voucher.VoucherDate = voucherDate;
voucher.Description = "EPF & CPF contribution for the month " + voucherDate.ToString("MMM yyyy");
voucher.GLTranType = EnumGLTranType.MonthlyContribution;
// EPF
tempAmount = Convert.ToDouble(dr["epf"]);
MembersTransactionDetail efp = new MembersTransactionDetail(0,
fundTypeID, EnumMemberTranType.EPF, tempAmount, effectDate, EnumFundCategory.EPF);
efp.EmpCode = tempMember.EmpCode;
membertrans.Add(efp);
ActivityVoucherSetup epfgl = oActivityVoucherSetups.FirstOrDefault(x => x.FundProcessType == EnumFundProcessType.Monthly_Contribution
&& x.VouhcerSetupItemType == EnumVouhcerSetupItemType.EPF); // EPF
if (epfgl == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("GL.", nRow, "EPF GL not found in the system"));
continue;
}
GL vgl = gls.FirstOrDefault(x => x.ID == epfgl.GLID);
if (vgl == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("GL.", nRow, "EPF GL not found"));
continue;
}
GLTranDetail vefp = voucherDetails.FirstOrDefault(x => x.GLID == vgl.ID);
if (vefp == null)
{
vefp = new GLTranDetail(vgl.ID, (EnumTranSide)epfgl.GLSide, tempAmount, "");
voucherDetails.Add(vefp);
vefp.GLTranUserRecords = new List<GLTranUserRecord>();
}
else
{
voucherDetails.Find(x => x.GLID == vgl.ID).Amount += tempAmount;
}
GLTranUserRecord vur = new GLTranUserRecord(vgl.ID, 0, 0, GlobalFunctions.Fund_UserObject_Member, 0, tempAmount);
vur.UserRecord1 = tempMember.userRecord;
vefp.GLTranUserRecords.Add(vur);
voucher.CreditAmount += (double)tempAmount;
TotalAmount += tempAmount;
//CPF
tempAmount = Convert.ToDouble(dr["cpf"]);
MembersTransactionDetail cpf = new MembersTransactionDetail(0,
fundTypeID, EnumMemberTranType.CPF, tempAmount, effectDate, EnumFundCategory.CPF);
cpf.EmpCode = tempMember.EmpCode;
membertrans.Add(cpf);
ActivityVoucherSetup cpfgl = oActivityVoucherSetups.FirstOrDefault(x => x.FundProcessType == EnumFundProcessType.Monthly_Contribution
&& x.VouhcerSetupItemType == EnumVouhcerSetupItemType.CPF);
if (cpfgl == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("GL.", nRow, "CPF GL not found in the system"));
continue;
}
vgl = gls.FirstOrDefault(x => x.ID == cpfgl.GLID);
if (vgl == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("GL.", nRow, "CPF GL not found"));
continue;
}
GLTranDetail vcpf = voucherDetails.FirstOrDefault(x => x.GLID == vgl.ID);
if (vcpf == null)
{
vcpf = new GLTranDetail(vgl.ID, (EnumTranSide)cpfgl.GLSide, tempAmount, "");
voucherDetails.Add(vcpf);
vcpf.GLTranUserRecords = new List<GLTranUserRecord>();
}
else
{
voucherDetails.Find(x => x.GLID == vgl.ID).Amount += tempAmount;
}
GLTranUserRecord vur2 = new GLTranUserRecord(vgl.ID, 0, 0, GlobalFunctions.Fund_UserObject_Member, 0, tempAmount);
vur2.UserRecord1 = tempMember.userRecord;
vcpf.GLTranUserRecords.Add(vur2);
voucher.CreditAmount += (double)tempAmount;
TotalAmount += tempAmount;
//Bank GL
ActivityVoucherSetup bankVS = oActivityVoucherSetups.FirstOrDefault(x => x.FundProcessType == EnumFundProcessType.Monthly_Contribution
&& (x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Bank
|| x.VouhcerSetupItemType == EnumVouhcerSetupItemType.Contra));
if (bankVS == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("GL.", nRow, "Bank GL not found in system"));
continue;
}
vgl = gls.FirstOrDefault(x => x.ID == bankVS.GLID);
if (vgl == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("GL.", nRow, "Bank GL not found"));
continue;
}
GLTranDetail bank = voucherDetails.FirstOrDefault(x => x.GLID == vgl.ID);
if (bank == null)
{
bank = new GLTranDetail(vgl.ID, (EnumTranSide)bankVS.GLSide, TotalAmount, "");
voucherDetails.Add(bank);
}
bank.Amount = TotalAmount;
voucher.DebitAmount = (double)TotalAmount;
memberList.Add(tempMember);
voucher.GlTranDetails = voucherDetails;
}
if (_errorOrSuccessList.Count == 0)
{
voucher.VoucherDate = voucherDate;
foreach (var item in memberList)
{
if (item.IsNew == true)
{
item.CreatedBy = _userID;
item.CreatedDate = DateTime.Now;
}
else
{
item.ModifiedBy = _userID;
item.ModifiedDate = DateTime.Now;
}
}
foreach (var item in membertrans)
{
item.CreatedBy = _userID;
item.CreatedDate = DateTime.Now;
}
voucher.CreatedBy = _userID;
voucher.CreatedDate = DateTime.Now;
foreach (var item in voucher.GlTranDetails)
{
item.CreatedBy = _userID;
item.CreatedDate = DateTime.Now;
if (item.GLTranUserRecords != null)
{
foreach (var record in item.GLTranUserRecords)
{
record.CreatedBy = _userID;
record.CreatedDate = DateTime.Now;
}
}
}
new MemberService().UploadOpeningBalance(memberList, membertrans, voucher, fundTypeID, _userID);
}
}
catch (Exception ex)
{
throw new ServiceException("Error occured on row:" + nRow + " Reason:" + ex.Message);
}
return Ok(_errorOrSuccessList);
}
[HttpGet("getMaxGLCodeByParent/{id}")]
public ActionResult GetMaxGLCodeByParent(int id)
{
string MaxGLCode = "";
try
{
MaxGLCode = _gLService.GetMaxGLCodeByParent(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(MaxGLCode);
}
[HttpPost]
[Route("updateMemberLoanDeductionDataFromPayroll")]
public ActionResult updateMemberLoanDeductionDataFromPayroll(dynamic data)
{
//Variable
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)items["fundTypeID"].ToObject<int>();
DataTable _uplodedData = (DataTable)items["dataTable"].ToObject<DataTable>();
int nRow = 0;
FundType ofundtype = new FundTypeService().Get(fundTypeID);
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int _userID = currentUser.UserID;
//Objects
List<FMLoanSchedule> oLoanSchedules = new FMLoanScheduleService().Get(ofundtype.CurrentMonth,
fundTypeID);
List<Member> oMembers = new MemberService().GetByFundType(fundTypeID);
List<FMLoan> oLoans = new FMLoanService().GetByFundType(fundTypeID); // only running loan; where payment date is null for the selected month
List<FMLoanSchedule> schedules = [];
List<GLTranDetail> voucherDetails = new List<GLTranDetail>();
List<GL> gls = new GLService().GetbyFundType(fundTypeID);
List<ActivityVoucherSetup> oPrincipalVoucherSetup =
new ActivityVoucherSetupService().GetByProcessType(fundTypeID, EnumFundProcessType.Loan_Principal_Reliazation); // fundProcessType
List<ActivityVoucherSetup> oInterestVoucherSetup =
new ActivityVoucherSetupService().GetByProcessType(fundTypeID, EnumFundProcessType.Loan_Principal_Reliazation); // fundProcessType
List<GLTranDetail> Principaltrandetails = new List<GLTranDetail>();
List<GLTranDetail> Interestrandetails = new List<GLTranDetail>();
List<UploadErrorOrSuccess> _errorOrSuccessList = new List<UploadErrorOrSuccess>();
DateTime voucherDate = DateTime.Today;
if (new GLTranService().VoucherExist(EnumGLTranType.LoanPrincipalReliazation, GlobalFunctions.FirstDateOfMonth(ofundtype.CurrentMonth),
GlobalFunctions.LastDateOfMonth(ofundtype.CurrentMonth), fundTypeID) == true)
{
throw new Exception("Loan Deduction data has already uploaded, Please check fund current month:" + ofundtype.CurrentMonth.ToString("MMM yyyy"));
}
if (_uplodedData.Rows.Count != oLoanSchedules.Count)
{
throw new Exception("Excel file row count is not equal to system data, please check excel" +
" file data to system Reports ( Monthly Loan installment) data:" + ofundtype.CurrentMonth.ToString("MMM yyyy"));
}
try
{
foreach (DataRow dRow in _uplodedData.Rows)
{
nRow += 1;
#region
Member member = oMembers.Find(x => x.EmpCode == dRow["employeeno"].ToString());
if (member == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Member not Found",
nRow, "(" + dRow["employeeno"].ToString() + ")" + "Member/employee not found in the system."));
continue;
}
FMLoan ol = oLoans.Where(o => o.MemberID == member.ID).FirstOrDefault();
if (ol == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow, "(" + dRow["employeeno"].ToString() + ")" + "There is no Loan Entry in Fund System for this employee "));
continue;
}
DateTime slt = DateTime.MinValue;
if (DateTime.TryParse(Convert.ToString(dRow["Payroll Month"]), out slt) == false)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row.", nRow, "(" + dRow["Payroll Month"].ToString() + ")" + "This cannot be empty"));
continue;
}
FMLoanSchedule oschedule = ol.LoanSchedules.FirstOrDefault(o => o.ScheduledPayDate ==
GlobalFunctions.LastDateOfMonth(Convert.ToDateTime(dRow["Payroll Month"])) && ol.ID == o.LoanID);
if (oschedule == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow, "(" + dRow["Payroll Month"].ToString() + ")" +
"There is no Loan installment in current month: "));
continue;
}
//if (oschedule.InstallmentPrincipal != Convert.ToDouble(dRow["Principle"]))
//{
// _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow, "(" + dRow["Principle"].ToString() + ")" + "Principle Does Not Match"));
//}
//if (oschedule.InstallmentInterest != Convert.ToDouble(dRow["Interest"]))
//{
// _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow, "(" + dRow["Principle"].ToString() + ")" + "Interest Does Not Match"));
//}
oschedule.PayDate = GlobalFunctions.LastDateOfMonth(slt);
voucherDate = (DateTime)oschedule.PayDate;
if (oschedule.SerialNo == ol.InstallmentNo)
{
oschedule.IsCompleted = true;
}
oschedule.ModifiedBy = _userID;
oschedule.ModifiedDate = DateTime.Now;
schedules.Add(oschedule);
#endregion
#region Principal Voucher
if (oschedule.InstallmentPrincipal != 0)
{
ActivityVoucherSetup pvprincipal =
oPrincipalVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType
== EnumVouhcerSetupItemType.Loan_Principal);
if (pvprincipal == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow,
"Loan Principal deduction voucher setup not found"));
continue;
}
GL ogl = gls.FirstOrDefault(x => x.ID == pvprincipal.GLID);
GLTranDetail oGTDetail = Principaltrandetails.FirstOrDefault(x => x.GLID == ogl.ID);
if (oGTDetail == null)
{
oGTDetail = new GLTranDetail();
oGTDetail.GLID = ogl.ID;
oGTDetail.Amount = oschedule.InstallmentPrincipal;
oGTDetail.Transide = pvprincipal.GLSide;
Principaltrandetails.Add(oGTDetail);
}
else
{
oGTDetail.Amount = oGTDetail.Amount + oschedule.InstallmentPrincipal;
}
if (ogl.UserObjectID != null)
{
UserRecord oRecord = new UserRecordService().GetByField1(ol.LoanNo,
GlobalFunctions.Fund_UserObject_Loan, fundTypeID);
HRM.BO.GLTranUserRecord gltUR =
new GLTranUserRecord(ogl.ID, 0, 0,
oRecord.UserObjectID, oRecord.ID, oschedule.InstallmentPrincipal);
if (oGTDetail.GLTranUserRecords == null)
oGTDetail.GLTranUserRecords = new List<GLTranUserRecord>();
oGTDetail.GLTranUserRecords.Add(gltUR);
}
ActivityVoucherSetup pricipalContra =
oPrincipalVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType
== EnumVouhcerSetupItemType.Bank || x.VouhcerSetupItemType
== EnumVouhcerSetupItemType.Contra);
if (pricipalContra == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow,
"Loan Interest setup not found"));
continue;
}
// ogl = new GLService().Get(pricipalContra.GLID);
ogl = gls.FirstOrDefault(x => x.ID == pricipalContra.GLID);
GLTranDetail pvcontra = Principaltrandetails.FirstOrDefault(x => x.GLID == ogl.ID);
if (pvcontra == null)
{
pvcontra = new GLTranDetail();
pvcontra.GLID = ogl.ID;
pvcontra.Amount = oschedule.InstallmentPrincipal;
pvcontra.Transide = pricipalContra.GLSide;
Principaltrandetails.Add(pvcontra);
}
else
{
pvcontra.Amount = pvcontra.Amount + oschedule.InstallmentPrincipal;
}
}
#endregion Principal Voucher
#region Interest Voucher
if (oschedule.InstallmentInterest > 0)
{
ActivityVoucherSetup pvinterest =
oInterestVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType
== EnumVouhcerSetupItemType.Loan_Principal);
if (pvinterest == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow,
"Loan Principal deduction voucher setup not found"));
continue;
}
// GL ogl = new GLService().Get(pvinterest.GLID);
GL ogl = gls.FirstOrDefault(x => x.ID == pvinterest.GLID);
GLTranDetail oGTDetail = Interestrandetails.FirstOrDefault(x => x.GLID == ogl.ID);
if (oGTDetail == null)
{
oGTDetail = new GLTranDetail();
oGTDetail.GLID = ogl.ID;
oGTDetail.Amount = oschedule.InstallmentInterest;
oGTDetail.Transide = pvinterest.GLSide;
Principaltrandetails.Add(oGTDetail);
}
else
{
oGTDetail.Amount = oGTDetail.Amount + oschedule.InstallmentInterest;
}
if (ogl.UserObjectID != null)
{
UserRecord oRecord = new UserRecordService().GetByField1(ol.LoanNo,
GlobalFunctions.Fund_UserObject_Loan, fundTypeID);
HRM.BO.GLTranUserRecord gltUR =
new GLTranUserRecord(ogl.ID, 0, 0,
oRecord.UserObjectID, oRecord.ID, oschedule.InstallmentInterest);
if (oGTDetail.GLTranUserRecords == null)
oGTDetail.GLTranUserRecords = new List<GLTranUserRecord>();
oGTDetail.GLTranUserRecords.Add(gltUR);
}
ActivityVoucherSetup interestContra =
oPrincipalVoucherSetup.FirstOrDefault(x => x.VouhcerSetupItemType
== EnumVouhcerSetupItemType.Bank || x.VouhcerSetupItemType
== EnumVouhcerSetupItemType.Contra);
if (interestContra == null)
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Error Row. ", nRow,
"Loan Interest setup not found"));
continue;
}
// ogl = new GLService().Get(interestContra.GLID);
ogl = gls.FirstOrDefault(x => x.ID == interestContra.GLID);
GLTranDetail pvInterest = Interestrandetails.FirstOrDefault(x => x.GLID == ogl.ID);
if (pvInterest == null)
{
pvInterest = new GLTranDetail();
pvInterest.GLID = ogl.ID;
pvInterest.Amount = oschedule.InstallmentInterest;
pvInterest.Transide = interestContra.GLSide;
Interestrandetails.Add(oGTDetail);
}
else
{
pvInterest.Amount = pvInterest.Amount + oschedule.InstallmentInterest;
}
}
#endregion Principal Voucher
}
GLTran oPrincipalTran = new GLTran();
oPrincipalTran.VoucherDate = voucherDate;
oPrincipalTran.Description = "Loan Principal Deduction,Month:" + voucherDate.ToString("MMM yyyy");
oPrincipalTran.GLTranType = EnumGLTranType.LoanPrincipalReliazation;
oPrincipalTran.GlTranDetails = Principaltrandetails;
oPrincipalTran.DebitAmount = Convert.ToDouble(Principaltrandetails.Where(X =>
X.Transide == EnumTranSide.Debit).Sum(x => x.Amount));
oPrincipalTran.CreditAmount = Convert.ToDouble(Principaltrandetails.Where(X =>
X.Transide == EnumTranSide.Credit).Sum(x => x.Amount));
oPrincipalTran.CreatedBy = _userID;
oPrincipalTran.CreatedDate = DateTime.Today;
GLTran oInterestTran = new GLTran();
oInterestTran.Description = "Loan Interest Deduction, Month:" + voucherDate.ToString("MMM yyyy");
oInterestTran.VoucherDate = voucherDate;
oInterestTran.GlTranDetails = Interestrandetails;
oInterestTran.GLTranType = EnumGLTranType.LoanInterestReliazation;
oInterestTran.DebitAmount = Convert.ToDouble(Interestrandetails.Where(X =>
X.Transide == EnumTranSide.Debit).Sum(x => x.Amount));
oInterestTran.CreditAmount = Convert.ToDouble(Interestrandetails.Where(X =>
X.Transide == EnumTranSide.Credit).Sum(x => x.Amount));
oInterestTran.CreatedBy = _userID;
oInterestTran.CreatedDate = DateTime.Today;
List<GLTran> otrans = new List<GLTran>();
otrans.Add(oPrincipalTran);
otrans.Add(oInterestTran);
if (_errorOrSuccessList.Count == 0)
{
new FMLoanService().UpdateLoanPayDateSchedule(schedules, otrans);
}
}
catch (Exception ex)
{
throw new ServiceException("Error occured on row:" + nRow + " Reason:" + ex.Message);
}
return Ok(_errorOrSuccessList);
}
[HttpPost]
[Route("getProcessMonthForInterfaceWithPayroll")]
public ActionResult GetProcessMonthForInterfaceWithPayroll(dynamic data)
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)items["fundTypeID"].ToObject<int>();
DateTime month = (DateTime)items["month"].ToObject<DateTime>();
bool loanDeduction = (bool)items["loanDeduction"].ToObject<bool>();
bool contribution = (bool)items["contribution"].ToObject<bool>();
bool isMonthProcessed;
try
{
isMonthProcessed = _glTranService.GetProcessMonthForInterfaceWithPayroll(fundTypeID, month, loanDeduction, contribution);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(isMonthProcessed);
}
[HttpPost]
[Route("IsVoucherExistInMonth")]
public ActionResult IsVoucherExistInMonth(dynamic data)
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)items["fundTypeID"].ToObject<int>();
DateTime month = (DateTime)items["month"].ToObject<DateTime>();
int typeid = (int)items["voucherType"].ToObject<int>();
EnumGLTranType tranType = (EnumGLTranType)typeid;
bool isMonthProcessed;
try
{
isMonthProcessed = new GLTranService().VoucherExist(tranType,
GlobalFunctions.FirstDateOfMonth(month),
GlobalFunctions.LastDateOfMonth(month), fundTypeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(isMonthProcessed);
}
//[HttpPost]
//[Route("getProcessMonthForInterfaceWithPayroll")]
//public ActionResult GetProcessMonthForInterfaceWithPayroll(dynamic data)
//{
// var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
// int fundTypeID = (int)items["fundTypeID"].ToObject<int>();
// DateTime month = (DateTime)items["month"].ToObject<DateTime>();
// bool loanDeduction = (bool)items["loanDeduction"].ToObject<bool>();
// bool contribution = (bool)items["contribution"].ToObject<bool>();
// bool isMonthProcessed;
// try
// {
// isMonthProcessed = _glTranService.GetProcessMonthForInterfaceWithPayroll(fundTypeID, month, loanDeduction, contribution);
// }
// catch (Exception ex)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
// }
// return Ok(isMonthProcessed);
//}
[HttpPost]
[Route("getYearEndVouchers")]
public ActionResult GetYearEndVouchers(dynamic data)
{
List<GLTran> items = new List<GLTran>();
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundTypeID"].ToObject<int>();
items = _glTranService.GetYearEndGlTrans(fundTypeID);
DataTable table = new DataTable("Customers");
table.Columns.Add("PLDate", typeof(string));
table.Columns.Add("pltranid", typeof(int));
table.Columns.Add("PLAmount", typeof(double));
table.Columns.Add("AllowPLUndo", typeof(bool));
table.Columns.Add("DistributionStatus", typeof(string));
table.Columns.Add("DistributeAmount", typeof(double));
table.Columns.Add("distributetranid", typeof(int));
table.Columns.Add("AllowDistributeUndo", typeof(bool));
table.Columns.Add("distributeOnBalPercent", typeof(double));
List<ActivityVoucherSetup> vsetups = new
ActivityVoucherSetupService().GetByProcessType(fundTypeID, EnumFundProcessType.Profit_Loss);
if (vsetups.Count == 0) throw new Exception("Profit/Loss voucher setup not found.");
ActivityVoucherSetup profit = vsetups.FirstOrDefault(x => x.VouhcerSetupItemType ==
EnumVouhcerSetupItemType.PL_Profit);
if (profit == null) throw new Exception("Profit/Loss voucher setup not found.");
try
{
foreach (GLTran pl in items)
{
DataRow row = table.NewRow();
if (pl.GLTranType == EnumGLTranType.YearEndVoucher)
{
row["PLDate"] = pl.VoucherDate.ToString("dd MMM yyyy");
row["pltranid"] = pl.ID;
row["distributeOnBalPercent"] = 5;
var plitem = pl.GlTranDetails.FirstOrDefault(x => x.GLID == profit.GLID);
if (plitem != null)
row["PLAmount"] = plitem.Amount;
else row["PLAmount"] = 0;
var distirbution = items.FirstOrDefault(x => x.GLTranType
== EnumGLTranType.DividendDistribution && x.VoucherDate == pl.VoucherDate);
if (distirbution == null)
{
row["AllowPLUndo"] = true;
row["DistributionStatus"] = "Not yet Distributed";
row["DistributeAmount"] = plitem.Amount;
}
else
{
row["AllowDistributeUndo"] = true;
row["DistributionStatus"] = "Distributed";
row["distributetranid"] = distirbution.ID;
row["DistributeAmount"] = distirbution.DebitAmount;
row["AllowPLUndo"] = false;
}
table.Rows.Add(row);
}
}
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(table);
}
[HttpGet("GetGLTranByID/{id}")]
public ActionResult GetGLTranByID(int id)
{
GLTran item = new GLTran();
try
{
item = _glTranService.Get(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpPost]
[Route("UndoYearEnd")]
public ActionResult UndoYearEnd(dynamic data)
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundtypeid"].ToObject<int>();
int GLTranID = (int)item["tranID"].ToObject<int>();
try
{
FundType oFundType = _fundTypeService.Get(fundTypeID);
_yearEndService.UndoYearEnd(GLTranID, oFundType);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("UndoDistribute")]
public ActionResult UndoDistribute(dynamic data)
{
var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int fundTypeID = (int)item["fundtypeid"].ToObject<int>();
int GLTranID = (int)item["distributetranid"].ToObject<int>();
try
{
FundType oFundType = _fundTypeService.Get(fundTypeID);
_yearEndService.UndoDistribute(GLTranID, oFundType);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
// Add the following endpoints (place them in the controller, e.g. after GetUserRecordByUserObjectID)
/// <summary>
/// Returns fund user permissions for specified user.
/// GET api/Fund/getUserPermissions/{userId}
/// </summary>
[HttpGet("getUserPermissions/{userId}")]
public ActionResult GetUserPermissions(int userId)
{
List<FMFundUserPermission> items = new List<FMFundUserPermission>();
try
{
items = _fundUserPermissionService.GetByUserID(userId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
/// <summary>
/// Save fund user permissions.
/// POST api/Fund/saveUserPermissions
/// Body: JSON array of FMFundUserPermission
/// </summary>
[HttpPost("saveUserPermissions")]
public ActionResult SaveUserPermissions([FromBody] List<FMFundUserPermission> items)
{
if (items == null)
return BadRequest("Invalid payload.");
if (items.Count == 0)
return BadRequest("No permissions to save.");
try
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
// Set audit fields on each item
foreach (var it in items)
{
if (it.IsNew)
{
it.CreatedBy = currentUser.UserID;
it.CreatedDate = DateTime.Now;
}
else
{
it.ModifiedBy = currentUser.UserID;
it.ModifiedDate = DateTime.Now;
}
}
_fundUserPermissionService.SavePermissions(items, currentUser.UserID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
}
}