560 lines
25 KiB
C#
560 lines
25 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.LeftWorkAgg;
|
|
using Company.Domain.PersonnelCodeAgg;
|
|
using CompanyManagment.App.Contracts.LeftWork;
|
|
using CompanyManagment.App.Contracts.PersonnleCode;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public LeftWorkRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public EditLeftWork GetDetails(long id)
|
|
{
|
|
return _context.LeftWorkList.Select(x => new EditLeftWork()
|
|
{
|
|
Id = x.id,
|
|
LeftWorkDate = x.LeftWorkDate.ToFarsi(),
|
|
StartWorkDate = x.StartWorkDate.ToFarsi(),
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
WorkshopName = x.WorkshopName,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId
|
|
|
|
|
|
|
|
})
|
|
.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public string StartWork(long employeeId, long workshopId, string leftWork)
|
|
{
|
|
var checkExist = _context.LeftWorkList.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
|
|
if (checkExist)
|
|
{
|
|
var LeftWorks = _context.LeftWorkList
|
|
.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId)
|
|
.OrderByDescending(x => x.LeftWorkDate).ToList();
|
|
var lastLeft = LeftWorks.Select(x => x.LeftWorkDate).FirstOrDefault();
|
|
|
|
var leftWorkNew = leftWork.ToGeorgianDateTime();
|
|
|
|
var startWorkList = _context.Contracts
|
|
.Where(x => x.EmployeeId == employeeId && x.WorkshopIds == workshopId)
|
|
.Where(x => x.ContarctStart < leftWorkNew && x.ContarctStart > lastLeft)
|
|
.OrderBy(x => x.ContarctStart).ToList();
|
|
|
|
var startWorkDate = startWorkList.Select(x => x.ContarctStart).FirstOrDefault();
|
|
var result = startWorkDate.ToFarsi();
|
|
return result;
|
|
|
|
}
|
|
else
|
|
{
|
|
var leftWorkNew = leftWork.ToGeorgianDateTime();
|
|
|
|
var startWorkList = _context.Contracts
|
|
.Where(x => x.EmployeeId == employeeId && x.WorkshopIds == workshopId)
|
|
.Where(x => x.ContarctStart < leftWorkNew)
|
|
.OrderBy(x => x.ContarctStart).ToList();
|
|
|
|
var startWorkDate = startWorkList.Select(x => x.ContarctStart).FirstOrDefault();
|
|
var result = startWorkDate.ToFarsi();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public List<LeftWorkViewModel> searchByWorkshopId(long workshopId)
|
|
{
|
|
var query = _context.LeftWorkList.Select(x => new LeftWorkViewModel()
|
|
{
|
|
Id = x.id,
|
|
LeftWorkDate = x.LeftWorkDate.ToFarsi(),
|
|
StartWorkDate = x.StartWorkDate.ToFarsi(),
|
|
LeftWorkDateGr = x.LeftWorkDate,
|
|
StartWorkDateGr = x.StartWorkDate,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
WorkshopName = x.WorkshopName,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
AddBonusesPay = x.AddBonusesPay,
|
|
AddYearsPay = x.AddYearsPay,
|
|
AddLeavePay = x.AddLeavePay,
|
|
JobId = x.JobId,
|
|
|
|
|
|
|
|
}).Where(x=>x.WorkshopId == workshopId);
|
|
|
|
return query.ToList();
|
|
}
|
|
|
|
|
|
public List<LeftWorkViewModel> search(LeftWorkSearchModel searchModel)
|
|
{
|
|
|
|
var query = _context.LeftWorkList.Select(x => new LeftWorkViewModel()
|
|
{
|
|
Id = x.id,
|
|
LeftWorkDate = x.LeftWorkDate.ToFarsi(),
|
|
StartWorkDate = x.StartWorkDate.ToFarsi(),
|
|
LeftWorkDateGr = x.LeftWorkDate,
|
|
StartWorkDateGr = x.StartWorkDate,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
WorkshopName = x.WorkshopName,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
AddBonusesPay = x.AddBonusesPay,
|
|
AddYearsPay = x.AddYearsPay,
|
|
AddLeavePay = x.AddLeavePay,
|
|
JobId = x.JobId,
|
|
JobName = _context.Jobs.FirstOrDefault(j => j.id == x.JobId).JobName
|
|
|
|
|
|
});
|
|
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)
|
|
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
|
|
if (searchModel.WorkshopId != 0 && searchModel.EmployeeId == 0)
|
|
query = query.Where(x => x.WorkshopId == searchModel.WorkshopId);
|
|
return query.OrderByDescending(x => x.StartWorkDateGr).ToList();
|
|
}
|
|
|
|
public LeftWorkViewModel CheckoutleftWorkCheck(DateTime contractStart, long workshopId, long employeeId)
|
|
{
|
|
return _context.LeftWorkList.Select(x => new LeftWorkViewModel()
|
|
{
|
|
Id = x.id,
|
|
LeftWorkDate = x.LeftWorkDate.ToFarsi(),
|
|
StartWorkDate = x.StartWorkDate.ToFarsi(),
|
|
StartWorkDateGr = x.StartWorkDate,
|
|
LeftWorkDateGr = x.LeftWorkDate,
|
|
EmployeeFullName = x.EmployeeFullName,
|
|
WorkshopName = x.WorkshopName,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
AddLeavePay = x.AddLeavePay,
|
|
AddBonusesPay = x.AddBonusesPay,
|
|
AddYearsPay = x.AddYearsPay,
|
|
|
|
|
|
|
|
})
|
|
.FirstOrDefault(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId
|
|
&& contractStart >= x.StartWorkDateGr && contractStart <= x.LeftWorkDateGr);
|
|
}
|
|
|
|
public OperationResult RemoveLeftWork(long id)
|
|
{
|
|
var op = new OperationResult();
|
|
var item = _context.LeftWorkList.FirstOrDefault(x=>x.id==id);
|
|
if(item !=null)
|
|
_context.LeftWorkList.Remove(item);
|
|
|
|
_context.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
|
|
public LeftWorkViewModel GetByDateAndWorkshopIdAndEmployeeId(long workshopId, long employeeId, DateTime dateTime)
|
|
{
|
|
var entity = _context.LeftWorkList.FirstOrDefault(x =>
|
|
x.WorkshopId == workshopId && x.EmployeeId == employeeId &&
|
|
(x.StartWorkDate <= dateTime && x.LeftWorkDate >= dateTime));
|
|
return new()
|
|
{
|
|
EmployeeId = entity.EmployeeId,
|
|
WorkshopId = entity.WorkshopId,
|
|
LeftWorkDate = entity.LeftWorkDate.ToFarsi(),
|
|
HasLeft = entity.HasLeft,
|
|
LeftWorkDateGr = entity.LeftWorkDate,
|
|
StartWorkDateGr = entity.StartWorkDate,
|
|
Id = entity.id
|
|
|
|
};
|
|
}
|
|
|
|
public List<LeftWorkViewModel> GetLeftPersonelByWorkshopId(List<long> workshopIds)
|
|
{
|
|
return _context.LeftWorkList.Select(x => new LeftWorkViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
|
|
}).Where(x => workshopIds.Contains(x.WorkshopId)).ToList();
|
|
}
|
|
|
|
public OperationResult RemoveAllLeftWork(long workshopId, long employeeId)
|
|
{
|
|
var op = new OperationResult();
|
|
using (var transaction = _context.Database.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
//bool hasContracts = _context.Contracts.Any(x => x.EmployeeId == employeeId && x.WorkshopIds == workshopId && x.IsActiveString == "true");
|
|
//if (hasContracts)
|
|
//{
|
|
// return op.Failed("حذف ترک کار این پرسنل به دلیل داشتن قرارداد امکان پذیر نمی باشد.");
|
|
//}
|
|
|
|
bool hasCheckout = _context.CheckoutSet.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
|
|
if (hasCheckout)
|
|
{
|
|
return op.Failed("حذف ترک کار این پرسنل به دلیل داشتن فیش حقوقی امکان پذیر نمی باشد.");
|
|
}
|
|
|
|
var list = _context.LeftWorkList.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId).ToList();
|
|
if (list != null && list.Count > 0)
|
|
_context.LeftWorkList.RemoveRange(list);
|
|
|
|
|
|
bool hasLeftWorkInsurance = _context.LeftWorkInsuranceList.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
|
|
if (!hasLeftWorkInsurance)
|
|
{
|
|
var personelCodeList = _context.PersonnelCodeSet.Where(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId).ToList();
|
|
_context.PersonnelCodeSet.RemoveRange(personelCodeList);
|
|
}
|
|
|
|
_context.SaveChanges();
|
|
transaction.Commit();
|
|
if (hasLeftWorkInsurance)
|
|
return
|
|
op.Succcedded(1, "حذف با موفقیت انجام شد."); //+ "<br/>" + "<span class='text-danger'>" + "کد پرسنلی این شخص به دلیل استفاده در ترک کار بیمه قابل حذف نمی باشد. " + "</span>");
|
|
else
|
|
return op.Succcedded();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
transaction.Rollback();
|
|
return op.Failed("حذف اطلاعات با خطا مواجه شد");
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<LeftWorkViewModel> SearchLeftWork(LeftWorkSearchModel searchModel)
|
|
{
|
|
//var query = _context.LeftWorkList.Select(x => new LeftWorkViewModel()
|
|
//{
|
|
// Id = x.id,
|
|
// LeftWorkDate = x.LeftWorkDate.ToFarsi(),
|
|
// StartWorkDate = x.StartWorkDate.ToFarsi(),
|
|
// LeftWorkDateGr = x.LeftWorkDate,
|
|
// StartWorkDateGr = x.StartWorkDate,
|
|
// EmployeeFullName = x.EmployeeFullName,
|
|
// WorkshopName = x.WorkshopName,
|
|
// WorkshopId = x.WorkshopId,
|
|
// EmployeeId = x.EmployeeId,
|
|
//});
|
|
|
|
var query = new List<LeftWork>();
|
|
if (searchModel.WorkshopId != 0 && searchModel.EmployeeId != 0)
|
|
query = _context.LeftWorkList.Where(x => x.WorkshopId == searchModel.WorkshopId && x.EmployeeId == searchModel.EmployeeId).ToList();
|
|
if (searchModel.EmployeeId != 0)
|
|
query = _context.LeftWorkList.Where(x => x.EmployeeId == searchModel.EmployeeId).ToList();
|
|
|
|
var list = new List<LeftWorkViewModel>();
|
|
|
|
foreach (var item in query)
|
|
{
|
|
var jobObj = _context.Jobs.Where(x => x.id == item.JobId).FirstOrDefault();
|
|
|
|
list.Add(new LeftWorkViewModel()
|
|
{
|
|
Id = item.id,
|
|
LeftWorkDate = item.LeftWorkDate.ToFarsi(),
|
|
StartWorkDate = item.StartWorkDate.ToFarsi(),
|
|
LeftWorkDateGr = item.LeftWorkDate,
|
|
StartWorkDateGr = item.StartWorkDate,
|
|
EmployeeFullName = item.EmployeeFullName,
|
|
WorkshopName = item.WorkshopName,
|
|
WorkshopId = item.WorkshopId,
|
|
EmployeeId = item.EmployeeId,
|
|
JobId = item.JobId,
|
|
IncludeStatus = item.IncludeStatus,
|
|
JobName = jobObj != null ? jobObj.JobName : string.Empty,
|
|
JobCode = jobObj != null ? jobObj.JobCode : string.Empty,
|
|
AddLeavePay = item.AddLeavePay,
|
|
AddBonusesPay = item.AddBonusesPay,
|
|
AddYearsPay = item.AddYearsPay
|
|
});
|
|
}
|
|
return list.OrderByDescending(x => x.StartWorkDateGr).ToList();
|
|
}
|
|
|
|
public OperationResult CreateLeftWork(InformationLeftwork command)
|
|
{
|
|
var op = new OperationResult();
|
|
using (var transaction = _context.Database.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
#region PersonelCode
|
|
if (command.PersonnelCodeList != null && command.PersonnelCodeList.Count > 0)
|
|
{
|
|
var personelcode = command.PersonnelCodeList.Where(x => x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId).FirstOrDefault();
|
|
if (personelcode != null)
|
|
{
|
|
if (_context.PersonnelCodeSet.Any(x => x.WorkshopId == command.WorkshopId && x.PersonnelCode == personelcode.PersonnelCode))
|
|
{
|
|
op.Failed(" کد پرسنلی در کارگاه " + command.WorkshopName + " تکراری می باشد. ");
|
|
}
|
|
|
|
if (personelcode.PersonnelCode <= 0)
|
|
{
|
|
return op.Failed(" کد پرسنلی در کارگاه " + command.WorkshopName + "نامعتبر است.");
|
|
}
|
|
_context.PersonnelCodeSet.Add(new PersonnelCodeDomain(command.WorkshopId, command.EmployeeId, personelcode.PersonnelCode));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
if (command.ItemLeftworkList != null && command.ItemLeftworkList.Count > 0)
|
|
{
|
|
bool checkRegister = false;
|
|
var workshop = _context.Workshops
|
|
.FirstOrDefault(x => x.id == command.WorkshopId);
|
|
var workshopComputeOptions = workshop.ComputeOptions;
|
|
var workshopBonusesOptions = workshop.BonusesOptions;
|
|
foreach (var item2 in command.ItemLeftworkList)
|
|
{
|
|
var LeftWork = _context.LeftWorkList.Where(x => x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId).ToList();
|
|
_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);
|
|
Create(leftwork);
|
|
}
|
|
}
|
|
_context.SaveChanges();
|
|
transaction.Commit();
|
|
op.Succcedded(-1, " ثبت اطلاعات کارگاه " + command.WorkshopName + " با موفقیت انجام شد. ");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
transaction.Rollback();
|
|
op.Failed(" ثبت اطلاعات کارگاه " + command.WorkshopName + " با خطا مواجه شد. ");
|
|
}
|
|
}
|
|
return op;
|
|
}
|
|
|
|
public OperationResult CreateLeftWorkByLeftWorkGroups(string employeeFullName, long commandEmployeeId, List<PersonnelCodeViewModel> commandPersonnelCode, List<LeftWorkGroup> leftWorkGroups)
|
|
{
|
|
var op = new OperationResult();
|
|
using (var transaction = _context.Database.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
|
|
foreach (var item in leftWorkGroups)
|
|
{
|
|
#region PersonelCode
|
|
|
|
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 (_context.PersonnelCodeSet.Any(x => x.WorkshopId == item.WorkshopId && x.PersonnelCode == personelcode.PersonnelCode))
|
|
{
|
|
return op.Failed(" کد پرسنلی در کارگاه " + item.WorkshopName + " تکراری می باشد. ");
|
|
}
|
|
|
|
if (personelcode.PersonnelCode <= 0)
|
|
{
|
|
return op.Failed(" کد پرسنلی در کارگاه " + item.WorkshopName + "نامعتبر است.");
|
|
}
|
|
|
|
_context.PersonnelCodeSet.Add(new PersonnelCodeDomain(item.WorkshopId, commandEmployeeId, personelcode.PersonnelCode));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
if (item.LeftWorkViewModels != null && item.LeftWorkViewModels.Count > 0)
|
|
{
|
|
bool checkRegister = false;
|
|
|
|
|
|
var LeftWorkList = _context.LeftWorkList.Where(x => x.EmployeeId == commandEmployeeId && x.WorkshopId == item.WorkshopId).ToList();
|
|
|
|
var removeList = new List<LeftWork>();
|
|
|
|
foreach (var removeItem in LeftWorkList)
|
|
{
|
|
if (!item.LeftWorkViewModels.Any(x => x.Id == removeItem.id))
|
|
removeList.Add(removeItem);
|
|
}
|
|
foreach (var item2 in item.LeftWorkViewModels)
|
|
{
|
|
DateTime left = new DateTime();
|
|
if (!string.IsNullOrWhiteSpace(item2.LeftWorkDate))
|
|
left = item2.LeftWorkDate.ToGeorgianDateTime();
|
|
var start = item2.StartWorkDate.ToGeorgianDateTime();
|
|
|
|
if (item2.Id == 0)
|
|
{
|
|
var workshop = _context.Workshops
|
|
.FirstOrDefault(x => x.id == item2.WorkshopId);
|
|
var workshopComputeOptions = workshop.ComputeOptions;
|
|
var workshopBonusesOptions = workshop.BonusesOptions;
|
|
var LeftWorkObj = new LeftWork(left, start, item2.WorkshopId, item2.EmployeeId,
|
|
employeeFullName, item2.WorkshopName, item2.JobId, item2.IncludeStatus,
|
|
item2.AddBonusesPay, item2.AddYearsPay, item2.AddLeavePay, workshopComputeOptions, workshopBonusesOptions);
|
|
Create(LeftWorkObj);
|
|
}
|
|
else
|
|
{
|
|
var LeftWork = _context.LeftWorkList.Where(x => x.id == item2.Id)?.FirstOrDefault();
|
|
LeftWork.Edit(left, start, item2.WorkshopId, item2.EmployeeId, item2.JobId, item2.IncludeStatus,
|
|
item2.AddBonusesPay, item2.AddYearsPay, item2.AddLeavePay);
|
|
}
|
|
}
|
|
|
|
if (removeList != null && removeList.Count > 0)
|
|
{
|
|
_context.LeftWorkList.RemoveRange(removeList);
|
|
}
|
|
|
|
//foreach (var item2 in item.LeftWorkViewModels)
|
|
//{
|
|
// var LeftWork = _context.LeftWorkList.Where(x => x.EmployeeId == commandEmployeeId && x.WorkshopId == item.WorkshopId).ToList();
|
|
// _context.LeftWorkList.RemoveRange(LeftWork);
|
|
// DateTime left = item2.LeftWorkDate.ToGeorgianDateTime();
|
|
// var start = item2.StartWorkDate.ToGeorgianDateTime();
|
|
// var leftwork = new LeftWork(left, start, item2.WorkshopId, item2.EmployeeId,
|
|
// employeeFullName, item2.WorkshopName, item2.JobId, item2.IncludeStatus,
|
|
// item2.AddBonusesPay, item2.AddYearsPay, item2.AddLeavePay);
|
|
// Create(leftwork);
|
|
//}
|
|
}
|
|
}
|
|
|
|
_context.SaveChanges();
|
|
transaction.Commit();
|
|
op.Succcedded(-1, " ثبت با موفقیت انجام شد. ");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
transaction.Rollback();
|
|
op.Failed(" ثبت اطلاعات با خطا مواجه شد. ");
|
|
}
|
|
}
|
|
|
|
return op;
|
|
}
|
|
|
|
public OperationResult CheckDeleteLeftWork(long workshopId, long employeeId, DateTime date, int type)
|
|
{
|
|
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");
|
|
else
|
|
{
|
|
endDateSend = date.Date;
|
|
hasContracts = _context.CheckoutSet.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && (x.ContractStart.Date <= endDateSend && x.ContractEnd.Date >= endDateSend) && x.IsActiveString == "true");
|
|
}
|
|
|
|
if (type == 1 && hasContracts)
|
|
{
|
|
return op.Failed("برای حذف تاریخ شروع به کار، ابتدا تصفیه حساب های مربوطه را حذف کنید");
|
|
}
|
|
else if (type == 2 && hasContracts)
|
|
{
|
|
|
|
return op.Failed("در این تاریخ تصفیه حساب ثبت شده است.برای حذف تاریخ ترک کار، ابتدا تصفیه حساب های مربوطه را حذف کنید");
|
|
}
|
|
|
|
|
|
return op.Succcedded();
|
|
}
|
|
public OperationResult CheckEditLeftWork(long workshopId, long employeeId, DateTime date, int type)
|
|
{
|
|
var op = new OperationResult();
|
|
bool hasContracts = false;
|
|
|
|
|
|
if (type == 1)
|
|
{
|
|
hasContracts= _context.CheckoutSet.Any(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId && (x.ContractStart.Date>= date) && x.IsActiveString == "true");
|
|
if(hasContracts)
|
|
return op.Failed("لطفا ابتدا تصفیه حساب های آتی را حذف نمایید");
|
|
}
|
|
else
|
|
{
|
|
var LeftDay = date.Date;
|
|
var lastDay = date.Date.AddDays(-1);
|
|
var LastDayChekout = _context.CheckoutSet.FirstOrDefault(x =>
|
|
x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.ContractStart.Date <= lastDay.Date && x.ContractEnd.Date >= lastDay.Date);
|
|
var LeftDayCheckout = _context.CheckoutSet.FirstOrDefault(x =>
|
|
x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.ContractStart.Date <= LeftDay.Date && x.ContractEnd.Date >= LeftDay.Date);
|
|
if (LeftDayCheckout != null)
|
|
{
|
|
string resultDay = LeftDayCheckout.Month + " " + LeftDayCheckout.Year;
|
|
return op.Failed("در صورت تمایل به ثبت تاریخ، تصفیه حساب " + resultDay + " را حذف نمایید.");
|
|
}
|
|
//if (LastDayChekout != null)
|
|
//{
|
|
// string resultDay = LastDayChekout.Month + " " + LastDayChekout.Year;
|
|
// return op.Failed("در صورت تمایل به ثبت تاریخ، تصفیه حساب " + resultDay + " را حذف نمایید.");
|
|
//}
|
|
|
|
var LastDayContract = _context.CheckoutSet.Any(x =>
|
|
x.EmployeeId == employeeId && x.WorkshopId == workshopId && x.IsActiveString == "true" &&
|
|
x.ContractEnd.Date > lastDay.Date);
|
|
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();
|
|
|
|
//if (contract != null)
|
|
//{
|
|
|
|
// if ((contract.ContarctStart.Date <= endDateSend.Date && contract.ContractEnd.Date >= endDateSend.Date))
|
|
// {
|
|
|
|
// var checkout = _context.CheckoutSet.Where(x =>
|
|
// x.EmployeeId == employeeId && x.WorkshopId == workshopId &&
|
|
// (x.ContractStart.Date <= date.Date && x.ContractEnd.Date >= date.Date)).FirstOrDefault();
|
|
// hasContracts = false;
|
|
// if (checkout != null)
|
|
// {
|
|
// string resultDay = checkout.Month + " " + checkout.Year;
|
|
// return op.Failed("در صورت تمایل به ثبت تاریخ، تصفیه حساب "+resultDay+" را حذف نمایید.");
|
|
// }
|
|
// else
|
|
// {
|
|
// return op.Succcedded();
|
|
// }
|
|
// }
|
|
// else if ((contract.ContractEnd.Date == endDateSend))
|
|
// {
|
|
// return op.Succcedded();
|
|
// }
|
|
// else if ((contract.ContractEnd.Date > endDateSend.AddMonths(1)))
|
|
// {
|
|
// return op.Failed("AfterContracts");
|
|
// }
|
|
// //else if ((contract.ContractEnd.Date < endDateSend.AddMonths(1)))
|
|
// //{
|
|
// // return op.Failed("NoContracts");
|
|
// //}
|
|
//}
|
|
return op.Succcedded();
|
|
|
|
}
|
|
|
|
return op.Succcedded();
|
|
}
|
|
} |