From d887503b5193ad2c86195d20f2aef9b19a8b1384 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 7 Sep 2023 09:45:36 +0700 Subject: [PATCH 1/5] =?UTF-8?q?Execute=20=E0=B8=84=E0=B8=B3=E0=B8=AA?= =?UTF-8?q?=E0=B8=B1=E0=B9=88=E0=B8=87=20=E0=B9=80=E0=B8=9E=E0=B8=B4?= =?UTF-8?q?=E0=B9=88=E0=B8=A1=E0=B9=80=E0=B8=95=E0=B8=B4=E0=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandReportRepository.cs | 6 +- .../Commands/CommandRepository.cs | 654 +++++++++++++++++- 2 files changed, 655 insertions(+), 5 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs index 2d833fb6..518d95dc 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs @@ -1,6 +1,4 @@ -using Amazon.Runtime.Internal.Transform; -using Amazon.S3.Model.Internal.MarshallTransformations; -using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Responses.Reports; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Commands.Core; @@ -278,7 +276,7 @@ namespace BMA.EHR.Application.Repositories.Commands } var report_data = (from r in raw_data - join p in _dbContext.Set() + join p in _dbContext.Set() .Include(x => x.OrganizationPosition) .ThenInclude(x => x.Organization) .Include(x => x.PositionPath) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index c963a9ba..814ea9ce 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1458,12 +1458,21 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-02": await ExecuteCommand01_02Async(command); break; + case "C-PM-10": + await ExecuteCommand10Async(command); + break; case "C-PM-11": await ExecuteCommand11Async(command); break; case "C-PM-12": await ExecuteCommand12Async(command); break; + case "C-PM-15": + await ExecuteCommand15Async(command); + break; + case "C-PM-16": + await ExecuteCommand16Async(command); + break; case "C-PM-17": await ExecuteCommand17Async(command); break; @@ -1861,6 +1870,162 @@ namespace BMA.EHR.Application.Repositories.Commands } } + // + /// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand10Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + 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 ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + var inbox = new Inbox + { + Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + /// /// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป /// @@ -2020,7 +2185,170 @@ namespace BMA.EHR.Application.Repositories.Commands } /// - /// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด + /// C-PM-12 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand13Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .Include(x => x.Profile) + .ThenInclude(x => x.PositionLevel) + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.Profile.IsActive = false; + data.Profile.IsLeave = true; + data.Profile.LeaveReason = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ"; + data.Profile.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + 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 ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + 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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + var inbox = new Inbox + { + Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-13 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด /// /// object ของรายการคำสั่ง /// @@ -2180,6 +2508,330 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-15 - คำสั่งให้ช่วยราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand15Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + //data.Profile.IsActive = false; + //data.Profile.IsLeave = true; + //data.Profile.LeaveReason = "ออกจากราชการ"; + //data.Profile.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งให้ช่วยราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + 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 ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + 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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + var inbox = new Inbox + { + Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-16 - คำสั่งส่งตัวกลับ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand16Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + //data.Profile.IsActive = false; + //data.Profile.IsLeave = true; + //data.Profile.LeaveReason = "ออกจากราชการ"; + //data.Profile.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งส่งตัวกลับ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + 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 ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + 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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + var inbox = new Inbox + { + Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + /// /// C-PM-17 - คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ /// From ce377aaba5302cdb598fd8c9003e5a4f0674bba3 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 7 Sep 2023 16:26:43 +0700 Subject: [PATCH 2/5] command --- .../Commands/CommandRepository.cs | 329 +++++++++--------- 1 file changed, 166 insertions(+), 163 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 814ea9ce..2f7d9c4e 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1467,6 +1467,9 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-12": await ExecuteCommand12Async(command); break; + case "C-PM-13": + await ExecuteCommand13Async(command); + break; case "C-PM-15": await ExecuteCommand15Async(command); break; @@ -2185,7 +2188,168 @@ namespace BMA.EHR.Application.Repositories.Commands } /// - /// C-PM-12 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ + /// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand12Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.IsActive = false; + data.IsLeave = true; + data.LeaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; + data.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + 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 ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + var inbox = new Inbox + { + Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ /// /// object ของรายการคำสั่ง /// @@ -2345,168 +2509,7 @@ namespace BMA.EHR.Application.Repositories.Commands { throw; } - } - - /// - /// C-PM-13 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด - /// - /// object ของรายการคำสั่ง - /// - private async Task ExecuteCommand12Async(Command command) - { - try - { - foreach (var recv in command.Receivers) - { - var data = await _dbContext.Set() - .Include(x => x.Salaries) - .ThenInclude(x => x.PositionLevel) - .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); - - if (data == null) - throw new Exception(GlobalMessages.DataNotFound); - - data.IsActive = false; - data.IsLeave = true; - data.LeaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; - data.LeaveDate = command.CommandAffectDate; - - var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var order = 1; - if (lastSarary.Order != null) - order = lastSarary.Order.Value + 1; - - var salary = new ProfileSalary - { - Order = order, - Date = command.CommandAffectDate, - Amount = lastSarary.Amount, - PositionSalaryAmount = lastSarary.PositionSalaryAmount, - MouthSalaryAmount = lastSarary.MouthSalaryAmount, - SalaryClass = "", - SalaryRef = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", - CommandTypeName = command.CommandType.Name, - - - PositionEmployeeGroupId = null, - PositionEmployeeLevelId = null, - PositionEmployeePositionId = null, - PositionEmployeePositionSideId = null, - 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 ?? "", - - }; - - if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; - if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; - - data.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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - var body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; - _emailSenderService.SendMail(subject, body, "dev@frappet.com"); - - - var inbox = new Inbox - { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Id, - Payload = "", - }; - _dbContext.Set().Add(inbox); - - var noti = new Notification - { - Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = data.Id, - Type = "", - Payload = "", - }; - _dbContext.Set().Add(noti); - await _dbContext.SaveChangesAsync(); - } - - // send cc noti inbox - foreach (var cc in command.Deployments) - { - var pf = await _dbContext.Set().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 = "", - }; - _dbContext.Set().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 = "", - Payload = "", - }; - _dbContext.Set().Add(noti); - } - } - - // change command status - var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); - command.CommandStatusId = cmdStatus!.Id; - - await _dbContext.SaveChangesAsync(); - } - catch - { - throw; - } - } + } /// /// C-PM-15 - คำสั่งให้ช่วยราชการ From 9aa444b40b6052c3d2593e4229f14c0755d90274 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 8 Sep 2023 09:36:25 +0700 Subject: [PATCH 3/5] Execute Command --- .../Commands/CommandRepository.cs | 1557 ++++++++++++++++- 1 file changed, 1556 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 2f7d9c4e..404635e5 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -17,7 +17,9 @@ using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; +using System.Drawing; using System.Net.Http.Headers; +using System.Security.Cryptography; using Command = BMA.EHR.Domain.Models.Commands.Core.Command; using Profile = BMA.EHR.Domain.Models.HR.Profile; @@ -1458,6 +1460,27 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-02": await ExecuteCommand01_02Async(command); break; + case "C-PM-03": + await ExecuteCommand03Async(command); + break; + case "C-PM-04": + await ExecuteCommand04Async(command); + break; + case "C-PM-05": + await ExecuteCommand05Async(command); + break; + case "C-PM-06": + await ExecuteCommand06Async(command); + break; + case "C-PM-07": + await ExecuteCommand07Async(command); + break; + case "C-PM-08": + await ExecuteCommand08Async(command); + break; + case "C-PM-09": + await ExecuteCommand09Async(command); + break; case "C-PM-10": await ExecuteCommand10Async(command); break; @@ -1873,6 +1896,1538 @@ namespace BMA.EHR.Application.Repositories.Commands } } + // + /// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand03Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var placementProfile = await _dbContext.Set() + .Include(x => x.Prefix) + .Include(x => x.FatherPrefix) + .Include(x => x.MotherPrefix) + .Include(x => x.MarryPrefix) + .Include(x => x.Gender) + .Include(x => x.Relationship) + .Include(x => x.BloodGroup) + .Include(x => x.Religion) + + .Include(x => x.RegistSubDistrict) + .Include(x => x.RegistDistrict) + .Include(x => x.RegistProvince) + .Include(x => x.CurrentSubDistrict) + .Include(x => x.CurrentDistrict) + .Include(x => x.CurrentProvince) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + .Include(x => x.PlacementCertificates) + .Include(x => x.PlacementEducations) + .ThenInclude(x => x.EducationLevel) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + var profile = await _dbContext.Set() + .Include(x => x.Salaries) + .FirstOrDefaultAsync(x => x.CitizenId == placementProfile.CitizenId); + if(profile != null) + { + profile.Position = placementProfile.PositionPath; + profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + profile.PositionType = placementProfile.PositionType; + profile.PositionLevel = placementProfile.PositionLevel; + + profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + + // organization + profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + } + + var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + + Amount = placementProfile.Amount == null ? 0 : placementProfile.Amount, + PositionSalaryAmount = placementProfile.PositionSalaryAmount == null ? 0 : placementProfile.PositionSalaryAmount, + MouthSalaryAmount = placementProfile.MouthSalaryAmount == null ? 0 : placementProfile.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งแต่งตั้ง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandTypeName = command.CommandType.Name, + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + profile.Salaries.Add(salary); + + // update placementstatus + placementProfile.PlacementStatus = "CONTAIN"; + + 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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + // + /// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand04Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var placementProfile = await _dbContext.Set() + .Include(x => x.Prefix) + .Include(x => x.FatherPrefix) + .Include(x => x.MotherPrefix) + .Include(x => x.MarryPrefix) + .Include(x => x.Gender) + .Include(x => x.Relationship) + .Include(x => x.BloodGroup) + .Include(x => x.Religion) + + .Include(x => x.RegistSubDistrict) + .Include(x => x.RegistDistrict) + .Include(x => x.RegistProvince) + .Include(x => x.CurrentSubDistrict) + .Include(x => x.CurrentDistrict) + .Include(x => x.CurrentProvince) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + .Include(x => x.PlacementCertificates) + .Include(x => x.PlacementEducations) + .ThenInclude(x => x.EducationLevel) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + var profile = await _dbContext.Set() + .Include(x => x.Salaries) + .FirstOrDefaultAsync(x => x.CitizenId == placementProfile.CitizenId); + if (profile != null) + { + profile.Position = placementProfile.PositionPath; + profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + profile.PositionType = placementProfile.PositionType; + profile.PositionLevel = placementProfile.PositionLevel; + + profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + + // organization + profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + } + + var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + + Amount = placementProfile.Amount == null ? 0 : placementProfile.Amount, + PositionSalaryAmount = placementProfile.PositionSalaryAmount == null ? 0 : placementProfile.PositionSalaryAmount, + MouthSalaryAmount = placementProfile.MouthSalaryAmount == null ? 0 : placementProfile.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งย้าย คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandTypeName = command.CommandType.Name, + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + profile.Salaries.Add(salary); + + // update placementstatus + placementProfile.PlacementStatus = "CONTAIN"; + + 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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + // + /// C-PM-05 - คำสั่งแต่งตั้ง + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand05Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var placementProfile = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + var profile = placementProfile.Profile; + if (profile != null) + { + profile.Position = placementProfile.PositionPath; + profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + profile.PositionType = placementProfile.PositionType; + profile.PositionLevel = placementProfile.PositionLevel; + + profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + + // organization + profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + } + + var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + + Amount = recv.Amount == null ? 0 : recv.Amount, + PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount, + MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งแต่งตั้ง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandTypeName = command.CommandType.Name, + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + profile.Salaries.Add(salary); + + // update placementstatus + placementProfile.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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + // + /// C-PM-06 - คำสั่งเลื่อน + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand06Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var placementProfile = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + var profile = placementProfile.Profile; + if (profile != null) + { + profile.Position = placementProfile.PositionPath; + profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + profile.PositionType = placementProfile.PositionType; + profile.PositionLevel = placementProfile.PositionLevel; + + profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + + // organization + profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + } + + var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + + Amount = recv.Amount == null ? 0 : recv.Amount, + PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount, + MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งเลื่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandTypeName = command.CommandType.Name, + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + profile.Salaries.Add(salary); + + // update placementstatus + placementProfile.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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + // + /// C-PM-07 - คำสั่งย้าย + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand07Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var placementProfile = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + var profile = placementProfile.Profile; + if (profile != null) + { + profile.Position = placementProfile.PositionPath; + profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + profile.PositionType = placementProfile.PositionType; + profile.PositionLevel = placementProfile.PositionLevel; + + profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + + // organization + profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + } + + var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + + Amount = recv.Amount == null ? 0 : recv.Amount, + PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount, + MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งย้าย คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandTypeName = command.CommandType.Name, + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + profile.Salaries.Add(salary); + + // update placementstatus + placementProfile.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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + // + /// C-PM-08 - คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand08Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var placementProfile = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + var profile = placementProfile.Profile; + if (profile != null) + { + profile.IsActive = true; + profile.IsLeave = false; + profile.LeaveDate = null; + + + profile.Position = placementProfile.PositionPath; + profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + profile.PositionType = placementProfile.PositionType; + profile.PositionLevel = placementProfile.PositionLevel; + + profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + + // organization + profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + } + + var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + + Amount = recv.Amount == null ? 0 : recv.Amount, + PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount, + MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandTypeName = command.CommandType.Name, + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + profile.Salaries.Add(salary); + + // update placementstatus + placementProfile.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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + // + /// C-PM-09 - คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand09Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var placementProfile = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + var profile = placementProfile.Profile; + if (profile != null) + { + profile.IsActive = true; + profile.IsLeave = false; + profile.LeaveDate = null; + + + profile.Position = placementProfile.PositionPath; + profile.PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id; + profile.PositionType = placementProfile.PositionType; + profile.PositionLevel = placementProfile.PositionLevel; + + profile.PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id; + profile.PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name; + profile.PosNo = placementProfile.OrganizationPosition!.PositionNumber; + + // organization + profile.OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id; + profile.OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name; + profile.OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id; + profile.OcId = placementProfile.OrganizationPosition!.Organization!.Id; + profile.Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"); + } + + var lastSarary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + + Amount = recv.Amount == null ? 0 : recv.Amount, + PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount, + MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandTypeName = command.CommandType.Name, + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + profile.Salaries.Add(salary); + + // update placementstatus + placementProfile.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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + // /// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ /// @@ -2509,7 +4064,7 @@ namespace BMA.EHR.Application.Repositories.Commands { throw; } - } + } /// /// C-PM-15 - คำสั่งให้ช่วยราชการ From 085b6849803b72838321bbdd52dcfc52194b0e99 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 8 Sep 2023 11:31:56 +0700 Subject: [PATCH 4/5] fix select placement round --- .../Repositories/Commands/CommandRepository.cs | 5 +++++ .../Repositories/PlacementRepository.cs | 16 ++++++++++++++++ .../Controllers/OrderController.cs | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 404635e5..7fb242e9 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -182,6 +182,7 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.Organization) //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => x.Placement.Id == command.Placement.Id) .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.Draft! == true) @@ -246,6 +247,7 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.Organization) //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => x.Placement.Id == command.Placement.Id) .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.Draft! == true) @@ -311,6 +313,7 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.Organization) //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) + .Where(x => x.Placement.Id == command.Placement.Id) .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.Draft! == true) @@ -375,6 +378,7 @@ namespace BMA.EHR.Application.Repositories.Commands .Include(x => x.Prefix) .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.Organization) + .Where(x => x.Placement.Id == command.Placement.Id) .Where(x => !otherCommandReceivers.Contains(x.CitizenId!)) .Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN") .Where(x => x.Draft! == true) @@ -5981,6 +5985,7 @@ namespace BMA.EHR.Application.Repositories.Commands throw; } } + #endregion } diff --git a/BMA.EHR.Application/Repositories/PlacementRepository.cs b/BMA.EHR.Application/Repositories/PlacementRepository.cs index 9dd3f03a..49f1175c 100644 --- a/BMA.EHR.Application/Repositories/PlacementRepository.cs +++ b/BMA.EHR.Application/Repositories/PlacementRepository.cs @@ -43,6 +43,22 @@ namespace BMA.EHR.Application.Repositories } } + public async Task> GetAllPlacementAsync() + { + try + { + var data = await _dbContext.Set() + .Include(p => p.PlacementType) + .ToListAsync(); + + return data; + } + catch + { + throw; + } + } + public async Task> GetQualifyingPlacementAsync() { var data = await _dbContext.Set() diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 2a8342b6..030c4f02 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -2601,7 +2601,9 @@ namespace BMA.EHR.Command.Service.Controllers { try { - var rawData = commandCode.Trim().ToUpper() == "C-PM-01" ? await _placementRepository.GetCompetitivePlacementAsync() : await _placementRepository.GetQualifyingPlacementAsync(); + var rawData = commandCode.Trim().ToUpper() == "C-PM-01" ? await _placementRepository.GetCompetitivePlacementAsync() : + commandCode.Trim().ToUpper() == "C-PM-02" ? await _placementRepository.GetQualifyingPlacementAsync() : + await _placementRepository.GetAllPlacementAsync(); var data = rawData.Select(x => new From 8bb8cdc495f0482e49aeee8a8e0dca7a07b291fc Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 8 Sep 2023 15:14:39 +0700 Subject: [PATCH 5/5] execute command 14,21 --- .../Commands/CommandRepository.cs | 579 ++++++++++++++++-- 1 file changed, 538 insertions(+), 41 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 7fb242e9..b6d18618 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1497,6 +1497,9 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-13": await ExecuteCommand13Async(command); break; + case "C-PM-14": + await ExecuteCommand14Async(command); + break; case "C-PM-15": await ExecuteCommand15Async(command); break; @@ -1515,6 +1518,9 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-20": await ExecuteCommand20Async(command); break; + case "C-PM-21": + await ExecuteCommand21Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -1749,7 +1755,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = placementProfile.PositionSalaryAmount == null ? 0 : placementProfile.PositionSalaryAmount, MouthSalaryAmount = placementProfile.MouthSalaryAmount == null ? 0 : placementProfile.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้วุฒิ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้วุฒิ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = oc == null ? Guid.Empty : oc.Id, @@ -1760,7 +1766,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, @@ -1822,14 +1828,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = profile.Id, Payload = "", @@ -2018,7 +2024,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, PositionEmployeeGroupId = null, @@ -2249,7 +2255,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, PositionEmployeeGroupId = null, @@ -2461,7 +2467,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, PositionEmployeeGroupId = null, @@ -2673,7 +2679,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, PositionEmployeeGroupId = null, @@ -2885,7 +2891,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, PositionEmployeeGroupId = null, @@ -3102,7 +3108,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, PositionEmployeeGroupId = null, @@ -3319,7 +3325,7 @@ namespace BMA.EHR.Application.Repositories.Commands OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, PosNoId = positionNumber!.Id, - CommandNo = $"{command.CommandNo}/{command.CommandYear}", + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", CommandTypeName = command.CommandType.Name, PositionEmployeeGroupId = null, @@ -3464,7 +3470,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -3512,14 +3518,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Id, Payload = "", @@ -3622,7 +3628,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -3670,14 +3676,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Id, Payload = "", @@ -3783,7 +3789,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -3831,14 +3837,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Id, Payload = "", @@ -3946,7 +3952,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -3994,14 +4000,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Id, Payload = "", @@ -4070,6 +4076,337 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-14 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand14Async(Command command) + { + try + { + // create new profile + foreach (var recv in command.Receivers) + { + // query placement Profile + var placementProfile = await _dbContext.Set() + .Include(x => x.Prefix) + //.Include(x => x.FatherPrefix) + //.Include(x => x.MotherPrefix) + //.Include(x => x.MarryPrefix) + .Include(x => x.Gender) + .Include(x => x.Relationship) + .Include(x => x.BloodGroup) + .Include(x => x.Religion) + + //.Include(x => x.RegistSubDistrict) + //.Include(x => x.RegistDistrict) + //.Include(x => x.RegistProvince) + //.Include(x => x.CurrentSubDistrict) + //.Include(x => x.CurrentDistrict) + //.Include(x => x.CurrentProvince) + + .Include(x => x.PositionPath) + .Include(x => x.PositionPathSide) + .Include(x => x.PositionType) + .Include(x => x.PositionLine) + .Include(x => x.PositionLevel) + .Include(x => x.PositionNumber) + + //.Include(x => x.PlacementCertificates) + //.Include(x => x.PlacementEducations) + //.ThenInclude(x => x.EducationLevel) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationShortName) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutive) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionExecutiveSide) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.PositionMaster) + .ThenInclude(x => x.PositionLine) + + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x.Organization) + .ThenInclude(x => x.OrganizationOrganization) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (placementProfile == null) + throw new Exception("Invalid placement profile: " + recv.RefPlacementProfileId); + + // ใส่ฟีลจากข้อมูล + var profile = new Profile + { + ProfileType = "officer", + CitizenId = placementProfile.CitizenId, + Prefix = placementProfile.Prefix, + FirstName = placementProfile.Firstname, + LastName = placementProfile.Lastname, + Gender = placementProfile.Gender, + Nationality = placementProfile.Nationality, + BirthDate = placementProfile.DateOfBirth, + RelationshipId = placementProfile.Relationship == null ? Guid.Empty : placementProfile.Relationship!.Id, + TelephoneNumber = "", + Race = placementProfile.Race, + ReligionId = placementProfile.Religion == null ? Guid.Empty : placementProfile.Religion.Id, + BloodGroupId = placementProfile.BloodGroup == null ? Guid.Empty : placementProfile.BloodGroup.Id, + + DateAppoint = placementProfile.RecruitDate == null ? null : placementProfile.RecruitDate.Value, + DateStart = placementProfile.RecruitDate == null ? null : placementProfile.RecruitDate.Value, + + //RegistrationAddress = placementProfile.RegistAddress, + //RegistrationSubDistrictId = placementProfile.RegistSubDistrict == null ? Guid.Empty : placementProfile.RegistSubDistrict!.Id, + //RegistrationDistrictId = placementProfile.RegistDistrict == null ? Guid.Empty : placementProfile.RegistDistrict!.Id, + //RegistrationProvinceId = placementProfile.RegistProvince == null ? Guid.Empty : placementProfile.RegistProvince!.Id, + + //CurrentAddress = placementProfile.CurrentAddress, + //CurrentSubDistrictId = placementProfile.CurrentSubDistrict == null ? Guid.Empty : placementProfile.CurrentSubDistrict!.Id, + //CurrentDistrictId = placementProfile.CurrentDistrict == null ? Guid.Empty : placementProfile.CurrentDistrict!.Id, + //CurrentProvinceId = placementProfile.CurrentProvince == null ? Guid.Empty : placementProfile.CurrentProvince!.Id, + + //FatherPrefixId = placementProfile.FatherPrefix == null ? Guid.Empty : placementProfile.FatherPrefix.Id, + //FatherFirstName = placementProfile.FatherFirstName, + //FatherLastName = placementProfile.FatherLastName, + //FatherCareer = placementProfile.FatherOccupation, + + //MotherPrefixId = placementProfile.MotherPrefix == null ? Guid.Empty : placementProfile.MotherPrefix.Id, + //MotherFirstName = placementProfile.MotherFirstName, + //MotherLastName = placementProfile.MotherLastName, + //MotherCareer = placementProfile.MotherOccupation, + + //CouplePrefixId = placementProfile.MarryPrefix == null ? Guid.Empty : placementProfile.MarryPrefix.Id, + //CoupleFirstName = placementProfile.MarryFirstName, + //CoupleLastName = placementProfile.MarryLastName, + //CoupleCareer = placementProfile.MarryOccupation, + + Position = placementProfile.PositionPath, + PositionPathSideId = placementProfile.PositionPathSide == null ? Guid.Empty : placementProfile.PositionPathSide.Id, + PositionType = placementProfile.PositionType, + PositionLevel = placementProfile.PositionLevel, + //PositionEmployeeLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine == null ? Guid.Empty : placementProfile.PositionLine.Id, + PositionLine = placementProfile.PositionLine == null ? "" : placementProfile.PositionLine.Name, + PosNo = placementProfile.OrganizationPosition!.PositionNumber, + + IsVerified = true, + IsProbation = true, + Physical = "", + Ability = "", + AvatarRef = "", + GovAgeAbsent = 0, + GovAgePlus = 0, + EntryStatus = "", + IsTransfer = false, + IsActive = true, + IsLeave = false, + VerifiedUser = "", + FirstNameOld = "", + LastNameOld = "", + CoupleLive = false, + FatherLive = false, + MotherLive = false, + CreatedUser = "", + + Educations = new List(), + Certificates = new List(), + Salaries = new List(), + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + // organization + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + OrganizationShortName = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Name, + OrganizationOrganizationId = placementProfile.OrganizationPosition!.Organization!.OrganizationOrganization!.Id, + OcId = placementProfile.OrganizationPosition!.Organization!.Id, + Oc = _organizationCommonRepository.GetOrganizationNameFullPath(placementProfile.OrganizationPosition!.Organization!.Id, false, false, "/"), + + }; + + // add profile salary + + var oc = _dbContext.Set() + .FirstOrDefault(x => x.Id == placementProfile.OrganizationPosition!.Organization!.Id); + + var position = placementProfile.PositionPath; + + var positionNumber = placementProfile.PositionNumber; + + var positionType = placementProfile.PositionType; + + var positionLevel = placementProfile.PositionLevel; + + + var salary = new ProfileSalary + { + Order = 1, + Date = command.CommandAffectDate, + Amount = recv.Amount == null ? 0 : recv.Amount, + PositionSalaryAmount = recv.PositionSalaryAmount == null ? 0 : recv.PositionSalaryAmount, + MouthSalaryAmount = recv.MouthSalaryAmount == null ? 0 : recv.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "รับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = oc == null ? Guid.Empty : oc.Id, + + + PositionLevel = placementProfile.PositionLevel, + PositionLineId = placementProfile.PositionLine!.Id, + PositionTypeId = placementProfile.PositionType!.Id, + OrganizationShortNameId = placementProfile.OrganizationPosition!.Organization!.OrganizationShortName!.Id, + PosNoId = positionNumber!.Id, + + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + PositionPathSideId = placementProfile.PositionPathSide! == null ? null : placementProfile.PositionPathSide!.Id, + PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id, + PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! == null ? null : placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id, + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + //if (placementProfile.PositionPathSide! != null) + //{ + // salary.PositionPathSideId = placementProfile.PositionPathSide!.Id; + //} + //else + + //if (placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive! != null) + //{ + // salary.PositionExecutiveId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutive!.Id; + //} + + //if (placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide! != null) + //{ + // salary.PositionExecutiveSideId = placementProfile.OrganizationPosition!.PositionMaster!.PositionExecutiveSide!.Id; + //} + + // add profile position + var profilePosition = new ProfilePosition + { + Profile = profile, + OrganizationPosition = placementProfile.OrganizationPosition, + IsActive = true, + IsPublished = true, + }; + _dbContext.Set().Add(profilePosition); + + profile.Salaries.Add(salary); + + _dbContext.Set().Add(profile); + + // update placementstatus + placementProfile.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"); + + + 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 = profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + + + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + /// /// C-PM-15 - คำสั่งให้ช่วยราชการ /// @@ -4109,7 +4446,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งให้ช่วยราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งให้ช่วยราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -4156,14 +4493,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Profile.Id, Payload = "", @@ -4271,7 +4608,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งส่งตัวกลับ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งส่งตัวกลับ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -4318,14 +4655,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Profile.Id, Payload = "", @@ -4433,7 +4770,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -4481,14 +4818,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Profile.Id, Payload = "", @@ -4596,7 +4933,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งให้ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งให้ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -4644,14 +4981,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Profile.Id, Payload = "", @@ -4759,7 +5096,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -4807,14 +5144,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Profile.Id, Payload = "", @@ -4922,7 +5259,7 @@ namespace BMA.EHR.Application.Repositories.Commands PositionSalaryAmount = lastSarary.PositionSalaryAmount, MouthSalaryAmount = lastSarary.MouthSalaryAmount, SalaryClass = "", - SalaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + SalaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", OcId = lastSarary.OcId, @@ -4970,14 +5307,14 @@ namespace BMA.EHR.Application.Repositories.Commands // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // Send noti inbox and email - var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}"; _emailSenderService.SendMail(subject, body, "dev@frappet.com"); var inbox = new Inbox { - Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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()}", ReceiverUserId = data.Profile.Id, Payload = "", @@ -5046,6 +5383,166 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand21Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.Profile.EmployeeClass = "perm"; // ลจ ประจำ + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.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()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + 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 ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + 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"); + + + 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 = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().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 = "", + }; + _dbContext.Set().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 = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + #endregion #endregion