HRM-10/HRM.UI/Controllers/Adhoc-feature/AdhocFeatureController.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

213 lines
6.8 KiB
C#

using System;
using System.Collections.Generic;
using HRM.BO;
using HRM.DA;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace HRM.UI.Controllers.Adhoc_feature
{
[Route("api/AdhocFeature")]
[ApiController]
[Authorize]
public class AdhocFeatureController : ControllerBase
{
private readonly IADParameterEmployeeService _adParameterEmployeeService;
private readonly IApproveFinantialDataService _approveFinancialDataService;
public AdhocFeatureController(IADParameterEmployeeService adParameterEmployeeService,
IApproveFinantialDataService approveFinancialDataService)
{
_adParameterEmployeeService = adParameterEmployeeService;
_approveFinancialDataService = approveFinancialDataService;
}
[HttpGet("getAllFinancialData")]
public ActionResult GetAllFinancialData()
{
List<ApproveFinantialData> items = new List<ApproveFinantialData>();
try
{
items = _approveFinancialDataService.Get();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpPost("getAdParamEmpForApproval")]
public ActionResult GetAdParamEmpForApproval(dynamic data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int itemId = (int)items["id"].ToObject<int>();
DateTime fromDate = (DateTime)items["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)items["toDate"].ToObject<DateTime>();
List<ADParameterEmployee> adParameterEmployees = new List<ADParameterEmployee>();
try
{
adParameterEmployees = _adParameterEmployeeService.GetForApproval(itemId, payrollTypeId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(adParameterEmployees);
}
[HttpPost]
[Route("UpdateApprovalStatus")]
public ActionResult UpdateApprovalStatus(List<ADParameterEmployee> parmEmps)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollId = currentUser.PayrollTypeID.GetValueOrDefault();
try
{
this._adParameterEmployeeService.UpdateApprovalStatus(parmEmps);
return Ok(true);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
[HttpPost("GetAdParamEmpForApprovalNew")]
public ActionResult GetAdParamEmpForApprovalNew(dynamic data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault();
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int itemId = (int)items["id"].ToObject<int>();
DateTime fromDate = (DateTime)items["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)items["toDate"].ToObject<DateTime>();
List<ADParameterEmployee> adParameterEmployees = new List<ADParameterEmployee>();
try
{
adParameterEmployees = _adParameterEmployeeService.GetForApprovalNew(itemId, fromDate, toDate, payrollTypeId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(adParameterEmployees);
}
[HttpPost("getAllFinancialDataByType")]
public ActionResult GetAllFinancialDataByType(dynamic data)
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int selectedDataType = (int)items["selectedDataType"].ToObject<int>();
ApproveFinantialDataService service = new ApproveFinantialDataService();
List<ApproveFinantialData> finantialData = new List<ApproveFinantialData>();
try
{
finantialData = service.GetByType(selectedDataType);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(finantialData);
}
[HttpPost("GetAllFinancialDataByTypeNew")]
public ActionResult GetAllFinancialDataByTypeNew(dynamic data)
{
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
int selectedDataType = (int)items["selectedDataType"].ToObject<int>();
string empIds = (string)items["dataList"].ToObject<string>();
DateTime fromDate = (DateTime)items["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)items["toDate"].ToObject<DateTime>();
ApproveFinantialDataService service = new ApproveFinantialDataService();
List<ApproveFinantialData> finantialData = new List<ApproveFinantialData>();
try
{
//finantialData = service.GetByType(selectedDataType, empIds);
finantialData = service.GetByTypeAndDate(selectedDataType, empIds, fromDate, GlobalFunctions.LastDateOfMonth(toDate));
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(finantialData);
}
[HttpGet("getByAllowForApproval/{allowDeductId}")]
public ActionResult GetByAllowForApproval(int allowDeductId)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollId = currentUser.PayrollTypeID.GetValueOrDefault();
List<ADParameterEmployee> items = new List<ADParameterEmployee>();
try
{
items = _adParameterEmployeeService.GetByAllowForApproval(allowDeductId, payrollId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("GetPendingApprovalSummary")]
public ActionResult GetPendingApprovalSummary()
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollId = currentUser.PayrollTypeID.GetValueOrDefault();
PendingApprovalSummary item = new PendingApprovalSummary();
try
{
item = _adParameterEmployeeService.GetByAllowForApproval(payrollId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(item);
}
[HttpPost("saveFinancialDataList")]
public ActionResult SaveFinancialDataList(List<ApproveFinantialData> items)
{
try
{
_approveFinancialDataService.Save(items);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost("deleteFinancialDataList")]
public ActionResult DeleteFinancialDataList(List<ApproveFinantialData> items)
{
try
{
_approveFinancialDataService.Delete(items);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
}
}