แก้ api พ้นราชการ

This commit is contained in:
Kittapath 2024-05-21 19:41:55 +07:00
parent 2a3a151f34
commit 63b02dcc4c
19 changed files with 54771 additions and 431 deletions

View file

@ -835,10 +835,10 @@ namespace BMA.EHR.Application.Repositories.Commands
var report_data = (from r in raw_data var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementResign>() join p in _dbContext.Set<RetirementResign>()
.Include(p => p.Profile) //.Include(p => p.Profile)
.ThenInclude(p => p.Position) //.ThenInclude(p => p.Position)
.Include(p => p.Profile) //.Include(p => p.Profile)
.ThenInclude(p => p.Salaries) //.ThenInclude(p => p.Salaries)
on r.RefPlacementProfileId equals p.Id on r.RefPlacementProfileId equals p.Id
orderby r.Sequence orderby r.Sequence
select new CommandType17Response select new CommandType17Response
@ -846,7 +846,7 @@ namespace BMA.EHR.Application.Repositories.Commands
Seq = r.Sequence.ToString().ToThaiNumber(), Seq = r.Sequence.ToString().ToThaiNumber(),
CitizenId = r.CitizenId, CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
PositionName = p.Profile.Position == null ? "" : p.Profile.Position.Name, PositionName = p.position ?? "",
Organization = p.OrganizationPositionOld ?? "", Organization = p.OrganizationPositionOld ?? "",
PositionLevel = p.PositionLevelOld ?? "", PositionLevel = p.PositionLevelOld ?? "",
PositionType = p.PositionTypeOld ?? "", PositionType = p.PositionTypeOld ?? "",
@ -1165,20 +1165,20 @@ namespace BMA.EHR.Application.Repositories.Commands
var report_data = (from r in raw_data var report_data = (from r in raw_data
join p in _dbContext.Set<RetirementResign>() join p in _dbContext.Set<RetirementResign>()
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.Position) //.ThenInclude(x => x.Position)
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.PositionLevel) //.ThenInclude(x => x.PositionLevel)
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.PositionType) //.ThenInclude(x => x.PositionType)
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.PosNo) //.ThenInclude(x => x.PosNo)
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.PositionEmployeePosition) //.ThenInclude(x => x.PositionEmployeePosition)
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.PositionEmployeeLevel) //.ThenInclude(x => x.PositionEmployeeLevel)
//.Include(x => x.OrgEmployee) //.Include(x => x.OrgEmployee)
//.ThenInclude(x => x.OrganizationAgency) //.ThenInclude(x => x.OrganizationAgency)
//.ThenInclude(x => x.OrganizationOrganization) //.ThenInclude(x => x.OrganizationOrganization)
@ -1197,7 +1197,7 @@ namespace BMA.EHR.Application.Repositories.Commands
CitizenId = r.CitizenId.ToThaiNumber(), CitizenId = r.CitizenId.ToThaiNumber(),
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
Organization = p.OrganizationPositionOld ?? "", Organization = p.OrganizationPositionOld ?? "",
PositionName = p.Profile.PositionEmployeePosition == null ? "" : p.Profile.PositionEmployeePosition.Name.ToThaiNumber(), PositionName = p.position ?? "",
PositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld.ToThaiNumber(), PositionLevel = p.PositionLevelOld == null ? "" : p.PositionLevelOld.ToThaiNumber(),
PositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld.ToThaiNumber(), PositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld.ToThaiNumber(),
PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(),

View file

@ -1249,13 +1249,13 @@ namespace BMA.EHR.Application.Repositories.Commands
// 2. Query // 2. Query
var appointPeople = await _dbContext.Set<RetirementResign>() var appointPeople = await _dbContext.Set<RetirementResign>()
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.Prefix) //.ThenInclude(x => x.Prefix)
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) .Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Profile.ProfileType == "officer") // .Where(x => x.Profile.ProfileType == "officer")
.Where(x => x.Status.Trim().ToUpper() == "REPORT") .Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.Profile!.CitizenId) .OrderBy(x => x.citizenId)
.ToListAsync(); .ToListAsync();
// 3. Create new Record // 3. Create new Record
@ -1265,10 +1265,10 @@ namespace BMA.EHR.Application.Repositories.Commands
var receiver = new CommandReceiver var receiver = new CommandReceiver
{ {
Sequence = seq, Sequence = seq,
CitizenId = item.Profile!.CitizenId!, CitizenId = item.citizenId,
Prefix = item.Profile!.Prefix!.Name, Prefix = item.prefix,
FirstName = item.Profile!.FirstName!, FirstName = item.firstName,
LastName = item.Profile!.LastName!, LastName = item.lastName,
RefPlacementProfileId = item.Id, RefPlacementProfileId = item.Id,
Amount = item.AmountOld, Amount = item.AmountOld,
}; };
@ -1691,13 +1691,13 @@ namespace BMA.EHR.Application.Repositories.Commands
// 2. Query // 2. Query
var appointPeople = await _dbContext.Set<RetirementResign>() var appointPeople = await _dbContext.Set<RetirementResign>()
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.Prefix) //.ThenInclude(x => x.Prefix)
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) .Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Profile.ProfileType == "employee") // .Where(x => x.Profile.ProfileType == "employee")
.Where(x => x.Status.Trim().ToUpper() == "REPORT") .Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.Profile!.CitizenId) .OrderBy(x => x.citizenId)
.ToListAsync(); .ToListAsync();
// 3. Create new Record // 3. Create new Record
@ -1707,10 +1707,10 @@ namespace BMA.EHR.Application.Repositories.Commands
var receiver = new CommandReceiver var receiver = new CommandReceiver
{ {
Sequence = seq, Sequence = seq,
CitizenId = item.Profile!.CitizenId!, CitizenId = item.citizenId,
Prefix = item.Profile!.Prefix!.Name, Prefix = item.prefix,
FirstName = item.Profile!.FirstName!, FirstName = item.firstName,
LastName = item.Profile!.LastName!, LastName = item.lastName,
RefPlacementProfileId = item.Id, RefPlacementProfileId = item.Id,
Amount = item.AmountOld, Amount = item.AmountOld,
}; };
@ -5644,7 +5644,7 @@ namespace BMA.EHR.Application.Repositories.Commands
//var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); //var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
//var order = 1; //var order = 1;
//if (lastSarary != null && lastSarary.Order != null) //if (lastSarary != null && lastSarary.Order != null)
//order = lastSarary.Order.Value + 1; //order = lastSarary.Order.Value + 1;
// var salary = new ProfileSalary // var salary = new ProfileSalary
// { // {
@ -6526,85 +6526,85 @@ namespace BMA.EHR.Application.Repositories.Commands
foreach (var recv in command.Receivers) foreach (var recv in command.Receivers)
{ {
var data = await _dbContext.Set<RetirementResign>() var data = await _dbContext.Set<RetirementResign>()
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.Salaries) //.ThenInclude(x => x.Salaries)
.ThenInclude(x => x.PositionLevel) //.ThenInclude(x => x.PositionLevel)
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null) if (data == null)
throw new Exception(GlobalMessages.DataNotFound); throw new Exception(GlobalMessages.DataNotFound);
data.Profile.IsActive = false; // data.Profile.IsActive = false;
data.Profile.IsLeave = true; // data.Profile.IsLeave = true;
data.Profile.LeaveReason = "ลาออกจากราชการ"; // data.Profile.LeaveReason = "ลาออกจากราชการ";
data.Profile.LeaveDate = command.CommandAffectDate; // data.Profile.LeaveDate = command.CommandAffectDate;
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); // var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
var order = 1; // var order = 1;
if (lastSarary != null && lastSarary.Order != null) // if (lastSarary != null && lastSarary.Order != null)
order = lastSarary.Order.Value + 1; // order = lastSarary.Order.Value + 1;
var salary = new ProfileSalary // var salary = new ProfileSalary
{ // {
Order = order, // Order = order,
Date = command.CommandAffectDate, // Date = command.CommandAffectDate,
Amount = lastSarary == null ? null : lastSarary.Amount, // Amount = lastSarary == null ? null : lastSarary.Amount,
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
SalaryClass = "", // SalaryClass = "",
SalaryRef = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", // SalaryRef = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
OcId = lastSarary == null ? null : lastSarary.OcId, // OcId = lastSarary == null ? null : lastSarary.OcId,
PositionId = lastSarary == null ? null : lastSarary.PositionId, // PositionId = lastSarary == null ? null : lastSarary.PositionId,
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
PosNoId = lastSarary == null ? null : lastSarary.PosNoId, // PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
CommandTypeName = command.CommandType.Name, // CommandTypeName = command.CommandType.Name,
PositionEmployeeGroupId = null, // PositionEmployeeGroupId = null,
PositionEmployeeLevelId = null, // PositionEmployeeLevelId = null,
PositionEmployeePositionId = null, // PositionEmployeePositionId = null,
PositionEmployeePositionSideId = null, // PositionEmployeePositionSideId = null,
PosNoEmployee = "", // PosNoEmployee = "",
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
IsActive = true, // IsActive = true,
CreatedAt = DateTime.Now, // CreatedAt = DateTime.Now,
CreatedFullName = FullName ?? "System Administrator", // CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "", // CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now, // LastUpdatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator", // LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "", // LastUpdateUserId = UserId ?? "",
}; // };
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; // if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; // if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
data.Profile.Salaries.Add(salary); // data.Profile.Salaries.Add(salary);
// remove profile position // // remove profile position
var profilePosition = await _dbContext.Set<ProfilePosition>() // var profilePosition = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile) // .Include(x => x.Profile)
.Include(x => x.OrganizationPosition) // .Include(x => x.OrganizationPosition)
.FirstOrDefaultAsync(x => x.Profile!.Id == data.Profile.Id); // .FirstOrDefaultAsync(x => x.Profile!.Id == data.Profile.Id);
if (profilePosition != null) // if (profilePosition != null)
_dbContext.Set<ProfilePosition>().Remove(profilePosition); // _dbContext.Set<ProfilePosition>().Remove(profilePosition);
// update placementstatus // // update placementstatus
data.Status = "DONE"; data.Status = "DONE";
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
@ -6620,7 +6620,7 @@ namespace BMA.EHR.Application.Repositories.Commands
{ {
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Profile.Id, KeycloakUserId = data.CreatedUserId,
Payload = payload_str, Payload = payload_str,
}; };
_dbContext.Set<Inbox>().Add(inbox); _dbContext.Set<Inbox>().Add(inbox);
@ -6628,7 +6628,7 @@ namespace BMA.EHR.Application.Repositories.Commands
var noti = new Notification var noti = new Notification
{ {
Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Profile.Id, KeycloakUserId = data.CreatedUserId,
Type = "LINK", Type = "LINK",
Payload = payload_str, Payload = payload_str,
}; };
@ -6636,44 +6636,44 @@ namespace BMA.EHR.Application.Repositories.Commands
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
} }
// send cc noti inbox // // send cc noti inbox
foreach (var cc in command.Deployments) // foreach (var cc in command.Deployments)
{ // {
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); // var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
if (pf != null) // if (pf != null)
{ // {
if (cc.IsSendInbox) // if (cc.IsSendInbox)
{ // {
var inbox = new Inbox // var inbox = new Inbox
{ // {
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id, // ReceiverUserId = pf.Id,
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Inbox>().Add(inbox); // _dbContext.Set<Inbox>().Add(inbox);
} // }
if (cc.IsSendMail) // if (cc.IsSendMail)
{ // {
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email // // Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com"); // _emailSenderService.SendMail(subject, body, "dev@frappet.com");
} // }
var noti = new Notification // var noti = new Notification
{ // {
Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id, // ReceiverUserId = pf.Id,
Type = "LINK", // Type = "LINK",
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Notification>().Add(noti); // _dbContext.Set<Notification>().Add(noti);
} // }
} // }
// change command status // change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5); var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
@ -7689,76 +7689,76 @@ namespace BMA.EHR.Application.Repositories.Commands
foreach (var recv in command.Receivers) foreach (var recv in command.Receivers)
{ {
var data = await _dbContext.Set<RetirementResign>() var data = await _dbContext.Set<RetirementResign>()
.Include(x => x.Profile) //.Include(x => x.Profile)
.ThenInclude(x => x.Salaries) //.ThenInclude(x => x.Salaries)
.ThenInclude(x => x.PositionLevel) //.ThenInclude(x => x.PositionLevel)
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null) if (data == null)
throw new Exception(GlobalMessages.DataNotFound); throw new Exception(GlobalMessages.DataNotFound);
data.Profile.IsActive = false; // data.Profile.IsActive = false;
data.Profile.IsLeave = true; // data.Profile.IsLeave = true;
data.Profile.LeaveReason = "ลาออกจากราชการ"; // data.Profile.LeaveReason = "ลาออกจากราชการ";
data.Profile.LeaveDate = command.CommandAffectDate; // data.Profile.LeaveDate = command.CommandAffectDate;
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); // var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
var order = 1; // var order = 1;
if (lastSarary != null && lastSarary.Order != null) // if (lastSarary != null && lastSarary.Order != null)
order = lastSarary.Order.Value + 1; // order = lastSarary.Order.Value + 1;
var salary = new ProfileSalary // var salary = new ProfileSalary
{ // {
Order = order, // Order = order,
Date = command.CommandAffectDate, // Date = command.CommandAffectDate,
Amount = lastSarary == null ? null : lastSarary.Amount, // Amount = lastSarary == null ? null : lastSarary.Amount,
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
SalaryClass = "", // SalaryClass = "",
SalaryRef = "คำสั่งให้ลูกจ้างออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", // SalaryRef = "คำสั่งให้ลูกจ้างออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
OcId = lastSarary == null ? null : lastSarary.OcId, // OcId = lastSarary == null ? null : lastSarary.OcId,
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
PosNoId = lastSarary == null ? null : lastSarary.PosNoId, // PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
CommandTypeName = command.CommandType.Name, // CommandTypeName = command.CommandType.Name,
PositionEmployeeGroupId = null, // PositionEmployeeGroupId = null,
PositionEmployeeLevelId = null, // PositionEmployeeLevelId = null,
PositionEmployeePositionId = null, // PositionEmployeePositionId = null,
PositionEmployeePositionSideId = null, // PositionEmployeePositionSideId = null,
PosNoEmployee = "", // PosNoEmployee = "",
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
IsActive = true, // IsActive = true,
CreatedAt = DateTime.Now, // CreatedAt = DateTime.Now,
CreatedFullName = FullName ?? "System Administrator", // CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "", // CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now, // LastUpdatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator", // LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "", // LastUpdateUserId = UserId ?? "",
}; // };
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; // if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; // if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
data.Profile.Salaries.Add(salary); // data.Profile.Salaries.Add(salary);
// update placementstatus // // update placementstatus
data.Status = "DONE"; data.Status = "DONE";
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
@ -7774,7 +7774,7 @@ namespace BMA.EHR.Application.Repositories.Commands
{ {
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Profile.Id, KeycloakUserId = data.CreatedUserId,
Payload = payload_str, Payload = payload_str,
}; };
_dbContext.Set<Inbox>().Add(inbox); _dbContext.Set<Inbox>().Add(inbox);
@ -7782,7 +7782,7 @@ namespace BMA.EHR.Application.Repositories.Commands
var noti = new Notification var noti = new Notification
{ {
Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Profile.Id, KeycloakUserId = data.CreatedUserId,
Type = "LINK", Type = "LINK",
Payload = payload_str, Payload = payload_str,
}; };
@ -7790,44 +7790,44 @@ namespace BMA.EHR.Application.Repositories.Commands
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
} }
// send cc noti inbox // // send cc noti inbox
foreach (var cc in command.Deployments) // foreach (var cc in command.Deployments)
{ // {
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); // var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
if (pf != null) // if (pf != null)
{ // {
if (cc.IsSendInbox) // if (cc.IsSendInbox)
{ // {
var inbox = new Inbox // var inbox = new Inbox
{ // {
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id, // ReceiverUserId = pf.Id,
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Inbox>().Add(inbox); // _dbContext.Set<Inbox>().Add(inbox);
} // }
if (cc.IsSendMail) // if (cc.IsSendMail)
{ // {
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email // // Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com"); // _emailSenderService.SendMail(subject, body, "dev@frappet.com");
} // }
var noti = new Notification // var noti = new Notification
{ // {
Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id, // ReceiverUserId = pf.Id,
Type = "LINK", // Type = "LINK",
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Notification>().Add(noti); // _dbContext.Set<Notification>().Add(noti);
} // }
} // }
// change command status // change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5); var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);

View file

@ -342,11 +342,10 @@ namespace BMA.EHR.Application.Repositories.Reports
.Select(p => new .Select(p => new
{ {
p.Id, p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name, p.prefix,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id, p.firstName,
p.Profile.FirstName, p.lastName,
p.Profile.LastName, p.profileId,
ProfileId = p.Profile.Id,
p.Location, p.Location,
p.SendDate, p.SendDate,
p.ActiveDate, p.ActiveDate,
@ -378,12 +377,12 @@ namespace BMA.EHR.Application.Repositories.Reports
var _data = new var _data = new
{ {
data.Id, data.Id,
data.ProfileId, data.profileId,
data.Prefix, data.prefix,
data.FirstName, data.firstName,
data.LastName, data.lastName,
data.Location, data.Location,
FullName = $"{data.Prefix}{data.FirstName} {data.LastName}", FullName = $"{data.prefix}{data.firstName} {data.lastName}",
SendDate = string.IsNullOrEmpty(data.SendDate.ToString()) ? string.Empty : DateTime.Parse(data.SendDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(), SendDate = string.IsNullOrEmpty(data.SendDate.ToString()) ? string.Empty : DateTime.Parse(data.SendDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(),
ActiveDate = string.IsNullOrEmpty(data.ActiveDate.ToString()) ? string.Empty : DateTime.Parse(data.ActiveDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(), ActiveDate = string.IsNullOrEmpty(data.ActiveDate.ToString()) ? string.Empty : DateTime.Parse(data.ActiveDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(),
data.Reason, data.Reason,

View file

@ -7,7 +7,7 @@
public Guid ReceiverUserId { get; set; } = Guid.Empty; public Guid ReceiverUserId { get; set; } = Guid.Empty;
public string KeycloakUserId { get; set; } public string? KeycloakUserId { get; set; }
public string Type { get; set; } = "TEXT"; public string Type { get; set; } = "TEXT";

View file

@ -16,7 +16,7 @@ namespace BMA.EHR.Domain.Models.Notifications
[Comment("รหัสผู้รับข้อความ")] [Comment("รหัสผู้รับข้อความ")]
public Guid ReceiverUserId { get; set; } public Guid ReceiverUserId { get; set; }
public string KeycloakUserId { get; set; } public string? KeycloakUserId { get; set; }
[Column(TypeName = "text"), Comment("สิงที่แนบมาด้วย")] [Column(TypeName = "text"), Comment("สิงที่แนบมาด้วย")]
public string Payload { get; set; } public string Payload { get; set; }

View file

@ -13,7 +13,7 @@ namespace BMA.EHR.Domain.Models.Notifications
[Comment("รหัสผู้รับข้อความ")] [Comment("รหัสผู้รับข้อความ")]
public Guid ReceiverUserId { get; set; } public Guid ReceiverUserId { get; set; }
public string KeycloakUserId { get; set; } public string? KeycloakUserId { get; set; }
[Required, Comment("ประเภทการแจ้งเตือน")] [Required, Comment("ประเภทการแจ้งเตือน")]
public string Type { get; set; } public string Type { get; set; }

View file

@ -19,8 +19,8 @@ namespace BMA.EHR.Domain.Models.Retirement
public DateTime? ActiveDate { get; set; } public DateTime? ActiveDate { get; set; }
[Comment("เหตุผลที่ลาออกจากราชการ")] [Comment("เหตุผลที่ลาออกจากราชการ")]
public string? Reason { get; set; } = string.Empty; public string? Reason { get; set; } = string.Empty;
[Comment("Id ผู้ลาออก")] // [Comment("Id ผู้ลาออก")]
public Profile Profile { get; set; } // public Profile Profile { get; set; }
[Comment("สังกัด")] [Comment("สังกัด")]
public string? OrganizationPositionOld { get; set; } public string? OrganizationPositionOld { get; set; }
[Comment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท")] [Comment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท")]
@ -37,8 +37,12 @@ namespace BMA.EHR.Domain.Models.Retirement
public string? ApproveReason { get; set; } public string? ApproveReason { get; set; }
[Comment("เหตุผลไม่อนุมัติ")] [Comment("เหตุผลไม่อนุมัติ")]
public string? RejectReason { get; set; } public string? RejectReason { get; set; }
[Comment("เหตุผลยกเลิก")]
public string? CancelReason { get; set; }
[Comment("สถานะการใช้งาน")] [Comment("สถานะการใช้งาน")]
public bool IsActive { get; set; } = true; public bool IsActive { get; set; } = true;
[Comment("สถานะไม่เป็นหนี้สหกรณ์")]
public bool IsNoDebt { get; set; } = false;
[Comment("สถานะยับยั้งผู้ดูแล")] [Comment("สถานะยับยั้งผู้ดูแล")]
public bool? OligarchReject { get; set; } public bool? OligarchReject { get; set; }
[Comment("เหตุผลอนุมัติผู้ดูแล")] [Comment("เหตุผลอนุมัติผู้ดูแล")]
@ -57,7 +61,70 @@ namespace BMA.EHR.Domain.Models.Retirement
public DateTime? CommanderRejectDate { get; set; } public DateTime? CommanderRejectDate { get; set; }
[Comment("หมายเหตุแนวนอน")] [Comment("หมายเหตุแนวนอน")]
public string? RemarkHorizontal { get; set; } public string? RemarkHorizontal { get; set; }
[Comment("สังกัดเดิม")]
public string? OrganizationOld { get; set; }
[Comment("ตำแหน่งเดิม")]
public string? PositionOld { get; set; }
[Comment("profile Id")]
public string? profileId { get; set; }
[Comment("คำนำหน้า")]
public string? prefix { get; set; }
[Comment("ชื่อ")]
public string? firstName { get; set; }
[Comment("นามสกุล")]
public string? lastName { get; set; }
[Comment("เลขบัตรประชาชน")]
public string? citizenId { get; set; }
[Comment("ชื่อหน่วยงาน root")]
public string? root { get; set; }
[Comment("id หน่วยงาน root")]
public string? rootId { get; set; }
[Comment("ชื่อย่อหน่วยงาน root")]
public string? rootShortName { get; set; }
[Comment("ชื่อหน่วยงาน child1")]
public string? child1 { get; set; }
[Comment("id หน่วยงาน child1")]
public string? child1Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child1")]
public string? child1ShortName { get; set; }
[Comment("ชื่อหน่วยงาน child2")]
public string? child2 { get; set; }
[Comment("id หน่วยงาน child2")]
public string? child2Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child2")]
public string? child2ShortName { get; set; }
[Comment("ชื่อหน่วยงาน child3")]
public string? child3 { get; set; }
[Comment("id หน่วยงาน child3")]
public string? child3Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child3")]
public string? child3ShortName { get; set; }
[Comment("ชื่อหน่วยงาน child4")]
public string? child4 { get; set; }
[Comment("id หน่วยงาน child4")]
public string? child4Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child4")]
public string? child4ShortName { get; set; }
// [Comment("id revision")]
// public string? orgRevisionId { get; set; }
[Comment("เลขที่ตำแหน่ง")]
public int? posMasterNo { get; set; }
[Comment("ชื่อตำแหน่งในสายงาน")]
public string? position { get; set; }
[Comment("id ประเภทตำแหน่ง")]
public string? posTypeId { get; set; }
[Comment("ชื่อประเภทตำแหน่ง")]
public string? posTypeName { get; set; }
[Comment("id ระดับตำแหน่ง")]
public string? posLevelId { get; set; }
[Comment("ชื่อระดับตำแหน่ง")]
public string? posLevelName { get; set; }
public virtual List<RetirementResignDoc> RetirementResignDocs { get; set; } = new List<RetirementResignDoc>(); public virtual List<RetirementResignDoc> RetirementResignDocs { get; set; } = new List<RetirementResignDoc>();
public virtual List<RetirementResignDebtDoc> RetirementResignDebtDocs { get; set; } = new List<RetirementResignDebtDoc>();
} }
} }

View file

@ -0,0 +1,15 @@
using BMA.EHR.Domain.Models.Base;
using BMA.EHR.Domain.Models.Documents;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
namespace BMA.EHR.Domain.Models.Retirement
{
public class RetirementResignDebtDoc : EntityBase
{
[Required, Comment("อ้างอิงรหัสเอกสาร")]
public Document Document { get; set; }
[Required, Comment("อ้างอิงรับย้าย")]
public virtual RetirementResign RetirementResign { get; set; }
}
}

View file

@ -0,0 +1,397 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updatetableRetirementResignsaddchild : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_RetirementResigns_Profiles_ProfileId",
table: "RetirementResigns");
migrationBuilder.DropIndex(
name: "IX_RetirementResigns_ProfileId",
table: "RetirementResigns");
migrationBuilder.RenameColumn(
name: "ProfileId",
table: "RetirementResigns",
newName: "profileId");
migrationBuilder.AlterColumn<string>(
name: "profileId",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "profile Id",
oldClrType: typeof(Guid),
oldType: "char(36)")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("Relational:Collation", "ascii_general_ci");
migrationBuilder.AddColumn<string>(
name: "OrganizationOld",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "สังกัดเดิม")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "PositionOld",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ตำแหน่งเดิม")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child1",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child1")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child1Id",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child1")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child1ShortName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child1")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child2",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child2")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child2Id",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child2")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child2ShortName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child2")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child3",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child3")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child3Id",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child3")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child3ShortName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child3")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child4",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child4")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child4Id",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child4")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child4ShortName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child4")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "citizenId",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "เลขบัตรประชาชน")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "firstName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อ")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "lastName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "นามสกุล")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "posLevelId",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "id ระดับตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "posLevelName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อระดับตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "posMasterNo",
table: "RetirementResigns",
type: "int",
nullable: true,
comment: "เลขที่ตำแหน่ง");
migrationBuilder.AddColumn<string>(
name: "posTypeId",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "id ประเภทตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "posTypeName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อประเภทตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "position",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อตำแหน่งในสายงาน")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "prefix",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "คำนำหน้า")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "root",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน root")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "rootId",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน root")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "rootShortName",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน root")
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "OrganizationOld",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "PositionOld",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child1",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child1Id",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child1ShortName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child2",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child2Id",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child2ShortName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child3",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child3Id",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child3ShortName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child4",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child4Id",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "child4ShortName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "citizenId",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "firstName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "lastName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "posLevelId",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "posLevelName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "posMasterNo",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "posTypeId",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "posTypeName",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "position",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "prefix",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "root",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "rootId",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "rootShortName",
table: "RetirementResigns");
migrationBuilder.RenameColumn(
name: "profileId",
table: "RetirementResigns",
newName: "ProfileId");
migrationBuilder.AlterColumn<Guid>(
name: "ProfileId",
table: "RetirementResigns",
type: "char(36)",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
collation: "ascii_general_ci",
oldClrType: typeof(string),
oldType: "longtext",
oldNullable: true,
oldComment: "profile Id")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_RetirementResigns_ProfileId",
table: "RetirementResigns",
column: "ProfileId");
migrationBuilder.AddForeignKey(
name: "FK_RetirementResigns_Profiles_ProfileId",
table: "RetirementResigns",
column: "ProfileId",
principalTable: "Profiles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View file

@ -0,0 +1,74 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updatetableRetirementResignsaddchild1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "KeycloakUserId",
table: "Notifications",
type: "longtext",
nullable: true,
oldClrType: typeof(string),
oldType: "longtext")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AlterColumn<string>(
name: "KeycloakUserId",
table: "Inboxes",
type: "longtext",
nullable: true,
oldClrType: typeof(string),
oldType: "longtext")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.UpdateData(
table: "Notifications",
keyColumn: "KeycloakUserId",
keyValue: null,
column: "KeycloakUserId",
value: "");
migrationBuilder.AlterColumn<string>(
name: "KeycloakUserId",
table: "Notifications",
type: "longtext",
nullable: false,
oldClrType: typeof(string),
oldType: "longtext",
oldNullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.UpdateData(
table: "Inboxes",
keyColumn: "KeycloakUserId",
keyValue: null,
column: "KeycloakUserId",
value: "");
migrationBuilder.AlterColumn<string>(
name: "KeycloakUserId",
table: "Inboxes",
type: "longtext",
nullable: false,
oldClrType: typeof(string),
oldType: "longtext",
oldNullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -0,0 +1,92 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updatetableRetirementResignsadddebt : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "CancelReason",
table: "RetirementResigns",
type: "longtext",
nullable: true,
comment: "เหตุผลยกเลิก")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<bool>(
name: "IsNoDebt",
table: "RetirementResigns",
type: "tinyint(1)",
nullable: false,
defaultValue: false,
comment: "สถานะไม่เป็นหนี้สหกรณ์");
migrationBuilder.CreateTable(
name: "RetirementResignDebtDocs",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "สร้างข้อมูลเมื่อ"),
CreatedUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่สร้างข้อมูล")
.Annotation("MySql:CharSet", "utf8mb4"),
LastUpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "แก้ไขข้อมูลล่าสุดเมื่อ"),
LastUpdateUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่แก้ไขข้อมูลล่าสุด")
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่สร้างข้อมูล")
.Annotation("MySql:CharSet", "utf8mb4"),
LastUpdateFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด")
.Annotation("MySql:CharSet", "utf8mb4"),
DocumentId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
RetirementResignId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_RetirementResignDebtDocs", x => x.Id);
table.ForeignKey(
name: "FK_RetirementResignDebtDocs_Documents_DocumentId",
column: x => x.DocumentId,
principalTable: "Documents",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RetirementResignDebtDocs_RetirementResigns_RetirementResignId",
column: x => x.RetirementResignId,
principalTable: "RetirementResigns",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_RetirementResignDebtDocs_DocumentId",
table: "RetirementResignDebtDocs",
column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_RetirementResignDebtDocs_RetirementResignId",
table: "RetirementResignDebtDocs",
column: "RetirementResignId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "RetirementResignDebtDocs");
migrationBuilder.DropColumn(
name: "CancelReason",
table: "RetirementResigns");
migrationBuilder.DropColumn(
name: "IsNoDebt",
table: "RetirementResigns");
}
}
}

View file

@ -9251,7 +9251,6 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasComment("เปิดอ่านแล้วหรือยัง"); .HasComment("เปิดอ่านแล้วหรือยัง");
b.Property<string>("KeycloakUserId") b.Property<string>("KeycloakUserId")
.IsRequired()
.HasColumnType("longtext"); .HasColumnType("longtext");
b.Property<string>("LastUpdateFullName") b.Property<string>("LastUpdateFullName")
@ -9443,7 +9442,6 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasComment("เปิดอ่านแล้วหรือยัง"); .HasComment("เปิดอ่านแล้วหรือยัง");
b.Property<string>("KeycloakUserId") b.Property<string>("KeycloakUserId")
.IsRequired()
.HasColumnType("longtext"); .HasColumnType("longtext");
b.Property<string>("LastUpdateFullName") b.Property<string>("LastUpdateFullName")
@ -15486,6 +15484,10 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("เหตุผลอนุมัติ"); .HasComment("เหตุผลอนุมัติ");
b.Property<string>("CancelReason")
.HasColumnType("longtext")
.HasComment("เหตุผลยกเลิก");
b.Property<string>("CommanderApproveReason") b.Property<string>("CommanderApproveReason")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("เหตุผลอนุมัติผู้บังคับบัญชา"); .HasComment("เหตุผลอนุมัติผู้บังคับบัญชา");
@ -15525,6 +15527,10 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("tinyint(1)") .HasColumnType("tinyint(1)")
.HasComment("สถานะการใช้งาน"); .HasComment("สถานะการใช้งาน");
b.Property<bool>("IsNoDebt")
.HasColumnType("tinyint(1)")
.HasComment("สถานะไม่เป็นหนี้สหกรณ์");
b.Property<string>("LastUpdateFullName") b.Property<string>("LastUpdateFullName")
.IsRequired() .IsRequired()
.HasMaxLength(200) .HasMaxLength(200)
@ -15564,6 +15570,10 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("เหตุผลยับยั้งผู้ดูแล"); .HasComment("เหตุผลยับยั้งผู้ดูแล");
b.Property<string>("OrganizationOld")
.HasColumnType("longtext")
.HasComment("สังกัดเดิม");
b.Property<string>("OrganizationPositionOld") b.Property<string>("OrganizationPositionOld")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("สังกัด"); .HasComment("สังกัด");
@ -15576,13 +15586,14 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("ข้อมูลหน่วยงานเดิม เลขที่"); .HasComment("ข้อมูลหน่วยงานเดิม เลขที่");
b.Property<string>("PositionOld")
.HasColumnType("longtext")
.HasComment("ตำแหน่งเดิม");
b.Property<string>("PositionTypeOld") b.Property<string>("PositionTypeOld")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท"); .HasComment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท");
b.Property<Guid>("ProfileId")
.HasColumnType("char(36)");
b.Property<string>("Reason") b.Property<string>("Reason")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("เหตุผลที่ลาออกจากราชการ"); .HasComment("เหตุผลที่ลาออกจากราชการ");
@ -15603,13 +15614,177 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("สถานะลาออก"); .HasComment("สถานะลาออก");
b.Property<string>("child1")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child1");
b.Property<string>("child1Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child1");
b.Property<string>("child1ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child1");
b.Property<string>("child2")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child2");
b.Property<string>("child2Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child2");
b.Property<string>("child2ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child2");
b.Property<string>("child3")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child3");
b.Property<string>("child3Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child3");
b.Property<string>("child3ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child3");
b.Property<string>("child4")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child4");
b.Property<string>("child4Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child4");
b.Property<string>("child4ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child4");
b.Property<string>("citizenId")
.HasColumnType("longtext")
.HasComment("เลขบัตรประชาชน");
b.Property<string>("firstName")
.HasColumnType("longtext")
.HasComment("ชื่อ");
b.Property<string>("lastName")
.HasColumnType("longtext")
.HasComment("นามสกุล");
b.Property<string>("posLevelId")
.HasColumnType("longtext")
.HasComment("id ระดับตำแหน่ง");
b.Property<string>("posLevelName")
.HasColumnType("longtext")
.HasComment("ชื่อระดับตำแหน่ง");
b.Property<int?>("posMasterNo")
.HasColumnType("int")
.HasComment("เลขที่ตำแหน่ง");
b.Property<string>("posTypeId")
.HasColumnType("longtext")
.HasComment("id ประเภทตำแหน่ง");
b.Property<string>("posTypeName")
.HasColumnType("longtext")
.HasComment("ชื่อประเภทตำแหน่ง");
b.Property<string>("position")
.HasColumnType("longtext")
.HasComment("ชื่อตำแหน่งในสายงาน");
b.Property<string>("prefix")
.HasColumnType("longtext")
.HasComment("คำนำหน้า");
b.Property<string>("profileId")
.HasColumnType("longtext")
.HasComment("profile Id");
b.Property<string>("root")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน root");
b.Property<string>("rootId")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน root");
b.Property<string>("rootShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน root");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ProfileId");
b.ToTable("RetirementResigns"); b.ToTable("RetirementResigns");
}); });
modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResignDebtDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)")
.HasColumnOrder(0)
.HasComment("PrimaryKey")
.HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)")
.HasColumnOrder(100)
.HasComment("สร้างข้อมูลเมื่อ");
b.Property<string>("CreatedFullName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnOrder(104)
.HasComment("ชื่อ User ที่สร้างข้อมูล");
b.Property<string>("CreatedUserId")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnOrder(101)
.HasComment("User Id ที่สร้างข้อมูล");
b.Property<Guid>("DocumentId")
.HasColumnType("char(36)");
b.Property<string>("LastUpdateFullName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnOrder(105)
.HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด");
b.Property<string>("LastUpdateUserId")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnOrder(103)
.HasComment("User Id ที่แก้ไขข้อมูลล่าสุด");
b.Property<DateTime?>("LastUpdatedAt")
.HasColumnType("datetime(6)")
.HasColumnOrder(102)
.HasComment("แก้ไขข้อมูลล่าสุดเมื่อ");
b.Property<Guid>("RetirementResignId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("DocumentId");
b.HasIndex("RetirementResignId");
b.ToTable("RetirementResignDebtDocs");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResignDoc", b => modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResignDoc", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
@ -17342,15 +17517,23 @@ namespace BMA.EHR.Infrastructure.Migrations
b.Navigation("RetirementResign"); b.Navigation("RetirementResign");
}); });
modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResign", b => modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResignDebtDoc", b =>
{ {
b.HasOne("BMA.EHR.Domain.Models.HR.Profile", "Profile") b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "Document")
.WithMany() .WithMany()
.HasForeignKey("ProfileId") .HasForeignKey("DocumentId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Profile"); b.HasOne("BMA.EHR.Domain.Models.Retirement.RetirementResign", "RetirementResign")
.WithMany("RetirementResignDebtDocs")
.HasForeignKey("RetirementResignId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Document");
b.Navigation("RetirementResign");
}); });
modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResignDoc", b => modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResignDoc", b =>
@ -17641,6 +17824,8 @@ namespace BMA.EHR.Infrastructure.Migrations
modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResign", b => modelBuilder.Entity("BMA.EHR.Domain.Models.Retirement.RetirementResign", b =>
{ {
b.Navigation("RetirementResignDebtDocs");
b.Navigation("RetirementResignDocs"); b.Navigation("RetirementResignDocs");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618

View file

@ -332,6 +332,7 @@ namespace BMA.EHR.Infrastructure.Persistence
public DbSet<RetirementDeceasedNoti> RetirementDeceasedNotis { get; set; } public DbSet<RetirementDeceasedNoti> RetirementDeceasedNotis { get; set; }
public DbSet<RetirementResign> RetirementResigns { get; set; } public DbSet<RetirementResign> RetirementResigns { get; set; }
public DbSet<RetirementResignDoc> RetirementResignDocs { get; set; } public DbSet<RetirementResignDoc> RetirementResignDocs { get; set; }
public DbSet<RetirementResignDebtDoc> RetirementResignDebtDocs { get; set; }
public DbSet<RetirementOut> RetirementOuts { get; set; } public DbSet<RetirementOut> RetirementOuts { get; set; }
public DbSet<RetirementDischarge> RetirementDischarges { get; set; } public DbSet<RetirementDischarge> RetirementDischarges { get; set; }
public DbSet<RetirementExpulsion> RetirementExpulsions { get; set; } public DbSet<RetirementExpulsion> RetirementExpulsions { get; set; }

View file

@ -572,10 +572,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
(org.result.child2 == null ? "" : org.result.child2 + "/") + (org.result.child2 == null ? "" : org.result.child2 + "/") +
(org.result.child1 == null ? "" : org.result.child1 + "/") + (org.result.child1 == null ? "" : org.result.child1 + "/") +
(org.result.root == null ? "" : org.result.root + "/"); (org.result.root == null ? "" : org.result.root + "/");
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
} }
retirementDeceased.RetirementDeceasedNotis.Add(retirementDeceasedNoti);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }

View file

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json; using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims; using System.Security.Claims;
using System.Security.Cryptography; using System.Security.Cryptography;
@ -30,18 +31,21 @@ namespace BMA.EHR.Retirement.Service.Controllers
private readonly ApplicationDBContext _context; private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService; private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
public RetirementResignController(RetirementRepository repository, public RetirementResignController(RetirementRepository repository,
NotificationRepository repositoryNoti, NotificationRepository repositoryNoti,
ApplicationDBContext context, ApplicationDBContext context,
MinIOService documentService, MinIOService documentService,
IHttpContextAccessor httpContextAccessor) IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
{ {
_repository = repository; _repository = repository;
_repositoryNoti = repositoryNoti; _repositoryNoti = repositoryNoti;
_context = context; _context = context;
_documentService = documentService; _documentService = documentService;
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
_configuration = configuration;
} }
#region " Properties " #region " Properties "
@ -49,63 +53,64 @@ namespace BMA.EHR.Retirement.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
#endregion #endregion
private List<string> GetOcNameFullPath(Guid id, bool showRoot = false) // private List<string> GetOcNameFullPath(Guid id, bool showRoot = false)
{ // {
try // try
{ // {
var ocList = new List<string>(); // 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() // 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 // join oc_name in _context.OrganizationOrganizations.AsQueryable() on o.OrganizationOrganization.Id equals oc_name.Id
where o.Parent != null // where o.Parent != null
select new // select new
{ // {
Id = o.Id, // Id = o.Id,
Name = oc_name.Name, // Name = oc_name.Name,
o.IsActive, // o.IsActive,
o.Parent // o.Parent
}).FirstOrDefault(x => x.Id == id && x.IsActive); // }).FirstOrDefault(x => x.Id == id && x.IsActive);
if (oc == null) // if (oc == null)
return ocList; // return ocList;
ocList.Add(oc.Name); // ocList.Add(oc.Name);
if (oc.Parent?.Id != null) // if (oc.Parent?.Id != null)
{ // {
ocList.AddRange(GetOcNameFullPath(oc.Parent.Id, showRoot)); // ocList.AddRange(GetOcNameFullPath(oc.Parent.Id, showRoot));
} // }
return ocList; // return ocList;
} // }
catch // catch
{ // {
throw; // throw;
} // }
} // }
private string FindOCFullPath(Guid id, bool showRoot = false) // private string FindOCFullPath(Guid id, bool showRoot = false)
{ // {
try // try
{ // {
var ocList = GetOcNameFullPath(id, showRoot); // var ocList = GetOcNameFullPath(id, showRoot);
var ret = String.Empty; // var ret = String.Empty;
foreach (var oc in ocList) // foreach (var oc in ocList)
{ // {
ret = oc + "/" + ret; // ret = oc + "/" + ret;
} // }
if (ret.Length > 2) // if (ret.Length > 2)
ret = ret.Substring(0, ret.Length - 1); // ret = ret.Substring(0, ret.Length - 1);
return ret; // return ret;
} // }
catch // catch
{ // {
throw; // throw;
} // }
} // }
/// <summary> /// <summary>
/// list รายการลาออกของ User /// list รายการลาออกของ User
@ -118,29 +123,38 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpGet("user")] [HttpGet("user")]
public async Task<ActionResult<ResponseObject>> GetListByProfile() public async Task<ActionResult<ResponseObject>> GetListByProfile()
{ {
var profile = await _context.Profiles var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId)); using (var client = new HttpClient())
if (profile == null) {
return Error(GlobalMessages.DataNotFound, 404); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var retirementResigns = await _context.RetirementResigns.AsQueryable() var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
.Where(x => x.Profile == profile)
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.Location,
p.SendDate,
p.ActiveDate,
p.Reason,
p.ApproveReason,
p.RejectReason,
p.Status,
p.IsActive,
})
.ToListAsync();
return Success(retirementResigns); if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
var retirementResigns = await _context.RetirementResigns.AsQueryable()
.Where(x => x.profileId == org.result.profileId)
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.Location,
p.SendDate,
p.ActiveDate,
p.Reason,
p.ApproveReason,
p.RejectReason,
p.Status,
p.IsActive,
})
.ToListAsync();
return Success(retirementResigns);
}
} }
/// <summary> /// <summary>
@ -160,10 +174,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new .Select(p => new
{ {
p.Id, p.Id,
ProfileId = p.Profile.Id, p.profileId,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name, p.prefix,
p.Profile.FirstName, p.firstName,
p.Profile.LastName, p.lastName,
p.Location, p.Location,
p.SendDate, p.SendDate,
p.ActiveDate, p.ActiveDate,
@ -202,11 +216,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new .Select(p => new
{ {
p.Id, p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name, p.prefix,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id, p.firstName,
p.Profile.FirstName, p.lastName,
p.Profile.LastName, p.profileId,
ProfileId = p.Profile.Id,
p.Location, p.Location,
p.SendDate, p.SendDate,
p.ActiveDate, p.ActiveDate,
@ -230,8 +243,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
p.CommanderRejectReason, p.CommanderRejectReason,
p.CommanderRejectDate, p.CommanderRejectDate,
p.RemarkHorizontal, p.RemarkHorizontal,
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id, // Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
RetirementResignDebtDocs = p.RetirementResignDebtDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
if (data == null) if (data == null)
@ -243,18 +257,30 @@ namespace BMA.EHR.Retirement.Service.Controllers
var _doc = new var _doc = new
{ {
FileName = doc.FileName, FileName = doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id) PathName = await _documentService.ImagesPath(doc.Id),
doc.Id,
}; };
retirementResignDocs.Add(_doc); retirementResignDocs.Add(_doc);
} }
var retirementResignDebtDocs = new List<dynamic>();
foreach (var doc in data.RetirementResignDebtDocs)
{
var _doc = new
{
FileName = doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id),
doc.Id,
};
retirementResignDebtDocs.Add(_doc);
}
var _data = new var _data = new
{ {
data.Id, data.Id,
data.ProfileId, data.profileId,
data.Prefix, data.prefix,
data.PrefixId, // data.PrefixId,
data.FirstName, data.firstName,
data.LastName, data.lastName,
data.Location, data.Location,
data.SendDate, data.SendDate,
data.ActiveDate, data.ActiveDate,
@ -278,8 +304,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
data.CommanderRejectReason, data.CommanderRejectReason,
data.CommanderRejectDate, data.CommanderRejectDate,
data.RemarkHorizontal, data.RemarkHorizontal,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar), // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
Docs = retirementResignDocs, Docs = retirementResignDocs,
DocDebts = retirementResignDebtDocs,
}; };
return Success(_data); return Success(_data);
@ -296,29 +323,29 @@ namespace BMA.EHR.Retirement.Service.Controllers
[HttpPost()] [HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementResignRequest req) public async Task<ActionResult<ResponseObject>> Post([FromForm] RetirementResignRequest req)
{ {
var profile = await _context.Profiles // var profile = await _context.Profiles
.Include(x => x.PositionLevel) // .Include(x => x.PositionLevel)
.Include(x => x.PositionType) // .Include(x => x.PositionType)
.Include(x => x.PosNo) // .Include(x => x.PosNo)
.Include(x => x.Salaries) // .Include(x => x.Salaries)
.Include(x => x.Position) // .Include(x => x.Position)
.Include(x => x.Prefix) // .Include(x => x.Prefix)
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId)); // .FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
if (profile == null) // if (profile == null)
return Error(GlobalMessages.DataNotFound, 404); // return Error(GlobalMessages.DataNotFound, 404);
var retirementResign = new RetirementResign var retirementResign = new RetirementResign
{ {
Profile = profile, // Profile = profile,
Location = req.Location, Location = req.Location,
SendDate = req.SendDate, SendDate = req.SendDate,
ActiveDate = req.ActiveDate, ActiveDate = req.ActiveDate,
Reason = req.Reason, Reason = req.Reason,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount, // AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name, // PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name, // PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name, // PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}", // OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING", Status = "WAITTING",
IsActive = true, IsActive = true,
CreatedFullName = FullName ?? "System Administrator", CreatedFullName = FullName ?? "System Administrator",
@ -328,6 +355,58 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdateUserId = UserId ?? "", LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now,
}; };
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
retirementResign.profileId = org.result.profileId;
retirementResign.prefix = org.result.prefix;
retirementResign.firstName = org.result.firstName;
retirementResign.lastName = org.result.lastName;
retirementResign.citizenId = org.result.citizenId;
retirementResign.root = org.result.root;
retirementResign.rootId = org.result.rootId;
retirementResign.rootShortName = org.result.rootShortName;
retirementResign.child1 = org.result.child1;
retirementResign.child1Id = org.result.child1Id;
retirementResign.child1ShortName = org.result.child1ShortName;
retirementResign.child2 = org.result.child2;
retirementResign.child2Id = org.result.child2Id;
retirementResign.child2ShortName = org.result.child2ShortName;
retirementResign.child3 = org.result.child3;
retirementResign.child3Id = org.result.child3Id;
retirementResign.child3ShortName = org.result.child3ShortName;
retirementResign.child4 = org.result.child4;
retirementResign.child4Id = org.result.child4Id;
retirementResign.child4ShortName = org.result.child4ShortName;
retirementResign.posMasterNo = org.result.posMasterNo;
retirementResign.position = org.result.position;
retirementResign.posTypeId = org.result.posTypeId;
retirementResign.posTypeName = org.result.posTypeName;
retirementResign.posLevelId = org.result.posLevelId;
retirementResign.posLevelName = org.result.posLevelName;
retirementResign.PositionOld = org.result.position;
retirementResign.PositionLevelOld = org.result.posLevelName;
retirementResign.PositionTypeOld = org.result.posTypeName;
retirementResign.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;
retirementResign.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "/") +
(org.result.child3 == null ? "" : org.result.child3 + "/") +
(org.result.child2 == null ? "" : org.result.child2 + "/") +
(org.result.child1 == null ? "" : org.result.child1 + "/") +
(org.result.root == null ? "" : org.result.root + "/");
retirementResign.OrganizationPositionOld = org.result.position + "-" + retirementResign.OrganizationOld;
}
await _context.RetirementResigns.AddAsync(retirementResign); await _context.RetirementResigns.AddAsync(retirementResign);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
if (Request.Form.Files != null && Request.Form.Files.Count != 0) if (Request.Form.Files != null && Request.Form.Files.Count != 0)
@ -358,8 +437,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
} }
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-6268-4e2c-80a3-aca65eedc6d0"), Guid.Parse("08dbc953-6268-4e2c-80a3-aca65eedc6d0"),
$"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นขอลาออก", $"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
$"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นขอลาออก", $"{retirementResign.prefix}{retirementResign.firstName} {retirementResign.lastName} ได้ทำการยื่นขอลาออก",
"", "",
true true
); );
@ -402,6 +481,108 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Success(); return Success();
} }
/// <summary>
/// แก้ไขรายการตรวจสอบเงื่อนไขต่าง ๆ
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("debt/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Debt([FromForm] RetirementResignDebtRequest req, Guid id)
{
var updated = await _context.RetirementResigns.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
updated.IsNoDebt = req.IsNoDebt;
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
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, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var retirementResignDebtDoc = new RetirementResignDebtDoc
{
RetirementResign = updated,
Document = _doc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementResignDebtDocs.AddAsync(retirementResignDebtDoc);
}
}
}
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขรายการตรวจสอบเงื่อนไขต่าง ๆ
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("debt/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> DebtDelete(Guid id)
{
var deleted = await _context.RetirementResignDocs.AsQueryable()
.FirstOrDefaultAsync(x => x.Document.Id == id);
if (deleted == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
_context.RetirementResignDocs.Remove(deleted);
var _deleted = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (_deleted == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
_context.Documents.Remove(_deleted);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ยกเลิกลาออก
/// </summary>
/// <param name="id">Id ลาออก</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("cancel/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Cancel([FromBody] RetirementReasonRequest req, Guid id)
{
var updated = await _context.RetirementResigns.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404);
updated.Status = "CANCEL";
updated.CancelReason = req.Reason;
updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
/// <summary> /// <summary>
/// ลบลาออก /// ลบลาออก
/// </summary> /// </summary>
@ -439,7 +620,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> AdminConfirm([FromBody] RetirementReasonRequest req, Guid id) public async Task<ActionResult<ResponseObject>> AdminConfirm([FromBody] RetirementReasonRequest req, Guid id)
{ {
var updated = await _context.RetirementResigns var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (updated == null) if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404); return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -467,7 +647,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> AdminReject([FromBody] RetirementReasonRequest req, Guid id) public async Task<ActionResult<ResponseObject>> AdminReject([FromBody] RetirementReasonRequest req, Guid id)
{ {
var updated = await _context.RetirementResigns var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (updated == null) if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404); return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -495,8 +674,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> CommanderConfirm([FromBody] RetirementReasonRequest req, Guid id) public async Task<ActionResult<ResponseObject>> CommanderConfirm([FromBody] RetirementReasonRequest req, Guid id)
{ {
var updated = await _context.RetirementResigns var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (updated == null) if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404); return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -509,15 +686,15 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdatedAt = DateTime.Now; updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"), Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
"", "",
true true
); );
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-61ac-47eb-82d7-0e72df7669b5"), Guid.Parse("08dbc953-61ac-47eb-82d7-0e72df7669b5"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้บังคับบัญชา",
"", "",
true true
); );
@ -539,8 +716,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> CommanderReject([FromBody] RetirementReasonDateRequest req, Guid id) public async Task<ActionResult<ResponseObject>> CommanderReject([FromBody] RetirementReasonDateRequest req, Guid id)
{ {
var updated = await _context.RetirementResigns var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (updated == null) if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404); return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -555,15 +730,15 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdatedAt = DateTime.Now; updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"), Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
"", "",
true true
); );
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-61ac-47eb-82d7-0e72df7669b5"), Guid.Parse("08dbc953-61ac-47eb-82d7-0e72df7669b5"),
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้บังคับบัญชา", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้บังคับบัญชา",
"", "",
true true
); );
@ -584,8 +759,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> OligarchConfirm([FromBody] RetirementReasonRequest req, Guid id) public async Task<ActionResult<ResponseObject>> OligarchConfirm([FromBody] RetirementReasonRequest req, Guid id)
{ {
var updated = await _context.RetirementResigns var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (updated == null) if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404); return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -596,10 +769,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now; updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsyncV2(
updated.Profile.Id, updated.CreatedUserId,
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้มีอำนาจ", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ได้รับการอนุมัติจากผู้มีอำนาจ", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ได้รับการอนุมัติจากผู้มีอำนาจ",
"", "",
true true
); );
@ -621,8 +794,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
public async Task<ActionResult<ResponseObject>> OligarchReject([FromBody] RetirementReasonDateRequest req, Guid id) public async Task<ActionResult<ResponseObject>> OligarchReject([FromBody] RetirementReasonDateRequest req, Guid id)
{ {
var updated = await _context.RetirementResigns var updated = await _context.RetirementResigns
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (updated == null) if (updated == null)
return Error(GlobalMessages.RetirementResignNotFound, 404); return Error(GlobalMessages.RetirementResignNotFound, 404);
@ -635,10 +806,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
updated.LastUpdateFullName = FullName ?? "System Administrator"; updated.LastUpdateFullName = FullName ?? "System Administrator";
updated.LastUpdateUserId = UserId ?? ""; updated.LastUpdateUserId = UserId ?? "";
updated.LastUpdatedAt = DateTime.Now; updated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsyncV2(
updated.Profile.Id, updated.CreatedUserId,
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้มีอำนาจ", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ",
$"คำขอลาออกขอ {updated.Profile.Prefix?.Name}{updated.Profile.FirstName} {updated.Profile.LastName} ถูกยับยั้งจากผู้มีอำนาจ", $"คำขอลาออกขอ {updated.prefix}{updated.firstName} {updated.lastName} ถูกยับยั้งจากผู้มีอำนาจ",
"", "",
true true
); );
@ -691,7 +862,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new .Select(p => new
{ {
Id = p.Id, Id = p.Id,
Fullname = $"{(p.RetirementResign.Profile.Prefix == null ? null : p.RetirementResign.Profile.Prefix.Name)}{p.RetirementResign.Profile.FirstName} {p.RetirementResign.Profile.LastName}", Fullname = $"{p.RetirementResign.prefix}{p.RetirementResign.firstName} {p.RetirementResign.lastName}",
ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork), ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork),
ReasonWorkOther = p.ReasonWorkOther, ReasonWorkOther = p.ReasonWorkOther,
TimeThink = p.TimeThink, TimeThink = p.TimeThink,
@ -733,13 +904,12 @@ namespace BMA.EHR.Retirement.Service.Controllers
.Select(p => new .Select(p => new
{ {
Id = p.Id, Id = p.Id,
PrefixId = p.RetirementResign.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.RetirementResign.Profile.Prefix.Id, Prefix = p.RetirementResign.prefix,
Position = p.RetirementResign.Profile.Position == null ? null : p.RetirementResign.Profile.Position.Name, Position = p.RetirementResign.position,
PositionLevel = p.RetirementResign.Profile.PositionLevel == null ? null : p.RetirementResign.Profile.PositionLevel.Name, PositionLevel = p.RetirementResign.posLevelName,
Org = p.RetirementResign.Profile.OcId == null ? null : p.RetirementResign.Profile.OcId, Org = p.RetirementResign.OrganizationOld,
Fullname = $"{(p.RetirementResign.Profile.Prefix == null ? null : p.RetirementResign.Profile.Prefix.Name)}{p.RetirementResign.Profile.FirstName} {p.RetirementResign.Profile.LastName}", Fullname = $"{p.RetirementResign.prefix}{p.RetirementResign.firstName} {p.RetirementResign.lastName}",
Prefix = p.RetirementResign.Profile.Prefix == null ? null : p.RetirementResign.Profile.Prefix.Name, // Avatar = p.RetirementResign.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.RetirementResign.Profile.Avatar.Id,
Avatar = p.RetirementResign.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.RetirementResign.Profile.Avatar.Id,
ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork), ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork),
ReasonWorkOther = p.ReasonWorkOther, ReasonWorkOther = p.ReasonWorkOther,
TimeThink = p.TimeThink, TimeThink = p.TimeThink,
@ -777,51 +947,51 @@ namespace BMA.EHR.Retirement.Service.Controllers
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
if (data == null) if (data == null)
return Error(GlobalMessages.RetirementQuestionNotFound, 404); return Error(GlobalMessages.RetirementQuestionNotFound, 404);
var _data = new // var _data = new
{ // {
data.Id, // data.Id,
data.PrefixId, // // data.PrefixId,
data.Position, // data.Position,
data.PositionLevel, // data.PositionLevel,
Org = data.Org == null ? null : FindOCFullPath(data.Org.Value, true), // data.Org,
data.Fullname, // data.Fullname,
data.Prefix, // data.Prefix,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar), // // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
data.ReasonWork, // data.ReasonWork,
data.ReasonWorkOther, // data.ReasonWorkOther,
data.TimeThink, // data.TimeThink,
data.ExitFactor, // data.ExitFactor,
data.ExitFactorOther, // data.ExitFactorOther,
data.Adjust, // data.Adjust,
data.AdjustOther, // data.AdjustOther,
data.RealReason, // data.RealReason,
data.NotExitFactor, // data.NotExitFactor,
data.Havejob, // data.Havejob,
data.HavejobReason, // data.HavejobReason,
data.SuggestFriends, // data.SuggestFriends,
data.SuggestFriendsReason, // data.SuggestFriendsReason,
data.FutureWork, // data.FutureWork,
data.FutureWorkReason, // data.FutureWorkReason,
data.Suggestion, // data.Suggestion,
data.AppointDate, // data.AppointDate,
data.OrganizationPositionOld, // data.OrganizationPositionOld,
data.LastUpdatedAt, // data.LastUpdatedAt,
data.CreatedAt, // data.CreatedAt,
data.Score1, // data.Score1,
data.Score2, // data.Score2,
data.Score3, // data.Score3,
data.Score4, // data.Score4,
data.Score5, // data.Score5,
data.Score6, // data.Score6,
data.Score7, // data.Score7,
data.Score8, // data.Score8,
data.Score9, // data.Score9,
data.Score10, // data.Score10,
data.ScoreTotal, // data.ScoreTotal,
data.Comment, // data.Comment,
}; // };
return Success(_data); return Success(data);
} }
/// <summary> /// <summary>
@ -996,7 +1166,6 @@ namespace BMA.EHR.Retirement.Service.Controllers
{ {
var uppdated = await _context.RetirementQuestions.AsQueryable() var uppdated = await _context.RetirementQuestions.AsQueryable()
.Include(x => x.RetirementResign) .Include(x => x.RetirementResign)
.ThenInclude(x => x.Profile)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null) if (uppdated == null)
return Error(GlobalMessages.RetirementQuestionNotFound); return Error(GlobalMessages.RetirementQuestionNotFound);
@ -1005,8 +1174,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
uppdated.LastUpdateFullName = FullName ?? "System Administrator"; uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? ""; uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now; uppdated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync( await _repositoryNoti.PushNotificationAsyncV2(
uppdated.RetirementResign.Profile.Id, uppdated.RetirementResign.CreatedUserId,
$"การนัดสัมภาษณ์เหตุผลการลาออก {req.AppointDate.ToThaiFullDate()}", $"การนัดสัมภาษณ์เหตุผลการลาออก {req.AppointDate.ToThaiFullDate()}",
$"การนัดสัมภาษณ์เหตุผลการลาออก {req.AppointDate.ToThaiFullDate()}", $"การนัดสัมภาษณ์เหตุผลการลาออก {req.AppointDate.ToThaiFullDate()}",
"", "",

View file

@ -0,0 +1,11 @@
using BMA.EHR.Domain.Models.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class RetirementResignDebtRequest
{
public bool IsNoDebt { get; set; }
public List<FormFile>? File { get; set; }
}
}