using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Threading.Tasks; using HRM.BO; using HRM.BO.Report; using HRM.DA; using Microsoft.AspNetCore.Authorization; using System.IO; using HRM.BO.Configuration; using iTextSharp.text; using Microsoft.Extensions.Options; using NPOI.POIFS.Storage; using Ease.Core; using static iTextSharp.text.pdf.AcroFields; using HRM.Service; namespace HRM.UI.Controllers.Leave { [Route("api/Leave")] [ApiController] public class LeaveController : ControllerBase { private readonly IEmployeeShortLeaveService _employeeShortLeaveService; private readonly ILeaveService _leaveService; private readonly ILeaveEntryService _leaveEntryService; private readonly ILeaveExceptionService _leaveExceptionService; private readonly ILeaveParameterService _leaveParameterService; private readonly ILeavePlanService _leavePlanService; private readonly ILeaveProcessService _leaveProcessService; private readonly ILeaveYearService _leaveYearService; private readonly IUploadEncashAmountService _uploadEncashAmountService; private readonly IDepartmentService _departmentService; private readonly IDesignationService _designationService; private readonly IWeeklyHolidayService _weeklyHoliday; private readonly IOptions _emailSettings; private readonly ILeaveEncashmentService _leaveEncashmentService; private readonly IEmployeeService _employeeService; private readonly IShortLeaveService _shortLeaveService; private readonly IMaternityLeaveService _maternityLeaveService; public LeaveController(IEmployeeShortLeaveService employeeShortLeaveService, ILeaveService leaveService, ILeaveEntryService leaveEntryService, ILeaveExceptionService leaveExceptionService, ILeaveParameterService leaveParameterService, ILeavePlanService leavePlanService, ILeaveProcessService leaveProcessService, ILeaveYearService leaveYearService, IUploadEncashAmountService uploadEncashAmountService, IDepartmentService departmentService, IDesignationService designationService, IWeeklyHolidayService weeklyHoliday, IOptions emailSettings, ILeaveEncashmentService leaveEncashmentService, IEmployeeService employeeService, IShortLeaveService shortLeaveService, IMaternityLeaveService maternityLeaveService) { this._employeeShortLeaveService = employeeShortLeaveService; this._leaveService = leaveService; this._leaveEntryService = leaveEntryService; this._leaveExceptionService = leaveExceptionService; this._leaveParameterService = leaveParameterService; this._leavePlanService = leavePlanService; this._leaveProcessService = leaveProcessService; this._leaveYearService = leaveYearService; this._uploadEncashAmountService = uploadEncashAmountService; this._departmentService = departmentService; this._designationService = designationService; this._weeklyHoliday = weeklyHoliday; this._emailSettings = emailSettings; _leaveEncashmentService = leaveEncashmentService; _employeeService = employeeService; this._shortLeaveService = shortLeaveService; this._maternityLeaveService = maternityLeaveService; } // EmployeeShortLeave [HttpGet("getWeeklyHoliday")] public ActionResult getWeeklyHoliday() { List item = new List(); try { item = _weeklyHoliday.Get(EnumStatus.Regardless); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getWeeklyHolidayByID/{ID}")] public ActionResult getWeeklyHolidayByID(int id) { WeeklyHoliday item = new WeeklyHoliday(); try { item = _weeklyHoliday.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getWeeklyHolidayByLocation/{ID}")] public ActionResult getWeeklyHolidayByLocation(int locationID) { List item = new List(); try { item = _weeklyHoliday.GetByLocation(locationID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost("SaveWeeklyHoliday")] public ActionResult SaveWeeklyHoliday(List holidays) { try { _weeklyHoliday.Save(holidays); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(true); } [HttpPost("DeleteWeeklyHoliday")] public ActionResult DeleteWeeklyHoliday(WeeklyHoliday item) { try { _weeklyHoliday.Delete(item.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(true); } [HttpGet("getEmployeeShortLeave")] public ActionResult GetEmployeeShortLeave() { EmployeeShortLeave item = new EmployeeShortLeave(); try { item = _employeeShortLeaveService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getEmployeeShortLeaveById/{id}")] public ActionResult GetEmployeeShortLeaveById(int id) { EmployeeShortLeave item = new EmployeeShortLeave(); try { item = _employeeShortLeaveService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getEmployeeShortLeaveByType/{type}")] public ActionResult GetEmployeeShortLeaveByType(int type) { EmployeeShortLeave item = new EmployeeShortLeave(); try { item = _employeeShortLeaveService.GetByType(type); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getEmployeeShortLeaveByEmpId/{employeeId}")] public ActionResult GetEmployeeShortLeaveByEmpId(int employeeId) { EmployeeShortLeave item = new EmployeeShortLeave(); try { item = _employeeShortLeaveService.GetByEmpID(employeeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getEmployeeShortLeaveByEmp/{employeeId}")] public ActionResult GetEmployeeShortLeaveByEmp(int employeeId) { List items = new List(); try { items = _employeeShortLeaveService.GetByEmp(employeeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost] [Route("saveEmployeeShortLeave")] public ActionResult SaveEmployeeShortLeave(EmployeeShortLeave item) { try { _employeeShortLeaveService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteEmployeeShortLeave")] public ActionResult DeleteEmployeeShortLeave(int id) { try { _employeeShortLeaveService.Delete(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // Leave [HttpGet("getLeaveById/{id}")] public ActionResult GetLeaveById(int id) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); BO.Leave item = new BO.Leave(); try { item = _leaveService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } //[HttpGet("getLeaveIdByName/{leave}")] //public ActionResult GetLeaveIdByName(string leave) //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); // BO.Leave item = new BO.Leave(); // try // { // item = _leaveService.GetIDByName(leave, payrollTypeId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(item); //} //[HttpGet("getLeaveIdByCode/{leave}")] //public ActionResult GetLeaveIdByCode(string leave) //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); // BO.Leave item = new BO.Leave(); // try // { // item = _leaveService.GetIDByCode(leave, payrollTypeId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(item); //} //[HttpGet("getLeaveListByInParamId/{inParamId}")] //public ActionResult GetLeaveListByInParamId(string inParamId) //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); // List item = new List(); // try // { // item = _leaveService.Get(inParamId, payrollTypeId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(item); //} [HttpGet("getAllLeave/{status}/{code}/{name}")] public ActionResult getAllLeave(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); List item = new List(); try { item = _leaveService.Get(status, code, name, payrollTypeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getEmpApplicableLeave/{employeeid}")] public ActionResult getEmpApplicableLeave(int employeeid) { List item = new List(); try { item = _leaveService.getEmpApplicableLeave(employeeid); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } //[HttpGet("getLeaves")] //public ActionResult GetLeaves() //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); // List item = new List(); // try // { // item = _leaveService.Get(EnumStatus.Regardless, payrollTypeId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(item); //} //[HttpGet("getStringValue")] //public ActionResult GetStringValue(DateTime fromDate, DateTime toDate) //{ // string ans; // try // { // ans = _leaveService.Get(fromDate, toDate); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(ans); //} [HttpPost] [Route("saveLeave")] public ActionResult SaveLeave(BO.Leave item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); if (item.IsNew) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.PayrollTypeID = payrollTypeId; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } _leaveService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteLeave")] public ActionResult DeleteLeave(BO.Leave item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { _leaveService.Delete(item.ID, payrollTypeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // LeaveEntry [HttpGet("getAllLeaveEntry")] public ActionResult GetAllLeaveEntry() { List items = new List(); try { items = _leaveEntryService.GetAll(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getLeaveEntry/{id}")] public ActionResult getLeaveEntry(int id) { LeaveEntry item = new LeaveEntry(); try { item = _leaveEntryService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("isLeaveEntryEntered/{year}")] public ActionResult IsLeaveEntryEntered(DateTime year) { bool ans; try { ans = _leaveEntryService.IsEntered(year); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } //[HttpGet("getEmployeeWiseLeaveDetailReport/{empId}/{fromDate}/{toDate}/{leaveType}")] //public ActionResult GetEmployeeWiseLeaveDetailReport(int empId, DateTime fromDate, DateTime toDate, int leaveType) //{ // List items = new List(); // try // { // items = _leaveEntryService.GetEmployeeWiseLeaveDetailReport(empId, fromDate, toDate, leaveType); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getByLeaveYear/{leaveType}")] //public ActionResult GetByLeaveYear(int leaveType) //{ // List items = new List(); // try // { // items = _leaveEntryService.GetByLeaveYear(leaveType); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} // getLeaveEntries(empId?: number, empids?: string, leaveID?: number, fromDate?: Date, //toDate?: Date, leavestatus?: EnumLeaveStatus, isLFA?: boolean) [HttpGet("getLeaveEntries/{empids}/{empId}/{leaveYearid}/{leaveID}/{fromDate}/{toDate}/{leavestatus}/{isLFA}")] public ActionResult GetLeaveEntryByEmpId(string EmpIds, string empId, string leaveYearid, string leaveid, string fromDate, string toDate, string leaveStatus, string isLfa) { string cEmpIds = GlobalFunctions.GetApiDefaultData(EmpIds); var cempId = GlobalFunctions.GetApiDefaultIntData(empId); var cleaveYearid = GlobalFunctions.GetApiDefaultIntData(leaveYearid); var cleaveid = GlobalFunctions.GetApiDefaultIntData(leaveid); var cfromDate = GlobalFunctions.GetApiDefaultDateData(fromDate); var ctoDate = GlobalFunctions.GetApiDefaultDateData(toDate); EnumLeaveStatus? cleaveStatus = null; if (leaveStatus.ToLower() != "undefined" && leaveStatus.ToLower() != "null" && leaveStatus.ToLower() != string.Empty) { cleaveStatus = (EnumLeaveStatus)GlobalFunctions.GetApiDefaultIntData(leaveStatus); } List items = new List(); try { items = _leaveEntryService.Get(cEmpIds, cempId, cleaveYearid, cleaveid, cfromDate, ctoDate, cleaveStatus, false); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } //[HttpGet("getLeaveEntryByDateRange/{fromDate}/{toDate}/{leaveStatus}")] //public ActionResult GetLeaveEntryByDateRange(DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus) //{ // List items = new List(); // try // { // items = _leaveEntryService.Get(fromDate, toDate, leaveStatus); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getLeaveEntryByAttnDate/{attnDate}")] //public ActionResult GetLeaveEntryByAttnDate(DateTime attnDate) //{ // List items = new List(); // try // { // items = _leaveEntryService.Get(attnDate); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getLeaveEntryByEmpIdAndDateRange/{empId}/{fromDate}/{toDate}/{leaveStatus}")] //public ActionResult GetLeaveEntryByEmpIdAndDateRange(string empId, DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus) //{ // List items = new List(); // try // { // items = _leaveEntryService.Get(empId, fromDate, toDate, leaveStatus); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getLeaveEntryPending/{empId}/{leaveId}/{status}")] //public ActionResult GetLeaveEntryPending(int empId, int leaveId, EnumLeaveStatus leaveStatus) //{ // List items = new List(); // try // { // items = _leaveEntryService.GetPending(empId, leaveId, leaveStatus); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getLeaveEntryByEmpIdAndLeaveYearId/{empId}/{leaveYearId}")] //public ActionResult GetLeaveEntryByEmpIdAndLeaveYearId(int empId, int leaveYearId) //{ // List items = new List(); // try // { // items = _leaveEntryService.Get(empId, leaveYearId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getByLeaveID/{leaveId}/{empId}/{fromDate}/{toDate}")] //public ActionResult GetByLeaveID(int leaveId, int empId, DateTime fromDate, DateTime toDate) //{ // List items = new List(); // try // { // items = _leaveEntryService.GetByLeaveID(leaveId, empId, fromDate, toDate); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} [HttpGet("getEmployeeLeaveBalance/{empId}/{leaveYear}/{leaveType}")] public ActionResult GetEmployeeLeaveBalance(int empId, int leaveYear, int leaveType) { int ans; try { ans = _leaveEntryService.GetEmployeeLeaveBalance(empId, leaveYear, leaveType); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } //[HttpGet("getLeaveEntryByLeaveStatus/{empId}/{fromDate}/{toDate}/{leaveStatus}")] //public ActionResult GetLeaveEntryByLeaveStatus(string empId, DateTime fromDate, DateTime toDate, string leaveStatus) //{ // List items = new List(); // try // { // items = _leaveEntryService.Get(empId, fromDate, toDate, leaveStatus); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getLeaveEntryByLeaveStatusAndSortExpresion/{empId}/{fromDate}/{toDate}/{leaveStatus}/{sortExpresion}")] //public ActionResult GetLeaveEntryByLeaveStatusAndSortExpresion(string empId, DateTime fromDate, DateTime toDate, EnumLeaveStatus leaveStatus, string sortExpresion) //{ // List items = new List(); // try // { // items = _leaveEntryService.Get(empId, fromDate, toDate, leaveStatus, sortExpresion); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} //[HttpGet("getForAdminPanel/{empId}")] //public ActionResult GetForAdminPanel(int empId) //{ // List items = new List(); // try // { // items = _leaveEntryService.GetForAdminPanel(empId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} [HttpGet("getLeaveAmtByType/{empId}/{leaveId}/{leaveYear}/{leaveStatus}")] public ActionResult GetLeaveAmtByType(int empId, int leaveId, int leaveYear, EnumLeaveStatus leaveStatus) { double ans; try { ans = _leaveEntryService.GetLeaveAmtByType(empId, leaveId, leaveYear, leaveStatus); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpGet("getAvailedLeave/{empId}/{leaveId}/{leaveYear}/{leaveStatus}")] public ActionResult GetAvailedLeave(int empId, int leaveId, int leaveYear, EnumLeaveStatus leaveStatus) { double ans; try { ans = _leaveEntryService.GetAvailedLeave(empId, leaveId, leaveYear, leaveStatus); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpGet("getSumOfAvailedLeaveByEmpId/{empId}/{leaveYear}")] public ActionResult GetSumOfAvailedLeaveByEmpId(int empId, int leaveYear) { List items = new List(); try { items = _leaveEntryService.GetSumOfAvailedLeave(empId, leaveYear); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getLeaveEntriesByEmpId/{empId}/{leaveYearId}")] public ActionResult GetLeaveEntriesByEmpId(int empId, int leaveYearId) { List items = new List(); try { items = _leaveEntryService.GetLeaveEntries(empId, leaveYearId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // string empIds, int leaveYearId, EnumLeaveStatus leaveStatus [HttpPost("getLeaveEntriesByEmpIds")] public ActionResult GetLeaveEntriesByEmpIds(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string empIds = (string)item["empIds"].ToObject(); int leaveYearId = item["leaveYearId"].ToObject(); var leaveStatus = (EnumLeaveStatus)item["leaveStatus"].ToObject(); List items = new List(); try { items = _leaveEntryService.Get(empIds, leaveYearId, leaveStatus); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getSumOfAvailedLeave/{leaveYear}")] public ActionResult GetSumOfAvailedLeave(int leaveYear) { List items = new List(); try { items = _leaveEntryService.GetSumOfAvailedLeave(leaveYear); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getAmountOnFromDate/{empId}/{leaveYearId}/{leaveId}/{leaveStatus}/{startDate}/{endDate}")] public ActionResult GetAmountOnFromDate(int empId, int leaveYearId, int leaveID, EnumLeaveStatus leaveStatus, DateTime startDate, DateTime endDate) { double ans; try { ans = _leaveEntryService.GetAmountOnFromDate(empId, leaveYearId, leaveID, leaveStatus, startDate, endDate); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpGet("getTotalLeaveAmountInYear/{empId}/{leaveYearId}/{leaveId}/{leaveStatus}")] public ActionResult GetTotalLeaveAmountInYear(int empId, int leaveYearId, int leaveID, EnumLeaveStatus leaveStatus) { double ans; try { ans = _leaveEntryService.GetTotalLeaveAmountInYear(empId, leaveYearId, leaveID, leaveStatus); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpGet("getLFAOnMonth/{month}")] public ActionResult GetLFAOnMonth(DateTime month) { List items = new List(); try { items = _leaveEntryService.GetLFAOnMonth(month); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost] [Route("saveLeaveEntry")] public ActionResult SaveLeaveEntry(LeaveEntry item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.IsNew == false) { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } else { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.EntryDate = DateTime.Today; item.IsDrafted = 1; item.IsAvailed = 1; } int leaveentryid = 0; try { leaveentryid = _leaveEntryService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(leaveentryid); } [HttpPost] [Route("leaveApprove")] public ActionResult leaveApprove(WFMovementTran item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item.FromEmployeeID = (int)currentUser.EmployeeID; _leaveEntryService.LeaveApplicationApprove(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("leaveReject")] public ActionResult LeaveReject(WFMovementTran item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item.FromEmployeeID = (int)currentUser.EmployeeID; _leaveEntryService.LeaveApplicationReject(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("LeaveRevert")] public ActionResult LeaveRevert(WFMovementTran item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item.FromEmployeeID = (int)currentUser.EmployeeID; _leaveEntryService.LeaveApplicationRevert(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveLeaveEntryList")] public ActionResult SaveLeaveEntry(List items) { try { _leaveEntryService.SaveLeaveEntry(items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteLeaveEntryById")] public ActionResult DeleteLeaveEntryById(LeaveEntry entry) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _leaveEntryService.Delete(entry.ID, (int) currentUser.UserID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteLeaveEntry")] public ActionResult DeleteLeaveEntry(LeaveEntry item) { try { _leaveEntryService.Delete(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteByLeaveYear")] public ActionResult DeleteByLeaveYear(int leaveYear) { int leaveId = 1; try { _leaveEntryService.DeleteByLeaveYear(leaveYear, leaveId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("isLeaveEntryExist/{employee}/{fromDate}/{toDate}")] public ActionResult IsLeaveEntryExist(Employee employee, DateTime fromDate, DateTime toDate) { bool ans; try { ans = _leaveEntryService.IsExist(employee, fromDate, toDate); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpPost("uploadLeaveAttachment")] [AllowAnonymous] public ActionResult UploadLeaveAttachment() { LeaveAttachment item = new LeaveAttachment(); string base64String = ""; try { var fdata = Request.Form.Files["filedata"]; item.OriginalFileName = Request.Form["originalfilename"].ToString(); item.LeaveEntryID = Convert.ToInt32(Request.Form["leaveentryid"]); item.FileType = (EnumFileType)Convert.ToInt32(Request.Form["filetype"]); using (var ms = new MemoryStream()) { fdata.CopyTo(ms); item.FileAsByteArray = ms.ToArray(); byte[] textAsBytes = ms.ToArray(); new LeaveEntryService().UplaodFileInProfileUpdate(item); base64String = Convert.ToBase64String(textAsBytes); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(base64String); } [HttpGet("getLeaveAttachments/{leaveEntryId}")] public ActionResult GetEmployeeAttachments(int leaveEntryId) { List items = new List(); try { items = new LeaveEntryService().GetAllAttachmentsById(leaveEntryId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getAttachments/{leaveEntryId}")] public ActionResult GetAttachments(int leaveEntryId) { List items = new List(); try { items = _leaveEntryService.GetAttachments(leaveEntryId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // LeaveException [HttpGet("getLeaveException")] public ActionResult GetLeaveException() { List items = new List(); try { items = _leaveExceptionService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getLeaveExceptionByDateRange/{from}/{to}")] public ActionResult GetLeaveExceptionByDateRange(DateTime from, DateTime to) { List items = new List(); try { items = _leaveExceptionService.Get(from, to); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getLeaveExceptionByLeaveId/{leaveId}/{empId}")] public ActionResult GetLeaveExceptionByLeaveId(int leaveId, int empId) { List items = new List(); try { items = _leaveExceptionService.GetByEmpID(leaveId, empId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost] [Route("saveLeaveException")] public ActionResult SaveLeaveException(LeaveException item) { try { _leaveExceptionService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteLeaveExceptionByEmpId")] public ActionResult DeleteLeaveExceptionByEmpId(LeaveException item) { try { _leaveExceptionService.DeleteByEmpID(item.EmployeeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteLeaveExceptionById")] public ActionResult DeleteLeaveExceptionById(int id) { try { _leaveExceptionService.DeleteItem(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // LeaveParameter [HttpGet("getLeaveParameterById/{leaveParameterId}")] public ActionResult GetLeaveParameterById(int leaveParameterId) { LeaveParameter item = new LeaveParameter(); try { item = _leaveParameterService.Get(leaveParameterId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("GetUsedParamItem/{leaveParameterId}")] public ActionResult GetUsedParamItem(int leaveParameterId) { List item = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { item = _leaveParameterService.GetUsedParam(leaveParameterId, (int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } // double CalculatedLeaveDays(int leaveid, int itemid, EnumLeaveparamOn paramType, int payrollTypeid, //DateTime FromDate, DateTime ToDate, int ddlFromValue, int ddlToValue); [HttpGet( "CalculatedLeaveDays/{leaveid}/{itemID}/{locationID}/{paramType}/{fromDate}/{Todate}/{firstHalf}/{secondHalf}/{isHalfday}/{empId}")] public ActionResult CalculatedLeaveDays(int leaveid, int itemID, int locationID, EnumLeaveparamOn paramType, DateTime fromDate, DateTime Todate, bool firstHalf, bool secondHalf, bool isHalfday, int empId) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); double days = 0; try { days = _leaveEntryService.CalculatedLeaveDays(leaveid, itemID, locationID, paramType, (int)currentUser.PayrollTypeID, fromDate, Todate, firstHalf, secondHalf, isHalfday, empId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(days); } [HttpGet("getLeaveParameter/{status}/{leaveID}")] public ActionResult GetLeaveParameter(EnumStatus status, string leaveid) { int? lvid = GlobalFunctions.GetApiDefaultIntData(leaveid); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); List item = new List(); try { item = _leaveParameterService.Get(status, (int)payrollTypeId, lvid); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } //[HttpGet("getLeaveParameterListByLeaveID/{leaveId}")] //public ActionResult getLeaveParameterListByLeaveID(int leaveId) //{ // List item = new List(); // try // { // item = _leaveParameterService.GetbyLeaveID(leaveId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(item); //} [HttpGet("getLeaveParameterDetails/{leaveParamId}")] public ActionResult GetLeaveParameterDetails(int leaveParamId) { List items = new List(); try { items = _leaveParameterService.GetDetails(leaveParamId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getLeaveParameterDetailsByParamId/{paramId}")] public ActionResult GetLeaveParameterDetailsByParamId(int paramId) { LeaveParameterDetail item = new LeaveParameterDetail(); try { item = _leaveParameterService.GetDetail(paramId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } //[HttpGet("getLeaveParameterByLeaveID/{paramId}")] //public ActionResult GetLeaveParameterByLeaveID(int paramId) //{ // LeaveParameter item = new LeaveParameter(); // try // { // item = _leaveParameterService.GetByLeaveID(paramId); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(item); //} //[HttpGet("getAllLeaveParameterDetails")] //public ActionResult GetAllLeaveParameterDetails() //{ // List items = new List(); // try // { // items = _leaveParameterService.GetDetails(); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} [HttpPost] [Route("deleteLeaveParameter")] public ActionResult DeleteLeaveParameter(int leaveParamId) { try { _leaveParameterService.Delete(leaveParamId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveLeaveParameter")] public ActionResult SaveLeaveParameter(LeaveParameter item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.IsNew == false) { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } else { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.PayrollTypeID = (int)currentUser.PayrollTypeID; } _leaveParameterService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // LeavePlan [HttpGet("getLeavePlanByEmpId/{empId}")] public ActionResult GetLeavePlanByEmpId(int empId) { List items = new List(); try { items = _leavePlanService.Get(empId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getPlanData/{empId}/{leaveYear}")] public ActionResult GetPlanData(int empId, int leaveYear) { List items = new List(); try { items = _leavePlanService.GetPlanData(empId, leaveYear); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getAllPlanData")] public ActionResult GetAllPlanData() { List items = new List(); try { items = _leavePlanService.GetAllData(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getPlanId/{id}")] public ActionResult GetPlanId(int id) { LeavePlan item = new LeavePlan(); try { item = _leavePlanService.GetID(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getPlanByMonthRange/{empId}/{fromDate}/{toDate}")] public ActionResult GetPlanByMonthRange(int empId, DateTime fromDate, DateTime toDate) { List items = new List(); try { items = _leavePlanService.GetByMonthRange(empId, fromDate, toDate); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("isEmpIDExist")] public ActionResult IsEmpIDExist(int empId, int leaveYear) { bool ans; try { ans = _leavePlanService.IsEmpIDExist(empId, leaveYear); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpGet("isEmpApproved")] public ActionResult IsEmpApproved(int empId, int leaveYear, DateTime fromDate, DateTime toDate, bool isApproved) { bool ans; try { ans = _leavePlanService.IsEmpApproved(empId, leaveYear, fromDate, toDate, isApproved); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpPost] [Route("saveLeavePlan")] public ActionResult SaveLeavePlan(List items) { try { _leavePlanService.Save(items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteLeavePlan")] public ActionResult DeleteLeavePlan(int id) { try { _leavePlanService.Delete(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("updateApproveLeavePlan")] public ActionResult UpdateApproveLeavePlan(int empId) { int leaveYear = 1; DateTime formDate = new DateTime(); DateTime toDate = new DateTime(); bool isApproved = true; try { _leavePlanService.UpdateApprove(empId, leaveYear, formDate, toDate, isApproved); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("upDateLeavePlan")] public ActionResult UpDateLeavePlan(LeavePlan item) { int planID = 1; try { _leavePlanService.UpDateLeavePlan(item, planID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("updateLeavePlanSubmit")] public ActionResult UpdateLeavePlanSubmit(List items) { int planID = 1; try { _leavePlanService.UpdateLeavePlanSubmit(items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // LeaveProcess [HttpGet("getLeaveProcessById/{leaveProcessId}")] public ActionResult GetLeaveProcessById(int leaveProcessId) { LeaveProcess item = new LeaveProcess(); try { item = _leaveProcessService.Get(leaveProcessId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } // List GetLeaveBalance(int leaveYearID, int payrollTypeID, string EmpIDsIn, int? empID = null); [HttpGet("GetEmpLeaveStatus/{leaveYearID}/{empids}")] public ActionResult GetEmpLeaveStatus(int leaveYearID, string empids) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); empids = GlobalFunctions.GetApiDefaultData(empids); List item = new List(); try { item = _leaveProcessService.GetByEmpIDs(empids, leaveYearID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost("saveEmpLeaveStatus")] public ActionResult saveEmpLeaveStatus(List leaveStatus) { try { _leaveProcessService.SaveStatus(leaveStatus); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(true); } [HttpGet("GetLeaveBalance/{leaveYearID}/{EmpIDsIn}/{EmpId}")] public ActionResult GetLeaveBalance(int leaveYearID, string EmpIDsIn, string empID) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int? nempid = GlobalFunctions.GetApiDefaultIntData(empID); EmpIDsIn = GlobalFunctions.GetApiDefaultData(EmpIDsIn); List item = new List(); try { item = _leaveProcessService.GetLeaveBalance(leaveYearID, (int)currentUser.PayrollTypeID, EmpIDsIn, nempid); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getLeaveBalanceInDataSet/{leaveYearID}/{EmpIDsIn}/{EmpId}")] public ActionResult GetLeaveBalanceInDataSet(int leaveYearID, string EmpIDsIn, string empID) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int? nempid = GlobalFunctions.GetApiDefaultIntData(empID); EmpIDsIn = GlobalFunctions.GetApiDefaultData(EmpIDsIn); List item = new List(); DataTable dataTable = new DataTable(); try { item = _leaveProcessService.GetLeaveBalance(leaveYearID, (int)currentUser.PayrollTypeID, EmpIDsIn, nempid); dataTable.Columns.Add("AnnualLeave"); dataTable.Columns.Add("alOpening"); item.ForEach(x => { dataTable.Columns.Add(x.LeaveNameView); dataTable.Columns.Add(x.LeaveNameView + "Opening"); dataTable.Columns.Add(x.LeaveNameView + "Balance"); dataTable.Columns.Add(x.LeaveNameView + "Closing"); }); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getLeaveProcessByLeaveProcessYear/{leaveProcessYear}")] public ActionResult GetLeaveProcessByLeaveProcessYear(int leaveProcessYear) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); LeaveProcess item = new LeaveProcess(); try { item = _leaveProcessService.Get(leaveProcessYear, payrollTypeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getAllLeaveProcess")] public ActionResult GetAllLeaveProcess() { List items = new List(); try { items = _leaveProcessService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getLastProcess")] public ActionResult GetLastProcess() { LeaveProcess item = new LeaveProcess(); try { item = _leaveProcessService.GetLastProcess(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("isProcessed/{processYear}")] public ActionResult IsProcessed(int processYear) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); bool ans; try { ans = _leaveProcessService.IsProcessed(processYear, (int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpPost] [Route("DoYearEnd")] public ActionResult DoYearEnd(LeaveProcess item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.LeaveYear == null) item.LeaveYear = new LeaveYearService().Get(item.LeaveYearID); item.CreatedDate = DateTime.Today; item.CreatedBy = (int)currentUser.UserID; item.PayrollTypeID = (int)currentUser.PayrollTypeID; item.ProcessDate = DateTime.Today; item.ProcessYearDescription = ""; try { _leaveProcessService.DoYearEnd(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(true); } [HttpPost] [Route("UnDoYearEnd")] public ActionResult UnDoYearEnd(LeaveProcess item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.LeaveYear == null) item.LeaveYear = new LeaveYearService().Get(item.LeaveYearID); item.CreatedDate = DateTime.Today; item.CreatedBy = (int)currentUser.UserID; item.PayrollTypeID = (int)currentUser.PayrollTypeID; try { _leaveProcessService.UnDoYearEnd(item.LeaveYearID, item.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(true); } [HttpPost] [Route("updateLeaveYearStatus")] public ActionResult UpdateLeaveYearStatus(LeaveProcess item) { try { _leaveProcessService.UpadteLeaveYearStatus(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getLeaveDetails/{empId}")] public ActionResult GetLeaveDetails(int empId) { LeaveDetails item = new LeaveDetails(); try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item = new LeaveDetails(); item.LeaveYear = _leaveYearService.GetCurrentYear((int)currentUser.PayrollTypeID); item.Empleavestatus = _leaveProcessService.GetLeaveBalance(item.LeaveYear.ID, (int)currentUser.PayrollTypeID, string.Empty, empId); item.LeaveHistory = _leaveProcessService.GetRecord(empId.ToString(), item.LeaveYear.StartDate, item.LeaveYear.EndDate, EnumLeaveStatus.Drafted); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } // LeaveYear [HttpGet("getLeaveYear/{id}")] public ActionResult GetLeaveYear(int id) { LeaveYear item = new LeaveYear(); try { item = _leaveYearService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getCurrentYearByYear/{year}")] public ActionResult GetCurrentYearByYear(string year) { LeaveYear item = new LeaveYear(); try { item = _leaveYearService.GetCurrentYear(year); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getAllLeaveYear")] public ActionResult GetAllLeaveYear() { List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _leaveYearService.GetByPayrollTypeId((int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getLeaveYearListByStatus")] public ActionResult GetLeaveYearListByStatus(EnumStatus status) { List items = new List(); try { items = _leaveYearService.Get(status); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getCurrentYear")] public ActionResult GetCurrentYear() { LeaveYear item = new LeaveYear(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { item = _leaveYearService.GetCurrentYear((int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getLastLeaveYear")] public ActionResult getLastLeaveYear() { LeaveYear item = new LeaveYear(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { item = _leaveYearService.GetLastYear((int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("countCurrentYear")] public ActionResult CountCurrentYear() { int ans; try { ans = _leaveYearService.CountCurrentYear(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpGet("getIDByName/{leaveYear}")] public ActionResult GetIDByName(string leaveYear) { LeaveYear item = new LeaveYear(); try { item = _leaveYearService.GetIDByName(leaveYear); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost] [Route("saveLeaveYear")] public ActionResult SaveLeaveYear(LeaveYear item) { try { _leaveYearService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteLeaveYearById")] public ActionResult DeleteLeaveYearById(int id) { try { _leaveYearService.Delete(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // UploadEncashAmount [HttpGet("getAllUploadEncashAmount")] public ActionResult GetAllUploadEncashAmount() { List items = new List(); try { items = _uploadEncashAmountService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getUploadEncashAmountByEmpId/{empId}")] public ActionResult GetUploadEncashAmountByEmpId(int empId) { List items = new List(); try { items = _uploadEncashAmountService.Get(empId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost] [Route("saveUploadEncashAmount")] public ActionResult SaveUploadEncashAmount(List items) { try { _uploadEncashAmountService.Save(items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteUploadEncashAmount")] public ActionResult DeleteUploadEncashAmount(int id) { try { _uploadEncashAmountService.Delete(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getEmpLeaveStatusByEmpIds/{empIds}/{leaveYearId}")] public ActionResult GetEmpLeaveStatusByEmpIds(string empIds, int leaveYearId) { List items = new List(); try { items = _leaveProcessService.GetByEmpIDs(empIds, leaveYearId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost("getMonthWiseLeaveRegister")] public ActionResult GetMonthWiseLeaveRegister(dynamic data) { var datas = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string empIds = (string)datas["empIds"].ToObject(); int leaveYearId = datas["leaveYearId"].ToObject(); int leaveId = datas["leaveId"].ToObject(); EnumLeaveStatus leaveStatus = (EnumLeaveStatus)Enum.Parse(typeof(EnumLeaveStatus), datas["status"].ToObject(), true); string leaveFromMonth = (string)datas["leaveFromMonth"].ToObject(); string leaveToMonth = (string)datas["leaveToMonth"].ToObject(); List items = new List(); try { DateTime dateFromTime = Convert.ToDateTime(leaveFromMonth); DateTime dateToTime = Convert.ToDateTime(leaveToMonth); items = _leaveProcessService.GetMonthWiseLeaveRegister(empIds, leaveYearId, leaveId, leaveStatus, dateFromTime, dateToTime); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } //[HttpPost("getMultipleEmployeeLeaveBalance")] //public ActionResult GetMultipleEmployeeLeaveBalance(List emps) //{ // List items = new List(); // List employeeLeaveBalances = new List(); // DataTable mulLeaveBalance = new DataTable(); // DataSet dSet = new DataSet(); // try // { // EmployeeService empService = new EmployeeService(); // LeaveYearService leaveYearService = new LeaveYearService(); // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // int payrollTypeID = currentUser.PayrollTypeID.GetValueOrDefault(); // DataRow dr = null; // string sDatecheck = string.Empty; // LeaveYear lyy = new LeaveYear(); // lyy = _leaveYearService.Get(emps[0].DepartmentID); // List oleaves = _leaveService.Get(EnumStatus.Regardless, payrollTypeID); // LeaveYear cly = leaveYearService.GetCurrentYear((int)currentUser.PayrollTypeID); // List obalance = new List(); // if (cly == lyy) // { // obalance = _leaveProcessService.GetLeaveBalance(cly.ID, payrollTypeID, // SearchEmployee.getEmpID(emps)); // } // else // { // obalance = _leaveProcessService.GetByEmpIDs(SearchEmployee.getEmpID(emps), lyy.ID); // } // string empID = string.Empty; // mulLeaveBalance.Columns.Add("EmpNo"); // mulLeaveBalance.Columns.Add("Name"); // List newLeaves = new List(); // foreach (HRM.BO.Leave ol in oleaves) // { // if (obalance.Any(x => x.LeaveId == ol.ID) == true) // { // if (newLeaves.Any(x => x.ID == ol.ID) == false) // newLeaves.Add(ol); // } // } // oleaves = newLeaves; // foreach (HRM.BO.Leave ol in oleaves) // { // //mulLeaveBalance.Columns.Add(ol.Code + "_Op"); // //mulLeaveBalance.Columns.Add(ol.Code + "_Av"); // //mulLeaveBalance.Columns.Add(ol.Code + "_Cls"); // mulLeaveBalance.Columns.Add(ol.Code + "_Opening"); // mulLeaveBalance.Columns.Add(ol.Code + "_Availed"); // mulLeaveBalance.Columns.Add(ol.Code + "_Closing"); // } // var results = from p in obalance // group p by p.EmpId // into g // select g; // foreach (var eItem in results) // { // List leaveStatus = obalance.FindAll(x => x.EmpId == eItem.Key); // dr = mulLeaveBalance.NewRow(); // SearchEmployee oemp = // emps.Find(delegate (SearchEmployee oem) { return oem.EmployeeID == eItem.Key; }); // if (oemp == null) continue; // dr["EmpNo"] = oemp.EmployeeNo; // dr["Name"] = oemp.Name; // foreach (EmpLeaveStatus olevestatus in leaveStatus) // { // HRM.BO.Leave oleave = oleaves.FirstOrDefault(x => x.ID == olevestatus.LeaveId); // dr[oleave.Code + "_Opening"] = olevestatus.OpeningBalance; // dr[oleave.Code + "_Availed"] = olevestatus.LeaveAvailed; // dr[oleave.Code + "_Closing"] = olevestatus.ClosingBalance; // } // mulLeaveBalance.Rows.Add(dr); // } // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(mulLeaveBalance); //} [HttpPost("getMultipleEmployeeLeaveBalance/{leaveyearid}")] public ActionResult GetMultipleEmployeeLeaveBalance(int leaveyearid, List emps) { List items = new List(); List employeeLeaveBalances = new List(); DataTable mulLeaveBalance = new DataTable(); DataSet dSet = new DataSet(); try { EmployeeService empService = new EmployeeService(); LeaveYearService leaveYearService = new LeaveYearService(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeID = currentUser.PayrollTypeID.GetValueOrDefault(); DataRow dr = null; string sDatecheck = string.Empty; LeaveYear lyy = new LeaveYear(); lyy = _leaveYearService.Get(leaveyearid); List oleaves = _leaveService.Get(EnumStatus.Regardless, payrollTypeID); LeaveYear cly = leaveYearService.GetCurrentYear((int)currentUser.PayrollTypeID); List obalance = new List(); if (cly == lyy) { obalance = _leaveProcessService.GetLeaveBalance(cly.ID, payrollTypeID, SearchEmployee.getEmpID(emps)); } else { obalance = _leaveProcessService.GetByEmpIDs(SearchEmployee.getEmpID(emps), lyy.ID); } string empID = string.Empty; mulLeaveBalance.Columns.Add("EmpNo"); mulLeaveBalance.Columns.Add("Name"); List newLeaves = new List(); foreach (HRM.BO.Leave ol in oleaves) { if (obalance.Any(x => x.LeaveId == ol.ID) == true) { if (newLeaves.Any(x => x.ID == ol.ID) == false) newLeaves.Add(ol); } } oleaves = newLeaves; foreach (HRM.BO.Leave ol in oleaves) { //mulLeaveBalance.Columns.Add(ol.Code + "_Op"); //mulLeaveBalance.Columns.Add(ol.Code + "_Av"); //mulLeaveBalance.Columns.Add(ol.Code + "_Cls"); mulLeaveBalance.Columns.Add(ol.Code + "_Opening"); mulLeaveBalance.Columns.Add(ol.Code + "_Availed"); mulLeaveBalance.Columns.Add(ol.Code + "_Closing"); } var results = from p in obalance group p by p.EmpId into g select g; foreach (var eItem in results) { List leaveStatus = obalance.FindAll(x => x.EmpId == eItem.Key); dr = mulLeaveBalance.NewRow(); SearchEmployee oemp = emps.Find(delegate (SearchEmployee oem) { return oem.EmployeeID == eItem.Key; }); if (oemp == null) continue; dr["EmpNo"] = oemp.EmployeeNo; dr["Name"] = oemp.Name; foreach (EmpLeaveStatus olevestatus in leaveStatus) { HRM.BO.Leave oleave = oleaves.FirstOrDefault(x => x.ID == olevestatus.LeaveId); dr[oleave.Code + "_Opening"] = olevestatus.OpeningBalance; dr[oleave.Code + "_Availed"] = olevestatus.LeaveAvailed; dr[oleave.Code + "_Closing"] = olevestatus.ClosingBalance; } mulLeaveBalance.Rows.Add(dr); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(mulLeaveBalance); } [HttpGet("GetMyTeamLeave/{frommonth}/{tomonth}")] public ActionResult GetMyTeamLeave(string frommonth, string tomonth) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DataTable olist = null; DateTime ddate = Convert.ToDateTime(frommonth); DateTime dtomonth = Convert.ToDateTime(tomonth); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { olist = _leaveEntryService.GetMyTeamLeave((int)currentUser.EmployeeID , GlobalFunctions.FirstDateOfMonth(ddate), GlobalFunctions.LastDateOfMonth(dtomonth)); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(olist); } [HttpPost] [Route("initiateCancelRequest")] [AllowAnonymous] public ActionResult InitiateCancelRequest(LeaveEntry item) { try { _leaveEntryService.InitiateCancelRequest(item); return Ok(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpPost("currentYearStatus")] public ActionResult CurrentYearStatus(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = (int)currentUser.PayrollTypeID; var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string empIds = (string)item["empIds"].ToObject(); int leaveYearId = item["leaveYearId"].ToObject(); var employeeIdList = empIds.Split(','); List employees = new List(); try { foreach (var employeeId in employeeIdList) { var employee = _employeeService.Get(int.Parse(employeeId)); employees.Add(employee); } var leaveYear = _leaveYearService.Get(leaveYearId); var employeeStatus = _leaveProcessService.CurrentYearStatus(employees, leaveYear, payrollTypeId); return Ok(employeeStatus); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpGet("OnapprovalCancelRequest/{tranId}")] public ActionResult OnapprovalCancelRequest(int tranId) { try { EmailSettings emailSettings = _emailSettings.Value; _leaveEntryService.OnapprovalCancelRequest(tranId); List temperr = _leaveEntryService.SendMailToTheApproversForCancellation(tranId, emailSettings); if (temperr.Count > 0) { return StatusCode(StatusCodes.Status500InternalServerError, "Mail Sending Failed"); } return Ok(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpPost] [Route("cancelLeaveApprove")] [AllowAnonymous] public ActionResult CancelLeaveApprove(WFMovementTran item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item.FromEmployeeID = (int)currentUser.EmployeeID; _leaveEntryService.CancelRequestApprove(item); return Ok(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpPost] [Route("cancelLeaveReject")] [AllowAnonymous] public ActionResult CancelLeaveReject(WFMovementTran item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item.FromEmployeeID = (int)currentUser.EmployeeID; _leaveEntryService.CancelRequestReject(item); return Ok(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpGet] [Route("getLeaveEncashment/{leaveYearId}/{employeeId}")] public ActionResult GetLeaveEncashment(int leaveYearId, int employeeId) { LeaveEncashment item = new LeaveEncashment(); try { item = _leaveEncashmentService.Get(leaveYearId, employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet] [Route("getLeaveEncashmentByLeaveYearId/{leaveYearId}")] public ActionResult GetLeaveEncashmentByLeaveYearId(int leaveYearId) { List items = new List(); try { items = _leaveEncashmentService.Get(leaveYearId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Leave Encashment [HttpPost("saveLeaveEncashment")] public ActionResult SaveLeaveEncashment(LeaveEncashment item) { try { _leaveEncashmentService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost("saveLeaveEncashmentList")] public ActionResult SaveLeaveEncashmentList(List items) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); foreach (var leaveEncashment in items) { if (leaveEncashment.IsNew == true) { leaveEncashment.CreatedBy = currentUser.UserID; leaveEncashment.CreatedDate = DateTime.Today; } else { leaveEncashment.ModifiedBy = currentUser.UserID; leaveEncashment.ModifiedDate = DateTime.Today; } } _leaveEncashmentService.Save(items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost("calculateTax")] public ActionResult CalculateTax(List items) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var nextPayProcess = currentUser.NextPayProcessDate.GetValueOrDefault(); var payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); var taxParamId = currentUser.TaxParamID.GetValueOrDefault(); try { _leaveEncashmentService.CalculateTax(items, nextPayProcess, taxParamId, payrollTypeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost("calculateTaxForLeaveEncashment")] public ActionResult calculateTaxForLeaveEncashment(List items) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var nextPayProcess = currentUser.NextPayProcessDate.GetValueOrDefault(); var payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); var taxParamId = currentUser.TaxParamID.GetValueOrDefault(); try { //new LeaveEncashmentService().calculateTaxForLeaveEncashment(items, currentUser, taxParamId, payrollTypeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("getMultipleLeaveLedgerData")] public ActionResult GetMultipleLeaveLedgerData(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string empIds = (string)item["empIds"].ToObject(); int leaveYearId = item["leaveYearId"].ToObject(); int leaveId = item["leaveId"].ToObject(); DateTime fromDate = item["fromDate"].ToObject(); DateTime toDate = item["toDate"].ToObject(); DataTable dt = null; try { if (leaveId > 0) { dt = _leaveEntryService.GetMultipleLeaveLedgerData(leaveYearId, leaveId, empIds, fromDate, toDate); } else { dt = _leaveEntryService.GetMultipleLeaveLedgerData(leaveYearId, empIds, fromDate, toDate); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } #region Short Leave [HttpPost] [Route("saveShortLeave")] public ActionResult SaveShortLeave(ShortLeave item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); Employee oEmp = _employeeService.Get(currentUser.EmployeeID.GetValueOrDefault()); item.EmployeeID = oEmp.ID; item.PayrollTypeID = oEmp.PayrollTypeID; item.LineManagerID = (int)oEmp.LineManagerID; if(item.ExpectedReturnTime != null) { TimeSpan timeDiff = (TimeSpan)(item.ExpectedReturnTime - item.DepartureTime); if (timeDiff.TotalHours >= 1) { item.TotalHour = timeDiff.TotalHours; } else { item.TotalHour = 0; } } //else //{ //} if (item.IsNew == false) { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } else { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; } try { _shortLeaveService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet] [Route("getShortLeaveByID/{ID}")] public ActionResult getShortLeaveByID(int id) { ShortLeave item = new ShortLeave(); try { item = _shortLeaveService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } //[HttpGet] //[Route("getShortLeaveByDate/{empID}/{payrollTypeID}/{status}/{fromDate}/{toDate}")] //public ActionResult getShortLeaveByDate(int empid, int pID, int status, DateTime fromDate, DateTime toDate) //{ // //code = GlobalFunctions.GetApiDefaultData(code); // //name = GlobalFunctions.GetApiDefaultData(name); // List items = new List(); // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // int employeeId = currentUser.EmployeeID.GetValueOrDefault(); // int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); // try // { // //DateTime fromDate = Convert.ToDateTime(sFromDate); // //DateTime toDate = Convert.ToDateTime(sToDate); // items = _shortLeaveService.Get(employeeId, payrollTypeId, status, fromDate, toDate); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(items); //} [HttpPost] [Route("getShortLeaveByDateRange")] public ActionResult getShortLeaveByDateRange(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); EnumGatePassStatus status = item["status"].ToObject(); DateTime fromDate = item["fromDate"].ToObject(); DateTime toDate = item["toDate"].ToObject(); DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { dt = _shortLeaveService.Get(employeeId, payrollTypeId, status, fromDate, toDate); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("getAppliedShortLeave")] public ActionResult getAppliedShortLeave(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); EnumGatePassStatus status = item["status"].ToObject(); DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int lmId = currentUser.EmployeeID.GetValueOrDefault(); try { dt = _shortLeaveService.GetAppliedSortLeave(lmId, status); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("getApprovedShortLeave")] public ActionResult getApprovedShortLeave(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); EnumGatePassStatus status = item["status"].ToObject(); DateTime fromDate = item["fromDate"].ToObject(); DateTime toDate = item["toDate"].ToObject(); DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int lmId = currentUser.EmployeeID.GetValueOrDefault(); try { dt = _shortLeaveService.GetApprovedShortLeave(lmId, status, fromDate, toDate); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("ApproveOrRejectShortLeave")] public ActionResult ApproveShortLeave(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); EnumGatePassStatus status = item["status"].ToObject(); int shortLeaveid = item["item"]["shortLeaveId"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int approver = currentUser.EmployeeID.GetValueOrDefault(); try { _shortLeaveService.ApproveOrRejectShortLeave(shortLeaveid, status, approver); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("ApproveMultipleShortLeave")] public ActionResult ApproveMultipleShortLeave(dynamic data) { var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); EnumGatePassStatus status = items["status"].ToObject(); string sID = (string)items["item"].ToObject(); //int shortLeaveid = item["item"]["shortLeaveId"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int approver = currentUser.EmployeeID.GetValueOrDefault(); try { _shortLeaveService.ApproveMultipleShortLeave(sID, status, approver); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("getGatemanShortLeave")] public ActionResult getGatemanShortLeave(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); EnumGatePassStatus status = item["status"].ToObject(); DateTime fromDate = item["fromDate"].ToObject(); DateTime toDate = item["toDate"].ToObject(); DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { dt = _shortLeaveService.getGatemanShortLeave(status, fromDate, toDate); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("saveGatemanEntry")] public ActionResult saveGatemanEntry(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int empid = item["employeeid"].ToObject(); int shortleaveid = item["shortLeaveid"].ToObject(); string type = item["type"].ToObject(); ShortLeave oShortleave = _shortLeaveService.Get(shortleaveid); DateTime now = DateTime.Now; TimeSpan timeSpan = now.TimeOfDay; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); Employee oEmp = _employeeService.Get(id); if (type == "IN") { oShortleave.ActualInTime = timeSpan; } if (type == "OUT") { oShortleave.ActualOutTime = timeSpan; } if (oShortleave.ActualInTime != TimeSpan.FromMinutes(0) && oShortleave.ActualOutTime != TimeSpan.FromMinutes(0)) { TimeSpan timeDiff = (TimeSpan)(oShortleave.ActualInTime - oShortleave.ActualOutTime); if (timeDiff.TotalHours >= 1) { oShortleave.TotalHour = timeDiff.TotalHours; } else { oShortleave.TotalHour = 0; } } try { //_shortLeaveService.saveGatemanEntry(shortleaveid, type); _shortLeaveService.UpdateInAndOutTime(oShortleave, oEmp); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } #endregion #region My Team Leave [HttpGet] [Route("GetLeaveTodayAndNextWeek")] public ActionResult GetLeaveTodayAndNextWeek() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); Employee oEmp = _employeeService.Get(id); try { dt = _leaveEntryService.GetLeaveTodayAndNextWeek(oEmp, EnumLeaveStatus.Approved); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getTopLeaveChartData")] public ActionResult getTopLeaveChartData() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); LeaveYear LeaveYear = new LeaveYearService().GetCurrentYear((int)currentUser.PayrollTypeID); Employee oEmp = _employeeService.Get(id); try { dt = _leaveEntryService.getTopLeaveChartData(oEmp, LeaveYear.ID, EnumLeaveStatus.Approved); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getcorehrLeaveChartData")] public ActionResult getcorehrLeaveChartData() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); LeaveYear LeaveYear = new LeaveYearService().GetCurrentYear((int)currentUser.PayrollTypeID); Employee oEmp = _employeeService.Get(id); try { dt = _leaveEntryService.getcorehrLeaveChartData(oEmp, LeaveYear.ID, EnumLeaveStatus.Approved); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("rmgLeaveEncashmentCalculation")] public ActionResult rmgLeaveEncashmentCalculation(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); var item = items[0]; int month = (int)item["month"].ToObject(); string years = (string)item["year"].ToObject(); string empIds = (string)item["empid"].ToObject(); //int leaveYearId = item["leaveyearid"].ToObject(); List dt = null; try { dt = new LeaveEncashmentService().rmgLeaveEncashmentCalculation( month, years,empIds, (int) currentUser.PayrollTypeID,5); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } #endregion My Team Leave #region Maternity Leave [HttpGet] [Route("getMaternityLeave")] public ActionResult getMaternityLeave() { int rowIndex = 0; List oMaternityLeaves = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { //List employees = _employeeService.GetAllEmps(); List employees = _employeeService.GetAllLive(); List maternityLeaves = _maternityLeaveService.Get(); foreach (MaternityLeave item in maternityLeaves) { Employee oEmployee = employees.Find(delegate (Employee oem) { return oem.ID == item.EmployeeID; }); if(oEmployee!= null) { item.EmployeeNo = employees.Find(delegate (Employee oem) { return oem.ID == item.EmployeeID; }).EmployeeNo; item.EmployeeName = employees.Find(delegate (Employee oem) { return oem.ID == item.EmployeeID; }).Name; rowIndex++; oMaternityLeaves.Add(item); } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(oMaternityLeaves); } [HttpPost] [Route("deleteMaternityLeave")] public ActionResult deleteMaternityLeave(MaternityLeave oMaternityLeave) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { List _taxRawItems = new List(); oMaternityLeave.MaternityItemDetailColl = _maternityLeaveService.GetMItemDetail(oMaternityLeave.ID); oMaternityLeave.MaternityStatusDetailColl = _maternityLeaveService.GetMStatusDetail(oMaternityLeave.ID); if (oMaternityLeave.MaternityStatusDetailColl.Count == 0) { //MakeTaxRawItems(oMaternityLeave.MaternityItemDetailColl); foreach (MaternityLeave.MaternityItemDetail maternityItemDetail in oMaternityLeave.MaternityItemDetailColl) { TaxRawItem taxRawItem = new TaxRawItem(); if (maternityItemDetail.ItemType == EnumMaternityItemDetailType.GrossSalary) { taxRawItem = TaxRawItem.Create("Gross Component", maternityItemDetail.Amount, maternityItemDetail.IncomeTaxItemType, maternityItemDetail.SalaryComponentID); _taxRawItems.Add(taxRawItem); } else if (maternityItemDetail.ItemType != EnumMaternityItemDetailType.Total && maternityItemDetail.ItemType != EnumMaternityItemDetailType.Days) { taxRawItem = TaxRawItem.Create(maternityItemDetail.Description, maternityItemDetail.Amount, maternityItemDetail.IncomeTaxItemType, maternityItemDetail.SalaryComponentID); _taxRawItems.Add(taxRawItem); } } TaxCalculator otaxCal = new TaxCalculator(); otaxCal.TaxParameter = new TaxParameterService().Get((int)currentUser.TaxParamID); otaxCal.Employee = _employeeService.Get(oMaternityLeave.EmployeeID); //oMaternityLeave.IncomeTaxColl = otaxCal.UndoCalculate(_taxRawItems, oMaternityLeave.TaxAmount); oMaternityLeave.IncomeTaxColl = new List(); _maternityLeaveService.Delete(oMaternityLeave); } else { throw new Exception("Payment is already done. so, Data delete is not allowed." + " This Data is not Deleteable"); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } //[HttpPost] //[Route("deleteMaternityStatusDetail")] //public ActionResult deleteMaternityStatusDetail(MaternityLeave.MaternityStatusDetail oMaternityStatusDetail) //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // try // { // MaternityLeave.MaternityStatusDetail maternityStatusDetailRemove = oMaternityStatusDetail; // MaternityLeave _maternityLeave = _maternityLeaveService.Get(oMaternityStatusDetail.MaternityLeaveID); // MaternityLeave.MaternityStatusDetail maternityStatusDetail = _maternityLeave.MaternityStatusDetailColl.Find(delegate (MaternityLeave.MaternityStatusDetail mStatusDetail) { return mStatusDetail.PaymentDate.Value == maternityStatusDetailRemove.PaymentDate.Value; }); // if (maternityStatusDetail != null) // { // _maternityLeave.PaidAmount -= maternityStatusDetail.Amount; // //AmountAndDaysCalculation(_maternityLeave.PaidAmount, _maternityLeave.NetAmount - _maternityLeave.PaidAmount, (int)numPaymentDays.Value + maternityStatusDetail.PaymentDays); // _maternityLeave.MaternityStatusDetailColl.Remove(maternityStatusDetail); // //RefreshGridPayment(); // //if (_maternityLeave.MaternityStatusDetailColl.Count == 0) // //{ // // btnAddAllowance.Enabled = true; // // btnRemoveAllowance.Enabled = true; // //} // } // } // catch (Exception ex) // { // return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); // } // return Ok(); //} [HttpGet("getMaternityStatusDetail/{parentId}")] public ActionResult GetMStatusDetail(int parentId) { List item = new List(); try { item = _maternityLeaveService.GetMStatusDetail(parentId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("getMaternityItemDetail/{parentId}")] public ActionResult GetMaternityItemDetail(int parentId) { List item = new List(); try { item = _maternityLeaveService.GetMItemDetail(parentId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost] [Route("prepareMaternityItemDetails")] public ActionResult prepareMaternityItemDetails(dynamic data) { //List listItems = new List(); //DataSet ds = new DataSet(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); //var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); //var item = items[0]; var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int maternityLeaveid = (int)item["id"].ToObject(); int employeeid = (int)item["employeeid"].ToObject(); DateTime applyDate = (DateTime)item["applyDate"].ToObject(); DateTime dateOfApproval = (DateTime)item["dateOfApproval"].ToObject(); DateTime leaveFromDate = item["leaveFromDate"].ToObject(); DateTime leaveToDate = item["leaveToDate"].ToObject(); int totalDays = (int)item["totalDays"].ToObject(); DataTable dt = null; double totalEarning = 0; int totalWorkingDays = 0; double dailyAvgEarning = 0; int numPaymentDays = 0; MaternityLeave maternityLeave = new MaternityLeave(); if (maternityLeaveid == 0) { maternityLeave.ID = maternityLeaveid; maternityLeave.EmployeeID = employeeid; maternityLeave.ApplicationDate = applyDate; maternityLeave.DateOfApproval = dateOfApproval; maternityLeave.LeaveFromDate = leaveFromDate; maternityLeave.LeaveToDate = leaveToDate; maternityLeave.ApproveDays = totalDays; maternityLeave.MaternityItemDetailColl = _maternityLeaveService.GetMItemDetail(maternityLeave.ID); } else { maternityLeave = _maternityLeaveService.Get(maternityLeaveid); maternityLeave.MaternityItemDetailColl = _maternityLeaveService.GetMItemDetail(maternityLeave.ID); maternityLeave.MaternityStatusDetailColl = _maternityLeaveService.GetMStatusDetail(maternityLeave.ID); } Employee employee = new EmployeeService().Get(employeeid); DateTime monthLastDate = GlobalFunctions.LastDateOfMonth(leaveFromDate); List MaternityItemDetailOut = new List(); MaternityLeaveService maternityLeaveService = new MaternityLeaveService(); try { maternityLeave.MaternityItemDetailColl = maternityLeaveService.PrepareMaternityItemDetails(maternityLeave, employee, monthLastDate, (int)currentUser.PayrollTypeID, out totalEarning, out totalWorkingDays); dt = maternityLeaveService.RefreshGridAllowanceMaternityLeave(maternityLeave, monthLastDate, out MaternityItemDetailOut); if (maternityLeave.ID == 0) { maternityLeave = maternityLeaveService.RefreshGridPaymentMaternityLeave(maternityLeave, out numPaymentDays); double nTaxAmount = 0; TaxCalculator otaxCal = new TaxCalculator(); if (leaveFromDate <= leaveToDate) { int days = totalDays; if (totalWorkingDays > 0) { dailyAvgEarning = totalEarning / totalWorkingDays; } else { //_maternityLeave = new MaternityLeave(); //dgvMaternityItemDetails.Rows.Clear(); //dgvPaymentStatus.Rows.Clear(); //MessageBox.Show("Zero or invalid value of total working days.", "Zero or Invalid value", MessageBoxButtons.OK, MessageBoxIcon.Information); //return; } List taxRawItems = new List(); double ntaxableIncome = days * dailyAvgEarning; TaxRawItem taxRawItemBS = TaxRawItem.Create("Maternity Benefit", ntaxableIncome, enumIncomeTaxItemType.AdjustItem, 5); taxRawItems.Add(taxRawItemBS); otaxCal.TaxParameter = new TaxParameterService().Get((int)currentUser.TaxParamID); otaxCal.Employee = _employeeService.Get(employeeid); try { //List incomeTaxes = otaxCal.MaternityLeaveCalculate(taxRawItems, currentUser, ref nTaxAmount); } catch (Exception ex) { nTaxAmount = 0; throw new Exception("Failed to calculate tax"); } double netAmount = 0; netAmount = days * dailyAvgEarning - nTaxAmount; if (maternityLeave == null) { maternityLeave = new MaternityLeave(); } maternityLeave.EmployeeID = employeeid; maternityLeave.ApplicationDate = applyDate; maternityLeave.LeaveFromDate = leaveFromDate; maternityLeave.LeaveToDate = leaveToDate; maternityLeave.DateOfApproval = dateOfApproval; maternityLeave.ApproveDays = Convert.ToInt32(totalDays); maternityLeave.CurrentStatus = (int)EnumLeaveStatus.Approved; maternityLeave.DailyAvgEarning = dailyAvgEarning; maternityLeave.MaternityBenifit = days * dailyAvgEarning; maternityLeave.TaxAmount = nTaxAmount; maternityLeave.NetAmount = maternityLeave.MaternityBenifit - maternityLeave.TaxAmount; maternityLeave.PaidAmount = 0; maternityLeave.MaternityItemDetailColl = MaternityItemDetailOut; numPaymentDays = days / 2; } } else { MaternityItemDetailOut = maternityLeave.MaternityItemDetailColl; //foreach(MaternityLeave.MaternityItemDetail miDtailitem in maternityLeave.MaternityItemDetailColl) //{ // if(miDtailitem.Description == "Actual Working Days") // totalWorkingDays += (int)miDtailitem.Amount; //} maternityLeave = maternityLeaveService.RefreshGridPaymentMaternityLeave(maternityLeave, out numPaymentDays); //if (leaveFromDate <= leaveToDate) //{ // int days = totalDays; // if (totalWorkingDays > 0) // { // dailyAvgEarning = totalEarning / totalWorkingDays; // } //} } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } DataSet ds = new DataSet(); //List maternityLeaves = new List(); //maternityLeaves.Add(maternityLeave); DataTable maternityLeavedt = new DataTable(); maternityLeavedt.Columns.Add("id", typeof(int)); maternityLeavedt.Columns.Add("employeeID", typeof(int)); maternityLeavedt.Columns.Add("applicationDate", typeof(DateTime)); maternityLeavedt.Columns.Add("leaveFromDate", typeof(DateTime)); maternityLeavedt.Columns.Add("leaveToDate", typeof(DateTime)); maternityLeavedt.Columns.Add("dateOfApproval", typeof(DateTime)); maternityLeavedt.Columns.Add("approveDays", typeof(int)); maternityLeavedt.Columns.Add("currentStatus", typeof(int)); maternityLeavedt.Columns.Add("dailyAvgEarning", typeof(double)); maternityLeavedt.Columns.Add("maternityBenifit", typeof(double)); maternityLeavedt.Columns.Add("taxAmount", typeof(double)); maternityLeavedt.Columns.Add("netAmount", typeof(double)); maternityLeavedt.Columns.Add("paidAmount", typeof(double)); maternityLeavedt.Columns.Add("maternityItemDetailColl", typeof(List)); maternityLeavedt.Columns.Add("maternityStatusDetailColl", typeof(List)); maternityLeavedt.Columns.Add("incomeTaxColl", typeof(List)); DataRow oDr = maternityLeavedt.NewRow(); oDr["id"] = maternityLeave.ID; oDr["employeeID"] = maternityLeave.EmployeeID; oDr["applicationDate"] = maternityLeave.ApplicationDate; oDr["leaveFromDate"] = maternityLeave.LeaveFromDate; oDr["leaveToDate"] = maternityLeave.LeaveToDate; oDr["dateOfApproval"] = maternityLeave.DateOfApproval; oDr["approveDays"] = maternityLeave.ApproveDays; oDr["currentStatus"] = maternityLeave.CurrentStatus; oDr["dailyAvgEarning"] = maternityLeave.DailyAvgEarning; oDr["maternityBenifit"] = maternityLeave.MaternityBenifit; oDr["taxAmount"] = maternityLeave.TaxAmount; oDr["netAmount"] = maternityLeave.NetAmount; oDr["paidAmount"] = maternityLeave.PaidAmount; oDr["maternityItemDetailColl"] = maternityLeave.MaternityItemDetailColl; oDr["maternityStatusDetailColl"] = maternityLeave.MaternityStatusDetailColl; oDr["incomeTaxColl"] = maternityLeave.IncomeTaxColl; maternityLeavedt.Rows.Add(oDr); maternityLeavedt.TableName = "MaternityLeave"; ds.Tables.Add(maternityLeavedt); dt.TableName = "MaternityLeaveItemDetailsGridData"; ds.Tables.Add(dt); DataTable paymentDays = new DataTable(); paymentDays.Columns.Add("numPaymentDays", typeof(int)); //paymentDays.Columns.Add("dailyAvgEarning", typeof(double)); DataRow dRow = paymentDays.NewRow(); dRow["numPaymentDays"] = numPaymentDays; //dRow["dailyAvgEarning"] = dailyAvgEarning; paymentDays.Rows.Add(dRow); paymentDays.TableName = "Payment"; ds.Tables.Add(paymentDays); //DataTable mIDetails = new DataTable(); //mIDetails.Columns.Add("id", typeof(int)); //mIDetails.Columns.Add("MaternityLeaveID", typeof(int)); //mIDetails.Columns.Add("ItemType", typeof(EnumMaternityItemDetailType)); //mIDetails.Columns.Add("Amount", typeof(double)); //mIDetails.Columns.Add("Description", typeof(string)); //mIDetails.Columns.Add("MonthDate", typeof(DateTime)); //mIDetails.Columns.Add("SalaryComponentID", typeof(int)); //mIDetails.Columns.Add("IncomeTaxItemType", typeof(int)); //mIDetails.Columns.Add("TaxRawItemObject", typeof(TaxRawItem)); //foreach (MaternityLeave.MaternityItemDetail itemDetail in MaternityItemDetailOut) //{ // DataRow midRow = mIDetails.NewRow(); // midRow["id"] = itemDetail.ID; // midRow["MaternityLeaveID"] = itemDetail.MaternityLeaveID; // midRow["ItemType"] = itemDetail.ItemType; // midRow["Amount"] = itemDetail.Amount; // midRow["Description"] = itemDetail.Description; // midRow["MonthDate"] = itemDetail.MonthDate; // midRow["SalaryComponentID"] = itemDetail.SalaryComponentID; // midRow["IncomeTaxItemType"] = itemDetail.IncomeTaxItemType; // midRow["TaxRawItemObject"] = itemDetail.TaxRawItemObject; // mIDetails.Rows.Add(midRow); //} //mIDetails.TableName = "MaternityItemDetails"; //ds.Tables.Add(mIDetails); return Ok(ds); } [HttpPost] [Route("saveMaternityLeave")] public ActionResult saveMaternityLeave(MaternityLeave oMaternityLeave) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); User user = new UserService().Get(currentUser.UserID); try { _maternityLeaveService.Save(oMaternityLeave, user); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } #endregion Maternity Leave } }