This commit is contained in:
parent
16f6eb7b50
commit
746f435ca8
1 changed files with 44 additions and 16 deletions
|
|
@ -473,7 +473,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
rawData.LeaveCancelStatus = "APPROVE";
|
||||
rawData.LeaveCancelComment = Reason;
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
|
||||
// TODO: remove วันลา
|
||||
|
||||
|
|
@ -606,7 +606,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||
|
||||
|
||||
var rawData = await GetByIdAsync(id);
|
||||
var rawData = await GetByIdWithTrackingAsync(id);
|
||||
if (rawData == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -618,6 +618,13 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
}
|
||||
|
||||
// check commander approve
|
||||
//var approvers = await _dbContext.Set<LeaveRequestApprover>()
|
||||
// //.AsNoTracking()
|
||||
// .Include(x => x.LeaveRequest)
|
||||
// .Where(x => x.LeaveRequest.Id == id && x.ApproveType == "COMMANDER")
|
||||
// .OrderBy(x => x.Seq)
|
||||
// .ToListAsync();
|
||||
|
||||
var approvers = rawData.Approvers.Where(x => x.ApproveType!.ToUpper() == "COMMANDER").OrderBy(x => x.Seq).ToList();
|
||||
|
||||
var approver = approvers.FirstOrDefault(x => x.KeycloakId == userId);
|
||||
|
|
@ -639,11 +646,33 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
var maxSeq = approvers.Max(x => x.Seq);
|
||||
|
||||
//var data = await _dbContext.Set<LeaveRequestApprover>()
|
||||
// .AsNoTracking()
|
||||
// .Include(x => x.LeaveRequest)
|
||||
// .Where(x => x.LeaveRequest.Id == id && x.KeycloakId == userId && x.ApproveType == "COMMANDER")
|
||||
// .FirstOrDefaultAsync();
|
||||
|
||||
//if(data != null)
|
||||
//{
|
||||
// data.ApproveStatus = "APPROVE";
|
||||
// data.Comment = reason;
|
||||
|
||||
// data.LastUpdatedAt = DateTime.Now;
|
||||
// data.LastUpdateUserId = userId.ToString("D");
|
||||
// data.LastUpdateFullName = FullName ?? "";
|
||||
|
||||
// await _appDbContext.SaveChangesAsync();
|
||||
//}
|
||||
|
||||
approver.ApproveStatus = "APPROVE";
|
||||
approver.Comment = reason;
|
||||
|
||||
//await _dbContext.SaveChangesAsync();
|
||||
|
||||
if (approver.Seq != maxSeq)
|
||||
{
|
||||
rawData.LeaveStatus = "PENDING";
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
|
||||
var nextApprover = approvers.FirstOrDefault(x => x.Seq == approver.Seq + 1);
|
||||
|
||||
|
|
@ -657,9 +686,6 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
};
|
||||
_appDbContext.Set<Notification>().Add(noti);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
rawData.LeaveStatus = "PENDING";
|
||||
await UpdateAsync(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -667,13 +693,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
rawData.LeaveComment = reason;
|
||||
rawData.ApproveStep = "st3";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
|
||||
// TODO: Send notification to 1st Approver
|
||||
var firstCommander = rawData.Approvers
|
||||
.Where(x => x.ApproveType!.ToUpper() == "APPROVER")
|
||||
.OrderBy(x => x.Seq)
|
||||
.FirstOrDefault();
|
||||
|
||||
// Send Notification
|
||||
var noti1 = new Notification
|
||||
{
|
||||
|
|
@ -685,7 +712,6 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task CommanderRejectLeaveRequest(Guid id, string reason)
|
||||
|
|
@ -694,7 +720,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||
|
||||
|
||||
var rawData = await GetByIdAsync(id);
|
||||
var rawData = await GetByIdWithTrackingAsync(id);
|
||||
if (rawData == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -748,7 +774,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
rawData.LeaveStatus = "PENDING";
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -756,7 +782,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
rawData.LeaveComment = reason;
|
||||
rawData.ApproveStep = "st3";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
|
||||
// TODO: Send notification to 1st Approver
|
||||
var firstCommander = rawData.Approvers
|
||||
|
|
@ -782,7 +808,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
// Get UserId from token
|
||||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||
|
||||
var rawData = await GetByIdAsync(id);
|
||||
var rawData = await GetByIdWithTrackingAsync(id);
|
||||
if (rawData == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -833,7 +859,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -847,7 +873,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
rawData.LeaveDirectorComment = reason;
|
||||
rawData.ApproveStep = "st4";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
|
||||
// TODO : Update ไปตาราง beginning
|
||||
|
||||
var _baseAPI = _configuration["API"];
|
||||
var apiUrlSalary = string.Empty;
|
||||
|
|
@ -922,7 +950,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
// Get UserId from token
|
||||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||
|
||||
var rawData = await GetByIdAsync(id);
|
||||
var rawData = await GetByIdWithTrackingAsync(id);
|
||||
if (rawData == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -973,7 +1001,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
_appDbContext.Set<Notification>().Add(noti1);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -987,7 +1015,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
rawData.LeaveDirectorComment = reason;
|
||||
rawData.ApproveStep = "st5";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
await UpdateWithTrackingAsync(rawData);
|
||||
|
||||
// Send Noti
|
||||
var noti = new Notification
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue