This commit is contained in:
kamonwan taengsuk
2022-05-30 13:31:32 +07:00
parent 507b06dd4c
commit 39e455bd0e
45 changed files with 7588 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using FastReport;
using FastReport.Export.Csv;
using FastReport.Export.Mht;
using FastReport.Export.OoXML;
using FastReport.Export.Pdf;
using Microsoft.AspNetCore.Mvc;
using rmutr_report.Models;
using rmutr_report.Models.Hr;
namespace rmutr_report.Controllers
{
public class PersonnelController : Controller
{
readonly Setting _setting;
public PersonnelController(Setting setting)
{
this._setting = setting;
}
[HttpPost, Route("reports/personnel_summary/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetHrReport([FromRoute] string type, [FromBody] personnel_summary personnel_summarys)
{
foreach (var v in personnel_summarys.personnel_types)
{
if (v.count != null)
{
var total = personnel_summarys.personnel_types.Select(r => r.count).Sum(t=>t.Value);
personnel_summarys.total_pertype = total;
}
else
{
return null;
}
}
var personnel_summaryss = new List<personnel_summary>() { personnel_summarys };
Report report = new Report();
report.Load(_setting.report_path + "personnel_summary.frx");
report.RegisterData(personnel_summaryss, "personnel_summary");
report.Prepare();
MemoryStream stream = new MemoryStream();
switch (type)
{
case "pdf":
PDFExport pdf = new PDFExport();
report.Export(pdf, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf");
case "xls":
Excel2007Export excel = new Excel2007Export();
report.Export(excel, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/vnd.ms-excel");
break;
case "mht":
MHTExport mht = new MHTExport();
report.Export(mht, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "multipart/related");
break;
case "csv":
CSVExport csv = new CSVExport();
report.Export(csv, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "text/csv");
break;
}
return Ok();
}
[HttpPost, Route("reports/man_power/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetManReport([FromRoute] string type, [FromBody] List<man_power> man_powers)
{
//var personnel_summaryss = new List<personnel_summary>() { personnel_summarys };
Report report = new Report();
report.Load(_setting.report_path + "man_power.frx");
report.RegisterData(man_powers, "man_power");
report.Prepare();
MemoryStream stream = new MemoryStream();
switch (type)
{
case "pdf":
PDFExport pdf = new PDFExport();
report.Export(pdf, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf");
case "xls":
Excel2007Export excel = new Excel2007Export();
report.Export(excel, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/vnd.ms-excel");
break;
case "mht":
MHTExport mht = new MHTExport();
report.Export(mht, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "multipart/related");
break;
case "csv":
CSVExport csv = new CSVExport();
report.Export(csv, stream);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "text/csv");
break;
}
return Ok();
}
}
}