เพิ่ม api บรรจุ พ้นราชการ

This commit is contained in:
Kittapath 2023-08-11 01:57:09 +07:00
parent f587ab6a87
commit e2fee53a94
52 changed files with 34312 additions and 225 deletions

View file

@ -0,0 +1,290 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Retirement.Service.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
namespace BMA.EHR.Retirement.Service.Controllers
{
[Route("api/v{version:apiVersion}/retirement/discharge")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("ระบบปลดออก")]
public class RetirementDischargeController : BaseController
{
private readonly RetirementRepository _repository;
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
public RetirementDischargeController(RetirementRepository repository,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
{
_repository = repository;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
}
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private bool? RetirementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
#endregion
/// <summary>
/// list รายการปลดออกของ Admin
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{
var retirementDischarges = await _context.RetirementDischarges.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
if (RetirementAdmin == true)
retirementDischarges.Where(x => x.Status.Trim().ToUpper().Contains("APPROVE"));
return Success(retirementDischarges);
}
/// <summary>
/// get รายละเอียดปลดออกเจ้าหน้าที่
/// </summary>
/// <param name="id">Id ปลดออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> GetDetailAdmin(Guid id)
{
var data = await _context.RetirementDischarges.AsQueryable()
.Where(x => x.Id == id)
.Where(x => x.Profile != null)
.Select(p => new
{
p.Id,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
ProfileId = p.Profile.Id,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
organizationOrganization = p.Profile.OrganizationOrganization,
p.Reason,
p.Status,
p.Organization,
p.Date,
salary = p.AmountOld,
p.CreatedAt,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
return Success(data);
}
/// <summary>
/// สร้างปลดออก
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementAddProfileRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var retirementDischarge = new RetirementDischarge
{
Profile = profile,
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
// Date = req.Date,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementDischarges.AddAsync(retirementDischarge);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขปลดออก
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Put([FromBody] RetirementDischargeEditRequest req, Guid id)
{
var uppdated = await _context.RetirementDischarges
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementDischargeNotFound, 404);
uppdated.PositionNumberOld = req.PositionNumberOld;
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;
uppdated.PositionLevelOld = req.PositionLevelOld;
uppdated.PositionTypeOld = req.PositionTypeOld;
uppdated.AmountOld = req.AmountOld;
uppdated.Organization = req.Organization;
uppdated.Reason = req.Reason;
uppdated.Date = req.Date;
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// อนุมัติปลดออก
/// </summary>
/// <param name="id">Id ปลดออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("confirm/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id)
{
var uppdated = await _context.RetirementDischarges
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementDischargeNotFound, 404);
uppdated.Status = "APPROVE";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ลบปลดออก
/// </summary>
/// <param name="id">Id ปลดออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
{
var deleted = await _context.RetirementDischarges.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
return NotFound();
_context.RetirementDischarges.Remove(deleted);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// สั่งรายชื่อไปออกคำสั่ง
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report")]
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] RetirementProfileRequest req)
{
foreach (var item in req.Id)
{
var uppdated = await _context.RetirementDischarges
.FirstOrDefaultAsync(x => x.Id == item);
if (uppdated == null)
continue;
uppdated.Status = "REPORT";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
return Success();
}
}
}

View file

@ -0,0 +1,290 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Retirement.Service.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
namespace BMA.EHR.Retirement.Service.Controllers
{
[Route("api/v{version:apiVersion}/retirement/expulsion")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("ระบบไล่ออก")]
public class RetirementExpulsionController : BaseController
{
private readonly RetirementRepository _repository;
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
public RetirementExpulsionController(RetirementRepository repository,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
{
_repository = repository;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
}
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private bool? RetirementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
#endregion
/// <summary>
/// list รายการไล่ออกของ Admin
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{
var retirementExpulsions = await _context.RetirementExpulsions.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
if (RetirementAdmin == true)
retirementExpulsions.Where(x => x.Status.Trim().ToUpper().Contains("APPROVE"));
return Success(retirementExpulsions);
}
/// <summary>
/// get รายละเอียดไล่ออกเจ้าหน้าที่
/// </summary>
/// <param name="id">Id ไล่ออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> GetDetailAdmin(Guid id)
{
var data = await _context.RetirementExpulsions.AsQueryable()
.Where(x => x.Id == id)
.Where(x => x.Profile != null)
.Select(p => new
{
p.Id,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
ProfileId = p.Profile.Id,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
organizationOrganization = p.Profile.OrganizationOrganization,
p.Reason,
p.Status,
p.Organization,
p.Date,
salary = p.AmountOld,
p.CreatedAt,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
return Success(data);
}
/// <summary>
/// สร้างไล่ออก
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementAddProfileRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var retirementExpulsion = new RetirementExpulsion
{
Profile = profile,
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
// Date = req.Date,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementExpulsions.AddAsync(retirementExpulsion);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขไล่ออก
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Put([FromBody] RetirementExpulsionEditRequest req, Guid id)
{
var uppdated = await _context.RetirementExpulsions
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementExpulsionNotFound, 404);
uppdated.PositionNumberOld = req.PositionNumberOld;
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;
uppdated.PositionLevelOld = req.PositionLevelOld;
uppdated.PositionTypeOld = req.PositionTypeOld;
uppdated.AmountOld = req.AmountOld;
uppdated.Organization = req.Organization;
uppdated.Reason = req.Reason;
uppdated.Date = req.Date;
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// อนุมัติไล่ออก
/// </summary>
/// <param name="id">Id ไล่ออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("confirm/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id)
{
var uppdated = await _context.RetirementExpulsions
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementExpulsionNotFound, 404);
uppdated.Status = "APPROVE";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ลบไล่ออก
/// </summary>
/// <param name="id">Id ไล่ออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
{
var deleted = await _context.RetirementExpulsions.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
return NotFound();
_context.RetirementExpulsions.Remove(deleted);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// สั่งรายชื่อไปออกคำสั่ง
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report")]
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] RetirementProfileRequest req)
{
foreach (var item in req.Id)
{
var uppdated = await _context.RetirementExpulsions
.FirstOrDefaultAsync(x => x.Id == item);
if (uppdated == null)
continue;
uppdated.Status = "REPORT";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
return Success();
}
}
}

View file

@ -0,0 +1,292 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Retirement.Service.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
namespace BMA.EHR.Retirement.Service.Controllers
{
[Route("api/v{version:apiVersion}/retirement/other")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("ระบบอื่นๆ")]
public class RetirementOtherController : BaseController
{
private readonly RetirementRepository _repository;
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
public RetirementOtherController(RetirementRepository repository,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
{
_repository = repository;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
}
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private bool? RetirementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
#endregion
/// <summary>
/// list รายการอื่นๆของ Admin
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{
var retirementOthers = await _context.RetirementOthers.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
if (RetirementAdmin == true)
retirementOthers.Where(x => x.Status.Trim().ToUpper().Contains("APPROVE"));
return Success(retirementOthers);
}
/// <summary>
/// get รายละเอียดอื่นๆเจ้าหน้าที่
/// </summary>
/// <param name="id">Id อื่นๆ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> GetDetailAdmin(Guid id)
{
var data = await _context.RetirementOthers.AsQueryable()
.Where(x => x.Id == id)
.Where(x => x.Profile != null)
.Select(p => new
{
p.Id,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
ProfileId = p.Profile.Id,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
organizationOrganization = p.Profile.OrganizationOrganization,
p.Reason,
p.Status,
p.Organization,
p.Date,
salary = p.AmountOld,
p.CreatedAt,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
return Success(data);
}
/// <summary>
/// สร้างอื่นๆ
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementAddProfileRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var retirementOther = new RetirementOther
{
Profile = profile,
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
// Date = req.Date,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementOthers.AddAsync(retirementOther);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขอื่นๆ
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Put([FromBody] RetirementOtherEditRequest req, Guid id)
{
var uppdated = await _context.RetirementOthers
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementOtherNotFound, 404);
uppdated.PositionNumberOld = req.PositionNumberOld;
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;
uppdated.PositionLevelOld = req.PositionLevelOld;
uppdated.PositionTypeOld = req.PositionTypeOld;
uppdated.AmountOld = req.AmountOld;
uppdated.Organization = req.Organization;
uppdated.Reason = req.Reason;
uppdated.Date = req.Date;
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// อนุมัติอื่นๆ
/// </summary>
/// <param name="id">Id อื่นๆ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("confirm/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id)
{
var uppdated = await _context.RetirementOthers
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementOtherNotFound, 404);
uppdated.Status = "APPROVE";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ลบอื่นๆ
/// </summary>
/// <param name="id">Id อื่นๆ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
{
var deleted = await _context.RetirementOthers.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
return NotFound();
_context.RetirementOthers.Remove(deleted);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// สั่งรายชื่อไปออกคำสั่ง
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("report/{commandTypeId:length(36)}")]
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] RetirementProfileRequest req, Guid commandTypeId)
{
foreach (var item in req.Id)
{
var uppdated = await _context.RetirementOthers
.FirstOrDefaultAsync(x => x.Id == item);
if (uppdated == null)
continue;
uppdated.CommandType = await _context.CommandTypes.FindAsync(commandTypeId);
uppdated.Status = "REPORT";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
return Success();
}
}
}

View file

@ -0,0 +1,290 @@
using BMA.EHR.Application.Repositories;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Retirement.Service.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
namespace BMA.EHR.Retirement.Service.Controllers
{
[Route("api/v{version:apiVersion}/retirement/out")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("ระบบให้ออก")]
public class RetirementOutController : BaseController
{
private readonly RetirementRepository _repository;
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
public RetirementOutController(RetirementRepository repository,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
{
_repository = repository;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
}
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private bool? RetirementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
#endregion
/// <summary>
/// list รายการให้ออกของ Admin
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{
var retirementOuts = await _context.RetirementOuts.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
if (RetirementAdmin == true)
retirementOuts.Where(x => x.Status.Trim().ToUpper().Contains("APPROVE"));
return Success(retirementOuts);
}
/// <summary>
/// get รายละเอียดให้ออกเจ้าหน้าที่
/// </summary>
/// <param name="id">Id ให้ออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> GetDetailAdmin(Guid id)
{
var data = await _context.RetirementOuts.AsQueryable()
.Where(x => x.Id == id)
.Where(x => x.Profile != null)
.Select(p => new
{
p.Id,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
ProfileId = p.Profile.Id,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : p.Profile.PositionEmployeePosition,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : p.Profile.PositionEmployeeLevel,
organizationOrganization = p.Profile.OrganizationOrganization,
p.Reason,
p.Status,
p.Organization,
p.Date,
salary = p.AmountOld,
p.CreatedAt,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
return Success(data);
}
/// <summary>
/// สร้างให้ออก
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementAddProfileRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var retirementOut = new RetirementOut
{
Profile = profile,
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
// Date = req.Date,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementOuts.AddAsync(retirementOut);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขให้ออก
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Put([FromBody] RetirementOutEditRequest req, Guid id)
{
var uppdated = await _context.RetirementOuts
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementOutNotFound, 404);
uppdated.PositionNumberOld = req.PositionNumberOld;
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;
uppdated.PositionLevelOld = req.PositionLevelOld;
uppdated.PositionTypeOld = req.PositionTypeOld;
uppdated.AmountOld = req.AmountOld;
uppdated.Organization = req.Organization;
uppdated.Reason = req.Reason;
uppdated.Date = req.Date;
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// อนุมัติให้ออก
/// </summary>
/// <param name="id">Id ให้ออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("confirm/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id)
{
var uppdated = await _context.RetirementOuts
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.RetirementOutNotFound, 404);
uppdated.Status = "APPROVE";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ลบให้ออก
/// </summary>
/// <param name="id">Id ให้ออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
{
var deleted = await _context.RetirementOuts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
return NotFound();
_context.RetirementOuts.Remove(deleted);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// สั่งรายชื่อไปออกคำสั่ง
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report")]
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] RetirementProfileRequest req)
{
foreach (var item in req.Id)
{
var uppdated = await _context.RetirementOuts
.FirstOrDefaultAsync(x => x.Id == item);
if (uppdated == null)
continue;
uppdated.Status = "REPORT";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
return Success();
}
}
}

View file

@ -107,11 +107,11 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.ActiveDate,
p.Reason,
p.Status,
PositionType = p.PositionType == null ? null : p.PositionType.Name,
PositionLine = p.PositionLine == null ? null : p.PositionLine.Name,
PositionLevel = p.PositionLevel == null ? null : p.PositionLevel.Name,
PositionExecutive = p.PositionExecutive == null ? null : p.PositionExecutive.Name,
OrganizationOrganization = p.OrganizationOrganization == null ? null : p.OrganizationOrganization.Name,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
p.CreatedAt,
})
@ -147,16 +147,11 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.ActiveDate,
p.Reason,
p.Status,
PositionType = p.PositionType == null ? null : p.PositionType.Name,
PositionTypeId = p.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionType.Id,
PositionLine = p.PositionLine == null ? null : p.PositionLine.Name,
PositionLineId = p.PositionLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLine.Id,
PositionLevel = p.PositionLevel == null ? null : p.PositionLevel.Name,
PositionLevelId = p.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLevel.Id,
PositionExecutive = p.PositionExecutive == null ? null : p.PositionExecutive.Name,
PositionExecutiveId = p.PositionExecutive == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionExecutive.Id,
OrganizationOrganization = p.OrganizationOrganization == null ? null : p.OrganizationOrganization.Name,
OrganizationOrganizationId = p.OrganizationOrganization == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationOrganization.Id,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
p.CreatedAt,
})
@ -179,8 +174,11 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementResignRequest req)
{
var profile = await _context.Profiles
.Include(x => x.PositionType)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
@ -192,15 +190,12 @@ namespace BMA.EHR.Retirement.Service.Controllers
SendDate = req.SendDate,
ActiveDate = req.ActiveDate,
Reason = req.Reason,
PositionType = profile.PositionType,
PositionLine = await _context.PositionLines
.FirstOrDefaultAsync(x => x.Id == profile.PositionLineId),
PositionLevel = profile.PositionLevel,
PositionExecutive = await _context.PositionExecutives
.FirstOrDefaultAsync(x => x.Id == profile.PositionExecutiveId),
OrganizationOrganization = await _context.OrganizationOrganizations
.FirstOrDefaultAsync(x => x.Id == profile.OrganizationOrganizationId),
Status = "PENDING",
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING",
IsActive = true,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
@ -235,6 +230,11 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.SendDate = req.SendDate;
updated.ActiveDate = req.ActiveDate;
updated.Reason = req.Reason;
updated.OrganizationPositionOld = req.OrganizationPositionOld;
updated.PositionTypeOld = req.PositionTypeOld;
updated.PositionLevelOld = req.PositionLevelOld;
updated.PositionNumberOld = req.PositionNumberOld;
updated.AmountOld = req.AmountOld;
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
@ -315,5 +315,33 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Success();
}
/// <summary>
/// สั่งรายชื่อไปออกคำสั่ง
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("report")]
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] RetirementProfileRequest req)
{
foreach (var item in req.Id)
{
var uppdated = await _context.RetirementResigns
.FirstOrDefaultAsync(x => x.Id == item);
if (uppdated == null)
continue;
uppdated.Status = "REPORT";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
return Success();
}
}
}

View file

@ -0,0 +1,16 @@
using BMA.EHR.Domain.Models.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class PersonSelectPositionReceiveRequest
{
public DateTime? RecruitDate { get; set; }
public Guid? PosNoId { get; set; }
public Guid? PositionId { get; set; }
public Guid? PositionLevelId { get; set; }
public Guid? PositionLineId { get; set; }
public Guid? PositionPathSideId { get; set; }
public Guid? PositionTypeId { get; set; }
}
}

View file

@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementAddProfileRequest
{
public Guid Id { get; set; }
}
}

View file

@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementDischargeEditRequest
{
public string Organization { get; set; }
public string Reason { get; set; }
public string? OrganizationPositionOld { get; set; }
public DateTime? Date { get; set; }
public string? PositionTypeOld { get; set; }
public string? PositionLevelOld { get; set; }
public string? PositionNumberOld { get; set; }
public double? AmountOld { get; set; }
}
}

View file

@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementExpulsionEditRequest
{
public string Organization { get; set; }
public string Reason { get; set; }
public string? OrganizationPositionOld { get; set; }
public DateTime? Date { get; set; }
public string? PositionTypeOld { get; set; }
public string? PositionLevelOld { get; set; }
public string? PositionNumberOld { get; set; }
public double? AmountOld { get; set; }
}
}

View file

@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementOtherEditRequest
{
public string Organization { get; set; }
public string Reason { get; set; }
public string? OrganizationPositionOld { get; set; }
public DateTime? Date { get; set; }
public string? PositionTypeOld { get; set; }
public string? PositionLevelOld { get; set; }
public string? PositionNumberOld { get; set; }
public double? AmountOld { get; set; }
}
}

View file

@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementOutEditRequest
{
public string Organization { get; set; }
public string Reason { get; set; }
public string? OrganizationPositionOld { get; set; }
public DateTime? Date { get; set; }
public string? PositionTypeOld { get; set; }
public string? PositionLevelOld { get; set; }
public string? PositionNumberOld { get; set; }
public double? AmountOld { get; set; }
}
}

View file

@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementProfileRequest
{
public List<Guid> Id { get; set; }
}
}

View file

@ -0,0 +1,13 @@
using BMA.EHR.Domain.Models.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementResignEditRequest
{
public string? Location { get; set; }
public DateTime? SendDate { get; set; }
public DateTime? ActiveDate { get; set; }
public string? Reason { get; set; }
}
}

View file

@ -9,5 +9,10 @@ namespace BMA.EHR.Retirement.Service.Requests
public DateTime? SendDate { get; set; }
public DateTime? ActiveDate { get; set; }
public string? Reason { get; set; }
public string? OrganizationPositionOld { get; set; }
public string? PositionTypeOld { get; set; }
public string? PositionLevelOld { get; set; }
public string? PositionNumberOld { get; set; }
public double? AmountOld { get; set; }
}
}