Merge branch 'Feature/ClientLeavePageApi' of https://github.com/samsyntax24/OriginalGozareshgir into Feature/ClientLeavePageApi

This commit is contained in:
SamSys
2025-12-24 11:53:15 +03:30
5 changed files with 116 additions and 0 deletions

View File

@@ -29,6 +29,8 @@ public interface ILeaveRepository : IRepository<long, Leave>
List<LeaveMainViewModel> searchClient(LeaveSearchModel searchModel);
LeavePrintViewModel PrintOne(long id);
List<LeavePrintViewModel> PrintAll(List<long> id);
Task<List<LeavePrintResponseViewModel>> PrintAllAsync(List<long> ids, long workshopId);
#region Vafa

View File

@@ -47,4 +47,36 @@ public interface ILeaveApplication
/// <returns></returns>
Task<PagedResult<leaveListDto>> GetList(
LeaveListSearchModel searchModel);
Task<List<LeavePrintResponseViewModel>> PrintAllAsync(List<long> ids, long workshopId);
Task<LeavePrintResponseViewModel> 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<string> 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; }
}

View File

@@ -609,5 +609,15 @@ public class LeaveApplication : ILeaveApplication
return await _leaveRepository.GetList(searchModel);
}
public async Task<List<LeavePrintResponseViewModel>> PrintAllAsync(List<long> ids,long workshopId)
{
return await _leaveRepository.PrintAllAsync(ids,workshopId);
}
public async Task<LeavePrintResponseViewModel> PrintOneAsync(long id, long workshopId)
{
return (await _leaveRepository.PrintAllAsync([id],workshopId)).FirstOrDefault();
}
#endregion
}

View File

@@ -294,6 +294,65 @@ public class LeaveRepository : RepositoryBase<long, Leave>, ILeaveRepository
return query;
}
public async Task<List<LeavePrintResponseViewModel>> PrintAllAsync(List<long> 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<LeaveViewModel> LastLeaveMain(LeaveSearchModel searchModel)

View File

@@ -29,4 +29,17 @@ public class LeaveController : ClientBaseController
var leaveList = await _leaveApplication.GetList(searchModel);
return Ok(leaveList);
}
[HttpGet("print/{id}")]
public async Task<ActionResult<LeavePrintResponseViewModel>> PrintOneAsync(long id)
{
var leavePrint = await _leaveApplication.PrintOneAsync(id, _workshopId);
return leavePrint;
}
[HttpGet("print")]
public async Task<ActionResult<List<LeavePrintResponseViewModel>>> PrintAllAsync([FromQuery] List<long> ids)
{
var leavePrints = await _leaveApplication.PrintAllAsync(ids, _workshopId);
return Ok(leavePrints);
}
}