165 lines
5.8 KiB
C#
165 lines
5.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.EmployeeComputeOptionsAgg;
|
|
using CompanyManagment.App.Contracts.Checkout;
|
|
using CompanyManagment.App.Contracts.EmployeeComputeOptions;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class EmployeeComputeOptionsRepository : RepositoryBase<long, EmployeeComputeOptions>, IEmployeeComputeOptionsRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public EmployeeComputeOptionsRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public EmployeeComputeOptionsViewModel GetEmployeeOptions(long workshopId, long employeeId)
|
|
{
|
|
var result = new EmployeeComputeOptionsViewModel();
|
|
result = _context.EmployeeComputeOptionsSet.Select(x => new EmployeeComputeOptionsViewModel
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
ComputeOptions = x.ComputeOptions,
|
|
YearsOptions = x.YearsOptions,
|
|
BonusesOptions = x.BonusesOptions,
|
|
SignCheckout = x.SignCheckout,
|
|
CreateCheckout = x.CreateCheckout,
|
|
CreateContract = x.CreateContract,
|
|
SignContract = x.SignContract,
|
|
|
|
}).FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId);
|
|
|
|
if (result == null)
|
|
{
|
|
var getFromWorkshop = _context.Workshops.FirstOrDefault(x => x.id == workshopId);
|
|
if (getFromWorkshop != null)
|
|
{
|
|
var fromWorkshop = new EmployeeComputeOptionsViewModel()
|
|
{
|
|
EmployeeId = employeeId,
|
|
WorkshopId = workshopId,
|
|
ComputeOptions = getFromWorkshop.ComputeOptions,
|
|
YearsOptions = getFromWorkshop.YearsOptions,
|
|
BonusesOptions= getFromWorkshop.BonusesOptions,
|
|
CreateCheckout = getFromWorkshop.CreateCheckout,
|
|
CreateContract = getFromWorkshop.CreateContract,
|
|
SignCheckout = getFromWorkshop.SignCheckout,
|
|
SignContract = getFromWorkshop.SignContract
|
|
};
|
|
|
|
result = fromWorkshop;
|
|
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<EmployeeComputeOptionsViewModel> GetAllByWorkshopId(long workshopId)
|
|
{
|
|
|
|
|
|
|
|
return _context.EmployeeComputeOptionsSet.Select(x => new EmployeeComputeOptionsViewModel
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
ComputeOptions = x.ComputeOptions,
|
|
YearsOptions = x.YearsOptions,
|
|
BonusesOptions = x.BonusesOptions,
|
|
|
|
}).Where(x => x.WorkshopId == workshopId).ToList();
|
|
}
|
|
|
|
public List<WorkshopViewModel> TestBonusesBugWorkshops()
|
|
{
|
|
var beforDate = new DateTime(2025, 04, 10, 16, 15, 0);
|
|
var options = _context.Workshops.Where(x => x.BonusesOptions == "OnEndOfYear")
|
|
.Join(
|
|
_context.CheckoutSet.Where(c =>
|
|
c.BaseYearsPay > 0 && c.Year == "1403" && c.Month == "اسفند" && c.BonusesPay > 0 && c.CreationDate < beforDate),
|
|
option => option.id,
|
|
checkout => checkout.WorkshopId, (option, checkout) => new { option, checkout }).Select(ch =>
|
|
new CheckoutViewModel()
|
|
{
|
|
Id = ch.checkout.id,
|
|
EmployeeId = ch.checkout.EmployeeId,
|
|
WorkshopId = ch.checkout.WorkshopId,
|
|
WorkshopName = ch.checkout.WorkshopName,
|
|
EmployeeFullName = ch.checkout.EmployeeFullName,
|
|
|
|
Year = ch.checkout.Year,
|
|
Month = ch.checkout.Month,
|
|
|
|
MonthlySalary = ch.checkout.MonthlySalary.ToMoney(),
|
|
BaseYearsPay = ch.checkout.BaseYearsPay.ToMoney(),
|
|
BonusesPay = ch.checkout.BonusesPay.ToMoney(),
|
|
Signature = ch.checkout.Signature,
|
|
|
|
});
|
|
var workshopIds = options.GroupBy(x => x.WorkshopId).Select(x => x.Key);
|
|
|
|
|
|
var res = _context.Workshops.Where(x => workshopIds.Contains(x.id)).Select(x => new WorkshopViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopFullName = x.WorkshopFullName,
|
|
IsActiveString = "",
|
|
//foreach (var item in workshops)
|
|
//{
|
|
|
|
// Console.WriteLine(" workshopId : " + item.id + " workshopName : " + item.WorkshopFullName);
|
|
//}
|
|
//Console.WriteLine(" Count All : " + workshopIds.Count());
|
|
//Console.WriteLine(" Count Signed : " + options.Count(x => x.Signature == "1"));
|
|
//Console.WriteLine(" Count NotSigned: " + options.Count(x => x.Signature == "0"));
|
|
}).ToList();
|
|
var result = res.Select(n =>
|
|
{
|
|
var idList = options.Where(o => o.WorkshopId == n.Id).Select(o => o.Id).ToList();
|
|
var checkoutIds = GetCheckoutIds(idList);
|
|
return new WorkshopViewModel()
|
|
{
|
|
Id = n.Id,
|
|
WorkshopFullName = n.WorkshopFullName,
|
|
IsActiveString = checkoutIds,
|
|
|
|
};
|
|
|
|
|
|
}).OrderBy(n=>n.Id).ToList();
|
|
return result;
|
|
}
|
|
private string GetCheckoutIds(List<long> ids)
|
|
{
|
|
string idList = "";
|
|
int counter = 1;
|
|
foreach (var item in ids)
|
|
{
|
|
if (counter == 1)
|
|
{
|
|
idList = $"{item}";
|
|
}
|
|
else
|
|
{
|
|
idList = $"{idList}+{item}";
|
|
}
|
|
|
|
counter++;
|
|
|
|
}
|
|
return idList;
|
|
}
|
|
}
|
|
|
|
|