From 95cd49ecbcc647df39d35a373bac7647723cd4c7 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 9 Jan 2026 19:10:16 +0700 Subject: [PATCH] update LeaveReportController to pass date parameter to GetLastEffectRound method --- BMA.EHR.Leave/Controllers/LeaveController.cs | 70 ++++++++++++++++--- .../Controllers/LeaveReportController.cs | 2 +- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index d4edffb2..2ff01180 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -877,7 +877,28 @@ namespace BMA.EHR.Leave.Service.Controllers else startTime = duty.StartTimeMorning; - var checkInStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) > + string checkInStatus = "NORMAL"; + var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(userId, currentDate.Date); + if (leaveReq != null) + { + var leaveRange = leaveReq.LeaveRange == null ? "" : leaveReq.LeaveRange.ToUpper(); + if (leaveRange == "MORNING") + checkInStatus = "NORMAL"; + else + { + 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" : + "LATE" : + "NORMAL"; + } + } + else + { + 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")) > @@ -885,6 +906,8 @@ namespace BMA.EHR.Leave.Service.Controllers "ABSENT" : "LATE" : "NORMAL"; + } + // process - รอทำใน queue var checkin_process = new ProcessUserTimeStamp @@ -959,16 +982,41 @@ namespace BMA.EHR.Leave.Service.Controllers { return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound); } - // fix issue : SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลาเข้า-ออกงาน (กรณีลงเวลาออกอีกวัน) #921 - var checkOutStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < - DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ? - // "ABSENT" : - checkout.CheckIn.Date < currentDate.Date ? "NORMAL" : - "ABSENT" : - DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < - DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ? - "ABSENT" : - "NORMAL"; + + string checkOutStatus = "NORMAL"; + var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(userId, currentDate.Date); + if (leaveReq != null) + { + var leaveRange = leaveReq.LeaveRange == null ? "" : leaveReq.LeaveRange.ToUpper(); + if (leaveRange == "AFTERNOON") + checkOutStatus = "NORMAL"; + else + { + // fix issue : SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลาเข้า-ออกงาน (กรณีลงเวลาออกอีกวัน) #921 + checkOutStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < + DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ? + // "ABSENT" : + checkout.CheckIn.Date < currentDate.Date ? "NORMAL" : + "ABSENT" : + DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < + DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ? + "ABSENT" : + "NORMAL"; + } + } + else + { + // fix issue : SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลาเข้า-ออกงาน (กรณีลงเวลาออกอีกวัน) #921 + checkOutStatus = DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < + DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ? + // "ABSENT" : + checkout.CheckIn.Date < currentDate.Date ? "NORMAL" : + "ABSENT" : + DateTime.Parse(currentDate.ToString("yyyy-MM-dd HH:mm")) < + DateTime.Parse($"{currentDate.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ? + "ABSENT" : + "NORMAL"; + } if (checkout_process != null) { diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 059da265..ecebb4a0 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -2099,7 +2099,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{p.Prefix}{p.FirstName} {p.LastName}"; - var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); + var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id, dd.date); var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);