瀏覽代碼

HRDetails

zinab_elgendy 2 月之前
父節點
當前提交
0b1e4a6fe5

+ 8 - 1
MTWorkHR.API/Controllers/HRController.cs

@@ -27,6 +27,13 @@ namespace MTWorkHR.API.Controllers
         {
             return Ok(await _ContractService.GetAllForHr(pagingInput));
         }
-       
+
+        [HttpGet("GetByIdHRDetails")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+        public async Task<ActionResult<ContractDto>> GetByIdHRDetails([FromQuery] long contractId)
+        {
+            return Ok(await _ContractService.GetByIdHRDetails(contractId));
+        }
+
     }
 }

+ 4 - 0
MTWorkHR.Application/Dtos/Contract/ContractDto.cs

@@ -1,4 +1,5 @@
 using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities;
 using MTWorkHR.Core.Entities.Base;
 using MTWorkHR.Core.Global;
 using Newtonsoft.Json;
@@ -77,6 +78,9 @@ namespace MTWorkHR.Application.Models
         public string? Teams{ get; set; }
         public string? Vacations{ get; set; }
 
+        //__________________HR data_________-
+        public List<TeamDto>? TeamList { get; set; }
+        public List<OrderRequestDto>? OrderList { get; set; }
 
 
         //---------Allowances----------------------

+ 32 - 1
MTWorkHR.Application/Services/Contract/ContractService.cs

@@ -125,6 +125,8 @@ namespace MTWorkHR.Application.Services
 
             return response;
         }
+
+        #region HR data____________________________
         public async Task<PagingResultDto<ContractDto>> GetAllForHr(ContractPagingInputDto PagingInputDto)
         {
             var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
@@ -193,7 +195,36 @@ namespace MTWorkHR.Application.Services
 
             return response;
         }
-
+        public async Task<ContractDto> GetByIdHRDetails(long id)
+        {
+            var entity = await _unitOfWork.Contract.GetByIdWithAllChildren(id);
+            if (entity != null)
+            {
+                var response = MapperObject.Mapper.Map<ContractDto>(entity);
+                response.WorkingDays = entity.WorkingDays != null ? entity.WorkingDays.Split(",").ToList() : null;
+                //--------------------
+                var user = await _userService.GetUserWithAttachmentById(entity.UserId);
+                response.EmployeeName = user.FirstName + " " + user.LastName;
+                response.EmployeeEmail = user.Email;
+                //___________Get Teams
+                var teamUsersList = await _unitOfWork.TeamUser.GetUserTeams(entity.UserId);
+                var teamsList = MapperObject.Mapper.Map<List<TeamDto>>(teamUsersList.Item1);
+
+                response.TeamList = teamsList;
+                //_____________Get vacation balance
+                var vacationAllocations = await _unitOfWork.OrderAllocation.GetUserAllocations(entity.UserId, 1, 1, entity.Id, DateTime.Now.Year);
+                var remainVacations = vacationAllocations;
+                response.Vacations = remainVacations == null ? "" : remainVacations.NumberOfDays + " / " + entity.VacationDays;
+                //__-----------Order Requests----
+                var orderRequestsList = await _unitOfWork.OrderRequest.GetAllUserOrdersAsync(entity.UserId);
+                var orderList = MapperObject.Mapper.Map<List<OrderRequestDto>>(orderRequestsList.Item1);
+
+                response.OrderList = orderList;
+                return response;
+            }
+            return new ContractDto();
+        }
+        #endregion
         public async Task<bool> ChangeStatus(long contractId, int statusId)
         {
             var entity = await _unitOfWork.Contract.GetByIdAsync(contractId);

+ 1 - 1
MTWorkHR.Application/Services/Interfaces/IContractService.cs

@@ -10,6 +10,6 @@ namespace MTWorkHR.Application.Services.Interfaces
         Task<PagingResultDto<ContractDto>> GetAll(ContractPagingInputDto PagingInputDto);
         Task<PagingResultDto<ContractDto>> GetAllForHr(ContractPagingInputDto PagingInputDto);
         Task<bool> ChangeStatus(long contractId, int statusId);
-
+        Task<ContractDto> GetByIdHRDetails(long id);
     }
 }

+ 1 - 1
MTWorkHR.Application/Services/User/OrderAllocationService.cs

@@ -47,7 +47,7 @@ namespace MTWorkHR.Application.Services
                 var allocations = new List<OrderAllocation>();
                 foreach (var emp in employees)
                 {
-                    if (await _unitOfWork.OrderAllocation.AllocationExists(emp.Id, orderType.Id, input.LeaveTypeId, period))
+                    if (await _unitOfWork.OrderAllocation.AllocationExists(emp.Id, orderType.Id, input.LeaveTypeId,0, period))
                         continue;
                     allocations.Add(new OrderAllocation
                     {

+ 4 - 2
MTWorkHR.Application/Services/User/OrderRequestService.cs

@@ -132,7 +132,8 @@ namespace MTWorkHR.Application.Services
             }
             if(input.OrderTypeId == 1 &&  input.LeaveTypeId == 1) // Annual vacation in contract
             {
-                var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, period);
+                var contractId = await _unitOfWork.Contract.GetLatestActiveContract(input.RequestingEmployeeId);
+                var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, contractId.Id, period);
 
                 if (allocation is null)
                 {
@@ -208,7 +209,8 @@ namespace MTWorkHR.Application.Services
             orderRequest.OrderStatus = (ApprovalStatusEnum)statusId;
             if (orderRequest.OrderStatus == ApprovalStatusEnum.Approved)
             {
-                var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(orderRequest.RequestingEmployeeId, orderRequest.OrderTypeId, orderRequest.LeaveTypeId, DateTime.Now.Year);
+                var contractId = await _unitOfWork.Contract.GetLatestActiveContract(orderRequest.RequestingEmployeeId);
+                var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(orderRequest.RequestingEmployeeId, orderRequest.OrderTypeId, orderRequest.LeaveTypeId,contractId.Id, DateTime.Now.Year);
                 if (allocation != null)
                 {
                     int daysRequested = !orderRequest.EndDate.HasValue ? 1 : (int)(orderRequest.EndDate.Value - orderRequest.StartDate).TotalDays;

+ 1 - 0
MTWorkHR.Core/IRepositories/Contract/IContractRepository.cs

@@ -11,6 +11,7 @@ namespace MTWorkHR.Core.IRepositories
     public interface IContractRepository : IRepository<Contract>
     {
         Task<Contract> GetByIdWithAllChildren(long id);
+        Task<Contract> GetLatestActiveContract(string userId);
         Task<Tuple<IQueryable<Contract>, int>> GetAllWithChildrenAsync();
     }
 }

+ 2 - 2
MTWorkHR.Core/IRepositories/User/IOrderAllocationRepository.cs

@@ -10,9 +10,9 @@ namespace MTWorkHR.Core.IRepositories
 {
     public interface IOrderAllocationRepository : IRepository<OrderAllocation>
     {
-        Task<bool> AllocationExists(string userId, long orderTypeId, long? leaveTypeId, int period);
+        Task<bool> AllocationExists(string userId, long orderTypeId, long? leaveTypeId, long contractId, int period);
         Task<OrderAllocation> GetByIdWithAllChildren(long id);
-        Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long? leaveTypeId, int period);
+        Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long? leaveTypeId, long contractId, int period);
 
     }
 }

+ 1 - 0
MTWorkHR.Core/IRepositories/User/IOrderRequestRepository.cs

@@ -13,6 +13,7 @@ namespace MTWorkHR.Core.IRepositories
     {
        Task<OrderRequest> GetByIdWithAllChildren(long id);
         Task<Tuple<IQueryable<OrderRequest>, int>> GetAllWithChildrenAsync();
+        Task<Tuple<IQueryable<OrderRequest>, int>> GetAllUserOrdersAsync(string userId);
 
     }
 }

+ 10 - 1
MTWorkHR.Infrastructure/Repositories/Contract/ContractRepository.cs

@@ -4,6 +4,7 @@ using MTWorkHR.Core.IDto;
 using MTWorkHR.Core.IRepositories;
 using MTWorkHR.Infrastructure.Entities;
 using MTWorkHR.Infrastructure.DBContext;
+using MTWorkHR.Core.Global;
 
 namespace MTWorkHR.Infrastructure.Repositories
 {
@@ -23,9 +24,17 @@ namespace MTWorkHR.Infrastructure.Repositories
                 .Include(x => x.ContractTasks)
                 .Include(x => x.FixedAllowances)
                 .Include(x => x.ProjectStages)
-                .Include(x => x.WorkingDays)
+            //    .Include(x => x.WorkingDays)
                 .FirstOrDefaultAsync(x => x.Id == id);
         }
+        public async Task<Contract> GetLatestActiveContract(string userId)
+        {
+            return await dbSet
+                .FirstOrDefaultAsync(x => x.UserId == userId 
+                && x.ContractStatusId == (int)ContractStatusEnum.Approved
+                && x.StartDate <= DateTime.Now.Date
+                && (x.EndDate == null || x.EndDate < DateTime.Now.Date));
+        }
 
 
         public async Task<Tuple<IQueryable<Contract>, int>> GetAllWithChildrenAsync()

+ 6 - 4
MTWorkHR.Infrastructure/Repositories/User/OrderAllocationRepository.cs

@@ -25,19 +25,21 @@ namespace MTWorkHR.Infrastructure.Repositories
 
      
 
-        public async Task<bool> AllocationExists(string userId, long orderTypeId, long? leaveTypeId, int period)
+        public async Task<bool> AllocationExists(string userId, long orderTypeId, long? leaveTypeId, long contractId, int period)
         {
             return await dbSet.AnyAsync(q => q.EmployeeId == userId
+                                        && q.ContractId == contractId   
                                         && q.OrderTypeId == orderTypeId
-                                        && q.Period == period
+                                      //  && q.Period == period
                                         && (!leaveTypeId.HasValue || leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId));
         }
 
-        public async Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long? leaveTypeId, int period)
+        public async Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long? leaveTypeId, long contractId, int period)
         {
             return await dbSet.FirstOrDefaultAsync(q => q.EmployeeId == userId
+                                        && q.ContractId == contractId
                                         && q.OrderTypeId == orderTypeId
-                                        && q.Period == period
+                                        //&& q.Period == period
                                         && (!leaveTypeId.HasValue || leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId));
         }
     }

+ 8 - 0
MTWorkHR.Infrastructure/Repositories/User/OrderRequestRepository.cs

@@ -30,5 +30,13 @@ namespace MTWorkHR.Infrastructure.Repositories
 
             return new Tuple<IQueryable<OrderRequest>, int>(query, total);
         }
+
+        public async Task<Tuple<IQueryable<OrderRequest>, int>> GetAllUserOrdersAsync(string userId)
+        {
+            var query = dbSet.Include(x => x.OrderType).Include(x => x.LeaveType).Where(a=> a.RequestingEmployeeId == userId).AsQueryable();
+            var total = await query.CountAsync();
+
+            return new Tuple<IQueryable<OrderRequest>, int>(query, total);
+        }
     }
 }