merge from adminCheckoutApi

This commit is contained in:
gozareshgir
2026-01-18 18:07:10 +03:30
7 changed files with 577 additions and 15 deletions

View File

@@ -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<long, Checkout>
Task<Checkout> GetByWorkshopIdEmployeeIdInDate(long workshopId, long employeeId, DateTime inDate);
Task<PagedResult<CheckoutListClientDto>> GetListForClient(long workshopId,
CheckoutListClientSearchModel searchModel);
#region ForApi
/// <summary>
/// دریافت لیست فیش حقوقی
/// </summary>
/// <param name="searchModel"></param>
/// <returns></returns>
Task<PagedResult<CheckoutDto>> GetList(CheckoutSearchModelDto searchModel);
#endregion
}

View File

@@ -0,0 +1,92 @@
using System.Collections.Generic;
namespace CompanyManagment.App.Contracts.Checkout.Dto;
public class CheckoutDto
{
/// <summary>
/// آی دی فیش
/// </summary>
public long Id { get; set; }
/// <summary>
/// نام پرسنل
/// </summary>
public string EmployeeFullName { get; set; }
/// <summary>
/// نام کارگاه
/// </summary>
public string WorkshopName { get; set; }
/// <summary>
/// شماره قراداد
/// </summary>
public string ContractNo { get; set; }
/// <summary>
/// تاریخ شروع فیش
/// </summary>
public string ContractStart { get; set; }
/// <summary>
/// تاریخ پایان فیش
/// </summary>
public string ContractEnd { get; set; }
/// <summary>
/// ماه
/// </summary>
public string Month { get; set; }
/// <summary>
/// سال
/// </summary>
public string Year { get; set; }
/// <summary>
/// روزهای کارکرد
/// </summary>
public string SumOfWorkingDays { get; set; }
/// <summary>
/// شماره کارگاه
/// </summary>
public string ArchiveCode { get; set; }
/// <summary>
/// کد پرسنلی
/// </summary>
public string PersonnelCode { get; set; }
/// <summary>
/// فعال/غیرفعال
/// </summary>
public bool IsActive { get; set; }
/// <summary>
/// امضاء فیش
/// </summary>
public bool Signature { get; set; }
/// <summary>
/// نام کارفرما
/// </summary>
public string EmployerName { get; set; }
public bool IsBlockCantracingParty { get; set; }
/// <summary>
/// آیا فیش نیاز به بروزرسانی دارد
/// </summary>
public bool IsUpdateNeeded { get; set; }
/// <summary>
/// لیست پیام های هشدار فیش حقوقی
/// </summary>
public List<CheckoutWarningMessageModel> CheckoutWarningMessageList { get; set; }
/// <summary>
/// نیاز به امزا دارد یا خیر
/// </summary>
public bool HasSignCheckoutOption { get; set; }
}

View File

@@ -0,0 +1,47 @@
using _0_Framework.Application;
namespace CompanyManagment.App.Contracts.Checkout.Dto;
public class CheckoutSearchModelDto : PaginationRequest
{
/// <summary>
/// نام پرسنل
/// </summary>
public string EmployeeFullName { get; set; }
/// <summary>
/// آی دی کارگاه
/// </summary>
public long WorkshopId { get; set; }
/// <summary>
/// شماره قرارداد
/// </summary>
public string ContractNo { get; set; }
/// <summary>
/// تاریخ شروع فیش
/// </summary>
public string ContractStart { get; set; }
/// <summary>
/// تاریخ پاین فیش
/// </summary>
public string ContractEnd { get; set; }
/// <summary>
/// ماه
/// </summary>
public string Month { get; set; }
/// <summary>
/// سال
/// </summary>
public string Year { get; set; }
/// <summary>
/// آی دی گارفرما
/// </summary>
public long EmployerId { get; set; }
}

View File

@@ -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<PagedResult<CheckoutListClientDto>> GetListForClient(long workshopId,
CheckoutListClientSearchModel searchModel);
#region ForApi
Task<PagedResult<CheckoutDto>> GetList(CheckoutSearchModelDto searchModel);
#endregion
}
public class CheckoutListClientSearchModel:PaginationRequest
@@ -98,4 +105,7 @@ public enum CheckoutClientListOrderType
ByPersonnelCodeDescending,
ByCheckoutStartDate,
ByCheckoutStartDateDescending
}

View File

@@ -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<PagedResult<CheckoutDto>> GetList(CheckoutSearchModelDto searchModel)
{
return await _checkoutRepository.GetList(searchModel);
}
#endregion
}

View File

@@ -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<long, Checkout>, ICheckoutRepos
}
#endregion
#region ForApi
public async Task<PagedResult<CheckoutDto>> 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<CheckoutDto>()
{
TotalCount = count,
List = result
};
}
#endregion
}

View File

@@ -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;
}
/// <summary>
/// دریافت لیست فیش حقوقی
/// </summary>
/// <param name="searchModel"></param>
/// <returns></returns>
[HttpGet("GetList")]
public async Task<ActionResult<PagedResult<CheckoutDto>>> GetList(CheckoutSearchModelDto searchModel)
{
return await _checkoutApplication.GetList(searchModel);
}
}