From 9592960a400e9ae25538178a280e57c2dc748b9f Mon Sep 17 00:00:00 2001 From: MahanCh Date: Wed, 30 Apr 2025 14:55:38 +0330 Subject: [PATCH 01/16] add recalculate values --- ...omizeWorkshopEmployeeSettingsRepository.cs | 1 + .../RollCallAgg/IRollCallRepository.cs | 3 + .../ICustomizeWorkshopSettingsApplication.cs | 11 +- .../RollCall/IRollCallApplication.cs | 18 +- .../CustomizeWorkshopSettingsApplication.cs | 83 +- .../EmployeeAplication.cs | 12 +- .../RollCallApplication.cs | 63 +- ...omizeWorkshopEmployeeSettingsRepository.cs | 64 ++ .../Repository/RollCallRepository.cs | 7 + .../Pages/Company/RollCall/Grouping.cshtml.cs | 85 +- .../Pages/Company/RollCall/Grouping.cshtml.cs | 42 +- .../ModalEditEmployeeFromGroup.cshtml | 764 +++++++++--------- .../Company/RollCall/ModalEditGroup.cshtml | 23 +- .../ConfirmEditGroupTimeChangeModal.cshtml | 65 ++ .../ConfirmEmployeeChangeModal.cshtml | 8 +- .../ConfirmEmployeeTimeChangeModal.cshtml | 63 ++ .../css/ConfirmEditGroupTimeChangeModal.css | 222 +++++ .../css/ConfirmEmployeeTimeChangeModal.css | 264 ++++++ .../RollCall/js/ConfirmEmployeeChange.js | 82 +- .../RollCall/js/ModalEditEmployeeGroup.js | 144 +++- .../pages/RollCall/js/ModalEditGroup.js | 144 +++- 21 files changed, 1628 insertions(+), 540 deletions(-) create mode 100644 ServiceHost/Areas/Client/Pages/Company/RollCall/_Partials/ConfirmEditGroupTimeChangeModal.cshtml create mode 100644 ServiceHost/Areas/Client/Pages/Company/RollCall/_Partials/ConfirmEmployeeTimeChangeModal.cshtml create mode 100644 ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/ConfirmEditGroupTimeChangeModal.css create mode 100644 ServiceHost/wwwroot/AssetsClient/pages/RollCall/css/ConfirmEmployeeTimeChangeModal.css diff --git a/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs b/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs index 6c981a4d..33f8da81 100644 --- a/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs +++ b/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs @@ -15,4 +15,5 @@ public interface ICustomizeWorkshopEmployeeSettingsRepository : IRepository GetEmployeeSettingNotInMainGroup(long entityWorkshopId); void RemoveByWorkshopIdAndEmployeeId(long workshopId, long employeeId); + bool CheckEmployeeShiftHasChanged(EditCustomizeEmployeeSettings command); } \ No newline at end of file diff --git a/Company.Domain/RollCallAgg/IRollCallRepository.cs b/Company.Domain/RollCallAgg/IRollCallRepository.cs index d11b17e0..47f851c6 100644 --- a/Company.Domain/RollCallAgg/IRollCallRepository.cs +++ b/Company.Domain/RollCallAgg/IRollCallRepository.cs @@ -87,6 +87,9 @@ namespace Company.Domain.RollCallAgg long workshopId); Task> GetRollCallsInShiftDate(DateTime rollCallShiftDate, long employeeId, long workshopId); + + Task> GetRollCallsUntilNowWithWorkshopIdEmployeeIds(long workshopId, List employeeIds, + DateTime fromDate); #endregion } } diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs index accb0fca..97bf7a29 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs @@ -2,8 +2,10 @@ using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; using CompanyManagment.App.Contracts.Employee; +using CompanyManagment.App.Contracts.RollCall; using System.Collections.Generic; using System.ComponentModel; +using System.Threading.Tasks; namespace CompanyManagment.App.Contracts.CustomizeWorkshopSettings; @@ -34,7 +36,8 @@ public interface ICustomizeWorkshopSettingsApplication OperationResult EditSimpleRollCallGroupSetting(EditCustomizeWorkshopGroupSettings command); #region Vafa - OperationResult EditSimpleRollCallEmployeeSetting(EditCustomizeEmployeeSettings command); + OperationResult EditSimpleRollCallEmployeeSetting(EditCustomizeEmployeeSettings command, + List reCalculateCommand); #endregion OperationResult RemoveGroupSettings(long employeeSettingsId); @@ -89,4 +92,10 @@ public interface ICustomizeWorkshopSettingsApplication bool HasAnyEmployeeWithoutGroup(long workshopId); + + /// + /// این متد چک میکند که آیا شیفت پرسنل تغییر کرده است یا نه + /// + /// + bool CheckEmployeeShiftHasChanged(EditCustomizeEmployeeSettings command); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs index 4fe562d4..6ada660b 100644 --- a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs +++ b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs @@ -42,6 +42,9 @@ namespace CompanyManagment.App.Contracts.RollCall DateTime end); List GetUndefinedRollCallWorkFlowsService(long workshopId, DateTime durationStart, DateTime durationEnd); + + + OperationResult RemoveEmployeeRollCallsInDate(long workshopId, long employeeId, string dateFa); @@ -114,5 +117,18 @@ namespace CompanyManagment.App.Contracts.RollCall OperationResult SetModifyTypeToEditByEmployerForRollCallsInDate(long workshopId, long employeeId, string absenceDate); List GetWorkshopEmployeeRollCallsWithUndefinedForDate(long workshopId, long employeeId, string date); - } + + /// + /// محاسبه مجدد مقادیر حضور غیاب + /// + /// + /// + /// + OperationResult RecalculateValues(long workshopId, List command); + } + public class ReCalculateRollCallValues + { + public long EmployeeId { get; set; } + public string FromDate { get; set; } + } } diff --git a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs index ae305fc0..23a3c447 100644 --- a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs +++ b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs @@ -17,7 +17,10 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Transactions; +using CompanyManagment.App.Contracts.RollCall; +using Microsoft.EntityFrameworkCore.Query; namespace CompanyManagment.Application; @@ -26,7 +29,8 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo IAuthHelper authHelper, IPasswordHasher passwordHasher, ICameraAccountApplication cameraAccountApplication, ICustomizeWorkshopGroupSettingsRepository customizeWorkshopGroupSettingsRepository, IEmployeeRepository employeeRepository, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, - IRollCallEmployeeApplication rollCallEmployeeApplication) + IRollCallEmployeeApplication rollCallEmployeeApplication, + IRollCallApplication rollCallAppllication) : ICustomizeWorkshopSettingsApplication { private readonly ICustomizeWorkshopSettingsRepository _customizeWorkshopSettingsRepository = customizeWorkshopSettingsRepository; @@ -37,8 +41,9 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo private readonly IPasswordHasher _passwordHasher = passwordHasher; private readonly ICameraAccountApplication _cameraAccountApplication = cameraAccountApplication; private readonly IRollCallEmployeeApplication _rollCallEmployeeApplication = rollCallEmployeeApplication; + private readonly IRollCallApplication _rollCallApplication = rollCallAppllication; - #region RollCallShifts + #region RollCallShifts //Create workshop settings public OperationResult CreateWorkshopSettings(CreateCustomizeWorkshopSettings command) @@ -102,7 +107,12 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo if (previousEnd != new DateTime()) { - if (newShift.start <= previousEnd) + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) { newShift.start = newShift.start.AddDays(1); } @@ -242,7 +252,12 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo if (previousEnd != new DateTime()) { - if (newShift.start <= previousEnd) + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) { newShift.start = newShift.start.AddDays(1); } @@ -340,17 +355,6 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo return createDefaultEmployee; } - if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => - x.WorkshopId == command.WorkshopId && command.EmployeeIds.First()== x.EmployeeId && - x.CustomizeWorkshopGroupSettingId == command.GroupId)) - { - var employeeSettings = _customizeWorkshopEmployeeSettingsRepository - .GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(command.WorkshopId,command.EmployeeIds.First()); - - _customizeWorkshopEmployeeSettingsRepository.Remove(employeeSettings.id); - _customizeWorkshopEmployeeSettingsRepository.SaveChanges(); - } - List shiftCollection = new List(); List rotatingShift = []; @@ -412,7 +416,7 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); } - if (newShift.start <= previousEnd) + if (newShift.start <= previousEnd) { newShift.start = newShift.start.AddDays(1); } @@ -599,7 +603,12 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo if (previousEnd != new DateTime()) { - if (newShift.start <= previousEnd) + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) { newShift.start = newShift.start.AddDays(1); } @@ -758,7 +767,8 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo _customizeWorkshopGroupSettingsRepository.SaveChanges(); return op.Succcedded(); } - public OperationResult EditSimpleRollCallEmployeeSetting(EditCustomizeEmployeeSettings command) + public OperationResult EditSimpleRollCallEmployeeSetting(EditCustomizeEmployeeSettings command, + List reCalculateCommand) { OperationResult op = new(); @@ -774,7 +784,9 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo var groupSettings = _customizeWorkshopGroupSettingsRepository.GetIncludeWorkshopSettings( entity.CustomizeWorkshopGroupSettingId); + List employeesShifts = []; + ICollection rotatingShift = []; bool isChanged = false; if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) @@ -833,7 +845,12 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo if (previousEnd != new DateTime()) { - if (newShift.start <= previousEnd) + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) { newShift.start = newShift.start.AddDays(1); } @@ -928,13 +945,26 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo } - + using var transaction = new TransactionScope(); entity.SimpleEdit(employeesShifts, command.IrregularShift, command.WorkshopShiftStatus, command.BreakTime, isChanged, command.FridayWork, command.HolidayWork,rotatingShift); - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - return op.Succcedded(); + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + if (reCalculateCommand.Count>0) + { + var result = _rollCallApplication.RecalculateValues(command.WorkshopId, reCalculateCommand); + + if (result.IsSuccedded == false) + { + return result; + } + } + + + transaction.Complete(); + + return op.Succcedded(); } //Remove the Employee From the Group Settings @@ -994,7 +1024,7 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo //if (!_customizeWorkshopGroupSettingsRepository.Exists(x => x.id == command.GroupId)) // return op.Failed("چنین گروهی وجود ندارد"); - if (!_employeeRepository.Exists(x => command.EmployeeIds.Any(y => x.id == y))) + if (!_employeeRepository.ExistsIgnoreQueryFilter(x => command.EmployeeIds.Any(y => x.id == y))) return op.Failed("چنین پرسنلی وجود ندارد"); #endregion @@ -1392,7 +1422,7 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo if (entity == null) return null; - string employeeFullName = _employeeRepository.Get(entity.EmployeeId).FullName; + string employeeFullName = _employeeRepository.GetIgnoreQueryFilter(entity.EmployeeId).FullName; return new CustomizeWorkshopEmployeeSettingsViewModel() { EmployeeId = entity.EmployeeId, @@ -1497,6 +1527,11 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo return _customizeWorkshopGroupSettingsRepository.HasAnyEmployeeWithoutGroup(workshopId); } + public bool CheckEmployeeShiftHasChanged(EditCustomizeEmployeeSettings command) + { + return _customizeWorkshopEmployeeSettingsRepository.CheckEmployeeShiftHasChanged(command); + } + private OperationResult CreateGeneralGroup(CustomizeWorkshopSettings entity) { var op = new OperationResult(); diff --git a/CompanyManagment.Application/EmployeeAplication.cs b/CompanyManagment.Application/EmployeeAplication.cs index 2c9bfc70..87a30d41 100644 --- a/CompanyManagment.Application/EmployeeAplication.cs +++ b/CompanyManagment.Application/EmployeeAplication.cs @@ -49,7 +49,6 @@ public class EmployeeAplication : RepositoryBase, IEmployeeAppli private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; private readonly ICustomizeWorkshopSettingsApplication _customizeWorkshopSettingsApplication; private readonly IEmployeeDocumentsApplication _employeeDocumentsApplication; - private readonly IEmployeeDocumentsRepository _employeeDocumentsRepository; private readonly IEmployeeBankInformationApplication _employeeBankInformationApplication; private readonly ILeftWorkTempRepository _leftWorkTempRepository; private readonly IUidService _uidService; @@ -57,9 +56,14 @@ public class EmployeeAplication : RepositoryBase, IEmployeeAppli private readonly ILeftWorkRepository _leftWorkRepository; private readonly IPersonnelCodeRepository _personnelCodeRepository; private readonly IEmployeeClientTempRepository _employeeClientTempRepository; - private readonly ICustomizeWorkshopGroupSettingsRepository _customizeWorkshopGroupSettingsRepository; - public EmployeeAplication(IEmployeeRepository employeeRepository, CompanyContext context, IWorkshopRepository workShopRepository, IWebHostEnvironment webHostEnvironment, IRollCallEmployeeStatusApplication rollCallEmployeeStatusApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, ICustomizeWorkshopSettingsApplication customizeWorkshopSettingsApplication, IEmployeeDocumentsApplication employeeDocumentsApplication, IEmployeeDocumentsRepository employeeDocumentsRepository, IEmployeeBankInformationApplication employeeBankInformationApplication, ILeftWorkTempRepository leftWorkTempRepository, IUidService uidService, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, IPersonnelCodeRepository personnelCodeRepository, IEmployeeClientTempRepository employeeClientTempRepository, ICustomizeWorkshopGroupSettingsRepository customizeWorkshopGroupSettingsRepository, ILeftWorkRepository leftWorkRepository) : base(context) + public EmployeeAplication(IEmployeeRepository employeeRepository, CompanyContext context, + IWorkshopRepository workShopRepository, IWebHostEnvironment webHostEnvironment, + IRollCallEmployeeStatusApplication rollCallEmployeeStatusApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, + ICustomizeWorkshopSettingsApplication customizeWorkshopSettingsApplication, IEmployeeDocumentsApplication employeeDocumentsApplication, + IEmployeeBankInformationApplication employeeBankInformationApplication, ILeftWorkTempRepository leftWorkTempRepository, + IUidService uidService, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, IPersonnelCodeRepository personnelCodeRepository, + IEmployeeClientTempRepository employeeClientTempRepository, ILeftWorkRepository leftWorkRepository) : base(context) { _context = context; _WorkShopRepository = workShopRepository; @@ -68,14 +72,12 @@ public class EmployeeAplication : RepositoryBase, IEmployeeAppli _rollCallEmployeeRepository = rollCallEmployeeRepository; _customizeWorkshopSettingsApplication = customizeWorkshopSettingsApplication; _employeeDocumentsApplication = employeeDocumentsApplication; - _employeeDocumentsRepository = employeeDocumentsRepository; _employeeBankInformationApplication = employeeBankInformationApplication; _leftWorkTempRepository = leftWorkTempRepository; _uidService = uidService; _customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository; _personnelCodeRepository = personnelCodeRepository; _employeeClientTempRepository = employeeClientTempRepository; - _customizeWorkshopGroupSettingsRepository = customizeWorkshopGroupSettingsRepository; _leftWorkRepository = leftWorkRepository; _EmployeeRepository = employeeRepository; } diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index f5505e23..9b84101c 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -8,6 +8,7 @@ using _0_Framework.Application; using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using Company.Domain.CheckoutAgg; using Company.Domain.CustomizeCheckoutAgg; +using Company.Domain.CustomizeCheckoutTempAgg; using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg; using Company.Domain.CustomizeWorkshopSettingsAgg; using Company.Domain.EmployeeAgg; @@ -24,7 +25,6 @@ namespace CompanyManagment.Application; public class RollCallApplication : IRollCallApplication { private readonly IRollCallRepository _rollCallRepository; - private readonly IEmployeeApplication _employeeApplication; private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; private readonly IEmployeeRepository _employeeRepository; private readonly ILeaveRepository _leaveRepository; @@ -33,11 +33,11 @@ public class RollCallApplication : IRollCallApplication private readonly IRollCallDomainService _rollCallDomainService; private readonly ICustomizeWorkshopSettingsRepository _customizeWorkshopSettingsRepository; private readonly ICustomizeWorkshopEmployeeSettingsRepository _customizeWorkshopEmployeeSettingsRepository; + private readonly ICustomizeCheckoutTempRepository _customizeCheckoutTempRepository; - public RollCallApplication(IRollCallRepository rollCallRepository, IEmployeeApplication employeeApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository, ICustomizeCheckoutRepository customizeCheckoutRepository, ICheckoutRepository checkoutRepository, IRollCallDomainService rollCallDomainService, ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository) + public RollCallApplication(IRollCallRepository rollCallRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository, ICustomizeCheckoutRepository customizeCheckoutRepository, ICheckoutRepository checkoutRepository, IRollCallDomainService rollCallDomainService, ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, ICustomizeCheckoutTempRepository customizeCheckoutTempRepository) { _rollCallRepository = rollCallRepository; - _employeeApplication = employeeApplication; _rollCallEmployeeRepository = rollCallEmployeeRepository; _employeeRepository = employeeRepository; _leaveRepository = leaveRepository; @@ -46,7 +46,8 @@ public class RollCallApplication : IRollCallApplication _rollCallDomainService = rollCallDomainService; _customizeWorkshopSettingsRepository = customizeWorkshopSettingsRepository; _customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository; - } + _customizeCheckoutTempRepository = customizeCheckoutTempRepository; + } public OperationResult Create(CreateRollCall command) { @@ -55,7 +56,7 @@ public class RollCallApplication : IRollCallApplication var yearFa = Convert.ToInt32(startDateFa.Substring(0, 4)); var monthFa = Convert.ToInt32(startDateFa.Substring(5, 2)); - var employeeName = _employeeApplication.GetDetails(command.EmployeeId).EmployeeFullName; + var employeeName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName; var create = new RollCall(command.WorkshopId, command.EmployeeId, employeeName, command.StartDate.Value, null, yearFa, monthFa, _rollCallDomainService); _rollCallRepository.Create(create); @@ -772,4 +773,56 @@ public class RollCallApplication : IRollCallApplication { return _rollCallRepository.CheckRepeat(employeeId, workshopId); } + + public OperationResult RecalculateValues(long workshopId, List commands) + { + var operationResult = new OperationResult(); + try + { + 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))) + { + return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش رسمی است"); + } + + if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + { + return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی نهایی است"); + } + + if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart))) + { + return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی موقت است"); + } + + var oldestDate = commands.MinBy(x => x.FromDate).FromDate.ToGeorgianDateTime(); + + var allRollCalls = _rollCallRepository + .GetRollCallsUntilNowWithWorkshopIdEmployeeIds(workshopId, commands.Select(x => x.EmployeeId).ToList(), + oldestDate).GetAwaiter().GetResult(); + + + foreach (var command in commands) + { + var rollCalls = allRollCalls + .Where(x => x.EmployeeId == command.EmployeeId && x.ShiftDate >= command.FromDate.ToGeorgianDateTime()).ToList(); + + foreach (var rollCall in rollCalls) + { + rollCall.ClearTimeDiff(); + _rollCallRepository.SaveChanges(); + rollCall.SetEndDateTime(rollCall.EndDate!.Value, _rollCallDomainService); + } + } + + + return operationResult.Succcedded(); + } + catch (Exception e) + { + return operationResult.Failed(e.Message); + } + } + } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs index 303da08f..fff9d80d 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs @@ -1,12 +1,15 @@ using _0_Framework.Application; using _0_Framework.Domain.CustomizeCheckoutShared.Enums; +using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; using _0_Framework.InfraStructure; using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg; using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg.Entities; using CompanyManagment.App.Contracts.CustomizeWorkshopSettings; using CompanyManagment.App.Contracts.CustomizeWorkshopSettings.ValueObjectsViewModel; using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; namespace CompanyManagment.EFCore.Repository; @@ -174,4 +177,65 @@ public class CustomizeWorkshopEmployeeSettingsRepository(CompanyContext companyC if (entity != null) Remove(entity); } + + public bool CheckEmployeeShiftHasChanged(EditCustomizeEmployeeSettings command) + { + var employeeSettings = _companyContext.CustomizeWorkshopEmployeeSettings.Find(command.Id); + if (employeeSettings == null) + { + throw new InvalidDataException(); + } + + if (command.WorkshopShiftStatus != employeeSettings.WorkshopShiftStatus) + { + return true; + } + + switch (employeeSettings.WorkshopShiftStatus) + { + case WorkshopShiftStatus.Irregular: + if (command.IrregularShift != employeeSettings.IrregularShift) + { + return true; + } + break; + case WorkshopShiftStatus.Rotating: + var rotatingShift = command.CustomizeRotatingShifts + .Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))) + .ToList(); + + if (!rotatingShift.All(x => employeeSettings.CustomizeRotatingShifts.Any(x.Equals))) + { + return true; + } + break; + case WorkshopShiftStatus.Regular: + var employeesShifts = + command.ShiftViewModel.Select(x => + { + var placement = x.Placement switch + { + ShiftPlacement.First => "اول", + ShiftPlacement.Second => "دوم", + ShiftPlacement.Third => "سوم" + }; + if (!TimeOnly.TryParseExact(x.StartTime, "HH:mm", out TimeOnly start)) + throw new InvalidDataException($"فرمت شروع نوبت{placement}نادرست است"); + if (!TimeOnly.TryParseExact(x.EndTime, "HH:mm", out TimeOnly end)) + throw new InvalidDataException($"فرمت پایان نوبت{placement}نادرست است"); + + + return new CustomizeWorkshopEmployeeSettingsShift(start, end, x.Placement); + + }).ToList(); + if (!employeesShifts.All(x => employeeSettings.CustomizeWorkshopEmployeeSettingsShifts.Any(x.Equals))) + { + return true; + } + break; + } + return false; + + + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index 1986a106..baf7fb5c 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -2049,5 +2049,12 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos #endregion } + + 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(); + } } diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Grouping.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Grouping.cshtml.cs index 47127403..29fc8aa7 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Grouping.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Grouping.cshtml.cs @@ -1,6 +1,7 @@ using _0_Framework.Application; using CompanyManagment.App.Contracts.CustomizeWorkshopSettings; using CompanyManagment.App.Contracts.Employee; +using CompanyManagment.App.Contracts.RollCall; using CompanyManagment.App.Contracts.Workshop; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -221,54 +222,54 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.RollCall return Partial("ModalEditEmployeeFromGroup", command); } - public IActionResult OnPostChangeEditEmployee(EditCustomizeEmployeeSettings command, long workshopId) - { - command.WorkshopId = workshopId; - OperationResult result = _customizeWorkshopSettingsApplication.EditSimpleRollCallEmployeeSetting(command); - return new JsonResult(new - { - success = result.IsSuccedded, - message = result.Message - }); - } + public IActionResult OnPostChangeEditEmployee(EditCustomizeEmployeeSettings command, long workshopId, List reCalculateCommand) + { + command.WorkshopId = workshopId; + OperationResult result = _customizeWorkshopSettingsApplication.EditSimpleRollCallEmployeeSetting(command, reCalculateCommand); + return new JsonResult(new + { + success = result.IsSuccedded, + message = result.Message + }); + } - // public IActionResult OnGetGroupingSetting(long groupId) - // { - // var command = _customizeWorkshopSettingsApplication.GetCustomizeWorkshopGroupSettingsDetails(groupId); + // public IActionResult OnGetGroupingSetting(long groupId) + // { + // var command = _customizeWorkshopSettingsApplication.GetCustomizeWorkshopGroupSettingsDetails(groupId); - // return Partial("ModalSettingGroup", command); - //} + // return Partial("ModalSettingGroup", command); + //} - // public IActionResult OnPostGroupingSetting(EditCustomizeWorkshopGroupSettings command) - // { - // command.EmployeeIds = _customizeWorkshopSettingsApplication.GetEmployeeSettingsByGroupSettingsId(command.Id).Select(x => x.EmployeeId).ToList(); - // OperationResult result = _customizeWorkshopSettingsApplication.EditRollCallGroupSetting(command); + // public IActionResult OnPostGroupingSetting(EditCustomizeWorkshopGroupSettings command) + // { + // command.EmployeeIds = _customizeWorkshopSettingsApplication.GetEmployeeSettingsByGroupSettingsId(command.Id).Select(x => x.EmployeeId).ToList(); + // OperationResult result = _customizeWorkshopSettingsApplication.EditRollCallGroupSetting(command); - // return new JsonResult(new - // { - // isSuccess = result.IsSuccedded, - // message = result.Message - // }); - //} + // return new JsonResult(new + // { + // isSuccess = result.IsSuccedded, + // message = result.Message + // }); + //} - //public IActionResult OnGetGroupingEmployeeSetting(long customizeEmployeeId, List employeeId) - // { - // var command = _customizeWorkshopSettingsApplication.GetCustomizeEmployeeSettingsDetails(customizeEmployeeId); - // command.EmployeeIds = employeeId; + //public IActionResult OnGetGroupingEmployeeSetting(long customizeEmployeeId, List employeeId) + // { + // var command = _customizeWorkshopSettingsApplication.GetCustomizeEmployeeSettingsDetails(customizeEmployeeId); + // command.EmployeeIds = employeeId; - // return Partial("ModalSettingGroupEmployee", command); - // } + // return Partial("ModalSettingGroupEmployee", command); + // } - // public IActionResult OnPostGroupingEmployeeSetting(EditCustomizeEmployeeSettings command) - // { - // command.WorkshopId = _workshopId; - // OperationResult result = _customizeWorkshopSettingsApplication.EditRollCallEmployeeSettings(command); + // public IActionResult OnPostGroupingEmployeeSetting(EditCustomizeEmployeeSettings command) + // { + // command.WorkshopId = _workshopId; + // OperationResult result = _customizeWorkshopSettingsApplication.EditRollCallEmployeeSettings(command); - // return new JsonResult(new - // { - // isSuccess = result.IsSuccedded, - // message = result.Message - // }); - //} - } + // return new JsonResult(new + // { + // isSuccess = result.IsSuccedded, + // message = result.Message + // }); + //} + } } diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs index 1d6eadc1..43658362 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs @@ -16,6 +16,7 @@ using CompanyManagment.App.Contracts.RollCallEmployee; using Company.Domain.EmployeeAgg; using CompanyManagement.Infrastructure.Excel.CWS; using CompanyManagement.Infrastructure.Excel.EmployeeBankInfo; +using CompanyManagment.App.Contracts.RollCall; namespace ServiceHost.Areas.Client.Pages.Company.RollCall { @@ -30,13 +31,14 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall private readonly ICustomizeWorkshopSettingsApplication _customizeWorkshopSettingsApplication; private readonly IHttpContextAccessor _contextAccessor; private readonly IAuthHelper _authHelper; + private readonly IRollCallApplication _rollCallApplication; public bool GroupedAllEmployees; private readonly long _workshopId; public string WorkshopFullName; public CustomizeWorkshopSettingsViewModel RollCallWorkshopSettings; public List RollCallEmployeeList; - public GroupingModel(IPasswordHasher passwordHasher, IWorkshopApplication workshopApplication, ICustomizeWorkshopSettingsApplication rollCallWorkshopSettingsApplication, IEmployeeApplication employeeApplication, IHttpContextAccessor contextAccessor, IAuthHelper authHelper, IRollCallEmployeeApplication rollCallEmployeeApplication) + public GroupingModel(IPasswordHasher passwordHasher, IWorkshopApplication workshopApplication, ICustomizeWorkshopSettingsApplication rollCallWorkshopSettingsApplication, IEmployeeApplication employeeApplication, IHttpContextAccessor contextAccessor, IAuthHelper authHelper, IRollCallEmployeeApplication rollCallEmployeeApplication, IRollCallApplication rollCallApplication) { _passwordHasher = passwordHasher; _workshopApplication = workshopApplication; @@ -45,6 +47,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall _contextAccessor = contextAccessor; _authHelper = authHelper; _rollCallEmployeeApplication = rollCallEmployeeApplication; + _rollCallApplication = rollCallApplication; var workshopHash = _contextAccessor.HttpContext?.User.FindFirstValue("WorkshopSlug"); _workshopId = _passwordHasher.SlugDecrypt(workshopHash); @@ -244,10 +247,21 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall return Partial("ModalEditEmployeeFromGroup", command); } - public IActionResult OnPostChangeEditEmployee(EditCustomizeEmployeeSettings command) + public IActionResult OnGetEmployeesHaveToChange(long groupId, bool isChange) { - command.WorkshopId = _workshopId; - OperationResult result = _customizeWorkshopSettingsApplication.EditSimpleRollCallEmployeeSetting(command); + var result = _customizeWorkshopSettingsApplication.GetEmployeeSettingsByGroupSettingsId(groupId) + .Where(x => x.IsSettingChanged = isChange).ToList(); + return new JsonResult(new + { + success = true, + data = result + }); + } + + public IActionResult OnPostChangeEditEmployee(EditCustomizeEmployeeSettings command, List reCalculateCommand) + { + command.WorkshopId = _workshopId; + OperationResult result = _customizeWorkshopSettingsApplication.EditSimpleRollCallEmployeeSetting(command, reCalculateCommand); return new JsonResult(new { success = result.IsSuccedded, @@ -255,6 +269,26 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall }); } + public IActionResult OnGetEmployeeSettingsHasChangedValue(EditCustomizeEmployeeSettings command) + { + var employeeChange = _customizeWorkshopSettingsApplication.CheckEmployeeShiftHasChanged(command); + return new JsonResult(new + { + data = employeeChange + }); + } + + public IActionResult OnPostReCalculateValues(List command) + { + var result = _rollCallApplication.RecalculateValues(_workshopId, command); + + return new JsonResult(new + { + success = result.IsSuccedded, + message = result.Message + }); + } + public IActionResult OnGetDownloadExcel() { var groupData = _customizeWorkshopSettingsApplication.GetWorkshopSettingsByWorkshopIdForAdmin(_workshopId); diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml index 0b8b103e..674460bb 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml @@ -12,434 +12,454 @@