From 59bbb7aae6c846af654b92877dd1cea88fab95fb Mon Sep 17 00:00:00 2001 From: SamSys Date: Tue, 23 Dec 2025 18:15:48 +0330 Subject: [PATCH 1/2] ini leave groupList --- Company.Domain/LeaveAgg/ILeaveRepository.cs | 7 ++ .../Leave/GroupLeaveListDto.cs | 88 ++++++++++++++++++ .../Repository/LeaveRepository.cs | 93 +++++++++++++++++++ .../Client/Controllers/LeaveController.cs | 1 + 4 files changed, 189 insertions(+) create mode 100644 CompanyManagment.App.Contracts/Leave/GroupLeaveListDto.cs diff --git a/Company.Domain/LeaveAgg/ILeaveRepository.cs b/Company.Domain/LeaveAgg/ILeaveRepository.cs index cc050bf1..58d6f50f 100644 --- a/Company.Domain/LeaveAgg/ILeaveRepository.cs +++ b/Company.Domain/LeaveAgg/ILeaveRepository.cs @@ -45,4 +45,11 @@ public interface ILeaveRepository : IRepository /// Task> GetList( LeaveListSearchModel searchModel); + + /// + /// دریافت لیست گروه بندی شده + /// + /// + /// + Task> GetGroupList(LeaveListSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Leave/GroupLeaveListDto.cs b/CompanyManagment.App.Contracts/Leave/GroupLeaveListDto.cs new file mode 100644 index 00000000..8f409fbe --- /dev/null +++ b/CompanyManagment.App.Contracts/Leave/GroupLeaveListDto.cs @@ -0,0 +1,88 @@ +using System.Collections.Generic; + +namespace CompanyManagment.App.Contracts.Leave; + +public class GroupLeaveListDto +{ + /// + /// سال مرخصی + /// + public string YearStr { get; set; } + + /// + /// ماه مرخصی + /// + public string MonthStr { get; set; } + /// + /// آیتم های هر گروه + /// + public List LeaveListItemsDto { get; set; } +} + +/// +/// آیتم های هر گروه +/// +public class LeaveListItemsDto +{ + /// + /// نوع مرخصی، استحقاقی/استعلاجی + /// + public string LeaveType { get; set; } + + + /// + /// تاریخ شروع مرخصی + /// + public string StartLeave { get; set; } + + /// + /// تاریخ پایان مرخصی + /// + public string EndLeave { get; set; } + + + /// + /// زمان مرخصی + /// بازه مرخصی ساعتی + /// + public string HourlyInterval { get; set; } + + + /// + /// مدت مرخصی + /// + public string LeaveDuration { get; set; } + + /// + /// موافقت/عدم موافقت کارفرما + /// + public bool IsAccepted { get; set; } + + + + + + /// + /// آی دی + /// + public long Id { get; set; } + + + + /// + /// آی دی گارگاه + /// + public long WorkshopId { get; set; } + + /// + /// آی دی پرسنل + /// + public long EmployeeId { get; set; } + + + + /// + ///آیا فاقد اعتبار است. فاقد اعتبار ها فقط برای فیش های غیررسمی مورد استفاده قرار میگیرند + /// + public bool IsInvalid { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/LeaveRepository.cs b/CompanyManagment.EFCore/Repository/LeaveRepository.cs index a2c14461..1557045b 100644 --- a/CompanyManagment.EFCore/Repository/LeaveRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeaveRepository.cs @@ -644,5 +644,98 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository }; } + + public async Task> GetGroupList(LeaveListSearchModel searchModel) + { + var query = _context.LeaveList.Where(x => x.WorkshopId == searchModel.WorkshopId && 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 List(); + } + + 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 List(); + } + + } + + if (!string.IsNullOrWhiteSpace(searchModel.MonthStr)) + { + try + { + int month = Convert.ToInt32(searchModel.MonthStr); + query = query.Where(x => x.Month == month); + } + catch (Exception) + { + + return new List(); + } + + } + + + } + + var leaveList = await query.GroupBy(x => new { x.Year, x.Month }) + .OrderByDescending(group => group.Key.Year) + .ThenByDescending(group => group.Key.Month) + .Select(group => new GroupLeaveListDto + { + YearStr = $"{group.Key.Year}", + MonthStr = group.Key.Month.ToFarsiMonthByIntNumber(), + LeaveListItemsDto = group.OrderByDescending(x=>x.StartLeave).Select(item => new LeaveListItemsDto + { + Id = item.id, + 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() + }).ToListAsync(); + + return leaveList; + } #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/LeaveController.cs b/ServiceHost/Areas/Client/Controllers/LeaveController.cs index 92eac4d6..bcda8ed9 100644 --- a/ServiceHost/Areas/Client/Controllers/LeaveController.cs +++ b/ServiceHost/Areas/Client/Controllers/LeaveController.cs @@ -25,6 +25,7 @@ public class LeaveController : ClientBaseController public async Task>> GetLeaveList(LeaveListSearchModel searchModel) { searchModel.WorkshopId = _workshopId; + var leaveList = await _leaveApplication.GetList(searchModel); return Ok(leaveList); } From 69476f3f2dbe27efb05c852829fd5286c10ee07d Mon Sep 17 00:00:00 2001 From: SamSys Date: Wed, 24 Dec 2025 12:53:06 +0330 Subject: [PATCH 2/2] add multiple get list for leaveController --- .../Leave/ILeaveApplication.cs | 22 +++++++- .../Leave/LeaveListMultipleDto.cs | 24 +++++++++ .../LeaveApplication.cs | 53 +++++++++++++++++++ .../Client/Controllers/LeaveController.cs | 28 ++++++++-- 4 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 CompanyManagment.App.Contracts/Leave/LeaveListMultipleDto.cs diff --git a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs index 4a08358d..4185d007 100644 --- a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs +++ b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs @@ -47,7 +47,27 @@ public interface ILeaveApplication /// Task> GetList( LeaveListSearchModel searchModel); - + + /// + /// دریافت لیست گروه بندی شده + /// + /// + /// + Task> GetGroupList(LeaveListSearchModel searchModel); + + /// + /// دریافت مجکوع مرخصی پرسنل + /// اگر آی دی پرسنل، سال و ماه خالی نباشد + /// + /// + /// + /// + /// + /// + /// + TimeSpan SumOfEmployeeLeaveTimeSpanInDates(long workshopId, long employeeId, string yearStr, string monthStr, + LeaveType leaveType); + Task> PrintAllAsync(List ids, long workshopId); Task PrintOneAsync(long id, long workshopId); diff --git a/CompanyManagment.App.Contracts/Leave/LeaveListMultipleDto.cs b/CompanyManagment.App.Contracts/Leave/LeaveListMultipleDto.cs new file mode 100644 index 00000000..00b8c5e9 --- /dev/null +++ b/CompanyManagment.App.Contracts/Leave/LeaveListMultipleDto.cs @@ -0,0 +1,24 @@ +using _0_Framework.Application; +using System.Collections.Generic; + +namespace CompanyManagment.App.Contracts.Leave; + +public class LeaveListMultipleDto +{ + /// + /// لیست گروهبندی شده بر اساس سال و ماه + /// اگر در جستجو پرسنل انتخاب شود + /// + public List? GroupLeaveListDto { get; set; } + + /// + /// لیست نرمال PageResult + /// + public PagedResult? leaveListDto { get; set; } + + /// + /// مجموع مرخصی پرسنل + /// اگر پرسنل انتخاب شده باشد + /// + public string? SumOfEmployeeleaves { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.Application/LeaveApplication.cs b/CompanyManagment.Application/LeaveApplication.cs index 6dd28650..63c50d32 100644 --- a/CompanyManagment.Application/LeaveApplication.cs +++ b/CompanyManagment.Application/LeaveApplication.cs @@ -609,6 +609,59 @@ public class LeaveApplication : ILeaveApplication return await _leaveRepository.GetList(searchModel); } + public async Task> GetGroupList(LeaveListSearchModel searchModel) + { + return await _leaveRepository.GetGroupList(searchModel); + } + + public TimeSpan SumOfEmployeeLeaveTimeSpanInDates(long workshopId, long employeeId, string yearStr, string monthStr, LeaveType leaveType) + { + + + var startFa = $"{yearStr}/{monthStr:00}/01"; + var endFa = startFa.FindeEndOfMonth(); + + if (startFa.TryToGeorgianDateTime(out var start) == false || endFa.TryToGeorgianDateTime(out var end) == false) + return TimeSpan.Zero; + + var leaveTotalTimeSpan = TimeSpan.Zero; + + var leaves = _leaveRepository.GetByWorkshopIdEmployeeIdInDates(workshopId, employeeId, start, end); + //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); + + if (leaveType == LeaveType.PaidLeave) + { + var timeSpanHourlyLeave = new TimeSpan(leaves.Where(x => x.PaidLeaveType == "ساعتی" && x.LeaveType == "استحقاقی") + .Sum(x => TimeOnly.Parse(x.LeaveHourses).Ticks)); + var dailyLeaveTime = leaves.Where(x => x.PaidLeaveType == "روزانه" && x.LeaveType == "استحقاقی") + .Sum(x => Convert.ToInt32(x.LeaveHourses)) * TimeSpan.FromDays(1); + + leaveTotalTimeSpan = timeSpanHourlyLeave + dailyLeaveTime; + } + else if (leaveType == LeaveType.SickLeave) + { + var timeSpanHourlyLeave = new TimeSpan(leaves.Where(x => x.PaidLeaveType == "ساعتی" && x.LeaveType == "استعلاجی") + .Sum(x => TimeOnly.Parse(x.LeaveHourses).Ticks)); + + var dailyLeaveTime = leaves.Where(x => x.PaidLeaveType == "روزانه" && x.LeaveType == "استعلاجی") + .Sum(x => Convert.ToInt32(x.LeaveHourses)) * TimeSpan.FromDays(1); + + leaveTotalTimeSpan = timeSpanHourlyLeave + dailyLeaveTime; + } + else + { + var timeSpanHourlyLeave = new TimeSpan(leaves.Where(x => x.PaidLeaveType == "ساعتی").Sum(x => TimeOnly.Parse(x.LeaveHourses).Ticks)); + var dailyLeaveTime = leaves.Where(x => x.PaidLeaveType == "روزانه").Sum(x => Convert.ToInt32(x.LeaveHourses)) * TimeSpan.FromDays(1); + leaveTotalTimeSpan = timeSpanHourlyLeave + dailyLeaveTime; + } + + + + + return leaveTotalTimeSpan; + } + public async Task> PrintAllAsync(List ids,long workshopId) { return await _leaveRepository.PrintAllAsync(ids,workshopId); diff --git a/ServiceHost/Areas/Client/Controllers/LeaveController.cs b/ServiceHost/Areas/Client/Controllers/LeaveController.cs index acb423af..8e94d7e1 100644 --- a/ServiceHost/Areas/Client/Controllers/LeaveController.cs +++ b/ServiceHost/Areas/Client/Controllers/LeaveController.cs @@ -1,8 +1,10 @@ using _0_Framework.Application; +using Company.Domain.EmployeeAgg; using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.Leave; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; +using System.Security.Cryptography; namespace ServiceHost.Areas.Client.Controllers; @@ -22,13 +24,31 @@ public class LeaveController : ClientBaseController /// /// [HttpGet("GetLeaveList")] - public async Task>> GetLeaveList(LeaveListSearchModel searchModel) + public async Task> GetLeaveList(LeaveListSearchModel searchModel) { + var result = new LeaveListMultipleDto(); searchModel.WorkshopId = _workshopId; - - var leaveList = await _leaveApplication.GetList(searchModel); - return Ok(leaveList); + if (searchModel.EmployeeId > 0) + { + //لیست گروه بندی شده + result.GroupLeaveListDto = await _leaveApplication.GetGroupList(searchModel); + + if (!string.IsNullOrWhiteSpace(searchModel.YearStr) && !string.IsNullOrWhiteSpace(searchModel.MonthStr)) + { + TimeSpan timeSpan = _leaveApplication.SumOfEmployeeLeaveTimeSpanInDates(_workshopId, searchModel.EmployeeId, searchModel.YearStr, searchModel.MonthStr, searchModel.LeaveType); + //مجموع مرخصی پرسنل + result.SumOfEmployeeleaves = timeSpan.ToFarsiDaysAndHoursAndMinutes(); + } + + return Ok(result); + } + //لیست نرمال PageResult + result.leaveListDto = await _leaveApplication.GetList(searchModel); + return Ok(result); } + + + [HttpGet("print/{id}")] public async Task> PrintOneAsync(long id) {