Files
rmutr_report/Controllers/KpiNotAchieve.Controller.cs
kamonwan taengsuk 913edd07d3
All checks were successful
continuous-integration/drone/push Build is passing
edited Font
2023-12-06 14:10:47 +07:00

134 lines
7.4 KiB
C#

using System;
using System.IO;
using ClosedXML.Excel;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualBasic;
using rmutr_report.Models;
using rmutr_report.Models.Hr;
using Swashbuckle.AspNetCore.Annotations;
namespace rmutr_report.Controllers
{
[SwaggerTag("สำหรับรายงานผลการปฏิบัติงานตัวชี้วัดที่ไม่บรรลุแผนกลยุทธ์ทางการเงิน")]
public class kpi_not_achieve : Controller
{
readonly Setting _setting;
public kpi_not_achieve(Setting setting)
{
_setting = setting;
}
[HttpPost, Route("reports/kpi_not_achieve/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetDetailKpiReport([FromRoute] string type, [FromBody] kpi_not_achieves _kpi)
{
var workbook = new XLWorkbook();
var ws = workbook.Worksheets.Add("kpi");
ws.Range("A1:E1").Merge().Value = "ผลการปฏิบัติงานตัวชี้วัดแผนกลยุทธ์ทางการเงิน (พ.ศ. " + _kpi.year_range+ ") "+"มหาวิทยาลัยเทคโนโลยีราชมงคลรัตนโกสินทร์ ประจำปี "+_kpi.budget_year
+" รอบ "+_kpi.budget_month+" เดือน";
ws.Cell("A1").Style.Font.Bold = true;
ws.Cell("A1").Style.Alignment.WrapText = true;
ws.Cell("A2").Value = "ลำดับ";
ws.Cell("A2").Style.Font.Bold = true;
ws.Cell("B2").Value = "ตัวชี้วัด";
ws.Cell("B2").Style.Font.Bold = true;
ws.Cell("B2").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Cell("C2").Value = "แผนปี "+ _kpi.plan_year.Substring(2,2);;
ws.Cell("C2").Style.Font.Bold = true;
ws.Cell("C2").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Cell("D2").Value = "ผลลัพธ์";
ws.Cell("D2").Style.Font.Bold = true;
ws.Cell("D2").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Cell("E2").Value = "หมายเหตุ";
ws.Cell("E2").Style.Font.Bold = true;
ws.Cell("E2").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Range("A2:E2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
ws.Range("A2:E2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
ws.Range("A2:E2").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Range("A1:E1").Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Range("A1:E1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
ws.Range("A1:E1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
ws.Column(1).Width = 10;
ws.Column(2).Width = 40;
ws.Column(3).Width = 20;
ws.Column(4).Width = 30;
ws.Column(5).Width = 30;
ws.Column(1).Style.Font.FontName = "TH SarabunPSK";
ws.Column(1).Style.Font.FontSize = 16;
ws.Column(2).Style.Font.FontName = "TH SarabunPSK";
ws.Column(2).Style.Font.FontSize = 16;
ws.Column(3).Style.Font.FontName = "TH SarabunPSK";
ws.Column(3).Style.Font.FontSize = 16;
ws.Column(4).Style.Font.FontName = "TH SarabunPSK";
ws.Column(4).Style.Font.FontSize = 16;
ws.Column(5).Style.Font.FontName = "TH SarabunPSK";
ws.Column(5).Style.Font.FontSize = 16;
int col = 1;
int row = 3;
int no = 1;
int rowno = 1;
// foreach (var kpis in _kpi)
// {
if (_kpi != null)
{
foreach (var header in _kpi.header_data)
{
string kpiname = "ประเด็นยุทธ์ศาสตร์ที่ " + no +" : " + header.strategic_issues;
no++;
ws.Cell(row, 1).SetValue(kpiname).Style.Font.Bold = true;
// ws.Cell(row, 2).Value = header.header_1;
ws.Cell(row, 1).Style.Fill.BackgroundColor = XLColor.Bisque;
ws.Cell(row, 1).Style.Border.OutsideBorder =
XLBorderStyleValues.None;
ws.Range(ws.Cell(row, 1), ws.Cell(row, 5)).Merge().Style.Fill.BackgroundColor = XLColor.Bisque;
ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
ws.Cell(row, 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
ws.Cell(row,5).Style.Border.RightBorder = XLBorderStyleValues.Thin;
row++;
foreach (var data1 in header.data)
{
// if ( rowno > 1 )
// {
// ws.Range(ws.Cell(row, 1), ws.Cell(row,1)).Merge()
// }
ws.Cell(row, 1).Value = rowno;
ws.Cell(row, 2).Value = data1.name;
ws.Cell(row, 3).Value = data1.value;
ws.Cell(row, 4).Value = data1.result;
ws.Cell(row, 5).Value = data1.note;
ws.Range(ws.Cell(row, 1),ws.Cell(row,5)).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
ws.Range(ws.Cell(row, 1),ws.Cell(row,5)).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
ws.Cell(row, 1).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Cell(row, 1).Style.Border.LeftBorder = XLBorderStyleValues.Thin;
ws.Cell(row, 1).Style.Border.RightBorder = XLBorderStyleValues.Thin;
ws.Cell(row, 2).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Cell(row, 3).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Cell(row, 4).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Cell(row, 5).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
ws.Range(ws.Cell(row, 1),ws.Cell(row,5)).Style.Alignment.WrapText = true;
ws.Range(ws.Cell(row, 1),ws.Cell(row,5)).Style.Font.FontName = "TH SarabunPSK";
ws.Range(ws.Cell(row, 1),ws.Cell(row,5)).Style.Font.FontSize = 16;
row++;
rowno++;
}
//row++;
}
}
using (var stream = new MemoryStream())
{
workbook.SaveAs(stream);
var content = stream.ToArray();
string date = DateTime.Now.ToString("yyyyMMddHHmmss");
return File(
content,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
date + ".xlsx");
}
}
}
}