แก้ defect
add send noti when create ลงเวลากรณีพิเศษ
This commit is contained in:
parent
bb637bca36
commit
ee4ef41547
8 changed files with 144 additions and 12 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using BMA.EHR.Domain.Models.Base;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.IO.Pipes;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories.Leaves
|
||||
|
|
@ -24,7 +25,6 @@ namespace BMA.EHR.Application.Repositories.Leaves
|
|||
_dbContext = dbContext;
|
||||
_dbSet = _dbContext.Set<T>();
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return await rawData.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<LeaveRequest>> GetLeaveRequestForAdminAsync(int year, Guid type, string status)
|
||||
public async Task<List<LeaveRequest>> GetLeaveRequestForAdminAsync(int year, Guid type, string status, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var rawData = _dbContext.Set<LeaveRequest>()
|
||||
.Include(x => x.Type)
|
||||
|
|
@ -164,6 +164,12 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
if (status.Trim().ToUpper() != "ALL")
|
||||
rawData = rawData.Where(x => x.LeaveStatus == status);
|
||||
|
||||
if (startDate != DateTime.MinValue)
|
||||
rawData = rawData.Where(x => x.LeaveStartDate >= startDate);
|
||||
|
||||
if (endDate != DateTime.MinValue)
|
||||
rawData = rawData.Where(x => x.LeaveEndDate <= endDate);
|
||||
|
||||
return await rawData.ToListAsync();
|
||||
}
|
||||
|
||||
|
|
@ -570,7 +576,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date == startDate.Date || x.LeaveEndDate.Date == endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "DELETE" && x.LeaveStatus == "REJECT")
|
||||
.Where(x => x.LeaveStatus == "NEW" || x.LeaveStatus == "PENDING" || x.LeaveStatus == "APPROVE")
|
||||
.ToListAsync();
|
||||
|
||||
return data.Count > 0;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Messaging;
|
||||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Responses;
|
||||
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
|
||||
using BMA.EHR.Domain.Models.Notifications;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
@ -18,6 +21,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
private readonly UserProfileRepository _userProfileRepository;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly EmailSenderService _emailSenderService;
|
||||
private readonly IApplicationDBContext _appContext;
|
||||
private readonly CommandRepository _commandRepository;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -28,7 +33,9 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
OrganizationCommonRepository organizationCommonRepository,
|
||||
UserProfileRepository userProfileRepository,
|
||||
IConfiguration configuration,
|
||||
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
|
||||
EmailSenderService emailSenderService,
|
||||
IApplicationDBContext appContext,
|
||||
CommandRepository commandRepository) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
|
@ -36,6 +43,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
_userProfileRepository = userProfileRepository;
|
||||
_configuration = configuration;
|
||||
_emailSenderService = emailSenderService;
|
||||
_appContext = appContext;
|
||||
_commandRepository = commandRepository;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -57,6 +66,57 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
|
||||
#region " Methods "
|
||||
|
||||
public override async Task<AdditionalCheckRequest> AddAsync(AdditionalCheckRequest entity)
|
||||
{
|
||||
await base.AddAsync(entity);
|
||||
|
||||
var userId = UserId != null ? Guid.Parse(UserId) : Guid.Empty;
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId);
|
||||
var profile_id = profile == null ? Guid.Empty : profile.Id;
|
||||
|
||||
var rootOc = _userProfileRepository.GetRootOcId(profile_id);
|
||||
var approver = string.Empty;
|
||||
var list = new List<OrganizationApproverResponse>();
|
||||
if (rootOc != null)
|
||||
{
|
||||
list = await _commandRepository.GetOrgApproverAsync(rootOc ?? Guid.Empty);
|
||||
}
|
||||
if (list.Count > 0)
|
||||
{
|
||||
var appr = list.FirstOrDefault();
|
||||
|
||||
// send inbox and notification
|
||||
var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ";
|
||||
var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix.Name}{profile.FirstName} {profile.LastName}";
|
||||
|
||||
var subject = subject_str;
|
||||
var body = body_str;
|
||||
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
|
||||
|
||||
|
||||
var inbox = new Inbox
|
||||
{
|
||||
Subject = subject_str,
|
||||
Body = body_str,
|
||||
ReceiverUserId = appr.Id,
|
||||
Payload = "",
|
||||
};
|
||||
_appContext.Set<Inbox>().Add(inbox);
|
||||
|
||||
var noti = new Notification
|
||||
{
|
||||
Body = body_str,
|
||||
ReceiverUserId = appr.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_appContext.Set<Notification>().Add(noti);
|
||||
await _appContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<List<AdditionalCheckRequest>> GetAdditionalCheckRequestsByUserId(Guid keycloakId, int year, int month)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Domain.Models.HR;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Organizations;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
|
@ -29,7 +30,29 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
#region " Methods "
|
||||
|
||||
public async Task<OrganizationEntity?> GetOrganizationById(Guid id)
|
||||
{
|
||||
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<OrganizationAgency?> GetOrgAgencyById(Guid id)
|
||||
{
|
||||
var data = await _dbContext.Set<OrganizationAgency>().AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<OrganizationGovernmentAgency?> GetOrgGovAgencyById(Guid id)
|
||||
{
|
||||
var data = await _dbContext.Set<OrganizationGovernmentAgency>().AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<Profile?> GetProfileByKeycloakIdAsync(Guid keycloakId)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue