ออกคำสั่ง 22 24

This commit is contained in:
Kittapath 2023-10-30 20:36:53 +07:00
parent cbabad68a9
commit cc711146c5
9 changed files with 634 additions and 42 deletions

View file

@ -1734,6 +1734,9 @@ namespace BMA.EHR.Application.Repositories.Commands
case "C-PM-23":
await ExecuteCommand23Async(command);
break;
case "C-PM-24":
await ExecuteCommand24Async(command);
break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
}
@ -6378,7 +6381,7 @@ namespace BMA.EHR.Application.Repositories.Commands
}
/// <summary>
/// C-PM-22 - คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ
/// C-PM-22 - คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน)
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
@ -6404,7 +6407,6 @@ namespace BMA.EHR.Application.Repositories.Commands
foreach (var recv in command.Receivers)
{
// TODO: รอมอสเข้ามา Query แล้วแก้ไขข้อมูลทะเบียนประวัติ
var data = await _dbContext.Set<PlacementAppointment>()
.Include(x => x.PositionEmployeeLine)
.Include(x => x.PositionEmployeePosition)
@ -6415,19 +6417,32 @@ namespace BMA.EHR.Application.Repositories.Commands
.ThenInclude(x => x.PositionEmployeeLine)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionEmployeePosition)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionEmployeeLevel)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationShortName)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationOrganization)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.Organization)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.PositionEmployeePosition)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationPositionEmployeeLevels)
.ThenInclude(x => x.PositionEmployeeLevel)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.PositionEmployeeLine)
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
data.Profile.EmployeeClass = "perm"; // ลจ ประจำ
data.Profile.PositionEmployeeLine = data.PositionEmployeeLine;
data.Profile.PositionEmployeePosition = data.PositionEmployeePosition;
// data.Profile.PositionEmployeeLine = data.PositionEmployeeLine;
// data.Profile.PositionEmployeePosition = data.PositionEmployeePosition;
data.Profile.PositionEmployeePosition = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeePosition;
// data.Profile.PositionEmployeePositionSide = data.OrgEmployee == null ? null : data.OrgEmployee!.po;
data.Profile.PositionEmployeeLevel = data.OrgEmployee == null || data.OrgEmployee.OrganizationPositionEmployeeLevels == null || data.OrgEmployee.OrganizationPositionEmployeeLevels.Count() == 0 ? null : data.OrgEmployee!.OrganizationPositionEmployeeLevels.FirstOrDefault().PositionEmployeeLevel;
// data.Profile.PositionEmployeeGroup = data.OrgEmployee == null ? null : data.OrgEmployee!.gr;
data.Profile.PositionEmployeeLine = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeeLine;
data.Profile.OrganizationShortNameId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Id;
data.Profile.OrganizationShortName = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Name;
data.Profile.OrganizationOrganizationId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationOrganization == null ? null : data.OrgEmployee!.OrganizationOrganization!.Id;
@ -6449,7 +6464,7 @@ namespace BMA.EHR.Application.Repositories.Commands
PositionSalaryAmount = recv.PositionSalaryAmount,
MouthSalaryAmount = recv.MouthSalaryAmount,
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.OcId,
//PositionLevel = lastSarary.PositionLevel,
//PositionLineId = lastSarary.PositionLineId,
@ -6460,10 +6475,10 @@ namespace BMA.EHR.Application.Repositories.Commands
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
CommandTypeName = command.CommandType.Name,
//PositionEmployeeGroupId = null,
//PositionEmployeeLevelId = null,
//PositionEmployeePositionId = null,
PositionEmployeeLevelId = data.Profile.PositionEmployeeLevel == null ? null : data.Profile.PositionEmployeeLevel.Id,
PositionEmployeePositionId = data.Profile.PositionEmployeePosition == null ? null : data.Profile.PositionEmployeePosition.Id,
//PositionEmployeePositionSideId = null,
//PosNoEmployee = "",
PosNoEmployee = data.Profile.PosNoEmployee,
////PositionPathSideId = lastSarary.PositionPathSideId == null,
//PositionExecutiveId = lastSarary.PositionExecutiveId,
////PositionExecutiveSideId = lastSarary.PositionExecutiveSideId,
@ -6483,7 +6498,7 @@ namespace BMA.EHR.Application.Repositories.Commands
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
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");
@ -6520,7 +6535,7 @@ namespace BMA.EHR.Application.Repositories.Commands
var inbox = new Inbox
{
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,
Payload = payload_str,
};
@ -6532,14 +6547,14 @@ namespace BMA.EHR.Application.Repositories.Commands
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
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");
}
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,
Type = "LINK",
Payload = payload_str,
@ -6740,6 +6755,201 @@ namespace BMA.EHR.Application.Repositories.Commands
}
}
/// <summary>
/// C-PM-24 - คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย)
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand24Async(Command command)
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<PlacementAppointment>()
.Include(x => x.PositionEmployeeLine)
.Include(x => x.PositionEmployeePosition)
.Include(x => x.Profile)
.ThenInclude(x => x.Salaries)
.ThenInclude(x => x.PositionLevel)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionEmployeeLine)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionEmployeePosition)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionEmployeeLevel)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationShortName)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationOrganization)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.Organization)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.PositionEmployeePosition)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.OrganizationPositionEmployeeLevels)
.ThenInclude(x => x.PositionEmployeeLevel)
.Include(x => x.OrgEmployee)
.ThenInclude(x => x.PositionEmployeeLine)
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
// data.Profile.PositionEmployeeLine = data.PositionEmployeeLine;
// data.Profile.PositionEmployeePosition = data.PositionEmployeePosition;
data.Profile.PositionEmployeePosition = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeePosition;
// data.Profile.PositionEmployeePositionSide = data.OrgEmployee == null ? null : data.OrgEmployee!.po;
data.Profile.PositionEmployeeLevel = data.OrgEmployee == null || data.OrgEmployee.OrganizationPositionEmployeeLevels == null || data.OrgEmployee.OrganizationPositionEmployeeLevels.Count() == 0 ? null : data.OrgEmployee!.OrganizationPositionEmployeeLevels.FirstOrDefault().PositionEmployeeLevel;
// data.Profile.PositionEmployeeGroup = data.OrgEmployee == null ? null : data.OrgEmployee!.gr;
data.Profile.PositionEmployeeLine = data.OrgEmployee == null ? null : data.OrgEmployee!.PositionEmployeeLine;
data.Profile.OrganizationShortNameId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Id;
data.Profile.OrganizationShortName = data.OrgEmployee == null || data.OrgEmployee!.OrganizationShortName == null ? null : data.OrgEmployee!.OrganizationShortName!.Name;
data.Profile.OrganizationOrganizationId = data.OrgEmployee == null || data.OrgEmployee!.OrganizationOrganization == null ? null : data.OrgEmployee!.OrganizationOrganization!.Id;
data.Profile.OrganizationOrganization = data.OrgEmployee == null || data.OrgEmployee!.OrganizationOrganization == null ? null : data.OrgEmployee!.OrganizationOrganization!.Name;
data.Profile.PosNoEmployee = data.OrgEmployee == null ? null : data.OrgEmployee!.PosNo;
data.Profile.OcId = data.OrgEmployee == null || data.OrgEmployee!.Organization == null ? null : data.OrgEmployee!.Organization!.Id;
data.Profile.Oc = data.OrgEmployee == null || data.OrgEmployee!.Organization == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(data.OrgEmployee!.Organization!.Id, false, false, "/");
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
var order = 1;
if (lastSarary != null && lastSarary.Order != null)
order = lastSarary.Order.Value + 1;
var salary = new ProfileSalary
{
Order = order,
Date = command.CommandAffectDate,
Amount = recv.Amount,
PositionSalaryAmount = recv.PositionSalaryAmount,
MouthSalaryAmount = recv.MouthSalaryAmount,
SalaryClass = "",
SalaryRef = "คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
//OcId = lastSarary.OcId,
//PositionLevel = lastSarary.PositionLevel,
//PositionLineId = lastSarary.PositionLineId,
//PositionTypeId = lastSarary.PositionTypeId,
//OrganizationShortNameId = lastSarary.OrganizationShortNameId,
//PosNoId = lastSarary.PosNoId,
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
CommandTypeName = command.CommandType.Name,
//PositionEmployeeGroupId = null,
PositionEmployeeLevelId = data.Profile.PositionEmployeeLevel == null ? null : data.Profile.PositionEmployeeLevel.Id,
PositionEmployeePositionId = data.Profile.PositionEmployeePosition == null ? null : data.Profile.PositionEmployeePosition.Id,
//PositionEmployeePositionSideId = null,
PosNoEmployee = data.Profile.PosNoEmployee,
////PositionPathSideId = lastSarary.PositionPathSideId == null,
//PositionExecutiveId = lastSarary.PositionExecutiveId,
////PositionExecutiveSideId = lastSarary.PositionExecutiveSideId,
IsActive = true,
CreatedAt = DateTime.Now,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
};
data.Profile.Salaries.Add(salary);
// update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {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");
// รอเอาข้อมูลที่ได้มาส่ง inbox noti ให้ผู้รับคำสั่ง
//var inbox = new Inbox
//{
// Subject = $"คุณได้รับคำสั่งเลขที่ {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,
// Payload = payload_str,
//};
//_dbContext.Set<Inbox>().Add(inbox);
//var noti = new Notification
//{
// Body = $"คุณได้รับคำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
// ReceiverUserId = data.Profile.Id,
// Type = "LINK",
// Payload = payload_str,
//};
//_dbContext.Set<Notification>().Add(noti);
//await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
if (pf != null)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id,
Payload = payload_str,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {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");
}
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id,
Type = "LINK",
Payload = payload_str,
};
_dbContext.Set<Notification>().Add(noti);
}
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
#endregion
#region " Regenerate Json File "