diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index a0d0d4b1..9c91f891 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -7,6 +7,7 @@ using BMA.EHR.Application.Responses.Profiles; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Leave.Requests; +using BMA.EHR.Domain.Models.Leave.TimeAttendants; using BMA.EHR.Domain.Shared; using BMA.EHR.Leave.Service.DTOs.Reports; using Microsoft.AspNetCore.Authorization; @@ -2855,25 +2856,41 @@ namespace BMA.EHR.Leave.Service.Controllers { nodeId = profileAdmin?.RootDnaId; } + var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync(); + if (getDefaultRound == null) + { + return Error("ไม่พบรอบลงเวลา Default", StatusCodes.Status404NotFound); + } var userTimeStamps = await _processUserTimeStampRepository.GetTimestampByDateLateAsync(type.Trim().ToUpper(), role, nodeId, profileAdmin.Node, req.nodeId, req.node, req.StartDate, req.EndDate); foreach (var p in userTimeStamps) { var fullName = $"{p.Prefix}{p.FirstName} {p.LastName}"; - var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); + UserDutyTime? effectiveDate = null; + + effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); + //return Error($"{data.Id} PF{data.FirstName} {data.LastName} : {GlobalMessages.DataNotFound}", StatusCodes.Status404NotFound); + + //var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty); var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); - var duty = userRound; - if (duty == null) - { - duty = await _dutyTimeRepository.GetDefaultAsync(); - if (duty == null) - { - return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound); - } - } + var duty = userRound ?? getDefaultRound; + + // var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); + // var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; + // var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); + + // var duty = userRound; + // if (duty == null) + // { + // duty = await _dutyTimeRepository.GetDefaultAsync(); + // if (duty == null) + // { + // return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound); + // } + // } DateTime? checkIn = p.CheckIn; DateTime? checkOut = p.CheckOut ?? null; var emp = new