diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 0968b3b6..94cc9e4e 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -530,8 +530,27 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests // TODO : Update ไปตาราง beginning if (data.ApproveStep == "st4") // ถ้ามีการอนุมัติจากผู้มีอำนาจแล้ว + { await _leaveBeginningRepository.UpdateLeaveUsageAsync(data.LeaveStartDate.Year, data.Type.Id, data.KeycloakUserId, -1 * data.LeaveTotal); + var _baseAPI = _configuration["API"]; + var apiUrlSalary = $"{_baseAPI}/org/profile/leave/cancel/{data.Id}"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); + + var request = new HttpRequestMessage(HttpMethod.Patch, apiUrlSalary); + + // ส่ง request + var _res = await client.SendAsync(request); + if (!_res.IsSuccessStatusCode) + throw new Exception("ไม่สามารถอัพเดตการยกเลิกรายการลาไปยังระบบทะเบียนประวัติ"); + //var _result = await _res.Content.ReadAsStringAsync(); + } + } + + // Send Noti var noti = new Notification { @@ -543,24 +562,6 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests _appDbContext.Set().Add(noti); await _appDbContext.SaveChangesAsync(); - - var _baseAPI = _configuration["API"]; - var apiUrlSalary = $"{_baseAPI}/org/profile/leave/cancel/{data.Id}"; - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", "")); - client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); - - var request = new HttpRequestMessage(HttpMethod.Patch, apiUrlSalary); - - // ส่ง request - var _res = await client.SendAsync(request); - if (!_res.IsSuccessStatusCode) - throw new Exception("ไม่สามารถอัพเดตการยกเลิกรายการลาไปยังระบบทะเบียนประวัติ"); - //var _result = await _res.Content.ReadAsStringAsync(); - } - - return data; } catch