diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs index 2d6f0fcf..737d42b3 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs @@ -142,6 +142,43 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants } } + public async Task> GetAdditionalCheckRequestsByAdminRole(int year, int month, string role, string nodeId, int? node) + { + try + { + var data = await _dbContext.Set().AsQueryable() + .Where(x => (x.CheckDate.Year == year && x.CheckDate.Month == month)) + .OrderByDescending(x => x.CreatedAt.Date) + .ToListAsync(); + if (role == "OWNER") + { + node = null; + } + if (role == "OWNER" || role == "CHILD") + { + data = data + .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(); + } + else if (role == "ROOT") + { + data = data + .Where(x => x.RootDnaId == Guid.Parse(nodeId!)).ToList(); + } + else if (role == "NORMAL") + { + data = data + .Where(x => node == 0 ? x.Child1DnaId == null : (node == 1 ? x.Child2DnaId == null : (node == 2 ? x.Child3DnaId == null : (node == 3 ? x.Child4DnaId == null : true)))) + .ToList(); + } + return data; + } + catch + { + throw; + } + } + #endregion } } diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs index ebf61de0..2e708df8 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs @@ -254,6 +254,38 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants return data; } + public async Task> GetTimeStampHistoryForAdminRoleAsync(DateTime startDate, DateTime endDate, string role, string nodeId, int? node) + { + var data = await _dbContext.Set() + .Where(u => u.CheckIn.Date >= startDate.Date && u.CheckIn.Date <= endDate.Date) + .OrderBy(u => u.CheckIn) + + .ToListAsync(); + if (role == "OWNER") + { + node = null; + } + if (role == "OWNER" || role == "CHILD") + { + data = data + .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(); + } + else if (role == "ROOT") + { + data = data + .Where(x => x.RootDnaId == Guid.Parse(nodeId!)) + .ToList(); + } + else if (role == "NORMAL") + { + data = data + .Where(x => node == 0 ? x.Child1DnaId == null : (node == 1 ? x.Child2DnaId == null : (node == 2 ? x.Child3DnaId == null : (node == 3 ? x.Child4DnaId == null : true)))) + .ToList(); + } + return data; + } + public async Task GetTimeStampById(Guid id) { var data = await _dbContext.Set() diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs index 2eb6f6b3..f8af29b2 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs @@ -107,6 +107,38 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants return data; } + public async Task> GetTimeStampHistoryForAdminRoleAsync(DateTime startDate, DateTime endDate, string role, string nodeId, int? node) + { + var data = await _dbContext.Set() + .Where(u => u.CheckIn.Date >= startDate.Date && u.CheckIn.Date <= endDate.Date) + .OrderBy(u => u.CheckIn) + + .ToListAsync(); + if (role == "OWNER") + { + node = null; + } + if (role == "OWNER" || role == "CHILD") + { + data = data + .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(); + } + else if (role == "ROOT") + { + data = data + .Where(x => x.RootDnaId == Guid.Parse(nodeId!)) + .ToList(); + } + else if (role == "NORMAL") + { + data = data + .Where(x => node == 0 ? x.Child1DnaId == null : (node == 1 ? x.Child2DnaId == null : (node == 2 ? x.Child3DnaId == null : (node == 3 ? x.Child4DnaId == null : true)))) + .ToList(); + } + return data; + } + public async Task GetTimeStampById(Guid id) { var data = await _dbContext.Set() diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index 71bd30ad..7c3a9449 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -684,7 +684,7 @@ namespace BMA.EHR.Application.Repositories } } - public async Task> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken) + public async Task> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, string? role, string? nodeId, int? node) { try { @@ -694,7 +694,10 @@ namespace BMA.EHR.Application.Repositories { citizenId = citizenId, firstName = firstName, - lastName = lastName + lastName = lastName, + role = role, + nodeId = nodeId, + node = node, }; var profiles = new List(); diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index 70bc1062..c45cbbd4 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -1270,7 +1270,31 @@ namespace BMA.EHR.Leave.Service.Controllers var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}"; - var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate)) + string role = jsonData["result"]?.ToString(); + var nodeId = string.Empty; + var profileAdmin = new GetUserOCAllDto(); + profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); + if (role == "NORMAL" || role == "CHILD") + { + nodeId = profileAdmin?.Node == 4 + ? profileAdmin?.Child4DnaId + : profileAdmin?.Node == 3 + ? profileAdmin?.Child3DnaId + : profileAdmin?.Node == 2 + ? profileAdmin?.Child2DnaId + : profileAdmin?.Node == 1 + ? profileAdmin?.Child1DnaId + : profileAdmin?.Node == 0 + ? profileAdmin?.RootDnaId + : ""; + } + else if (role == "ROOT") + { + nodeId = profileAdmin?.RootDnaId; + } + + //var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate)) + var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminRoleAsync(startDate, endDate, role, nodeId, profileAdmin?.Node)) .Select(d => new CheckInHistoryForAdminDto { Id = d.Id, @@ -1484,8 +1508,30 @@ namespace BMA.EHR.Leave.Service.Controllers //var count = await _processUserTimeStampRepository.GetTimeStampHistoryForAdminCountAsync(startDate, endDate); var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}"; - - var resultData = await _processUserTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate); + string role = jsonData["result"]?.ToString(); + var nodeId = string.Empty; + var profileAdmin = new GetUserOCAllDto(); + profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); + if (role == "NORMAL" || role == "CHILD") + { + nodeId = profileAdmin?.Node == 4 + ? profileAdmin?.Child4DnaId + : profileAdmin?.Node == 3 + ? profileAdmin?.Child3DnaId + : profileAdmin?.Node == 2 + ? profileAdmin?.Child2DnaId + : profileAdmin?.Node == 1 + ? profileAdmin?.Child1DnaId + : profileAdmin?.Node == 0 + ? profileAdmin?.RootDnaId + : ""; + } + else if (role == "ROOT") + { + nodeId = profileAdmin?.RootDnaId; + } + //var resultData = await _processUserTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate); + var resultData = await _processUserTimeStampRepository.GetTimeStampHistoryForAdminRoleAsync(startDate, endDate, role, nodeId, profileAdmin?.Node); var data = new List(); foreach (var d in resultData) @@ -1637,7 +1683,29 @@ namespace BMA.EHR.Leave.Service.Controllers { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } - var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? ""); + string role = jsonData["result"]?.ToString(); + var nodeId = string.Empty; + var profileAdmin = new GetUserOCAllDto(); + profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); + if (role == "NORMAL" || role == "CHILD") + { + nodeId = profileAdmin?.Node == 4 + ? profileAdmin?.Child4DnaId + : profileAdmin?.Node == 3 + ? profileAdmin?.Child3DnaId + : profileAdmin?.Node == 2 + ? profileAdmin?.Child2DnaId + : profileAdmin?.Node == 1 + ? profileAdmin?.Child1DnaId + : profileAdmin?.Node == 0 + ? profileAdmin?.RootDnaId + : ""; + } + else if (role == "ROOT") + { + nodeId = profileAdmin?.RootDnaId; + } + var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node); var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList(); @@ -1923,8 +1991,30 @@ namespace BMA.EHR.Leave.Service.Controllers { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } - - var rawData = await _additionalCheckRequestRepository.GetAdditionalCheckRequests(year, month); + string role = jsonData["result"]?.ToString(); + var nodeId = string.Empty; + var profileAdmin = new GetUserOCAllDto(); + profileAdmin = await _userProfileRepository.GetUserOCAll(Guid.Parse(UserId!), AccessToken); + if (role == "NORMAL" || role == "CHILD") + { + nodeId = profileAdmin?.Node == 4 + ? profileAdmin?.Child4DnaId + : profileAdmin?.Node == 3 + ? profileAdmin?.Child3DnaId + : profileAdmin?.Node == 2 + ? profileAdmin?.Child2DnaId + : profileAdmin?.Node == 1 + ? profileAdmin?.Child1DnaId + : profileAdmin?.Node == 0 + ? profileAdmin?.RootDnaId + : ""; + } + else if (role == "ROOT") + { + nodeId = profileAdmin?.RootDnaId; + } + //var rawData = await _additionalCheckRequestRepository.GetAdditionalCheckRequests(year, month); + var rawData = await _additionalCheckRequestRepository.GetAdditionalCheckRequestsByAdminRole(year, month, role, nodeId, profileAdmin?.Node); var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync(); if (getDefaultRound == null)