add report

This commit is contained in:
kamonwan taengsuk
2022-08-24 09:56:16 +07:00
parent 90139d9c12
commit a2d85ea320
11 changed files with 167 additions and 10 deletions

View File

@@ -0,0 +1,68 @@
using System.Collections.Generic;
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;
using Swashbuckle.AspNetCore.Annotations;
namespace rmutr_report.Controllers
{
[SwaggerTag("สำหรับรายงาน_budget")]
public class Budget: Controller
{
readonly Setting _setting;
public Budget(Setting setting)
{
this._setting = setting;
}
[HttpPost, Route("reports/budget_report/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetSum1Report([FromRoute] string type, [FromBody] List<budget_report> budget_reports)
{
Report report = new Report();
report.Load(_setting.report_path + "budget_report.frx");
report.RegisterData(budget_reports, "budget_report");
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();
}
}
}