Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop
This commit is contained in:
commit
31c21469ec
13 changed files with 3455 additions and 86 deletions
|
|
@ -10313,7 +10313,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
.Where(x => x.Receivers.Where(x => x.RefPlacementProfileId == id).FirstOrDefault() != null)
|
||||
.Select(x => new
|
||||
{
|
||||
CommandSubject = x.CommandSubject,
|
||||
CommandSubject = $"{x.CommandNo}/{Int32.Parse(x.CommandYear) + 543} {x.CommandSubject}",
|
||||
CreatedAt = x.CreatedAt,
|
||||
LastUpdatedAt = x.LastUpdatedAt,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var isDuplicate = await CheckDuplicateLeave(rawData.KeycloakUserId, rawData.LeaveStartDate.Date, rawData.LeaveEndDate.Date);
|
||||
var isDuplicate = await CheckDuplicateLeave(rawData.KeycloakUserId, rawData.LeaveStartDate.Date, rawData.LeaveEndDate.Date, rawData.LeaveRange ?? "ALL");
|
||||
if (isDuplicate)
|
||||
{
|
||||
throw new Exception("ไม่สามารถขอลาในช่วงเวลาเดียวกันได้ เนื่องจากมีการขอลาในช่วงเวลาดังกล่าวแล้ว");
|
||||
|
|
@ -577,17 +577,34 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckDuplicateLeave(Guid keycloakUserId, DateTime startDate, DateTime endDate)
|
||||
public async Task<bool> CheckDuplicateLeave(Guid keycloakUserId, DateTime startDate, DateTime endDate, string range)
|
||||
{
|
||||
var leaveStatus = new List<string>() { "NEW", "PENDING", "APPROVE" };
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
|
||||
.Where(x => leaveStatus.Contains(x.LeaveStatus))
|
||||
.ToListAsync();
|
||||
if (range == "ALL")
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
//.Where(x => x.LeaveRange == "ALL")
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
|
||||
.Where(x => leaveStatus.Contains(x.LeaveStatus))
|
||||
.ToListAsync();
|
||||
|
||||
return data.Count > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.LeaveRange == range)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
|
||||
.Where(x => leaveStatus.Contains(x.LeaveStatus))
|
||||
.ToListAsync();
|
||||
|
||||
return data.Count > 0;
|
||||
}
|
||||
|
||||
return data.Count > 0;
|
||||
}
|
||||
|
||||
public async Task DeleteLeaveDocumentAsync(Guid Id)
|
||||
|
|
@ -602,6 +619,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<LeaveRequest?> GetLeavePeriodAsync(Guid keycloakUserId, DateTime date)
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStatus == "APPROVE")
|
||||
.Where(x => x.LeaveStartDate.Date >= date.Date && x.LeaveEndDate <= date.Date)
|
||||
.FirstOrDefaultAsync();
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue