add recalculate values

This commit is contained in:
MahanCh
2025-04-30 14:55:38 +03:30
parent 4ec4935a1d
commit 9592960a40
21 changed files with 1628 additions and 540 deletions

View File

@@ -8,6 +8,7 @@ using _0_Framework.Application;
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
using Company.Domain.CheckoutAgg;
using Company.Domain.CustomizeCheckoutAgg;
using Company.Domain.CustomizeCheckoutTempAgg;
using Company.Domain.CustomizeWorkshopEmployeeSettingsAgg;
using Company.Domain.CustomizeWorkshopSettingsAgg;
using Company.Domain.EmployeeAgg;
@@ -24,7 +25,6 @@ namespace CompanyManagment.Application;
public class RollCallApplication : IRollCallApplication
{
private readonly IRollCallRepository _rollCallRepository;
private readonly IEmployeeApplication _employeeApplication;
private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository;
private readonly IEmployeeRepository _employeeRepository;
private readonly ILeaveRepository _leaveRepository;
@@ -33,11 +33,11 @@ public class RollCallApplication : IRollCallApplication
private readonly IRollCallDomainService _rollCallDomainService;
private readonly ICustomizeWorkshopSettingsRepository _customizeWorkshopSettingsRepository;
private readonly ICustomizeWorkshopEmployeeSettingsRepository _customizeWorkshopEmployeeSettingsRepository;
private readonly ICustomizeCheckoutTempRepository _customizeCheckoutTempRepository;
public RollCallApplication(IRollCallRepository rollCallRepository, IEmployeeApplication employeeApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository, ICustomizeCheckoutRepository customizeCheckoutRepository, ICheckoutRepository checkoutRepository, IRollCallDomainService rollCallDomainService, ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository)
public RollCallApplication(IRollCallRepository rollCallRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, IEmployeeRepository employeeRepository, ILeaveRepository leaveRepository, ICustomizeCheckoutRepository customizeCheckoutRepository, ICheckoutRepository checkoutRepository, IRollCallDomainService rollCallDomainService, ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, ICustomizeCheckoutTempRepository customizeCheckoutTempRepository)
{
_rollCallRepository = rollCallRepository;
_employeeApplication = employeeApplication;
_rollCallEmployeeRepository = rollCallEmployeeRepository;
_employeeRepository = employeeRepository;
_leaveRepository = leaveRepository;
@@ -46,7 +46,8 @@ public class RollCallApplication : IRollCallApplication
_rollCallDomainService = rollCallDomainService;
_customizeWorkshopSettingsRepository = customizeWorkshopSettingsRepository;
_customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository;
}
_customizeCheckoutTempRepository = customizeCheckoutTempRepository;
}
public OperationResult Create(CreateRollCall command)
{
@@ -55,7 +56,7 @@ public class RollCallApplication : IRollCallApplication
var yearFa = Convert.ToInt32(startDateFa.Substring(0, 4));
var monthFa = Convert.ToInt32(startDateFa.Substring(5, 2));
var employeeName = _employeeApplication.GetDetails(command.EmployeeId).EmployeeFullName;
var employeeName = _employeeRepository.GetDetails(command.EmployeeId).EmployeeFullName;
var create = new RollCall(command.WorkshopId, command.EmployeeId, employeeName, command.StartDate.Value, null,
yearFa, monthFa, _rollCallDomainService);
_rollCallRepository.Create(create);
@@ -772,4 +773,56 @@ public class RollCallApplication : IRollCallApplication
{
return _rollCallRepository.CheckRepeat(employeeId, workshopId);
}
public OperationResult RecalculateValues(long workshopId, List<ReCalculateRollCallValues> commands)
{
var operationResult = new OperationResult();
try
{
List<DateTime> fromDates = commands.Select(x => x.FromDate.ToGeorgianDateTime()).ToList();
var employeeIds = commands.Select(x => x.EmployeeId).ToList();
if (_checkoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart)))
{
return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش رسمی است");
}
if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart)))
{
return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی نهایی است");
}
if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == workshopId && employeeIds.Contains(x.EmployeeId) && fromDates.Any(a => a <= x.ContractStart)))
{
return operationResult.Failed("پرسنل بعد از تاریخ وارد شده دارای فیش غیررسمی موقت است");
}
var oldestDate = commands.MinBy(x => x.FromDate).FromDate.ToGeorgianDateTime();
var allRollCalls = _rollCallRepository
.GetRollCallsUntilNowWithWorkshopIdEmployeeIds(workshopId, commands.Select(x => x.EmployeeId).ToList(),
oldestDate).GetAwaiter().GetResult();
foreach (var command in commands)
{
var rollCalls = allRollCalls
.Where(x => x.EmployeeId == command.EmployeeId && x.ShiftDate >= command.FromDate.ToGeorgianDateTime()).ToList();
foreach (var rollCall in rollCalls)
{
rollCall.ClearTimeDiff();
_rollCallRepository.SaveChanges();
rollCall.SetEndDateTime(rollCall.EndDate!.Value, _rollCallDomainService);
}
}
return operationResult.Succcedded();
}
catch (Exception e)
{
return operationResult.Failed(e.Message);
}
}
}