ปรับการเอาวันที่ใช้ไป และยอดวันลาพักผ่อนยกมา มาใช้งาน
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
Suphonchai Phoonsawat 2025-04-25 11:05:19 +07:00
parent a7b8c2786c
commit 04b17729e0
4 changed files with 56 additions and 19 deletions

View file

@ -61,5 +61,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
.Where(x => x.LeaveYear == year)
.ToListAsync();
}
public async Task<LeaveBeginning?> GetByYearAndTypeIdAsync(int year, Guid typeId)
{
return await _dbContext.Set<LeaveBeginning>()
.Include(x => x.LeaveType)
.FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId);
}
}
}

View file

@ -280,6 +280,18 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
public async Task<double> GetSumLeaveByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId, int year)
{
var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(keycloakUserId, AccessToken);
if (pf == null)
throw new Exception(GlobalMessages.DataNotFound);
var beginningLeave = await _dbContext.Set<LeaveBeginning>().AsNoTracking()
.Where(x => x.ProfileId == pf.Id)
.Where(x => x.LeaveYear == year)
.Where(x => x.LeaveTypeId == leaveTypeId)
.FirstOrDefaultAsync();
var startFiscalDate = new DateTime(year - 1, 10, 1);
var endFiscalDate = new DateTime(year, 9, 30);
@ -293,7 +305,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
//.Where(x => x.LeaveStatus != "REJECT" && x.LeaveStatus != "DELETE")
.ToListAsync();
return data.Sum(x => x.LeaveTotal);
return data.Sum(x => x.LeaveTotal) + (beginningLeave == null ? 0 : beginningLeave.LeaveDaysUsed);
}
//public async Task<double> GetSumApproveLeaveByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId, int year)