From aa316b94aee3fb5aeb118d2ceb47a157ab9d836d Mon Sep 17 00:00:00 2001 From: Naz <2022755409@student.uitm.edu.my> Date: Tue, 25 Mar 2025 15:34:38 +0800 Subject: [PATCH] - --- Areas/OTcalculate/Models/CalendarModel.cs | 1 + Areas/OTcalculate/Models/OtRegisterModel.cs | 6 ++ Areas/OTcalculate/Models/RateModel.cs | 2 + Areas/OTcalculate/Models/SettingsModel.cs | 12 +++ .../Views/HrDashboard/Calendar.cshtml | 70 ++++++++++++++-- .../OTcalculate/Views/HrDashboard/Rate.cshtml | 3 +- .../Views/HrDashboard/Settings.cshtml | 84 ++++++++++++++----- .../Views/Overtime/OtRegister.cshtml | 20 +++-- Controllers/API/OvertimeAPI.cs | 45 ++++++++++ 9 files changed, 208 insertions(+), 35 deletions(-) create mode 100644 Areas/OTcalculate/Models/OtRegisterModel.cs create mode 100644 Areas/OTcalculate/Models/SettingsModel.cs diff --git a/Areas/OTcalculate/Models/CalendarModel.cs b/Areas/OTcalculate/Models/CalendarModel.cs index dc47176..a758895 100644 --- a/Areas/OTcalculate/Models/CalendarModel.cs +++ b/Areas/OTcalculate/Models/CalendarModel.cs @@ -15,5 +15,6 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Models [ForeignKey("StateId")] public virtual StateModel? States { get; set; } + public DateTime LastUpdated { get; set; } } } \ No newline at end of file diff --git a/Areas/OTcalculate/Models/OtRegisterModel.cs b/Areas/OTcalculate/Models/OtRegisterModel.cs new file mode 100644 index 0000000..64ef768 --- /dev/null +++ b/Areas/OTcalculate/Models/OtRegisterModel.cs @@ -0,0 +1,6 @@ +namespace PSTW_CentralSystem.Areas.OTcalculate.Models +{ + public class OtRegisterModel + { + } +} diff --git a/Areas/OTcalculate/Models/RateModel.cs b/Areas/OTcalculate/Models/RateModel.cs index 0efac10..84eabbc 100644 --- a/Areas/OTcalculate/Models/RateModel.cs +++ b/Areas/OTcalculate/Models/RateModel.cs @@ -18,5 +18,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Models public virtual UserModel? Users { get; set; } + public DateTime LastUpdated { get; set; } + } } diff --git a/Areas/OTcalculate/Models/SettingsModel.cs b/Areas/OTcalculate/Models/SettingsModel.cs new file mode 100644 index 0000000..65196c5 --- /dev/null +++ b/Areas/OTcalculate/Models/SettingsModel.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using PSTW_CentralSystem.Models; + +namespace PSTW_CentralSystem.Areas.OTcalculate.Models +{ + public class SettingsViewModel + { + public DateTime? LatestRateUpdate { get; set; } + public DateTime? LatestCalendarUpdate { get; set; } + } +} diff --git a/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml b/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml index 968a204..89312f8 100644 --- a/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml +++ b/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml @@ -69,6 +69,12 @@
+
+
+ + +
+
@@ -101,8 +107,12 @@
Holidays for Selected State
    -
  • - {{ formatDate(holiday.holidayDate) }} - {{ holiday.holidayName }} +
  • + {{ formatDate(holiday.holidayDate) }} - {{ holiday.holidayName }} +
@@ -113,6 +123,12 @@
+
+
+ + +
+
@@ -141,7 +157,6 @@
-
Weekend Days per State
@@ -175,7 +190,8 @@ holidayList: [], selectedDay: "", weekendList: [], - stateWeekends: [] + stateWeekends: [], + selectAllChecked: false }; }, @@ -202,6 +218,25 @@ grouped[weekend.day].push(weekend.stateName); }); return grouped; + }, + filteredHolidays() { + return this.selectedState + ? this.holidayList + .filter(h => h.stateId === this.selectedState) + .sort((a, b) => new Date(a.holidayDate) - new Date(b.holidayDate)) + : []; + } + }, + + watch: { + selectAllChecked(ckeckedState) { + if (ckeckedState) { + this.selectedStates = this.stateList.map(state => state.stateId); + } + }, + + selectedStates(ckeckedState) { + this.selectAllChecked = ckeckedState.length === this.stateList.length; } }, @@ -278,6 +313,28 @@ } }, + async deleteHoliday(holidayId) { + if (!confirm("Are you sure you want to delete this holiday?")) { + return; + } + + try { + const response = await fetch(`/OvertimeAPI/DeleteHoliday/${holidayId}`, { + method: "DELETE" + }); + + if (response.ok) { + alert("Holiday deleted successfully!"); + this.fetchHolidays(); + } else { + alert("Failed to delete holiday."); + } + } catch (error) { + console.error("Error deleting holiday:", error); + alert("An error occurred while deleting the holiday."); + } + }, + async fetchWeekends() { try { const response = await fetch("/OvertimeAPI/GetWeekendDay"); @@ -289,6 +346,7 @@ alert("Failed to load weekend list."); } }, + async fetchStateWeekends() { try { const response = await fetch("/OvertimeAPI/GetStateWeekends"); @@ -301,7 +359,8 @@ alert("Failed to load state weekend data."); } }, - async updateWeekend() { + + async updateWeekend() { try { if (this.selectedStates.length === 0 || !this.selectedDay) { alert("Please select at least one state and a day."); @@ -355,7 +414,6 @@ this.selectedDay = ""; this.selectedStates = []; } - } }); diff --git a/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml b/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml index 6ac364a..f141866 100644 --- a/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml +++ b/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml @@ -177,7 +177,8 @@ }, { "title": "Select Rate", - "data": "id", + "data": "id", + "className": "text-center", "render": function (data) { return ``; diff --git a/Areas/OTcalculate/Views/HrDashboard/Settings.cshtml b/Areas/OTcalculate/Views/HrDashboard/Settings.cshtml index 39779cc..eec4d5d 100644 --- a/Areas/OTcalculate/Views/HrDashboard/Settings.cshtml +++ b/Areas/OTcalculate/Views/HrDashboard/Settings.cshtml @@ -4,6 +4,7 @@ } @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +
@@ -36,42 +37,81 @@
-
-
-
-
-
-
-
-
-
-

UPDATE DATE

-
+
+
+
+
+
+
+
+
+

LATEST UPDATE DATES

-
-
-
-
- Rate Latest Update: +
+
+
+
+
+ +
-
-
-
-
- Calendar Latest Update: +
+
+
+
+
+ +
- +
+@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + } + + +} \ No newline at end of file diff --git a/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml b/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml index 0991c57..ed04c58 100644 --- a/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml +++ b/Areas/OTcalculate/Views/Overtime/OtRegister.cshtml @@ -2,13 +2,21 @@ ViewData["Title"] = "Register Overtime"; Layout = "~/Views/Shared/_Layout.cshtml"; } - -
-
-
-

Name:

+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers + +
+
+
+
+
+ + +
+

OFFICE HOURS

+
+
+
diff --git a/Controllers/API/OvertimeAPI.cs b/Controllers/API/OvertimeAPI.cs index cac0933..c5682af 100644 --- a/Controllers/API/OvertimeAPI.cs +++ b/Controllers/API/OvertimeAPI.cs @@ -32,6 +32,28 @@ namespace PSTW_CentralSystem.Controllers.API _centralDbContext = centralDbContext; _userManager = userManager; } + [HttpGet("GetUpdateDates")] + public IActionResult GetUpdateDates() + { + try + { + + var latestRateUpdate = _centralDbContext.Rates.OrderByDescending(r => r.LastUpdated).FirstOrDefault()?.LastUpdated; + var latestCalendarUpdate = _centralDbContext.Holidays.OrderByDescending(c => c.LastUpdated).FirstOrDefault()?.LastUpdated; + + var updateDates = new + { + rateUpdateDate = latestRateUpdate.HasValue ? latestRateUpdate.Value.ToString("dd MMMM yyyy") : null, + calendarUpdateDate = latestCalendarUpdate.HasValue ? latestCalendarUpdate.Value.ToString("dd MMMM yyyy") : null + }; + + return Json(updateDates); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } #region Rate [HttpPost("UpdateRates")] @@ -195,6 +217,29 @@ namespace PSTW_CentralSystem.Controllers.API var holidays = _centralDbContext.Holidays.ToList(); return Ok(holidays); } + + [HttpDelete("DeleteHoliday/{id}")] + public async Task DeleteHoliday(int id) + { + try + { + var holiday = await _centralDbContext.Holidays.FindAsync(id); + if (holiday == null) + { + return NotFound("Holiday not found."); + } + + _centralDbContext.Holidays.Remove(holiday); + await _centralDbContext.SaveChangesAsync(); + + return Ok(new { message = "Holiday deleted successfully." }); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + #endregion #region Weekend