From b5c967c5fc100394c46c9c867bac1e31d0caacf9 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 1 May 2025 19:59:05 +0700 Subject: [PATCH] =?UTF-8?q?add=20Field=20to=20/leave/report/reject/{id}=20?= =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B9=89=E0=B8=81=20=E0=B8=99=E0=B8=B1=E0=B8=9A=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=99=E0=B8=A5=E0=B8=B2=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=20approve=20=E0=B8=81=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=A5=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LeaveRequests/LeaveRequestRepository.cs | 18 ++++++++++++- .../Controllers/LeaveReportController.cs | 27 ++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 59fad799..5d2f76e2 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -1218,6 +1218,22 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return 0.0; } + public async Task GetSumApproveLeaveByTypeAndRangeForUser(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + { + var data = await _dbContext.Set().AsQueryable().AsNoTracking() + .Include(x => x.Type) + .Where(x => x.KeycloakUserId == keycloakUserId) + .Where(x => x.Type.Id == leaveTypeId) + .Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date) + .Where(x => x.LeaveStatus == "APPROVE") + .ToListAsync(); + + if (data.Count > 0) + return data.Sum(x => x.LeaveTotal); + else + return 0; + } + public async Task GetSumApproveLeaveByRangeForUser(Guid keycloakUserId, DateTime startDate, DateTime endDate) { var data = await _dbContext.Set().AsQueryable().AsNoTracking() @@ -1347,7 +1363,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests return res; } - public async Task GetSumApproveLeaveByTypeAndRangeForUser(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) + public async Task GetSumApproveLeaveTotalByTypeAndRangeForUser(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate) { var data = await _dbContext.Set().AsQueryable().AsNoTracking() .Include(x => x.Type) diff --git a/BMA.EHR.Leave/Controllers/LeaveReportController.cs b/BMA.EHR.Leave/Controllers/LeaveReportController.cs index d4bd7fa0..0aa63e9d 100644 --- a/BMA.EHR.Leave/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveReportController.cs @@ -160,9 +160,15 @@ namespace BMA.EHR.Leave.Service.Controllers //} //var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveByTypeForUserAsync(data.KeycloakUserId, data.Type.Id, data.LeaveStartDate.Year); + //GetSumApproveLeaveByRangeForUser + + var startFiscalYear = new DateTime(data.LeaveStartDate.Year - 1, 10, 1); + var endFiscalYear = data.CreatedAt.Date.AddDays(-1); // นับจากวันที่ยื่นลา var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUserAsync(data.LeaveStartDate.Year, data.Type.Id, data.KeycloakUserId); - var sumLeave = leaveData == null ? 0 : leaveData.LeaveDaysUsed; + //var sumLeave = leaveData == null ? 0 : leaveData.LeaveDaysUsed; + + var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); return new { @@ -784,17 +790,20 @@ namespace BMA.EHR.Leave.Service.Controllers reportName = $"leave_cancel_form", data = new { - leaveWrote = data.CancelLeaveWrote ?? "", - dateSendLeave = data.CreatedAt.Date.ToThaiShortDate(), + leaveWrote = data.CancelLeaveWrote!.ToThaiNumber() ?? "", + dateSendLeave = data.CreatedAt.Date.ToThaiShortDate().ToThaiNumber(), leaveTypeName = data.Type.Name, fullname = fullName, - positionName = profile!.Position == null ? "-" : profile!.Position, - positionLeaveName = profile!.PositionLeaveName == null ? "-" : profile!.PositionLeaveName, + positionName = profile!.Position == null ? "-" : profile!.Position.ToThaiNumber(), + positionLeaveName = profile!.PositionLeaveName == null ? "-" : profile!.PositionLeaveName.ToThaiNumber(), organizationName = profile!.Oc ?? "", - leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate(), - leaveDateEnd = data.LeaveEndDate.Date.ToThaiShortDate(), - dear = data.Dear, - leaveTotal = data.LeaveTotal + leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate().ToThaiNumber(), + leaveDateEnd = data.LeaveEndDate.Date.ToThaiShortDate().ToThaiNumber(), + dear = data.CommanderPosition == null ? data.Dear : data.CommanderPosition.ToThaiNumber(), + leaveTotal = data.LeaveTotal.ToString().ToThaiNumber(), + profileType = data.ProfileType, + leaveReasonDelete = data.LeaveCancelComment == null ? "" : data.LeaveCancelComment!.ToThaiNumber(), + leaveDetail = data.LeaveDetail.ToThaiNumber(), } };