From a4aff718dc576f3a0500bfc85cbb02a99d246f2f Mon Sep 17 00:00:00 2001 From: Mahan Ch Date: Mon, 24 Mar 2025 18:59:30 +0330 Subject: [PATCH] fix bug --- .../Repository/CustomizeCheckoutRepository.cs | 4 +- .../Repository/RollCallRepository.cs | 87 +++++++++++-------- 2 files changed, 55 insertions(+), 36 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/CustomizeCheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeCheckoutRepository.cs index c98c56a3..ad25bc24 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeCheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeCheckoutRepository.cs @@ -168,9 +168,9 @@ namespace CompanyManagment.EFCore.Repository SalaryAidDateTimeGe = s.SalaryAidDateTime }).ToList(), - LateToWorkValue = x.LateToWorkValue == TimeSpan.Zero ? "-" : $"{(int)x.LateToWorkValue.TotalHours}:{x.LateToWorkValue.Minutes:D2}" + LateToWorkValue = x.LateToWorkValue == TimeSpan.Zero ? "-" : $"{Convert.ToInt32(x.LateToWorkValue.TotalHours)}:{Convert.ToInt32(x.LateToWorkValue.TotalMinutes % 60):00}" - }).ToList(); + }).ToList(); List workshopsList = workshopsQuery.Select(x => new WorkshopViewModel { WorkshopFullName = x.WorkshopFullName, diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index 1f59e614..b3a8ecef 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -1791,43 +1791,62 @@ 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(); - return new CheckoutDailyRollCallViewModel() - { - StartDate1 = orderedRollcalls.FirstOrDefault()?.StartDate?.ToString("HH:mm"), - EndDate1 = orderedRollcalls.FirstOrDefault()?.EndDate?.ToString("HH:mm"), + 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(); + 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") ?? "", + 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) - }; - }); - 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 - }); + 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), - List checkoutDailyRollCalls = presentDays.Concat(absentRecords).OrderBy(x => x.DateTimeGr).ToList(); + EnterDifferencesMinutes1 = firstRollCall != null && firstRollCall.LateEntryDuration > TimeSpan.Zero && workshopId == 170 + ? CalculateEntryMinuteDifference(firstRollCall.EarlyEntryDuration, + firstRollCall.LateEntryDuration) + : "", + ExitDifferencesMinutes1 = "", + + EnterDifferencesMinutes2 = secondRollCall != null && secondRollCall.LateEntryDuration > TimeSpan.Zero && workshopId == 170 + ? 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(); checkoutDailyRollCalls.ForEach(x => {