From 7a58423eb34c3e57b73ec3bac8c2ec9c3cbfced8 Mon Sep 17 00:00:00 2001 From: mahan Date: Thu, 9 Oct 2025 14:30:09 +0330 Subject: [PATCH] feat: implement "GetNotCreatedWorkshop" method and update related functionality in InsuranceList --- .../InfraStructure/QueryableExtensions.cs | 4 +- .../IInsuranceListRepository.cs | 2 +- .../IInsuranceListApplication.cs | 2 +- .../InsuranceListApplication.cs | 2 +- .../Repository/InsuranceListRepository.cs | 52 ++++++++++++++++++- .../Pages/Company/InsuranceList/Index.cshtml | 1 + .../Company/InsuranceList/Index.cshtml.cs | 2 +- .../page/InsuranceList/js/Index.js | 6 +-- 8 files changed, 60 insertions(+), 11 deletions(-) diff --git a/0_Framework/InfraStructure/QueryableExtensions.cs b/0_Framework/InfraStructure/QueryableExtensions.cs index 8d28d29f..bcfb7bc6 100644 --- a/0_Framework/InfraStructure/QueryableExtensions.cs +++ b/0_Framework/InfraStructure/QueryableExtensions.cs @@ -5,14 +5,14 @@ namespace _0_Framework.InfraStructure; public static class QueryableExtensions { - public static IQueryable ApplyPagination(this IQueryable query, int page, int pageSize) + public static IQueryable ApplyPagination(this IQueryable query, int page, int pageSize = 30) { if (page <= 0) page = 1; if (pageSize <= 0) pageSize = 10; return query.Skip((page - 1) * pageSize).Take(pageSize); } - public static IEnumerable ApplyPagination(this IEnumerable source, int page, int pageSize) + public static IEnumerable ApplyPagination(this IEnumerable source, int page, int pageSize = 30) { if (page <= 0) page = 1; if (pageSize <= 0) pageSize = 10; diff --git a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs index 75607aaf..2e7fda1d 100644 --- a/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs +++ b/Company.Domain/InsuranceListAgg/IInsuranceListRepository.cs @@ -68,7 +68,7 @@ public interface IInsuranceListRepository:IRepository #endregion - Task GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); + Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); } diff --git a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs index 84f5b3f2..51e29b09 100644 --- a/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs +++ b/CompanyManagment.App.Contracts/InsuranceList/IInsuranceListApplication.cs @@ -49,5 +49,5 @@ public interface IInsuranceListApplication #endregion - Task GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); + Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.Application/InsuranceListApplication.cs b/CompanyManagment.Application/InsuranceListApplication.cs index 14b59841..2c0e032e 100644 --- a/CompanyManagment.Application/InsuranceListApplication.cs +++ b/CompanyManagment.Application/InsuranceListApplication.cs @@ -2366,7 +2366,7 @@ public class InsuranceListApplication : IInsuranceListApplication return _insuranceListRepositpry.GetTabCounts(searchModel); } - public async Task GetNotCreatedWorkshop(InsuranceListSearchModel searchModel) + public async Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel) { return await _insuranceListRepositpry.GetNotCreatedWorkshop(searchModel); } diff --git a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs index cfd0237d..c93e2b0c 100644 --- a/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs +++ b/CompanyManagment.EFCore/Repository/InsuranceListRepository.cs @@ -1473,6 +1473,7 @@ public class InsuranceListRepository : RepositoryBase, IIns var workshopIds = _context.WorkshopAccounts .Where(a => a.AccountId == acountId) .Select(a => a.WorkshopId); + var query = _context.InsuranceListSet .Where(x => workshopIds.Contains(x.WorkshopId)) .Join(_context.Workshops.Include(x => x.InsuranceWorkshopInfo), @@ -1569,9 +1570,56 @@ public class InsuranceListRepository : RepositoryBase, IIns } - public Task GetNotCreatedWorkshop(InsuranceListSearchModel searchModel) + public async Task> GetNotCreatedWorkshop(InsuranceListSearchModel searchModel) { - throw new NotImplementedException(); + if (string.IsNullOrEmpty(searchModel.Month) || string.IsNullOrEmpty(searchModel.Year) ) + { + return []; + } + var acountId = _authHelper.CurrentAccountId(); + var accountWorkshopIds = _context.WorkshopAccounts.Where(x => x.AccountId == acountId) + .Select(x => x.WorkshopId); + + var insuranceWorkshops = _context.Workshops + .Where(x=>x.InsuranceCode != null && x.InsuranceCode.Length >=10 && accountWorkshopIds.Contains(x.id) && x.IsActiveString== "true"); + + + var existInsurances = _context.InsuranceListSet + .Where(x=>x.Month == searchModel.Month&& x.Year == searchModel.Year).AsQueryable(); + + var notCreatedWorkshop = insuranceWorkshops.Where(w=>!existInsurances.Select(x=>x.WorkshopId).Contains(w.id)); + + var res = await notCreatedWorkshop + .GroupJoin(_context.WorkshopEmployers, + workshop => workshop.id, + workshopEmployer => workshopEmployer.WorkshopId, + (workshop, workshopEmployer) => new { workshop, workshopEmployer }) + .SelectMany(x => x.workshopEmployer.DefaultIfEmpty(), (x, workshopEmployer) => new { x.workshop, workshopEmployer }) + .GroupJoin(_context.Employers, + allResult => allResult.workshopEmployer.EmployerId, + employer => employer.id, + (allResult, employer) => new { allResult.workshop, allResult.workshopEmployer, employer }) + .SelectMany(x => x.employer.DefaultIfEmpty(), (x, employer) => new { x.workshop, x.workshopEmployer, employer }) + .Select(x => new InsuranceListViewModel + { + WorkShopId = x.workshop.id, + WorkShopCode = x.workshop.InsuranceCode, + WorkShopName = x.workshop.InsuranceWorkshopInfo != null ? x.workshop.InsuranceWorkshopInfo.WorkshopName : x.workshop.WorkshopFullName, + EmployerName = x.employer != null ? x.employer.FullName : (x.workshop.InsuranceWorkshopInfo != null ? x.workshop.InsuranceWorkshopInfo.EmployerName : x.workshop.WorkshopFullName), + Year = searchModel.Year, + Month = searchModel.Month, + TypeOfInsuranceSend = x.workshop.TypeOfInsuranceSend == "NormalList" ? "عادی" : + x.workshop.TypeOfInsuranceSend == "Govermentlist" ? "کمک دولت" : + x.workshop.TypeOfInsuranceSend == "Familylist" ? "خانوادگی" : "", + FixedSalary = (bool)x.workshop.FixedSalary, + StrFixedSalary = (bool)x.workshop.FixedSalary ? "دارد" : "ندارد", + EmployerId = x.workshopEmployer != null ? x.workshopEmployer.EmployerId : 0, + ArchiveCode = x.workshop.ArchiveCode, + City = x.workshop.City, + }).ApplyPagination(searchModel.PageIndex).ToListAsync(); + + return res; + } /// diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml index 0191e276..63560c20 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml @@ -544,6 +544,7 @@ var ajaxGetTabCountsUrl = `@Url.Page("/Company/InsuranceList/Index", "TabCounts")`; var ajaxSearchNewUrl = `@Url.Page("/Company/InsuranceList/Index", "SearchNew")`; + var ajaxNotCreatedUrl = `@Url.Page("/Company/InsuranceList/Index", "NotCreatedWorkshops")`; var openOperationsModalUrl = `@Url.Page("/Company/InsuranceList/Index", "OperationsModal")`; var editUrl = `#showmodal=@Url.Page("/Company/InsuranceList/Index", "Edit")`; var insuranceSummaryUrl = `#showmodal=@Url.Page("/Company/InsuranceList/Index", "InsuranceSummary")`; diff --git a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs index 65012021..f327b4d5 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/InsuranceList/Index.cshtml.cs @@ -1167,7 +1167,7 @@ public class IndexModel : PageModel var result =await _insuranceListApplication.GetNotCreatedWorkshop(searchModel); return new JsonResult(new { - result + data = result }); diff --git a/ServiceHost/wwwroot/AssetsAdmin/page/InsuranceList/js/Index.js b/ServiceHost/wwwroot/AssetsAdmin/page/InsuranceList/js/Index.js index a6f2797c..1b8b78fd 100644 --- a/ServiceHost/wwwroot/AssetsAdmin/page/InsuranceList/js/Index.js +++ b/ServiceHost/wwwroot/AssetsAdmin/page/InsuranceList/js/Index.js @@ -125,7 +125,7 @@ $(document).ready(function () { }); function loadNotCreatedData() { var pageIndex = pageIndexJs; - + var html = ""; var htmlMobile = ""; @@ -151,17 +151,17 @@ $(document).ready(function () { //Branch: paramsUrl['branch'], //City: paramsUrl['city'], FixedSalary: paramsUrl['fixed-salary'], - Status: status, PageIndex: pageIndex }; var b = pageIndexJs % 30; if (b === 0 && hasMoreData) { - ajaxService.get(ajaxSearchNewUrl, searchModel, false) + ajaxService.get(ajaxNotCreatedUrl, searchModel, false) .then(response => { var responseData = response.data; + debugger; if (responseData.length > 0) { responseData.forEach(function (item) {