|
@@ -18,19 +18,22 @@ namespace MTWorkHR.Application.Services
|
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
private readonly IUserService _userService;
|
|
|
private readonly GlobalInfo _globalInfo;
|
|
|
- private readonly OrderAllocationService _orderAllocationService;
|
|
|
+ private readonly IOrderAllocationService _orderAllocationService;
|
|
|
|
|
|
- public ContractService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo) : base(unitOfWork)
|
|
|
+ public ContractService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo, IOrderAllocationService orderAllocationService) : base(unitOfWork)
|
|
|
{
|
|
|
_unitOfWork = unitOfWork;
|
|
|
_userService = userService;
|
|
|
_globalInfo = globalInfo;
|
|
|
+ _orderAllocationService = orderAllocationService;
|
|
|
}
|
|
|
|
|
|
public override async Task<ContractDto> GetById(long id)
|
|
|
{
|
|
|
var entity = await _unitOfWork.Contract.GetByIdWithAllChildren(id);
|
|
|
var response = MapperObject.Mapper.Map<ContractDto>(entity);
|
|
|
+ response.WorkingDays = entity.WorkingDays != null ? entity.WorkingDays.Split(",").ToList() : null;
|
|
|
+
|
|
|
return response;
|
|
|
}
|
|
|
|
|
@@ -42,7 +45,7 @@ namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
throw new AppException(ExceptionEnum.MapperIssue);
|
|
|
}
|
|
|
-
|
|
|
+ entity.WorkingDays = input.WorkingDays!=null? string.Join(",", input.WorkingDays): null;
|
|
|
var team = await _unitOfWork.Contract.AddAsync(entity);
|
|
|
await _unitOfWork.CompleteAsync();
|
|
|
|
|
@@ -71,22 +74,6 @@ namespace MTWorkHR.Application.Services
|
|
|
var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
|
|
|
var query = res.Item1;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- //var query = queryx
|
|
|
- // .Join(
|
|
|
- // teamUsersList.Item1,
|
|
|
- // c => c.UserId,
|
|
|
- // teamUser => teamUser.AssignedUserId,
|
|
|
- // (contract, teamUser) => new
|
|
|
- // {
|
|
|
- // Contract = contract,
|
|
|
- // Teams = teamUser.Team.NameEn
|
|
|
- // }
|
|
|
- // )
|
|
|
- // .AsQueryable();
|
|
|
-
|
|
|
-
|
|
|
if (_globalInfo.UserType != UserTypeEnum.Business)
|
|
|
{
|
|
|
// query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
|
|
@@ -115,7 +102,10 @@ namespace MTWorkHR.Application.Services
|
|
|
|
|
|
var list = MapperObject.Mapper
|
|
|
.Map<IList<ContractDto>>(await page.ToListAsync());
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ var teamUsersList = await _unitOfWork.TeamUser.GetAllWithChildrenAsync();
|
|
|
+ var vacationAllocations = await _unitOfWork.OrderAllocation.GetAllAsync();
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
if (item.UserId != null)
|
|
@@ -125,17 +115,20 @@ namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
item.EmployeeName = user.FirstName + " " + user.LastName;
|
|
|
item.EmployeeEmail = user.Email;
|
|
|
+ //___________Get Teams
|
|
|
+ var TeamsList = teamUsersList.Item1.Where(t => t.AssignedUserId == item.UserId).Select(t => GlobalInfo.lang == "en" ? t.Team.NameEn : t.Team.NameAr);
|
|
|
+ item.Teams = TeamsList == null ? "" : string.Join(",", TeamsList);
|
|
|
+ //_____________Get vacation balance
|
|
|
+ var remainVacations = vacationAllocations.Item1.FirstOrDefault(t => t.EmployeeId == item.UserId && t.ContractId == item.Id);
|
|
|
+ item.Vacations = remainVacations == null ? "" : remainVacations.NumberOfDays + " / " + item.VacationDays;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- var teamUsersList = await _unitOfWork.TeamUser.GetAllWithChildrenAsync();
|
|
|
- foreach (var item in list)
|
|
|
- {
|
|
|
- if (item.UserId != null)
|
|
|
- {
|
|
|
- item.Teams = teamUsersList.Item1.Where(t => t.AssignedUserId == item.UserId).Select(t=> t.Team.NameEn).Aggregate((a,b)=> a+","+b);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
var response = new PagingResultDto<ContractDto>
|
|
|
{
|
|
|
Result = list,
|
|
@@ -155,16 +148,38 @@ namespace MTWorkHR.Application.Services
|
|
|
if (statusId == (int)ContractStatusEnum.Approved)
|
|
|
{
|
|
|
var updatedSuccess = await _userService.Update(entity.UserId, entity.CompanyId);
|
|
|
- addVacationAllocation(entity.VacationDays.HasValue ? entity.VacationDays.Value : 0, entity.UserId);
|
|
|
- if (!updatedSuccess) { result = false; }
|
|
|
+ addVacationAllocation(entity.VacationDays.HasValue ? entity.VacationDays.Value : 0, entity.UserId, contractId);
|
|
|
+ if (!updatedSuccess) {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
}
|
|
|
- await _unitOfWork.CompleteAsync();
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private void addVacationAllocation(int noVacationDays, string employeeId)
|
|
|
+ private async void addVacationAllocation(int noVacationDays, string employeeId, long contractId)
|
|
|
{
|
|
|
- _orderAllocationService.Create(new OrderAllocationDto { EmployeeId = employeeId,OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year});
|
|
|
+ await _orderAllocationService.Create(new OrderAllocationDto { ContractId = contractId, EmployeeId = employeeId, OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year });
|
|
|
+ var orderTypes = await _unitOfWork.OrderType.GetAllAsync();
|
|
|
+ var leaveTypes = await _unitOfWork.LeaveType.GetAllAsync();
|
|
|
+ foreach(var orderType in orderTypes.Item1)
|
|
|
+ {
|
|
|
+ foreach (var leaveType in leaveTypes.Item1)
|
|
|
+ {
|
|
|
+ if(orderType.Id !=1 && leaveType.Id != 1 && (leaveType.DefaultDays> 0 || orderType.DefaultDays > 0))
|
|
|
+ {
|
|
|
+ await _orderAllocationService.Create(new OrderAllocationDto
|
|
|
+ {
|
|
|
+ ContractId = contractId,
|
|
|
+ EmployeeId = employeeId,
|
|
|
+ OrderTypeId =(int) orderType.Id,
|
|
|
+ LeaveTypeId = (int)leaveType.Id,
|
|
|
+ NumberOfDays = leaveType.DefaultDays > 0 ? leaveType.DefaultDays : orderType.DefaultDays,
|
|
|
+ Period = DateTime.Now.Year }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|