From e131348fb8091575262975d3845ac8fca91e6db9 Mon Sep 17 00:00:00 2001 From: Naz <2022755409@student.uitm.edu.my> Date: Mon, 24 Mar 2025 00:07:33 +0800 Subject: [PATCH] update --- .../Controllers/HrDashboardController.cs | 68 +---- Areas/OTcalculate/Models/CalendarModel.cs | 16 +- Areas/OTcalculate/Models/RateModel.cs | 1 + Areas/OTcalculate/Models/StateModel.cs | 13 + .../Views/HrDashboard/Calendar.cshtml | 240 +++++++++++++----- .../OTcalculate/Views/HrDashboard/Rate.cshtml | 239 +++++++++++------ Controllers/API/Inventory/InvMainAPI.cs | 10 +- Controllers/API/OvertimeAPI.cs | 165 +++++++++++- DBContext/CentralSystemContext.cs | 2 + 9 files changed, 529 insertions(+), 225 deletions(-) create mode 100644 Areas/OTcalculate/Models/StateModel.cs diff --git a/Areas/OTcalculate/Controllers/HrDashboardController.cs b/Areas/OTcalculate/Controllers/HrDashboardController.cs index 177fe9c..d8a0829 100644 --- a/Areas/OTcalculate/Controllers/HrDashboardController.cs +++ b/Areas/OTcalculate/Controllers/HrDashboardController.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; namespace PSTW_CentralSystem.Areas.OTcalculate.Controllers { [Area("OTcalculate")] + public class HrDashboardController : Controller { private readonly CentralSystemContext _context; @@ -40,72 +41,5 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Controllers return View(); } - #region Rates - [HttpPost("UpdateRates")] - public async Task UpdateRate([FromBody] List rates) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - try - { - foreach (var Rate in rates) - { - var existingRate = await _context.Rates.FindAsync(Rate.RateId); - if (existingRate != null) - { - existingRate.RateValue = Rate.RateValue; - _context.Rates.Update(existingRate); - } - } - - await _context.SaveChangesAsync(); - - var updateRates = await _context.Rates - .Include(rates => rates.Users) - .Select(rates => new - { - rates.RateId, - rates.RateValue, - rates.UserId, - FullName = rates.Users.FullName, - DepartmentName = rates.Users.DepartmentName - }) - .ToListAsync(); - - return Json(updateRates); - } - catch (Exception ex) - { - return BadRequest(ex.Message); - } - } - [HttpPost("GetUserRates")] - public async Task GetUserRates() - { - try - { - var userRates = await _context.Rates - .Include(rates => rates.Users) - .Select(rates => new - { - rates.RateId, - rates.RateValue, - rates.UserId, - FullName = rates.Users.FullName, - DepartmentName = rates.Users.DepartmentName - }) - .ToListAsync(); - - return Json(userRates); - } - catch (Exception ex) - { - return BadRequest(ex.Message); - } - } - #endregion } } diff --git a/Areas/OTcalculate/Models/CalendarModel.cs b/Areas/OTcalculate/Models/CalendarModel.cs index 9c39e80..06fd26e 100644 --- a/Areas/OTcalculate/Models/CalendarModel.cs +++ b/Areas/OTcalculate/Models/CalendarModel.cs @@ -1,6 +1,18 @@ -namespace PSTW_CentralSystem.Areas.OTcalculate.Models +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using PSTW_CentralSystem.Models; + +namespace PSTW_CentralSystem.Areas.OTcalculate.Models { public class CalendarModel { + [Key] + public int HolidayId { get; set; } + public required string HolidayName { get; set; } + public DateTime HolidayDate { get; set; } + public int StateId { get; set; } + + [ForeignKey("StateId")] + public virtual StateModel? States { get; set; } } -} +} \ No newline at end of file diff --git a/Areas/OTcalculate/Models/RateModel.cs b/Areas/OTcalculate/Models/RateModel.cs index 1a46309..0efac10 100644 --- a/Areas/OTcalculate/Models/RateModel.cs +++ b/Areas/OTcalculate/Models/RateModel.cs @@ -9,6 +9,7 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Models [Key] public int RateId { get; set; } + [Column(TypeName = "decimal(10,2)")] public decimal RateValue { get; set; } public int UserId { get; set; } diff --git a/Areas/OTcalculate/Models/StateModel.cs b/Areas/OTcalculate/Models/StateModel.cs new file mode 100644 index 0000000..0ac3d49 --- /dev/null +++ b/Areas/OTcalculate/Models/StateModel.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using PSTW_CentralSystem.Models; + +namespace PSTW_CentralSystem.Areas.OTcalculate.Models +{ + public class StateModel + { + [Key] + public int StateId { get; set; } + public required string StateName { get; set; } + } +} \ No newline at end of file diff --git a/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml b/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml index fef2412..bf561a0 100644 --- a/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml +++ b/Areas/OTcalculate/Views/HrDashboard/Calendar.cshtml @@ -4,6 +4,7 @@ } @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +
@@ -34,98 +35,201 @@
+
+
-
-
- @* Holiday *@ -
-
-
-

UPDATE HOLIDAY

-
+ @* Tab Page *@ + + +
+ + @* Update Holiday *@ +
- - + +
+
-
-
- - +
+
+
+ + +
+
+
- + +
-
- - -
+
+ +
-
- @* Weekend *@ -
-
-
-

UPDATE WEEKEND

-
+
- -
-
- - -
-
- - - + - -
- - -
-
-
-
-
- - @* Updated Data*@ -
-
-
-
-

Holiday Updates

-
    -
  • - {{ holiday.Date }}: {{ holiday.HolidayName }} ({{ holiday.States.join(', ') }}) +
    Holidays for Selected State
    +
      +
    • + {{ formatDate(holiday.holidayDate) }} - {{ holiday.holidayName }}
-
-
-
-
-

Weekend Updates

-
+ @* Update Weekend *@ +
-
    -
  • - {{ weekend.States.join(', ') }}: {{ weekend.WeekendDays }} -
  • -
+

Weekend Update Section

+
+ +@section Scripts { + + + +} diff --git a/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml b/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml index aaf0c27..6ac364a 100644 --- a/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml +++ b/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml @@ -1,4 +1,4 @@ -@model List + @{ ViewData["Title"] = "Rate Update"; @@ -36,62 +36,39 @@
- -
-
-
-
-
-
-
-
-
-
-
-

UPDATE RATE

-
-
- - @* Enter Rate *@ -
- -
- -
-
- -
-
-
- - @* User Table Rate *@ -
- - - - - - - - - - - - - - - -
Full NameDepartmentSelect Rate
{{ user.FullName }}{{ user.DepartmentName }} - -
- -
-
-
-
+
+
+ +
+

UPDATE RATE

+
+ @* Enter Rate *@ +
+
+ + + +
- -
+
+
+ + + + + + + + + +
Full NameDepartmentCurrent RateSelect Rate
+
+
+ + +
+ +
@@ -99,35 +76,133 @@ @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } + -} \ No newline at end of file +} diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs index 4afb06a..02e03d5 100644 --- a/Controllers/API/Inventory/InvMainAPI.cs +++ b/Controllers/API/Inventory/InvMainAPI.cs @@ -1195,8 +1195,14 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory [HttpPost("UserList")] public async Task UserList() { - var userList = await _centralDbContext.Users.ToListAsync(); - return Json(userList); + var userList = await _centralDbContext.Users.Include(i => i.Department).ToListAsync(); + return Json(userList.Select(i => new + { + i.Id, + i.FullName, + i.Department, + i.Department?.DepartmentName, + })); } diff --git a/Controllers/API/OvertimeAPI.cs b/Controllers/API/OvertimeAPI.cs index 9ff4ed1..bdcf9a3 100644 --- a/Controllers/API/OvertimeAPI.cs +++ b/Controllers/API/OvertimeAPI.cs @@ -7,6 +7,7 @@ using Mono.TextTemplating; using Newtonsoft.Json; using PSTW_CentralSystem.Areas.OTcalculate.Models; using PSTW_CentralSystem.Controllers.API; +using PSTW_CentralSystem.Controllers.API.Inventory; using PSTW_CentralSystem.DBContext; using PSTW_CentralSystem.Models; using System.ComponentModel.Design; @@ -32,13 +33,169 @@ namespace PSTW_CentralSystem.Controllers.API _userManager = userManager; } - public class UserDetails + #region Rate + [HttpPost("UpdateRates")] + public async Task UpdateRate([FromBody] List rates) { - public required string FullName { get; set; } - public int DepartmentId { get; set; } + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + try + { + foreach (var rate in rates) + { + var existingRate = await _centralDbContext.Rates + .FirstOrDefaultAsync(r => r.UserId == rate.UserId); + if (existingRate != null) + { + existingRate.RateValue = rate.RateValue; + _centralDbContext.Rates.Update(existingRate); + } + else + { + _centralDbContext.Rates.Add(new RateModel + { + UserId = rate.UserId, + RateValue = rate.RateValue + }); + } + } + await _centralDbContext.SaveChangesAsync(); + + var updatedRates = await _centralDbContext.Rates + .Include(r => r.Users) + .Select(r => new + { + r.RateId, + r.RateValue, + r.UserId, + FullName = r.Users.FullName, + DepartmentName = r.Users.Department.DepartmentName + }) + .ToListAsync(); + + return Json(updatedRates); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } } + + [HttpPost("GetUserRates")] + public async Task GetUserRates() + { + try + { + var userRates = await _centralDbContext.Rates + .Include(rates => rates.Users) + .ThenInclude(user => user.Department) + .Select(rates => new + { + rates.RateId, + rates.RateValue, + rates.UserId, + rates.Users.FullName, + rates.Users.Department.DepartmentName + }) + .ToListAsync(); + + return Json(userRates); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + #endregion + + #region Calendar + [HttpGet("GetStatesName")] + public async Task GetStatesName() + { + try + { + var states = await _centralDbContext.States + .Select(s => new + { + s.StateId, + s.StateName + }) + .ToListAsync(); + + return Json(states); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + + + [HttpPost("UpdateHoliday")] + public async Task UpdateHoliday([FromBody] List holidays) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + try + { + foreach (var calendar in holidays) + { + var existingCalendar = await _centralDbContext.Holidays + .FirstOrDefaultAsync(h => h.StateId == calendar.StateId && h.HolidayDate == calendar.HolidayDate); + + if (existingCalendar != null) + { + existingCalendar.HolidayName = calendar.HolidayName; + _centralDbContext.Holidays.Update(existingCalendar); + } + else + { + _centralDbContext.Holidays.Add(new CalendarModel + { + HolidayName = calendar.HolidayName, + HolidayDate = calendar.HolidayDate, + StateId = calendar.StateId + }); + } + } + + await _centralDbContext.SaveChangesAsync(); + + var updatedHoliday = await _centralDbContext.Holidays + .Include(h => h.States) + .Select(h => new + { + h.HolidayId, + h.HolidayName, + h.HolidayDate, + h.StateId, + StateName = h.States.StateName + }) + .ToListAsync(); + + return Json(updatedHoliday); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + + [HttpGet("GetAllHolidays")] + public IActionResult GetAllHolidays() + { + var holidays = _centralDbContext.Holidays.ToList(); + return Ok(holidays); + } + #endregion + } -} +} \ No newline at end of file diff --git a/DBContext/CentralSystemContext.cs b/DBContext/CentralSystemContext.cs index b9358c1..7a036be 100644 --- a/DBContext/CentralSystemContext.cs +++ b/DBContext/CentralSystemContext.cs @@ -100,5 +100,7 @@ namespace PSTW_CentralSystem.DBContext public DbSet Stations { get; set; } public DbSet Stores { get; set; } public DbSet Rates { get; set; } + public DbSet Holidays { get; set; } + public DbSet States { get; set; } } }