From 79a38c31a8be04785503fcfe3622dbce9ae6ef4a Mon Sep 17 00:00:00 2001 From: SamSys Date: Tue, 24 Dec 2024 16:57:11 +0330 Subject: [PATCH] Onpage Handler CaseHistory-> Edit and WorkFlow->Edit --- ...omizeWorkshopEmployeeSettingsRepository.cs | 1 + ...ustomizeWorkshopGroupSettingsRepository.cs | 1 + .../Entities/CustomizeWorkshopSettings.cs | 27 +- .../CreateCustomizeWorkshopGroupSettings.cs | 4 +- ...tomizeWorkshopEmployeeSettingsViewModel.cs | 5 +- .../ICustomizeWorkshopSettingsApplication.cs | 10 +- .../RollCall/EmployeeRollCallRecord.cs | 13 +- .../RollCall/EmployeeRollCallsViewModel.cs | 1 + .../RollCall/IRollCallApplication.cs | 12 +- ...CallEditableDatesForManualEditViewModel.cs | 15 + .../CustomizeWorkshopSettingsApplication.cs | 43 +- .../RollCallApplication.cs | 739 ++++++++++-------- .../Repository/CheckoutRepository.cs | 3 +- ...omizeWorkshopEmployeeSettingsRepository.cs | 6 + ...ustomizeWorkshopGroupSettingsRepository.cs | 25 + .../Pages/Company/RollCall/Options.cshtml.cs | 5 +- .../Company/RollCall/CameraAccounts.cshtml.cs | 2 +- .../Pages/Company/RollCall/CaseHistory.cshtml | 2 +- .../Company/RollCall/CaseHistory.cshtml.cs | 384 +++++---- .../Company/RollCall/CurrentDay.cshtml.cs | 8 +- .../Pages/Company/RollCall/Grouping.cshtml | 76 +- .../Pages/Company/RollCall/Grouping.cshtml.cs | 27 +- .../Pages/Company/RollCall/Index.cshtml | 4 +- .../Pages/Company/RollCall/Index.cshtml.cs | 5 +- .../Company/RollCall/ModalAddRollCall.cshtml | 130 ++- .../RollCall/ModalCreateAccountSetting.cshtml | 19 +- .../Company/RollCall/ModalCreateGroup.cshtml | 50 +- .../ModalEditEmployeeFromGroup.cshtml | 50 +- .../Company/RollCall/ModalEditGroup.cshtml | 57 +- .../Company/RollCall/ModalEditRollCall.cshtml | 389 +++++++-- .../RollCall/ModalSettingWorkTime.cshtml | 48 +- .../AssetsClient/pages/RollCall/css/Group.css | 1 + .../pages/RollCall/css/ModalCreateGroup.css | 27 +- .../css/ModalEditEmployeeFromGroup.css | 83 +- .../pages/RollCall/css/ModalEditGroup.css | 150 +--- .../RollCall/css/ModalSettingWorkTime.css | 105 ++- .../RollCall/js/ModalAddEmployeeToGroup.js | 7 +- .../pages/RollCall/js/ModalAddRollCall.js | 507 ++++++++---- .../pages/RollCall/js/ModalCameraAccount.js | 173 ++-- .../pages/RollCall/js/ModalChangeName.js | 4 +- .../RollCall/js/ModalEditEmployeeGroup.js | 28 +- .../pages/RollCall/js/ModalEditGroup.js | 29 +- .../pages/RollCall/js/ModalEditRollCall.js | 352 ++++++--- .../pages/RollCall/js/modalcreategroup.js | 28 +- .../WorkFlowApplication.cs | 2 +- .../WorkFlowCustomizedWorkshopSettingsACL.cs | 2 +- 46 files changed, 2508 insertions(+), 1151 deletions(-) create mode 100644 CompanyManagment.App.Contracts/RollCall/RollCallEditableDatesForManualEditViewModel.cs diff --git a/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs b/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs index 22e91dc6..624a931f 100644 --- a/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs +++ b/Company.Domain/CustomizeWorkshopEmployeeSettingsAgg/ICustomizeWorkshopEmployeeSettingsRepository.cs @@ -8,6 +8,7 @@ namespace Company.Domain.CustomizeWorkshopEmployeeSettingsAgg; public interface ICustomizeWorkshopEmployeeSettingsRepository : IRepository { EditCustomizeEmployeeSettings GetCustomizeEmployeeSettingsDetails(long customizeEmployeeId); + CustomizeWorkshopEmployeeSettings GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(long workshopId, long employeeId); CustomizeWorkshopEmployeeSettings GetByEmployeeIdGroupSettingsId(long workshopId, long employeeId); void Remove(long id); List GetBy(long groupId); diff --git a/Company.Domain/CustomizeWorkshopGroupSettingsAgg/ICustomizeWorkshopGroupSettingsRepository.cs b/Company.Domain/CustomizeWorkshopGroupSettingsAgg/ICustomizeWorkshopGroupSettingsRepository.cs index 012fc43f..29f39d5a 100644 --- a/Company.Domain/CustomizeWorkshopGroupSettingsAgg/ICustomizeWorkshopGroupSettingsRepository.cs +++ b/Company.Domain/CustomizeWorkshopGroupSettingsAgg/ICustomizeWorkshopGroupSettingsRepository.cs @@ -11,6 +11,7 @@ public interface ICustomizeWorkshopGroupSettingsRepository : IRepository GetEmployeesWithoutGroup(long workshopId); + List GetEmployeesWithoutGroupByWorkshopId(long workshopId); CustomizeWorkshopGroupSettings GetWithEmployees(long groupId); List GetShiftChangedEmployeeSettingsByGroupSettingsId(long groupSettingsId); List GetSettingChangedEmployeeSettingsByGroupSettingsId(long groupSettingsId); diff --git a/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs b/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs index 5fb30dbf..0a3e2537 100644 --- a/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs +++ b/Company.Domain/CustomizeWorkshopSettingsAgg/Entities/CustomizeWorkshopSettings.cs @@ -129,23 +129,26 @@ public class CustomizeWorkshopSettings : BaseCustomizeEntity Currency = currency; } - public void ChangeWorkshopShifts(ICollection customizeWorkshopSettingsShifts, WorkshopShiftStatus workshopShiftStatus) - { - WorkshopShiftStatus = workshopShiftStatus; - CustomizeWorkshopSettingsShifts = workshopShiftStatus == WorkshopShiftStatus.Regular ? customizeWorkshopSettingsShifts : new List(); - 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); - - + public void ChangeWorkshopShifts(ICollection customizeWorkshopSettingsShifts, + WorkshopShiftStatus workshopShiftStatus, FridayWork fridayWork, HolidayWork holidayWork) + { + WorkshopShiftStatus = workshopShiftStatus; + HolidayWork = holidayWork; + FridayWork = fridayWork; + CustomizeWorkshopSettingsShifts = workshopShiftStatus == WorkshopShiftStatus.Regular ? customizeWorkshopSettingsShifts : new List(); + 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); EndTimeOffSet = TimeOnly.FromDateTime(lastEndShift.Add(offSet)); } - } + } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs index b75f9d57..4354f2f4 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CreateCustomizeWorkshopGroupSettings.cs @@ -7,7 +7,6 @@ namespace CompanyManagment.App.Contracts.CustomizeWorkshopSettings; public class CreateCustomizeWorkshopGroupSettings { - public string Name { get; set; } public string Salary { get; set; } public long CustomizeWorkshopSettingId { get; set; } @@ -15,4 +14,7 @@ public class CreateCustomizeWorkshopGroupSettings public WorkshopShiftStatus WorkshopShiftStatus { get; set; } public IrregularShift IrregularShift { get; set; } public BreakTime BreakTime { get; set; } + public int LeavePermittedDays { get; set; } + public FridayWork FridayWork { get; set; } + public HolidayWork HolidayWork { get; set; } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs index cfe43275..015d5438 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/CustomizeWorkshopEmployeeSettingsViewModel.cs @@ -18,7 +18,10 @@ public class CustomizeWorkshopEmployeeSettingsViewModel public List RollCallWorkshopShifts { get; set; } public WorkshopShiftStatus WorkshopShiftStatus { get; set; } public IrregularShift IrregularShift { get; set; } - + public long GroupSettingsId { get; set; } public bool ChangeSettingEmployeeShiftIsChange { get; set; } public BreakTime BreakTime { get; set; } + public HolidayWork HolidayWork { get; set; } + public FridayWork FridayWork { get; set; } + public int LeavePermittedDays { 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 fde3fe54..cb6aef7b 100644 --- a/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs +++ b/CompanyManagment.App.Contracts/CustomizeWorkshopSettings/ICustomizeWorkshopSettingsApplication.cs @@ -50,10 +50,10 @@ public interface ICustomizeWorkshopSettingsApplication /// /// OperationResult EditWorkshopSettingShifts(List shiftViewModels, - long customizeWorkshopSettingsId,WorkshopShiftStatus workshopShiftStatus); + long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus, FridayWork fridayWork, HolidayWork holidayWork); - // It will Get the Workshop Settings with its groups and the employees of groups. - CustomizeWorkshopSettingsViewModel GetWorkshopSettingsByWorkshopId(long workshopId, AuthViewModel auth); + // It will Get the Workshop Settings with its groups and the employees of groups. + CustomizeWorkshopSettingsViewModel GetWorkshopSettingsByWorkshopId(long workshopId, AuthViewModel auth); public CustomizeWorkshopEmployeeSettingsViewModel GetEmployeeSettingsByEmployeeIdWorkshopId(long workshopId, long employeeId); @@ -63,6 +63,8 @@ public interface ICustomizeWorkshopSettingsApplication List GetEmployeesWithoutGroup(long customizeWorkshopSettingId); + CustomizeWorkshopEmployeeSettingsViewModel GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(long workshopId, long employeeId); + CustomizeWorkshopEmployeeSettingsViewModel GetEmployeeSettingsByEmployeeIdGroupSettingsId(long workshopId, long employeeId); List GetEmployeeSettingsByGroupSettingsId(long groupSettingsId); @@ -80,7 +82,7 @@ public interface ICustomizeWorkshopSettingsApplication EditCustomizeEmployeeSettings GetCustomizeEmployeeSettingsDetails(long customizeEmployeeId); - + List GetEmployeesWithoutGroupByWorkshopId(long workshopId); List GetShiftChangesGroupAndEmployees(long customizeWorkshopSettingsId); List GetEmployeeSettingsByWorkshopId(long workshopId); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallRecord.cs b/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallRecord.cs index e1bb27c4..21829642 100644 --- a/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallRecord.cs +++ b/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallRecord.cs @@ -4,9 +4,12 @@ namespace CompanyManagment.App.Contracts.RollCall { public class EmployeeRollCallRecord { - public long RollCallId { get; set; } - public DateTime Date { get; set; } - public string StartTime { get; set; } - public string EndTime { get; set; } - } + public long RollCallId { get; set; } + public DateTime Date { get; set; } + + public string StartDate { get; set; } + public string StartTime { get; set; } + public string EndDate { get; set; } + public string EndTime { get; set; } + } } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallsViewModel.cs b/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallsViewModel.cs index 71ac7bef..5b5a10a6 100644 --- a/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallsViewModel.cs +++ b/CompanyManagment.App.Contracts/RollCall/EmployeeRollCallsViewModel.cs @@ -10,5 +10,6 @@ namespace CompanyManagment.App.Contracts.RollCall public string EmployeeFullName { get; set; } public string DateFa { get; set; } public List RollCalls { get; set; } + public List EditableDates { get; set; } } } diff --git a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs index c8b80af8..e9d981da 100644 --- a/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs +++ b/CompanyManagment.App.Contracts/RollCall/IRollCallApplication.cs @@ -46,10 +46,14 @@ namespace CompanyManagment.App.Contracts.RollCall TimeSpan GetEmployeeRollCallTimeSpanForDuration(long employeeId, long workshopId, string startFa, string endFa); - /// - /// برای صدور فیش حقوقی - /// - List GetActiveEmployeeRollCallsForDuration(long employeeId, long workshopId, + /// + /// دریافت بازه قابل تغییر برای ویرایش دستی حضور غیاب + /// + List GetEditableDatesForManualEdit(DateTime date); + /// + /// برای صدور فیش حقوقی + /// + List GetActiveEmployeeRollCallsForDuration(long employeeId, long workshopId, string startDate, string endDate); diff --git a/CompanyManagment.App.Contracts/RollCall/RollCallEditableDatesForManualEditViewModel.cs b/CompanyManagment.App.Contracts/RollCall/RollCallEditableDatesForManualEditViewModel.cs new file mode 100644 index 00000000..51c3ea43 --- /dev/null +++ b/CompanyManagment.App.Contracts/RollCall/RollCallEditableDatesForManualEditViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CompanyManagment.App.Contracts.RollCall +{ + public class RollCallEditableDatesForManualEditViewModel + { + public string StartFa{ get; set; } + public string EndFa { get; set; } + public string DayOfWeekFa { get; set; } + } +} diff --git a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs index 627eb243..d287bc8d 100644 --- a/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs +++ b/CompanyManagment.Application/CustomizeWorkshopSettingsApplication.cs @@ -326,7 +326,8 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo } //Create Employee Settings with Group data. It will Replace the Group data (such as salary, shifts and ...) on Employee settings On creation. - public OperationResult EditWorkshopSettingShifts(List shiftViewModels, long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus) + public OperationResult EditWorkshopSettingShifts(List shiftViewModels, long customizeWorkshopSettingsId, + WorkshopShiftStatus workshopShiftStatus, FridayWork fridayWork, HolidayWork holidayWork) { OperationResult op = new OperationResult(); var entity = _customizeWorkshopSettingsRepository.Get(customizeWorkshopSettingsId); @@ -414,7 +415,7 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo #endregion using var transActionScope = new TransactionScope(); - entity.ChangeWorkshopShifts(shiftCollection, workshopShiftStatus); + entity.ChangeWorkshopShifts(shiftCollection, workshopShiftStatus, fridayWork, holidayWork); //op = ChangeAllGroupsShiftsWithEmployees(entity, replaceChangedGroups); @@ -1115,6 +1116,39 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo return record; } + public CustomizeWorkshopEmployeeSettingsViewModel GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(long workshopId, + long employeeId) + { + var entity = + _customizeWorkshopEmployeeSettingsRepository.GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(workshopId, employeeId); + if (entity == null) + return new(); + + string employeeFullName = _employeeRepository.Get(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 + }; + } + public CustomizeWorkshopEmployeeSettingsViewModel GetEmployeeSettingsByEmployeeIdGroupSettingsId(long workshopId, long employeeId) { var entity = @@ -1194,6 +1228,11 @@ public class CustomizeWorkshopSettingsApplication(ICustomizeWorkshopSettingsRepo return _customizeWorkshopEmployeeSettingsRepository.GetCustomizeEmployeeSettingsDetails(customizeEmployeeId); } + public List GetEmployeesWithoutGroupByWorkshopId(long workshopId) + { + return _customizeWorkshopGroupSettingsRepository.GetEmployeesWithoutGroupByWorkshopId(workshopId); + } + public List GetShiftChangesGroupAndEmployees(long customizeWorkshopSettingsId) { return _customizeWorkshopSettingsRepository.GetShiftChangesGroupAndEmployees(customizeWorkshopSettingsId); diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index 03c383ce..a556dccf 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -5,10 +5,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using _0_Framework.Application; +using Company.Domain.CheckoutAgg; +using Company.Domain.CustomizeCheckoutAgg; using Company.Domain.EmployeeAgg; using Company.Domain.LeaveAgg; using Company.Domain.RollCallAgg; using Company.Domain.RollCallEmployeeAgg; +using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.RollCall; @@ -16,59 +19,63 @@ namespace CompanyManagment.Application; public class RollCallApplication : IRollCallApplication { - private readonly IRollCallRepository _rollCallRepository; - private readonly IEmployeeApplication _employeeApplication; - private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; - private readonly IEmployeeRepository _employeeRepository; - private readonly ILeaveRepository _leaveRepository; + private readonly IRollCallRepository _rollCallRepository; + private readonly IEmployeeApplication _employeeApplication; + private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; + private readonly IEmployeeRepository _employeeRepository; + private readonly ILeaveRepository _leaveRepository; + private readonly ICustomizeCheckoutRepository _customizeCheckoutRepository; + private readonly ICheckoutRepository _checkoutRepository; - public RollCallApplication(IRollCallRepository rollCallRepository, IEmployeeApplication employeeApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository) - { - _rollCallRepository = rollCallRepository; - _employeeApplication = employeeApplication; - _rollCallEmployeeRepository = rollCallEmployeeRepository; - _employeeRepository = employeeRepository; - _leaveRepository = leaveRepository; - } + public RollCallApplication(IRollCallRepository rollCallRepository, IEmployeeApplication employeeApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository, ICustomizeCheckoutRepository customizeCheckoutRepository, ICheckoutRepository checkoutRepository) + { + _rollCallRepository = rollCallRepository; + _employeeApplication = employeeApplication; + _rollCallEmployeeRepository = rollCallEmployeeRepository; + _employeeRepository = employeeRepository; + _leaveRepository = leaveRepository; + _customizeCheckoutRepository = customizeCheckoutRepository; + _checkoutRepository = checkoutRepository; + } - public OperationResult Create(CreateRollCall command) - { - var opration = new OperationResult(); - var startDateFa = command.StartDate.ToFarsi(); + public OperationResult Create(CreateRollCall command) + { + var opration = new OperationResult(); + var startDateFa = command.StartDate.ToFarsi(); - var yearFa = Convert.ToInt32(startDateFa.Substring(0, 4)); - var monthFa = Convert.ToInt32(startDateFa.Substring(5, 2)); - var employeeName = _employeeApplication.GetDetails(command.EmployeeId).EmployeeFullName; - var create = new RollCall(command.WorkshopId, command.EmployeeId, employeeName, command.StartDate, null, - yearFa, monthFa); - _rollCallRepository.Create(create); - _rollCallRepository.SaveChanges(); - return opration.Succcedded(); - } + var yearFa = Convert.ToInt32(startDateFa.Substring(0, 4)); + var monthFa = Convert.ToInt32(startDateFa.Substring(5, 2)); + var employeeName = _employeeApplication.GetDetails(command.EmployeeId).EmployeeFullName; + var create = new RollCall(command.WorkshopId, command.EmployeeId, employeeName, command.StartDate, null, + yearFa, monthFa); + _rollCallRepository.Create(create); + _rollCallRepository.SaveChanges(); + return opration.Succcedded(); + } - public OperationResult Edit(long id) - { - var opration = new OperationResult(); - var personRollCall = _rollCallRepository.Get(id); - if (personRollCall == null) - opration.Failed("رکورد مورد نظر وجود ندارد"); - var now = DateTime.Now; + public OperationResult Edit(long id) + { + var opration = new OperationResult(); + var personRollCall = _rollCallRepository.Get(id); + if (personRollCall == null) + opration.Failed("رکورد مورد نظر وجود ندارد"); + var now = DateTime.Now; personRollCall.SetEndDateTime(now); _rollCallRepository.SaveChanges(); - return opration.Succcedded(); - } + return opration.Succcedded(); + } - public EditRollCall GetByEmployeeIdAndWorkshopId(long employeeId, long workshopId) - { - return _rollCallRepository.GetByEmployeeIdAndWorkshopId(employeeId, workshopId); - } + public EditRollCall GetByEmployeeIdAndWorkshopId(long employeeId, long workshopId) + { + return _rollCallRepository.GetByEmployeeIdAndWorkshopId(employeeId, workshopId); + } - public EditRollCall GetById(long id) - { - return _rollCallRepository.GetById(id); - } + public EditRollCall GetById(long id) + { + return _rollCallRepository.GetById(id); + } @@ -82,305 +89,371 @@ public class RollCallApplication : IRollCallApplication if (endFa.TryToGeorgianDateTime(out DateTime endDateTime) == false) return TimeSpan.Zero; - if(startDateTime > endDateTime) - return TimeSpan.Zero; + if (startDateTime > endDateTime) + return TimeSpan.Zero; return _rollCallRepository.GetEmployeeRollCallTimeSpanForDuration(employeeId, workshopId, startDateTime, endDateTime); } + public List GetEditableDatesForManualEdit(DateTime date) + { + var date1 = new RollCallEditableDatesForManualEditViewModel() + { + StartFa = date.AddDays(-1).Date.ToFarsi(), + EndFa = date.Date.ToFarsi(), + + }; + var date2 = new RollCallEditableDatesForManualEditViewModel() + { + StartFa = date.Date.ToFarsi(), + EndFa = date.Date.ToFarsi() + }; + var date3 = new RollCallEditableDatesForManualEditViewModel() + { + StartFa = date.Date.ToFarsi(), + EndFa = date.AddDays(1).Date.ToFarsi() + }; + + return [date1, date2, date3]; + } + + + public List GetOverlappedRollCallsWithLeaveInDates(long workshopId, DateTime start, DateTime end) + { + return _rollCallRepository.GetOverlappedRollCallsWithLeaveInDates(workshopId, start, end); + } + + public List GetUndefinedRollCallWorkFlowsService(long workshopId, DateTime durationStart, DateTime durationEnd) + { + return _rollCallRepository.GetUndefinedRollCallWorkFlowsInDates(workshopId, durationStart, durationEnd); + } + + + public OperationResult RemoveEmployeeRollCallsInDate(long workshopId, long employeeId, string dateFa) + { + OperationResult op = new(); + var date = dateFa.ToGeorgianDateTime(); + if (date == Tools.GetUndefinedDateTime()) + return op.Failed("خطای سیستمی"); + _rollCallRepository.RemoveEmployeeRollCallsInDate(workshopId, employeeId, date); + _rollCallRepository.SaveChanges(); + return op.Succcedded(); + } + public RollCallsByDateViewModel GetWorkshopRollCallHistory(RollCallSearchModel searchModel) + { + return _rollCallRepository.GetWorkshopRollCallHistory(searchModel); + } + + public CurrentDayRollCall GetWorkshopCurrentDayRollCalls(long workshopId) + { + return _rollCallRepository.GetWorkshopCurrentDayRollCalls(workshopId); + } + + public List GetActiveEmployeeRollCallsForDuration(long employeeId, long workshopId, string startDate, + string endDate) + { + if (!string.IsNullOrWhiteSpace(startDate) || !string.IsNullOrWhiteSpace(endDate)) + return new(); + + var startDateGr = startDate.ToGeorgianDateTime(); + var endDateGr = endDate.ToGeorgianDateTime(); + + if (startDateGr >= endDateGr) + return new(); + + //if (!_rollCallEmployeeRepository.Exists(x => x.EmployeeId == employeeId && + // x.WorkshopId == workshopId && x.IsActiveString == "true")) + // return new(); + return _rollCallRepository.GetEmployeeRollCallsForMonth(employeeId, workshopId, startDateGr, endDateGr); + } + + + public EmployeeRollCallsByMonthViewModel GetEmployeeRollCallsHistory(long employeeId, long workshopId, string startDateTime, string endDateTime, string exactDateTime, + string dateIndex) + { + DateTime? startDateTimeGr = null; + DateTime? endDateTimeGr = null; + if (!string.IsNullOrWhiteSpace(startDateTime) && !string.IsNullOrWhiteSpace(endDateTime)) + { + startDateTimeGr = startDateTime.ToGeorgianDateTime(); + endDateTimeGr = endDateTime.ToGeorgianDateTime(); + if (endDateTimeGr < startDateTimeGr) + { + return new(); + } + + } + + DateTime? exactDateTimeGr = + !string.IsNullOrWhiteSpace(exactDateTime) ? exactDateTime.ToGeorgianDateTime() : null; + + + DateTime? index = null; + if (!string.IsNullOrWhiteSpace(dateIndex)) + { + index = dateIndex.ToGeorgianDateTime(); + index = (index.Value.Date >= DateTime.Now) || (index.Value == new DateTime(3000, 12, 20, new PersianCalendar())) ? null : index; + + } + + return _rollCallRepository.GetEmployeeRollCallsHistory(employeeId, workshopId, startDateTimeGr, endDateTimeGr, exactDateTimeGr, index); + } + + + /// + /// افزودن حضور غیاب به صورت دستی. اگر آیدی رکورد صفر باشد رکورد جدید، در غیر این صورت ویرایش می کند + /// + public OperationResult ManualEdit(CreateOrEditEmployeeRollCall command) + { + var operation = new OperationResult(); + + DateTime date = command.DateFa.ToGeorgianDateTime(); + if (date == Tools.GetUndefinedDateTime()) + return operation.Failed("فرمت تاریخ وارد شده صحیح نمی باشد"); + + if (date >= DateTime.Now.Date) + { + return operation.Failed("امکان اضافه کردن حضور غیاب برای روز جاری و روز های آینده وجود ندارد"); + } + + var twoDaysEarlier = date.AddDays(-2).Date; + var twoDaysLater = date.AddDays(2).Date >= DateTime.Today + ? (date.AddDays(1).Date >= DateTime.Today ? DateTime.Today : date.AddDays(1).Date) + : date.AddDays(2).Date; + + if (command.WorkshopId < 1) + { + return operation.Failed("خطای سیستمی"); + } + + if (command.RollCallRecords == null || command.RollCallRecords.Count == 0) + return operation.Failed("خطای سیستمی"); + + + if (_leaveRepository.HasDailyLeave(command.EmployeeId, command.WorkshopId, date)) + return operation.Failed("در روز مرخصی کارمند نمی توانید حضور غیاب ثبت کنید"); + + var employeeStatuses = _rollCallEmployeeRepository.GetByEmployeeIdWithStatuses(command.EmployeeId) + .FirstOrDefault(x => x.WorkshopId == command.WorkshopId)?.Statuses; + + var employeeRollCalls = _rollCallRepository.GetEmployeeRollCallsHistoryAllInDates(command.WorkshopId, command.EmployeeId, twoDaysEarlier, twoDaysLater); + + //if (employeeRollCalls.Any(x => x.StartDate.Value.Date== x.EndDate == null)) + // return operation.Failed("به دلیل عدم ثبت خروج پرسنل در این تاریخ، شما قادر به افزودن رکورد جدید نمی باشید"); + + if (command.RollCallRecords.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) + return operation.Failed("ساعات شروع و پایان نمیتوانند خالی باشد"); + + + DateTime day = command.DateFa.ToGeorgianDateTime(); + if (day == Tools.GetUndefinedDateTime()) + return operation.Failed("خطای سیستمی"); + + List newRollCallDates = new(); + + foreach (var record in command.RollCallRecords) + { + if (record.StartDate.TryToGeorgianDateTime(out var startDateGr) == false || record.EndDate.TryToGeorgianDateTime(out var endDateGr) == false) + return operation.Failed("فرمت تاریخ صحیح نمی باشد"); + + + if (TimeOnly.TryParse(record.StartTime, out var startTimeOnly) == false || TimeOnly.TryParse(record.EndTime, out var endTimeOnly) == false) + return operation.Failed("فرمت ساعت صحیح نمی باشد"); + DateTime startDateTime = startDateGr + startTimeOnly.ToTimeSpan(); + DateTime endDateTime = endDateGr + endTimeOnly.ToTimeSpan(); + + if (startDateTime >= endDateTime) + return operation.Failed("زمان ورود نمی تواند بعد یا مساوی زمان خروج باشد"); + + if (endDateTime.Date >= DateTime.Today) + return operation.Failed("نمی توانید برای روز جاری یا روز های آینده حضور غیاب ثبت کنید"); + + var rollCall = new EditRollCall + { + StartDate = startDateTime, + EndDate = endDateTime, + Id = record.RollCallId + }; + newRollCallDates.Add(rollCall); + } + + if (newRollCallDates.Any(x => newRollCallDates.Any(y => x != y && x.EndDate >= y.StartDate && x.StartDate <= y.EndDate))) + return operation.Failed("بازه های وارد شده با هم تداخل دارند"); + + + //foreach (var item in preprocessedRollCalls) + //{ + // (DateTime Start, DateTime End, long RollCallId) rollCallWithDateTime = + // new() + // { + // Start = new DateTime(DateOnly.FromDateTime(day), item.start), + // End = new DateTime(DateOnly.FromDateTime(day), item.end), + // RollCallId = item.rollCallId + + // }; + + // if (previousEnd != new DateTime()) + // { + // if (rollCallWithDateTime.Start < previousEnd) + // { + // rollCallWithDateTime.Start = rollCallWithDateTime.Start.AddDays(1); + // } + // if (rollCallWithDateTime.Start == previousEnd) + // return operation.Failed("ساعت ورود نمی تواند با ساعت خروج حضور غیاب دیگری در آن روز برابر باشد"); + + // } + // while (rollCallWithDateTime.Start >= rollCallWithDateTime.End) + // { + // rollCallWithDateTime.End = rollCallWithDateTime.End.AddDays(1); + // } + // result.Add(rollCallWithDateTime); + // previousEnd = rollCallWithDateTime.End; + //} + //var firstShiftStart = result.OrderBy(x => x.Start).FirstOrDefault().Start; + //var lastShiftEnd = result.OrderByDescending(x => x.Start).FirstOrDefault().End; + //var lastShiftStart = result.OrderByDescending(x => x.Start).FirstOrDefault().Start; + + //if (firstShiftStart.AddDays(1) < lastShiftEnd) + // return operation.Failed("بازه زمانی وارد شده نا معتبر است"); + //if (result.Sum(x => (x.End - x.Start).TotalHours) > 24) + //{ + // return operation.Failed("بازه زمانی نمیتواند بیشتر از 24 ساعت باشد"); + //} + //if (firstShiftStart.Date != lastShiftStart.Date) + // return operation.Failed("شروع رکورد حضور غیاب نمی تواند در روز های بعد از تاریخ تعیین شده باشد"); + + + foreach (var activity in newRollCallDates) + { + + //مرخصی روزانه در بالا چک شده است + var leave = _leaveRepository.GetByWorkshopIdEmployeeIdInDates(command.WorkshopId, command.EmployeeId, activity.StartDate.Value, activity.EndDate.Value) + .Where(x => x.PaidLeaveType == "ساعتی"); + if (leave.Any()) + return operation.Failed("کارمند در بازه انتخاب شده مرخصی ساعتی دارد"); + } + + if (newRollCallDates == null || !newRollCallDates.All(x => employeeStatuses.Any(y => x.StartDate >= y.StartDateGr && x.EndDate <= y.EndDateGr))) + return operation.Failed("کارمند در بازه وارد شده غیر فعال است"); + var editableDates = GetEditableDatesForManualEdit(date); + + if (newRollCallDates.Any(x => !editableDates.Any(y => + x.StartDate.Value.Date == y.StartFa.ToGeorgianDateTime().Date && + x.EndDate.Value.Date == y.EndFa.ToGeorgianDateTime().Date))) + { + return operation.Failed("حضور غیاب در حال ویرایش را نمیتوانید بیشتر از یک روز از ثبت حضور غیاب عقب تر یا جلو تر ببرید"); + } + + if (newRollCallDates.Any(x => employeeRollCalls.Any(y => + y.StartDate.Value.Date != command.DateFa.ToGeorgianDateTime().Date && + x.EndDate >= y.StartDate.Value && x.StartDate <= y.EndDate.Value))) + return operation.Failed("بازه های وارد شده با حضور غیاب های مربوط به روز های قبل و بعد تداخل زمانی دارد"); + + + var checkoutViewModels = _checkoutRepository.SimpleSearch(new CheckoutSearchModel() { WorkshopId = command.WorkshopId, EmployeeId = command.EmployeeId }); + + if (checkoutViewModels.Any(x => x.HasRollCall && x.WorkshopId == command.WorkshopId && x.EmployeeId == command.EmployeeId && + newRollCallDates.Any(y => (y.StartDate.Value.Date >= x.ContractStartGr.Date) + && (y.StartDate.Value.Date <= x.ContractEndGr.Date)))) + return operation.Failed("برای بازه های وارد شده فیش حقوقی ثبت شده است"); + + //return operation.Failed("برای بازه های وارد شده فیش حقوقی ثبت شده است، برای ویرایش حضور و غیاب باید فیش حقوقی را پاک کنید"); + + //if (_customizeCheckoutRepository.Exists(x => + // newRollCallDates.Any(y => y.Start.Date >= x.ContractStart.Date && + // y.Start.Date <= x.ContractEnd.Date))) + // return operation.Failed("برای بازه های وارد شده فیش حقوقی غیر رسمی نهایی ثبت شده است"); + + + //if (_customizeCheckoutTempRepository.Exists(x => + // newRollCallDates.Any(y => y.Start.Date >= x.ContractStart.Date && + // y.Start.Date <= x.ContractEnd.Date))) + // return operation.Failed("برای بازه های وارد شده فیش حقوقی غیر رسمی موقت شده است"); + + var name = _rollCallEmployeeRepository.GetByEmployeeIdAndWorkshopId(command.EmployeeId, command.WorkshopId).EmployeeFullName; + var rollCallsAsEntityModels = newRollCallDates.Select(x => new RollCall(command.WorkshopId, command.EmployeeId, name, x.StartDate, x.EndDate, + Convert.ToInt32(x.StartDate.Value.ToFarsi().Substring(0, 4)), Convert.ToInt32(x.StartDate.ToFarsi().Substring(5, 2)), RollCallModifyType.EditByEmployer)).ToList(); + _rollCallRepository.RemoveEmployeeRollCallsInDate(command.WorkshopId, command.EmployeeId, date); + + + _rollCallRepository.AddRange(rollCallsAsEntityModels); + _rollCallRepository.SaveChanges(); + return operation.Succcedded(); + } + + + public List GetWorkshopEmployeeRollCallsForDate(long workshopId, long employeeId, string dateFa) + { + DateTime date = Tools.ToGeorgianDateTime(dateFa); + if (date == Tools.GetUndefinedDateTime()) + return new(); + var res = _rollCallRepository.GetWorkshopEmployeeRollCallsForDate(workshopId, employeeId, date); + return res; + } + + public IEnumerable GetNotSlicedRollCallsByWorkshopId(long workshopId, DateTime durationStart, DateTime durationEnd) + { + return _rollCallRepository.GetNotSlicedRollCallsByWorkshopId(workshopId, durationStart, durationEnd); + } + + public List GetWorkshopAbsentHistory(long workshopId, DateTime startSearch, DateTime endSearch) + { + return _rollCallRepository.GetWorkshopAbsentHistory(workshopId, startSearch, endSearch); + } + + public OperationResult SetModifyTypeToNone(long rollCallId) + { + var operation = new OperationResult(); + + var rollCall = _rollCallRepository.Get(rollCallId); + + if (rollCall == null) + return operation.Failed("چنین آیتمی یافت نشد"); + + rollCall.SetModifyType(RollCallModifyType.None); + + _rollCallRepository.SaveChanges(); + + return operation.Succcedded(); + } + + public OperationResult SetModifyTypeToEditByEmployer(long rollCallId) + { + var operation = new OperationResult(); + + var rollCall = _rollCallRepository.Get(rollCallId); + + if (rollCall == null) + return operation.Failed("چنین آیتمی یافت نشد"); + + rollCall.SetModifyType(RollCallModifyType.EditByEmployer); + + _rollCallRepository.SaveChanges(); + + return operation.Succcedded(); + } - public List GetOverlappedRollCallsWithLeaveInDates(long workshopId, DateTime start, DateTime end) - { - return _rollCallRepository.GetOverlappedRollCallsWithLeaveInDates(workshopId, start, end); - } + public List GetRollCallWorkFlowsCutByBgService(long workshopId, DateTime start, DateTime end) + { + return _rollCallRepository.GetRollCallWorkFlowsCutByBgService(workshopId, start, end); + } - public List GetUndefinedRollCallWorkFlowsService(long workshopId, DateTime durationStart, DateTime durationEnd) - { - return _rollCallRepository.GetUndefinedRollCallWorkFlowsInDates(workshopId, durationStart, durationEnd); - } - public OperationResult RemoveEmployeeRollCallsInDate(long workshopId, long employeeId, string dateFa) - { - OperationResult op = new(); - var date = dateFa.ToGeorgianDateTime(); - if (date == Tools.GetUndefinedDateTime()) - return op.Failed("خطای سیستمی"); - _rollCallRepository.RemoveEmployeeRollCallsInDate(workshopId, employeeId, date); - _rollCallRepository.SaveChanges(); - return op.Succcedded(); - } - public RollCallsByDateViewModel GetWorkshopRollCallHistory(RollCallSearchModel searchModel) - { - return _rollCallRepository.GetWorkshopRollCallHistory(searchModel); - } - public CurrentDayRollCall GetWorkshopCurrentDayRollCalls(long workshopId) - { - return _rollCallRepository.GetWorkshopCurrentDayRollCalls(workshopId); - } + public RollCallViewModel GetDetails(long rollCallId) + { + return _rollCallRepository.GetDetails(rollCallId); + } + #endregion + public long Flag(long employeeId, long workshopId) + { + return _rollCallRepository.Flag(employeeId, workshopId); + } - public List GetActiveEmployeeRollCallsForDuration(long employeeId, long workshopId, string startDate, - string endDate) - { - if (!string.IsNullOrWhiteSpace(startDate) || !string.IsNullOrWhiteSpace(endDate)) - return new(); - - var startDateGr = startDate.ToGeorgianDateTime(); - var endDateGr = endDate.ToGeorgianDateTime(); - - if (startDateGr >= endDateGr) - return new(); - - //if (!_rollCallEmployeeRepository.Exists(x => x.EmployeeId == employeeId && - // x.WorkshopId == workshopId && x.IsActiveString == "true")) - // return new(); - return _rollCallRepository.GetEmployeeRollCallsForMonth(employeeId, workshopId, startDateGr, endDateGr); - } - - - public EmployeeRollCallsByMonthViewModel GetEmployeeRollCallsHistory(long employeeId, long workshopId, string startDateTime, string endDateTime, string exactDateTime, - string dateIndex) - { - DateTime? startDateTimeGr = null; - DateTime? endDateTimeGr = null; - if (!string.IsNullOrWhiteSpace(startDateTime) && !string.IsNullOrWhiteSpace(endDateTime)) - { - startDateTimeGr = startDateTime.ToGeorgianDateTime(); - endDateTimeGr = endDateTime.ToGeorgianDateTime(); - if (endDateTimeGr < startDateTimeGr) - { - return new(); - } - - } - - DateTime? exactDateTimeGr = - !string.IsNullOrWhiteSpace(exactDateTime) ? exactDateTime.ToGeorgianDateTime() : null; - - - DateTime? index = null; - if (!string.IsNullOrWhiteSpace(dateIndex)) - { - index = dateIndex.ToGeorgianDateTime(); - index = (index.Value.Date >= DateTime.Now) || (index.Value == new DateTime(3000, 12, 20, new PersianCalendar())) ? null : index; - - } - - return _rollCallRepository.GetEmployeeRollCallsHistory(employeeId, workshopId, startDateTimeGr, endDateTimeGr, exactDateTimeGr, index); - } - - - /// - /// افزودن حضور غیاب به صورت دستی. اگر آیدی رکورد صفر باشد رکورد جدید، در غیر این صورت ویرایش می کند - /// - public OperationResult ManualEdit(CreateOrEditEmployeeRollCall command) - { - var operation = new OperationResult(); - var activities = command.RollCallRecords.Select(x => (x.StartTime, x.EndTime)); - - DateTime date = command.DateFa.ToGeorgianDateTime(); - if (date == Tools.GetUndefinedDateTime()) - return operation.Failed("فرمت تاریخ وارد شده صحیح نمی باشد"); - - if (date >= DateTime.Now.Date) - { - return operation.Failed("امکان اضافه کردن حضور غیاب برای روز جاری و روز های آینده وجود ندارد"); - } - - if (command.WorkshopId < 1) - { - return operation.Failed("خطای سیستمی"); - } - - if (command.RollCallRecords == null || command.RollCallRecords.Count == 0) - return operation.Failed("خطای سیستمی"); - - if (_leaveRepository.HasDailyLeave(command.EmployeeId, command.WorkshopId, date)) - return operation.Failed("در روز مرخصی کارمند نمی توانید حضور غیاب ثبت کنید"); - - var employeeStatuses = _rollCallEmployeeRepository.GetByEmployeeIdWithStatuses(command.EmployeeId) - .FirstOrDefault(x => x.WorkshopId == command.WorkshopId)?.Statuses; - - //var employeeRollCalls = _rollCallRepository.GetWorkshopEmployeeRollCallsForDate(command.WorkshopId, command.EmployeeId, date); - - //if (employeeRollCalls.Any(x => x.EndDate == null && x.)) - // return operation.Failed("به دلیل عدم ثبت خروج پرسنل در این تاریخ، شما قادر به افزودن رکورد جدید نمی باشید"); - - if (command.RollCallRecords.Any(x => string.IsNullOrWhiteSpace(x.StartTime) || string.IsNullOrWhiteSpace(x.EndTime))) - return operation.Failed("ساعات شروع و پایان نمیتوانند خالی باشد"); - - #region RollCallTimes validation and parse to DateTime - - List<(TimeOnly start, TimeOnly end, long rollCallId)> preprocessedRollCalls = new(); - try - { - preprocessedRollCalls = command.RollCallRecords.Select(x => - { - - if (!TimeOnly.TryParseExact(x.StartTime, "HH:mm", out TimeOnly start)) - throw new Exception(); - if (!TimeOnly.TryParseExact(x.EndTime, "HH:mm", out TimeOnly end)) - throw new Exception(); - return (start, end, x.RollCallId); - - }).ToList(); - } - catch (Exception e) - { - - return operation.Failed("فرمت ساعات ورودی نادرست می باشد"); - } - - DateTime day = command.DateFa.ToGeorgianDateTime(); - if (day == Tools.GetUndefinedDateTime()) - return operation.Failed("خطای سیستمی"); - DateTime previousEnd = new DateTime(); - preprocessedRollCalls = preprocessedRollCalls.OrderBy(x => x.start).ToList(); - List<(DateTime Start, DateTime End, long RollCallId)> result = new(); - - - foreach (var item in preprocessedRollCalls) - { - (DateTime Start, DateTime End, long RollCallId) rollCallWithDateTime = - new() - { - Start = new DateTime(DateOnly.FromDateTime(day), item.start), - End = new DateTime(DateOnly.FromDateTime(day), item.end), - RollCallId = item.rollCallId - - }; - - if (previousEnd != new DateTime()) - { - if (rollCallWithDateTime.Start < previousEnd) - { - rollCallWithDateTime.Start = rollCallWithDateTime.Start.AddDays(1); - } - if (rollCallWithDateTime.Start == previousEnd) - return operation.Failed("ساعت ورود نمی تواند با ساعت خروج حضور غیاب دیگری در آن روز برابر باشد"); - - } - while (rollCallWithDateTime.Start >= rollCallWithDateTime.End) - { - rollCallWithDateTime.End = rollCallWithDateTime.End.AddDays(1); - } - result.Add(rollCallWithDateTime); - previousEnd = rollCallWithDateTime.End; - } - var firstShiftStart = result.OrderBy(x => x.Start).FirstOrDefault().Start; - var lastShiftEnd = result.OrderByDescending(x => x.Start).FirstOrDefault().End; - var lastShiftStart = result.OrderByDescending(x => x.Start).FirstOrDefault().Start; - - if (firstShiftStart.AddDays(1) < lastShiftEnd) - return operation.Failed("بازه زمانی وارد شده نا معتبر است"); - if (result.Sum(x => (x.End - x.Start).TotalHours) > 24) - { - return operation.Failed("بازه زمانی نمیتواند بیشتر از 24 ساعت باشد"); - } - if (firstShiftStart.Date != lastShiftStart.Date) - return operation.Failed("شروع رکورد حضور غیاب نمی تواند در روز های بعد از تاریخ تعیین شده باشد"); - - #endregion - foreach (var activity in result) - { - - //مرخصی روزانه در بالا چک شده است - var leave = _leaveRepository.GetByWorkshopIdEmployeeIdInDates(command.WorkshopId, command.EmployeeId, activity.Start, activity.End) - .Where(x => x.PaidLeaveType == "ساعتی"); - if (leave.Any()) - return operation.Failed("کارمند در بازه انتخاب شده مرخصی ساعتی دارد"); - } - - if (result == null || !result.All(x => employeeStatuses.Any(y => x.Start >= y.StartDateGr && x.End <= y.EndDateGr))) - return operation.Failed("کارمند در بازه وارد شده غیر فعال است"); - - - var name = _rollCallEmployeeRepository.GetByEmployeeIdAndWorkshopId(command.EmployeeId, command.WorkshopId).EmployeeFullName; - var rollCallsAsEntityModels = result.Select(x => new RollCall(command.WorkshopId, command.EmployeeId, name, x.Start, x.End, - Convert.ToInt32(x.Start.ToFarsi().Substring(0, 4)), Convert.ToInt32(x.Start.ToFarsi().Substring(5, 2)), RollCallModifyType.EditByEmployer)).ToList(); - _rollCallRepository.RemoveEmployeeRollCallsInDate(command.WorkshopId, command.EmployeeId, date); - - - _rollCallRepository.AddRange(rollCallsAsEntityModels); - _rollCallRepository.SaveChanges(); - return operation.Succcedded(); - } - - public List GetWorkshopEmployeeRollCallsForDate(long workshopId, long employeeId, string dateFa) - { - DateTime date = Tools.ToGeorgianDateTime(dateFa); - if (date == Tools.GetUndefinedDateTime()) - return new(); - var res = _rollCallRepository.GetWorkshopEmployeeRollCallsForDate(workshopId, employeeId, date); - return res; - } - - public IEnumerable GetNotSlicedRollCallsByWorkshopId(long workshopId, DateTime durationStart, DateTime durationEnd) - { - return _rollCallRepository.GetNotSlicedRollCallsByWorkshopId(workshopId, durationStart, durationEnd); - } - - public List GetWorkshopAbsentHistory(long workshopId, DateTime startSearch, DateTime endSearch) - { - return _rollCallRepository.GetWorkshopAbsentHistory(workshopId, startSearch, endSearch); - } - - public OperationResult SetModifyTypeToNone(long rollCallId) - { - var operation = new OperationResult(); - - var rollCall = _rollCallRepository.Get(rollCallId); - - if (rollCall == null) - return operation.Failed("چنین آیتمی یافت نشد"); - - rollCall.SetModifyType(RollCallModifyType.None); - - _rollCallRepository.SaveChanges(); - - return operation.Succcedded(); - } - - public OperationResult SetModifyTypeToEditByEmployer(long rollCallId) - { - var operation = new OperationResult(); - - var rollCall = _rollCallRepository.Get(rollCallId); - - if (rollCall == null) - return operation.Failed("چنین آیتمی یافت نشد"); - - rollCall.SetModifyType(RollCallModifyType.EditByEmployer); - - _rollCallRepository.SaveChanges(); - - return operation.Succcedded(); - } - - - - public List GetRollCallWorkFlowsCutByBgService(long workshopId, DateTime start, DateTime end) - { - return _rollCallRepository.GetRollCallWorkFlowsCutByBgService(workshopId, start, end); - } - - - - - public RollCallViewModel GetDetails(long rollCallId) - { - return _rollCallRepository.GetDetails(rollCallId); - } - #endregion - public long Flag(long employeeId, long workshopId) - { - return _rollCallRepository.Flag(employeeId, workshopId); - } - - public string CheckRepeat(long employeeId, long workshopId) - { - return _rollCallRepository.CheckRepeat(employeeId, workshopId); - } + public string CheckRepeat(long employeeId, long workshopId) + { + return _rollCallRepository.CheckRepeat(employeeId, workshopId); + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 500903c3..957ad3dc 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -509,7 +509,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos Year = x.Year, Month = x.Month, ContractNo = x.ContractNo, - ContractId = x.ContractId + ContractId = x.ContractId, + HasRollCall = x.HasRollCall }); diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs index 229dcf13..53d04704 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopEmployeeSettingsRepository.cs @@ -101,6 +101,12 @@ public class CustomizeWorkshopEmployeeSettingsRepository(CompanyContext companyC }; } + public CustomizeWorkshopEmployeeSettings GetByEmployeeIdAndWorkshopIdIncludeGroupSettings(long workshopId, long employeeId) + { + return _companyContext.CustomizeWorkshopEmployeeSettings.AsSplitQuery().Include(x => x.CustomizeWorkshopGroupSettings).FirstOrDefault(x => + x.WorkshopId == workshopId && x.EmployeeId == employeeId); + } + public CustomizeWorkshopEmployeeSettings GetByEmployeeIdGroupSettingsId(long workshopId, long employeeId) { return _companyContext.CustomizeWorkshopEmployeeSettings.AsSplitQuery().Include(x => x.CustomizeWorkshopGroupSettings).FirstOrDefault(x => diff --git a/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs b/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs index 1ce21c93..aa2b4d1c 100644 --- a/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/CustomizeWorkshopGroupSettingsRepository.cs @@ -70,6 +70,31 @@ public class CustomizeWorkshopGroupSettingsRepository(CompanyContext companyCont return employees; } + public List GetEmployeesWithoutGroupByWorkshopId(long workshopId) + { + var workshopSettings = _companyContext.CustomizeWorkshopSettings.Where(x => x.WorkshopId == workshopId); + + if (workshopSettings == null) + return new(); + + var existsEmployees = _companyContext.CustomizeWorkshopEmployeeSettings + .AsSplitQuery().Include(x => x.CustomizeWorkshopGroupSettings) + .Where(x => x.WorkshopId == workshopId && !x.CustomizeWorkshopGroupSettings.MainGroup) + .Select(x => x.EmployeeId).ToList(); + + var rollCallEmployees = _rollCallEmployeeRepository.GetActivePersonnelByWorkshopId(workshopId); + + var employees = rollCallEmployees + .Where(x => !existsEmployees.Contains(x.EmployeeId)) + .Select(x => new EmployeeViewModel() + { + EmployeeFullName = x.EmployeeFullName, + Id = x.EmployeeId + }).ToList(); + + return employees; + } + public CustomizeWorkshopGroupSettings GetWithEmployees(long groupId) { return _companyContext.CustomizeWorkshopGroupSettings.AsSplitQuery().Include(x => x.CustomizeWorkshopEmployeeSettingsCollection) diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Options.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/Options.cshtml.cs index 5f5c0d90..98bda2a4 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) + long customizeWorkshopSettingsId, WorkshopShiftStatus workshopShiftStatus, long workshopId,FridayWork fridayWork,HolidayWork holidayWork) { if (workshopId < 1) return new JsonResult(new @@ -239,7 +239,8 @@ 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); + var result = _customizeWorkshopSettingsApplication + .EditWorkshopSettingShifts(shiftViewModels, customizeWorkshopSettingsId, workshopShiftStatus, fridayWork, holidayWork); return new JsonResult(new { diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/CameraAccounts.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/CameraAccounts.cshtml.cs index 783387e1..ded56f7d 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/CameraAccounts.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/CameraAccounts.cshtml.cs @@ -54,7 +54,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall if (accountInfo.SubAccountId == 0) { var accountId = accountInfo.Id; - var result = _accountApplication.GetDetails(accountId); + var result = _accountApplication.Search(new AccountSearchModel() { Id = accountId }).FirstOrDefault(); if (result != null) { _accountApplication.SendVerifyCodeToChangingPass(result.Mobile, accountId); diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml b/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml index a2cb03b5..c5e3fe39 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml @@ -371,7 +371,7 @@