EchoTex_Payroll/HRM.UI/Controllers/Payroll/LoanController.cs

865 lines
26 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using HRM.BO;
using HRM.DA;
using Microsoft.AspNetCore.Authorization;
namespace HRM.UI.Controllers.Payroll
{
[Route("api/Loan")]
[ApiController]
[Authorize]
public class LoanController : ControllerBase
{
private readonly ILoanService _loanService;
private readonly ILoanEmployeeDocService _employeeDocService;
private readonly ILoanIssueService _loanIssueService;
private readonly ILoanParameterService _loanParameterService;
private readonly ILoanScheduleService _loanScheduleService;
public LoanController(ILoanService loanService,
ILoanEmployeeDocService loanEmployeeDocService,
ILoanIssueService loanIssueService,
ILoanParameterService loanParameterService,
ILoanScheduleService loanScheduleService)
{
this._loanService = loanService;
this._employeeDocService = loanEmployeeDocService;
this._loanIssueService = loanIssueService;
this._loanParameterService = loanParameterService;
this._loanScheduleService = loanScheduleService;
}
// loan
[HttpGet("getLoanById/{id}")]
public ActionResult GetLoanById(int id)
{
Loan loan = new Loan();
try
{
loan = _loanService.Get(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loan);
}
[HttpGet("getLoanListByStatus/{status}")]
public ActionResult GetLoanListByStatus(EnumStatus status)
{
List<Loan> loans = new List<Loan>();
try
{
loans = _loanService.Get(status);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loans);
}
[HttpGet("getLoanByLoanNo/{loanNo}")]
public ActionResult GetLoanByLoanNo(string loanNo)
{
Loan loan = new Loan();
try
{
loan = _loanService.Get(loanNo);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loan);
}
[HttpGet("getLoanSettlementData/{empId}/{loanId}")]
public ActionResult GetLoanSettlementData(int empId, int loanId)
{
DataTable dt = new DataTable();
try
{
dt = _loanIssueService.GetLoanSettlementData(empId, loanId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dt);
}
[HttpGet("getLoanListByEmployee/{empId}")]
public ActionResult GetLoanListByEmployee(int empId)
{
DataTable dt = new DataTable();
try
{
dt = _loanIssueService.GetLoanListByEmployee(empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(dt);
}
[HttpPost]
[Route("saveLoan")]
public ActionResult SaveLoan(Loan loan)
{
try
{
_loanService.Save(loan);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loan);
}
[HttpPost]
[Route("calculateLoanSchedule")]
public ActionResult calculateLoanSchedule(LoanIssue issue)
{
Loan oloan = this._loanService.Get(issue.LoanID);
try
{
if(oloan.LoanGroup == EnumLoanGroup.PF_Loan)
{
issue.loan = oloan;
issue.Schedules = issue.PreparePFLoanSchedule(issue);
}
else if (oloan.LoanGroup == EnumLoanGroup.Flat_Amount)
{
issue.loan = oloan;
issue.Schedules = issue.PrepareFlatAmountSchedule(issue);
}
else issue.Schedules = issue.PrepareEMISchedule(issue);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(issue.Schedules);
}
[HttpPost]
[Route("deleteLoan")]
public ActionResult DeleteLoan(int id)
{
try
{
_loanService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
// Loan Employee Doc
[HttpGet("getLoanEmployeeDocById/{id}")]
public ActionResult GetLoanEmployeeDocById(int id)
{
LoanEmployeeDoc loanEmployeeDoc = new LoanEmployeeDoc();
try
{
loanEmployeeDoc = _employeeDocService.Get(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanEmployeeDoc);
}
[HttpGet("getLoanEmployeeDocByIssueId/{id}")]
public ActionResult GetLoanEmployeeDocByIssueId(int id)
{
List<LoanEmployeeDoc> loanEmployeeDocs = new List<LoanEmployeeDoc>();
try
{
loanEmployeeDocs = _employeeDocService.GetbyIssueId(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanEmployeeDocs);
}
[HttpPost]
[Route("deleteLoanEmployee")]
public ActionResult DeleteLoanEmployee(int id)
{
try
{
_employeeDocService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
// Loan Issue
[HttpGet("getLoanIssueById/{id}")]
public ActionResult GetLoanIssueById(int id)
{
LoanIssue loanIssue = new LoanIssue();
try
{
loanIssue = _loanIssueService.Get(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssue);
}
[HttpGet("getAllLoanIssue")]
public ActionResult GetAllLoanIssue()
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getExistingLoan/{loanId}/{empId}")]
public ActionResult GetExistingLoan(int loanId, int empId)
{
LoanIssue loanIssue = new LoanIssue();
try
{
loanIssue = _loanIssueService.GetExistingLoan(loanId, empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssue);
}
[HttpGet("getExistingAllLoan/{loanId}/{empId}")]
public ActionResult GetExistingAllLoan(int loanId, int empId)
{
LoanIssue loanIssue = new LoanIssue();
try
{
loanIssue = _loanIssueService.GetExistingAllLoan(loanId, empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssue);
}
[HttpGet("getExistingLoanList/{empId}")]
public ActionResult GetExistingLoanList(int empId)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetExistingLoan(empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getExistingLoanListByEmpId/{empId}")]
public ActionResult GetExistingLoanListByEmpId(int empId)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetExistingLoan(empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getLoanListByEmpIds/{empId}")]
public ActionResult GetLoanListByEmpIds(string empId)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetByEmpIDs(empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getByDueInstallmentDate/{dateTime}/{empId}")]
public ActionResult GetByDueInstallmentDate(DateTime dateTime, string empId)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetByDueInstallmentDate(dateTime, empId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getLoanIssueByDateTime/{dateTime}")]
public ActionResult GetLoanIssueByDateTime(DateTime dateTime)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.Get(dateTime);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getLoanIssueByDateTimeRange/{dateTime1}/{dateTime2}")]
public ActionResult GetLoanIssueByDateTimeRange(DateTime dateTime1, DateTime dateTime2)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.Get(dateTime1, dateTime2);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getLoanIssueByEmployeeNo/{employeeNo}")]
public ActionResult GetLoanIssueByEmployeeNo(string employeeNo)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.Get(employeeNo);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getLoanIssueByEmployeeID/{employeeID}")]
public ActionResult GetLoanIssueByEmployeeID(string employeeID)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetByEmpIDs(employeeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("generateLoanNumber/{employeeID}")]
public ActionResult generateLoanNumber(int employeeID)
{
string loanNumber = "";
try
{
loanNumber = new LoanIssueService().GenerateLoanNo(employeeID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanNumber);
}
[HttpGet("getLoanIssueByLoanID/{loanID}")]
public ActionResult GetLoanIssueByLoanID(int loanID)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetByLoanID(loanID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getByEmployeeIdAndLoanNumber/{id}/{loanID}")]
public ActionResult GetByEmployeeIdAndLoanNumber(int id, string loanID)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetByEmployeeIdAndLoanNumber(id, loanID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getByLoanAndEmployeeIdAndLoanNumber/{loanID}/{employeeId}/{loadNumber}")]
public ActionResult GetByEmployeeIdAndLoanNumber(int loanID, int employeeId, string loanNumber)
{
LoanIssue loanIssue = new LoanIssue();
try
{
loanIssue = _loanIssueService.GetByLoanAndEmployeeIdAndLoanNumber(loanID, employeeId, loanNumber);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssue);
}
[HttpGet("getByDueInstallmentDateList/{dateTime}")]
public ActionResult GetByDueInstallmentDateList(DateTime dateTime)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetByDueInstallmentDate(dateTime, payrollTypeId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpGet("getUnPaidLoanWithSchedule/{dateTime}")]
public ActionResult getUnPaidLoanWithSchedule(DateTime dateTime)
{
List<LoanIssue> loanIssues = new List<LoanIssue>();
try
{
loanIssues = _loanIssueService.GetUnPaidLoanWithSchedule(dateTime);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanIssues);
}
[HttpPost]
[Route("updateAvgIntStatus")]
public ActionResult UpdateAvgIntStatus(List<LoanIssue> loansIssues)
{
try
{
_loanIssueService.UpdateAvgIntStatus(loansIssues);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("saveLoanIssue")]
public ActionResult SaveLoanIssue(LoanIssue loansIssue)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int pkid = 0;
if (loansIssue.IsNew == true)
{
loansIssue.CreatedBy = currentUser.UserID;
loansIssue.CreatedDate = DateTime.Today;
}
else
{
loansIssue.ModifiedBy = currentUser.UserID;
loansIssue.ModifiedDate = DateTime.Today;
}
try
{
pkid= _loanIssueService.Save(loansIssue);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(pkid);
}
[HttpPost]
[Route("saveLoanIssueList")]
public ActionResult SaveLoanIssueList(List<LoanIssue> loansIssues)
{
try
{
_loanIssueService.SaveAll(loansIssues);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("save2")]
public ActionResult Save2(LoanIssue loansIssue)
{
try
{
_loanIssueService.Save2(loansIssue);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("deleteLoadIssue")]
public ActionResult DeleteLoadIssue(LoanIssue lissue)
{
try
{
_loanIssueService.Delete(lissue.ID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
// loan parameter
[HttpGet("getLoanParameter/{id}")]
public ActionResult GetLoanParameter(int id)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
LoanParameter loanParameter = new LoanParameter();
try
{
loanParameter = _loanParameterService.Get(id, payrollTypeId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanParameter);
}
[HttpGet("getAllLoanParameter")]
public ActionResult GetAllLoanParameter()
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
List<LoanParameter> loanParameters = new List<LoanParameter>();
try
{
loanParameters = _loanParameterService.Get(payrollTypeId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanParameters);
}
[HttpGet("getLoanGrades/{loanParameterID}")]
public ActionResult GetLoanGrades(int loanParameterID)
{
List<LoanGrades> loanGrades = new List<LoanGrades>();
try
{
loanGrades = _loanParameterService.GetLoanGrades(loanParameterID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanGrades);
}
[HttpGet("getLoanDoc/{loanParameterID}")]
public ActionResult GetLoanDoc(int loanParameterID)
{
List<LoanDoc> loanDocs = new List<LoanDoc>();
try
{
loanDocs = _loanParameterService.GetLoanDoc(loanParameterID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanDocs);
}
[HttpPost]
[Route("saveLoanParameter")]
public ActionResult SaveLoanParameter(LoanParameter loanParameter)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
try
{
_loanParameterService.Save(loanParameter, payrollTypeId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("deleteLoanParameter")]
public ActionResult DeleteLoanParameter(int id)
{
try
{
_loanParameterService.Delete(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
// loan Schedule
[HttpGet("getLoanScheduleByIssueId/{issueId}")]
public ActionResult GetLoanScheduleByIssueId(int issueId)
{
List<LoanSchedule> loanSchedules = new List<LoanSchedule>();
try
{
loanSchedules = _loanScheduleService.GetByIssueID(issueId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(loanSchedules);
}
[HttpPost]
[Route("saveLoanScheduleList")]
public ActionResult SaveLoanSchedule(List<LoanSchedule> items)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
items.ForEach(x =>
{
x.ModifiedBy = currentUser.UserID;
x.ModifiedDate = DateTime.Today;
});
try
{
_loanScheduleService.SaveList(items);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[Route("UpdateLoanScheduleAmount")]
public ActionResult UpdateLoanScheduleAmount(List<LoanSchedule> items)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
items.ForEach(x =>
{
x.ModifiedBy = currentUser.UserID;
x.ModifiedDate = DateTime.Today;
});
try
{
new LoanScheduleService().UpdateSchedules(items);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
/*[HttpPost]
[Route("saveLoanSchedule")]
public ActionResult SaveLoanSchedule(FmLoanSchedule loanSchedule)
{
try
{
_loanScheduleService.Save(loanSchedule);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("deleteLoanSchedule")]
public ActionResult DeleteLoanSchedule(int loadScheduleId)
{
try
{
_loanScheduleService.Delete(loadScheduleId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpGet("getByLoanScheduleId/{loanScheduleId}")]
public ActionResult GetByLoanScheduleId(int loanScheduleId)
{
FmLoanSchedule fmLoanSchedule = new FmLoanSchedule();
try
{
fmLoanSchedule = _loanScheduleService.Get(loanScheduleId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(fmLoanSchedule);
}
[HttpGet("getAllLoanSchedule")]
public ActionResult GetAllLoanSchedule()
{
List<FmLoanSchedule> fmLoanSchedules = new List<FmLoanSchedule>();
try
{
fmLoanSchedules = _loanScheduleService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(fmLoanSchedules);
}
[HttpGet("getSchedule/{dt}")]
public ActionResult GetSchedule(DateTime dt)
{
bool result;
try
{
result = _loanScheduleService.GetSchedule(dt);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(result);
}*/
}
}