add condition for creating employee status
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Domain;
|
||||
using CompanyManagment.App.Contracts.LeftWork;
|
||||
@@ -40,4 +41,6 @@ public interface ILeftWorkRepository : IRepository<long, LeftWork>
|
||||
List<LeftWorkViewModel> GetByWorkshopIdInDates(long workshopId, DateTime startDateGr, DateTime endDateGr);
|
||||
LeftWorkViewModel GetByWorkshopIdEmployeeIdInDates(long workshopId, long employeeId, DateTime start, DateTime end);
|
||||
#endregion
|
||||
|
||||
Task<LeftWork> GetLastLeftWork(long employeeId, long workshopId);
|
||||
}
|
||||
@@ -5,25 +5,26 @@ using Company.Domain.RollCallEmployeeStatusAgg;
|
||||
using CompanyManagment.App.Contracts.RollCallEmployeeStatus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Company.Domain.RollCallServiceAgg;
|
||||
|
||||
|
||||
namespace CompanyManagment.Application
|
||||
{
|
||||
public class RollCallEmployeeStatusApplication : IRollCallEmployeeStatusApplication
|
||||
{
|
||||
private readonly IRollCallEmployeeStatusRepository _employeeRollCallStatusRepository;
|
||||
private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository;
|
||||
private readonly ILeftWorkRepository _leftWorkRepository;
|
||||
public class RollCallEmployeeStatusApplication : IRollCallEmployeeStatusApplication
|
||||
{
|
||||
private readonly IRollCallEmployeeStatusRepository _employeeRollCallStatusRepository;
|
||||
private readonly IRollCallEmployeeRepository _rollCallEmployeeRepository;
|
||||
private readonly ILeftWorkRepository _leftWorkRepository;
|
||||
private readonly IRollCallServiceRepository _rollCallServiceRepository;
|
||||
|
||||
|
||||
public RollCallEmployeeStatusApplication(IRollCallEmployeeStatusRepository employeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, ILeftWorkRepository leftWorkRepository, IRollCallServiceRepository rollCallServiceRepository)
|
||||
{
|
||||
_employeeRollCallStatusRepository = employeeStatusRepository;
|
||||
_rollCallEmployeeRepository = rollCallEmployeeRepository;
|
||||
_leftWorkRepository = leftWorkRepository;
|
||||
public RollCallEmployeeStatusApplication(IRollCallEmployeeStatusRepository employeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository, ILeftWorkRepository leftWorkRepository, IRollCallServiceRepository rollCallServiceRepository)
|
||||
{
|
||||
_employeeRollCallStatusRepository = employeeStatusRepository;
|
||||
_rollCallEmployeeRepository = rollCallEmployeeRepository;
|
||||
_leftWorkRepository = leftWorkRepository;
|
||||
_rollCallServiceRepository = rollCallServiceRepository;
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ namespace CompanyManagment.Application
|
||||
return op.Failed("کارمند مجاز نیست");
|
||||
|
||||
if (!_leftWorkRepository.Exists(x => x.EmployeeId == rollCallEmployee.EmployeeId && x.WorkshopId == rollCallEmployee.WorkshopId &&
|
||||
x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date))
|
||||
(x.LeftWorkDate.Date > DateTime.Now.Date && x.StartWorkDate.Date <= DateTime.Now.Date) || x.StartWorkDate >= DateTime.Today))
|
||||
return op.Failed("کارمند در کارگاه شروع به کار نکرده است");
|
||||
|
||||
if (_employeeRollCallStatusRepository.Exists(y =>
|
||||
@@ -50,7 +51,21 @@ namespace CompanyManagment.Application
|
||||
}
|
||||
else
|
||||
{
|
||||
RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, DateTime.Now.Date);
|
||||
var pc = new PersianCalendar();
|
||||
var startStatus = DateTime.Today;
|
||||
LeftWork leftWork =
|
||||
_leftWorkRepository.GetLastLeftWork(rollCallEmployee.EmployeeId, rollCallEmployee.WorkshopId).GetAwaiter().GetResult();
|
||||
|
||||
if(leftWork.StartWorkDate>DateTime.Today)
|
||||
startStatus = leftWork.StartWorkDate;
|
||||
|
||||
else if(pc.GetMonth(DateTime.Today) == pc.GetMonth(leftWork.StartWorkDate))
|
||||
{
|
||||
startStatus = new DateTime(pc.GetYear(leftWork.StartWorkDate), pc.GetMonth(leftWork.StartWorkDate),
|
||||
1, pc);
|
||||
}
|
||||
|
||||
RollCallEmployeeStatus newRecord = new(rollCallEmployee.id, startStatus);
|
||||
_employeeRollCallStatusRepository.Create(newRecord);
|
||||
}
|
||||
|
||||
@@ -83,7 +98,7 @@ namespace CompanyManagment.Application
|
||||
if (!service.Any(x => x.StartService.Date <= contractStart.Date && x.EndService.Date >= contractEnd.Date))
|
||||
return false;
|
||||
var rollCallEmployee =
|
||||
_rollCallEmployeeRepository.GetByEmployeeIdAndWorkshopId(employeeId,workshopId);
|
||||
_rollCallEmployeeRepository.GetByEmployeeIdAndWorkshopId(employeeId, workshopId);
|
||||
|
||||
if (rollCallEmployee == null)
|
||||
return false;
|
||||
@@ -99,33 +114,33 @@ namespace CompanyManagment.Application
|
||||
}
|
||||
|
||||
public OperationResult Deactivate(long id)
|
||||
{
|
||||
OperationResult op = new();
|
||||
RollCallEmployeeStatus entity = _employeeRollCallStatusRepository.Get(id);
|
||||
if (entity == null)
|
||||
return op.Failed(ApplicationMessages.RecordNotFound);
|
||||
if (!entity.EndDate.IsDateUndefined())
|
||||
return op.Failed("کارمند قبلا غیر فعال شده است");
|
||||
entity.Deactivate(DateTime.Now.Date);
|
||||
_employeeRollCallStatusRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
}
|
||||
{
|
||||
OperationResult op = new();
|
||||
RollCallEmployeeStatus entity = _employeeRollCallStatusRepository.Get(id);
|
||||
if (entity == null)
|
||||
return op.Failed(ApplicationMessages.RecordNotFound);
|
||||
if (!entity.EndDate.IsDateUndefined())
|
||||
return op.Failed("کارمند قبلا غیر فعال شده است");
|
||||
entity.Deactivate(DateTime.Now.Date);
|
||||
_employeeRollCallStatusRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
}
|
||||
|
||||
public OperationResult Edit(EditRollCallEmployeeStatus cmd)
|
||||
{
|
||||
OperationResult op = new();
|
||||
RollCallEmployeeStatus entity = _employeeRollCallStatusRepository.Get(cmd.Id);
|
||||
if (entity == null)
|
||||
return op.Failed(ApplicationMessages.RecordNotFound);
|
||||
public OperationResult Edit(EditRollCallEmployeeStatus cmd)
|
||||
{
|
||||
OperationResult op = new();
|
||||
RollCallEmployeeStatus entity = _employeeRollCallStatusRepository.Get(cmd.Id);
|
||||
if (entity == null)
|
||||
return op.Failed(ApplicationMessages.RecordNotFound);
|
||||
|
||||
entity.Edit(cmd.StartDate, cmd.EndDate);
|
||||
_employeeRollCallStatusRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
}
|
||||
entity.Edit(cmd.StartDate, cmd.EndDate);
|
||||
_employeeRollCallStatusRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
}
|
||||
|
||||
public List<RollCallEmployeeStatusViewModel> GetAll()
|
||||
{
|
||||
return _employeeRollCallStatusRepository.GetAll();
|
||||
}
|
||||
}
|
||||
public List<RollCallEmployeeStatusViewModel> GetAll()
|
||||
{
|
||||
return _employeeRollCallStatusRepository.GetAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.InfraStructure;
|
||||
using Company.Domain.LeftWorkAgg;
|
||||
@@ -627,6 +628,13 @@ public class LeftWorkRepository : RepositoryBase<long, LeftWork>, ILeftWorkRepos
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<LeftWork> GetLastLeftWork(long employeeId, long workshopId)
|
||||
{
|
||||
var leftWork =await _context.LeftWorkList.Where(x => x.WorkshopId == workshopId && x.EmployeeId == employeeId)
|
||||
.OrderByDescending(x => x.StartWorkDate).FirstOrDefaultAsync();
|
||||
return leftWork;
|
||||
}
|
||||
|
||||
private bool HasActiveRollCallStatus(long workshopId, long employeeId)
|
||||
{
|
||||
var now = DateTime.Today;
|
||||
|
||||
Reference in New Issue
Block a user