diff --git a/Company.Domain/LeaveAgg/ILeaveRepository.cs b/Company.Domain/LeaveAgg/ILeaveRepository.cs index 58d6f50f..93d5009b 100644 --- a/Company.Domain/LeaveAgg/ILeaveRepository.cs +++ b/Company.Domain/LeaveAgg/ILeaveRepository.cs @@ -29,6 +29,8 @@ public interface ILeaveRepository : IRepository List searchClient(LeaveSearchModel searchModel); LeavePrintViewModel PrintOne(long id); List PrintAll(List id); + + Task> PrintAllAsync(List ids, long workshopId); #region Vafa diff --git a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs index e7588892..4a08358d 100644 --- a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs +++ b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs @@ -47,4 +47,36 @@ public interface ILeaveApplication /// Task> GetList( LeaveListSearchModel searchModel); + + Task> PrintAllAsync(List ids, long workshopId); + Task PrintOneAsync(long id, long workshopId); + +} + +public class LeavePrintResponseViewModel +{ + public string FullName { get; set; } + public string NationalCode { get; set; } + public string WorkshopName { get; set; } + public List EmployerNames { get; set; } + public string PaidLeaveType { get; set; } + public string ContractNo { get; set; } + public LeavePrintHourlyResponseViewModel HourlyLeave { get; set; } + public LeavePrintDailyResponseViewModel DailyLeave { get; set; } + +} + +public class LeavePrintDailyResponseViewModel +{ + public string StartLeave { get; set; } + public string EndLeave { get; set; } + public string TotalDay { get; set; } +} + +public class LeavePrintHourlyResponseViewModel +{ + public string LeaveDate { get; set; } + public string StartHour { get; set; } + public string EndHour { get; set; } + public string TotalHour { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/LeaveApplication.cs b/CompanyManagment.Application/LeaveApplication.cs index 9b7acbcd..6dd28650 100644 --- a/CompanyManagment.Application/LeaveApplication.cs +++ b/CompanyManagment.Application/LeaveApplication.cs @@ -609,5 +609,15 @@ public class LeaveApplication : ILeaveApplication return await _leaveRepository.GetList(searchModel); } + public async Task> PrintAllAsync(List ids,long workshopId) + { + return await _leaveRepository.PrintAllAsync(ids,workshopId); + } + + public async Task PrintOneAsync(long id, long workshopId) + { + return (await _leaveRepository.PrintAllAsync([id],workshopId)).FirstOrDefault(); + } + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/LeaveRepository.cs b/CompanyManagment.EFCore/Repository/LeaveRepository.cs index 1557045b..b4a86ff3 100644 --- a/CompanyManagment.EFCore/Repository/LeaveRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeaveRepository.cs @@ -294,6 +294,65 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository return query; } + public async Task> PrintAllAsync(List ids, long workshopId) + { + var leaves =await _context + .LeaveList.Where(x => ids.Contains(x.id) && x.WorkshopId == workshopId).ToListAsync(); + + var minLeave = leaves.Min(x => x.StartLeave); + var maxLeave = leaves.Max(x => x.EndLeave); + + var employeeIds = leaves.Select(x => x.EmployeeId).Distinct().ToList(); + + var contracts = await _context.Contracts + .Where(x => x.WorkshopIds == workshopId && employeeIds.Contains(x.EmployeeId) + && x.ContarctStart<= maxLeave && x.ContractEnd>= minLeave) + .ToListAsync(); + + var employees = await _context + .Employees.Where(x=> employeeIds.Contains(x.id)).ToListAsync(); + + var employerNames = _context.WorkshopEmployers.Include(x=>x.Employer) + .Where(x=>x.WorkshopId == workshopId).Select(x=>x.Employer.FName+" "+x.Employer.LName).ToList(); + + var workshopName = _context.Workshops.FirstOrDefault(x => x.id == workshopId)?.WorkshopName; + + var res = leaves.Select(leave => + { + var employee = employees.FirstOrDefault(x => x.id == leave.EmployeeId); + return new LeavePrintResponseViewModel + { + FullName = employee?.FName + " " + + employee?.LName, + NationalCode = employee?.NationalCode, + WorkshopName = workshopName, + EmployerNames = employerNames, + PaidLeaveType = leave.PaidLeaveType, + ContractNo = contracts.FirstOrDefault(x => + x.EmployeeId == leave.EmployeeId && + x.ContarctStart <= leave.StartLeave && + x.ContractEnd >= leave.EndLeave)?.ContractNo, + DailyLeave = leave.PaidLeaveType == "روزانه" ? new LeavePrintDailyResponseViewModel + { + StartLeave = leave.StartLeave.ToFarsi(), + EndLeave = leave.EndLeave.ToFarsi(), + TotalDay = leave.LeaveHourses + } : null, + + HourlyLeave = leave.PaidLeaveType == "ساعتی" ? + new LeavePrintHourlyResponseViewModel + { + LeaveDate = leave.StartLeave.ToFarsi(), + StartHour = leave.StartLeave.ToString("HH:mm"), + EndHour = leave.EndLeave.ToString("HH:mm"), + TotalHour = TimeSpan.Parse(leave.LeaveHourses) + .TotalHours.ToString("F0") + } : null + }; + }).ToList(); + return res; + } + #region Vafa public List LastLeaveMain(LeaveSearchModel searchModel) diff --git a/ServiceHost/Areas/Client/Controllers/LeaveController.cs b/ServiceHost/Areas/Client/Controllers/LeaveController.cs index bcda8ed9..acb423af 100644 --- a/ServiceHost/Areas/Client/Controllers/LeaveController.cs +++ b/ServiceHost/Areas/Client/Controllers/LeaveController.cs @@ -29,4 +29,17 @@ public class LeaveController : ClientBaseController var leaveList = await _leaveApplication.GetList(searchModel); return Ok(leaveList); } + [HttpGet("print/{id}")] + public async Task> PrintOneAsync(long id) + { + var leavePrint = await _leaveApplication.PrintOneAsync(id, _workshopId); + return leavePrint; + } + [HttpGet("print")] + public async Task>> PrintAllAsync([FromQuery] List ids) + { + var leavePrints = await _leaveApplication.PrintAllAsync(ids, _workshopId); + return Ok(leavePrints); + } + }