2506 lines
141 KiB
C#
2506 lines
141 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Application.Repositories.Reports;
|
|
using BMA.EHR.Application.Requests;
|
|
using BMA.EHR.Application.Responses.Insignias;
|
|
using BMA.EHR.Application.Responses.Organizations;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.Insignias;
|
|
using BMA.EHR.Domain.Shared;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using BMA.EHR.Insignia.Service.Requests;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using OfficeOpenXml;
|
|
using RabbitMQ.Client;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
|
|
namespace BMA.EHR.Insignia.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/insignia/request")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("เครื่องราช")]
|
|
public class InsigniaRequestController : BaseController
|
|
{
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly InsigniaPeriodsRepository _repository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly IWebHostEnvironment _hostingEnvironment;
|
|
private readonly string Royal_Type = "Royal";
|
|
private readonly UserProfileRepository _userProfileRepository;
|
|
private const string INSIGNIA_QUEUE = "bma_insignia_request";
|
|
|
|
private readonly InsigniaPeriodsRepository _insigniaPeriodRepository;
|
|
private readonly InsigniaReportRepository _insigniaReportRepository;
|
|
|
|
private readonly IConfiguration _configuration;
|
|
private readonly PermissionRepository _permission;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <param name="documentService"></param>
|
|
/// <param name="repository"></param>
|
|
/// <param name="repositoryNoti"></param>
|
|
/// <param name="hostingEnvironment"></param>
|
|
/// <param name="httpContextAccessor"></param>
|
|
/// <param name="userProfileRepository"></param>
|
|
/// <param name="insigniaPeriodRepository"></param>
|
|
/// <param name="producer"></param>
|
|
public InsigniaRequestController(ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
InsigniaPeriodsRepository repository,
|
|
NotificationRepository repositoryNoti,
|
|
IWebHostEnvironment hostingEnvironment,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
UserProfileRepository userProfileRepository,
|
|
InsigniaPeriodsRepository insigniaPeriodRepository,
|
|
InsigniaReportRepository insigniaReportRepository,
|
|
IConfiguration configuration,
|
|
PermissionRepository permission)
|
|
{
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_repository = repository;
|
|
_repositoryNoti = repositoryNoti;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_hostingEnvironment = hostingEnvironment;
|
|
_userProfileRepository = userProfileRepository;
|
|
_insigniaPeriodRepository = insigniaPeriodRepository;
|
|
_configuration = configuration;
|
|
_permission = permission;
|
|
_insigniaReportRepository = insigniaReportRepository;
|
|
}
|
|
|
|
#region " Properties "
|
|
|
|
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
|
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
|
|
|
#endregion
|
|
|
|
#region " Private "
|
|
|
|
private static string GetRequestlStatusText(string status)
|
|
{
|
|
switch (status.ToLower())
|
|
{
|
|
case "st1": return "จัดทำรายชื่อ";
|
|
case "st2": return "รอ ผอ. โรงเรียนรับรอง";
|
|
case "st3": return "รอเจ้าหน้าที่เขตตรวจสอบ";
|
|
case "st3p": return "รอนำเสนอผู้อำนวยการเขต";
|
|
case "st4": return "รอเสนอสำนักการศึกษา";
|
|
case "st5": return "รอเจ้าหน้าที่ สนศ. ตรวจสอบ";
|
|
case "st5p": return "เจ้าหน้าที่ สนศ. ตรวจสอบแล้ว";
|
|
case "pending": return "รอออกคำสั่ง";
|
|
case "finish": return "ออกคำสั่งแล้ว";
|
|
default: return "สถานะไม่ถูกต้อง";
|
|
}
|
|
}
|
|
private List<string> GetOcNameFullPath(Guid id, bool showRoot = false)
|
|
{
|
|
try
|
|
{
|
|
var ocList = new List<string>();
|
|
|
|
var oc = (from o in _context.Organizations.Include(x => x.Parent).Include(x => x.OrganizationOrganization).Where(x => x.OrganizationOrganization != null).AsQueryable()
|
|
join oc_name in _context.OrganizationOrganizations.AsQueryable() on o.OrganizationOrganization.Id equals oc_name.Id
|
|
where o.Parent != null
|
|
select new
|
|
{
|
|
Id = o.Id,
|
|
Name = oc_name.Name,
|
|
o.IsActive,
|
|
o.Parent
|
|
}).FirstOrDefault(x => x.Id == id && x.IsActive);
|
|
|
|
if (oc == null)
|
|
return ocList;
|
|
|
|
ocList.Add(oc.Name);
|
|
|
|
if (oc.Parent?.Id != null)
|
|
{
|
|
ocList.AddRange(GetOcNameFullPath(oc.Parent.Id, showRoot));
|
|
}
|
|
|
|
return ocList;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
private string FindOCFullPath(Guid id, bool showRoot = false)
|
|
{
|
|
try
|
|
{
|
|
var ocList = GetOcNameFullPath(id, showRoot);
|
|
var ret = String.Empty;
|
|
foreach (var oc in ocList)
|
|
{
|
|
ret = oc + "/" + ret;
|
|
}
|
|
|
|
if (ret.Length > 2)
|
|
ret = ret.Substring(0, ret.Length - 1);
|
|
|
|
return ret;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private async Task<List<ImportReceiveRequest>> ReadExcelImportReceive(IFormFile formFile)
|
|
{
|
|
var list = new List<ImportReceiveRequest>();
|
|
using (var stream = new MemoryStream())
|
|
{
|
|
await formFile.CopyToAsync(stream);
|
|
using (var package = new ExcelPackage(stream))
|
|
{
|
|
for (int i = 0; i < package.Workbook.Worksheets.Count(); i++)
|
|
{
|
|
ExcelWorksheet worksheet = package.Workbook.Worksheets[i];
|
|
var rowCount = worksheet.Dimension.Rows;
|
|
for (int row = 2; row <= rowCount; row++)
|
|
{
|
|
if (worksheet.Cells[row, 1].ToString() == "") break;
|
|
list.Add(new ImportReceiveRequest
|
|
{
|
|
Number = worksheet.Cells[row, 1].Value != null ? worksheet.Cells[row, 1].Value.ToString() : null,
|
|
RequestInsignia = worksheet.Cells[row, 2].Value != null ? worksheet.Cells[row, 2].Value.ToString() : null,
|
|
CitizanId = worksheet.Cells[row, 3].Value != null ? worksheet.Cells[row, 3].Value.ToString() : null,
|
|
Prefix = worksheet.Cells[row, 4].Value != null ? worksheet.Cells[row, 4].Value.ToString() : null,
|
|
FullName = worksheet.Cells[row, 5].Value != null ? worksheet.Cells[row, 5].Value.ToString() : null,
|
|
Position = worksheet.Cells[row, 6].Value != null ? worksheet.Cells[row, 6].Value.ToString() : null,
|
|
DateReceive = worksheet.Cells[row, 7].Value != null ? DateTime.Parse(worksheet.Cells[row, 7].Value.ToString()) : null,
|
|
OrgSend = worksheet.Cells[row, 8].Value != null ? worksheet.Cells[row, 8].Value.ToString() : null,
|
|
OrgReceive = worksheet.Cells[row, 9].Value != null ? worksheet.Cells[row, 9].Value.ToString() : null,
|
|
Date = worksheet.Cells[row, 10].Value != null ? DateTime.Parse(worksheet.Cells[row, 10].Value.ToString()) : null,
|
|
VolumeNo = worksheet.Cells[row, 11].Value != null ? worksheet.Cells[row, 11].Value.ToString() : null,
|
|
Section = worksheet.Cells[row, 12].Value != null ? worksheet.Cells[row, 12].Value.ToString() : null,
|
|
Page = worksheet.Cells[row, 13].Value != null ? worksheet.Cells[row, 13].Value.ToString() : null,
|
|
No = worksheet.Cells[row, 14].Value != null ? worksheet.Cells[row, 14].Value.ToString() : null,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private async Task<List<ImportInvoiceRequest>> ReadExcelImportInvoice(IFormFile formFile)
|
|
{
|
|
var list = new List<ImportInvoiceRequest>();
|
|
using (var stream = new MemoryStream())
|
|
{
|
|
await formFile.CopyToAsync(stream);
|
|
using (var package = new ExcelPackage(stream))
|
|
{
|
|
for (int i = 0; i < package.Workbook.Worksheets.Count(); i++)
|
|
{
|
|
ExcelWorksheet worksheet = package.Workbook.Worksheets[i];
|
|
var rowCount = worksheet.Dimension.Rows;
|
|
for (int row = 2; row <= rowCount; row++)
|
|
{
|
|
list.Add(new ImportInvoiceRequest
|
|
{
|
|
CitizanId = worksheet.Cells[row, 1].Value != null ? worksheet.Cells[row, 1].Value.ToString() : null,
|
|
Number = worksheet.Cells[row, 2].Value != null ? worksheet.Cells[row, 2].Value.ToString() : null,
|
|
DatePayment = worksheet.Cells[row, 3].Value != null ? DateTime.Parse(worksheet.Cells[row, 3].Value.ToString()) : null,
|
|
TypePayment = worksheet.Cells[row, 4].Value != null ? worksheet.Cells[row, 4].Value.ToString() : null,
|
|
Address = worksheet.Cells[row, 5].Value != null ? worksheet.Cells[row, 5].Value.ToString() : null,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private dynamic FormatRequestProfiles(List<InsigniaRequestProfile> requestProfiles)
|
|
{
|
|
var rawData = requestProfiles
|
|
.Select(irp => new
|
|
{
|
|
request_id = irp.Request.Id,
|
|
isApprove = irp.IsApprove,
|
|
statusInstitute = irp.IsApprove.ToString(),
|
|
request_date = irp.RequestDate,
|
|
profileId = irp.ProfileId,
|
|
citizenId = irp.CitizenId,
|
|
prefix = irp.Prefix,
|
|
firstname = irp.FirstName,
|
|
lastname = irp.LastName,
|
|
type = irp.ProfileType,
|
|
position = irp.Position,
|
|
posno = irp.PosNo,
|
|
rank = $"{irp.PosTypeName}/{irp.PosLevelName}",
|
|
lastInsigniaName = irp.LastInsigniaName,
|
|
instituteName = "",
|
|
instituteId = -1,
|
|
requestInsigniaLevel = irp.RequestInsignia.InsigniaType.Name,
|
|
requestInsigniaName = irp.RequestInsignia.Name,
|
|
requestQua = "",// irp.QualificationStatus,
|
|
requestDoc = "", //irp.DocumentStatus,
|
|
requestNote = "", // irp.Note,
|
|
requestSalary = irp.Salary,
|
|
matchingConditions = JsonConvert.DeserializeObject<List<MatchingCondition>>(irp.MatchingConditions)
|
|
})
|
|
.OrderBy(x => x.citizenId)
|
|
.ToList();
|
|
|
|
return rawData;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " จัดทำรายชื่อครูที่มีสิทธิในการยืนขอเครื่องราชฯ "
|
|
|
|
/// <summary>
|
|
/// list รายการคำขอเครื่องราช ผู้ได้รับ,คนไม่ยื่น,คนที่ถูกลบ
|
|
/// </summary>
|
|
/// <param name="insigniaPeriodId">Id รอบเครื่องราช</param>
|
|
/// <param name="ocId">Id สังกัด</param>
|
|
/// <param name="role">ชื่อตำแหน่งระหว่างสกจ กับ เขต (ตอนนี้ให้ส่ง officer ก่อน)</param>
|
|
/// <param name="status">pending=ผู้ได้รับ, reject=คนไม่ยื่น, delete=คนที่ถูกลบ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{insigniaPeriodId:length(36)}/{ocId:length(36)}/{role}/{status}")]
|
|
public async Task<ActionResult<ResponseObject>> GetInsignaiRequestBkk(Guid insigniaPeriodId, Guid ocId, string role, string status)
|
|
{
|
|
var result = await _repository.GetInsigniaRequest(insigniaPeriodId, ocId);
|
|
if (result != null)
|
|
{
|
|
Guid period = result.PeriodId;
|
|
var periodName = result.Name;
|
|
string requestStatus = result.RequestStatus;
|
|
string requestNote = result.RequestNote;
|
|
|
|
var resend = new InsigniaResults
|
|
{
|
|
PeriodId = result.PeriodId,
|
|
Year = result.Year,
|
|
Round = result.Round,
|
|
Name = result.Name,
|
|
RequestId = result.RequestId,
|
|
RequestStatus = result.RequestStatus,
|
|
RequestNote = result.RequestNote,
|
|
IsLock = result.IsLock,
|
|
OrganizationName = result.OrganizationName,
|
|
Document = result.Document,
|
|
Items = new List<InsigniaRequestItem>()
|
|
};
|
|
GetIsOfficerDto RoleInsignia = await _userProfileRepository.GetIsOfficerRootAsync(AccessToken, "SYS_INSIGNIA_MANAGE");
|
|
if (RoleInsignia.isOfficer == true && result.RequestStatus != "st6")
|
|
return Success(resend);
|
|
if (RoleInsignia.isDirector == true && (result.RequestStatus == "st1" || result.RequestStatus == "st2"))
|
|
return Success(resend);
|
|
|
|
// Jack Remark Remove เพื่อให้เรียกขข้อมูลออกมาเร็สวขึ้น
|
|
//var candidate = await _repository.GetInsigniaCandidateBKK(period, ocId);
|
|
|
|
//// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
|
//if (requestStatus == null)
|
|
//{
|
|
// // บันทึกรายชื่อ
|
|
// await _repository.InsertCandidate(period, ocId, candidate);
|
|
//}
|
|
if (role.Trim().ToUpper() == "OFFICER")
|
|
{
|
|
resend.Items = await _repository.InsigniaHasProfile(result.PeriodId, ocId, status);
|
|
return Success(resend);
|
|
}
|
|
else
|
|
{
|
|
var passData = _context.InsigniaRequests.AsQueryable()
|
|
.Include(x => x.RequestProfiles)
|
|
.Where(x => x.OrganizationId == ocId)
|
|
.Where(x => x.Period.Id == period)
|
|
.Select(ir => new
|
|
{
|
|
requstID = ir.Id,
|
|
requstStatus = ir.RequestStatus,
|
|
requstStatusName = GetRequestlStatusText(ir.RequestStatus),
|
|
fkInstituteId = -1,
|
|
fkInstitute = "",
|
|
fkPeriodId = ir.Period.Id,
|
|
insigniaRequestHasProfile = FormatRequestProfiles(ir.RequestProfiles.AsQueryable()
|
|
.Include(x => x.RequestInsignia)
|
|
.ThenInclude(x => x.InsigniaType)
|
|
.Where(x => x.IsApprove)
|
|
.ToList())
|
|
})
|
|
.ToList()
|
|
.FirstOrDefault();
|
|
|
|
var failData = _context.InsigniaRequests.AsQueryable()
|
|
.Include(x => x.RequestProfiles)
|
|
.Where(x => x.OrganizationId == ocId)
|
|
.Where(x => x.Period.Id == period)
|
|
.Select(ir => new
|
|
{
|
|
requstID = ir.Id,
|
|
requstStatus = ir.RequestStatus,
|
|
requstStatusName = GetRequestlStatusText(ir.RequestStatus),
|
|
fkInstituteId = -1,
|
|
fkInstitute = "",
|
|
fkPeriodId = ir.Period.Id,
|
|
insigniaRequestHasProfile = FormatRequestProfiles(ir.RequestProfiles.AsQueryable()
|
|
.Include(x => x.RequestInsignia)
|
|
.ThenInclude(x => x.InsigniaType)
|
|
.Where(x => !x.IsApprove)
|
|
.ToList())
|
|
})
|
|
.ToList()
|
|
.FirstOrDefault();
|
|
|
|
var period_data = (from p in _context.InsigniaPeriods.AsQueryable()
|
|
where p.Id == period
|
|
select new
|
|
{
|
|
periodName = p.Name,
|
|
periodYear = p.Year,
|
|
}).FirstOrDefault();
|
|
|
|
return Success(new { passData = passData, failData = failData, period = period_data });
|
|
}
|
|
}
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// คำนวณราชชื่อผู้ได้รับเครื่องราช
|
|
/// </summary>
|
|
/// <param name="insigniaPeriodId">Id รอบเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{insigniaPeriodId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdateInsigniaRequestBkk(Guid insigniaPeriodId)
|
|
{
|
|
var selectPeriod = _context.InsigniaPeriods.AsNoTracking().Where(x => x.Id == insigniaPeriodId).FirstOrDefault();
|
|
if (selectPeriod == null)
|
|
throw new Exception(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
var organizations = await _userProfileRepository.GetActiveRootAsync(AccessToken, selectPeriod.RevisionId);
|
|
|
|
foreach (var organization in organizations)
|
|
{
|
|
if (organization == null)
|
|
continue;
|
|
|
|
// TODO - Comment This
|
|
//if (organization.Id.ToString() != "e93c0ed3-7b80-42aa-8626-8abf0042f618") continue;
|
|
|
|
var result = await _repository.GetInsigniaRequest(insigniaPeriodId, organization.Id);
|
|
if (result != null)
|
|
{
|
|
Guid period = result.PeriodId;
|
|
string requestStatus = result.RequestStatus;
|
|
var candidate = await _repository.GetInsigniaCandidateBKK(insigniaPeriodId, organization.Id);
|
|
// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
|
if (requestStatus == null)
|
|
{
|
|
// บันทึกรายชื่อ
|
|
await _repository.InsertCandidate(period, organization.Id, organization.OrgRootName, candidate);
|
|
}
|
|
}
|
|
}
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// คำนวณราชชื่อผู้ได้รับเครื่องราช (Rabbit MQ)
|
|
/// </summary>
|
|
/// <param name="insigniaPeriodId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("queue/{insigniaPeriodId:length(36)}")]
|
|
public ActionResult<ResponseObject> InsigniaRequestCalculate(Guid insigniaPeriodId)
|
|
{
|
|
var host = _configuration["RabbitMQ:URL"];
|
|
var userName = _configuration["RabbitMQ:UserName"];
|
|
var password = _configuration["RabbitMQ:Password"];
|
|
|
|
var factory = new ConnectionFactory()
|
|
{
|
|
HostName = host,
|
|
UserName = userName,
|
|
Password = password
|
|
};
|
|
|
|
using (var connection = factory.CreateConnection())
|
|
using (var channel = connection.CreateModel())
|
|
{
|
|
channel.QueueDeclare(queue: INSIGNIA_QUEUE, durable: false, exclusive: false, autoDelete: false, arguments: null);
|
|
var body = Encoding.UTF8.GetBytes(insigniaPeriodId.ToString("D"));
|
|
channel.BasicPublish(exchange: "", routingKey: INSIGNIA_QUEUE, basicProperties: null, body: body);
|
|
return Success();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " บันทึกหมายเหตุ "
|
|
|
|
[HttpPut("note/{profileId}")]
|
|
public async Task<ActionResult<ResponseObject>> SaveNote(Guid profileId, SaveRequsetNote items)
|
|
{
|
|
var id = await _repository.GetRequestId(items.PeriodId, items.OcId);
|
|
var note = _context.InsigniaRequestProfiles.AsQueryable()
|
|
.Where(d => d.ProfileId == profileId && d.Request.Id == id).FirstOrDefault();
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " บันทึกรายชื่อครูในการขอยื่นเครื่องราชฯ เเต่ยังไม่ส่งไปยัง ผอ.โรงเรียน "
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="ocId"></param>
|
|
/// <param name="items"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("approve/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> SaveRequestList(Guid id, Guid ocId, InsigniaApproveRequest items)
|
|
{
|
|
var result = await _repository.GetInsigniaRequest(id, ocId);
|
|
if (result != null)
|
|
await _repository.SaveAprove(result.PeriodId, ocId);
|
|
return Success();
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// เปลี่ยน status เป็น st3 การเจ้าหน้าที่อนุมัติ "
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("officer/approve/{id:length(36)}/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ApproveChangeStatusToSt3(Guid id, Guid ocId)
|
|
{
|
|
await _repository.SaveAprove(id, ocId);
|
|
var requestId = await _repository.GetRequestId(id, ocId);
|
|
var requestNew = await _context.InsigniaRequests
|
|
.Include(x => x.Period)
|
|
.FirstOrDefaultAsync(i => i.Id == requestId);
|
|
if (requestNew != null)
|
|
{
|
|
requestNew.RequestStatus = "st3";
|
|
requestNew.RequestNote = "";
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbc953-630a-4e72-88a7-c68dbb1ba856"),
|
|
$"{requestNew.Organization} ยื่นขอมูลข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
$"{requestNew.Organization} ยื่นขอมูลข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
"",
|
|
"",
|
|
true
|
|
);
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
else
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
}
|
|
|
|
/// <summary>
|
|
/// เปลี่ยน status เป็น st2 การเจ้าหน้าที่ไม่อนุมัติ "
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("officer/reject/{id:length(36)}/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> RejectChangeStatusToSt2([FromBody] InsigniaReasonRequest req, Guid id, Guid ocId)
|
|
{
|
|
await _repository.SaveAprove(id, ocId);
|
|
var requestId = await _repository.GetRequestId(id, ocId);
|
|
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
|
if (requestNew != null)
|
|
{
|
|
requestNew.RequestStatus = "st2";
|
|
requestNew.RequestNote = req.Reason;
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
else
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
}
|
|
|
|
/// <summary>
|
|
/// เปลี่ยน status เป็น st6 ผอ.หน่วยอนุมัติ "
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("director/approve/{id:length(36)}/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ApproveChangeStatusToSt6(Guid id, Guid ocId)
|
|
{
|
|
var requestId = await _repository.GetRequestId(id, ocId);
|
|
var requestNew = await _context.InsigniaRequests
|
|
.Include(x => x.Period)
|
|
.FirstOrDefaultAsync(i => i.Id == requestId);
|
|
if (requestNew != null)
|
|
{
|
|
requestNew.RequestStatus = "st6";
|
|
requestNew.RequestNote = "";
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbc953-64d9-497a-87a3-0244eade622c"),
|
|
$"{requestNew.Organization} ยื่นขอมูลข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
$"{requestNew.Organization} ยื่นขอมูลข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
"",
|
|
"",
|
|
true
|
|
);
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
|
|
$"{requestNew.Organization} ยื่นขอมูลข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
$"{requestNew.Organization} ยื่นขอมูลข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
"",
|
|
"",
|
|
true
|
|
);
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
else
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
}
|
|
|
|
/// <summary>
|
|
/// เปลี่ยน status เป็น st4 ผอ.หน่วยไม่อนุมัติ "
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("director/reject/{id:length(36)}/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> RejectChangeStatusToSt4([FromBody] InsigniaReasonRequest req, Guid id, Guid ocId)
|
|
{
|
|
var requestId = await _repository.GetRequestId(id, ocId);
|
|
var requestNew = await _context.InsigniaRequests
|
|
.Include(x => x.Period)
|
|
.FirstOrDefaultAsync(i => i.Id == requestId);
|
|
if (requestNew != null)
|
|
{
|
|
requestNew.RequestStatus = "st4";
|
|
requestNew.RequestNote = req.Reason;
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbc953-61ac-47eb-82d7-0e72df7669b5"),
|
|
$"{requestNew.Organization} ตีกลับข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
$"{requestNew.Organization} ตีกลับข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
"",
|
|
"",
|
|
true
|
|
);
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
else
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
}
|
|
|
|
/// <summary>
|
|
/// เปลี่ยน status เป็น st5 สกจ. หน่วยไม่อนุมัติ "
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("head/reject/{id:length(36)}/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> RejectChangeStatusToSt5([FromBody] InsigniaReasonRequest req, Guid id, Guid ocId)
|
|
{
|
|
var requestId = await _repository.GetRequestId(id, ocId);
|
|
var requestNew = await _context.InsigniaRequests
|
|
.Include(x => x.Period)
|
|
.FirstOrDefaultAsync(i => i.Id == requestId);
|
|
if (requestNew != null)
|
|
{
|
|
requestNew.RequestStatus = "st5";
|
|
requestNew.RequestNote = req.Reason;
|
|
await _repositoryNoti.PushNotificationAsync(
|
|
Guid.Parse("08dbc953-630a-4e72-88a7-c68dbb1ba856"),
|
|
$"สกจ. ตีกลับข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
$"สกจ. ตีกลับข้อมูลผู้มีสิทธิ์ได้รับเครื่องราชฯ {requestNew.Period.Name}",
|
|
"",
|
|
"",
|
|
true
|
|
);
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
else
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
}
|
|
|
|
// #endregion
|
|
|
|
#region " เปลี่ยน status สำหรับ ผอ.สำนัก "
|
|
|
|
[HttpPost("status/director/approve/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ChangeStatusToSt5p(Guid id, Guid ocId)
|
|
{
|
|
var result = await _repository.GetInsigniaRequest(id, ocId);
|
|
if (result == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var requestId = await _repository.GetRequestId(result.PeriodId, ocId);
|
|
if (requestId == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
|
if (requestNew != null)
|
|
{
|
|
requestNew.RequestStatus = "st5p";
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
else
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
}
|
|
|
|
[HttpPost("status/director/reject/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ChangeStatusToSt1(Guid id, Guid ocId)
|
|
{
|
|
var result = await _repository.GetInsigniaRequest(id, ocId);
|
|
if (result == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var requestId = await _repository.GetRequestId(result.PeriodId, ocId);
|
|
if (requestId == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
|
if (requestNew != null)
|
|
{
|
|
requestNew.RequestStatus = "st1";
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
else
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// ย้ายขอมูลไปเป็น คนที่ไม่ยื่นขอ
|
|
/// </summary>
|
|
/// <param name="insigniaRequestProfileId">Id รายชื่อคนที่ยื่นของในรอบ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("status/reject/{insigniaRequestProfileId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> RejectProfileInsignia([FromBody] InsigniaReasonRequest req, Guid insigniaRequestProfileId)
|
|
{
|
|
var insigniaRequestProfile = await _context.InsigniaRequestProfiles.FirstOrDefaultAsync(x => x.Id == insigniaRequestProfileId);
|
|
if (insigniaRequestProfile == null)
|
|
return Error(GlobalMessages.InsigniaRequestProfileNotFound);
|
|
insigniaRequestProfile.Status = "REJECT";
|
|
insigniaRequestProfile.ReasonReject = req.Reason;
|
|
insigniaRequestProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
insigniaRequestProfile.LastUpdateUserId = UserId ?? "";
|
|
insigniaRequestProfile.LastUpdatedAt = DateTime.Now;
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ย้ายขอมูลไปเป็น คนที่ถูกลบออก
|
|
/// </summary>
|
|
/// <param name="insigniaRequestProfileId">Id รายชื่อคนที่ยื่นของในรอบ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("status/delete/{insigniaRequestProfileId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteProfileInsignia([FromBody] InsigniaReasonRequest req, Guid insigniaRequestProfileId)
|
|
{
|
|
var insigniaRequestProfile = await _context.InsigniaRequestProfiles.FirstOrDefaultAsync(x => x.Id == insigniaRequestProfileId);
|
|
if (insigniaRequestProfile == null)
|
|
return Error(GlobalMessages.InsigniaRequestProfileNotFound);
|
|
insigniaRequestProfile.Status = "DELETE";
|
|
insigniaRequestProfile.ReasonReject = req.Reason;
|
|
insigniaRequestProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
insigniaRequestProfile.LastUpdateUserId = UserId ?? "";
|
|
insigniaRequestProfile.LastUpdatedAt = DateTime.Now;
|
|
_context.SaveChanges();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// สรุปจำนวนการยื่นขอในแต่ละรอบ
|
|
/// </summary>
|
|
/// <param name="insigniaPeriodId">Id รอบการยื่นขอ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("dashboard/{insigniaPeriodId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> DashboardInsigniaPeriod(Guid insigniaPeriodId)
|
|
{
|
|
var insigniaPeriod = await _context.InsigniaPeriods.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId);
|
|
if (insigniaPeriod == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var orgAllCount = await _context.InsigniaRequests
|
|
.Where(x => x.Period == insigniaPeriod)
|
|
.ToListAsync();
|
|
GetIsOfficerDto RoleInsignia = await _userProfileRepository.GetIsOfficerRootAsync(AccessToken, "SYS_INSIGNIA_MANAGE");
|
|
var allUserUser = await _context.InsigniaRequests
|
|
.Where(x => x.Period == insigniaPeriod)
|
|
.Where(x => RoleInsignia.isOfficer == true ? x.RequestStatus == "st6" : (RoleInsignia.isDirector == true ? (x.RequestStatus != "st1" && x.RequestStatus != "st2") : x.Id != null))
|
|
.Select(x => x.RequestProfiles.Count(x => x.Status != "DELETE" && x.Status != "REJECT"))
|
|
.SumAsync();
|
|
|
|
return Success(new { OrgAllCount = orgAllCount.Count(), OrgSendCount = orgAllCount.Where(x => x.RequestStatus != "st1" && x.RequestStatus != "st2").Count(), OrgNoSendCount = orgAllCount.Where(x => x.RequestStatus == "st1" || x.RequestStatus == "st2").Count(), AllUserUser = allUserUser });
|
|
}
|
|
|
|
/// <summary>
|
|
/// หน่วยงานทียังไม่ส่งรายชื่อ
|
|
/// </summary>
|
|
/// <param name="insigniaPeriodId">Id รอบการยื่นขอ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("org/no-send/{insigniaPeriodId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ListOrgDontSentUser(Guid insigniaPeriodId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_MANAGE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var insigniaPeriod = await _context.InsigniaPeriods.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId);
|
|
if (insigniaPeriod == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var orgIdSend = await _context.InsigniaRequests
|
|
.Where(x => x.Period == insigniaPeriod)
|
|
.Where(x => x.RequestStatus == "st6")
|
|
.Select(x => x.OrganizationId)
|
|
.ToListAsync();
|
|
|
|
var organizations = await _userProfileRepository.GetActiveRootAsync(AccessToken, insigniaPeriod.RevisionId);
|
|
var orgAllCount = organizations
|
|
.Where(x => !orgIdSend.Contains(x.Id))
|
|
.Select(x => new
|
|
{
|
|
OrgId = x.Id,
|
|
OrgName = x.OrgRootName
|
|
})
|
|
.ToList();
|
|
|
|
return Success(orgAllCount);
|
|
}
|
|
|
|
/// <summary>
|
|
/// หน่วยงานที่อยู่ปัจจุบัน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("agency")]
|
|
public async Task<ActionResult<ResponseObject>> GetOrgAgency()
|
|
{
|
|
await _insigniaReportRepository.CalInsignaiRequestBkk();
|
|
return Success();
|
|
}
|
|
|
|
/// <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>> AddUserToRequestInsignia([FromBody] AddUserRequestInsigniaRequest req)
|
|
{
|
|
var insigniaPeriod = await _context.InsigniaPeriods.FirstOrDefaultAsync(x => x.Id == req.insigniaPeriodId);
|
|
if (insigniaPeriod == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
|
|
var profile = await _userProfileRepository.GetProfileByProfileIdAsync(req.ProfileId, AccessToken);
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound);
|
|
|
|
var insignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Id == req.insigniaId);
|
|
|
|
if (insignia == null)
|
|
return Error(GlobalMessages.InsigniaNotFound);
|
|
|
|
var insigniaRequestProfile = await _context.InsigniaRequestProfiles
|
|
.Include(x => x.Request)
|
|
.ThenInclude(x => x.Period)
|
|
.FirstOrDefaultAsync(x => x.ProfileId == profile.Id && x.Request.Period.Id == insigniaPeriod.Id);
|
|
if (insigniaRequestProfile != null)
|
|
return Error(GlobalMessages.InsigniaRequestProfileDupicate);
|
|
|
|
var insigniaRequest = await _context.InsigniaRequests.Include(x => x.Period).FirstOrDefaultAsync(x => x.Period.Id == insigniaPeriod.Id && x.OrganizationId == req.OcId);
|
|
if (insigniaRequest == null)
|
|
{
|
|
insigniaRequest = new InsigniaRequest
|
|
{
|
|
Period = insigniaPeriod,
|
|
OrganizationId = profile.RootId ?? Guid.Empty,
|
|
Organization = profile.Root,
|
|
RequestStatus = "st1",
|
|
RequestNote = "",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
}
|
|
|
|
var lastInsignia = string.Empty;
|
|
if (profile.ProfileInsignia != null)
|
|
{
|
|
var id = profile.ProfileInsignia.Id ?? Guid.Empty;
|
|
var insigniaEnt = _insigniaPeriodRepository.GetInsigniaById(id);
|
|
if (insigniaEnt != null)
|
|
lastInsignia = insigniaEnt.Name;
|
|
}
|
|
|
|
await _context.AddAsync(new InsigniaRequestProfile
|
|
{
|
|
Status = "PENDING",
|
|
ProfileId = profile.Id,
|
|
RequestInsignia = insignia,
|
|
Request = insigniaRequest,
|
|
Reason = req.Reason,
|
|
RequestDate = DateTime.Now,
|
|
MatchingConditions = System.Text.Json.JsonSerializer.Serialize(new List<dynamic>()), // serialize to string
|
|
Salary = profile.Amount, //profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
// Add Information for reused in API Call
|
|
ProfileType = profile.ProfileType ?? "officer",
|
|
Prefix = profile.Prefix,
|
|
FirstName = profile.FirstName,
|
|
LastName = profile.LastName,
|
|
CitizenId = profile.CitizenId,
|
|
BirthDate = profile.BirthDate,
|
|
DateAppoint = profile.DateAppoint,
|
|
Position = profile.Position,
|
|
Gender = profile.Gender,
|
|
PosTypeName = profile.PosType,
|
|
PosLevelName = profile.PosLevel,
|
|
PosNo = profile.ProfileSalary == null ? "" : profile.ProfileSalary.PosNo,
|
|
Amount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.Amount,
|
|
PositionSalaryAmount = profile.ProfileSalary == null ? 0 : profile.ProfileSalary.PositionSalaryAmount,
|
|
LastInsigniaName = lastInsignia,
|
|
Root = profile.Root,
|
|
RootId = profile.RootId,
|
|
Child1 = profile.Child1,
|
|
Child1Id = profile.Child1Id,
|
|
Child2 = profile.Child2,
|
|
Child2Id = profile.Child2Id,
|
|
Child3 = profile.Child3,
|
|
Child3Id = profile.Child3Id,
|
|
Child4 = profile.Child4,
|
|
Child4Id = profile.Child4Id,
|
|
});
|
|
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขรายชื่อผู้ได้รับเครื่องราช
|
|
/// </summary>
|
|
/// <param name="insigniaRequestProfileId">Id รายชื่อคนที่ยื่นของในรอบ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("{insigniaRequestProfileId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdateUserToRequestInsignia([FromBody] UpdateUserRequestInsigniaRequest req, Guid insigniaRequestProfileId)
|
|
{
|
|
var insigniaRequestProfile = await _context.InsigniaRequestProfiles.FirstOrDefaultAsync(x => x.Id == insigniaRequestProfileId);
|
|
if (insigniaRequestProfile == null)
|
|
return Error(GlobalMessages.InsigniaRequestProfileNotFound);
|
|
var insignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Id == req.insigniaId);
|
|
if (insignia == null)
|
|
return Error(GlobalMessages.InsigniaNotFound);
|
|
|
|
insigniaRequestProfile.RequestInsignia = insignia;
|
|
insigniaRequestProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
insigniaRequestProfile.LastUpdateUserId = UserId ?? "";
|
|
insigniaRequestProfile.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// รายชื่อผู้ได้รับเครื่องราชส่งข้อมูลไปบันทึกผลได้รับเครื่องราช
|
|
/// </summary>
|
|
/// <param name="insigniaPeriodId">Id รอบการยื่นขอ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("send/note/{insigniaPeriodId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> SendPeriodToNote([FromBody] InsigniaNoteNameRequest req, Guid insigniaPeriodId)
|
|
{
|
|
var insigniaPeriod = await _context.InsigniaPeriods
|
|
.Include(x => x.InsigniaRequests)
|
|
.Include(x => x.ReliefDoc)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId);
|
|
if (insigniaPeriod == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
insigniaPeriod.IsLock = true;
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.FirstOrDefaultAsync(x => x.Year == insigniaPeriod.Year);
|
|
if (insigniaNote == null)
|
|
{
|
|
insigniaNote = new InsigniaNote
|
|
{
|
|
Name = req.Name,
|
|
Year = insigniaPeriod.Year,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.InsigniaNotes.AddAsync(insigniaNote);
|
|
await _context.SaveChangesAsync();
|
|
insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNote.Id);
|
|
}
|
|
var requestOlds = await _context.InsigniaRequests
|
|
.Where(p => p.Period == insigniaPeriod)
|
|
.Where(p => p.RequestStatus == "st6")
|
|
.ToListAsync();
|
|
foreach (var requestOld in requestOlds)
|
|
{
|
|
var profileOlds = await _context.InsigniaRequestProfiles
|
|
.Include(x => x.RequestInsignia)
|
|
.Where(p => p.Request == requestOld)
|
|
.ToListAsync();
|
|
|
|
foreach (var profileOld in profileOlds)
|
|
{
|
|
if (profileOld.Status == "DELETE" || profileOld.Status == "REJECT")
|
|
continue;
|
|
var noreProfileOld = insigniaNote.InsigniaNoteProfiles
|
|
.Where(x => x.ProfileId == profileOld.ProfileId)
|
|
.FirstOrDefault();
|
|
if (noreProfileOld != null)
|
|
{
|
|
noreProfileOld.RequestDate = profileOld.RequestDate;
|
|
noreProfileOld.Salary = profileOld.Salary;
|
|
noreProfileOld.IsApprove = profileOld.IsApprove;
|
|
noreProfileOld.RequestInsignia = profileOld.RequestInsignia;
|
|
noreProfileOld.CreatedFullName = FullName ?? "System Administrator";
|
|
noreProfileOld.CreatedUserId = UserId ?? "";
|
|
noreProfileOld.CreatedAt = DateTime.Now;
|
|
noreProfileOld.LastUpdateFullName = FullName ?? "System Administrator";
|
|
noreProfileOld.LastUpdateUserId = UserId ?? "";
|
|
noreProfileOld.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
if (profileOld.ProfileId == null)
|
|
continue;
|
|
await _context.InsigniaNoteProfiles.AddAsync(new InsigniaNoteProfile
|
|
{
|
|
RequestDate = profileOld.RequestDate,
|
|
Salary = profileOld.Salary,
|
|
IsApprove = profileOld.IsApprove,
|
|
Status = "PENDING",
|
|
ProfileId = profileOld.ProfileId,
|
|
RequestInsignia = profileOld.RequestInsignia,
|
|
OrganizationOrganizationSend = null,
|
|
InsigniaNote = insigniaNote,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
|
|
// Add Information for reused in API Call
|
|
ProfileType = profileOld.ProfileType ?? "officer",
|
|
Prefix = profileOld.Prefix,
|
|
FirstName = profileOld.FirstName,
|
|
LastName = profileOld.LastName,
|
|
CitizenId = profileOld.CitizenId,
|
|
BirthDate = profileOld.BirthDate,
|
|
DateAppoint = profileOld.DateAppoint,
|
|
Position = profileOld.Position,
|
|
Gender = profileOld.Gender,
|
|
PosTypeName = profileOld.PosTypeName,
|
|
PosLevelName = profileOld.PosLevelName,
|
|
PosNo = profileOld.PosNo,
|
|
Amount = profileOld.Amount,
|
|
PositionSalaryAmount = profileOld.PositionSalaryAmount,
|
|
Root = profileOld.Root,
|
|
RootId = profileOld.RootId,
|
|
Child1 = profileOld.Child1,
|
|
Child1Id = profileOld.Child1Id,
|
|
Child2 = profileOld.Child2,
|
|
Child2Id = profileOld.Child2Id,
|
|
Child3 = profileOld.Child3,
|
|
Child3Id = profileOld.Child3Id,
|
|
Child4 = profileOld.Child4,
|
|
Child4Id = profileOld.Child4Id,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// รายชื่อผู้ได้รับเครื่องราชส่งข้อมูลไปบันทึกผลได้รับเครื่องราช(อัพเดทstatus)
|
|
/// </summary>
|
|
/// <param name="insigniaPeriodId">Id รอบการยื่นขอ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("send/note/{insigniaPeriodId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> SendPeriodToNoteUpdateStatus(Guid insigniaPeriodId)
|
|
{
|
|
var insigniaPeriod = await _context.InsigniaPeriods
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId);
|
|
if (insigniaPeriod == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
//insigniaPeriod.IsLock = true;
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// list รอบบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยสภรณ์/การจ่ายใบกำกับ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("note")]
|
|
public async Task<ActionResult<ResponseObject>> GetListNote(string path)
|
|
{
|
|
path = path.Trim().ToUpper();
|
|
string getPermission = string.Empty;
|
|
if (path == "RECORD")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECORD");
|
|
}
|
|
else if (path == "ALLOCATE")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_ALLOCATE");
|
|
}
|
|
else if (path == "BORROW")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_BORROW");
|
|
}
|
|
else
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECORD");
|
|
}
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var insigniaNotes = await _context.InsigniaNotes.AsQueryable()
|
|
.OrderByDescending(x => x.Year)
|
|
.Select(p => new
|
|
{
|
|
Id = p.Id,
|
|
Name = p.Name,
|
|
Year = p.Year,
|
|
})
|
|
.ToListAsync();
|
|
return Success(insigniaNotes);
|
|
}
|
|
|
|
/// <summary>
|
|
/// list รายชื่อบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยสภรณ์/การจ่ายใบกำกับ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("note/search")]
|
|
public async Task<ActionResult<ResponseObject>> GetListNoteProfile([FromBody] InsigniaNoteSearchRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECORD");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var insigniaType = await _context.InsigniaTypes
|
|
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId);
|
|
if (insigniaType == null)
|
|
return Error(GlobalMessages.InsigniaTypeNotFound);
|
|
|
|
var rawNoteProfiles = await _context.InsigniaNoteProfiles
|
|
.Where(x => x.InsigniaNote == insigniaNote)
|
|
.Where(x => x.RequestInsignia.InsigniaType == insigniaType)
|
|
.Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId))
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
x.Prefix,
|
|
x.FirstName,
|
|
x.LastName,
|
|
x.Position,
|
|
x.CitizenId,
|
|
x.ProfileType,
|
|
OcId = x.RootId, // TODO: ต้องมาแก้ไข
|
|
RequestInsignia = x.RequestInsignia.Name,
|
|
RequestInsigniaId = x.RequestInsignia.Id,
|
|
RequestInsigniaShortName = x.RequestInsignia.ShortName,
|
|
DateReceive = x.DateReceive,
|
|
x.OrganizationOrganizationSend,
|
|
x.OrganizationOrganizationReceive,
|
|
Status = x.Status,
|
|
Issue = x.Issue,
|
|
Date = x.Date,
|
|
VolumeNo = x.VolumeNo,
|
|
Section = x.Section,
|
|
Page = x.Page,
|
|
No = x.No,
|
|
DatePayment = x.DatePayment,
|
|
TypePayment = x.TypePayment,
|
|
Address = x.Address,
|
|
Number = x.Number,
|
|
Salary = x.Salary,
|
|
DateReceiveInsignia = x.DateReceiveInsignia,
|
|
DocReceiveInsignia = x.DocReceiveInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReceiveInsignia.Id,
|
|
x.OrgReceiveInsignia,
|
|
x.OrgReceiveInsigniaId,
|
|
DateReturnInsignia = x.DateReturnInsignia,
|
|
DocReturnInsignia = x.DocReturnInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReturnInsignia.Id,
|
|
x.OrgReturnInsignia,
|
|
x.OrgReturnInsigniaId,
|
|
})
|
|
.ToListAsync();
|
|
|
|
var insigniaNoteProfiles = rawNoteProfiles
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
Prefix = x.Prefix ?? "",
|
|
Position = x.Position ?? "",
|
|
ProfileType = x.ProfileType ?? "",
|
|
x.OcId,
|
|
CitizenId = x.CitizenId ?? "",
|
|
FullName = $"{x.Prefix ?? ""}{x.FirstName ?? ""} {x.LastName ?? ""}".Trim(),
|
|
RequestInsignia = x.RequestInsignia,
|
|
RequestInsigniaId = x.RequestInsigniaId,
|
|
RequestInsigniaShortName = x.RequestInsigniaShortName,
|
|
DateReceive = x.DateReceive,
|
|
x.OrganizationOrganizationSend,
|
|
x.OrganizationOrganizationReceive,
|
|
Status = x.Status,
|
|
Issue = x.Issue,
|
|
Date = x.Date,
|
|
VolumeNo = x.VolumeNo,
|
|
Section = x.Section,
|
|
Page = x.Page,
|
|
No = x.No,
|
|
DatePayment = x.DatePayment,
|
|
TypePayment = x.TypePayment,
|
|
Address = x.Address,
|
|
Number = x.Number,
|
|
Salary = x.Salary,
|
|
DateReceiveInsignia = x.DateReceiveInsignia,
|
|
DocReceiveInsignia = x.DocReceiveInsignia,
|
|
x.OrgReceiveInsignia,
|
|
x.OrgReceiveInsigniaId,
|
|
DateReturnInsignia = x.DateReturnInsignia,
|
|
DocReturnInsignia = x.DocReturnInsignia,
|
|
x.OrgReturnInsignia,
|
|
x.OrgReturnInsigniaId,
|
|
})
|
|
.ToList();
|
|
|
|
var _insigniaNoteProfiles = new List<dynamic>();
|
|
foreach (var insigniaNoteProfile in insigniaNoteProfiles)
|
|
{
|
|
_insigniaNoteProfiles.Add(
|
|
new
|
|
{
|
|
insigniaNoteProfile.Id,
|
|
insigniaNoteProfile.Prefix,
|
|
insigniaNoteProfile.Position,
|
|
insigniaNoteProfile.CitizenId,
|
|
insigniaNoteProfile.ProfileType,
|
|
insigniaNoteProfile.FullName,
|
|
insigniaNoteProfile.RequestInsignia,
|
|
insigniaNoteProfile.RequestInsigniaId,
|
|
insigniaNoteProfile.RequestInsigniaShortName,
|
|
insigniaNoteProfile.DateReceive,
|
|
insigniaNoteProfile.OrganizationOrganizationSend,
|
|
insigniaNoteProfile.OrganizationOrganizationReceive,
|
|
insigniaNoteProfile.Status,
|
|
insigniaNoteProfile.Issue,
|
|
insigniaNoteProfile.Date,
|
|
insigniaNoteProfile.VolumeNo,
|
|
insigniaNoteProfile.Section,
|
|
insigniaNoteProfile.Page,
|
|
insigniaNoteProfile.No,
|
|
insigniaNoteProfile.DatePayment,
|
|
insigniaNoteProfile.TypePayment,
|
|
insigniaNoteProfile.Address,
|
|
insigniaNoteProfile.Number,
|
|
insigniaNoteProfile.Salary,
|
|
insigniaNoteProfile.DateReceiveInsignia,
|
|
DocReceiveInsignia = insigniaNoteProfile.DocReceiveInsignia == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaNoteProfile.DocReceiveInsignia),
|
|
insigniaNoteProfile.OrgReceiveInsignia,
|
|
insigniaNoteProfile.OrgReceiveInsigniaId,
|
|
insigniaNoteProfile.DateReturnInsignia,
|
|
DocReturnInsignia = insigniaNoteProfile.DocReturnInsignia == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaNoteProfile.DocReturnInsignia),
|
|
insigniaNoteProfile.OrgReturnInsignia,
|
|
insigniaNoteProfile.OrgReturnInsigniaId,
|
|
}
|
|
);
|
|
}
|
|
|
|
return Success(_insigniaNoteProfiles);
|
|
}
|
|
|
|
/// <summary>
|
|
/// list รายชื่อบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยสภรณ์/การจ่ายใบกำกับ ไม่ validate สิทธิ์
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("note-list/search")]
|
|
public async Task<ActionResult<ResponseObject>> GetListNoteProfileNonValidateRole([FromBody] InsigniaNoteSearchRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECORD");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var insigniaType = await _context.InsigniaTypes
|
|
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId);
|
|
if (insigniaType == null)
|
|
return Error(GlobalMessages.InsigniaTypeNotFound);
|
|
|
|
var rawNoteProfiles = await _context.InsigniaNoteProfiles
|
|
.Where(x => x.InsigniaNote == insigniaNote)
|
|
.Where(x => x.RequestInsignia.InsigniaType == insigniaType)
|
|
.Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId))
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
x.CitizenId,
|
|
x.Prefix,
|
|
x.FirstName,
|
|
x.LastName,
|
|
x.ProfileType,
|
|
x.Position,
|
|
OcId = x.RootId, // TODO: ต้องมาแก้ไข
|
|
RequestInsignia = x.RequestInsignia.Name,
|
|
RequestInsigniaId = x.RequestInsignia.Id,
|
|
RequestInsigniaShortName = x.RequestInsignia.ShortName,
|
|
DateReceive = x.DateReceive,
|
|
x.OrganizationOrganizationSend,
|
|
x.OrganizationOrganizationReceive,
|
|
Status = x.Status,
|
|
Issue = x.Issue,
|
|
Date = x.Date,
|
|
VolumeNo = x.VolumeNo,
|
|
Section = x.Section,
|
|
Page = x.Page,
|
|
No = x.No,
|
|
DatePayment = x.DatePayment,
|
|
TypePayment = x.TypePayment,
|
|
Address = x.Address,
|
|
Number = x.Number,
|
|
Salary = x.Salary,
|
|
DateReceiveInsignia = x.DateReceiveInsignia,
|
|
DocReceiveInsignia = x.DocReceiveInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReceiveInsignia.Id,
|
|
x.OrgReceiveInsignia,
|
|
x.OrgReceiveInsigniaId,
|
|
DateReturnInsignia = x.DateReturnInsignia,
|
|
DocReturnInsignia = x.DocReturnInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.DocReturnInsignia.Id,
|
|
x.OrgReturnInsignia,
|
|
x.OrgReturnInsigniaId,
|
|
})
|
|
.ToListAsync();
|
|
|
|
var insigniaNoteProfiles = rawNoteProfiles
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
Prefix = x.Prefix ?? "",
|
|
Position = x.Position ?? "",
|
|
ProfileType = x.ProfileType ?? "",
|
|
x.OcId,
|
|
CitizenId = x.CitizenId ?? "",
|
|
FullName = $"{x.Prefix ?? ""}{x.FirstName ?? ""} {x.LastName ?? ""}".Trim(),
|
|
RequestInsignia = x.RequestInsignia,
|
|
RequestInsigniaId = x.RequestInsigniaId,
|
|
RequestInsigniaShortName = x.RequestInsigniaShortName,
|
|
DateReceive = x.DateReceive,
|
|
x.OrganizationOrganizationSend,
|
|
x.OrganizationOrganizationReceive,
|
|
Status = x.Status,
|
|
Issue = x.Issue,
|
|
Date = x.Date,
|
|
VolumeNo = x.VolumeNo,
|
|
Section = x.Section,
|
|
Page = x.Page,
|
|
No = x.No,
|
|
DatePayment = x.DatePayment,
|
|
TypePayment = x.TypePayment,
|
|
Address = x.Address,
|
|
Number = x.Number,
|
|
Salary = x.Salary,
|
|
DateReceiveInsignia = x.DateReceiveInsignia,
|
|
DocReceiveInsignia = x.DocReceiveInsignia,
|
|
x.OrgReceiveInsignia,
|
|
x.OrgReceiveInsigniaId,
|
|
DateReturnInsignia = x.DateReturnInsignia,
|
|
DocReturnInsignia = x.DocReturnInsignia,
|
|
x.OrgReturnInsignia,
|
|
x.OrgReturnInsigniaId,
|
|
})
|
|
.ToList();
|
|
|
|
var _insigniaNoteProfiles = new List<dynamic>();
|
|
foreach (var insigniaNoteProfile in insigniaNoteProfiles)
|
|
{
|
|
_insigniaNoteProfiles.Add(
|
|
new
|
|
{
|
|
insigniaNoteProfile.Id,
|
|
insigniaNoteProfile.Prefix,
|
|
insigniaNoteProfile.Position,
|
|
insigniaNoteProfile.CitizenId,
|
|
insigniaNoteProfile.ProfileType,
|
|
insigniaNoteProfile.FullName,
|
|
insigniaNoteProfile.RequestInsignia,
|
|
insigniaNoteProfile.RequestInsigniaId,
|
|
insigniaNoteProfile.RequestInsigniaShortName,
|
|
insigniaNoteProfile.DateReceive,
|
|
insigniaNoteProfile.OrganizationOrganizationSend,
|
|
insigniaNoteProfile.OrganizationOrganizationReceive,
|
|
insigniaNoteProfile.Status,
|
|
insigniaNoteProfile.Issue,
|
|
insigniaNoteProfile.Date,
|
|
insigniaNoteProfile.VolumeNo,
|
|
insigniaNoteProfile.Section,
|
|
insigniaNoteProfile.Page,
|
|
insigniaNoteProfile.No,
|
|
insigniaNoteProfile.DatePayment,
|
|
insigniaNoteProfile.TypePayment,
|
|
insigniaNoteProfile.Address,
|
|
insigniaNoteProfile.Number,
|
|
insigniaNoteProfile.Salary,
|
|
insigniaNoteProfile.DateReceiveInsignia,
|
|
DocReceiveInsignia = insigniaNoteProfile.DocReceiveInsignia == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaNoteProfile.DocReceiveInsignia),
|
|
insigniaNoteProfile.OrgReceiveInsignia,
|
|
insigniaNoteProfile.OrgReceiveInsigniaId,
|
|
insigniaNoteProfile.DateReturnInsignia,
|
|
DocReturnInsignia = insigniaNoteProfile.DocReturnInsignia == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaNoteProfile.DocReturnInsignia),
|
|
insigniaNoteProfile.OrgReturnInsignia,
|
|
insigniaNoteProfile.OrgReturnInsigniaId,
|
|
}
|
|
);
|
|
}
|
|
|
|
return Success(_insigniaNoteProfiles);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get รายชื่อบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยสภรณ์/การจ่ายใบกำกับ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteProfileId">Id บุคคลในบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("note/{insigniaNoteProfileId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> GetListNoteProfile(Guid insigniaNoteProfileId)
|
|
{
|
|
var insigniaNoteProfile = await _context.InsigniaNoteProfiles
|
|
.Where(x => x.Id == insigniaNoteProfileId)
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
Prefix = x.Prefix,
|
|
FirstName = x.FirstName,
|
|
LastName = x.LastName,
|
|
CitizenId = x.CitizenId,
|
|
Positon = x.Position ?? "",
|
|
ProfileType = x.ProfileType,
|
|
OcId = x.RootId ?? Guid.Empty,
|
|
Oc = x.Root ?? "",
|
|
RequestInsignia = x.RequestInsignia.Name,
|
|
RequestInsigniaId = x.RequestInsignia.Id,
|
|
RequestInsigniaShortName = x.RequestInsignia.ShortName,
|
|
DateReceive = x.DateReceive,
|
|
x.OrganizationOrganizationSend,
|
|
x.OrganizationOrganizationReceive,
|
|
Status = x.Status,
|
|
Issue = x.Issue,
|
|
Date = x.Date,
|
|
VolumeNo = x.VolumeNo,
|
|
Section = x.Section,
|
|
Page = x.Page,
|
|
No = x.No,
|
|
DatePayment = x.DatePayment,
|
|
TypePayment = x.TypePayment,
|
|
Address = x.Address,
|
|
Number = x.Number,
|
|
Salary = x.Salary,
|
|
}).FirstOrDefaultAsync();
|
|
if (insigniaNoteProfile == null)
|
|
return Error(GlobalMessages.InsigniaRequestProfileNotFound);
|
|
var _insigniaNoteProfile = new
|
|
{
|
|
insigniaNoteProfile.Id,
|
|
Prefix = insigniaNoteProfile.Prefix ?? "",
|
|
Position = insigniaNoteProfile.Positon,
|
|
insigniaNoteProfile.CitizenId,
|
|
ProfileType = insigniaNoteProfile.ProfileType ?? "",
|
|
FullName = $"{insigniaNoteProfile.Prefix ?? ""}{insigniaNoteProfile.FirstName ?? ""} {insigniaNoteProfile.LastName ?? ""}",
|
|
insigniaNoteProfile.RequestInsignia,
|
|
insigniaNoteProfile.RequestInsigniaId,
|
|
insigniaNoteProfile.RequestInsigniaShortName,
|
|
insigniaNoteProfile.DateReceive,
|
|
insigniaNoteProfile.OrganizationOrganizationSend,
|
|
OrganizationOrganizationReceive = insigniaNoteProfile.OrganizationOrganizationReceive == null ? insigniaNoteProfile.Oc : insigniaNoteProfile.OrganizationOrganizationReceive,
|
|
insigniaNoteProfile.Status,
|
|
insigniaNoteProfile.Issue,
|
|
insigniaNoteProfile.Date,
|
|
insigniaNoteProfile.VolumeNo,
|
|
insigniaNoteProfile.Section,
|
|
insigniaNoteProfile.Page,
|
|
insigniaNoteProfile.No,
|
|
insigniaNoteProfile.DatePayment,
|
|
insigniaNoteProfile.TypePayment,
|
|
insigniaNoteProfile.Address,
|
|
insigniaNoteProfile.Number,
|
|
insigniaNoteProfile.Salary,
|
|
};
|
|
|
|
return Success(_insigniaNoteProfile);
|
|
}
|
|
|
|
/// <summary>
|
|
/// เพิ่ม/แก้ไขรายชื่อบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยสภรณ์/การจ่ายใบกำกับ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteId">Id รอบบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("note/{insigniaNoteId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> AddNoteProfile([FromBody] InsigniaNoteRequest req, Guid insigniaNoteId)
|
|
{
|
|
var profile = await _userProfileRepository.GetOfficerProfileByCitizenId(req.CitizanId, AccessToken);
|
|
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound);
|
|
|
|
var insignia = await _context.Insignias
|
|
.Include(x => x.InsigniaType)
|
|
.FirstOrDefaultAsync(x => x.Id == req.InsigniaId);
|
|
if (insignia == null)
|
|
return Error(GlobalMessages.InsigniaNotFound);
|
|
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
|
|
var profileInsignia = insigniaNote.InsigniaNoteProfiles.FirstOrDefault(x => x.ProfileId == profile.Id);
|
|
|
|
if (profileInsignia == null)
|
|
{
|
|
/* var insigniaNoteProfile = new InsigniaNoteProfile
|
|
{
|
|
Salary = profile.ProfileSalary == null || profile.ProfileSalary.Count() == 0 ? null : profile.ProfileSalary.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
|
|
IsApprove = true,
|
|
Status = "PENDING",
|
|
ProfileId = profile.Id,
|
|
Issue = req.Issue,
|
|
Number = req.Number,
|
|
DateReceive = req.DateReceive,
|
|
Date = req.Date,
|
|
VolumeNo = req.VolumeNo,
|
|
Section = req.Section,
|
|
Page = req.Page,
|
|
No = req.No,
|
|
DatePayment = req.DatePayment,
|
|
TypePayment = req.TypePayment,
|
|
Address = req.Address,
|
|
RequestInsignia = insignia,
|
|
OrganizationOrganizationReceive = req.OrganizationOrganizationReceive,
|
|
req.OrganizationOrganizationSend,
|
|
InsigniaNote = insigniaNote,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};*/
|
|
if (req.DateReceive != null && req.Date != null && profile.Id != null)
|
|
{
|
|
/*insigniaNoteProfile.Status = "DONE";*/
|
|
var profileInsigniaBody = new PostProfileInsigniaDto
|
|
{
|
|
profileId = profile.Id,
|
|
year = insigniaNote.Year,
|
|
no = req.No,
|
|
volumeNo = req.VolumeNo,
|
|
section = req.Section,
|
|
page = req.Page,
|
|
receiveDate = req.DateReceive.Value,
|
|
dateAnnounce = req.Date.Value,
|
|
insigniaId = insignia.Id,
|
|
issue = req.Issue,
|
|
note = "",
|
|
refCommandDate = null,
|
|
refCommandNo = "",
|
|
volume = "",
|
|
|
|
};
|
|
await _userProfileRepository.PostProfileInsigniaAsync(profileInsigniaBody, AccessToken);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
profileInsignia.DatePayment = req.DatePayment;
|
|
profileInsignia.TypePayment = req.TypePayment;
|
|
profileInsignia.Address = req.Address;
|
|
if (profileInsignia.Status != "DONE")
|
|
{
|
|
profileInsignia.Issue = req.Issue;
|
|
profileInsignia.Number = req.Number;
|
|
profileInsignia.DateReceive = req.DateReceive;
|
|
profileInsignia.Date = req.Date;
|
|
profileInsignia.VolumeNo = req.VolumeNo;
|
|
profileInsignia.Section = req.Section;
|
|
profileInsignia.Page = req.Page;
|
|
profileInsignia.No = req.No;
|
|
profileInsignia.RequestInsignia = insignia;
|
|
profileInsignia.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profileInsignia.LastUpdateUserId = UserId ?? "";
|
|
profileInsignia.LastUpdatedAt = DateTime.Now;
|
|
if (req.DateReceive != null && req.Date != null)
|
|
{
|
|
profileInsignia.Status = "DONE";
|
|
var profileInsigniaBody = new PostProfileInsigniaDto
|
|
{
|
|
profileId = profileInsignia.ProfileId.Value,
|
|
year = insigniaNote.Year,
|
|
no = profileInsignia.No,
|
|
volumeNo = profileInsignia.VolumeNo,
|
|
section = profileInsignia.Section,
|
|
page = profileInsignia.Page,
|
|
receiveDate = profileInsignia.DateReceive.Value,
|
|
dateAnnounce = profileInsignia.Date.Value,
|
|
insigniaId = profileInsignia.RequestInsignia.Id,
|
|
issue = profileInsignia.Issue,
|
|
note = "",
|
|
refCommandDate = null,
|
|
refCommandNo = "",
|
|
volume = "",
|
|
};
|
|
await _userProfileRepository.PostProfileInsigniaAsync(profileInsigniaBody, AccessToken);
|
|
}
|
|
}
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// เพิ่มเอกสารบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยสภรณ์/การจ่ายใบกำกับ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteId">Id รอบบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("note/doc/{insigniaNoteId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> AddDocumentProfile([FromForm] InsigniaNoteDocRequest req, Guid insigniaNoteId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_INSIGNIA_RECORD");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
|
|
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
|
{
|
|
foreach (var file in Request.Form.Files)
|
|
{
|
|
var fileExtension = Path.GetExtension(file.FileName);
|
|
|
|
var doc = await _documentService.UploadFileAsync(file, req.Name == null ? file.FileName : req.Name);
|
|
var _doc = await _context.Documents.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == doc.Id);
|
|
if (_doc != null)
|
|
{
|
|
await _context.InsigniaNoteDocs.AddAsync(new InsigniaNoteDoc
|
|
{
|
|
Reason = req.Reason,
|
|
Document = _doc,
|
|
InsigniaNote = insigniaNote,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// List เอกสารบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยสภรณ์/การจ่ายใบกำกับ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteId">Id รอบบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("note/doc/{insigniaNoteId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> GetDocumentProfile(Guid insigniaNoteId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECORD");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteDocs)
|
|
.ThenInclude(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
var insigniaNoteDocs = new List<dynamic>();
|
|
foreach (var doc in insigniaNote.InsigniaNoteDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
Reason = doc.Reason,
|
|
FileName = doc.Document.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Document.Id)
|
|
};
|
|
insigniaNoteDocs.Add(_doc);
|
|
}
|
|
return Success(insigniaNoteDocs);
|
|
}
|
|
|
|
/// <summary>
|
|
/// import บันทึกผลการได้รับเครื่องราชฯ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteId">Id รอบบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("import/receice/{insigniaNoteId:length(36)}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> ImportReceiceProfile([FromForm] ImportFileRequest req, Guid insigniaNoteId)
|
|
{
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.ThenInclude(x => x.InsigniaType)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
var file = Request.Form.Files[0];
|
|
if (!Path.GetExtension(file.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return Error("นามสกุลไฟล์ต้องเป็น .xlsx!");
|
|
}
|
|
var items = await ReadExcelImportReceive(file);
|
|
foreach (var item in items)
|
|
{
|
|
if (item.DateReceive == null || item.Date == null)
|
|
continue;
|
|
var pf = await _userProfileRepository.GetOfficerProfileByCitizenId(item.CitizanId, AccessToken);
|
|
var profile = insigniaNote.InsigniaNoteProfiles.FirstOrDefault(x => x.ProfileId == pf.Id);
|
|
if (profile == null)
|
|
{
|
|
var _insignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Name == item.RequestInsignia);
|
|
if (_insignia == null)
|
|
continue;
|
|
profile = new InsigniaNoteProfile
|
|
{
|
|
RequestDate = DateTime.Now,
|
|
Salary = pf.Amount,
|
|
IsApprove = true,
|
|
Status = "PENDIND",
|
|
Number = item.Number,
|
|
RequestInsignia = _insignia,
|
|
DateReceive = item.DateReceive,
|
|
Date = item.Date,
|
|
VolumeNo = item.VolumeNo,
|
|
Section = item.Section,
|
|
Page = item.Page,
|
|
No = item.No,
|
|
ProfileId = pf.Id,
|
|
InsigniaNote = insigniaNote,
|
|
Prefix = pf.Prefix,
|
|
FirstName = pf.FirstName,
|
|
LastName = pf.LastName,
|
|
CitizenId = pf.CitizenId,
|
|
BirthDate = pf.BirthDate,
|
|
DateAppoint = pf.DateAppoint,
|
|
Position = pf.Position,
|
|
ProfileType = pf.ProfileType,
|
|
Gender = pf.Gender,
|
|
PosTypeName = pf.PosType,
|
|
PosLevelName = pf.PosLevel,
|
|
PosNo = pf.PosNo,
|
|
Amount = pf.Amount,
|
|
PositionSalaryAmount = pf.PositionSalaryAmount,
|
|
RootId = pf.RootId,
|
|
Root = pf.Root,
|
|
Child1 = pf.Child1,
|
|
Child1Id = pf.Child1Id,
|
|
Child2 = pf.Child2,
|
|
Child2Id = pf.Child2Id,
|
|
Child3 = pf.Child3,
|
|
Child3Id = pf.Child3Id,
|
|
Child4 = pf.Child4,
|
|
Child4Id = pf.Child4Id,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.InsigniaNoteProfiles.AddAsync(profile);
|
|
}
|
|
else
|
|
{
|
|
if (profile.Status != "DONE")
|
|
{
|
|
profile.Number = item.Number;
|
|
profile.RequestInsignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Name == item.RequestInsignia) == null ? profile.RequestInsignia : await _context.Insignias.FirstOrDefaultAsync(x => x.Name == item.RequestInsignia);
|
|
profile.DateReceive = item.DateReceive;
|
|
profile.Date = item.Date;
|
|
profile.VolumeNo = item.VolumeNo;
|
|
profile.Section = item.Section;
|
|
profile.Page = item.Page;
|
|
profile.No = item.No;
|
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profile.LastUpdateUserId = UserId ?? "";
|
|
profile.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
}
|
|
if (profile.Status != "DONE")
|
|
{
|
|
profile.Status = "DONE";
|
|
var profileInsignia = new PostProfileInsigniaDto
|
|
{
|
|
profileId = profile.ProfileId.Value,
|
|
year = insigniaNote.Year,
|
|
no = profile.No,
|
|
volumeNo = profile.VolumeNo,
|
|
section = profile.Section,
|
|
page = profile.Page,
|
|
receiveDate = profile.DateReceive.Value,
|
|
dateAnnounce = profile.Date.Value,
|
|
insigniaId = profile.RequestInsignia.Id,
|
|
issue = "",
|
|
note = "",
|
|
refCommandDate = null,
|
|
refCommandNo = "",
|
|
volume = "",
|
|
};
|
|
await _userProfileRepository.PostProfileInsigniaAsync(profileInsignia, AccessToken);
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// import บันทึกผลใบกำกับเครื่องราชฯ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteId">Id รอบบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("import/invoice/{insigniaNoteId:length(36)}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> ImportInvoiceProfile([FromForm] ImportFileRequest req, Guid insigniaNoteId)
|
|
{
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
var file = Request.Form.Files[0];
|
|
if (!Path.GetExtension(file.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
|
|
return Error("นามสกุลไฟล์ต้องเป็น .xlsx!");
|
|
var items = await ReadExcelImportInvoice(file);
|
|
foreach (var item in items)
|
|
{
|
|
if (item.CitizanId == null) continue;
|
|
var pf = await _userProfileRepository.GetOfficerProfileByCitizenId(item.CitizanId, AccessToken);
|
|
var profile = insigniaNote.InsigniaNoteProfiles.FirstOrDefault(x => x.ProfileId == pf.Id);
|
|
if (profile == null)
|
|
continue;
|
|
profile.Number = item.Number;
|
|
profile.DatePayment = item.DatePayment;
|
|
profile.TypePayment = item.TypePayment;
|
|
profile.Address = item.Address;
|
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profile.LastUpdateUserId = UserId ?? "";
|
|
profile.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// preview บันทึกผลการได้รับเครื่องราชฯ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteId">Id รอบบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("preview/receice/{insigniaNoteId:length(36)}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> PreviewReceiceProfile([FromForm] ImportFileRequest req, Guid insigniaNoteId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_INSIGNIA_RECORD");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.ThenInclude(x => x.InsigniaType)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
var file = Request.Form.Files[0];
|
|
if (!Path.GetExtension(file.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
|
|
return Error("นามสกุลไฟล์ต้องเป็น .xlsx!");
|
|
var items = await ReadExcelImportReceive(file);
|
|
var _insigniaNoteProfiles = new List<dynamic>();
|
|
foreach (var item in items)
|
|
{
|
|
if (item.CitizanId == null) continue;
|
|
var _profile = await _userProfileRepository.GetOfficerProfileByCitizenId(item.CitizanId, AccessToken);
|
|
var profile = insigniaNote.InsigniaNoteProfiles.FirstOrDefault(x => x.ProfileId == _profile.Id);
|
|
if (profile == null)
|
|
{
|
|
if (_profile == null)
|
|
continue;
|
|
var _insignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Name == item.RequestInsignia);
|
|
if (_insignia == null)
|
|
continue;
|
|
profile = new InsigniaNoteProfile
|
|
{
|
|
RequestDate = DateTime.Now,
|
|
Salary = _profile.Amount,
|
|
IsApprove = true,
|
|
Status = "DONE",
|
|
Number = item.Number,
|
|
RequestInsignia = _insignia,
|
|
DateReceive = item.DateReceive,
|
|
Date = item.Date,
|
|
VolumeNo = item.VolumeNo,
|
|
Section = item.Section,
|
|
Page = item.Page,
|
|
No = item.No,
|
|
ProfileId = _profile.Id,
|
|
InsigniaNote = insigniaNote,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
Prefix = _profile.Prefix,
|
|
Position = _profile.Position,
|
|
CitizenId = _profile.CitizenId,
|
|
ProfileType = _profile.ProfileType,
|
|
FirstName = _profile.FirstName,
|
|
LastName = _profile.LastName,
|
|
BirthDate = _profile.BirthDate,
|
|
DateAppoint = _profile.DateAppoint,
|
|
Gender = _profile.Gender,
|
|
PosTypeName = _profile.PosType,
|
|
PosLevelName = _profile.PosLevel,
|
|
PosNo = _profile.PosNo,
|
|
Amount = _profile.Amount,
|
|
PositionSalaryAmount = _profile.PositionSalaryAmount,
|
|
Root = _profile.Root,
|
|
RootId = _profile.RootId,
|
|
Child1 = _profile.Child1,
|
|
Child1Id = _profile.Child1Id,
|
|
Child2 = _profile.Child2,
|
|
Child2Id = _profile.Child2Id,
|
|
Child3 = _profile.Child3,
|
|
Child3Id = _profile.Child3Id,
|
|
Child4 = _profile.Child4,
|
|
Child4Id = _profile.Child4Id,
|
|
};
|
|
}
|
|
else
|
|
{
|
|
profile.Status = "DONE";
|
|
profile.Number = item.Number;
|
|
profile.RequestInsignia = await _context.Insignias.FirstOrDefaultAsync(x => x.Name == item.RequestInsignia) == null ? profile.RequestInsignia : await _context.Insignias.FirstOrDefaultAsync(x => x.Name == item.RequestInsignia);
|
|
profile.DateReceive = item.DateReceive;
|
|
profile.Date = item.Date;
|
|
profile.VolumeNo = item.VolumeNo;
|
|
profile.Section = item.Section;
|
|
profile.Page = item.Page;
|
|
profile.No = item.No;
|
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profile.LastUpdateUserId = UserId ?? "";
|
|
profile.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
_insigniaNoteProfiles.Add(
|
|
new
|
|
{
|
|
profile.Id,
|
|
Prefix = _profile.Prefix,
|
|
Position = _profile.Position,
|
|
CitizenId = _profile.CitizenId,
|
|
ProfileType = _profile.ProfileType,
|
|
FullName = $"{_profile.Prefix}{_profile.FirstName} {_profile.LastName}",
|
|
RequestInsignia = profile.RequestInsignia == null ? null : profile.RequestInsignia.Name,
|
|
RequestInsigniaId = profile.RequestInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : profile.RequestInsignia.Id,
|
|
RequestInsigniaShortName = profile.RequestInsignia == null ? null : profile.RequestInsignia.ShortName,
|
|
profile.DateReceive,
|
|
profile.OrganizationOrganizationSend,
|
|
profile.OrganizationOrganizationReceive,
|
|
profile.Status,
|
|
profile.Issue,
|
|
profile.Date,
|
|
profile.VolumeNo,
|
|
profile.Section,
|
|
profile.Page,
|
|
profile.No,
|
|
profile.DatePayment,
|
|
profile.TypePayment,
|
|
profile.Address,
|
|
profile.Number,
|
|
profile.Salary,
|
|
}
|
|
);
|
|
}
|
|
return Success(_insigniaNoteProfiles);
|
|
}
|
|
|
|
/// <summary>
|
|
/// preview บันทึกผลใบกำกับเครื่องราชฯ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteId">Id รอบบันทึกผลเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("preview/invoice/{insigniaNoteId:length(36)}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> PreviewInvoiceProfile([FromForm] ImportFileRequest req, Guid insigniaNoteId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_INSIGNIA_RECORD");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var insigniaNote = await _context.InsigniaNotes
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.ThenInclude(x => x.InsigniaType)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.Include(x => x.InsigniaNoteProfiles)
|
|
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
|
if (insigniaNote == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound);
|
|
|
|
if (Request.Form.Files == null || Request.Form.Files.Count == 0)
|
|
{
|
|
return Error(GlobalMessages.NoFileToUpload);
|
|
}
|
|
var file = Request.Form.Files[0];
|
|
if (!Path.GetExtension(file.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return Error("นามสกุลไฟล์ต้องเป็น .xlsx!");
|
|
}
|
|
var items = await ReadExcelImportInvoice(file);
|
|
var _insigniaNoteProfiles = new List<dynamic>();
|
|
foreach (var item in items)
|
|
{
|
|
if (item.CitizanId == null) continue;
|
|
var pf = await _userProfileRepository.GetOfficerProfileByCitizenId(item.CitizanId, AccessToken);
|
|
if (pf == null) continue;
|
|
var profile = insigniaNote.InsigniaNoteProfiles.FirstOrDefault(x => x.ProfileId == pf.Id);
|
|
if (profile == null)
|
|
continue;
|
|
profile.Status = "DONE";
|
|
profile.Number = item.Number;
|
|
profile.DatePayment = item.DatePayment;
|
|
profile.TypePayment = item.TypePayment;
|
|
profile.Address = item.Address;
|
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profile.LastUpdateUserId = UserId ?? "";
|
|
profile.LastUpdatedAt = DateTime.Now;
|
|
_insigniaNoteProfiles.Add(
|
|
new
|
|
{
|
|
profile.Id,
|
|
Prefix = pf.Prefix,
|
|
Position = pf.Position,
|
|
pf.CitizenId,
|
|
pf.ProfileType,
|
|
FullName = $"{pf.Prefix}{pf.FirstName} {pf.LastName}",
|
|
RequestInsignia = profile.RequestInsignia == null ? null : profile.RequestInsignia.Name,
|
|
RequestInsigniaId = profile.RequestInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : profile.RequestInsignia.Id,
|
|
RequestInsigniaShortName = profile.RequestInsignia == null ? null : profile.RequestInsignia.ShortName,
|
|
profile.DateReceive,
|
|
profile.OrganizationOrganizationSend,
|
|
profile.OrganizationOrganizationReceive,
|
|
profile.Status,
|
|
profile.Issue,
|
|
profile.Date,
|
|
profile.VolumeNo,
|
|
profile.Section,
|
|
profile.Page,
|
|
profile.No,
|
|
profile.DatePayment,
|
|
profile.TypePayment,
|
|
profile.Address,
|
|
profile.Number,
|
|
profile.Salary,
|
|
}
|
|
);
|
|
}
|
|
return Success(_insigniaNoteProfiles);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Download รายชื่อข้าราชการสามัญฯ ที่มีสิทธิ์ยื่นขอพระราชทานเครื่องราชอิสริยาภรณ์
|
|
/// </summary>
|
|
/// <param name="RequestId">Id รอบเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("download/excel/{RequestId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> DownloadExcalInsignia(Guid RequestId)
|
|
{
|
|
var insigniaPeriod = await _context.InsigniaRequests
|
|
.Include(x => x.RequestProfiles)
|
|
.FirstOrDefaultAsync(x => x.Id == RequestId);
|
|
if (insigniaPeriod == null)
|
|
return Error(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
var template_dir = Path.Combine(_hostingEnvironment.ContentRootPath, "Templates");
|
|
var template_file = Path.Combine(template_dir, "PersonInsignia.xlsx");
|
|
var tmpDir = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp");
|
|
if (!Directory.Exists(tmpDir))
|
|
Directory.CreateDirectory(tmpDir);
|
|
|
|
var exportFile = Path.Combine(tmpDir, $"InsigniaRequestList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
|
try
|
|
{
|
|
// copy template
|
|
System.IO.File.Copy(template_file, exportFile);
|
|
|
|
using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
|
{
|
|
var workSheet = excel.Workbook.Worksheets[0];
|
|
var requestProfiles = insigniaPeriod.RequestProfiles.Where(x => x.Status == "PENDING").ToList();
|
|
var row = 2;
|
|
foreach (var item in requestProfiles)
|
|
{
|
|
workSheet.Cells[row, 1].Value = item.Root;
|
|
workSheet.Cells[row, 2].Value = item.CitizenId;
|
|
workSheet.Cells[row, 3].Value = item.Prefix == null ? "-" : ((item.Prefix == "นาย" || item.Prefix == "นาง" || item.Prefix == "นางสาว") ? item.Prefix : "-");
|
|
workSheet.Cells[row, 4].Value = item.Prefix == null ? "-" : ((item.Prefix == "นาย" || item.Prefix == "นาง" || item.Prefix == "นางสาว") ? "-" : item.Prefix);
|
|
workSheet.Cells[row, 5].Value = item.FirstName;
|
|
workSheet.Cells[row, 6].Value = item.LastName;
|
|
workSheet.Cells[row, 7].Value = item.Gender == null ? "-" : item.Gender;
|
|
workSheet.Cells[row, 8].Value = item.BirthDate == null ? "" : item.BirthDate.Value.ToThaiDate();
|
|
workSheet.Cells[row, 9].Value = item.DateAppoint == null ? "" : item.DateAppoint.Value.ToThaiDate();
|
|
workSheet.Cells[row, 12].Value = "";
|
|
workSheet.Cells[row, 13].Value = item.PosLevelName == null ? "" : item.PosLevelName;
|
|
workSheet.Cells[row, 14].Value = "";
|
|
workSheet.Cells[row, 15].Value = null;
|
|
workSheet.Cells[row, 16].Value = item.Position ?? "";
|
|
workSheet.Cells[row, 17].Value = item.Amount == null ? 0 : item.Amount;
|
|
workSheet.Cells[row, 18].Value = null;
|
|
workSheet.Cells[row, 19].Value = item.PositionSalaryAmount == null ? 0 : item.PositionSalaryAmount;
|
|
workSheet.Cells[row, 20].Value = item.LastInsigniaName;
|
|
workSheet.Cells[row, 21].Value = "";
|
|
workSheet.Cells[row, 22].Value = null;
|
|
row++;
|
|
}
|
|
excel.Save();
|
|
using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
|
{
|
|
byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
|
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
|
fs.Close();
|
|
var fname = Path.GetFileName(exportFile);
|
|
Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
|
var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
{
|
|
FileDownloadName = fname
|
|
};
|
|
return ret;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์ขอพระราชทานเครื่องราชย์ได้!!");
|
|
}
|
|
finally
|
|
{
|
|
if (System.IO.File.Exists(exportFile))
|
|
System.IO.File.Delete(exportFile);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Download รายชื่อข้าราชการสามัญฯ ที่มีสิทธิ์ยื่นขอพระราชทานเครื่องราชอิสริยาภรณ์
|
|
/// </summary>
|
|
/// <param name="RequestId">Id การขอเครื่องราช (Request)</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("download/excel/{RequestId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> DownloadExcelInsigniaByFilter([FromBody] ExportFileInsigniaRequest req, Guid RequestId)
|
|
{
|
|
var insigniaPeriod = await _context.InsigniaRequests
|
|
.Include(x => x.RequestProfiles)
|
|
.ThenInclude(x => x.RequestInsignia)
|
|
.FirstOrDefaultAsync(x => x.Id == RequestId);
|
|
if (insigniaPeriod == null)
|
|
return Error(GlobalMessages.InsigniaPeriodNotFound);
|
|
|
|
var template_dir = Path.Combine(_hostingEnvironment.ContentRootPath, "Templates");
|
|
var template_file = Path.Combine(template_dir, "PersonInsignia.xlsx");
|
|
var tmpDir = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp");
|
|
if (!Directory.Exists(tmpDir))
|
|
Directory.CreateDirectory(tmpDir);
|
|
|
|
var exportFile = Path.Combine(tmpDir, $"InsigniaRequestList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
|
|
try
|
|
{
|
|
// copy template
|
|
System.IO.File.Copy(template_file, exportFile);
|
|
|
|
using (var excel = new ExcelPackage(new FileInfo(exportFile)))
|
|
{
|
|
var workSheet = excel.Workbook.Worksheets[0];
|
|
var requestProfiles = insigniaPeriod.RequestProfiles.Where(x => x.Status == "PENDING").ToList();
|
|
if (req.ProfileType != null)
|
|
requestProfiles = requestProfiles.Where(x => x.ProfileId != null)
|
|
.ToList();
|
|
if (req.InsigniaId != null)
|
|
requestProfiles = requestProfiles.Where(x => x.RequestInsignia.Id == req.InsigniaId).ToList();
|
|
var row = 2;
|
|
foreach (var item in requestProfiles)
|
|
{
|
|
workSheet.Cells[row, 1].Value = item.Root == null ? "-" : item.Root;
|
|
workSheet.Cells[row, 2].Value = item.CitizenId == null ? "-" : item.CitizenId;
|
|
workSheet.Cells[row, 3].Value = item.Prefix == null ? "-" : ((item.Prefix == "นาย" || item.Prefix == "นาง" || item.Prefix == "นางสาว") ? item.Prefix : "-");
|
|
workSheet.Cells[row, 4].Value = item.Prefix == null ? "-" : ((item.Prefix == "นาย" || item.Prefix == "นาง" || item.Prefix == "นางสาว") ? "-" : item.Prefix);
|
|
workSheet.Cells[row, 5].Value = item.FirstName == null ? "-" : item.FirstName;
|
|
workSheet.Cells[row, 6].Value = item.LastName == null ? "-" : item.LastName;
|
|
workSheet.Cells[row, 7].Value = item.Gender == null ? "-" : item.Gender;
|
|
workSheet.Cells[row, 8].Value = item.BirthDate == null ? "-" : item.BirthDate.Value.ToThaiDate();
|
|
workSheet.Cells[row, 9].Value = item.DateAppoint == null ? "-" : item.DateAppoint.Value.ToThaiDate();
|
|
workSheet.Cells[row, 10].Value = "-";
|
|
workSheet.Cells[row, 11].Value = "-";
|
|
workSheet.Cells[row, 12].Value = "-";
|
|
workSheet.Cells[row, 13].Value = item.PosLevelName == null ? "-" : item.PosLevelName;
|
|
workSheet.Cells[row, 14].Value = "-";
|
|
workSheet.Cells[row, 15].Value = "-";
|
|
workSheet.Cells[row, 16].Value = item.Position == null ? "-" : item.Position;
|
|
workSheet.Cells[row, 17].Value = item.Amount == null ? 0 : item.Amount;
|
|
workSheet.Cells[row, 18].Value = "-";
|
|
workSheet.Cells[row, 19].Value = item.PositionSalaryAmount == null ? 0 : item.PositionSalaryAmount;
|
|
workSheet.Cells[row, 20].Value = item.LastInsigniaName == null ? "-" : item.LastInsigniaName;
|
|
workSheet.Cells[row, 21].Value = "-";
|
|
workSheet.Cells[row, 22].Value = "-";
|
|
row++;
|
|
}
|
|
excel.Save();
|
|
using (FileStream fs = new FileStream(exportFile, FileMode.Open, FileAccess.Read))
|
|
{
|
|
byte[] bytes = System.IO.File.ReadAllBytes(exportFile);
|
|
fs.Read(bytes, 0, System.Convert.ToInt32(fs.Length));
|
|
fs.Close();
|
|
var fname = Path.GetFileName(exportFile);
|
|
Response.Headers["Content-Disposition"] = $"inline; filename={fname}";
|
|
var ret = new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
{
|
|
FileDownloadName = fname
|
|
};
|
|
return ret;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Error(ex, "ไม่สามารถส่งออกรายชื่อผู้มีสิทธิ์ขอพระราชทานเครื่องราชย์ได้!!");
|
|
}
|
|
finally
|
|
{
|
|
if (System.IO.File.Exists(exportFile))
|
|
System.IO.File.Delete(exportFile);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upload เอกสาร เครื่องราชฯ
|
|
/// </summary>
|
|
/// <param name="requestId">Id รอบเครื่องราช</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("upload/{requestId:length(36)}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> UpdatePersonDeferment([FromForm] ImportFileRequest req, Guid requestId)
|
|
{
|
|
var insigniaRequest = await _context.InsigniaRequests.AsNoTracking().Include(x => x.Document).Where(x => x.Id == requestId).FirstOrDefaultAsync();
|
|
if (insigniaRequest == null)
|
|
return Error(GlobalMessages.InsigniaRequestNotFound, 404);
|
|
|
|
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
|
{
|
|
if (insigniaRequest.Document != null)
|
|
{
|
|
await _documentService.DeleteFileAsync(insigniaRequest.Document.Id);
|
|
}
|
|
var file = Request.Form.Files[0];
|
|
var fileExtension = Path.GetExtension(file.FileName);
|
|
|
|
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
|
insigniaRequest.Document = doc;
|
|
}
|
|
insigniaRequest.LastUpdateFullName = FullName ?? "System Administrator";
|
|
insigniaRequest.LastUpdateUserId = UserId ?? "";
|
|
insigniaRequest.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ยื่นรายการคืนเครื่องราชฯ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteProfileId">Id บุคคลบันทึกผลเครื่องราชฯ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("note/return/{insigniaNoteProfileId:length(36)}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> UpdateReturnNoteInsignia([FromForm] InsigniaNoteReturnRequest req, Guid insigniaNoteProfileId)
|
|
{
|
|
var insigniaNoteProfile = await _context.InsigniaNoteProfiles.Include(x => x.DocReturnInsignia).Where(x => x.Id == insigniaNoteProfileId).FirstOrDefaultAsync();
|
|
if (insigniaNoteProfile == null)
|
|
return Error(GlobalMessages.InsigniaRequestProfileNotFound, 404);
|
|
|
|
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
|
{
|
|
if (insigniaNoteProfile.DocReturnInsignia != null)
|
|
{
|
|
await _documentService.DeleteFileAsync(insigniaNoteProfile.DocReturnInsignia.Id);
|
|
}
|
|
var file = Request.Form.Files[0];
|
|
var fileExtension = Path.GetExtension(file.FileName);
|
|
|
|
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
|
insigniaNoteProfile.DocReturnInsignia = doc;
|
|
}
|
|
var root = _userProfileRepository.GetOc(req.OrgId, 0, AccessToken)?.Root ?? null;
|
|
if (req.OrgId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
|
{
|
|
if (root == null)
|
|
return Error(GlobalMessages.OCNotFound, 404);
|
|
}
|
|
else
|
|
{
|
|
root = "สำนักนายกรัฐมนตรี";
|
|
}
|
|
insigniaNoteProfile.OrgReturnInsignia = root;
|
|
insigniaNoteProfile.OrgReturnInsigniaId = req.OrgId;
|
|
insigniaNoteProfile.DateReturnInsignia = req.Date;
|
|
insigniaNoteProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
insigniaNoteProfile.LastUpdateUserId = UserId ?? "";
|
|
insigniaNoteProfile.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ยื่นรายการรับเครื่องราชฯ
|
|
/// </summary>
|
|
/// <param name="insigniaNoteProfileId">Id บุคคลบันทึกผลเครื่องราชฯ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("note/receive/{insigniaNoteProfileId:length(36)}"), DisableRequestSizeLimit]
|
|
public async Task<ActionResult<ResponseObject>> UpdateReceiveNoteInsignia([FromForm] InsigniaNoteReturnRequest req, Guid insigniaNoteProfileId)
|
|
{
|
|
var insigniaNoteProfile = await _context.InsigniaNoteProfiles.Include(x => x.DocReceiveInsignia).Where(x => x.Id == insigniaNoteProfileId).FirstOrDefaultAsync();
|
|
if (insigniaNoteProfile == null)
|
|
return Error(GlobalMessages.InsigniaRequestProfileNotFound, 404);
|
|
|
|
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
|
{
|
|
if (insigniaNoteProfile.DocReceiveInsignia != null)
|
|
{
|
|
await _documentService.DeleteFileAsync(insigniaNoteProfile.DocReceiveInsignia.Id);
|
|
}
|
|
|
|
var file = Request.Form.Files[0];
|
|
var fileExtension = Path.GetExtension(file.FileName);
|
|
|
|
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
|
insigniaNoteProfile.DocReceiveInsignia = doc;
|
|
}
|
|
var root = _userProfileRepository.GetOc(req.OrgId, 0, AccessToken)?.Root ?? null;
|
|
if (req.OrgId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
|
{
|
|
if (root == null)
|
|
return Error(GlobalMessages.OCNotFound, 404);
|
|
}
|
|
else
|
|
{
|
|
root = "สำนักนายกรัฐมนตรี";
|
|
}
|
|
insigniaNoteProfile.OrgReceiveInsignia = root;
|
|
insigniaNoteProfile.OrgReceiveInsigniaId = req.OrgId;
|
|
insigniaNoteProfile.DateReceiveInsignia = req.Date;
|
|
insigniaNoteProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
insigniaNoteProfile.LastUpdateUserId = UserId ?? "";
|
|
insigniaNoteProfile.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
}
|
|
}
|