163 lines
5.8 KiB
C#
163 lines
5.8 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);
|
|
}
|
|
}
|
|
|
|
// ── 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);
|
|
}
|
|
}
|
|
|
|
[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);
|
|
}
|
|
}
|
|
|
|
private ActionResult NotAllowed()
|
|
{
|
|
return StatusCode(StatusCodes.Status403Forbidden, "You are not allowed to process LFA payment.");
|
|
}
|
|
}
|
|
}
|