แก้รายงานการแสดงวันลา
This commit is contained in:
parent
c0d7aa92cc
commit
34da86653f
4 changed files with 224 additions and 49 deletions
|
|
@ -3,6 +3,7 @@ using BMA.EHR.Application.Repositories;
|
|||
using BMA.EHR.Application.Repositories.Commands;
|
||||
using BMA.EHR.Application.Repositories.Leaves.LeaveRequests;
|
||||
using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
|
||||
using BMA.EHR.Application.Repositories.MetaData;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.Leave.Requests;
|
||||
|
|
@ -12,6 +13,7 @@ using BMA.EHR.Infrastructure.Persistence;
|
|||
using BMA.EHR.Leave.Service.DTOs.Reports;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Leave.Service.Controllers
|
||||
|
|
@ -32,6 +34,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
private readonly ProcessUserTimeStampRepository _processUserTimeStampRepository;
|
||||
private readonly DutyTimeRepository _dutyTimeRepository;
|
||||
private readonly UserDutyTimeRepository _userDutyTimeRepository;
|
||||
private readonly HolidayRepository _holidayRepository;
|
||||
private readonly UserCalendarRepository _userCalendarRepository;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -43,7 +47,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
LeaveTypeRepository leaveTypeRepository,
|
||||
ProcessUserTimeStampRepository processUserTimeStampRepository,
|
||||
DutyTimeRepository dutyTimeRepository,
|
||||
UserDutyTimeRepository userDutyTimeRepository)
|
||||
UserDutyTimeRepository userDutyTimeRepository,
|
||||
HolidayRepository holidayRepository,
|
||||
UserCalendarRepository userCalendarRepository)
|
||||
{
|
||||
_leaveRequestRepository = leaveRequestRepository;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
|
|
@ -52,6 +58,8 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
_processUserTimeStampRepository = processUserTimeStampRepository;
|
||||
_dutyTimeRepository = dutyTimeRepository;
|
||||
_userDutyTimeRepository = userDutyTimeRepository;
|
||||
_holidayRepository = holidayRepository;
|
||||
_userCalendarRepository = userCalendarRepository;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -1096,54 +1104,155 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
var profile = await _userProfileRepository.GetProfileWithKeycloak();
|
||||
var date = req.StartDate.Date;
|
||||
|
||||
var holidays = await _holidayRepository.GetHolidayAsync(req.StartDate.Date, req.EndDate.Date);
|
||||
var weekend = _holidayRepository.GetWeekEnd(req.StartDate.Date, req.EndDate.Date);
|
||||
var excludeDates = holidays.Union(weekend).ToList();
|
||||
|
||||
var dateList = new List<DateTime>();
|
||||
|
||||
for (DateTime i = req.StartDate.Date; i <= req.EndDate.Date; i = i.AddDays(1))
|
||||
{
|
||||
if (!excludeDates.Contains(i))
|
||||
dateList.Add(i);
|
||||
}
|
||||
|
||||
var employees = new List<dynamic>();
|
||||
var count = 1;
|
||||
|
||||
var restTotal = 0;
|
||||
var sickTotal = 0;
|
||||
var lateTotal = 0;
|
||||
var wfhTotal = 0;
|
||||
var studyTotal = 0;
|
||||
|
||||
|
||||
|
||||
foreach (var p in profile)
|
||||
{
|
||||
var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(p.KeycloakId ?? Guid.Empty, date);
|
||||
|
||||
var fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty);
|
||||
|
||||
|
||||
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||
if (defaultRound == null)
|
||||
foreach (var dd in dateList)
|
||||
{
|
||||
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
|
||||
var keycloakUserId = p.KeycloakId ?? Guid.Empty;
|
||||
|
||||
var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(keycloakUserId, dd);
|
||||
|
||||
var fullName = _userProfileRepository.GetUserFullName(keycloakUserId);
|
||||
|
||||
|
||||
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||
if (defaultRound == null)
|
||||
{
|
||||
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
|
||||
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
||||
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||
|
||||
var duty = userRound ?? defaultRound;
|
||||
|
||||
// check วันลาของแต่ละคน
|
||||
var leaveReq = await _leaveRequestRepository.GetLeavePeriodAsync(keycloakUserId, dd);
|
||||
var remarkStr = string.Empty;
|
||||
|
||||
if (leaveReq != null)
|
||||
{
|
||||
switch (leaveReq.Type.Code.ToUpper())
|
||||
{
|
||||
case "LV-001":
|
||||
case "LV-002":
|
||||
case "LV-005":
|
||||
remarkStr += leaveReq.Type.Name;
|
||||
var leaveRange = leaveReq.LeaveRange == null ? "" : leaveReq.LeaveRange.ToUpper();
|
||||
if (leaveRange == "MORNING")
|
||||
remarkStr += "ครึ่งวันเช้า";
|
||||
else if (leaveRange == "AFTERNOON")
|
||||
remarkStr += "ครึ่งวันบ่าย";
|
||||
break;
|
||||
default:
|
||||
remarkStr += leaveReq.Type.Name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeStamps == null)
|
||||
{
|
||||
remarkStr = "ขาดราชการ";
|
||||
}
|
||||
else
|
||||
{
|
||||
// check status ของการลงเวลา
|
||||
if (timeStamps.CheckOutStatus == "ABSENT")
|
||||
remarkStr = "ขาดราชการ";
|
||||
else if (timeStamps.CheckInStatus == "ABSENT")
|
||||
remarkStr = "ขาดราชการ";
|
||||
else if (timeStamps.CheckInStatus == "LATE")
|
||||
{
|
||||
remarkStr = "สาย";
|
||||
lateTotal += 1;
|
||||
}
|
||||
else
|
||||
remarkStr = "";
|
||||
}
|
||||
}
|
||||
|
||||
var emp = new
|
||||
{
|
||||
no = count,
|
||||
fullName = fullName,
|
||||
dutyTimeName = $"{duty.StartTimeMorning} - {duty.EndTimeAfternoon} น.",
|
||||
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInPOI,
|
||||
checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.ToString("HH:mm")} น.",
|
||||
|
||||
checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutPOI ?? "",
|
||||
checkOutTime = timeStamps == null ? "" :
|
||||
timeStamps.CheckOut != null ?
|
||||
$"{timeStamps.CheckOut.Value.ToString("HH:mm")} น." :
|
||||
"",
|
||||
|
||||
//remark = timeStamps == null ? "ขาดราชการ" : "",
|
||||
remark = remarkStr,
|
||||
|
||||
checkInDate = timeStamps == null ? "" : timeStamps.CheckIn.Date.ToThaiFullDate2().ToThaiNumber(),
|
||||
checkedOutDate = timeStamps == null ? "" :
|
||||
timeStamps.CheckOut != null ?
|
||||
timeStamps.CheckOut.Value.ToThaiFullDate2().ToThaiNumber() :
|
||||
"",
|
||||
};
|
||||
|
||||
if (timeStamps != null)
|
||||
{
|
||||
if (timeStamps.IsLocationCheckIn)
|
||||
wfhTotal += 1;
|
||||
else
|
||||
{
|
||||
if (leaveReq != null)
|
||||
{
|
||||
switch (leaveReq.Type.Code.ToUpper())
|
||||
{
|
||||
case "LV-001":
|
||||
case "LV-002":
|
||||
sickTotal += 1;
|
||||
break;
|
||||
case "LV-005":
|
||||
restTotal += 1;
|
||||
break;
|
||||
case "LV-008":
|
||||
studyTotal += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
employees.Add(emp);
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
|
||||
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id);
|
||||
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||
|
||||
var duty = userRound ?? defaultRound;
|
||||
|
||||
var emp = new
|
||||
{
|
||||
no = count,
|
||||
fullName = fullName,
|
||||
dutyTimeName = $"{duty.StartTimeMorning} - {duty.EndTimeAfternoon} น.",
|
||||
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInPOI,
|
||||
checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.ToString("HH:mm")} น.",
|
||||
|
||||
checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutPOI ?? "",
|
||||
checkOutTime = timeStamps == null ? "" :
|
||||
timeStamps.CheckOut != null ?
|
||||
$"{timeStamps.CheckOut.Value.ToString("HH:mm")} น." :
|
||||
"",
|
||||
|
||||
remark = timeStamps == null ? "ขาดราชการ" : "",
|
||||
|
||||
checkInDate = timeStamps == null ? "" : timeStamps.CheckIn.Date.ToThaiFullDate2().ToThaiNumber(),
|
||||
checkedOutDate = timeStamps == null ? "" :
|
||||
timeStamps.CheckOut != null ?
|
||||
timeStamps.CheckOut.Value.ToThaiFullDate2().ToThaiNumber() :
|
||||
"",
|
||||
};
|
||||
|
||||
employees.Add(emp);
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
var item = new
|
||||
|
|
@ -1151,11 +1260,11 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
DateTimeStamp = date.Date.ToThaiFullDate(),
|
||||
officerTotal = profile.Count,
|
||||
workTotal = (count - 1),
|
||||
restTotal = 0,
|
||||
sickTotal = 0,
|
||||
lateTotal = 0,
|
||||
wfhTotal = 0,
|
||||
studyTotal = 0,
|
||||
restTotal = restTotal,
|
||||
sickTotal = sickTotal,
|
||||
lateTotal = lateTotal,
|
||||
wfhTotal = wfhTotal,
|
||||
studyTotal = studyTotal,
|
||||
employees = employees
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -707,7 +707,62 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
isLeave = govAge >= 365;
|
||||
break;
|
||||
case "LV-010":
|
||||
var maxEnd = new DateTime(req.StartLeaveDate.Year + 2, req.StartLeaveDate.Month, req.StartLeaveDate.Day - 1);
|
||||
int yy, mm, dd;
|
||||
yy = req.StartLeaveDate.Year + 2;
|
||||
if (req.StartLeaveDate.Day == 1)
|
||||
{
|
||||
if (req.StartLeaveDate.Month == 1)
|
||||
{
|
||||
mm = 12;
|
||||
dd = 31;
|
||||
}
|
||||
else
|
||||
{
|
||||
mm = req.StartLeaveDate.Month - 1;
|
||||
switch (mm)
|
||||
{
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
{
|
||||
dd = 31;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (DateTime.IsLeapYear(yy))
|
||||
{
|
||||
dd = 29;
|
||||
}
|
||||
else
|
||||
dd = 28;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
{
|
||||
dd = 30;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dd = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mm = req.StartLeaveDate.Month;
|
||||
dd = req.StartLeaveDate.Day - 1;
|
||||
}
|
||||
|
||||
var maxEnd = new DateTime(yy, mm, dd);
|
||||
isLeave = req.EndLeaveDate.Date <= maxEnd;
|
||||
break;
|
||||
case "LV-011":
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace BMA.EHR.Leave.Service.DTOs.Reports
|
|||
{
|
||||
public DateTime StartDate { get; set; } = DateTime.MinValue;
|
||||
|
||||
//public DateTime EndDate { get; set; } = DateTime.MinValue;
|
||||
public DateTime EndDate { get; set; } = DateTime.MinValue;
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue