feat: enhance leave request filtering and update configuration settings
Some checks failed
release-dev / release-dev (push) Failing after 13s

This commit is contained in:
Suphonchai Phoonsawat 2025-12-12 15:18:27 +07:00
parent 23a6058eba
commit 88a48577e9
3 changed files with 71 additions and 30 deletions

View file

@ -8,6 +8,7 @@ using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.IO.Compression;
using System.Net.Http.Headers;
using System.Net.Http.Json;
@ -275,11 +276,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
public async Task<List<LeaveRequest>> GetLeaveRequestByYearForAdminAsync(int year, string role, string? nodeId, int? node)
{
var rawData = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
var rawData = _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
.Include(x => x.Type)
.Where(x => x.LeaveStartDate.Year == year)
.Where(x => x.LeaveStatus != "REJECT" && x.LeaveStatus != "DELETE")
.ToListAsync();
.Where(x => x.LeaveStatus != "REJECT" && x.LeaveStatus != "DELETE");
//.ToListAsync();
if (year != 0)
{
var startFiscalDate = new DateTime(year - 1, 10, 1);
var endFiscalDate = new DateTime(year, 9, 30);
rawData = rawData.Where(x => x.LeaveStartDate.Date >= startFiscalDate && x.LeaveStartDate.Date <= endFiscalDate);
}
if (role == "OWNER")
{
node = null;
@ -287,22 +294,22 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
if (role == "OWNER" || role == "CHILD")
{
rawData = rawData
.Where(x => node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : (node == 3 ? x.Child3DnaId == Guid.Parse(nodeId!) : (node == 2 ? x.Child2DnaId == Guid.Parse(nodeId!) : (node == 1 ? x.Child1DnaId == Guid.Parse(nodeId!) : (node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) : (node == null ? true : true)))))).ToList();
.Where(x => node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : (node == 3 ? x.Child3DnaId == Guid.Parse(nodeId!) : (node == 2 ? x.Child2DnaId == Guid.Parse(nodeId!) : (node == 1 ? x.Child1DnaId == Guid.Parse(nodeId!) : (node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) : (node == null ? true : true))))));
}
else if (role == "BROTHER")
{
rawData = rawData
.Where(x => node == 4 ? x.Child3DnaId == Guid.Parse(nodeId!) : (node == 3 ? x.Child2DnaId == Guid.Parse(nodeId!) : (node == 2 ? x.Child1DnaId == Guid.Parse(nodeId!) : (node == 1 || node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) : (node == null ? true : true))))).ToList();
.Where(x => node == 4 ? x.Child3DnaId == Guid.Parse(nodeId!) : (node == 3 ? x.Child2DnaId == Guid.Parse(nodeId!) : (node == 2 ? x.Child1DnaId == Guid.Parse(nodeId!) : (node == 1 || node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) : (node == null ? true : true)))));
}
else if (role == "ROOT")
{
rawData = rawData
.Where(x => x.RootDnaId == Guid.Parse(nodeId!)).ToList();
.Where(x => x.RootDnaId == Guid.Parse(nodeId!));
}
else if (role == "PARENT")
{
rawData = rawData
.Where(x => x.RootDnaId == Guid.Parse(nodeId!) && x.Child1DnaId != null).ToList();
.Where(x => x.RootDnaId == Guid.Parse(nodeId!) && x.Child1DnaId != null);
}
else if (role == "NORMAL")
{
@ -312,10 +319,10 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
node == 1 ? x.Child1DnaId == Guid.Parse(nodeId!) && x.Child2DnaId == null :
node == 2 ? x.Child2DnaId == Guid.Parse(nodeId!) && x.Child3DnaId == null :
node == 3 ? x.Child3DnaId == Guid.Parse(nodeId!) && x.Child4DnaId == null :
node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : true).ToList();
node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : true);
}
return rawData;
return await rawData.ToListAsync();
}
public async Task<List<LeaveRequest>> GetLeaveRequestByUserIdAsync(Guid keycloakUserId, int year, Guid type, string status)
@ -566,8 +573,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
.Where(x => x.LeaveStatus == "DELETE" || x.LeaveStatus == "DELETING")
.AsQueryable();
// if (year != 0)
// rawData = rawData.Where(x => x.LeaveStartDate.Year == year);
if (year != 0)
rawData = rawData.Where(x => x.LeaveStartDate.Year == year);
{
var startFiscalDate = new DateTime(year - 1, 10, 1);
var endFiscalDate = new DateTime(year, 9, 30);
rawData = rawData.Where(x => x.LeaveStartDate.Date >= startFiscalDate && x.LeaveStartDate.Date <= endFiscalDate);
}
if (type != Guid.Empty)
rawData = rawData.Where(x => x.Type.Id == type);
@ -901,6 +914,26 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
};
_appDbContext.Set<Notification>().Add(noti1);
}
else
{
// มีแต่ approver อย่างเดียว
var firstApprover = rawData.Approvers
.Where(x => x.ApproveType!.ToUpper() == "APPROVER")
.OrderBy(x => x.Seq)
.FirstOrDefault();
if(firstApprover != null)
{
// Send Notification
var noti2 = new Notification
{
Body = $"การขอลาของคุณ {rawData.FirstName} {rawData.LastName} รอรับการอนุมัติจากคุณ",
ReceiverUserId = firstApprover!.ProfileId,
Type = "",
Payload = $"{URL}/leave/detail/{id}",
};
_appDbContext.Set<Notification>().Add(noti2);
}
}
await _appDbContext.SaveChangesAsync();
}
@ -1127,7 +1160,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
.Where(x => x.ApproveType!.ToUpper() == "COMMANDER")
.OrderBy(x => x.Seq)
.ToList();
if (commanders.Count > 0 || commanders != null)
if (commanders.Count > 0 && commanders != null)
{
if (rawData.ApproveStep != "st3")
{