From bcbac7814da63271eee98acec5688eb8ee257e30 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Sun, 24 Dec 2023 13:28:37 +0700 Subject: [PATCH] =?UTF-8?q?fix=20Report=20=E0=B8=A3=E0=B8=B0=E0=B8=9A?= =?UTF-8?q?=E0=B8=9A=E0=B8=A5=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProcessUserTimeStampRepository.cs | 17 +++ .../Repositories/UserProfileRepository.cs | 17 +++ .../Controllers/LeaveReportController.cs | 115 +++++++++--------- .../DTOs/Reports/GetLeaveDetailReportDto.cs | 2 +- 4 files changed, 92 insertions(+), 59 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs index eb8dda94..74535bd1 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs @@ -56,6 +56,23 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants #region " Methods " + public async Task> GetCheckInKeycloakId() + { + try + { + var data = await _dbContext.Set() + .Select(x => x.KeycloakUserId) + .Distinct() + .ToListAsync(); + + return data; + } + catch + { + throw; + } + } + public bool IsEditRequest(Guid userId, DateTime checkDate) { try diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index b179bf33..4ee80a18 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -80,6 +80,23 @@ namespace BMA.EHR.Application.Repositories } } + public async Task> GetProfileWithKeycloak() + { + try + { + var data = await _dbContext.Set().AsQueryable() + .Where(x => x.ProfileType == "officer") + .Where(x => x.KeycloakId != null) + .ToListAsync(); + + return data; + } + catch + { + throw; + } + } + public async Task> SearchProfile(string? citizenId, string? firstName, string? lastName) { try diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs index a5500046..a31f134b 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs @@ -698,7 +698,9 @@ namespace BMA.EHR.Leave.Service.Controllers { try { - var profile = await _userProfileRepository.SearchProfile(null, null, null); + //var profile = await _userProfileRepository.SearchProfile(null, null, null); + var profile = await _userProfileRepository.GetProfileWithKeycloak(); + var count = 1; var employees = new List(); @@ -1083,77 +1085,74 @@ namespace BMA.EHR.Leave.Service.Controllers { try { - var profile = await _userProfileRepository.SearchProfile(null, null, null); + //var profile = await _userProfileRepository.SearchProfile(null, null, null); + var profile = await _userProfileRepository.GetProfileWithKeycloak(); + var date = req.StartDate.Date; - var data = new List(); - - for (DateTime date = req.StartDate.Date; date.Date <= req.EndDate.Date; date = date.AddDays(1)) + var employees = new List(); + var count = 1; + foreach (var p in profile) { - var employees = new List(); - var count = 1; - foreach (var p in profile) + var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(p.KeycloakId ?? Guid.Empty, date); + + var fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty); + + + var defaultRound = await _dutyTimeRepository.GetDefaultAsync(); + if (defaultRound == null) { - var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(p.KeycloakId ?? Guid.Empty, date); - - var fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty); - - - var defaultRound = await _dutyTimeRepository.GetDefaultAsync(); - if (defaultRound == null) - { - return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound); - } - - //var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty); - var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); - var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; - var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); - - var duty = userRound ?? defaultRound; - - var emp = new - { - no = count, - fullName = fullName, - dutyTimeName = $"{duty.StartTimeMorning} น.", - checkInLocation = timeStamps == null ? "" : timeStamps.CheckInLocationName, - checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.Date.ToString("HH:mm")} น.", - - checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutLocationName ?? "", - checkOutTime = timeStamps == null ? "" : - timeStamps.CheckOut != null ? - $"{timeStamps.CheckOut.Value.Date.ToString("HH:mm")} น." : - "", - - remark = "" - }; - - employees.Add(emp); - count++; - + return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound); } - var item = new + //var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty); + var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); + var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; + var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); + + var duty = userRound ?? defaultRound; + + var emp = new { - DateTimeStamp = date.Date.ToThaiFullDate(), - officerTotal = profile.Count, - workTotal = count - 1, - restTotal = 0, - sickTotal = 0, - lateTotal = 0, - wfhTotal = 0, - studyTotal = 0, - employees = employees + no = count, + fullName = fullName, + dutyTimeName = $"{duty.StartTimeMorning} น.", + checkInLocation = timeStamps == null ? "" : timeStamps.CheckInLocationName, + checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.Date.ToString("HH:mm")} น.", + + checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutLocationName ?? "", + checkOutTime = timeStamps == null ? "" : + timeStamps.CheckOut != null ? + $"{timeStamps.CheckOut.Value.Date.ToString("HH:mm")} น." : + "", + + remark = "" }; - data.Add(item); + employees.Add(emp); + count++; + } + var item = new + { + DateTimeStamp = date.Date.ToThaiFullDate(), + officerTotal = profile.Count, + workTotal = count - 1, + restTotal = 0, + sickTotal = 0, + lateTotal = 0, + wfhTotal = 0, + studyTotal = 0, + employees = employees + }; + + + var result = new { template = "TimeStamp", reportName = "TimeStamp", - data = data + data = item }; return Success(result); diff --git a/BMA.EHR.Leave.Service/DTOs/Reports/GetLeaveDetailReportDto.cs b/BMA.EHR.Leave.Service/DTOs/Reports/GetLeaveDetailReportDto.cs index 4a12851a..08c67851 100644 --- a/BMA.EHR.Leave.Service/DTOs/Reports/GetLeaveDetailReportDto.cs +++ b/BMA.EHR.Leave.Service/DTOs/Reports/GetLeaveDetailReportDto.cs @@ -4,7 +4,7 @@ namespace BMA.EHR.Leave.Service.DTOs.Reports { public DateTime StartDate { get; set; } = DateTime.MinValue; - public DateTime EndDate { get; set; } = DateTime.MinValue; + //public DateTime EndDate { get; set; } = DateTime.MinValue; } } \ No newline at end of file