From 8134216a4a42c4953a6bebca4212492a75e3606b Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 27 Oct 2025 16:46:09 +0330 Subject: [PATCH 01/11] feat: update roll call links to use dynamic domain --- ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml | 2 +- ServiceHost/Areas/AdminNew/Pages/Shared/_Menu.cshtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml b/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml index e53dbc46..06228481 100644 --- a/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Shared/_Menu.cshtml @@ -176,7 +176,7 @@ @* قراردادهای موسسه *@ @* *@
  • - + diff --git a/ServiceHost/Areas/AdminNew/Pages/Shared/_Menu.cshtml b/ServiceHost/Areas/AdminNew/Pages/Shared/_Menu.cshtml index 5777d935..6e57e512 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Shared/_Menu.cshtml +++ b/ServiceHost/Areas/AdminNew/Pages/Shared/_Menu.cshtml @@ -238,7 +238,7 @@ @* *@ @*
  • *@
  • - + From c7bace728ed5dc6a86c921e57125e566047e7895 Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 28 Oct 2025 12:31:08 +0330 Subject: [PATCH 02/11] feat: integrate workshop repository for roll call workflows --- .../WorkFlowApplication.cs | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs b/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs index 9bed52c5..ed188fea 100644 --- a/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs +++ b/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs @@ -1,6 +1,7 @@ using _0_Framework.Application; using _0_Framework.Domain.CustomizeCheckoutShared.Enums; using Company.Domain.RollCallAgg.DomainService; +using Company.Domain.WorkshopAgg; using CompanyManagment.App.Contracts.EmployeeDocuments; using WorkFlow.Application.Contracts.RollCallConfirmedAbsence; using WorkFlow.Application.Contracts.RollCallConfirmedWithoutLunchBreak; @@ -23,7 +24,9 @@ public class WorkFlowApplication : IWorkFlowApplication private readonly IRollCallDomainService _rollCallDomainService; private readonly IRollCallConfirmedWithoutLunchBreakRepository _rollCallConfirmedWithoutLunchBreakRepository; private readonly IEmployeeDocumentsApplication _employeeDocumentsApplication; - public WorkFlowApplication(IRollCallConfirmedAbsenceRepository absenceRepository, IWorkFlowRollCallACL rollCallACL, IWorkFlowCheckoutACL checkoutACL, IWorkFlowCustomizedWorkshopSettingsACL customizedWorkshopSettingsACL, IRollCallConfirmedWithoutLunchBreakRepository rollCallConfirmedWithoutLunchBreakRepository, IRollCallDomainService rollCallDomainService, IEmployeeDocumentsApplication employeeDocumentsApplication) + private readonly IWorkshopRepository _workshopRepository; + + public WorkFlowApplication(IRollCallConfirmedAbsenceRepository absenceRepository, IWorkFlowRollCallACL rollCallACL, IWorkFlowCheckoutACL checkoutACL, IWorkFlowCustomizedWorkshopSettingsACL customizedWorkshopSettingsACL, IRollCallConfirmedWithoutLunchBreakRepository rollCallConfirmedWithoutLunchBreakRepository, IRollCallDomainService rollCallDomainService, IEmployeeDocumentsApplication employeeDocumentsApplication, IWorkshopRepository workshopRepository) { _absenceRepository = absenceRepository; _rollCallACL = rollCallACL; @@ -32,6 +35,7 @@ public class WorkFlowApplication : IWorkFlowApplication _rollCallConfirmedWithoutLunchBreakRepository = rollCallConfirmedWithoutLunchBreakRepository; _rollCallDomainService = rollCallDomainService; _employeeDocumentsApplication = employeeDocumentsApplication; + _workshopRepository = workshopRepository; } public async Task CreateRollCallConfirmedAbsence(CreateRollCallConfirmedAbsence command) @@ -416,6 +420,10 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetUndefinedRollCalls(long workshopId) { + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return []; var now = DateTime.Now; DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo); @@ -443,6 +451,10 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetRollCallWorkFlowsCutByBgService(long workshopId) { + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return []; var now = DateTime.Now; DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo); @@ -468,6 +480,11 @@ public class WorkFlowApplication : IWorkFlowApplication public async Task CountCutByBgServiceLastMonth(long workshopId) { + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return 0; + DateTime lastMonthEnd = ($"{DateTime.Now.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime().AddDays(-1); var now = lastMonthEnd; var twoMonthsAgo = ($"{lastMonthEnd.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime(); @@ -496,7 +513,11 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task CountAbsentRollCallLastMonth(long workshopId) { - + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return 0; + DateTime lastMonthEnd = ($"{DateTime.Now.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime().AddDays(-1); var now = lastMonthEnd; var twoMonthsAgo = ($"{lastMonthEnd.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime(); @@ -558,6 +579,11 @@ public class WorkFlowApplication : IWorkFlowApplication public async Task CountEmployeesWithoutLunchBreakLastMonth(long workshopId) { + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return 0; + DateTime lastMonthEnd = ($"{DateTime.Now.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime().AddDays(-1); var now = lastMonthEnd; var twoMonthsAgo = ($"{lastMonthEnd.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime(); @@ -596,6 +622,11 @@ public class WorkFlowApplication : IWorkFlowApplication public async Task CountUndefinedLastMonth(long workshopId) { + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return 0; + DateTime lastMonthEnd = ($"{DateTime.Now.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime().AddDays(-1); var now = lastMonthEnd; var twoMonthsAgo = ($"{lastMonthEnd.ToFarsi().Substring(0, 8)}01").ToGeorgianDateTime(); @@ -625,7 +656,10 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetAbsentRollCallWorkFlows(long workshopId) { - + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return []; var now = DateTime.Now; DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo); @@ -689,6 +723,10 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetEmployeesWithoutLunchBreak(long workshopId) { + var workshop = _workshopRepository.Get(workshopId); + + if (workshop == null || workshop.IsStaticCheckout) + return []; var now = DateTime.Now.Date; now.AddMonthsFa(-2, out var twoMonthsAgo); From 632ab3631badf241b4e8219a89e3f8cb3fa8aa99 Mon Sep 17 00:00:00 2001 From: SamSys Date: Tue, 28 Oct 2025 13:16:56 +0330 Subject: [PATCH 03/11] added UseWebSockets --- ServiceHost/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ServiceHost/Program.cs b/ServiceHost/Program.cs index bf46f1d7..7e3431e0 100644 --- a/ServiceHost/Program.cs +++ b/ServiceHost/Program.cs @@ -356,6 +356,7 @@ else app.UseExceptionHandler(options => { }); // این خط CustomExceptionHandler رو فعال می‌کنه app.UseRouting(); +app.UseWebSockets(); app.UseAuthentication(); app.UseAuthorization(); From ca1ef420afa76b2aea840f6c17b1d38ae1984491 Mon Sep 17 00:00:00 2001 From: mahan Date: Tue, 28 Oct 2025 17:31:43 +0330 Subject: [PATCH 04/11] feat: add exception for Amir's pizza workshop to adjust roll call date handling --- .../WorkFlowApplication.cs | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs b/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs index ed188fea..d644bb5f 100644 --- a/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs +++ b/WorkFlow/Application/WorkFlow.Application/WorkFlowApplication.cs @@ -420,14 +420,17 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetUndefinedRollCalls(long workshopId) { - var workshop = _workshopRepository.Get(workshopId); - - if (workshop == null || workshop.IsStaticCheckout) - return []; + var now = DateTime.Now; DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo); + //استثنا برای کارگاه پیتزا امیر برای برای نمایش ندادن کارپوشه قبل از 1 آبان 1404 + if(workshopId == 367 && twoMonthsAgo< new DateTime(2025,10,23)) + { + twoMonthsAgo = new DateTime(2025,10,23); + } + var lastCheckouts = _checkoutACL.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, twoMonthsAgo, now); List rollCalls = _rollCallACL.GetUndefinedRollCalls(workshopId, twoMonthsAgo, now.AddDays(-1).Date); var activeEmployees = _rollCallACL.GetActiveWorkshopRollCallEmployees(workshopId, twoMonthsAgo, now); @@ -451,14 +454,17 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetRollCallWorkFlowsCutByBgService(long workshopId) { - var workshop = _workshopRepository.Get(workshopId); - - if (workshop == null || workshop.IsStaticCheckout) - return []; + var now = DateTime.Now; DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo); + //استثنا برای کارگاه پیتزا امیر برای برای نمایش ندادن کارپوشه قبل از 1 آبان 1404 + if(workshopId == 367 && twoMonthsAgo< new DateTime(2025,10,23)) + { + twoMonthsAgo = new DateTime(2025,10,23); + } + var lastCheckouts = _checkoutACL.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, twoMonthsAgo, now); var rollCalls = _rollCallACL.GetRollCallWorkFlowsCutByBgService(workshopId, twoMonthsAgo, now.AddDays(-1).Date); var activeEmployees = _rollCallACL.GetActiveWorkshopRollCallEmployees(workshopId, twoMonthsAgo, now); @@ -656,14 +662,17 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetAbsentRollCallWorkFlows(long workshopId) { - var workshop = _workshopRepository.Get(workshopId); - - if (workshop == null || workshop.IsStaticCheckout) - return []; + var now = DateTime.Now; + DateTime.Now.Date.AddMonthsFa(-2, out var twoMonthsAgo); + //استثنا برای کارگاه پیتزا امیر برای برای نمایش ندادن کارپوشه قبل از 1 آبان 1404 + if(workshopId == 367 && twoMonthsAgo< new DateTime(2025,10,23)) + { + twoMonthsAgo = new DateTime(2025,10,23); + } var lastCheckouts = _checkoutACL.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, twoMonthsAgo, now); @@ -723,14 +732,16 @@ public class WorkFlowApplication : IWorkFlowApplication /// public async Task> GetEmployeesWithoutLunchBreak(long workshopId) { - var workshop = _workshopRepository.Get(workshopId); - - if (workshop == null || workshop.IsStaticCheckout) - return []; + var now = DateTime.Now.Date; now.AddMonthsFa(-2, out var twoMonthsAgo); + //استثنا برای کارگاه پیتزا امیر برای برای نمایش ندادن کارپوشه قبل از 1 آبان 1404 + if(workshopId == 367 && twoMonthsAgo< new DateTime(2025,10,23)) + { + twoMonthsAgo = new DateTime(2025,10,23); + } var lastCheckouts = _checkoutACL.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, twoMonthsAgo, now); var notSlicedRollCalls = _rollCallACL.GetNotSlicedRollCallsByWorkshopId(workshopId, twoMonthsAgo, now.AddDays(-1).Date); var employeesWithoutBreakTime = _customizedWorkshopSettingsACL.GetEmployeesWithoutBreakTime(workshopId); From 2a9d9574e36fa46de6c7b5db87c2a927c0f2fcd2 Mon Sep 17 00:00:00 2001 From: mahan Date: Wed, 29 Oct 2025 12:06:17 +0330 Subject: [PATCH 05/11] feat: filter employers in institution contract repository to exclude specific contracting party --- .../Repository/InstitutionContractRepository.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index b7435d03..535a43d8 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -2623,10 +2623,12 @@ public class InstitutionContractRepository : RepositoryBase new InstitutionContractSelectListViewModel() + //کارفرما ها به غیر از آن هایی که به طرف حساب ---- وصل هستند + var employers = _context.Employers.Where(x=>x.ContractingPartyId != 30428) + .Select(x => new InstitutionContractSelectListViewModel() { Id = x.id, - Text = x.FName + " " + x.LName + Text = x.FullName }); var representatives = _context.RepresentativeSet.Select(x => new InstitutionContractSelectListViewModel() { From 470651cb7622787c1e6c4d64d0f7431612604c69 Mon Sep 17 00:00:00 2001 From: mahan Date: Wed, 29 Oct 2025 18:43:23 +0330 Subject: [PATCH 06/11] feat: add method to remove roll call employee statuses and update handling of left work dates --- .../IRollCallEmployeeStatusRepository.cs | 3 +- .../LeftWorkApplication.cs | 180 ++++++++++----- .../LeftWorkTempApplication.cs | 208 ++++++++++-------- .../Repository/RollCallEmployeeRepository.cs | 3 +- 4 files changed, 249 insertions(+), 145 deletions(-) diff --git a/Company.Domain/RollCallEmployeeStatusAgg/IRollCallEmployeeStatusRepository.cs b/Company.Domain/RollCallEmployeeStatusAgg/IRollCallEmployeeStatusRepository.cs index ed2db0ec..2009aeec 100644 --- a/Company.Domain/RollCallEmployeeStatusAgg/IRollCallEmployeeStatusRepository.cs +++ b/Company.Domain/RollCallEmployeeStatusAgg/IRollCallEmployeeStatusRepository.cs @@ -26,5 +26,6 @@ namespace Company.Domain.RollCallEmployeeStatusAgg List GetActiveByWorkshopIdInDate(long workshopId, DateTime startDateGr, DateTime endDateGr); List GetByWorkshopIdInDates(long workshopId, DateTime start, DateTime end); bool IsActiveInPeriod(long employeeId, long workshopId, DateTime startDate, DateTime endDate); - } + void RemoveRange(IEnumerable rollCallEmployeeStatusList); + } } diff --git a/CompanyManagment.Application/LeftWorkApplication.cs b/CompanyManagment.Application/LeftWorkApplication.cs index 8f7a30ae..9aca683f 100644 --- a/CompanyManagment.Application/LeftWorkApplication.cs +++ b/CompanyManagment.Application/LeftWorkApplication.cs @@ -30,13 +30,14 @@ public class LeftWorkApplication : ILeftWorkApplication private readonly IEmployeeRepository _employeeRepository; private readonly IWorkshopRepository _workshopRepository; private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; - private readonly IRollCallEmployeeStatusRepository _rollCallEmployeeStatusRepository; + private readonly IRollCallEmployeeStatusRepository _rollCallEmployeeStatusRepository; - public LeftWorkApplication(ILeftWorkRepository leftWorkRepository, IContractRepository contractRepository, + public LeftWorkApplication(ILeftWorkRepository leftWorkRepository, IContractRepository contractRepository, IContractApplication contractApplication, IWorkingHoursApplication workingHoursApplication, IWorkingHoursItemsApplication workingHoursItemsApplication, IEmployeeRepository employeeRepository, - IWorkshopRepository workshopRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository) + IWorkshopRepository workshopRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, + IRollCallEmployeeRepository rollCallEmployeeRepository) { _leftWorkRepository = leftWorkRepository; _contractRepository = contractRepository; @@ -51,7 +52,6 @@ public class LeftWorkApplication : ILeftWorkApplication public OperationResult Create(CreateLeftWork command) { - // var Contracts = _contractRepository.Search(new ContractSearchModel() // { // EmployeeId = command.EmployeeId, @@ -70,7 +70,6 @@ public class LeftWorkApplication : ILeftWorkApplication var start = command.StartWorkDate.ToGeorgianDateTime(); - //if (_leftWorkRepository.Exists(x => // x.StartWorkDate > start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId)) // return operation.Failed("تاریخ وارد شده کوچکتر از سابقه شروع به کار قبلی است"); @@ -112,16 +111,17 @@ public class LeftWorkApplication : ILeftWorkApplication return operation.Failed("تاریخ وارد شده در بازه زمانی سابقه ترک کار قبلی است"); var employeeFullName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName; - var workshop = _workshopRepository.GetDetails(command.WorkshopId); - var workshopName = workshop.WorkshopFullName; + var workshop = _workshopRepository.GetDetails(command.WorkshopId); + var workshopName = workshop.WorkshopFullName; var leftWork = new LeftWork(left, start, command.WorkshopId, command.EmployeeId, employeeFullName, workshopName, command.JobId, command.IncludeStatus, - command.AddBonusesPay, command.AddYearsPay, command.AddLeavePay,workshop.ComputeOptions,workshop.BonusesOptions); + command.AddBonusesPay, command.AddYearsPay, command.AddLeavePay, workshop.ComputeOptions, + workshop.BonusesOptions); _leftWorkRepository.Create(leftWork); _leftWorkRepository.SaveChanges(); - IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId); + IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId, command.WorkshopId); - return operation.Succcedded(); + return operation.Succcedded(); } //public OperationResult Create(CreateLeftWork command) @@ -193,8 +193,8 @@ public class LeftWorkApplication : ILeftWorkApplication command.EmployeeId, command.JobId, command.IncludeStatus, command.AddBonusesPay, command.AddYearsPay, command.AddLeavePay); _leftWorkRepository.SaveChanges(); - IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId); - return operation.Succcedded(); + IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId, command.WorkshopId); + return operation.Succcedded(); } public EditLeftWork GetDetails(long id) @@ -214,11 +214,9 @@ public class LeftWorkApplication : ILeftWorkApplication public List SearchCreateContract(LeftWorkSearchModel searchModel) { - return _leftWorkRepository.SearchCreateContract(searchModel); } - public async Task> searchAsync(LeftWorkSearchModel searchModel) { @@ -228,7 +226,6 @@ public class LeftWorkApplication : ILeftWorkApplication public string GetBeforeDate(string date) { - var persianBefore = ""; var year = Convert.ToInt32(date.Substring(0, 4)); var month = Convert.ToInt32(date.Substring(5, 2)); @@ -255,10 +252,8 @@ public class LeftWorkApplication : ILeftWorkApplication } - public void LeftWorkExtension(long contractId, string CStart, string CEnd) { - var step1 = _contractApplication.GetDetails(contractId); var step2 = _workingHoursApplication.GetByContractId(contractId); var step3 = _workingHoursItemsApplication.GetWorkingHoursItems(); @@ -380,13 +375,11 @@ public class LeftWorkApplication : ILeftWorkApplication ContarctStart = CStart, ContractEnd = CEnd, GetWorkDateHide = step1.GetWorkDate, - }; var step5 = _contractApplication.MandatoryHours(computing); string workingDays = string.Empty; if (step5.NumberOfWorkingDays == "0") { - workingDays = step5.ComplexNumberOfWorkingDays; } else @@ -477,8 +470,6 @@ public class LeftWorkApplication : ILeftWorkApplication OverTimeWorkM = step5.OverTimeWorkM == "0" ? "" : step5.OverTimeWorkM, OverNightWorkH = step5.OverNightWorkH == "0" ? "" : step5.OverNightWorkH, OverNightWorkM = step5.OverNightWorkM == "0" ? "" : step5.OverNightWorkM, - - }; var resss = _contractApplication.Create(createNew); } @@ -529,7 +520,9 @@ public class LeftWorkApplication : ILeftWorkApplication item.LeftWorkDate = string.IsNullOrWhiteSpace(item.LeftWorkDate) ? "1500/01/01" : item.LeftWorkDate; var left = item.LeftWorkDate.ToGeorgianDateTime(); var start = item.StartWorkDate.ToGeorgianDateTime(); - if (_leftWorkRepository.Exists(x => x.StartWorkDate > start && left == null && x.EmployeeId == informationLeftwork.EmployeeId && x.WorkshopId == informationLeftwork.WorkshopId && x.id!=item.Id)) + if (_leftWorkRepository.Exists(x => + x.StartWorkDate > start && left == null && x.EmployeeId == informationLeftwork.EmployeeId && + x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id)) return operation.Failed("وارد کردن تاریخ پایان کار اجباری است "); if (_leftWorkRepository.Exists(x => x.StartWorkDate == start && x.EmployeeId == informationLeftwork.EmployeeId && @@ -540,17 +533,23 @@ public class LeftWorkApplication : ILeftWorkApplication x.EmployeeId == informationLeftwork.EmployeeId && x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id)) return operation.Failed("شروع به کار قبلی این شخص ترک کار ندارد "); - if (_leftWorkRepository.Exists(x => x.StartWorkDate <= start && x.LeftWorkDate < left && x.LeftWorkDate >= start && x.EmployeeId == informationLeftwork.EmployeeId && x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id)) + if (_leftWorkRepository.Exists(x => + x.StartWorkDate <= start && x.LeftWorkDate < left && x.LeftWorkDate >= start && + x.EmployeeId == informationLeftwork.EmployeeId && + x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id)) return operation.Failed("تاریخ وارد شده در بازه زمانی سابقه ترک کار قبلی است"); } } - operation = _leftWorkRepository.CreateLeftWork(informationLeftwork); - if (informationLeftwork != null && operation.IsSuccedded) IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(informationLeftwork.EmployeeId); - return operation; - } + operation = _leftWorkRepository.CreateLeftWork(informationLeftwork); + if (informationLeftwork != null && operation.IsSuccedded) + IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(informationLeftwork.EmployeeId, + informationLeftwork.WorkshopId); + return operation; + } - public OperationResult CreateLeftWorkByLeftWorkGroups(string employeeFullName, long commandEmployeeId, List commandPersonnelCode, List leftWorkGroups) + public OperationResult CreateLeftWorkByLeftWorkGroups(string employeeFullName, long commandEmployeeId, + List commandPersonnelCode, List leftWorkGroups) { var operation = new OperationResult(); @@ -560,7 +559,9 @@ public class LeftWorkApplication : ILeftWorkApplication { foreach (var item2 in item.LeftWorkViewModels) { - item2.LeftWorkDate = string.IsNullOrWhiteSpace(item2.LeftWorkDate) ? "1500/01/01" : item2.LeftWorkDate; + item2.LeftWorkDate = string.IsNullOrWhiteSpace(item2.LeftWorkDate) + ? "1500/01/01" + : item2.LeftWorkDate; var left = item2.LeftWorkDate.ToGeorgianDateTime(); var start = item2.StartWorkDate.ToGeorgianDateTime(); if (_leftWorkRepository.Exists(x => @@ -586,14 +587,16 @@ public class LeftWorkApplication : ILeftWorkApplication } } - operation = _leftWorkRepository.CreateLeftWorkByLeftWorkGroups(employeeFullName, commandEmployeeId, commandPersonnelCode, leftWorkGroups); - if (operation.IsSuccedded) IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(commandEmployeeId); - return operation; - } + operation = _leftWorkRepository.CreateLeftWorkByLeftWorkGroups(employeeFullName, commandEmployeeId, + commandPersonnelCode, leftWorkGroups); + if (operation.IsSuccedded) + IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(commandEmployeeId); + return operation; + } public OperationResult CheckDeleteLeftWork(long workshopId, long employeeId, string date, int type) { - return _leftWorkRepository.CheckDeleteLeftWork( workshopId, employeeId, date.ToGeorgianDateTime(),type); + return _leftWorkRepository.CheckDeleteLeftWork(workshopId, employeeId, date.ToGeorgianDateTime(), type); } public OperationResult CheckEditLeftWork(long workshopId, long employeeId, string date, int type) @@ -607,21 +610,23 @@ public class LeftWorkApplication : ILeftWorkApplication } #region Pooya + //این متد ترک کار های کارمند را با فعالیت حضور غیاب یکپارچه می کند private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId) { //get last leftworks for employee in all workshops - var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() { EmployeeId = employeeId }).GroupBy(x => x.WorkshopId).Select(x => - { - var leftWork = x.MaxBy(y => y.StartWorkDateGr); - return new LeftWorkViewModel() + var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() { EmployeeId = employeeId }) + .GroupBy(x => x.WorkshopId).Select(x => { - EmployeeId = employeeId, - WorkshopId = x.Key, - LeftWorkDateGr = leftWork.LeftWorkDateGr.Date.AddDays(-1), - StartWorkDateGr = leftWork.StartWorkDateGr - }; - }).ToList(); + var leftWork = x.MaxBy(y => y.StartWorkDateGr); + return new LeftWorkViewModel() + { + EmployeeId = employeeId, + WorkshopId = x.Key, + LeftWorkDateGr = leftWork.LeftWorkDateGr.Date.AddDays(-1), + StartWorkDateGr = leftWork.StartWorkDateGr + }; + }).ToList(); //get rollCallEmployee associated with those leftworks which have a higher end date than leftworkDate var rollCallsEmployee = _rollCallEmployeeRepository.GetByEmployeeIdWithStatuses(employeeId) @@ -632,17 +637,90 @@ public class LeftWorkApplication : ILeftWorkApplication x.WorkshopId, x.EmployeeId, y.LeftWorkDateGr, - Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr) + Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => + z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr) }); //shaping up the list to send as parameter to repository - var newRollCallRecords = joinedList.Where(x => x.Status != null).Select(x => new AdjustRollCallEmployeesWithEmployeeLeftWork() - { - LeaveDate = x.LeftWorkDateGr, - RollCallStatusId = x.Status.Id - }).ToList(); - if(newRollCallRecords.Count > 0) + var newRollCallRecords = joinedList.Where(x => x.Status != null).Select(x => + new AdjustRollCallEmployeesWithEmployeeLeftWork() + { + LeaveDate = x.LeftWorkDateGr, + RollCallStatusId = x.Status.Id + }).ToList(); + if (newRollCallRecords.Count > 0) _rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates(newRollCallRecords); + + foreach (var rollCallEmployeeViewModel in rollCallsEmployee) + { + var maxLeftWork = leftWorks.FirstOrDefault(x => x.WorkshopId == rollCallEmployeeViewModel.WorkshopId); + if (maxLeftWork == null) + { + continue; + } + + var employeeStatus = _rollCallEmployeeRepository.GetBy(rollCallEmployeeViewModel.EmployeeId, + rollCallEmployeeViewModel.WorkshopId); + var rollCallEmployeeStatusList = employeeStatus.EmployeesStatus + .Where(x => x.StartDate >= maxLeftWork.LeftWorkDateGr).ToList(); + if (rollCallEmployeeStatusList.Any()) + { + _rollCallEmployeeStatusRepository.RemoveRange(rollCallEmployeeStatusList); + _rollCallEmployeeStatusRepository.SaveChanges(); + } + } + } + + private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId, long workshopId) + { + //get last leftworks for employee in all workshops + var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() + { EmployeeId = employeeId, WorkshopId = workshopId }) + .Select(x => new LeftWorkViewModel() + { + EmployeeId = employeeId, + WorkshopId = x.WorkshopId, + LeftWorkDateGr = x.LeftWorkDateGr.Date.AddDays(-1), + StartWorkDateGr = x.StartWorkDateGr + }).ToList(); + + var maxLeftWork = leftWorks.MaxBy(y => y.StartWorkDateGr); + + + //get rollCallEmployee associated with those leftworks which have a higher end date than leftworkDate + var rollCallsEmployee = _rollCallEmployeeRepository.GetBy(employeeId, workshopId); + + // var joinedList = rollCallsEmployee.Join(leftWorks, x => x.WorkshopId, y => y.WorkshopId, (x, y) => new + // { + // x.WorkshopId, + // x.EmployeeId, + // y.LeftWorkDateGr, + // Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr) + // }); + + + var status = rollCallsEmployee.EmployeesStatus.OrderByDescending(z => z.StartDate) + .FirstOrDefault(rollCallEmployeeStatus => rollCallEmployeeStatus.StartDate.Date < maxLeftWork.LeftWorkDateGr + && rollCallEmployeeStatus.EndDate.Date > + maxLeftWork.LeftWorkDateGr); + + if (status != null) + { + var adjust = new AdjustRollCallEmployeesWithEmployeeLeftWork() + { + LeaveDate = maxLeftWork.LeftWorkDateGr, + RollCallStatusId = status.id + }; + _rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates([adjust]); + } + + var rollCallEmployeeStatusList = rollCallsEmployee.EmployeesStatus + .Where(x => x.StartDate >= maxLeftWork.LeftWorkDateGr).ToList(); + if (rollCallEmployeeStatusList.Any()) + { + _rollCallEmployeeStatusRepository.RemoveRange(rollCallEmployeeStatusList); + _rollCallEmployeeStatusRepository.SaveChanges(); + } } #endregion diff --git a/CompanyManagment.Application/LeftWorkTempApplication.cs b/CompanyManagment.Application/LeftWorkTempApplication.cs index fbb8daf4..3f2b2dab 100644 --- a/CompanyManagment.Application/LeftWorkTempApplication.cs +++ b/CompanyManagment.Application/LeftWorkTempApplication.cs @@ -27,26 +27,30 @@ namespace CompanyManagment.Application; public class LeftWorkTempApplication : ILeftWorkTempApplication { - private readonly ILeftWorkTempRepository _leftWorkTempRepository; - private readonly ILeftWorkRepository _leftWorkRepository; - private readonly IWorkshopRepository _workshopRepository; - private readonly IEmployeeRepository _employeeRepository; - private readonly IJobRepository _jobRepository; - private readonly ICheckoutRepository _checkoutRepository; - private readonly IContractRepository _contractRepository; + private readonly ILeftWorkTempRepository _leftWorkTempRepository; + private readonly ILeftWorkRepository _leftWorkRepository; + private readonly IWorkshopRepository _workshopRepository; + private readonly IEmployeeRepository _employeeRepository; + private readonly IJobRepository _jobRepository; + private readonly ICheckoutRepository _checkoutRepository; + private readonly IContractRepository _contractRepository; private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository; private readonly IRollCallEmployeeStatusRepository _rollCallEmployeeStatusRepository; - public LeftWorkTempApplication(ILeftWorkTempRepository leftWorkTempRepository, ILeftWorkRepository leftWorkRepository, IWorkshopRepository workshopRepository, IEmployeeRepository employeeRepository, IJobRepository jobRepository, ICheckoutRepository checkoutRepository, IContractRepository contractRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository) - { - _leftWorkTempRepository = leftWorkTempRepository; - _leftWorkRepository = leftWorkRepository; - _workshopRepository = workshopRepository; - _employeeRepository = employeeRepository; - _jobRepository = jobRepository; - _checkoutRepository = checkoutRepository; - _contractRepository = contractRepository; + public LeftWorkTempApplication(ILeftWorkTempRepository leftWorkTempRepository, + ILeftWorkRepository leftWorkRepository, IWorkshopRepository workshopRepository, + IEmployeeRepository employeeRepository, IJobRepository jobRepository, ICheckoutRepository checkoutRepository, + IContractRepository contractRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, + IRollCallEmployeeRepository rollCallEmployeeRepository) + { + _leftWorkTempRepository = leftWorkTempRepository; + _leftWorkRepository = leftWorkRepository; + _workshopRepository = workshopRepository; + _employeeRepository = employeeRepository; + _jobRepository = jobRepository; + _checkoutRepository = checkoutRepository; + _contractRepository = contractRepository; _rollCallEmployeeStatusRepository = rollCallEmployeeStatusRepository; _rollCallEmployeeRepository = rollCallEmployeeRepository; } @@ -59,15 +63,16 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication { #region Validation - if (_leftWorkTempRepository.Exists(x=>x.WorkshopId == command.WorkshopId && x.EmployeeId == employeeId)) + if (_leftWorkTempRepository.Exists(x => x.WorkshopId == command.WorkshopId && x.EmployeeId == employeeId)) { - return op.Failed("برای پرسنل وارد شده قبلا درخواست ترک کار ثبت کرده اید"); + return op.Failed("برای پرسنل وارد شده قبلا درخواست ترک کار ثبت کرده اید"); } if (command.LeftWorkTime.TryToGeorgianDateTime(out var leftWorkDateGr) == false) { return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است"); } + if (command.LastDayStanding.TryToGeorgianDateTime(out var lastDayStandingDateGr) == false) { return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است"); @@ -101,7 +106,6 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication } - //if (leftWork.StartWorkDate >= leftWorkDateGr) //{ // return op.Failed("ترک کار نمیتواند کوچک تر یا مساوی شروع به کار باشد"); @@ -121,10 +125,10 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication // return op.Failed("این پرسنل در تاریخ ترک کار وارد شده دارای قرارداد میباشد"); //} - #endregion - var leftWorkTemp = LeftWorkTemp.CreateLeftWork(leftWork.id, leftWork.StartWorkDate, leftWorkDateGr, lastDayStandingDateGr, + var leftWorkTemp = LeftWorkTemp.CreateLeftWork(leftWork.id, leftWork.StartWorkDate, leftWorkDateGr, + lastDayStandingDateGr, command.WorkshopId, employeeId, leftWork.JobId); await _leftWorkTempRepository.CreateAsync(leftWorkTemp); @@ -135,61 +139,63 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication } public Task GetStartAndLeftWorkDetails(long employeeId, long workshopId) - { - return _leftWorkTempRepository.GetStartAndLeftWorkDetails(employeeId, workshopId); - } + { + return _leftWorkTempRepository.GetStartAndLeftWorkDetails(employeeId, workshopId); + } - public async Task AcceptStartWork(AcceptStartWorkTemp command) - { - var op = new OperationResult(); - if (command.StartDateTime.TryToGeorgianDateTime(out var startDateGr) == false) - { - return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است"); - } + public async Task AcceptStartWork(AcceptStartWorkTemp command) + { + var op = new OperationResult(); + if (command.StartDateTime.TryToGeorgianDateTime(out var startDateGr) == false) + { + return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است"); + } - var leftWorkTemp = _leftWorkTempRepository.Get(command.LeftWorkTempId); + var leftWorkTemp = _leftWorkTempRepository.Get(command.LeftWorkTempId); - if (leftWorkTemp.LeftWorkType != LeftWorkTempType.StartWork) - { - return op.Failed("اطلاعات وارد شده نامعتبر است"); - } + if (leftWorkTemp.LeftWorkType != LeftWorkTempType.StartWork) + { + return op.Failed("اطلاعات وارد شده نامعتبر است"); + } - if (_leftWorkRepository.Exists(x => x.WorkshopId == leftWorkTemp.WorkshopId && x.EmployeeId == leftWorkTemp.EmployeeId && x.LeftWorkDate >= startDateGr)) - { - return op.Failed("شروع به کار وارد شده با ترک کار های قبلی تداخل دارد"); - } + if (_leftWorkRepository.Exists(x => + x.WorkshopId == leftWorkTemp.WorkshopId && x.EmployeeId == leftWorkTemp.EmployeeId && + x.LeftWorkDate >= startDateGr)) + { + return op.Failed("شروع به کار وارد شده با ترک کار های قبلی تداخل دارد"); + } - if (_jobRepository.Exists(x => x.id == command.JobId) == false) - { - return op.Failed("سمت وارد شده نامعتبر است"); - } + if (_jobRepository.Exists(x => x.id == command.JobId) == false) + { + return op.Failed("سمت وارد شده نامعتبر است"); + } - var defaultTime = new DateTime(2121, 03, 21); + var defaultTime = new DateTime(2121, 03, 21); - var workshop = _workshopRepository.Get(leftWorkTemp.WorkshopId); - var employee = _employeeRepository.Get(leftWorkTemp.EmployeeId); + var workshop = _workshopRepository.Get(leftWorkTemp.WorkshopId); + var employee = _employeeRepository.Get(leftWorkTemp.EmployeeId); - var newLeftWork = new LeftWork(defaultTime, startDateGr, leftWorkTemp.WorkshopId, leftWorkTemp.EmployeeId, - employee.FullName, workshop.WorkshopFullName, command.JobId, false, false, false, false, "", ""); + var newLeftWork = new LeftWork(defaultTime, startDateGr, leftWorkTemp.WorkshopId, leftWorkTemp.EmployeeId, + employee.FullName, workshop.WorkshopFullName, command.JobId, false, false, false, false, "", ""); - await _leftWorkRepository.CreateAsync(newLeftWork); - _leftWorkTempRepository.Remove(leftWorkTemp); - var rollCallEmployee = _rollCallEmployeeRepository.GetBy(leftWorkTemp.EmployeeId, leftWorkTemp.WorkshopId); + await _leftWorkRepository.CreateAsync(newLeftWork); + _leftWorkTempRepository.Remove(leftWorkTemp); + var rollCallEmployee = _rollCallEmployeeRepository.GetBy(leftWorkTemp.EmployeeId, leftWorkTemp.WorkshopId); - var rollCallStatus = rollCallEmployee?.EmployeesStatus.MaxBy(x => x.StartDate); + var rollCallStatus = rollCallEmployee?.EmployeesStatus.MaxBy(x => x.StartDate); - if (rollCallStatus != null) - { - var startWork = newLeftWork.StartWorkDate; - rollCallStatus.Edit(startWork, rollCallStatus.EndDate); + if (rollCallStatus != null) + { + var startWork = newLeftWork.StartWorkDate; + rollCallStatus.Edit(startWork, rollCallStatus.EndDate); + } - } - await _leftWorkRepository.SaveChangesAsync(); - await _leftWorkTempRepository.SaveChangesAsync(); + await _leftWorkRepository.SaveChangesAsync(); + await _leftWorkTempRepository.SaveChangesAsync(); - return op.Succcedded(); - } + return op.Succcedded(); + } public async Task AcceptLeftWork(AcceptLeftWorkTemp command) { @@ -237,9 +243,12 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication x.WorkshopId == leftWorkTemp.WorkshopId && x.ContractStart <= lastDayStandingGr && x.ContractEnd >= lastDayStandingGr)) { - return op.Failed("این پرسنل در تاریخ ترک کار وارد شده دارای فیش حقوقی میباشد. ابتدا فیش حقوقی پرسنل را حذف کنید "); + return op.Failed( + "این پرسنل در تاریخ ترک کار وارد شده دارای فیش حقوقی میباشد. ابتدا فیش حقوقی پرسنل را حذف کنید "); } + var transaction = await _rollCallEmployeeStatusRepository.BeginTransactionAsync(); + leftWork.Edit(leftWorkDateGr, leftWork.StartWorkDate, leftWork.WorkshopId, leftWork.EmployeeId, leftWork.JobId, leftWork.IncludeStatus, leftWork.AddBonusesPay, leftWork.AddYearsPay, leftWork.AddLeavePay); @@ -247,8 +256,9 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication await _leftWorkRepository.SaveChangesAsync(); await _leftWorkTempRepository.SaveChangesAsync(); - IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(leftWork.EmployeeId); + IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(leftWork.EmployeeId, leftWork.WorkshopId); + await transaction.CommitAsync(); return op.Succcedded(); } @@ -259,45 +269,59 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication public List GetLeftWorksByWorkshopId(long workshopId) { - return _leftWorkTempRepository.GetLeftWorksByWorkshopId(workshopId); - + return _leftWorkTempRepository.GetLeftWorksByWorkshopId(workshopId); } //این متد ترک کار های کارمند را با فعالیت حضور غیاب یکپارچه می کند - private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId) + private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId, long workshopId) { //get last leftworks for employee in all workshops - var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() { EmployeeId = employeeId }).GroupBy(x => x.WorkshopId).Select(x => - { - var leftWork = x.MaxBy(y => y.StartWorkDateGr); - return new LeftWorkViewModel() + var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() + { EmployeeId = employeeId, WorkshopId = workshopId }) + .Select(x => new LeftWorkViewModel() { EmployeeId = employeeId, - WorkshopId = x.Key, - LeftWorkDateGr = leftWork.LeftWorkDateGr.Date.AddDays(-1), - StartWorkDateGr = leftWork.StartWorkDateGr - }; - }).ToList(); + WorkshopId = x.WorkshopId, + LeftWorkDateGr = x.LeftWorkDateGr.Date.AddDays(-1), + StartWorkDateGr = x.StartWorkDateGr + }).ToList(); + + var maxLeftWork = leftWorks.MaxBy(y => y.StartWorkDateGr); + //get rollCallEmployee associated with those leftworks which have a higher end date than leftworkDate - var rollCallsEmployee = _rollCallEmployeeRepository.GetByEmployeeIdWithStatuses(employeeId) - .Where(x => leftWorks.Any(y => y.WorkshopId == x.WorkshopId)).ToList(); + var rollCallsEmployee = _rollCallEmployeeRepository.GetBy(employeeId, workshopId); - var joinedList = rollCallsEmployee.Join(leftWorks, x => x.WorkshopId, y => y.WorkshopId, (x, y) => new - { - x.WorkshopId, - x.EmployeeId, - y.LeftWorkDateGr, - Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr) - }); + // var joinedList = rollCallsEmployee.Join(leftWorks, x => x.WorkshopId, y => y.WorkshopId, (x, y) => new + // { + // x.WorkshopId, + // x.EmployeeId, + // y.LeftWorkDateGr, + // Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr) + // }); - //shaping up the list to send as parameter to repository - var newRollCallRecords = joinedList.Where(x => x.Status != null).Select(x => new AdjustRollCallEmployeesWithEmployeeLeftWork() + + var status = rollCallsEmployee.EmployeesStatus.OrderByDescending(z => z.StartDate) + .FirstOrDefault(rollCallEmployeeStatus => rollCallEmployeeStatus.StartDate.Date < maxLeftWork.LeftWorkDateGr + && rollCallEmployeeStatus.EndDate.Date > + maxLeftWork.LeftWorkDateGr); + + if (status != null) { - LeaveDate = x.LeftWorkDateGr, - RollCallStatusId = x.Status.Id - }).ToList(); - if (newRollCallRecords.Count > 0) - _rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates(newRollCallRecords); + var adjust = new AdjustRollCallEmployeesWithEmployeeLeftWork() + { + LeaveDate = maxLeftWork.LeftWorkDateGr, + RollCallStatusId = status.id + }; + _rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates([adjust]); + } + + var rollCallEmployeeStatusList = rollCallsEmployee.EmployeesStatus + .Where(x => x.StartDate >= maxLeftWork.LeftWorkDateGr).ToList(); + if (rollCallEmployeeStatusList.Any()) + { + _rollCallEmployeeStatusRepository.RemoveRange(rollCallEmployeeStatusList); + _rollCallEmployeeStatusRepository.SaveChanges(); + } } } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs index 7e027a38..8955c814 100644 --- a/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallEmployeeRepository.cs @@ -478,7 +478,8 @@ public class RollCallEmployeeRepository : RepositoryBase public RollCallEmployee GetBy(long employeeId, long workshopId) { - return _context.RollCallEmployees.Include(x => x.EmployeesStatus).FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId); + return _context.RollCallEmployees.Include(x => x.EmployeesStatus) + .FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId); } #endregion From 0eb9ecc373012642fed6f5cb338026e1e6253e96 Mon Sep 17 00:00:00 2001 From: SamSys Date: Sat, 1 Nov 2025 13:21:41 +0330 Subject: [PATCH 07/11] client checkou warning message FrontEnd --- .../Repository/CheckoutRepository.cs | 11 ++++-- .../Pages/Company/Checkouts/Index.cshtml | 35 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index f67e1c2e..cb843e5a 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -1691,7 +1691,7 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos return new List(); } #endregion - var query = _context.CheckoutSet + var query = _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList) .AsSplitQuery().Select(x => new CheckoutViewModel() { Id = x.id, @@ -1726,7 +1726,14 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos SalaryAidDateTimeFa = s.SalaryAidDateTimeFa, SalaryAidDateTimeGe = s.SalaryAidDateTime }).ToList(), - HasAmountConflict = x.HasAmountConflict + HasAmountConflict = x.HasAmountConflict, + IsUpdateNeeded = x.IsUpdateNeeded, + CheckoutWarningMessageList = x.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel + { + WarningMessage = wm.WarningMessage, + TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, + + }).ToList() }).Where(x => x.WorkshopId == searchModel.WorkshopId); if (searchModel.EmployeeId > 0) diff --git a/ServiceHost/Areas/Client/Pages/Company/Checkouts/Index.cshtml b/ServiceHost/Areas/Client/Pages/Company/Checkouts/Index.cshtml index b06f3dd1..2bb15424 100644 --- a/ServiceHost/Areas/Client/Pages/Company/Checkouts/Index.cshtml +++ b/ServiceHost/Areas/Client/Pages/Company/Checkouts/Index.cshtml @@ -8,6 +8,9 @@ Layout = "Shared/_ClientLayout"; ViewData["Title"] = " - " + "فیش حقوقی"; int i = 0; + + const string hasAmountConflictText = "توجه داشته باشید این فیش حقوقی دارای تغییرات اعمال نشده میباشد. جهت صدور فیش حقوقی استاندارد مجددا فیش را ایجاد کنید!"; + const string needUpdateText = "جهت صدور فیش حقوقی استاندارد مجددا فیش را ایجاد کنید"; } @section Styles { @@ -335,7 +338,7 @@
    -
    شماره پرسنلی
    +
    شماره پرسنلی
    سال
    ماه
    شماره قرارداد
    @@ -364,7 +367,10 @@
    - @if (item.HasAmountConflict) + + + + @if (item.IsUpdateNeeded || item.HasAmountConflict) { - - + title='@{ + var tooltipText = ""; int messCounter = 1; + if (item.HasAmountConflict && !item.IsUpdateNeeded) + { + tooltipText += @hasAmountConflictText; + + }else if (item.HasAmountConflict && item.IsUpdateNeeded) + { + foreach (var warning in item.CheckoutWarningMessageList) { tooltipText += " " + messCounter + " - " + warning.WarningMessage; messCounter++;} + + + tooltipText += " " + @needUpdateText; } + else if (!item.HasAmountConflict && item.IsUpdateNeeded) + { foreach (var warning in item.CheckoutWarningMessageList) { tooltipText += " " + messCounter + " - " + warning.WarningMessage; messCounter++; } + tooltipText += " " + @needUpdateText;} + @Html.Raw(tooltipText) + + }'> + + + } +
    From 18c27d7a9ab3ec3891af1f6e73c8475a66163f79 Mon Sep 17 00:00:00 2001 From: mahan Date: Sun, 2 Nov 2025 11:05:27 +0330 Subject: [PATCH 08/11] fix dates js error --- ServiceHost/wwwroot/AssetsClient/pages/Reward/js/Index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ServiceHost/wwwroot/AssetsClient/pages/Reward/js/Index.js b/ServiceHost/wwwroot/AssetsClient/pages/Reward/js/Index.js index ced00532..38198aef 100644 --- a/ServiceHost/wwwroot/AssetsClient/pages/Reward/js/Index.js +++ b/ServiceHost/wwwroot/AssetsClient/pages/Reward/js/Index.js @@ -66,8 +66,7 @@ $(document).ready(function () { let value = convertPersianNumbersToEnglish(element.val()); element.val(value); }); - - new Cleave('.dateInput', { + new Cleave(this, { delimiters: ['/', '/'], blocks: [4, 2, 2], numericOnly: true @@ -78,6 +77,7 @@ $(document).ready(function () { // datePattern: ['Y', 'm', 'd'] // }); }); + //******************** انتخاب همه ی چک باکس ها ******************** $(".checkAll").change(function () { From 7b9e7881c64c7727ce5729458044242fc051804b Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 3 Nov 2025 14:45:41 +0330 Subject: [PATCH 09/11] feat: add commented-out method for retrieving contract list for client --- Company.Domain/ContractAgg/IContractRepository.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Company.Domain/ContractAgg/IContractRepository.cs b/Company.Domain/ContractAgg/IContractRepository.cs index 3d6ea269..109d3a6a 100644 --- a/Company.Domain/ContractAgg/IContractRepository.cs +++ b/Company.Domain/ContractAgg/IContractRepository.cs @@ -48,6 +48,9 @@ public interface IContractRepository : IRepository bool Remove(long id); List SearchForClient(ContractSearchModel searchModel); + + //Task> GetContractListForClient(ContractClientSearchModel searchModel); + #endregion #region NewChangeByHeydari From e124a4d5d90edc8b0c83d78fbab348dfa6b66040 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 3 Nov 2025 17:43:50 +0330 Subject: [PATCH 10/11] feat: implement method to retrieve paginated contract list for client with filtering options --- .../ContractAgg/IContractRepository.cs | 34 +++++- .../Repository/ContractRepository.cs | 104 ++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-) diff --git a/Company.Domain/ContractAgg/IContractRepository.cs b/Company.Domain/ContractAgg/IContractRepository.cs index 109d3a6a..4edc80fe 100644 --- a/Company.Domain/ContractAgg/IContractRepository.cs +++ b/Company.Domain/ContractAgg/IContractRepository.cs @@ -49,7 +49,7 @@ public interface IContractRepository : IRepository List SearchForClient(ContractSearchModel searchModel); - //Task> GetContractListForClient(ContractClientSearchModel searchModel); + Task> GetContractListForClient(GetContractListForClientRequest searchModel); #endregion #region NewChangeByHeydari @@ -66,4 +66,36 @@ public interface IContractRepository : IRepository ContractViweModel GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime startOfMonth, DateTime endOfMonth); List GetByWorkshopIdInDates(long workshopId, DateTime contractStart, DateTime contractEnd); #endregion +} + +public class GetContractListForClientResponse +{ + public long Id { get; set; } + public string PersonnelCode { get; set; } + public string ContractNo { get; set; } + public string EmployeeFullName { get; set; } + public string ContractStart { get; set; } + public string ContractEnd { get; set; } + public bool IsSigned { get; set; } +} + +public class GetContractListForClientRequest: PaginationRequest +{ + public int Year { get; set; } + public int Month { get; set; } + public string StartDate { get; set; } + public string EndDate { get; set; } + public long EmployeeId { get; set; } + public ContractListOrderType? OrderType { get; set; } +} + +public enum ContractListOrderType +{ + ByContractCreationDate, + BySignedContract, + ByUnSignedContract, + ByPersonnelCode, + ByPersonnelCodeDescending, + ByContractStartDate, + ByContractStartDateDescending } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/ContractRepository.cs b/CompanyManagment.EFCore/Repository/ContractRepository.cs index c9d82f10..0a563b28 100644 --- a/CompanyManagment.EFCore/Repository/ContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/ContractRepository.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Threading.Tasks; using _0_Framework.Application; +using _0_Framework.Exceptions; using _0_Framework.InfraStructure; using Company.Domain.ContractAgg; using Company.Domain.empolyerAgg; @@ -1506,6 +1507,109 @@ public class ContractRepository : RepositoryBase, IContractRepos } + public async Task> GetContractListForClient(GetContractListForClientRequest searchModel) + { + var workshopId = _authHelper.GetWorkshopId(); + var query = _context.Contracts + .Where(c => c.WorkshopIds == workshopId); + + #region Search + + if (searchModel.EmployeeId > 0) + query = query.Where(x => x.EmployeeId == searchModel.EmployeeId); + if (!string.IsNullOrWhiteSpace(searchModel.StartDate) && string.IsNullOrWhiteSpace(searchModel.EndDate)) + { + if (!searchModel.StartDate.TryToGeorgianDateTime(out var startDate)) + throw new BadRequestException("تاریخ شروع وارد شده معتبر نمی باشد."); + + if (!searchModel.EndDate.TryToGeorgianDateTime(out var endDate)) + throw new BadRequestException("تاریخ پایان وارد شده معتبر نمی باشد."); + + query = query.Where(x => x.ContarctStart <=endDate && x.ContractEnd >= startDate); + } + + if (searchModel.Year>0 && searchModel.Month >0) + { + + var startDateFa = $"{searchModel.Year:0000}/{searchModel.Month:00}/01"; + if (!startDateFa.TryToGeorgianDateTime(out var startDate)) + throw new BadRequestException("سال و ماه وارد شده معتبر نمی باشد."); + + if(!startDateFa.FindeEndOfMonth().TryToGeorgianDateTime(out var endDate)) + throw new BadRequestException("سال و ماه وارد شده معتبر نمی باشد."); + + query = query.Where(x => x.ContarctStart <=endDate && x.ContractEnd >= startDate); + } + + if (searchModel.OrderType != null) + { + switch (searchModel.OrderType) + { + case ContractListOrderType.ByContractCreationDate: + query = query.OrderBy(x => x.CreationDate); + break; + case ContractListOrderType.ByContractStartDate: + query = query.OrderBy(x => x.ContarctStart); + break; + case ContractListOrderType.ByContractStartDateDescending: + query = query.OrderByDescending(x=>x.ContarctStart); + break; + case ContractListOrderType.ByPersonnelCode: + query = query.OrderBy(x => x.PersonnelCode); + break; + case ContractListOrderType.ByPersonnelCodeDescending: + query = query.OrderByDescending(x => x.PersonnelCode); + break; + case ContractListOrderType.BySignedContract: + query = query.OrderByDescending(x => x.Signature == "1"); + break; + case ContractListOrderType.ByUnSignedContract: + query = query.OrderBy(x => x.Signature == "1"); + break; + } + } + else + { + query = query.OrderByDescending(x => x.id); + } + #endregion + + var pagedList =await query + .ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); + + var employeeIds = pagedList.Select(x => x.EmployeeId).ToList(); + + var employees = await _context.Employees + .Where(x => employeeIds.Contains(x.id)).Select(x => new + { + Id = x.id, + x.FullName + }).ToListAsync(); + + var result = new PagedResult + { + TotalCount = await query.CountAsync(), + List = pagedList.Select(c => + { + var employeeFullName = employees + .FirstOrDefault(e => e.Id == c.EmployeeId)?.FullName ?? ""; + + return new GetContractListForClientResponse + { + Id = c.id, + PersonnelCode = c.PersonnelCode.ToString(), + ContractStart = c.ContarctStart.ToFarsi(), + ContractEnd = c.ContractEnd.ToFarsi(), + ContractNo = c.ContractNo, + IsSigned = c.Signature == "1", + EmployeeFullName = employeeFullName + }; + }).ToList() + }; + + return result; + } + #endregion #region NewChangeByHeydari From 9cf8447a83bb16d41ccd2404e9b5fcbd32ab57e0 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 3 Nov 2025 17:49:51 +0330 Subject: [PATCH 11/11] feat: add API for retrieving paginated contract list for client with filtering options --- .../ContractAgg/IContractRepository.cs | 29 ------------------- .../Contract/ContractListOrderType.cs | 12 ++++++++ .../GetContractListForClientRequest.cs | 13 +++++++++ .../GetContractListForClientResponse.cs | 12 ++++++++ .../Contract/IContractApplication.cs | 11 +++++++ .../ContractApplication.cs | 5 ++++ .../Client/Controllers/ContractController.cs | 27 +++++++++++++++++ 7 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 CompanyManagment.App.Contracts/Contract/ContractListOrderType.cs create mode 100644 CompanyManagment.App.Contracts/Contract/GetContractListForClientRequest.cs create mode 100644 CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs create mode 100644 ServiceHost/Areas/Client/Controllers/ContractController.cs diff --git a/Company.Domain/ContractAgg/IContractRepository.cs b/Company.Domain/ContractAgg/IContractRepository.cs index 4edc80fe..fbffa304 100644 --- a/Company.Domain/ContractAgg/IContractRepository.cs +++ b/Company.Domain/ContractAgg/IContractRepository.cs @@ -68,34 +68,5 @@ public interface IContractRepository : IRepository #endregion } -public class GetContractListForClientResponse -{ - public long Id { get; set; } - public string PersonnelCode { get; set; } - public string ContractNo { get; set; } - public string EmployeeFullName { get; set; } - public string ContractStart { get; set; } - public string ContractEnd { get; set; } - public bool IsSigned { get; set; } -} -public class GetContractListForClientRequest: PaginationRequest -{ - public int Year { get; set; } - public int Month { get; set; } - public string StartDate { get; set; } - public string EndDate { get; set; } - public long EmployeeId { get; set; } - public ContractListOrderType? OrderType { get; set; } -} -public enum ContractListOrderType -{ - ByContractCreationDate, - BySignedContract, - ByUnSignedContract, - ByPersonnelCode, - ByPersonnelCodeDescending, - ByContractStartDate, - ByContractStartDateDescending -} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Contract/ContractListOrderType.cs b/CompanyManagment.App.Contracts/Contract/ContractListOrderType.cs new file mode 100644 index 00000000..0fca1352 --- /dev/null +++ b/CompanyManagment.App.Contracts/Contract/ContractListOrderType.cs @@ -0,0 +1,12 @@ +namespace CompanyManagment.App.Contracts.Contract; + +public enum ContractListOrderType +{ + ByContractCreationDate, + BySignedContract, + ByUnSignedContract, + ByPersonnelCode, + ByPersonnelCodeDescending, + ByContractStartDate, + ByContractStartDateDescending +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Contract/GetContractListForClientRequest.cs b/CompanyManagment.App.Contracts/Contract/GetContractListForClientRequest.cs new file mode 100644 index 00000000..060a5f08 --- /dev/null +++ b/CompanyManagment.App.Contracts/Contract/GetContractListForClientRequest.cs @@ -0,0 +1,13 @@ +using _0_Framework.Application; + +namespace CompanyManagment.App.Contracts.Contract; + +public class GetContractListForClientRequest: PaginationRequest +{ + public int Year { get; set; } + public int Month { get; set; } + public string StartDate { get; set; } + public string EndDate { get; set; } + public long EmployeeId { get; set; } + public ContractListOrderType? OrderType { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs b/CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs new file mode 100644 index 00000000..d7efa472 --- /dev/null +++ b/CompanyManagment.App.Contracts/Contract/GetContractListForClientResponse.cs @@ -0,0 +1,12 @@ +namespace CompanyManagment.App.Contracts.Contract; + +public class GetContractListForClientResponse +{ + public long Id { get; set; } + public string PersonnelCode { get; set; } + public string ContractNo { get; set; } + public string EmployeeFullName { get; set; } + public string ContractStart { get; set; } + public string ContractEnd { get; set; } + public bool IsSigned { get; set; } +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs index 5048b564..8e17f094 100644 --- a/CompanyManagment.App.Contracts/Contract/IContractApplication.cs +++ b/CompanyManagment.App.Contracts/Contract/IContractApplication.cs @@ -45,7 +45,18 @@ public interface IContractApplication #region Client OperationResult Remove(long id); + + [Obsolete("این متد منسوخ شده است. لطفاً از متد GetContractListForClient استفاده کنید.")] List SearchForClient(ContractSearchModel searchModel); + + /// + /// لیست قراردادها برای کلاینت + /// + /// + /// + Task> + GetContractListForClient(GetContractListForClientRequest searchModel); + #endregion #region NewChangeByHeydari diff --git a/CompanyManagment.Application/ContractApplication.cs b/CompanyManagment.Application/ContractApplication.cs index 085616ea..b5936feb 100644 --- a/CompanyManagment.Application/ContractApplication.cs +++ b/CompanyManagment.Application/ContractApplication.cs @@ -3107,6 +3107,11 @@ public class ContractApplication : IContractApplication return _contractRepository.SearchForClient(searchModel); } + public async Task> GetContractListForClient(GetContractListForClientRequest searchModel) + { + return await _contractRepository.GetContractListForClient(searchModel); + } + #endregion #region NewChangeByHeydari diff --git a/ServiceHost/Areas/Client/Controllers/ContractController.cs b/ServiceHost/Areas/Client/Controllers/ContractController.cs new file mode 100644 index 00000000..95d24437 --- /dev/null +++ b/ServiceHost/Areas/Client/Controllers/ContractController.cs @@ -0,0 +1,27 @@ +using _0_Framework.Application; +using Company.Domain.ContractAgg; +using CompanyManagment.App.Contracts.Contract; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Client.Controllers; + +public class ContractController:ClientBaseController +{ + private readonly IContractApplication _contractApplication; + + public ContractController(IContractApplication contractApplication) + { + _contractApplication = contractApplication; + } + + [HttpGet] + public async Task>> GetList( + GetContractListForClientRequest searchModel) + { + var res = await _contractApplication + .GetContractListForClient(searchModel); + + return res; + } +} \ No newline at end of file