From 05d860795e424034e9ad9a707d3504e1d99a0284 Mon Sep 17 00:00:00 2001 From: mahan Date: Sun, 11 Jan 2026 15:12:08 +0330 Subject: [PATCH] add rollcall title case history query --- .../RollCallAgg/IRollCallRepository.cs | 5 + .../RollCall/IRollCallApplication.cs | 46 + .../RollCallApplication.cs | 11 + .../Repository/EmployeeDocumentsRepository.cs | 11 +- .../Repository/RollCallRepository.cs | 1165 ++++++++++------- .../RollCall/CaseHistoryController.cs | 31 + ServiceHost/Properties/launchSettings.json | 2 +- 7 files changed, 764 insertions(+), 507 deletions(-) create mode 100644 ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs diff --git a/Company.Domain/RollCallAgg/IRollCallRepository.cs b/Company.Domain/RollCallAgg/IRollCallRepository.cs index 47f851c6..4afc1f6a 100644 --- a/Company.Domain/RollCallAgg/IRollCallRepository.cs +++ b/Company.Domain/RollCallAgg/IRollCallRepository.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using _0_Framework.Application; using _0_Framework.Domain; using CompanyManagment.App.Contracts.RollCall; using CompanyManagment.App.Contracts.WorkingHoursTemp; @@ -91,5 +92,9 @@ namespace Company.Domain.RollCallAgg Task> GetRollCallsUntilNowWithWorkshopIdEmployeeIds(long workshopId, List employeeIds, DateTime fromDate); #endregion + + Task> GetCaseHistoryTitles(long workshopId,RollCallCaseHistorySearchModel searchModel); + Task> GetCaseHistoryDetails(long workshopId, + string titleId, RollCallCaseHistorySearchModel searchModel); } } diff --git a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs index 6ce7bbfd..78132004 100644 --- a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs +++ b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using _0_Framework.Application; +using CompanyManagment.App.Contracts.Workshop; +using Microsoft.AspNetCore.Mvc; namespace CompanyManagment.App.Contracts.RollCall { @@ -125,7 +127,51 @@ namespace CompanyManagment.App.Contracts.RollCall /// /// Task RecalculateValues(long workshopId, List command); + + Task> GetCaseHistoryTitles(long workshopId,RollCallCaseHistorySearchModel searchModel); + Task> GetCaseHistoryDetails(long workshopId, string titleId, RollCallCaseHistorySearchModel searchModel); } + + public class RollCallCaseHistoryDetail + { + public string EmployeeFullName { get; set; } + public string PersonnelCode { get; set; } + public TimeSpan TotalWorkingTime { get; set; } + public List Records { get; set; } + public RollCallRecordStatus Status { get; set; } + + } + + public enum RollCallRecordStatus + { + Worked = 0, + Absent = 1, + Leaved = 2 + } + + public class RollCallCaseHistoryDetailRecord + { + public TimeSpan EntryTimeDifference { get; set; } + public string StartTime { get; set; } + public string EndTime { get; set; } + public TimeSpan ExitTimeDifference { get; set; } + + } + + public class RollCallCaseHistorySearchModel:PaginationRequest + { + public string StartDate { get; set; } + public string EndDate { get; set; } + public string OneDayDate { get; set; } + public long? EmployeeId { get; set; } + } + + public class RollCallCaseHistoryTitleDto + { + public string Id { get; set; } + public string Title { get; set; } + } + public class ReCalculateRollCallValues { public long EmployeeId { get; set; } diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index e73e4c3e..96594dc8 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -858,4 +858,15 @@ public class RollCallApplication : IRollCallApplication } } + public async Task> GetCaseHistoryTitles(long workshopId, + RollCallCaseHistorySearchModel searchModel) + { + return await _rollCallRepository.GetCaseHistoryTitles(workshopId,searchModel); + } + + public async Task> GetCaseHistoryDetails(long workshopId, + string titleId, RollCallCaseHistorySearchModel searchModel) + { + return await _rollCallRepository.GetCaseHistoryDetails(workshopId, titleId, searchModel); + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/EmployeeDocumentsRepository.cs b/CompanyManagment.EFCore/Repository/EmployeeDocumentsRepository.cs index 1cffdc1d..b1728546 100644 --- a/CompanyManagment.EFCore/Repository/EmployeeDocumentsRepository.cs +++ b/CompanyManagment.EFCore/Repository/EmployeeDocumentsRepository.cs @@ -713,10 +713,15 @@ public class EmployeeDocumentsRepository : RepositoryBase x.DocumentStatus != DocumentStatus.Unsubmitted) .Include(x => x.EmployeeDocuments) - .ThenInclude(x => x.Workshop).ThenInclude(x => x.WorkshopEmployers).ThenInclude(x => x.Employer) - .GroupBy(x => x.WorkshopId).Select(x => new WorkshopWithEmployeeDocumentsViewModel() + .ThenInclude(x => x.Workshop) + .ThenInclude(x => x.WorkshopEmployers) + .ThenInclude(x => x.Employer) + .GroupBy(x => x.WorkshopId) + .Select(x => new WorkshopWithEmployeeDocumentsViewModel() { - SubmittedItemsCount = x.Count(y => y.DocumentStatus == DocumentStatus.SubmittedByAdmin || y.DocumentStatus == DocumentStatus.SubmittedByClient), + SubmittedItemsCount = x + .Count(y => y.DocumentStatus == DocumentStatus.SubmittedByAdmin + || y.DocumentStatus == DocumentStatus.SubmittedByClient), WorkshopId = x.Key, WorkshopFullName = x.First().EmployeeDocuments.Workshop.WorkshopName, EmployerName = x.First().EmployeeDocuments.Workshop.WorkshopEmployers.First().Employer.FullName diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index b76e01b8..5923d1de 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -14,6 +14,7 @@ using MD.PersianDateTime.Standard; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -27,7 +28,10 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos private readonly IHolidayItemApplication _holidayItemApplication; private readonly IWorkshopRepository _workshopRepository; private readonly IRollCallMandatoryRepository _rollCallMandatoryRepository; - public RollCallRepository(CompanyContext context, IHolidayItemApplication holidayItemApplication, IAuthHelper authHelper, IWorkshopRepository workshopRepository, IRollCallMandatoryRepository rollCallMandatoryRepository) : base(context) + + public RollCallRepository(CompanyContext context, IHolidayItemApplication holidayItemApplication, + IAuthHelper authHelper, IWorkshopRepository workshopRepository, + IRollCallMandatoryRepository rollCallMandatoryRepository) : base(context) { _context = context; _holidayItemApplication = holidayItemApplication; @@ -36,13 +40,12 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos } - #region Pooya + //حضور غیاب گروهی از پرسنل برای پرینت گروهی فیش حقوقی غیر رسمی موقت public List GetEmployeeRollCallsInDates(IEnumerable employeeIds, - long workshopId, DateTime start, DateTime end) + long workshopId, DateTime start, DateTime end) { - var rollCalls = _context.RollCalls.Where(x => employeeIds.Contains(x.EmployeeId) && workshopId == x.WorkshopId && x.StartDate != null && x.EndDate != null && @@ -55,8 +58,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos List result = new(); foreach (var employeeId in employeeIds) { - - var absentRecords = completeDaysList.Where(x => !rollCalls.Any(y => y.EmployeeId == employeeId && x.Date.Date == y.ShiftDate.Date)) + var absentRecords = completeDaysList.Where(x => + !rollCalls.Any(y => y.EmployeeId == employeeId && x.Date.Date == y.ShiftDate.Date)) .Select(x => new CheckoutDailyRollCallViewModel() { StartDate1 = null, @@ -65,25 +68,27 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos DayOfWeek = x.Date.DayOfWeek.ToString(), RollCallDateFa = x.Date.ToFarsi() }); - var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date).Select(x => - { - var orderedRollcalls = x.OrderBy(y => y.ShiftDate); - return new CheckoutDailyRollCallViewModel() + var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date) + .Select(x => { - StartDate1 = orderedRollcalls.FirstOrDefault().StartDate.Value.ToString("HH:mm"), - EndDate1 = orderedRollcalls.FirstOrDefault().EndDate.Value.ToString("HH:mm"), + var orderedRollcalls = x.OrderBy(y => y.ShiftDate); + return new CheckoutDailyRollCallViewModel() + { + StartDate1 = orderedRollcalls.FirstOrDefault().StartDate.Value.ToString("HH:mm"), + EndDate1 = orderedRollcalls.FirstOrDefault().EndDate.Value.ToString("HH:mm"), - StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.StartDate?.ToString("HH:mm") ?? "", - EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndDate?.ToString("HH:mm") ?? "", + StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.StartDate?.ToString("HH:mm") ?? "", + EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndDate?.ToString("HH:mm") ?? "", - TotalhourseSpan = - new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)), - DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), - RollCallDateFa = x.Key.Date.ToFarsi(), - DateTimeGr = x.Key.Date, - IsSliced = x.Count() > 2 - }; - }); + TotalhourseSpan = + new TimeSpan(x.Where(y => y.EndDate != null) + .Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)), + DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), + RollCallDateFa = x.Key.Date.ToFarsi(), + DateTimeGr = x.Key.Date, + IsSliced = x.Count() > 2 + }; + }); presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel { StartDate1 = x.StartDate1, @@ -95,10 +100,10 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos RollCallDateFa = x.RollCallDateFa, DateTimeGr = x.DateTimeGr, IsSliced = x.IsSliced - }); - List checkoutDailyRollCalls = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); + List checkoutDailyRollCalls = + presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); var resultItem = new PersonnelCheckoutDailyRollCallViewModel() @@ -112,17 +117,17 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return result; - - } - //قطع شده توسط سیستم - public List GetRollCallWorkFlowsCutByBgService(long workshopId, DateTime start, DateTime end) + //قطع شده توسط سیستم + public List GetRollCallWorkFlowsCutByBgService(long workshopId, DateTime start, + DateTime end) { var personnelCode = _context.PersonnelCodeSet.Where(x => x.WorkshopId == workshopId); var rollCalls = _context.RollCalls - .Where(x => personnelCode.Any(y => y.EmployeeId == x.EmployeeId) && x.RollCallModifyType == RollCallModifyType.CutByBgService && x.WorkshopId == workshopId && + .Where(x => personnelCode.Any(y => y.EmployeeId == x.EmployeeId) && + x.RollCallModifyType == RollCallModifyType.CutByBgService && x.WorkshopId == workshopId && x.ShiftDate.Date >= start.Date && x.ShiftDate.Date <= end.Date).ToList(); var names = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId) @@ -145,25 +150,29 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos }) }) .ToList(); - } - //حضور غیاب در پرینت فیش حقوقی رسمی - public List GetEmployeeRollCallsForMonth(long employeeId, long workshopId, DateTime startMonthDay, DateTime endMonthDay) + //حضور غیاب در پرینت فیش حقوقی رسمی + public List GetEmployeeRollCallsForMonth(long employeeId, long workshopId, + DateTime startMonthDay, DateTime endMonthDay) { - var firstDayOfMonth = $"{startMonthDay.ToFarsi().Substring(0,8)}01".ToGeorgianDateTime(); + var firstDayOfMonth = $"{startMonthDay.ToFarsi().Substring(0, 8)}01".ToGeorgianDateTime(); var endFarvardin = "1404/01/31".ToGeorgianDateTime(); //گرفتن ساعت استراحت پرسنل از تنظیمات + #region breakTime + BaseCustomizeEntity settings = _context.CustomizeWorkshopEmployeeSettings.AsSplitQuery().FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId); //اگر ساعت استراحت پرسنل وجود نداشت صفر است var breakTime = settings == null ? new BreakTime(false, new TimeOnly()) : settings.BreakTime; + #endregion var rollCalls = _context.RollCalls.Where(x => - x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined && - x.ShiftDate.Date >= startMonthDay && x.ShiftDate.Date <= endMonthDay).ToList(); + x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null && + x.RollCallModifyType != RollCallModifyType.Undefined && + x.ShiftDate.Date >= startMonthDay && x.ShiftDate.Date <= endMonthDay).ToList(); var leaves = _context.LeaveList.Where(x => @@ -194,10 +203,11 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos HolidayYear = startMonthDay.ToFarsiYear() }); //all the dates from start to end, to be compared with present days to get absent dates - var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => firstDayOfCurrentMonth.AddDays(offset).Date).ToList(); + var completeDaysList = Enumerable.Range(0, dateRange) + .Select(offset => firstDayOfCurrentMonth.AddDays(offset).Date).ToList(); var absentRecords = completeDaysList - .ExceptBy(rollCalls.Select(x => x.ShiftDate.Date), y => y.Date) + .ExceptBy(rollCalls.Select(x => x.ShiftDate.Date), y => y.Date) .Select(x => { var leave = leaves.FirstOrDefault(y => @@ -219,35 +229,35 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var presentDays = rollCalls.GroupBy(x => x.ShiftDate.Date).Select(x => { - var orderedRollcalls = x.OrderBy(y => y.ShiftDate); var rollCallTimeSpanPerDay = new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)); - TimeSpan breakTimePerDay ; - if(startMonthDay>endFarvardin) - breakTimePerDay= RollCallMandatoryRepository.CalculateBreakTime(x.First().BreakTimeSpan, rollCallTimeSpanPerDay); + TimeSpan breakTimePerDay; + if (startMonthDay > endFarvardin) + breakTimePerDay = + RollCallMandatoryRepository.CalculateBreakTime(x.First().BreakTimeSpan, rollCallTimeSpanPerDay); else breakTimePerDay = RollCallMandatoryRepository.CalculateBreakTime(breakTime, rollCallTimeSpanPerDay); return new CheckoutDailyRollCallViewModel() - { - StartDate1 = orderedRollcalls.FirstOrDefault().StartDate.Value.ToString("HH:mm"), - EndDate1 = orderedRollcalls.FirstOrDefault().EndDate.Value.ToString("HH:mm"), + { + StartDate1 = orderedRollcalls.FirstOrDefault().StartDate.Value.ToString("HH:mm"), + EndDate1 = orderedRollcalls.FirstOrDefault().EndDate.Value.ToString("HH:mm"), - StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.StartDate?.ToString("HH:mm") ?? "", - EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndDate?.ToString("HH:mm") ?? "", + StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.StartDate?.ToString("HH:mm") ?? "", + EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndDate?.ToString("HH:mm") ?? "", - TotalhourseSpan = rollCallTimeSpanPerDay - breakTimePerDay, + TotalhourseSpan = rollCallTimeSpanPerDay - breakTimePerDay, - BreakTimeTimeSpan = breakTimePerDay, + BreakTimeTimeSpan = breakTimePerDay, - DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), - RollCallDateFa = x.Key.Date.ToFarsi(), - DateTimeGr = x.Key.Date, - IsSliced = x.Count() > 2, - IsAbsent = false - }; + DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), + RollCallDateFa = x.Key.Date.ToFarsi(), + DateTimeGr = x.Key.Date, + IsSliced = x.Count() > 2, + IsAbsent = false + }; }); @@ -276,34 +286,32 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos }); return result; - } - //محاسبه کارکرد پرسنل در هنگام جستجو - public TimeSpan GetEmployeeRollCallTimeSpanForDuration(long employeeId, long workshopId, DateTime start, DateTime end) + //محاسبه کارکرد پرسنل در هنگام جستجو + public TimeSpan GetEmployeeRollCallTimeSpanForDuration(long employeeId, long workshopId, DateTime start, + DateTime end) { - - var rollCalls = _context.RollCalls.Where(x => - x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined && - x.ShiftDate.Date >= start && x.ShiftDate.Date <= end).ToList(); + x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate != null && x.EndDate != null && + x.RollCallModifyType != RollCallModifyType.Undefined && + x.ShiftDate.Date >= start && x.ShiftDate.Date <= end).ToList(); return new TimeSpan(rollCalls.Sum(x => (x.EndDate - x.StartDate).Value.Ticks)); - } //حضور غیاب گروهی از پرسنل برای پرینت گروهی فیش حقوقی غیر رسمی نهایی - public List GetEmployeeRollCallsForMonth(IEnumerable employeeIds, long workshopId, DateTime start, DateTime end) + public List GetEmployeeRollCallsForMonth(IEnumerable employeeIds, + long workshopId, DateTime start, DateTime end) { - if (workshopId == 170) return GetEmployeeRollCallsForMonthForKababMahdi(employeeIds, workshopId, start, end); var rollCalls = _context.RollCalls.Where(x => - employeeIds.Contains(x.EmployeeId) && workshopId == x.WorkshopId && x.StartDate != null && - x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined && - x.ShiftDate.Date >= start && x.ShiftDate.Date <= end).ToList(); + employeeIds.Contains(x.EmployeeId) && workshopId == x.WorkshopId && x.StartDate != null && + x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined && + x.ShiftDate.Date >= start && x.ShiftDate.Date <= end).ToList(); var leaves = _context.LeaveList.Where(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && x.EndLeave.Date >= start.Date && @@ -365,72 +373,78 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos (worksInHolidays && isHoliday)) }; }); - var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date).Select(x => - { - var orderedRollcalls = x.OrderBy(y => y.StartDate!.Value).ToList(); - var firstRollCall = orderedRollcalls.FirstOrDefault(); - var secondRollCall = orderedRollcalls.Skip(1).FirstOrDefault(); - //این برای این هست که ببینه اگر که این شخص گردشی بوده و دوبار وارد در دو شیفت مختلف وارد شده شیفت دوم تاثیر نخواهد گذاشت - //منطق کباب مهدی!!!! - - #region SecondTimeDiff - var hasSecondTimeDiff = false; - if (settings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating) + var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date) + .Select(x => { - if (firstRollCall != null && secondRollCall != null) + var orderedRollcalls = x.OrderBy(y => y.StartDate!.Value).ToList(); + var firstRollCall = orderedRollcalls.FirstOrDefault(); + var secondRollCall = orderedRollcalls.Skip(1).FirstOrDefault(); + //این برای این هست که ببینه اگر که این شخص گردشی بوده و دوبار وارد در دو شیفت مختلف وارد شده شیفت دوم تاثیر نخواهد گذاشت + //منطق کباب مهدی!!!! + + #region SecondTimeDiff + + var hasSecondTimeDiff = false; + if (settings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating) { - var firstShift = FindRotatingShift(firstRollCall.StartDate.Value, firstRollCall.EndDate.Value, settings.CustomizeRotatingShifts); - var secondShift = FindRotatingShift(secondRollCall.StartDate.Value, secondRollCall.EndDate.Value, settings.CustomizeRotatingShifts); - if (firstShift.start == secondShift.start && firstShift.end == secondShift.end) + if (firstRollCall != null && secondRollCall != null) { - hasSecondTimeDiff = true; + var firstShift = FindRotatingShift(firstRollCall.StartDate.Value, + firstRollCall.EndDate.Value, settings.CustomizeRotatingShifts); + var secondShift = FindRotatingShift(secondRollCall.StartDate.Value, + secondRollCall.EndDate.Value, settings.CustomizeRotatingShifts); + if (firstShift.start == secondShift.start && firstShift.end == secondShift.end) + { + hasSecondTimeDiff = true; + } } } + else + { + hasSecondTimeDiff = true; + } - } - else - { - hasSecondTimeDiff = true; - } + #endregion + return new CheckoutDailyRollCallViewModel() + { + StartDate1 = firstRollCall?.StartDate?.ToString("HH:mm"), + EndDate1 = firstRollCall?.EndDate?.ToString("HH:mm"), + StartDate2 = secondRollCall?.StartDate?.ToString("HH:mm") ?? "", + EndDate2 = secondRollCall?.EndDate?.ToString("HH:mm") ?? "", - #endregion + TotalhourseSpan = + new TimeSpan(x.Where(y => y.EndDate != null) + .Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)), + DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), + RollCallDateFa = x.Key.Date.ToFarsi(), + DateTimeGr = x.Key.Date, + IsSliced = x.Count() > 2, + IsAbsent = false, + EnterDifferencesMinutes1 = + firstRollCall != null && firstRollCall.LateEntryDuration > TimeSpan.Zero + ? CalculateEntryMinuteDifference(firstRollCall.EarlyEntryDuration, + firstRollCall.LateEntryDuration) + : "", + ExitDifferencesMinutes1 = + firstRollCall != null && firstRollCall.EarlyExitDuration > TimeSpan.Zero + ? CalculateExitMinuteDifference(firstRollCall.EarlyExitDuration, + firstRollCall.LateExitDuration) + : "", - return new CheckoutDailyRollCallViewModel() - { - StartDate1 = firstRollCall?.StartDate?.ToString("HH:mm"), - EndDate1 = firstRollCall?.EndDate?.ToString("HH:mm"), - - StartDate2 = secondRollCall?.StartDate?.ToString("HH:mm") ?? "", - EndDate2 = secondRollCall?.EndDate?.ToString("HH:mm") ?? "", - - TotalhourseSpan = - new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)), - DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), - RollCallDateFa = x.Key.Date.ToFarsi(), - DateTimeGr = x.Key.Date, - IsSliced = x.Count() > 2, - IsAbsent = false, - EnterDifferencesMinutes1 = firstRollCall != null && firstRollCall.LateEntryDuration > TimeSpan.Zero - ? CalculateEntryMinuteDifference(firstRollCall.EarlyEntryDuration, - firstRollCall.LateEntryDuration) - : "", - ExitDifferencesMinutes1 = firstRollCall != null && firstRollCall.EarlyExitDuration > TimeSpan.Zero - ? CalculateExitMinuteDifference(firstRollCall.EarlyExitDuration, - firstRollCall.LateExitDuration) - : "", - - EnterDifferencesMinutes2 = secondRollCall != null && secondRollCall.LateEntryDuration > TimeSpan.Zero && hasSecondTimeDiff - ? CalculateEntryMinuteDifference(secondRollCall.EarlyEntryDuration, - secondRollCall.LateEntryDuration) - : "", - ExitDifferencesMinutes2 = secondRollCall != null && secondRollCall.EarlyExitDuration > TimeSpan.Zero && hasSecondTimeDiff - ? CalculateExitMinuteDifference(secondRollCall.EarlyExitDuration, - secondRollCall.LateExitDuration) - : "" - }; - }); + EnterDifferencesMinutes2 = secondRollCall != null && + secondRollCall.LateEntryDuration > TimeSpan.Zero && hasSecondTimeDiff + ? CalculateEntryMinuteDifference(secondRollCall.EarlyEntryDuration, + secondRollCall.LateEntryDuration) + : "", + ExitDifferencesMinutes2 = secondRollCall != null && + secondRollCall.EarlyExitDuration > TimeSpan.Zero && hasSecondTimeDiff + ? CalculateExitMinuteDifference(secondRollCall.EarlyExitDuration, + secondRollCall.LateExitDuration) + : "" + }; + }); presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel { StartDate1 = x.StartDate1, @@ -447,10 +461,10 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos ExitDifferencesMinutes1 = x.ExitDifferencesMinutes1, EnterDifferencesMinutes2 = x.EnterDifferencesMinutes2, ExitDifferencesMinutes2 = x.ExitDifferencesMinutes2 - }); - List checkoutDailyRollCalls = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); + List checkoutDailyRollCalls = + presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); checkoutDailyRollCalls.ForEach(x => { @@ -468,8 +482,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return result; - - } private string CalculateExitMinuteDifference(TimeSpan early, TimeSpan late) @@ -536,7 +548,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos .FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId); //if no status was found return empty - if (employeeRollCallStatuses == null || employeeRollCallStatuses.EmployeesStatus == null || !employeeRollCallStatuses.EmployeesStatus.Any()) + if (employeeRollCallStatuses == null || employeeRollCallStatuses.EmployeesStatus == null || + !employeeRollCallStatuses.EmployeesStatus.Any()) return new(); //this list will have all the months which employee was active in, remember this doesn't have statuses, @@ -551,7 +564,9 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var persianStartFirstDayOfMonth = new PersianDateTime(persianStartDate.Year, persianStartDate.Month, 1); - for (PersianDateTime start = persianStartFirstDayOfMonth; start <= persianEndDate && start < PersianDateTime.Today.Date; start = start.AddMonths(1)) + for (PersianDateTime start = persianStartFirstDayOfMonth; + start <= persianEndDate && start < PersianDateTime.Today.Date; + start = start.AddMonths(1)) { activeMonths.Add(start); } @@ -571,14 +586,19 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos endSearch = new PersianDateTime(endDateTime.Value); //get the months that include these dates - activeMonthsList = activeMonthsList.Where(x => x.Year >= startSearch.Year && x.Month >= startSearch.Month && x.Year <= endSearch.Year && x.Month <= endSearch.Month).ToList(); + activeMonthsList = activeMonthsList.Where(x => + x.Year >= startSearch.Year && x.Month >= startSearch.Month && x.Year <= endSearch.Year && + x.Month <= endSearch.Month).ToList(); } + //if exact datetime is given start and end will be the same date if (exactDateTime.HasValue) { startSearch = new PersianDateTime(exactDateTime.Value); endSearch = startSearch; - activeMonthsList = activeMonthsList.Where(x => x.Year >= startSearch.Year && x.Month >= startSearch.Month && x.Year <= endSearch.Year && x.Month <= endSearch.Month).ToList(); + activeMonthsList = activeMonthsList.Where(x => + x.Year >= startSearch.Year && x.Month >= startSearch.Month && x.Year <= endSearch.Year && + x.Month <= endSearch.Month).ToList(); } //dateIndex is a kind of selector which moves @@ -607,23 +627,27 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //get leaves in the specified month var leavesQuery = - _context.LeaveList.Where(x => (x.LeaveType == "استعلاجی" || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "روزانه")) && - x.IsAccepted && - x.EndLeave >= selectedMonthFirstDay && x.StartLeave < nextMonthFirstDay && - x.WorkshopId == workshopId && x.EmployeeId == employeeId); + _context.LeaveList.Where(x => + (x.LeaveType == "استعلاجی" || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "روزانه")) && + x.IsAccepted && + x.EndLeave >= selectedMonthFirstDay && x.StartLeave < nextMonthFirstDay && + x.WorkshopId == workshopId && x.EmployeeId == employeeId); //get employee rollcalls where there is no leave in that day, var rollCalls = _context.RollCalls.Where(x => x.EmployeeId == employeeId && !leavesQuery.Any(y => y.StartLeave.Date <= x.ShiftDate.Date && y.EndLeave.Date >= x.ShiftDate.Date) && - x.WorkshopId == workshopId && x.StartDate != null && - x.ShiftDate >= selectedMonthFirstDay && x.ShiftDate < nextMonthFirstDay && x.RollCallModifyType != RollCallModifyType.Undefined); + x.WorkshopId == workshopId && x.StartDate != null && + x.ShiftDate >= selectedMonthFirstDay && x.ShiftDate < nextMonthFirstDay && + x.RollCallModifyType != RollCallModifyType.Undefined); var personnelCode = - _context.PersonnelCodeSet.FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId)?.PersonnelCode; + _context.PersonnelCodeSet.FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId) + ?.PersonnelCode; - var employeeName = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId).Select(x => new { x.EmployeeId, x.EmployeeFullName }) + 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(); @@ -635,7 +659,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var todayDate = DateTime.Now.Date; //all the dates from start to end, to be compared with present days to get absent dates - var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => selectedMonthFirstDay.AddDays(offset).Date).Where(x => x.Date < todayDate); + var completeDaysList = Enumerable.Range(0, dateRange) + .Select(offset => selectedMonthFirstDay.AddDays(offset).Date).Where(x => x.Date < todayDate); //if user search range is within a month for example, we dont want 30/31/29 days for month, we want it to be the size of the search range //user input = 2024/04/15~2024/04/21, output days count is 21-15+1=6 days from 15th to 21st @@ -644,36 +669,38 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //get the days in which user was active and no rollcall with enddate==null is present //(im thinking about removing the rollcall condition) - var result = completeDaysList.Where(x => !rollCallsList.Any(y => y.ShiftDate.Date == x.Date.Date && y.EndDate == null) && - statusesOfMonth.Any(y => x >= y.StartDate.Date && x <= y.EndDate.Date)) - .Select(x => - { - //iterating day by day - - //get the leaves for this day so we can find out if employee was on a permitted absence - var leave = leavesList.FirstOrDefault(y => y.EndLeave >= x.Date && y.StartLeave <= x.Date); - return new RollCallViewModel() + var result = completeDaysList.Where(x => + !rollCallsList.Any(y => y.ShiftDate.Date == x.Date.Date && y.EndDate == null) && + statusesOfMonth.Any(y => x >= y.StartDate.Date && x <= y.EndDate.Date)) + .Select(x => { - DateGr = x.Date, - DateFa = x.Date.ToFarsi(), + //iterating day by day - //all the roll calls which have a start date in this day - RollCallTimesList = rollCallsList.Where(y => x.Date == y.ShiftDate.Date).Select(y => - new RollCallTimeViewModel() - { - StartDate = y.StartDate.Value.ToString("HH:mm"), - EndDate = y.EndDate!.Value.ToString("HH:mm"), - StartDateGr = y.StartDate.Value, - EndDateGr = y.EndDate.Value, - EntryTimeDifferences = CalculateEntryTimeDifferences(y.EarlyEntryDuration, y.LateEntryDuration), - ExitTimeDifferences = CalculateExitTimeDifferences(y.EarlyExitDuration, y.LateExitDuration) - }), - TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date == y.ShiftDate.Date) - .Sum(y => (y.EndDate!.Value - y.StartDate.Value).Ticks)), - Reason = leave?.LeaveType ?? "", - HasLeave = (leave?.PaidLeaveType == "روزانه" || leave?.LeaveType == "استعلاجی") ? true : false - }; - }); + //get the leaves for this day so we can find out if employee was on a permitted absence + var leave = leavesList.FirstOrDefault(y => y.EndLeave >= x.Date && y.StartLeave <= x.Date); + return new RollCallViewModel() + { + DateGr = x.Date, + DateFa = x.Date.ToFarsi(), + + //all the roll calls which have a start date in this day + RollCallTimesList = rollCallsList.Where(y => x.Date == y.ShiftDate.Date).Select(y => + new RollCallTimeViewModel() + { + StartDate = y.StartDate.Value.ToString("HH:mm"), + EndDate = y.EndDate!.Value.ToString("HH:mm"), + StartDateGr = y.StartDate.Value, + EndDateGr = y.EndDate.Value, + EntryTimeDifferences = + CalculateEntryTimeDifferences(y.EarlyEntryDuration, y.LateEntryDuration), + ExitTimeDifferences = CalculateExitTimeDifferences(y.EarlyExitDuration, y.LateExitDuration) + }), + TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date == y.ShiftDate.Date) + .Sum(y => (y.EndDate!.Value - y.StartDate.Value).Ticks)), + Reason = leave?.LeaveType ?? "", + HasLeave = (leave?.PaidLeaveType == "روزانه" || leave?.LeaveType == "استعلاجی") ? true : false + }; + }); //filling TotalWorkingHours string from TimeSpans we filled in the last step and other info result = result.Select(x => new RollCallViewModel() @@ -690,7 +717,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos RollCallTimesList = x.RollCallTimesList.OrderBy(r => r.StartDateGr), HasLeave = x.HasLeave, TotalWorkingHoursSpan = x.TotalWorkingHoursSpan, - TotalWorkingHours = $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{x.TotalWorkingHoursSpan.Minutes.ToString("00")}" + TotalWorkingHours = + $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{x.TotalWorkingHoursSpan.Minutes.ToString("00")}" }).ToList(); //total working hours in the whole month or duration @@ -706,7 +734,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos DateIndex = activeMonthsList.Count > 1 ? activeMonthsList.Skip(1).First().ToString("yyyy/MM/dd") : null, TotalWorkingHours = new TimeSpan(result.Sum(x => x.TotalWorkingHoursSpan.Ticks)).ToFarsiHoursAndMinutes(), TotalWorkingHoursTimeSpan = $"{(int)totalWorkingHours.TotalHours}:{totalWorkingHours.Minutes:00}" - }; } @@ -728,7 +755,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos { return $""; } - } private string CalculateEntryTimeDifferences(TimeSpan early, TimeSpan late) @@ -749,17 +775,18 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos { return $""; } - } //Without Paginate, With EndDate==null, without undefined, Ordered Descending By StartDate - public List GetEmployeeRollCallsHistoryAllInDates(long workshopId, long employeeId, DateTime start, DateTime end) + public List GetEmployeeRollCallsHistoryAllInDates(long workshopId, long employeeId, + DateTime start, DateTime end) { var withPersonnelCode = _context.PersonnelCodeSet.Where(x => x.WorkshopId == workshopId); return _context.RollCalls.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && withPersonnelCode.Any(y => y.EmployeeId == x.EmployeeId) && - (x.EndDate == null || x.EndDate.Value.Date >= start.Date) && x.ShiftDate.Date <= end.Date) + (x.EndDate == null || x.EndDate.Value.Date >= start.Date) && + x.ShiftDate.Date <= end.Date) .OrderByDescending(x => x.StartDate.Value) .Select(x => new RollCallViewModel { @@ -776,13 +803,11 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //سوابق حضور غیاب کارگاه public RollCallsByDateViewModel GetWorkshopRollCallHistory(RollCallSearchModel searchModel) { - //initialize DateTime searchDurationEnd = DateTime.Now.AddDays(-1).Date; DateTime searchDurationStart = DateTime.MinValue; - //override if user has entered inputs (dates must be validated in the application layer) if (!string.IsNullOrWhiteSpace(searchModel.StarDateFa) && !string.IsNullOrWhiteSpace(searchModel.StarDateFa)) { @@ -791,9 +816,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos } - - else - if (!string.IsNullOrWhiteSpace(searchModel.ExactDateFa)) + else if (!string.IsNullOrWhiteSpace(searchModel.ExactDateFa)) { searchDurationEnd = searchModel.ExactDateFa.ToGeorgianDateTime().Date; searchDurationStart = searchModel.ExactDateFa.ToGeorgianDateTime().AddDays(-1).Date; @@ -804,7 +827,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return new(); - DateTime dateIndex = searchDurationEnd.AddDays(-1 * (searchModel.DateIndex)).Date; if (dateIndex <= searchDurationStart) @@ -813,12 +835,15 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //get leaves for workshop that have been activated in dateIndex date var leavesQuery = _context.LeaveList.Where(x => x.WorkshopId == searchModel.WorkshopId && - x.IsAccepted && (x.LeaveType == "استعلاجی" || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "روزانه")) && + x.IsAccepted && + (x.LeaveType == "استعلاجی" || (x.LeaveType == "استحقاقی" && + x.PaidLeaveType == "روزانه")) && x.EndLeave.Date >= dateIndex && x.StartLeave.Date <= dateIndex); //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.RollCallModifyType != RollCallModifyType.Undefined && x.ShiftDate < DateTime.Now.Date && + .Where(x => x.WorkshopId == searchModel.WorkshopId && x.StartDate.HasValue && + x.RollCallModifyType != RollCallModifyType.Undefined && x.ShiftDate < DateTime.Now.Date && x.ShiftDate.Date == dateIndex.Date); var personnelCodeQuery = _context.PersonnelCodeSet.Where(x => x.WorkshopId == searchModel.WorkshopId); @@ -826,9 +851,10 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //get active employees of workshop in dateIndex date var activeEmployeesQuery = _context.RollCallEmployees.Include(x => x.EmployeesStatus) - .Where(x => x.WorkshopId == searchModel.WorkshopId && personnelCodeQuery.Any(y => y.EmployeeId == x.EmployeeId) && + .Where(x => x.WorkshopId == searchModel.WorkshopId && + personnelCodeQuery.Any(y => y.EmployeeId == x.EmployeeId) && x.EmployeesStatus.Any(y => y.EndDate.Date >= dateIndex && y.StartDate.Date <= dateIndex) - && !rollCallsQuery.Any(rc => rc.EmployeeId == x.EmployeeId && !rc.EndDate.HasValue)); + && !rollCallsQuery.Any(rc => rc.EmployeeId == x.EmployeeId && !rc.EndDate.HasValue)); if (searchModel.EmployeeId > 0) { @@ -861,17 +887,21 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos EmployeeFullName = x.EmployeeFullName, EmployeeId = x.EmployeeId, Reason = leave == null ? "" : $"{leave.LeaveType}-{leave.PaidLeaveType}", - RollCallTimesList = employeeRollCallsForDate.OrderBy(r => r.StartDate).Select(y => new RollCallTimeViewModel() - { - EndDate = y.EndDate!.Value.ToString("HH:mm"), - StartDate = y.StartDate!.Value.ToString("HH:mm"), - EntryTimeDifferences = CalculateEntryTimeDifferences(y.EarlyEntryDuration, y.LateEntryDuration), - ExitTimeDifferences = CalculateExitTimeDifferences(y.EarlyExitDuration, y.LateExitDuration) - }), + RollCallTimesList = employeeRollCallsForDate.OrderBy(r => r.StartDate).Select(y => + new RollCallTimeViewModel() + { + EndDate = y.EndDate!.Value.ToString("HH:mm"), + StartDate = y.StartDate!.Value.ToString("HH:mm"), + EntryTimeDifferences = + CalculateEntryTimeDifferences(y.EarlyEntryDuration, y.LateEntryDuration), + ExitTimeDifferences = CalculateExitTimeDifferences(y.EarlyExitDuration, y.LateExitDuration) + }), HasLeave = leave != null, IsAbsent = !employeeRollCallsForDate.Any(), - TotalWorkingHoursSpan = new TimeSpan(employeeRollCallsForDate.Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)), - PersonnelCode = personnelCodeList.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.PersonnelCode.ToString(), + TotalWorkingHoursSpan = + new TimeSpan(employeeRollCallsForDate.Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)), + PersonnelCode = personnelCodeList.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.PersonnelCode + .ToString(), }; }) }; @@ -884,7 +914,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos HasLeave = x.HasLeave, IsAbsent = x.IsAbsent, PersonnelCode = x.PersonnelCode, - TotalWorkingHours = $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{(x.TotalWorkingHoursSpan.Minutes).ToString("00")}" + TotalWorkingHours = + $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{(x.TotalWorkingHoursSpan.Minutes).ToString("00")}" }); return result; } @@ -892,14 +923,12 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //برای دریافت سوابق به صورت collapsed public RollCallsByDateViewModel GetWorkshopRollCallHistoryCollapsed(RollCallSearchModel searchModel) { - //initialize DateTime searchDurationEnd = DateTime.Now.AddDays(-1).Date; DateTime searchDurationStart = searchDurationEnd.AddDays(-16); - //override if user has entered inputs (dates must be validated in the application layer) if (!string.IsNullOrWhiteSpace(searchModel.StarDateFa) && !string.IsNullOrWhiteSpace(searchModel.StarDateFa)) { @@ -908,9 +937,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos } - - else - if (!string.IsNullOrWhiteSpace(searchModel.ExactDateFa)) + else if (!string.IsNullOrWhiteSpace(searchModel.ExactDateFa)) { searchDurationEnd = searchModel.ExactDateFa.ToGeorgianDateTime().Date; searchDurationStart = searchModel.ExactDateFa.ToGeorgianDateTime().AddDays(-1).Date; @@ -921,7 +948,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return new(); - DateTime dateIndex = searchDurationEnd.AddDays(-1 * (searchModel.DateIndex)).Date; if (dateIndex <= searchDurationStart) @@ -930,7 +956,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var activeEmployeesList = _context.RollCallEmployees.Include(x => x.EmployeesStatus) .Where(x => x.WorkshopId == searchModel.WorkshopId && - x.EmployeesStatus.Any(y => y.EndDate.Date >= dateIndex && y.StartDate.Date <= dateIndex)).ToList(); + x.EmployeesStatus.Any(y => y.EndDate.Date >= dateIndex && y.StartDate.Date <= dateIndex)) + .ToList(); var result = new RollCallsByDateViewModel() { @@ -944,14 +971,19 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos } //سوابق غیبت - public List GetWorkshopAbsentHistory(long workshopId, DateTime startSearch, DateTime endSearch) + public List GetWorkshopAbsentHistory(long workshopId, DateTime startSearch, + DateTime endSearch) { if (endSearch.Date == DateTime.Now.Date) endSearch = endSearch.AddDays(-1); //get leaves for workshop that have been activated in dateIndex date var leavesQuery = _context.LeaveList.AsSplitQuery().Where(x => x.WorkshopId == workshopId && - x.IsAccepted && (x.LeaveType == "استعلاجی" || (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "روزانه")) && - x.EndLeave.Date >= startSearch.Date && x.StartLeave.Date <= endSearch.Date); + x.IsAccepted && + (x.LeaveType == "استعلاجی" || + (x.LeaveType == "استحقاقی" && + x.PaidLeaveType == "روزانه")) && + x.EndLeave.Date >= startSearch.Date && + x.StartLeave.Date <= endSearch.Date); //roll calls for current workshop where shift start is in dateIndex date (filters today's shifts) var rollCallsQuery = _context.RollCalls.AsSplitQuery() @@ -966,7 +998,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var activeEmployeesQuery = _context.RollCallEmployees.AsSplitQuery().Include(x => x.EmployeesStatus) .Where(x => x.WorkshopId == workshopId && - x.EmployeesStatus.Any(y => y.EndDate.Date >= startSearch && y.StartDate.Date <= endSearch) && + x.EmployeesStatus.Any(y => + y.EndDate.Date >= startSearch && y.StartDate.Date <= endSearch) && withPersonnelCode.Any(y => y.EmployeeId == x.EmployeeId)); var employeeSettingsList = @@ -995,14 +1028,16 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos List activatedEmployeesListInDay = new(); activatedEmployeesListInDay = activatedEmployeesList - .Join(employeeSettingsList.Where(x => x.WeeklyOffDays == null || !x.WeeklyOffDays.Select(w => w.DayOfWeek).Contains(day.DayOfWeek)) - , x => x.EmployeeId, y => y.EmployeeId, - (x, _) => x).ToList(); + .Join(employeeSettingsList.Where(x => + x.WeeklyOffDays == null || !x.WeeklyOffDays.Select(w => w.DayOfWeek).Contains(day.DayOfWeek)) + , x => x.EmployeeId, y => y.EmployeeId, + (x, _) => x).ToList(); if (isHoliday) { activatedEmployeesListInDay = activatedEmployeesListInDay - .Join(employeeSettingsList.Where(x => x.WeeklyOffDays == null || x.HolidayWork != HolidayWork.Default) + .Join(employeeSettingsList.Where(x => + x.WeeklyOffDays == null || x.HolidayWork != HolidayWork.Default) , x => x.EmployeeId, y => y.EmployeeId, (x, _) => x).ToList(); } @@ -1037,15 +1072,16 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos DateFa = day.ToFarsi(), ActiveEmployees = activatedEmployeesListInDay.Where(x => x.EmployeesStatus.Any(y => y.StartDate.Date <= day && y.EndDate.AddDays(-1).Date >= day) && - !leavesList.Any(y => y.EmployeeId == x.EmployeeId && y.StartLeave.Date <= day && y.EndLeave.Date >= day) && + !leavesList.Any(y => + y.EmployeeId == x.EmployeeId && y.StartLeave.Date <= day && y.EndLeave.Date >= day) && !rollCallsList.Any(rc => rc.EmployeeId == x.EmployeeId && rc.ShiftDate.Date == day.Date)) - .Select(x => new RollCallViewModel() - { - EmployeeId = x.EmployeeId, - EmployeeFullName = x.EmployeeFullName, - Id = x.id, - WorkshopId = x.WorkshopId - }), + .Select(x => new RollCallViewModel() + { + EmployeeId = x.EmployeeId, + EmployeeFullName = x.EmployeeFullName, + Id = x.id, + WorkshopId = x.WorkshopId + }), IsHoliday = isHoliday, IsFriday = day.DayOfWeek == DayOfWeek.Friday }; @@ -1056,7 +1092,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos } - //گزارش آنلاین حضور غیاب کارگاه public CurrentDayRollCall GetWorkshopCurrentDayRollCalls(long workshopId) { @@ -1067,7 +1102,9 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos 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)) + ((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); @@ -1077,7 +1114,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos // _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && x.StartWorkDate < date && x.LeftWorkDate.Date > date); - //get activated employees var activeEmployees = _context.RollCallEmployees.Include(x => x.EmployeesStatus) @@ -1087,17 +1123,15 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //get today's roll calls var rollCallsQuery = _context.RollCalls.Where(x => - x.WorkshopId == workshopId && (x.ShiftDate.Date == date || x.EndDate == null) && x.RollCallModifyType != RollCallModifyType.Undefined); - - + x.WorkshopId == workshopId && (x.ShiftDate.Date == date || x.EndDate == null) && + x.RollCallModifyType != RollCallModifyType.Undefined); var mustBePresent = activeEmployees.Where(x => !leaves.Any(y => y.EmployeeId == x.EmployeeId)); - var filteredRollCallQuery = rollCallsQuery.Where(x => mustBePresent - .Any(y => x.EmployeeId == y.EmployeeId)).ToList(); + .Any(y => x.EmployeeId == y.EmployeeId)).ToList(); var nameReferences = activeEmployees.ToList(); @@ -1110,17 +1144,15 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos .PersonnelCode.ToString(), 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)), + TotalWorkingHoursSpan = + new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate!.Value - y.StartDate!.Value).Ticks)), RollCallTimesList = x.OrderBy(r => r.StartDate).Select(y => new RollCallTimeViewModel() { StartDate = y.StartDate!.Value.ToString("HH:mm"), EndDate = y.EndDate?.ToString("HH:mm"), EntryTimeDifferences = CalculateEntryTimeDifferences(y.EarlyEntryDuration, y.LateEntryDuration), ExitTimeDifferences = CalculateExitTimeDifferences(y.EarlyExitDuration, y.LateExitDuration) - }).ToList() - - }); presentEmployees = presentEmployees.Select(x => new RollCallViewModel() @@ -1138,10 +1170,9 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos .ExceptBy(presentEmployees.Select(x => x.EmployeeId), e => e.EmployeeId).ToList(); - //get today's active leaves var employeesWithLeave = leaves.AsEnumerable() - .Where(x => absentsQuery.Any(y => y.EmployeeId == x.EmployeeId)) + .Where(x => absentsQuery.Any(y => y.EmployeeId == x.EmployeeId)) .Select(x => new { x.EmployeeId, x.LeaveType }).ToList(); var personnelCodesList = personnelCodes.ToList(); @@ -1161,7 +1192,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return new CurrentDayRollCall() { AbsentEmployees = absentsViewModel.ToList(), - PresentEmployees = presentEmployees.OrderByDescending(x => x.RollCallTimesList.Any(y => string.IsNullOrWhiteSpace(y.EndDate))) + PresentEmployees = presentEmployees + .OrderByDescending(x => x.RollCallTimesList.Any(y => string.IsNullOrWhiteSpace(y.EndDate))) .ThenByDescending(x => x.RollCallTimesList.Max(y => y.StartDate)).ToList() }; } @@ -1176,38 +1208,40 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //تداخل مرخصی در کارپوشه public EditRollCall GetByEmployeeIdAndWorkshopId(long employeeId, long workshopId) { - throw new NotImplementedException(); + throw new NotImplementedException(); } public EditRollCall GetById(long id) { - throw new NotImplementedException(); + throw new NotImplementedException(); } public List GetOverlappedRollCallsWithLeaveInDates(long workshopId, DateTime start, DateTime end) { - - var rollCalls = _context.RollCalls.Where(x => x.WorkshopId == workshopId && x.ShiftDate.Date >= start.Date && x.EndDate.HasValue && + var rollCalls = _context.RollCalls.Where(x => + x.WorkshopId == workshopId && x.ShiftDate.Date >= start.Date && x.EndDate.HasValue && x.ShiftDate.Date <= end).ToList(); var leaves = - _context.LeaveList.Where(x => x.WorkshopId == workshopId && x.EndLeave >= start && x.StartLeave <= end).ToList(); + _context.LeaveList.Where(x => x.WorkshopId == workshopId && x.EndLeave >= start && x.StartLeave <= end) + .ToList(); var dailyLeaves = leaves.Where(x => x.PaidLeaveType == "روزانه").ToList(); - var hourlyLeaves = leaves.Where(x => x.PaidLeaveType== "ساعتی").ToList(); + var hourlyLeaves = leaves.Where(x => x.PaidLeaveType == "ساعتی").ToList(); var hourlyOverlappedRollCalls = rollCalls.Where(x => - hourlyLeaves.Any(y => x.EmployeeId == y.EmployeeId && x.EndDate.Value >= y.StartLeave && x.StartDate.Value <= y.EndLeave)); + hourlyLeaves.Any(y => + x.EmployeeId == y.EmployeeId && x.EndDate.Value >= y.StartLeave && x.StartDate.Value <= y.EndLeave)); var dailyOverlappedRollCalls = rollCalls.Where(x => - dailyLeaves.Any(y => x.EmployeeId == y.EmployeeId && x.ShiftDate.Date == y.StartLeave.Date)); + dailyLeaves.Any(y => x.EmployeeId == y.EmployeeId && x.ShiftDate.Date == y.StartLeave.Date)); - var hourlyOverlappedRollCallsResult = hourlyOverlappedRollCalls.Select(x => + var hourlyOverlappedRollCallsResult = hourlyOverlappedRollCalls.Select(x => { var leave = leaves.FirstOrDefault(y => x.EmployeeId == y.EmployeeId && - x.EndDate.Value >= y.StartLeave && - x.StartDate.Value <= y.EndLeave); + x.EndDate.Value >= y.StartLeave && + x.StartDate.Value <= y.EndLeave); return new OverlappedRollCallWithLeave() { RollCallId = x.id, @@ -1221,22 +1255,22 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var dailyOverlappedRollCallsResult = dailyOverlappedRollCalls.Select(x => { - var leave = leaves.FirstOrDefault(y => x.EmployeeId == y.EmployeeId && - x.ShiftDate.Date == y.StartLeave.Date); - return new OverlappedRollCallWithLeave() - { - RollCallId = x.id, - LeaveId = leave.id, - StartOfOverlapDateTime = leave.StartLeave > x.StartDate.Value ? leave.StartLeave : x.StartDate.Value, - EndOfOverlapDateTime = leave.EndLeave < x.EndDate ? leave.EndLeave : x.EndDate.Value, - EmployeeFullName = x.EmployeeFullName, - EmployeeId = x.EmployeeId - }; + var leave = leaves.FirstOrDefault(y => x.EmployeeId == y.EmployeeId && + x.ShiftDate.Date == y.StartLeave.Date); + return new OverlappedRollCallWithLeave() + { + RollCallId = x.id, + LeaveId = leave.id, + StartOfOverlapDateTime = leave.StartLeave > x.StartDate.Value ? leave.StartLeave : x.StartDate.Value, + EndOfOverlapDateTime = leave.EndLeave < x.EndDate ? leave.EndLeave : x.EndDate.Value, + EmployeeFullName = x.EmployeeFullName, + EmployeeId = x.EmployeeId + }; }).ToList(); var result = hourlyOverlappedRollCallsResult.Concat(dailyOverlappedRollCallsResult); - return result.Select(x => new OverlappedRollCallWithLeave() + return result.Select(x => new OverlappedRollCallWithLeave() { RollCallId = x.RollCallId, LeaveId = x.LeaveId, @@ -1248,7 +1282,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos StartOfOverlapTime = x.StartOfOverlapDateTime.ToString("HH:mm"), EmployeeFullName = x.EmployeeFullName, EmployeeId = x.EmployeeId - }).ToList(); } @@ -1263,7 +1296,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //نیز پاک می شوند Undefined حضور و غیاب های public void RemoveEmployeeRollCallsInDate(long workshopId, long employeeId, DateTime date) { - var rollCalls = _context.RollCalls.IgnoreQueryFilters().Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ShiftDate == date.Date); + var rollCalls = _context.RollCalls.IgnoreQueryFilters().Where(x => + x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ShiftDate == date.Date); if (!rollCalls.Any()) return; _context.RollCalls.RemoveRange(rollCalls); @@ -1275,11 +1309,12 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos /// public List GetWorkshopEmployeeRollCallsForDate(long workshopId, long employeeId, DateTime date) { - var names = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId).Select(x => new - { - x.EmployeeId, - x.EmployeeFullName - }).ToList(); + var names = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId) + .Select(x => new + { + x.EmployeeId, + x.EmployeeFullName + }).ToList(); var rollcalls = _context.RollCalls .Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ShiftDate.Date == date.Date) @@ -1311,13 +1346,14 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos StartDayOfWeekFa = x.StartDate.Value.DayOfWeek.DayOfWeeKToPersian(), EndDayOfWeekFa = x.EndDate?.DayOfWeek.DayOfWeeKToPersian(), TotalWorkingHoursSpan = x.EndDate == null ? new() : x.EndDate.Value - x.StartDate.Value - }).OrderBy(x=>x.StartDate).ToList(); + }).OrderBy(x => x.StartDate).ToList(); } /// /// دریافت حضور غیاب های غیر منقطع /// - public IEnumerable GetNotSlicedRollCallsByWorkshopId(long workshopId, DateTime durationStart, DateTime durationEnd) + public IEnumerable GetNotSlicedRollCallsByWorkshopId(long workshopId, DateTime durationStart, + DateTime durationEnd) { if (durationEnd.Date >= DateTime.Now.Date) durationEnd = DateTime.Now.AddDays(-1).Date; @@ -1325,12 +1361,13 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var names = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId).ToList(); var rollCalls = _context.RollCalls.Where(x => x.WorkshopId == workshopId && - x.ShiftDate.Date >= durationStart && x.ShiftDate.Date <= durationEnd && x.EndDate.HasValue).ToList(); + x.ShiftDate.Date >= durationStart && + x.ShiftDate.Date <= durationEnd && x.EndDate.HasValue).ToList(); if (rollCalls == null || !rollCalls.Any()) return new List(); return rollCalls.GroupBy(x => x.ShiftDate.Date).SelectMany(x => - x.GroupBy(y => y.EmployeeId).Where(y => y.Count() == 1) - .SelectMany(y => y)).Select(x => new RollCallViewModel + x.GroupBy(y => y.EmployeeId).Where(y => y.Count() == 1) + .SelectMany(y => y)).Select(x => new RollCallViewModel { Id = x.id, StartDate = x.StartDate.Value, @@ -1339,14 +1376,14 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos DateGr = x.ShiftDate.Date, EmployeeFullName = names.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.EmployeeFullName ?? "" }); - } - + public List GetRange(IEnumerable rollCallIds) { var query = _context.RollCalls.Where(x => rollCallIds.Contains(x.id)); - var names = _context.RollCallEmployees.Where(x => query.Any(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId)).ToList(); + var names = _context.RollCallEmployees + .Where(x => query.Any(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId)).ToList(); return query.Select(x => new RollCallViewModel @@ -1354,53 +1391,57 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos StartDate = x.StartDate.Value, EndDate = x.EndDate.Value, Id = x.id, - EmployeeFullName = names.FirstOrDefault(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId).EmployeeFullName + EmployeeFullName = names.FirstOrDefault(y => y.EmployeeId == x.EmployeeId && y.WorkshopId == x.WorkshopId) + .EmployeeFullName }).ToList(); } public List GetRangeByWorkshopIdEmployeeIdForDate(long workshopId, long employeeId, - DateTime date) + DateTime date) { - return _context.RollCalls.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && - x.ShiftDate.Date == date).ToList(); + return _context.RollCalls.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && + x.ShiftDate.Date == date).ToList(); } - /// - /// undefined دریافت حضور و غیاب های - /// - public List GetUndefinedRollCallWorkFlowsInDates(long workshopId, DateTime start, DateTime end) + /// + /// undefined دریافت حضور و غیاب های + /// + public List GetUndefinedRollCallWorkFlowsInDates(long workshopId, DateTime start, + DateTime end) { { var rollCalls = _context.RollCalls.IgnoreQueryFilters() .Where(x => x.RollCallModifyType == RollCallModifyType.Undefined && x.WorkshopId == workshopId && - x.ShiftDate.Date >= start.Date && x.ShiftDate.Date <= end.Date).ToList(); + x.ShiftDate.Date >= start.Date && x.ShiftDate.Date <= end.Date).ToList(); var names = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId) .Select(x => new { x.EmployeeId, x.WorkshopId, x.EmployeeFullName }).ToList(); var result = rollCalls.GroupBy(x => x.ShiftDate.Date) - .Select(g => new RollCallsByDateViewModel() - { - DateGr = g.Key, - DateFa = g.Key.ToFarsi(), - DayOfWeekFa = g.Key.DayOfWeek.DayOfWeeKToPersian(), - ActiveEmployees = g.Select(x => new RollCallViewModel() + .Select(g => new RollCallsByDateViewModel() { - EmployeeId = x.EmployeeId, - EmployeeFullName = names.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.EmployeeFullName ?? "", - WorkshopId = x.WorkshopId, - Id = x.id, - StartDate = x.StartDate, - EndDate = x.EndDate + DateGr = g.Key, + DateFa = g.Key.ToFarsi(), + DayOfWeekFa = g.Key.DayOfWeek.DayOfWeeKToPersian(), + ActiveEmployees = g.Select(x => new RollCallViewModel() + { + EmployeeId = x.EmployeeId, + EmployeeFullName = names.FirstOrDefault(y => y.EmployeeId == x.EmployeeId)?.EmployeeFullName ?? + "", + WorkshopId = x.WorkshopId, + Id = x.id, + StartDate = x.StartDate, + EndDate = x.EndDate + }) }) - }) - .ToList(); + .ToList(); return result; } } + #endregion @@ -1434,7 +1475,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos { var checkTime = DateTime.Now; var checkLastOne = query.OrderByDescending(x => x.StartDate).FirstOrDefault(); - if (checkLastOne != null && checkLastOne.EndDate == null && checkLastOne.RollCallModifyType == RollCallModifyType.None) + if (checkLastOne != null && checkLastOne.EndDate == null && + checkLastOne.RollCallModifyType == RollCallModifyType.None) { var checkSpan = (DateTime.Now - checkLastOne.StartDate); if (checkSpan < validSpan) @@ -1443,7 +1485,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos } } - if (checkLastOne != null && checkLastOne.EndDate != null && checkLastOne.RollCallModifyType == RollCallModifyType.None) + if (checkLastOne != null && checkLastOne.EndDate != null && + checkLastOne.RollCallModifyType == RollCallModifyType.None) { var checkSpan = (DateTime.Now - checkLastOne.EndDate); if (checkSpan < validSpan) @@ -1451,6 +1494,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return "outRegistred-InvalidIncom"; } } + return "Valid"; } else @@ -1466,7 +1510,9 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var entity = _context.RollCalls.FirstOrDefault(x => x.id == rollCallId); if (entity == null) return null; - var name = _context.RollCallEmployees.FirstOrDefault(x => x.WorkshopId == entity.WorkshopId && x.EmployeeId == entity.EmployeeId).EmployeeFullName; + var name = _context.RollCallEmployees + .FirstOrDefault(x => x.WorkshopId == entity.WorkshopId && x.EmployeeId == entity.EmployeeId) + .EmployeeFullName; return new RollCallViewModel { WorkshopId = entity.WorkshopId, @@ -1482,23 +1528,30 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos /// /// برای پرینت سوابق حضور و غیاب /// - public EmployeeRollCallsByMonthViewModel GetEmployeeRollCallsHistoryForPrint(long employeeId, long workshopId, DateTime firstRollCallToPrintStartDate, DateTime lastRollCallToPrintStartDate) + public EmployeeRollCallsByMonthViewModel GetEmployeeRollCallsHistoryForPrint(long employeeId, long workshopId, + DateTime firstRollCallToPrintStartDate, DateTime lastRollCallToPrintStartDate) { - - var selectedMonthPersian = (new PersianCalendar()).GetMonth(firstRollCallToPrintStartDate).ToFarsiMonthByIntNumber(); + var selectedMonthPersian = + (new PersianCalendar()).GetMonth(firstRollCallToPrintStartDate).ToFarsiMonthByIntNumber(); var selectedYearPersian = (new PersianCalendar()).GetYear(firstRollCallToPrintStartDate); - var rollCallsList = _context.RollCalls.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.ShiftDate.Date >= firstRollCallToPrintStartDate.Date && - x.ShiftDate.Date <= lastRollCallToPrintStartDate.Date).ToList(); + var rollCallsList = _context.RollCalls.Where(x => + x.EmployeeId == employeeId && x.WorkshopId == workshopId && + x.ShiftDate.Date >= firstRollCallToPrintStartDate.Date && + x.ShiftDate.Date <= lastRollCallToPrintStartDate.Date).ToList(); var employeeName = _context.Employees.FirstOrDefault(x => x.id == employeeId).FullName; - var personnelCode = _context.PersonnelCodeSet.FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId); + var personnelCode = + _context.PersonnelCodeSet.FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId); var statuses = _context.RollCallEmployeesStatus.Include(x => x.RollCallEmployee) - .Where(x => x.RollCallEmployee.EmployeeId == employeeId && x.RollCallEmployee.WorkshopId == workshopId).ToList(); + .Where(x => x.RollCallEmployee.EmployeeId == employeeId && x.RollCallEmployee.WorkshopId == workshopId) + .ToList(); - var leavesList = _context.LeaveList.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.EndLeave.Date >= firstRollCallToPrintStartDate.Date && - x.StartLeave.Date <= lastRollCallToPrintStartDate.AddDays(2)).ToList(); + var leavesList = _context.LeaveList.Where(x => + x.EmployeeId == employeeId && x.WorkshopId == workshopId && + x.EndLeave.Date >= firstRollCallToPrintStartDate.Date && + x.StartLeave.Date <= lastRollCallToPrintStartDate.AddDays(2)).ToList(); //if (rollCallsList.Count < 1) // return new(); @@ -1506,33 +1559,36 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos int dateRange = (int)(lastRollCallToPrintStartDate - firstRollCallToPrintStartDate).TotalDays + 1; - var completeDaysList = Enumerable.Range(0, dateRange).Select(offset => firstRollCallToPrintStartDate.AddDays(offset).Date); + var completeDaysList = Enumerable.Range(0, dateRange) + .Select(offset => firstRollCallToPrintStartDate.AddDays(offset).Date); - var result = completeDaysList.Where(x => !rollCallsList.Any(y => y.ShiftDate.Date == x.Date && y.EndDate == null) && - statuses.Any(y => x >= y.StartDate.Date && x <= y.EndDate.Date)) - .Select(x => - { - var leave = leavesList.FirstOrDefault(y => y.EndLeave >= x.Date && y.StartLeave <= x.Date); - return new RollCallViewModel() - { - DateGr = x.Date, - DateFa = x.Date.ToFarsi(), - RollCallTimesList = rollCallsList.Where(y => x.Date == y.StartDate!.Value.Date).Select(y => - new RollCallTimeViewModel() - { - StartDate = y.StartDate.Value.ToString("HH:mm"), - EndDate = y.EndDate!.Value.ToString("HH:mm"), - StartDateGr = y.StartDate.Value, - EndDateGr = y.EndDate.Value, - EntryTimeDifferences = CalculateEntryTimeDifferences( y.EarlyEntryDuration, y.LateEntryDuration), - ExitTimeDifferences = CalculateExitTimeDifferences(y.EarlyExitDuration, y.LateExitDuration) - }), - TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date == y.ShiftDate.Date) - .Sum(y => (y.EndDate!.Value - y.StartDate.Value).Ticks)), - Reason = leave?.LeaveType ?? "", - HasLeave = (leave?.PaidLeaveType == "روزانه" || leave?.LeaveType == "استعلاجی") ? true : false - }; - }); + var result = completeDaysList.Where(x => + !rollCallsList.Any(y => y.ShiftDate.Date == x.Date && y.EndDate == null) && + statuses.Any(y => x >= y.StartDate.Date && x <= y.EndDate.Date)) + .Select(x => + { + var leave = leavesList.FirstOrDefault(y => y.EndLeave >= x.Date && y.StartLeave <= x.Date); + return new RollCallViewModel() + { + DateGr = x.Date, + DateFa = x.Date.ToFarsi(), + RollCallTimesList = rollCallsList.Where(y => x.Date == y.StartDate!.Value.Date).Select(y => + new RollCallTimeViewModel() + { + StartDate = y.StartDate.Value.ToString("HH:mm"), + EndDate = y.EndDate!.Value.ToString("HH:mm"), + StartDateGr = y.StartDate.Value, + EndDateGr = y.EndDate.Value, + EntryTimeDifferences = + CalculateEntryTimeDifferences(y.EarlyEntryDuration, y.LateEntryDuration), + ExitTimeDifferences = CalculateExitTimeDifferences(y.EarlyExitDuration, y.LateExitDuration) + }), + TotalWorkingHoursSpan = new TimeSpan(rollCallsList.Where(y => x.Date == y.ShiftDate.Date) + .Sum(y => (y.EndDate!.Value - y.StartDate.Value).Ticks)), + Reason = leave?.LeaveType ?? "", + HasLeave = (leave?.PaidLeaveType == "روزانه" || leave?.LeaveType == "استعلاجی") ? true : false + }; + }); result = result.Select(x => new RollCallViewModel() { EmployeeFullName = employeeName, @@ -1546,73 +1602,76 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos RollCallTimesList = x.RollCallTimesList, HasLeave = x.HasLeave, TotalWorkingHoursSpan = x.TotalWorkingHoursSpan, - TotalWorkingHours = $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{x.TotalWorkingHoursSpan.Minutes.ToString("00")}" + TotalWorkingHours = + $"{(int)x.TotalWorkingHoursSpan.TotalHours}:{x.TotalWorkingHoursSpan.Minutes.ToString("00")}" }).ToList(); var totalWorkingHours = new TimeSpan(result.Sum(x => x.TotalWorkingHoursSpan.Ticks)); - return new EmployeeRollCallsByMonthViewModel() + return new EmployeeRollCallsByMonthViewModel() { PersianMonthName = selectedMonthPersian, PersianYear = selectedYearPersian.ToString(), DateGr = firstRollCallToPrintStartDate.AddMonthsFa(0, out _).ToGeorgianDateTime(), RollCalls = result.OrderByDescending(x => x.DateGr), TotalWorkingHours = totalWorkingHours.ToFarsiHoursAndMinutes(), - + TotalWorkingHoursTimeSpan = $"{(int)totalWorkingHours.TotalHours}:{totalWorkingHours.Minutes:00}" - }; + }; } - public List GetWorkshopEmployeeRollCallsWithUndefinedForDate(long workshopId, long employeeId, DateTime date) + public List GetWorkshopEmployeeRollCallsWithUndefinedForDate(long workshopId, long employeeId, + DateTime date) { + var names = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId) + .Select(x => new + { + x.EmployeeId, + x.EmployeeFullName + }).ToList(); - var names = _context.RollCallEmployees.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId).Select(x => new - { - x.EmployeeId, - x.EmployeeFullName - }).ToList(); - - var rollcalls = _context.RollCalls.IgnoreQueryFilters() - .Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ShiftDate.Date == date.Date) - .Select(x => new RollCallViewModel() - { - Id = x.id, - StartDate = x.StartDate.Value, - EndDate = x.EndDate.Value, - DateFa = x.ShiftDate.Date.ToFarsi(), + var rollcalls = _context.RollCalls.IgnoreQueryFilters() + .Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ShiftDate.Date == date.Date) + .Select(x => new RollCallViewModel() + { + Id = x.id, + StartDate = x.StartDate.Value, + EndDate = x.EndDate.Value, + DateFa = x.ShiftDate.Date.ToFarsi(), DateGr = x.ShiftDate.Date, - StartDateFa = x.StartDate.Value.ToFarsi(), - EndDateFa = x.EndDate != null ? x.EndDate.Value.ToFarsi() : null - }).ToList(); - return rollcalls.Select(x => new RollCallViewModel() - { - Id = x.Id, - StartDate = x.StartDate, - EndDate = x.EndDate, - StartTimeString = x.StartDate!.Value.ToString("HH:mm"), - EndTimeString = x.EndDate?.ToString("HH:mm"), - DateFa = x.DateFa, + StartDateFa = x.StartDate.Value.ToFarsi(), + EndDateFa = x.EndDate != null ? x.EndDate.Value.ToFarsi() : null + }).ToList(); + return rollcalls.Select(x => new RollCallViewModel() + { + Id = x.Id, + StartDate = x.StartDate, + EndDate = x.EndDate, + StartTimeString = x.StartDate!.Value.ToString("HH:mm"), + EndTimeString = x.EndDate?.ToString("HH:mm"), + DateFa = x.DateFa, DateGr = x.DateGr, - StartDateFa = x.StartDateFa, - EndDateFa = x.EndDateFa, - EmployeeId = employeeId, - EmployeeFullName = names.FirstOrDefault(e => e.EmployeeId == employeeId)!.EmployeeFullName, - DayOfWeekFa = x.StartDate.Value.DayOfWeek.DayOfWeeKToPersian(), - StartDayOfWeekFa = x.StartDate.Value.DayOfWeek.DayOfWeeKToPersian(), - EndDayOfWeekFa = x.EndDate?.DayOfWeek.DayOfWeeKToPersian(), - TotalWorkingHoursSpan = x.EndDate == null ? new() : x.EndDate.Value - x.StartDate.Value - }).ToList(); - } + StartDateFa = x.StartDateFa, + EndDateFa = x.EndDateFa, + EmployeeId = employeeId, + EmployeeFullName = names.FirstOrDefault(e => e.EmployeeId == employeeId)!.EmployeeFullName, + DayOfWeekFa = x.StartDate.Value.DayOfWeek.DayOfWeeKToPersian(), + StartDayOfWeekFa = x.StartDate.Value.DayOfWeek.DayOfWeeKToPersian(), + EndDayOfWeekFa = x.EndDate?.DayOfWeek.DayOfWeeKToPersian(), + TotalWorkingHoursSpan = x.EndDate == null ? new() : x.EndDate.Value - x.StartDate.Value + }).ToList(); + } public void RemoveEmployeeRollCallsWithUndefinedInDate(long workshopId, long employeeId, DateTime date) - { + { + var rollCalls = _context.RollCalls.IgnoreQueryFilters().Where(x => + x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ShiftDate == date.Date); + if (!rollCalls.Any()) + return; + _context.RollCalls.RemoveRange(rollCalls); + } - var rollCalls = _context.RollCalls.IgnoreQueryFilters().Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && x.ShiftDate == date.Date); - if (!rollCalls.Any()) - return; - _context.RollCalls.RemoveRange(rollCalls); - } - - public List GetEmployeeRollCallsForCustomizeCheckoutTemp(IEnumerable customizeCheckoutIds, long workshopId) + public List GetEmployeeRollCallsForCustomizeCheckoutTemp( + IEnumerable customizeCheckoutIds, long workshopId) { //if (workshopId == 170) // return GetEmployeeRollCallsInDatesForKababMahdi(employeeIds, workshopId, start, end); @@ -1623,13 +1682,12 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos (customizeCheckout) => customizeCheckout.EmployeeId, (employee) => employee.id, ((customizeCheckout, employee) => new { customizeCheckout, employee })).Select(x => new - { - CustomizeCheckoutId = x.customizeCheckout.id, - CheckoutStart = x.customizeCheckout.ContractStart, - CheckoutEnd = x.customizeCheckout.ContractEnd, - EmployeeId = x.employee.id, - - }).ToList(); + { + CustomizeCheckoutId = x.customizeCheckout.id, + CheckoutStart = x.customizeCheckout.ContractStart, + CheckoutEnd = x.customizeCheckout.ContractEnd, + EmployeeId = x.employee.id, + }).ToList(); List result = new(); PersianCalendar pc = new(); @@ -1687,13 +1745,11 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos (worksInFriday && x.Date.DayOfWeek == DayOfWeek.Friday) || (worksInHolidays && isHoliday)), - - }; }); - var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date).Select( - x => + var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date) + .Select(x => { var orderedRollcalls = x.OrderBy(y => y.ShiftDate).ToList(); var firstRollCall = orderedRollcalls.FirstOrDefault(); @@ -1702,28 +1758,29 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //منطق کباب مهدی!!!! #region SecondTimeDiff + var hasSecondTimeDiff = false; if (settings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating) { - if (firstRollCall !=null && secondRollCall != null) + if (firstRollCall != null && secondRollCall != null) { - var firstShift = FindRotatingShift(firstRollCall.StartDate.Value, firstRollCall.EndDate.Value, settings.CustomizeRotatingShifts); - var secondShift = FindRotatingShift(secondRollCall.StartDate.Value, secondRollCall.EndDate.Value, settings.CustomizeRotatingShifts); + var firstShift = FindRotatingShift(firstRollCall.StartDate.Value, + firstRollCall.EndDate.Value, settings.CustomizeRotatingShifts); + var secondShift = FindRotatingShift(secondRollCall.StartDate.Value, + secondRollCall.EndDate.Value, settings.CustomizeRotatingShifts); if (firstShift.start == secondShift.start && firstShift.end == secondShift.end) { hasSecondTimeDiff = true; } } - } else { hasSecondTimeDiff = true; } - - #endregion + return new CheckoutDailyRollCallViewModel() { StartDate1 = firstRollCall?.StartDate?.ToString("HH:mm"), @@ -1742,20 +1799,24 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos IsSliced = x.Count() > 2, IsAbsent = false, - EnterDifferencesMinutes1 = firstRollCall != null && firstRollCall.LateEntryDuration > TimeSpan.Zero - ? CalculateEntryMinuteDifference(firstRollCall.EarlyEntryDuration, - firstRollCall.LateEntryDuration) - : "", - ExitDifferencesMinutes1 = firstRollCall != null && firstRollCall.EarlyExitDuration > TimeSpan.Zero - ? CalculateExitMinuteDifference(firstRollCall.EarlyExitDuration, - firstRollCall.LateExitDuration) - : "", + EnterDifferencesMinutes1 = + firstRollCall != null && firstRollCall.LateEntryDuration > TimeSpan.Zero + ? CalculateEntryMinuteDifference(firstRollCall.EarlyEntryDuration, + firstRollCall.LateEntryDuration) + : "", + ExitDifferencesMinutes1 = + firstRollCall != null && firstRollCall.EarlyExitDuration > TimeSpan.Zero + ? CalculateExitMinuteDifference(firstRollCall.EarlyExitDuration, + firstRollCall.LateExitDuration) + : "", - EnterDifferencesMinutes2 = secondRollCall != null && secondRollCall.LateEntryDuration > TimeSpan.Zero && hasSecondTimeDiff + EnterDifferencesMinutes2 = secondRollCall != null && + secondRollCall.LateEntryDuration > TimeSpan.Zero && hasSecondTimeDiff ? CalculateEntryMinuteDifference(secondRollCall.EarlyEntryDuration, secondRollCall.LateEntryDuration) : "", - ExitDifferencesMinutes2 = secondRollCall != null && secondRollCall.EarlyExitDuration > TimeSpan.Zero && hasSecondTimeDiff + ExitDifferencesMinutes2 = secondRollCall != null && + secondRollCall.EarlyExitDuration > TimeSpan.Zero && hasSecondTimeDiff ? CalculateExitMinuteDifference(secondRollCall.EarlyExitDuration, secondRollCall.LateExitDuration) : "" @@ -1777,8 +1838,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos EnterDifferencesMinutes2 = x.EnterDifferencesMinutes2, ExitDifferencesMinutes1 = x.ExitDifferencesMinutes1, ExitDifferencesMinutes2 = x.ExitDifferencesMinutes2 - - }); List checkoutDailyRollCalls = @@ -1788,7 +1847,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos { x.IsFriday = x.DateTimeGr.DayOfWeek == DayOfWeek.Friday; x.IsHoliday = holidays.Any(y => y.HolidaydateGr == x.DateTimeGr); - x.IsBirthDay = workshopId == 170 && pc.GetMonth(x.DateTimeGr) == pc.GetMonth(birthDay) && pc.GetDayOfMonth(x.DateTimeGr) == pc.GetDayOfMonth(birthDay); + x.IsBirthDay = workshopId == 170 && pc.GetMonth(x.DateTimeGr) == pc.GetMonth(birthDay) && + pc.GetDayOfMonth(x.DateTimeGr) == pc.GetDayOfMonth(birthDay); }); var resultItem = new PersonnelCheckoutDailyRollCallViewModel() @@ -1798,31 +1858,34 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos DailyRollCalls = checkoutDailyRollCalls }; result.Add(resultItem); - } return result; - } - public async Task> GetRollCallsInShiftDate(DateTime rollCallShiftDate, long employeeId, long workshopId) + public async Task> GetRollCallsInShiftDate(DateTime rollCallShiftDate, long employeeId, + long workshopId) { - return await _context.RollCalls.Where(x => x.ShiftDate.Date == rollCallShiftDate.Date && x.WorkshopId == workshopId && x.EmployeeId == employeeId).ToListAsync(); + return await _context.RollCalls.Where(x => + x.ShiftDate.Date == rollCallShiftDate.Date && x.WorkshopId == workshopId && x.EmployeeId == employeeId) + .ToListAsync(); } //حضور غیاب گروهی از پرسنل برای پرینت گروهی فیش حقوقی غیر رسمی نهایی - public List GetEmployeeRollCallsForMonthForKababMahdi(IEnumerable employeeIds, long workshopId, DateTime start, DateTime end) + public List GetEmployeeRollCallsForMonthForKababMahdi( + IEnumerable employeeIds, long workshopId, DateTime start, DateTime end) { var rollCalls = _context.RollCalls.Where(x => - employeeIds.Contains(x.EmployeeId) && workshopId == x.WorkshopId && x.StartDate != null && - x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined && - x.ShiftDate.Date >= start && x.ShiftDate.Date <= end).ToList(); + employeeIds.Contains(x.EmployeeId) && workshopId == x.WorkshopId && x.StartDate != null && + x.EndDate != null && x.RollCallModifyType != RollCallModifyType.Undefined && + x.ShiftDate.Date >= start && x.ShiftDate.Date <= end).ToList(); var leaves = _context.LeaveList.Where(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && x.EndLeave.Date >= start.Date && x.StartLeave.Date <= end.Date).ToList(); - var employees = _context.Employees.Where(x => employeeIds.Contains(x.id)).Select(x => new { Id = x.id, x.DateOfBirth }).ToList(); + var employees = _context.Employees.Where(x => employeeIds.Contains(x.id)) + .Select(x => new { Id = x.id, x.DateOfBirth }).ToList(); var year = Convert.ToInt32(start.ToFarsi().Substring(0, 4)); var month = Convert.ToInt32(start.ToFarsi().Substring(5, 2)); var firstDayOfCurrentMonth = new DateTime(year, month, 1, new PersianCalendar()); @@ -1866,7 +1929,8 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos y.EmployeeId == employeeId && y.EndLeave.Date >= x.Date && y.StartLeave.Date <= x.Date); var isHoliday = holidays.Any(y => y.HolidaydateGr == x.Date); var isFriday = x.Date.DayOfWeek == DayOfWeek.Friday; - var isBirthday = pc.GetMonth(x) == pc.GetMonth(birthDay) && pc.GetDayOfMonth(x) == pc.GetDayOfMonth(birthDay); + var isBirthday = pc.GetMonth(x) == pc.GetMonth(birthDay) && + pc.GetDayOfMonth(x) == pc.GetDayOfMonth(birthDay); var isNormalWorkingDay = isHoliday == false && isFriday == false; return new CheckoutDailyRollCallViewModel() { @@ -1882,89 +1946,97 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos IsBirthDay = isBirthday }; }); - var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date).Select(x => - { - var orderedRollcalls = x.OrderBy(y => y.StartDate!.Value).ToList(); - var firstRollCall = orderedRollcalls.FirstOrDefault(); - var secondRollCall = orderedRollcalls.Skip(1).FirstOrDefault(); - - //این برای این هست که ببینه اگر که این شخص گردشی بوده و دوبار وارد در دو شیفت مختلف وارد شده شیفت دوم تاثیر نخواهد گذاشت - //منطق کباب مهدی!!!! - - #region SecondTimeDiff - var hasSecondTimeDiff = false; - if (settings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating) + var presentDays = rollCalls.Where(x => x.EmployeeId == employeeId).GroupBy(x => x.ShiftDate.Date) + .Select(x => { - if (firstRollCall != null && secondRollCall != null) + var orderedRollcalls = x.OrderBy(y => y.StartDate!.Value).ToList(); + var firstRollCall = orderedRollcalls.FirstOrDefault(); + var secondRollCall = orderedRollcalls.Skip(1).FirstOrDefault(); + + //این برای این هست که ببینه اگر که این شخص گردشی بوده و دوبار وارد در دو شیفت مختلف وارد شده شیفت دوم تاثیر نخواهد گذاشت + //منطق کباب مهدی!!!! + + #region SecondTimeDiff + + var hasSecondTimeDiff = false; + if (settings.WorkshopShiftStatus == WorkshopShiftStatus.Rotating) { - var firstShift = FindRotatingShift(firstRollCall.StartDate.Value, firstRollCall.EndDate.Value, settings.CustomizeRotatingShifts); - var secondShift = FindRotatingShift(secondRollCall.StartDate.Value, secondRollCall.EndDate.Value, settings.CustomizeRotatingShifts); - if (firstShift.start == secondShift.start && firstShift.end == secondShift.end) + if (firstRollCall != null && secondRollCall != null) { - hasSecondTimeDiff = true; + var firstShift = FindRotatingShift(firstRollCall.StartDate.Value, + firstRollCall.EndDate.Value, settings.CustomizeRotatingShifts); + var secondShift = FindRotatingShift(secondRollCall.StartDate.Value, + secondRollCall.EndDate.Value, settings.CustomizeRotatingShifts); + if (firstShift.start == secondShift.start && firstShift.end == secondShift.end) + { + hasSecondTimeDiff = true; + } } } + else + { + hasSecondTimeDiff = true; + } - } - else - { - hasSecondTimeDiff = true; - } + #endregion + + return new CheckoutDailyRollCallViewModel() + { + StartDate1 = orderedRollcalls.FirstOrDefault()?.StartDate?.ToString("HH:mm"), + EndDate1 = orderedRollcalls.FirstOrDefault()?.EndDate?.ToString("HH:mm"), + + StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.StartDate?.ToString("HH:mm") ?? "", + EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndDate?.ToString("HH:mm") ?? "", + + TotalhourseSpan = + new TimeSpan(x.Where(y => y.EndDate != null) + .Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)), + DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), + RollCallDateFa = x.Key.Date.ToFarsi(), + DateTimeGr = x.Key.Date, + IsSliced = x.Count() > 2, + IsAbsent = false, + IsBirthDay = pc.GetMonth(x.Key) == pc.GetMonth(birthDay) && + pc.GetDayOfMonth(x.Key) == pc.GetDayOfMonth(birthDay), + + EnterDifferencesMinutes1 = firstRollCall != null && + firstRollCall.LateEntryDuration > TimeSpan.Zero && workshopId == 170 + ? CalculateEntryMinuteDifference(firstRollCall.EarlyEntryDuration, + firstRollCall.LateEntryDuration) + : "", + ExitDifferencesMinutes1 = "", + + EnterDifferencesMinutes2 = secondRollCall != null && + secondRollCall.LateEntryDuration > TimeSpan.Zero && + workshopId == 170 && hasSecondTimeDiff + ? CalculateEntryMinuteDifference(secondRollCall.EarlyEntryDuration, + secondRollCall.LateEntryDuration) + : "", + ExitDifferencesMinutes2 = "" + }; + }); + presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel + { + StartDate1 = x.StartDate1, + EndDate1 = x.EndDate1, + EndDate2 = x.EndDate2, + StartDate2 = x.StartDate2, + TotalWorkingHours = $"{(int)(x.TotalhourseSpan.TotalHours)}:{x.TotalhourseSpan.Minutes.ToString("00")}", + DayOfWeek = x.DayOfWeek, + RollCallDateFa = x.RollCallDateFa, + DateTimeGr = x.DateTimeGr, + IsSliced = x.IsSliced, + IsAbsent = false, + IsBirthDay = x.IsBirthDay, + EnterDifferencesMinutes1 = x.EnterDifferencesMinutes1, + ExitDifferencesMinutes1 = x.ExitDifferencesMinutes1, + EnterDifferencesMinutes2 = x.EnterDifferencesMinutes2, + ExitDifferencesMinutes2 = x.ExitDifferencesMinutes2, + }); - - #endregion - return new CheckoutDailyRollCallViewModel() - { - StartDate1 = orderedRollcalls.FirstOrDefault()?.StartDate?.ToString("HH:mm"), - EndDate1 = orderedRollcalls.FirstOrDefault()?.EndDate?.ToString("HH:mm"), - - StartDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.StartDate?.ToString("HH:mm") ?? "", - EndDate2 = orderedRollcalls.Skip(1).FirstOrDefault()?.EndDate?.ToString("HH:mm") ?? "", - - TotalhourseSpan = - new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)), - DayOfWeek = x.Key.DayOfWeek.DayOfWeeKToPersian(), - RollCallDateFa = x.Key.Date.ToFarsi(), - DateTimeGr = x.Key.Date, - IsSliced = x.Count() > 2, - IsAbsent = false, - IsBirthDay = pc.GetMonth(x.Key) == pc.GetMonth(birthDay) && pc.GetDayOfMonth(x.Key) == pc.GetDayOfMonth(birthDay), - - EnterDifferencesMinutes1 = firstRollCall != null && firstRollCall.LateEntryDuration > TimeSpan.Zero && workshopId == 170 - ? CalculateEntryMinuteDifference(firstRollCall.EarlyEntryDuration, - firstRollCall.LateEntryDuration) - : "", - ExitDifferencesMinutes1 = "", - - EnterDifferencesMinutes2 = secondRollCall != null && secondRollCall.LateEntryDuration > TimeSpan.Zero && workshopId == 170 && hasSecondTimeDiff - ? CalculateEntryMinuteDifference(secondRollCall.EarlyEntryDuration, - secondRollCall.LateEntryDuration) - : "", - ExitDifferencesMinutes2 = "" - }; - }); - presentDays = presentDays.Select(x => new CheckoutDailyRollCallViewModel - { - StartDate1 = x.StartDate1, - EndDate1 = x.EndDate1, - EndDate2 = x.EndDate2, - StartDate2 = x.StartDate2, - TotalWorkingHours = $"{(int)(x.TotalhourseSpan.TotalHours)}:{x.TotalhourseSpan.Minutes.ToString("00")}", - DayOfWeek = x.DayOfWeek, - RollCallDateFa = x.RollCallDateFa, - DateTimeGr = x.DateTimeGr, - IsSliced = x.IsSliced, - IsAbsent = false, - IsBirthDay = x.IsBirthDay, - EnterDifferencesMinutes1 = x.EnterDifferencesMinutes1, - ExitDifferencesMinutes1 = x.ExitDifferencesMinutes1, - EnterDifferencesMinutes2 = x.EnterDifferencesMinutes2, - ExitDifferencesMinutes2 = x.ExitDifferencesMinutes2, - }); - - - List checkoutDailyRollCalls = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); + List checkoutDailyRollCalls = + presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); checkoutDailyRollCalls.ForEach(x => { @@ -1982,18 +2054,15 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return result; - - - } + public static (DateTime start, DateTime end) FindRotatingShift(DateTime startRollCall, DateTime endRollCall, - ICollection rotatingShifts) + ICollection rotatingShifts) { DateTime startDate = startRollCall.Date; DateTime endDate = endRollCall.Date; - DateTime startEntryWithDate = startDate.Add(startRollCall.TimeOfDay); DateTime endEntryWithDate = endDate.Add(endRollCall.TimeOfDay); @@ -2039,7 +2108,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return startChosenShift; } - #endregion #region مقایسه پایان حضورغیاب با شیفت @@ -2057,7 +2125,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return endChosenShift; } - #endregion #region اشتراک حضور غیاب و شیفت @@ -2081,11 +2148,103 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos #endregion } - public async Task> GetRollCallsUntilNowWithWorkshopIdEmployeeIds(long workshopId, List employeeIds, DateTime fromDate) + public async Task> GetRollCallsUntilNowWithWorkshopIdEmployeeIds(long workshopId, + List employeeIds, DateTime fromDate) { return await _context.RollCalls.Where(x => x.ShiftDate >= fromDate && x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && x.EndDate != null).ToListAsync(); } -} + public async Task> GetCaseHistoryTitles(long workshopId, + RollCallCaseHistorySearchModel searchModel) + { + var yesterday = DateTime.Now.AddDays(-1).Date; + + var groupByMonth = false; + var rollCallStatusQuery = _context.RollCallEmployeesStatus + .Where(x => x.RollCallEmployee.WorkshopId == workshopId); + + if (searchModel.EmployeeId is > 0) + { + rollCallStatusQuery = + rollCallStatusQuery.Where(x => x.RollCallEmployee.EmployeeId == searchModel.EmployeeId); + groupByMonth = true; + } + + + var startDateNullable = (await rollCallStatusQuery + .OrderBy(x => x.StartDate).FirstOrDefaultAsync())?.StartDate; + var endDateNullable = (await rollCallStatusQuery + .OrderByDescending(x => x.EndDate).FirstOrDefaultAsync())?.EndDate; + + if (!startDateNullable.HasValue || !endDateNullable.HasValue) + { + return new PagedResult(); + } + + var startDate = startDateNullable.Value.Date; + var endDate = endDateNullable.Value.Date; + if (endDate.Date > yesterday) + { + endDate = yesterday; + } + + var dateRange = (int)(endDate - startDate).TotalDays + 1; + + var dates = Enumerable.Range(0, dateRange) + .Select(offset => startDate.AddDays(offset)).OrderByDescending(x => x).ToList(); + + if (!string.IsNullOrWhiteSpace(searchModel.OneDayDate)) + { + var date = searchModel.OneDayDate.ToGeorgianDateTime(); + + dates = dates + .Where(x => x.Date == date.Date).ToList(); + } + else if (!string.IsNullOrWhiteSpace(searchModel.StartDate) + && !string.IsNullOrWhiteSpace(searchModel.EndDate)) + { + var start = searchModel.StartDate.ToGeorgianDateTime(); + var end = searchModel.EndDate.ToGeorgianDateTime(); + + dates = dates + .Where(x => x <= end && x >= start).ToList(); + } + + List rollCallCaseHistoryTitles; + if (groupByMonth) + { + var persianDates = dates + .Select(x => new PersianTools.Core.PersianDateTime(x)).ToList(); + rollCallCaseHistoryTitles = persianDates.GroupBy(x => (x.Year, x.Month)) + .Select(x => new RollCallCaseHistoryTitleDto() + { + Id = $"{x.Key.Year}_{x.Key.Month}", + Title = $"{x.Key.Year} {x.Key.Month.ToFarsiMonthByIntNumber()}" + }).ToList(); + } + else + { + rollCallCaseHistoryTitles = dates + .Select(x => new RollCallCaseHistoryTitleDto() + { + Id = x.ToFarsi(), + Title = $"{x.ToFarsi()} {x.DayOfWeek.DayOfWeeKToPersian()}" + }).ToList(); + } + + + var res = new PagedResult() + { + List = rollCallCaseHistoryTitles, + TotalCount = rollCallCaseHistoryTitles.Count + }; + return res; + } + + public Task> GetCaseHistoryDetails(long workshopId, string titleId, RollCallCaseHistorySearchModel searchModel) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs b/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs new file mode 100644 index 00000000..b6cbeccc --- /dev/null +++ b/ServiceHost/Areas/Client/Controllers/RollCall/CaseHistoryController.cs @@ -0,0 +1,31 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.RollCall; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Client.Controllers.RollCall; + +public class CaseHistoryController:ClientBaseController +{ + private readonly IRollCallApplication _rollCallApplication; + private long _workshopId; + + public CaseHistoryController(IRollCallApplication rollCallApplication, + IAuthHelper authHelper) + { + _rollCallApplication = rollCallApplication; + _workshopId = authHelper.GetWorkshopId(); + } + + [HttpGet] + public async Task>> GetTitles(RollCallCaseHistorySearchModel searchModel) + { + return await _rollCallApplication.GetCaseHistoryTitles(_workshopId, searchModel); + } + + [HttpGet("{titleId}")] + public async Task GetDetails(string titleId, RollCallCaseHistorySearchModel searchModel) + { + return await _rollCallApplication.GetCaseHistoryDetails(_workshopId, titleId, searchModel); + } +} \ No newline at end of file diff --git a/ServiceHost/Properties/launchSettings.json b/ServiceHost/Properties/launchSettings.json index 788962e4..d7381591 100644 --- a/ServiceHost/Properties/launchSettings.json +++ b/ServiceHost/Properties/launchSettings.json @@ -19,7 +19,7 @@ "sqlDebugging": true, "dotnetRunMessages": "true", "nativeDebugging": true, - "applicationUrl": "https://localhost:5004;http://localhost:5003;", + "applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.0.117:5006", "jsWebView2Debugging": false, "hotReloadEnabled": true },