fix Report ระบบลา
This commit is contained in:
parent
ef415217c8
commit
bcbac7814d
4 changed files with 92 additions and 59 deletions
|
|
@ -56,6 +56,23 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
||||||
|
|
||||||
#region " Methods "
|
#region " Methods "
|
||||||
|
|
||||||
|
public async Task<List<Guid>> GetCheckInKeycloakId()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var data = await _dbContext.Set<ProcessUserTimeStamp>()
|
||||||
|
.Select(x => x.KeycloakUserId)
|
||||||
|
.Distinct()
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsEditRequest(Guid userId, DateTime checkDate)
|
public bool IsEditRequest(Guid userId, DateTime checkDate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,23 @@ namespace BMA.EHR.Application.Repositories
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<Profile>> GetProfileWithKeycloak()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var data = await _dbContext.Set<Profile>().AsQueryable()
|
||||||
|
.Where(x => x.ProfileType == "officer")
|
||||||
|
.Where(x => x.KeycloakId != null)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<List<Profile>> SearchProfile(string? citizenId, string? firstName, string? lastName)
|
public async Task<List<Profile>> SearchProfile(string? citizenId, string? firstName, string? lastName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -698,7 +698,9 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var profile = await _userProfileRepository.SearchProfile(null, null, null);
|
//var profile = await _userProfileRepository.SearchProfile(null, null, null);
|
||||||
|
var profile = await _userProfileRepository.GetProfileWithKeycloak();
|
||||||
|
|
||||||
var count = 1;
|
var count = 1;
|
||||||
var employees = new List<dynamic>();
|
var employees = new List<dynamic>();
|
||||||
|
|
||||||
|
|
@ -1083,77 +1085,74 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var profile = await _userProfileRepository.SearchProfile(null, null, null);
|
//var profile = await _userProfileRepository.SearchProfile(null, null, null);
|
||||||
|
var profile = await _userProfileRepository.GetProfileWithKeycloak();
|
||||||
|
var date = req.StartDate.Date;
|
||||||
|
|
||||||
var data = new List<dynamic>();
|
var employees = new List<dynamic>();
|
||||||
|
var count = 1;
|
||||||
for (DateTime date = req.StartDate.Date; date.Date <= req.EndDate.Date; date = date.AddDays(1))
|
foreach (var p in profile)
|
||||||
{
|
{
|
||||||
var employees = new List<dynamic>();
|
var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(p.KeycloakId ?? Guid.Empty, date);
|
||||||
var count = 1;
|
|
||||||
foreach (var p in profile)
|
var fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty);
|
||||||
|
|
||||||
|
|
||||||
|
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||||
|
if (defaultRound == null)
|
||||||
{
|
{
|
||||||
var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(p.KeycloakId ?? Guid.Empty, date);
|
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
|
||||||
|
|
||||||
var fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty);
|
|
||||||
|
|
||||||
|
|
||||||
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 emp = new
|
|
||||||
{
|
|
||||||
no = count,
|
|
||||||
fullName = fullName,
|
|
||||||
dutyTimeName = $"{duty.StartTimeMorning} น.",
|
|
||||||
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInLocationName,
|
|
||||||
checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.Date.ToString("HH:mm")} น.",
|
|
||||||
|
|
||||||
checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutLocationName ?? "",
|
|
||||||
checkOutTime = timeStamps == null ? "" :
|
|
||||||
timeStamps.CheckOut != null ?
|
|
||||||
$"{timeStamps.CheckOut.Value.Date.ToString("HH:mm")} น." :
|
|
||||||
"",
|
|
||||||
|
|
||||||
remark = ""
|
|
||||||
};
|
|
||||||
|
|
||||||
employees.Add(emp);
|
|
||||||
count++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = new
|
//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
|
||||||
{
|
{
|
||||||
DateTimeStamp = date.Date.ToThaiFullDate(),
|
no = count,
|
||||||
officerTotal = profile.Count,
|
fullName = fullName,
|
||||||
workTotal = count - 1,
|
dutyTimeName = $"{duty.StartTimeMorning} น.",
|
||||||
restTotal = 0,
|
checkInLocation = timeStamps == null ? "" : timeStamps.CheckInLocationName,
|
||||||
sickTotal = 0,
|
checkInTime = timeStamps == null ? "" : $"{timeStamps.CheckIn.Date.ToString("HH:mm")} น.",
|
||||||
lateTotal = 0,
|
|
||||||
wfhTotal = 0,
|
checkOutLocation = timeStamps == null ? "" : timeStamps.CheckOutLocationName ?? "",
|
||||||
studyTotal = 0,
|
checkOutTime = timeStamps == null ? "" :
|
||||||
employees = employees
|
timeStamps.CheckOut != null ?
|
||||||
|
$"{timeStamps.CheckOut.Value.Date.ToString("HH:mm")} น." :
|
||||||
|
"",
|
||||||
|
|
||||||
|
remark = ""
|
||||||
};
|
};
|
||||||
|
|
||||||
data.Add(item);
|
employees.Add(emp);
|
||||||
|
count++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var item = new
|
||||||
|
{
|
||||||
|
DateTimeStamp = date.Date.ToThaiFullDate(),
|
||||||
|
officerTotal = profile.Count,
|
||||||
|
workTotal = count - 1,
|
||||||
|
restTotal = 0,
|
||||||
|
sickTotal = 0,
|
||||||
|
lateTotal = 0,
|
||||||
|
wfhTotal = 0,
|
||||||
|
studyTotal = 0,
|
||||||
|
employees = employees
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = new
|
var result = new
|
||||||
{
|
{
|
||||||
template = "TimeStamp",
|
template = "TimeStamp",
|
||||||
reportName = "TimeStamp",
|
reportName = "TimeStamp",
|
||||||
data = data
|
data = item
|
||||||
};
|
};
|
||||||
|
|
||||||
return Success(result);
|
return Success(result);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace BMA.EHR.Leave.Service.DTOs.Reports
|
||||||
{
|
{
|
||||||
public DateTime StartDate { get; set; } = DateTime.MinValue;
|
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