fix #2545
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m48s

This commit is contained in:
Suphonchai Phoonsawat 2026-06-04 10:01:11 +07:00
parent 077b60b1c3
commit afa5c85393
2 changed files with 19 additions and 2 deletions

View file

@ -1952,6 +1952,23 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
return 0; return 0;
} }
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
{
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
.Include(x => x.Type)
.Where(x => x.KeycloakUserId == keycloakUserId)
.Where(x => x.Type.Id == leaveTypeId)
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) < endDate))
//.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
.ToListAsync();
if (data.Count > 0)
return data.Sum(x => x.LeaveTotal);
else
return 0;
}
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate) public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
{ {
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking() var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()

View file

@ -164,7 +164,7 @@ namespace BMA.EHR.Leave.Service.Controllers
if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31)) if (toDay >= new DateTime(toDay.Year, 10, 1) && toDay <= new DateTime(toDay.Year, 12, 31))
thisYear = thisYear + 1; thisYear = thisYear + 1;
var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId); var leaveData = await _leaveBeginningRepository.GetByYearAndTypeIdForUser2Async(thisYear, data.Type.Id, data.KeycloakUserId);
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
if (leaveData != null) if (leaveData != null)
{ {
sumLeave += leaveData.BeginningLeaveDays; sumLeave += leaveData.BeginningLeaveDays;
@ -346,7 +346,7 @@ namespace BMA.EHR.Leave.Service.Controllers
//var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); //var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUser2(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear); var sumLeave = await _leaveRequestRepository.GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(data.KeycloakUserId, data.Type.Id, startFiscalYear, endFiscalYear);
if (leaveData != null) if (leaveData != null)
{ {
sumLeave += leaveData.BeginningLeaveDays; sumLeave += leaveData.BeginningLeaveDays;