diff --git a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs index 82eace7f..561ddd3e 100644 --- a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs @@ -49,7 +49,8 @@ namespace BMA.EHR.Application.Repositories.Reports // throw; // } //} - + + #region รายงานประกาศเกษียณ public async Task GetProfileRetirementdAsync(Guid retireId) { var retire = await _dbContext.Set() @@ -122,6 +123,68 @@ namespace BMA.EHR.Application.Repositories.Reports return new { retire.Id, retire.CreatedAt, Year = retire.Year.ToThaiYear().ToString().ToThaiNumber(), retire.Round, retire.Type, retire.TypeReport, Total = profile_retire.Count.ToString().ToThaiNumber(), profile = profile_retire }; } } + #endregion + + #region รายงานบันทึกการถึงแก่กรรม + public async Task GetRetirementDeceasedAsync(Guid id) + { + var data = await _dbContext.Set().AsQueryable() + .Where(x => x.Id == id) + .Select(p => new + { + p.Id, + ProfileId = p.Profile.Id, + Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name, + PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id, + p.Profile.FirstName, + p.Profile.LastName, + Position = p.Profile.Position == null ? null : p.Profile.Position.Name, + PositionId = p.Profile.Position == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Position.Id, + PositionType = p.Profile.PositionType == null ? null : p.Profile.PositionType.Name, + PositionTypeId = p.Profile.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionType.Id, + p.Profile.PositionLine, + p.Profile.PositionLineId, + PositionLevel = p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name, + PositionLevelId = p.Profile.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.PositionLevel.Id, + p.Profile.PositionExecutive, + p.Profile.PositionExecutiveId, + Organization = p.Profile.Oc, + OrganizationId = p.Profile.OcId, + p.Number, + p.Date, + p.Location, + p.Reason, + }) + .FirstOrDefaultAsync(); + + if (data == null) + return null; + + string Date = string.IsNullOrEmpty(data.Date.ToString()) ? "วันที่ - เดือน - พ.ศ. -" : DateTime.Parse(data.Date.ToString()).ToThaiFullDate().ToString().ToThaiNumber(); + return new + { + data.Prefix, + data.FirstName, + data.LastName, + data.Position, + data.PositionExecutive, + data.PositionType, + data.PositionLine, + data.PositionLevel, + data.Organization, + data.PositionId, + data.PositionExecutiveId, + data.PositionTypeId, + data.PositionLineId, + data.PositionLevelId, + data.OrganizationId, + data.Number, + Date, + data.Location, + data.Reason, + }; + } + #endregion #endregion } diff --git a/BMA.EHR.Report.Service/Controllers/DeceasedReportController.cs b/BMA.EHR.Report.Service/Controllers/DeceasedReportController.cs index 804f9691..29c9eeae 100644 --- a/BMA.EHR.Report.Service/Controllers/DeceasedReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/DeceasedReportController.cs @@ -26,18 +26,19 @@ namespace BMA.EHR.Report.Service.Controllers private readonly IWebHostEnvironment _hostingEnvironment; private readonly IConfiguration _configuration; private readonly GenericReportGenerator _reportGenerator; - + private readonly RetireReportRepository _repository; #endregion #region " Constuctor and Destructor " - public DeceasedReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator) + public DeceasedReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator, RetireReportRepository repository) { _hostingEnvironment = hostingEnvironment; _configuration = configuration; _reportGenerator = reportGenerator; + _repository = repository; } #endregion @@ -55,23 +56,42 @@ namespace BMA.EHR.Report.Service.Controllers /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("36/{exportType}/{id}")] - public IActionResult GetDeceasedConvertReportAsync(Guid id, string exportType = "pdf") + public async Task> GetDeceasedReportAsync(Guid id, string exportType = "pdf") { try { - var mimeType = ""; - switch (exportType.Trim().ToLower()) + var data = await _repository.GetRetirementDeceasedAsync(id); + if (data != null) { - 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 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 rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp"); + ReportPackager reportPacker = new ReportPackager(); + Telerik.Reporting.Report? report = null; + using (var sourceStream = System.IO.File.OpenRead(rptFile)) + { + report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream); + } + report.DataSource = data; + 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); + return File(result.DocumentBytes, mimeType, $"deceased.{exportType.Trim().ToLower()}"); + } + else + { + return NotFound(); } - - var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp"); - var contentData = _reportGenerator.GenerateReport(rptFile, exportType); - - return File(contentData, mimeType, $"deceased.{exportType.Trim().ToLower()}"); - } catch { diff --git a/BMA.EHR.Report.Service/Reports/36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp b/BMA.EHR.Report.Service/Reports/36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp index 63385573..1ddb6506 100644 Binary files a/BMA.EHR.Report.Service/Reports/36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp and b/BMA.EHR.Report.Service/Reports/36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp differ