add new metod

This commit is contained in:
SamSys
2025-06-17 17:09:16 +03:30
parent e379727606
commit 256717c6f8
5 changed files with 214 additions and 113 deletions

View File

@@ -5,6 +5,7 @@ using _0_Framework.Application;
using _0_Framework.Domain;
using CompanyManagment.App.Contracts.LeftWork;
using CompanyManagment.App.Contracts.PersonnleCode;
using CompanyManagment.App.Contracts.Workshop.DTOs;
namespace Company.Domain.LeftWorkAgg;
@@ -46,4 +47,11 @@ public interface ILeftWorkRepository : IRepository<long, LeftWork>
Task<LeftWork> GetLastLeftWork(long employeeId, long workshopId);
List<LeftWorkViewModel> SearchCreateContract(LeftWorkSearchModel searchModel);
/// <summary>
/// دریافت اطلاعات کارگاه و پرسنل برای ایجاد قرارداد
/// </summary>
/// <param name="workshopId"></param>
/// <returns></returns>
AutoExtensionDto AutoExtentionEmployees(long workshopId);
}

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using _0_Framework.Application;
using CompanyManagment.App.Contracts.PersonnleCode;
using CompanyManagment.App.Contracts.Workshop.DTOs;
using Microsoft.AspNetCore.Mvc;
namespace CompanyManagment.App.Contracts.LeftWork;
@@ -30,4 +31,10 @@ public interface ILeftWorkApplication
OperationResult CreateLeftWorkByLeftWorkGroups(string employeeFullName, long commandEmployeeId, List<PersonnelCodeViewModel> commandPersonnelCode, List<LeftWorkGroup> leftWorkGroups);
OperationResult CheckDeleteLeftWork(long workshopId, long employeeId, string date, int type);
OperationResult CheckEditLeftWork(long workshopId, long employeeId, string date, int type);
/// <summary>
/// دریافت اطلاعات کارگاه و پرسنل برای ایجاد قرارداد
/// </summary>
/// <param name="workshopId"></param>
/// <returns></returns>
AutoExtensionDto AutoExtentionEmployees(long workshopId);
}

View File

@@ -15,6 +15,7 @@ using CompanyManagment.App.Contracts.PersonnleCode;
using CompanyManagment.App.Contracts.RollCallEmployee;
using CompanyManagment.App.Contracts.WorkingHours;
using CompanyManagment.App.Contracts.WorkingHoursItems;
using CompanyManagment.App.Contracts.Workshop.DTOs;
using PersianTools.Core;
namespace CompanyManagment.Application;
@@ -600,6 +601,11 @@ public class LeftWorkApplication : ILeftWorkApplication
return _leftWorkRepository.CheckEditLeftWork(workshopId, employeeId, date.ToGeorgianDateTime(), type);
}
public AutoExtensionDto AutoExtentionEmployees(long workshopId)
{
return _leftWorkRepository.AutoExtentionEmployees(workshopId);
}
#region Pooya
//این متد ترک کار های کارمند را با فعالیت حضور غیاب یکپارچه می کند
private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId)

View File

@@ -98,7 +98,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
}).Where(x=>x.WorkshopId == workshopId);
}).Where(x => x.WorkshopId == workshopId);
return query.ToList();
}
@@ -372,7 +372,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
_context.LeftWorkList.RemoveRange(LeftWork);
DateTime left = item2.LeftWorkDate.ToGeorgianDateTime();
var start = item2.StartWorkDate.ToGeorgianDateTime();
var leftwork = new LeftWork(left, start, item2.WorkshopId, item2.EmployeeId, command.EmployeeFullName, item2.WorkshopName, item2.JobId, item2.IncludeStatus,item2.AddBonusesPay,item2.AddYearsPay,item2.AddLeavePay, workshopComputeOptions, workshopBonusesOptions);
var leftwork = new LeftWork(left, start, item2.WorkshopId, item2.EmployeeId, command.EmployeeFullName, item2.WorkshopName, item2.JobId, item2.IncludeStatus, item2.AddBonusesPay, item2.AddYearsPay, item2.AddLeavePay, workshopComputeOptions, workshopBonusesOptions);
Create(leftwork);
}
}
@@ -404,7 +404,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
if (commandPersonnelCode != null && commandPersonnelCode.Count > 0)
{
var personelcode = commandPersonnelCode.Where(x => x.EmployeeId == commandEmployeeId && x.WorkshopId == item.WorkshopId).FirstOrDefault();
if (personelcode != null && personelcode.HasPersonelCode==false)
if (personelcode != null && personelcode.HasPersonelCode == false)
{
if (_context.PersonnelCodeSet.Any(x => x.WorkshopId == item.WorkshopId && x.PersonnelCode == personelcode.PersonnelCode))
{
@@ -500,8 +500,8 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
var op = new OperationResult();
bool hasContracts = false;
var endDateSend = date.Date.AddDays(-1);
if (type==1)
hasContracts= _context.CheckoutSet.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && (x.ContractStart.Date >= endDateSend) && x.IsActiveString == "true");
if (type == 1)
hasContracts = _context.CheckoutSet.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && (x.ContractStart.Date >= endDateSend) && x.IsActiveString == "true");
else
{
endDateSend = date.Date;
@@ -529,8 +529,8 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
if (type == 1)
{
hasContracts= _context.CheckoutSet.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && (x.ContractStart.Date>= date) && x.IsActiveString == "true");
if(hasContracts)
hasContracts = _context.CheckoutSet.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && (x.ContractStart.Date >= date) && x.IsActiveString == "true");
if (hasContracts)
return op.Failed("لطفا ابتدا تصفیه حساب های آتی را حذف نمایید");
}
@@ -556,7 +556,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
var LastDayContract = _context.CheckoutSet.Any(x =>
x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.IsActiveString == "true" &&
x.ContractEnd.Date > lastDay.Date);
if(LastDayContract)
if (LastDayContract)
return op.Failed("AfterContracts");
// var contract = _context.Contracts.Where(x => x.EmployeeId == employeeId && x.WorkshopIds == workshopId && x.IsActiveString == "true").OrderByDescending(x=>x.ContarctStart).FirstOrDefault();
@@ -647,7 +647,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
public async Task<LeftWork> GetLastLeftWork(long employeeId, long workshopId)
{
var leftWork =await _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId)
var leftWork = await _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId)
.OrderByDescending(x => x.StartWorkDate).FirstOrDefaultAsync();
return leftWork;
}
@@ -678,7 +678,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
JobName = _context.Jobs.FirstOrDefault(j => j.id == x.JobId).JobName
}).Where(x=> !vipGroup.Contains(x.EmployeeId) && !clientTemps.Contains(x.EmployeeId));
}).Where(x => !vipGroup.Contains(x.EmployeeId) && !clientTemps.Contains(x.EmployeeId));
if (searchModel.WorkshopId != 0 && searchModel.EmployeeId != 0)
query = query.Where(x => x.WorkshopId == searchModel.WorkshopId && x.EmployeeId == searchModel.EmployeeId);
if (searchModel.EmployeeId != 0 && searchModel.WorkshopId == 0)
@@ -698,7 +698,7 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
}
private void RemoveEmployeeRollCallStatus(long workshopId, long employeeId)
{
var entity = _context.RollCallEmployees.Include(x=>x.EmployeesStatus).FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId);
var entity = _context.RollCallEmployees.Include(x => x.EmployeesStatus).FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId);
if (entity == null)
return;
@@ -738,44 +738,112 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
{
if (workshopId == 0)
return new AutoExtensionDto();
var query = _context.LeftWorkList.Include(x => x.Employee).Include(w=>w.Workshop)
var query = _context.LeftWorkList
.Include(x => x.Employee)
.Include(x => x.Workshop)
.Where(x => x.WorkshopId == workshopId)
.Join(_context.PersonnelCodeSet.AsSplitQuery().Where(p => p.WorkshopId == workshopId),
// Left Join با PersonnelCodeSet
.GroupJoin(_context.PersonnelCodeSet.Where(p => p.WorkshopId == workshopId),
leftList => leftList.EmployeeId,
personnelCode => personnelCode.EmployeeId,
(leftList, personnelCode) =>
new { leftList, personnelCode })
.Join(_context.Jobs,
left => left.leftList.JobId,
(leftList, personnelCodes) => new { leftList, personnelCodes })
.SelectMany(
x => x.personnelCodes.DefaultIfEmpty(),
(x, personnelCode) => new { x.leftList, personnelCode })
// Left Join با Jobs
.GroupJoin(_context.Jobs,
x => x.leftList.JobId,
job => job.id,
(left, job) => new { left, job })
.Join(_context.EmployeeComputeOptionsSet.Where(o=>o.WorkshopId == workshopId),
leftResult => leftResult.left.leftList.EmployeeId,
options => options.EmployeeId,
(leftResult, options) => new { leftResult, options })
.Select(result => new AutoExtensionEmployeeListDto()
(x, jobs) => new { x.leftList, x.personnelCode, jobs })
.SelectMany(
x => x.jobs.DefaultIfEmpty(),
(x, job) => new { x.leftList, x.personnelCode, job })
// Left Join با EmployeeComputeOptionsSet
.GroupJoin(_context.EmployeeComputeOptionsSet.Where(o => o.WorkshopId == workshopId),
x => x.leftList.EmployeeId,
option => option.EmployeeId,
(x, options) => new { x.leftList, x.personnelCode, x.job, options })
.SelectMany(
x => x.options.DefaultIfEmpty(),
(x, option) => new { x.leftList, x.personnelCode, x.job, option })
.Select(result => new AutoExtensionEmployeeListDto
{
EmployeeId = result.leftList.EmployeeId,
EmployeeName = result.leftList.EmployeeFullName,
PersonnelCode = result.personnelCode != null ? result.personnelCode.PersonnelCode : 0,
JobType = result.job != null ? result.job.JobName : "نامشخص",
JobTypeId = result.job != null ? result.job.id : 0,
EmployeeHasCreateContract = result.option != null
? result.option.CreateContract
: result.leftList.Workshop.CreateContract
}).GroupBy(x => x.EmployeeId)
.Select(g => g.First())
.ToList();
EmployeeId = result.leftResult.left.leftList.EmployeeId,
EmployeeName = result.leftResult.left.leftList.EmployeeFullName,
PersonnelCode = result.leftResult.left.personnelCode == null ? 0 : result.leftResult.left.personnelCode.PersonnelCode,
JobType = result.leftResult.job.JobName,
JobTypeId = result.leftResult.job.id,
EmployeeHasCreateContract = result.options == null ? result.leftResult.left.leftList.Workshop.CreateContract : result.options.CreateContract
//var query = _context.LeftWorkList.Include(x => x.Employee).Include(w => w.Workshop)
// .Where(x => x.WorkshopId == workshopId)
// .Join(_context.PersonnelCodeSet.AsSplitQuery().Where(p => p.WorkshopId == workshopId),
// leftList => leftList.EmployeeId,
// personnelCode => personnelCode.EmployeeId,
// (leftList, personnelCode) =>
// new { leftList, personnelCode })
// .Join(_context.Jobs,
// left => left.leftList.JobId,
// job => job.id,
// (left, job) => new { left, job })
// .Join(_context.EmployeeComputeOptionsSet.Where(o => o.WorkshopId == workshopId),
// leftResult => leftResult.left.leftList.EmployeeId,
// options => options.EmployeeId,
// (leftResult, options) => new { leftResult, options })
// .Select(result => new AutoExtensionEmployeeListDto()
// {
}).ToList();
// EmployeeId = result.leftResult.left.leftList.EmployeeId,
// EmployeeName = result.leftResult.left.leftList.EmployeeFullName,
// PersonnelCode = result.leftResult.left.personnelCode == null ? 0 : result.leftResult.left.personnelCode.PersonnelCode,
// JobType = result.leftResult.job.JobName,
// JobTypeId = result.leftResult.job.id,
// EmployeeHasCreateContract = result.options == null ? result.leftResult.left.leftList.Workshop.CreateContract : result.options.CreateContract
// }).ToList();
var result = new AutoExtensionDto();
var workshop = _context.Workshops.FirstOrDefault(x => x.id == workshopId);
var employerId = _context.WorkshopEmployers.FirstOrDefault(x => x.WorkshopId == workshopId)!.EmployerId;
if (query.Count > 0 && workshop != null)
var employer = _context.Employers.FirstOrDefault(x => x.id == employerId);
var employerWarning = false;
var employerWarningMessage = "";
if (employer != null && employer.IsLegal == "حقوقی")
{
if (string.IsNullOrWhiteSpace(employer.NationalId) || string.IsNullOrWhiteSpace(employer.RegisterId))
{
employerWarning = true;
employerWarningMessage = "شناسه ملی ، شماره ثبت کارفرمای این کارگاه را بررسی کنید";
}
}
else
{
if (string.IsNullOrWhiteSpace(employer.Nationalcode) || string.IsNullOrWhiteSpace(employer.Gender))
{
employerWarning = true;
employerWarningMessage = "کد ملی ، جنسیت کارفرمای این کارگاه را بررسی گنید";
}
}
if (query.Any() && workshop != null)
{
var result = new AutoExtensionDto()
result = new AutoExtensionDto()
{
WorkshopId = workshopId,
HavingPersonel = true,
@@ -783,7 +851,10 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
ArchiveCode = workshop.ArchiveCode,
WAddress1 = workshop.Address,
CreateContract = workshop.CreateContract,
EmployeeList = query.Select(x=> new AutoExtensionEmployeeListDto()
EmployerId = employerId,
EmployerWarning = employerWarning,
EmployerWarningMessage = employerWarningMessage,
EmployeeList = query.Select(x => new AutoExtensionEmployeeListDto()
{
EmployeeId = x.EmployeeId,
EmployeeName = x.EmployeeName,
@@ -793,14 +864,14 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
EmployeeHasCreateContract = x.EmployeeHasCreateContract
}).ToList(),
EmployeeSelectList = new SelectList(query.Where(x=>x.EmployeeHasCreateContract), "EmployeeId", "EmployeeName ")
EmployeeSelectList = new SelectList(query.Where(x => x.EmployeeHasCreateContract), "EmployeeId", "EmployeeName ")
};
}
else
{
var result = new AutoExtensionDto()
result = new AutoExtensionDto()
{
WorkshopId = workshopId,
HavingPersonel = false,

View File

@@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using _0_Framework.Application;
using Company.Domain.ContractAgg;
@@ -82,6 +83,8 @@ public class AutoExtensionModel : PageModel
public void OnGet(long id)
{
var watch = new Stopwatch();
watch.Start();
var selctedWorkshop = _workshopApplication.GetDetails(id);
workshopName = selctedWorkshop?.WorkshopFullName;
YearlyList =
@@ -159,6 +162,12 @@ public class AutoExtensionModel : PageModel
WorkshopAddress1 = selctedWorkshop.Address
}).OrderBy(x => x.PersonnelCode).ToList();
EmployeeSelectList = new SelectList(personelList, "EmployeeId", "EmployeeFullName");
Console.WriteLine(" old : " + watch.Elapsed);
watch.Reset();
watch.Start();
var res = _leftWorkApplication.AutoExtentionEmployees(id);
Console.WriteLine(" new : " + watch.Elapsed);
}
else
{