Merge branch 'develop' into working

This commit is contained in:
Suphonchai Phoonsawat 2023-10-12 09:43:09 +07:00
commit 3eb932ad4a
4 changed files with 117 additions and 8 deletions

View file

@ -311,6 +311,84 @@ namespace BMA.EHR.Application.Repositories.Reports
}
#endregion
#region
public async Task<object> GetResignByUser(Guid id)
{
var data = await _dbContext.Set<RetirementResign>().AsQueryable()
.Where(x => x.Id == id)
.Select(p => new
{
p.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,
ProfileId = p.Profile.Id,
p.Location,
p.SendDate,
p.ActiveDate,
p.Reason,
p.Status,
salary = p.AmountOld,
p.ApproveReason,
p.RejectReason,
p.IsActive,
p.CreatedAt,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.OligarchReject,
p.OligarchApproveReason,
p.OligarchRejectReason,
p.OligarchRejectDate,
p.CommanderReject,
p.CommanderApproveReason,
p.CommanderRejectReason,
p.CommanderRejectDate,
p.RemarkHorizontal,
})
.FirstOrDefaultAsync();
if (data == null)
return null;
var _data = new
{
data.Id,
data.ProfileId,
data.Prefix,
data.FirstName,
data.LastName,
data.Location,
FullName = $"{data.Prefix}{data.FirstName} {data.LastName}",
SendDate = string.IsNullOrEmpty(data.SendDate.ToString())? string.Empty : DateTime.Parse(data.SendDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(),
ActiveDate = string.IsNullOrEmpty(data.ActiveDate.ToString())? string.Empty : DateTime.Parse(data.ActiveDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(),
data.Reason,
data.Status,
data.salary,
data.PositionTypeOld,
data.PositionLevelOld,
data.PositionNumberOld,
data.OrganizationPositionOld,
data.ApproveReason,
data.RejectReason,
data.IsActive,
data.CreatedAt,
data.OligarchReject,
data.OligarchApproveReason,
data.OligarchRejectReason,
OligarchRejectDate = string.IsNullOrEmpty(data.OligarchRejectDate.ToString()) ? string.Empty : DateTime.Parse(data.OligarchRejectDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(),
data.CommanderReject,
data.CommanderApproveReason,
data.CommanderRejectReason,
CommanderRejectDate = string.IsNullOrEmpty(data.CommanderRejectDate.ToString()) ? string.Empty : DateTime.Parse(data.CommanderRejectDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber(),
data.RemarkHorizontal,
};
return _data;
}
#endregion
#endregion
}
}

View file

@ -25,7 +25,7 @@ namespace BMA.EHR.Report.Service.Controllers
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IConfiguration _configuration;
//private readonly ProbationReportRepository _repository;
private readonly RetireReportRepository _service;
private readonly GenericReportGenerator _reportGenerator;
@ -33,12 +33,12 @@ namespace BMA.EHR.Report.Service.Controllers
#region " Constuctor and Destructor "
public ResignReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, /*ProbationReportRepository repository,*/ GenericReportGenerator reportGenerator)
public ResignReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, RetireReportRepository service, GenericReportGenerator reportGenerator)
{
_hostingEnvironment = hostingEnvironment;
_configuration = configuration;
//_repository = repository;
_service = service;
_reportGenerator = reportGenerator;
}
@ -57,11 +57,15 @@ namespace BMA.EHR.Report.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("33/{exportType}/{id}")]
public IActionResult GetResign33ConvertReportAsync(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetResign33ConvertReportAsync(string id= "08dbca15-bb57-4b2e-8435-69116599421b", string exportType = "pdf")
{
try
{
Guid ids = Guid.Parse(id);
var resign = await _service.GetResignByUser(ids);
if (resign == null)
return NotFound();
var mimeType = "";
switch (exportType.Trim().ToLower())
{
@ -69,11 +73,38 @@ namespace BMA.EHR.Report.Service.Controllers
case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
//var FullName = resign.GetType().GetProperty("FirstName").GetValue(resign);
var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"33-แบบฟอร์มหนังสือขอลาออกจากราชการ-1.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
var rptFile1 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"33-แบบฟอร์มหนังสือขอลาออกจากราชการ-1.trdp");
var rptFile2 = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"33-แบบฟอร์มหนังสือขอลาออกจากราชการ-2.trdp");
return File(contentData, mimeType, $"resign.{exportType.Trim().ToLower()}");
ReportPackager reportPacker = new ReportPackager();
Telerik.Reporting.Report? report1 = null;
Telerik.Reporting.Report? report2 = null;
using (var sourceStream1 = System.IO.File.OpenRead(rptFile1))
using (var sourceStream2 = System.IO.File.OpenRead(rptFile2))
{
report1 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream1);
report2 = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream2);
}
report1.DataSource = resign;
var reportBook = new ReportBook();
reportBook.Reports.Add(report1);
reportBook.Reports.Add(report2);
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = reportBook,
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
return File(result.DocumentBytes, mimeType, $"แบบฟอร์มหนังสือขอลาออกจากราชการ.{exportType.Trim().ToLower()}");
}
catch