diff --git a/Company.Domain/LeaveAgg/ILeaveRepository.cs b/Company.Domain/LeaveAgg/ILeaveRepository.cs index d5c96aa4..cc050bf1 100644 --- a/Company.Domain/LeaveAgg/ILeaveRepository.cs +++ b/Company.Domain/LeaveAgg/ILeaveRepository.cs @@ -1,8 +1,10 @@ -using System; -using System.Collections.Generic; -using _0_Framework.Application; +using _0_Framework.Application; using _0_Framework.Domain; +using CompanyManagment.App.Contracts.InstitutionPlan; using CompanyManagment.App.Contracts.Leave; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Company.Domain.LeaveAgg; @@ -34,4 +36,13 @@ public interface ILeaveRepository : IRepository #endregion bool CheckIfValidToEdit(long id); + + /// + /// دریافت لیست مرخصی ها در کلاینت + /// Api + /// + /// + /// + Task> GetList( + LeaveListSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs index a43de371..e7588892 100644 --- a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs +++ b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs @@ -36,5 +36,15 @@ public interface ILeaveApplication TimeSpan GetEmployeeLeaveTimeSpanInDates(long workshopId, long employeeId, string startFa, string endFa, string type); - #endregion + #endregion + + + /// + /// دریافت لیست مرخصی ها در کلاینت + /// Api + /// + /// + /// + Task> GetList( + LeaveListSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Leave/LeaveListSearchModel.cs b/CompanyManagment.App.Contracts/Leave/LeaveListSearchModel.cs new file mode 100644 index 00000000..b117f4b0 --- /dev/null +++ b/CompanyManagment.App.Contracts/Leave/LeaveListSearchModel.cs @@ -0,0 +1,45 @@ +using _0_Framework.Application; + +namespace CompanyManagment.App.Contracts.Leave; + +public class LeaveListSearchModel : PaginationRequest +{ + /// + /// آی دی کارگاه + /// + public long WorkshopId { get; set; } + /// + /// نوع مرخصی، استحقاقی/استعلاجی + /// + public LeaveType LeaveType { get; set; } + + /// + /// سال مرخصی + /// + public string YearStr { get; set; } + + /// + /// ماه مرخصی + /// + public string MonthStr { get; set; } + + /// + ///آیا فاقد اعتبار است. فاقد اعتبار ها فقط برای فیش های غیررسمی مورد استفاده قرار میگیرند + /// + public bool IsInvalid { get; private set; } + + /// + /// تاریخ شروع مرخصی + /// + public string StartLeave { get; set; } + + /// + /// تاریخ پایان مرخصی + /// + public string EndLeave { get; set; } + + /// + /// آی دی پرسنل + /// + public long EmployeeId { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Leave/LeaveType.cs b/CompanyManagment.App.Contracts/Leave/LeaveType.cs new file mode 100644 index 00000000..66244f63 --- /dev/null +++ b/CompanyManagment.App.Contracts/Leave/LeaveType.cs @@ -0,0 +1,18 @@ +namespace CompanyManagment.App.Contracts.Leave; + +public enum LeaveType +{ + /// + /// هر دو + /// + Both, + /// + /// مرخصی استعلاجی + /// + SickLeave, + + /// + /// مرخصی استحقاقی + /// + PaidLeave +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Leave/leaveListDto.cs b/CompanyManagment.App.Contracts/Leave/leaveListDto.cs index aae584aa..dee78fe4 100644 --- a/CompanyManagment.App.Contracts/Leave/leaveListDto.cs +++ b/CompanyManagment.App.Contracts/Leave/leaveListDto.cs @@ -39,7 +39,7 @@ public class leaveListDto /// /// زمان مرخصی - /// باز مرخصی ساعتی + /// بازه مرخصی ساعتی /// public string HourlyInterval { get; set; } @@ -80,5 +80,5 @@ public class leaveListDto /// ///آیا فاقد اعتبار است. فاقد اعتبار ها فقط برای فیش های غیررسمی مورد استفاده قرار میگیرند /// - public bool IsInvalid { get; private set; } + public bool IsInvalid { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/LeaveApplication.cs b/CompanyManagment.Application/LeaveApplication.cs index bbd79520..9b7acbcd 100644 --- a/CompanyManagment.Application/LeaveApplication.cs +++ b/CompanyManagment.Application/LeaveApplication.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg; @@ -590,11 +591,23 @@ public class LeaveApplication : ILeaveApplication return leaveTotalTimeSpan; } - private TimeSpan CalculateTotalLeaveTimeSpan(List leaves) + + + private TimeSpan CalculateTotalLeaveTimeSpan(List leaves) { var timeSpanHourlyLeave = new TimeSpan(leaves.Where(x => x.PaidLeaveType != "روزانه").Sum(x => (x.EndLeaveGr - x.StartLeaveGr).Ticks)); var dailyLeaveCount = leaves.Count(x => x.PaidLeaveType == "روزانه") * new TimeSpan(1, 0, 0, 0); return timeSpanHourlyLeave + dailyLeaveCount; } - #endregion + #endregion + + + #region ForApi + + public async Task> GetList(LeaveListSearchModel searchModel) + { + return await _leaveRepository.GetList(searchModel); + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/LeaveRepository.cs b/CompanyManagment.EFCore/Repository/LeaveRepository.cs index e76e682e..a2c14461 100644 --- a/CompanyManagment.EFCore/Repository/LeaveRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeaveRepository.cs @@ -1,23 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using _0_Framework.Application; +using _0_Framework.Application; using _0_Framework.InfraStructure; +using Azure.Core; using Company.Domain.LeaveAgg; using CompanyManagment.App.Contracts.Checkout; +using CompanyManagment.App.Contracts.InstitutionPlan; using CompanyManagment.App.Contracts.Leave; using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace CompanyManagment.EFCore.Repository; public class LeaveRepository : RepositoryBase, ILeaveRepository { private readonly CompanyContext _context; - private readonly long _workshopId; - public LeaveRepository(CompanyContext context, IAuthHelper authHelper) : base(context) + + public LeaveRepository(CompanyContext context) : base(context) { _context = context; - _workshopId = authHelper.GetWorkshopId(); + } public EditLeave GetDetails(long id) @@ -372,6 +375,8 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository } } + + public OperationResult RemoveLeave(long id) { var op = new OperationResult(); @@ -541,7 +546,103 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository #region ForApi - + public async Task> GetList(LeaveListSearchModel searchModel) + { + var query = _context.LeaveList.Where(x => x.WorkshopId == searchModel.WorkshopId); + + if (searchModel.EmployeeId != 0) + query = query.Where(x => x.EmployeeId == searchModel.EmployeeId); + + if (searchModel.LeaveType == LeaveType.PaidLeave) + query = query.Where(x => x.LeaveType == "استحقاقی"); + + if (searchModel.LeaveType == LeaveType.SickLeave) + query = query.Where(x => x.LeaveType == "استعلاجی"); + + if (searchModel.IsInvalid) + { + query = query.IgnoreQueryFilters().Where(x => x.IsInvalid); + } + + if (!string.IsNullOrWhiteSpace(searchModel.StartLeave) && !string.IsNullOrWhiteSpace(searchModel.EndLeave)) + { + var start = new DateTime(); + var end = new DateTime(); + try + { + start = searchModel.StartLeave.ToGeorgianDateTime(); + end = searchModel.EndLeave.ToGeorgianDateTime(); + } + catch (Exception e) + { + return new PagedResult(); + } + + query = query.Where(x => x.StartLeave >= start && x.EndLeave <= end); + } + else if (!string.IsNullOrWhiteSpace(searchModel.YearStr) || !string.IsNullOrWhiteSpace(searchModel.MonthStr)) + { + if (!string.IsNullOrWhiteSpace(searchModel.YearStr)) + { + try + { + int year = Convert.ToInt32(searchModel.YearStr); + query = query.Where(x => x.Year == year); + } + catch (Exception) + { + + return new PagedResult(); + } + + } + + if (!string.IsNullOrWhiteSpace(searchModel.MonthStr)) + { + try + { + int month = Convert.ToInt32(searchModel.MonthStr); + query = query.Where(x => x.Month == month); + } + catch (Exception) + { + + return new PagedResult(); + } + + } + + + + } + var count = await query.CountAsync(); + query = query.OrderByDescending(x => x.CreationDate); + var queryPaginationFilter = await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); + + + var leaveResult = queryPaginationFilter.Select(item => new leaveListDto() + { + Id = item.id, + EmployeeFullName = item.EmployeeFullName, + YearStr = $"{item.Year}", + MonthStr = item.Month.ToFarsiMonthByIntNumber(), + IsInvalid = item.IsInvalid, + LeaveType = item.LeaveType, + StartLeave = item.StartLeave.ToFarsi(), + EndLeave = item.EndLeave.ToFarsi(), + HourlyInterval = item.PaidLeaveType == "ساعتی" ? $"{item.StartLeave.TimeOfDay:hh\\:mm} الی {item.EndLeave.TimeOfDay:hh\\:mm}" : "-", + LeaveDuration = Tools.CalculateLeaveHoursAndDays(item.PaidLeaveType, item.LeaveHourses), + IsAccepted = item.IsAccepted, + WorkshopId = item.WorkshopId, + EmployeeId = item.EmployeeId, + + }).ToList(); + return new PagedResult() + { + TotalCount = count, + List = leaveResult + }; + } #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/LeaveController.cs b/ServiceHost/Areas/Client/Controllers/LeaveController.cs new file mode 100644 index 00000000..92eac4d6 --- /dev/null +++ b/ServiceHost/Areas/Client/Controllers/LeaveController.cs @@ -0,0 +1,31 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.InsuranceList; +using CompanyManagment.App.Contracts.Leave; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Client.Controllers; + +public class LeaveController : ClientBaseController +{ + private readonly ILeaveApplication _leaveApplication; + private long _workshopId; + public LeaveController(ILeaveApplication leaveApplication, IAuthHelper authHelper) + { + _leaveApplication = leaveApplication; + _workshopId = authHelper.GetWorkshopId(); + } + + /// + /// دریافت لیست مرخصی ها + /// + /// + /// + [HttpGet("GetLeaveList")] + public async Task>> GetLeaveList(LeaveListSearchModel searchModel) + { + searchModel.WorkshopId = _workshopId; + var leaveList = await _leaveApplication.GetList(searchModel); + return Ok(leaveList); + } +}