From d6b31e50bb0bbd4ccfcf5f2222c9f7433ba74536 Mon Sep 17 00:00:00 2001 From: kamonwan taengsuk Date: Tue, 24 Jan 2023 14:20:21 +0700 Subject: [PATCH] =?UTF-8?q?add=20report=20=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/RepairCost.Controller.cs | 228 +++++++++++++++++++++- Controllers/StudentNews.Controller.cs | 184 +++++++++++------- Controllers/StudyMaterial.Controller.cs | 244 ++++++++++++++++++++++++ Models/budget/study_material.cs | 28 +++ 4 files changed, 605 insertions(+), 79 deletions(-) create mode 100644 Controllers/StudyMaterial.Controller.cs create mode 100644 Models/budget/study_material.cs diff --git a/Controllers/RepairCost.Controller.cs b/Controllers/RepairCost.Controller.cs index 3a7826e..12d5791 100644 --- a/Controllers/RepairCost.Controller.cs +++ b/Controllers/RepairCost.Controller.cs @@ -8,7 +8,7 @@ using Swashbuckle.AspNetCore.Annotations; namespace rmutr_report.Controllers { - [SwaggerTag("สำหรับรายงานค่าซ่อมพาหนะ ง.2")] + [SwaggerTag("สำหรับรายงาน ง.2")] public class repaircost : Controller { readonly Setting _setting; @@ -122,7 +122,8 @@ namespace rmutr_report.Controllers { foreach (var house in _repair_cost.data) { - + if (house.type_vehicle_transport != "รวม") + { ws.Cell(row, 1).Value = house.no; ws.Cell(row, 2).Value = house.type_vehicle_transport; ws.Cell(row, 3).Value = house.quantity; @@ -149,14 +150,40 @@ namespace rmutr_report.Controllers ws.Range(ws.Cell(row, 4), ws.Cell(row, 5)).SetDataType(XLDataType.Number); ws.Range(ws.Cell(row, 4), ws.Cell(row, 5)).Style.NumberFormat.SetFormat("#,#"); row++; - + } if (house.type_vehicle_transport == "รวม") { - ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Style.Border.LeftBorder = - XLBorderStyleValues.None; - ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Style.Border.RightBorder = - XLBorderStyleValues.None; + ws.Cell(row, 1).Value = house.no; + ws.Cell(row, 2).Value = house.type_vehicle_transport; + ws.Cell(row, 3).Value = house.quantity; + ws.Cell(row, 4).Value = house.repair_rate; + ws.Cell(row, 5).Value = house.amount; + 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; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 5)).Style.Alignment.WrapText = true; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 2).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 3).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 4).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 5).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Style.Border.LeftBorder = + XLBorderStyleValues.None; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 5)).Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Border.RightBorder = + XLBorderStyleValues.None; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 5)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 4), ws.Cell(row, 5)).SetDataType(XLDataType.Number); + ws.Range(ws.Cell(row, 4), ws.Cell(row, 5)).Style.NumberFormat.SetFormat("#,#"); + row++; } } } @@ -173,5 +200,192 @@ namespace rmutr_report.Controllers } } } + + [HttpPost, Route("reports/fuel_cost/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetFuelReport([FromRoute] string type, + [FromBody] repair_cost _repair_cost) + { + //var t = _teaching_fee_extra.ToArray(); + { + var workbook = new XLWorkbook(); + var ws = workbook.Worksheets.Add("ค่าน้ำมันเชื้อเพลิง"); + ws.Cell("E1").Value = "แบบ ง.2"; + ws.Cell("E1").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("E1").Style.Font.FontSize = 16; + ws.Cell("E1").Style.Font.Bold = true; + ws.Cell("E1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("E1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("A2:E2").Merge().Value = + "รายละเอียดค่าน้ำมันเชื้อเพลิง ปีงบประมาณ " + _repair_cost.budget_year; + ws.Range("A2:E2").Style.Alignment.WrapText = true; + ws.Range("A2:E2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A2:E2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A2").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("A2").Style.Font.FontSize = 16; + ws.Range("A2:E2").Style.Font.Bold = true; + ws.Range("A3:E3").Merge().Value = "แผน " + _repair_cost.plan + " ผลผลิต " + _repair_cost.product; + ws.Range("A3:E3").Style.Alignment.WrapText = true; + ws.Range("A3:E3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A3:E3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A3").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("A3").Style.Font.FontSize = 16; + ws.Range("A3:E3").Style.Font.Bold = true; + ws.Range("A4:E4").Merge().Value = "หน่วยงาน " + _repair_cost.agency + " พื้นที่ " + _repair_cost.area; + ws.Range("A4:E4").Style.Alignment.WrapText = true; + ws.Range("A4:E4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A4:E4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A4").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("A4").Style.Font.FontSize = 16; + ws.Range("A4:E4").Style.Font.Bold = true; + + ws.Range("A5:A6").Merge().Value = "ที่"; + ws.Range("A5:A6").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("A5:A6").Style.Font.FontSize = 16; + ws.Range("A5:A6").Style.Font.Bold = true; + ws.Range("A5:A6").Style.Alignment.WrapText = true; + ws.Range("B5:B6").Merge().Value = "ประเภทยานพาหนะและขนส่ง"; + ws.Cell("B5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("B5").Style.Font.FontSize = 16; + ws.Cell("B5").Style.Font.Bold = true; + ws.Cell("B5").Style.Alignment.WrapText = true; + ws.Cell("C5").Value = "จำนวน"; + ws.Cell("C5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("C5").Style.Font.FontSize = 16; + ws.Cell("C5").Style.Font.Bold = true; + ws.Cell("C5").Style.Alignment.WrapText = true; + ws.Cell("C6").Value = "(คัน)"; + ws.Cell("C6").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("C6").Style.Font.FontSize = 16; + ws.Cell("C6").Style.Font.Bold = true; + ws.Cell("C6").Style.Alignment.WrapText = true; + ws.Cell("D5").Value = "อัตราค่าน้ำมันเชื้อเพลิง"; + ws.Cell("D5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("D5").Style.Font.FontSize = 16; + ws.Cell("D5").Style.Font.Bold = true; + ws.Cell("D5").Style.Alignment.WrapText = true; + ws.Cell("D6").Value = "บาท/คัน/ปี"; + ws.Cell("D6").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("D6").Style.Font.FontSize = 16; + ws.Cell("D6").Style.Font.Bold = true; + ws.Cell("D6").Style.Alignment.WrapText = true; + ws.Cell("E5").Value = "ค่าน้ำมันเชื้อเพลิง"; + ws.Cell("E5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("E5").Style.Font.FontSize = 16; + ws.Cell("E5").Style.Font.Bold = true; + ws.Cell("E5").Style.Alignment.WrapText = true; + ws.Cell("E6").Value = "บาท/ปี"; + ws.Cell("E6").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("E6").Style.Font.FontSize = 16; + ws.Cell("E6").Style.Font.Bold = true; + ws.Cell("E6").Style.Alignment.WrapText = true; + + ws.Range("A5:E6").Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Range("A5:E6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A5:E6").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("A5:E6").Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range("A5:A6").Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Range("B5:B6").Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Range("C5:C6").Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Range("D5:D6").Style.Border.RightBorder = + XLBorderStyleValues.Thin; + + ws.Column(1).Width = 10; + ws.Column(2).Width = 40; + ws.Column(3).Width = 10; + ws.Column(4).Width = 25; + ws.Column(5).Width = 25; + + int row = 7; + //int row2 = 9; + //ws.Cell(row, 3).SetDataType(XLDataType.Number); + if (_repair_cost != null) + { + foreach (var house in _repair_cost.data) + { + if (house.type_vehicle_transport != "รวม") + { + ws.Cell(row, 1).Value = house.no; + ws.Cell(row, 2).Value = house.type_vehicle_transport; + ws.Cell(row, 3).Value = house.quantity; + ws.Cell(row, 4).Value = house.repair_rate; + ws.Cell(row, 5).Value = house.amount; + + 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; + 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.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + + ws.Range(ws.Cell(row, 1), ws.Cell(row, 5)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 5)).Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + 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.Range(ws.Cell(row, 4), ws.Cell(row, 5)).SetDataType(XLDataType.Number); + ws.Range(ws.Cell(row, 4), ws.Cell(row, 5)).Style.NumberFormat.SetFormat("#,#"); + row++; + } + + if (house.type_vehicle_transport == "รวม") + { + ws.Cell(row, 1).Value = house.no; + ws.Cell(row, 2).Value = house.type_vehicle_transport; + ws.Cell(row, 3).Value = house.quantity; + ws.Cell(row, 4).Value = house.repair_rate; + ws.Cell(row, 5).Value = house.amount; + 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; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 5)).Style.Alignment.WrapText = true; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 2).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 3).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 4).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 5).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Style.Border.LeftBorder = + XLBorderStyleValues.None; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 5)).Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Border.RightBorder = + XLBorderStyleValues.None; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 5)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 4), ws.Cell(row, 5)).SetDataType(XLDataType.Number); + ws.Range(ws.Cell(row, 4), ws.Cell(row, 5)).Style.NumberFormat.SetFormat("#,#"); + 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", + "fuel_cost_" + date + ".xlsx"); + } + } + } } } \ No newline at end of file diff --git a/Controllers/StudentNews.Controller.cs b/Controllers/StudentNews.Controller.cs index 61fcb0d..95bcc7c 100644 --- a/Controllers/StudentNews.Controller.cs +++ b/Controllers/StudentNews.Controller.cs @@ -234,78 +234,118 @@ namespace rmutr_report.Controllers public IActionResult GetStd4Report([FromRoute] string type, [FromBody] student_news_year _student_news_faculty) { - // var std = _student_news_faculty.data; - // var a1 = _student_news_faculty.data.Where(d => d.bachelors_degree_science1 == d.bachelors_degree_science1) - // .Sum(o => o.bachelors_degree_science1); - // var a2 = _student_news_faculty.data.Where(d => d.bachelors_degree_social1 == d.bachelors_degree_social1) - // .Sum(o => o.bachelors_degree_social1); - // - // foreach (var data in std) - // { - // if (data.bachelors_degree_science1 != 0 && data.bachelors_degree_social1 != 0) - // { - // data.bachelors_degree_total1 = data.bachelors_degree_science1 + data.bachelors_degree_social1; - // } - // if (data.bachelors_degree_social1 == 0) - // { - // data.bachelors_degree_total1 = data.bachelors_degree_science1; - // } - // if (data.bachelors_degree_social1 == 0 && data.bachelors_degree_social2 == 0 ) - // { - // data.bachelors_degree_total1 = data.bachelors_degree_science1; - // data.bachelors_degree_total2 = data.bachelors_degree_science2; - // } - // if (data.bachelors_degree_science2 != 0 && data.bachelors_degree_social2 != 0) - // { - // data.bachelors_degree_total2 = data.bachelors_degree_science2 + data.bachelors_degree_social2; - // } - // - // if (data.bachelors_degree_science1 == 0 && data.bachelors_degree_science2 == 0 ) - // { - // data.bachelors_degree_total2 = data.bachelors_degree_social2; - // data.bachelors_degree_total1 = data.bachelors_degree_social1; - // } - // data.total1 = a1; - // data.sum_percentage_science = - // ((data.bachelors_degree_science2 - data.bachelors_degree_science1) / - // data.bachelors_degree_science1) * 100; - // - // data.sum_percentage_social = ((data.bachelors_degree_social2 - data.bachelors_degree_social1) / - // data.bachelors_degree_social1) * 100; - // - // if (data.bachelors_degree_science1 == 0 || data.bachelors_degree_science2 == 0) - // { - // - // data.sum_percentage_science = - // null; - // - // } - // - // if (data.bachelors_degree_social1 == 0 || data.bachelors_degree_social2 == 0) - // { - // data.sum_percentage_social = null; - // } - // var a3 = _student_news_faculty.data - // .Where(d => d.bachelors_degree_total1 == d.bachelors_degree_total1) - // .Sum(o => o.bachelors_degree_total1); - // var a4 = _student_news_faculty.data - // .Where(d => d.bachelors_degree_science2 == d.bachelors_degree_science2) - // .Sum(o => o.bachelors_degree_science2); - // var a5 = _student_news_faculty.data - // .Where(d => d.bachelors_degree_social2 == d.bachelors_degree_social2) - // .Sum(o => o.bachelors_degree_social2); - // var a6 = _student_news_faculty.data - // .Where(d => d.bachelors_degree_total2 == d.bachelors_degree_total2) - // .Sum(o => o.bachelors_degree_total2); - // data.total2 = a2; - // data.total3 = a3; - // data.total4 = a4; - // data.total5 = a5; - // data.total6 = a6; - // data.total7 = ((data.total4 - data.total1) / data.total1) * 100; - // data.total8 = ((data.total5 - data.total2) / data.total2) * 100; - // - //} + var std = _student_news_faculty.data; + var a1 = _student_news_faculty.data.Where(d => d.bachelors_degree_science1 == d.bachelors_degree_science1) + .Sum(o => o.bachelors_degree_science1); + var a2 = _student_news_faculty.data.Where(d => d.bachelors_degree_social1 == d.bachelors_degree_social1) + .Sum(o => o.bachelors_degree_social1); + + foreach (var data in std) + { + if (data.bachelors_degree_science1 != 0 && data.bachelors_degree_social1 != 0) + { + data.bachelors_degree_total1 = data.bachelors_degree_science1 + data.bachelors_degree_social1; + } + if (data.bachelors_degree_social1 == 0) + { + data.bachelors_degree_total1 = data.bachelors_degree_science1; + } + if (data.bachelors_degree_social1 == 0 && data.bachelors_degree_social2 == 0 ) + { + data.bachelors_degree_total1 = data.bachelors_degree_science1; + data.bachelors_degree_total2 = data.bachelors_degree_science2; + } + if (data.bachelors_degree_science2 != 0 && data.bachelors_degree_social2 != 0) + { + data.bachelors_degree_total2 = data.bachelors_degree_science2 + data.bachelors_degree_social2; + } + + if (data.bachelors_degree_science1 == 0 && data.bachelors_degree_science2 == 0 ) + { + data.bachelors_degree_total2 = data.bachelors_degree_social2; + data.bachelors_degree_total1 = data.bachelors_degree_social1; + } + + if (data.bachelors_degree_science1 != 0 && data.bachelors_degree_science2!=0) + { + + data.sum_percentage_science = + ((data.bachelors_degree_science2 - data.bachelors_degree_science1) / + data.bachelors_degree_science1) * 100; + + } + // if (data.bachelors_degree_science1 == 0 || data.bachelors_degree_science2==0) + // { + // data.total1 = a1; + // data.sum_percentage_science = + // ((data.bachelors_degree_science2 - data.bachelors_degree_science1) / + // data.bachelors_degree_science1) * 100; + // + // } + if (data.bachelors_degree_social1 != 0 && data.bachelors_degree_social2 != 0) + { + data.sum_percentage_social = ((data.bachelors_degree_social2 - data.bachelors_degree_social1) / + data.bachelors_degree_social1) * 100; + } + + if (data.bachelors_degree_science1 == 0 || data.bachelors_degree_science2 == 0) + { + + data.sum_percentage_science = + null; + + } + + if (data.bachelors_degree_social1 == 0 || data.bachelors_degree_social2 == 0) + { + data.sum_percentage_social = null; + } + var a3 = _student_news_faculty.data + .Where(d => d.bachelors_degree_total1 == d.bachelors_degree_total1) + .Sum(o => o.bachelors_degree_total1); + var a4 = _student_news_faculty.data + .Where(d => d.bachelors_degree_science2 == d.bachelors_degree_science2) + .Sum(o => o.bachelors_degree_science2); + var a5 = _student_news_faculty.data + .Where(d => d.bachelors_degree_social2 == d.bachelors_degree_social2) + .Sum(o => o.bachelors_degree_social2); + var a6 = _student_news_faculty.data + .Where(d => d.bachelors_degree_total2 == d.bachelors_degree_total2) + .Sum(o => o.bachelors_degree_total2); + data.total1 = a1; + data.total2 = a2; + data.total3 = a3; + data.total4 = a4; + data.total5 = a5; + data.total6 = a6; + if (data.total1!=0 && data.total4!=0 ) + { + data.total7 = ((data.total4 - data.total1) / data.total1) * 100; + } + + if (data.total1 == 0 || data.total4 == 0) + { + data.total7 = ((data.total4 - data.total1) / data.total1) * 100; + } + + if (data.total2!=0 && data.total5!=0) + { + data.total8 = ((data.total5 - data.total2) / data.total2) * 100; + } + if (data.total2==0 || data.total5==0) + { + data.total8 = ((data.total5 - data.total2) / data.total2) * 100; + } + + if (data.sum_percentage_science == null) + { + data.sum_percentage_science = 0; + } + if (data.sum_percentage_social == null) + { + data.sum_percentage_social = 0; + } + } var student_news_facultys = new List() {_student_news_faculty}; Report report = new Report(); diff --git a/Controllers/StudyMaterial.Controller.cs b/Controllers/StudyMaterial.Controller.cs new file mode 100644 index 0000000..992791c --- /dev/null +++ b/Controllers/StudyMaterial.Controller.cs @@ -0,0 +1,244 @@ +using System; +using System.Collections.Generic; +using System.IO; +using ClosedXML.Excel; +using Microsoft.AspNetCore.Mvc; +using rmutr_report.Models; +using Swashbuckle.AspNetCore.Annotations; + +namespace rmutr_report.Controllers +{ + [SwaggerTag("สำหรับรายงาน ง.7")] + public class studymaterial : Controller + { + readonly Setting _setting; + + public studymaterial(Setting setting) + { + this._setting = setting; + } + [HttpPost, Route("reports/study_material/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetMaterialReport([FromRoute] string type, + [FromBody] study_material _study_material) + { + { + var workbook = new XLWorkbook(); + var ws = workbook.Worksheets.Add("ง.7"); + ws.Range("A1:J1").Merge().Value = "แบบฟอร์มแผนการเรียน คณะ" + _study_material.faculty + "ปีงบประมาณ "+ _study_material.budget_year; + ws.Range("A1:J1").Style.Alignment.WrapText = true; + ws.Range("A1:J1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A1:J1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A1").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("A1").Style.Font.FontSize = 16; + ws.Range("A1:J1").Style.Font.Bold = true; + ws.Range("A2:J2").Merge().Value = "ผลผลิต " + _study_material.product+" คณะ "+ _study_material.faculty; + ws.Range("A2:J2").Style.Alignment.WrapText = true; + ws.Range("A2:J2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A2:J2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A2").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("A2").Style.Font.FontSize = 16; + ws.Range("A2:J2").Style.Font.Bold = true; + ws.Range("A3:A5").Merge().Value = "ภาคการศึกษา"; + ws.Range("A3:A5").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("A3:A5").Style.Font.FontSize = 16; + ws.Range("A3:A5").Style.Font.Bold = true; + ws.Range("A3:A5").Style.Alignment.WrapText = true; + ws.Range("B3:B5").Merge().Value = "นักศึกษา"; + ws.Range("B3:B5").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("B3:B5").Style.Font.FontSize = 16; + ws.Range("B3:B5").Style.Font.Bold = true; + ws.Range("B3:B5").Style.Alignment.WrapText = true; + ws.Range("C3:F4").Merge().Value = "พื้นที่เขตการศึกษา"; + ws.Range("C3:F4").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("C3:F4").Style.Font.FontSize = 16; + ws.Range("C3:F4").Style.Font.Bold = true; + ws.Range("C3:F4").Style.Alignment.WrapText = true; + ws.Range("C3:F4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("C3:F4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("C5").Value = "เพาะช่าง"; + ws.Cell("C5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("C5").Style.Font.FontSize = 16; + ws.Cell("C5").Style.Font.Bold = true; + ws.Cell("C5").Style.Alignment.WrapText = true; + ws.Cell("D5").Value = "บพิตรพิมุข จักรวรรดิ"; + ws.Cell("D5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("D5").Style.Font.FontSize = 16; + ws.Cell("D5").Style.Font.Bold = true; + ws.Cell("D5").Style.Alignment.WrapText = true; + ws.Cell("E5").Value = "ศาลายา"; + ws.Cell("E5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("E5").Style.Font.FontSize = 16; + ws.Cell("E5").Style.Font.Bold = true; + ws.Cell("E5").Style.Alignment.WrapText = true; + ws.Cell("F5").Value = "วังไกลกังวล"; + ws.Cell("F5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("F5").Style.Font.FontSize = 16; + ws.Cell("F5").Style.Font.Bold = true; + ws.Cell("F5").Style.Alignment.WrapText = true; + ws.Range("G3:G4").Merge().Value = "รวม สายวิทย์"; + ws.Range("G3:G4").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("G3:G4").Style.Font.FontSize = 16; + ws.Range("G3:G4").Style.Font.Bold = true; + ws.Cell("G3").Style.Alignment.WrapText = true; + ws.Cell("G5").Value = "(1)"; + ws.Cell("G5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("G5").Style.Font.FontSize = 16; + ws.Cell("G5").Style.Font.Bold = true; + ws.Cell("G5").Style.Alignment.WrapText = true; + ws.Range("H3:H4").Merge().Value = "รวม สายสังคม"; + ws.Range("H3:H4").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("H3:H4").Style.Font.FontSize = 16; + ws.Range("H3:H4").Style.Font.Bold = true; + ws.Cell("H3").Style.Alignment.WrapText = true; + ws.Cell("H5").Value = "(2)"; + ws.Cell("H5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("H5").Style.Font.FontSize = 16; + ws.Cell("H5").Style.Font.Bold = true; + ws.Cell("H5").Style.Alignment.WrapText = true; + ws.Range("I3:I4").Merge().Value = "อัตราค่าสอน สายวิทย์"; + ws.Range("I3:I4").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("I3:I4").Style.Font.FontSize = 16; + ws.Range("I3:I4").Style.Font.Bold = true; + ws.Cell("I3").Style.Alignment.WrapText = true; + ws.Cell("I5").Value = "(1) x 175 = (3)"; + ws.Cell("I5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("I5").Style.Font.FontSize = 16; + ws.Cell("I5").Style.Font.Bold = true; + ws.Cell("I5").Style.Alignment.WrapText = true; + ws.Range("J3:J4").Merge().Value = "อัตราค่าสอน สายสังคม"; + ws.Range("J3:J4").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("J3:J4").Style.Font.FontSize = 16; + ws.Range("J3:J4").Style.Font.Bold = true; + ws.Cell("J3").Style.Alignment.WrapText = true; + ws.Cell("J5").Value = "(2) x 125 = (4)"; + ws.Cell("J5").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("J5").Style.Font.FontSize = 16; + ws.Cell("J5").Style.Font.Bold = true; + ws.Cell("J5").Style.Alignment.WrapText = true; + ws.Range("A3:J5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("A3:J5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A3:J5").Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Range("C3:F4").Style.Border.BottomBorder = + XLBorderStyleValues.Thin; + ws.Range("A3:J5").Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range("A3:J5").Style.Border.LeftBorder = + XLBorderStyleValues.Thin; + ws.Range("A3:J5").Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Column(1).Width = 20; + ws.Column(2).Width = 40; + ws.Column(3).Width = 15; + ws.Column(4).Width = 15; + ws.Column(5).Width = 15; + ws.Column(6).Width = 15; + ws.Column(7).Width = 15; + ws.Column(8).Width = 15; + ws.Column(9).Width = 15; + ws.Column(10).Width = 15; + var row1 = ws.Row(3); + row1.Height = 20; + int row = 6; + + if (_study_material != null) + { + foreach (var data in _study_material.data) + { + if (data.academic_semester != "รวม") + { + ws.Cell(row, 1).Value = data.academic_semester; + ws.Cell(row, 2).Value = data.student; + ws.Cell(row, 3).Value = data.pohchang; + ws.Cell(row, 4).Value = data.bophitphimuk; + ws.Cell(row, 5).Value = data.salaya; + ws.Cell(row, 6).Value = data.klai_kangwon; + ws.Cell(row, 7).Value = data.sum_science; + ws.Cell(row, 8).Value = data.sum_social; + ws.Cell(row, 9).Value = data.cost_science; + ws.Cell(row, 10).Value = data.cost_social; + + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Cell(row, 1).Style.Font.Bold = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 7).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 8).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 9).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 10).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + + ws.Range(ws.Cell(row, 3), ws.Cell(row, 10)).SetDataType(XLDataType.Number); + ws.Range(ws.Cell(row, 3), ws.Cell(row, 10)).Style.NumberFormat.SetFormat("#,#"); + row++; + + } + if (data.academic_semester == "รวม" || data.academic_semester == "รวม 1 ปีภาคการศึกษา") + { + + ws.Cell(row, 1).Value = data.academic_semester; + ws.Cell(row, 2).Value = data.student; + ws.Cell(row, 3).Value = data.pohchang; + ws.Cell(row, 4).Value = data.bophitphimuk; + ws.Cell(row, 5).Value = data.salaya; + ws.Cell(row, 6).Value = data.klai_kangwon; + ws.Cell(row, 7).Value = data.sum_science; + ws.Cell(row, 8).Value = data.sum_social; + ws.Cell(row, 9).Value = data.cost_science; + ws.Cell(row, 10).Value = data.cost_social; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.Bold = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Cell(row, 1).Style.Font.Bold = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 7).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 8).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 9).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 10).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + + ws.Range(ws.Cell(row, 3), ws.Cell(row, 10)).SetDataType(XLDataType.Number); + ws.Range(ws.Cell(row, 3), ws.Cell(row, 10)).Style.NumberFormat.SetFormat("#,#"); + 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", + "study_material_" + date + ".xlsx"); + } + } + } + } +} \ No newline at end of file diff --git a/Models/budget/study_material.cs b/Models/budget/study_material.cs new file mode 100644 index 0000000..6bea812 --- /dev/null +++ b/Models/budget/study_material.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +namespace rmutr_report.Models +{ + public class study_material + { + public string budget_year { get; set; } + public string product { get; set; } + public string faculty { get; set; } + public List data { get; set; } + } + + public class study_material_detail + { + public string academic_semester { get; set; } + public string student { get; set; } + // public string code { get; set; } + // public string major { get; set; } + public string salaya { get; set; } + public string bophitphimuk { get; set; } + public string pohchang { get; set; } + public string klai_kangwon { get; set; } + public decimal? sum_science { get; set; } + public decimal? sum_social { get; set; } + public decimal? cost_science { get; set; } + public decimal? cost_social { get; set; } + } +} \ No newline at end of file