fix admin rollcall report bug
This commit is contained in:
@@ -37,7 +37,7 @@ namespace Query.AdminReports.Handlers
|
||||
var allWorkshops = _companyContext.Workshops.AsSplitQuery().Select(x => new { x.id, x.WorkshopFullName });
|
||||
|
||||
if (parameters.WorkshopId != 0)
|
||||
allWorkshops = allWorkshops.Where(x => x.id == parameters.WorkshopId);
|
||||
allWorkshops = allWorkshops.Where(x => x.id == parameters.WorkshopId);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(parameters.WorkshopName))
|
||||
allWorkshops = allWorkshops.Where(x => x.WorkshopFullName.Contains(parameters.WorkshopName));
|
||||
@@ -45,10 +45,10 @@ namespace Query.AdminReports.Handlers
|
||||
if (!string.IsNullOrWhiteSpace(parameters.RollCallServiceType))
|
||||
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.ServiceType == parameters.RollCallServiceType);
|
||||
|
||||
if (parameters.FilterMode == FilterMode.Active)
|
||||
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.StartService.Date <= now && x.EndService.Date >= now);
|
||||
else if(parameters.FilterMode == FilterMode.DeActive)
|
||||
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.EndService.Date < now || x.StartService.Date > now);
|
||||
if (parameters.FilterMode == FilterMode.Active)
|
||||
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.StartService.Date <= now && x.EndService.Date >= now);
|
||||
else if (parameters.FilterMode == FilterMode.DeActive)
|
||||
rollCallServiceQuery = rollCallServiceQuery.Where(x => x.EndService.Date < now || x.StartService.Date > now);
|
||||
|
||||
var workshopsWithService = rollCallServiceQuery.Join(allWorkshops, x => x.WorkshopId, y => y.id, (rcs, workshop) =>
|
||||
new WorkshopWithRollCallServiceQueryModel()
|
||||
@@ -60,7 +60,7 @@ namespace Query.AdminReports.Handlers
|
||||
IsActive = rcs.StartService <= DateTime.Now && rcs.EndService >= DateTime.Now,
|
||||
ServiceStart = rcs.StartService,
|
||||
ServiceEnd = rcs.EndService
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//workshop population
|
||||
@@ -73,12 +73,15 @@ namespace Query.AdminReports.Handlers
|
||||
}).ToList();
|
||||
|
||||
var workshopsWorkingEmployeesList = workshopLeftWorks
|
||||
.Select(x => new { x.WorkshopId, TotalWorkingEmployeesCount = x.LeftWorks.Concat(x.LeftWorkInsurances).Distinct().Count() }).ToList();
|
||||
.Select(x => new { x.WorkshopId, TotalWorkingEmployeesCount = x.LeftWorks.Concat(x.LeftWorkInsurances).Distinct().Count(), EmployeeIds = x.LeftWorks.Concat(x.LeftWorkInsurances).Distinct() }).ToList();
|
||||
|
||||
|
||||
|
||||
var activeEmployees = _companyContext.RollCallEmployees.AsSplitQuery().Include(x => x.EmployeesStatus).Where(x => x.EmployeesStatus.Any(y =>
|
||||
y.EndDate.Date >= now) && workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId)).Select(x => new { x.WorkshopId, x.EmployeeId });
|
||||
var activeEmployees = _companyContext.RollCallEmployees.AsSplitQuery()
|
||||
.Include(x => x.EmployeesStatus)
|
||||
.Where(x => x.EmployeesStatus.Any(y => y.EndDate.Date >= now) &&
|
||||
workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId))
|
||||
.Select(x => new { x.WorkshopId, x.EmployeeId });
|
||||
|
||||
var lastWeekRollCalls = _companyContext.RollCalls.AsSplitQuery().Where(x => x.StartDate.HasValue && x.StartDate.Value >= lastWeek
|
||||
&& workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId)).GroupBy(x => x.EmployeeId).Select(x => x.Key);
|
||||
@@ -88,27 +91,27 @@ namespace Query.AdminReports.Handlers
|
||||
&& workshopsWithService.Any(y => y.WorkshopId == x.WorkshopId)).Select(x => x.EmployeeId);
|
||||
|
||||
|
||||
var activeEmployeesList = activeEmployees.ToList();
|
||||
var activeEmployeesList = activeEmployees.ToList().Where(x => workshopsWorkingEmployeesList.Any(w => w.WorkshopId == x.WorkshopId && w.EmployeeIds.Contains(x.EmployeeId)));
|
||||
var lastWeekRollCallsList = lastWeekRollCalls.ToList();
|
||||
var leavesList = leaves.ToList();
|
||||
var workshopsWithServiceList = workshopsWithService.ToList();
|
||||
return workshopsWithServiceList.GroupBy(x=>x.WorkshopId)
|
||||
.Select(x=>x.OrderByDescending(y=>y.ServiceStartFa).First())
|
||||
.Select(x => new WorkshopWithRollCallServiceQueryModel()
|
||||
{
|
||||
IsActive = x.IsActive,
|
||||
ServiceStartFa = x.ServiceStart.ToFarsi(),
|
||||
ServiceEndFa = x.ServiceEnd.ToFarsi(),
|
||||
WorkshopId = x.WorkshopId,
|
||||
RollCallServiceType = x.RollCallServiceType,
|
||||
MaxPersonValid = x.MaxPersonValid,
|
||||
WorkshopName = x.WorkshopName,
|
||||
ActiveEmployeesCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId),
|
||||
ActiveEmployeesWithRollCallInLastWeekCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId &&
|
||||
lastWeekRollCallsList.Contains(y.EmployeeId) && !leavesList.Contains(y.EmployeeId)),
|
||||
TotalEmployeesCount = workshopsWorkingEmployeesList.FirstOrDefault(y => y.WorkshopId == x.WorkshopId)?.TotalWorkingEmployeesCount ?? 0,
|
||||
//UndoneWorkFlowsCount = workFlowApplication.GetAllWorkFlowCount(x.WorkshopId).Result
|
||||
}).OrderByDescending(x=>x.IsActive).ToList();
|
||||
return workshopsWithServiceList.GroupBy(x => x.WorkshopId)
|
||||
.Select(x => x.OrderByDescending(y => y.ServiceStartFa).First())
|
||||
.Select(x => new WorkshopWithRollCallServiceQueryModel()
|
||||
{
|
||||
IsActive = x.IsActive,
|
||||
ServiceStartFa = x.ServiceStart.ToFarsi(),
|
||||
ServiceEndFa = x.ServiceEnd.ToFarsi(),
|
||||
WorkshopId = x.WorkshopId,
|
||||
RollCallServiceType = x.RollCallServiceType,
|
||||
MaxPersonValid = x.MaxPersonValid,
|
||||
WorkshopName = x.WorkshopName,
|
||||
ActiveEmployeesCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId),
|
||||
ActiveEmployeesWithRollCallInLastWeekCount = activeEmployeesList.Count(y => y.WorkshopId == x.WorkshopId &&
|
||||
lastWeekRollCallsList.Contains(y.EmployeeId) && !leavesList.Contains(y.EmployeeId)),
|
||||
TotalEmployeesCount = workshopsWorkingEmployeesList.FirstOrDefault(y => y.WorkshopId == x.WorkshopId)?.TotalWorkingEmployeesCount ?? 0,
|
||||
//UndoneWorkFlowsCount = workFlowApplication.GetAllWorkFlowCount(x.WorkshopId).Result
|
||||
}).OrderByDescending(x => x.IsActive).ToList();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user