From d834f8b1550dc1e418997c96928b8b0f32b53f30 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 11 Oct 2023 14:07:01 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AB=E0=B8=99=E0=B9=89=E0=B8=B2=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=20C-PM-22,23=20?= =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87=2023=20=E0=B8=AA=E0=B9=88=E0=B8=A7=E0=B8=99?= =?UTF-8?q?=2022=20=E0=B8=A3=E0=B8=AD=E0=B8=A1=E0=B8=AD=E0=B8=AA=E0=B8=8A?= =?UTF-8?q?=E0=B9=88=E0=B8=A7=E0=B8=A2=E0=B9=80=E0=B8=82=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=99=E0=B8=95=E0=B9=88=E0=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandReportRepository.cs | 125 ++++++++ .../Commands/CommandRepository.cs | 294 ++++++++++++++++++ .../Controllers/CommandReportController.cs | 236 ++++++++++++++ .../Reports/20-คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ.trdp | Bin 29903 -> 29917 bytes 4 files changed, 655 insertions(+) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs index 5e7ae76f..c15789c7 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs @@ -1088,6 +1088,131 @@ namespace BMA.EHR.Application.Repositories.Commands } } + public async Task> GetCommandType22AttachmentAsync(Guid id) + { + try + { + var raw_data = await _dbContext.Set() + .Include(c => c.Command) + .Where(c => c.Command.Id == id) + .ToListAsync(); + if (raw_data == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + var report_data = (from r in raw_data + join p in _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Position) + .Include(x => x.Profile) + .ThenInclude(x => x.PositionLevel) + .Include(x => x.Profile) + .ThenInclude(x => x.PositionType) + .Include(x => x.Profile) + .ThenInclude(x => x.PosNo) + .Include(x => x.OrgEmployee) + .ThenInclude(x => x.OrganizationAgency) + .ThenInclude(x => x.OrganizationOrganization) + //.Include(x => x.OrgEmployee) + //.ThenInclude(x => x.PosNo) + .Include(x => x.OrgEmployee) + .ThenInclude(x => x.PositionEmployeePosition) + .Include(x => x.OrgEmployee) + .ThenInclude(x => x.OrganizationPositionEmployeeLevels) + .ThenInclude(x => x.PositionEmployeeLevel) + on r.RefPlacementProfileId equals p.Id + orderby r.Sequence + select new CommandType21Response + { + Seq = r.Sequence.ToString().ToThaiNumber(), + CitizenId = r.CitizenId.ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Organization = p.OrgEmployee == null || p.OrgEmployee!.OrganizationAgency == null || p.OrgEmployee!.OrganizationAgency!.OrganizationOrganization == null ? "" : p.OrgEmployee!.OrganizationAgency!.OrganizationOrganization!.Name, + PositionName = p.OrgEmployee.PositionEmployeePosition == null ? "" : p.OrgEmployee.PositionEmployeePosition.Name.ToThaiNumber(), + PositionLevel = p.OrgEmployee.OrganizationPositionEmployeeLevels == null ? "" : p.OrgEmployee.OrganizationPositionEmployeeLevels.First().PositionEmployeeLevel.Name.ToThaiNumber(), + PositionType = p.Profile.PositionType == null ? "" : p.Profile.PositionType.Name.ToThaiNumber(), + PositionNumber = p.OrgEmployee.PosNo == null ? "" : p.OrgEmployee.PosNo.ToThaiNumber(), + Salary = r.Amount == null ? "" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), + RetireDate = p.Profile.BirthDate.CalculateRetireDate().ToThaiFullDate3().ToThaiNumber(), + CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber() + }) + .ToList(); + + return report_data; + } + catch + { + throw; + } + } + + public async Task> GetCommandType23AttachmentAsync(Guid id) + { + try + { + var raw_data = await _dbContext.Set() + .Include(c => c.Command) + .Where(c => c.Command.Id == id) + .ToListAsync(); + if (raw_data == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + var report_data = (from r in raw_data + join p in _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Position) + .Include(x => x.Profile) + .ThenInclude(x => x.PositionLevel) + .Include(x => x.Profile) + .ThenInclude(x => x.PositionType) + .Include(x => x.Profile) + .ThenInclude(x => x.PosNo) + + + .Include(x => x.Profile) + .ThenInclude(x => x.PositionEmployeePosition) + .Include(x => x.Profile) + .ThenInclude(x => x.PositionEmployeeLevel) + //.Include(x => x.OrgEmployee) + //.ThenInclude(x => x.OrganizationAgency) + //.ThenInclude(x => x.OrganizationOrganization) + //.Include(x => x.OrgEmployee) + //.ThenInclude(x => x.PosNo) + //.Include(x => x.OrgEmployee) + //.ThenInclude(x => x.PositionEmployeePosition) + //.Include(x => x.OrgEmployee) + //.ThenInclude(x => x.OrganizationPositionEmployeeLevels) + //.ThenInclude(x => x.PositionEmployeeLevel) + on r.RefPlacementProfileId equals p.Id + orderby r.Sequence + select new CommandType21Response + { + Seq = r.Sequence.ToString().ToThaiNumber(), + CitizenId = r.CitizenId.ToThaiNumber(), + FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", + Organization = p.OrganizationPositionOld ?? "", + PositionName = p.Profile.PositionEmployeePosition == null ? "" : p.Profile.PositionEmployeePosition.Name.ToThaiNumber(), + PositionLevel = p.PositionLevelOld == null ? "" :p.PositionLevelOld.ToThaiNumber(), + PositionType = p.PositionTypeOld == null ? "" : p.PositionTypeOld.ToThaiNumber(), + PositionNumber = p.PositionNumberOld == null ? "" : p.PositionNumberOld.ToThaiNumber(), + Salary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), + RetireDate = p.ActiveDate.Value.ToThaiFullDate3().ToThaiNumber(), + CommandYear = r.Command.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(), + + }) + .ToList(); + + return report_data; + } + catch + { + throw; + } + } + #endregion } } diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 0f84c302..c93422b0 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1661,6 +1661,12 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-21": await ExecuteCommand21Async(command); break; + case "C-PM-22": + await ExecuteCommand22Async(command); + break; + case "C-PM-23": + await ExecuteCommand23Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -6060,6 +6066,294 @@ namespace BMA.EHR.Application.Repositories.Commands } } + /// + /// C-PM-22 - คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand22Async(Command command) + { + try + { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + + foreach (var recv in command.Receivers) + { + // TODO: รอมอสเข้ามา Query แล้วแก้ไขข้อมูลทะเบียนประวัติ + + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + var body = $"คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; + _emailSenderService.SendMail(subject, body, "dev@frappet.com"); + + + // รอเอาข้อมูลที่ได้มาส่ง inbox noti ให้ผู้รับคำสั่ง + + //var inbox = new Inbox + //{ + // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // Body = $"คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = data.Profile.Id, + // Payload = payload_str, + //}; + //_dbContext.Set().Add(inbox); + + //var noti = new Notification + //{ + // Body = $"คุณได้รับคำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + // ReceiverUserId = data.Profile.Id, + // Type = "LINK", + // Payload = payload_str, + //}; + //_dbContext.Set().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 = payload_str, + }; + _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 = "LINK", + Payload = payload_str, + }; + _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-23 - คำสั่งให้ลูกจ้างออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand23Async(Command command) + { + try + { + // create command payload + var payload_attach = command.Documents + .Select(x => new PayloadAttachment + { + name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย", + url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}" + }) + .ToList(); + + var payload = new CommandPayload() + { + attachments = payload_attach + }; + + var payload_str = JsonConvert.SerializeObject(payload); + + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .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.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 = payload_str, + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "LINK", + Payload = payload_str, + }; + _dbContext.Set().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 = payload_str, + }; + _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 = "LINK", + Payload = payload_str, + }; + _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 #region " Regenerate Json File " diff --git a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs index d4e6d85b..4dbc1b5b 100644 --- a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs @@ -2071,6 +2071,156 @@ namespace BMA.EHR.Report.Service.Controllers #endregion + #region " C-PM-22 " + + private async Task GenerateCommandReportType22_Cover(Guid commandId, string exportType) + { + try + { + var raw_data = await _repository.GetByIdAsync(commandId); + if (raw_data == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList(); + //var positionList = string.Empty; + + var command = new + { + CommandNo = raw_data.CommandNo.ToThaiNumber(), + CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(), + IssuerOrganizationName = raw_data.IssuerOrganizationName, + ConclusionRegisterNo = raw_data.ConclusionRegisterNo.ToThaiNumber(), + ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3().ToThaiNumber(), + ConclusionResultNo = raw_data.ConclusionResultNo.ToThaiNumber(), + ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3().ToThaiNumber(), + PositionList = "", + Count = raw_data.Receivers.Count.ToString().ToThaiNumber(), + CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(), + AuthorizedUserFullName = raw_data.AuthorizedUserFullName, + AuthorizedPosition = raw_data.AuthorizedPosition, + Subject = $"เรื่อง {raw_data.CommandSubject}", + }; + + + var receiver = await _commandReportRepository.GetCommandType22AttachmentAsync(commandId); + + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"20-คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ.trdp"); + + ReportPackager reportPackager = new ReportPackager(); + Telerik.Reporting.Report? report = null; + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + { + report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + } + + report.DataSource = command; + + var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + + tblData.DataSource = receiver; + + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + if (exportType == "docx") + deviceInfo["OutputFormat"] = "DOCX"; + + InstanceReportSource instanceReportSource = new InstanceReportSource() + { + ReportDocument = report + }; + + + ReportProcessor reportProcessor = new ReportProcessor(_configuration); + RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo); + + var content = result.DocumentBytes; + + return content; + } + catch + { + throw; + } + } + + #endregion + + #region " C-PM-23 " + + private async Task GenerateCommandReportType23_Cover(Guid commandId, string exportType) + { + try + { + var raw_data = await _repository.GetByIdAsync(commandId); + if (raw_data == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList(); + //var positionList = string.Empty; + + var command = new + { + CommandNo = raw_data.CommandNo.ToThaiNumber(), + CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString().ToThaiNumber(), + IssuerOrganizationName = raw_data.IssuerOrganizationName, + ConclusionRegisterNo = raw_data.ConclusionRegisterNo.ToThaiNumber(), + ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3().ToThaiNumber(), + ConclusionResultNo = raw_data.ConclusionResultNo.ToThaiNumber(), + ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3().ToThaiNumber(), + PositionList = "", + Count = raw_data.Receivers.Count.ToString().ToThaiNumber(), + CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3().ToThaiNumber(), + AuthorizedUserFullName = raw_data.AuthorizedUserFullName, + AuthorizedPosition = raw_data.AuthorizedPosition, + Subject = $"เรื่อง {raw_data.CommandSubject}", + }; + + + var receiver = await _commandReportRepository.GetCommandType23AttachmentAsync(commandId); + + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"35-คำสั่งอนุญาตให้ลูกจ้างลาออก.trdp"); + + ReportPackager reportPackager = new ReportPackager(); + Telerik.Reporting.Report? report = null; + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + { + report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream); + } + + report.DataSource = command; + + var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"]; + + tblData.DataSource = receiver; + + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + if (exportType == "docx") + deviceInfo["OutputFormat"] = "DOCX"; + + InstanceReportSource instanceReportSource = new InstanceReportSource() + { + ReportDocument = report + }; + + + ReportProcessor reportProcessor = new ReportProcessor(_configuration); + RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo); + + var content = result.DocumentBytes; + + return content; + } + catch + { + throw; + } + } + + #endregion + #endregion #region " C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ " @@ -3489,6 +3639,92 @@ namespace BMA.EHR.Report.Service.Controllers #endregion + #region " C-PM-22 คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ " + + /// + /// คำสั่ง C-PM-22 คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("c-pm-22/cover/{exportType}/{id}")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetCommandType22CoverReportAsync(Guid id, string exportType = "pdf") + { + try + { + var mimeType = ""; + switch (exportType.Trim().ToLower()) + { + case "pdf": mimeType = "application/pdf"; break; + case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; + case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; + } + + var cmd = await _repository.GetByIdAsync(id); + if (cmd == null) + throw new Exception(GlobalMessages.CommandNotFound); + + var contentData = await GenerateCommandReportType22_Cover(id, exportType); + return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); + } + catch + { + throw; + } + } + + #endregion + + #region " C-PM-23 คำสั่งให้ลูกจ้างออกจากราชการ " + + /// + /// คำสั่ง C-PM-23 คำสั่งให้ลูกจ้างออกจากราชการ + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("c-pm-23/cover/{exportType}/{id}")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetCommandType23CoverReportAsync(Guid id, string exportType = "pdf") + { + try + { + var mimeType = ""; + switch (exportType.Trim().ToLower()) + { + case "pdf": mimeType = "application/pdf"; break; + case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; + case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; + } + + var cmd = await _repository.GetByIdAsync(id); + if (cmd == null) + throw new Exception(GlobalMessages.CommandNotFound); + + var contentData = await GenerateCommandReportType23_Cover(id, exportType); + return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); + } + catch + { + throw; + } + } + + #endregion + #endregion } } diff --git a/BMA.EHR.Report.Service/Reports/20-คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ.trdp b/BMA.EHR.Report.Service/Reports/20-คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ.trdp index f003b248253dfa48658aaa2a934c23046b8c60be..dea2a728a995a4845f09df90869d0f07c317202e 100644 GIT binary patch delta 2719 zcmV;Q3Sjlm=>gs80S!<~0|XQR000O8Zf{Gm4U=dMZf{Fh^yoAgGYS9zZIi8NPk%SX z?i(XbWNs)@C8@^t!a&>_a9r#H={l}q2MCZDMRpqmXfEAK|As$hXU@!!!x1IXx3rrj zV90YlbI!+aX3lVCSo>tPV<}%F*E1cvuI9Czsvx`Rv`o8QS9|{5%hT#7AOGHV-Uk8JSL4O;LG3M)-{zsni}+!ZCI*u)9j$-wJvVcBu(mFyUj5X8dn8%6F?aa%))XoI1tfD zLWHD57>LQsXw@gMgk%&g&S{m%<{YOfSY4zD0Axv={oA~Wtd^%OcwP^=pSx|tHrEY; z2{B-UBjD5K3rXfHM7JxJ*~XoJX%5*wa@ACbEH*w_!I*$hj>??V=@@qFmb0NK`cU$pk>Sb+6+bA1rUZnz@r~Y{zv9tBHoWvZG`z85 zbP+eZq)B#{BD>4fQn0$L6{FG6BNEQN({okH@FUB;VcLk=an*F`s9aZnKm9U6Xo3Wm znwktnZMsqx=n#TZ5r`mY7xZ7j6!$Nf%AP}%PJlS^A@M+zkSjKskILcJtOUZ(%G6QdvxJXt5;|6&y^X_=||Ax5UOoK^bHr3N*qS&sfKaV zg26w7!5;iQR=^*iCT;?DhY)xzSnvvC@_jIPBtgS6M<9|?C6b5B{R%>{tZhZGn%Fo1 zQ4cwk+o2T-H)9w7Qq?v|slgVg_5d1u2Xdc5l4H1QNlhO`a2OzHd$MQH*7j?4CtCqLl8c)GvjelvBWe}w`g{OQnMqC%)0 zNMPacISL_MX&)4!X#SJ<2R>@V}uQjOc-AOUTI_*8wgcfr*hAoO`M0zU3d{?lK;)P7Y=1-HgWhumIvd6G0BqQa ztd!>O@}&8jObPGTZ87dx;q09+Yt^Z|I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