From 3a6e4501fd08a6e6168ff401be0d5d2a7dd2a043 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 14 Jan 2026 16:38:55 +0700 Subject: [PATCH] refactor LeaveController to update start and end time logic for check-in and check-out #2199 --- BMA.EHR.Leave/Controllers/LeaveController.cs | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index e730a2a9..ab0e61b9 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -872,7 +872,8 @@ namespace BMA.EHR.Leave.Service.Controllers var startTime = ""; if (!data.IsLocation && data.LocationName == "ไปประชุม / อบรม / สัมมนา") { - startTime = "09:30"; + //startTime = "09:30"; + startTime = "10:30"; } else startTime = duty.StartTimeMorning; @@ -888,7 +889,6 @@ namespace BMA.EHR.Leave.Service.Controllers { checkInStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) > DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {startTime}") ? - DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) > DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ? "ABSENT" : @@ -900,7 +900,6 @@ namespace BMA.EHR.Leave.Service.Controllers { checkInStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) > DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {startTime}") ? - DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) > DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ? "ABSENT" : @@ -956,8 +955,6 @@ namespace BMA.EHR.Leave.Service.Controllers } else { - - var checkout = await _userTimeStampRepository.GetByIdAsync(data.CheckInId.Value); var currentCheckInProcess = await _processUserTimeStampRepository.GetTimestampByDateAsync(userId, checkout.CheckIn.Date); @@ -983,6 +980,15 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound); } + var endTime = ""; + if (!data.IsLocation && data.LocationName == "ไปประชุม / อบรม / สัมมนา") + { + //startTime = "09:30"; + endTime = "14:30"; + } + else + endTime = duty.EndTimeAfternoon; + string checkOutStatus = "NORMAL"; var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(userId, currentDate.Date); if (leaveReq != null) @@ -997,6 +1003,9 @@ namespace BMA.EHR.Leave.Service.Controllers DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ? // "ABSENT" : checkout.CheckIn.Date < currentDate.Date ? "NORMAL" : + DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) >= + DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTime}") ? + "NORMAL" : "ABSENT" : DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ? @@ -1011,6 +1020,9 @@ namespace BMA.EHR.Leave.Service.Controllers DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ? // "ABSENT" : checkout.CheckIn.Date < currentDate.Date ? "NORMAL" : + DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) >= + DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {endTime}") ? + "NORMAL" : "ABSENT" : DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ?