From e0793bc300e27da52812ac1a463f6cf45763f651 Mon Sep 17 00:00:00 2001 From: SamSys Date: Mon, 12 May 2025 19:36:58 +0330 Subject: [PATCH] convert completed --- .../IRollCallMandatoryRepository.cs | 2 +- .../Repository/RollCallMandatoryRepository.cs | 82 +++++++++++++++---- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs index a1ec3262..9cac44c2 100644 --- a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs +++ b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs @@ -18,7 +18,7 @@ public interface IRollCallMandatoryRepository : IRepository List RotatingShiftCheck(List rollCallList); - List ConvertStaticHourseToRollCall(CreateWorkingHoursTemp command, bool workshopHolidyWorking); + List ConvertStaticHoursToRollCall(CreateWorkingHoursTemp command, bool workshopHolidyWorking); CustomizeCheckoutMandatoryViewModel CustomizeCheckoutMandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd); List LateToWorkEarlyExit(List groupedRollCall, diff --git a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs index 818d281e..1ec3588c 100644 --- a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs @@ -114,7 +114,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll command.EmployeeId = employeeId; command.ContractStartGr = contractStart; command.ContractEndGr = contractEnd; - rollCallResult = ConvertStaticHourseToRollCall(command, holidayWorking); + rollCallResult = ConvertStaticHoursToRollCall(command, holidayWorking); groupedRollCall = rollCallResult.GroupBy(x => x.ShiftDate.Date).Select(x => new GroupedRollCalls() { CreationDate = x.Key, @@ -157,9 +157,42 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll // CreationDate = x.CreationDate, // AfterSubtractRestSpan = AfterSubtract(command, x.SumOneDaySpan, x.CreationDate), //}).ToList(); + + + + TimeSpan sumSpans = new TimeSpan(groupedRollCall.Sum(x => x.SumOneDaySpan.Ticks)); TimeSpan sumSpansWhitOutleaves = new TimeSpan(groupedRollCall.Sum(x => x.SumOneDaySpan.Ticks)); + + //بدست آوردن مرخصی ساعتی + LeaveSearchModel hoursleaveSearch = new LeaveSearchModel() + { + EmployeeId = employeeId, + WorkshopId = workshopId, + LeaveType = "استحقاقی", + PaidLeaveType = "ساعتی", + StartLeaveGr = contractStart, + EndLeaveGr = contractEnd, + IsAccepted = true, + }; + var hoursesleave = _leaveRepository.search(hoursleaveSearch); + var hoursesleaveTimeSpansList = hoursesleave.Count > 0 + ? hoursesleave.Select(x => TimeSpan.Parse(x.LeaveHourses)).ToList() + : new List(); + + // مجموع مرخصی ساعتی + var hoursesleaveTimeSpans = new TimeSpan(hoursesleaveTimeSpansList.Sum(x => x.Ticks)); + //کسر مرخصی ساعتی از فیش استاتیک + if (isStaticCheckout && command.ShiftWork != "4") + { + // کم کردن از مجموع ساعت کار پرسنل + sumSpans = sumSpans.Subtract(hoursesleaveTimeSpans); + + } + + + //****افزودن مرخصی پرسنل به مجموع ساعات کار*** #region AddEmployeeLeavs @@ -191,10 +224,6 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll { if (leaveSearchResult.Any(x => x.HasShiftDuration)) { - - - - var sumSpansDouble = (sumSpans.TotalMinutes) / 60; if (sumSpansDouble < mandatoryHours) { @@ -209,6 +238,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll } TimeSpan totalLeave = new TimeSpan(leaveSearchResult.Sum(x => x.ShiftDuration.Ticks)); + totalLeave = totalLeave.Add(hoursesleaveTimeSpans); var totalLeaveDouble = (totalLeave.TotalMinutes) / 60; if (totalLeaveDouble > starndardHoursesPerTotalDays) { @@ -255,12 +285,14 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll if (workingPerDayAve <= new TimeSpan(7, 20, 0)) { sumLeave = leavingDayCout * workingPerDayAve; + sumLeave = sumLeave.Add(hoursesleaveTimeSpans); } else { sumLeave = leavingDayCout * new TimeSpan(7, 20, 0); } + if (sumLeave > starndardHoursesPerTotalDaysSapn) { sumSpans = sumSpans.Add(starndardHoursesPerTotalDaysSapn); @@ -273,7 +305,18 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll } - + //اگر مرخصی روزانه نداشت و فقط مرخصی ساعتی داشت + if (leaveSearchResult.Count == 0 && hoursesleave.Count > 0) + { + if (hoursesleaveTimeSpans > starndardHoursesPerTotalDaysSapn) + { + sumSpans = sumSpans.Add(starndardHoursesPerTotalDaysSapn); + } + else + { + sumSpans = sumSpans.Add(hoursesleaveTimeSpans); + } + } Console.WriteLine(sumSpans); #endregion //***********************************// @@ -295,10 +338,10 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll TimeSpan Mandatory = sumSpansWhitOutleaves.Subtract(mandatoryHoursTimeSpan); double mandatoryWorkWithOutleaves = (sumSpansWhitOutleaves.TotalMinutes) / 60; - double owerTimeWork = 0; + double overTimeWork = 0; if (mandatoryWorkWithOutleaves > mandatoryHours) { - owerTimeWork = mandatoryWorkWithOutleaves - mandatoryHours; + overTimeWork = mandatoryWorkWithOutleaves - mandatoryHours; } @@ -471,13 +514,13 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll SumWorkeTime = $"{44}"; //اضافه کار - if (owerTimeWork > 0) + if (overTimeWork > 0) { //int mandatoryH = (int)Mandatory.TotalHours; //int mandatoryM = (int)(Mandatory.TotalMinutes % 60); - int mandatoryH = (int)owerTimeWork; - int mandatoryM = (int)Math.Round((owerTimeWork - mandatoryH) * 60); + int mandatoryH = (int)overTimeWork; + int mandatoryM = (int)Math.Round((overTimeWork - mandatoryH) * 60); overMandatoryHours = mandatoryH.ToString(); overMandatoryMinuts = mandatoryM.ToString(); } @@ -1237,7 +1280,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll } - public List ConvertStaticHourseToRollCall(CreateWorkingHoursTemp command, bool workshopHolidyWorking) + public List ConvertStaticHoursToRollCall(CreateWorkingHoursTemp command, bool workshopHolidyWorking) { var rollCallList = new List(); #region Entities @@ -1451,7 +1494,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll //[12-24 : 5] [24-24 : 6] [12-36 : 7] [24-48 : 8] if (command.ShiftWork is "5" or "6" or "7" or "8") { - int addHourse = command.ShiftWork switch + int addHours = command.ShiftWork switch { "5" => 36, "6" => 48, @@ -1465,7 +1508,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll var startDateAndTime = new PersianDateTime(syear, smonth, sday, start.Hour, start.Minute); var startContract = new PersianDateTime(syear, smonth, sday, start.Hour, start.Minute); var endContract = new PersianDateTime(eyear, emonth, eday, 23, 59); - for (var da = startDateAndTime; da <= endContract; da = da.AddHours(addHourse)) + for (var da = startDateAndTime; da <= endContract; da = da.AddHours(addHours)) { @@ -1495,16 +1538,19 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll var endCal = end - start; - start = startComplex.AddHours(addHourse); + start = startComplex.AddHours(addHours); end = start.Add(endCal); } - int countLeveSearch = leaveSearchResult.Count(x => x.PaidLeaveType == "روزانه"); - if (countLeveSearch > 0) + var countLeves = leaveSearchResult.Where(x => x.PaidLeaveType == "روزانه").ToList(); + if (countLeves.Count > 0) { + int totalDays = countLeves.Sum(x => int.Parse(x.LeaveHourses)); + + int countRollCall = rollCallList.Count(); - int takRollCall = countLeveSearch < countRollCall ? (countRollCall - countLeveSearch) : 0; + int takRollCall = totalDays < countRollCall ? (countRollCall - totalDays) : 0; rollCallList = rollCallList.Take(takRollCall).ToList(); }