Update ค่าไปตาราง Beginning เมื่อมีการ approve การลา
Some checks failed
release-dev / release-dev (push) Failing after 11s
Some checks failed
release-dev / release-dev (push) Failing after 11s
This commit is contained in:
parent
749b2b68a1
commit
6f9116ead5
2 changed files with 34 additions and 1 deletions
|
|
@ -76,6 +76,27 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
return data;
|
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)
|
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUserAsync(int year, Guid typeId, Guid userId)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
private readonly IApplicationDBContext _appDbContext;
|
private readonly IApplicationDBContext _appDbContext;
|
||||||
private readonly MinIOLeaveService _minIOService;
|
private readonly MinIOLeaveService _minIOService;
|
||||||
|
|
||||||
|
private readonly LeaveBeginningRepository _leaveBeginningRepository;
|
||||||
|
|
||||||
private readonly string URL = string.Empty;
|
private readonly string URL = string.Empty;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -44,7 +46,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
EmailSenderService emailSenderService,
|
EmailSenderService emailSenderService,
|
||||||
IApplicationDBContext appDbContext,
|
IApplicationDBContext appDbContext,
|
||||||
MinIOLeaveService minIOService) : base(dbContext, httpContextAccessor)
|
MinIOLeaveService minIOService,
|
||||||
|
LeaveBeginningRepository leaveBeginningRepository) : base(dbContext, httpContextAccessor)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
|
@ -56,6 +59,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
|
|
||||||
URL = (_configuration["API"]).Replace("/api/v1", "");
|
URL = (_configuration["API"]).Replace("/api/v1", "");
|
||||||
_minIOService = minIOService;
|
_minIOService = minIOService;
|
||||||
|
_leaveBeginningRepository = leaveBeginningRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -435,6 +439,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
data.LeaveCancelStatus = "APPROVE";
|
data.LeaveCancelStatus = "APPROVE";
|
||||||
data.LeaveCancelComment = Reason;
|
data.LeaveCancelComment = Reason;
|
||||||
|
|
||||||
|
// TODO : Update ไปตาราง beginning
|
||||||
|
await _leaveBeginningRepository.UpdateLeaveUsageAsync(data.LeaveStartDate.Year, data.Type.Id, data.KeycloakUserId, -1 * data.LeaveTotal);
|
||||||
|
|
||||||
// Send Noti
|
// Send Noti
|
||||||
var noti = new Notification
|
var noti = new Notification
|
||||||
{
|
{
|
||||||
|
|
@ -475,6 +482,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
|
|
||||||
await UpdateWithTrackingAsync(rawData);
|
await UpdateWithTrackingAsync(rawData);
|
||||||
|
|
||||||
|
// TODO : Update ไปตาราง beginning
|
||||||
|
await _leaveBeginningRepository.UpdateLeaveUsageAsync(rawData.LeaveStartDate.Year, rawData.Type.Id, rawData.KeycloakUserId, -1 * rawData.LeaveTotal);
|
||||||
|
|
||||||
// TODO: remove วันลา
|
// TODO: remove วันลา
|
||||||
|
|
||||||
// Send Noti
|
// Send Noti
|
||||||
|
|
@ -876,6 +886,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
await UpdateWithTrackingAsync(rawData);
|
await UpdateWithTrackingAsync(rawData);
|
||||||
|
|
||||||
// TODO : Update ไปตาราง beginning
|
// TODO : Update ไปตาราง beginning
|
||||||
|
await _leaveBeginningRepository.UpdateLeaveUsageAsync(rawData.LeaveStartDate.Year, rawData.Type.Id, rawData.KeycloakUserId, rawData.LeaveTotal);
|
||||||
|
|
||||||
|
|
||||||
var _baseAPI = _configuration["API"];
|
var _baseAPI = _configuration["API"];
|
||||||
var apiUrlSalary = string.Empty;
|
var apiUrlSalary = string.Empty;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue