From 12af5dcb56cb043d3096aee2eb9c939294ec8641 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Wed, 14 Jan 2026 16:39:05 +0330 Subject: [PATCH 1/2] get checkout list init --- .../CheckoutAgg/ICheckoutRepository.cs | 21 +- .../Checkout/Dto/CheckoutDto.cs | 92 ++++++ .../Checkout/Dto/CheckoutSearchModelDto.cs | 47 +++ .../Checkout/ICheckoutApplication.cs | 12 +- .../CheckoutApplication.cs | 16 +- .../Repository/CheckoutRepository.cs | 297 +++++++++++++++++- .../Admin/Controllers/CheckoutController.cs | 30 ++ 7 files changed, 499 insertions(+), 16 deletions(-) create mode 100644 CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs create mode 100644 CompanyManagment.App.Contracts/Checkout/Dto/CheckoutSearchModelDto.cs create mode 100644 ServiceHost/Areas/Admin/Controllers/CheckoutController.cs diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index 5294bbaa..daa2c35d 100644 --- a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs +++ b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs @@ -1,9 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using _0_Framework.Application; +using _0_Framework.Application; using _0_Framework.Domain; using CompanyManagment.App.Contracts.Checkout; +using CompanyManagment.App.Contracts.Checkout.Dto; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Company.Domain.CheckoutAgg; @@ -80,4 +81,16 @@ public interface ICheckoutRepository : IRepository #endregion Task GetByWorkshopIdEmployeeIdInDate(long workshopId, long employeeId, DateTime inDate); + + + #region ForApi + + /// + /// دریافت لیست فیش حقوقی + /// + /// + /// + Task> GetList(CheckoutSearchModelDto searchModel); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs new file mode 100644 index 00000000..29a1b200 --- /dev/null +++ b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs @@ -0,0 +1,92 @@ +using System.Collections.Generic; + +namespace CompanyManagment.App.Contracts.Checkout.Dto; + +public class CheckoutDto +{ + /// + /// آی دی فیش + /// + public long Id { get; set; } + + /// + /// نام پرسنل + /// + public string EmployeeFullName { get; set; } + + /// + /// نام کارگاه + /// + public string WorkshopName { get; set; } + + /// + /// شماره قراداد + /// + public string ContractNo { get; set; } + + /// + /// تاریخ شروع فیش + /// + public string ContractStart { get; set; } + + /// + /// تاریخ پایان فیش + /// + public string ContractEnd { get; set; } + + /// + /// ماه + /// + public string Month { get; set; } + + /// + /// سال + /// + public string Year { get; set; } + + + + /// + /// روزهای کارکرد + /// + public string SumOfWorkingDays { get; set; } + + /// + /// شماره کارگاه + /// + public string ArchiveCode { get; set; } + + /// + /// کد پرسنلی + /// + public int PersonnelCode { get; set; } + /// + /// فعال/غیرفعال + /// + public string IsActiveString { get; set; } + + /// + /// امضاء فیش + /// + public string Signature { get; set; } + + /// + /// نام کارفرما + /// + public string EmployerName { get; set; } + public string IsBlockCantracingParty { get; set; } + /// + /// آیا فیش نیاز به بروزرسانی دارد + /// + public bool IsUpdateNeeded { get; set; } + /// + /// لیست پیام های هشدار فیش حقوقی + /// + public List CheckoutWarningMessageList { get; set; } + + /// + /// نیاز به امزا دارد یا خیر + /// + public bool HasSignCheckoutOption { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutSearchModelDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutSearchModelDto.cs new file mode 100644 index 00000000..1a231c29 --- /dev/null +++ b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutSearchModelDto.cs @@ -0,0 +1,47 @@ +using _0_Framework.Application; + +namespace CompanyManagment.App.Contracts.Checkout.Dto; + +public class CheckoutSearchModelDto : PaginationRequest +{ + /// + /// نام پرسنل + /// + public string EmployeeFullName { get; set; } + + /// + /// آی دی کارگاه + /// + public long WorkshopId { get; set; } + + /// + /// شماره قرارداد + /// + public string ContractNo { get; set; } + + /// + /// تاریخ شروع فیش + /// + public string ContractStart { get; set; } + + /// + /// تاریخ پاین فیش + /// + public string ContractEnd { get; set; } + + /// + /// ماه + /// + public string Month { get; set; } + + /// + /// سال + /// + public string Year { get; set; } + + /// + /// آی دی گارفرما + /// + public long EmployerId { get; set; } + +} \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs index 74f5cccb..e06f76c7 100644 --- a/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs +++ b/CompanyManagment.App.Contracts/Checkout/ICheckoutApplication.cs @@ -1,9 +1,10 @@ -using System; +using _0_Framework.Application; +using CompanyManagment.App.Contracts.Checkout.Dto; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using _0_Framework.Application; namespace CompanyManagment.App.Contracts.Checkout; @@ -62,4 +63,11 @@ public interface ICheckoutApplication long workshopId, DateTime start, DateTime end); #endregion + + + #region ForApi + + Task> GetList(CheckoutSearchModelDto searchModel); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 8768f70e..e5853920 100644 --- a/CompanyManagment.Application/CheckoutApplication.cs +++ b/CompanyManagment.Application/CheckoutApplication.cs @@ -23,6 +23,7 @@ using CompanyManagment.EFCore.Repository; using System.Globalization; using Company.Domain.LeaveAgg; using Company.Domain.WorkshopAgg; +using CompanyManagment.App.Contracts.Checkout.Dto; namespace CompanyManagment.Application; @@ -706,5 +707,18 @@ public class CheckoutApplication : ICheckoutApplication return _checkoutRepository.GetLastCheckoutsByWorkshopIdForWorkFlow(workshopId, start, end); } - #endregion + + + #endregion + + + + #region ForApi + + public async Task> GetList(CheckoutSearchModelDto searchModel) + { + return await _checkoutRepository.GetList(searchModel); + } + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index a78ff18e..837920d6 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Reflection.Metadata.Ecma335; -using System.Threading.Tasks; -using _0_Framework.Application; +using _0_Framework.Application; using _0_Framework.InfraStructure; using Company.Domain.CheckoutAgg; using Company.Domain.LeftWorkAgg; @@ -14,9 +6,11 @@ using Company.Domain.RollCallAgg; using Company.Domain.RollCallEmployeeAgg; using Company.Domain.WorkshopEmployerAgg; using CompanyManagment.App.Contracts.Checkout; +using CompanyManagment.App.Contracts.Checkout.Dto; using CompanyManagment.App.Contracts.Contract; using CompanyManagment.App.Contracts.Employee; using CompanyManagment.App.Contracts.HolidayItem; +using CompanyManagment.App.Contracts.InstitutionPlan; using CompanyManagment.App.Contracts.InsuranceList; using CompanyManagment.App.Contracts.Leave; using CompanyManagment.App.Contracts.LeftWork; @@ -31,6 +25,14 @@ using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using PersianTools.Core; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Threading.Tasks; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace CompanyManagment.EFCore.Repository; @@ -2752,4 +2754,281 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } #endregion + + + + + #region ForApi + + public async Task> GetList(CheckoutSearchModelDto searchModel) + { + var acountID = _authHelper.CurrentAccountId(); + var workshopAcounts =await _context.WorkshopAccounts.Where(x => x.AccountId == acountID) + .Select(x => x.WorkshopId).ToListAsync(); + + + //var checkouts = + // _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList).Where(x => workshopAcounts.Contains(x.WorkshopId)) + // .Join(_context.Workshops.AsSplitQuery(), + // ch => ch.WorkshopId, + // workshop => workshop.id, + // (ch, workshop) => new { ch, workshop }) + // .GroupJoin(_context.EmployeeComputeOptionsSet.AsSplitQuery(), + // x => x.workshop.id, + // option => option.WorkshopId, + // (x, options) => new { x.ch, x.workshop, options }) + // .SelectMany( + // x => x.options.DefaultIfEmpty(), + // (x, option) => new { x.ch, x.workshop, option }) + // .GroupJoin(_context.WorkshopEmployers.AsSplitQuery().Include(we => we.Employer), + // result => result.workshop.id, + // workshopEmployer => workshopEmployer.WorkshopId, + // (result, workshopEmployer) => new { result.ch, result.workshop, result.option, workshopEmployer }) + // .SelectMany( + // y => y.workshopEmployer.DefaultIfEmpty(), + // (y, workshopEmployer) => new { y.option, y.ch, y.workshop, workshopEmployer }) + // .Select(res => new + // { + // res.ch, + // res.workshop, + // option = _context.EmployeeComputeOptionsSet.FirstOrDefault(x => x.WorkshopId == res.ch.WorkshopId && x.EmployeeId == res.ch.EmployeeId), + // res.workshopEmployer, + // contractingParty = _context.PersonalContractingParties + // .Include(p => p.Employers) + // .FirstOrDefault(p => p.Employers.Any(e => e.id == res.workshopEmployer.Employer.id)) + // }); + + var checkouts = + _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList).Where(x => workshopAcounts.Contains(x.WorkshopId)) + .Join(_context.Workshops.AsSplitQuery(), + ch => ch.WorkshopId, + workshop => workshop.id, + (ch, workshop) => new { ch, workshop }) + .Select(res => new + { + res.ch, + res.workshop, + }); + #region SercheModel + + if (!string.IsNullOrWhiteSpace(searchModel.ContractNo)) + checkouts = checkouts.Where(x => + x.ch.ContractNo == searchModel.ContractNo); + if (searchModel.WorkshopId != 0) + { + checkouts = checkouts.Where(x => x.ch.WorkshopId == searchModel.WorkshopId); + } + if (!string.IsNullOrWhiteSpace(searchModel.EmployeeFullName)) + { + checkouts = checkouts.Where(x => x.ch.EmployeeFullName.Contains(searchModel.EmployeeFullName)); + } + //if (searchModel.EmployerId != 0) + //{ + // checkouts = checkouts.Where(x => x.contractingParty.Employers.Select(c => c.id).Contains(searchModel.EmployerId)); + //} + + + + + + //سرچ سال + + if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month) && + (string.IsNullOrWhiteSpace(searchModel.ContractStart) || + string.IsNullOrWhiteSpace(searchModel.ContractEnd))) + { + + var startYear = searchModel.Year + "/01/01"; + var startyearGr = startYear.ToGeorgianDateTime(); + var endYear = $"{searchModel.Year}/12/01".FindeEndOfMonth(); + var endYearGr = endYear.ToGeorgianDateTime(); + + + checkouts = checkouts.Where(x => x.ch.ContractStart >= startyearGr && x.ch.ContractEnd <= endYearGr); + if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || searchModel.EmployerId > 0) + checkouts = checkouts.OrderByDescending(x => x.ch.ContractEnd); + + } + else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) && + string.IsNullOrWhiteSpace(searchModel.ContractStart) && + string.IsNullOrWhiteSpace(searchModel.ContractEnd)) + { + + //سرچ سال و ماه + string y1 = $"{searchModel.Year}/{searchModel.Month}/01"; + var startDate = y1.ToGeorgianDateTime(); + string y2 = string.Empty; + int month = Convert.ToInt32(searchModel.Month); + int year = Convert.ToInt32(searchModel.Year); + + if (month <= 6) + { + y2 = $"{searchModel.Year}/{searchModel.Month}/31"; + } + else if (month > 6 && month < 12) + { + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + } + else if (month == 12) + { + switch (year) + { + case 1346: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1350: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1354: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1358: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1362: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1366: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1370: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1375: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1379: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1383: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1387: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1391: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1395: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1399: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1403: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1408: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1412: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1416: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1420: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1424: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1428: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1432: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1436: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1441: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + case 1445: + y2 = $"{searchModel.Year}/{searchModel.Month}/30"; + break; + + default: + y2 = $"{searchModel.Year}/{searchModel.Month}/29"; + break; + } + } + + + var endDate = y2.ToGeorgianDateTime(); + + //checkouts = checkouts.Where(x => x.ContractEndGr >= start && x.ContractEndGr <= end).ToList(); + checkouts = checkouts.Where(x => + x.ch.ContractStart >= startDate && x.ch.ContractStart < endDate && x.ch.ContractEnd > startDate && + x.ch.ContractEnd <= endDate || + x.ch.ContractStart <= startDate && x.ch.ContractEnd >= endDate || + startDate <= x.ch.ContractStart && endDate > x.ch.ContractStart || + endDate >= x.ch.ContractEnd && startDate < x.ch.ContractEnd); + //if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) + // checkouts = checkouts.OrderBy(x => x.ch.PersonnelCodeInt); + + } + else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && + !string.IsNullOrWhiteSpace(searchModel.ContractEnd) && + string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month)) + { + + //سرچ تاریخ + var start = searchModel.ContractStart.ToGeorgianDateTime(); + var endd = searchModel.ContractEnd.ToGeorgianDateTime(); + checkouts = checkouts.Where(x => + x.ch.ContractStart >= start && x.ch.ContractStart <= endd); + + //if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) + // checkouts = checkouts.OrderByDescending(x => x.ch.ContractEnd).ThenBy(x => x.ch.PersonnelCodeInt); + } + + + #endregion + + + var count = await checkouts.CountAsync(); + var checkoutQueryFilter = await checkouts.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); + + var result = checkoutQueryFilter.Select(x => new CheckoutDto + { + Id = x.ch.id, + EmployeeFullName = x.ch.EmployeeFullName, + ContractStart = x.ch.ContractStart.ToFarsi(), + ContractEnd = x.ch.ContractEnd.ToFarsi(), + PersonnelCode = Convert.ToInt32(x.ch.PersonnelCode), + ArchiveCode = x.workshop.ArchiveCode, + SumOfWorkingDays = x.ch.SumOfWorkingDays, + WorkshopName = x.workshop.WorkshopName, + Month = x.ch.Month, + Year = x.ch.Year, + ContractNo = x.ch.ContractNo, + IsActiveString = x.ch.IsActiveString, + Signature = x.ch.Signature, + //EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", + //IsBlockCantracingParty = x.contractingParty.IsBlock, + //HasSignCheckoutOption = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, + IsUpdateNeeded = x.ch.IsUpdateNeeded, + CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel + { + WarningMessage = wm.WarningMessage, + TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, + + }).ToList() + + }).OrderByDescending(x => x.Id) + .ThenByDescending(x => x.Year) + .ThenBy(x => x.PersonnelCode) + .ToList(); + + + return new PagedResult() + { + TotalCount = count, + List = result + }; + } + + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs new file mode 100644 index 00000000..b8ef27ba --- /dev/null +++ b/ServiceHost/Areas/Admin/Controllers/CheckoutController.cs @@ -0,0 +1,30 @@ +using _0_Framework.Application; +using CompanyManagment.App.Contracts.Checkout; +using CompanyManagment.App.Contracts.Checkout.Dto; +using CompanyManagment.App.Contracts.InstitutionPlan; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Admin.Controllers; + +public class CheckoutController : AdminBaseController +{ + private readonly ICheckoutApplication _checkoutApplication; + + public CheckoutController(ICheckoutApplication checkoutApplication) + { + _checkoutApplication = checkoutApplication; + } + + /// + /// دریافت لیست فیش حقوقی + /// + /// + /// + [HttpGet("GetList")] + public async Task>> GetList(CheckoutSearchModelDto searchModel) + { + return await _checkoutApplication.GetList(searchModel); + } +} + From bf03247f81c0475930c81cb9d33366dea2bc77d6 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Sun, 18 Jan 2026 15:59:17 +0330 Subject: [PATCH 2/2] checkout list completed --- .../Checkout/Dto/CheckoutDto.cs | 8 +- .../Repository/CheckoutRepository.cs | 198 ++++++++++++------ 2 files changed, 141 insertions(+), 65 deletions(-) diff --git a/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs index 29a1b200..23d88b82 100644 --- a/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs +++ b/CompanyManagment.App.Contracts/Checkout/Dto/CheckoutDto.cs @@ -59,22 +59,22 @@ public class CheckoutDto /// /// کد پرسنلی /// - public int PersonnelCode { get; set; } + public string PersonnelCode { get; set; } /// /// فعال/غیرفعال /// - public string IsActiveString { get; set; } + public bool IsActive { get; set; } /// /// امضاء فیش /// - public string Signature { get; set; } + public bool Signature { get; set; } /// /// نام کارفرما /// public string EmployerName { get; set; } - public string IsBlockCantracingParty { get; set; } + public bool IsBlockCantracingParty { get; set; } /// /// آیا فیش نیاز به بروزرسانی دارد /// diff --git a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs index 837920d6..87871b5b 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -4,6 +4,7 @@ using Company.Domain.CheckoutAgg; using Company.Domain.LeftWorkAgg; using Company.Domain.RollCallAgg; using Company.Domain.RollCallEmployeeAgg; +using Company.Domain.WorkshopAgg; using Company.Domain.WorkshopEmployerAgg; using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Checkout.Dto; @@ -33,6 +34,7 @@ using System.Globalization; using System.Linq; using System.Reflection.Metadata.Ecma335; using System.Threading.Tasks; +using System.Xml.XPath; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace CompanyManagment.EFCore.Repository; @@ -2763,8 +2765,8 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos public async Task> GetList(CheckoutSearchModelDto searchModel) { var acountID = _authHelper.CurrentAccountId(); - var workshopAcounts =await _context.WorkshopAccounts.Where(x => x.AccountId == acountID) - .Select(x => x.WorkshopId).ToListAsync(); + var workshopAccounts = _context.WorkshopAccounts.Where(x => x.AccountId == acountID) + .Select(x => x.WorkshopId); //var checkouts = @@ -2798,36 +2800,82 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos // .FirstOrDefault(p => p.Employers.Any(e => e.id == res.workshopEmployer.Employer.id)) // }); - var checkouts = - _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList).Where(x => workshopAcounts.Contains(x.WorkshopId)) - .Join(_context.Workshops.AsSplitQuery(), - ch => ch.WorkshopId, - workshop => workshop.id, - (ch, workshop) => new { ch, workshop }) - .Select(res => new - { - res.ch, - res.workshop, - }); + //var checkoutss = + // _context.CheckoutSet.Include(w => w.CheckoutWarningMessageList).Where(x => workshopAcounts.Contains(x.WorkshopId)) + // .Join(_context.Workshops.AsSplitQuery(), + // ch => ch.WorkshopId, + // workshop => workshop.id, + // (ch, workshop) => new { ch, workshop }) + // .Select(res => new + // { + // res.ch, + // res.workshop, + // }); + var watch = new Stopwatch(); + watch.Start(); + var checkouts = + ( + from workshop in _context.Workshops.Where(x => workshopAccounts.Contains(x.id)) + join x in _context.CheckoutSet + on workshop.id equals x.WorkshopId + + //.Include(x=>x.CheckoutWarningMessageList) + //join workshop in _context.Workshops + // on ch.WorkshopId equals workshop.id + + + select new + { + Id = x.id, + EmployeeFullName = x.EmployeeFullName, + EmployeeId = x.EmployeeId, + ContractStart = x.ContractStart, + ContractEnd = x.ContractEnd, + PersonnelCode = x.PersonnelCode, + SumOfWorkingDays = x.SumOfWorkingDays, + Month = x.Month, + Year = x.Year, + ContractNo = x.ContractNo, + IsActiveString = x.IsActiveString, + Signature = x.Signature, + IsUpdateNeeded = x.IsUpdateNeeded, + WorkshopId = x.WorkshopId, + ArchiveCode = workshop.ArchiveCode, + WorkshopName = workshop.WorkshopFullName, + WorkshopSignCheckout = workshop.SignCheckout, + + } + + ).OrderByDescending(x => x.Id) + .ThenByDescending(x => x.Year) + .ThenByDescending(x=>x.ContractStart) + .ThenBy(x => x.PersonnelCode).AsNoTracking(); + + Console.WriteLine("getList======================= : " + watch.Elapsed); #region SercheModel if (!string.IsNullOrWhiteSpace(searchModel.ContractNo)) checkouts = checkouts.Where(x => - x.ch.ContractNo == searchModel.ContractNo); + x.ContractNo == searchModel.ContractNo); if (searchModel.WorkshopId != 0) { - checkouts = checkouts.Where(x => x.ch.WorkshopId == searchModel.WorkshopId); + checkouts = checkouts.Where(x => x.WorkshopId == searchModel.WorkshopId) + .OrderByDescending(x => x.ContractStart) + .ThenBy(x => x.PersonnelCode); } if (!string.IsNullOrWhiteSpace(searchModel.EmployeeFullName)) { - checkouts = checkouts.Where(x => x.ch.EmployeeFullName.Contains(searchModel.EmployeeFullName)); + checkouts = checkouts.Where(x => x.EmployeeFullName.Contains(searchModel.EmployeeFullName)); + } + if (searchModel.EmployerId != 0) + { + var workshopIds = _context.WorkshopEmployers.Where(e => e.EmployerId == searchModel.EmployerId) + .Select(e => e.WorkshopId); + checkouts = checkouts.Where(x => workshopIds.Contains(x.WorkshopId)) + .OrderByDescending(x => x.ContractStart); } - //if (searchModel.EmployerId != 0) - //{ - // checkouts = checkouts.Where(x => x.contractingParty.Employers.Select(c => c.id).Contains(searchModel.EmployerId)); - //} - + @@ -2844,9 +2892,9 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var endYearGr = endYear.ToGeorgianDateTime(); - checkouts = checkouts.Where(x => x.ch.ContractStart >= startyearGr && x.ch.ContractEnd <= endYearGr); + checkouts = checkouts.Where(x => x.ContractStart >= startyearGr && x.ContractEnd <= endYearGr); if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || searchModel.EmployerId > 0) - checkouts = checkouts.OrderByDescending(x => x.ch.ContractEnd); + checkouts = checkouts.OrderByDescending(x => x.ContractEnd); } else if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month) && @@ -2960,13 +3008,13 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos //checkouts = checkouts.Where(x => x.ContractEndGr >= start && x.ContractEndGr <= end).ToList(); checkouts = checkouts.Where(x => - x.ch.ContractStart >= startDate && x.ch.ContractStart < endDate && x.ch.ContractEnd > startDate && - x.ch.ContractEnd <= endDate || - x.ch.ContractStart <= startDate && x.ch.ContractEnd >= endDate || - startDate <= x.ch.ContractStart && endDate > x.ch.ContractStart || - endDate >= x.ch.ContractEnd && startDate < x.ch.ContractEnd); + x.ContractStart >= startDate && x.ContractStart < endDate && x.ContractEnd > startDate && + x.ContractEnd <= endDate || + x.ContractStart <= startDate && x.ContractEnd >= endDate || + startDate <= x.ContractStart && endDate > x.ContractStart || + endDate >= x.ContractEnd && startDate < x.ContractEnd); //if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) - // checkouts = checkouts.OrderBy(x => x.ch.PersonnelCodeInt); + // checkouts = checkouts.OrderBy(x => x.PersonnelCodeInt); } else if (!string.IsNullOrWhiteSpace(searchModel.ContractStart) && @@ -2978,51 +3026,79 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos var start = searchModel.ContractStart.ToGeorgianDateTime(); var endd = searchModel.ContractEnd.ToGeorgianDateTime(); checkouts = checkouts.Where(x => - x.ch.ContractStart >= start && x.ch.ContractStart <= endd); + x.ContractStart >= start && x.ContractStart <= endd); - //if (searchModel.WorkshopId > 0 || searchModel.EmployeeId > 0 || searchModel.EmployerId > 0) - // checkouts = checkouts.OrderByDescending(x => x.ch.ContractEnd).ThenBy(x => x.ch.PersonnelCodeInt); + if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || searchModel.EmployerId > 0) + checkouts = checkouts.OrderByDescending(x => x.ContractEnd).ThenBy(x => x.PersonnelCode); } #endregion - var count = await checkouts.CountAsync(); + watch.Reset(); + watch.Start(); + var checkoutQueryFilter = await checkouts.ApplyPagination(searchModel.PageIndex, searchModel.PageSize).ToListAsync(); + Console.WriteLine("pagination===================== : " + watch.Elapsed); + + var employers =await + _context.WorkshopEmployers.Where(x => checkoutQueryFilter + .Select(c => c.WorkshopId).Contains(x.WorkshopId)) + .Select(x=> new {x.Employer, x.WorkshopId}).ToListAsync(); + var contractingPartiesIds = employers.Select(x => x.Employer.ContractingPartyId).ToList(); + var warningMessages = await _context.CheckoutWarningMessages.Where(x => checkoutQueryFilter + .Select(c => c.Id).Contains(x.CheckoutId)).ToListAsync(); + + + var contractnigParties = await _context.PersonalContractingParties + .Where(x => contractingPartiesIds.Contains(x.id)).ToListAsync(); + + var options = await _context.EmployeeComputeOptionsSet.Where(x => checkoutQueryFilter + .Select(c => c.WorkshopId).Contains(x.WorkshopId)).ToListAsync(); + + watch.Reset(); + watch.Start(); + var result = checkoutQueryFilter.Select(x => + - var result = checkoutQueryFilter.Select(x => new CheckoutDto - { - Id = x.ch.id, - EmployeeFullName = x.ch.EmployeeFullName, - ContractStart = x.ch.ContractStart.ToFarsi(), - ContractEnd = x.ch.ContractEnd.ToFarsi(), - PersonnelCode = Convert.ToInt32(x.ch.PersonnelCode), - ArchiveCode = x.workshop.ArchiveCode, - SumOfWorkingDays = x.ch.SumOfWorkingDays, - WorkshopName = x.workshop.WorkshopName, - Month = x.ch.Month, - Year = x.ch.Year, - ContractNo = x.ch.ContractNo, - IsActiveString = x.ch.IsActiveString, - Signature = x.ch.Signature, - //EmployerName = $"{x.workshopEmployer.Employer.FName} {x.workshopEmployer.Employer.LName}", - //IsBlockCantracingParty = x.contractingParty.IsBlock, - //HasSignCheckoutOption = x.option != null ? x.option.SignCheckout : x.workshop.SignCheckout, - IsUpdateNeeded = x.ch.IsUpdateNeeded, - CheckoutWarningMessageList = x.ch.CheckoutWarningMessageList.Select(wm => new CheckoutWarningMessageModel { - WarningMessage = wm.WarningMessage, - TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, + var warningMessage = warningMessages.Where(wm => wm.CheckoutId == x.Id); + var empl = employers.First(em => em.WorkshopId == x.WorkshopId); + var isBlock = contractnigParties.Any(cp => cp.id == empl.Employer.ContractingPartyId && cp.IsBlock == "true"); + var option = options.FirstOrDefault(o => o.WorkshopId == x.WorkshopId && o.EmployeeId == x.EmployeeId); + return new CheckoutDto + { + Id = x.Id, + EmployeeFullName = x.EmployeeFullName, + ContractStart = x.ContractStart.ToFarsi(), + ContractEnd = x.ContractEnd.ToFarsi(), + PersonnelCode = x.PersonnelCode, + ArchiveCode = x.ArchiveCode, + SumOfWorkingDays = x.SumOfWorkingDays, + WorkshopName = x.WorkshopName, + Month = x.Month, + Year = x.Year, + ContractNo = x.ContractNo, + IsActive = x.IsActiveString == "true", + Signature = x.Signature == "1", + EmployerName = $"{empl.Employer.FullName}", + IsBlockCantracingParty = isBlock, + HasSignCheckoutOption = option != null ? option.SignCheckout : x.WorkshopSignCheckout, + IsUpdateNeeded = x.IsUpdateNeeded, + CheckoutWarningMessageList = warningMessage.Select(wm => new CheckoutWarningMessageModel + { + WarningMessage = wm.WarningMessage, + TypeOfCheckoutWarning = wm.TypeOfCheckoutWarning, - }).ToList() + }).ToList() + }; - }).OrderByDescending(x => x.Id) - .ThenByDescending(x => x.Year) - .ThenBy(x => x.PersonnelCode) + + }) .ToList(); - - + var count = await checkouts.CountAsync(); + Console.WriteLine("FinalList================================ : " + watch.Elapsed); return new PagedResult() { TotalCount = count,