Merge branch 'Feature/ClientLeavePageApi' into Main

This commit is contained in:
SamSys
2025-12-24 12:54:18 +03:30
7 changed files with 310 additions and 4 deletions

View File

@@ -47,4 +47,11 @@ public interface ILeaveRepository : IRepository<long, Leave>
/// <returns></returns>
Task<PagedResult<leaveListDto>> GetList(
LeaveListSearchModel searchModel);
/// <summary>
/// دریافت لیست گروه بندی شده
/// </summary>
/// <param name="searchModel"></param>
/// <returns></returns>
Task<List<GroupLeaveListDto>> GetGroupList(LeaveListSearchModel searchModel);
}

View File

@@ -0,0 +1,88 @@
using System.Collections.Generic;
namespace CompanyManagment.App.Contracts.Leave;
public class GroupLeaveListDto
{
/// <summary>
/// سال مرخصی
/// </summary>
public string YearStr { get; set; }
/// <summary>
/// ماه مرخصی
/// </summary>
public string MonthStr { get; set; }
/// <summary>
/// آیتم های هر گروه
/// </summary>
public List<LeaveListItemsDto> LeaveListItemsDto { get; set; }
}
/// <summary>
/// آیتم های هر گروه
/// </summary>
public class LeaveListItemsDto
{
/// <summary>
/// نوع مرخصی، استحقاقی/استعلاجی
/// </summary>
public string LeaveType { get; set; }
/// <summary>
/// تاریخ شروع مرخصی
/// </summary>
public string StartLeave { get; set; }
/// <summary>
/// تاریخ پایان مرخصی
/// </summary>
public string EndLeave { get; set; }
/// <summary>
/// زمان مرخصی
/// بازه مرخصی ساعتی
/// </summary>
public string HourlyInterval { get; set; }
/// <summary>
/// مدت مرخصی
/// </summary>
public string LeaveDuration { get; set; }
/// <summary>
/// موافقت/عدم موافقت کارفرما
/// </summary>
public bool IsAccepted { get; set; }
/// <summary>
/// آی دی
/// </summary>
public long Id { get; set; }
/// <summary>
/// آی دی گارگاه
/// </summary>
public long WorkshopId { get; set; }
/// <summary>
/// آی دی پرسنل
/// </summary>
public long EmployeeId { get; set; }
/// <summary>
///آیا فاقد اعتبار است. فاقد اعتبار ها فقط برای فیش های غیررسمی مورد استفاده قرار میگیرند
/// </summary>
public bool IsInvalid { get; set; }
}

View File

@@ -47,7 +47,27 @@ public interface ILeaveApplication
/// <returns></returns>
Task<PagedResult<leaveListDto>> GetList(
LeaveListSearchModel searchModel);
/// <summary>
/// دریافت لیست گروه بندی شده
/// </summary>
/// <param name="searchModel"></param>
/// <returns></returns>
Task<List<GroupLeaveListDto>> GetGroupList(LeaveListSearchModel searchModel);
/// <summary>
/// دریافت مجکوع مرخصی پرسنل
/// اگر آی دی پرسنل، سال و ماه خالی نباشد
/// </summary>
/// <param name="workshopId"></param>
/// <param name="employeeId"></param>
/// <param name="yearStr"></param>
/// <param name="monthStr"></param>
/// <param name="leaveType"></param>
/// <returns></returns>
TimeSpan SumOfEmployeeLeaveTimeSpanInDates(long workshopId, long employeeId, string yearStr, string monthStr,
LeaveType leaveType);
Task<List<LeavePrintResponseViewModel>> PrintAllAsync(List<long> ids, long workshopId);
Task<LeavePrintResponseViewModel> PrintOneAsync(long id, long workshopId);

View File

@@ -0,0 +1,24 @@
using _0_Framework.Application;
using System.Collections.Generic;
namespace CompanyManagment.App.Contracts.Leave;
public class LeaveListMultipleDto
{
/// <summary>
/// لیست گروهبندی شده بر اساس سال و ماه
/// اگر در جستجو پرسنل انتخاب شود
/// </summary>
public List<GroupLeaveListDto>? GroupLeaveListDto { get; set; }
/// <summary>
/// لیست نرمال PageResult
/// </summary>
public PagedResult<leaveListDto>? leaveListDto { get; set; }
/// <summary>
/// مجموع مرخصی پرسنل
/// اگر پرسنل انتخاب شده باشد
/// </summary>
public string? SumOfEmployeeleaves { get; set; }
}

View File

@@ -609,6 +609,59 @@ public class LeaveApplication : ILeaveApplication
return await _leaveRepository.GetList(searchModel);
}
public async Task<List<GroupLeaveListDto>> 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<List<LeavePrintResponseViewModel>> PrintAllAsync(List<long> ids,long workshopId)
{
return await _leaveRepository.PrintAllAsync(ids,workshopId);

View File

@@ -703,5 +703,98 @@ public class LeaveRepository : RepositoryBase<long, Leave>, ILeaveRepository
};
}
public async Task<List<GroupLeaveListDto>> 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<GroupLeaveListDto>();
}
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<GroupLeaveListDto>();
}
}
if (!string.IsNullOrWhiteSpace(searchModel.MonthStr))
{
try
{
int month = Convert.ToInt32(searchModel.MonthStr);
query = query.Where(x => x.Month == month);
}
catch (Exception)
{
return new List<GroupLeaveListDto>();
}
}
}
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
}

View File

@@ -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,12 +24,31 @@ public class LeaveController : ClientBaseController
/// <param name="searchModel"></param>
/// <returns></returns>
[HttpGet("GetLeaveList")]
public async Task<ActionResult<PagedResult<leaveListDto>>> GetLeaveList(LeaveListSearchModel searchModel)
public async Task<ActionResult<LeaveListMultipleDto>> 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<ActionResult<LeavePrintResponseViewModel>> PrintOneAsync(long id)
{