diff --git a/Company.Domain/CheckoutAgg/ICheckoutRepository.cs b/Company.Domain/CheckoutAgg/ICheckoutRepository.cs index b14ba1cd..aa30b980 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; @@ -82,4 +83,16 @@ public interface ICheckoutRepository : IRepository Task GetByWorkshopIdEmployeeIdInDate(long workshopId, long employeeId, DateTime inDate); Task> GetListForClient(long workshopId, CheckoutListClientSearchModel searchModel); + + + #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..23d88b82 --- /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 string PersonnelCode { get; set; } + /// + /// فعال/غیرفعال + /// + public bool IsActive { get; set; } + + /// + /// امضاء فیش + /// + public bool Signature { get; set; } + + /// + /// نام کارفرما + /// + public string EmployerName { get; set; } + public bool 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 93ddb0cc..5d3c861c 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; @@ -65,6 +66,12 @@ public interface ICheckoutApplication Task> GetListForClient(long workshopId, CheckoutListClientSearchModel searchModel); + + #region ForApi + + Task> GetList(CheckoutSearchModelDto searchModel); + + #endregion } public class CheckoutListClientSearchModel:PaginationRequest @@ -98,4 +105,7 @@ public enum CheckoutClientListOrderType ByPersonnelCodeDescending, ByCheckoutStartDate, ByCheckoutStartDateDescending + + + } \ No newline at end of file diff --git a/CompanyManagment.Application/CheckoutApplication.cs b/CompanyManagment.Application/CheckoutApplication.cs index 11ce1fa9..231e69ab 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; @@ -712,4 +713,18 @@ public class CheckoutApplication : ICheckoutApplication } #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 d2fdc947..b4619895 100644 --- a/CompanyManagment.EFCore/Repository/CheckoutRepository.cs +++ b/CompanyManagment.EFCore/Repository/CheckoutRepository.cs @@ -1,23 +1,18 @@ -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.Exceptions; using _0_Framework.InfraStructure; 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; 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; @@ -32,6 +27,15 @@ 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 System.Xml.XPath; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace CompanyManagment.EFCore.Repository; @@ -2810,4 +2814,355 @@ public class CheckoutRepository : RepositoryBase, ICheckoutRepos } #endregion + + + + + #region ForApi + + public async Task> GetList(CheckoutSearchModelDto searchModel) + { + var acountID = _authHelper.CurrentAccountId(); + var workshopAccounts = _context.WorkshopAccounts.Where(x => x.AccountId == acountID) + .Select(x => x.WorkshopId); + + + //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 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.ContractNo == searchModel.ContractNo); + if (searchModel.WorkshopId != 0) + { + 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.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 (!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.ContractStart >= startyearGr && x.ContractEnd <= endYearGr); + if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || searchModel.EmployerId > 0) + checkouts = checkouts.OrderByDescending(x => x.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.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.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.ContractStart >= start && x.ContractStart <= endd); + + if (searchModel.WorkshopId > 0 || !string.IsNullOrWhiteSpace(searchModel.EmployeeFullName) || searchModel.EmployerId > 0) + checkouts = checkouts.OrderByDescending(x => x.ContractEnd).ThenBy(x => x.PersonnelCode); + } + + + #endregion + + + 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 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(); + var count = await checkouts.CountAsync(); + Console.WriteLine("FinalList================================ : " + watch.Elapsed); + 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); + } +} +