|
|
|
|
@@ -30,8 +30,11 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
private readonly ICheckoutRepository _checkoutRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SalaryAidApplication(ISalaryAidRepository salaryAidRepository, ICustomizeCheckoutRepository customizeCheckoutRepository,
|
|
|
|
|
IEmployeeRepository employeeRepository, ICustomizeCheckoutTempRepository customizeCheckoutTempRepository, IAuthHelper authHelper, ICustomizeCheckoutApplication customizeCheckoutApplication, ICustomizeCheckoutTempApplication customizeCheckoutTempApplication, ICheckoutRepository checkoutRepository)
|
|
|
|
|
public SalaryAidApplication(ISalaryAidRepository salaryAidRepository,
|
|
|
|
|
ICustomizeCheckoutRepository customizeCheckoutRepository,
|
|
|
|
|
IEmployeeRepository employeeRepository, ICustomizeCheckoutTempRepository customizeCheckoutTempRepository,
|
|
|
|
|
IAuthHelper authHelper, ICustomizeCheckoutApplication customizeCheckoutApplication,
|
|
|
|
|
ICustomizeCheckoutTempApplication customizeCheckoutTempApplication, ICheckoutRepository checkoutRepository)
|
|
|
|
|
{
|
|
|
|
|
_salaryAidRepository = salaryAidRepository;
|
|
|
|
|
_customizeCheckoutRepository = customizeCheckoutRepository;
|
|
|
|
|
@@ -62,6 +65,7 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("تاریخ وارد شده نامعتبر است");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var calculationDate = $"{command.CalculationYear:0000}/{command.CalculationMonth:00}/01";
|
|
|
|
|
if (!calculationDate.TryToGeorgianDateTime(out var calculationDateGr))
|
|
|
|
|
{
|
|
|
|
|
@@ -71,7 +75,6 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
if (startDate > DateTime.Now)
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("تاریخ پرداخت مساعده می بایست تاریخ امروز یا قبل تر باشد");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (command.Amount.Length > 15)
|
|
|
|
|
@@ -100,15 +103,15 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
calculationDateGr, command.WorkshopId, command.EmployeeIds);
|
|
|
|
|
|
|
|
|
|
//if (existsCheckouts.Checkout)
|
|
|
|
|
// return op.Failed("شما نمیتوانید برای پرسنلی در تاریخی که برای فیش حقوقی رسمی صادر شده است مساعده ای دهید");
|
|
|
|
|
// return op.Failed("شما نمیتوانید برای پرسنلی در تاریخی که برای فیش حقوقی رسمی صادر شده است مساعده ای دهید");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (userId, userType, _) = _authHelper.GetUserTypeWithId();
|
|
|
|
|
using var transaction = new TransactionScope();
|
|
|
|
|
foreach (var employeeId in command.EmployeeIds)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var entity = new SalaryAid(employeeId, command.WorkshopId, command.Amount.MoneyToDouble(), startDate, userId, userType, command.CalculationMonth, command.CalculationYear);
|
|
|
|
|
var entity = new SalaryAid(employeeId, command.WorkshopId, command.Amount.MoneyToDouble(), startDate,
|
|
|
|
|
userId, userType, command.CalculationMonth, command.CalculationYear);
|
|
|
|
|
_salaryAidRepository.Create(entity);
|
|
|
|
|
_salaryAidRepository.SaveChanges();
|
|
|
|
|
if (existsCheckouts.CustomizeCheckout)
|
|
|
|
|
@@ -119,13 +122,13 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
|
|
|
|
|
if (customizeCheckouts != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var salaryAids = customizeCheckouts.CustomizeCheckoutSalaryAids.ToList();
|
|
|
|
|
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime, entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate, entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime,
|
|
|
|
|
entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate, entity.CalculationDate.ToFarsi(),
|
|
|
|
|
entity.id));
|
|
|
|
|
customizeCheckouts.SetSalaryAids(salaryAids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (existsCheckouts.CustomizeCheckoutTemp)
|
|
|
|
|
@@ -137,11 +140,12 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
{
|
|
|
|
|
var salaryAids = customizeCheckoutTemp.CustomizeCheckoutSalaryAids.ToList();
|
|
|
|
|
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime, entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate, entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime,
|
|
|
|
|
entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate, entity.CalculationDate.ToFarsi(),
|
|
|
|
|
entity.id));
|
|
|
|
|
customizeCheckoutTemp.SetSalaryAids(salaryAids);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_customizeCheckoutRepository.SaveChanges();
|
|
|
|
|
@@ -167,12 +171,13 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
if (startDate > DateTime.Now)
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("تاریخ پرداخت مساعده می بایست تاریخ امروز یا قبل تر باشد");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (command.Amount.Length > 15)
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("مبلغ وارد شده معتبر نیست");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entity = _salaryAidRepository.Get(command.Id);
|
|
|
|
|
if (entity == null)
|
|
|
|
|
return op.Failed("چنین مساعده ای وجود ندارد");
|
|
|
|
|
@@ -198,14 +203,15 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
var existsCheckouts = _customizeCheckoutRepository.ValidateExistsCheckouts(calculationDateGr,
|
|
|
|
|
calculationDateGr, entity.WorkshopId, [entity.EmployeeId]);
|
|
|
|
|
|
|
|
|
|
// if (existsCheckouts.Checkout)
|
|
|
|
|
// return op.Failed("شما نمیتوانید برای پرسنلی در تاریخی که برای فیش حقوقی رسمی صادر شده است مساعده ای دهید");
|
|
|
|
|
// if (existsCheckouts.Checkout)
|
|
|
|
|
// return op.Failed("شما نمیتوانید برای پرسنلی در تاریخی که برای فیش حقوقی رسمی صادر شده است مساعده ای دهید");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using var transaction = new TransactionScope();
|
|
|
|
|
var (userId, userType, _) = _authHelper.GetUserTypeWithId();
|
|
|
|
|
|
|
|
|
|
entity.Edit(Tools.MoneyToDouble(command.Amount), startDate, userId, userType, command.CalculationMonth, command.CalculationYear);
|
|
|
|
|
entity.Edit(Tools.MoneyToDouble(command.Amount), startDate, userId, userType, command.CalculationMonth,
|
|
|
|
|
command.CalculationYear);
|
|
|
|
|
_salaryAidRepository.SaveChanges();
|
|
|
|
|
|
|
|
|
|
if (existsCheckouts.CustomizeCheckout)
|
|
|
|
|
@@ -226,8 +232,8 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
entity.CalculationDate, entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
|
|
|
|
|
customizeCheckouts.SetSalaryAids(salaryAids);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (existsCheckouts.CustomizeCheckoutTemp)
|
|
|
|
|
{
|
|
|
|
|
var customizeCheckoutTemp = _customizeCheckoutTempRepository.GetByWorkshopIdEmployeeIdInDate(
|
|
|
|
|
@@ -245,8 +251,8 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
entity.CalculationDate, entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
|
|
|
|
|
customizeCheckoutTemp.SetSalaryAids(salaryAids);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_customizeCheckoutRepository.SaveChanges();
|
|
|
|
|
transaction.Complete();
|
|
|
|
|
return op.Succcedded();
|
|
|
|
|
@@ -262,18 +268,23 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
var month = Convert.ToInt32(entity.CalculationDate.ToFarsi().Substring(5, 2));
|
|
|
|
|
var year = Convert.ToInt32(entity.CalculationDate.ToFarsi().Substring(0, 4));
|
|
|
|
|
|
|
|
|
|
if (_customizeCheckoutRepository.Exists(x => x.WorkshopId == entity.WorkshopId && entity.EmployeeId == x.EmployeeId && x.YearInt == year && x.MonthInt == month))
|
|
|
|
|
if (_customizeCheckoutRepository.Exists(x =>
|
|
|
|
|
x.WorkshopId == entity.WorkshopId && entity.EmployeeId == x.EmployeeId && x.YearInt == year &&
|
|
|
|
|
x.MonthInt == month))
|
|
|
|
|
return op.Failed("این پرسنل در این تاریخ دارای فیش حقوقی است");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_customizeCheckoutTempRepository.Exists(x => x.WorkshopId == entity.WorkshopId && entity.EmployeeId == x.EmployeeId &&
|
|
|
|
|
x.YearInt == year && x.MonthInt == month && x.ContractStart <= entity.CalculationDate && x.ContractEnd >= entity.CalculationDate))
|
|
|
|
|
if (_customizeCheckoutTempRepository.Exists(x =>
|
|
|
|
|
x.WorkshopId == entity.WorkshopId && entity.EmployeeId == x.EmployeeId &&
|
|
|
|
|
x.YearInt == year && x.MonthInt == month && x.ContractStart <= entity.CalculationDate &&
|
|
|
|
|
x.ContractEnd >= entity.CalculationDate))
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("این پرسنل در این تاریخ دارای فیش حقوقی موقت است");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_checkoutRepository.Exists(x => x.WorkshopId == entity.WorkshopId && entity.EmployeeId == x.EmployeeId &&
|
|
|
|
|
x.ContractStart <= entity.CalculationDate && x.ContractEnd >= entity.CalculationDate))
|
|
|
|
|
x.ContractStart <= entity.CalculationDate &&
|
|
|
|
|
x.ContractEnd >= entity.CalculationDate))
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("این پرسنل در این تاریخ دارای فیش حقوقی رسمی است");
|
|
|
|
|
}
|
|
|
|
|
@@ -293,17 +304,18 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public OperationResult CreateRange(List<CreateSalaryAidViewModel> commands)
|
|
|
|
|
public async Task<OperationResult> CreateRangeAsync(List<CreateSalaryAidViewModel> commands)
|
|
|
|
|
{
|
|
|
|
|
var op = new OperationResult();
|
|
|
|
|
using var transaction = new TransactionScope();
|
|
|
|
|
await using var transaction = await _salaryAidRepository.BeginTransactionAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var command in commands)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!command.SalaryDateTime.TryToGeorgianDateTime(out var startDate))
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("تاریخ وارد شده نامعتبر است");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var calculationDate = $"{command.CalculationYear:0000}/{command.CalculationMonth:00}/01";
|
|
|
|
|
if (!calculationDate.TryToGeorgianDateTime(out var calculationDateGr))
|
|
|
|
|
{
|
|
|
|
|
@@ -313,12 +325,13 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
if (startDate > DateTime.Now)
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("تاریخ پرداخت مساعده می بایست تاریخ امروز یا قبل تر باشد");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (command.Amount.Length > 15)
|
|
|
|
|
{
|
|
|
|
|
return op.Failed("مبلغ وارد شده معتبر نیست");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ = DateTime.Now.Date.AddMonthsFa(-1, out var oneMonthAgoGr);
|
|
|
|
|
|
|
|
|
|
if (oneMonthAgoGr > calculationDateGr)
|
|
|
|
|
@@ -336,14 +349,13 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
calculationDateGr, command.WorkshopId, command.EmployeeIds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (existsCheckouts.Checkout)
|
|
|
|
|
// return op.Failed("شما نمیتوانید برای پرسنلی در تاریخی که برای فیش حقوقی رسمی صادر شده است مساعده ای دهید");
|
|
|
|
|
// if (existsCheckouts.Checkout)
|
|
|
|
|
// return op.Failed("شما نمیتوانید برای پرسنلی در تاریخی که برای فیش حقوقی رسمی صادر شده است مساعده ای دهید");
|
|
|
|
|
|
|
|
|
|
var month = Convert.ToInt32(command.CalculationMonth);
|
|
|
|
|
var year = Convert.ToInt32(command.CalculationYear);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (userId, userType, _) = _authHelper.GetUserTypeWithId();
|
|
|
|
|
|
|
|
|
|
foreach (var employeeId in command.EmployeeIds)
|
|
|
|
|
@@ -355,9 +367,10 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
id = employee.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entity = new SalaryAid(id, command.WorkshopId, command.Amount.MoneyToDouble(), startDate, userId, userType, command.CalculationMonth, command.CalculationYear);
|
|
|
|
|
_salaryAidRepository.Create(entity);
|
|
|
|
|
_salaryAidRepository.SaveChanges();
|
|
|
|
|
var entity = new SalaryAid(id, command.WorkshopId, command.Amount.MoneyToDouble(), startDate, userId,
|
|
|
|
|
userType, command.CalculationMonth, command.CalculationYear);
|
|
|
|
|
await _salaryAidRepository.CreateAsync(entity);
|
|
|
|
|
await _salaryAidRepository.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
if (existsCheckouts.CustomizeCheckout)
|
|
|
|
|
{
|
|
|
|
|
@@ -367,13 +380,13 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
|
|
|
|
|
if (customizeCheckouts != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var salaryAids = customizeCheckouts.CustomizeCheckoutSalaryAids.ToList();
|
|
|
|
|
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime, entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate, entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime,
|
|
|
|
|
entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate,
|
|
|
|
|
entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
customizeCheckouts.SetSalaryAids(salaryAids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (existsCheckouts.CustomizeCheckoutTemp)
|
|
|
|
|
@@ -385,17 +398,23 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
{
|
|
|
|
|
var salaryAids = customizeCheckoutTemp.CustomizeCheckoutSalaryAids.ToList();
|
|
|
|
|
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime, entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate, entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
salaryAids.Add(new(entity.Amount.ToMoney(), entity.SalaryAidDateTime,
|
|
|
|
|
entity.SalaryAidDateTime.ToFarsi(), entity.CalculationDate,
|
|
|
|
|
entity.CalculationDate.ToFarsi(), entity.id));
|
|
|
|
|
customizeCheckoutTemp.SetSalaryAids(salaryAids);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_customizeCheckoutRepository.SaveChanges();
|
|
|
|
|
|
|
|
|
|
await _customizeCheckoutRepository.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
transaction.Complete();
|
|
|
|
|
|
|
|
|
|
await transaction.CommitAsync();
|
|
|
|
|
return op.Succcedded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Pooya
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// گروهبندی بر اساس ماه هنگام جستجو با انتخاب کارمند
|
|
|
|
|
/// </summary>
|
|
|
|
|
@@ -404,6 +423,5 @@ public class SalaryAidApplication : ISalaryAidApplication
|
|
|
|
|
return _salaryAidRepository.GetSearchListAsGrouped(searchModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|