From 331f20619e39016e91a2ffead67f9b89b76e0463 Mon Sep 17 00:00:00 2001 From: SamSys Date: Thu, 12 Dec 2024 14:55:55 +0330 Subject: [PATCH] cameraDirectLogin from admin - fix bug at GetWorkshopAbsentHistory --- .../Account/IAccountApplication.cs | 4 +- .../AccountApplication.cs | 33 ++- Company.Domain/LeaveAgg/ILeaveRepository.cs | 3 +- .../RollCallAgg/IRollCallRepository.cs | 1 + .../Leave/ILeaveApplication.cs | 7 +- .../LeaveApplication.cs | 235 ++++++++++-------- .../RollCallApplication.cs | 15 +- .../Repository/LeaveRepository.cs | 20 +- .../Repository/RollCallRepository.cs | 19 +- .../Company/RollCall/CameraAccounts.cshtml | 1 + .../Company/RollCall/CameraAccounts.cshtml.cs | 15 ++ .../Company/RollCall/CaseHistory.cshtml.cs | 2 +- .../Company/CustomizeCheckout/Index.cshtml.cs | 2 +- .../Pages/Company/Employees/Index.cshtml.cs | 2 +- .../Company/RollCall/CaseHistory.cshtml.cs | 2 +- .../Areas/Client/Pages/Index.cshtml.cs | 2 +- .../RollCall/js/CameraAccounts.js | 22 ++ .../RollCall/js/ModalAddRollCall.js | 2 +- 18 files changed, 259 insertions(+), 128 deletions(-) diff --git a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs index 19ac782c..52161779 100644 --- a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs +++ b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs @@ -52,5 +52,7 @@ public interface IAccountApplication OperationResult IsPhoneNumberAndPasswordValid(long accountId, string phoneNumber, string password, string rePassword); - #endregion + #endregion + + OperationResult DirectCameraLogin(long cameraAccountId); } \ No newline at end of file diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index 36f85862..18b90a14 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -477,7 +477,7 @@ public class AccountApplication : IAccountApplication var operation = new OperationResult(); var account = _accountRepository.GetById(id); if (account == null) - return operation.Failed("این اکان وجود ندارد"); + return operation.Failed("این اکانت وجود ندارد"); @@ -510,8 +510,37 @@ public class AccountApplication : IAccountApplication _authHelper.Signin(authViewModel); return operation.Succcedded(2); } + public OperationResult DirectCameraLogin(long cameraAccountId) + { + var prAcc = _authHelper.CurrentAccountInfo(); + var operation = new OperationResult(); + var cameraAccount = _cameraAccountRepository.GetById(cameraAccountId); + if (cameraAccount == null) + return operation.Failed("این اکانت وجود ندارد"); - public AccountLeftWorkViewModel WorkshopList(long accountId) + + + + + _authHelper.SignOut(); + + + var mobile = string.IsNullOrWhiteSpace(cameraAccount.Mobile) ? " " : cameraAccount.Mobile; + var authViewModel = new CameraAuthViewModel(cameraAccount.id, cameraAccount.WorkshopId, + cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId, cameraAccount.IsActiveSting); + if (cameraAccount.IsActiveSting == "true") + { + _authHelper.CameraSignIn(authViewModel); + + } + else + { + return operation.Failed("این اکانت غیر فعال شده است"); + } + return operation.Succcedded(2); + } + + public AccountLeftWorkViewModel WorkshopList(long accountId) { string fullname = this._accountRepository.GetById(accountId).Fullname; List source =_accountLeftworkRepository.WorkshopList(accountId); diff --git a/Company.Domain/LeaveAgg/ILeaveRepository.cs b/Company.Domain/LeaveAgg/ILeaveRepository.cs index da1d27ef..7b4ee239 100644 --- a/Company.Domain/LeaveAgg/ILeaveRepository.cs +++ b/Company.Domain/LeaveAgg/ILeaveRepository.cs @@ -13,10 +13,11 @@ public interface ILeaveRepository : IRepository OperationResult RemoveLeave(long id); #region Pooya + List GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end); /// /// چک می کند که آیا پرسنل مرخصی روزانه استحقاقی دارد یا خیر /// - bool HasLeave(long employeeId, long workshopId, DateTime date); + bool HasDailyLeave(long employeeId, long workshopId, DateTime date); #endregion bool CheckContractExist(DateTime myDate,long employeeId, long workshopId); diff --git a/Company.Domain/RollCallAgg/IRollCallRepository.cs b/Company.Domain/RollCallAgg/IRollCallRepository.cs index c6996c4e..59874d3c 100644 --- a/Company.Domain/RollCallAgg/IRollCallRepository.cs +++ b/Company.Domain/RollCallAgg/IRollCallRepository.cs @@ -22,6 +22,7 @@ namespace Company.Domain.RollCallAgg #region Pooya List GetWorkshopAbsentHistory(long workshopId, DateTime startSearch, DateTime endSearch); + List GetEmployeeRollCallsHistoryAllByDate(long workshopId, long employeeId, DateTime start, DateTime end); void RemoveEmployeeRollCallsInDate(long workshopId, long employeeId, DateTime date); RollCallsByDateViewModel GetWorkshopRollCallHistory(RollCallSearchModel searchModel); CurrentDayRollCall GetWorkshopCurrentDayRollCalls(long workshopId); diff --git a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs index 84779071..3e37bfdb 100644 --- a/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs +++ b/CompanyManagment.App.Contracts/Leave/ILeaveApplication.cs @@ -26,5 +26,10 @@ public interface ILeaveApplication #endregion bool CheckIfValidToEdit(long id); - OperationResult HasLeave(long workshopId, long employeeId, string dateFa); + OperationResult HasDailyLeave(long workshopId, long employeeId, string dateFa); + + #region Pooya + OperationResult ValidateNewLeaveWithExistingRollCalls(long workshopId, long employeeId, string paidLeaveType, DateTime start, DateTime end); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/LeaveApplication.cs b/CompanyManagment.Application/LeaveApplication.cs index c408f61a..6263f2f3 100644 --- a/CompanyManagment.Application/LeaveApplication.cs +++ b/CompanyManagment.Application/LeaveApplication.cs @@ -72,12 +72,12 @@ public class LeaveApplication : ILeaveApplication var start = command.StartLeave.ToGeorgianDateTime(); - var end = command.PaidLeaveType == "ساعتی"? start : command.EndLeave.ToGeorgianDateTime(); + var end = command.PaidLeaveType == "ساعتی" ? start : command.EndLeave.ToGeorgianDateTime(); var checkErr = _leaveRepository.CheckErrors(start, end, command.EmployeeId, command.WorkshopId); - - // start = new DateTime(start.Year, start.Month, start.Day, startH.Hours, startH.Minutes, startH.Seconds); - //end = new DateTime(end.Year, end.Month, end.Day, endH.Hours, endH.Minutes, endH.Seconds); + + // start = new DateTime(start.Year, start.Month, start.Day, startH.Hours, startH.Minutes, startH.Seconds); + //end = new DateTime(end.Year, end.Month, end.Day, endH.Hours, endH.Minutes, endH.Seconds); if (checkErr.HasChekout) @@ -89,8 +89,8 @@ public class LeaveApplication : ILeaveApplication if (start > end) return op.Failed("تارخ شروع از پایان بزرگتر است"); - - + + var totalhourses = "-"; if (command.LeaveType == "استحقاقی" && command.PaidLeaveType == "ساعتی") { @@ -100,7 +100,7 @@ public class LeaveApplication : ILeaveApplication if (start > end) end = end.AddDays(1); - var totalLeavHourses = (end - start); + var totalLeavHourses = (end - start); var h = totalLeavHourses.Hours < 10 ? $"0{totalLeavHourses.Hours}" : $"{totalLeavHourses.Hours}"; var m = totalLeavHourses.Minutes < 10 ? $"0{totalLeavHourses.Minutes}" : $"{totalLeavHourses.Minutes}"; totalhourses = $"{h}:{m}"; @@ -112,14 +112,14 @@ public class LeaveApplication : ILeaveApplication x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی")) return op.Failed("برای ساعت پایان سابقه مرخصی وجود دارد"); if (_leaveRepository.Exists(x => - x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی")) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); - + x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی")) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + var end24 = endH.Hours == 0 && endH.Minutes == 0 ? end.AddDays(-1) : end; if (_leaveRepository.Exists(x => - (x.StartLeave.Date == start.Date || x.EndLeave.Date == end24.Date) && (x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); - } + (x.StartLeave.Date == start.Date || x.EndLeave.Date == end24.Date) && (x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه"))) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + } else if (command.LeaveType == "استحقاقی" && command.PaidLeaveType == "روزانه") { var totalLeavHourses = (end - start).TotalDays + 1; @@ -131,9 +131,9 @@ public class LeaveApplication : ILeaveApplication x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد"); if (_leaveRepository.Exists(x => - x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); - if (_leaveRepository.Exists(x => + x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + if (_leaveRepository.Exists(x => x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی")) return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است"); } @@ -143,29 +143,31 @@ public class LeaveApplication : ILeaveApplication var totalLeavHourses = (end - start).TotalDays + 1; totalhourses = $"{(int)totalLeavHourses}"; command.PaidLeaveType = "روزانه"; - if (_leaveRepository.Exists(x => - x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) - return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد"); - if (_leaveRepository.Exists(x => - x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) - return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد"); - if (_leaveRepository.Exists(x => - x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); - if (_leaveRepository.Exists(x => - x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی")) - return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است"); - } - - var year = Convert.ToInt32(command.StartLeave.Substring(0, 4)); + if (_leaveRepository.Exists(x => + x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) + return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد"); + if (_leaveRepository.Exists(x => + x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) + return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد"); + if (_leaveRepository.Exists(x => + x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه")) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + if (_leaveRepository.Exists(x => + x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی")) + return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است"); + } + + var year = Convert.ToInt32(command.StartLeave.Substring(0, 4)); var month = Convert.ToInt32(command.StartLeave.Substring(5, 2)); - // var checkIfHasRollCall =ValidateNewLeaveWithExistingRollCalls(command.WorkshopId, command.EmployeeId, start, end); - //if (!checkIfHasRollCall.IsSuccedded) - // return checkIfHasRollCall; - var employeeFullName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName; + + var validation = ValidateNewLeaveWithExistingRollCalls(command.WorkshopId, command.EmployeeId, command.PaidLeaveType, start, end); + if (validation.IsSuccedded == false) + return validation; + + var employeeFullName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName; var workshopName = _workshopRepository.GetDetails(command.WorkshopId).WorkshopName; - var leave = new Leave(start,end,totalhourses,command.WorkshopId,command.EmployeeId - ,command.PaidLeaveType,command.LeaveType,employeeFullName,workshopName, command.IsAccepted, command.Decription, year, month); + var leave = new Leave(start, end, totalhourses, command.WorkshopId, command.EmployeeId + , command.PaidLeaveType, command.LeaveType, employeeFullName, workshopName, command.IsAccepted, command.Decription, year, month); _leaveRepository.Create(leave); _leaveRepository.SaveChanges(); @@ -182,37 +184,37 @@ public class LeaveApplication : ILeaveApplication if (leave == null) op.Failed("رکورد مورد نظر وجود ندارد"); - if (command.PaidLeaveType == "روزانه") + if (command.PaidLeaveType == "روزانه") + { + if (string.IsNullOrWhiteSpace(command.EndLeave)) { - if (string.IsNullOrWhiteSpace(command.EndLeave)) - { - return op.Failed("لطفا تاریخ پایان را وارد کنید"); - } - - if (string.IsNullOrWhiteSpace(command.StartLeave)) - { - return op.Failed("لطفا تاریخ شروع را وارد کنید"); - } + return op.Failed("لطفا تاریخ پایان را وارد کنید"); } - else if (command.PaidLeaveType == "ساعتی") + + if (string.IsNullOrWhiteSpace(command.StartLeave)) { - if (string.IsNullOrWhiteSpace(command.StartLeave)) - return op.Failed("لطفا تاریخ شروع را وارد کنید"); - if (string.IsNullOrWhiteSpace(command.StartHoures) || string.IsNullOrWhiteSpace(command.EndHours)) - return op.Failed("ساعت شروع و پایان نمیتواند خالی باشد"); - - string pattern = @"^([01]\d|2[0-3]):[0-5]\d$"; - if (!Regex.IsMatch(command.StartHoures, pattern)) - return op.Failed("لطفا ساعت شروع را به درستی وارد کنید"); - - if (!Regex.IsMatch(command.EndHours, pattern)) - return op.Failed("لطفا ساعت پایان را به درستی وارد کنید"); - - startH = TimeSpan.Parse(command.StartHoures); - endH = TimeSpan.Parse(command.EndHours); - if (startH == endH) - return op.Failed("ساعت شروع و پایان نباید برابر باشد"); + return op.Failed("لطفا تاریخ شروع را وارد کنید"); } + } + else if (command.PaidLeaveType == "ساعتی") + { + if (string.IsNullOrWhiteSpace(command.StartLeave)) + return op.Failed("لطفا تاریخ شروع را وارد کنید"); + if (string.IsNullOrWhiteSpace(command.StartHoures) || string.IsNullOrWhiteSpace(command.EndHours)) + return op.Failed("ساعت شروع و پایان نمیتواند خالی باشد"); + string pattern = @"^([01]\d|2[0-3]):[0-5]\d$"; + + if (!Regex.IsMatch(command.StartHoures, pattern)) + return op.Failed("لطفا ساعت شروع را به درستی وارد کنید"); + + if (!Regex.IsMatch(command.EndHours, pattern)) + return op.Failed("لطفا ساعت پایان را به درستی وارد کنید"); + + startH = TimeSpan.Parse(command.StartHoures); + endH = TimeSpan.Parse(command.EndHours); + if (startH == endH) + return op.Failed("ساعت شروع و پایان نباید برابر باشد"); + } if (command.LeaveType == "استعلاجی" && string.IsNullOrWhiteSpace(command.StartLeave)) return op.Failed("لطفا تاریخ شروع را وارد کنید"); @@ -227,14 +229,14 @@ public class LeaveApplication : ILeaveApplication var end = command.PaidLeaveType == "ساعتی" ? start : command.EndLeave.ToGeorgianDateTime(); var checkErr = _leaveRepository.CheckErrors(start, end, command.EmployeeId, command.WorkshopId); - + if (checkErr.HasChekout) return op.Failed(checkErr.CheckoutErrMessage); if (checkErr.HasLeftWork) return op.Failed(checkErr.LeftWorlErrMessage); if (start > end) return op.Failed("تارخ شروع از پایان بزرگتر است"); - + //var totalHoursbetween = new TimeSpan(); //totalHoursbetween = (end - start); @@ -248,67 +250,71 @@ public class LeaveApplication : ILeaveApplication if (start > end) end = end.AddDays(1); - var totalLeavHourses = (end - start); + var totalLeavHourses = (end - start); var h = totalLeavHourses.Hours < 10 ? $"0{totalLeavHourses.Hours}" : $"{totalLeavHourses.Hours}"; var m = totalLeavHourses.Minutes < 10 ? $"0{totalLeavHourses.Minutes}" : $"{totalLeavHourses.Minutes}"; totalhourses = $"{h}:{m}"; if (_leaveRepository.Exists(x => - x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) - return op.Failed("برای ساعت شروع سابقه مرخصی وجود دارد"); + x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) + return op.Failed("برای ساعت شروع سابقه مرخصی وجود دارد"); if (_leaveRepository.Exists(x => - x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) - return op.Failed("برای ساعت پایان سابقه مرخصی وجود دارد"); + x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) + return op.Failed("برای ساعت پایان سابقه مرخصی وجود دارد"); if (_leaveRepository.Exists(x => - x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); - + x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + var end24 = endH.Hours == 0 && endH.Minutes == 0 ? end.AddDays(-1) : end; if (_leaveRepository.Exists(x => - (x.StartLeave.Date == start.Date || x.EndLeave.Date == end24.Date) && (x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id))) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); - } + (x.StartLeave.Date == start.Date || x.EndLeave.Date == end24.Date) && (x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id))) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + } else if (command.LeaveType == "استحقاقی" && command.PaidLeaveType == "روزانه") { var totalLeavHourses = (end - start).TotalDays + 1; totalhourses = $"{(int)totalLeavHourses}"; if (_leaveRepository.Exists(x => - x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) - return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد"); + x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) + return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد"); if (_leaveRepository.Exists(x => - x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) - return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد"); + x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) + return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد"); if (_leaveRepository.Exists(x => - x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); if (_leaveRepository.Exists(x => - x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) - return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است"); - } + x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) + return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است"); + } if (command.LeaveType == "استعلاجی") { var totalLeavHourses = (end - start).TotalDays + 1; totalhourses = $"{(int)totalLeavHourses}"; command.PaidLeaveType = "روزانه"; - if (_leaveRepository.Exists(x => - x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) - return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد"); - if (_leaveRepository.Exists(x => - x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) - return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد"); - if (_leaveRepository.Exists(x => - x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) - return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); - if (_leaveRepository.Exists(x => - x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) - return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است"); - } + if (_leaveRepository.Exists(x => + x.StartLeave <= start && x.EndLeave >= start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) + return op.Failed("برای تاریخ شروع سابقه مرخصی وجود دارد"); + if (_leaveRepository.Exists(x => + x.StartLeave <= end && x.EndLeave >= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) + return op.Failed("برای تاریخ پایان سابقه مرخصی وجود دارد"); + if (_leaveRepository.Exists(x => + x.StartLeave >= start && x.EndLeave <= end && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "روزانه" && x.id != command.Id)) + return op.Failed("در بازه زمانی وارد شده مرخصی ثبت شده است"); + if (_leaveRepository.Exists(x => + x.StartLeave.Date >= start.Date && x.StartLeave.Date <= end.Date && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId && x.PaidLeaveType == "ساعتی" && x.id != command.Id)) + return op.Failed("دربازه تاریخ وارد شده مرخصی ساعتی ثبت شده است"); + } - var year = Convert.ToInt32(command.StartLeave.Substring(0, 4)); + var year = Convert.ToInt32(command.StartLeave.Substring(0, 4)); var month = Convert.ToInt32(command.StartLeave.Substring(5, 2)); + var validation = ValidateNewLeaveWithExistingRollCalls(command.WorkshopId, command.EmployeeId, command.PaidLeaveType, start, end); + if (validation.IsSuccedded == false) + return validation; + var employeeFullName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName; var workshopName = _workshopRepository.GetDetails(command.WorkshopId).WorkshopName; leave.Edit(start, end, totalhourses, command.WorkshopId, command.EmployeeId @@ -350,13 +356,13 @@ public class LeaveApplication : ILeaveApplication return _leaveRepository.CheckIfValidToEdit(id); } - public OperationResult HasLeave(long workshopId, long employeeId, string dateFa) + public OperationResult HasDailyLeave(long workshopId, long employeeId, string dateFa) { OperationResult op = new(); DateTime date = dateFa.ToGeorgianDateTime(); if (date == Tools.GetUndefinedDateTime()) return op.Failed("تاریخ وارد شده صحیح نمی باشد"); - var result = _leaveRepository.HasLeave(employeeId, workshopId, date); + var result = _leaveRepository.HasDailyLeave(employeeId, workshopId, date); return op.Succcedded(result); } @@ -386,15 +392,26 @@ public class LeaveApplication : ILeaveApplication { return _leaveRepository.LastLeaveMain(searchModel); } - #region Pooya - public OperationResult ValidateNewLeaveWithExistingRollCalls(long workshopId, long employeeId, DateTime start, DateTime end) + public OperationResult ValidateNewLeaveWithExistingRollCalls(long workshopId, long employeeId, string paidLeaveType, DateTime start, DateTime end) { - OperationResult op = new(); - var rollCallsInDate = _rollCallRepository.GetEmployeeRollCallsHistoryAll(workshopId, employeeId, start, end); - if (rollCallsInDate.Any()) - return op.Failed("در این بازه زمانی رکورد حضور غیاب برای این شخص وجود دارد"); - return op.Succcedded(); + OperationResult op = new(); + var rollCallsInDate = _rollCallRepository.GetEmployeeRollCallsHistoryAllByDate(workshopId, employeeId, start, end); + if (paidLeaveType == "ساعتی") + { + if (rollCallsInDate.Any(x => x.EndDate >= start && x.StartDate <= end)) + return op.Failed("در این بازه زمانی رکورد حضور غیاب برای این شخص وجود دارد"); + } + else + { + var rollCallsInDateGrouped = rollCallsInDate.GroupBy(x => x.StartDate.Value.Date); + if (rollCallsInDateGrouped.Any(x => x.Key.Date >= start && x.Key.Date <= end)) + return op.Failed("در این روز رکورد حضور غیاب برای این شخص وجود دارد"); + + } + return op.Succcedded(); } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/RollCallApplication.cs b/CompanyManagment.Application/RollCallApplication.cs index 9fa13d8d..2f9ef4d3 100644 --- a/CompanyManagment.Application/RollCallApplication.cs +++ b/CompanyManagment.Application/RollCallApplication.cs @@ -154,7 +154,7 @@ public class RollCallApplication : IRollCallApplication 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()) @@ -173,7 +173,7 @@ public class RollCallApplication : IRollCallApplication if (command.RollCallRecords == null || command.RollCallRecords.Count == 0) return operation.Failed("خطای سیستمی"); - if (_leaveRepository.HasLeave(command.EmployeeId, command.WorkshopId, date)) + if (_leaveRepository.HasDailyLeave(command.EmployeeId, command.WorkshopId, date)) return operation.Failed("در روز مرخصی کارمند نمی توانید حضور غیاب ثبت کنید"); var employeeStatuses = _rollCallEmployeeRepository.GetByEmployeeIdWithStatuses(command.EmployeeId) @@ -259,8 +259,17 @@ public class RollCallApplication : IRollCallApplication return operation.Failed("شروع رکورد حضور غیاب نمی تواند در روز های بعد از تاریخ تعیین شده باشد"); #endregion + foreach (var activity in result) + { - if (result == null || !result.All(x => employeeStatuses.Any(y => x.Start >= y.StartDateGr || x.End <= y.EndDateGr))) + //مرخصی روزانه در بالا چک شده است + 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("کارمند در بازه وارد شده غیر فعال است"); diff --git a/CompanyManagment.EFCore/Repository/LeaveRepository.cs b/CompanyManagment.EFCore/Repository/LeaveRepository.cs index 454fdc0b..ff7ade15 100644 --- a/CompanyManagment.EFCore/Repository/LeaveRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeaveRepository.cs @@ -320,7 +320,7 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository #endregion - + public bool CheckIfValidToEdit(long id) { var leave = _context.LeaveList.FirstOrDefault(x => x.id == id); @@ -363,12 +363,28 @@ public class LeaveRepository : RepositoryBase, ILeaveRepository return op.Failed("موردی یافت نشد"); } - public bool HasLeave(long employeeId, long workshopId, DateTime date) + #region Pooya + public bool HasDailyLeave(long employeeId, long workshopId, DateTime date) { return _context.LeaveList.Where(x => (x.LeaveType == "استحقاقی" && x.PaidLeaveType == "روزانه") || x.LeaveType == "استعلاجی") .FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.StartLeave.Date <= date.Date && x.EndLeave.Date >= date.Date) != null; } + public List GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end) + { + return _context.LeaveList.Where(x => x.EmployeeId == employeeId && x.EndLeave >= start && x.StartLeave <= end) + .Select(x => new LeaveViewModel + { + EmployeeId = employeeId, + WorkshopId = workshopId, + PaidLeaveType = x.PaidLeaveType, + LeaveType = x.LeaveType, + StartLeaveGr = x.StartLeave, + EndLeaveGr = x.EndLeave + }).ToList(); + + } + #endregion public bool CheckContractExist(DateTime myDate, long employeeId, long workshopId) { diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index b986283f..3e2e83b3 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -377,8 +377,9 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //roll calls for current workshop where shift start is in dateIndex date (filters today's shifts) var rollCallsQuery = _context.RollCalls .Where(x => x.WorkshopId == workshopId && x.StartDate.HasValue && - x.StartDate.Value.Date >= startSearch.Date && x.StartDate.Value.Date <= endSearch.Date && x.RollCallModifyType != RollCallModifyType.Undefined && - x.RollCallModifyType != RollCallModifyType.CutByBgService); + x.StartDate.Value.Date >= startSearch.Date && x.StartDate.Value.Date <= endSearch.Date && + x.RollCallModifyType != RollCallModifyType.Undefined); + //get active employees of workshop in dateIndex date @@ -409,7 +410,6 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos EmployeeFullName = x.EmployeeFullName, Id = x.id, WorkshopId = x.WorkshopId - }), IsHoliday = _holidayItemApplication.IsHoliday(day), IsFriday = day.DayOfWeek == DayOfWeek.Friday @@ -419,6 +419,19 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos return result; } + public List GetEmployeeRollCallsHistoryAllByDate(long workshopId, long employeeId, DateTime start, DateTime end) + { + return _context.RollCalls.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId && + x.EndDate.Value.Date >= start.Date && x.StartDate.Value.Date <= end.Date) + .Select(x => new RollCallViewModel + { + EmployeeId = employeeId, + WorkshopId = workshopId, + StartDate = x.StartDate, + EndDate = x.EndDate + }).ToList(); + } + //سوابق حضور غیاب کارگاه public RollCallsByDateViewModel GetWorkshopRollCallHistory(RollCallSearchModel searchModel) { diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml index a852c954..3f8c29bd 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml +++ b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml @@ -198,6 +198,7 @@ var antiForgeryToken = $('@Html.AntiForgeryToken()').val(); var loadCameraAccountsAjax = `@Url.Page("CameraAccounts", "CameraAccounts")`; var changeCameraAccountStatusAjax = `@Url.Page("./CameraAccounts", "CameraAccountChangeStatus")`; + var directLoginUrl = `@Url.Page("./CameraAccounts", "DirectCameraAccountLogin")`; var wpId = Number(@Model.WorkshopId); diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml.cs index 04764f1a..d1beab22 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CameraAccounts.cshtml.cs @@ -216,6 +216,21 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.RollCall message = result.Message }); } + + + public IActionResult OnGetDirectCameraAccountLogin(long id) + { + var res = _accountApplication.DirectCameraLogin(id); + if (res.IsSuccedded) + return Redirect("/Camera"); + + return new JsonResult(new + { + success = res.IsSuccedded, + message = res.Message + }); + + } #endregion } } diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CaseHistory.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CaseHistory.cshtml.cs index d17f919f..cf26d684 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CaseHistory.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/RollCall/CaseHistory.cshtml.cs @@ -132,7 +132,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.RollCall isSuccess = resultData.Any(); } - var result = _leaveApplication.HasLeave(workshopId, employeeId, date); + var result = _leaveApplication.HasDailyLeave(workshopId, employeeId, date); var isLeave = result.IsSuccedded ? result.Data : false; var isNullEndDate = resultData.Any(x => x.EndDate == null); diff --git a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/Index.cshtml.cs index c5437c18..49e218c7 100644 --- a/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/CustomizeCheckout/Index.cshtml.cs @@ -40,7 +40,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.CustomizeCheckout public IActionResult OnGet() { - HasCustomizeCheckoutService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(_workshopId).HasCustomizeCheckoutService; + HasCustomizeCheckoutService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(_workshopId)?.HasCustomizeCheckoutService; var workshopInfo = _workshopApplication.GetWorkshopInfo(_workshopId); WorkshopFullName = workshopInfo.WorkshopFullName; diff --git a/ServiceHost/Areas/Client/Pages/Company/Employees/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/Employees/Index.cshtml.cs index 90e10105..f8ea53a7 100644 --- a/ServiceHost/Areas/Client/Pages/Company/Employees/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/Employees/Index.cshtml.cs @@ -104,7 +104,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.Employees HasEmployees = Employees.PersonnelInfoViewModels.Count > 0 ? true : false; - HasCustomizeCheckoutService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(id).HasCustomizeCheckoutService; + HasCustomizeCheckoutService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(id)?.HasCustomizeCheckoutService; return Page(); } diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs index 25b5c495..954cb127 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/CaseHistory.cshtml.cs @@ -197,7 +197,7 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall isSuccess = resultData.Any(); } - var result = _leaveApplication.HasLeave(workshopId, employeeId, date); + var result = _leaveApplication.HasDailyLeave(workshopId, employeeId, date); var isLeave = result.IsSuccedded ? result.Data : false; var isNullEndDate = resultData.Any(x => x.EndDate == null); diff --git a/ServiceHost/Areas/Client/Pages/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Index.cshtml.cs index 81e1c107..080b59de 100644 --- a/ServiceHost/Areas/Client/Pages/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Index.cshtml.cs @@ -79,7 +79,7 @@ namespace ServiceHost.Areas.Client.Pages #endregion - HasCustomizeCheckoutService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(workshopIDecrypt).HasCustomizeCheckoutService; + HasCustomizeCheckoutService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(workshopIDecrypt)?.HasCustomizeCheckoutService; #region TodayDate diff --git a/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/CameraAccounts.js b/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/CameraAccounts.js index bafaf5e3..2063c82b 100644 --- a/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/CameraAccounts.js +++ b/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/CameraAccounts.js @@ -88,6 +88,28 @@ function loadDataCameraAccountAjax() { +
+ +
+ diff --git a/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/ModalAddRollCall.js b/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/ModalAddRollCall.js index c0fc72e6..e53c97a2 100644 --- a/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/ModalAddRollCall.js +++ b/ServiceHost/wwwroot/AssetsAdminNew/RollCall/js/ModalAddRollCall.js @@ -400,7 +400,7 @@ function fetchAndDisplayRollCallData(employeeId, dateFa) { if (response.hasLeave) { htmlElement = ` -
این پرسنل مرخصی ثبت شده است.
+
برای این پرسنل مرخصی ثبت شده است
`; $('#appendChildTimeWorkHtml').html(htmlElement); $('.btn-register').addClass('disable');