Update LeaveController to adjust check-in/check-out times based on user duty schedule #2223
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m16s
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m16s
This commit is contained in:
parent
e1c7688913
commit
9bd6017ded
1 changed files with 24 additions and 0 deletions
|
|
@ -3634,6 +3634,30 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
var data = await _processUserTimeStampRepository.GetByIdAsync(id);
|
var data = await _processUserTimeStampRepository.GetByIdAsync(id);
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return Error(GlobalMessages.DataNotFound);
|
return Error(GlobalMessages.DataNotFound);
|
||||||
|
|
||||||
|
if (data.CheckInStatus == "NORMAL" || data.CheckOutStatus == "NORMAL")
|
||||||
|
{
|
||||||
|
var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(id, AccessToken);
|
||||||
|
var defaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||||
|
if (defaultRound == null)
|
||||||
|
{
|
||||||
|
return Error("ไม่พบรอบการลงเวลา Default", StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile!.Id);
|
||||||
|
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
|
||||||
|
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
|
||||||
|
|
||||||
|
var duty = userRound ?? defaultRound;
|
||||||
|
if (req.CheckInStatus == "NORMAL")
|
||||||
|
{
|
||||||
|
data.CheckIn = DateTime.Parse($"{data.CheckIn.Date.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}");
|
||||||
|
}
|
||||||
|
if (req.CheckOutStatus == "NORMAL" )
|
||||||
|
{
|
||||||
|
var checkOutTime = data.CheckOut != null ? data.CheckOut.Value : data.CheckIn;
|
||||||
|
data.CheckOut = DateTime.Parse($"{checkOutTime.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data.CheckInStatus = req.CheckInStatus;
|
data.CheckInStatus = req.CheckInStatus;
|
||||||
data.CheckOutStatus = req.CheckOutStatus;
|
data.CheckOutStatus = req.CheckOutStatus;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue