2026-11-26 10:48:45 +06:00
|
|
|
using System;
|
|
|
|
|
using HRM.BO;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace HRM.UI.Controllers.Payroll
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Core Payroll > LFA. The Excel template and upload are in DataUploadController, with every other uploader.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/lfa")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class LFAController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ILFAPaymentService _lfaPaymentService;
|
|
|
|
|
|
|
|
|
|
public LFAController(ILFAPaymentService lfaPaymentService)
|
|
|
|
|
{
|
|
|
|
|
this._lfaPaymentService = lfaPaymentService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The current salary month and the next batch number.</summary>
|
|
|
|
|
[HttpGet("getPaymentInfo")]
|
|
|
|
|
public ActionResult GetPaymentInfo()
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetInfo(currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Calculates the rows again; nothing is saved.</summary>
|
|
|
|
|
[HttpPost("calculatePayment")]
|
|
|
|
|
public ActionResult CalculatePayment(LFAPaymentRequest request)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.Calculate(request, currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Saves the rows as a new batch, all or nothing. The payroll type and user come from the token.</summary>
|
|
|
|
|
[HttpPost("processPayment")]
|
|
|
|
|
public ActionResult ProcessPayment(LFAPaymentRequest request)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.Process(request, currentUser.PayrollTypeID.GetValueOrDefault(), currentUser.UserID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("getPaymentHistory/{fromDate}/{toDate}")]
|
|
|
|
|
public ActionResult GetPaymentHistory(DateTime fromDate, DateTime toDate)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetHistory(fromDate, toDate, currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-26 15:13:21 +06:00
|
|
|
// ── LFA Payment Undo ──
|
|
|
|
|
|
|
|
|
|
/// <summary>Every batch of the current payroll type, and whether each one can be undone.</summary>
|
|
|
|
|
[HttpGet("getUndoBatches")]
|
|
|
|
|
public ActionResult GetUndoBatches()
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetUndoBatches(currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-29 09:50:10 +06:00
|
|
|
/// <summary>LFA Bank Advice: the approved batches of the payroll type.</summary>
|
|
|
|
|
[HttpGet("getBankAdviceBatches")]
|
|
|
|
|
public ActionResult GetBankAdviceBatches()
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetBankAdviceBatches(currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-26 15:13:21 +06:00
|
|
|
[HttpGet("getBatchEmployees/{lfaPaymentID}")]
|
|
|
|
|
public ActionResult GetBatchEmployees(int lfaPaymentID)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetBatchEmployees(lfaPaymentID, currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Undoes the whole batch or the selected employees of it; the server checks everything again.</summary>
|
|
|
|
|
[HttpPost("undoPayment")]
|
|
|
|
|
public ActionResult UndoPayment(LFAPaymentUndoRequest request)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.Undo(request, currentUser.PayrollTypeID.GetValueOrDefault(), currentUser.UserID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-26 18:54:00 +06:00
|
|
|
// ── LFA Payment Approval (as Salary Approve: Direct Approve or the approval workflow, Logic lfaapproval/workflow) ──
|
|
|
|
|
|
|
|
|
|
/// <summary>Logic key, whether the login has an employee, and whether Work Flow Setup has LFA rules.</summary>
|
|
|
|
|
[HttpGet("getApprovalInfo")]
|
|
|
|
|
public ActionResult GetApprovalInfo()
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetApprovalInfo(currentUser.EmployeeID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("getApprovalBatches")]
|
|
|
|
|
public ActionResult GetApprovalBatches()
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetApprovalBatches(currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("getFlowHistory/{lfaPaymentID}")]
|
|
|
|
|
public ActionResult GetFlowHistory(int lfaPaymentID)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetFlowHistory(lfaPaymentID, currentUser.PayrollTypeID.GetValueOrDefault()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Direct Approve, when the workflow is off.</summary>
|
|
|
|
|
[HttpPost("approveDirect")]
|
|
|
|
|
public ActionResult ApproveDirect(LFAApprovalRequest request)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.ApproveDirect(request, currentUser.PayrollTypeID.GetValueOrDefault(), currentUser.UserID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Submit for approval (or submit again after a revert), when the workflow is on.</summary>
|
|
|
|
|
[HttpPost("submitForApproval")]
|
|
|
|
|
public ActionResult SubmitForApproval(LFAApprovalRequest request)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
if (currentUser.UserType == EnumUserType.Employee)
|
|
|
|
|
{
|
|
|
|
|
return NotAllowed();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.SubmitForApproval(request, currentUser.PayrollTypeID.GetValueOrDefault(),
|
|
|
|
|
currentUser.EmployeeID, currentUser.UserID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The approver's side (/payment-approval/lfa). Approvers act as employees, as on Salary's Payment Approval
|
|
|
|
|
// page, so these are open to every login; the service checks that the step is pending with the login.
|
|
|
|
|
|
|
|
|
|
[HttpGet("getApproverBatch/{wfMovementTranID}")]
|
|
|
|
|
public ActionResult GetApproverBatch(int wfMovementTranID)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.GetApproverBatch(wfMovementTranID, currentUser.EmployeeID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("approveFromApprover")]
|
|
|
|
|
public ActionResult ApproveFromApprover(LFAApproverActionRequest request)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.ApproveFromApprover(request, currentUser.EmployeeID, currentUser.UserID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("revertFromApprover")]
|
|
|
|
|
public ActionResult RevertFromApprover(LFAApproverActionRequest request)
|
|
|
|
|
{
|
|
|
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Ok(this._lfaPaymentService.RevertFromApprover(request, currentUser.EmployeeID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-26 10:48:45 +06:00
|
|
|
private ActionResult NotAllowed()
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(StatusCodes.Status403Forbidden, "You are not allowed to process LFA payment.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|