fix defect
This commit is contained in:
parent
be10c7ef95
commit
a167f5ec9e
3 changed files with 48 additions and 23 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using Amazon.S3.Model.Internal.MarshallTransformations;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Messaging;
|
||||
using BMA.EHR.Domain.Models.Leave.Commons;
|
||||
using BMA.EHR.Domain.Models.Leave.Requests;
|
||||
|
|
@ -7,7 +6,6 @@ using BMA.EHR.Domain.Models.Notifications;
|
|||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||
|
|
@ -23,6 +21,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
private readonly IConfiguration _configuration;
|
||||
private readonly EmailSenderService _emailSenderService;
|
||||
|
||||
private readonly IApplicationDBContext _appDbContext;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destuctor "
|
||||
|
|
@ -32,7 +32,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
OrganizationCommonRepository organizationCommonRepository,
|
||||
UserProfileRepository userProfileRepository,
|
||||
IConfiguration configuration,
|
||||
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
|
||||
EmailSenderService emailSenderService,
|
||||
IApplicationDBContext appDbContext) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
|
@ -40,6 +41,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
_userProfileRepository = userProfileRepository;
|
||||
_configuration = configuration;
|
||||
_emailSenderService = emailSenderService;
|
||||
_appDbContext = appDbContext;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -121,7 +123,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
var rawData = _dbContext.Set<LeaveRequest>()
|
||||
.Include(x => x.Type)
|
||||
.AsQueryable();
|
||||
|
||||
|
||||
|
||||
|
||||
if (year != 0)
|
||||
|
|
@ -240,8 +242,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_dbContext.Set<Notification>().Add(noti);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
_appDbContext.Set<Notification>().Add(noti);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task RejectCancelLeaveRequestAsync(Guid id, string Reason)
|
||||
|
|
@ -273,8 +275,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_dbContext.Set<Notification>().Add(noti);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
_appDbContext.Set<Notification>().Add(noti);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task OfficerApproveLeaveRequest(Guid id)
|
||||
|
|
@ -286,7 +288,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
}
|
||||
|
||||
rawData.LeaveStatus = "PENDING";
|
||||
rawData.ApproveStep = "st1";
|
||||
rawData.ApproveStep = "st2";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
}
|
||||
|
|
@ -306,7 +308,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
rawData.LeaveStatus = "PENDING";
|
||||
rawData.LeaveComment = reason;
|
||||
rawData.ApproveStep = "st2";
|
||||
rawData.ApproveStep = "st3";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
}
|
||||
|
|
@ -319,7 +321,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
if (rawData.ApproveStep != "st2")
|
||||
if (rawData.ApproveStep != "st3")
|
||||
{
|
||||
throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้");
|
||||
}
|
||||
|
|
@ -332,7 +334,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
rawData.LeaveStatus = "APPROVE";
|
||||
rawData.LeaveDirectorComment = reason;
|
||||
rawData.ApproveStep = "st2";
|
||||
rawData.ApproveStep = "st4";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
|
||||
|
|
@ -344,8 +346,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_dbContext.Set<Notification>().Add(noti);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
_appDbContext.Set<Notification>().Add(noti);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task RejectLeaveRequest(Guid id, string reason)
|
||||
|
|
@ -356,7 +358,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
if (rawData.ApproveStep != "st2")
|
||||
if (rawData.ApproveStep != "st3")
|
||||
{
|
||||
throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้");
|
||||
}
|
||||
|
|
@ -369,7 +371,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
rawData.LeaveStatus = "REJECT";
|
||||
rawData.LeaveDirectorComment = reason;
|
||||
rawData.ApproveStep = "st2";
|
||||
rawData.ApproveStep = "st5";
|
||||
|
||||
await UpdateAsync(rawData);
|
||||
|
||||
|
|
@ -381,8 +383,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_dbContext.Set<Notification>().Add(noti);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
_appDbContext.Set<Notification>().Add(noti);
|
||||
await _appDbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<int> GetSumSendLeaveByTypeForUserAsync(Guid keycloakUserId, Guid leaveTypeId, int year)
|
||||
|
|
@ -425,7 +427,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
if (data.Count > 0)
|
||||
return data.Sum(x => x.LeaveTotal);
|
||||
else
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -441,7 +443,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
|
||||
if (data.Count > 0)
|
||||
return data.Sum(x => x.LeaveTotal);
|
||||
else
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
private readonly HolidayRepository _holidayRepository;
|
||||
private readonly CommandRepository _commandRepository;
|
||||
|
||||
private const string APPROVE_STEP_CREATE = "st1";
|
||||
private const string APPROVE_STEP_OFFICER_APPROVE = "st2";
|
||||
private const string APPROVE_STEP_COMMANDER_APPROVE = "st3";
|
||||
private const string APPROVE_STEP_APPROVE = "st4";
|
||||
private const string APPROVE_STEP_REJECT = "st5";
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constuctor and Destructor "
|
||||
|
|
@ -133,6 +139,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
LeaveSalaryText = req.LeaveSalaryText ?? "",
|
||||
LeaveStatus = "NEW",
|
||||
KeycloakUserId = userId,
|
||||
ApproveStep = APPROVE_STEP_CREATE
|
||||
};
|
||||
|
||||
// get leave last
|
||||
|
|
@ -909,6 +916,15 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(rawData.KeycloakUserId,
|
||||
rawData.Type.Id);
|
||||
|
||||
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
|
||||
var approver = string.Empty;
|
||||
if (rootOc != null)
|
||||
{
|
||||
var list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty);
|
||||
if (list.Count > 0)
|
||||
approver = list.First().Name;
|
||||
}
|
||||
|
||||
var result = new GetLeaveRequestForAdminByIdDto
|
||||
{
|
||||
Id = rawData.Id,
|
||||
|
|
@ -928,8 +944,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
LeaveAddress = rawData.LeaveAddress,
|
||||
LeaveNumber = rawData.LeaveNumber,
|
||||
LeaveDetail = rawData.LeaveDetail,
|
||||
LeaveDocument = await _minIOService.ImagesPath(rawData.LeaveDocument.Id),
|
||||
LeaveDraftDocument = await _minIOService.ImagesPath(rawData.LeaveDraftDocument.Id),
|
||||
LeaveDocument = rawData.LeaveDocument == null ? "" : await _minIOService.ImagesPath(rawData.LeaveDocument.Id),
|
||||
LeaveDraftDocument = rawData.LeaveDraftDocument == null ? "" : await _minIOService.ImagesPath(rawData.LeaveDraftDocument.Id),
|
||||
|
||||
LeaveLastStart = lastLeaveRequest == null ? null : lastLeaveRequest.LeaveStartDate,
|
||||
LeaveLastEnd = lastLeaveRequest == null ? null : lastLeaveRequest.LeaveEndDate,
|
||||
|
|
@ -976,6 +992,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
CoupleDayStartDateHistory = rawData.CoupleDayStartDateHistory,
|
||||
CoupleDayEndDateHistory = rawData.CoupleDayEndDateHistory,
|
||||
CoupleDaySumTotalHistory = rawData.CoupleDaySumTotalHistory,
|
||||
|
||||
Dear = approver,
|
||||
ApproveStep = rawData.ApproveStep ?? "-",
|
||||
};
|
||||
|
||||
return Success(result);
|
||||
|
|
|
|||
|
|
@ -121,5 +121,9 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
|
|||
public DateTime CoupleDayEndDateHistory { get; set; } = DateTime.Now;
|
||||
|
||||
public string CoupleDaySumTotalHistory { get; set; } = string.Empty;
|
||||
|
||||
public string Dear { get; set; } = string.Empty;
|
||||
|
||||
public string ApproveStep { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue