diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index e474850d..76f9844d 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -1728,6 +1728,59 @@ namespace BMA.EHR.Leave.Service.Controllers } + #endregion + + #region " Check Checkout Time " + + /// + /// ตรวจสอบว่าเวลาปัจจุบัน ถ้า checkout จะขาดราชการหรือไม่? + /// + /// + /// + /// เมื่อทำรายการสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("user/checkout-check")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> CheckoutCheckAsync() + { + var time = DateTime.Now; + + var userId = UserId != null ? Guid.Parse(UserId) : Guid.Empty; + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + if (profile == null) + { + throw new Exception(GlobalMessages.DataNotFound); + } + + var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync(); + if (getDefaultRound == 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 ?? getDefaultRound; + + var endTime = DateTime.Parse($"{DateTime.Now.Date.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}"); + + var status = time < endTime ? "ABSENT" : "NORMAL"; + + return Success(new + { + Status = status, + StatusText = status == "ABSENT" ? "ขาดราชการ" : "ปกติ", + ServerTime = time + }); + + } + + #endregion #region " ขอลงเวลาเป็นกรณีพิเศษ "