diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index f055dc1c..eb09e73a 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -813,7 +813,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos if (early != TimeSpan.Zero) { - return early*1; + return early * 1; } return TimeSpan.Zero; @@ -2292,6 +2292,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos .Include(x => x.RollCallEmployee) .Where(x => x.RollCallEmployee.WorkshopId == workshopId); + DateTime startDate; + DateTime endDate; //این برای این هست که اگر بر اساس پرسنل جستجو شده بود و در titleId اگر به فرمت YYYY_MM اومد به این معنی هست که باید بر طبق ماه فیلتر بشه نه به صورت روزانه if (searchModel.EmployeeId is > 0) { @@ -2305,75 +2307,84 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var startDateFa = $"{year:D4}/{month:D2}/01"; var endDateFa = startDateFa.FindeEndOfMonth(); - var startDate = startDateFa.ToGeorgianDateTime(); - var endDate = endDateFa.ToGeorgianDateTime(); - - query = query.Where(x => x.StartDate <= endDate && x.EndDate >= startDate - && 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(); - 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; - - + startDate = startDateFa.ToGeorgianDateTime(); + endDate = endDateFa.ToGeorgianDateTime(); + query = query + .Where(x => x.RollCallEmployee.EmployeeId == searchModel.EmployeeId); } + 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(); + 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(); } } \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs b/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs index b5d18351..df1f1b9d 100644 --- a/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs +++ b/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs @@ -23,7 +23,7 @@ public class CaseHistoryController:ClientBaseController return await _rollCallApplication.GetCaseHistoryTitles(_workshopId, searchModel); } - [HttpGet("{titleId}")] + [HttpGet("details")] public async Task>> GetDetails(string titleId, RollCallCaseHistorySearchModel searchModel) { return await _rollCallApplication.GetCaseHistoryDetails(_workshopId, titleId, searchModel);