change report templates (transfer, retire)

This commit is contained in:
Bright 2024-09-12 10:54:23 +07:00
parent f85c0cf636
commit d67e0450e5
5 changed files with 453 additions and 354 deletions

View file

@ -1,5 +1,6 @@
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.Reports;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
@ -20,12 +21,14 @@ namespace BMA.EHR.Report.Service.Controllers
private readonly RetireReportRepository _service;
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IConfiguration _configuration;
private readonly PermissionRepository _permission;
public RetireReportController(RetireReportRepository service, IWebHostEnvironment hostingEnvironment, IConfiguration configuration)
public RetireReportController(RetireReportRepository service, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, PermissionRepository permission)
{
_service = service;
_hostingEnvironment = hostingEnvironment;
_configuration = configuration;
_permission = permission;
}
#region 31- & 32-
@ -45,25 +48,28 @@ namespace BMA.EHR.Report.Service.Controllers
if (retire != null)
{
var reportfile = string.Empty;
var returnfile = string.Empty;
//var returnfile = string.Empty;
exportType = exportType.Trim();
switch (retire.GetType().GetProperty("Type").GetValue(retire))
{
case "OFFICER":
if (string.IsNullOrEmpty(retire.GetType().GetProperty("TypeReport").GetValue(retire)))
{
reportfile = $"31-ประกาศเกษียณข้าราชการ-1.trdp";
returnfile = $"ประกาศเกษียณข้าราชการ.{exportType}";
//reportfile = $"31-ประกาศเกษียณข้าราชการ-1.trdp";
//returnfile = $"ประกาศเกษียณข้าราชการ.{exportType}";
reportfile = $"retire-1";
}
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "ADD" || retire.GetType().GetProperty("TypeReport").GetValue(retire) == "EDIT")
{
reportfile = $"31-ประกาศเกษียณข้าราชการ-2.trdp";
returnfile = $"แก้ไขประกาศเกษียณข้าราชการ.{exportType}";
//reportfile = $"31-ประกาศเกษียณข้าราชการ-2.trdp";
//returnfile = $"แก้ไขประกาศเกษียณข้าราชการ.{exportType}";
reportfile = $"retire-2";
}
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "REMOVE")
{
reportfile = $"31-ประกาศเกษียณข้าราชการ-3.trdp";
returnfile = $"ยกเลิกประกาศเกษียณข้าราชการ.{exportType}";
//reportfile = $"31-ประกาศเกษียณข้าราชการ-3.trdp";
//returnfile = $"ยกเลิกประกาศเกษียณข้าราชการ.{exportType}";
reportfile = $"retire-3";
}
else
{
@ -73,18 +79,21 @@ namespace BMA.EHR.Report.Service.Controllers
case "EMPLOYEE":
if (string.IsNullOrEmpty(retire.GetType().GetProperty("TypeReport").GetValue(retire)))
{
reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-1.trdp";
returnfile = $"ประกาศเกษียณลูกจ้างประจำ.{exportType}";
//reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-1.trdp";
//returnfile = $"ประกาศเกษียณลูกจ้างประจำ.{exportType}";
reportfile = $"retire-emp-1";
}
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "ADD" || retire.GetType().GetProperty("TypeReport").GetValue(retire) == "EDIT")
{
reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-2.trdp";
returnfile = $"แก้ไขประกาศเกษียณลูกจ้างประจำ.{exportType}";
//reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-2.trdp";
//returnfile = $"แก้ไขประกาศเกษียณลูกจ้างประจำ.{exportType}";
reportfile = $"retire-emp-2";
}
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "REMOVE")
{
reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-3.trdp";
returnfile = $"ยกเลิกประกาศเกษียณลูกจ้างประจำ.{exportType}";
//reportfile = $"32-ประกาศเกษียณลูกจ้างประจำ-3.trdp";
//returnfile = $"ยกเลิกประกาศเกษียณลูกจ้างประจำ.{exportType}";
reportfile = $"retire-emp-3";
}
else
{
@ -95,86 +104,94 @@ namespace BMA.EHR.Report.Service.Controllers
return Error(retire.GetType().GetProperty("Type").GetValue(retire));
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", reportfile);
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.ReportParameters["Type"].Value = (returnfile != "ยกเลิกประกาศเกษียณข้าราชการ.pdf" && returnfile != "ยกเลิกประกาศเกษียณข้าราชการ.docx") && (returnfile != "แก้ไขประกาศเกษียณข้าราชการ.pdf" && returnfile != "แก้ไขประกาศเกษียณข้าราชการ.docx") && (returnfile != "ยกเลิกประกาศเกษียณลูกจ้างประจำ.pdf" && returnfile != "ยกเลิกประกาศเกษียณลูกจ้างประจำ.docx") && (returnfile != "แก้ไขประกาศเกษียณลูกจ้างประจำ.pdf" && returnfile != "แก้ไขประกาศเกษียณลูกจ้างประจำ.docx") ? "1" : "0";
var _profileList = new List<dynamic>();
var _count = 0;
var tmpOc1 = string.Empty;
foreach (var profile in retire.GetType().GetProperty("profile").GetValue(retire))
{
var tmpOc2 = profile.GetType().GetProperty("root").GetValue(profile);
if (tmpOc1 != tmpOc2)
{
_count = 1;
tmpOc1 = tmpOc2;
}
else
{
_count++;
}
string position = profile.GetType().GetProperty("position").GetValue(profile);
position = position != string.Empty && position != null ? position : "-";
string thaiOrder = profile.GetType().GetProperty("order").GetValue(profile).ToString();
thaiOrder = $"ลำดับที่ {thaiOrder.ToThaiNumber()}";
string thaiPosNo = profile.GetType().GetProperty("posNo").GetValue(profile);
thaiPosNo = thaiPosNo != null ? $"(ตำแหน่งเลขที่ {thaiPosNo.ToThaiNumber()})" : $"(ตำแหน่งเลขที่ - )";
string organizationOrganization = (profile.GetType().GetProperty("child4").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child4").GetValue(profile) + "/") +
(profile.GetType().GetProperty("child3").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child3").GetValue(profile) + "/") +
(profile.GetType().GetProperty("child2").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child2").GetValue(profile) + "/") +
(profile.GetType().GetProperty("child1").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child1").GetValue(profile) + "/") +
(profile.GetType().GetProperty("root").GetValue(profile) == null ? "" : profile.GetType().GetProperty("root").GetValue(profile));
string reason = profile.GetType().GetProperty("reason").GetValue(profile);
organizationOrganization = organizationOrganization != string.Empty ? organizationOrganization : reason != string.Empty ? reason : string.Empty ;
reason = organizationOrganization == reason ? string.Empty : reason;
_profileList.Add(new
{
count = $"{_count.ToString().ToThaiNumber()}.",
no = $"{(_profileList.Count() + 1).ToString().ToThaiNumber()}.",
order = thaiOrder,
organizationOrganization = organizationOrganization,
fullName = $"{profile.GetType().GetProperty("prefix").GetValue(profile)}{profile.GetType().GetProperty("firstName").GetValue(profile)} {profile.GetType().GetProperty("lastName").GetValue(profile)}",
position = position,
posNo = thaiPosNo,
oc = profile.GetType().GetProperty("root").GetValue(profile),
positionEmployeePosition = profile.GetType().GetProperty("position").GetValue(profile),
posNoEmployee = profile.GetType().GetProperty("posMasterNo").GetValue(profile),
reason = reason,
});
}
//var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", reportfile);
//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.ReportParameters["Type"].Value = (returnfile != "ยกเลิกประกาศเกษียณข้าราชการ.pdf" && returnfile != "ยกเลิกประกาศเกษียณข้าราชการ.docx") && (returnfile != "แก้ไขประกาศเกษียณข้าราชการ.pdf" && returnfile != "แก้ไขประกาศเกษียณข้าราชการ.docx") && (returnfile != "ยกเลิกประกาศเกษียณลูกจ้างประจำ.pdf" && returnfile != "ยกเลิกประกาศเกษียณลูกจ้างประจำ.docx") && (returnfile != "แก้ไขประกาศเกษียณลูกจ้างประจำ.pdf" && returnfile != "แก้ไขประกาศเกษียณลูกจ้างประจำ.docx") ? "1" : "0";
//var _profileList = new List<dynamic>();
//var _count = 0;
//var tmpOc1 = string.Empty;
//foreach (var profile in retire.GetType().GetProperty("profile").GetValue(retire))
//{
// var tmpOc2 = profile.GetType().GetProperty("root").GetValue(profile);
// if (tmpOc1 != tmpOc2)
// {
// _count = 1;
// tmpOc1 = tmpOc2;
// }
// else
// {
// _count++;
// }
// string position = profile.GetType().GetProperty("position").GetValue(profile);
// position = position != string.Empty && position != null ? position : "-";
// string thaiOrder = profile.GetType().GetProperty("order").GetValue(profile).ToString();
// thaiOrder = $"ลำดับที่ {thaiOrder.ToThaiNumber()}";
// string thaiPosNo = profile.GetType().GetProperty("posNo").GetValue(profile);
// thaiPosNo = thaiPosNo != null ? $"(ตำแหน่งเลขที่ {thaiPosNo.ToThaiNumber()})" : $"(ตำแหน่งเลขที่ - )";
// string organizationOrganization = (profile.GetType().GetProperty("child4").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child4").GetValue(profile) + "/") +
// (profile.GetType().GetProperty("child3").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child3").GetValue(profile) + "/") +
// (profile.GetType().GetProperty("child2").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child2").GetValue(profile) + "/") +
// (profile.GetType().GetProperty("child1").GetValue(profile) == null ? "" : profile.GetType().GetProperty("child1").GetValue(profile) + "/") +
// (profile.GetType().GetProperty("root").GetValue(profile) == null ? "" : profile.GetType().GetProperty("root").GetValue(profile));
// string reason = profile.GetType().GetProperty("reason").GetValue(profile);
// organizationOrganization = organizationOrganization != string.Empty ? organizationOrganization : reason != string.Empty ? reason : string.Empty ;
// reason = organizationOrganization == reason ? string.Empty : reason;
// _profileList.Add(new
// {
// count = $"{_count.ToString().ToThaiNumber()}.",
// no = $"{(_profileList.Count() + 1).ToString().ToThaiNumber()}.",
// order = thaiOrder,
// organizationOrganization = organizationOrganization,
// fullName = $"{profile.GetType().GetProperty("prefix").GetValue(profile)}{profile.GetType().GetProperty("firstName").GetValue(profile)} {profile.GetType().GetProperty("lastName").GetValue(profile)}",
// position = position,
// posNo = thaiPosNo,
// oc = profile.GetType().GetProperty("root").GetValue(profile),
// positionEmployeePosition = profile.GetType().GetProperty("position").GetValue(profile),
// posNoEmployee = profile.GetType().GetProperty("posMasterNo").GetValue(profile),
// reason = reason,
// });
//}
//Binding Data
if (report.ReportParameters["Type"].Value == "1")
////Binding Data
//if (report.ReportParameters["Type"].Value == "1")
//{
// // report.ReportParameters["Year"].Value = retire.GetType().GetProperty("year").GetValue(retire);
// // report.ReportParameters["Total"].Value = retire.GetType().GetProperty("total").GetValue(retire);
// // report.ReportParameters["Detail"].Value = retire.GetType().GetProperty("detail").GetValue(retire);
// // report.DataSource = _profileList;
// report.DataSource = retire;
// var tblProfile = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
// tblProfile.DataSource = _profileList;
//}
//else
//{
// report.DataSource = retire;
// var tblProfile = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
// tblProfile.DataSource = _profileList;
//}
//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 File(content, $"application/{exportType}", returnfile);
var data = new
{
// report.ReportParameters["Year"].Value = retire.GetType().GetProperty("year").GetValue(retire);
// report.ReportParameters["Total"].Value = retire.GetType().GetProperty("total").GetValue(retire);
// report.ReportParameters["Detail"].Value = retire.GetType().GetProperty("detail").GetValue(retire);
// report.DataSource = _profileList;
report.DataSource = retire;
var tblProfile = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
tblProfile.DataSource = _profileList;
}
else
{
report.DataSource = retire;
var tblProfile = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];
tblProfile.DataSource = _profileList;
}
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
InstanceReportSource instanceReportSource = new InstanceReportSource()
{
ReportDocument = report,
template = reportfile,
reportName = "docx-report",
data = retire
};
ReportProcessor reportProcessor = new ReportProcessor(_configuration);
RenderingResult result = reportProcessor.RenderReport($"{exportType}", instanceReportSource, deviceInfo);
var content = result.DocumentBytes;
return File(content, $"application/{exportType}", returnfile);
return Success(data);
}
else
{