From 99accd44e365d80478f1cb7ae36d6c79fb5ff0e3 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 9 Jan 2026 18:57:24 +0700 Subject: [PATCH] update GetLastEffectRound method to accept effectiveDate parameter and adjust usage in LeaveReportController --- .../Leaves/TimeAttendants/UserDutyTimeRepository.cs | 6 +++--- BMA.EHR.Leave/Controllers/LeaveReportController.cs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs index 3eefefe0..5ca823d9 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs @@ -101,12 +101,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants return data; } - public async Task GetLastEffectRound(Guid profileId) + public async Task GetLastEffectRound(Guid profileId, DateTime? effectiveDate = null) { + effectiveDate ??= DateTime.Now; var data = await _dbContext.Set() .Where(x => x.ProfileId == profileId) - .Where(x => x.IsProcess) - .Where(x => x.EffectiveDate.Value.Date <= DateTime.Now.Date) + .Where(x => x.EffectiveDate.Value.Date <= effectiveDate.Value.Date) .OrderByDescending(x => x.EffectiveDate) .FirstOrDefaultAsync(); diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index 9f88401b..059da265 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -1768,7 +1768,8 @@ namespace BMA.EHR.Leave.Service.Controllers // return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound); //} - var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); + // ให้ใช้วันที่จาก loop date แทน + var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id, dd.date); var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);