fix fiscal Year #2551
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 2m3s
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 2m3s
This commit is contained in:
parent
6843e3ff3f
commit
030098c0b9
1 changed files with 81 additions and 3 deletions
|
|
@ -130,16 +130,19 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
public async Task ProcessEarlyLeaveRequest(int year)
|
||||
{
|
||||
// Get Early Leave Request
|
||||
// Get Early Leave Request (กรองตามปีงบประมาณ: 1 ต.ค. (year-1) – 30 ก.ย. (year))
|
||||
var fiscalStart = new DateTime(year - 1, 10, 1);
|
||||
var fiscalEnd = new DateTime(year, 9, 30);
|
||||
|
||||
var leaveReq = await _dbContext.Set<LeaveRequest>()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.LeaveStatus == "APPROVE")
|
||||
.Where(x => x.LeaveStartDate.Year == year || x.LeaveEndDate.Year == year)
|
||||
.Where(x => x.LeaveStartDate.Date <= fiscalEnd && x.LeaveEndDate.Date >= fiscalStart)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var leave in leaveReq)
|
||||
{
|
||||
await GetByYearAndTypeIdForUserAsync(year, leave.Type.Id, leave.KeycloakUserId);
|
||||
await GetByYearAndTypeIdForUserWithUpdateAsync(year, leave.Type.Id, leave.KeycloakUserId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -215,6 +218,81 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return await GetOrAddForUserAsync(year, typeId, pf.Id, Factory);
|
||||
}
|
||||
|
||||
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUserWithUpdateAsync(int year, Guid typeId, Guid userId)
|
||||
{
|
||||
// var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken);
|
||||
var pf = await _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, AccessToken);
|
||||
if (pf == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date);
|
||||
|
||||
var leaveType = await _dbContext.Set<LeaveType>().FirstOrDefaultAsync(x => x.Id == typeId);
|
||||
|
||||
|
||||
var limit = 0.0;
|
||||
|
||||
var prev = _dbContext.Set<LeaveBeginning>()
|
||||
.Include(x => x.LeaveType)
|
||||
.FirstOrDefault(x => x.LeaveYear == year - 1 && x.LeaveTypeId == typeId && x.ProfileId == pf.Id);
|
||||
|
||||
var prevRemain = 0.0;
|
||||
if (prev != null)
|
||||
{
|
||||
prevRemain = prev.LeaveDays - (prev.LeaveDaysUsed ?? 0.0);
|
||||
}
|
||||
|
||||
if (govAge >= 180)
|
||||
{
|
||||
if (govAge >= 3650)
|
||||
{
|
||||
limit = 10 + prevRemain;
|
||||
if (limit > 30) limit = 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
limit = 10 + prevRemain;
|
||||
if (limit > 20) limit = 20;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
limit = 0.0;
|
||||
}
|
||||
|
||||
var data = await _dbContext.Set<LeaveBeginning>()
|
||||
.Where(x => x.LeaveYear == year && x.LeaveTypeId == typeId && x.ProfileId == pf.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
data.LeaveDays = leaveType?.Code == "LV-005" ? limit : 0;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// return new LeaveBeginning
|
||||
// {
|
||||
// LeaveYear = year,
|
||||
// LeaveTypeId = typeId,
|
||||
// ProfileId = pf.Id,
|
||||
// Prefix = pf.Prefix,
|
||||
// FirstName = pf.FirstName,
|
||||
// LastName = pf.LastName,
|
||||
// LeaveDaysUsed = 0,
|
||||
// LeaveDays = leaveType?.Code == "LV-005" ? limit : 0,
|
||||
// RootDnaId = pf.RootDnaId,
|
||||
// Child1DnaId = pf.Child1DnaId,
|
||||
// Child2DnaId = pf.Child2DnaId,
|
||||
// Child3DnaId = pf.Child3DnaId,
|
||||
// Child4DnaId = pf.Child4DnaId
|
||||
// };
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async Task<LeaveBeginning?> GetByYearAndTypeIdForUser(int year, Guid typeId, GetProfileByKeycloakIdDto? pf)
|
||||
{
|
||||
var govAge = (pf?.DateStart?.Date ?? DateTime.Now.Date).DiffDay(DateTime.Now.Date);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue