diff --git a/Company.Domain/LeaveAgg/ILeaveRepository.cs b/Company.Domain/LeaveAgg/ILeaveRepository.cs index 93d5009b..293114ea 100644 --- a/Company.Domain/LeaveAgg/ILeaveRepository.cs +++ b/Company.Domain/LeaveAgg/ILeaveRepository.cs @@ -54,4 +54,11 @@ public interface ILeaveRepository : IRepository /// /// Task> GetGroupList(LeaveListSearchModel searchModel); + + /// + /// پرینت لیستی + /// + /// + /// + Task ListPrint(List ids); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs index 3234526e..95548f1f 100644 --- a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs +++ b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs @@ -97,6 +97,13 @@ public interface ILeaveApplication /// Task> HasRotatingShift(long workshopId, long employeeId, string startLeaveDate); + /// + /// پرینت لیستی + /// + /// + /// + Task ListPrint(List ids); + } public class LeavePrintResponseViewModel diff --git a/CompanyManagment.App.Contracts/Leave/LeavePrintListDto.cs b/CompanyManagment.App.Contracts/Leave/LeaveListPrintDto.cs similarity index 94% rename from CompanyManagment.App.Contracts/Leave/LeavePrintListDto.cs rename to CompanyManagment.App.Contracts/Leave/LeaveListPrintDto.cs index 7a614219..caae96a3 100644 --- a/CompanyManagment.App.Contracts/Leave/LeavePrintListDto.cs +++ b/CompanyManagment.App.Contracts/Leave/LeaveListPrintDto.cs @@ -2,7 +2,11 @@ namespace CompanyManagment.App.Contracts.Leave; -public class LeavePrintListDto +/// +/// پرینت لیستی +/// api +/// +public class LeaveListPrintDto { /// @@ -10,15 +14,17 @@ public class LeavePrintListDto /// public string EmployeeFullName { get; set; } + /// + /// مجموع مرخصی پرسنل + /// + public string? SumOfEmployeeleaves { get; set; } + /// /// لیست مرخصی /// public List LeavePrintListItemsDto { get; set; } - /// - /// مجموع مرخصی پرسنل - /// - public string? SumOfEmployeeleaves { get; set; } + } public class LeavePrintListItemsDto diff --git a/CompanyManagment.Application/LeaveApplication.cs b/CompanyManagment.Application/LeaveApplication.cs index 1b3a998a..2bcffefe 100644 --- a/CompanyManagment.Application/LeaveApplication.cs +++ b/CompanyManagment.Application/LeaveApplication.cs @@ -960,4 +960,10 @@ public class LeaveApplication : ILeaveApplication return op.Succcedded(result); } #endregion + + + public async Task ListPrint(List ids) + { + return await _leaveRepository.ListPrint(ids); + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/LeaveRepository.cs b/CompanyManagment.EFCore/Repository/LeaveRepository.cs index b4a86ff3..de080e64 100644 --- a/CompanyManagment.EFCore/Repository/LeaveRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeaveRepository.cs @@ -1,9 +1,7 @@ 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; @@ -11,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; + namespace CompanyManagment.EFCore.Repository; public class LeaveRepository : RepositoryBase, ILeaveRepository @@ -678,6 +677,7 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository query = query.OrderByDescending(x => x.CreationDate); var queryPaginationFilter = await query.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); + var leaveResult = queryPaginationFilter.Select(item => new leaveListDto() { @@ -796,5 +796,54 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository return leaveList; } + + + public async Task ListPrint(List ids) + { + var result = new LeaveListPrintDto(); + var timeSpanHourlyLeave = new TimeSpan(); + var dailyLeaveTime = new TimeSpan(); + if (ids.Any()) + { + var query = _context.LeaveList.Where(x => ids.Contains(x.id)).OrderByDescending(x=>x.StartLeave).AsQueryable(); + + #region sumOfLeaves + + var hourly = await query.Where(x => x.PaidLeaveType == "ساعتی").Select(x => x.LeaveHourses).ToListAsync(); + var daily = await query.Where(x => x.PaidLeaveType == "روزانه").Select(x => x.LeaveHourses).ToListAsync(); + + + if (hourly.Any()) + timeSpanHourlyLeave = new TimeSpan(hourly.Sum(x => TimeOnly.Parse(x).Ticks)); + if (daily.Any()) + dailyLeaveTime = daily.Sum(x => Convert.ToInt32(x)) * TimeSpan.FromDays(1); + + var sumOfLeaves = timeSpanHourlyLeave.Add(dailyLeaveTime); + + result.SumOfEmployeeleaves = sumOfLeaves.ToFarsiDaysAndHoursAndMinutes(); + + #endregion + + + result.LeavePrintListItemsDto = await query.Select(item => new LeavePrintListItemsDto + { + YearStr = $"{item.Year}", + MonthStr = item.Month.ToFarsiMonthByIntNumber(), + StartLeave = item.StartLeave.ToFarsi(), + EndLeave = item.EndLeave.ToFarsi(), + LeaveType = item.LeaveType, + HourlyInterval = item.PaidLeaveType == "ساعتی" ? $"{item.StartLeave.TimeOfDay:hh\\:mm} الی {item.EndLeave.TimeOfDay:hh\\:mm}" : "-", + LeaveDuration = Tools.CalculateLeaveHoursAndDays(item.PaidLeaveType, item.LeaveHourses), + IsAccepted = item.IsAccepted, + }).ToListAsync(); + + + result.EmployeeFullName = query.FirstOrDefault()!.EmployeeFullName; + } + + + return result; + } + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/LeaveController.cs b/ServiceHost/Areas/Client/Controllers/LeaveController.cs index 21d39aaa..68962504 100644 --- a/ServiceHost/Areas/Client/Controllers/LeaveController.cs +++ b/ServiceHost/Areas/Client/Controllers/LeaveController.cs @@ -111,14 +111,14 @@ public class LeaveController : ClientBaseController } /// - /// پرینت گروهی + /// پرینت لیستی /// /// /// [HttpGet("ListPrint")] - public async Task> ListPrint([FromQuery] List ids,) + public async Task> ListPrint([FromQuery] List ids) { - var leavePrints = await _leaveApplication.PrintAllAsync(ids, _workshopId); + var leavePrints = await _leaveApplication.ListPrint(ids); return Ok(leavePrints); }