HRM-10/HRM.UI/Controllers/Payroll/LFAController.cs
Mohaimen Hasan 88235461bf LFA
2026-11-26 10:48:45 +06:00

105 lines
3.7 KiB
C#

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);
}
}
private ActionResult NotAllowed()
{
return StatusCode(StatusCodes.Status403Forbidden, "You are not allowed to process LFA payment.");
}
}
}