This commit is contained in:
SamSys
2024-10-28 19:01:02 +03:30
parent a75c90d072
commit 79f894624a
47 changed files with 17355 additions and 531 deletions

View File

@@ -190,13 +190,14 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
var rollCalls = _context.RollCalls.Where(x =>
!leavesQuery.Any(y =>
y.StartLeave.Date <= x.StartDate.Value.Date && y.EndLeave.Date >= x.StartDate.Value.Date) &&
x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null &&
x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null &&
x.StartDate >= selectedMonthFirstDay && x.StartDate < nextMonthFirstDay);
var personnelCode =
_context.PersonnelCodeSet.FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId)?.PersonnelCode;
var employeeName = _context.Employees.Select(x => new { x.id, x.FName, x.LName }).FirstOrDefault(x => x.id == employeeId);
var employeeName = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId).Select(x => new { x.EmployeeId, x.EmployeeFullName })
.FirstOrDefault(x => x.EmployeeId == employeeId);
var rollCallsList = rollCalls.ToList();
var leavesList = leavesQuery.ToList();
@@ -221,15 +222,15 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
new RollCallTimeViewModel()
{
StartDate = y.StartDate.Value.ToString("HH:mm"),
EndDate = y.EndDate?.ToString("HH:mm")?? ""
EndDate = y.EndDate!.Value.ToString("HH:mm")
}),
TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date.Date == y.StartDate!.Value.Date && y.EndDate.HasValue)
TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date.Date == y.StartDate!.Value.Date)
.Sum(y => (y.EndDate!.Value - y.StartDate.Value).Ticks)),
Reason = leavesList.FirstOrDefault(y => y.EndLeave >= x.Date.Date && y.StartLeave <= x.Date.Date)?.LeaveType ?? ""
});
result = result.Select(x => new RollCallViewModel()
{
EmployeeFullName = $"{employeeName?.FName} {employeeName?.LName}",
EmployeeFullName = employeeName.EmployeeFullName,
PersonnelCode = personnelCode.ToString(),
DateGr = x.DateGr,
DateFa = x.DateFa,
@@ -237,8 +238,8 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
IsHoliday = _holidayItemApplication.IsHoliday(x.DateGr),
IsAbsent = !x.RollCallTimesList.Any(),
RollCallTimesList = x.RollCallTimesList,
TotalWorkingHours = $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{(x.TotalWorkingHoursSpan.Minutes):00}",
}).ToList();
TotalWorkingHours = $"{x.TotalWorkingHoursSpan.TotalHours.ToString("0")}:{x.TotalWorkingHoursSpan.Minutes.ToString("00")}",
}).ToList();
return new EmployeeRollCallsByMonthViewModel()
{
PersianMonthName = selectedMonthPersian.ToString("MMMM"),
@@ -296,7 +297,7 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
//roll calls for current workshop where shift start is in dateIndex date (filters today's shifts)
var rollCallsQuery = _context.RollCalls
.Where(x => x.WorkshopId == searchModel.WorkshopId && x.StartDate.HasValue && x.StartDate < DateTime.Now.Date &&
.Where(x => x.WorkshopId == searchModel.WorkshopId && x.StartDate.HasValue && x.EndDate.HasValue && x.StartDate < DateTime.Now.Date &&
x.StartDate.Value.Date == dateIndex.Date);
@@ -319,7 +320,7 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
var personnelCodeList =
_context.PersonnelCodeSet.Where(x => activeEmployeesQuery.Any(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId));
_context.PersonnelCodeSet.Where(x => activeEmployeesQuery.Any(y => y.EmployeeId == x.EmployeeId));
var rollCallsList = rollCallsQuery.ToList();
var activatedEmployeesList = activeEmployeesQuery.ToList();
var leavesList = leavesQuery.ToList();
@@ -343,12 +344,12 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
Reason = leave == null ? "" : $"{leave.LeaveType}-{leave.PaidLeaveType}",
RollCallTimesList = employeeRollCallsForDate.Select(y => new RollCallTimeViewModel()
{
EndDate = y.EndDate?.ToString("HH:mm") ?? "",
EndDate = y.EndDate!.Value.ToString("HH:mm"),
StartDate = y.StartDate!.Value.ToString("HH:mm")
}),
HasLeave = leave != null,
IsAbsent = !employeeRollCallsForDate.Any(),
TotalWorkingHoursSpan = new TimeSpan(employeeRollCallsForDate.Where(y=>y.EndDate.HasValue).Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)),
TotalWorkingHoursSpan = new TimeSpan(employeeRollCallsForDate.Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)),
PersonnelCode = personnelCodeList.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.PersonnelCode.ToString()
};
})
@@ -362,8 +363,8 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
HasLeave = x.HasLeave,
IsAbsent = x.IsAbsent,
PersonnelCode = x.PersonnelCode,
TotalWorkingHours = $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{(x.TotalWorkingHoursSpan.Minutes):00}",
});
TotalWorkingHours = $"{x.TotalWorkingHoursSpan.TotalHours.ToString("0")}:{x.TotalWorkingHoursSpan.Minutes.ToString("00")}"
});
return result;
}
@@ -375,14 +376,14 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
var date = DateTime.Now.Date;
//get active leaves for workshop which are active today and accepted and are either روزانه and استحقاقی or استعلاجی
var leaves = _context.LeaveList
.Where(x =>
(x.WorkshopId == workshopId && x.EndLeave.Date >= date && x.StartLeave.Date <= date && x.IsAccepted) &&
((x.LeaveType == "استعلاجی" || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "روزانه")) || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "ساعتی" && x.StartLeave <= DateTime.Now && x.EndLeave >= DateTime.Now))
);
//get active leaves for workshop which are active today and accepted and are either روزانه and استحقاقی or استعلاجی
var leaves = _context.LeaveList
.Where(x =>
(x.WorkshopId == workshopId && x.EndLeave.Date >= date && x.StartLeave.Date <= date && x.IsAccepted) &&
((x.LeaveType == "استعلاجی" || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "روزانه")) || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "ساعتی" && x.StartLeave <= DateTime.Now && x.EndLeave >= DateTime.Now))
);
var personnelCodes = _context.PersonnelCodeSet.Where(x => x.WorkshopId == workshopId).ToList();
var personnelCodes = _context.PersonnelCodeSet.Where(x => x.WorkshopId == workshopId).ToList();
//get currently working employees with leftWork table
//var workingEmployees =
@@ -397,29 +398,23 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
y.StartDate.Date <= date &&
y.EndDate.Date >= date));
//get today's roll calls
var rollCallsQuery = _context.RollCalls.Where(x =>
x.WorkshopId == workshopId && x.StartDate.Value.Date == date);
//var mustBePresent = activeEmployees.Where(x => !leaves.Any(y => y.EmployeeId == x.EmployeeId) &&
// workingEmployees.Any(y => y.EmployeeId == x.EmployeeId));
var mustBePresent = activeEmployees.Where(x => !leaves.Any(y => y.EmployeeId == x.EmployeeId));
//filter roll calls for active and currently working employees only
// var filteredRollCallQuery = rollCallsQuery.Where(x => mustBePresent
// .Any(y => x.EmployeeId == y.EmployeeId))
//.Where(x => workingEmployees.Any(y => y.EmployeeId == x.EmployeeId)).ToList();
var filteredRollCallQuery = rollCallsQuery.Where(x => mustBePresent
.Any(y => x.EmployeeId == y.EmployeeId)).ToList();
var nameReferences = activeEmployees.ToList();
//presents list is ready
var presentEmployees = filteredRollCallQuery.GroupBy(x => x.EmployeeId).Select(x => new RollCallViewModel()
@@ -427,9 +422,8 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
PersonnelCode = personnelCodes
.FirstOrDefault(y => y.EmployeeId == x.Key)?
.PersonnelCode.ToString(),
EmployeeFullName = x.FirstOrDefault()!.EmployeeFullName,
EmployeeFullName = nameReferences.FirstOrDefault(y => x.Key == y.EmployeeId)?.EmployeeFullName??"-",
EmployeeId = x.FirstOrDefault()!.EmployeeId,
TotalWorkingHoursSpan = new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)),
RollCallTimesList = x.Select(y => new RollCallTimeViewModel()
{
@@ -446,9 +440,9 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
EmployeeFullName = x.EmployeeFullName,
EmployeeId = x.EmployeeId,
TotalWorkingHours =
$"{(int)x.TotalWorkingHoursSpan.TotalHours}:{(x.TotalWorkingHoursSpan.Minutes):00}",
RollCallTimesList = x.RollCallTimesList
}).ToList();
$"{(int)x.TotalWorkingHoursSpan.TotalHours}:{x.TotalWorkingHoursSpan.Minutes.ToString("00")}",
RollCallTimesList = x.RollCallTimesList
}).OrderBy(x => x.RollCallTimesList.Any(y => y.EndDate != null)).ToList();
//absent ones are those who are active and not on the roll call list
var absentsQuery = activeEmployees.AsEnumerable()
@@ -465,10 +459,10 @@ public class RollCallRepository : RepositoryBase<long, RollCall>, IRollCallRepos
var absentsViewModel = absentsQuery.Select(x => new AbsentEmployeeViewModel()
{
PersonnelCode = personnelCodes
.FirstOrDefault(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId)?
.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?
.PersonnelCode.ToString(),
EmployeeId = x.EmployeeId,
EmployeeFullName = x.EmployeeFullName,
EmployeeFullName = nameReferences.FirstOrDefault(y => x.EmployeeId == y.EmployeeId)?.EmployeeFullName ?? "-",
HasLeave = employeesWithLeave.Any(y => y.EmployeeId == x.EmployeeId),
Reason = employeesWithLeave.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.LeaveType
}).ToList();