337 lines
18 KiB
C#
337 lines
18 KiB
C#
using _0_Framework.Application;
|
|
using Company.Domain.ContractAgg;
|
|
using Company.Domain.CustomizeCheckoutAgg.ValueObjects;
|
|
using Company.Domain.CustomizeCheckoutTempAgg;
|
|
using Company.Domain.CustomizeWorkshopSettingsAgg;
|
|
using Company.Domain.EmployeeAgg;
|
|
using Company.Domain.LeftWorkAgg;
|
|
using Company.Domain.RollCallAgg;
|
|
using Company.Domain.RollCallEmployeeStatusAgg;
|
|
using Company.Domain.WorkshopAgg;
|
|
using CompanyManagment.App.Contracts.CustomizeCheckout;
|
|
using CompanyManagment.App.Contracts.LeftWork;
|
|
using CompanyManagment.App.Contracts.RollCallEmployeeStatus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using Company.Domain.CustomizeCheckoutTempAgg.ValueObjects;
|
|
using Company.Domain.PersonnelCodeAgg;
|
|
using CompanyManagment.App.Contracts.PersonnleCode;
|
|
using _0_Framework.Domain.CustomizeCheckoutShared.ValueObjects;
|
|
using Company.Domain.CustomizeWorkshopGroupSettingsAgg;
|
|
|
|
namespace CompanyManagment.Application
|
|
{
|
|
public class CustomizeCheckoutTempApplication : ICustomizeCheckoutTempApplication
|
|
{
|
|
private readonly ICustomizeCheckoutTempRepository _customizeCheckoutTempRepository;
|
|
private readonly IEmployeeRepository _employeeRepository;
|
|
private readonly ILeftWorkRepository _leftWorkRepository;
|
|
private readonly IWorkshopRepository _workshopRepository;
|
|
private readonly IRollCallMandatoryRepository _rollCallMandatoryRepository;
|
|
private readonly IRollCallEmployeeStatusRepository _rollCallEmployeeStatusRepository;
|
|
private readonly IContractRepository _contractRepository;
|
|
private readonly IPersonnelCodeRepository _personnelCodeRepository;
|
|
private readonly ICustomizeWorkshopSettingsRepository _customizeWorkshopSettingsRepository;
|
|
private readonly ICustomizeWorkshopGroupSettingsRepository _customizeWorkshopGroupSettingsRepository;
|
|
|
|
|
|
public CustomizeCheckoutTempApplication(IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, ILeftWorkRepository leftWorkRepository, IEmployeeRepository employeeRepository, IRollCallMandatoryRepository rollCallMandatoryRepository, IContractRepository contractRepository, ICustomizeCheckoutTempRepository customizeCheckoutTempRepository, IWorkshopRepository workshopRepository, ICustomizeWorkshopSettingsRepository customizeWorkshopSettingsRepository, IPersonnelCodeRepository personnelCodeRepository, ICustomizeWorkshopGroupSettingsRepository customizeWorkshopGroupSettingsRepository)
|
|
{
|
|
_rollCallEmployeeStatusRepository = rollCallEmployeeStatusRepository;
|
|
_leftWorkRepository = leftWorkRepository;
|
|
_employeeRepository = employeeRepository;
|
|
_rollCallMandatoryRepository = rollCallMandatoryRepository;
|
|
_contractRepository = contractRepository;
|
|
_customizeCheckoutTempRepository = customizeCheckoutTempRepository;
|
|
_workshopRepository = workshopRepository;
|
|
_customizeWorkshopSettingsRepository = customizeWorkshopSettingsRepository;
|
|
_personnelCodeRepository = personnelCodeRepository;
|
|
_customizeWorkshopGroupSettingsRepository = customizeWorkshopGroupSettingsRepository;
|
|
}
|
|
|
|
public IEnumerable<CustomizeCheckoutViewModel> Search(SearchCustomizeCheckout searchModel)
|
|
{
|
|
return _customizeCheckoutTempRepository.Search(searchModel);
|
|
}
|
|
|
|
public OperationResult Create(CreateCustomizeCheckoutTemp command)
|
|
{
|
|
OperationResult op = new();
|
|
var contract = _contractRepository.GetByWorkshopIdEmployeeIdInDates(command.WorkshopId, command.EmployeeId, command.ContractStart, command.ContractEnd);
|
|
|
|
Employee employee = _employeeRepository.Get(command.EmployeeId);
|
|
|
|
var workshop = _workshopRepository.Get(command.WorkshopId);
|
|
//get sumOfWorkingDays
|
|
var result = _rollCallMandatoryRepository.CustomizeCheckoutMandatoryCompute(command.EmployeeId, command.WorkshopId, command.ContractStart, command.ContractEnd);
|
|
|
|
var fines = result.FineViewModels
|
|
.Select(x =>
|
|
new CustomizeCheckoutTempFine(
|
|
x.Title,
|
|
x.Amount,
|
|
x.FineDate,
|
|
x.FineDate.ToGeorgianDateTime(),
|
|
x.IsActive, x.CreationDate.ToGeorgianDateTime(), x.Id)
|
|
).ToList();
|
|
|
|
var rewards = result.RewardViewModels.Select(x =>
|
|
new CustomizeCheckoutTempReward(x.Amount, x.Description, x.GrantDateGr, x.GrantDateFa,
|
|
x.IsActive, x.Title, x.Id)).ToList();
|
|
|
|
var loanInstallments = result.InstallmentViewModels.Select(x =>
|
|
new CustomizeCheckoutTempLoanInstallments(x.Amount, x.Month, x.Year, x.IsActive, x.RemainingAmount, x.LoanAmount, x.Id)).ToList();
|
|
|
|
var salaryAids = result.SalaryAidViewModels.Select(x =>
|
|
new CustomizeCheckoutTempSalaryAid(x.Amount, x.SalaryAidDateTimeGe, x.SalaryAidDateTimeFa, x.CalculationDateTimeGe, x.CalculationDateTimeFa, x.Id)).ToList();
|
|
|
|
var regularShift = result.EmployeeSettingsShifts.Select(x =>
|
|
new CustomizeCheckoutRegularShift(x.StartTime, x.EndTime, x.Placement)).ToList();
|
|
|
|
var entity = new CustomizeCheckoutTemp(command.ContractStart, command.ContractEnd, command.EmployeeId, employee.FName, employee.LName, employee.DateOfBirth, employee.NationalCode,
|
|
workshop.WorkshopFullName, command.WorkshopId, contract?.Id,
|
|
result.MonthlySalary, result.FridayPay, result.OverTimePay, result.BaseYearsPay,
|
|
result.BonusesPay, result.NightWorkPay, result.MarriedAllowance, result.ShiftPay,
|
|
result.FamilyAllowance, result.LeavePay, result.InsuranceDeduction, result.FineAbsenceDeduction,
|
|
result.LateToWorkDeduction, result.EarlyExitDeduction, result.RewardPay, result.SalaryAidDeduction, result.InstallmentDeduction, result.FineDeduction,
|
|
result.TaxDeduction, result.SumOfWorkingDays, result.TotalClaimsStr, result.TotalDeductionsStr, result.TotalPayment, contract?.ContractNo ?? "-",
|
|
fines, loanInstallments, salaryAids, rewards, result.LateToWorkValue, result.SettingSalary, result.DailyWage, result.ShiftStatus, result.IrregularShift, result.CustomizeRotatingShifts,
|
|
regularShift,result.DynamicDeductions);
|
|
|
|
|
|
_customizeCheckoutTempRepository.Create(entity);
|
|
_customizeCheckoutTempRepository.RemoveEmployeeTemporaryCheckoutInDates(command.WorkshopId, employee.id, command.ContractStart, command.ContractEnd);
|
|
_customizeCheckoutTempRepository.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
|
|
public OperationResult GroupCreate(CreateCustomizeCheckoutTempGroup command)
|
|
{
|
|
OperationResult op = new();
|
|
var contracts = _contractRepository
|
|
.GetByWorkshopIdInDates(command.WorkshopId, command.ContractStart, command.ContractEnd);
|
|
var employees = _employeeRepository.GetRangeByIds(command.EmployeeIds);
|
|
var workshop = _workshopRepository.Get(command.WorkshopId);
|
|
|
|
foreach (var employeeId in command.EmployeeIds)
|
|
{
|
|
var computations = _rollCallMandatoryRepository
|
|
.CustomizeCheckoutMandatoryCompute(employeeId, command.WorkshopId, command.ContractStart, command.ContractEnd);
|
|
|
|
var fines = computations.FineViewModels
|
|
.Select(x =>
|
|
new CustomizeCheckoutTempFine(
|
|
x.Title,
|
|
x.Amount,
|
|
x.FineDate,
|
|
x.FineDate.ToGeorgianDateTime(),
|
|
x.IsActive, x.CreationDate.ToGeorgianDateTime(), x.Id)
|
|
).ToList();
|
|
|
|
var rewards = computations.RewardViewModels.Select(x =>
|
|
new CustomizeCheckoutTempReward(x.Amount, x.Description, x.GrantDateGr, x.GrantDateFa,
|
|
x.IsActive, x.Title, x.Id)).ToList();
|
|
|
|
var loanInstallments = computations.InstallmentViewModels.Select(x =>
|
|
new CustomizeCheckoutTempLoanInstallments(x.Amount, x.Month, x.Year, x.IsActive, x.RemainingAmount, x.LoanAmount, x.Id)).ToList();
|
|
|
|
var salaryAids = computations.SalaryAidViewModels.Select(x =>
|
|
new CustomizeCheckoutTempSalaryAid(x.Amount, x.SalaryAidDateTimeGe, x.SalaryAidDateTimeFa, x.CalculationDateTimeGe, x.CalculationDateTimeFa, x.Id)).ToList();
|
|
|
|
var contract = contracts.Where(x => x.IsActiveString == "true").FirstOrDefault(x => x.EmployeeId == employeeId);
|
|
|
|
var employee = employees.FirstOrDefault(x => x.id == employeeId);
|
|
|
|
var regularShift = computations.EmployeeSettingsShifts.Select(x =>
|
|
new CustomizeCheckoutRegularShift(x.StartTime, x.EndTime, x.Placement)).ToList();
|
|
|
|
|
|
var entity = new CustomizeCheckoutTemp(command.ContractStart, command.ContractEnd, employeeId, employee.FName, employee.LName, employee.DateOfBirth, employee.NationalCode,
|
|
workshop.WorkshopFullName, command.WorkshopId, contract?.Id,
|
|
computations.MonthlySalary, computations.FridayPay, computations.OverTimePay, computations.BaseYearsPay,
|
|
computations.BonusesPay, computations.NightWorkPay, computations.MarriedAllowance, computations.ShiftPay,
|
|
computations.FamilyAllowance, computations.LeavePay, computations.InsuranceDeduction, computations.FineAbsenceDeduction,
|
|
computations.LateToWorkDeduction, computations.EarlyExitDeduction, computations.RewardPay, computations.SalaryAidDeduction, computations.InstallmentDeduction, computations.FineDeduction,
|
|
computations.TaxDeduction, computations.SumOfWorkingDays, computations.TotalClaimsStr, computations.TotalDeductionsStr, computations.TotalPayment, contract?.ContractNo ?? "-",
|
|
fines, loanInstallments, salaryAids, rewards, computations.LateToWorkValue, computations.SettingSalary, computations.DailyWage, computations.ShiftStatus, computations.IrregularShift,
|
|
computations.CustomizeRotatingShifts, regularShift,computations.DynamicDeductions);
|
|
_customizeCheckoutTempRepository.Create(entity);
|
|
_customizeCheckoutTempRepository.RemoveEmployeeTemporaryCheckoutInDates(command.WorkshopId, employeeId, command.ContractStart, command.ContractEnd);
|
|
}
|
|
|
|
_customizeCheckoutTempRepository.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
public OperationResult GroupRemove(long workshopId, List<long> idList)
|
|
{
|
|
OperationResult op = new();
|
|
var entities = _customizeCheckoutTempRepository.GetRange(workshopId,idList);
|
|
if (entities == null)
|
|
return op.Succcedded();
|
|
_customizeCheckoutTempRepository.RemoveRange(entities);
|
|
_customizeCheckoutTempRepository.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
public List<CustomizeCheckoutViewModel> PrintAll(long workshopId, List<long> checkoutIds)
|
|
{
|
|
if (checkoutIds == null || checkoutIds.Count == 0)
|
|
return new();
|
|
//var allCheckouts = Search(new SearchCustomizeCheckout()
|
|
//{
|
|
// WorkshopId = workshopId,
|
|
// Year = yearFa,
|
|
// Month = monthFa
|
|
//});
|
|
//if (checkoutIds.Any(x => !allCheckouts.Any(y => y.Id == x)))
|
|
//{
|
|
// return new();
|
|
//}
|
|
return _customizeCheckoutTempRepository.PrintAll(workshopId, checkoutIds);
|
|
|
|
}
|
|
public OperationResult<List<EligibleEmployeesForCustomizeCheckoutViewModel>> GetWorkshopEmployeesEligibleForCheckoutInDates(long workshopId)
|
|
{
|
|
|
|
OperationResult<List<EligibleEmployeesForCustomizeCheckoutViewModel>> op = new();
|
|
var today = DateTime.Today;
|
|
var pc = new PersianCalendar();
|
|
|
|
int currentMonthDay = pc.GetDayOfMonth(today);
|
|
|
|
|
|
if (currentMonthDay == 1)
|
|
return op.Failed("صدور فیش حقوقی موقت در یکم ماه امکان پذیر نمی باشد");
|
|
|
|
|
|
var start = today.AddMonthsFa(0, out _).ToGeorgianDateTime().Date;
|
|
var end = today.AddDays(-1).Date;
|
|
|
|
var workshopLeftWorksInMonth = _leftWorkRepository.GetByWorkshopIdInDates(workshopId, start, end)
|
|
.Select(x => new LeftWorkViewModel
|
|
{
|
|
WorkshopId = workshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
LeftWorkDateGr = x.LeftWorkDateGr.AddDays(-1).Date > end ? end : x.LeftWorkDateGr.AddDays(-1).Date,
|
|
StartWorkDateGr = x.StartWorkDateGr.Date < start ? start : x.StartWorkDateGr.Date
|
|
}).ToList();
|
|
|
|
|
|
var statuses = _rollCallEmployeeStatusRepository.GetByWorkshopIdInDates(workshopId, start, end)
|
|
.Select(x => new RollCallEmployeeStatusViewModel
|
|
{
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeName = x.EmployeeName,
|
|
Id = x.Id,
|
|
EndDate = x.EndDate,
|
|
StartDate = x.StartDate,
|
|
EndDateGr = x.EndDateGr > end ? end : x.EndDateGr.Date,
|
|
StartDateGr = x.StartDateGr < start ? start : x.StartDateGr.Date
|
|
});
|
|
|
|
var personnelCodes = _personnelCodeRepository.Search(new PersonnelCodeSearchModel()
|
|
{
|
|
WorkshopId = workshopId
|
|
});
|
|
|
|
var workshopGroups = _customizeWorkshopSettingsRepository.GetWorkshopIncludeGroupsByWorkshopId(workshopId)
|
|
.GroupSettings.Where(x => x.MainGroup == false);
|
|
var employeeSettings = _customizeWorkshopSettingsRepository.GetEmployeeSettingsByWorkshopId(workshopId);
|
|
|
|
|
|
var statusesWithActiveLeftWorks = statuses
|
|
.Where(status => workshopLeftWorksInMonth.Any(leftWork => leftWork.EmployeeId == status.EmployeeId &&
|
|
leftWork.StartWorkDateGr.Date <= status.StartDateGr.Date &&
|
|
leftWork.LeftWorkDateGr.Date >= status.EndDateGr.Date)).ToList();
|
|
|
|
|
|
#region CustomForKebabMahdi
|
|
|
|
if (workshopId == 170)
|
|
{
|
|
var exceptionEmployeeIds = _customizeWorkshopGroupSettingsRepository
|
|
.GetEmployeeSettingsByGroupSettingsId(117)
|
|
.Select(x => x.EmployeeId)
|
|
.Where(x=> workshopLeftWorksInMonth.Select(l=>l.EmployeeId).Contains(x)).ToList();
|
|
foreach (var employeesId in exceptionEmployeeIds)
|
|
{
|
|
|
|
var status = new RollCallEmployeeStatusViewModel()
|
|
{
|
|
EmployeeId = employeesId,
|
|
};
|
|
statusesWithActiveLeftWorks.Add(status);
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
if (!statusesWithActiveLeftWorks.Any())
|
|
return op.Failed("امکان ایجاد فیش برای تاریخ انتخاب شده وجود ندارد");
|
|
|
|
|
|
var employeesWithoutGroup = statusesWithActiveLeftWorks
|
|
.Where(x => employeeSettings
|
|
.All(y => y.EmployeeId != x.EmployeeId || y.GroupSettingsId == 0 ||
|
|
workshopGroups.All(z => y.GroupSettingsId != z.Id)))
|
|
.Select(x => x.EmployeeId).ToList();
|
|
|
|
|
|
//var eligibleEmployees = statusesWithActiveLeftWorks
|
|
// .Where(x => !employeesWithoutGroup.Contains(x.EmployeeId));
|
|
|
|
|
|
//var employeesWithoutGroup = employeeSettings.Where(x => statusesWithActiveLeftWorks.Any(y => y.EmployeeId == x.EmployeeId)
|
|
//&& (x.GroupSettingsId == 0 || !workshopGroups.Any(y => x.GroupSettingsId == y.Id))).Select(x => x.EmployeeId).ToList();
|
|
var eligibleEmployees = statusesWithActiveLeftWorks.Where(x => !employeesWithoutGroup.Contains(x.EmployeeId)).ToList();
|
|
|
|
|
|
|
|
var employeesWithoutSalary = employeeSettings.Where(x => statusesWithActiveLeftWorks
|
|
.Any(y => y.EmployeeId == x.EmployeeId) && x.Salary <= 0).ToList();
|
|
eligibleEmployees = eligibleEmployees.Where(x => employeesWithoutSalary
|
|
.All(y => y.EmployeeId != x.EmployeeId)).ToList();
|
|
|
|
|
|
|
|
var employees = _employeeRepository.SimpleGetRangeByIds(statusesWithActiveLeftWorks
|
|
.Select(x => x.EmployeeId))
|
|
.Select(x =>
|
|
{
|
|
bool isEligible = eligibleEmployees.Any(y => x.Id == y.EmployeeId);
|
|
string reason = "";
|
|
string color = "";
|
|
if (isEligible == false)
|
|
{
|
|
reason = employeesWithoutGroup.Any(y => y == x.Id) ? "فاقد گروهبندی" :
|
|
employeesWithoutSalary.Any(y => y.EmployeeId == x.Id) ? "فاقد تعیین حقوق" : "خطای سیستمی";
|
|
}
|
|
color = reason switch
|
|
{
|
|
"فاقد تعیین حقوق" => "orange",
|
|
|
|
"فاقد گروهبندی" => "red",
|
|
|
|
"خطای سیستمی" => "black",
|
|
|
|
_ => "white"
|
|
};
|
|
|
|
return new EligibleEmployeesForCustomizeCheckoutViewModel()
|
|
{
|
|
Id = x.Id,
|
|
Name = x.Name,
|
|
IsEligible = isEligible,
|
|
Reason = reason,
|
|
Color = color,
|
|
PersonnelCode = personnelCodes.FirstOrDefault(y => x.Id == y.EmployeeId)?.PersonnelCode.ToString() ?? "-"
|
|
};
|
|
}).OrderByDescending(x => x.IsEligible).ThenByDescending(x => x.Reason).ToList();
|
|
return op.Succcedded(employees);
|
|
}
|
|
|
|
}
|
|
}
|