ปรับการคำนวนวันหยุดนักขัตฤกษ์ และสุดสัปดาห์ ตามการตั้งค่าปฏิทินการทำงาน
This commit is contained in:
parent
77410d9fa3
commit
d6807710d9
2 changed files with 39 additions and 11 deletions
|
|
@ -1557,3 +1557,4 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
using Swashbuckle.AspNetCore.Annotations;
|
using Swashbuckle.AspNetCore.Annotations;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using BMA.EHR.Application.Repositories.Commands;
|
using BMA.EHR.Application.Repositories.Commands;
|
||||||
|
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||||
|
|
||||||
namespace BMA.EHR.Leave.Service.Controllers
|
namespace BMA.EHR.Leave.Service.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -35,6 +36,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
private readonly MinIOLeaveService _minIOService;
|
private readonly MinIOLeaveService _minIOService;
|
||||||
private readonly HolidayRepository _holidayRepository;
|
private readonly HolidayRepository _holidayRepository;
|
||||||
private readonly CommandRepository _commandRepository;
|
private readonly CommandRepository _commandRepository;
|
||||||
|
private readonly UserCalendarRepository _userCalendarRepository;
|
||||||
|
|
||||||
private const string APPROVE_STEP_CREATE = "st1";
|
private const string APPROVE_STEP_CREATE = "st1";
|
||||||
private const string APPROVE_STEP_OFFICER_APPROVE = "st2";
|
private const string APPROVE_STEP_OFFICER_APPROVE = "st2";
|
||||||
|
|
@ -55,7 +57,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
LeaveRequestRepository leaveRequestRepository,
|
LeaveRequestRepository leaveRequestRepository,
|
||||||
MinIOLeaveService minIOService,
|
MinIOLeaveService minIOService,
|
||||||
HolidayRepository holidayRepository,
|
HolidayRepository holidayRepository,
|
||||||
CommandRepository commandRepository)
|
CommandRepository commandRepository,
|
||||||
|
UserCalendarRepository userCalendarRepository)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
|
@ -67,6 +70,7 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
_minIOService = minIOService;
|
_minIOService = minIOService;
|
||||||
_holidayRepository = holidayRepository;
|
_holidayRepository = holidayRepository;
|
||||||
_commandRepository = commandRepository;
|
_commandRepository = commandRepository;
|
||||||
|
_userCalendarRepository = userCalendarRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -118,6 +122,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
||||||
|
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
||||||
|
|
||||||
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
|
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
|
||||||
if (leaveType == null)
|
if (leaveType == null)
|
||||||
{
|
{
|
||||||
|
|
@ -125,8 +132,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
var sumLeave = req.LeaveStartDate.DiffDay(req.LeaveEndDate);
|
var sumLeave = req.LeaveStartDate.DiffDay(req.LeaveEndDate);
|
||||||
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(req.LeaveStartDate, req.LeaveEndDate);
|
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(req.LeaveStartDate, req.LeaveEndDate, category);
|
||||||
var sumWeekend = _holidayRepository.GetWeekEndCount(req.LeaveStartDate, req.LeaveEndDate);
|
var sumWeekend = _holidayRepository.GetWeekEndCount(req.LeaveStartDate, req.LeaveEndDate, category);
|
||||||
|
|
||||||
var leaveTotal = 0.0;
|
var leaveTotal = 0.0;
|
||||||
if (req.LeaveRange != "ALL")
|
if (req.LeaveRange != "ALL")
|
||||||
|
|
@ -328,6 +335,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
||||||
|
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
||||||
|
|
||||||
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
|
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
|
||||||
if (leaveType == null)
|
if (leaveType == null)
|
||||||
{
|
{
|
||||||
|
|
@ -335,8 +345,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
var sumLeave = req.LeaveStartDate.DiffDay(req.LeaveEndDate);
|
var sumLeave = req.LeaveStartDate.DiffDay(req.LeaveEndDate);
|
||||||
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(req.LeaveStartDate, req.LeaveEndDate);
|
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(req.LeaveStartDate, req.LeaveEndDate, category);
|
||||||
var sumWeekend = _holidayRepository.GetWeekEndCount(req.LeaveStartDate, req.LeaveEndDate);
|
var sumWeekend = _holidayRepository.GetWeekEndCount(req.LeaveStartDate, req.LeaveEndDate, category);
|
||||||
|
|
||||||
var leaveTotal = 0.0;
|
var leaveTotal = 0.0;
|
||||||
if (req.LeaveRange != "ALL")
|
if (req.LeaveRange != "ALL")
|
||||||
|
|
@ -593,17 +603,28 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
public async Task<ActionResult<ResponseObject>> CheckUserLeaveAsync([FromBody] GetLeaveCheckDto req)
|
public async Task<ActionResult<ResponseObject>> CheckUserLeaveAsync([FromBody] GetLeaveCheckDto req)
|
||||||
{
|
{
|
||||||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||||
|
|
||||||
|
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId);
|
||||||
|
|
||||||
|
if (profile == null)
|
||||||
|
{
|
||||||
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
|
var leaveType = await _leaveTypeRepository.GetByIdAsync(req.Type);
|
||||||
if (leaveType == null)
|
if (leaveType == null)
|
||||||
{
|
{
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
||||||
|
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
||||||
|
|
||||||
var sumLeave =
|
var sumLeave =
|
||||||
await _leaveRequestRepository.GetSumLeaveByTypeForUserAsync(userId, req.Type, req.StartLeaveDate.Year);
|
await _leaveRequestRepository.GetSumLeaveByTypeForUserAsync(userId, req.Type, req.StartLeaveDate.Year);
|
||||||
var sumWorkDay = await _holidayRepository.GetHolidayCountAsync(req.StartLeaveDate, req.EndLeaveDate);
|
var sumWorkDay = await _holidayRepository.GetHolidayCountAsync(req.StartLeaveDate, req.EndLeaveDate, category);
|
||||||
var totalDay = req.StartLeaveDate.DiffDay(req.EndLeaveDate);
|
var totalDay = req.StartLeaveDate.DiffDay(req.EndLeaveDate);
|
||||||
var sumWeekend = _holidayRepository.GetWeekEndCount(req.StartLeaveDate, req.EndLeaveDate);
|
var sumWeekend = _holidayRepository.GetWeekEndCount(req.StartLeaveDate, req.EndLeaveDate, category);
|
||||||
|
|
||||||
var isLeave = sumLeave + (totalDay - sumWorkDay) <= leaveType.Limit;
|
var isLeave = sumLeave + (totalDay - sumWorkDay) <= leaveType.Limit;
|
||||||
|
|
||||||
|
|
@ -745,6 +766,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
||||||
|
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
||||||
|
|
||||||
var lastSalary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
var lastSalary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
||||||
var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0;
|
var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0;
|
||||||
|
|
||||||
|
|
@ -753,8 +777,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
rawData.Type.Id);
|
rawData.Type.Id);
|
||||||
|
|
||||||
var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
|
var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
|
||||||
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate);
|
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
|
||||||
var sumWeekend = _holidayRepository.GetWeekEndCount(rawData.LeaveStartDate, rawData.LeaveEndDate);
|
var sumWeekend = _holidayRepository.GetWeekEndCount(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
|
||||||
|
|
||||||
var result = new GetLeaveRequestByIdDto
|
var result = new GetLeaveRequestByIdDto
|
||||||
{
|
{
|
||||||
|
|
@ -1201,6 +1225,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var userCalendar = await _userCalendarRepository.GetExist(profile.Id);
|
||||||
|
var category = userCalendar == null ? "NORMAL" : userCalendar.Calendar;
|
||||||
|
|
||||||
var lastSalary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
var lastSalary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
|
||||||
var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0;
|
var lastSalaryAmount = lastSalary == null ? 0 : lastSalary.Amount ?? 0;
|
||||||
|
|
||||||
|
|
@ -1220,8 +1247,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveByTypeForUserAsync(userId, rawData.Type.Id, thisYear);
|
var leaveSummary = await _leaveRequestRepository.GetSumApproveLeaveByTypeForUserAsync(userId, rawData.Type.Id, thisYear);
|
||||||
|
|
||||||
var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
|
var sumLeave = rawData.LeaveStartDate.DiffDay(rawData.LeaveEndDate);
|
||||||
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate);
|
var sumHoliday = await _holidayRepository.GetHolidayCountAsync(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
|
||||||
var sumWeekend = _holidayRepository.GetWeekEndCount(rawData.LeaveStartDate, rawData.LeaveEndDate);
|
var sumWeekend = _holidayRepository.GetWeekEndCount(rawData.LeaveStartDate, rawData.LeaveEndDate, category);
|
||||||
|
|
||||||
var result = new GetLeaveRequestForAdminByIdDto
|
var result = new GetLeaveRequestForAdminByIdDto
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue