ออกคำสั่ง

This commit is contained in:
kittapath 2024-10-04 15:36:34 +07:00
parent 604b234c4b
commit 1290da7211
14 changed files with 1979 additions and 2004 deletions

View file

@ -487,7 +487,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
/// <summary>
/// ออกคำสั่ง C-PM-18
/// ออกคำสั่ง C-PM-18 คำสั่งให้ออกจากราชการ
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
@ -497,62 +497,49 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost("command/report/excecute")]
public async Task<ActionResult<ResponseObject>> PostReportExecuteLeave([FromBody] ReportExecuteRequest req)
{
// create new profile
foreach (var recv in req.refIds)
var data = await _context.RetirementOuts
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
.ToListAsync();
var resultData = (from p in data
join r in req.refIds
on p.Id.ToString() equals r.refId
select new
{
profileId = p.profileId,
date = r.commandAffectDate,
amount = r.amount,
positionSalaryAmount = r.positionSalaryAmount,
mouthSalaryAmount = r.mouthSalaryAmount,
posNo = p.PositionNumberOld,
position = p.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = p.PositionTypeOld,
positionLevel = p.PositionLevelOld,
refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}",
templateDoc = r.templateDoc,
isLeave = true,
leaveReason = "ให้ออกจากราชการ",
dateLeave = r.commandAffectDate,
}).ToList();
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
using (var client = new HttpClient())
{
var data = await _context.RetirementOuts
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(recv.refId));
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/leave/{data.profileId}";
using (var client = new HttpClient())
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
isLeave = true,
leaveReason = "ให้ออกจากราชการ",
dateLeave = recv.commandAffectDate,
});
var _result = await _res.Content.ReadAsStringAsync();
}
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
data = resultData,
});
var _result = await _res.Content.ReadAsStringAsync();
if (_res.IsSuccessStatusCode)
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = recv.commandAffectDate,
amount = recv.amount,
positionSalaryAmount = recv.positionSalaryAmount,
mouthSalaryAmount = recv.mouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{recv.commandNo}/{recv.commandYear.ToThaiYear()}",
templateDoc = recv.templateDoc,
});
var _result = await _res.Content.ReadAsStringAsync();
data.ForEach(profile => profile.Status = "DONE");
await _context.SaveChangesAsync();
}
// update placementstatus
data.Status = "DONE";
await _context.SaveChangesAsync();
}
return Success();
}