diff --git a/Controllers/Personnel.Controller.cs b/Controllers/Personnel.Controller.cs index 412cd38..b4c6dfb 100644 --- a/Controllers/Personnel.Controller.cs +++ b/Controllers/Personnel.Controller.cs @@ -6156,5 +6156,261 @@ namespace rmutr_report.Controllers "personnel_expense_budget" + date + ".xlsx"); } } + + [HttpPost, Route("reports/national_budget/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetNationalBudgetReport([FromRoute] string type, + [FromBody] national_budget personnel) + { + var workbook = new XLWorkbook(); + var ws = workbook.Worksheets.Add("บุคลากร"); + ws.Cell("A1").Value = "งบประมาณแผ่นดิน ปีงบประมาณ พ.ศ. " + personnel.academic_year_name_th; + ws.Cell("A1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell("A1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A1").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("A1").Style.Font.FontSize = 16; + ws.Cell("A1").Style.Font.Bold = true; + + ws.Cell("A2").Value = "มหาวิทยาลัยเทคโนโลยีราชมงคลรัตนโกสินทร์"; + ws.Cell("A2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell("A2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A2").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("A2").Style.Font.FontSize = 16; + ws.Cell("A2").Style.Font.Bold = true; + ws.Cell("F2").Value = "แผนบุคลากร"; + ws.Cell("F2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("F2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("F2").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("F2").Style.Font.FontSize = 16; + ws.Cell("F2").Style.Font.Bold = true; + + //ws.Cell("K12").Style.NumberFormat.Format = "#,##0.0000"; + + ws.Column(1).Width = 30; + ws.Column(2).Width = 10; + ws.Column(3).Width = 10; + ws.Column(4).Width = 10; + ws.Column(5).Width = 10; + ws.Column(6).Width = 10; + ws.Column(7).Width = 10; + + int row = 6; + //int no = 1; + if (personnel != null) + { + ws.Range("A3:A5").Merge().Value = "งบรายจ่าย"; + ws.Range("A3:A5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A3:A5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("A3:A5").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("A3:A5").Style.Font.SetBold().Font.FontSize = 14; + ws.Range("A3:A5").Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Range("A3:A5").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range("B3:F3").Merge().Value = "งบประมาณ "+personnel.academic_year_name_th+" (เบื้องต้น)"; + ws.Range("B3:F3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("B3:F3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("B3:F3").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("B3:F3").Style.Font.SetBold().Font.FontSize = 14; + ws.Range("B3:F3").Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Range("B3:F3").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell("B4").Value = " ปี "+personnel.agency_name_th.Substring(2,2) + " วิทย์"; + ws.Cell("B4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("B4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("B4").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("B4").Style.Font.SetBold().Font.FontSize = 14; + ws.Cell("B4").Style.Alignment.WrapText = true; + ws.Cell("B4").Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Cell("B4").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell("C4").Value = " ปี "+personnel.agency_name_th.Substring(2,2) + " สังคม"; + ws.Cell("C4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("C4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("C4").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("C4").Style.Font.SetBold().Font.FontSize = 14; + ws.Cell("C4").Style.Alignment.WrapText = true; + ws.Cell("C4").Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Cell("C4").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell("D4").Value = " ปี "+personnel.agency_name_th.Substring(2,2) + " บริการวิชาการ"; + ws.Cell("D4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("D4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("D4").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("D4").Style.Font.SetBold().Font.FontSize = 14; + ws.Cell("D4").Style.Alignment.WrapText = true; + ws.Cell("D4").Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Cell("D4").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell("E4").Value = " ปี "+personnel.agency_name_th.Substring(2,2) + " ทำนุบำรุง"; + ws.Cell("E4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("E4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("E4").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("E4").Style.Font.SetBold().Font.FontSize = 14; + ws.Cell("E4").Style.Alignment.WrapText = true; + ws.Cell("E4").Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Cell("F4").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell("F4").Value = "งบประมาณปี " + personnel.agency_name_th.Substring(2, 2); + ws.Cell("F4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("F4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("F4").Style.Font.FontName = "TH SarabunPSK"; + ws.Cell("F4").Style.Font.SetBold().Font.FontSize = 14; + ws.Cell("F4").Style.Alignment.WrapText = true; + ws.Cell("F4").Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Range("B4:F4").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range(ws.Cell(4, 2), ws.Cell(4, 6)).Style.Alignment.WrapText = true; + ws.Cell(5, 2).Value = personnel.science; + ws.Cell(5, 3).Value = personnel.society; + ws.Cell(5, 4).Value = personnel.academic_service; + ws.Cell(5, 5).Value = personnel.nourish; + ws.Cell(5, 6).Value = personnel.budget; + ws.Cell(5, 2).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(5, 3).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(5, 4).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(5, 5).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(5, 6).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range(ws.Cell(5, 2), ws.Cell(5, 6)).Style.Fill.BackgroundColor = XLColor.FromArgb(255,153,204); + ws.Range(ws.Cell(5, 2), ws.Cell(5, 6)).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Range(ws.Cell(5, 2), ws.Cell(5, 6)).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(5, 2), ws.Cell(5, 6)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(5, 2), ws.Cell(5, 6)).Style.Font.FontSize = 14; + ws.Range(ws.Cell(5, 2), ws.Cell(5, 6)).Style.Font.FontColor = XLColor.Blue; + ws.Range(ws.Cell(5, 2), ws.Cell(5, 6)).Style.NumberFormat.SetFormat("#,#"); + + foreach (var detail in personnel.national_budget_details) + { + if (detail.topic_type == 1) + { + ws.Cell(row, 1).Value = detail.topic; + ws.Cell(row, 2).Value = detail.science; + ws.Cell(row, 3).Value = detail.society; + ws.Cell(row, 4).Value = detail.academic_service; + ws.Cell(row, 5).Value = detail.nourish; + ws.Cell(row, 6).Value = detail.budget; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.SetBold().Font.FontSize = 14; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 6)).Style.NumberFormat.SetFormat("#,#"); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Fill.BackgroundColor = XLColor.FromArgb(204,153,255); + ws.Cell(row, 1).Style.Border.OutsideBorder = 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.Cell(row, 6).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + row++; + } + + if (detail.topic_type == 2) + { + ws.Cell(row, 1).Value = detail.topic; + ws.Cell(row, 2).Value = detail.science; + ws.Cell(row, 3).Value = detail.society; + ws.Cell(row, 4).Value = detail.academic_service; + ws.Cell(row, 5).Value = detail.nourish; + ws.Cell(row, 6).Value = detail.budget; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.SetBold().Font.FontSize = 14; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 6)).Style.NumberFormat.SetFormat("#,#"); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 1).Style.Border.OutsideBorder = 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.Cell(row, 6).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Fill.BackgroundColor = XLColor.FromArgb(153,204,255); + row++; + } + if (detail.topic_type == 3) + { + ws.Cell(row, 1).Value = detail.topic; + ws.Cell(row, 2).Value = detail.science; + ws.Cell(row, 3).Value = detail.society; + ws.Cell(row, 4).Value = detail.academic_service; + ws.Cell(row, 5).Value = detail.nourish; + ws.Cell(row, 6).Value = detail.budget; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.SetBold().Font.FontSize = 14; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 6)).Style.NumberFormat.SetFormat("#,#"); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 1).Style.Border.OutsideBorder = 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.Cell(row, 6).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + row++; + } + if (detail.topic_type == 4) + { + ws.Cell(row, 1).Value = detail.topic; + ws.Cell(row, 2).Value = detail.science; + ws.Cell(row, 3).Value = detail.society; + ws.Cell(row, 4).Value = detail.academic_service; + ws.Cell(row, 5).Value = detail.nourish; + ws.Cell(row, 6).Value = detail.budget; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Font.SetBold().Font.FontSize = 14; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 6)).Style.NumberFormat.SetFormat("#,#"); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 6)).Style.Fill.BackgroundColor = XLColor.FromArgb(255,204,153); + ws.Cell(row, 1).Style.Border.OutsideBorder = 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.Cell(row, 6).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + row++; + } + } + } + + using (var stream1 = new MemoryStream()) + { + workbook.SaveAs(stream1); + var content = stream1.ToArray(); + string date = DateTime.Now.ToString("yyyyMMddHHmmss"); + return File( + content, + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "national_budget_" + date + ".xlsx"); + } + } } } \ No newline at end of file diff --git a/Models/Personnel/national_budget.cs b/Models/Personnel/national_budget.cs new file mode 100644 index 0000000..6e746ce --- /dev/null +++ b/Models/Personnel/national_budget.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace rmutr_report.Models.Personnel +{ + public class national_budget + { + [Key] public Guid? national_budget_uid { get; set; } + + public string academic_year_name_th { get; set; } + public string agency_name_th { get; set; } + public Guid? log_report_uid_government { get; set; } + public Guid? log_report_uid_university { get; set; } + public Guid? log_report_uid_government_employee { get; set; } + public Guid? log_report_uid_permanent { get; set; } + public Guid? log_report_uid_temporary { get; set; } + public decimal? science { get; set; } + public decimal? society { get; set; } + public decimal? academic_service { get; set; } + public decimal? nourish { get; set; } + public decimal? budget { get; set; } + public DateTime? version { get; set; } + public List national_budget_details { get; set; } + + } + + public class t_national_budget_detail + { + [Key] public Guid? national_budget_detail_uid { get; set; } + public Guid? national_budget_uid { get; set; } + public string topic { get; set; } + public decimal? science { get; set; } + public decimal? society { get; set; } + public decimal? academic_service { get; set; } + public decimal? nourish { get; set; } + public decimal? budget { get; set; } + public int? row { get; set; } + + public int? topic_type { get; set; } + } +} \ No newline at end of file diff --git a/bin/Debug/netcoreapp3.1/rmutr_report.dll b/bin/Debug/netcoreapp3.1/rmutr_report.dll index 80b0211..9aefadb 100644 Binary files a/bin/Debug/netcoreapp3.1/rmutr_report.dll and b/bin/Debug/netcoreapp3.1/rmutr_report.dll differ diff --git a/bin/Debug/netcoreapp3.1/rmutr_report.pdb b/bin/Debug/netcoreapp3.1/rmutr_report.pdb index 7b407c0..7fe2722 100644 Binary files a/bin/Debug/netcoreapp3.1/rmutr_report.pdb and b/bin/Debug/netcoreapp3.1/rmutr_report.pdb differ diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.csproj.CoreCompileInputs.cache b/obj/Debug/netcoreapp3.1/rmutr_report.csproj.CoreCompileInputs.cache index 881cf83..381e992 100644 --- a/obj/Debug/netcoreapp3.1/rmutr_report.csproj.CoreCompileInputs.cache +++ b/obj/Debug/netcoreapp3.1/rmutr_report.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -e0851d273baf2b54360a75945243ff2ff8920ed8 +7e2739011ea2dfb9109e8abe681c5a2c80dbe65d diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.dll b/obj/Debug/netcoreapp3.1/rmutr_report.dll index 80b0211..9aefadb 100644 Binary files a/obj/Debug/netcoreapp3.1/rmutr_report.dll and b/obj/Debug/netcoreapp3.1/rmutr_report.dll differ diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.pdb b/obj/Debug/netcoreapp3.1/rmutr_report.pdb index 7b407c0..7fe2722 100644 Binary files a/obj/Debug/netcoreapp3.1/rmutr_report.pdb and b/obj/Debug/netcoreapp3.1/rmutr_report.pdb differ