diff --git a/Controllers/HouseForRent.Controller.cs b/Controllers/HouseForRent.Controller.cs index 8f34a14..e8bb199 100644 --- a/Controllers/HouseForRent.Controller.cs +++ b/Controllers/HouseForRent.Controller.cs @@ -39,7 +39,7 @@ namespace rmutr_report.Controllers ws.Cell("A2").Style.Font.FontName = "TH SarabunPSK"; ws.Cell("A2").Style.Font.FontSize = 16; ws.Range("A2:F2").Style.Font.Bold = true; - ws.Range("A3:F3").Merge().Value = "แผน" + _house_for_rent.budget_year+" ผลผลิต "+_house_for_rent.product; + ws.Range("A3:F3").Merge().Value = "แผน" + _house_for_rent.plan+" ผลผลิต "+_house_for_rent.product; ws.Range("A3:F3").Style.Alignment.WrapText = true; ws.Range("A3:F3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; ws.Range("A3:F3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; diff --git a/Controllers/RepairCost.Controller.cs b/Controllers/RepairCost.Controller.cs new file mode 100644 index 0000000..3a7826e --- /dev/null +++ b/Controllers/RepairCost.Controller.cs @@ -0,0 +1,177 @@ +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("สำหรับรายงานค่าซ่อมพาหนะ ง.2")] + public class repaircost : Controller + { + readonly Setting _setting; + + public repaircost(Setting setting) + { + this._setting = setting; + } + [HttpPost, Route("reports/repair_cost/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetRepairReport([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 = 15; + ws.Column(5).Width = 15; + + int row = 7; + //int row2 = 9; + //ws.Cell(row, 3).SetDataType(XLDataType.Number); + if (_repair_cost != null) + { + foreach (var house in _repair_cost.data) + { + + 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, 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; + } + } + } + + 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", + "repair_cost_" + date + ".xlsx"); + } + } + } + } +} \ No newline at end of file diff --git a/Controllers/StudentNews.Controller.cs b/Controllers/StudentNews.Controller.cs new file mode 100644 index 0000000..3face58 --- /dev/null +++ b/Controllers/StudentNews.Controller.cs @@ -0,0 +1,233 @@ +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; +using Swashbuckle.AspNetCore.Annotations; + +namespace rmutr_report.Controllers +{ + [SwaggerTag("สำหรับรายงานนักศึกษาเข้าใหม่")] + public class StudentNews : Controller + { + readonly Setting _setting; + + public StudentNews(Setting setting) + { + this._setting = setting; + } + + [HttpPost, Route("reports/student_news_faculty/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetStd1Report([FromRoute] string type, + [FromBody] student_news_faculty _student_news_faculty) + { + var std = _student_news_faculty.data; + var a1 = _student_news_faculty.data.Where(d => d.bachelors_degree == d.bachelors_degree) + .Sum(o => o.bachelors_degree); + + foreach (var data in std) + { + data.total1 = a1; + if (data.bachelors_degree != 0 ) + { + data.sum_percentage = (data.bachelors_degree*100)/a1; + } + var a2 = _student_news_faculty.data.Where(d => d.sum_percentage == d.sum_percentage) + .Sum(o => o.sum_percentage); + data.total2 = a2; + } + var student_news_facultys = new List() {_student_news_faculty}; + + Report report = new Report(); + report.Load(_setting.report_path + "student_news_faculty.frx"); + report.RegisterData(student_news_facultys, "student_news_faculty"); + 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/student_news_area/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetStd2Report([FromRoute] string type, + [FromBody] student_news_area _student_news_faculty) + { + var std = _student_news_faculty.data; + var a1 = _student_news_faculty.data.Where(d => d.bachelors_degree_science == d.bachelors_degree_science) + .Sum(o => o.bachelors_degree_science); + var a2 = _student_news_faculty.data.Where(d => d.bachelors_degree_social == d.bachelors_degree_social) + .Sum(o => o.bachelors_degree_social); + + foreach (var data in std) + { + data.bachelors_degree_total = data.bachelors_degree_science + data.bachelors_degree_social; + data.total1 = a1; + if ( data.bachelors_degree_total != 0) + { + data.sum_percentage_science = (data.bachelors_degree_science*100)/data.bachelors_degree_total; + } + if ( data.bachelors_degree_total != 0) + { + data.sum_percentage_social = (data.bachelors_degree_social*100)/data.bachelors_degree_total; + } + var a3 = _student_news_faculty.data.Where(d => d.bachelors_degree_total == d.bachelors_degree_total) + .Sum(o => o.bachelors_degree_total); + var a4 = _student_news_faculty.data.Where(d => d.sum_percentage_science == d.sum_percentage_science) + .Sum(o => o.sum_percentage_science); + var a5 = _student_news_faculty.data.Where(d => d.sum_percentage_social == d.sum_percentage_social) + .Sum(o => o.sum_percentage_social); + data.total2 = a2; + data.total3 = a3; + data.total4 = (data.total1*100)/data.total3; + data.total5 = (data.total2*100)/data.total3; + } + var student_news_facultys = new List() {_student_news_faculty}; + + Report report = new Report(); + report.Load(_setting.report_path + "student_news_area.frx"); + report.RegisterData(student_news_facultys, "student_news_area"); + 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/student_news_area_major/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetStd3Report([FromRoute] string type, + [FromBody] student_news_area _student_news_faculty) + { + var std = _student_news_faculty.data; + var a1 = _student_news_faculty.data.Where(d => d.bachelors_degree_science == d.bachelors_degree_science) + .Sum(o => o.bachelors_degree_science); + var a2 = _student_news_faculty.data.Where(d => d.bachelors_degree_social == d.bachelors_degree_social) + .Sum(o => o.bachelors_degree_social); + + foreach (var data in std) + { + data.bachelors_degree_total = data.bachelors_degree_science + data.bachelors_degree_social; + data.total1 = a1; + if ( data.bachelors_degree_total != 0) + { + data.sum_percentage_science = (data.bachelors_degree_science*100)/data.bachelors_degree_total; + } + if ( data.bachelors_degree_total != 0) + { + data.sum_percentage_social = (data.bachelors_degree_social*100)/data.bachelors_degree_total; + } + var a3 = _student_news_faculty.data.Where(d => d.bachelors_degree_total == d.bachelors_degree_total) + .Sum(o => o.bachelors_degree_total); + var a4 = _student_news_faculty.data.Where(d => d.sum_percentage_science == d.sum_percentage_science) + .Sum(o => o.sum_percentage_science); + var a5 = _student_news_faculty.data.Where(d => d.sum_percentage_social == d.sum_percentage_social) + .Sum(o => o.sum_percentage_social); + data.total2 = a2; + data.total3 = a3; + data.total4 = (data.total1*100)/data.total3; + data.total5 = (data.total2*100)/data.total3; + } + var student_news_facultys = new List() {_student_news_faculty}; + + Report report = new Report(); + report.Load(_setting.report_path + "student_news_area_major.frx"); + report.RegisterData(student_news_facultys, "student_news_area"); + 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(); + } + } +} \ No newline at end of file diff --git a/Models/budget/repair_cost.cs b/Models/budget/repair_cost.cs new file mode 100644 index 0000000..3eae4ea --- /dev/null +++ b/Models/budget/repair_cost.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace rmutr_report.Models +{ + public class repair_cost + { + public string budget_year { get; set; } + public string plan { get; set; } + public string product { get; set; } + public string agency { get; set; } + public string area { get; set; } + public List data { get; set; } + } + + public class repair_cost_detail + { + public string no { get; set; } + public string type_vehicle_transport { get; set; } + public decimal? quantity { get; set; } + public decimal? repair_rate { get; set; } + public decimal? amount { get; set; } + } +} \ No newline at end of file diff --git a/Models/budget/student_news.cs b/Models/budget/student_news.cs new file mode 100644 index 0000000..dca9311 --- /dev/null +++ b/Models/budget/student_news.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; + +namespace rmutr_report.Models +{ + public class student_news_faculty + { + public string academic_year_name_th { get; set; } + public string curriculum_name_th { get; set; } + public List data { get; set; } + //public string faculty_academy_name_th { get; set; } + } + + public class student_news_faculty_detail + { + public string faculty_academy_name_th { get; set; } + public decimal? bachelors_degree { get; set; } + public decimal? sum_percentage { get; set; } + public decimal? total1 { get; set; } + public decimal? total2 { get; set; } + } +} \ No newline at end of file diff --git a/Models/budget/student_news_area.cs b/Models/budget/student_news_area.cs new file mode 100644 index 0000000..74959e4 --- /dev/null +++ b/Models/budget/student_news_area.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +namespace rmutr_report.Models +{ + public class student_news_area + { + public string academic_year_name_th { get; set; } + public string curriculum_name_th { get; set; } + public List data { get; set; } + } + + public class student_news_area_detail + { + public string area_name_th { get; set; } + public string faculty_academy_name_th { get; set; } + + public decimal? bachelors_degree_science { get; set; } + public decimal? bachelors_degree_social { get; set; } + public decimal? bachelors_degree_total { get; set; } + public decimal? sum_percentage_science { get; set; } + public decimal? sum_percentage_social { get; set; } + public decimal? total1 { get; set; } + public decimal? total2 { get; set; } + public decimal? total3 { get; set; } + public decimal? total4 { get; set; } + public decimal? total5 { get; set; } + } + +} \ No newline at end of file diff --git a/wwwroot/reports/student_news_area.frx b/wwwroot/reports/student_news_area.frx new file mode 100644 index 0000000..29150b3 --- /dev/null +++ b/wwwroot/reports/student_news_area.frx @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wwwroot/reports/student_news_area_major.frx b/wwwroot/reports/student_news_area_major.frx new file mode 100644 index 0000000..76425e8 --- /dev/null +++ b/wwwroot/reports/student_news_area_major.frx @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wwwroot/reports/student_news_faculty.frx b/wwwroot/reports/student_news_faculty.frx new file mode 100644 index 0000000..6add570 --- /dev/null +++ b/wwwroot/reports/student_news_faculty.frx @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +