EchoTex_Payroll/HRM.UI/Controllers/Employee/empLifeCycleController.cs

357 lines
12 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using AutoMapper;
using HRM.BO;
using HRM.DA;
using HRM.UI.DTOs.Training;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace HRM.UI.Controllers
{
[ApiController]
[Route("api/EmpLifeCycle")]
[Authorize]
public class EmpLifeCycleController : ControllerBase
{
private readonly IMapper _mapper;
private readonly IUserService _userService;
private readonly IEmployeeStatusService _employeeStatusService;
IEmpLifeCycleService _lifeCycleService;
IEmployeeGradeSalaryService _empGradeSalaries;
private readonly IPayrollTypeService _payrollTypeService;
public EmpLifeCycleController(IEmployeeStatusService empStatus,
IEmpLifeCycleService lifeCycleService,
IEmployeeStatusService employeeStatusService, IPayrollTypeService pTypeService,
IUserService userService, IEmployeeGradeSalaryService empGradeSalaries)
{
_employeeStatusService = employeeStatusService;
_lifeCycleService = lifeCycleService;
_userService = userService;
_empGradeSalaries = empGradeSalaries;
this._payrollTypeService = pTypeService;
}
[HttpPost]
[Route("SaveLifeCycle")]
public ActionResult SaveLifeCycle(EmpLifeCycle lifecycle)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollId = currentUser.PayrollTypeID.GetValueOrDefault();
lifecycle.CreatedBy = currentUser.UserID;
lifecycle.CreatedDate = DateTime.Today;
lifecycle.SalaryMonth = (DateTime)currentUser.NextPayProcessDate;
try
{
return Ok(this._lifeCycleService.Save(lifecycle, (DateTime)currentUser.NextPayProcessDate, payrollId));
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
[HttpPost]
[Route("deleteGradeSalary")]
public ActionResult deleteGradeSalary(EmployeeGradeSalary item)
{
if(item.ArrearType != EnumArrearType.ToCalculate)
{
throw new Exception("Only Arrear item are allowed to delete");
}
try
{
this._empGradeSalaries.Delete(item.ID);
return Ok(true);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
[HttpPost("getEmpLifeCyclesByDate")]
public ActionResult GetEmpLifeCycles(dynamic data)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollId = currentUser.PayrollTypeID.GetValueOrDefault();
var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data));
DateTime fromDate = (DateTime)items["fromDate"].ToObject<DateTime>();
DateTime toDate = (DateTime)items["toDate"].ToObject<DateTime>();
List<EmpLifeCycle> empLifeCycles = new List<EmpLifeCycle>();
try
{
empLifeCycles = _lifeCycleService.GetByDate(fromDate, toDate, payrollId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(empLifeCycles);
}
[HttpGet("getEmpLifeByStatus/{status}")]
public ActionResult GetEmpLifeByStatus(EnumStatus status)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollId = currentUser.PayrollTypeID.GetValueOrDefault();
List<EmpLifeCycle> empLifeCycles = new List<EmpLifeCycle>();
try
{
empLifeCycles = _lifeCycleService.Get(status, payrollId);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(empLifeCycles);
}
[HttpGet("getEmpLifeCycles/{EmpID}")]
public ActionResult GetEmpLifeCycles(int EmpID)
{
try
{
return Ok(this._lifeCycleService.GetEmpID(EmpID));
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
}
[HttpGet("get/{sts}")]
public List<EmployeeStatus> Get(EnumStatus sts)
{
EmployeeStatusService service = new EmployeeStatusService();
return service.Get(sts);
}
[HttpGet("getEmpStatus")]
public List<EmployeeStatus> GetEmpStatus()
{
EmployeeStatusService service = new EmployeeStatusService();
return service.Get();
}
//[HttpGet("get")]
//public List<Configaration> GetChilds(string NodeName, EnumConfigurationType type);
//{
// //EmployeeStatusService service = new EmployeeStatusService();
// //return service.Get();
//}
[HttpGet("GetByUserID")]
public ActionResult GetByUserID()
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
List<EmployeeStatus> oEmpStatusComponent = new List<EmployeeStatus>();
try
{
oEmpStatusComponent = this._employeeStatusService.GetByUserID(currentUser.UserID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oEmpStatusComponent);
}
[HttpGet("GetEmployeeGradeSalaries/{empid}")]
public ActionResult GetEmployeeGradeSalaries(int empid)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
List<EmployeeGradeSalary> salaries = new List<EmployeeGradeSalary>();
try
{
salaries = this._empGradeSalaries.Get(empid);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(salaries);
}
[HttpGet("GetSalaryHistory/{empid}")]
public ActionResult GetSalaryHistory(int empid)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
DataTable items =null;
try
{
items = this._empGradeSalaries.GetSalaryHistory(empid);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(items);
}
[HttpGet("getEmpStatusComponent/{id}")]
public ActionResult GetEmpStatusComponent(int id)
{
List<EmployeeStatus.EmpStatusComponent> oEmpStatusComponent = new List<EmployeeStatus.EmpStatusComponent>();
try
{
oEmpStatusComponent = this._employeeStatusService.GetChild(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oEmpStatusComponent);
}
[HttpGet("getEmpStatusComponentUser/{id}")]
public ActionResult GetEmpStatusComponentUser(int id)
{
List<EmployeeStatus.EmployeeStatusComponentUser> oEmployeeStatusComponentUser =
new List<EmployeeStatus.EmployeeStatusComponentUser>();
try
{
oEmployeeStatusComponentUser = this._employeeStatusService.GetEmpStatusComponentUser(id);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(oEmployeeStatusComponentUser);
}
[HttpPost("submit-employee-status")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK)]
public HttpResponseMessage save(EmployeeStatus oEmployeeStatus)
{
// CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
// var tempDate = oLeaveEntry.EntryDate;
try
{
//ouser.CreatedBy = currentUser.UserID;
//ouser.CreatedDate = DateTime.Now;
//ouser.ParentID = currentUser.UserID;
_employeeStatusService.Save(oEmployeeStatus);
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
}
catch (Exception)
{
return new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
}
}
[HttpGet("GetAllPayrollTypes")]
public ActionResult GetAllPayrollTypes()
{
List<PayrollType> items = new List<PayrollType>();
try
{
items = this._payrollTypeService.Get();
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
int payrollId = currentUser.PayrollTypeID.GetValueOrDefault();
items = items.Where(x => x.ID != payrollId).ToList();
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
return Ok(items);
}
[HttpGet("getUsers")]
public ActionResult GetUsers()
{
List<User> _users = new List<User>();
try
{
_users = _userService.GetAll();
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(_users);
}
//[HttpGet("getAllUser")]
//public ActionResult GetAllUser()
//{
// List<User> items = new List<User>();
// try
// {
// items = this._userService.Get();
// }
// catch (Exception ex)
// {
// return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
// }
// return Ok(items);
//}
// Employee Status
[HttpPost]
[Route("saveEmployeeStatus")]
public ActionResult SaveCostCenterList(EmployeeStatus item)
{
try
{
_employeeStatusService.SaveStatus(item);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("DeleteEmployeeStatus")]
public ActionResult DeleteEmployeeStatus(EmployeeStatus item)
{
try
{
_employeeStatusService.Delete(item.ID);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok();
}
[HttpPost]
[Route("DeleteEmpLifecycele")]
public ActionResult DeleteEmpLifecycele(EmpLifeCycle item)
{
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
try
{
_lifeCycleService.Delete(item, (DateTime) currentUser.NextPayProcessDate);
}
catch (Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
}
return Ok(true);
}
}
}