Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop

This commit is contained in:
Kittapath 2023-12-24 15:06:11 +07:00
commit 1e574fcdee
4 changed files with 92 additions and 59 deletions

View file

@ -56,6 +56,23 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
#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)
{
try

View file

@ -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)
{
try

View file

@ -698,7 +698,9 @@ namespace BMA.EHR.Leave.Service.Controllers
{
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 employees = new List<dynamic>();
@ -1083,77 +1085,74 @@ namespace BMA.EHR.Leave.Service.Controllers
{
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>();
for (DateTime date = req.StartDate.Date; date.Date <= req.EndDate.Date; date = date.AddDays(1))
var employees = new List<dynamic>();
var count = 1;
foreach (var p in profile)
{
var employees = new List<dynamic>();
var count = 1;
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)
{
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)
{
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++;
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
}
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(),
officerTotal = profile.Count,
workTotal = count - 1,
restTotal = 0,
sickTotal = 0,
lateTotal = 0,
wfhTotal = 0,
studyTotal = 0,
employees = employees
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 = ""
};
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
{
template = "TimeStamp",
reportName = "TimeStamp",
data = data
data = item
};
return Success(result);

View file

@ -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;
}
}