leave report

This commit is contained in:
Suphonchai Phoonsawat 2025-09-02 14:55:07 +07:00
parent 3ae9be5869
commit 8001dd0c11
12 changed files with 678 additions and 244 deletions

View file

@ -6,29 +6,17 @@ using BMA.EHR.Application.Repositories.MetaData;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Leave.Commons;
using BMA.EHR.Domain.Models.Leave.Requests;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.ModelsExam.Candidate;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Leave.Service.DTOs.Reports;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Any;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Ocsp;
using Sentry;
using OfficeOpenXml;
using Swashbuckle.AspNetCore.Annotations;
using System.Diagnostics.Eventing.Reader;
using System.Diagnostics.Metrics;
using System.Globalization;
using System.Security.Claims;
using static Nest.JoinField;
using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml;
using Microsoft.AspNetCore.Routing.Template;
namespace BMA.EHR.Leave.Service.Controllers
{
[Route("api/v{version:apiVersion}/leave/report")]
@ -1000,6 +988,8 @@ namespace BMA.EHR.Leave.Service.Controllers
var leaveDays = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRange(req.StartDate, req.EndDate);
var leaveTypes = await _leaveTypeRepository.GetAllAsync();
var count = 1;
var employees = new List<dynamic>();
// กรองตามที่ fe ส่งมา
@ -1009,122 +999,327 @@ namespace BMA.EHR.Leave.Service.Controllers
.Where(x => req.node == 4 ? x.OrgChild4Id == req.nodeId : req.node == 3 ? x.OrgChild3Id == req.nodeId : req.node == 2 ? x.OrgChild2Id == req.nodeId : req.node == 1 ? x.OrgChild1Id == req.nodeId : req.node == 0 ? x.OrgRootId == req.nodeId : true)
.ToList();
}
var reportType = req!.Type!.Trim().ToUpper();
var year = req.EndDate.Year;
var profileList = profile.Select(x => new ProfileData
{
Id = x.Id,
Prefix = x.Prefix ?? "",
FirstName = x.FirstName ?? "",
LastName = x.LastName ?? "",
DateStart = x.DateStart ?? x.DateAppoint,
}).Distinct().ToList();
var beginningData = await _leaveBeginningRepository.GetAllByYearAsync(year);
// sum all user
//var sickDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-001")?.Id ?? Guid.Empty, profileList!);
//var personalDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-002")?.Id ?? Guid.Empty, profileList!);
//var maternityDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-003")?.Id ?? Guid.Empty, profileList!);
//var wifeDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-004")?.Id ?? Guid.Empty, profileList!);
//var restDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-005")?.Id ?? Guid.Empty, profileList!);
//var ordainDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-006")?.Id ?? Guid.Empty, profileList!);
//var absentDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-007")?.Id ?? Guid.Empty, profileList!);
//var studyDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-008")?.Id ?? Guid.Empty, profileList!);
//var agencyDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-009")?.Id ?? Guid.Empty, profileList!);
//var coupleDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-010")?.Id ?? Guid.Empty, profileList!);
//var therapyDaySumALL = await _leaveBeginningRepository.GetAllByYearAndTypeAsync(year, leaveTypes.FirstOrDefault(x => x.Code == "LV-011")?.Id ?? Guid.Empty, profileList!);
foreach (var p in profile)
{
var keycloakUserId = p.Keycloak ?? Guid.Empty;
var sickDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-001");
var sickDayCount = sickDay != null ? sickDay.SumLeaveDay : 0;
var personalDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-002");
var personalDayCount = personalDay != null ? personalDay.SumLeaveDay : 0;
var maternityDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-003");
var maternityDayCount = maternityDay != null ? maternityDay.SumLeaveDay : 0;
var wifeDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-004");
var wifeDayCount = wifeDay != null ? wifeDay.SumLeaveDay : 0;
var restDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-005");
var restDayCount = restDay != null ? restDay.SumLeaveDay : 0;
var ordainDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-006");
var ordainDayCount = ordainDay != null ? ordainDay.SumLeaveDay : 0;
var absentDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-007");
var absentDayCount = absentDay != null ? absentDay.SumLeaveDay : 0;
var studyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-008");
var studyDayCount = studyDay != null ? studyDay.SumLeaveDay : 0;
var agencyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-009");
var agencyDayCount = agencyDay != null ? agencyDay.SumLeaveDay : 0;
var coupleDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-010");
var coupleDayCount = coupleDay != null ? coupleDay.SumLeaveDay : 0;
var therapyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-011");
var therapyDayCount = therapyDay != null ? therapyDay.SumLeaveDay : 0;
var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.Keycloak ?? Guid.Empty, req.StartDate, req.EndDate);
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
if (defaultRound == null)
if (reportType == "FULL")
{
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
var sickDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-001");
var sickDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-001");
var sickDayCount = sickDaySum != null ? sickDaySum.LeaveDaysUsed : 0;
var sickCount = sickDay != null ? sickDay.CountLeaveDay : 0;
var personalDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-002");
var personalDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-002");
var personalDayCount = personalDaySum != null ? personalDaySum.LeaveDaysUsed : 0;
var personalCount = personalDay != null ? personalDay.CountLeaveDay : 0;
var maternityDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-003");
var maternityDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-003");
var maternityDayCount = maternityDaySum != null ? maternityDaySum.LeaveDaysUsed : 0;
var maternityCount = maternityDay != null ? maternityDay.CountLeaveDay : 0;
var wifeDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-004");
var wifeDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-004");
var wifeDayCount = wifeDaySum != null ? wifeDaySum.LeaveDaysUsed : 0;
var wifeCount = wifeDay != null ? wifeDay.CountLeaveDay : 0;
var restDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-005");
var restDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-005");
var restDayCount = restDaySum != null ? restDaySum.LeaveDaysUsed : 0;
var restCount = restDay != null ? restDay.CountLeaveDay : 0;
var ordainDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-006");
var ordainDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-006");
var ordainDayCount = ordainDaySum != null ? ordainDaySum.LeaveDaysUsed : 0;
var ordainCount = ordainDay != null ? ordainDay.CountLeaveDay : 0;
var absentDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-007");
var absentDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-007");
var absentDayCount = absentDaySum != null ? absentDaySum.LeaveDaysUsed : 0;
var absentCount = absentDay != null ? absentDay.CountLeaveDay : 0;
var studyDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-008");
var studyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-008");
var studyDayCount = studyDaySum != null ? studyDaySum.LeaveDaysUsed : 0;
var studyCount = studyDay != null ? studyDay.CountLeaveDay : 0;
var agencyDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-009");
var agencyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-009");
var agencyDayCount = agencyDaySum != null ? agencyDaySum.LeaveDaysUsed : 0;
var agencyCount = agencyDay != null ? agencyDay.CountLeaveDay : 0;
var coupleDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-010");
var coupleDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-010");
var coupleDayCount = coupleDaySum != null ? coupleDaySum.LeaveDaysUsed : 0;
var coupleCount = coupleDay != null ? coupleDay.CountLeaveDay : 0;
var therapyDaySum = beginningData.FirstOrDefault(x => x.ProfileId == p.Id && x.LeaveType.Code == "LV-011");
var therapyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-011");
var therapyDayCount = therapyDaySum != null ? therapyDaySum.LeaveDaysUsed : 0;
var therapyCount = therapyDay != null ? therapyDay.CountLeaveDay : 0;
var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.Keycloak ?? Guid.Empty, req.StartDate, req.EndDate);
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;
/* var processTimeStamps = timeStamps
.Select(d => new
{
d.Id,
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
"LATE" :
"NORMAL",
CheckOutStatus = d.CheckOut == null ? "" :
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
"LATE" :
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ?
"ABSENT" :
"NORMAL",
});*/
/*var absentCount = processTimeStamps.Count(x => x.CheckOutStatus == "ABSENT");
var lateCount = processTimeStamps.Count(x => x.CheckInStatus == "LATE");*/
var absentCount1 = timeStamps.Count(d =>
d.CheckOutStatus == "ABSENT" || d.CheckInStatus == "ABSENT"); // นับจำนวนที่มี CheckOutStatus == "ABSENT"
var lateCount1 = timeStamps.Count(d =>
d.CheckInStatus == "LATE"); // นับจำนวนที่มี CheckInStatus == "LATE"
var emp = new
{
no = count,
fullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
position = p.Position == null ? "" : p.Position,
positionLevel = p.PositionLevel == null ? "" : p.PositionLevel,
posNo = p.PosNo == null ? "" : p.PosNo,
reason = "",
sickDayCount = sickDayCount,
maternityDayCount = maternityDayCount,
wifeDayCount = wifeDayCount,
personalDayCount = personalDayCount,
restDayCount = restDayCount,
ordainDayCount = ordainDayCount,
absentDayCount = absentDayCount,
studyDayCount = studyDayCount,
agencyDayCount = agencyDayCount,
coupleDayCount = coupleDayCount,
therapyDayCount = therapyDayCount,
absentTotal = absentCount1,
lateTotal = lateCount1,
sickCount = sickCount,
maternityCount = maternityCount,
wifeCount = wifeCount,
personalCount = personalCount,
restCount = restCount,
ordainCount = ordainCount,
absentCount = absentCount,
studyCount = studyCount,
agencyCount = agencyCount,
coupleCount = coupleCount,
therapyCount = therapyCount,
leaveTotal = sickCount +
maternityCount +
wifeCount +
personalCount +
restCount +
ordainCount +
absentCount +
studyCount +
agencyCount +
coupleCount +
therapyCount
};
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 processTimeStamps = timeStamps
.Select(d => new
{
d.Id,
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
"LATE" :
"NORMAL",
CheckOutStatus = d.CheckOut == null ? "" :
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
"LATE" :
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ?
"ABSENT" :
"NORMAL",
});*/
/*var absentCount = processTimeStamps.Count(x => x.CheckOutStatus == "ABSENT");
var lateCount = processTimeStamps.Count(x => x.CheckInStatus == "LATE");*/
var absentCount = timeStamps.Count(d =>
d.CheckOutStatus == "ABSENT"); // นับจำนวนที่มี CheckOutStatus == "ABSENT"
var lateCount = timeStamps.Count(d =>
d.CheckInStatus == "LATE"); // นับจำนวนที่มี CheckInStatus == "LATE"
var emp = new
else
{
no = count,
fullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
position = p.Position == null ? "" : p.Position,
positionLevel = p.PositionLevel == null ? "" : p.PositionLevel,
posNo = p.PosNo == null ? "" : p.PosNo,
reason = "",
sickDayCount = sickDayCount,
maternityDayCount = maternityDayCount,
wifeDayCount = wifeDayCount,
personalDayCount = personalDayCount,
restDayCount = restDayCount,
ordainDayCount = ordainDayCount,
absentDayCount = absentDayCount,
studyDayCount = studyDayCount,
agencyDayCount = agencyDayCount,
coupleDayCount = coupleDayCount,
therapyDayCount = therapyDayCount,
absentTotal = absentCount,
lateTotal = lateCount,
leaveTotal = sickDayCount +
maternityDayCount +
wifeDayCount +
personalDayCount +
restDayCount +
ordainDayCount +
absentDayCount +
studyDayCount +
agencyDayCount +
coupleDayCount +
therapyDayCount
};
var sickDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-001");
var sickDayCount = sickDay != null ? sickDay.SumLeaveDay : 0;
var sickCount = sickDay != null ? sickDay.CountLeaveDay : 0;
employees.Add(emp);
count++;
var personalDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-002");
var personalDayCount = personalDay != null ? personalDay.SumLeaveDay : 0;
var personalCount = personalDay != null ? personalDay.CountLeaveDay : 0;
var maternityDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-003");
var maternityDayCount = maternityDay != null ? maternityDay.SumLeaveDay : 0;
var maternityCount = maternityDay != null ? maternityDay.CountLeaveDay : 0;
var wifeDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-004");
var wifeDayCount = wifeDay != null ? wifeDay.SumLeaveDay : 0;
var wifeCount = wifeDay != null ? wifeDay.CountLeaveDay : 0;
var restDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-005");
var restDayCount = restDay != null ? restDay.SumLeaveDay : 0;
var restCount = restDay != null ? restDay.CountLeaveDay : 0;
var ordainDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-006");
var ordainDayCount = ordainDay != null ? ordainDay.SumLeaveDay : 0;
var ordainCount = ordainDay != null ? ordainDay.CountLeaveDay : 0;
var absentDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-007");
var absentDayCount = absentDay != null ? absentDay.SumLeaveDay : 0;
var absentCount = absentDay != null ? absentDay.CountLeaveDay : 0;
var studyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-008");
var studyDayCount = studyDay != null ? studyDay.SumLeaveDay : 0;
var studyCount = studyDay != null ? studyDay.CountLeaveDay : 0;
var agencyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-009");
var agencyDayCount = agencyDay != null ? agencyDay.SumLeaveDay : 0;
var agencyCount = agencyDay != null ? agencyDay.CountLeaveDay : 0;
var coupleDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-010");
var coupleDayCount = coupleDay != null ? coupleDay.SumLeaveDay : 0;
var coupleCount = coupleDay != null ? coupleDay.CountLeaveDay : 0;
var therapyDay = leaveDays.FirstOrDefault(x => x.KeycloakUserId == keycloakUserId && x.LeaveTypeCode == "LV-011");
var therapyDayCount = therapyDay != null ? therapyDay.SumLeaveDay : 0;
var therapyCount = therapyDay != null ? therapyDay.CountLeaveDay : 0;
var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.Keycloak ?? Guid.Empty, req.StartDate, req.EndDate);
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;
/* var processTimeStamps = timeStamps
.Select(d => new
{
d.Id,
CheckInStatus = DateTime.Parse(d.CheckIn.ToString("yyyy-MM-dd HH:mm")) >
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}") ?
"LATE" :
"NORMAL",
CheckOutStatus = d.CheckOut == null ? "" :
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}") ?
"LATE" :
DateTime.Parse(d.CheckOut.Value.ToString("yyyy-MM-dd HH:mm")) <
DateTime.Parse($"{d.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.EndTimeMorning}") ?
"ABSENT" :
"NORMAL",
});*/
/*var absentCount = processTimeStamps.Count(x => x.CheckOutStatus == "ABSENT");
var lateCount = processTimeStamps.Count(x => x.CheckInStatus == "LATE");*/
var absentCount2 = timeStamps.Count(d =>
d.CheckOutStatus == "ABSENT" || d.CheckInStatus == "ABSENT"); // นับจำนวนที่มี CheckOutStatus == "ABSENT"
var lateCount2 = timeStamps.Count(d =>
d.CheckInStatus == "LATE"); // นับจำนวนที่มี CheckInStatus == "LATE"
var emp = new
{
no = count,
fullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
position = p.Position == null ? "" : p.Position,
positionLevel = p.PositionLevel == null ? "" : p.PositionLevel,
posNo = p.PosNo == null ? "" : p.PosNo,
reason = "",
sickDayCount = sickDayCount,
maternityDayCount = maternityDayCount,
wifeDayCount = wifeDayCount,
personalDayCount = personalDayCount,
restDayCount = restDayCount,
ordainDayCount = ordainDayCount,
absentDayCount = absentDayCount,
studyDayCount = studyDayCount,
agencyDayCount = agencyDayCount,
coupleDayCount = coupleDayCount,
therapyDayCount = therapyDayCount,
absentTotal = absentCount2,
lateTotal = lateCount2,
sickCount = sickCount,
maternityCount = maternityCount,
wifeCount = wifeCount,
personalCount = personalCount,
restCount = restCount,
ordainCount = ordainCount,
absentCount = absentCount,
studyCount = studyCount,
agencyCount = agencyCount,
coupleCount = coupleCount,
therapyCount = therapyCount,
leaveTotal = sickCount +
maternityCount +
wifeCount +
personalCount +
restCount +
ordainCount +
absentCount +
studyCount +
agencyCount +
coupleCount +
therapyCount
};
employees.Add(emp);
count++;
}
}
var leaveTitleType = "";
@ -1983,7 +2178,7 @@ namespace BMA.EHR.Leave.Service.Controllers
worksheet.Cells[2, 1].Value = organizationName;
worksheet.Cells[3, 1].Value = dateTimeStamp;
using (var range = worksheet.Cells[4, 1 ,4, 10])
using (var range = worksheet.Cells[4, 1, 4, 10])
{
range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
@ -2020,7 +2215,7 @@ namespace BMA.EHR.Leave.Service.Controllers
}
// ใส่กรอบให้ตาราง
using (var range = worksheet.Cells[5, 1, startRow-1, 10])
using (var range = worksheet.Cells[5, 1, startRow - 1, 10])
{
range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;