add report development
This commit is contained in:
134
Controllers/HrDevelopment.Controller.cs
Normal file
134
Controllers/HrDevelopment.Controller.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
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 rmutr_report.Models.HrDevelopment;
|
||||
using rmutr_report.Models.Hrrecruit;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace rmutr_report.Controllers
|
||||
{
|
||||
[SwaggerTag("สำหรับรายงาน งานพัฒนา")]
|
||||
public class HrDevelopment : Controller
|
||||
{
|
||||
readonly Setting _setting;
|
||||
|
||||
public HrDevelopment(Setting setting)
|
||||
{
|
||||
this._setting = setting;
|
||||
}
|
||||
|
||||
[HttpPost, Route("reports/passer_join_project/{type}")]
|
||||
[ApiExplorerSettings(GroupName = "reports")]
|
||||
public IActionResult Gethr1Report([FromRoute] string type, [FromBody] List<passer_join_project> _hr)
|
||||
{
|
||||
// foreach (var deatil in _hr)
|
||||
// {
|
||||
// foreach (var x in deatil.data)
|
||||
// {
|
||||
// if (x.quantity_person != null)
|
||||
// {
|
||||
// var total = deatil.data.Select(r => r.quantity_person).Sum(t=>t.Value);
|
||||
// deatil.total_1 = total;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// deatil.total_1 = 0;
|
||||
// }
|
||||
// if (x.quantity_trained != null)
|
||||
// {
|
||||
// var total = deatil.data.Select(r => r.quantity_trained).Sum(t=>t.Value);
|
||||
// deatil.total_2 = total;
|
||||
// }else
|
||||
// {
|
||||
// deatil.total_2 = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// var hr1 = new List<passer_join_project>() {_hr};
|
||||
Report report = new Report();
|
||||
report.Load(_setting.report_path + "passer_join_project.frx");
|
||||
report.RegisterData(_hr, "passer_join_project");
|
||||
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": case "xlsx":
|
||||
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/passer_join_project_agency/{type}")]
|
||||
[ApiExplorerSettings(GroupName = "reports")]
|
||||
public IActionResult Gethr2Report([FromRoute] string type, [FromBody] List<passer_join_project_agency> _hr)
|
||||
{
|
||||
Report report = new Report();
|
||||
report.Load(_setting.report_path + "passer_join_project_agency.frx");
|
||||
report.RegisterData(_hr, "passer_join_project_agency");
|
||||
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": case "xlsx":
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user