fix #2551
This commit is contained in:
parent
be1f6dd84e
commit
bc29952e83
4 changed files with 50 additions and 68 deletions
|
|
@ -1935,19 +1935,17 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0;
|
||||
}
|
||||
|
||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||
{
|
||||
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||
var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year;
|
||||
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||
|
||||
// startDate/endDate คือขอบเขตปีงบประมาณ (fiscalStart/fiscalEnd) ที่ caller ส่งมา
|
||||
// ใช้ LeaveStartDate เป็นหลักในการ filter เพื่อให้กรณียื่นลาล่วงหน้าข้ามปีงบประมาณ
|
||||
// ถูกนับในปีงบประมาณของวันลาจริง (ไม่ใช้วันที่ยื่นลา)
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.Type.Id == leaveTypeId)
|
||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) <= endDate))
|
||||
.Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date)
|
||||
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||
.ToListAsync();
|
||||
|
||||
|
|
@ -1957,19 +1955,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0;
|
||||
}
|
||||
|
||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserBefore(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate)
|
||||
{
|
||||
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||
var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year;
|
||||
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.Type.Id == leaveTypeId)
|
||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ?? x.CreatedAt) < endDate))
|
||||
.Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date)
|
||||
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||
.ToListAsync();
|
||||
|
||||
|
|
@ -1979,19 +1972,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0;
|
||||
}
|
||||
|
||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
public async Task<double> GetSumApproveLeaveTotalByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate)
|
||||
{
|
||||
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||
var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year;
|
||||
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.ProfileId == profileId)
|
||||
.Where(x => x.Type.Id == leaveTypeId)
|
||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate))
|
||||
.Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date)
|
||||
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||
.ToListAsync();
|
||||
|
||||
|
|
@ -2001,38 +1989,28 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0;
|
||||
}
|
||||
|
||||
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUserByProfile(Guid profileId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||
{
|
||||
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||
var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year;
|
||||
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.ProfileId == profileId)
|
||||
.Where(x => x.Type.Id == leaveTypeId)
|
||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate))
|
||||
.Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date)
|
||||
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||
.ToListAsync();
|
||||
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
public async Task<int> GetSumApproveLeaveCountByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||
{
|
||||
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||
var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year;
|
||||
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.Type.Id == leaveTypeId)
|
||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) <= endDate))
|
||||
.Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date)
|
||||
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "APPROVE" || x.LeaveStatus == "DELETING")
|
||||
.ToListAsync();
|
||||
|
||||
|
|
@ -2046,21 +2024,16 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
/// <param name="leaveTypeId"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <param name="sendLeaveDate"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<double> GetSumDraftLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
public async Task<double> GetSumDraftLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate, DateTime sendLeaveDate)
|
||||
{
|
||||
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||
var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year;
|
||||
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.Type.Id == leaveTypeId)
|
||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt).Date >= startDate
|
||||
&& (x.DateSendLeave ?? x.CreatedAt).Date < endDate))
|
||||
.Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date)
|
||||
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "DRAFT")
|
||||
.ToListAsync();
|
||||
|
||||
|
|
@ -2078,19 +2051,14 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<double> GetSumNewLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate)
|
||||
public async Task<double> GetSumNewLeaveTotalByTypeAndRangeForUser2(Guid keycloakUserId, Guid leaveTypeId, DateTime startDate, DateTime endDate,DateTime sendLeaveDate)
|
||||
{
|
||||
// คำนวณปีงบประมาณจาก startDate (ปีงบประมาณเริ่ม 1 ต.ค. และสิ้นสุด 30 ก.ย.)
|
||||
var fiscalYear = startDate.Month >= 10 ? startDate.Year + 1 : startDate.Year;
|
||||
var fiscalStart = new DateTime(fiscalYear - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(fiscalYear, 9, 30);
|
||||
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.Type.Id == leaveTypeId)
|
||||
.Where(x => ((x.DateSendLeave ?? x.CreatedAt) >= startDate && (x.DateSendLeave ??x.CreatedAt) < endDate))
|
||||
.Where(x => x.LeaveStartDate.Date >= fiscalStart.Date && x.LeaveStartDate.Date <= fiscalEnd.Date)
|
||||
.Where(x => (x.DateSendLeave ?? x.CreatedAt) < sendLeaveDate)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => (x.LeaveStatus == "NEW" || x.LeaveStatus == "PENDING"))
|
||||
.ToListAsync();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue