From 12af5dcb56cb043d3096aee2eb9c939294ec8641 Mon Sep 17 00:00:00 2001 From: gozareshgir Date: Wed, 14 Jan 2026 16:39:05 +0330 Subject: [PATCH] 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); + } +} +