complete rollcall history details
This commit is contained in:
@@ -813,7 +813,7 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
|
|||||||
|
|
||||||
if (early != TimeSpan.Zero)
|
if (early != TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
return early*1;
|
return early * 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TimeSpan.Zero;
|
return TimeSpan.Zero;
|
||||||
@@ -2292,6 +2292,8 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
|
|||||||
.Include(x => x.RollCallEmployee)
|
.Include(x => x.RollCallEmployee)
|
||||||
.Where(x => x.RollCallEmployee.WorkshopId == workshopId);
|
.Where(x => x.RollCallEmployee.WorkshopId == workshopId);
|
||||||
|
|
||||||
|
DateTime startDate;
|
||||||
|
DateTime endDate;
|
||||||
//این برای این هست که اگر بر اساس پرسنل جستجو شده بود و در titleId اگر به فرمت YYYY_MM اومد به این معنی هست که باید بر طبق ماه فیلتر بشه نه به صورت روزانه
|
//این برای این هست که اگر بر اساس پرسنل جستجو شده بود و در titleId اگر به فرمت YYYY_MM اومد به این معنی هست که باید بر طبق ماه فیلتر بشه نه به صورت روزانه
|
||||||
if (searchModel.EmployeeId is > 0)
|
if (searchModel.EmployeeId is > 0)
|
||||||
{
|
{
|
||||||
@@ -2305,75 +2307,84 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
|
|||||||
var startDateFa = $"{year:D4}/{month:D2}/01";
|
var startDateFa = $"{year:D4}/{month:D2}/01";
|
||||||
var endDateFa = startDateFa.FindeEndOfMonth();
|
var endDateFa = startDateFa.FindeEndOfMonth();
|
||||||
|
|
||||||
var startDate = startDateFa.ToGeorgianDateTime();
|
startDate = startDateFa.ToGeorgianDateTime();
|
||||||
var endDate = endDateFa.ToGeorgianDateTime();
|
endDate = endDateFa.ToGeorgianDateTime();
|
||||||
|
query = query
|
||||||
query = query.Where(x => x.StartDate <= endDate && x.EndDate >= startDate
|
.Where(x => x.RollCallEmployee.EmployeeId == searchModel.EmployeeId);
|
||||||
&& x.RollCallEmployee.EmployeeId == searchModel.EmployeeId);
|
|
||||||
|
|
||||||
var employeeIds =await query.Select(x => x.RollCallEmployee.EmployeeId).ToListAsync();
|
|
||||||
|
|
||||||
var rollCalls =await _context.RollCalls
|
|
||||||
.Where(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId)
|
|
||||||
&& startDate <= x.ShiftDate && endDate >= x.ShiftDate).ToListAsync();
|
|
||||||
|
|
||||||
var leaves =await _context.LeaveList.Where(x => x.WorkshopId == workshopId
|
|
||||||
&& employeeIds.Contains(x.EmployeeId) &&
|
|
||||||
x.StartLeave >= endDate && x.EndLeave <= startDate).ToListAsync();
|
|
||||||
var dateRange = (int)(endDate - startDate).TotalDays + 1;
|
|
||||||
|
|
||||||
var dates = Enumerable.Range(0, dateRange).Select(x => startDate.AddDays(x)).ToList();
|
|
||||||
|
|
||||||
var employees = await _context.Employees.Where(x => employeeIds
|
|
||||||
.Contains(x.id)).ToListAsync();
|
|
||||||
|
|
||||||
var personnelCodes =await _context.PersonnelCodeSet
|
|
||||||
.Where(x => x.WorkshopId == workshopId
|
|
||||||
&& employeeIds.Contains(x.EmployeeId)).ToListAsync();
|
|
||||||
|
|
||||||
var res = new PagedResult<RollCallCaseHistoryDetail>();
|
|
||||||
foreach (var date in dates)
|
|
||||||
{
|
|
||||||
var rollCallInDate = rollCalls
|
|
||||||
.Where(x => x.ShiftDate.Date == date.Date).ToList();
|
|
||||||
foreach (var employeeId in employeeIds)
|
|
||||||
{
|
|
||||||
var leave = leaves.FirstOrDefault(y => y.EmployeeId == employeeId);
|
|
||||||
var employeeRollCallsForDate = rollCallInDate
|
|
||||||
.Where(y => y.EmployeeId == employeeId).ToList();
|
|
||||||
var employee = employees.FirstOrDefault(x => x.id == employeeId);
|
|
||||||
|
|
||||||
var item = new RollCallCaseHistoryDetail()
|
|
||||||
{
|
|
||||||
EmployeeFullName = employee?.FullName ?? "",
|
|
||||||
EmployeeId = employee?.id ?? 0,
|
|
||||||
Records = employeeRollCallsForDate.OrderBy(r => r.StartDate).Select(y =>
|
|
||||||
new RollCallCaseHistoryDetailRecord()
|
|
||||||
{
|
|
||||||
EndTime = y.EndDate!.Value.ToString("HH:mm"),
|
|
||||||
StartTime = y.StartDate!.Value.ToString("HH:mm"),
|
|
||||||
EntryTimeDifference =
|
|
||||||
CalculateEntryTimeDifferencesTimeSpan(y.EarlyEntryDuration, y.LateEntryDuration),
|
|
||||||
ExitTimeDifference =
|
|
||||||
CalculateExitTimeDifferencesTimeSpan(y.EarlyExitDuration, y.LateExitDuration)
|
|
||||||
}).ToList(),
|
|
||||||
Status = employeeRollCallsForDate.Any() ? RollCallRecordStatus.Worked
|
|
||||||
: leave != null ? RollCallRecordStatus.Leaved
|
|
||||||
: RollCallRecordStatus.Absent,
|
|
||||||
TotalWorkingTime =
|
|
||||||
new TimeSpan(
|
|
||||||
employeeRollCallsForDate.Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)),
|
|
||||||
PersonnelCode = personnelCodes.FirstOrDefault(y => y.EmployeeId == employeeId)?.PersonnelCode
|
|
||||||
.ToString(),
|
|
||||||
};
|
|
||||||
res.List.Add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//TODO: set correct regex.
|
||||||
|
// if (!Regex.IsMatch(titleId, ""))
|
||||||
|
// throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است");
|
||||||
|
|
||||||
|
startDate = titleId.ToGeorgianDateTime();
|
||||||
|
endDate = startDate;
|
||||||
|
}
|
||||||
|
query = query.Where(x => x.StartDate <= endDate && x.EndDate >= startDate);
|
||||||
|
|
||||||
|
var employeeIds = await query.Select(x => x.RollCallEmployee.EmployeeId).ToListAsync();
|
||||||
|
|
||||||
|
var rollCalls = await _context.RollCalls
|
||||||
|
.Where(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId)
|
||||||
|
&& startDate <= x.ShiftDate && endDate >= x.ShiftDate).ToListAsync();
|
||||||
|
|
||||||
|
var leaves = await _context.LeaveList.Where(x => x.WorkshopId == workshopId
|
||||||
|
&& employeeIds.Contains(x.EmployeeId) &&
|
||||||
|
x.StartLeave >= endDate && x.EndLeave <= startDate)
|
||||||
|
.ToListAsync();
|
||||||
|
var dateRange = (int)(endDate - startDate).TotalDays + 1;
|
||||||
|
|
||||||
|
var dates = Enumerable.Range(0, dateRange).Select(x => startDate.AddDays(x)).ToList();
|
||||||
|
|
||||||
|
var employees = await _context.Employees.Where(x => employeeIds
|
||||||
|
.Contains(x.id)).ToListAsync();
|
||||||
|
|
||||||
|
var personnelCodes = await _context.PersonnelCodeSet
|
||||||
|
.Where(x => x.WorkshopId == workshopId
|
||||||
|
&& employeeIds.Contains(x.EmployeeId)).ToListAsync();
|
||||||
|
|
||||||
|
var res = new PagedResult<RollCallCaseHistoryDetail>();
|
||||||
|
foreach (var date in dates)
|
||||||
|
{
|
||||||
|
var rollCallInDate = rollCalls
|
||||||
|
.Where(x => x.ShiftDate.Date == date.Date).ToList();
|
||||||
|
foreach (var employeeId in employeeIds)
|
||||||
|
{
|
||||||
|
var leave = leaves.FirstOrDefault(y => y.EmployeeId == employeeId);
|
||||||
|
var employeeRollCallsForDate = rollCallInDate
|
||||||
|
.Where(y => y.EmployeeId == employeeId).ToList();
|
||||||
|
var employee = employees.FirstOrDefault(x => x.id == employeeId);
|
||||||
|
|
||||||
|
var item = new RollCallCaseHistoryDetail()
|
||||||
|
{
|
||||||
|
EmployeeFullName = employee?.FullName ?? "",
|
||||||
|
EmployeeId = employee?.id ?? 0,
|
||||||
|
Records = employeeRollCallsForDate.OrderBy(r => r.StartDate).Select(y =>
|
||||||
|
new RollCallCaseHistoryDetailRecord()
|
||||||
|
{
|
||||||
|
EndTime = y.EndDate!.Value.ToString("HH:mm"),
|
||||||
|
StartTime = y.StartDate!.Value.ToString("HH:mm"),
|
||||||
|
EntryTimeDifference =
|
||||||
|
CalculateEntryTimeDifferencesTimeSpan(y.EarlyEntryDuration, y.LateEntryDuration),
|
||||||
|
ExitTimeDifference =
|
||||||
|
CalculateExitTimeDifferencesTimeSpan(y.EarlyExitDuration, y.LateExitDuration)
|
||||||
|
}).ToList(),
|
||||||
|
Status = employeeRollCallsForDate.Any() ? RollCallRecordStatus.Worked
|
||||||
|
: leave != null ? RollCallRecordStatus.Leaved
|
||||||
|
: RollCallRecordStatus.Absent,
|
||||||
|
TotalWorkingTime =
|
||||||
|
new TimeSpan(
|
||||||
|
employeeRollCallsForDate.Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)),
|
||||||
|
PersonnelCode = personnelCodes.FirstOrDefault(y => y.EmployeeId == employeeId)?.PersonnelCode
|
||||||
|
.ToString(),
|
||||||
|
};
|
||||||
|
res.List.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
return new PagedResult<RollCallCaseHistoryDetail>();
|
return new PagedResult<RollCallCaseHistoryDetail>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ public class CaseHistoryController:ClientBaseController
|
|||||||
return await _rollCallApplication.GetCaseHistoryTitles(_workshopId, searchModel);
|
return await _rollCallApplication.GetCaseHistoryTitles(_workshopId, searchModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{titleId}")]
|
[HttpGet("details")]
|
||||||
public async Task<ActionResult<PagedResult<RollCallCaseHistoryDetail>>> GetDetails(string titleId, RollCallCaseHistorySearchModel searchModel)
|
public async Task<ActionResult<PagedResult<RollCallCaseHistoryDetail>>> GetDetails(string titleId, RollCallCaseHistorySearchModel searchModel)
|
||||||
{
|
{
|
||||||
return await _rollCallApplication.GetCaseHistoryDetails(_workshopId, titleId, searchModel);
|
return await _rollCallApplication.GetCaseHistoryDetails(_workshopId, titleId, searchModel);
|
||||||
|
|||||||
Reference in New Issue
Block a user