ini leave groupList

This commit is contained in:
SamSys
2025-12-23 18:15:48 +03:30
parent 89de3162de
commit 59bbb7aae6
4 changed files with 189 additions and 0 deletions

View File

@@ -45,4 +45,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

@@ -644,5 +644,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

@@ -25,6 +25,7 @@ public class LeaveController : ClientBaseController
public async Task<ActionResult<PagedResult<leaveListDto>>> GetLeaveList(LeaveListSearchModel searchModel)
{
searchModel.WorkshopId = _workshopId;
var leaveList = await _leaveApplication.GetList(searchModel);
return Ok(leaveList);
}