using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Globalization; using System.IO; using System.Linq; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using AutoMapper.Configuration; using Ease.Core; using HRM.BO; using HRM.DA; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Payroll.BO; using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration; namespace HRM.UI.Controllers { [ApiController] [Route("api/Claim")] [Authorize] public class ClaimController : Controller { #region Declerations private readonly IClaimBasicService _claimBasicService; private readonly IClaimBasicItemService _claimBasicItemService; private readonly IClaimRuleService _claimRuleService; private readonly IConfiguration _config; private readonly IEmployeeService _employeeService; private readonly IClaimRequisitionService _claimRequisitionService; private readonly IClaimDisbursementService _claimDisbursementService; private readonly IWFMovementTranService _wfMovementTranService; private readonly IClaimBalaceService _claimBalaceService; private static string _filePath = @"ClientApp\Documents\"; #endregion #region Constructor public ClaimController(IConfiguration config, IClaimBasicService claimBasicService, IClaimBasicItemService claimBasicItemService, IClaimRuleService claimRuleService, IEmployeeService employeeService, IClaimRequisitionService claimRequisitionService, IWFMovementTranService wfMovementTranService, IClaimDisbursementService claimDisbursementService, IClaimBalaceService claimBalaceService) { _config = config; _claimBasicService = claimBasicService; _claimBasicItemService = claimBasicItemService; _claimRuleService = claimRuleService; _employeeService = employeeService; _claimRequisitionService = claimRequisitionService; _wfMovementTranService = wfMovementTranService; _claimDisbursementService = claimDisbursementService; _claimBalaceService = claimBalaceService; } #endregion #region Functions [HttpPost] [Route("saveclaim")] public ActionResult SaveClaim(ClaimBasic item) { int ans; var isNew = item.ID <= 0; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (isNew) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.PayrollTypeID = (int)currentUser.PayrollTypeID; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } if (item.ClaimBasicItems != null && item.ClaimBasicItems.Count > 0) { foreach (ClaimBasicItem basicItem in item.ClaimBasicItems) { basicItem.CreatedBy = currentUser.UserID; } } try { ans = _claimBasicService.Save(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ans); } [HttpGet("getClaims")] public ActionResult GetClaims() { List obs = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { obs = _claimBasicService.Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); //if(obs != null && obs.Count > 0) //{ // foreach (var item in obs) // { // item.SubItemCount = _claimBasicItemService.GetByClaimBasicID(item.ID).Count; // } //} } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(obs); } [HttpPost] [Route("DeleteClaimBasic")] public ActionResult DeleteClaimBasic(ClaimBasic item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _claimBasicService.Delete(item.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpGet] [Route("GetClaimBasic/{calimBasicID}")] public ActionResult GetClaimBasic(int calimBasicID) { ClaimBasic item = new ClaimBasic(); try { item = _claimBasicService.Get(calimBasicID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet] [Route("getDesignationsForClaim")] public ActionResult GetDesignationsForClaim() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List tempDesignations = new List(); List designations = new List(); try { tempDesignations = new DesignationService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); if (tempDesignations != null && tempDesignations.Count > 0) { designations = tempDesignations .Where(x => x.Code == "014" || x.Code == "040" || x.Code == "075" || x.Code == "011" || x.Code == "016" || x.Code == "013" || x.Code == "029" || x.Code == "015" || x.Code == "066" || x.Code == "100" || x.Code == "110" || x.Code == "104" || x.Code == "107" || x.Code == "061").ToList(); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(designations); } [HttpGet] [Route("GetClaimBasicItems/{calimBasicID}")] public ActionResult GetClaimBasicItems(int calimBasicID) { List claimBasicItems = new List(); try { claimBasicItems = _claimBasicItemService.GetByClaimBasicID(calimBasicID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(claimBasicItems); } [HttpPost] [Route("saveclaimrule")] public ActionResult SaveClaimRule(ClaimRule item) { int ans; var isNew = item.ID <= 0; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (isNew) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; // item.PayrollTypeID = (int)currentUser.PayrollTypeID; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } try { ans = _claimRuleService.Save(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ans); } [HttpGet("getClaimRules")] public ActionResult GetClaimRules() { List obs = new List(); //CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { obs = _claimRuleService.Get(); if (obs.Count > 0) { foreach (ClaimRule item in obs) { if (item.IsAnnualBalance == true) { item.AnnualBalance = "Yes"; } else if (item.IsAnnualBalance == false) { item.AnnualBalance = "No"; } if (item.IsAtActualPayment == true) { item.AtActualPayment = "Yes"; } else if (item.IsAtActualPayment == false) { item.AtActualPayment = "No"; } } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(obs); } [HttpGet] [Route("GetClaimRule/{claimRuleId}")] public ActionResult GetClaimRule(int claimRuleId) { ClaimRule item = new ClaimRule(); try { item = _claimRuleService.Get(claimRuleId); if (item != null) { item.ClaimRuleDesignations = _claimRuleService.GetClaimRuleGradesByClaimRuleID(item.ID); item.ClaimBasicItems = _claimBasicItemService.GetByClaimBasicID(item.ClaimBasicID); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet] [Route("GetWithDesignation")] public ActionResult GetWithDesignation() { List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); Employee employee = new Employee(); employee = _employeeService.Get((int)currentUser.EmployeeID); DataSet ds = new DataSet(); try { ds = _claimBasicService.GetWithDesignation((int)employee.DesignationID, (int)currentUser.PayrollTypeID); foreach (var row in ds.Tables[0].AsEnumerable()) { ClaimBasic temp = new ClaimBasic(); temp.ID = row["ClaimBasicID"] == null ? 0 : row.Field("ClaimBasicID"); temp.ItemName = row["ItemName"] == null ? "" : row.Field("ItemName"); items.Add(temp); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet] [Route("GetClaimRuleAmount/{claimBasicItemID}")] public ActionResult GetClaimRuleAmount(int claimBasicItemID) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); ClaimRuleDesignations claimRuleDesignation = new ClaimRuleDesignations(); try { ClaimBasicItem claimitem = _claimBasicItemService.Get(claimBasicItemID); Employee employee = new Employee(); employee = _employeeService.Get((int)currentUser.EmployeeID); List claimRules = _claimRuleService.GetByClaimBasicID(claimitem.ClaimBasicID); if (claimRules != null) { foreach (var item in claimRules) { item.ClaimRuleDesignations = _claimRuleService.GetClaimRuleGradesByClaimRuleID(item.ID); } } ClaimRule claimRule = (claimRules != null && claimRules.Count > 0) ? claimRules.First() : new ClaimRule(); //claimRuleDesignation = claimRule.ClaimRuleDesignations.Where(x => x.ClaimBasicItemId == claimBasicItemID && // x.DesignationID == employee.DesignationID // ).FirstOrDefault(); claimRuleDesignation = claimRule.ClaimRuleDesignations.Where(x => x.ClaimBasicItemId == claimBasicItemID).FirstOrDefault(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(claimRuleDesignation); } [HttpPost] [Route("saveClaimRequisition")] public ActionResult SaveClaimRequisition(ClaimRequisition item) { string connectionString = _config.GetSection("dbSettings").GetSection("SqlCommandConnection").Value; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item.ConnectionString = connectionString; int startIndex = 0; if (item.IsNew) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.PayrollTypeID = currentUser.PayrollTypeID; item.EmployeeID = (int)currentUser.EmployeeID; item.SalaryMonth = (DateTime)currentUser.NextPayProcessDate; item.ClaimProcessDate = null; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } try { if (item.ClaimRequisitionItems != null && item.ClaimRequisitionItems.Count > 0) { foreach (var tempItem in item.ClaimRequisitionItems) { if (tempItem.claimRequisitionFileAttacment != null) { if (tempItem.claimRequisitionFileAttacment.ID <= 0 && tempItem.claimRequisitionFileAttacment.PreviousFileTobase64 != null) { string[] items = tempItem.claimRequisitionFileAttacment.PreviousFileTobase64.Split(new char[] { ',', ' ' }, StringSplitOptions.None); byte[] newBytes = Convert.FromBase64String(items[1]); tempItem.claimRequisitionFileAttacment.FileAsByteArray = newBytes; } } } } _claimRequisitionService.Save(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpGet] [Route("GetDraftedClaimItems")] public ActionResult GetDraftedClaimItems() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); ClaimRequisition draftedClaimRequisition = new ClaimRequisition(); List obs = new List(); // List obsi = new List(); ClaimBasicItem obsi = new ClaimBasicItem(); try { obs = _claimBasicService.Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); draftedClaimRequisition = _claimRequisitionService.GetClaimByprocessDate(EnumwfStatus.Initiate, (int)currentUser.EmployeeID); if (draftedClaimRequisition != null) { draftedClaimRequisition.ClaimRequisitionItems = _claimRequisitionService.GetClaimRequisitionItem(draftedClaimRequisition.ID.ToString()); if (draftedClaimRequisition.ClaimRequisitionItems != null && draftedClaimRequisition.ClaimRequisitionItems.Count > 0) { draftedClaimRequisition.IRFileAttacments = new List(); draftedClaimRequisition.IRFileAttacments = _claimRequisitionService.GetIRFileAttachments(draftedClaimRequisition.ID); } foreach (var item in draftedClaimRequisition.ClaimRequisitionItems) { obsi = _claimBasicItemService.Get(item.ClaimBasicItemID); item.ClaimBasicName = obs?.Where(x => x.ID == item.ClaimBasicID)?.FirstOrDefault().ItemName; item.ClaimBasicItemName = obsi.Name; item.claimRequisitionFileAttacment = new FileAttachment(); item.claimRequisitionFileAttacment = draftedClaimRequisition.IRFileAttacments?.Where(x => x.RefchildID == item.ID)?.FirstOrDefault(); // item.claimRequisitionFileAttacment.PreviousFileTobase64 = item.claimRequisitionFileAttacment.FileTobase64; if (item.claimRequisitionFileAttacment != null) item.claimRequisitionFileAttacment.PreviousFileTobase64 = item.claimRequisitionFileAttacment == null ? null : item.claimRequisitionFileAttacment.FileTobase64; } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(draftedClaimRequisition); } [HttpGet] [Route("getClaim/{claimId}")] public ActionResult GetClaim(int claimId) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); ClaimRequisition prevClaimRequisition = new ClaimRequisition(); List obs = new List(); // List obsi = new List(); ClaimBasicItem obsi = new ClaimBasicItem(); try { prevClaimRequisition = _claimRequisitionService.Get(claimId); obs = _claimBasicService.Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); //field fillup //if (prevClaimRequisition != null) //{ // if (prevClaimRequisition.ClaimBasicID != null && prevClaimRequisition.ClaimBasicID > 0) // { // var selecetedClaimBasic = obs.Find(x => x.ID == prevClaimRequisition.ClaimBasicID); // if (selecetedClaimBasic != null) // { // if (selecetedClaimBasic.IsField1 == true && selecetedClaimBasic.Field1Type == EnumFieldTypeStatus.Date) // { // prevClaimRequisition.Field1 = Convert.ToDateTime(prevClaimRequisition.Field1); // } // else if (selecetedClaimBasic.IsField1 == true && selecetedClaimBasic.Field1Type == EnumFieldTypeStatus.Number) // { // prevClaimRequisition.Field1 = Convert.ToDouble(prevClaimRequisition.Field1, CultureInfo.InvariantCulture); ; // } // if (selecetedClaimBasic.IsField2 == true && selecetedClaimBasic.Field2Type == EnumFieldTypeStatus.Date) // { // prevClaimRequisition.Field2 = Convert.ToDateTime(prevClaimRequisition.Field2); // } // else if (selecetedClaimBasic.IsField2 == true && selecetedClaimBasic.Field2Type == EnumFieldTypeStatus.Number) // { // prevClaimRequisition.Field2 = Convert.ToDouble(prevClaimRequisition.Field2, CultureInfo.InvariantCulture); ; // } // if (selecetedClaimBasic.IsField3 == true && selecetedClaimBasic.Field3Type == EnumFieldTypeStatus.Date) // { // prevClaimRequisition.Field3 = Convert.ToDateTime(prevClaimRequisition.Field3); // } // else if (selecetedClaimBasic.IsField3 == true && selecetedClaimBasic.Field3Type == EnumFieldTypeStatus.Number) // { // prevClaimRequisition.Field3 = Convert.ToDouble(prevClaimRequisition.Field3, CultureInfo.InvariantCulture); ; // } // if (selecetedClaimBasic.IsField4 == true && selecetedClaimBasic.Field4Type == EnumFieldTypeStatus.Date) // { // prevClaimRequisition.Field4 = Convert.ToDateTime(prevClaimRequisition.Field4); // } // else if (selecetedClaimBasic.IsField4 == true && selecetedClaimBasic.Field4Type == EnumFieldTypeStatus.Number) // { // prevClaimRequisition.Field4 = Convert.ToDouble(prevClaimRequisition.Field4, CultureInfo.InvariantCulture); ; // } // } // } //} if (prevClaimRequisition != null) { prevClaimRequisition.ClaimRequisitionItems = _claimRequisitionService.GetClaimRequisitionItem(prevClaimRequisition.ID.ToString()); if (prevClaimRequisition.ClaimRequisitionItems != null && prevClaimRequisition.ClaimRequisitionItems.Count > 0) { foreach (var item in prevClaimRequisition.ClaimRequisitionItems) { if (item != null) { if (item.ClaimBasicID > 0) { var selecetedClaimBasic = obs.Find(x => x.ID == item.ClaimBasicID); if (selecetedClaimBasic != null) { if (selecetedClaimBasic.IsField1 == true) { item.Description += " " + selecetedClaimBasic.Field1 +" :"; if (selecetedClaimBasic.Field1Type == EnumFieldTypeStatus.Date) { var Field1 = Convert.ToDateTime(item.Field1) == DateTime.MinValue ? null : Convert.ToDateTime(item.Field1); item.VisitingDate= Convert.ToDateTime(item.Field1) == DateTime.MinValue ? null : Convert.ToDateTime(item.Field1); item.Description += " " + Field1 + " "; } else if (selecetedClaimBasic.Field1Type == EnumFieldTypeStatus.Number) { var Field1 = Convert.ToDouble(item.Field1, CultureInfo.InvariantCulture); item.Description += " " + Field1 + " "; } else { item.Description += " " + item.Field1 + " "; } } if (selecetedClaimBasic.IsField2 == true) item.Description += selecetedClaimBasic.Field2 + " :"; if (selecetedClaimBasic.IsField2 == true && selecetedClaimBasic.Field2Type == EnumFieldTypeStatus.Date) { var Field2 = Convert.ToDateTime(item.Field2); if (Field2 == DateTime.MinValue) { Field2 = null; } item.VisitingDate = Field2; item.Description += " " + Field2 + " " + " "; } else if (selecetedClaimBasic.IsField2 == true && selecetedClaimBasic.Field2Type == EnumFieldTypeStatus.Number) { var Field2 = Convert.ToDouble(item.Field2, CultureInfo.InvariantCulture); item.Description += " " + Field2 + " " + " "; } else { item.Description += " " + item.Field2 + " " + " "; } if (selecetedClaimBasic.IsField3 == true) item.Description += selecetedClaimBasic.Field3 + " :"; //if (selecetedClaimBasic.IsField3 == true && selecetedClaimBasic.Field3Type == EnumFieldTypeStatus.Date) //{ // var Field3 = Convert.ToDateTime(item.Field3); // if (Field3 == DateTime.MinValue) // { // Field3 = null; // } // item.Description += " " + Field3 + " "; // item.VisitingDate = Field3; //} //else if (selecetedClaimBasic.IsField3 == true && selecetedClaimBasic.Field3Type == EnumFieldTypeStatus.Number) //{ // var Field3 = Convert.ToDouble(item.Field3, CultureInfo.InvariantCulture); // item.Description += " " + Field3 + " "; //} //else //{ // item.Description += " " + item.Field3 + " "; //} //if (selecetedClaimBasic.IsField4 == true) // item.Description += selecetedClaimBasic.Field4 + " :"; //if (selecetedClaimBasic.IsField4 == true && selecetedClaimBasic.Field4Type == EnumFieldTypeStatus.Date) //{ // var Field4 = Convert.ToDateTime(item.Field4); // if (Field4 == DateTime.MinValue) // { // Field4 = null; // } // item.VisitingDate = Field4; // item.Description += " " + Field4 + " "; //} //else if (selecetedClaimBasic.IsField4 == true && selecetedClaimBasic.Field4Type == EnumFieldTypeStatus.Number) //{ // var Field4 = Convert.ToDouble(item.Field4, CultureInfo.InvariantCulture); // item.Description += " " + Field4 + " "; //} //else //{ // item.Description += " " + item.Field4 + " "; //} if (selecetedClaimBasic.IsField5 == true) item.Description += selecetedClaimBasic.Field5 + " :"; if (selecetedClaimBasic.IsField5 == true && selecetedClaimBasic.Field5Type == EnumFieldTypeStatus.Date) { var Field5 = Convert.ToDateTime(item.Field5); if (Field5 == DateTime.MinValue) { Field5 = null; } item.VisitingDate = Field5; item.Description += " " + Field5 + " "; } else if (selecetedClaimBasic.IsField5 == true && selecetedClaimBasic.Field5Type == EnumFieldTypeStatus.Number) { var Field5 = Convert.ToDouble(item.Field5, CultureInfo.InvariantCulture); item.Description += " " + Field5 + " "; } else { item.Description += " " + item.Field5 + " "; } if (selecetedClaimBasic.IsField6 == true && selecetedClaimBasic.Field6Type == EnumFieldTypeStatus.Date) { var Field6 = Convert.ToDateTime(item.Field5); if (Field6 == DateTime.MinValue) { Field6 = null; } item.VisitingDate = Field6; item.Description += " " + Field6 + " "; } else if (selecetedClaimBasic.IsField6 == true && selecetedClaimBasic.Field6Type == EnumFieldTypeStatus.Number) { var Field6 = Convert.ToDouble(item.Field6, CultureInfo.InvariantCulture); item.Description += " " + Field6 + " "; } else { item.Description += " " + item.Field6 + " "; } } } } } //prevClaimRequisition.IRFileAttacments = new List(); //prevClaimRequisition.IRFileAttacments = _claimRequisitionService.GetIRFileAttachments(prevClaimRequisition.ID); } foreach (var item in prevClaimRequisition.ClaimRequisitionItems) { obsi = _claimBasicItemService.Get(item.ClaimBasicItemID); item.ClaimBasicName = obs?.Where(x => x.ID == item.ClaimBasicID)?.FirstOrDefault().ItemName; item.ClaimBasicItemName = obsi.Name; //File Retrieve // item.claimRequisitionFileAttacment = new FileAttachment(); //item.claimRequisitionFileAttacment = prevClaimRequisition.IRFileAttacments?.Where(x => x.RefchildID == item.ID)?.FirstOrDefault(); item.claimRequisitionFileAttacment = _claimRequisitionService.GetByRefChildId(prevClaimRequisition.ID, item.ID); if (item.claimRequisitionFileAttacment != null) { item.claimRequisitionFileAttacment.PreviousFileTobase64 = item.claimRequisitionFileAttacment == null ? null : item.claimRequisitionFileAttacment.FileTobase64; item.IsFileExist = item.claimRequisitionFileAttacment.PreviousFileTobase64 != null ? true : false; } } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(prevClaimRequisition); } [HttpGet] [Route("GetMyPendingList/{ids}/{fromDate}/{toDate}/")] public ActionResult GetMyPendingList(string ids, DateTime fromDate, DateTime toDate) { DataTable odata = null; try { ids = (ids == "null" || ids == "undefined") ? null : ids; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); odata = this._claimRequisitionService.GetPendingList((int)currentUser.EmployeeID, ids, fromDate, toDate); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(odata); } [HttpGet] [Route("getFilteredClaimReqsByIds/{ids}/{fromDate}/{toDate}/{employeeNo}/{employeeName}")] public ActionResult GetFilteredClaimReqsByIds(string ids, DateTime? fromDate, DateTime? toDate, string employeeNo, string employeeName) { DataSet ds = new DataSet(); List oClaimRequisitions = new List(); employeeNo = (employeeNo == "null" || employeeNo == "undefined") ? null : employeeNo; employeeName = (employeeName == "null" || employeeName == "undefined") ? null : employeeName; try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); ds = _claimRequisitionService.GetFilteredClaimReqsByIds(ids, fromDate == null ? DateTime.MinValue : (DateTime)fromDate, toDate == null ? DateTime.MinValue : (DateTime)toDate, employeeNo, employeeName); foreach (var row in ds.Tables[0].AsEnumerable()) { ClaimRequisition temp = new ClaimRequisition(); temp.ID = row["ClaimRequisitionID"] == null ? 0 : row.Field("ClaimRequisitionID"); temp.ClaimDate = !string.IsNullOrEmpty(row["ClaimDate"].ToString()) ? DateTime.Parse(row["ClaimDate"].ToString()) : DateTime.MinValue; temp.ClaimAmount = !string.IsNullOrEmpty(row["ClaimAmount"].ToString()) ? Convert.ToDouble(row["ClaimAmount"]) : 0; temp.EmailAddress = !string.IsNullOrEmpty(row["EmailAddress"].ToString()) ? row["EmailAddress"].ToString() : string.Empty; temp.Designation = !string.IsNullOrEmpty(row["Designation"].ToString()) ? row["Designation"].ToString() : string.Empty; temp.Name = !string.IsNullOrEmpty(row["NAME"].ToString()) ? row["NAME"].ToString() : string.Empty; temp.EmployeeNo = !string.IsNullOrEmpty(row["EmployeeNo"].ToString()) ? row["EmployeeNo"].ToString() : string.Empty; //temp.ToDate = !string.IsNullOrEmpty(row["ToDate"].ToString()) ? DateTime.Parse(row["ToDate"].ToString()) : null; //temp.CreatedDate = DateTime.Parse(row["CREATIONDATE"].ToString()); //temp.ApprovalDate = !string.IsNullOrEmpty(row["APPROVALDATE"].ToString()) ? DateTime.Parse(row["APPROVALDATE"].ToString()) : null; //temp.EmployeeId = row["EmployeeId"] == null ? 0 : row.Field("EmployeeId"); //temp.EmployeeNo = !string.IsNullOrEmpty(row["EMPLOYEENO"].ToString()) ? row["EMPLOYEENO"].ToString() : string.Empty; //temp.EmployeeName = !string.IsNullOrEmpty(row["EmployeeName"].ToString()) ? row["EmployeeName"].ToString() : string.Empty; ////temp.ApprovalNeeded = ; //temp.RejectComment = !string.IsNullOrEmpty(row["REJECTCOMMENT"].ToString()) ? row["REJECTCOMMENT"].ToString() : string.Empty; //temp.RequestDate = DateTime.Parse(row["LETTERREQUESTDATE"].ToString()); ////if ((enumwfStatus)int.Parse(row["WfStatus"].ToString()) == enumwfStatus.End) ////{ //// temp.StatusString = "Approved"; ////} ////else if ((enumwfStatus)int.Parse(row["WfStatus"].ToString()) == enumwfStatus.Decline) ////{ //// temp.StatusString = "Rejected"; ////} ////else ////{ //// temp.StatusString = !string.IsNullOrEmpty(row["Status"].ToString()) ? ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString() == "Approval_Not_Required" ? string.Empty : ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString().Replace("_", " ") : string.Empty; ////} //if ((enumwfStatus)int.Parse(row["WfStatus"].ToString()) == enumwfStatus.End) //{ // temp.StatusString = "Approved"; //} //else if ((enumwfStatus)int.Parse(row["WfStatus"].ToString()) == enumwfStatus.Decline) //{ // temp.StatusString = "Rejected"; //} //else if ((enumwfStatus)int.Parse(row["WfStatus"].ToString()) == enumwfStatus.Not_yet_Initiated) //{ // temp.StatusString = "Not Approved"; //} //else //{ // temp.StatusString = !string.IsNullOrEmpty(row["Status"].ToString()) ? ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString() == "Approval_Not_Required" ? string.Empty : ((EnumLetterRequestStatus)int.Parse(row["Status"].ToString())).ToString().Replace("_", " ") : string.Empty; //} oClaimRequisitions.Add(temp); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(oClaimRequisitions); } [HttpPost] [Route("ApproveRequisition")] public ActionResult ApproveRequisition(WFMovementTran otran) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); otran.FromEmployeeID = (int)currentUser.EmployeeID; try { _claimRequisitionService.ApproveClaimRequisition(otran); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("ApproveAllRequisition")] public ActionResult ApproveAllRequisition(List otranList) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { foreach (var item in otranList) { item.FromEmployeeID = (int)currentUser.EmployeeID; item.Remarks = ""; } _claimRequisitionService.ApproveClaimRequisitions(otranList); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("RejectRequisition")] public ActionResult RejectRequisition(WFMovementTran otran) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); otran.FromEmployeeID = (int)currentUser.EmployeeID; try { _claimRequisitionService.claimRequisitionReject(otran); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("RejectAllRequisition")] public ActionResult RejectAllRequisition(List otranList) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { foreach (var item in otranList) { item.FromEmployeeID = (int)currentUser.EmployeeID; item.Remarks = ""; } _claimRequisitionService.claimRequisitionRejects(otranList); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpGet] [Route("getClaimItemsForApprove/{id}")] public ActionResult GetClaimItemsForApprove(int id) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); WFMovementTran item = new WFMovementTran(); item.FromEmployeeID = (int)currentUser.EmployeeID; item.ID = id; try { this._claimRequisitionService.ApproveClaimRequisition(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpGet("getClaimRequisitionTranItemsForApproval")] public ActionResult GetClaimRequisitionTranItemsForApproval() { List obs = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { obs = _wfMovementTranService.GetClaimRequisitionTranItemsForApproval((int)currentUser.EmployeeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(obs); } [HttpGet] [Route("getAllClaimRequisitions/{fromDate}/{toDate}/{status}")] public ActionResult GetAllClaimRequisitions(DateTime? fromDate, DateTime? toDate, EnumClaimRequsitionStatus? status) { DataSet ds = new DataSet(); List oClaimRequisitions = new List(); try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); oClaimRequisitions = _claimRequisitionService.GetAllClaimRequisition(fromDate == null ? DateTime.MinValue : (DateTime)fromDate, toDate == null ? DateTime.MinValue : (DateTime)toDate, (int)currentUser.EmployeeID, status); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(oClaimRequisitions); } [HttpGet("getClaimRequisitionTranItemHistory/{claimId}")] public ActionResult GetClaimRequisitionTranItemHistory(int claimId) { List obs = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { obs = _wfMovementTranService.GetClaimRequisitionTranItemHistory(claimId, (int)currentUser.EmployeeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(obs); } [HttpPost] [Route("DeleteClaimRule")] public ActionResult DeleteClaimRule(ClaimRule item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _claimRuleService.DeleteClaimRuleGrades(item.ID); _claimRuleService.Delete(item.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpPost] [Route("DeleteClaimBasicItem")] public ActionResult DeleteClaimBasicItem(ClaimBasicItem item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _claimBasicItemService.Delete(item.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpGet] [Route("getClaimBasicItemCount")] public ActionResult GetClaimBasicItemCount() { List obs = new List(); try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); obs = _claimBasicService.GetClaimBasicItemCount(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(obs); } [HttpPost("getClaimReqsByEmployeeIds")] public ActionResult GetClaimReqsByEmployeeIds(dynamic data) { List oClaimRequisitions = new List(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string sEmpID = items["empIds"]== null ? null : (string)items["empIds"].ToObject(); DateTime fromDate = (DateTime)items["fromDate"].ToObject(); DateTime toDate = (DateTime)items["toDate"].ToObject(); EnumClaimPaymentType? paymentType = items["paymentStatus"]; EnumClaimWFStatus? approveStatus = items["approveStatus"]; string empBasicInfo = string.Empty; try { sEmpID = sEmpID == "null" ? null : sEmpID; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); oClaimRequisitions = _claimRequisitionService.GetClaimReqsByEmployeeIds(fromDate, toDate, sEmpID, (int)currentUser.UserID, approveStatus, paymentType); if (oClaimRequisitions.Count > 0) { foreach (ClaimRequisition item in oClaimRequisitions) { item.RequisitionString = EnumDescription.GetEnumDescription(item.RequsitionStatus); } } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(oClaimRequisitions); } [HttpPost] [Route("updateclaimrequisition")] public ActionResult UpdateClaimRequisition(ClaimRequisition item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); item.PaidBy = (int)currentUser.UserID; _claimRequisitionService.UpdateClaimPaymentType(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost("updateClaimbyClaimId")] public ActionResult UpdateClaimbyClaimId(dynamic data) { // List oClaimids = new List(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string oClaimids = items["claimIds"] == null ? null : (string)items["claimIds"].ToObject(); EnumClaimPaymentType? paymentType = (EnumClaimPaymentType)items["paymentType"].ToObject(); var remarks = ""; try { if(paymentType== EnumClaimPaymentType.Paid) { remarks = "Paid"; } else if (paymentType == EnumClaimPaymentType.With_Salary) { remarks = "With Salary"; } CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); _claimRequisitionService.UpdateClaimPaymentStatusByClaimId(oClaimids, paymentType,remarks,(int)currentUser.UserID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveClaimDisbursement")] public ActionResult SaveClaimDisbursement(ClaimDisbursement item) { string connectionString = _config.GetSection("dbSettings").GetSection("SqlCommandConnection").Value; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int startIndex = 0; if (item.IsNew) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } try { _claimDisbursementService.Save(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpGet] [Route("getUserLocation")] public ActionResult GetUserLocation() { List obs = new List(); try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); obs = _claimDisbursementService.GetUserLocation(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(obs); } [HttpGet] [Route("DeleteClaimDisbursement/{id}")] public ActionResult DeleteClaimDisbursement(int id) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _claimDisbursementService.Delete(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } //[HttpGet] //[Route("getClaimDisbursementByReport/{fromDate}/{toDate}/{employeeIds}")] //public ActionResult GetClaimDisbursementByReport(DateTime fromDate, DateTime toDate, string employeeIds) //{ // List obs = new List(); // try // { // employeeIds = employeeIds == "null" || employeeIds == "undefined" ? null : employeeIds; // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // obs = _claimRequisitionService.GetClaimDisbursementReport(employeeIds, fromDate, toDate, (int)currentUser.UserID); // } // catch (Exception ex) // { // return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); // } // return Ok(obs); //} [HttpPost("getClaimDisbursementByReport")] public ActionResult GetClaimDisbursementByReport(dynamic data) { List obs = new List(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string sEmpID = items["empIds"] == null ? null : (string)items["empIds"].ToObject(); DateTime fromDate = (DateTime)items["fromDate"].ToObject(); DateTime toDate = (DateTime)items["toDate"].ToObject(); EnumClaimPaymentType? paymentType = items["paymentStatus"]; EnumClaimWFStatus? approveStatus = items["approveStatus"]; string empBasicInfo = string.Empty; try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); obs = _claimRequisitionService.GetClaimDisbursementReport(sEmpID, fromDate, toDate, (int)currentUser.UserID, approveStatus, paymentType); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(obs); } [HttpGet] [Route("getClaimReportEcport/{fromDate}/{toDate}/{status}")] public ActionResult GetClaimReportEcport(DateTime? fromDate, DateTime? toDate, EnumClaimRequsitionStatus? status) { DataSet ds = new DataSet(); List claimRequisitionReportItems = new List(); try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); claimRequisitionReportItems = _claimRequisitionService.GetClaimReportEcport(fromDate == null ? DateTime.MinValue : (DateTime)fromDate, toDate == null ? DateTime.MinValue : (DateTime)toDate, status, (int)currentUser.EmployeeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(claimRequisitionReportItems); } [HttpGet] [Route("GetClearanceAmount/{empid}")] public ActionResult GetClearanceAmount(int empid) { double amount = 0; try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); amount = _claimRequisitionService.GetClearanceAmount(empid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(amount); } [HttpGet] [Route("GetPrevAdavancedAmountbyEmployeeId")] public ActionResult GetPrevAdavancedAmountbyEmployeeId() { List oClaimRequisitions = null; double amount = 0; try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); oClaimRequisitions = _claimRequisitionService.GetPrevAdavancedAmountbyEmployeeId((int)currentUser.EmployeeID); if(oClaimRequisitions != null && oClaimRequisitions.Count > 0) { amount = oClaimRequisitions.Sum(x => x.ClaimAmount); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(amount); } [HttpGet] [Route("GetBalanceEmployeeId")] public ActionResult GetBalanceEmployeeId() { ClaimCurrentBalance claimCurrentbalance = null; try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); claimCurrentbalance = _claimBalaceService.GetCurrentBalancebyEmployeeId((int)currentUser.EmployeeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(claimCurrentbalance); } #endregion } }