using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using HRM.BO; using HRM.BO.Basic; using HRM.DA; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Ease.Core.DataAccess; using System.Data; using System.IO; using HRM.DA.Service.Tax; namespace HRM.UI.Controllers.Basic { [ApiController] [Route("api/HRBasic")] [Authorize] public class BasicController : ControllerBase { public BasicController(IAllowanceDeductionService allowanceDeductionService, IBonusService bonusService, ICategoryService categoryService, IDepartmentService departmentService, IDesignationService designationService, IGradeService gradeService, IGradeSegmentService gradeSegmentService, ILocationService locationService, IEmployeeOverTimeService employeeOverTimeService, ITermService termService, IOccupationService occupationService, IEducationLevelService educationLevelService, ITrainingTypeService trainingTypeService, IEducationTypeService educationTypeService, INominationPurposeService nominationPurposeService, IBankService bankService, IBranchService brachService, ICostcenterService icostcenterService, ILoanService iLoanService, IReligionService religionService, IProcessItemService processItemService, ISalaryComponent salarycoponenet, IHREmployeeService hrEmployeeService, ICountryService countryService, INatureOfTrainingService natureOfTrainingService, IInstitutionService institutionService, IRelationService relationService, IDistrictService districtService, IThanaService thanaService, IResultTypeService resultTypeService, IDisciplineService disciplineService, IJobDefinitionService jobDefinitionService, INationalityService nationalityService, IReminderService reminderService, IHrNotificationService hrNotificationService, IPayrollPaymentComponent paycomponenet, IAchievementService achievementService, IExtraCurricularActivityService extraCurricularActivityService, IHobbyService hobbyService, IOtherTalentService otherTalentService, IComponentUploadSetupService componentUploadSetupService, IUploadedComponentService uploadedComponentService) { this._allowanceDeductionService = allowanceDeductionService; this._bonusService = bonusService; this._categoryService = categoryService; this._departmentService = departmentService; this._designationService = designationService; this._gradeService = gradeService; this._gradeSegmentService = gradeSegmentService; this._locationService = locationService; this._employeeOverTimeService = employeeOverTimeService; this._tempService = termService; this._occupationService = occupationService; this._educationLevelService = educationLevelService; this._trainingTypeService = trainingTypeService; this._educationTypeService = educationTypeService; this._nominationPurposeService = nominationPurposeService; this._bankService = bankService; this._branchService = brachService; this._costCenterService = icostcenterService; this._loanService = iLoanService; this._processItemService = processItemService; this._salaryComponent = salarycoponenet; this._hrEmployeeService = hrEmployeeService; this._countryService = countryService; this._natureOfTrainingService = natureOfTrainingService; this._institutionService = institutionService; this._relationService = relationService; this._districtService = districtService; this._thanaService = thanaService; this._resultTypeService = resultTypeService; this._disciplineService = disciplineService; this._religionService = religionService; this._jobDefinitionService = jobDefinitionService; _nationalityService = nationalityService; _reminderService = reminderService; _hrNotificationService = hrNotificationService; _paycomponent = paycomponenet; _achievementService = achievementService; _extraCurricularActivityService = extraCurricularActivityService; _hobbyService = hobbyService; _otherTalentService = otherTalentService; _componentUploadSetupService = componentUploadSetupService; _uploadedComponentService = uploadedComponentService; } private readonly IAllowanceDeductionService _allowanceDeductionService; private readonly IBonusService _bonusService; private readonly ICategoryService _categoryService; private readonly IDepartmentService _departmentService; private readonly IDesignationService _designationService; private readonly IGradeService _gradeService; private readonly IGradeSegmentService _gradeSegmentService; private readonly ILocationService _locationService; private readonly IEmployeeOverTimeService _employeeOverTimeService; private readonly ITermService _tempService; private readonly IOccupationService _occupationService; private readonly IEducationLevelService _educationLevelService; private readonly ITrainingTypeService _trainingTypeService; private readonly IEducationTypeService _educationTypeService; private readonly INominationPurposeService _nominationPurposeService; private readonly IBankService _bankService; private readonly IBranchService _branchService; private readonly ICostcenterService _costCenterService; private readonly ILoanService _loanService; private readonly IProcessItemService _processItemService; private readonly ISalaryComponent _salaryComponent; private readonly IHREmployeeService _hrEmployeeService; private readonly ICountryService _countryService; private readonly INatureOfTrainingService _natureOfTrainingService; private readonly IInstitutionService _institutionService; private readonly IRelationService _relationService; private readonly IDistrictService _districtService; private readonly IThanaService _thanaService; private readonly IResultTypeService _resultTypeService; private readonly IDisciplineService _disciplineService; private readonly IReligionService _religionService; private readonly IJobDefinitionService _jobDefinitionService; private readonly INationalityService _nationalityService; private readonly IReminderService _reminderService; private readonly IHrNotificationService _hrNotificationService; private readonly IPayrollPaymentComponent _paycomponent; private readonly IAchievementService _achievementService; private readonly IExtraCurricularActivityService _extraCurricularActivityService; private readonly IHobbyService _hobbyService; private readonly IOtherTalentService _otherTalentService; private readonly IComponentUploadSetupService _componentUploadSetupService; private readonly IUploadedComponentService _uploadedComponentService; [HttpGet("getAllowance")] public ActionResult getAllowance() { List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _allowanceDeductionService.GetAllowance(EnumStatus.Active, (int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getDeduction")] public ActionResult getDeduction() { List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _allowanceDeductionService.GetDeduction(EnumStatus.Active, (int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("GetAllAllowanceDeduction/{allowOrDeduct}/{status}/{code}/{name}")] public ActionResult GetAllAllowanceDeduction(EnumAllowOrDeduct allowOrDeduct, EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _allowanceDeductionService.GetAllAllowance(payrollTypeId, allowOrDeduct, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getAllowanceByID/{id}")] public ActionResult GetAllowanceByID(int id) { AllowanceDeduction item = new AllowanceDeduction(); try { item = _allowanceDeductionService.Get(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getAllowanceBy2Enum/{periodicity}/{allowOrDeduct}")] public ActionResult GetAllowanceBy2Enum(int periodicity, int allowOrDeduct) { List items = new List(); try { items = _allowanceDeductionService.GetAllowance((EnumPeriodicity)periodicity, (EnumAllowOrDeduct)allowOrDeduct); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getAllowanceBy3Enum/{periodicity}/{entitleType}/{allowOrDeduct}")] public ActionResult GetAllowanceBy3Enum(int periodicity, int entitleType, int allowOrDeduct) { List items = new List(); try { items = _allowanceDeductionService.GetAllowance((EnumPeriodicity)periodicity, (EnumEntitleType)entitleType, (EnumAllowOrDeduct)allowOrDeduct); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Bonus [HttpGet("getAllBonus/{status}/{code}/{name}")] public ActionResult GetAllBonus(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _bonusService.GetAllBonus(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getBonusByID/{id}")] public ActionResult GetBonusByID(int id) { Bonus item = new Bonus(); try { item = _bonusService.Get(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getBonusReligions/{bonusID}")] public ActionResult GetBonusReligions(int bonusID) { List items = new List(); try { items = _bonusService.GetReligions(bonusID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Category [HttpGet("getAllCategory/{status}/{code}/{name}")] public ActionResult GetAllCategory(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _categoryService.GetAllCategory(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getCategoryByID/{id}")] public ActionResult getCategoryByID(int id) { try { return Ok(this._categoryService.Get(id)); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpGet("payrollTypeID/{id}")] public ActionResult Get(int id) { Category item = new Category(); try { item = _categoryService.Get(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } // Department [HttpGet("getAllDepartment/{status}/{code}/{name}")] public ActionResult GetAllDepartment(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _departmentService.GetAllDepartment(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getDepartmentByID/{id}")] public ActionResult getDepartmentByID(int id) { try { return Ok(this._departmentService.Get(id)); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpGet("getAllBank/{status}/{code}/{name}")] public ActionResult getAllBank(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List items = new List(); try { items = _bankService.Get(status, (int) currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getBranchesByBankID/{bankid}/{status}/{code}/{name}")] public ActionResult getBranchesByBankID(int bankid, EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); try { items = _branchService.GetChild(bankid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getAllBranches/{status}/{code}/{name}")] public ActionResult getAllBranches(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _branchService.Get(status, (int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getAllOccupation/{status}/{code}/{name}")] public ActionResult getAllOccupation(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); try { items = _occupationService.Get(status); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getAllEducationLevel/{status}/{code}/{name}")] public ActionResult getAllEducationLevel(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); try { items = _educationLevelService.Get(status); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getAllCostCenter/{status}/{code}/{name}")] public ActionResult getAllCostCenter(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _costCenterService.GetAllCostCenter(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getCostCenter/{id}")] public ActionResult getCostCenter(int id) { Costcenter item = new Costcenter(); try { item = _costCenterService.Get(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getGradeByID/{id}")] public ActionResult getGradeByID(int id) { try { return Ok(this._gradeService.Get(id)); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } // Grade [HttpGet("getAllGrade/{status}/{code}/{name}")] public ActionResult GetAllGrade(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _gradeService.GetAllGrade(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // GradeSegment [HttpGet("getAllGradeSegment/{status}/{code}/{name}")] public ActionResult GetAllGradeSegment(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _gradeSegmentService.GetAllGradeSegment(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Loan [HttpGet("GetAllLoan/{status}/{code}/{name}")] public ActionResult GetAllLoan(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); try { items = _loanService.Get(status); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Location [HttpGet("GetAllLocation/{status}/{code}/{name}")] public ActionResult GetAllLocation(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _locationService.GetAllLocation(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getLocationByID/{id}")] public ActionResult getLocationByID(int id) { try { return Ok(this._locationService.Get(id)); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } // Term [HttpGet("getAllTerm/{status}/{code}/{name}")] public ActionResult GetAllTerm(EnumStatus status, string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { items = _tempService.GetAllTerm(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Occupation [HttpGet("getAllOccupation")] public ActionResult GetAllOccupation() { List items = new List(); try { items = _occupationService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } //// Education Level //[HttpGet("getAllEducationLevel")] //public ActionResult GetAllEducationLevel() //{ // List items = new List(); // try // { // items = _educationLevelService.Get(); // } // catch (Exception ex) // { // return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); // } // return Ok(items); //} // Training Type [HttpGet("getAllTrainingType")] public ActionResult GetAllTrainingType() { List items = new List(); try { items = _trainingTypeService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Education Type [HttpGet("getAllEducationType")] public ActionResult GetAllEducationType() { List items = new List(); try { items = _educationTypeService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Nomination Purpose [HttpGet("getAllNominationPurpose")] public ActionResult GetAllNominationPurpose() { List items = new List(); try { items = _nominationPurposeService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // ProcessItem [HttpGet("getForTHeadGroup")] public ActionResult GetForTHeadGroup() { List items = new List(); try { items = _processItemService.GetForTHeadGroup(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getSalaryCoponentBenefits")] public ActionResult getSalaryCoponentBenefits() { List items = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = this._salaryComponent.Benefits((int) ouser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getSalaryCoponent")] public ActionResult getSalaryCoponent() { List items = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = this._salaryComponent.Components((int) ouser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // EmpRelation [HttpGet("getEmpRelation/{id}")] public ActionResult GetEmpRelation(int id) { List items = new List(); try { items = _hrEmployeeService.GetEmpRelations(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getAllEmpRelations")] public ActionResult GetAllEmpRelations() { List items = new List(); try { items = _hrEmployeeService.GetAllEmpRelations(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Relation [HttpGet("getAllRelations")] public ActionResult GetAllRelations() { List items = new List(); try { items = _relationService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // EmpRelative [HttpGet("getEmpRelatives/{id}")] public ActionResult GetEmpRelatives(int id) { List items = new List(); try { items = _hrEmployeeService.GetEmpRelatives(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Designation [HttpGet("getDesignationByID/{id}")] public ActionResult getDesignationByID(int id) { try { return Ok(this._designationService.Get(id)); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpGet("getAllDesignation/{status}/{code}/{name}")] public ActionResult GetAllDesignation(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 items = new List(); try { items = _designationService.GetAllDesignation(payrollTypeId, status, code, name); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } // Country [HttpGet("getAllCountries")] public ActionResult GetAllCountries() { List items = new List(); try { items = _countryService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Nature of Training [HttpGet("getAllNatureOfTrainings")] public ActionResult GetAllNatureOfTrainings() { List items = new List(); try { items = _natureOfTrainingService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // institution [HttpGet("getAllInstitutions")] public ActionResult GetAllInstitutions() { List items = new List(); try { items = _institutionService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // District [HttpGet("getAllDistricts")] public ActionResult GetAllDistricts() { List items = new List(); try { items = _districtService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getDistrictById/{id}")] public ActionResult GetDistrictById(int id) { District item = new District(); try { item = _districtService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } // Thana [HttpGet("getAllThanas/{id}")] public ActionResult GetAllThanas(int id) { List items = new List(); try { items = _thanaService.GetByDistID(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getThanaById/{id}")] public ActionResult GetThanaById(int id) { Thana item = new Thana(); try { item = _thanaService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } // Result type [HttpGet("getAllResultTypesByStatus/{status}")] public ActionResult GetAllResultTypesByStatus(EnumStatus status) { List items = new List(); try { items = _resultTypeService.Get(status); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Disciple [HttpGet("getAllDiscipline")] public ActionResult GetAllDiscipline() { List items = new List(); try { items = _disciplineService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Religion [HttpGet("getAllReligion")] public ActionResult GetAllReligion() { List items = new List(); try { items = _religionService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Job Definition [HttpPost] [Route("saveJobDefinition")] public ActionResult SaveJobDefinition(JobDefinition item) { try { var isNew = item.ID <= 0; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (isNew) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } _jobDefinitionService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getAllJobDefinitions")] public ActionResult GetAllJobDefinitions() { List items = new List(); try { items = _jobDefinitionService.GetAll(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getJobDefinition/{id}")] public ActionResult GetJobDefinition(int id) { JobDefinition item = null; try { item = _jobDefinitionService.GetByID(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost] [Route("deleteJobDefinition")] public ActionResult DeleteJobDefinition(JobDefinition item) { try { _jobDefinitionService.DeleteJobDefinition(item.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getJobDefinitionForApprovedData/{id}")] public ActionResult GetJobDefinitionForApprovedData(int id) { JobDefinition item = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List grades = new GradeService().Get(EnumStatus.Regardless, (int) currentUser.PayrollTypeID); List designations = new DesignationService().Get(EnumStatus.Regardless, (int) currentUser.PayrollTypeID); List departments = new DepartmentService().Get(EnumStatus.Regardless, (int) currentUser.PayrollTypeID); try { item = _jobDefinitionService.GetJobDefinitionById(id); if (item != null) { var grd = grades.FirstOrDefault(d => d.ID == item.GradeId); if (grd != null) item.GradeName = grd.Name; var designation = designations.FirstOrDefault(d => d.ID == item.DesignationId); if (designation != null) item.DesignationName = designation.Name; var department = departments.FirstOrDefault(d => d.ID == item.DepartmentId); if (department != null) item.DepartmentName = department.Name; if (item.RevisionDate != null) { item.RevisionDateString = item.RevisionDate.ToString("dd/MM/yyyy"); } if (item.JdEducationList != null && item.JdEducationList.Count > 0) { item.EducationListName = string.Join(",", item.JdEducationList?.Select(x => x.JdEducationName)?.ToList()); } } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpGet("GetByLevelIDs/{ids}")] public ActionResult GetByLevelIDs(string ids) { //JobDefinition item = null; List items = new List(); try { items = _educationLevelService.GetByLevelIDs(ids); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("GetByIDs/{ids}")] public ActionResult GetByIDs(string ids) { //JobDefinition item = null; List items = new List(); try { items = _disciplineService.GetByIDs(ids); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Nationality [HttpGet("getAllNationality")] public ActionResult GetAllNationality() { List items = new List(); try { items = _nationalityService.Get(EnumStatus.Active); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getReminders")] public ActionResult GetReminders() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); List items = new List(); try { items = _reminderService.Get(employeeId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpPost] [Route("saveReminder")] public ActionResult SaveReminder(Reminder item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); try { item.EmployeeId = employeeId; _reminderService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteReminder")] public ActionResult DeleteReminder(Reminder item) { try { _reminderService.Delete(item.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet] [Route("getAllHrNotifications")] public ActionResult GetAllHrNotifications() { List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _hrNotificationService.GetAllNew(currentUser.PayrollTypeID ?? 0); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } // Every company update / HR notification the signed-in employee can see // (ESS "View all" page). The employee comes from the token, not the URL. [HttpGet] [Route("getMyHrNotifications")] public ActionResult GetMyHrNotifications() { List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { if (currentUser.EmployeeID != null) { items = _hrNotificationService.GetForEmployee(currentUser.PayrollTypeID ?? 0, (int)currentUser.EmployeeID); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet] [Route("getHrNotification/{id}")] public ActionResult GetHrNotification(int id) { HrNotification item = null; try { item = _hrNotificationService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(item); } [HttpPost] [Route("saveHrNotification")] public ActionResult SaveHrNotification(HrNotification item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { if (item != null && item.IsNew == true) { item.PayrollTypeID = currentUser.PayrollTypeID ?? 0; } if (!item.IsNew) { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } _hrNotificationService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteHrNotification")] public ActionResult DeleteHrNotification(HrNotification item) { try { _hrNotificationService.Delete(item.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet] [Route("getPayrollPayrollComponenet")] public ActionResult getPayrollPayrollComponenet() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List cops = new List(); try { cops = _paycomponent.get((int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(cops); } [HttpGet("getOpiItem")] public ActionResult getOpiItem() { List items = new List(); try { OpiItemService opiItemService = new OpiItemService(); items = opiItemService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost("uploadHallOfFame")] //[AllowAnonymous] public ActionResult uploadHallOfFame() { HallOfFame item = new HallOfFame(); string base64String = ""; try { var fdata = Request.Form.Files["File"]; item.Code = Convert.ToString(Request.Form["code"]); item.Tittle = Convert.ToString(Request.Form["title"]); item.Description = Convert.ToString(Request.Form["description"]); item.EmployeeID = Convert.ToInt32(Request.Form["employeeID"]); item.EmployeeNo = Convert.ToString(Request.Form["employeeNo"]); item.EmployeeName = Convert.ToString(Request.Form["employeeName"]); item.DepartmentName = Convert.ToString(Request.Form["departmentName"]); item.DesignationName = Convert.ToString(Request.Form["designationName"]); #region to save locally //for deployment //string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "assets", "halloffame"); //for development //string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "ClientApp","src", "assets", "halloffame"); //if (!Directory.Exists(directoryPath)) //{ // Directory.CreateDirectory(directoryPath); //} #endregion using (var ms = new MemoryStream()) { fdata.CopyTo(ms); item.FileData = ms.ToArray(); item.FileName = item.Code + ".jpg"; #region to save locally //byte[] textAsBytes = ms.ToArray(); //base64String = Convert.ToBase64String(textAsBytes); //string filePath = Path.Combine(directoryPath, item.FileName); //System.IO.File.WriteAllBytes(filePath, (byte[])item.FileData); #endregion this._hrNotificationService.UploadHallOfFame(item); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(base64String); } [HttpGet("loadHallOfFameData")] public ActionResult LoadHallOfFameData() { DataTable dt = new DataTable(); try { dt = _hrNotificationService.GetHallOfFame(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(dt); } [HttpPost] [Route("deleteHallOfFame")] public ActionResult DeleteHallOfFame(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int Id = item["Id"].ToObject(); try { DataTable hallOfFameItem = _hrNotificationService.GetHallOfFame(); if (hallOfFameItem == null) { return NotFound("Hall of Fame item not found."); } #region to save Locally //for deployment //string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "assets", "halloffame"); //for development //string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "ClientApp", "src", "assets", "halloffame"); //string fileName =""; //foreach(DataRow oRow in hallOfFameItem.Rows) //{ // if (Convert.ToInt32(oRow["HallOfFameID"])==Id) // { // fileName = oRow["FileName"].ToString(); // } //} //string filePath = Path.Combine(directoryPath, fileName); //if (System.IO.File.Exists(filePath)) //{ // System.IO.File.Delete(filePath); //} #endregion _hrNotificationService.DeleteHallOfFame(Id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveLegalTracking")] public ActionResult saveLegalTracking(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int legalTrackingID = item["legalTrackingID"].ToObject(); string name = item["name"].ToObject(); string shortDescription = item["shortDescription"].ToObject(); string detailDescription = item["detailDescription"].ToObject(); string nextAction = item["nextAction"].ToObject(); string nextActionDescription = item["nextActionDescription"].ToObject(); DateTime fromDate = item["fromDate"].ToObject(); DateTime toDate = item["toDate"].ToObject(); DateTime nextNotificationDate = item["nextNotificationDate"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _hrNotificationService.SaveLegalTracking(legalTrackingID, name, shortDescription, detailDescription, nextAction, nextActionDescription, fromDate, toDate, nextNotificationDate,(int)currentUser.PayrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getLegalTrackingData")] public ActionResult getLegalTrackingData() { DataTable dt = new DataTable(); try { dt = _hrNotificationService.GetLegalTracking(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(dt); } [HttpPost] [Route("deleteLegalTracking")] public ActionResult DeleteLegalTracking(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int Id = item["Id"].ToObject(); try { _hrNotificationService.DeleteLegalTracking(Id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getBranches")] public ActionResult GetBranches() { List items = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _branchService.GetBranches(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("GetAchievements")] public ActionResult GetAchievements() { List items = new List(); try { items = _achievementService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("GetExtraCurricularActivities")] public ActionResult GetExtraCurricularActivities() { List items = new List(); try { items = _extraCurricularActivityService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("GetHobbies")] public ActionResult GetHobbies() { List items = new List(); try { items = _hobbyService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("GetOtherTalents")] public ActionResult GetOtherTalents() { List items = new List(); try { items = _otherTalentService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getThanas")] public ActionResult GetThanas() { List items = new List(); try { items = _thanaService.Get(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } #region Component Upload (as GP) //Component Upload Setup [HttpGet("getComponentUploadSetups")] [Authorize(Roles = "User")] public ActionResult getComponentUploadSetups() { List detailedItems = new List(); try { List allSetups = _componentUploadSetupService.Get(); List employeeIds = allSetups .SelectMany(x => new[] { x.EmployeeID, x.ApproverID }) .Where(id => id > 0) .Distinct() .ToList(); Dictionary employeeMap = employeeIds.Count > 0 ? new EmployeeService().Get(string.Join(",", employeeIds)) .GroupBy(e => e.ID) .ToDictionary(g => g.Key, g => g.First()) : new Dictionary(); foreach (var group in allSetups.GroupBy(x => x.EmployeeID)) { Employee emp = employeeMap.ContainsKey(group.Key) ? employeeMap[group.Key] : null; if (emp == null) continue; List empSetups = group.ToList(); ComponentUploadSetup first = empSetups.First(); Employee appr = employeeMap.ContainsKey(first.ApproverID) ? employeeMap[first.ApproverID] : null; ComponentUploadSetup item = new ComponentUploadSetup(); item.ID = first.ID; item.Description = string.Join(", ", empSetups.Select(s => s.Description)); item.EmployeeID = emp.ID; item.EmployeeName = emp.EmployeeNo + "-" + emp.Name; item.ApproverID = appr != null ? appr.ID : 0; item.ApproverName = appr != null ? appr.EmployeeNo + "-" + appr.Name : string.Empty; item.DamageManagementDescription = string.Join(", ", empSetups.Select(s => s.IsDamageManagement ? "Yes" : "No")); detailedItems.Add(item); } detailedItems = detailedItems.OrderBy(o => o.Description).ToList(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(detailedItems); } [HttpGet("getAllComponentUploadSetups")] [Authorize(Roles = "User")] public ActionResult getAllComponentUploadSetups() { List allItems = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { allItems = _componentUploadSetupService.LoadComponentType(currentUser.PayrollTypeID.GetValueOrDefault()); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(allItems); } [HttpGet("getComponentUploadSetupsByEmpId/{id}")] [Authorize(Roles = "User")] public ActionResult getComponentUploadSetupsByEmpId(int id) { List allItems = new List(); try { allItems = _componentUploadSetupService.Get(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(allItems); } [HttpPost] [Authorize(Roles = "User")] [Route("saveComponentUploadSetups")] public ActionResult saveComponentUploadSetups(List items) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { if (items == null || items.Count == 0) return StatusCode(StatusCodes.Status400BadRequest, "Please add at least one component to save."); // An employee can have at most one approver. (One approver may still serve many employees.) Dictionary> existingByEmployee = new Dictionary>(); foreach (var empGroup in items.GroupBy(x => x.EmployeeID)) { int empId = empGroup.Key; List approverIds = empGroup.Select(x => x.ApproverID).Distinct().ToList(); if (empId <= 0 || approverIds.Any(a => a <= 0)) return StatusCode(StatusCodes.Status400BadRequest, "Employee and Approver are required."); if (approverIds.Count > 1) return StatusCode(StatusCodes.Status400BadRequest, "An employee can have only one approver."); int approverId = approverIds[0]; if (empId == approverId) return StatusCode(StatusCodes.Status400BadRequest, "Employee and Approver cannot be the same."); List existing = _componentUploadSetupService.Get(empId); existingByEmployee[empId] = existing; // Reject if the employee already has a DIFFERENT approver on rows that are not part of this batch. bool hasDifferentApprover = existing.Any(x => x.ApproverID != approverId && items.All(i => i.ID != x.ID)); if (hasDifferentApprover) return StatusCode(StatusCodes.Status400BadRequest, "This employee already has a different approver. Keep the same approver for an employee, or remove the existing setup first."); } // Description is resolved server-side from the component master (client sends only the numeric keys). List componentMaster = _componentUploadSetupService.LoadComponentType(currentUser.PayrollTypeID.GetValueOrDefault()); foreach (ComponentUploadSetup item in items) { ComponentUploadSetup master = componentMaster.FirstOrDefault( c => c.ComponentType == item.ComponentType && c.ItemID == item.ItemID); if (master != null) { item.Description = master.Description; } else if (!item.IsNew && existingByEmployee.TryGetValue(item.EmployeeID, out var empRows)) { // Component no longer in master: keep whatever description the stored row already has. ComponentUploadSetup stored = empRows.FirstOrDefault(r => r.ID == item.ID); if (stored != null) item.Description = stored.Description; } if (string.IsNullOrWhiteSpace(item.Description)) return StatusCode(StatusCodes.Status400BadRequest, "One of the selected components is invalid."); if (item.IsNew) { if(currentUser.EmployeeID != null) item.CreatedBy = (int)currentUser.EmployeeID; item.CreatedDate = DateTime.Now; } else { if (currentUser.EmployeeID != null) item.ModifiedBy = (int)currentUser.EmployeeID; item.ModifiedDate = DateTime.Now; } } _componentUploadSetupService.Save(items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteComponentSetup")] [Authorize(Roles = "User")] public ActionResult deleteComponentSetup(ComponentUploadSetup item) { try { _componentUploadSetupService.Delete(item.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteSingleComponent")] [Authorize(Roles = "User")] public ActionResult deleteSingleComponent(ComponentUploadSetup item) { try { _componentUploadSetupService.DeleteSingleComponent(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getEmpComponentUploadSetups")] [Authorize(Roles = "EssUpload")] public ActionResult getEmpComponentUploadSetups() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List componentUploadSetups = new List(); List empComponentUploadSetups = new List(); List items = new List(); try { int employeeId = currentUser.EmployeeID.GetValueOrDefault(); componentUploadSetups = _componentUploadSetupService.LoadComponentType(currentUser.PayrollTypeID.GetValueOrDefault()); empComponentUploadSetups = _componentUploadSetupService.Get(employeeId).Where(a => a.IsDamageManagement == false).ToList(); items = componentUploadSetups.Join(empComponentUploadSetups, c => new { c.ItemID, c.Description }, o => new { o.ItemID, o.Description }, (c, o) => new ComponentUploadSetup { Description = c.Description, ItemID = c.ItemID, ComponentType = c.ComponentType }).ToList(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getExistingUploadedComponent/{componentID}/{type}")] [Authorize(Roles = "EssUpload")] public ActionResult getExistingUploadedComponent(int componentID, EnumComponentType type) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); UploadedComponent componentUpload = null; try { int employeeId = currentUser.EmployeeID.GetValueOrDefault(); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); DateTime salaryMonth = (DateTime)currentUser.NextPayProcessDate; componentUpload = _uploadedComponentService.GetExistingComponent(employeeId, componentID, type, salaryMonth); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(componentUpload); } [HttpGet("getComponentSetupEmployees")] [Authorize(Roles = "EssApprove")] public ActionResult getComponentSetupEmployees() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List oSenderEmployees = new List(); try { int employeeId = currentUser.EmployeeID.GetValueOrDefault(); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); DateTime salaryMonth = (DateTime)currentUser.NextPayProcessDate; List oEmployees = new EmployeeService().GetAllLive(); List oComponentUploadSetups = _componentUploadSetupService.GetByApproverID(employeeId); foreach (var item in oComponentUploadSetups) { var oEmployee = oEmployees.Find(e => e.ID == item.EmployeeID); if (oEmployee != null && !oSenderEmployees.Any(e => e.ID == oEmployee.ID)) { oSenderEmployees.Add(oEmployee); } } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(oSenderEmployees); } //[HttpGet("getComponentSetupForEmployee/{empId}")] //[Authorize(Roles = "EssApprove")] //public ActionResult getComponentSetupForEmployee(int empId) //{ // CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); // List oSenderEmployees = new List(); // List _oUploadedComponents = new List(); // List _oTempComponentTypes = null; // List _oComponentTypes = new List(); // try // { // int employeeId = currentUser.EmployeeID.GetValueOrDefault(); // int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); // DateTime salaryMonth = (DateTime)currentUser.NextPayProcessDate; // _oUploadedComponents = _uploadedComponentService.Get(empId, salaryMonth); // _oTempComponentTypes = _componentUploadSetupService.LoadComponentType(currentUser.PayrollTypeID.GetValueOrDefault()); // _oUploadedComponents.ForEach(uc => _oComponentTypes.Add(_oTempComponentTypes.Where(ct => ct.ItemID == uc.ComponentID && ct.ComponentType == uc.ComponentType).FirstOrDefault())); // } // catch (Exception e) // { // return StatusCode(StatusCodes.Status500InternalServerError, e.Message); // } // return Ok(_oComponentTypes); //} [HttpPost] [Route("getUploadedComponentsMonthwise")] [Authorize(Roles = "User")] public ActionResult getUploadedComponentsMonthwise(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime selectedMonth = item["selectedMonth"].ToObject(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DataTable _oUploadedComponents = new DataTable(); try { _oUploadedComponents = _componentUploadSetupService.GetUploadedComponent(selectedMonth); //DataRow dr = _oUploadedComponents.NewRow(); //dr["ComponentId"] = 0; //dr["ComponentName"] = "All"; //_oUploadedComponents.Rows.Add(dr); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(_oUploadedComponents); } [HttpGet("getUploadedComponentSetupForEmployee/{empId}/{componentID}/{componentType}/{description}")] [Authorize(Roles = "EssApprove")] public ActionResult getUploadedComponentSetupForEmployee(int empId, int componentID, EnumComponentType componentType, string description) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List oSenderEmployees = new List(); List _oUploadedComponents = new List(); List _oTempComponentTypes = null; UploadedComponent component = null; DataTable oDataTable = new DataTable(); try { List oEmployees = new EmployeeService().GetAllLive(); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); DateTime salaryMonth = (DateTime)currentUser.NextPayProcessDate; _oUploadedComponents = _uploadedComponentService.Get(empId, salaryMonth); //EnumComponentType componentType = _oTempComponentTypes.Where(c => c.ItemID == componentID && c.Description == description).Select(c => (EnumComponentType)c.ComponentType).FirstOrDefault(); //string componentDescription = _oTempComponentTypes.Where(c => c.ItemID == componentID && c.Description == description).Select(c => c.Description).FirstOrDefault(); component = _oUploadedComponents.Where(c => c.ComponentID == componentID && c.ComponentType == componentType).FirstOrDefault(); if (component != null) { if (component.ApprovedBy == null || component.ApprovedBy == 0) { Employee employee = null; DataRow oDataRow = null; oDataTable.Columns.Add("ComponentName"); oDataTable.Columns.Add("EmployeeNo"); oDataTable.Columns.Add("EmployeeName"); oDataTable.Columns.Add("Amount"); oDataTable.Columns.Add("SendDate"); foreach (UploadedComponentEmp item in component.UploadedComponentEmps) { oDataRow = oDataTable.NewRow(); employee = oEmployees.Find(e => e.ID == item.EmployeeID); oDataRow["ComponentName"] = description; oDataRow["EmployeeNo"] = employee != null ? employee.EmployeeNo : string.Empty; oDataRow["EmployeeName"] = employee != null ? employee.Name : string.Empty; oDataRow["Amount"] = item.Amount; oDataRow["SendDate"] = component.UploadedDate.ToString("dd-MMM-yyyy"); oDataTable.Rows.Add(oDataRow); } } } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(new { component, oDataTable }); } [HttpGet("getApproverComponentUploadDT")] [Authorize(Roles = "EssApprove")] public ActionResult getApproverComponentUploadDT() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List _oUploadedComponents = new List(); List _oTempComponentTypes = null; List allEmployees = new List(); Employee emp = null; List oSenderEmployees = new List(); DataTable oDataTable = new DataTable(); try { int approverId = currentUser.EmployeeID.GetValueOrDefault(); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); DateTime salaryMonth = CurrentSalaryMonth(currentUser); // Load allEmployees = new EmployeeService().GetAllLive(); _oUploadedComponents = _uploadedComponentService.GetByApprover(approverId, salaryMonth); //new by alvee _oTempComponentTypes = _componentUploadSetupService.LoadComponentType(currentUser.PayrollTypeID.GetValueOrDefault()); //DT oDataTable.Columns.Add("uploadedComponentId"); oDataTable.Columns.Add("componentID"); oDataTable.Columns.Add("componentType"); oDataTable.Columns.Add("empId"); oDataTable.Columns.Add("salaryMonth"); oDataTable.Columns.Add("componentName"); oDataTable.Columns.Add("employeeNoName"); oDataTable.Columns.Add("amount"); oDataTable.Columns.Add("empCount"); oDataTable.Columns.Add("uploadedDate"); oDataTable.Columns.Add("status"); foreach (var uploadedComponent in _oUploadedComponents) { emp = allEmployees.Where(e => e.ID == uploadedComponent.UploadedBy).FirstOrDefault(); var cType = _oTempComponentTypes.Where(ct => ct.ItemID == uploadedComponent.ComponentID && ct.ComponentType == uploadedComponent.ComponentType).FirstOrDefault(); int empCount = uploadedComponent.UploadedComponentEmps != null ? uploadedComponent.UploadedComponentEmps.Count : 0; double totalAmount = uploadedComponent.UploadedComponentEmps != null ? uploadedComponent.UploadedComponentEmps.Sum(x => x.Amount) : 0; DataRow row = oDataTable.NewRow(); row["uploadedComponentId"] = uploadedComponent.ID; row["componentID"] = uploadedComponent.ComponentID; row["componentType"] = uploadedComponent.ComponentType; row["empId"] = emp.ID; row["salaryMonth"] = uploadedComponent.SalaryMonth.ToString("dd-MMM-yyyy"); row["componentName"] = cType != null ? cType.Description : 0; row["employeeNoName"] = emp.EmployeeNo + '-' + emp.Name; row["amount"] = totalAmount; row["empCount"] = empCount; row["uploadedDate"] = uploadedComponent.UploadedDate.ToString("dd-MMM-yyyy"); row["status"] = uploadedComponent.ApprovedBy == null || uploadedComponent.ApprovedBy == 0 ? "Pending" : "Approved"; oDataTable.Rows.Add(row); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(oDataTable); } [HttpGet("getUploaderComponentUploadDT")] [Authorize(Roles = "EssUpload")] public ActionResult getUploaderComponentUploadDT() { DataTable oDataTable = new DataTable(); try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeID = currentUser.EmployeeID.GetValueOrDefault(); oDataTable = _uploadedComponentService.GetByUploaderDT(employeeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(oDataTable); } [HttpGet("viewUploadedComponent/{id}")] [Authorize(Roles = "EssUpload")] public ActionResult viewUploadedComponent(int id) { DataTable oDataTable = new DataTable(); try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeID = currentUser.EmployeeID.GetValueOrDefault(); oDataTable = _uploadedComponentService.GetByIDandUploaderID(id, employeeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(oDataTable); } [HttpPost] [Route("approveComponentUpload")] [Authorize(Roles = "EssApprove")] public ActionResult approveComponentUpload(UploadedComponent component) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DateTime salaryMonth = (DateTime)currentUser.NextPayProcessDate; component.ApprovedBy = employeeId; component.ApprovedDate = DateTime.Today; _uploadedComponentService.SaveWithADParameter(component, salaryMonth); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // Breakdown (per-employee amounts) of one uploaded component, for its assigned approver. [HttpGet("viewUploadedComponentForApprover/{id}")] [Authorize(Roles = "EssApprove")] public ActionResult viewUploadedComponentForApprover(int id) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int approverId = currentUser.EmployeeID.GetValueOrDefault(); DateTime salaryMonth = CurrentSalaryMonth(currentUser); bool isMine = _uploadedComponentService.GetByApprover(approverId, salaryMonth).Any(c => c.ID == id); if (!isMine) return StatusCode(StatusCodes.Status403Forbidden, "You are not the approver for this upload."); return Ok(_uploadedComponentService.GetByID(id)); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } } // Approve an uploaded component by its keys (uploader + component). The server resolves the // UploadedComponent for the current salary month so the client only sends numeric route values. [HttpPost("approveComponentUploadByKey/{empId}/{componentID}/{componentType}")] [Authorize(Roles = "EssApprove")] public ActionResult approveComponentUploadByKey(int empId, int componentID, EnumComponentType componentType) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int approverEmployeeId = currentUser.EmployeeID.GetValueOrDefault(); DateTime salaryMonth; DateTime? deadline; if (!ComputeComponentDeadline(currentUser, out salaryMonth, out deadline)) return StatusCode(StatusCodes.Status400BadRequest, "The approval date for this salary month has passed. Approval is no longer allowed."); List uploads = _uploadedComponentService.Get(empId, salaryMonth); UploadedComponent component = uploads.FirstOrDefault( c => c.ComponentID == componentID && c.ComponentType == componentType); if (component == null) return StatusCode(StatusCodes.Status404NotFound, "The uploaded component was not found for this month."); if (component.ApprovedBy != null && component.ApprovedBy != 0) return StatusCode(StatusCodes.Status400BadRequest, "This component upload is already approved."); component.ApprovedBy = approverEmployeeId; component.ApprovedDate = DateTime.Today; _uploadedComponentService.SaveWithADParameter(component, salaryMonth); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } // Reject (delete) an uploaded component so the uploader can submit it again. [HttpPost("rejectComponentUploadByKey/{empId}/{componentID}/{componentType}")] [Authorize(Roles = "EssApprove")] public ActionResult rejectComponentUploadByKey(int empId, int componentID, EnumComponentType componentType) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime salaryMonth; DateTime? deadline; if (!ComputeComponentDeadline(currentUser, out salaryMonth, out deadline)) return StatusCode(StatusCodes.Status400BadRequest, "The approval date for this salary month has passed. Reject is no longer allowed."); List uploads = _uploadedComponentService.Get(empId, salaryMonth); UploadedComponent component = uploads.FirstOrDefault( c => c.ComponentID == componentID && c.ComponentType == componentType); if (component == null) return StatusCode(StatusCodes.Status404NotFound, "The uploaded component was not found for this month."); if (component.ApprovedBy != null && component.ApprovedBy != 0) return StatusCode(StatusCodes.Status400BadRequest, "This component upload is already approved and cannot be rejected."); _uploadedComponentService.Delete(component.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteUploadComponent")] [Authorize(Roles = "EssUpload")] public ActionResult deleteUploadComponent([FromBody]int id) { try { _uploadedComponentService.Delete(id); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("checkComponentUploadValidity")] [Authorize(Roles = "Employee")] public ActionResult checkComponentUploadValidity() { bool valid = true; int componentuploadfromdate, componentuploadtodate; try { componentuploadfromdate = new SystemConfigarationService().GetconfigIntValue(EnumConfigurationType.Logic, "componentuploaddaterange", "componentuploadfromdate"); componentuploadtodate = new SystemConfigarationService().GetconfigIntValue(EnumConfigurationType.Logic, "componentuploaddaterange", "componentuploadtodate"); valid = (DateTime.Today.Day > componentuploadfromdate || DateTime.Today.Day < componentuploadtodate) ? true : false; } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(new {valid, componentuploadfromdate, componentuploadtodate}); } // True when the current salary month has already been processed (a SalaryProcess row exists), // in which case component upload for that month is no longer allowed. // Component upload / approval deadline for the CURRENT salary month. // The admin-set PayrollType.ExpectedApprovalDate gives the cut-off DAY; that day is always // re-anchored to the current salary month (PayrollType.NextPayProcessDate) so that when the // admin forgets to set a new approval date after salary processing, the same day-of-month // is used for the new month automatically. [HttpGet("getComponentUploadDeadline")] [Authorize(Roles = "EssUpload,EssApprove")] public ActionResult getComponentUploadDeadline() { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime salaryMonth; DateTime? deadline; bool allowed = ComputeComponentDeadline(currentUser, out salaryMonth, out deadline); return Ok(new { allowed, deadline, salaryMonth }); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } } // The CURRENT salary month — always from the payroll type in the DB (not the login-time claim, // which goes stale after the admin advances the payroll process date). private DateTime CurrentSalaryMonth(CurrentUser currentUser) { PayrollType payrollType = new PayrollTypeService().Get(currentUser.PayrollTypeID.GetValueOrDefault()); return payrollType != null && payrollType.NextPayProcessDate != DateTime.MinValue ? payrollType.NextPayProcessDate : (DateTime)currentUser.NextPayProcessDate; } // Shared: returns true when component upload/approval is still allowed for the current salary month. private bool ComputeComponentDeadline(CurrentUser currentUser, out DateTime salaryMonth, out DateTime? deadline) { PayrollType payrollType = new PayrollTypeService().Get(currentUser.PayrollTypeID.GetValueOrDefault()); salaryMonth = payrollType != null && payrollType.NextPayProcessDate != DateTime.MinValue ? payrollType.NextPayProcessDate : (DateTime)currentUser.NextPayProcessDate; deadline = null; if (payrollType == null || payrollType.ExpectedApprovalDate == null) return true; DateTime configured = payrollType.ExpectedApprovalDate.Value; int day = Math.Min(configured.Day, DateTime.DaysInMonth(salaryMonth.Year, salaryMonth.Month)); DateTime effective = new DateTime(salaryMonth.Year, salaryMonth.Month, day); deadline = effective; return DateTime.Today.Date <= effective.Date; } #endregion } }