440 lines
16 KiB
C#
440 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using HRM.UI.Components;
|
|
using HRM.BO;
|
|
using HRM.DA;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using HRM.UI.MODELS;
|
|
using Microsoft.Extensions.Configuration;
|
|
using HRM.Report;
|
|
using HRM.UI.Controllers.Report;
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
namespace HRMobileAPI.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/Mobile/Leave")]
|
|
[Authorize]
|
|
public class LeaveController : ControllerBase
|
|
{
|
|
private readonly ILeaveService _leaveService;
|
|
private readonly ILeaveEntryService _leaveEntryService;
|
|
private readonly IEmployeeService _employeeService;
|
|
private readonly ILeaveYearService _leaveYearService;
|
|
private readonly ILeaveProcessService _leaveProcessService;
|
|
private readonly IGradeService _gradeService;
|
|
private readonly IConfiguration _config;
|
|
private readonly ISearchEmployeeService _searchManager;
|
|
public LeaveController(
|
|
IConfiguration config,
|
|
ILeaveService leaveService,
|
|
IEmployeeService employeeService,
|
|
ILeaveEntryService leaveEntryService,
|
|
ILeaveYearService leaveYearService,
|
|
ILeaveProcessService leaveProcessService,
|
|
IGradeService gradeService,
|
|
ISearchEmployeeService searchManager)
|
|
{
|
|
_config = config;
|
|
this._leaveService = leaveService;
|
|
this._employeeService = employeeService;
|
|
this._leaveEntryService = leaveEntryService;
|
|
this._leaveYearService = leaveYearService;
|
|
this._leaveProcessService = leaveProcessService;
|
|
this._gradeService = gradeService;
|
|
this._searchManager = searchManager;
|
|
}
|
|
|
|
// GET: api/Leave/1
|
|
public ActionResult Get(int id)
|
|
{
|
|
try
|
|
{
|
|
Leave oLeave = _leaveService.Get(id);
|
|
return Ok(oLeave != null ? oLeave.ConvertToTModel() : null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
// GET: api/Leave/GetByEmpID/1
|
|
[HttpGet]
|
|
[Route("GetByEmpID/{id}")]
|
|
|
|
public ActionResult GetByEmpID(int id)
|
|
{
|
|
try
|
|
{
|
|
List<LeaveTModel> objs = null;
|
|
Employee oEmp = _employeeService.Get(id);
|
|
|
|
if (oEmp != null)
|
|
{
|
|
List<Leave> _oLeaves = new List<Leave>();
|
|
_oLeaves = _leaveService.getEmpApplicableLeave(oEmp.ID);
|
|
|
|
objs = _oLeaves.ConvertToTModels();
|
|
}
|
|
return Ok(objs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetLeaveDays")]
|
|
|
|
public ActionResult GetLeaveDays(int LeaveID, int EmployeeID, DateTime FromDate, DateTime ToDate, bool IsHalfDay)
|
|
{
|
|
try
|
|
{
|
|
Employee oEmp = _employeeService.Get(EmployeeID);
|
|
Leave oLeave = _leaveService.Get(LeaveID);
|
|
//double totalApplicableLeave = _leaveEntryService.GetApplicableDays(oLeave, oEmp, FromDate, ToDate, IsHalfDay); // including workplan setup
|
|
double totalApplicableLeave = _leaveEntryService.CalculatedLeaveDays(oLeave.ID, oEmp.GradeID ?? 0, oEmp.LocationID ?? 0, EnumLeaveparamOn.Grade, oEmp.PayrollTypeID, FromDate, ToDate, false, false, IsHalfDay, (int)oEmp.ID);
|
|
return Ok(totalApplicableLeave);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetAttachmentApplicability")]
|
|
|
|
public ActionResult GetAttachmentApplicability(int EmployeeID, int LeaveID, double leaveDays)
|
|
{
|
|
try
|
|
{
|
|
Leave oLeave = _leaveService.Get(LeaveID);
|
|
bool IsAttachmentAplicable = _leaveService.IsAttachmentAplicable(oLeave, (decimal)leaveDays);
|
|
return Ok(IsAttachmentAplicable);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetCurrentLeaveYear")]
|
|
|
|
public ActionResult GetCurrentLeaveYear()
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
LeaveYear lvYear = _leaveYearService.GetCurrentYear((int)currentUser.PayrollTypeID );
|
|
return Ok(lvYear.Name);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetEmpLeaveBalance/{id}")]
|
|
|
|
public ActionResult GetEmpLeaveBalance(int id)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
Employee oEmp = _employeeService.Get(id);
|
|
LeaveYear ly = _leaveYearService.GetCurrentYear((int)currentUser.PayrollTypeID );
|
|
|
|
if (oEmp == null)
|
|
{
|
|
throw new Exception("Employee does not exists");
|
|
}
|
|
|
|
if (ly == null)
|
|
{
|
|
throw new Exception("Current Leave Year Not Found");
|
|
}
|
|
|
|
List<EmpLeaveStatus> statuses = _leaveProcessService.GetLeaveBalance(ly.ID, oEmp.PayrollTypeID, "", oEmp.ID);
|
|
|
|
return Ok(statuses.ConvertToTModels());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetEmployeeID")]
|
|
|
|
public ActionResult GetEmployeeID(string EmpName)
|
|
{
|
|
try
|
|
{
|
|
Employee oEmp = _employeeService.GetByName(EmpName);
|
|
|
|
if (oEmp == null)
|
|
{
|
|
throw new Exception("Employee does not exists");
|
|
}
|
|
return Ok(oEmp.ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
//[Route("GetEmpLeaveStatus/{id}")]
|
|
[Route("GetLeaveEntries/{id}")]
|
|
|
|
//public ActionResult GetEmpLeaveStatus(int id)
|
|
|
|
public ActionResult GetLeaveEntries(int id)
|
|
{
|
|
try
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
var leaveYear = _leaveYearService.GetCurrentYear((int)currentUser.PayrollTypeID);
|
|
DateTime fromDate = leaveYear.StartDate;
|
|
DateTime toDate = leaveYear.EndDate;
|
|
//DataSet ds = _leaveEntryService.GetRecord(id.ToString(), fromDate, toDate, EnumLeaveStatus.Drafted);
|
|
List<LeaveEntry> leaveEntries = _leaveEntryService.GetLeaveEntries(id, leaveYear.IDInteger);
|
|
|
|
return Ok(leaveEntries);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetGrades")]
|
|
|
|
public ActionResult GetGrades()
|
|
{
|
|
try
|
|
{
|
|
List<Grade> statuses = _gradeService.Get(EnumStatus.Active);
|
|
return Ok(statuses.ConvertToTModels());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("GetEmployees")]
|
|
|
|
public ActionResult GetEmployees(string EmployeeName, string EmployeeNo, int CurrentUserID)
|
|
{
|
|
try
|
|
{
|
|
List<Employee> _employees = _employeeService.GetAllLive();
|
|
Employee currentUser = _employees.Where(x => x.ID == CurrentUserID).FirstOrDefault();
|
|
if (EmployeeName != null)
|
|
_employees = _employees.Where(o => o.Name.ToLower().Contains(EmployeeName.ToLower()) && o.PayrollTypeID == currentUser.PayrollTypeID).ToList();
|
|
|
|
if (EmployeeNo != null)
|
|
{
|
|
_employees = _employees.Where(o => o.EmployeeNo.ToLower() == EmployeeNo.Trim().ToLower() && o.PayrollTypeID == currentUser.PayrollTypeID).ToList();
|
|
}
|
|
return Ok(_employees.ConvertToTModels());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("ValidateLeaveEntry")]
|
|
|
|
public ActionResult ValidateLeaveEntry(LeaveEntryTModel oLvEntryTModel)
|
|
{
|
|
try
|
|
{
|
|
#region validation is inside leaveentry->save
|
|
//Employee oEmp = _employeeService.Get(oLvEntryTModel.EmployeeID);
|
|
//Leave oLeave = _leaveService.Get(oLvEntryTModel.LeaveID);
|
|
//LeaveEntry leaveEntry = _leaveEntryService.RefreshObject(oLvEntryTModel.ResponsibleID, oLvEntryTModel.Address, oLeave, oEmp, oLvEntryTModel.FromDate, oLvEntryTModel.ToDate, oLvEntryTModel.TotalDays, oLvEntryTModel.Reason, string.Empty);
|
|
//leaveEntry.RefreshLeaveAttachment(oLeave, oLvEntryTModel.FileName);
|
|
//leaveEntry.ValidateObject(oEmp, oLeave);
|
|
#endregion
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("SaveLeaveEntry")]
|
|
|
|
public ActionResult SaveLeaveEntry(LeaveEntryTModel oLvEntryTModel)
|
|
{
|
|
try
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
Employee oEmp = _employeeService.Get(oLvEntryTModel.EmployeeID);
|
|
|
|
LeaveEntry leaveEntry = _leaveEntryService.RefreshObject(oLvEntryTModel.ResponsibleID, oLvEntryTModel.Address, oLvEntryTModel.LeaveID, oEmp,
|
|
oLvEntryTModel.FromDate, oLvEntryTModel.ToDate, oLvEntryTModel.TotalDays,
|
|
oLvEntryTModel.Reason, string.Empty, oLvEntryTModel.SelectedHalf, currentUser.UserID,
|
|
0, oLvEntryTModel.IsLFA, oLvEntryTModel.IsHalfDay );
|
|
if (oLvEntryTModel.FileInBytes != null)
|
|
{
|
|
_leaveEntryService.UploadLeaveAttachment(leaveEntry.LeaveID, oLvEntryTModel.FileName, oLvEntryTModel.FileInBytes);
|
|
}
|
|
_leaveEntryService.Save(leaveEntry);
|
|
|
|
return Ok();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
//Leave Ledger
|
|
[HttpGet]
|
|
[Route("GetEmpLeaveLedger/{empId}/{fromDate}/{toDate}")]
|
|
|
|
public ActionResult GetEmpLeaveLedger(int empId, string fromDate, string toDate)
|
|
{
|
|
List<LeaveLedgerMobile> items = new List<LeaveLedgerMobile>();
|
|
DateTime FromDate = DateTime.Parse(fromDate);
|
|
DateTime ToDate = DateTime.Parse(toDate);
|
|
try
|
|
{
|
|
items = _leaveEntryService.GetEmpLeaveLedger(empId, FromDate, ToDate);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(items);
|
|
}
|
|
|
|
|
|
//My Team Upcoming Leave
|
|
[HttpGet]
|
|
[Route("GetMyTeamUpcomingLeave/{empId}/{fromDate}/{toDate}")]
|
|
|
|
public ActionResult GetMyTeamUpcomingLeave(int empId, string fromDate, string toDate)
|
|
{
|
|
List<LeaveLedgerMobile> items = new List<LeaveLedgerMobile>();
|
|
DateTime FromDate = DateTime.Parse(fromDate);
|
|
DateTime ToDate = DateTime.Parse(toDate);
|
|
try
|
|
{
|
|
items = _leaveEntryService.GetMyTeamUpcomingLeave(empId, FromDate, ToDate);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
|
}
|
|
|
|
return Ok(items);
|
|
}
|
|
|
|
//Team Leave
|
|
[HttpGet]
|
|
[Route("getMyTeamByLoginID/{EmployeeID}")]
|
|
|
|
public ActionResult GetMyTeamByLoginID(int EmployeeID)
|
|
{
|
|
List<SearchEmployee> items = null;
|
|
Byte[] bytes = null;
|
|
FileTModel oFTModel = new FileTModel();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
LeaveYear oLeaveYear = new LeaveYearService().GetCurrentYear((int)currentUser.PayrollTypeID);
|
|
Employee oEmployee = new EmployeeService().Get(EmployeeID);
|
|
|
|
|
|
try
|
|
{
|
|
//items = _serachManager.GetTeam((int)currentUser.EmployeeID, EnumStatus.Active);
|
|
items = _searchManager.GetTeam(EmployeeID, EnumStatus.Active);
|
|
|
|
string sEmpIDs = "";
|
|
int count = 0;
|
|
foreach (var x in items)
|
|
{
|
|
if (sEmpIDs != "")
|
|
{
|
|
sEmpIDs += ",";
|
|
}
|
|
sEmpIDs += x.EmployeeID;
|
|
count++;
|
|
}
|
|
|
|
MultipleEmpLeaveBalance multipleEmpLeaveBalance = new MultipleEmpLeaveBalance();
|
|
if (sEmpIDs != "")
|
|
{
|
|
bytes = multipleEmpLeaveBalance.ShowMultipleEmpLeaveBalance(oLeaveYear.ID, oEmployee.PayrollTypeID, sEmpIDs, "EXCEL");
|
|
}
|
|
|
|
if (bytes == null)
|
|
{
|
|
throw new CustomException(EnumExceptionType.Informational, "No Team Leave Balance data found!");
|
|
}
|
|
|
|
oFTModel = new FileTModel()
|
|
{
|
|
FileName = string.Format("Team Leave Balance.xlsx"),
|
|
Type = EnumFileType.Excel,
|
|
Count = count,
|
|
FileInBytes = bytes
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(oFTModel);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("getMyTeamCount")]
|
|
|
|
public ActionResult GetMyTeamCount(int EmpID)
|
|
{
|
|
List<SearchEmployee> items = null;
|
|
int count = 0;
|
|
try
|
|
{
|
|
//items = _serachManager.GetTeam((int)currentUser.EmployeeID, EnumStatus.Active);
|
|
items = _searchManager.GetTeam(EmpID, EnumStatus.Active);
|
|
|
|
count = items.Count();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(count);
|
|
}
|
|
}
|
|
} |