Parcourir la source

OrderRequest, attendance Filters

zinab_elgendy il y a 5 mois
Parent
commit
0794b477a2

+ 1 - 1
MTWorkHR.API/Controllers/AttendanceController.cs

@@ -23,7 +23,7 @@ namespace MTWorkHR.API.Controllers
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
-        public async Task<ActionResult<List<AttendanceDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
+        public async Task<ActionResult<List<AttendanceDto>>> GetAll([FromQuery] AttendancePagingInputDto pagingInput)
         {
             return Ok(await _AttendanceService.GetAll(pagingInput));
         }

+ 3 - 3
MTWorkHR.API/Controllers/OrderRequestController.cs

@@ -23,7 +23,7 @@ namespace MTWorkHR.API.Controllers
         [HttpGet("GetAll")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
-        public async Task<ActionResult<List<OrderRequestDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
+        public async Task<ActionResult<List<OrderRequestDto>>> GetAll([FromQuery] OrderPagingInputDto pagingInput)
         {
             return Ok(await _LeaveRequestService.GetAll(pagingInput));
         }
@@ -46,9 +46,9 @@ namespace MTWorkHR.API.Controllers
         [HttpPost("Update")]
         [ProducesResponseType(StatusCodes.Status200OK)]
 
-        public async Task Update([FromBody] OrderRequestDto input)
+        public async Task<ActionResult<OrderRequestDto>> Update([FromBody] OrderRequestDto input)
         {
-            await _LeaveRequestService.Update(input);
+            return await _LeaveRequestService.Update(input);
         }
 
         [HttpPost("Delete")]

+ 2 - 0
MTWorkHR.Application/Dtos/Attendance/OrderRequestDto.cs

@@ -25,5 +25,7 @@ namespace MTWorkHR.Application.Models
         public OrderTypeDto? OrderType { get; set; }
         public LeaveTypeDto? LeaveType { get; set; }
         public UserDto? Employee { get; set; }
+        public string? StartTime { get; set; }
+        public string? EndTime { get; set; }
     }
 }

+ 17 - 0
MTWorkHR.Application/Dtos/User/AttendancePagingInputDto.cs

@@ -0,0 +1,17 @@
+using MTWorkHR.Core.IDto;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Application.Models
+{
+    public class AttendancePagingInputDto : PagingInputDto, IAttendancePagingInputDto
+    {
+        public DateTime? SearchDate { get; set; }
+        public string? AssignedUserId { get; set; }
+
+
+    }
+}

+ 20 - 0
MTWorkHR.Application/Dtos/User/IOrderPagingInputDto.cs

@@ -0,0 +1,20 @@
+using MTWorkHR.Core.IDto;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Application.Models
+{
+    public class OrderPagingInputDto : PagingInputDto, IOrderPagingInputDto
+    {
+        public DateTime? SearchDate { get; set; }
+        public string? AssignedUserId { get; set; }
+        public long? OrderTypeId { get; set; }
+        public long? LeaveTypeId { get; set; }
+        public long? StatusId { get; set; }
+
+
+    }
+}

+ 2 - 0
MTWorkHR.Application/Services/Interfaces/IAttendanceService.cs

@@ -7,5 +7,7 @@ namespace MTWorkHR.Application.Services.Interfaces
 {
     public interface IAttendanceService : IService<Attendance, AttendanceDto, AttendanceDto>
     {
+        Task<PagingResultDto<AttendanceDto>> GetAll(AttendancePagingInputDto PagingInputDto);
+
     }
 }

+ 1 - 0
MTWorkHR.Application/Services/Interfaces/IOrderRequestService.cs

@@ -9,5 +9,6 @@ namespace MTWorkHR.Application.Services.Interfaces
     public interface IOrderRequestService : IService< OrderRequest, OrderRequestDto, OrderRequestDto>
     {
         Task<OrderRequestDto> ChangeStatus(long id, int statusId);
+        Task<PagingResultDto<OrderRequestDto>> GetAll(OrderPagingInputDto PagingInputDto);
     }
 }

+ 39 - 2
MTWorkHR.Application/Services/User/AttendanceService.cs

@@ -12,19 +12,56 @@ using MTWorkHR.Infrastructure.Entities;
 using MTWorkHR.Application.Services.Interfaces;
 using MTWorkHR.Core.Email;
 using MTWorkHR.Core.Entities;
-using MTWorkHR.Infrastructure.UnitOfWorks;
+using System.Linq.Dynamic.Core;
 
 namespace MTWorkHR.Application.Services
 {
     public class AttendanceService : BaseService<Attendance, AttendanceDto, AttendanceDto>, IAttendanceService
     {
         private readonly IUnitOfWork _unitOfWork;
+        private readonly GlobalInfo _globalInfo;
 
-        public AttendanceService(IUnitOfWork unitOfWork):base(unitOfWork)
+        public AttendanceService(IUnitOfWork unitOfWork, GlobalInfo globalInfo) :base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
+            _globalInfo = globalInfo;
         }
+        public async Task<PagingResultDto<AttendanceDto>> GetAll(AttendancePagingInputDto PagingInputDto)
+        {
+            var res = await _unitOfWork.Attendance.GetAllWithChildrenAsync();
+            var query = res.Item1;
+
+            if (_globalInfo.UserType != UserTypeEnum.Business)
+            {
+                query = query.Where(m => m.UserId == _globalInfo.UserId);
+
+            }
+            if (PagingInputDto.Filter != null)
+            {
+                var filter = PagingInputDto.Filter;
+                query = query.Where(u => u.LeaveReason!.Contains(filter) || u.UserName!.Contains(filter));
+            }
+            if(PagingInputDto.SearchDate != null)
+            {
+                query = query.Where(u => u.AttendanceDate.Date == PagingInputDto.SearchDate.Value.Date);
+            }
+            var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);
+
+            var page = order.Skip((PagingInputDto.PageNumber * PagingInputDto.PageSize) - PagingInputDto.PageSize).Take(PagingInputDto.PageSize);
+
+            var total = await query.CountAsync();
 
+            var list = MapperObject.Mapper
+                .Map<IList<AttendanceDto>>(await page.ToListAsync());
+
+            var response = new PagingResultDto<AttendanceDto>
+            {
+                Result = list,
+                Total = total
+            };
+
+            return response;
+        }
 
         public override async Task<AttendanceDto> Create(AttendanceDto input)
         {

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

@@ -98,7 +98,7 @@ namespace MTWorkHR.Application.Services
             if (PagingInputDto.Filter != null)
             {
                 var filter = PagingInputDto.Filter;
-                query = query.Where(u => u.Title.Contains(filter) || u.Description.Contains(filter));
+                query = query.Where(u => u.Title.Contains(filter) || u.Description!.Contains(filter));
             }
 
             var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);

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

@@ -15,6 +15,7 @@ using MTWorkHR.Core.Entities;
 using MTWorkHR.Infrastructure.UnitOfWorks;
 using MTWorkHR.Core.Entities.User;
 using System.Linq.Dynamic.Core;
+using Microsoft.AspNetCore.Http;
 
 namespace MTWorkHR.Application.Services
 {
@@ -44,7 +45,7 @@ namespace MTWorkHR.Application.Services
             return response;
         }
       
-        public override async Task<PagingResultDto<OrderRequestDto>> GetAll(PagingInputDto PagingInputDto)
+        public  async Task<PagingResultDto<OrderRequestDto>> GetAll(OrderPagingInputDto PagingInputDto)
         {
             var res = await _unitOfWork.OrderRequest.GetAllWithChildrenAsync();
             var query = res.Item1;
@@ -53,7 +54,31 @@ namespace MTWorkHR.Application.Services
                 query = query.Where(m => m.RequestingEmployeeId != null && m.RequestingEmployeeId == _globalInfo.UserId);
 
             }
-
+            if (PagingInputDto.Filter != null)
+            {
+                var filter = PagingInputDto.Filter;
+                query = query.Where(u => u.RequestComments!.Contains(filter) 
+                || u.OrderType.NameEn!.Contains(filter)
+                || u.OrderType.NameAr!.Contains(filter)
+                || u.LeaveType!.NameEn!.Contains(filter)
+                || u.LeaveType!.NameAr!.Contains(filter));
+            }
+            if (PagingInputDto.SearchDate != null)
+            {
+                query = query.Where(u => u.StartDate.Date <= PagingInputDto.SearchDate.Value.Date && u.EndDate!.Value.Date >= PagingInputDto.SearchDate.Value.Date) ;
+            }
+            if (PagingInputDto.OrderTypeId != null)
+            {
+                query = query.Where(u => u.OrderTypeId == PagingInputDto.OrderTypeId);
+            }
+            if (PagingInputDto.LeaveTypeId != null)
+            {
+                query = query.Where(u => u.LeaveTypeId == PagingInputDto.LeaveTypeId);
+            }
+            if (PagingInputDto.StatusId != null)
+            {
+                query = query.Where(u => (long?)u.OrderStatus == PagingInputDto.StatusId);
+            }
             var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);
 
             var page = order.Skip((PagingInputDto.PageNumber * PagingInputDto.PageSize) - PagingInputDto.PageSize).Take(PagingInputDto.PageSize);
@@ -62,7 +87,34 @@ namespace MTWorkHR.Application.Services
 
             var list = MapperObject.Mapper
                 .Map<IList<OrderRequestDto>>(await page.ToListAsync());
-
+            foreach (var item in list)
+            {
+                if (item.RequestingEmployeeId != null)
+                {
+                    var user = await _userService.GetUserWithAttachmentById(item.RequestingEmployeeId);
+                    if (user != null)
+                    {
+                        item.Employee = user;
+                        var attach = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
+                        if(attach != null)
+                        using (var stream = new MemoryStream(attach.Content))
+                        {
+                            var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName)
+                            {
+                                Headers = new HeaderDictionary(),
+                                ContentType = attach.ContentType,
+                            };
+
+                            System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
+                            {
+                                FileName = file.FileName
+                            };
+                            file.ContentDisposition = cd.ToString();
+                            item.Employee.ProfileImage = file;
+                        }
+                    }
+                }
+            }
             var response = new PagingResultDto<OrderRequestDto>
             {
                 Result = list,
@@ -117,7 +169,31 @@ namespace MTWorkHR.Application.Services
                 //// Log or handle error, but don't throw...
             }
             var response = MapperObject.Mapper.Map<OrderRequestDto>(orderRequest);
-
+            if (response.RequestingEmployeeId != null)
+            {
+                var user = await _userService.GetUserWithAttachmentById(response.RequestingEmployeeId);
+                if (user != null)
+                {
+                    response.Employee = user;
+                    var attach = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
+                    if (attach != null)
+                        using (var stream = new MemoryStream(attach.Content))
+                        {
+                            var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName)
+                            {
+                                Headers = new HeaderDictionary(),
+                                ContentType = attach.ContentType,
+                            };
+
+                            System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
+                            {
+                                FileName = file.FileName
+                            };
+                            file.ContentDisposition = cd.ToString();
+                            response.Employee.ProfileImage = file;
+                        }
+                }
+            }
             return response;
         }
 

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

@@ -43,7 +43,7 @@ namespace MTWorkHR.Application.Services
             if (PagingInputDto.Filter != null)
             {
                 var filter = PagingInputDto.Filter;
-                query = query.Where(u => u.NameAr.Contains(filter) );
+                query = query.Where(u => u.NameAr.Contains(filter) || u.NameEn.Contains(filter));
             }
            
             var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);

+ 1 - 0
MTWorkHR.Core/Entities/Attendance/Attendance.cs

@@ -22,6 +22,7 @@ namespace MTWorkHR.Core.Entities
         public CheckOutEnum LeaveType { get; set; }
 
         [MaxLength(250)]
+        [Filter]
         public string? LeaveReason { get; set; }
         public long CompanyId { get; set; }
     }

+ 5 - 1
MTWorkHR.Core/Entities/Attendance/OrderRequest.cs

@@ -21,13 +21,17 @@ namespace MTWorkHR.Core.Entities.User
         [ForeignKey("LeaveTypeId")]
         public LeaveType? LeaveType { get; set; }
         public long? LeaveTypeId { get; set; }
-
+        [Filter]
         public string? RequestComments { get; set; }
         public ApprovalStatusEnum? OrderStatus { get; set; }
         [Filter]
         public string RequestingEmployeeId { get; set; }
         public int? CountryId{ get; set; }
         public int? CityId { get; set; }
+        public string? StartTime { get; set; }
+        public string? EndTime { get; set; }
+
         public long CompanyId { get ; set ; }
+
     }
 }

+ 11 - 0
MTWorkHR.Core/IDto/IAttendancePagingInputDto.cs

@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+
+namespace MTWorkHR.Core.IDto
+{
+    public interface IAttendancePagingInputDto:IPagingInputDto
+    {
+        public DateTime? SearchDate { get; set; }
+        public string? AssignedUserId { get; set; }
+
+    }
+}

+ 11 - 0
MTWorkHR.Core/IDto/IOrderPagingInputDto.cs

@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+
+namespace MTWorkHR.Core.IDto
+{
+    public interface IOrderPagingInputDto:IPagingInputDto
+    {
+        public DateTime? SearchDate { get; set; }
+        public string? AssignedUserId { get; set; }
+
+    }
+}

+ 1 - 1
MTWorkHR.Core/IRepositories/User/IAttendanceRepository.cs

@@ -11,6 +11,6 @@ namespace MTWorkHR.Core.IRepositories
     public interface IAttendanceRepository : IRepository<Attendance>
     {
         Task<Attendance> GetAttendanceByUserId(string userId, DateTime attendanceDate);
-
+        Task<Tuple<IQueryable<Attendance>, int>> GetAllWithChildrenAsync();
     }
 }

Fichier diff supprimé car celui-ci est trop grand
+ 3492 - 0
MTWorkHR.Infrastructure/Migrations/20240805065600_altrOrderRequest.Designer.cs


+ 38 - 0
MTWorkHR.Infrastructure/Migrations/20240805065600_altrOrderRequest.cs

@@ -0,0 +1,38 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrOrderRequest : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.AddColumn<string>(
+                name: "EndTime",
+                table: "OrderRequests",
+                type: "nvarchar(max)",
+                nullable: true);
+
+            migrationBuilder.AddColumn<string>(
+                name: "StartTime",
+                table: "OrderRequests",
+                type: "nvarchar(max)",
+                nullable: true);
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropColumn(
+                name: "EndTime",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "StartTime",
+                table: "OrderRequests");
+        }
+    }
+}

+ 6 - 0
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -2189,6 +2189,9 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<DateTime?>("EndDate")
                         .HasColumnType("datetime2");
 
+                    b.Property<string>("EndTime")
+                        .HasColumnType("nvarchar(max)");
+
                     b.Property<bool>("IsDeleted")
                         .HasColumnType("bit")
                         .HasColumnOrder(7);
@@ -2212,6 +2215,9 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<DateTime>("StartDate")
                         .HasColumnType("datetime2");
 
+                    b.Property<string>("StartTime")
+                        .HasColumnType("nvarchar(max)");
+
                     b.Property<DateTime?>("UpdateDate")
                         .HasColumnType("datetime2")
                         .HasColumnOrder(4);

+ 9 - 0
MTWorkHR.Infrastructure/Repositories/User/AttendanceRepository.cs

@@ -24,5 +24,14 @@ namespace MTWorkHR.Infrastructure.Repositories
                 .FirstOrDefaultAsync(x => x.UserId == userId && x.AttendanceDate.Date == attendanceDate.Date);
             return result;
         }
+
+
+        public async Task<Tuple<IQueryable<Attendance>, int>> GetAllWithChildrenAsync()
+        {
+            var query = dbSet.AsQueryable();
+            var total = await query.CountAsync();
+
+            return new Tuple<IQueryable<Attendance>, int>(query, total);
+        }
     }
 }