From 1c890685575e559129eb367924c28ed160a26672 Mon Sep 17 00:00:00 2001 From: SamSys Date: Wed, 12 Mar 2025 20:46:33 +0330 Subject: [PATCH 1/3] fix bug rollcallEmployee - upload picture --- .../RollCallEmployeeViewModel.cs | 3 +- .../Repository/LeftWorkRepository.cs | 35 ++++++++++++++----- .../Repository/ReportRepository.cs | 4 +-- .../Repository/RollCallEmployeeRepository.cs | 5 ++- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs b/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs index 58a9f016..5894322f 100644 --- a/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs +++ b/CompanyManagment.App.Contracts/RollCallEmployee/RollCallEmployeeViewModel.cs @@ -15,8 +15,7 @@ public class RollCallEmployeeViewModel : EditRollCallEmployee public string PersonName { get; set; } public bool ContractPerson { get; set; } public bool InsurancePerson { get; set; } - public long WorkshopId { get; set; } - public long EmployeeId { get; set; } + public bool ContractLeft { get; set; } public bool InsurancetLeft { get; set; } public bool Black { get; set; } diff --git a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs index 86d00b13..43c31933 100644 --- a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs @@ -162,15 +162,17 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos if (item != null) { + + _context.LeftWorkList.Remove(item); + _context.SaveChanges(); if (!_context.LeftWorkList.Any(x => x.WorkshopId == item.WorkshopId && x.EmployeeId == item.EmployeeId && item.id != x.id) && HasActiveRollCallStatus(item.WorkshopId, item.EmployeeId)) { - RemoveEmployeeRollCallStatus(item.WorkshopId,item.EmployeeId); + RemoveEmployeeRollCallStatus(item.WorkshopId, item.EmployeeId); } - _context.LeftWorkList.Remove(item); } - _context.SaveChanges(); + return op.Succcedded(); } @@ -238,8 +240,7 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos } - if (HasActiveRollCallStatus(workshopId, employeeId)) - RemoveEmployeeRollCallStatus(workshopId, employeeId); + var list = _context.LeftWorkList.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId).ToList(); @@ -255,7 +256,12 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos } _context.SaveChanges(); + + transaction.Commit(); + + if (HasActiveRollCallStatus(workshopId, employeeId)) + RemoveEmployeeRollCallStatus(workshopId, employeeId); if (hasLeftWorkInsurance) return op.Succcedded(1, "حذف با موفقیت انجام شد."); //+ "
" + "" + "کد پرسنلی این شخص به دلیل استفاده در ترک کار بیمه قابل حذف نمی باشد. " + ""); @@ -636,13 +642,26 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos } private void RemoveEmployeeRollCallStatus(long workshopId, long employeeId) { - var entity = _context.RollCallEmployees.FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId); + var entity = _context.RollCallEmployees.Include(x=>x.EmployeesStatus).FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId); if (entity == null) return; - _context.RollCallEmployees.Remove(entity); - _context.SaveChanges(); + var hasLeftWork = _context.LeftWorkList.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId); + //اگر هیچ شرع بکار ترک کاری نداشت + if (!hasLeftWork) + { + + entity.DeActive(); + var rollCallEmployeeStatus = + entity.EmployeesStatus.FirstOrDefault(x => x.EndDate.Date > DateTime.Now.Date); + if(rollCallEmployeeStatus != null) + rollCallEmployeeStatus.Deactivate(DateTime.Now.Date); + + _context.SaveChanges(); + } + //_context.RollCallEmployees.Remove(entity); + } #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/ReportRepository.cs b/CompanyManagment.EFCore/Repository/ReportRepository.cs index 2a3de1fe..ee61b69f 100644 --- a/CompanyManagment.EFCore/Repository/ReportRepository.cs +++ b/CompanyManagment.EFCore/Repository/ReportRepository.cs @@ -114,7 +114,7 @@ public class ReportRepository : IReportRepository // }; //} - public async Task GetAllActiveWorkshopsNew(string year, string month) + public Task GetAllActiveWorkshopsNew(string year, string month) { var watch = System.Diagnostics.Stopwatch.StartNew(); //یافتن آغاز و پایان ماه جاری @@ -442,7 +442,7 @@ public class ReportRepository : IReportRepository }; Console.WriteLine("new metod >>>>>: " + watch.Elapsed); - return finalResult; + return Task.FromResult(finalResult); } public AllReport GetAllActiveWorkshops(string year, string month) diff --git a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs index eb736e7d..c91cc4c8 100644 --- a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs @@ -48,12 +48,11 @@ public class RollCallEmployeeRepository : RepositoryBase public EditRollCallEmployee GetDetails(long id) { - return _context.RollCallEmployees.Select(x => new RollCallEmployeeViewModel() + return _context.RollCallEmployees.Select(x => new EditRollCallEmployee() { Id = x.id, WorkshopId = x.WorkshopId, - EmployeeFName = x.FName, - EmployeeLName = x.LName, + EmployeeId = x.EmployeeId, EmployeeFullName = x.EmployeeFullName, IsActiveString = x.IsActiveString, HasUploadedImage = x.HasUploadedImage From 6b543b4627a7648987f1214faa96b10291f3e1fc Mon Sep 17 00:00:00 2001 From: SamSys Date: Wed, 12 Mar 2025 23:13:05 +0330 Subject: [PATCH 2/3] mahan access to backup --- .../Repository/LeftWorkRepository.cs | 21 ++++++++++++++----- ServiceHost/Areas/Admin/Pages/Index.cshtml | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs index 43c31933..e6cb02a0 100644 --- a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs @@ -636,9 +636,10 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos private bool HasActiveRollCallStatus(long workshopId, long employeeId) { var now = DateTime.Today; + var isDateUndefined = new DateTime(2121, 03, 21); return _context.RollCallEmployees.Include(x => x.EmployeesStatus).Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && - x.EmployeesStatus.Any(y => y.EndDate.Date > now && y.StartDate <= now)); + x.EmployeesStatus.Any(y => (y.EndDate.Date > now && y.StartDate <= now) || (y.EndDate.Date == isDateUndefined))); } private void RemoveEmployeeRollCallStatus(long workshopId, long employeeId) { @@ -651,14 +652,24 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos //اگر هیچ شرع بکار ترک کاری نداشت if (!hasLeftWork) { - + var now = DateTime.Today; entity.DeActive(); var rollCallEmployeeStatus = - entity.EmployeesStatus.FirstOrDefault(x => x.EndDate.Date > DateTime.Now.Date); - if(rollCallEmployeeStatus != null) - rollCallEmployeeStatus.Deactivate(DateTime.Now.Date); + entity.EmployeesStatus.FirstOrDefault(x => x.EndDate.Date.IsDateUndefined() || x.EndDate.Date > now && x.StartDate <= now); + + + + if (rollCallEmployeeStatus != null) + { + var end = rollCallEmployeeStatus.StartDate.Date > DateTime.Now.Date + ? rollCallEmployeeStatus.StartDate.Date + : DateTime.Now.Date; + rollCallEmployeeStatus.Deactivate(end); + + } _context.SaveChanges(); + } //_context.RollCallEmployees.Remove(entity); diff --git a/ServiceHost/Areas/Admin/Pages/Index.cshtml b/ServiceHost/Areas/Admin/Pages/Index.cshtml index 860bc3e9..22c53614 100644 --- a/ServiceHost/Areas/Admin/Pages/Index.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Index.cshtml @@ -198,7 +198,7 @@
- + From a60e0bd211fbdb1780cb0e9135255a36c8c07f7a Mon Sep 17 00:00:00 2001 From: SamSys Date: Thu, 13 Mar 2025 00:04:47 +0330 Subject: [PATCH 3/3] mahan changed --- .../LeftWorkAgg/ILeftWorkRepository.cs | 5 ++++- .../RollCallEmployeeStatusApplication.cs | 19 +++++++++++++++++-- .../Repository/LeftWorkRepository.cs | 7 +++++++ .../Repository/RollCallEmployeeRepository.cs | 6 +++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs b/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs index 4a1f37eb..1c2aefbd 100644 --- a/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs +++ b/Company.Domain/LeftWorkAgg/ILeftWorkRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Domain; using CompanyManagment.App.Contracts.LeftWork; @@ -39,5 +40,7 @@ public interface ILeftWorkRepository : IRepository bool IsEmployeeWorkingInDates(long employeeId, long workshopId, List<(DateTime, DateTime)> dates); List GetByWorkshopIdInDates(long workshopId, DateTime startDateGr, DateTime endDateGr); LeftWorkViewModel GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end); - #endregion + #endregion + + Task GetLastLeftWork(long employeeId, long workshopId); } \ No newline at end of file diff --git a/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs b/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs index 236ded26..c77e8133 100644 --- a/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs +++ b/CompanyManagment.Application/RollCallEmployeeStatusApplication.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; using Company.Domain.RollCallServiceAgg; +using System.Globalization; namespace CompanyManagment.Application @@ -35,7 +36,7 @@ namespace CompanyManagment.Application return op.Failed("کارمند مجاز نیست"); if (!_leftWorkRepository.Exists(x => x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId && - x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date)) + (x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date) || x.StartWorkDate >= DateTime.Today)) return op.Failed("کارمند در کارگاه شروع به کار نکرده است"); if (_employeeRollCallStatusRepository.Exists(y => @@ -50,7 +51,21 @@ namespace CompanyManagment.Application } else { - RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, DateTime.Now.Date); + var pc = new PersianCalendar(); + var startStatus = DateTime.Today; + LeftWork leftWork = + _leftWorkRepository.GetLastLeftWork(rollCallEmployee.EmployeeId, rollCallEmployee.WorkshopId).GetAwaiter().GetResult(); + + if (leftWork.StartWorkDate > DateTime.Today) + startStatus = leftWork.StartWorkDate; + + //else if(pc.GetMonth(DateTime.Today) == pc.GetMonth(leftWork.StartWorkDate)) + //{ + // startStatus = new DateTime(pc.GetYear(leftWork.StartWorkDate), pc.GetMonth(leftWork.StartWorkDate), + // 1, pc); + //} + + RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, startStatus); _employeeRollCallStatusRepository.Create(newRecord); } diff --git a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs index e6cb02a0..3d0b9a41 100644 --- a/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs +++ b/CompanyManagment.EFCore/Repository/LeftWorkRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.LeftWorkAgg; @@ -675,4 +676,10 @@ public class LeftWorkRepository : RepositoryBase, ILeftWorkRepos } #endregion + public async Task GetLastLeftWork(long employeeId, long workshopId) + { + var leftWork = await _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId) + .OrderByDescending(x => x.StartWorkDate).FirstOrDefaultAsync(); + return leftWork; + } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs index c91cc4c8..32f97f66 100644 --- a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs @@ -95,15 +95,15 @@ public class RollCallEmployeeRepository : RepositoryBase var rawQuery = employeeQuery.Include(x => x.LeftWorks).Include(x => x.LeftWorkInsurances) .Where(x => x.LeftWorks.Any(y => - y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow && - y.LeftWorkDate > dateNow) || + (y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow && + y.LeftWorkDate > dateNow) || y.StartWorkDate > dateNow) || x.LeftWorkInsurances.Any(y => y.WorkshopId == command.WorkshopId && y.StartWorkDate <= dateNow && (y.LeftWorkDate > dateNow || y.LeftWorkDate == null))).OrderByDescending(x => x.id) .Select(x => new { Id = x.id, - FullName =x.FName +" "+x.LName, + FullName = x.FName + " " + x.LName, x.NationalCode, }).AsSplitQuery();