Update ค่าไปตาราง Beginning เมื่อมีการ approve การลา
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
Suphonchai Phoonsawat 2025-04-29 15:43:06 +07:00
parent 749b2b68a1
commit 6f9116ead5
2 changed files with 34 additions and 1 deletions

View file

@ -76,6 +76,27 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
return data;
}
public async Task UpdateLeaveUsageAsync(int year, Guid typeId, Guid userId, double day)
{
var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
if (pf == null)
{
throw new Exception(GlobalMessages.DataNotFound);
}
var data = await _dbContext.Set<LeaveBeginning>()
.Include(x => x.LeaveType)
.FirstOrDefaultAsync(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
if(data == null)
{
throw new Exception(GlobalMessages.DataNotFound);
}
data.LeaveDaysUsed += day;
await _dbContext.SaveChangesAsync();
}
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUserAsync(int year, Guid typeId, Guid userId)
{

View file

@ -31,6 +31,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
private readonly IApplicationDBContext _appDbContext;
private readonly MinIOLeaveService _minIOService;
private readonly LeaveBeginningRepository _leaveBeginningRepository;
private readonly string URL = string.Empty;
#endregion
@ -44,7 +46,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
IConfiguration configuration,
EmailSenderService emailSenderService,
IApplicationDBContext appDbContext,
MinIOLeaveService minIOService) : base(dbContext, httpContextAccessor)
MinIOLeaveService minIOService,
LeaveBeginningRepository leaveBeginningRepository) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
@ -56,6 +59,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
URL = (_configuration["API"]).Replace("/api/v1", "");
_minIOService = minIOService;
_leaveBeginningRepository = leaveBeginningRepository;
}
#endregion
@ -435,6 +439,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
data.LeaveCancelStatus = "APPROVE";
data.LeaveCancelComment = Reason;
// TODO : Update ไปตาราง beginning
await _leaveBeginningRepository.UpdateLeaveUsageAsync(data.LeaveStartDate.Year, data.Type.Id, data.KeycloakUserId, -1 * data.LeaveTotal);
// Send Noti
var noti = new Notification
{
@ -475,6 +482,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
await UpdateWithTrackingAsync(rawData);
// TODO : Update ไปตาราง beginning
await _leaveBeginningRepository.UpdateLeaveUsageAsync(rawData.LeaveStartDate.Year, rawData.Type.Id, rawData.KeycloakUserId, -1 * rawData.LeaveTotal);
// TODO: remove วันลา
// Send Noti
@ -876,6 +886,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
await UpdateWithTrackingAsync(rawData);
// TODO : Update ไปตาราง beginning
await _leaveBeginningRepository.UpdateLeaveUsageAsync(rawData.LeaveStartDate.Year, rawData.Type.Id, rawData.KeycloakUserId, rawData.LeaveTotal);
var _baseAPI = _configuration["API"];
var apiUrlSalary = string.Empty;