From ddafe4ff4f9df85f684a7700a5d698735d049e9c Mon Sep 17 00:00:00 2001 From: kamonwan taengsuk Date: Tue, 7 Mar 2023 15:08:17 +0700 Subject: [PATCH] =?UTF-8?q?add=20=E0=B8=87.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CalculationExcessTuitionFee.Controller.cs | 331 ++++++++++++++++++ Models/budget/building_four.cs | 2 +- .../budget/calculation_excess_tuition_fee.cs | 41 +++ 3 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 Controllers/CalculationExcessTuitionFee.Controller.cs create mode 100644 Models/budget/calculation_excess_tuition_fee.cs diff --git a/Controllers/CalculationExcessTuitionFee.Controller.cs b/Controllers/CalculationExcessTuitionFee.Controller.cs new file mode 100644 index 0000000..61e15ab --- /dev/null +++ b/Controllers/CalculationExcessTuitionFee.Controller.cs @@ -0,0 +1,331 @@ +using System; +using System.IO; +using System.Linq; +using ClosedXML.Excel; +using Microsoft.AspNetCore.Mvc; +using rmutr_report.Models; +using Swashbuckle.AspNetCore.Annotations; + +namespace rmutr_report.Controllers +{ + [SwaggerTag("สำหรับรายงาน ง.6")] + public class CalculationExcessTuitionFee : Controller + { + readonly Setting _setting; + + public CalculationExcessTuitionFee(Setting setting) + { + this._setting = setting; + } + [HttpPost, Route("reports/calculation_excess_tuition_fee/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetCalReport([FromRoute] string type, + [FromBody] calculation_excess_tuition_fee _calculation_excess_tuition_fee) + { + { + var workbook = new XLWorkbook(); + var ws = workbook.Worksheets.Add("แบบ ง.6"); + ws.Range("A1:M1").Merge().Value = "แบบฟอร์มการคำนวณค่าสอนเกินภาระงาน"; + ws.Range("A1:M1").Style.Alignment.WrapText = true; + ws.Range("A1:M1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A1:M1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("A1").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("A1").Style.Font.FontSize = 25; + ws.Range("A1:N1").Style.Font.Bold = true; + ws.Cell("N1").Value = "แบบ ง.6"; + ws.Cell("N1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("N1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("N1").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("N1").Style.Font.FontSize = 14; + ws.Cell("N1").Style.Font.Bold = true; + ws.Range("A2:D2").Merge().Value = "หน่วยงาน "+ _calculation_excess_tuition_fee.agency; + ws.Cell("A2").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("A2").Style.Font.FontSize = 14; + ws.Cell("A2").Style.Font.Bold = true; + ws.Cell("A2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("A2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("E2:G2").Merge().Value = "พื้นที่ "+ _calculation_excess_tuition_fee.area; + ws.Cell("E2").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("E2").Style.Font.FontSize = 14; + ws.Cell("E2").Style.Font.Bold = true; + ws.Cell("E2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("E2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("A3:G3").Merge().Value = "ผลผลิต "+ _calculation_excess_tuition_fee.product; + ws.Cell("A3").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("A3").Style.Font.FontSize = 14; + ws.Cell("A3").Style.Font.Bold = true; + ws.Cell("A3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("A3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("A5:A6").Merge().Value = "ลำดับที่"; + ws.Cell("A5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("A5").Style.Font.FontSize = 14; + ws.Cell("A5").Style.Font.Bold = true; + ws.Cell("A5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("A5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("A5:A6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range("B5:C6").Merge().Value = "ชื่อ - สกุล (1)"; + ws.Cell("B5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("B5").Style.Font.FontSize = 14; + ws.Cell("B5").Style.Font.Bold = true; + ws.Cell("B5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("B5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("B5:C6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Range("D5:D6").Merge().Value = "ตำแหน่ง (2)"; + ws.Cell("D5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("D5").Style.Font.FontSize = 14; + ws.Cell("D5").Style.Font.Bold = true; + ws.Cell("D5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("D5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("D5:D6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Range("E5:E6").Merge().Value = "ประเภทบุคลากร (3)"; + ws.Cell("E5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("E5").Style.Font.FontSize = 14; + ws.Cell("E5").Style.Font.Bold = true; + ws.Cell("E5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("E5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("E5:E6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Range("F5:H5").Merge().Value = "จำนวนชั่วโมงที่สอน / 1 ภาคการศึกษา "+_calculation_excess_tuition_fee.academic_semester_name_th1+ + " / "+" "+_calculation_excess_tuition_fee.academic_year_name_th1+")"; + ws.Cell("F5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("F5").Style.Font.FontSize = 14; + ws.Cell("F5").Style.Font.Bold = true; + ws.Cell("F5").Style.Alignment.WrapText = true; + ws.Cell("F5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("F5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("F5:H5").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Cell("F6").Value = "จำนวนชั่วโมงที่สอนตามภาระงานแต่ละประเภท (ตามเกณฑ์) (4)"; + ws.Cell("F6").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("F6").Style.Font.FontSize = 14; + ws.Cell("F6").Style.Font.Bold = true; + ws.Cell("F6").Style.Alignment.WrapText = true; + ws.Cell("F6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("F6").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("F6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Cell("G6").Value = "จำนวนชั่วโมงที่สอนจริงตามภาระงานแต่ละประเภท (5)"; + ws.Cell("G6").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("G6").Style.Font.FontSize = 14; + ws.Cell("G6").Style.Font.Bold = true; + ws.Cell("G6").Style.Alignment.WrapText = true; + ws.Cell("G6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("G6").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("G6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Cell("H6").Value = "ผลต่าง ระหว่าง (5) - (4) = (6)"; + ws.Cell("H6").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("H6").Style.Font.FontSize = 14; + ws.Cell("H6").Style.Font.Bold = true; + ws.Cell("H6").Style.Alignment.WrapText = true; + ws.Cell("H6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("H6").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("H6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Range("I5:I6").Merge().Value = "อัตราค่าสอน(400) x ( 6 ) = (7)"; + ws.Cell("I5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("I5").Style.Font.FontSize = 14; + ws.Cell("I5").Style.Font.Bold = true; + ws.Cell("I5").Style.Alignment.WrapText = true; + ws.Cell("I5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("I5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("I5").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Range("J5:L5").Merge().Value = "จำนวนชั่วโมงที่สอน / 1 ภาคการศึกษา "+_calculation_excess_tuition_fee.academic_semester_name_th2+ + " / "+" "+_calculation_excess_tuition_fee.academic_year_name_th2+")"; + ws.Cell("J5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("J5").Style.Font.FontSize = 14; + ws.Cell("J5").Style.Font.Bold = true; + ws.Cell("J5").Style.Alignment.WrapText = true; + ws.Cell("J5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("J5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("J5:L5").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Cell("J6").Value = "จำนวนชั่วโมงที่สอนตามภาระงานแต่ละประเภท (ตามเกณฑ์) (8)"; + ws.Cell("J6").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("J6").Style.Font.FontSize = 14; + ws.Cell("J6").Style.Font.Bold = true; + ws.Cell("J6").Style.Alignment.WrapText = true; + ws.Cell("J6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("J6").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("J6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Cell("K6").Value = "จำนวนชั่วโมงที่สอนจริงตามภาระงานแต่ละประเภท (9)"; + ws.Cell("K6").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("K6").Style.Font.FontSize = 14; + ws.Cell("K6").Style.Font.Bold = true; + ws.Cell("K6").Style.Alignment.WrapText = true; + ws.Cell("K6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("K6").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("K6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Cell("L6").Value = "ผลต่าง ระหว่าง (9) - (8) = (10)"; + ws.Cell("L6").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("L6").Style.Font.FontSize = 14; + ws.Cell("L6").Style.Font.Bold = true; + ws.Cell("L6").Style.Alignment.WrapText = true; + ws.Cell("L6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("L6").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell("L6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Range("M5:M6").Merge().Value = "อัตราค่าสอน(400) x (10) = (11)"; + ws.Cell("M5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("M5").Style.Font.FontSize = 14; + ws.Cell("M5").Style.Font.Bold = true; + ws.Cell("M5").Style.Alignment.WrapText = true; + ws.Cell("M5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("M5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("M5:M6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Range("N5:N6").Merge().Value = "รวมงบประมาณ (7) + (11) = (12)"; + ws.Cell("N5").Style.Font.FontName = "TH Sarabun New"; + ws.Cell("N5").Style.Font.FontSize = 14; + ws.Cell("N5").Style.Font.Bold = true; + ws.Cell("N5").Style.Alignment.WrapText = true; + ws.Cell("N5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("N5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Range("N5:N6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Column(1).Width = 10; + ws.Column(2).Width = 20; + ws.Column(3).Width = 20; + ws.Column(4).Width = 30; + ws.Column(5).Width = 30; + ws.Column(6).Width = 30; + ws.Column(7).Width = 30; + ws.Column(8).Width = 30; + ws.Column(9).Width = 30; + ws.Column(10).Width = 30; + ws.Column(11).Width = 30; + ws.Column(12).Width = 30; + ws.Column(13).Width = 30; + ws.Column(14).Width = 30; + int rowno = 1; + int row = 7; + //ws.Cell(row, 3).SetDataType(XLDataType.Number); + if (_calculation_excess_tuition_fee != null) + { + foreach (var expenses in _calculation_excess_tuition_fee.data) + { + decimal? sum1 = expenses.teaching_hours_workload1 - + expenses.teaching_hours_workload_pertype1; + decimal? sum2 = (expenses.teaching_hours_workload1 - + expenses.teaching_hours_workload_pertype1) * 400; + decimal? sum3 = (expenses.teaching_hours_workload2 - + expenses.teaching_hours_workload_pertype2); + decimal? sum4 = (expenses.teaching_hours_workload2 - + expenses.teaching_hours_workload_pertype2) * 400; + _calculation_excess_tuition_fee.total_1 = sum1; + var sum5 = _calculation_excess_tuition_fee.data.Where(g => + g.teaching_hours_workload_pertype1 == g.teaching_hours_workload_pertype1).Sum(a => + a.teaching_hours_workload_pertype1); + var sum6 = _calculation_excess_tuition_fee.data + .Where(g => g.teaching_hours_workload1 == g.teaching_hours_workload1).Sum(a => + a.teaching_hours_workload1); + var sum7 = _calculation_excess_tuition_fee.data.Where(g => + g.teaching_hours_workload_pertype2 == g.teaching_hours_workload_pertype2).Sum(a => + a.teaching_hours_workload_pertype2); + var sum8 = _calculation_excess_tuition_fee.data + .Where(g => g.teaching_hours_workload2 == g.teaching_hours_workload2).Sum(a => + a.teaching_hours_workload2); + var sum9 = sum6-sum5; + var sum10 = sum9*400; + var sum11 = sum8-sum7; + var sum12 = sum11*400; + var sum13 = sum10+sum12; + if ( expenses.name !="รวม") + { + ws.Cell(row, 1).Value = rowno; + rowno++; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 3)).Merge().Value = expenses.name; + //ws.Cell(row, 3).Value = null; + ws.Cell(row, 4).Value = expenses.position; + ws.Cell(row, 5).Value = expenses.pertype; + ws.Cell(row, 6).Value = expenses.teaching_hours_workload_pertype1; + ws.Cell(row, 7).Value = expenses.teaching_hours_workload1; + ws.Cell(row, 8).Value = sum1; + ws.Cell(row, 9).Value = sum2; + ws.Cell(row, 10).Value = expenses.teaching_hours_workload_pertype2; + ws.Cell(row, 11).Value = expenses.teaching_hours_workload2; + ws.Cell(row, 12).Value = sum3; + ws.Cell(row, 13).Value = sum4; + ws.Cell(row, 14).Value = sum2 + sum4; + + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Font.FontName = + "TH Sarabun New"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Font.FontSize = 14; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).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.Left; + ws.Range(ws.Cell(row, 4), ws.Cell(row, 14)).Style.Alignment.Horizontal = + XLAlignmentHorizontalValues.Center; + + //ws.Cell(row, 3).Style.NumberFormat.NumberFormatId = 2; + //ws.Cell(row, 3).DataType = XLDataType.Number; + //ws.Cell(row,3).SetDataType(XLDataType.Number); + ws.Range(ws.Cell(row, 6), ws.Cell(row, 14)).Style.NumberFormat.SetFormat("#,#"); + + row++; + } + + if ( expenses.name=="รวม") + { + ws.Range(ws.Cell(row, 2), ws.Cell(row, 3)).Merge().Value = expenses.name; + //ws.Cell(row, 3).Value = null; + ws.Cell(row, 4).Value = null; + ws.Cell(row, 5).Value = null; + ws.Cell(row, 6).Value = sum5; + ws.Cell(row, 7).Value = sum6; + ws.Cell(row, 8).Value = sum9; + ws.Cell(row, 9).Value = sum10; + ws.Cell(row, 10).Value = sum7; + ws.Cell(row, 11).Value = sum8; + ws.Cell(row, 12).Value = sum11; + ws.Cell(row, 13).Value = sum12; + ws.Cell(row, 14).Value = sum13; + + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Font.FontName = + "TH Sarabun New"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Font.FontSize = 14; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 14)).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.Range(ws.Cell(row, 4), ws.Cell(row, 14)).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + + //ws.Cell(row, 3).Style.NumberFormat.NumberFormatId = 2; + //ws.Cell(row, 3).DataType = XLDataType.Number; + //ws.Cell(row,3).SetDataType(XLDataType.Number); + ws.Range(ws.Cell(row, 6), ws.Cell(row, 14)).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", + "calculation_excess_tuition_" + date + ".xlsx"); + } + } + } + } +} \ No newline at end of file diff --git a/Models/budget/building_four.cs b/Models/budget/building_four.cs index eea78f9..c8fc264 100644 --- a/Models/budget/building_four.cs +++ b/Models/budget/building_four.cs @@ -61,7 +61,7 @@ namespace rmutr_report.Models public decimal? sum_year4 { get; set; } public decimal? sum_year5 { get; set; } public decimal? sum_year6 { get; set; } - public string bath { get; set; } + //public string bath { get; set; } } diff --git a/Models/budget/calculation_excess_tuition_fee.cs b/Models/budget/calculation_excess_tuition_fee.cs new file mode 100644 index 0000000..d8d2c45 --- /dev/null +++ b/Models/budget/calculation_excess_tuition_fee.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; + +namespace rmutr_report.Models +{ + public class calculation_excess_tuition_fee + { + public string agency { get; set; } + public string area { get; set; } + public string product { get; set; } + public string academic_year_name_th1 { get; set; } + public string academic_year_name_th2 { get; set; } + public string academic_semester_name_th1 { get; set; } + public string academic_semester_name_th2 { get; set; } + public List data { get; set; } + public decimal? total_1 { get; set; } + public decimal? total_2 { get; set; } + public decimal? total_3 { get; set; } + public decimal? total_4 { get; set; } + public decimal? total_5 { get; set; } + public decimal? total_6 { get; set; } + public decimal? total_7 { get; set; } + public decimal? total_8 { get; set; } + + } + + public class calculation_excess_tuition_fee_detail + { + public string name { get; set; } + public string position { get; set; } + public string pertype { get; set; } + public decimal? teaching_hours_workload_pertype1 { get; set; } + public decimal? teaching_hours_workload1 { get; set; } + // public decimal? difference1 { get; set; } + // public decimal? tuition_rate1 { get; set; } + public decimal? teaching_hours_workload_pertype2 { get; set; } + public decimal? teaching_hours_workload2 { get; set; } + // public decimal? difference2 { get; set; } + // public decimal? tuition_rate2 { get; set; } + //public decimal? total_budget { get; set; } + } +} \ No newline at end of file