From fb1db062f34b65245ac8fc6fb55518629fb5ce3f Mon Sep 17 00:00:00 2001 From: Mahan Ch Date: Sun, 15 Jun 2025 19:44:09 +0330 Subject: [PATCH] complete method for weeklyDayOfweek... --- .../Base/BaseCustomizeEntity.cs | 14 +- .../CustomizeWorkshopEmployeeSettings.cs | 19 +- .../CustomizeWorkshopGroupSettings.cs | 35 +- .../Entities/CustomizeWorkshopSettings.cs | 16 +- .../CreateCustomizeWorkshopGroupSettings.cs | 4 +- .../CreateCustomizeWorkshopSettings.cs | 8 +- ...tomizeWorkshopEmployeeSettingsViewModel.cs | 6 +- .../EditCustomizeEmployeeSettings.cs | 16 +- .../EditCustomizeWorkshopGroupSettings.cs | 14 +- .../ICustomizeWorkshopSettingsApplication.cs | 10 +- .../CustomizeWorkshopSettingsApplication.cs | 3426 +++++++++-------- ...omizeWorkshopEmployeeSettingsRepository.cs | 1 - ...ustomizeWorkshopGroupSettingsRepository.cs | 6 +- .../CustomizeWorkshopSettingsRepository.cs | 8 +- .../Pages/Company/RollCall/Options.cshtml.cs | 4 +- .../Salary.cshtml | 4 +- .../_ModalGroupSettingPartials/Salary.cshtml | 4 +- .../_ModalPartials/FridayAndHoliday.cshtml | 4 +- .../Pages/Company/RollCall/Grouping.cshtml.cs | 5 +- .../Pages/Company/RollCall/Index.cshtml.cs | 4 +- .../Company/RollCall/ModalCreateGroup.cshtml | 4 +- .../ModalEditEmployeeFromGroup.cshtml | 4 +- .../Company/RollCall/ModalEditGroup.cshtml | 4 +- .../RollCall/ModalSettingWorkTime.cshtml | 4 +- .../RollCall/WorkshopSetting/Index.cshtml.cs | 4 +- .../ModalCreateSettingWorkshop.cshtml | 4 +- .../_Partials/ModalSettingWorkTime.cshtml | 4 +- .../FridayAndHoliday.cshtml | 4 +- .../FridayAndHoliday.cshtml | 4 +- .../_ModalPartials/FridayAndHoliday.cshtml | 4 +- ServiceHost/Test/Tester.cs | 33 +- ServiceHost/appsettings.Development.json | 4 +- 32 files changed, 1875 insertions(+), 1810 deletions(-) diff --git a/0_Framework/Domain/CustomizeCheckoutShared/Base/BaseCustomizeEntity.cs b/0_Framework/Domain/CustomizeCheckoutShared/Base/BaseCustomizeEntity.cs index b315e609..a8522d14 100644 --- a/0_Framework/Domain/CustomizeCheckoutShared/Base/BaseCustomizeEntity.cs +++ b/0_Framework/Domain/CustomizeCheckoutShared/Base/BaseCustomizeEntity.cs @@ -14,8 +14,7 @@ public class BaseCustomizeEntity : EntityBase } public BaseCustomizeEntity(FridayPay fridayPay, OverTimePay overTimePay, BaseYearsPay baseYearsPay, BonusesPay bonusesPay, NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, ShiftPay shiftPay, - FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, - FridayWork fridayWork, HolidayWork holidayWork, BreakTime breakTime,int leavePermittedDays,List weeklyOffDays) + FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, HolidayWork holidayWork, BreakTime breakTime,int leavePermittedDays,List weeklyOffDays) { FridayPay = fridayPay; @@ -31,7 +30,6 @@ public class BaseCustomizeEntity : EntityBase FineAbsenceDeduction = fineAbsenceDeduction; LateToWork = lateToWork; EarlyExit = earlyExit; - FridayWork = fridayWork; HolidayWork = holidayWork; BreakTime = breakTime; LeavePermittedDays = leavePermittedDays; @@ -122,6 +120,16 @@ public class BaseCustomizeEntity : EntityBase public BreakTime BreakTime { get; protected set; } public List WeeklyOffDays { get; set; } + + public void FridayWorkToWeeklyDayOfWeek() + { + if (FridayWork == FridayWork.Default && !WeeklyOffDays.Any(x => x.DayOfWeek == DayOfWeek.Friday)) + { + WeeklyOffDays.Add(new WeeklyOffDay(DayOfWeek.Friday)); + } + + + } } public class WeeklyOffDay diff --git a/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/Entities/CustomizeWorkshopEmployeeSettings.cs b/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/Entities/CustomizeWorkshopEmployeeSettings.cs index f652ccd3..ecf628a0 100644 --- a/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/Entities/CustomizeWorkshopEmployeeSettings.cs +++ b/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/Entities/CustomizeWorkshopEmployeeSettings.cs @@ -27,13 +27,13 @@ public class CustomizeWorkshopEmployeeSettings : BaseCustomizeEntity FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, long employeeId, long workshopId, double salary, long customizeWorkshopGroupSettingId, ICollection customizeWorkshopEmployeeSettingsShifts, - FridayWork fridayWork, - HolidayWork holidayWork, IrregularShift irregularShift, WorkshopShiftStatus workshopShiftStatus, BreakTime breakTime, int leavePermittedDays, ICollection rotatingShifts + HolidayWork holidayWork, IrregularShift irregularShift, WorkshopShiftStatus workshopShiftStatus, BreakTime breakTime, + int leavePermittedDays, ICollection rotatingShifts , List weeklyOffDays) : base(fridayPay, overTimePay, baseYearsPay, bonusesPay, nightWorkPay, marriedAllowance, shiftPay, familyAllowance, leavePay, insuranceDeduction, fineAbsenceDeduction, lateToWork, - earlyExit, fridayWork, holidayWork, breakTime, leavePermittedDays,weeklyOffDays) + earlyExit, holidayWork, breakTime, leavePermittedDays,weeklyOffDays) { CustomizeWorkshopGroupSettingId = customizeWorkshopGroupSettingId; IsSettingChanged = false; @@ -83,7 +83,6 @@ public class CustomizeWorkshopEmployeeSettings : BaseCustomizeEntity /// جریمه غیبت /// تاخیر در ورود /// تعجیل درخروج - /// آیا در روز های جمعه موظف به کار است /// آیا در تعطیلات رسمی موظف به کار است /// نوع شیفت کاری /// آیا شیفت منظم است یا نا منظم @@ -92,7 +91,7 @@ public class CustomizeWorkshopEmployeeSettings : BaseCustomizeEntity NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, ShiftPay shiftPay, FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, - FridayWork fridayWork, HolidayWork holidayWork, IrregularShift irregularShift, bool isSettingChange, int leavePermittedDays) + HolidayWork holidayWork, IrregularShift irregularShift, bool isSettingChange, int leavePermittedDays) { SetValueObjects(fridayPay, overTimePay, baseYearsPay, bonusesPay , nightWorkPay, marriedAllowance, shiftPay, familyAllowance, leavePay, insuranceDeduction, fineAbsenceDeduction, @@ -100,7 +99,6 @@ public class CustomizeWorkshopEmployeeSettings : BaseCustomizeEntity Salary = salary; IsSettingChanged = isSettingChange; - FridayWork = fridayWork; HolidayWork = holidayWork; LeavePermittedDays = leavePermittedDays; } @@ -113,8 +111,8 @@ public class CustomizeWorkshopEmployeeSettings : BaseCustomizeEntity public void SimpleEdit( ICollection employeeSettingsShift, IrregularShift irregularShift, - WorkshopShiftStatus workshopShiftStatus, BreakTime breakTime, bool isShiftChange, FridayWork fridayWork, HolidayWork holidayWork, - ICollection rotatingShifts) + WorkshopShiftStatus workshopShiftStatus, BreakTime breakTime, bool isShiftChange,HolidayWork holidayWork, + ICollection rotatingShifts,List weeklyOffDays) { BreakTime = new BreakTime(breakTime.HasBreakTimeValue, breakTime.BreakTimeValue); IsShiftChanged = isShiftChange; @@ -127,9 +125,8 @@ public class CustomizeWorkshopEmployeeSettings : BaseCustomizeEntity : new IrregularShift(irregularShift.StartTime, irregularShift.EndTime, irregularShift.WorkshopIrregularShifts); CustomizeRotatingShifts = workshopShiftStatus == WorkshopShiftStatus.Rotating ? rotatingShifts : []; - - FridayWork = fridayWork; HolidayWork = holidayWork; + WeeklyOffDays = weeklyOffDays; } @@ -270,4 +267,6 @@ public class CustomizeWorkshopEmployeeSettings : BaseCustomizeEntity IsShiftChanged = isShiftChange; } + + } \ No newline at end of file diff --git a/Company.Domain/CustomizeWorkshopGroupSettingsAgg/Entities/CustomizeWorkshopGroupSettings.cs b/Company.Domain/CustomizeWorkshopGroupSettingsAgg/Entities/CustomizeWorkshopGroupSettings.cs index 0a0cb34d..f6fb2e6f 100644 --- a/Company.Domain/CustomizeWorkshopGroupSettingsAgg/Entities/CustomizeWorkshopGroupSettings.cs +++ b/Company.Domain/CustomizeWorkshopGroupSettingsAgg/Entities/CustomizeWorkshopGroupSettings.cs @@ -27,12 +27,12 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity FridayPay fridayPay, OverTimePay overTimePay, BaseYearsPay baseYearsPay, BonusesPay bonusesPay, NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, ShiftPay shiftPay, FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, - FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, FridayWork fridayWork, + FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, HolidayWork holidayWork, BreakTime breakTime, WorkshopShiftStatus workshopShiftStatus, IrregularShift irregularShift, int leavePermittedDays, ICollection rotatingShifts, List weeklyOffDays) : base(fridayPay, overTimePay, baseYearsPay, bonusesPay, nightWorkPay, marriedAllowance, shiftPay, familyAllowance, leavePay, insuranceDeduction, fineAbsenceDeduction, lateToWork, - earlyExit, fridayWork, holidayWork, breakTime, leavePermittedDays,weeklyOffDays) + earlyExit, holidayWork, breakTime, leavePermittedDays,weeklyOffDays) { GroupName = groupName; Salary = salary; @@ -77,7 +77,7 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, - ICollection customizeWorkshopGroupSettingsShifts, FridayWork fridayWork, + ICollection customizeWorkshopGroupSettingsShifts, HolidayWork holidayWork, IrregularShift irregularShift, ICollection rotatingShifts, WorkshopShiftStatus workshopShiftStatus, long customizeWorkshopSettingId, BreakTime breakTime, int leavePermittedDays) { @@ -97,7 +97,6 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity FineAbsenceDeduction = fineAbsenceDeduction; LateToWork = lateToWork; EarlyExit = earlyExit; - FridayWork = fridayWork; HolidayWork = holidayWork; LeavePermittedDays = leavePermittedDays; CustomizeWorkshopGroupSettingsShifts = workshopShiftStatus == WorkshopShiftStatus.Regular ? customizeWorkshopGroupSettingsShifts : []; @@ -124,7 +123,7 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity OverTimePay overTimePay, BaseYearsPay baseYearsPay, BonusesPay bonusesPay, ShiftPay shiftPay, NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, FineAbsenceDeduction fineAbsenceDeduction, - LateToWork lateToWork, EarlyExit earlyExit, FridayWork fridayWork, HolidayWork holidayWork, bool isSettingChange, int leavePermittedDays) + LateToWork lateToWork, EarlyExit earlyExit, HolidayWork holidayWork, bool isSettingChange, int leavePermittedDays) { GroupName = groupName; Salary = salary; @@ -141,7 +140,6 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity FineAbsenceDeduction = fineAbsenceDeduction; LateToWork = lateToWork; EarlyExit = earlyExit; - FridayWork = fridayWork; HolidayWork = holidayWork; IsSettingChange = isSettingChange; LeavePermittedDays = leavePermittedDays; @@ -155,7 +153,7 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity { item.EditEmployees(Salary, FridayPay, OverTimePay, BaseYearsPay, BonusesPay , NightWorkPay, MarriedAllowance, ShiftPay, FamilyAllowance, LeavePay, InsuranceDeduction, FineAbsenceDeduction, - LateToWork, EarlyExit, FridayWork, HolidayWork, IrregularShift, false, leavePermittedDays); + LateToWork, EarlyExit, HolidayWork, IrregularShift, false, leavePermittedDays); } } public void EditAndOverwriteOnAllEmployees(string groupName, double salary, @@ -163,14 +161,13 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity OverTimePay overTimePay, BaseYearsPay baseYearsPay, BonusesPay bonusesPay, ShiftPay shiftPay, NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, FineAbsenceDeduction fineAbsenceDeduction, - LateToWork lateToWork, EarlyExit earlyExit, FridayWork fridayWork, HolidayWork holidayWork, bool isSettingChange, int leavePermittedDays) + LateToWork lateToWork, EarlyExit earlyExit, HolidayWork holidayWork, bool isSettingChange, int leavePermittedDays) { SetValueObjects(fridayPay, overTimePay, baseYearsPay, bonusesPay , nightWorkPay, marriedAllowance, shiftPay, familyAllowance, leavePay, insuranceDeduction, fineAbsenceDeduction, lateToWork, earlyExit); GroupName = groupName; Salary = salary; - FridayWork = fridayWork; HolidayWork = holidayWork; IsSettingChange = isSettingChange; LeavePermittedDays = leavePermittedDays; @@ -183,7 +180,7 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity { item.EditEmployees(Salary, FridayPay, OverTimePay, BaseYearsPay, BonusesPay , NightWorkPay, MarriedAllowance, ShiftPay, FamilyAllowance, LeavePay, InsuranceDeduction, FineAbsenceDeduction, - LateToWork, EarlyExit, FridayWork, HolidayWork, IrregularShift, false, leavePermittedDays); + LateToWork, EarlyExit, HolidayWork, IrregularShift, false, leavePermittedDays); } } @@ -196,7 +193,7 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity public void EditSimpleAndOverwriteOnEmployee(string groupName, IEnumerable employeeIds, ICollection customizeWorkshopGroupSettingsShifts, WorkshopShiftStatus workshopShiftStatus, - IrregularShift irregularShift, BreakTime breakTime, bool isShiftChange, FridayWork fridayWork, HolidayWork holidayWork, ICollection rotatingShifts) + IrregularShift irregularShift, BreakTime breakTime, bool isShiftChange, HolidayWork holidayWork, ICollection rotatingShifts, List weeklyOffDays) { GroupName = groupName; CustomizeWorkshopGroupSettingsShifts = workshopShiftStatus == WorkshopShiftStatus.Regular ? customizeWorkshopGroupSettingsShifts : []; @@ -210,9 +207,11 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity BreakTime = new BreakTime(breakTime.HasBreakTimeValue, breakTime.BreakTimeValue); IsShiftChange = isShiftChange; - FridayWork = fridayWork; + HolidayWork = holidayWork; + WeeklyOffDays = weeklyOffDays; + //var employeeSettingsShift = customizeWorkshopGroupSettingsShifts // .Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); if (isShiftChange) @@ -228,15 +227,15 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity .ToList(); item.SimpleEdit(customizeWorkshopGroupSettingsShifts .Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(), - IrregularShift, WorkshopShiftStatus, BreakTime, false, FridayWork, HolidayWork, newRotatingShifts); + IrregularShift, WorkshopShiftStatus, BreakTime, false, HolidayWork, newRotatingShifts,WeeklyOffDays.ToList()); } } public void EditSimpleAndOverwriteOnAllEmployees(string groupName, ICollection customizeWorkshopGroupSettingsShifts, - WorkshopShiftStatus workshopShiftStatus, IrregularShift irregularShift, BreakTime breakTime, bool isShiftChange, - FridayWork fridayWork, HolidayWork holidayWork, ICollection rotatingShifts) + WorkshopShiftStatus workshopShiftStatus, IrregularShift irregularShift, BreakTime breakTime, bool isShiftChange, + HolidayWork holidayWork, ICollection rotatingShifts ,List weeklyOffDays) { GroupName = groupName; CustomizeWorkshopGroupSettingsShifts = workshopShiftStatus == WorkshopShiftStatus.Regular ? customizeWorkshopGroupSettingsShifts : []; @@ -252,8 +251,8 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity BreakTime = new BreakTime(breakTime.HasBreakTimeValue, breakTime.BreakTimeValue); IsShiftChange = isShiftChange; HolidayWork = holidayWork; - FridayWork = fridayWork; + WeeklyOffDays = weeklyOffDays; //var employeeSettingsShift = customizeWorkshopGroupSettingsShifts // .Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); @@ -263,7 +262,7 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity .ToList(); item.SimpleEdit(customizeWorkshopGroupSettingsShifts .Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(), - irregularShift, workshopShiftStatus, breakTime, false, FridayWork, HolidayWork, newRotatingShifts); + irregularShift, workshopShiftStatus, breakTime, false, HolidayWork, newRotatingShifts,WeeklyOffDays.ToList()); } } @@ -305,7 +304,7 @@ public class CustomizeWorkshopGroupSettings : BaseCustomizeEntity var customizeWorkshopEmployeeSettings = new CustomizeWorkshopEmployeeSettings(fridayPay, overTimePay, baseYearsPay, bonusesPay, nightWorkPay, marriedAllowance, shiftPay, familyAllowance, leavePay, insuranceDeduction, fineAbsenceDeduction, lateToWork, - earlyExit, employeeId, workshopId, Salary, id, shifts, FridayWork, HolidayWork, irregularShift, + earlyExit, employeeId, workshopId, Salary, id, shifts, HolidayWork, irregularShift, WorkshopShiftStatus, breakTime, LeavePermittedDays, rotatingShift, weeklyOffDays); CustomizeWorkshopEmployeeSettingsCollection.Add(customizeWorkshopEmployeeSettings); diff --git a/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs b/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs index 27da8b37..77c9fec2 100644 --- a/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs +++ b/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs @@ -17,7 +17,7 @@ public class CustomizeWorkshopSettings : BaseCustomizeEntity public CustomizeWorkshopSettings(long workshopId, ICollection customizeWorkshopSettingsShifts, int leavePermittedDays, - WorkshopShiftStatus workshopShiftStatus,FridayWork fridayWork,HolidayWork holidayWork, List weeklyOffDays) + WorkshopShiftStatus workshopShiftStatus,HolidayWork holidayWork, List weeklyOffDays) { FridayPay = new FridayPay(FridayPayType.None, 0); OverTimePay = new OverTimePay(OverTimePayType.None, 0); @@ -38,11 +38,10 @@ public class CustomizeWorkshopSettings : BaseCustomizeEntity OverTimeThresholdMinute = 0; Currency = Currency.Rial; MaxMonthDays = MaxMonthDays.Default; - FridayWork = fridayWork; - HolidayWork = holidayWork; BonusesPaysInEndOfMonth = BonusesPaysInEndOfYear.EndOfYear; WorkshopShiftStatus = workshopShiftStatus; WeeklyOffDays = weeklyOffDays; + HolidayWork = holidayWork; if (workshopShiftStatus == WorkshopShiftStatus.Irregular) return; @@ -92,8 +91,7 @@ public class CustomizeWorkshopSettings : BaseCustomizeEntity public void Edit(FridayPay fridayPay, OverTimePay overTimePay, BaseYearsPay baseYearsPay, BonusesPay bonusesPay, NightWorkPay nightWorkPay, MarriedAllowance marriedAllowance, ShiftPay shiftPay, FamilyAllowance familyAllowance, LeavePay leavePay, InsuranceDeduction insuranceDeduction, - FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, - FridayWork fridayWork, HolidayWork holidayWork, BonusesPaysInEndOfYear bonusesPaysInEndOfYear, + FineAbsenceDeduction fineAbsenceDeduction, LateToWork lateToWork, EarlyExit earlyExit, HolidayWork holidayWork, BonusesPaysInEndOfYear bonusesPaysInEndOfYear, int leavePermittedDays, BaseYearsPayInEndOfYear baseYearsPayInEndOfYear, int overTimeThresholdMinute) { FridayPay = fridayPay; @@ -109,7 +107,6 @@ public class CustomizeWorkshopSettings : BaseCustomizeEntity FineAbsenceDeduction = fineAbsenceDeduction; LateToWork = lateToWork; EarlyExit = earlyExit; - FridayWork = fridayWork; HolidayWork = holidayWork; BonusesPaysInEndOfMonth = bonusesPaysInEndOfYear; LeavePermittedDays = leavePermittedDays; @@ -127,19 +124,18 @@ public class CustomizeWorkshopSettings : BaseCustomizeEntity } public void ChangeWorkshopShifts(ICollection customizeWorkshopSettingsShifts, - WorkshopShiftStatus workshopShiftStatus,FridayWork fridayWork,HolidayWork holidayWork) + WorkshopShiftStatus workshopShiftStatus,HolidayWork holidayWork, List weeklyOffDays) { WorkshopShiftStatus = workshopShiftStatus; HolidayWork = holidayWork; - FridayWork = fridayWork; CustomizeWorkshopSettingsShifts = workshopShiftStatus == WorkshopShiftStatus.Regular ? customizeWorkshopSettingsShifts : new List(); + WeeklyOffDays = weeklyOffDays; + if (workshopShiftStatus == WorkshopShiftStatus.Regular) { var date = new DateOnly(); var firstStartShift = new DateTime(date, CustomizeWorkshopSettingsShifts.MinBy(x => x.Placement).StartTime); var lastEndShift = new DateTime(date, CustomizeWorkshopSettingsShifts.MaxBy(x => x.Placement).EndTime); - - if (lastEndShift > firstStartShift) firstStartShift = firstStartShift.AddDays(1); var offSet = (firstStartShift - lastEndShift).Divide(2); diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs index b80062f9..9c26475f 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs @@ -1,4 +1,5 @@  +using System; using System.Collections.Generic; using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; @@ -16,8 +17,9 @@ public class CreateCustomizeWorkshopGroupSettings public IrregularShift IrregularShift { get; set; } public BreakTime BreakTime { get; set; } public int LeavePermittedDays { get; set; } - public FridayWork FridayWork { get; set; } + //public FridayWork FridayWork { get; set; } public HolidayWork HolidayWork { get; set; } + public List OffDayOfWeeks { get; set; } public ICollection CustomizeRotatingShiftsViewModels { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopSettings.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopSettings.cs index 960f7cd4..6ddd5ef0 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopSettings.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopSettings.cs @@ -21,10 +21,10 @@ public class CreateCustomizeWorkshopSettings public BreakTime BreakTime { get; set; } - /// - /// آیا جمعه کار میکند یا نه - /// - public FridayWork FridayWork { get; set; } + ///// + ///// آیا جمعه کار میکند یا نه + ///// + //public FridayWork FridayWork { get; set; } /// /// آیا در روز های تعطیل کار میکند diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs index 5c130801..6ee51967 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs @@ -1,4 +1,5 @@ -using _0_Framework.Domain.CustomizeCheckoutShared.Enums; +using System; +using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; using System.Collections.Generic; @@ -20,7 +21,8 @@ public class CustomizeWorkshopEmployeeSettingsViewModel public bool ChangeSettingEmployeeShiftIsChange { get; set; } public BreakTime BreakTime { get; set; } public HolidayWork HolidayWork { get; set; } - public FridayWork FridayWork { get; set; } + //public FridayWork FridayWork { get; set; } public int LeavePermittedDays { get; set; } public ICollection CustomizeRotatingShiftsViewModels { get; set; } + public List WeeklyOffDays { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeEmployeeSettings.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeEmployeeSettings.cs index a29d491e..e5b94ea5 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeEmployeeSettings.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeEmployeeSettings.cs @@ -1,4 +1,5 @@ -using _0_Framework.Domain.CustomizeCheckoutShared.Enums; +using System; +using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using CompanyManagment.App.Contracts.CustomizeWorkshopSettings.ValueObjectsViewModel; using System.Collections.Generic; using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; @@ -72,17 +73,19 @@ public class EditCustomizeEmployeeSettings:CreateCustomizeEmployeeSettings /// public EarlyExitViewModel EarlyExit { get; set; } - /// - /// آیا جمعه کار میکند یا نه - /// - public FridayWork FridayWork { get; set; } + ///// + ///// آیا جمعه کار میکند یا نه + ///// + //public FridayWork FridayWork { get; set; } /// /// آیا در روز های تعطیل کار میکند /// public HolidayWork HolidayWork { get; set; } - public long Id { get; set; } + public List WeeklyOffDays { get; set; } + + public long Id { get; set; } public string Salary { get; set; } public string NameGroup { get; set; } public string EmployeeFullName { get; set; } @@ -91,4 +94,5 @@ public class EditCustomizeEmployeeSettings:CreateCustomizeEmployeeSettings public IEnumerable ShiftViewModel { get; set; } public ICollection CustomizeRotatingShifts{ get; set; } public BreakTime BreakTime { get; set; } + } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeWorkshopGroupSettings.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeWorkshopGroupSettings.cs index acb4683e..0f358acc 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeWorkshopGroupSettings.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/EditCustomizeWorkshopGroupSettings.cs @@ -1,6 +1,8 @@ -using _0_Framework.Domain.CustomizeCheckoutShared.Enums; +using System; +using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using CompanyManagment.App.Contracts.CustomizeWorkshopSettings.ValueObjectsViewModel; using System.Collections.Generic; +using _0_Framework.Domain.CustomizeCheckoutShared.Base; namespace CompanyManagment.App.Contracts.CustomizeWorkshopSettings; @@ -75,16 +77,18 @@ public class EditCustomizeWorkshopGroupSettings : CreateCustomizeWorkshopGroupSe /// public EarlyExitViewModel EarlyExit { get; set; } - /// - /// آیا جمعه کار میکند یا نه - /// - public FridayWork FridayWork { get; set; } + ///// + ///// آیا جمعه کار میکند یا نه + ///// + //public FridayWork FridayWork { get; set; } /// /// آیا در روز های تعطیل کار میکند /// public HolidayWork HolidayWork { get; set; } + //public List WeeklyOffDays { get; set; } + public bool IsShiftChanged { get; set; } public bool IsSettingChanged { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs index 46c5836e..65343eb0 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs @@ -1,4 +1,5 @@ -using _0_Framework.Application; +using System; +using _0_Framework.Application; using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects; using CompanyManagment.App.Contracts.Employee; @@ -51,11 +52,14 @@ public interface ICustomizeWorkshopSettingsApplication /// /// شیفت هت /// آیدی تنظیمات کارگاه - /// /// + /// + /// + /// /// OperationResult EditWorkshopSettingShifts(List shiftViewModels, - long customizeWorkshopSettingsId,WorkshopShiftStatus workshopShiftStatus,FridayWork fridayWork,HolidayWork holidayWork); + long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus, + HolidayWork holidayWork, List weeklyOffDays); // It will Get the Workshop Settings with its groups and the employees of groups. CustomizeWorkshopSettingsViewModel GetWorkshopSettingsByWorkshopId(long workshopId, AuthViewModel auth); diff --git a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs index 5b4b6e3a..b9fe479d 100644 --- a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs +++ b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs @@ -31,1710 +31,1726 @@ using CompanyManagment.EFCore.Repository; namespace CompanyManagment.Application; public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, - IAuthHelper authHelper, IPasswordHasher passwordHasher, ICameraAccountApplication cameraAccountApplication, - ICustomizeWorkshopGroupSettingsRepository customizeWorkshopGroupSettingsRepository, IEmployeeRepository employeeRepository, - ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, - IRollCallEmployeeApplication rollCallEmployeeApplication, - IRollCallApplication rollCallAppllication, - ICheckoutRepository checkoutRepository, - ICustomizeCheckoutRepository customizeCheckoutRepository, - ICustomizeCheckoutTempRepository customizeCheckoutTempRepository) - : ICustomizeWorkshopSettingsApplication + IAuthHelper authHelper, IPasswordHasher passwordHasher, ICameraAccountApplication cameraAccountApplication, + ICustomizeWorkshopGroupSettingsRepository customizeWorkshopGroupSettingsRepository, IEmployeeRepository employeeRepository, + ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, + IRollCallEmployeeApplication rollCallEmployeeApplication, + IRollCallApplication rollCallAppllication, + ICheckoutRepository checkoutRepository, + ICustomizeCheckoutRepository customizeCheckoutRepository, + ICustomizeCheckoutTempRepository customizeCheckoutTempRepository) + : ICustomizeWorkshopSettingsApplication { - private readonly ICustomizeWorkshopSettingsRepository _customizeWorkshopSettingsRepository = customizeWorkshopSettingsRepository; - private readonly ICustomizeWorkshopGroupSettingsRepository _customizeWorkshopGroupSettingsRepository = customizeWorkshopGroupSettingsRepository; - private readonly ICustomizeWorkshopEmployeeSettingsRepository _customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository; - private readonly IAuthHelper _authHelper = authHelper; - private readonly IEmployeeRepository _employeeRepository = employeeRepository; - private readonly IPasswordHasher _passwordHasher = passwordHasher; - private readonly ICameraAccountApplication _cameraAccountApplication = cameraAccountApplication; - private readonly IRollCallEmployeeApplication _rollCallEmployeeApplication = rollCallEmployeeApplication; - private readonly IRollCallApplication _rollCallApplication = rollCallAppllication; - private readonly ICheckoutRepository _checkoutRepository = checkoutRepository; - private readonly ICustomizeCheckoutRepository _customizeCheckoutRepository = customizeCheckoutRepository; - private readonly ICustomizeCheckoutTempRepository _customizeCheckoutTempRepository = customizeCheckoutTempRepository; - - #region RollCallShifts - - //Create workshop settings - public OperationResult CreateWorkshopSettings(CreateCustomizeWorkshopSettings command) - { - OperationResult op = new(); - var workshopId = _passwordHasher.SlugDecrypt(_authHelper.GetWorkshopSlug()); - //تبدیل شیفت های ویو مدل به انتیتی - List shiftCollection = new List(); - if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - #region Validation - if (command.ShiftsList.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) - return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); - try - { - shiftCollection = - command.ShiftsList.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 CustomizeWorkshopSettingsShift(start, end, x.Placement); - - }).ToList(); - } - catch (InvalidDataException e) - { - - return op.Failed(e.Message); - } - if (workshopId < 1) - { - return op.Failed("خطای سیستمی"); - } - DateTime day = DateTime.Now; - DateTime previousEnd = new DateTime(); - var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); - - shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); - - foreach (var shift in shiftCollection) - { - (DateTime start, DateTime end, ShiftPlacement placement) newShift = - new() - { - placement = shift.Placement, - start = new DateTime(DateOnly.FromDateTime(day), shift.StartTime), - end = new DateTime(DateOnly.FromDateTime(day), shift.EndTime) - - - }; - - if (previousEnd != new DateTime()) - { - if (newShift.start == previousEnd) - { - return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); - } - - if (newShift.start <= previousEnd) - { - newShift.start = newShift.start.AddDays(1); - } - } - while (newShift.start >= newShift.end) - { - newShift.end = newShift.end.AddDays(1); - } - finalShiftList.Add(newShift); - previousEnd = newShift.end; - } - - var firstShiftStart = finalShiftList.FirstOrDefault(x => x.placement == ShiftPlacement.First).start; - var lastShiftEnd = finalShiftList.OrderByDescending(x => x.placement).FirstOrDefault().end; - if (firstShiftStart.AddDays(1) < lastShiftEnd) - return op.Failed("بازه زمانی کارگاه نامعتبر است"); - var total = finalShiftList.Sum(x => (x.end - x.start).TotalHours); - if (total >= 24) - { - return op.Failed("بازه زمانی کارگاه نمیتواند بیشتر از 24 ساعت باشد"); - } - #endregion - } - else - { - command.ShiftsList = []; - shiftCollection = []; - - } - - var offDays = command.OffDays.Select(x => new WeeklyOffDay(x)).ToList(); - - var record = new CustomizeWorkshopSettings(workshopId, shiftCollection, command.LeavePermittedDays, - command.WorkshopShiftStatus, command.FridayWork, command.HolidayWork, offDays); - using (var transaction = new TransactionScope()) - { - - try - { - _customizeWorkshopSettingsRepository.Create(record); - _customizeWorkshopSettingsRepository.SaveChanges(); - - OperationResult result = new OperationResult(); - - result = command.WorkshopShiftStatus == WorkshopShiftStatus.Regular ? CreateGeneralGroup(record) : result.Succcedded(); - - if (result.IsSuccedded) - { - transaction.Complete(); - } - else - { - op = result; - transaction.Dispose(); - } - } - catch - { - transaction.Dispose(); - // ignored - } - } - - return string.IsNullOrWhiteSpace(op.Message) ? op.Succcedded() : op; - - } - - - //create group settings with workshopSettingsId. - public OperationResult CreateGroupSettingsByRollCallWorkshopSettingId(CreateCustomizeWorkshopGroupSettings command) - { - OperationResult op = new(); - CustomizeWorkshopSettings workshopSettings = - _customizeWorkshopSettingsRepository.Get(command.CustomizeWorkshopSettingId); - List shiftCollection = new List(); - - ICollection customizeRotatingShifts = []; - - #region validation - - if (workshopSettings == null) - return op.Failed("خطای سیستمی"); - - if (string.IsNullOrWhiteSpace(command.Name)) - return op.Failed("لطفا نام گروه را وارد کنید"); - - if (string.IsNullOrWhiteSpace(command.Salary)) - return op.Failed("لطفا حقوق مورد نظر خود را وارد کنید"); - - if (!_customizeWorkshopSettingsRepository.Exists(x => x.id == command.CustomizeWorkshopSettingId)) - return op.Failed("چنین ساعت کاری برای کارگاهی وجود ندارد"); - - if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - if (command.ShiftViewModel.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) - return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); - try - { - shiftCollection = - 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 CustomizeWorkshopGroupSettingsShift(start, end, x.Placement); - - }).ToList(); - } - catch (InvalidDataException e) - { - - return op.Failed(e.Message); - } - DateTime previousEnd = new DateTime(); - var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); - - shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); - - foreach (var shift in shiftCollection) - { - (DateTime start, DateTime end, ShiftPlacement placement) newShift = - new() - { - placement = shift.Placement, - start = new DateTime(DateOnly.MinValue, shift.StartTime), - end = new DateTime(DateOnly.MinValue, shift.EndTime) - - - }; - - if (previousEnd != new DateTime()) - { - if (newShift.start == previousEnd) - { - return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); - } - - if (newShift.start <= previousEnd) - { - newShift.start = newShift.start.AddDays(1); - } - } - while (newShift.start >= newShift.end) - { - newShift.end = newShift.end.AddDays(1); - } - finalShiftList.Add(newShift); - previousEnd = newShift.end; - } - //var firstWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MinBy(x => x.Placement).StartTime; - //var lastWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MaxBy(x => x.Placement).EndTime; - - //var startDateTime = new DateTime(DateOnly.MinValue, firstWorkshopTimeShift); - //var lastDateTime = new DateTime(DateOnly.MinValue, lastWorkshopTimeShift); - //if (lastDateTime < startDateTime) - //{ - // lastDateTime = lastDateTime.AddDays(1); - //} - - //var lastGroupShift = finalShiftList.MaxBy(x => x.placement).end; - //var firstGroupShift = finalShiftList.MinBy(x => x.placement).start; - //if (lastDateTime < lastGroupShift || firstGroupShift < startDateTime) - //{ - // return op.Failed("ساعت کاری گروه باید بین ساعت کاری کارگاه باشد"); - //} - } - else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) - { - var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); - - var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); - - if (irregularShiftEndTime < irregularShiftStartTime) - { - irregularShiftEndTime = irregularShiftEndTime.AddDays(1); - } - - switch (command.IrregularShift.WorkshopIrregularShifts) - { - case WorkshopIrregularShifts.TwelveThirtySix: - - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - case WorkshopIrregularShifts.TwelveTwentyFour: - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - } - } - else - { - if (command.CustomizeRotatingShiftsViewModels.Count == 1) - { - return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); - } - customizeRotatingShifts = command.CustomizeRotatingShiftsViewModels.Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))).ToList(); - } - - #endregion - - var breakTime = new BreakTime(command.BreakTime.HasBreakTimeValue, command.BreakTime.BreakTimeValue); - - double salary = command.Salary.MoneyToDouble(); - - - var entity = new CustomizeWorkshopGroupSettings(command.Name, salary, command.CustomizeWorkshopSettingId, shiftCollection, workshopSettings.FridayPay, workshopSettings.OverTimePay, - workshopSettings.BaseYearsPay, workshopSettings.BonusesPay, workshopSettings.NightWorkPay, workshopSettings.MarriedAllowance, - workshopSettings.ShiftPay, workshopSettings.FamilyAllowance, workshopSettings.LeavePay, workshopSettings.InsuranceDeduction, workshopSettings.FineAbsenceDeduction, - workshopSettings.LateToWork, workshopSettings.EarlyExit, command.FridayWork, - command.HolidayWork, breakTime, command.WorkshopShiftStatus, command.IrregularShift, command.LeavePermittedDays, customizeRotatingShifts,workshopSettings.WeeklyOffDays); - - _customizeWorkshopGroupSettingsRepository.Create(entity); - - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - return op.Succcedded(); - } - - //Create Employee Settings with Group data. It will Replace the Group data (such as salary, shifts and ...) on Employee settings On creation. - public OperationResult CreateEmployeesSettingsAndSetChanges(EditCustomizeEmployeeSettings command) - { - var op = new OperationResult(); - var customizeWorkshopGroupSettings = _customizeWorkshopGroupSettingsRepository.Get(command.GroupId); - if (customizeWorkshopGroupSettings == null) - { - return op.Failed("گروه انتخاب شده نا معتبر است"); - } - - if (_customizeWorkshopEmployeeSettingsRepository - .Exists(x => x.WorkshopId == command.WorkshopId && command.EmployeeIds.Contains(x.EmployeeId))) - { - foreach (var employeeId in command.EmployeeIds) - { - _customizeWorkshopEmployeeSettingsRepository.RemoveByWorkshopIdAndEmployeeId(command.WorkshopId, employeeId); - } - } - - if (customizeWorkshopGroupSettings.MainGroup) - { - var createDefaultEmployee = CreateEmployeeSettings(command); - return createDefaultEmployee; - } - - - List shiftCollection = new List(); - List rotatingShift = []; - var isChanged = false; - #region validation - - - if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - if (command.ShiftViewModel.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) - return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); - try - { - shiftCollection = - 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(); - } - catch (InvalidDataException e) - { - - return op.Failed(e.Message); - } - DateTime previousEnd = new DateTime(); - var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); - - shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); - - foreach (var shift in shiftCollection) - { - (DateTime start, DateTime end, ShiftPlacement placement) newShift = - new() - { - placement = shift.Placement, - start = new DateTime(DateOnly.MinValue, shift.StartTime), - end = new DateTime(DateOnly.MinValue, shift.EndTime) - - - }; - - if (previousEnd != new DateTime()) - { - if (newShift.start == previousEnd) - { - return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); - } - - if (newShift.start <= previousEnd) - { - newShift.start = newShift.start.AddDays(1); - } - } - while (newShift.start >= newShift.end) - { - newShift.end = newShift.end.AddDays(1); - } - finalShiftList.Add(newShift); - previousEnd = newShift.end; - } - //var firstWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MinBy(x => x.Placement).StartTime; - //var lastWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MaxBy(x => x.Placement).EndTime; - - //var startDateTime = new DateTime(DateOnly.MinValue, firstWorkshopTimeShift); - //var lastDateTime = new DateTime(DateOnly.MinValue, lastWorkshopTimeShift); - //if (lastDateTime < startDateTime) - //{ - // lastDateTime = lastDateTime.AddDays(1); - //} - - //var lastGroupShift = finalShiftList.MaxBy(x => x.placement).end; - //var firstGroupShift = finalShiftList.MinBy(x => x.placement).start; - //if (lastDateTime < lastGroupShift || firstGroupShift < startDateTime) - //{ - // return op.Failed("ساعت کاری گروه باید بین ساعت کاری کارگاه باشد"); - //} - - - if (shiftCollection.All(x => customizeWorkshopGroupSettings.CustomizeWorkshopGroupSettingsShifts.Any(y => x.Equals(y))) - && command.WorkshopShiftStatus == customizeWorkshopGroupSettings.WorkshopShiftStatus && command.FridayWork == customizeWorkshopGroupSettings.FridayWork && - command.HolidayWork == customizeWorkshopGroupSettings.HolidayWork && command.BreakTime == customizeWorkshopGroupSettings.BreakTime) - { - isChanged = false; - } - - else - { - isChanged = true; - } - } - else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) - { - var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); - - var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); - - if (irregularShiftEndTime < irregularShiftStartTime) - { - irregularShiftEndTime = irregularShiftEndTime.AddDays(1); - } - - switch (command.IrregularShift.WorkshopIrregularShifts) - { - case WorkshopIrregularShifts.TwelveThirtySix: - - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - case WorkshopIrregularShifts.TwelveTwentyFour: - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - } - if (command.WorkshopShiftStatus == customizeWorkshopGroupSettings.WorkshopShiftStatus && command.BreakTime == customizeWorkshopGroupSettings.BreakTime && - command.IrregularShift == customizeWorkshopGroupSettings.IrregularShift && command.FridayWork == customizeWorkshopGroupSettings.FridayWork && - command.HolidayWork == customizeWorkshopGroupSettings.HolidayWork) - { - isChanged = false; - } - else - { - isChanged = true; - } - } - else - { - if (command.CustomizeRotatingShifts.Count == 1) - { - return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); - } - rotatingShift = command.CustomizeRotatingShifts - .Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))) - .ToList(); - - if (rotatingShift.All(x => customizeWorkshopGroupSettings.CustomizeRotatingShifts.Any(y => x.Equals(y))) - && command.WorkshopShiftStatus == customizeWorkshopGroupSettings.WorkshopShiftStatus && - command.FridayWork == customizeWorkshopGroupSettings.FridayWork && - command.HolidayWork == customizeWorkshopGroupSettings.HolidayWork && command.BreakTime == customizeWorkshopGroupSettings.BreakTime) - { - isChanged = false; - } - - else - { - isChanged = true; - } - } - - #endregion - - var breakTime = new BreakTime(command.BreakTime.HasBreakTimeValue, command.BreakTime.BreakTimeValue); - - - - - var entity = new CustomizeWorkshopEmployeeSettings(customizeWorkshopGroupSettings.FridayPay, customizeWorkshopGroupSettings.OverTimePay, - customizeWorkshopGroupSettings.BaseYearsPay, customizeWorkshopGroupSettings.BonusesPay, customizeWorkshopGroupSettings.NightWorkPay, customizeWorkshopGroupSettings.MarriedAllowance, - customizeWorkshopGroupSettings.ShiftPay, customizeWorkshopGroupSettings.FamilyAllowance, customizeWorkshopGroupSettings.LeavePay, customizeWorkshopGroupSettings.InsuranceDeduction, customizeWorkshopGroupSettings.FineAbsenceDeduction, - customizeWorkshopGroupSettings.LateToWork, customizeWorkshopGroupSettings.EarlyExit, command.EmployeeIds.First(), command.WorkshopId, customizeWorkshopGroupSettings.Salary, command.GroupId, - shiftCollection, command.FridayWork, command.HolidayWork, command.IrregularShift, command.WorkshopShiftStatus, breakTime, command.LeavePermittedDays, rotatingShift,customizeWorkshopGroupSettings.WeeklyOffDays); - - _customizeWorkshopEmployeeSettingsRepository.Create(entity); - - entity.SimpleEdit(shiftCollection, command.IrregularShift, command.WorkshopShiftStatus, command.BreakTime, isChanged, command.FridayWork, command.HolidayWork, rotatingShift); - - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - return op.Succcedded(); - - - - - } - - public OperationResult EditWorkshopSettingShifts(List shiftViewModels, long customizeWorkshopSettingsId, - WorkshopShiftStatus workshopShiftStatus, FridayWork fridayWork, HolidayWork holidayWork) - { - OperationResult op = new OperationResult(); - var entity = _customizeWorkshopSettingsRepository.Get(customizeWorkshopSettingsId); - if (entity == null) - return op.Failed("چنین آیتمی وجود ندارد"); - - //تبدیل شیفت های ویو مدل به انتیتی - List shiftCollection = []; - - #region Validation - if (workshopShiftStatus == WorkshopShiftStatus.Regular) - { - try - { - shiftCollection = - shiftViewModels.Select(x => - { - var placement = x.Placement switch - { - ShiftPlacement.First => "اول", - ShiftPlacement.Second => "دوم", - ShiftPlacement.Third => "سوم", - _ => throw new ArgumentOutOfRangeException() - }; - 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 CustomizeWorkshopSettingsShift(start, end, x.Placement); - - }).ToList(); - } - catch (InvalidDataException e) - { - - return op.Failed(e.Message); - } - - DateTime day = DateTime.Now; - DateTime previousEnd = new DateTime(); - var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); - - shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); - - foreach (var shift in shiftCollection) - { - (DateTime start, DateTime end, ShiftPlacement placement) newShift = - new() - { - placement = shift.Placement, - start = new DateTime(DateOnly.FromDateTime(day), shift.StartTime), - end = new DateTime(DateOnly.FromDateTime(day), shift.EndTime) - - - }; - - if (previousEnd != new DateTime()) - { - if (newShift.start == previousEnd) - { - return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); - } - - if (newShift.start <= previousEnd) - { - newShift.start = newShift.start.AddDays(1); - } - } - while (newShift.start >= newShift.end) - { - newShift.end = newShift.end.AddDays(1); - } - finalShiftList.Add(newShift); - previousEnd = newShift.end; - } - - var firstShiftStart = finalShiftList.FirstOrDefault(x => x.placement == ShiftPlacement.First).start; - var lastShiftEnd = finalShiftList.OrderByDescending(x => x.placement).FirstOrDefault().end; - if (firstShiftStart.AddDays(1) < lastShiftEnd) - return op.Failed("بازه زمانی کارگاه نامعتبر است"); - var total = finalShiftList.Sum(x => (x.end - x.start).TotalHours); - if (total >= 24) - { - return op.Failed("بازه زمانی کارگاه نمیتواند بیشتر از 24 ساعت باشد"); - } - } - - #endregion - - using var transActionScope = new TransactionScope(); - entity.ChangeWorkshopShifts(shiftCollection, workshopShiftStatus, fridayWork, holidayWork); - - - //op = ChangeAllGroupsShiftsWithEmployees(entity, replaceChangedGroups); - //if (!op.IsSuccedded) - //{ - // return op; - //} - _customizeWorkshopSettingsRepository.SaveChanges(); - - if (!(_customizeWorkshopGroupSettingsRepository.Exists(x => x.CustomizeWorkshopSettingId == entity.id && x.MainGroup)) && entity.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - var operationResult = CreateGeneralGroup(entity); - if (!operationResult.IsSuccedded) - return operationResult; - } - transActionScope.Complete(); - return op.Succcedded(); - } - public OperationResult EditSimpleRollCallGroupSetting(EditCustomizeWorkshopGroupSettings command, - List reCalculateCommand) - { - OperationResult op = new(); - - #region Validation - - if (string.IsNullOrWhiteSpace(command.Name)) - return op.Failed("لطفا نام گروه را وارد کنید"); - - if (!_customizeWorkshopGroupSettingsRepository.Exists(x => x.id == command.Id)) - return op.Failed("چنین ساعت کاری برای گروه وجود ندارد"); - - #endregion - - - var entity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(command.Id); - - var workshopSettings = _customizeWorkshopSettingsRepository.Get(entity.CustomizeWorkshopSettingId); - - //var employeeIds = command.IsShiftChanged ? entity.CustomizeWorkshopEmployeeSettingsCollection - // .Select(x => x.id).ToList() : entity.CustomizeWorkshopEmployeeSettingsCollection.Where(x => !x.IsShiftChanged) - // .Select(x => x.id).ToList(); - - - var groupSettingsShifts = new List(); - ICollection rotatingShift = []; - bool isChanged; - if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - - groupSettingsShifts = command.ShiftViewModel.Select(x => - { - if (!TimeOnly.TryParseExact(x.StartTime, "HH:mm", out TimeOnly start)) - throw new InvalidDataException(); - if (!TimeOnly.TryParseExact(x.EndTime, "HH:mm", out TimeOnly end)) - throw new InvalidDataException(); - - return new CustomizeWorkshopGroupSettingsShift(start, end, x.Placement); - - }).ToList(); - - if (groupSettingsShifts.All(x => workshopSettings.CustomizeWorkshopSettingsShifts.Any(y => x.Equals(y))) - && command.WorkshopShiftStatus == workshopSettings.WorkshopShiftStatus && command.FridayWork == workshopSettings.FridayWork && - command.HolidayWork == workshopSettings.HolidayWork && - command.BreakTime == workshopSettings.BreakTime) - { - isChanged = false; - } - else - { - isChanged = true; - } - } - else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) - { - var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); - - var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); - - if (irregularShiftEndTime < irregularShiftStartTime) - { - irregularShiftEndTime = irregularShiftEndTime.AddDays(1); - } - - switch (command.IrregularShift.WorkshopIrregularShifts) - { - case WorkshopIrregularShifts.TwelveThirtySix: - - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - case WorkshopIrregularShifts.TwelveTwentyFour: - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - } - if (command.WorkshopShiftStatus == workshopSettings.WorkshopShiftStatus && command.BreakTime == workshopSettings.BreakTime - && command.FridayWork == workshopSettings.FridayWork && - command.HolidayWork == workshopSettings.HolidayWork) - { - isChanged = false; - } - else - { - isChanged = true; - } - } - else - { - if (command.CustomizeRotatingShiftsViewModels.Count == 1) - { - return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); - } - - rotatingShift = command.CustomizeRotatingShiftsViewModels - .Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))).ToList(); - if (command.WorkshopShiftStatus == workshopSettings.WorkshopShiftStatus && command.BreakTime == workshopSettings.BreakTime - && command.FridayWork == workshopSettings.FridayWork && - command.HolidayWork == workshopSettings.HolidayWork) - { - isChanged = false; - } - else - { - isChanged = true; - } - } - - var breakTime = new BreakTime(command.BreakTime.HasBreakTimeValue, command.BreakTime.BreakTimeValue); - - var employeeSettings = entity.CustomizeWorkshopEmployeeSettingsCollection; - - var employeeSettingIds = employeeSettings.Select(x => x.EmployeeId).ToList(); - - reCalculateCommand = reCalculateCommand.Where(x => employeeSettingIds.Contains(x.EmployeeId)).ToList(); - - var selectedEmployeesIds = reCalculateCommand.Select(x => x.EmployeeId).ToList(); - - var notSelectedEmployeeSettings = employeeSettings.Where(x => !selectedEmployeesIds.Contains(x.EmployeeId)); - - using var transaction = new TransactionScope(); - - entity.EditSimpleAndOverwriteOnEmployee(command.Name, selectedEmployeesIds, groupSettingsShifts, command.WorkshopShiftStatus, - command.IrregularShift, breakTime, isChanged, command.FridayWork, command.HolidayWork, rotatingShift); - if (reCalculateCommand.Count > 0) - { - var result = _rollCallApplication.RecalculateValues(workshopSettings.WorkshopId, reCalculateCommand); - - if (result.IsSuccedded == false) - { - return result; - } - } - - foreach (var notSelectedEmployeeSetting in notSelectedEmployeeSettings) - { - notSelectedEmployeeSetting.UpdateIsShiftChange(); - } - - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - - transaction.Complete(); - return op.Succcedded(); - } - public OperationResult EditSimpleRollCallEmployeeSetting(EditCustomizeEmployeeSettings command, - List reCalculateCommand) - { - OperationResult op = new(); - - var entity = _customizeWorkshopEmployeeSettingsRepository.Get(command.Id); - - #region Validation - - if (entity == null) - return op.Failed("چنین پرسنلی وجود ندارد"); - - #endregion - - var groupSettings = - _customizeWorkshopGroupSettingsRepository.GetIncludeWorkshopSettings( - entity.CustomizeWorkshopGroupSettingId); - - List employeesShifts = []; - - ICollection rotatingShift = []; - bool isChanged = false; - if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - - #region Validation - if (command.ShiftViewModel.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) - return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); - try - { - 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(); - } - catch (InvalidDataException e) - { - - return op.Failed(e.Message); - } - if (command.WorkshopId < 1) - { - return op.Failed("خطای سیستمی"); - } - DateTime day = DateTime.Now; - DateTime previousEnd = new DateTime(); - var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); - - employeesShifts = employeesShifts.OrderBy(x => x.Placement).ToList(); - - foreach (var shift in employeesShifts) - { - (DateTime start, DateTime end, ShiftPlacement placement) newShift = - new() - { - placement = shift.Placement, - start = new DateTime(DateOnly.FromDateTime(day), shift.StartTime), - end = new DateTime(DateOnly.FromDateTime(day), shift.EndTime) - - - }; - - if (previousEnd != new DateTime()) - { - if (newShift.start == previousEnd) - { - return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); - } - - if (newShift.start <= previousEnd) - { - newShift.start = newShift.start.AddDays(1); - } - } - while (newShift.start >= newShift.end) - { - newShift.end = newShift.end.AddDays(1); - } - finalShiftList.Add(newShift); - previousEnd = newShift.end; - } - - var firstShiftStart = finalShiftList.FirstOrDefault(x => x.placement == ShiftPlacement.First).start; - var lastShiftEnd = finalShiftList.OrderByDescending(x => x.placement).FirstOrDefault().end; - if (firstShiftStart.AddDays(1) < lastShiftEnd) - return op.Failed("بازه زمانی کارگاه نامعتبر است"); - var total = finalShiftList.Sum(x => (x.end - x.start).TotalHours); - if (total >= 24) - { - return op.Failed("بازه زمانی کارگاه نمیتواند بیشتر از 24 ساعت باشد"); - } - #endregion - - - if (employeesShifts.All(x => groupSettings.CustomizeWorkshopGroupSettingsShifts.Any(y => x.Equals(y))) - && command.WorkshopShiftStatus == groupSettings.WorkshopShiftStatus && command.FridayWork == groupSettings.FridayWork && - command.HolidayWork == groupSettings.HolidayWork && command.BreakTime == groupSettings.BreakTime) - { - isChanged = false; - } - - else - { - isChanged = true; - } - } - else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) - { - var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); - - var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); - - if (irregularShiftEndTime < irregularShiftStartTime) - { - irregularShiftEndTime = irregularShiftEndTime.AddDays(1); - } - - switch (command.IrregularShift.WorkshopIrregularShifts) - { - case WorkshopIrregularShifts.TwelveThirtySix: - - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - case WorkshopIrregularShifts.TwelveTwentyFour: - if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) - { - return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); - } - break; - } - - if (command.WorkshopShiftStatus == groupSettings.WorkshopShiftStatus && command.BreakTime == groupSettings.BreakTime && - command.IrregularShift == groupSettings.IrregularShift && command.FridayWork == groupSettings.FridayWork && - command.HolidayWork == groupSettings.HolidayWork) - { - isChanged = false; - } - else - { - isChanged = true; - } - } - else - { - if (command.CustomizeRotatingShifts.Count == 1) - { - return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); - } - - rotatingShift = command.CustomizeRotatingShifts - .Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))).ToList(); - - if (rotatingShift.All(x => groupSettings.CustomizeRotatingShifts.Any(y => x.Equals(y))) - && command.WorkshopShiftStatus == groupSettings.WorkshopShiftStatus && command.FridayWork == groupSettings.FridayWork && - command.HolidayWork == groupSettings.HolidayWork && command.BreakTime == groupSettings.BreakTime) - { - isChanged = false; - } - - else - { - isChanged = true; - } - - } - - using var transaction = new TransactionScope(); - - entity.SimpleEdit(employeesShifts, command.IrregularShift, command.WorkshopShiftStatus, command.BreakTime, - isChanged, command.FridayWork, command.HolidayWork, rotatingShift); - - _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 - public OperationResult RemoveEmployeeFromRollCallWorkshopGroup(long employeeId, long groupId, long workshopId) - { - OperationResult op = new(); - var groupEntity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(groupId); - - #region Validation - - if (groupEntity == null) - { - return op.Failed("چنین گروهی وجود ندارد"); - } - - #endregion - - using var transaction = new TransactionScope(); - groupEntity.RemoveEmployeeFromGroup(employeeId); - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - var res = AddEmployeeToMainGroupSettings(workshopId, employeeId); - if (res.IsSuccedded) - { - transaction.Complete(); - return op.Succcedded(); - - } - - return res; - - } - - public OperationResult AddEmployeeToMainGroupSettings(long workshopId, long employeeId) - { - var op = new OperationResult(); - - var mainGroup = _customizeWorkshopGroupSettingsRepository.GetWorkshopMainGroup(workshopId); - if (mainGroup == null) - return op.Succcedded(); - mainGroup.AddEmployeeSettingToGroupWithGroupData(employeeId, workshopId); - - _customizeWorkshopEmployeeSettingsRepository.SaveChanges(); - - return op.Succcedded(); - } - - #endregion - - #region CustomizeCheckoutSettings - public OperationResult CreateEmployeeSettings(CreateCustomizeEmployeeSettings command) - { - OperationResult op = new(); - CustomizeWorkshopGroupSettings mainGroup = new CustomizeWorkshopGroupSettings(); - - #region Validation - - //if (!_customizeWorkshopGroupSettingsRepository.Exists(x => x.id == command.GroupId)) - // return op.Failed("چنین گروهی وجود ندارد"); - - if (!_employeeRepository.ExistsIgnoreQueryFilter(x => command.EmployeeIds.Any(y => x.id == y))) - return op.Failed("چنین پرسنلی وجود ندارد"); - - #endregion - - var groupData = _customizeWorkshopGroupSettingsRepository.GetIncludeWorkshopSettings(command.GroupId); - if (groupData == null) - return op.Failed("خطای سیستمی"); - var workshopSettings = _customizeWorkshopSettingsRepository.Get(groupData.CustomizeWorkshopSettingId); - var employeesInMainGroup = new List(); - - mainGroup = _customizeWorkshopGroupSettingsRepository.GetWorkshopMainGroup(command.WorkshopId); - - if (workshopSettings.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - if (mainGroup != null) - { - - employeesInMainGroup = _customizeWorkshopEmployeeSettingsRepository.GetBy(mainGroup.id); - if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId - && command.EmployeeIds.Contains(x.EmployeeId) && x.CustomizeWorkshopGroupSettingId != mainGroup.id)) - { - return op.Failed("این پرسنل در گروه دیگری وجود دارد"); - } - } - else - { - if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId - && command.EmployeeIds.Contains(x.EmployeeId))) - { - return op.Failed("این پرسنل در گروه دیگری وجود دارد"); - } - } - } - else - { - if (mainGroup != null) - { - employeesInMainGroup = _customizeWorkshopEmployeeSettingsRepository.GetBy(mainGroup.id); - if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId - && command.EmployeeIds.Contains( - x.EmployeeId) && - x.CustomizeWorkshopGroupSettingId != - mainGroup.id)) - { - return op.Failed("این پرسنل در گروه دیگری وجود دارد"); - } - } - else - { - if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId - && command.EmployeeIds.Contains(x.EmployeeId))) - { - return op.Failed("این پرسنل در گروه دیگری وجود دارد"); - } - } - } - - - - var shifts = groupData.CustomizeWorkshopGroupSettingsShifts - .Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); - - - foreach (var id in command.EmployeeIds) - { - var employeeSettings = employeesInMainGroup.FirstOrDefault(x => x.EmployeeId == id); - if (employeeSettings != null) - { - _customizeWorkshopEmployeeSettingsRepository.Remove(employeeSettings.id); - } - var entity = new CustomizeWorkshopEmployeeSettings( - new(groupData.FridayPay.FridayPayType, groupData.FridayPay.Value), - new(groupData.OverTimePay.OverTimePayType, groupData.OverTimePay.Value), - new(groupData.BaseYearsPay.BaseYearsPayType, groupData.BaseYearsPay.Value, groupData.BaseYearsPay.PaymentType), - new(groupData.BonusesPay.BonusesPayType, groupData.BonusesPay.Value, groupData.BonusesPay.PaymentType), - new(groupData.NightWorkPay.NightWorkingType, groupData.NightWorkPay.Value), - new(groupData.MarriedAllowance.MarriedAllowanceType, groupData.MarriedAllowance.Value), - new(groupData.ShiftPay.ShiftType, groupData.ShiftPay.ShiftPayType, groupData.ShiftPay.Value), - new(groupData.FamilyAllowance.FamilyAllowanceType, groupData.FamilyAllowance.Value), - new(groupData.LeavePay.LeavePayType, groupData.LeavePay.Value), - new(groupData.InsuranceDeduction.InsuranceDeductionType, groupData.InsuranceDeduction.Value), - new(groupData.FineAbsenceDeduction.FineAbsenceDeductionType, groupData.FineAbsenceDeduction.Value, - groupData.FineAbsenceDeduction.FineAbsenceDayOfWeekCollection - .Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList()), - new(groupData.LateToWork.LateToWorkType, - groupData.LateToWork.LateToWorkTimeFines.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) - .ToList(), groupData.LateToWork.Value), - new(groupData.EarlyExit.EarlyExitType, - groupData.EarlyExit.EarlyExitTimeFines.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)) - .ToList(), groupData.EarlyExit.Value), - id, - groupData.CustomizeWorkshopSettings.WorkshopId, - groupData.Salary, - groupData.id, - shifts.Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)) - .ToList(), - groupData.FridayWork, - groupData.HolidayWork, - groupData.IrregularShift, - groupData.WorkshopShiftStatus, - new(groupData.BreakTime.HasBreakTimeValue, groupData.BreakTime.BreakTimeValue), - command.LeavePermittedDays, - groupData.CustomizeRotatingShifts.Select(x => new CustomizeRotatingShift(x.StartTime, x.EndTime)).ToList(), - groupData.WeeklyOffDays - ); - - _customizeWorkshopEmployeeSettingsRepository.Create(entity); - - } - _customizeWorkshopEmployeeSettingsRepository.SaveChanges(); - - - return op.Succcedded(); - } - - //Edit the Workshop Settings Data - public OperationResult EditWorkshopSetting(EditCustomizeWorkshopSettings command, bool replaceInAllGroups) - { - OperationResult op = new(); - - #region Validation - - if (!_customizeWorkshopSettingsRepository.Exists(x => x.id == command.Id)) - return op.Failed("خطای سیستمی"); - - #endregion - - - var entity = _customizeWorkshopSettingsRepository.Get(command.Id); - if (entity == null) - return op.Failed("چنین آیتمی وجود ندارد"); - - - FridayPay fridayPay = new(command.FridayPay.FridayPayType, command.FridayPay.Value); - OverTimePay overTimePay = new(command.OverTimePay.OverTimePayType, command.OverTimePay.Value); - BaseYearsPay baseYearsPay = new(command.BaseYearsPay.BaseYearsPayType, command.BaseYearsPay.Value, command.BaseYearsPay.PaymentType); - BonusesPay bonusesPay = new(command.BonusesPay.BonusesPayType, command.BonusesPay.Value, command.BonusesPay.PaymentType); - NightWorkPay nightWorkPay = new(command.NightWorkPay.NightWorkingType, command.NightWorkPay.Value); - MarriedAllowance marriedAllowance = new(command.MarriedAllowance.MarriedAllowanceType, command.MarriedAllowance.Value); - ShiftPay shiftPay = new(ShiftType.None, ShiftPayType.None, 0); - FamilyAllowance familyAllowance = new(command.FamilyAllowance.FamilyAllowanceType, command.FamilyAllowance.Value); - LeavePay leavePay = new(command.LeavePay.LeavePayType, command.LeavePay.Value); - InsuranceDeduction insuranceDeduction = new(command.InsuranceDeduction.InsuranceDeductionType, command.InsuranceDeduction.Value); - FineAbsenceDeduction fineAbsenceDeduction = new( - command.FineAbsenceDeduction.FineAbsenceDeductionType, - command.FineAbsenceDeduction.Value, - command.FineAbsenceDeduction.FineAbsenceDayOfWeekViewModels?.Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList() ?? new List() - ); - LateToWork lateToWork = new( - command.LateToWork.LateToWorkType, - command.LateToWork.LateToWorkTimeFinesVewModels?.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) - .ToList() ?? new List() - , command.LateToWork.Value - ); - - EarlyExit earlyExit = new(command.EarlyExit.EarlyExitType, - command.EarlyExit.EarlyExitTimeFinesViewModels?.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)).ToList() ?? new List() - , command.EarlyExit.Value); - - - var groups = _customizeWorkshopGroupSettingsRepository.GetAllGroupsIncludeEmployeeSettingsByWorkshopSettingsId(entity.id); - - using (var transaction = new TransactionScope()) - { - - try - { - entity.Edit(fridayPay, overTimePay, baseYearsPay, bonusesPay, nightWorkPay, marriedAllowance, shiftPay, - familyAllowance, leavePay, insuranceDeduction, - fineAbsenceDeduction, lateToWork, earlyExit, command.FridayWork, command.HolidayWork, - command.BonusesPaysInEndOfMonth, command.LeavePermittedDays, command.BaseYearsPayInEndOfYear, - command.OverTimeThresholdMinute); - - _customizeWorkshopSettingsRepository.SaveChanges(); - var editViewModel = new EditCustomizeWorkshopGroupSettings() - { - - }; - OperationResult result = new OperationResult(); - if (entity.WorkshopShiftStatus == WorkshopShiftStatus.Regular) - { - //foreach (var group in groups) - //{ - // var employeeIds = group.CustomizeWorkshopEmployeeSettingsCollection.Select(x => x.EmployeeId) - // .ToList(); - // group.EditAndOverwriteOnEmployees(group.GroupName,group.Salary,employeeIds,group.FridayPay,group.OverTimePay,group.BaseYearsPay,group.BonusesPay, - // group.ShiftPay,group.NightWorkPay,group.MarriedAllowance,group.FamilyAllowance,group.LeavePay,group.InsuranceDeduction, - // group.FineAbsenceDeduction,); - //} - } - else - { - result = result.Succcedded(); - } - - ChangeAllSettingsGroups(entity, replaceInAllGroups); - - result.Succcedded(); - - - transaction.Complete(); - - } - catch - { - // ignored - } - } - - return string.IsNullOrWhiteSpace(op.Message) ? op.Succcedded() : op; - } - - - - //Edit the Group Settings Data - public OperationResult EditRollCallGroupSetting(EditCustomizeWorkshopGroupSettings command) - { - OperationResult op = new(); - - #region Validation - - if (string.IsNullOrWhiteSpace(command.Name)) - return op.Failed("لطفا نام گروه را وارد کنید"); - - if (string.IsNullOrWhiteSpace(command.Salary)) - return op.Failed("لطفا حقوق مورد نظر خود را وارد کنید"); - - if (!_customizeWorkshopGroupSettingsRepository.Exists(x => x.id == command.Id)) - return op.Failed("چنین ساعت کاری برای گروه وجود ندارد"); - - #endregion - - - var entity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(command.Id); - - FridayPay fridayPay = new(command.FridayPay.FridayPayType, command.FridayPay.Value); - OverTimePay overTimePay = new(command.OverTimePay.OverTimePayType, command.OverTimePay.Value); - BaseYearsPay baseYearsPay = new(command.BaseYearsPay.BaseYearsPayType, command.BaseYearsPay.Value, command.BaseYearsPay.PaymentType); - BonusesPay bonusesPay = new(command.BonusesPay.BonusesPayType, command.BonusesPay.Value, command.BonusesPay.PaymentType); - NightWorkPay nightWorkPay = new(command.NightWorkPay.NightWorkingType, command.NightWorkPay.Value); - MarriedAllowance marriedAllowance = new(command.MarriedAllowance.MarriedAllowanceType, command.MarriedAllowance.Value); - //ShiftPay shiftPay = new(command.ShiftPay.ShiftType, command.ShiftPay.ShiftPayType, command.ShiftPay.Value); - ShiftPay shiftPay = new(ShiftType.None, ShiftPayType.None, 0); - FamilyAllowance familyAllowance = new(command.FamilyAllowance.FamilyAllowanceType, command.FamilyAllowance.Value); - LeavePay leavePay = new(command.LeavePay.LeavePayType, command.LeavePay.Value); - InsuranceDeduction insuranceDeduction = new(command.InsuranceDeduction.InsuranceDeductionType, command.InsuranceDeduction.Value); - FineAbsenceDeduction fineAbsenceDeduction = new( - command.FineAbsenceDeduction.FineAbsenceDeductionType, command.FineAbsenceDeduction.Value, - command.FineAbsenceDeduction.FineAbsenceDayOfWeekViewModels - .Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList() - ); - LateToWork lateToWork = new( - command.LateToWork.LateToWorkType, - command.LateToWork.LateToWorkTimeFinesVewModels.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) - .ToList(), command.LateToWork.Value - ); - EarlyExit earlyExit = new(command.EarlyExit.EarlyExitType, - command.EarlyExit.EarlyExitTimeFinesViewModels.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)) - .ToList(), command.EarlyExit.Value); - - double salary = command.Salary.MoneyToDouble(); - - - bool isChanged; - if (fridayPay == entity.FridayPay && overTimePay == entity.OverTimePay && baseYearsPay == entity.BaseYearsPay && bonusesPay == entity.BonusesPay - && shiftPay == entity.ShiftPay && nightWorkPay == entity.NightWorkPay && marriedAllowance == entity.MarriedAllowance - && familyAllowance == entity.FamilyAllowance && leavePay == entity.LeavePay && insuranceDeduction == entity.InsuranceDeduction - && fineAbsenceDeduction == entity.FineAbsenceDeduction && lateToWork == entity.LateToWork && earlyExit == entity.EarlyExit && command.FridayWork == entity.FridayWork - && command.HolidayWork == entity.HolidayWork && command.IrregularShift == entity.IrregularShift && command.WorkshopShiftStatus == entity.WorkshopShiftStatus) - { - isChanged = false; - } - else - { - isChanged = true; - } - entity.EditAndOverwriteOnEmployees(command.Name, salary, command.EmployeeIds, fridayPay, overTimePay, - baseYearsPay, bonusesPay, shiftPay, nightWorkPay, marriedAllowance, familyAllowance, - leavePay, insuranceDeduction, fineAbsenceDeduction, lateToWork, earlyExit, - command.FridayWork, command.HolidayWork, isChanged, command.LeavePermittedDays); - - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - - return op.Succcedded(); - } - - //Edit the Employee settings and change the 'IsChanged' bool to true. - public OperationResult EditRollCallEmployeeSettings(EditCustomizeEmployeeSettings command) - { - OperationResult op = new(); - var entity = _customizeWorkshopEmployeeSettingsRepository.Get(command.Id); - - #region Validation - - if (entity == null) - return op.Failed("چنین پرسنلی وجود ندارد"); - - #endregion - - FridayPay fridayPay = new(command.FridayPay.FridayPayType, command.FridayPay.Value); - OverTimePay overTimePay = new(command.OverTimePay.OverTimePayType, command.OverTimePay.Value); - BaseYearsPay baseYearsPay = new(command.BaseYearsPay.BaseYearsPayType, command.BaseYearsPay.Value, command.BaseYearsPay.PaymentType); - BonusesPay bonusesPay = new(command.BonusesPay.BonusesPayType, command.BonusesPay.Value, command.BonusesPay.PaymentType); - NightWorkPay nightWorkPay = new(command.NightWorkPay.NightWorkingType, command.NightWorkPay.Value); - MarriedAllowance marriedAllowance = new(command.MarriedAllowance.MarriedAllowanceType, command.MarriedAllowance.Value); - // ShiftPay shiftPay = new(command.ShiftPay.ShiftType, command.ShiftPay.ShiftPayType, command.ShiftPay.Value); - ShiftPay shiftPay = new(ShiftType.None, ShiftPayType.None, 0); - FamilyAllowance familyAllowance = new(command.FamilyAllowance.FamilyAllowanceType, command.FamilyAllowance.Value); - LeavePay leavePay = new(command.LeavePay.LeavePayType, command.LeavePay.Value); - InsuranceDeduction insuranceDeduction = new(command.InsuranceDeduction.InsuranceDeductionType, command.InsuranceDeduction.Value); - FineAbsenceDeduction fineAbsenceDeduction = new( - command.FineAbsenceDeduction.FineAbsenceDeductionType, command.FineAbsenceDeduction.Value, - command.FineAbsenceDeduction.FineAbsenceDayOfWeekViewModels - .Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList() - ); - LateToWork lateToWork = new( - command.LateToWork.LateToWorkType, - command.LateToWork.LateToWorkTimeFinesVewModels.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) - .ToList(), command.LateToWork.Value - ); - EarlyExit earlyExit = new(command.EarlyExit.EarlyExitType, - command.EarlyExit.EarlyExitTimeFinesViewModels.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)) - .ToList(), command.EarlyExit.Value); - - - double salary = command.Salary.MoneyToDouble(); - - - bool isChanged; - if (fridayPay == entity.FridayPay && overTimePay == entity.OverTimePay && baseYearsPay == entity.BaseYearsPay && bonusesPay == entity.BonusesPay - && shiftPay == entity.ShiftPay && nightWorkPay == entity.NightWorkPay && marriedAllowance == entity.MarriedAllowance - && familyAllowance == entity.FamilyAllowance && leavePay == entity.LeavePay && insuranceDeduction == entity.InsuranceDeduction - && fineAbsenceDeduction == entity.FineAbsenceDeduction && lateToWork == entity.LateToWork && earlyExit == entity.EarlyExit && command.FridayWork == entity.FridayWork - && command.HolidayWork == entity.HolidayWork) - { - isChanged = false; - } - else - { - isChanged = true; - } - - //change employee data manually. It changes the 'IsChanged' property to true. - entity.EditEmployees(salary, fridayPay, overTimePay, baseYearsPay, - bonusesPay, nightWorkPay, marriedAllowance, shiftPay, familyAllowance, leavePay, - insuranceDeduction, fineAbsenceDeduction, lateToWork, earlyExit, command.FridayWork, command.HolidayWork, command.IrregularShift, isChanged, command.LeavePermittedDays); - - - _customizeWorkshopEmployeeSettingsRepository.SaveChanges(); - return op.Succcedded(); - } - - public OperationResult RemoveGroupSettings(long groupSettingsId) - { - OperationResult op = new OperationResult(); - var entity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(groupSettingsId); - if (entity.CustomizeWorkshopEmployeeSettingsCollection.Any()) - return op.Failed("نمیتوانید گروهی که پرسنل در آن وجود دارد را حذف کنید"); - - _customizeWorkshopGroupSettingsRepository.Remove(entity.id); - return op.Succcedded(); - } - #endregion - - #region Queries - - - public List GetChangedEmployeeSettingsByGroupSettingsId(long groupSettingsId) - { - return _customizeWorkshopGroupSettingsRepository.GetShiftChangedEmployeeSettingsByGroupSettingsId( - groupSettingsId); - } - - - // It will Get the Workshop Settings with its groups and the employees of groups. - public CustomizeWorkshopSettingsViewModel GetWorkshopSettingsByWorkshopId(long workshopId, AuthViewModel auth) - { - - - #region Validation - - if (workshopId is < 1) - return new(); - - #endregion - - var record = _customizeWorkshopSettingsRepository.GetWorkshopSettingsByWorkshopId(workshopId, auth); - - return record; - } - - public CustomizeWorkshopEmployeeSettingsViewModel GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(long workshopId, long employeeId) - { - var entity = - _customizeWorkshopEmployeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(workshopId, employeeId); - if (entity == null) - return null; - - string employeeFullName = _employeeRepository.GetIgnoreQueryFilter(entity.EmployeeId).FullName; - return new CustomizeWorkshopEmployeeSettingsViewModel() - { - EmployeeId = entity.EmployeeId, - Id = entity.id, - IsSettingChanged = entity.IsSettingChanged, - IsShiftChanged = entity.IsShiftChanged, - Name = entity.CustomizeWorkshopGroupSettings.GroupName, - EmployeeFullName = employeeFullName, - Salary = entity.Salary, - BreakTime = entity.BreakTime, - WorkshopShiftStatus = entity.WorkshopShiftStatus, - IrregularShift = entity.IrregularShift, - RollCallWorkshopShifts = entity.CustomizeWorkshopEmployeeSettingsShifts.Select(x => - new CustomizeWorkshopShiftViewModel() - { - EndTime = x.EndTime.ToString("HH:mm"), - Placement = x.Placement, - StartTime = x.StartTime.ToString("HH:mm") - }).ToList(), - FridayWork = entity.FridayWork, - HolidayWork = entity.HolidayWork, - CustomizeRotatingShiftsViewModels = entity.CustomizeRotatingShifts.Select(x => new CustomizeRotatingShiftsViewModel() - { - StartTime = x.StartTime.ToString("HH:mm"), - EndTime = x.EndTime.ToString("HH:mm") - }).ToList() - - }; - } - - public List GetEmployeeSettingsByGroupSettingsId(long groupSettingsId) - { - - List result = _customizeWorkshopGroupSettingsRepository.GetEmployeeSettingsByGroupSettingsId(groupSettingsId); - - if (result == null) - return new(); - - return result; - - } - - public CustomizeWorkshopSettingsViewModel GetWorkshopIncludeGroupsByWorkshopId(long workshopId) - { - return _customizeWorkshopSettingsRepository.GetWorkshopIncludeGroupsByWorkshopId(workshopId); - } - - - public List GetEmployeesWithoutGroup(long rollCallWorkshopSettingId) - { - return _customizeWorkshopGroupSettingsRepository.GetEmployeesWithoutGroup(rollCallWorkshopSettingId); - } - public List GetEmployeesWithoutGroupByWorkshopId(long workshopId) - { - return _customizeWorkshopGroupSettingsRepository.GetEmployeesWithoutGroupByWorkshopId(workshopId); - } - - - - public CustomizeWorkshopSettingsViewModel GetWorkshopSettingsByWorkshopIdForAdmin(long workshopId) - { - return _customizeWorkshopSettingsRepository.GetWorkshopSettingsByWorkshopIdForAdmin(workshopId); - - } - public EditCustomizeWorkshopSettings GetWorkshopSettingsDetails(long workshopId) - { - return _customizeWorkshopSettingsRepository.GetWorkshopSettingsDetails(workshopId); - } - - public EditCustomizeWorkshopGroupSettings GetCustomizeWorkshopGroupSettingsDetails(long groupId) - { - return _customizeWorkshopGroupSettingsRepository.GetCustomizeWorkshopGroupSettingsDetails(groupId); - } - - public EditCustomizeWorkshopSettings GetSimpleWorkshopSettings(long workshopId) - { - return _customizeWorkshopSettingsRepository.GetSimpleWorkshopSettings(workshopId); - } - - public EditCustomizeEmployeeSettings GetCustomizeEmployeeSettingsDetails(long customizeEmployeeId) - { - return _customizeWorkshopEmployeeSettingsRepository.GetCustomizeEmployeeSettingsDetails(customizeEmployeeId); - } - - public List GetShiftChangesGroupAndEmployees(long customizeWorkshopSettingsId) - { - return _customizeWorkshopSettingsRepository.GetShiftChangesGroupAndEmployees(customizeWorkshopSettingsId); - } - - public List GetEmployeeSettingsByWorkshopId(long workshopId) - { - return _customizeWorkshopEmployeeSettingsRepository.GetEmployeeSettingsByWorkshopId(workshopId); - } - - public CustomizeWorkshopGroupSettingsViewModel GetEmployeesGroupSettingsByEmployeeId(long employeeId, long workshopId) - { - return _customizeWorkshopGroupSettingsRepository.GetEmployeesGroupSettingsByEmployeeId(employeeId, workshopId); - } - - public bool HasAnyEmployeeWithoutGroup(long workshopId) - { - return _customizeWorkshopGroupSettingsRepository.HasAnyEmployeeWithoutGroup(workshopId); - } - public OperationResult> ValidateReCalculateValueForGroupEdit(List commands, - long workshopId) - { - var operationResult = new OperationResult>(); - bool isSuccess = true; - List employeeIdsHasCheckout = []; - foreach (var command in commands) - { - var fromDateGr = command.FromDate.ToGeorgianDateTime(); - if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == command.EmployeeId && fromDateGr <= x.ContractEnd)) - { - isSuccess = false; - employeeIdsHasCheckout.Add(command.EmployeeId); - } - - if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == command.EmployeeId && fromDateGr <= x.ContractEnd)) - { - isSuccess = false; - employeeIdsHasCheckout.Add(command.EmployeeId); - } - - if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == command.EmployeeId && fromDateGr <= x.ContractEnd)) - { - isSuccess = false; - employeeIdsHasCheckout.Add(command.EmployeeId); - } - } - - employeeIdsHasCheckout = employeeIdsHasCheckout.Distinct().ToList(); - return isSuccess ? - operationResult.Succcedded(employeeIdsHasCheckout) - : - operationResult.Failed("پرسنل هایی دارای فیش هستند لطفا نسبت به تعیین تکلیف این ها اقدام نمایید", employeeIdsHasCheckout); - } - public bool CheckEmployeeShiftHasChanged(EditCustomizeEmployeeSettings command) - { - return _customizeWorkshopEmployeeSettingsRepository.CheckEmployeeShiftHasChanged(command); - } - - private OperationResult CreateGeneralGroup(CustomizeWorkshopSettings entity) - { - var op = new OperationResult(); - - if (_customizeWorkshopGroupSettingsRepository.Exists(x => x.CustomizeWorkshopSettingId == entity.id && x.MainGroup)) - { - return op.Succcedded(); - } - - try - { - var shifts = - entity.CustomizeWorkshopSettingsShifts.Select(x => - new CustomizeWorkshopGroupSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); - var irregularShift = new IrregularShift(new TimeOnly(), new TimeOnly(), WorkshopIrregularShifts.None); - - var customizeWorkshopGroupSettings = new CustomizeWorkshopGroupSettings().CreateMainGroup(entity.FridayPay, entity.OverTimePay, - entity.BaseYearsPay, entity.BonusesPay, entity.ShiftPay, entity.NightWorkPay, entity.MarriedAllowance, - entity.FamilyAllowance, entity.LeavePay, entity.InsuranceDeduction, entity.FineAbsenceDeduction, - entity.LateToWork, entity.EarlyExit, shifts, entity.FridayWork, entity.HolidayWork, - irregularShift, [], entity.WorkshopShiftStatus, entity.id, new BreakTime(false, new TimeOnly()), entity.LeavePermittedDays); - - _customizeWorkshopGroupSettingsRepository.Create(customizeWorkshopGroupSettings); - - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - - var employeesHasSettings = _customizeWorkshopEmployeeSettingsRepository - .GetEmployeeSettingNotInMainGroup(entity.WorkshopId).Select(x => x.EmployeeId); - - var rollCallEmployeeViewModels = _rollCallEmployeeApplication.GetByWorkshopId(entity.WorkshopId).Where(x => !employeesHasSettings.Contains(x.EmployeeId)); - - foreach (var rollCallEmployeeViewModel in rollCallEmployeeViewModels) - { - customizeWorkshopGroupSettings.AddEmployeeSettingToGroupWithGroupData( - rollCallEmployeeViewModel.EmployeeId, entity.WorkshopId); - } - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - return op.Succcedded(); - } - catch (Exception e) - { - return op.Failed(e.Message); - } - - - } - - private OperationResult ChangeAllGroupsShiftsWithEmployees(CustomizeWorkshopSettings entity, bool replaceChangedGroups) - { - var op = new OperationResult(); - var groupSettings = _customizeWorkshopGroupSettingsRepository.GetAllGroupsIncludeEmployeeSettingsByWorkshopSettingsId(entity.id); - - if (!replaceChangedGroups) - { - groupSettings = groupSettings.Where(x => !x.IsShiftChange).ToList(); - } - - var groupShifts = entity.CustomizeWorkshopSettingsShifts - .Select(x => new CustomizeWorkshopGroupSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); - - - - var irregularShift = new IrregularShift(new TimeOnly(), new TimeOnly(), WorkshopIrregularShifts.None); - foreach (var customizeWorkshopGroupSettings in groupSettings) - { - customizeWorkshopGroupSettings.EditSimpleAndOverwriteOnAllEmployees(customizeWorkshopGroupSettings.GroupName, - groupShifts, entity.WorkshopShiftStatus, irregularShift, new BreakTime(false, new TimeOnly()), - false, entity.FridayWork, entity.HolidayWork, []); - } - _customizeWorkshopGroupSettingsRepository.SaveChanges(); - return op.Succcedded(); - } - private void ChangeAllSettingsGroups(CustomizeWorkshopSettings customizeWorkshopSettings, bool replaceInAllGroups) - { - var op = new OperationResult(); - var groupSettings = _customizeWorkshopGroupSettingsRepository.GetAllGroupsIncludeEmployeeSettingsByWorkshopSettingsId(customizeWorkshopSettings.id); - - if (!replaceInAllGroups) - { - groupSettings = groupSettings.Where(x => !x.IsSettingChange).ToList(); - } - - - - foreach (var groupSetting in groupSettings) - { - groupSetting.EditAndOverwriteOnAllEmployees(groupSetting.GroupName, groupSetting.Salary, - customizeWorkshopSettings.FridayPay, - customizeWorkshopSettings.OverTimePay, customizeWorkshopSettings.BaseYearsPay, - customizeWorkshopSettings.BonusesPay, customizeWorkshopSettings.ShiftPay, - customizeWorkshopSettings.NightWorkPay, customizeWorkshopSettings.MarriedAllowance, - customizeWorkshopSettings.FamilyAllowance, customizeWorkshopSettings.LeavePay, - customizeWorkshopSettings.InsuranceDeduction, customizeWorkshopSettings.FineAbsenceDeduction, - customizeWorkshopSettings.LateToWork, customizeWorkshopSettings.EarlyExit, - customizeWorkshopSettings.FridayWork, customizeWorkshopSettings.HolidayWork, replaceInAllGroups, - customizeWorkshopSettings.LeavePermittedDays); - } - _customizeWorkshopSettingsRepository.SaveChanges(); - } - - #endregion + private readonly ICustomizeWorkshopSettingsRepository _customizeWorkshopSettingsRepository = customizeWorkshopSettingsRepository; + private readonly ICustomizeWorkshopGroupSettingsRepository _customizeWorkshopGroupSettingsRepository = customizeWorkshopGroupSettingsRepository; + private readonly ICustomizeWorkshopEmployeeSettingsRepository _customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository; + private readonly IAuthHelper _authHelper = authHelper; + private readonly IEmployeeRepository _employeeRepository = employeeRepository; + private readonly IPasswordHasher _passwordHasher = passwordHasher; + private readonly ICameraAccountApplication _cameraAccountApplication = cameraAccountApplication; + private readonly IRollCallEmployeeApplication _rollCallEmployeeApplication = rollCallEmployeeApplication; + private readonly IRollCallApplication _rollCallApplication = rollCallAppllication; + private readonly ICheckoutRepository _checkoutRepository = checkoutRepository; + private readonly ICustomizeCheckoutRepository _customizeCheckoutRepository = customizeCheckoutRepository; + private readonly ICustomizeCheckoutTempRepository _customizeCheckoutTempRepository = customizeCheckoutTempRepository; + + #region RollCallShifts + + //Create workshop settings + public OperationResult CreateWorkshopSettings(CreateCustomizeWorkshopSettings command) + { + OperationResult op = new(); + var workshopId = _passwordHasher.SlugDecrypt(_authHelper.GetWorkshopSlug()); + //تبدیل شیفت های ویو مدل به انتیتی + List shiftCollection = new List(); + if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + #region Validation + if (command.ShiftsList.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) + return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); + try + { + shiftCollection = + command.ShiftsList.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 CustomizeWorkshopSettingsShift(start, end, x.Placement); + + }).ToList(); + } + catch (InvalidDataException e) + { + + return op.Failed(e.Message); + } + if (workshopId < 1) + { + return op.Failed("خطای سیستمی"); + } + DateTime day = DateTime.Now; + DateTime previousEnd = new DateTime(); + var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); + + shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); + + foreach (var shift in shiftCollection) + { + (DateTime start, DateTime end, ShiftPlacement placement) newShift = + new() + { + placement = shift.Placement, + start = new DateTime(DateOnly.FromDateTime(day), shift.StartTime), + end = new DateTime(DateOnly.FromDateTime(day), shift.EndTime) + + + }; + + if (previousEnd != new DateTime()) + { + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) + { + newShift.start = newShift.start.AddDays(1); + } + } + while (newShift.start >= newShift.end) + { + newShift.end = newShift.end.AddDays(1); + } + finalShiftList.Add(newShift); + previousEnd = newShift.end; + } + + var firstShiftStart = finalShiftList.FirstOrDefault(x => x.placement == ShiftPlacement.First).start; + var lastShiftEnd = finalShiftList.OrderByDescending(x => x.placement).FirstOrDefault().end; + if (firstShiftStart.AddDays(1) < lastShiftEnd) + return op.Failed("بازه زمانی کارگاه نامعتبر است"); + var total = finalShiftList.Sum(x => (x.end - x.start).TotalHours); + if (total >= 24) + { + return op.Failed("بازه زمانی کارگاه نمیتواند بیشتر از 24 ساعت باشد"); + } + #endregion + } + else + { + command.ShiftsList = []; + shiftCollection = []; + + } + + var offDays = command.OffDays.Select(x => new WeeklyOffDay(x)).ToList(); + + var record = new CustomizeWorkshopSettings(workshopId, shiftCollection, command.LeavePermittedDays, + command.WorkshopShiftStatus, command.HolidayWork, offDays); + using (var transaction = new TransactionScope()) + { + + try + { + _customizeWorkshopSettingsRepository.Create(record); + _customizeWorkshopSettingsRepository.SaveChanges(); + + OperationResult result = new OperationResult(); + + result = command.WorkshopShiftStatus == WorkshopShiftStatus.Regular ? CreateGeneralGroup(record) : result.Succcedded(); + + if (result.IsSuccedded) + { + transaction.Complete(); + } + else + { + op = result; + transaction.Dispose(); + } + } + catch + { + transaction.Dispose(); + // ignored + } + } + + return string.IsNullOrWhiteSpace(op.Message) ? op.Succcedded() : op; + + } + + + //create group settings with workshopSettingsId. + public OperationResult CreateGroupSettingsByRollCallWorkshopSettingId(CreateCustomizeWorkshopGroupSettings command) + { + OperationResult op = new(); + CustomizeWorkshopSettings workshopSettings = + _customizeWorkshopSettingsRepository.Get(command.CustomizeWorkshopSettingId); + List shiftCollection = new List(); + + ICollection customizeRotatingShifts = []; + + #region validation + + if (workshopSettings == null) + return op.Failed("خطای سیستمی"); + + if (string.IsNullOrWhiteSpace(command.Name)) + return op.Failed("لطفا نام گروه را وارد کنید"); + + if (string.IsNullOrWhiteSpace(command.Salary)) + return op.Failed("لطفا حقوق مورد نظر خود را وارد کنید"); + + if (!_customizeWorkshopSettingsRepository.Exists(x => x.id == command.CustomizeWorkshopSettingId)) + return op.Failed("چنین ساعت کاری برای کارگاهی وجود ندارد"); + + if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + if (command.ShiftViewModel.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) + return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); + try + { + shiftCollection = + 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 CustomizeWorkshopGroupSettingsShift(start, end, x.Placement); + + }).ToList(); + } + catch (InvalidDataException e) + { + + return op.Failed(e.Message); + } + DateTime previousEnd = new DateTime(); + var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); + + shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); + + foreach (var shift in shiftCollection) + { + (DateTime start, DateTime end, ShiftPlacement placement) newShift = + new() + { + placement = shift.Placement, + start = new DateTime(DateOnly.MinValue, shift.StartTime), + end = new DateTime(DateOnly.MinValue, shift.EndTime) + + + }; + + if (previousEnd != new DateTime()) + { + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) + { + newShift.start = newShift.start.AddDays(1); + } + } + while (newShift.start >= newShift.end) + { + newShift.end = newShift.end.AddDays(1); + } + finalShiftList.Add(newShift); + previousEnd = newShift.end; + } + //var firstWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MinBy(x => x.Placement).StartTime; + //var lastWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MaxBy(x => x.Placement).EndTime; + + //var startDateTime = new DateTime(DateOnly.MinValue, firstWorkshopTimeShift); + //var lastDateTime = new DateTime(DateOnly.MinValue, lastWorkshopTimeShift); + //if (lastDateTime < startDateTime) + //{ + // lastDateTime = lastDateTime.AddDays(1); + //} + + //var lastGroupShift = finalShiftList.MaxBy(x => x.placement).end; + //var firstGroupShift = finalShiftList.MinBy(x => x.placement).start; + //if (lastDateTime < lastGroupShift || firstGroupShift < startDateTime) + //{ + // return op.Failed("ساعت کاری گروه باید بین ساعت کاری کارگاه باشد"); + //} + } + else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) + { + var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); + + var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); + + if (irregularShiftEndTime < irregularShiftStartTime) + { + irregularShiftEndTime = irregularShiftEndTime.AddDays(1); + } + + switch (command.IrregularShift.WorkshopIrregularShifts) + { + case WorkshopIrregularShifts.TwelveThirtySix: + + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + case WorkshopIrregularShifts.TwelveTwentyFour: + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + } + } + else + { + if (command.CustomizeRotatingShiftsViewModels.Count == 1) + { + return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); + } + customizeRotatingShifts = command.CustomizeRotatingShiftsViewModels.Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))).ToList(); + } + + #endregion + + var breakTime = new BreakTime(command.BreakTime.HasBreakTimeValue, command.BreakTime.BreakTimeValue); + + double salary = command.Salary.MoneyToDouble(); + + var weeklyOffDays = command.OffDayOfWeeks.Select(x => new WeeklyOffDay(x)).ToList(); + + var entity = new CustomizeWorkshopGroupSettings(command.Name, salary, command.CustomizeWorkshopSettingId, shiftCollection, workshopSettings.FridayPay, workshopSettings.OverTimePay, + workshopSettings.BaseYearsPay, workshopSettings.BonusesPay, workshopSettings.NightWorkPay, workshopSettings.MarriedAllowance, + workshopSettings.ShiftPay, workshopSettings.FamilyAllowance, workshopSettings.LeavePay, workshopSettings.InsuranceDeduction, workshopSettings.FineAbsenceDeduction, + workshopSettings.LateToWork, workshopSettings.EarlyExit, + command.HolidayWork, breakTime, command.WorkshopShiftStatus, command.IrregularShift, command.LeavePermittedDays, customizeRotatingShifts, workshopSettings.WeeklyOffDays); + + _customizeWorkshopGroupSettingsRepository.Create(entity); + + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + return op.Succcedded(); + } + + //Create Employee Settings with Group data. It will Replace the Group data (such as salary, shifts and ...) on Employee settings On creation. + public OperationResult CreateEmployeesSettingsAndSetChanges(EditCustomizeEmployeeSettings command) + { + var op = new OperationResult(); + var customizeWorkshopGroupSettings = _customizeWorkshopGroupSettingsRepository.Get(command.GroupId); + if (customizeWorkshopGroupSettings == null) + { + return op.Failed("گروه انتخاب شده نا معتبر است"); + } + + if (_customizeWorkshopEmployeeSettingsRepository + .Exists(x => x.WorkshopId == command.WorkshopId && command.EmployeeIds.Contains(x.EmployeeId))) + { + foreach (var employeeId in command.EmployeeIds) + { + _customizeWorkshopEmployeeSettingsRepository.RemoveByWorkshopIdAndEmployeeId(command.WorkshopId, employeeId); + } + } + + if (customizeWorkshopGroupSettings.MainGroup) + { + var createDefaultEmployee = CreateEmployeeSettings(command); + return createDefaultEmployee; + } + + + List shiftCollection = new List(); + List rotatingShift = []; + var isChanged = false; + #region validation + + var commandOffDayHashSet = command.WeeklyOffDays.ToHashSet(); + var groupOffDayHashSet = customizeWorkshopGroupSettings.WeeklyOffDays.Select(x => x.DayOfWeek).ToHashSet(); + + if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + if (command.ShiftViewModel.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) + return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); + try + { + shiftCollection = + 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(); + } + catch (InvalidDataException e) + { + + return op.Failed(e.Message); + } + DateTime previousEnd = new DateTime(); + var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); + + shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); + + foreach (var shift in shiftCollection) + { + (DateTime start, DateTime end, ShiftPlacement placement) newShift = + new() + { + placement = shift.Placement, + start = new DateTime(DateOnly.MinValue, shift.StartTime), + end = new DateTime(DateOnly.MinValue, shift.EndTime) + + + }; + + if (previousEnd != new DateTime()) + { + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) + { + newShift.start = newShift.start.AddDays(1); + } + } + while (newShift.start >= newShift.end) + { + newShift.end = newShift.end.AddDays(1); + } + finalShiftList.Add(newShift); + previousEnd = newShift.end; + } + //var firstWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MinBy(x => x.Placement).StartTime; + //var lastWorkshopTimeShift = workshopSettings.CustomizeWorkshopSettingsShifts.MaxBy(x => x.Placement).EndTime; + + //var startDateTime = new DateTime(DateOnly.MinValue, firstWorkshopTimeShift); + //var lastDateTime = new DateTime(DateOnly.MinValue, lastWorkshopTimeShift); + //if (lastDateTime < startDateTime) + //{ + // lastDateTime = lastDateTime.AddDays(1); + //} + + //var lastGroupShift = finalShiftList.MaxBy(x => x.placement).end; + //var firstGroupShift = finalShiftList.MinBy(x => x.placement).start; + //if (lastDateTime < lastGroupShift || firstGroupShift < startDateTime) + //{ + // return op.Failed("ساعت کاری گروه باید بین ساعت کاری کارگاه باشد"); + //} + + + + if (shiftCollection.All(x => customizeWorkshopGroupSettings.CustomizeWorkshopGroupSettingsShifts.Any(y => x.Equals(y))) + && command.WorkshopShiftStatus == customizeWorkshopGroupSettings.WorkshopShiftStatus && command.HolidayWork == customizeWorkshopGroupSettings.HolidayWork && + command.BreakTime == customizeWorkshopGroupSettings.BreakTime &&commandOffDayHashSet.SetEquals(groupOffDayHashSet)) + { + isChanged = false; + } + + else + { + isChanged = true; + } + } + else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) + { + var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); + + var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); + + if (irregularShiftEndTime < irregularShiftStartTime) + { + irregularShiftEndTime = irregularShiftEndTime.AddDays(1); + } + + switch (command.IrregularShift.WorkshopIrregularShifts) + { + case WorkshopIrregularShifts.TwelveThirtySix: + + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + case WorkshopIrregularShifts.TwelveTwentyFour: + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + } + if (command.WorkshopShiftStatus == customizeWorkshopGroupSettings.WorkshopShiftStatus && command.BreakTime == customizeWorkshopGroupSettings.BreakTime && + command.IrregularShift == customizeWorkshopGroupSettings.IrregularShift && commandOffDayHashSet.SetEquals(groupOffDayHashSet) && + command.HolidayWork == customizeWorkshopGroupSettings.HolidayWork) + { + isChanged = false; + } + else + { + isChanged = true; + } + } + else + { + if (command.CustomizeRotatingShifts.Count == 1) + { + return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); + } + rotatingShift = command.CustomizeRotatingShifts + .Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))) + .ToList(); + + if (rotatingShift.All(x => customizeWorkshopGroupSettings.CustomizeRotatingShifts.Any(y => x.Equals(y))) + && command.WorkshopShiftStatus == customizeWorkshopGroupSettings.WorkshopShiftStatus && + commandOffDayHashSet.SetEquals(groupOffDayHashSet) && + command.HolidayWork == customizeWorkshopGroupSettings.HolidayWork && command.BreakTime == customizeWorkshopGroupSettings.BreakTime) + { + isChanged = false; + } + + else + { + isChanged = true; + } + } + + #endregion + + var breakTime = new BreakTime(command.BreakTime.HasBreakTimeValue, command.BreakTime.BreakTimeValue); + + + + + var entity = new CustomizeWorkshopEmployeeSettings(customizeWorkshopGroupSettings.FridayPay, customizeWorkshopGroupSettings.OverTimePay, + customizeWorkshopGroupSettings.BaseYearsPay, customizeWorkshopGroupSettings.BonusesPay, customizeWorkshopGroupSettings.NightWorkPay, customizeWorkshopGroupSettings.MarriedAllowance, + customizeWorkshopGroupSettings.ShiftPay, customizeWorkshopGroupSettings.FamilyAllowance, customizeWorkshopGroupSettings.LeavePay, customizeWorkshopGroupSettings.InsuranceDeduction, customizeWorkshopGroupSettings.FineAbsenceDeduction, + customizeWorkshopGroupSettings.LateToWork, customizeWorkshopGroupSettings.EarlyExit, command.EmployeeIds.First(), command.WorkshopId, customizeWorkshopGroupSettings.Salary, command.GroupId, + shiftCollection, command.HolidayWork, command.IrregularShift, command.WorkshopShiftStatus, breakTime, command.LeavePermittedDays, rotatingShift, customizeWorkshopGroupSettings.WeeklyOffDays); + + _customizeWorkshopEmployeeSettingsRepository.Create(entity); + + entity.SimpleEdit(shiftCollection, command.IrregularShift, command.WorkshopShiftStatus, command.BreakTime, isChanged, command.HolidayWork, rotatingShift, customizeWorkshopGroupSettings.WeeklyOffDays.ToList()); + + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + return op.Succcedded(); + + + + + } + + public OperationResult EditWorkshopSettingShifts(List shiftViewModels, long customizeWorkshopSettingsId, + WorkshopShiftStatus workshopShiftStatus, HolidayWork holidayWork, List weeklyOffDays) + { + OperationResult op = new OperationResult(); + var entity = _customizeWorkshopSettingsRepository.Get(customizeWorkshopSettingsId); + if (entity == null) + return op.Failed("چنین آیتمی وجود ندارد"); + + //تبدیل شیفت های ویو مدل به انتیتی + List shiftCollection = []; + + #region Validation + if (workshopShiftStatus == WorkshopShiftStatus.Regular) + { + try + { + shiftCollection = + shiftViewModels.Select(x => + { + var placement = x.Placement switch + { + ShiftPlacement.First => "اول", + ShiftPlacement.Second => "دوم", + ShiftPlacement.Third => "سوم", + _ => throw new ArgumentOutOfRangeException() + }; + 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 CustomizeWorkshopSettingsShift(start, end, x.Placement); + + }).ToList(); + } + catch (InvalidDataException e) + { + + return op.Failed(e.Message); + } + + DateTime day = DateTime.Now; + DateTime previousEnd = new DateTime(); + var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); + + shiftCollection = shiftCollection.OrderBy(x => x.Placement).ToList(); + + foreach (var shift in shiftCollection) + { + (DateTime start, DateTime end, ShiftPlacement placement) newShift = + new() + { + placement = shift.Placement, + start = new DateTime(DateOnly.FromDateTime(day), shift.StartTime), + end = new DateTime(DateOnly.FromDateTime(day), shift.EndTime) + + + }; + + if (previousEnd != new DateTime()) + { + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) + { + newShift.start = newShift.start.AddDays(1); + } + } + while (newShift.start >= newShift.end) + { + newShift.end = newShift.end.AddDays(1); + } + finalShiftList.Add(newShift); + previousEnd = newShift.end; + } + + var firstShiftStart = finalShiftList.FirstOrDefault(x => x.placement == ShiftPlacement.First).start; + var lastShiftEnd = finalShiftList.OrderByDescending(x => x.placement).FirstOrDefault().end; + if (firstShiftStart.AddDays(1) < lastShiftEnd) + return op.Failed("بازه زمانی کارگاه نامعتبر است"); + var total = finalShiftList.Sum(x => (x.end - x.start).TotalHours); + if (total >= 24) + { + return op.Failed("بازه زمانی کارگاه نمیتواند بیشتر از 24 ساعت باشد"); + } + } + + #endregion + + var offDays = weeklyOffDays.Select(x => new WeeklyOffDay(x)).ToList(); + + using var transActionScope = new TransactionScope(); + entity.ChangeWorkshopShifts(shiftCollection, workshopShiftStatus, holidayWork, offDays); + + + //op = ChangeAllGroupsShiftsWithEmployees(entity, replaceChangedGroups); + //if (!op.IsSuccedded) + //{ + // return op; + //} + _customizeWorkshopSettingsRepository.SaveChanges(); + + if (!(_customizeWorkshopGroupSettingsRepository.Exists(x => x.CustomizeWorkshopSettingId == entity.id && x.MainGroup)) && entity.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + var operationResult = CreateGeneralGroup(entity); + if (!operationResult.IsSuccedded) + return operationResult; + } + transActionScope.Complete(); + return op.Succcedded(); + } + public OperationResult EditSimpleRollCallGroupSetting(EditCustomizeWorkshopGroupSettings command, + List reCalculateCommand) + { + OperationResult op = new(); + + #region Validation + + if (string.IsNullOrWhiteSpace(command.Name)) + return op.Failed("لطفا نام گروه را وارد کنید"); + + if (!_customizeWorkshopGroupSettingsRepository.Exists(x => x.id == command.Id)) + return op.Failed("چنین ساعت کاری برای گروه وجود ندارد"); + + #endregion + + + var entity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(command.Id); + + var workshopSettings = _customizeWorkshopSettingsRepository.Get(entity.CustomizeWorkshopSettingId); + + //var employeeIds = command.IsShiftChanged ? entity.CustomizeWorkshopEmployeeSettingsCollection + // .Select(x => x.id).ToList() : entity.CustomizeWorkshopEmployeeSettingsCollection.Where(x => !x.IsShiftChanged) + // .Select(x => x.id).ToList(); + + + var groupSettingsShifts = new List(); + ICollection rotatingShift = []; + bool isChanged; + + var commandOffDayHashSet = command.OffDayOfWeeks.ToHashSet(); + var workshopOffDayHashSet = workshopSettings.WeeklyOffDays.Select(x => x.DayOfWeek).ToHashSet(); + + if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + + groupSettingsShifts = command.ShiftViewModel.Select(x => + { + if (!TimeOnly.TryParseExact(x.StartTime, "HH:mm", out TimeOnly start)) + throw new InvalidDataException(); + if (!TimeOnly.TryParseExact(x.EndTime, "HH:mm", out TimeOnly end)) + throw new InvalidDataException(); + + return new CustomizeWorkshopGroupSettingsShift(start, end, x.Placement); + + }).ToList(); + + if (groupSettingsShifts.All(x => workshopSettings.CustomizeWorkshopSettingsShifts.Any(y => x.Equals(y))) + && command.WorkshopShiftStatus == workshopSettings.WorkshopShiftStatus && commandOffDayHashSet.SetEquals(workshopOffDayHashSet) && + command.HolidayWork == workshopSettings.HolidayWork && + command.BreakTime == workshopSettings.BreakTime) + { + isChanged = false; + } + else + { + isChanged = true; + } + } + else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) + { + var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); + + var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); + + if (irregularShiftEndTime < irregularShiftStartTime) + { + irregularShiftEndTime = irregularShiftEndTime.AddDays(1); + } + + switch (command.IrregularShift.WorkshopIrregularShifts) + { + case WorkshopIrregularShifts.TwelveThirtySix: + + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + case WorkshopIrregularShifts.TwelveTwentyFour: + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + } + if (command.WorkshopShiftStatus == workshopSettings.WorkshopShiftStatus && command.BreakTime == workshopSettings.BreakTime + && commandOffDayHashSet.SetEquals(workshopOffDayHashSet) && + command.HolidayWork == workshopSettings.HolidayWork) + { + isChanged = false; + } + else + { + isChanged = true; + } + } + else + { + if (command.CustomizeRotatingShiftsViewModels.Count == 1) + { + return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); + } + + rotatingShift = command.CustomizeRotatingShiftsViewModels + .Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))).ToList(); + if (command.WorkshopShiftStatus == workshopSettings.WorkshopShiftStatus && command.BreakTime == workshopSettings.BreakTime + && commandOffDayHashSet.SetEquals(workshopOffDayHashSet) && + command.HolidayWork == workshopSettings.HolidayWork) + { + isChanged = false; + } + else + { + isChanged = true; + } + } + + var breakTime = new BreakTime(command.BreakTime.HasBreakTimeValue, command.BreakTime.BreakTimeValue); + + var employeeSettings = entity.CustomizeWorkshopEmployeeSettingsCollection; + + var employeeSettingIds = employeeSettings.Select(x => x.EmployeeId).ToList(); + + reCalculateCommand = reCalculateCommand.Where(x => employeeSettingIds.Contains(x.EmployeeId)).ToList(); + + var selectedEmployeesIds = reCalculateCommand.Select(x => x.EmployeeId).ToList(); + + var notSelectedEmployeeSettings = employeeSettings.Where(x => !selectedEmployeesIds.Contains(x.EmployeeId)); + + var weeklyOffDays = command.OffDayOfWeeks.Select(x => new WeeklyOffDay(x)).ToList(); + using var transaction = new TransactionScope(); + + entity.EditSimpleAndOverwriteOnEmployee(command.Name, selectedEmployeesIds, groupSettingsShifts, command.WorkshopShiftStatus, + command.IrregularShift, breakTime, isChanged, command.HolidayWork, rotatingShift, weeklyOffDays); + if (reCalculateCommand.Count > 0) + { + var result = _rollCallApplication.RecalculateValues(workshopSettings.WorkshopId, reCalculateCommand); + + if (result.IsSuccedded == false) + { + return result; + } + } + + foreach (var notSelectedEmployeeSetting in notSelectedEmployeeSettings) + { + notSelectedEmployeeSetting.UpdateIsShiftChange(); + } + + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + + transaction.Complete(); + return op.Succcedded(); + } + public OperationResult EditSimpleRollCallEmployeeSetting(EditCustomizeEmployeeSettings command, + List reCalculateCommand) + { + OperationResult op = new(); + + var entity = _customizeWorkshopEmployeeSettingsRepository.Get(command.Id); + + #region Validation + + if (entity == null) + return op.Failed("چنین پرسنلی وجود ندارد"); + + #endregion + + var groupSettings = + _customizeWorkshopGroupSettingsRepository.GetIncludeWorkshopSettings( + entity.CustomizeWorkshopGroupSettingId); + + List employeesShifts = []; + + ICollection rotatingShift = []; + bool isChanged = false; + + var commandOffDayHashSet = command.WeeklyOffDays.ToHashSet(); + var groupOffDayHashSet = groupSettings.WeeklyOffDays.Select(x => x.DayOfWeek).ToHashSet(); + + if (command.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + + #region Validation + if (command.ShiftViewModel.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) + return op.Failed("ساعات کاری شروع و پایان نمیتواند خالی باشد"); + try + { + 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(); + } + catch (InvalidDataException e) + { + + return op.Failed(e.Message); + } + if (command.WorkshopId < 1) + { + return op.Failed("خطای سیستمی"); + } + DateTime day = DateTime.Now; + DateTime previousEnd = new DateTime(); + var finalShiftList = new List<(DateTime start, DateTime end, ShiftPlacement placement)>(); + + employeesShifts = employeesShifts.OrderBy(x => x.Placement).ToList(); + + foreach (var shift in employeesShifts) + { + (DateTime start, DateTime end, ShiftPlacement placement) newShift = + new() + { + placement = shift.Placement, + start = new DateTime(DateOnly.FromDateTime(day), shift.StartTime), + end = new DateTime(DateOnly.FromDateTime(day), shift.EndTime) + + + }; + + if (previousEnd != new DateTime()) + { + if (newShift.start == previousEnd) + { + return op.Failed("در شیفت منظم پایان شیفت نمیتواند با شروع شیفت بعدی برابر باشد"); + } + + if (newShift.start <= previousEnd) + { + newShift.start = newShift.start.AddDays(1); + } + } + while (newShift.start >= newShift.end) + { + newShift.end = newShift.end.AddDays(1); + } + finalShiftList.Add(newShift); + previousEnd = newShift.end; + } + + var firstShiftStart = finalShiftList.FirstOrDefault(x => x.placement == ShiftPlacement.First).start; + var lastShiftEnd = finalShiftList.OrderByDescending(x => x.placement).FirstOrDefault().end; + if (firstShiftStart.AddDays(1) < lastShiftEnd) + return op.Failed("بازه زمانی کارگاه نامعتبر است"); + var total = finalShiftList.Sum(x => (x.end - x.start).TotalHours); + if (total >= 24) + { + return op.Failed("بازه زمانی کارگاه نمیتواند بیشتر از 24 ساعت باشد"); + } + #endregion + + + if (employeesShifts.All(x => groupSettings.CustomizeWorkshopGroupSettingsShifts.Any(y => x.Equals(y))) + && command.WorkshopShiftStatus == groupSettings.WorkshopShiftStatus && commandOffDayHashSet.SetEquals(groupOffDayHashSet) && + command.HolidayWork == groupSettings.HolidayWork && command.BreakTime == groupSettings.BreakTime) + { + isChanged = false; + } + + else + { + isChanged = true; + } + } + else if (command.WorkshopShiftStatus == WorkshopShiftStatus.Irregular) + { + var irregularShiftStartTime = new DateTime(DateOnly.MinValue, command.IrregularShift.StartTime); + + var irregularShiftEndTime = new DateTime(DateOnly.MinValue, command.IrregularShift.EndTime); + + if (irregularShiftEndTime < irregularShiftStartTime) + { + irregularShiftEndTime = irregularShiftEndTime.AddDays(1); + } + + switch (command.IrregularShift.WorkshopIrregularShifts) + { + case WorkshopIrregularShifts.TwelveThirtySix: + + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + case WorkshopIrregularShifts.TwelveTwentyFour: + if ((irregularShiftEndTime - irregularShiftStartTime).TotalHours > 12) + { + return op.Failed("ساعت کاری شما نمیتواند بیشتر از 12 ساعت باشد"); + } + break; + } + + if (command.WorkshopShiftStatus == groupSettings.WorkshopShiftStatus && command.BreakTime == groupSettings.BreakTime && + command.IrregularShift == groupSettings.IrregularShift && commandOffDayHashSet.SetEquals(groupOffDayHashSet) && + command.HolidayWork == groupSettings.HolidayWork) + { + isChanged = false; + } + else + { + isChanged = true; + } + } + else + { + if (command.CustomizeRotatingShifts.Count == 1) + { + return op.Failed("در نوع گردشی میبایست بیشتر از یک شیفت تعریف کنید"); + } + + rotatingShift = command.CustomizeRotatingShifts + .Select(x => new CustomizeRotatingShift(TimeOnly.Parse(x.StartTime), TimeOnly.Parse(x.EndTime))).ToList(); + + if (rotatingShift.All(x => groupSettings.CustomizeRotatingShifts.Any(y => x.Equals(y))) + && command.WorkshopShiftStatus == groupSettings.WorkshopShiftStatus && commandOffDayHashSet.SetEquals(groupOffDayHashSet) && + command.HolidayWork == groupSettings.HolidayWork && command.BreakTime == groupSettings.BreakTime) + { + isChanged = false; + } + + else + { + isChanged = true; + } + + } + + var weeklyOffDays = command.WeeklyOffDays.Select(x => new WeeklyOffDay(x)).ToList(); + using var transaction = new TransactionScope(); + + entity.SimpleEdit(employeesShifts, command.IrregularShift, command.WorkshopShiftStatus, command.BreakTime, + isChanged, command.HolidayWork, rotatingShift, weeklyOffDays); + + _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 + public OperationResult RemoveEmployeeFromRollCallWorkshopGroup(long employeeId, long groupId, long workshopId) + { + OperationResult op = new(); + var groupEntity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(groupId); + + #region Validation + + if (groupEntity == null) + { + return op.Failed("چنین گروهی وجود ندارد"); + } + + #endregion + + using var transaction = new TransactionScope(); + groupEntity.RemoveEmployeeFromGroup(employeeId); + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + var res = AddEmployeeToMainGroupSettings(workshopId, employeeId); + if (res.IsSuccedded) + { + transaction.Complete(); + return op.Succcedded(); + + } + + return res; + + } + + public OperationResult AddEmployeeToMainGroupSettings(long workshopId, long employeeId) + { + var op = new OperationResult(); + + var mainGroup = _customizeWorkshopGroupSettingsRepository.GetWorkshopMainGroup(workshopId); + if (mainGroup == null) + return op.Succcedded(); + mainGroup.AddEmployeeSettingToGroupWithGroupData(employeeId, workshopId); + + _customizeWorkshopEmployeeSettingsRepository.SaveChanges(); + + return op.Succcedded(); + } + + #endregion + + #region CustomizeCheckoutSettings + public OperationResult CreateEmployeeSettings(CreateCustomizeEmployeeSettings command) + { + OperationResult op = new(); + CustomizeWorkshopGroupSettings mainGroup = new CustomizeWorkshopGroupSettings(); + + #region Validation + + //if (!_customizeWorkshopGroupSettingsRepository.Exists(x => x.id == command.GroupId)) + // return op.Failed("چنین گروهی وجود ندارد"); + + if (!_employeeRepository.ExistsIgnoreQueryFilter(x => command.EmployeeIds.Any(y => x.id == y))) + return op.Failed("چنین پرسنلی وجود ندارد"); + + #endregion + + var groupData = _customizeWorkshopGroupSettingsRepository.GetIncludeWorkshopSettings(command.GroupId); + if (groupData == null) + return op.Failed("خطای سیستمی"); + var workshopSettings = _customizeWorkshopSettingsRepository.Get(groupData.CustomizeWorkshopSettingId); + var employeesInMainGroup = new List(); + + mainGroup = _customizeWorkshopGroupSettingsRepository.GetWorkshopMainGroup(command.WorkshopId); + + if (workshopSettings.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + if (mainGroup != null) + { + + employeesInMainGroup = _customizeWorkshopEmployeeSettingsRepository.GetBy(mainGroup.id); + if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId + && command.EmployeeIds.Contains(x.EmployeeId) && x.CustomizeWorkshopGroupSettingId != mainGroup.id)) + { + return op.Failed("این پرسنل در گروه دیگری وجود دارد"); + } + } + else + { + if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId + && command.EmployeeIds.Contains(x.EmployeeId))) + { + return op.Failed("این پرسنل در گروه دیگری وجود دارد"); + } + } + } + else + { + if (mainGroup != null) + { + employeesInMainGroup = _customizeWorkshopEmployeeSettingsRepository.GetBy(mainGroup.id); + if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId + && command.EmployeeIds.Contains( + x.EmployeeId) && + x.CustomizeWorkshopGroupSettingId != + mainGroup.id)) + { + return op.Failed("این پرسنل در گروه دیگری وجود دارد"); + } + } + else + { + if (_customizeWorkshopEmployeeSettingsRepository.Exists(x => x.WorkshopId == command.WorkshopId + && command.EmployeeIds.Contains(x.EmployeeId))) + { + return op.Failed("این پرسنل در گروه دیگری وجود دارد"); + } + } + } + + + + var shifts = groupData.CustomizeWorkshopGroupSettingsShifts + .Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); + + + foreach (var id in command.EmployeeIds) + { + var employeeSettings = employeesInMainGroup.FirstOrDefault(x => x.EmployeeId == id); + if (employeeSettings != null) + { + _customizeWorkshopEmployeeSettingsRepository.Remove(employeeSettings.id); + } + var entity = new CustomizeWorkshopEmployeeSettings( + new(groupData.FridayPay.FridayPayType, groupData.FridayPay.Value), + new(groupData.OverTimePay.OverTimePayType, groupData.OverTimePay.Value), + new(groupData.BaseYearsPay.BaseYearsPayType, groupData.BaseYearsPay.Value, groupData.BaseYearsPay.PaymentType), + new(groupData.BonusesPay.BonusesPayType, groupData.BonusesPay.Value, groupData.BonusesPay.PaymentType), + new(groupData.NightWorkPay.NightWorkingType, groupData.NightWorkPay.Value), + new(groupData.MarriedAllowance.MarriedAllowanceType, groupData.MarriedAllowance.Value), + new(groupData.ShiftPay.ShiftType, groupData.ShiftPay.ShiftPayType, groupData.ShiftPay.Value), + new(groupData.FamilyAllowance.FamilyAllowanceType, groupData.FamilyAllowance.Value), + new(groupData.LeavePay.LeavePayType, groupData.LeavePay.Value), + new(groupData.InsuranceDeduction.InsuranceDeductionType, groupData.InsuranceDeduction.Value), + new(groupData.FineAbsenceDeduction.FineAbsenceDeductionType, groupData.FineAbsenceDeduction.Value, + groupData.FineAbsenceDeduction.FineAbsenceDayOfWeekCollection + .Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList()), + new(groupData.LateToWork.LateToWorkType, + groupData.LateToWork.LateToWorkTimeFines.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) + .ToList(), groupData.LateToWork.Value), + new(groupData.EarlyExit.EarlyExitType, + groupData.EarlyExit.EarlyExitTimeFines.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)) + .ToList(), groupData.EarlyExit.Value), + id, + groupData.CustomizeWorkshopSettings.WorkshopId, + groupData.Salary, + groupData.id, + shifts.Select(x => new CustomizeWorkshopEmployeeSettingsShift(x.StartTime, x.EndTime, x.Placement)) + .ToList(), + groupData.HolidayWork, + groupData.IrregularShift, + groupData.WorkshopShiftStatus, + new(groupData.BreakTime.HasBreakTimeValue, groupData.BreakTime.BreakTimeValue), + command.LeavePermittedDays, + groupData.CustomizeRotatingShifts.Select(x => new CustomizeRotatingShift(x.StartTime, x.EndTime)).ToList(), + groupData.WeeklyOffDays + ); + + _customizeWorkshopEmployeeSettingsRepository.Create(entity); + + } + _customizeWorkshopEmployeeSettingsRepository.SaveChanges(); + + + return op.Succcedded(); + } + + //Edit the Workshop Settings Data + public OperationResult EditWorkshopSetting(EditCustomizeWorkshopSettings command, bool replaceInAllGroups) + { + OperationResult op = new(); + + #region Validation + + if (!_customizeWorkshopSettingsRepository.Exists(x => x.id == command.Id)) + return op.Failed("خطای سیستمی"); + + #endregion + + + var entity = _customizeWorkshopSettingsRepository.Get(command.Id); + if (entity == null) + return op.Failed("چنین آیتمی وجود ندارد"); + + + FridayPay fridayPay = new(command.FridayPay.FridayPayType, command.FridayPay.Value); + OverTimePay overTimePay = new(command.OverTimePay.OverTimePayType, command.OverTimePay.Value); + BaseYearsPay baseYearsPay = new(command.BaseYearsPay.BaseYearsPayType, command.BaseYearsPay.Value, command.BaseYearsPay.PaymentType); + BonusesPay bonusesPay = new(command.BonusesPay.BonusesPayType, command.BonusesPay.Value, command.BonusesPay.PaymentType); + NightWorkPay nightWorkPay = new(command.NightWorkPay.NightWorkingType, command.NightWorkPay.Value); + MarriedAllowance marriedAllowance = new(command.MarriedAllowance.MarriedAllowanceType, command.MarriedAllowance.Value); + ShiftPay shiftPay = new(ShiftType.None, ShiftPayType.None, 0); + FamilyAllowance familyAllowance = new(command.FamilyAllowance.FamilyAllowanceType, command.FamilyAllowance.Value); + LeavePay leavePay = new(command.LeavePay.LeavePayType, command.LeavePay.Value); + InsuranceDeduction insuranceDeduction = new(command.InsuranceDeduction.InsuranceDeductionType, command.InsuranceDeduction.Value); + FineAbsenceDeduction fineAbsenceDeduction = new( + command.FineAbsenceDeduction.FineAbsenceDeductionType, + command.FineAbsenceDeduction.Value, + command.FineAbsenceDeduction.FineAbsenceDayOfWeekViewModels?.Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList() ?? new List() + ); + LateToWork lateToWork = new( + command.LateToWork.LateToWorkType, + command.LateToWork.LateToWorkTimeFinesVewModels?.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) + .ToList() ?? new List() + , command.LateToWork.Value + ); + + EarlyExit earlyExit = new(command.EarlyExit.EarlyExitType, + command.EarlyExit.EarlyExitTimeFinesViewModels?.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)).ToList() ?? new List() + , command.EarlyExit.Value); + + + var groups = _customizeWorkshopGroupSettingsRepository.GetAllGroupsIncludeEmployeeSettingsByWorkshopSettingsId(entity.id); + + using (var transaction = new TransactionScope()) + { + + try + { + entity.Edit(fridayPay, overTimePay, baseYearsPay, bonusesPay, nightWorkPay, marriedAllowance, shiftPay, + familyAllowance, leavePay, insuranceDeduction, + fineAbsenceDeduction, lateToWork, earlyExit, command.HolidayWork, + command.BonusesPaysInEndOfMonth, command.LeavePermittedDays, command.BaseYearsPayInEndOfYear, + command.OverTimeThresholdMinute); + + _customizeWorkshopSettingsRepository.SaveChanges(); + var editViewModel = new EditCustomizeWorkshopGroupSettings() + { + + }; + OperationResult result = new OperationResult(); + if (entity.WorkshopShiftStatus == WorkshopShiftStatus.Regular) + { + //foreach (var group in groups) + //{ + // var employeeIds = group.CustomizeWorkshopEmployeeSettingsCollection.Select(x => x.EmployeeId) + // .ToList(); + // group.EditAndOverwriteOnEmployees(group.GroupName,group.Salary,employeeIds,group.FridayPay,group.OverTimePay,group.BaseYearsPay,group.BonusesPay, + // group.ShiftPay,group.NightWorkPay,group.MarriedAllowance,group.FamilyAllowance,group.LeavePay,group.InsuranceDeduction, + // group.FineAbsenceDeduction,); + //} + } + else + { + result = result.Succcedded(); + } + + ChangeAllSettingsGroups(entity, replaceInAllGroups); + + result.Succcedded(); + + + transaction.Complete(); + + } + catch + { + // ignored + } + } + + return string.IsNullOrWhiteSpace(op.Message) ? op.Succcedded() : op; + } + + + + //Edit the Group Settings Data + public OperationResult EditRollCallGroupSetting(EditCustomizeWorkshopGroupSettings command) + { + OperationResult op = new(); + + #region Validation + + if (string.IsNullOrWhiteSpace(command.Name)) + return op.Failed("لطفا نام گروه را وارد کنید"); + + if (string.IsNullOrWhiteSpace(command.Salary)) + return op.Failed("لطفا حقوق مورد نظر خود را وارد کنید"); + + if (!_customizeWorkshopGroupSettingsRepository.Exists(x => x.id == command.Id)) + return op.Failed("چنین ساعت کاری برای گروه وجود ندارد"); + + #endregion + + + var entity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(command.Id); + + FridayPay fridayPay = new(command.FridayPay.FridayPayType, command.FridayPay.Value); + OverTimePay overTimePay = new(command.OverTimePay.OverTimePayType, command.OverTimePay.Value); + BaseYearsPay baseYearsPay = new(command.BaseYearsPay.BaseYearsPayType, command.BaseYearsPay.Value, command.BaseYearsPay.PaymentType); + BonusesPay bonusesPay = new(command.BonusesPay.BonusesPayType, command.BonusesPay.Value, command.BonusesPay.PaymentType); + NightWorkPay nightWorkPay = new(command.NightWorkPay.NightWorkingType, command.NightWorkPay.Value); + MarriedAllowance marriedAllowance = new(command.MarriedAllowance.MarriedAllowanceType, command.MarriedAllowance.Value); + //ShiftPay shiftPay = new(command.ShiftPay.ShiftType, command.ShiftPay.ShiftPayType, command.ShiftPay.Value); + ShiftPay shiftPay = new(ShiftType.None, ShiftPayType.None, 0); + FamilyAllowance familyAllowance = new(command.FamilyAllowance.FamilyAllowanceType, command.FamilyAllowance.Value); + LeavePay leavePay = new(command.LeavePay.LeavePayType, command.LeavePay.Value); + InsuranceDeduction insuranceDeduction = new(command.InsuranceDeduction.InsuranceDeductionType, command.InsuranceDeduction.Value); + FineAbsenceDeduction fineAbsenceDeduction = new( + command.FineAbsenceDeduction.FineAbsenceDeductionType, command.FineAbsenceDeduction.Value, + command.FineAbsenceDeduction.FineAbsenceDayOfWeekViewModels + .Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList() + ); + LateToWork lateToWork = new( + command.LateToWork.LateToWorkType, + command.LateToWork.LateToWorkTimeFinesVewModels.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) + .ToList(), command.LateToWork.Value + ); + EarlyExit earlyExit = new(command.EarlyExit.EarlyExitType, + command.EarlyExit.EarlyExitTimeFinesViewModels.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)) + .ToList(), command.EarlyExit.Value); + + double salary = command.Salary.MoneyToDouble(); + + + bool isChanged; + if (fridayPay == entity.FridayPay && overTimePay == entity.OverTimePay && baseYearsPay == entity.BaseYearsPay && bonusesPay == entity.BonusesPay + && shiftPay == entity.ShiftPay && nightWorkPay == entity.NightWorkPay && marriedAllowance == entity.MarriedAllowance + && familyAllowance == entity.FamilyAllowance && leavePay == entity.LeavePay && insuranceDeduction == entity.InsuranceDeduction + && fineAbsenceDeduction == entity.FineAbsenceDeduction && lateToWork == entity.LateToWork && earlyExit == entity.EarlyExit + && command.HolidayWork == entity.HolidayWork && command.IrregularShift == entity.IrregularShift && command.WorkshopShiftStatus == entity.WorkshopShiftStatus) + { + isChanged = false; + } + else + { + isChanged = true; + } + entity.EditAndOverwriteOnEmployees(command.Name, salary, command.EmployeeIds, fridayPay, overTimePay, + baseYearsPay, bonusesPay, shiftPay, nightWorkPay, marriedAllowance, familyAllowance, + leavePay, insuranceDeduction, fineAbsenceDeduction, lateToWork, earlyExit, command.HolidayWork, isChanged, command.LeavePermittedDays); + + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + + return op.Succcedded(); + } + + //Edit the Employee settings and change the 'IsChanged' bool to true. + public OperationResult EditRollCallEmployeeSettings(EditCustomizeEmployeeSettings command) + { + OperationResult op = new(); + var entity = _customizeWorkshopEmployeeSettingsRepository.Get(command.Id); + + #region Validation + + if (entity == null) + return op.Failed("چنین پرسنلی وجود ندارد"); + + #endregion + + FridayPay fridayPay = new(command.FridayPay.FridayPayType, command.FridayPay.Value); + OverTimePay overTimePay = new(command.OverTimePay.OverTimePayType, command.OverTimePay.Value); + BaseYearsPay baseYearsPay = new(command.BaseYearsPay.BaseYearsPayType, command.BaseYearsPay.Value, command.BaseYearsPay.PaymentType); + BonusesPay bonusesPay = new(command.BonusesPay.BonusesPayType, command.BonusesPay.Value, command.BonusesPay.PaymentType); + NightWorkPay nightWorkPay = new(command.NightWorkPay.NightWorkingType, command.NightWorkPay.Value); + MarriedAllowance marriedAllowance = new(command.MarriedAllowance.MarriedAllowanceType, command.MarriedAllowance.Value); + // ShiftPay shiftPay = new(command.ShiftPay.ShiftType, command.ShiftPay.ShiftPayType, command.ShiftPay.Value); + ShiftPay shiftPay = new(ShiftType.None, ShiftPayType.None, 0); + FamilyAllowance familyAllowance = new(command.FamilyAllowance.FamilyAllowanceType, command.FamilyAllowance.Value); + LeavePay leavePay = new(command.LeavePay.LeavePayType, command.LeavePay.Value); + InsuranceDeduction insuranceDeduction = new(command.InsuranceDeduction.InsuranceDeductionType, command.InsuranceDeduction.Value); + FineAbsenceDeduction fineAbsenceDeduction = new( + command.FineAbsenceDeduction.FineAbsenceDeductionType, command.FineAbsenceDeduction.Value, + command.FineAbsenceDeduction.FineAbsenceDayOfWeekViewModels + .Select(x => new FineAbsenceDayOfWeek(x.DayOfWeek)).ToList() + ); + LateToWork lateToWork = new( + command.LateToWork.LateToWorkType, + command.LateToWork.LateToWorkTimeFinesVewModels.Select(x => new LateToWorkTimeFine(x.Minute, x.FineMoney)) + .ToList(), command.LateToWork.Value + ); + EarlyExit earlyExit = new(command.EarlyExit.EarlyExitType, + command.EarlyExit.EarlyExitTimeFinesViewModels.Select(x => new EarlyExitTimeFine(x.Minute, x.FineMoney)) + .ToList(), command.EarlyExit.Value); + + + double salary = command.Salary.MoneyToDouble(); + + var commandOffDayHashSet = command.WeeklyOffDays.ToHashSet(); + var entityOffDayHashSet = entity.WeeklyOffDays.Select(x => x.DayOfWeek).ToHashSet(); + + bool isChanged; + if (fridayPay == entity.FridayPay && overTimePay == entity.OverTimePay && baseYearsPay == entity.BaseYearsPay && bonusesPay == entity.BonusesPay + && shiftPay == entity.ShiftPay && nightWorkPay == entity.NightWorkPay && marriedAllowance == entity.MarriedAllowance + && familyAllowance == entity.FamilyAllowance && leavePay == entity.LeavePay && insuranceDeduction == entity.InsuranceDeduction + && fineAbsenceDeduction == entity.FineAbsenceDeduction && lateToWork == entity.LateToWork && earlyExit == entity.EarlyExit && commandOffDayHashSet.SetEquals(entityOffDayHashSet) + && command.HolidayWork == entity.HolidayWork) + { + isChanged = false; + } + else + { + isChanged = true; + } + + //change employee data manually. It changes the 'IsChanged' property to true. + entity.EditEmployees(salary, fridayPay, overTimePay, baseYearsPay, + bonusesPay, nightWorkPay, marriedAllowance, shiftPay, familyAllowance, leavePay, + insuranceDeduction, fineAbsenceDeduction, lateToWork, earlyExit, command.HolidayWork, command.IrregularShift, isChanged, command.LeavePermittedDays); + + + _customizeWorkshopEmployeeSettingsRepository.SaveChanges(); + return op.Succcedded(); + } + + public OperationResult RemoveGroupSettings(long groupSettingsId) + { + OperationResult op = new OperationResult(); + var entity = _customizeWorkshopGroupSettingsRepository.GetWithEmployees(groupSettingsId); + if (entity.CustomizeWorkshopEmployeeSettingsCollection.Any()) + return op.Failed("نمیتوانید گروهی که پرسنل در آن وجود دارد را حذف کنید"); + + _customizeWorkshopGroupSettingsRepository.Remove(entity.id); + return op.Succcedded(); + } + #endregion + + #region Queries + + + public List GetChangedEmployeeSettingsByGroupSettingsId(long groupSettingsId) + { + return _customizeWorkshopGroupSettingsRepository.GetShiftChangedEmployeeSettingsByGroupSettingsId( + groupSettingsId); + } + + + // It will Get the Workshop Settings with its groups and the employees of groups. + public CustomizeWorkshopSettingsViewModel GetWorkshopSettingsByWorkshopId(long workshopId, AuthViewModel auth) + { + + + #region Validation + + if (workshopId is < 1) + return new(); + + #endregion + + var record = _customizeWorkshopSettingsRepository.GetWorkshopSettingsByWorkshopId(workshopId, auth); + + return record; + } + + public CustomizeWorkshopEmployeeSettingsViewModel GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(long workshopId, long employeeId) + { + var entity = + _customizeWorkshopEmployeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(workshopId, employeeId); + if (entity == null) + return null; + + string employeeFullName = _employeeRepository.GetIgnoreQueryFilter(entity.EmployeeId).FullName; + return new CustomizeWorkshopEmployeeSettingsViewModel() + { + EmployeeId = entity.EmployeeId, + Id = entity.id, + IsSettingChanged = entity.IsSettingChanged, + IsShiftChanged = entity.IsShiftChanged, + Name = entity.CustomizeWorkshopGroupSettings.GroupName, + EmployeeFullName = employeeFullName, + Salary = entity.Salary, + BreakTime = entity.BreakTime, + WorkshopShiftStatus = entity.WorkshopShiftStatus, + IrregularShift = entity.IrregularShift, + RollCallWorkshopShifts = entity.CustomizeWorkshopEmployeeSettingsShifts.Select(x => + new CustomizeWorkshopShiftViewModel() + { + EndTime = x.EndTime.ToString("HH:mm"), + Placement = x.Placement, + StartTime = x.StartTime.ToString("HH:mm") + }).ToList(), + //FridayWork = entity.FridayWork, + HolidayWork = entity.HolidayWork, + WeeklyOffDays = entity.WeeklyOffDays.Select(x=>x.DayOfWeek).ToList(), + CustomizeRotatingShiftsViewModels = entity.CustomizeRotatingShifts.Select(x => new CustomizeRotatingShiftsViewModel() + { + StartTime = x.StartTime.ToString("HH:mm"), + EndTime = x.EndTime.ToString("HH:mm") + }).ToList() + + }; + } + + public List GetEmployeeSettingsByGroupSettingsId(long groupSettingsId) + { + + List result = _customizeWorkshopGroupSettingsRepository.GetEmployeeSettingsByGroupSettingsId(groupSettingsId); + + if (result == null) + return new(); + + return result; + + } + + public CustomizeWorkshopSettingsViewModel GetWorkshopIncludeGroupsByWorkshopId(long workshopId) + { + return _customizeWorkshopSettingsRepository.GetWorkshopIncludeGroupsByWorkshopId(workshopId); + } + + + public List GetEmployeesWithoutGroup(long rollCallWorkshopSettingId) + { + return _customizeWorkshopGroupSettingsRepository.GetEmployeesWithoutGroup(rollCallWorkshopSettingId); + } + public List GetEmployeesWithoutGroupByWorkshopId(long workshopId) + { + return _customizeWorkshopGroupSettingsRepository.GetEmployeesWithoutGroupByWorkshopId(workshopId); + } + + + + public CustomizeWorkshopSettingsViewModel GetWorkshopSettingsByWorkshopIdForAdmin(long workshopId) + { + return _customizeWorkshopSettingsRepository.GetWorkshopSettingsByWorkshopIdForAdmin(workshopId); + + } + public EditCustomizeWorkshopSettings GetWorkshopSettingsDetails(long workshopId) + { + return _customizeWorkshopSettingsRepository.GetWorkshopSettingsDetails(workshopId); + } + + public EditCustomizeWorkshopGroupSettings GetCustomizeWorkshopGroupSettingsDetails(long groupId) + { + return _customizeWorkshopGroupSettingsRepository.GetCustomizeWorkshopGroupSettingsDetails(groupId); + } + + public EditCustomizeWorkshopSettings GetSimpleWorkshopSettings(long workshopId) + { + return _customizeWorkshopSettingsRepository.GetSimpleWorkshopSettings(workshopId); + } + + public EditCustomizeEmployeeSettings GetCustomizeEmployeeSettingsDetails(long customizeEmployeeId) + { + return _customizeWorkshopEmployeeSettingsRepository.GetCustomizeEmployeeSettingsDetails(customizeEmployeeId); + } + + public List GetShiftChangesGroupAndEmployees(long customizeWorkshopSettingsId) + { + return _customizeWorkshopSettingsRepository.GetShiftChangesGroupAndEmployees(customizeWorkshopSettingsId); + } + + public List GetEmployeeSettingsByWorkshopId(long workshopId) + { + return _customizeWorkshopEmployeeSettingsRepository.GetEmployeeSettingsByWorkshopId(workshopId); + } + + public CustomizeWorkshopGroupSettingsViewModel GetEmployeesGroupSettingsByEmployeeId(long employeeId, long workshopId) + { + return _customizeWorkshopGroupSettingsRepository.GetEmployeesGroupSettingsByEmployeeId(employeeId, workshopId); + } + + public bool HasAnyEmployeeWithoutGroup(long workshopId) + { + return _customizeWorkshopGroupSettingsRepository.HasAnyEmployeeWithoutGroup(workshopId); + } + public OperationResult> ValidateReCalculateValueForGroupEdit(List commands, + long workshopId) + { + var operationResult = new OperationResult>(); + bool isSuccess = true; + List employeeIdsHasCheckout = []; + foreach (var command in commands) + { + var fromDateGr = command.FromDate.ToGeorgianDateTime(); + if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == command.EmployeeId && fromDateGr <= x.ContractEnd)) + { + isSuccess = false; + employeeIdsHasCheckout.Add(command.EmployeeId); + } + + if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == command.EmployeeId && fromDateGr <= x.ContractEnd)) + { + isSuccess = false; + employeeIdsHasCheckout.Add(command.EmployeeId); + } + + if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && x.EmployeeId == command.EmployeeId && fromDateGr <= x.ContractEnd)) + { + isSuccess = false; + employeeIdsHasCheckout.Add(command.EmployeeId); + } + } + + employeeIdsHasCheckout = employeeIdsHasCheckout.Distinct().ToList(); + return isSuccess ? + operationResult.Succcedded(employeeIdsHasCheckout) + : + operationResult.Failed("پرسنل هایی دارای فیش هستند لطفا نسبت به تعیین تکلیف این ها اقدام نمایید", employeeIdsHasCheckout); + } + public bool CheckEmployeeShiftHasChanged(EditCustomizeEmployeeSettings command) + { + return _customizeWorkshopEmployeeSettingsRepository.CheckEmployeeShiftHasChanged(command); + } + + private OperationResult CreateGeneralGroup(CustomizeWorkshopSettings entity) + { + var op = new OperationResult(); + + if (_customizeWorkshopGroupSettingsRepository.Exists(x => x.CustomizeWorkshopSettingId == entity.id && x.MainGroup)) + { + return op.Succcedded(); + } + + try + { + var shifts = + entity.CustomizeWorkshopSettingsShifts.Select(x => + new CustomizeWorkshopGroupSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); + var irregularShift = new IrregularShift(new TimeOnly(), new TimeOnly(), WorkshopIrregularShifts.None); + + var customizeWorkshopGroupSettings = new CustomizeWorkshopGroupSettings().CreateMainGroup(entity.FridayPay, entity.OverTimePay, + entity.BaseYearsPay, entity.BonusesPay, entity.ShiftPay, entity.NightWorkPay, entity.MarriedAllowance, + entity.FamilyAllowance, entity.LeavePay, entity.InsuranceDeduction, entity.FineAbsenceDeduction, + entity.LateToWork, entity.EarlyExit, shifts, entity.HolidayWork, + irregularShift, [], entity.WorkshopShiftStatus, entity.id, new BreakTime(false, new TimeOnly()), entity.LeavePermittedDays); + + _customizeWorkshopGroupSettingsRepository.Create(customizeWorkshopGroupSettings); + + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + + var employeesHasSettings = _customizeWorkshopEmployeeSettingsRepository + .GetEmployeeSettingNotInMainGroup(entity.WorkshopId).Select(x => x.EmployeeId); + + var rollCallEmployeeViewModels = _rollCallEmployeeApplication.GetByWorkshopId(entity.WorkshopId).Where(x => !employeesHasSettings.Contains(x.EmployeeId)); + + foreach (var rollCallEmployeeViewModel in rollCallEmployeeViewModels) + { + customizeWorkshopGroupSettings.AddEmployeeSettingToGroupWithGroupData( + rollCallEmployeeViewModel.EmployeeId, entity.WorkshopId); + } + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + return op.Succcedded(); + } + catch (Exception e) + { + return op.Failed(e.Message); + } + + + } + + private OperationResult ChangeAllGroupsShiftsWithEmployees(CustomizeWorkshopSettings entity, bool replaceChangedGroups) + { + var op = new OperationResult(); + var groupSettings = _customizeWorkshopGroupSettingsRepository.GetAllGroupsIncludeEmployeeSettingsByWorkshopSettingsId(entity.id); + + if (!replaceChangedGroups) + { + groupSettings = groupSettings.Where(x => !x.IsShiftChange).ToList(); + } + + var groupShifts = entity.CustomizeWorkshopSettingsShifts + .Select(x => new CustomizeWorkshopGroupSettingsShift(x.StartTime, x.EndTime, x.Placement)).ToList(); + + + + var irregularShift = new IrregularShift(new TimeOnly(), new TimeOnly(), WorkshopIrregularShifts.None); + foreach (var customizeWorkshopGroupSettings in groupSettings) + { + customizeWorkshopGroupSettings.EditSimpleAndOverwriteOnAllEmployees(customizeWorkshopGroupSettings.GroupName, + groupShifts, entity.WorkshopShiftStatus, irregularShift, new BreakTime(false, new TimeOnly()), + false, entity.HolidayWork, [], []); + } + _customizeWorkshopGroupSettingsRepository.SaveChanges(); + return op.Succcedded(); + } + private void ChangeAllSettingsGroups(CustomizeWorkshopSettings customizeWorkshopSettings, bool replaceInAllGroups) + { + var op = new OperationResult(); + var groupSettings = _customizeWorkshopGroupSettingsRepository.GetAllGroupsIncludeEmployeeSettingsByWorkshopSettingsId(customizeWorkshopSettings.id); + + if (!replaceInAllGroups) + { + groupSettings = groupSettings.Where(x => !x.IsSettingChange).ToList(); + } + + + + foreach (var groupSetting in groupSettings) + { + groupSetting.EditAndOverwriteOnAllEmployees(groupSetting.GroupName, groupSetting.Salary, + customizeWorkshopSettings.FridayPay, + customizeWorkshopSettings.OverTimePay, customizeWorkshopSettings.BaseYearsPay, + customizeWorkshopSettings.BonusesPay, customizeWorkshopSettings.ShiftPay, + customizeWorkshopSettings.NightWorkPay, customizeWorkshopSettings.MarriedAllowance, + customizeWorkshopSettings.FamilyAllowance, customizeWorkshopSettings.LeavePay, + customizeWorkshopSettings.InsuranceDeduction, customizeWorkshopSettings.FineAbsenceDeduction, + customizeWorkshopSettings.LateToWork, customizeWorkshopSettings.EarlyExit, customizeWorkshopSettings.HolidayWork, replaceInAllGroups, + customizeWorkshopSettings.LeavePermittedDays); + } + _customizeWorkshopSettingsRepository.SaveChanges(); + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs index ad761f28..34cd8bee 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs @@ -26,7 +26,6 @@ public class CustomizeWorkshopEmployeeSettingsRepository(CompanyContext companyC return new(); return new EditCustomizeEmployeeSettings() { - FridayWork = entity.FridayWork, FridayPay = new() { FridayPayType = entity.FridayPay.FridayPayType, Value = entity.FridayPay.Value }, LateToWork = new() { diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs index a986ba2c..462284ff 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs @@ -265,7 +265,7 @@ public class CustomizeWorkshopGroupSettingsRepository(CompanyContext companyCont var entity = _companyContext.CustomizeWorkshopGroupSettings.AsSplitQuery().FirstOrDefault(x => x.id == groupId); return new EditCustomizeWorkshopGroupSettings() { - FridayWork = entity.FridayWork, + //FridayWork = entity.FridayWork, FridayPay = new (){ FridayPayType = entity.FridayPay.FridayPayType, Value = entity.FridayPay.Value }, LateToWork = new() { @@ -338,8 +338,8 @@ public class CustomizeWorkshopGroupSettingsRepository(CompanyContext companyCont { EndTime = x.EndTime.ToString("HH:mm"), StartTime = x.StartTime.ToString("HH:mm") - }).ToList() - + }).ToList(), + OffDayOfWeeks = entity.WeeklyOffDays.Select(x=>x.DayOfWeek).ToList() }; } diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopSettingsRepository.cs index 5652d774..51d02eb7 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopSettingsRepository.cs @@ -159,7 +159,6 @@ public class CustomizeWorkshopSettingsRepository(CompanyContext companyContext, return new(); var viewModel = new EditCustomizeWorkshopSettings() { - FridayWork = entity.FridayWork, FridayPay = new() { FridayPayType = entity.FridayPay.FridayPayType, Value = entity.FridayPay.Value }, LateToWork = new() { @@ -234,7 +233,8 @@ public class CustomizeWorkshopSettingsRepository(CompanyContext companyContext, LeavePermittedDays = entity.LeavePermittedDays, BaseYearsPayInEndOfYear = entity.BaseYearsPayInEndOfYear, WorkshopId = entity.WorkshopId, - WorkshopShiftStatus = entity.WorkshopShiftStatus + WorkshopShiftStatus = entity.WorkshopShiftStatus, + OffDays = entity.WeeklyOffDays.Select(x=>x.DayOfWeek).ToList() }; return viewModel; @@ -261,8 +261,8 @@ public class CustomizeWorkshopSettingsRepository(CompanyContext companyContext, Id = entity.id, WorkshopId = entity.WorkshopId, WorkshopShiftStatus = entity.WorkshopShiftStatus, - FridayWork = entity.FridayWork, - HolidayWork = entity.HolidayWork + HolidayWork = entity.HolidayWork, + OffDays = entity.WeeklyOffDays.Select(x=>x.DayOfWeek).ToList() }; } diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Options.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Options.cshtml.cs index 98bda2a4..62a6481e 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Options.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Options.cshtml.cs @@ -228,7 +228,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.RollCall } public IActionResult OnPostEditSettingWorkTime(List shiftViewModels, - long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus, long workshopId,FridayWork fridayWork,HolidayWork holidayWork) + long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus, long workshopId,FridayWork fridayWork,HolidayWork holidayWork,List offDayOfWeeks) { if (workshopId < 1) return new JsonResult(new @@ -240,7 +240,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.RollCall //Todo:Vafa!! //Todo: Vafa : to in ja bool replaceChange group ro ezafe kon. hatman ham workshopShiftStatus az front pas bede be in. var result = _customizeWorkshopSettingsApplication - .EditWorkshopSettingShifts(shiftViewModels, customizeWorkshopSettingsId, workshopShiftStatus, fridayWork, holidayWork); + .EditWorkshopSettingShifts(shiftViewModels, customizeWorkshopSettingsId, workshopShiftStatus, holidayWork, offDayOfWeeks); return new JsonResult(new { diff --git a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalEmployeeSettingPartials/Salary.cshtml b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalEmployeeSettingPartials/Salary.cshtml index 2c6919f0..44ba7e9e 100644 --- a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalEmployeeSettingPartials/Salary.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalEmployeeSettingPartials/Salary.cshtml @@ -58,14 +58,14 @@
وضعیت فعالیت مجموعه در روز های جمعه
-
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalGroupSettingPartials/Salary.cshtml b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalGroupSettingPartials/Salary.cshtml index 0034927e..2d556b42 100644 --- a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalGroupSettingPartials/Salary.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalGroupSettingPartials/Salary.cshtml @@ -56,14 +56,14 @@
وضعیت فعالیت مجموعه در روز های جمعه
-
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalPartials/FridayAndHoliday.cshtml b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalPartials/FridayAndHoliday.cshtml index 68387937..4a5c83be 100644 --- a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalPartials/FridayAndHoliday.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/_ModalPartials/FridayAndHoliday.cshtml @@ -29,14 +29,14 @@
وضعیت فعالیت مجموعه در روز های جمعه
-
+@*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs index 012db567..781d76b8 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/Grouping.cshtml.cs @@ -240,9 +240,10 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall BreakTime = employee.BreakTime, WorkshopShiftStatus = employee.WorkshopShiftStatus, IrregularShift = employee.IrregularShift, - FridayWork = employee.FridayWork, + //FridayWork = employee.FridayWork, HolidayWork = employee.HolidayWork, - CustomizeRotatingShifts = employee.CustomizeRotatingShiftsViewModels + CustomizeRotatingShifts = employee.CustomizeRotatingShiftsViewModels, + WeeklyOffDays = employee.WeeklyOffDays }; return Partial("ModalEditEmployeeFromGroup", command); } diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs index 65c2f5cd..2e067189 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs @@ -310,7 +310,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall } public IActionResult OnPostEditSettingWorkTime(List shiftViewModels, - long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus,FridayWork fridayWork,HolidayWork holidayWork) + long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus,FridayWork fridayWork,HolidayWork holidayWork,List offDayOfWeeks) { var workshopHash = User.FindFirstValue("WorkshopSlug"); var workshopId = _passwordHasher.SlugDecrypt(workshopHash); @@ -324,7 +324,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall //Todo:Vafa!! //Todo: Vafa : to in ja bool replaceChange group ro ezafe kon. hatman ham workshopShiftStatus az front pas bede be in. var result = _customizeWorkshopSettingsApplication - .EditWorkshopSettingShifts(shiftViewModels, customizeWorkshopSettingsId, workshopShiftStatus,fridayWork, holidayWork); + .EditWorkshopSettingShifts(shiftViewModels, customizeWorkshopSettingsId, workshopShiftStatus, holidayWork, offDayOfWeeks); return new JsonResult(new { diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalCreateGroup.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalCreateGroup.cshtml index b4c8ea5b..c34c2aaa 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalCreateGroup.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalCreateGroup.cshtml @@ -230,14 +230,14 @@
@*
وضعیت فعالیت مجموعه در روز های جمعه
*@ -
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml index ca2f96cf..684c25a3 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditEmployeeFromGroup.cshtml @@ -389,14 +389,14 @@
@*
وضعیت فعالیت مجموعه در روز های جمعه
*@ -
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditGroup.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditGroup.cshtml index 47606ccf..642b43fc 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditGroup.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalEditGroup.cshtml @@ -400,14 +400,14 @@
@*
وضعیت فعالیت مجموعه در روز های جمعه
*@ -
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalSettingWorkTime.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalSettingWorkTime.cshtml index 08a631b9..0af5a7c8 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalSettingWorkTime.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/ModalSettingWorkTime.cshtml @@ -162,14 +162,14 @@
@*
وضعیت فعالیت مجموعه در روز های جمعه
*@ -
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/Index.cshtml.cs index 2fd4e3df..e8ce8022 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/Index.cshtml.cs @@ -103,7 +103,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall._WorkshopSetting } public IActionResult OnPostEditSettingWorkTime(List shiftViewModels, - long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus, FridayWork fridayWork, HolidayWork holidayWork) + long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus, FridayWork fridayWork, HolidayWork holidayWork,List offDayOfWeeks) { var workshopHash = User.FindFirstValue("WorkshopSlug"); var workshopId = _passwordHasher.SlugDecrypt(workshopHash); @@ -115,7 +115,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall._WorkshopSetting }); var result = _customizeWorkshopSettingsApplication - .EditWorkshopSettingShifts(shiftViewModels, customizeWorkshopSettingsId, workshopShiftStatus, fridayWork, holidayWork); + .EditWorkshopSettingShifts(shiftViewModels, customizeWorkshopSettingsId, workshopShiftStatus, holidayWork, offDayOfWeeks); return new JsonResult(new { diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalCreateSettingWorkshop.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalCreateSettingWorkshop.cshtml index e408acd7..de2d4228 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalCreateSettingWorkshop.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalCreateSettingWorkshop.cshtml @@ -98,14 +98,14 @@
@*
وضعیت فعالیت مجموعه در روز های جمعه
*@ -
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalSettingWorkTime.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalSettingWorkTime.cshtml index 483e4132..3f57dddb 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalSettingWorkTime.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/WorkshopSetting/_Partials/ModalSettingWorkTime.cshtml @@ -162,14 +162,14 @@
@*
وضعیت فعالیت مجموعه در روز های جمعه
*@ -
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalEmployeeSettingPartials/FridayAndHoliday.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalEmployeeSettingPartials/FridayAndHoliday.cshtml index 6df058d2..76fed328 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalEmployeeSettingPartials/FridayAndHoliday.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalEmployeeSettingPartials/FridayAndHoliday.cshtml @@ -15,14 +15,14 @@
تعطیلات جمعه
-
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalGroupSettingPartials/FridayAndHoliday.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalGroupSettingPartials/FridayAndHoliday.cshtml index 5e1ce2c1..4e9c3905 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalGroupSettingPartials/FridayAndHoliday.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalGroupSettingPartials/FridayAndHoliday.cshtml @@ -16,14 +16,14 @@
تعطیلات جمعه
-
+ @*
-
+
*@
diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalPartials/FridayAndHoliday.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalPartials/FridayAndHoliday.cshtml index 2c0d988c..af6e2dc1 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalPartials/FridayAndHoliday.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/_ModalPartials/FridayAndHoliday.cshtml @@ -14,14 +14,14 @@
تعطیلات جمعه
-
+ @*
-
+
*@
diff --git a/ServiceHost/Test/Tester.cs b/ServiceHost/Test/Tester.cs index 95dcab26..49749c46 100644 --- a/ServiceHost/Test/Tester.cs +++ b/ServiceHost/Test/Tester.cs @@ -1,6 +1,8 @@ using System.Diagnostics; +using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using CompanyManagment.App.Contracts.AdminMonthlyOverview; using CompanyManagment.EFCore; +using Microsoft.EntityFrameworkCore; using ServiceHost.Areas.AdminNew.Pages.Company.RollCall; namespace ServiceHost.Test; @@ -18,9 +20,38 @@ public class Tester public async Task Test() { - // await AdminMonthlyOverviewTest(); + // await AdminMonthlyOverviewTest(); + //await ChangeFridayWorkToWeeklyDayOfWeek(); } + + private async Task ChangeFridayWorkToWeeklyDayOfWeek() + { + var employeeSettingsEnumerable =await _companyContext.CustomizeWorkshopEmployeeSettings.Where(x=>x.FridayWork ==FridayWork.Default).ToListAsync(); + foreach (var employeeSetting in employeeSettingsEnumerable) + { + employeeSetting.FridayWorkToWeeklyDayOfWeek(); + } + + var groupSettings = await _companyContext.CustomizeWorkshopGroupSettings + .Where(x => x.FridayWork == FridayWork.Default).ToListAsync(); + + foreach (var groupSetting in groupSettings) + { + groupSetting.FridayWorkToWeeklyDayOfWeek(); + } + + var workshopSettings = await _companyContext.CustomizeWorkshopSettings + .Where(x => x.FridayWork == FridayWork.Default).ToListAsync(); + foreach (var workshopSetting in workshopSettings) + { + workshopSetting.FridayWorkToWeeklyDayOfWeek(); + } + + await _companyContext.SaveChangesAsync(); + + } + private async Task AdminMonthlyOverviewTest() { var acc = _companyContext.WorkshopAccounts.FirstOrDefault(x => x.AccountId == 322); diff --git a/ServiceHost/appsettings.Development.json b/ServiceHost/appsettings.Development.json index df354fd1..6c608398 100644 --- a/ServiceHost/appsettings.Development.json +++ b/ServiceHost/appsettings.Development.json @@ -12,8 +12,8 @@ //"MesbahDb": "Data Source=DESKTOP-NUE119G\\MSNEW;Initial Catalog=Mesbah_db;Integrated Security=True" //server - //"MesbahDb": "Data Source=171.22.24.15;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]is[3019]#@ATt;TrustServerCertificate=true;", - + //"MesbahDb": "Data Source=171.22.24.15;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]18[3019]#@ATt;TrustServerCertificate=true;", + //local "MesbahDb": "Data Source=.;Initial Catalog=mesbah_db;Integrated Security=True;TrustServerCertificate=true;",