Report Command 04-07

This commit is contained in:
Suphonchai Phoonsawat 2023-09-03 13:35:58 +07:00
parent 1ebdddaa6a
commit 1404ba3be5
12 changed files with 922 additions and 51 deletions

View file

@ -1,14 +1,12 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Responses.Reports;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BMA.EHR.Application.Repositories.Commands
{
@ -119,6 +117,234 @@ namespace BMA.EHR.Application.Repositories.Commands
}
}
public async Task<List<CommandType03Response>> GetCommandType03AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.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<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType04AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.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<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType05_06AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.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<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
public async Task<List<CommandType03Response>> GetCommandType07AttachmentAsync(Guid id)
{
try
{
var raw_data = await _dbContext.Set<CommandReceiver>()
.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<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.Include(x => x.PositionPath)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PositionType)
on r.RefPlacementProfileId equals p.Id
join pf in _dbContext.Set<Profile>()
.Include(x => x.Position)
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
on r.CitizenId equals pf.CitizenId
select new CommandType03Response
{
CitizenId = r.CitizenId,
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
OldOc = pf.Oc == null ? "" : pf.Oc.Replace("/", " "),
OldPositionName = pf.Position == null ? "" : pf.Position.Name,
OldPositionLevel = pf.PositionLevel == null ? "" : pf.PositionLevel.Name,
OldPositionType = pf.PositionType == null ? "" : pf.PositionType.Name,
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name,
OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? 0 : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value,
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
NewPositionType = p.PositionType == null ? "" : p.PositionType.Name,
NewPositionNumber = p.PositionNumber == null ? "" : p.PositionNumber.Name,
NewSalary = p.Amount == null ? 0 : p.Amount.Value,
AppointDate = p.RecruitDate == null ? "" : p.RecruitDate.Value.ToThaiFullDate3()
})
.ToList();
return report_data;
}
catch
{
throw;
}
}
#endregion
}
}

View file

@ -0,0 +1,35 @@
namespace BMA.EHR.Application.Responses.Reports
{
public class CommandType03Response
{
public string CitizenId { get; set; } = string.Empty;
public string FullName { get; set; } = string.Empty;
public string OldOc { get; set; } = string.Empty;
public string OldPositionName { get; set; } = string.Empty;
public string OldPositionLevel { get; set; } = string.Empty;
public string OldPositionType { get; set; } = string.Empty;
public string OldPositionNumber { get; set; } = string.Empty;
public double OldSalary { get; set; } = 0;
public string NewOc { get; set; } = string.Empty;
public string NewPositionName { get; set; } = string.Empty;
public string NewPositionLevel { get; set; } = string.Empty;
public string NewPositionType { get; set; } = string.Empty;
public string NewPositionNumber { get; set; } = string.Empty;
public double NewSalary { get; set; } = 0;
public string AppointDate { get; set; } = string.Empty;
}
}

View file

@ -285,6 +285,596 @@ namespace BMA.EHR.Report.Service.Controllers
#endregion
#region " C-PM-03 "
private async Task<byte[]> GenerateCommandReportType03_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", $"03-คำสั่งแต่งตั้งผู้สอบแข่งขัน-Head.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<byte[]> GenerateCommandReportType03_Attachment(Guid commandId, string exportType)
{
try
{
var command = await _repository.GetByIdAsync(commandId);
if (command == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var data = await _commandReportRepository.GetCommandType03AttachmentAsync(commandId);
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"03-คำสั่งแต่งตั้งผู้สอบแข่งขัน.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
#region " C-PM-04 "
private async Task<byte[]> GenerateCommandReportType04_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", $"04-คำสั่งย้ายผู้สอบแข่งขัน-Head.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<byte[]> GenerateCommandReportType04_Attachment(Guid commandId, string exportType)
{
try
{
var command = await _repository.GetByIdAsync(commandId);
if (command == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var data = await _commandReportRepository.GetCommandType03AttachmentAsync(commandId);
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"04-คำสั่งย้ายผู้สอบแข่งขัน.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
#region " C-PM-05 "
private async Task<byte[]> GenerateCommandReportType05_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", $"05-06-คำสั่งแต่งตั้ง-คำสั่งเลื่อน.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<byte[]> GenerateCommandReportType05_Attachment(Guid commandId, string exportType)
{
try
{
var command = await _repository.GetByIdAsync(commandId);
if (command == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var data = await _commandReportRepository.GetCommandType05_06AttachmentAsync(commandId);
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-แนบท้ายคำสั่งแต่งตั้ง-คำสั่งเลื่อน.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
#region " C-PM-06 "
private async Task<byte[]> GenerateCommandReportType06_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", $"05-06-คำสั่งแต่งตั้ง-คำสั่งเลื่อน.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<byte[]> GenerateCommandReportType06_Attachment(Guid commandId, string exportType)
{
try
{
var command = await _repository.GetByIdAsync(commandId);
if (command == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var data = await _commandReportRepository.GetCommandType05_06AttachmentAsync(commandId);
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-แนบท้ายคำสั่งแต่งตั้ง-คำสั่งเลื่อน.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
#region " C-PM-07 "
private async Task<byte[]> GenerateCommandReportType07_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", $"07-คำสั่งย้าย.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<byte[]> GenerateCommandReportType07_Attachment(Guid commandId, string exportType)
{
try
{
var command = await _repository.GetByIdAsync(commandId);
if (command == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var data = await _commandReportRepository.GetCommandType05_06AttachmentAsync(commandId);
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"07-แนบท้ายคำสั่งย้าย.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 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ "
@ -477,7 +1067,7 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType03CoverReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType03CoverReportAsync(Guid id, string exportType = "pdf")
{
try
{
@ -489,10 +1079,12 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"03-คำสั่งแต่งตั้งผู้สอบแข่งขัน-Head.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 GenerateCommandReportType03_Cover(id, exportType);
return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -514,10 +1106,14 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType03AttachmentReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType03AttachmentReportAsync(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())
{
@ -526,10 +1122,8 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"03-คำสั่งแต่งตั้งผู้สอบแข่งขัน.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType03_Attachment(id, exportType);
return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -555,7 +1149,7 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType04CoverReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType04CoverReportAsync(Guid id, string exportType = "pdf")
{
try
{
@ -567,10 +1161,12 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"04-คำสั่งย้ายผู้สอบแข่งขัน-Head.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 GenerateCommandReportType04_Cover(id, exportType);
return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -592,10 +1188,14 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType04AttachmentReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType04AttachmentReportAsync(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())
{
@ -604,10 +1204,8 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"04-คำสั่งย้ายผู้สอบแข่งขัน.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType04_Attachment(id, exportType);
return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -633,7 +1231,7 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType05CoverReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType05CoverReport(Guid id, string exportType = "pdf")
{
try
{
@ -645,10 +1243,12 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-คำสั่งแต่งตั้ง-คำสั่งเลื่อน.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 GenerateCommandReportType05_Cover(id, exportType);
return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -670,10 +1270,14 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType05AttachmentReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType05AttachmentReport(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())
{
@ -682,10 +1286,8 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-แนบท้ายคำสั่งแต่งตั้ง-คำสั่งเลื่อน.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType05_Attachment(id, exportType);
return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -711,7 +1313,7 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType06CoverReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType06CoverReport(Guid id, string exportType = "pdf")
{
try
{
@ -723,10 +1325,12 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-คำสั่งแต่งตั้ง-คำสั่งเลื่อน.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 GenerateCommandReportType06_Cover(id, exportType);
return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -748,10 +1352,14 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType06AttachmentReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType06AttachmentReport(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())
{
@ -760,10 +1368,8 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-แนบท้ายคำสั่งแต่งตั้ง-คำสั่งเลื่อน.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType06_Attachment(id, exportType);
return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -789,7 +1395,7 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType07CoverReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType07CoverReport(Guid id, string exportType = "pdf")
{
try
{
@ -801,10 +1407,12 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"07-คำสั่งย้าย.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 GenerateCommandReportType07_Cover(id, exportType);
return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{
@ -826,10 +1434,14 @@ namespace BMA.EHR.Report.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public IActionResult GetCommandType07AttachmentReport(Guid id, string exportType = "pdf")
public async Task<ActionResult<ResponseObject>> GetCommandType07AttachmentReport(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())
{
@ -838,10 +1450,8 @@ namespace BMA.EHR.Report.Service.Controllers
case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
}
var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"07-แนบท้ายคำสั่งย้าย.trdp");
var contentData = _reportGenerator.GenerateReport(rptFile, exportType);
return File(contentData, mimeType, $"command-attachment.{exportType.Trim().ToLower()}");
var contentData = await GenerateCommandReportType07_Attachment(id, exportType);
return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
}
catch
{