diff --git a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs index a956fec8..21c5a321 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs @@ -87,6 +87,38 @@ namespace BMA.EHR.Application.Repositories.Commands } } + public async Task> GetCommandType02AttachmentAsync(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 ret = new List(); + + foreach (var c in raw_data) + { + ret.Add(new + { + FullName = $"{c.Prefix}{c.FirstName} {c.LastName}", + PositionName = "" + }); + } + + return ret; + } + catch + { + throw; + } + } + #endregion } } diff --git a/BMA.EHR.Command.Service/SeedCommand.xlsx b/BMA.EHR.Command.Service/SeedCommand.xlsx index ac512431..2a463821 100644 Binary files a/BMA.EHR.Command.Service/SeedCommand.xlsx and b/BMA.EHR.Command.Service/SeedCommand.xlsx differ diff --git a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs index cd8ca27e..61acf3c3 100644 --- a/BMA.EHR.Report.Service/Controllers/CommandReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/CommandReportController.cs @@ -61,6 +61,9 @@ namespace BMA.EHR.Report.Service.Controllers 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, @@ -72,7 +75,9 @@ namespace BMA.EHR.Report.Service.Controllers ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(), PositionList = "", Count = raw_data.Receivers.Count, - CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3() + CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(), + AuthorizedUserFullName = raw_data.AuthorizedUserFullName, + AuthorizedPosition = raw_data.AuthorizedPosition, }; var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp"); @@ -162,6 +167,124 @@ namespace BMA.EHR.Report.Service.Controllers #endregion + #region " C-PM-02 " + + private async Task GenerateCommandReportType02_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, + CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(), + IssuerOrganizationName = raw_data.IssuerOrganizationName, + ConclusionRegisterNo = raw_data.ConclusionRegisterNo, + ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(), + ConclusionResultNo = raw_data.ConclusionResultNo, + ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(), + PositionList = "", + Count = raw_data.Receivers.Count, + CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(), + AuthorizedUserFullName = raw_data.AuthorizedUserFullName, + AuthorizedPosition = raw_data.AuthorizedPosition, + }; + + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.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; + + 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; + } + } + + private async Task GenerateCommandReportType02_Attachment(Guid commandId, string exportType) + { + try + { + var command = await _repository.GetByIdAsync(commandId); + if (command == null) + { + throw new Exception(GlobalMessages.CommandNotFound); + } + + var data = await _commandReportRepository.GetCommandType02AttachmentAsync(commandId); + + var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.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); + } + + var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"]; + + tblData.DataSource = data; + + report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName; + report.ReportParameters["CommandNo"].Value = command.CommandNo; + report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString(); + report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3(); + + System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); + + InstanceReportSource instanceReportSource = new InstanceReportSource() + { + ReportDocument = report + }; + + + ReportProcessor reportProcessor = new ReportProcessor(_configuration); + RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo); + + var content = result.DocumentBytes; + + return content; + } + catch + { + throw; + } + } + + #endregion + #endregion #region " C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ " @@ -266,7 +389,7 @@ namespace BMA.EHR.Report.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public IActionResult GetCommandType02CoverReport(Guid id, string exportType = "pdf") + public async Task> GetCommandType02CoverReportAsync(Guid id, string exportType = "pdf") { try { @@ -278,10 +401,18 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + var cmd = await _repository.GetByIdAsync(id); + if (cmd == null) + throw new Exception(GlobalMessages.CommandNotFound); - return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}"); + var contentData = await GenerateCommandReportType02_Cover(id, exportType); + return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); + + + //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp"); + //var contentData = _reportGenerator.GenerateReport(rptFile, exportType); + + //return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}"); } catch { @@ -303,10 +434,14 @@ namespace BMA.EHR.Report.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public IActionResult GetCommandType02AttachmentReport(Guid id, string exportType = "pdf") + public async Task> GetCommandType02AttachmentReportAsync(Guid id, string exportType = "pdf") { try { + var cmd = await _repository.GetByIdAsync(id); + if (cmd == null) + throw new Exception(GlobalMessages.CommandNotFound); + var mimeType = ""; switch (exportType.Trim().ToLower()) { @@ -315,10 +450,8 @@ namespace BMA.EHR.Report.Service.Controllers case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } - var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); - - return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}"); + var contentData = await GenerateCommandReportType02_Attachment(id, exportType); + return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}"); } catch { diff --git a/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp b/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp index 5ca6ca92..b917c9ff 100644 Binary files a/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp and b/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-2.trdp b/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-2.trdp index 575b3c56..0f29e895 100644 Binary files a/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-2.trdp and b/BMA.EHR.Report.Service/Reports/01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-2.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp b/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp index 5010ffc4..c4ee438a 100644 Binary files a/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp and b/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.trdp b/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.trdp index c8c175ab..769a485b 100644 Binary files a/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.trdp and b/BMA.EHR.Report.Service/Reports/02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.trdp differ diff --git a/BMA.EHR.Report.Service/Reports/03-คำสั่งแต่งตั้งผู้สอบแข่งขัน-Head.trdp b/BMA.EHR.Report.Service/Reports/03-คำสั่งแต่งตั้งผู้สอบแข่งขัน-Head.trdp index 91ab6d79..3e4ebb33 100644 Binary files a/BMA.EHR.Report.Service/Reports/03-คำสั่งแต่งตั้งผู้สอบแข่งขัน-Head.trdp and b/BMA.EHR.Report.Service/Reports/03-คำสั่งแต่งตั้งผู้สอบแข่งขัน-Head.trdp differ