diff --git a/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs b/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs index 01f923c4..3084f5c4 100644 --- a/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs +++ b/Company.Domain/RollCallAgg/DomainService/IRollCallDomainService.cs @@ -32,6 +32,9 @@ public interface IRollCallDomainService (DateTime start, DateTime end) FindRotatingShift(DateTime startRollCall, DateTime endRollCall, ICollection rotatingShifts); (DateTime start, DateTime end) FindRotatingShift(List<(DateTime StartDate, DateTime EndDate)> rollcalls, ICollection rotatingShifts); + + BreakTime GetBreakTime(long employeeId, long workshopId); + } public class RollCallDomainService : IRollCallDomainService @@ -672,6 +675,17 @@ public class RollCallDomainService : IRollCallDomainService return (overlapChosenShift.Shift.Start, end); } + public BreakTime GetBreakTime(long employeeId, long workshopId) + { + var employeeSettings = _customizeWorkshopEmployeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(workshopId, + employeeId); + if (employeeSettings == null) + { + return new BreakTime(false, TimeOnly.MinValue); + } + + return employeeSettings.BreakTime; + } private DateTime CalculateRegularShiftDate(DateTime startDate, TimeOnly offset) { DateTime nextOffSetDateTime; diff --git a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs index 988528b6..9cac44c2 100644 --- a/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs +++ b/Company.Domain/RollCallAgg/IRollCallMandatoryRepository.cs @@ -13,12 +13,12 @@ namespace Company.Domain.RollCallAgg; public interface IRollCallMandatoryRepository : IRepository { - ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking); + ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout); TimeSpan AfterSubtract(CreateWorkingHoursTemp command, TimeSpan sumOneDaySpan, DateTime creationDate); List RotatingShiftCheck(List rollCallList); - + List ConvertStaticHoursToRollCall(CreateWorkingHoursTemp command, bool workshopHolidyWorking); CustomizeCheckoutMandatoryViewModel CustomizeCheckoutMandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd); List LateToWorkEarlyExit(List groupedRollCall, diff --git a/Company.Domain/RollCallAgg/RollCall.cs b/Company.Domain/RollCallAgg/RollCall.cs index 35204c1c..8436eeae 100644 --- a/Company.Domain/RollCallAgg/RollCall.cs +++ b/Company.Domain/RollCallAgg/RollCall.cs @@ -4,6 +4,8 @@ using System; using Company.Domain.RollCallAgg.DomainService; using System.Linq; using _0_Framework.Exceptions; +using Company.Domain.EmployeeAgg; +using Company.Domain.WorkshopAgg; namespace Company.Domain.RollCallAgg { @@ -34,10 +36,10 @@ namespace Company.Domain.RollCallAgg { throw new NotFoundException("اطلاعات گروهبندی شخص نامعتبر است"); } - + SetBreakTime(service, employeeId, workshopId); //if (endDate.HasValue) //{ - // Edit(StartDate.Value,endDate.Value,service); + // Edit(StartDate.Value,endDate.Value,service); //} } @@ -198,30 +200,7 @@ namespace Company.Domain.RollCallAgg - /// - /// Truncates the TimeSpan to only include days, hours, and minutes. - /// Removes seconds, milliseconds, and smaller units. - /// - /// The original TimeSpan value. - /// A truncated TimeSpan with only days, hours, and minutes. - private TimeSpan TruncateTimeSpan(TimeSpan time) - { - return new TimeSpan(time.Days, time.Hours, time.Minutes, 0); - } - - /// - /// Truncates the DateTime to only include Years,Month,days,Hours and Minutes. - /// Removes seconds, milliseconds, and smaller units. - /// - /// The original DateTime value. - /// A truncated DateTime with only days, hours, and minutes. - private DateTime TruncateDateTime(DateTime dateTime) - { - return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, - dateTime.Minute, 0); - } - - + public void SetEndDateTime(DateTime endDate, IRollCallDomainService service) { @@ -238,7 +217,7 @@ namespace Company.Domain.RollCallAgg ////محاسبه اختلاف زمانی(تاخیر و تعجیل)ء service.CalculateTimeDifferences(this); - + SetBreakTime(service, EmployeeId, WorkshopId); } @@ -259,6 +238,8 @@ namespace Company.Domain.RollCallAgg //محاسبه اختلاف زمانی(تاخیر و تعجیل)ء service.CalculateTimeDifferences(this); + SetBreakTime(service, EmployeeId, WorkshopId); + } @@ -331,6 +312,40 @@ namespace Company.Domain.RollCallAgg } } + + + public void SetBreakTime(IRollCallDomainService rollCallDomainService, long employeeId, long workshopId) + { + var breakTime = rollCallDomainService.GetBreakTime(employeeId, workshopId); + + if (breakTime.BreakTimeType == BreakTimeType.WithTime) + BreakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan(); + + + } + + /// + /// Truncates the TimeSpan to only include days, hours, and minutes. + /// Removes seconds, milliseconds, and smaller units. + /// + /// The original TimeSpan value. + /// A truncated TimeSpan with only days, hours, and minutes. + private TimeSpan TruncateTimeSpan(TimeSpan time) + { + return new TimeSpan(time.Days, time.Hours, time.Minutes, 0); + } + + /// + /// Truncates the DateTime to only include Years,Month,days,Hours and Minutes. + /// Removes seconds, milliseconds, and smaller units. + /// + /// The original DateTime value. + /// A truncated DateTime with only days, hours, and minutes. + private DateTime TruncateDateTime(DateTime dateTime) + { + return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, + dateTime.Minute, 0); + } //private static (DateTime start, DateTime end) FindRotatingShift(DateTime startRollCall, DateTime endRollCall, ICollection rotatingShifts) //{ diff --git a/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs b/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs index a7f43bf8..68e3dcf7 100644 --- a/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs +++ b/CompanyManagment.App.Contracts/RollCall/IRollCallMandatoryApplication.cs @@ -8,7 +8,7 @@ namespace CompanyManagment.App.Contracts.RollCall; public interface IRollCallMandatoryApplication { bool HasRollCallRecord(long employeeId, long workshopId, DateTime contractStart); - ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking); + ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout); /// /// گزارش نوبت کاری حضور غیاب diff --git a/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs b/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs index d1fa157d..4bfd8968 100644 --- a/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs +++ b/CompanyManagment.App.Contracts/RollCall/RollCallViewModel.cs @@ -61,4 +61,8 @@ public class RollCallViewModel /// مقدار تایم شیفت (مدت زمان شیفت کاری) /// public TimeSpan ShiftDurationTimeSpan { get; set; } + /// + /// مدت زمان استراحت + /// + public TimeSpan BreakTimeSpan { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index c470f86f..03879c1b 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -793,17 +793,17 @@ public class RollCallApplication : IRollCallApplication { List fromDates = commands.Select(x => x.FromDate.ToGeorgianDateTime()).ToList(); var employeeIds = commands.Select(x => x.EmployeeId).ToList(); - if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd))) { return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش رسمی است"); } - if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd))) { return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی نهایی است"); } - if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractEnd))) { return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی موقت است"); } diff --git a/CompanyManagment.Application/RollCallMandatoryApplication.cs b/CompanyManagment.Application/RollCallMandatoryApplication.cs index 080a7895..45598951 100644 --- a/CompanyManagment.Application/RollCallMandatoryApplication.cs +++ b/CompanyManagment.Application/RollCallMandatoryApplication.cs @@ -21,9 +21,9 @@ public class RollCallMandatoryApplication : IRollCallMandatoryApplication return _rollCallMandatoryRepository.Exists(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate.Value.Date >= contractStart.Date); } - public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking) + public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, DateTime contractEnd, CreateWorkingHoursTemp command, bool holidayWorking, bool isStaticCheckout) { - return _rollCallMandatoryRepository.MandatoryCompute(employeeId,workshopId, contractStart, contractEnd, command, holidayWorking); + return _rollCallMandatoryRepository.MandatoryCompute(employeeId,workshopId, contractStart, contractEnd, command, holidayWorking, isStaticCheckout); } public async Task RotatingShiftReport(long workshopId, long employeeId, DateTime contractStart, DateTime contractEnd, diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs index fff9d80d..33bcd3df 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs @@ -191,6 +191,11 @@ public class CustomizeWorkshopEmployeeSettingsRepository(CompanyContext companyC return true; } + if (command.BreakTime.BreakTimeValue != employeeSettings.BreakTime.BreakTimeValue || command.BreakTime.HasBreakTimeValue != employeeSettings.BreakTime.HasBreakTimeValue) + { + return true; + } + switch (employeeSettings.WorkshopShiftStatus) { case WorkshopShiftStatus.Irregular: diff --git a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs index 1fe18123..9276e8db 100644 --- a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs @@ -32,6 +32,9 @@ using Company.Domain.RewardAgg; using CompanyManagment.App.Contracts.Reward.Enums; using static System.Runtime.InteropServices.JavaScript.JSType; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; +using Company.Domain.HolidayItemAgg; +using PersianTools.Core; + namespace CompanyManagment.EFCore.Repository; @@ -42,21 +45,23 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll private readonly IYearlySalaryRepository _yearlySalaryRepository; private readonly ILeftWorkRepository _leftWorkRepository; private readonly ILeaveRepository _leaveRepository; + private readonly IHolidayItemRepository _holidayItemRepository; public RollCallMandatoryRepository(CompanyContext context, IYearlySalaryRepository yearlySalaryRepository, - ILeftWorkRepository leftWorkRepository, ILeaveRepository leaveRepository) : base(context) + ILeftWorkRepository leftWorkRepository, ILeaveRepository leaveRepository, IHolidayItemRepository holidayItemRepository) : base(context) { _context = context; _yearlySalaryRepository = yearlySalaryRepository; _leftWorkRepository = leftWorkRepository; _leaveRepository = leaveRepository; + _holidayItemRepository = holidayItemRepository; } #region OfficialChckout public ComputingViewModel MandatoryCompute(long employeeId, long workshopId, DateTime contractStart, -DateTime contractEnd, -CreateWorkingHoursTemp command, bool holidayWorking) + DateTime contractEnd, + CreateWorkingHoursTemp command, bool holidayWorking,bool isStaticCheckout) { #region Entities @@ -101,25 +106,51 @@ CreateWorkingHoursTemp command, bool holidayWorking) #endregion - List rollCallResult = _context.RollCalls.Where(x => - x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate.Value.Date >= contractStart.Date && - x.StartDate.Value.Date <= contractEnd.Date && x.EndDate != null).Select(x => new RollCallViewModel() + List rollCallResult; + List groupedRollCall; + if (isStaticCheckout) + { + command.WorkshopId = workshopId; + command.EmployeeId = employeeId; + command.ContractStartGr = contractStart; + command.ContractEndGr = contractEnd; + rollCallResult = ConvertStaticHoursToRollCall(command, holidayWorking); + groupedRollCall = rollCallResult.GroupBy(x => x.ShiftDate.Date).Select(x => new GroupedRollCalls() + { + CreationDate = x.Key, + ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), + HasFriday = x.Any(s => s.StartDate != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)), + + SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) + + }).OrderBy(x => x.CreationDate).ToList(); + } + else + { + rollCallResult = _context.RollCalls.Where(x => + x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate.Value.Date >= contractStart.Date && + x.StartDate.Value.Date <= contractEnd.Date && x.EndDate != null).Select(x => new RollCallViewModel() { StartDate = x.StartDate, EndDate = x.EndDate, ShiftSpan = (x.EndDate.Value - x.StartDate.Value), CreationDate = x.ShiftDate, - }).ToList(); - List groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x => new GroupedRollCalls() - { - CreationDate = x.Key, - ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), - HasFriday = x.Any(s => s.StartDate != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)), + BreakTimeSpan = x.BreakTimeSpan + }).ToList(); - SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(breakTime, - new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), + groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x => new GroupedRollCalls() + { + CreationDate = x.Key, + ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), + HasFriday = x.Any(s => s.StartDate != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)), + SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan, + new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), - }).OrderBy(x => x.CreationDate).ToList(); + BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), + + }).OrderBy(x => x.CreationDate).ToList(); + } + numberOfFridays = groupedRollCall.Count(x => x.HasFriday); @@ -129,9 +160,42 @@ CreateWorkingHoursTemp command, bool holidayWorking) // 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 @@ -163,10 +227,6 @@ CreateWorkingHoursTemp command, bool holidayWorking) { if (leaveSearchResult.Any(x => x.HasShiftDuration)) { - - - - var sumSpansDouble = (sumSpans.TotalMinutes) / 60; if (sumSpansDouble < mandatoryHours) { @@ -181,10 +241,11 @@ CreateWorkingHoursTemp command, bool holidayWorking) } TimeSpan totalLeave = new TimeSpan(leaveSearchResult.Sum(x => x.ShiftDuration.Ticks)); + totalLeave = totalLeave.Add(hoursesleaveTimeSpans); var totalLeaveDouble = (totalLeave.TotalMinutes) / 60; - if(totalLeaveDouble > starndardHoursesPerTotalDays) + if (totalLeaveDouble > starndardHoursesPerTotalDays) { - + sumSpans = sumSpans.Add(starndardHoursesPerTotalDaysSapn); } else @@ -227,12 +288,14 @@ CreateWorkingHoursTemp command, bool holidayWorking) 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); @@ -243,9 +306,20 @@ CreateWorkingHoursTemp command, bool holidayWorking) } } - - } + } + //اگر مرخصی روزانه نداشت و فقط مرخصی ساعتی داشت + if (leaveSearchResult.Count == 0 && hoursesleave.Count > 0) + { + if (hoursesleaveTimeSpans > starndardHoursesPerTotalDaysSapn) + { + sumSpans = sumSpans.Add(starndardHoursesPerTotalDaysSapn); + } + else + { + sumSpans = sumSpans.Add(hoursesleaveTimeSpans); + } + } Console.WriteLine(sumSpans); #endregion //***********************************// @@ -259,18 +333,18 @@ CreateWorkingHoursTemp command, bool holidayWorking) //********** محاسبه مدت اضافه کاری ***********// #region ComputeMandatoryAtThisTime - - + + //***********************************// var dailyFix = TimeSpan.Parse("07:20"); TimeSpan mandatoryHoursTimeSpan = new TimeSpan(7, 20, 0).Multiply(mandatorDays); 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; } @@ -443,13 +517,13 @@ CreateWorkingHoursTemp command, bool holidayWorking) 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(); } @@ -646,24 +720,24 @@ CreateWorkingHoursTemp command, bool holidayWorking) return res; } - public async Task RotatingShiftReport(long workshopId,long employeeId, DateTime contractStart, DateTime contractEnd, string shiftwork) + public async Task RotatingShiftReport(long workshopId, long employeeId, DateTime contractStart, DateTime contractEnd, string shiftwork) { - List rollCallResult =await _context.RollCalls.Where(x => + List rollCallResult = await _context.RollCalls.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartDate.Value.Date >= contractStart.Date && x.StartDate.Value.Date <= contractEnd.Date && x.EndDate != null).Select(x => new RollCallViewModel() - { - StartDate = x.StartDate, - EndDate = x.EndDate, - ShiftSpan = (x.EndDate.Value - x.StartDate.Value), - CreationDate = x.ShiftDate, - }).ToListAsync(); + { + StartDate = x.StartDate, + EndDate = x.EndDate, + ShiftSpan = (x.EndDate.Value - x.StartDate.Value), + CreationDate = x.ShiftDate, + }).ToListAsync(); List groupedRollCall = rollCallResult.GroupBy(x => x.CreationDate.Date).Select(x => new GroupedRollCalls() { CreationDate = x.Key, ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), HasFriday = x.Any(s => s.StartDate != null && s.EndDate != null && (s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value!.DayOfWeek == DayOfWeek.Friday)), - + }).OrderBy(x => x.CreationDate).ToList(); @@ -676,8 +750,8 @@ CreateWorkingHoursTemp command, bool holidayWorking) int moriningCount = 0; int eveningCount = 0; int nightCount = 0; - - int moriningWinRate = rotatingResultList.Where(x=>x.IsMorningShift).Sum(x => x.WinRate); + + int moriningWinRate = rotatingResultList.Where(x => x.IsMorningShift).Sum(x => x.WinRate); int eveningWinRate = rotatingResultList.Where(x => x.IsEveningShift).Sum(x => x.WinRate); int nightWinRate = rotatingResultList.Where(x => x.IsNightShift).Sum(x => x.WinRate); @@ -702,7 +776,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) eveningCount = rotatingResultList.Count(x => x.IsEveningShift && x.WinRate > 55); nightCount = rotatingResultList.Count(x => x.IsNightShift); } - + @@ -722,7 +796,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) //} //else// اگر منظم و شیفتی بود //{ - + //} var totalDays = (int)(contractEnd - contractStart).TotalDays + 1; @@ -754,7 +828,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) var rotatingFaResult = ""; if (RotatingfaName.Count > 1)// اگر تعداد شیفت های محاسبه شده بیش از یک بود { - + for (var rotateNumber = 0; rotateNumber < RotatingfaName.Count; rotateNumber++) { if (rotateNumber == 0) @@ -769,7 +843,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) { rotatingFaResult = "نوبت کاری ندارد"; - + } @@ -782,18 +856,24 @@ CreateWorkingHoursTemp command, bool holidayWorking) #endregion } - public static TimeSpan CalculateBreakTime(BreakTime breakTime, TimeSpan sumOneDaySpan) + //public static TimeSpan CalculateBreakTime(BreakTime breakTime, TimeSpan sumOneDaySpan) + //{ + // if (breakTime.BreakTimeType != BreakTimeType.WithTime) + // return new TimeSpan(); + + // var breakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan(); + + // if (breakTimeSpan * 2 >= sumOneDaySpan) + // return new TimeSpan(); + + // return breakTimeSpan; ; + + //} + public static TimeSpan CalculateBreakTime(TimeSpan breakTimeSpan, TimeSpan sumOneDaySpan) { - if (breakTime.BreakTimeType != BreakTimeType.WithTime) - return new TimeSpan(); - - var breakTimeSpan = breakTime.BreakTimeValue.ToTimeSpan(); - if (breakTimeSpan * 2 >= sumOneDaySpan) return new TimeSpan(); - return breakTimeSpan; ; - } public TimeSpan AfterSubtract(CreateWorkingHoursTemp command, TimeSpan sumOneDaySpan, DateTime creationDate) @@ -926,7 +1006,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) var nightWorkingTime = new TimeSpan(); #endregion - + foreach (var shift in item.ShiftList) { #region DatePeriod @@ -1154,7 +1234,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) result.IsNightShift = false; result.IsEveningShift = false; result.RotatingShiftStatus = "صبح"; - + } if (result.MorningWorkSpan < result.NightWorkSpan @@ -1208,6 +1288,926 @@ CreateWorkingHoursTemp command, bool holidayWorking) } + + public List ConvertStaticHoursToRollCall(CreateWorkingHoursTemp command, bool workshopHolidyWorking) + { + var rollCallList = new List(); + #region Entities + + var sdate = command.ContarctStart.ToEnglishNumber(); + var edate = command.ContractEnd.ToEnglishNumber(); + var syear = Convert.ToInt32(sdate.Substring(0, 4)); + var smonth = Convert.ToInt32(sdate.Substring(5, 2)); + var sday = Convert.ToInt32(sdate.Substring(8, 2)); + + var eyear = Convert.ToInt32(edate.Substring(0, 4)); + var emonth = Convert.ToInt32(edate.Substring(5, 2)); + var eday = Convert.ToInt32(edate.Substring(8, 2)); + + var d1 = new PersianDateTime(syear, smonth, sday); + var d2 = new PersianDateTime(eyear, emonth, eday); + + //بدست آوردن مرخصی + LeaveSearchModel leaveSearch = new LeaveSearchModel() + { + EmployeeId = command.EmployeeId, + WorkshopId = command.WorkshopId, + + StartLeaveGr = command.ContractStartGr, + EndLeaveGr = command.ContractEndGr, + IsAccepted = true, + }; + var leaveSearchResult = _leaveRepository.search(leaveSearch); + //بدس آوردن تعطیلات رسمی + var holidayList = _holidayItemRepository.GetHolidayItem(sdate.Substring(0, 4)); + bool isHoliday = false; + + #endregion + + + + #region SumRestTimesOneShift + + var rest0 = new TimeSpan(); + var rest1 = new TimeSpan(); + var rest2 = new TimeSpan(); + var rest3 = new TimeSpan(); + var rest4 = new TimeSpan(); + var rest5 = new TimeSpan(); + var rest6 = new TimeSpan(); + + var rest0w1 = new TimeSpan(); + var rest1w1 = new TimeSpan(); + var rest2w1 = new TimeSpan(); + var rest3w1 = new TimeSpan(); + var rest4w1 = new TimeSpan(); + var rest5w1 = new TimeSpan(); + var rest6w1 = new TimeSpan(); + + var rest0w2 = new TimeSpan(); + var rest1w2 = new TimeSpan(); + var rest2w2 = new TimeSpan(); + var rest3w2 = new TimeSpan(); + var rest4w2 = new TimeSpan(); + var rest5w2 = new TimeSpan(); + var rest6w2 = new TimeSpan(); + + var rest0w3 = new TimeSpan(); + var rest1w3 = new TimeSpan(); + var rest2w3 = new TimeSpan(); + var rest3w3 = new TimeSpan(); + var rest4w3 = new TimeSpan(); + var rest5w3 = new TimeSpan(); + var rest6w3 = new TimeSpan(); + + var rest0w4 = new TimeSpan(); + var rest1w4 = new TimeSpan(); + var rest2w4 = new TimeSpan(); + var rest3w4 = new TimeSpan(); + var rest4w4 = new TimeSpan(); + var rest5w4 = new TimeSpan(); + var rest6w4 = new TimeSpan(); + if (command.ShiftWork == "4") + { + + //week1 + command.RestTimeShanbe1 = command.RestTimeShanbe1 == "0" ? "00" : command.RestTimeShanbe1; + command.RestTimeShanbe1Min = command.RestTimeShanbe1Min == "0" ? "00" : command.RestTimeShanbe1Min; + command.RestTimeYekShanbe1 = command.RestTimeYekShanbe1 == "0" ? "00" : command.RestTimeYekShanbe1; + command.RestTimeYekShanbe1Min = + command.RestTimeYekShanbe1Min == "0" ? "00" : command.RestTimeYekShanbe1Min; + command.RestTimeDoShanbe1 = command.RestTimeDoShanbe1 == "0" ? "00" : command.RestTimeDoShanbe1; + command.RestTimeDoShanbe1Min = + command.RestTimeDoShanbe1Min == "0" ? "00" : command.RestTimeDoShanbe1Min; + command.RestTimeSeShanbe1 = command.RestTimeSeShanbe1 == "0" ? "00" : command.RestTimeSeShanbe1; + command.RestTimeSeShanbe1Min = + command.RestTimeSeShanbe1Min == "0" ? "00" : command.RestTimeSeShanbe1Min; + command.RestTimeCheharShanbe1 = + command.RestTimeCheharShanbe1 == "0" ? "00" : command.RestTimeCheharShanbe1; + command.RestTimeCheharShanbe1Min = + command.RestTimeCheharShanbe1Min == "0" ? "00" : command.RestTimeCheharShanbe1Min; + command.RestTimePanjShanbe1 = command.RestTimePanjShanbe1 == "0" ? "00" : command.RestTimePanjShanbe1; + command.RestTimePanjShanbe1Min = + command.RestTimePanjShanbe1Min == "0" ? "00" : command.RestTimePanjShanbe1Min; + command.RestTimeJome1 = command.RestTimeJome1 == "0" ? "00" : command.RestTimeJome1; + command.RestTimeJome1Min = command.RestTimeJome1Min == "0" ? "00" : command.RestTimeJome1Min; + + //week2 + command.RestTimeShanbe2 = command.RestTimeShanbe2 == "0" ? "00" : command.RestTimeShanbe2; + command.RestTimeShanbe2Min = command.RestTimeShanbe2Min == "0" ? "00" : command.RestTimeShanbe2Min; + command.RestTimeYekShanbe2 = command.RestTimeYekShanbe2 == "0" ? "00" : command.RestTimeYekShanbe2; + command.RestTimeYekShanbe2Min = + command.RestTimeYekShanbe2Min == "0" ? "00" : command.RestTimeYekShanbe2Min; + command.RestTimeDoShanbe2 = command.RestTimeDoShanbe2 == "0" ? "00" : command.RestTimeDoShanbe2; + command.RestTimeDoShanbe2Min = + command.RestTimeDoShanbe2Min == "0" ? "00" : command.RestTimeDoShanbe2Min; + command.RestTimeSeShanbe2 = command.RestTimeSeShanbe2 == "0" ? "00" : command.RestTimeSeShanbe2; + command.RestTimeSeShanbe2Min = + command.RestTimeSeShanbe2Min == "0" ? "00" : command.RestTimeSeShanbe2Min; + command.RestTimeCheharShanbe2 = + command.RestTimeCheharShanbe2 == "0" ? "00" : command.RestTimeCheharShanbe2; + command.RestTimeCheharShanbe2Min = + command.RestTimeCheharShanbe2Min == "0" ? "00" : command.RestTimeCheharShanbe2Min; + command.RestTimePanjShanbe2 = command.RestTimePanjShanbe2 == "0" ? "00" : command.RestTimePanjShanbe2; + command.RestTimePanjShanbe2Min = + command.RestTimePanjShanbe2Min == "0" ? "00" : command.RestTimePanjShanbe2Min; + command.RestTimeJome2 = command.RestTimeJome2 == "0" ? "00" : command.RestTimeJome2; + command.RestTimeJome2Min = command.RestTimeJome2Min == "0" ? "00" : command.RestTimeJome2Min; + + //week3 + command.RestTimeShanbe3 = command.RestTimeShanbe3 == "0" ? "00" : command.RestTimeShanbe3; + command.RestTimeShanbe3Min = command.RestTimeShanbe3Min == "0" ? "00" : command.RestTimeShanbe3Min; + command.RestTimeYekShanbe3 = command.RestTimeYekShanbe3 == "0" ? "00" : command.RestTimeYekShanbe3; + command.RestTimeYekShanbe3Min = + command.RestTimeYekShanbe3Min == "0" ? "00" : command.RestTimeYekShanbe3Min; + command.RestTimeDoShanbe3 = command.RestTimeDoShanbe3 == "0" ? "00" : command.RestTimeDoShanbe3; + command.RestTimeDoShanbe3Min = + command.RestTimeDoShanbe3Min == "0" ? "00" : command.RestTimeDoShanbe3Min; + command.RestTimeSeShanbe3 = command.RestTimeSeShanbe3 == "0" ? "00" : command.RestTimeSeShanbe3; + command.RestTimeSeShanbe3Min = + command.RestTimeSeShanbe3Min == "0" ? "00" : command.RestTimeSeShanbe3Min; + command.RestTimeCheharShanbe3 = + command.RestTimeCheharShanbe3 == "0" ? "00" : command.RestTimeCheharShanbe3; + command.RestTimeCheharShanbe3Min = + command.RestTimeCheharShanbe3Min == "0" ? "00" : command.RestTimeCheharShanbe3Min; + command.RestTimePanjShanbe3 = command.RestTimePanjShanbe3 == "0" ? "00" : command.RestTimePanjShanbe3; + command.RestTimePanjShanbe3Min = + command.RestTimePanjShanbe3Min == "0" ? "00" : command.RestTimePanjShanbe3Min; + command.RestTimeJome3 = command.RestTimeJome3 == "0" ? "00" : command.RestTimeJome3; + command.RestTimeJome3Min = command.RestTimeJome3Min == "0" ? "00" : command.RestTimeJome3Min; + + //week4 + command.RestTimeShanbe4 = command.RestTimeShanbe4 == "0" ? "00" : command.RestTimeShanbe4; + command.RestTimeShanbe4Min = command.RestTimeShanbe4Min == "0" ? "00" : command.RestTimeShanbe4Min; + command.RestTimeYekShanbe4 = command.RestTimeYekShanbe4 == "0" ? "00" : command.RestTimeYekShanbe4; + command.RestTimeYekShanbe4Min = + command.RestTimeYekShanbe4Min == "0" ? "00" : command.RestTimeYekShanbe4Min; + command.RestTimeDoShanbe4 = command.RestTimeDoShanbe4 == "0" ? "00" : command.RestTimeDoShanbe4; + command.RestTimeDoShanbe4Min = + command.RestTimeDoShanbe4Min == "0" ? "00" : command.RestTimeDoShanbe4Min; + command.RestTimeSeShanbe4 = command.RestTimeSeShanbe4 == "0" ? "00" : command.RestTimeSeShanbe4; + command.RestTimeSeShanbe4Min = + command.RestTimeSeShanbe4Min == "0" ? "00" : command.RestTimeSeShanbe4Min; + command.RestTimeCheharShanbe4 = + command.RestTimeCheharShanbe4 == "0" ? "00" : command.RestTimeCheharShanbe4; + command.RestTimeCheharShanbe4Min = + command.RestTimeCheharShanbe4Min == "0" ? "00" : command.RestTimeCheharShanbe4Min; + command.RestTimePanjShanbe4 = command.RestTimePanjShanbe4 == "0" ? "00" : command.RestTimePanjShanbe4; + command.RestTimePanjShanbe4Min = + command.RestTimePanjShanbe4Min == "0" ? "00" : command.RestTimePanjShanbe4Min; + command.RestTimeJome4 = command.RestTimeJome4 == "0" ? "00" : command.RestTimeJome4; + command.RestTimeJome4Min = command.RestTimeJome4Min == "0" ? "00" : command.RestTimeJome4Min; + + // sumrest week1 + rest0w1 = TimeSpan.Parse($"{command.RestTimeShanbe1}:{command.RestTimeShanbe1Min}"); + rest1w1 = TimeSpan.Parse($"{command.RestTimeYekShanbe1}:{command.RestTimeYekShanbe1Min}"); + rest2w1 = TimeSpan.Parse($"{command.RestTimeDoShanbe1}:{command.RestTimeDoShanbe1Min}"); + rest3w1 = TimeSpan.Parse($"{command.RestTimeSeShanbe1}:{command.RestTimeSeShanbe1Min}"); + rest4w1 = TimeSpan.Parse($"{command.RestTimeCheharShanbe1}:{command.RestTimeCheharShanbe1Min}"); + rest5w1 = TimeSpan.Parse($"{command.RestTimePanjShanbe1}:{command.RestTimePanjShanbe1Min}"); + rest6w1 = TimeSpan.Parse($"{command.RestTimeJome1}:{command.RestTimeJome1Min}"); + + // sumrest week2 + rest0w2 = TimeSpan.Parse($"{command.RestTimeShanbe2}:{command.RestTimeShanbe2Min}"); + rest1w2 = TimeSpan.Parse($"{command.RestTimeYekShanbe2}:{command.RestTimeYekShanbe2Min}"); + rest2w2 = TimeSpan.Parse($"{command.RestTimeDoShanbe2}:{command.RestTimeDoShanbe2Min}"); + rest3w2 = TimeSpan.Parse($"{command.RestTimeSeShanbe2}:{command.RestTimeSeShanbe2Min}"); + rest4w2 = TimeSpan.Parse($"{command.RestTimeCheharShanbe2}:{command.RestTimeCheharShanbe2Min}"); + rest5w2 = TimeSpan.Parse($"{command.RestTimePanjShanbe2}:{command.RestTimePanjShanbe2Min}"); + rest6w2 = TimeSpan.Parse($"{command.RestTimeJome2}:{command.RestTimeJome2Min}"); + + // sumrest week3 + rest0w3 = TimeSpan.Parse($"{command.RestTimeShanbe3}:{command.RestTimeShanbe3Min}"); + rest1w3 = TimeSpan.Parse($"{command.RestTimeYekShanbe3}:{command.RestTimeYekShanbe3Min}"); + rest2w3 = TimeSpan.Parse($"{command.RestTimeDoShanbe3}:{command.RestTimeDoShanbe3Min}"); + rest3w3 = TimeSpan.Parse($"{command.RestTimeSeShanbe3}:{command.RestTimeSeShanbe3Min}"); + rest4w3 = TimeSpan.Parse($"{command.RestTimeCheharShanbe3}:{command.RestTimeCheharShanbe3Min}"); + rest5w3 = TimeSpan.Parse($"{command.RestTimePanjShanbe3}:{command.RestTimePanjShanbe3Min}"); + rest6w3 = TimeSpan.Parse($"{command.RestTimeJome3}:{command.RestTimeJome3Min}"); + + // sumrest week4 + rest0w4 = TimeSpan.Parse($"{command.RestTimeShanbe4}:{command.RestTimeShanbe4Min}"); + rest1w4 = TimeSpan.Parse($"{command.RestTimeYekShanbe4}:{command.RestTimeYekShanbe4Min}"); + rest2w4 = TimeSpan.Parse($"{command.RestTimeDoShanbe4}:{command.RestTimeDoShanbe4Min}"); + rest3w4 = TimeSpan.Parse($"{command.RestTimeSeShanbe4}:{command.RestTimeSeShanbe4Min}"); + rest4w4 = TimeSpan.Parse($"{command.RestTimeCheharShanbe4}:{command.RestTimeCheharShanbe4Min}"); + rest5w4 = TimeSpan.Parse($"{command.RestTimePanjShanbe4}:{command.RestTimePanjShanbe4Min}"); + rest6w4 = TimeSpan.Parse($"{command.RestTimeJome4}:{command.RestTimeJome4Min}"); + + } + + + #endregion + + #region Complex + //[12-24 : 5] [24-24 : 6] [12-36 : 7] [24-48 : 8] + if (command.ShiftWork is "5" or "6" or "7" or "8") + { + int addHours = command.ShiftWork switch + { + "5" => 36, + "6" => 48, + "7" => 48, + "8" => 72, + _ => 0 + }; + var start = Convert.ToDateTime(command.StartComplex); + var end = Convert.ToDateTime(command.EndComplex); + + 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(addHours)) + { + + + var currentDateFa = $"{da}"; + var currentDateGr = da.ToGregorianDateTime(); + if (da == startContract) + { + start = new DateTime(currentDateGr.Year, currentDateGr.Month, currentDateGr.Day, start.Hour, start.Minute, 0); + end = new DateTime(currentDateGr.Year, currentDateGr.Month, currentDateGr.Day, end.Hour, end.Minute, 0); + if (start.Date == end.Date && start.TimeOfDay > end.TimeOfDay) + end = end.AddDays(1); + } + + var startComplex = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, + start.Second); + var endComplex = new DateTime(end.Year, end.Month, end.Day, end.Hour, end.Minute, + end.Second); + Console.WriteLine($"{currentDateFa} - {currentDateGr.Date} - start : {startComplex} end : {endComplex}"); + + rollCallList.Add(new RollCallViewModel() + { + StartDate = startComplex, + EndDate = endComplex, + ShiftSpan = (endComplex - startComplex), + ShiftDate = currentDateGr, + }); + + + var endCal = end - start; + start = startComplex.AddHours(addHours); + end = start.Add(endCal); + + } + + 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 = totalDays < countRollCall ? (countRollCall - totalDays) : 0; + rollCallList = rollCallList.Take(takRollCall).ToList(); + } + + } + + #endregion + + + + #region ShiftWork4Compute + + if (command.ShiftWork == "4") + { + //DateTime currentDay = ($"{da}").ToGeorgianDateTime(); + var hasSickLeave = false; + for (var da = d1; da <= d2; da.AddDays(1)) + { + var FirstDayOfMonth = new PersianDateTime(da.Year, da.Month, 1); + var w1 = 0; + var w2 = 0; + var w3 = 0; + var w4 = 0; + var w5 = 0; + var w6 = 0; + var currentDateFa = $"{da}"; + DateTime currntDateGr = currentDateFa.ToGeorgianDateTime(); + if (!workshopHolidyWorking) + { + isHoliday = holidayList.Any(x => x == currentDateFa); + } + switch (FirstDayOfMonth.DayOfWeek) + { + case "شنبه": + w1 = 7; + w2 = 14; + w3 = 28; + w4 = 31; + break; + case "یکشنبه": + w1 = 6; + w2 = 13; + w3 = 20; + w4 = 27; + w5 = 31; + break; + case "دوشنبه": + w1 = 5; + w2 = 12; + w3 = 19; + w4 = 26; + w5 = 31; + break; + case "سه شنبه": + w1 = 4; + w2 = 11; + w3 = 18; + w4 = 25; + w5 = 31; + break; + case "چهارشنبه": + w1 = 3; + w2 = 10; + w3 = 17; + w4 = 24; + w5 = 31; + break; + case "پنج شنبه": + w1 = 2; + w2 = 9; + w3 = 16; + w4 = 23; + w5 = 30; + w6 = 31; + break; + case "جمعه": + w1 = 1; + w2 = 8; + w3 = 15; + w4 = 22; + w5 = 29; + w6 = 31; + break; + } + + switch (da.DayOfWeek) + { + case "شنبه": + + if (((da.Day <= w1) || (da.Day > w4 && da.Day <= w5)) && command.Shanbe1 && isHoliday == false) + { + + var res = FindStaticShiftsStatus( + command.SingleShift1Shanbe1, + command.SingleShift2Shanbe1, + command.TowShifts1Shanbe1, + command.TowShifts2Shanbe1, currntDateGr, rest0w1,leaveSearchResult); + if (res.Count> 0) + rollCallList.AddRange(res); + + } + else if (((da.Day > w1 && da.Day <= w2) || (da.Day > w5 && da.Day <= w6)) && command.Shanbe2 && isHoliday == false) + { + + var res = FindStaticShiftsStatus( + command.SingleShift1Shanbe2, + command.SingleShift2Shanbe2, + command.TowShifts1Shanbe2, + command.TowShifts2Shanbe2, currntDateGr, rest0w2, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + + } + else if (da.Day > w2 && da.Day <= w3 && command.Shanbe3 && isHoliday == false) + { + + var res = FindStaticShiftsStatus( + command.SingleShift1Shanbe3, + command.SingleShift2Shanbe3, + command.TowShifts1Shanbe3, + command.TowShifts2Shanbe3, currntDateGr, rest0w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + + } + else if (da.Day > w3 && da.Day <= w4 && command.Shanbe4 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1Shanbe4, + command.SingleShift2Shanbe4, + command.TowShifts1Shanbe4, + command.TowShifts2Shanbe4, currntDateGr, rest0w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + + } + break; + case "یکشنبه": + if (((da.Day <= w1) || (da.Day > w4 && da.Day <= w5)) && command.YekShanbe1 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1YekShanbe1, + command.SingleShift2YekShanbe1, + command.TowShifts1YekShanbe1, + command.TowShifts2YekShanbe1, currntDateGr, rest1w1, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (((da.Day > w1 && da.Day <= w2) || (da.Day > w5 && da.Day <= w6)) && command.YekShanbe2 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1YekShanbe2, + command.SingleShift2YekShanbe2, + command.TowShifts1YekShanbe2, + command.TowShifts2YekShanbe2, currntDateGr, rest1w2, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w2 && da.Day <= w3 && command.YekShanbe3 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1YekShanbe3, + command.SingleShift2YekShanbe3, + command.TowShifts1YekShanbe3, + command.TowShifts2YekShanbe3, currntDateGr, rest1w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w3 && da.Day <= w4 && command.YekShanbe4 && isHoliday == false) + { + + var res = FindStaticShiftsStatus( + command.SingleShift1YekShanbe4, + command.SingleShift2YekShanbe4, + command.TowShifts1YekShanbe4, + command.TowShifts2YekShanbe4, currntDateGr, rest1w4, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + break; + case "دوشنبه": + if (((da.Day <= w1) || (da.Day > w4 && da.Day <= w5)) && command.DoShanbe1 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1DoShanbe1, + command.SingleShift2DoShanbe1, + command.TowShifts1DoShanbe1, + command.TowShifts2DoShanbe1, currntDateGr, rest2w1, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (((da.Day > w1 && da.Day <= w2) || (da.Day > w5 && da.Day <= w6)) && command.DoShanbe2 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1DoShanbe2, + command.SingleShift2DoShanbe2, + command.TowShifts1DoShanbe2, + command.TowShifts2DoShanbe2, currntDateGr, rest2w2, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w2 && da.Day <= w3 && command.DoShanbe3 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1DoShanbe3, + command.SingleShift2DoShanbe3, + command.TowShifts1DoShanbe3, + command.TowShifts2DoShanbe3, currntDateGr, rest2w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + + } + else if (da.Day > w3 && da.Day <= w4 && command.DoShanbe4 && isHoliday == false) + { + + var res = FindStaticShiftsStatus( + command.SingleShift1DoShanbe4, + command.SingleShift2DoShanbe4, + command.TowShifts1DoShanbe4, + command.TowShifts2DoShanbe4, currntDateGr, rest2w4, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + + + break; + case "سه شنبه": + if (((da.Day <= w1) || (da.Day > w4 && da.Day <= w5)) && command.SeShanbe1 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1SeShanbe1, + command.SingleShift2SeShanbe1, + command.TowShifts1SeShanbe1, + command.TowShifts2SeShanbe1, currntDateGr, rest3w1, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (((da.Day > w1 && da.Day <= w2) || (da.Day > w5 && da.Day <= w6)) && command.SeShanbe2 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1SeShanbe2, + command.SingleShift2SeShanbe2, + command.TowShifts1SeShanbe2, + command.TowShifts2SeShanbe2, currntDateGr, rest3w2, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w2 && da.Day <= w3 && command.SeShanbe3 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1SeShanbe3, + command.SingleShift2SeShanbe3, + command.TowShifts1SeShanbe3, + command.TowShifts2SeShanbe3, currntDateGr, rest3w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w3 && da.Day <= w4 && command.SeShanbe4 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1SeShanbe4, + command.SingleShift2SeShanbe4, + command.TowShifts1SeShanbe4, + command.TowShifts2SeShanbe4, currntDateGr, rest3w4, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + break; + case "چهارشنبه": + if (((da.Day <= w1) || (da.Day > w4 && da.Day <= w5)) && command.CheharShanbe1 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1CheharShanbe1, + command.SingleShift2CheharShanbe1, + command.TowShifts1CheharShanbe1, + command.TowShifts2CheharShanbe1, currntDateGr, rest4w1, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (((da.Day > w1 && da.Day <= w2) || (da.Day > w5 && da.Day <= w6)) && command.CheharShanbe2 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1CheharShanbe2, + command.SingleShift2CheharShanbe2, + command.TowShifts1CheharShanbe2, + command.TowShifts2CheharShanbe2, currntDateGr, rest4w2, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w2 && da.Day <= w3 && command.CheharShanbe3 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1CheharShanbe3, + command.SingleShift2CheharShanbe3, + command.TowShifts1CheharShanbe3, + command.TowShifts2CheharShanbe3, currntDateGr, rest4w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w3 && da.Day <= w4 && command.CheharShanbe4 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1CheharShanbe4, + command.SingleShift2CheharShanbe4, + command.TowShifts1CheharShanbe4, + command.TowShifts2CheharShanbe4, currntDateGr, rest4w4, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + break; + case "پنج شنبه": + if (((da.Day <= w1) || (da.Day > w4 && da.Day <= w5)) && command.PanjShanbe2 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1PanjShanbe1, + command.SingleShift2PanjShanbe1, + command.TowShifts1PanjShanbe1, + command.TowShifts2PanjShanbe1, currntDateGr, rest5w1, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (((da.Day > w1 && da.Day <= w2) || (da.Day > w5 && da.Day <= w6)) && command.PanjShanbe2 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1PanjShanbe2, + command.SingleShift2PanjShanbe2, + command.TowShifts1PanjShanbe2, + command.TowShifts2PanjShanbe2, currntDateGr, rest5w2, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w2 && da.Day <= w3 && command.PanjShanbe3 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1PanjShanbe3, + command.SingleShift2PanjShanbe3, + command.TowShifts1PanjShanbe3, + command.TowShifts2PanjShanbe3, currntDateGr, rest5w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w3 && da.Day <= w4 && command.PanjShanbe4 && isHoliday == false) + { + var res = FindStaticShiftsStatus( + command.SingleShift1PanjShanbe4, + command.SingleShift2PanjShanbe4, + command.TowShifts1PanjShanbe4, + command.TowShifts2PanjShanbe4, currntDateGr, rest5w4, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + break; + case "جمعه": + if (((da.Day <= w1) || (da.Day > w4 && da.Day <= w5)) && command.Jome1) + { + var res = FindStaticShiftsStatus( + command.SingleShift1Jome1, + command.SingleShift2Jome1, + command.TowShifts1Jome1, + command.TowShifts2Jome1, currntDateGr, rest6w1, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (((da.Day > w1 && da.Day <= w2) || (da.Day > w5 && da.Day <= w6)) && command.Jome2) + { + var res = FindStaticShiftsStatus( + command.SingleShift1Jome2, + command.SingleShift2Jome2, + command.TowShifts1Jome2, + command.TowShifts2Jome2, currntDateGr, rest6w2, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w2 && da.Day <= w3 && command.Jome3) + { + var res = FindStaticShiftsStatus( + command.SingleShift1Jome3, + command.SingleShift2Jome3, + command.TowShifts1Jome3, + command.TowShifts2Jome3, currntDateGr, rest6w3, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + else if (da.Day > w3 && da.Day <= w4 && command.Jome4) + { + var res = FindStaticShiftsStatus( + command.SingleShift1Jome4, + command.SingleShift2Jome4, + command.TowShifts1Jome4, + command.TowShifts2Jome4, currntDateGr, rest6w4, leaveSearchResult); + if (res.Count > 0) + rollCallList.AddRange(res); + } + break; + } + + } + } + + #endregion + + return rollCallList; + } + + /// + /// جاگذاری شیفت های استاتیک در بازه تاریخ + /// + /// + private List FindStaticShiftsStatus(string shift1Start, string shift1End, string shift2Start, + string shift2End, DateTime cuurentDate, TimeSpan restTime, List leaveSearchResult) + { + var result = new List(); + + var shift1StartGr = new DateTime(); + var shift1EndGr = new DateTime(); + + var shift2StartGr = new DateTime(); + var shift2EndGr = new DateTime(); + if (leaveSearchResult.Count > 0) + { + + leaveSearchResult = leaveSearchResult.Select(x => new LeaveViewModel() + { + LeaveHourses = x.LeaveHourses, + LeaveType = x.LeaveType, + PaidLeaveType = x.PaidLeaveType, + StartLeaveGr = x.StartLeaveGr, + EndLeaveGr = x.PaidLeaveType == "روزانه" ? new DateTime(x.EndLeaveGr.Year, x.EndLeaveGr.Month, x.EndLeaveGr.Day, 23,59,59) : x.EndLeaveGr, + }).ToList(); + } + + + #region Shift1 + + + + + + if (!string.IsNullOrWhiteSpace(shift1Start) && !string.IsNullOrWhiteSpace(shift1End)) + { + try + { + var starTimeSingel1 = Convert.ToDateTime(shift1Start); + var endTimeSingel2 = Convert.ToDateTime(shift1End); + + + + shift1StartGr = new DateTime(cuurentDate.Year, cuurentDate.Month, cuurentDate.Day, starTimeSingel1.Hour, starTimeSingel1.Minute,0); + shift1EndGr = new DateTime(cuurentDate.Year, cuurentDate.Month, cuurentDate.Day, endTimeSingel2.Hour, endTimeSingel2.Minute, 0); + + if (shift1EndGr.TimeOfDay < shift1StartGr.TimeOfDay) + shift1EndGr = shift1EndGr.AddDays(1); + + var shiftSpan = (shift1EndGr - shift1StartGr); + if (restTime > TimeSpan.Zero && shiftSpan >= restTime) + { + shift1EndGr = shift1EndGr.Subtract(restTime); + shiftSpan = (shift1EndGr - shift1StartGr); + } + + if (!leaveSearchResult.Any(x => x.StartLeaveGr < shift1EndGr && x.EndLeaveGr > shift1StartGr && x.PaidLeaveType =="روزانه")) + { + var hourseLeaveTypeResult = leaveSearchResult.FirstOrDefault(x => + x.StartLeaveGr < shift1EndGr && x.EndLeaveGr > shift1StartGr && x.PaidLeaveType == "ساعتی"); + if (hourseLeaveTypeResult == null) + { + result.Add(new RollCallViewModel() + { + StartDate = shift1StartGr, + EndDate = shift1EndGr, + ShiftSpan = shiftSpan, + ShiftDate = shift1StartGr, + }); + } + else + { + + if (hourseLeaveTypeResult.StartLeaveGr <= shift1StartGr && hourseLeaveTypeResult.EndLeaveGr < shift1EndGr) + { + //leave <--------------------> + //shift <----------------------------------> + result.Add(new RollCallViewModel() + { + StartDate = hourseLeaveTypeResult.EndLeaveGr, + EndDate = shift1EndGr, + ShiftSpan = (shift1EndGr - hourseLeaveTypeResult.EndLeaveGr), + ShiftDate = shift1StartGr, + }); + } + else if (hourseLeaveTypeResult.StartLeaveGr > shift1StartGr && hourseLeaveTypeResult.EndLeaveGr < shift1EndGr) + { + //leave <--------------------> + //shift <----------------------------------> + result.Add(new RollCallViewModel() + { + StartDate = shift1StartGr, + EndDate = hourseLeaveTypeResult.StartLeaveGr, + ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift1StartGr), + ShiftDate = shift1StartGr, + }); + + result.Add(new RollCallViewModel() + { + StartDate = hourseLeaveTypeResult.EndLeaveGr, + EndDate = shift1EndGr, + ShiftSpan = (shift1EndGr - hourseLeaveTypeResult.EndLeaveGr), + ShiftDate = shift1StartGr, + }); + } + else if (hourseLeaveTypeResult.StartLeaveGr > shift1StartGr && hourseLeaveTypeResult.EndLeaveGr >= shift1EndGr) + { + //leave <--------------------> + //shift <----------------------------------> + + result.Add(new RollCallViewModel() + { + StartDate = shift1StartGr, + EndDate = hourseLeaveTypeResult.StartLeaveGr, + ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift1StartGr), + ShiftDate = shift1StartGr, + }); + + } + + + } + + } + + } + catch (Exception e) + { + // ignored + } + } + + #endregion + + #region Shift2 + + if (!string.IsNullOrWhiteSpace(shift2Start) && !string.IsNullOrWhiteSpace(shift2End)) + { + try + { + + + var startTimeTowSh1 = Convert.ToDateTime(shift2Start); + var endTimeTowSh2 = Convert.ToDateTime(shift2End); + + //اگر شیفت 1 وجود داشت تاریخ جاری را از شیف 1 میگیریم + //زیرا ممکن پایان شیف 1 در روز بعد باشد + var shift1 = result.MaxBy(x=>x.EndDate); + if (shift1 != null) + if (shift1.EndDate != null) + cuurentDate = shift1.EndDate.Value; + + + shift2StartGr = new DateTime(cuurentDate.Year, cuurentDate.Month, cuurentDate.Day, startTimeTowSh1.Hour, startTimeTowSh1.Minute,0); + shift2EndGr = new DateTime(cuurentDate.Year, cuurentDate.Month, cuurentDate.Day, endTimeTowSh2.Hour, endTimeTowSh2.Minute,0); + + if (shift2EndGr.TimeOfDay < shift2StartGr.TimeOfDay) + shift2EndGr = shift2EndGr.AddDays(1); + + if (!leaveSearchResult.Any(x => x.StartLeaveGr < shift2EndGr && x.EndLeaveGr > shift2StartGr && x.PaidLeaveType == "روزانه")) + { + var hourseLeaveTypeResult = leaveSearchResult.FirstOrDefault(x => + x.StartLeaveGr < shift2EndGr && x.EndLeaveGr > shift2StartGr && x.PaidLeaveType == "ساعتی"); + if (hourseLeaveTypeResult == null) + { + + + result.Add(new RollCallViewModel() + { + StartDate = shift2StartGr, + EndDate = shift2EndGr, + ShiftSpan = (shift2EndGr - shift2StartGr), + ShiftDate = shift1?.ShiftDate ?? shift2EndGr, + }); + } + else + { + + if (hourseLeaveTypeResult.StartLeaveGr <= shift2StartGr && hourseLeaveTypeResult.EndLeaveGr < shift2EndGr) + { + //leave <--------------------> + //shift <----------------------------------> + result.Add(new RollCallViewModel() + { + StartDate = hourseLeaveTypeResult.EndLeaveGr, + EndDate = shift2EndGr, + ShiftSpan = (shift2EndGr - hourseLeaveTypeResult.EndLeaveGr), + ShiftDate = shift1?.EndDate ?? shift2EndGr, + }); + } + else if (hourseLeaveTypeResult.StartLeaveGr > shift2StartGr && hourseLeaveTypeResult.EndLeaveGr < shift2EndGr) + { + //leave <--------------------> + //shift <----------------------------------> + result.Add(new RollCallViewModel() + { + StartDate = shift2StartGr, + EndDate = hourseLeaveTypeResult.StartLeaveGr, + ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift2StartGr), + ShiftDate = shift1?.EndDate ?? shift2EndGr, + }); + + result.Add(new RollCallViewModel() + { + StartDate = hourseLeaveTypeResult.EndLeaveGr, + EndDate = shift2EndGr, + ShiftSpan = (shift2EndGr - hourseLeaveTypeResult.EndLeaveGr), + ShiftDate = shift1?.EndDate ?? shift2EndGr, + }); + } + else if (hourseLeaveTypeResult.StartLeaveGr > shift2StartGr && hourseLeaveTypeResult.EndLeaveGr >= shift2EndGr) + { + //leave <--------------------> + //shift <----------------------------------> + + result.Add(new RollCallViewModel() + { + StartDate = shift2StartGr, + EndDate = hourseLeaveTypeResult.StartLeaveGr, + ShiftSpan = (hourseLeaveTypeResult.StartLeaveGr - shift2StartGr), + ShiftDate = shift1?.EndDate ?? shift2EndGr, + }); + + } + + + } + + } + + } + catch (Exception e) + { + // ignored + } + } + + #endregion + + + return result; + + } + + #endregion #region CustomizeCheckout @@ -1328,6 +2328,7 @@ CreateWorkingHoursTemp command, bool holidayWorking) EndDate = x.EndDate, ShiftSpan = (x.EndDate.Value - x.StartDate.Value), CreationDate = x.CreationDate, + BreakTimeSpan = x.BreakTimeSpan }).ToList(); @@ -1339,10 +2340,10 @@ CreateWorkingHoursTemp command, bool holidayWorking) ShiftList = x.Select(s => new ShiftList() { Start = s.StartDate!.Value, End = s.EndDate!.Value }).ToList(), HasFriday = x.Any(s => s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value.DayOfWeek == DayOfWeek.Friday), - SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime, + SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), - BreakTime = CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))) + BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))) }).ToList(); @@ -1955,8 +2956,10 @@ CreateWorkingHoursTemp command, bool holidayWorking) LateEntryDuration = x.LateEntryDuration, EarlyExitDuration = x.EarlyExitDuration, LateExitDuration = x.LateExitDuration, - ShiftDurationTimeSpan = x.ShiftDurationTimeSpan - }).ToList(); + ShiftDurationTimeSpan = x.ShiftDurationTimeSpan, + BreakTimeSpan = x.BreakTimeSpan + + }).ToList(); @@ -1972,16 +2975,16 @@ CreateWorkingHoursTemp command, bool holidayWorking) EarlyEntryDuration = s.EarlyEntryDuration, EarlyExitDuration = s.EarlyExitDuration, LateEntryDuration = s.LateEntryDuration, - LateExitDuration = s.LateExitDuration + LateExitDuration = s.LateExitDuration, }).ToList(), HasFriday = x.Any(s => s.StartDate.Value.DayOfWeek == DayOfWeek.Friday || s.EndDate.Value.DayOfWeek == DayOfWeek.Friday), SumOneDaySpan = new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks)) - CalculateBreakTime( - customizeWorkshopEmployeeSettings.BreakTime, + x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), - BreakTime = CalculateBreakTime(customizeWorkshopEmployeeSettings.BreakTime, + BreakTime = CalculateBreakTime(x.First().BreakTimeSpan, new TimeSpan(x.Sum(shift => shift.ShiftSpan.Ticks))), ShiftDate = x.Key, TotalEarlyEntryDuration = new TimeSpan(x.Sum(rollCall => rollCall.EarlyEntryDuration.Ticks)), @@ -3873,4 +4876,13 @@ internal class EmployeeShiftResult { public ShiftPlacement Placement { get; set; } public TimeSpan ShiftSpan { get; set; } +} + +internal class StaticShiftStartEnd +{ + public DateTime StartShift { get; set; } + public DateTime EndShift { get; set; } + public TimeSpan ShiftSpanning { get; set; } + public bool HasValue { get; set; } + public string ShiftType { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index 34f6fdc2..2f384a23 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -154,13 +154,13 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //گرفتن ساعت استراحت پرسنل از تنظیمات #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; + //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 => + 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(); @@ -223,7 +223,7 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos var rollCallTimeSpanPerDay = new TimeSpan(x.Where(y => y.EndDate != null).Sum(y => (y.EndDate - y.StartDate)!.Value.Ticks)); - var breakTimePerDay = RollCallMandatoryRepository.CalculateBreakTime(breakTime, rollCallTimeSpanPerDay); + var breakTimePerDay = RollCallMandatoryRepository.CalculateBreakTime(x.First().BreakTimeSpan, rollCallTimeSpanPerDay); return new CheckoutDailyRollCallViewModel() { diff --git a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs index a95cbb5e..c506663b 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs @@ -19,6 +19,7 @@ using CompanyManagment.App.Contracts.WorkingHoursItems; using CompanyManagment.App.Contracts.WorkingHoursTemp; using CompanyManagment.App.Contracts.Workshop; using CompanyManagment.App.Contracts.YearlySalary; +using CompanyManagment.Application; using Humanizer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -330,6 +331,10 @@ public class IndexModel : PageModel return Partial("./Create", command); } + /// + /// متد اصلاحی + /// + /// public async Task OnGetCorrectCheckout() { var result = await _workingHoursTempApplication.Correct(); @@ -542,18 +547,20 @@ public class IndexModel : PageModel { mandatoryCompute = _rollCallMandatoryApplication.MandatoryCompute(contract.EmployeeId, contract.WorkshopIds, - separation.ContractStartGr, separation.ContractEndGr, workingHours, workshop.WorkshopHolidayWorking); - } - else - { - mandatoryCompute = MandatoryHours(workingHours, workshop.WorkshopHolidayWorking, 0); - //var hasLeave = _leaveApplication.LeavOnChekout(separation.ContractStartGr, - // separation.ContractEndGr, contract.EmployeeId, contract.WorkshopIds); - //if (hasLeave != null) - //{ - // //var LeaveCompute = MandatoryHours(workingHours, hasLeave.Id); - //} - } + separation.ContractStartGr, separation.ContractEndGr, workingHours, workshop.WorkshopHolidayWorking,false); + } + else + { + mandatoryCompute = _rollCallMandatoryApplication.MandatoryCompute(contract.EmployeeId, + contract.WorkshopIds, + separation.ContractStartGr, separation.ContractEndGr, workingHours, workshop.WorkshopHolidayWorking, true); + //var hasLeave = _leaveApplication.LeavOnChekout(separation.ContractStartGr, + // separation.ContractEndGr, contract.EmployeeId, contract.WorkshopIds); + //if (hasLeave != null) + //{ + // //var LeaveCompute = MandatoryHours(workingHours, hasLeave.Id); + //} + } var employee = _employeeApplication.GetDetails(contract.EmployeeId); @@ -653,7 +660,7 @@ public class IndexModel : PageModel { foundMandatoryCompute = _rollCallMandatoryApplication.MandatoryCompute(contract.EmployeeId, contract.WorkshopIds, - found.ContractStart, found.ContractEnd, foundWorkingHours, workshop.WorkshopHolidayWorking); + found.ContractStart, found.ContractEnd, foundWorkingHours, workshop.WorkshopHolidayWorking,false); } else diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs index 3e2a8b3b..9ea8a133 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs @@ -65,15 +65,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk public IActionResult OnPostShiftDateNew() { var startRollCall = new DateTime(2025, 4, 21); - var employees = _context.CustomizeWorkshopEmployeeSettings - .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList(); + //var employees = _context.CustomizeWorkshopEmployeeSettings + // .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList(); - var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null &&employees.Contains(x.EmployeeId)).ToList(); + var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList(); var r1 = rollCalls.ToList(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("endStep 1 ============"); - SetRollCall(r1); + SetBreakTime(r1); ViewData["message"] = "تومام یک"; @@ -444,6 +444,15 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk } + private void SetBreakTime(List r1) + { + foreach (var rollCall in r1) + { + rollCall.SetBreakTime(_rollCallDomainService,rollCall.EmployeeId,rollCall.WorkshopId); + } + + _context.SaveChanges(); + } private void SetRollCall(List r1) {