diff --git a/Controllers/Budget.Controller.cs b/Controllers/Budget.Controller.cs index 6b5fd0d..5795524 100644 --- a/Controllers/Budget.Controller.cs +++ b/Controllers/Budget.Controller.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using FastReport; @@ -241,7 +242,90 @@ namespace rmutr_report.Controllers return Ok(); } +[HttpPost, Route("reports/external_research/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetExReport([FromRoute] string type, [FromBody] external_research external) + { + var s1 = external.data.Sum(g => g.budget_1); + var s2 = external.data.Sum(g => g.budget_2); + var s3 = external.data.Sum(g => g.budget_3); + var s4 = external.data.Sum(g => g.budget_4); + var s5 = external.data.Sum(g => g.budget_5); + var s6 = external.data.Sum(g => g.budget_received); + var s7 = external.data.Sum(g => g.total_budget); + var s8 = external.data.Sum(g => g.expenses); + if (s1!=null&&s2!=null&&s3!=null&&s4!=null&&s5!=null) + { + external.project_amount = s6; + external.total_1 = s6; + //external.total_8 = s7; + external.total_2 = s8; + external.total_3 = s1; + external.total_4 = s2; + external.total_5 = s3; + external.total_6 = s4; + external.total_7 = s5; + } + + CultureInfo culture = new CultureInfo("th-TH"); + + if (external.data_date != null) + { + external.data_day = external.data_date.Value.ToString("dd", culture); + external.data_month = external.data_date.Value.ToString("MMMM", culture); + external.data_year = external.data_date.Value.ToString("yyyy", culture); + } + if (external.data_date == null) + { + external.data_day = ""; + external.data_month = ""; + external.data_year = ""; + } + foreach (var data in external.data) + { + data.total_budget = data.budget_1+data.budget_2+data.budget_3+data.budget_4+data.budget_5; + var ss = external.data.Sum(y => y.total_budget); + external.institutional_subsidy_fee = ss; + external.total_8 = external.institutional_subsidy_fee; + + + } + + + + var _budget_summary_report = new List() { external }; + + Report report = new Report(); + report.Load(_setting.report_path + "external_research.frx"); + report.RegisterData(_budget_summary_report, "external_research"); + 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"); + break; + case "xls":case "xlsx": + Excel2007Export excel = new Excel2007Export(); + report.Export(excel, stream); + stream.Seek(0, SeekOrigin.Begin); + //return File(stream, "application/vnd.ms-excel"); + string date = DateTime.Now.ToString("yyyyMMddHHmmss"); + return File( + stream, + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + date + ".xlsx"); + break; + + } + + return Ok(); + } } } \ No newline at end of file diff --git a/Models/budget/external_research.cs b/Models/budget/external_research.cs new file mode 100644 index 0000000..6f2b0cd --- /dev/null +++ b/Models/budget/external_research.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; + +namespace rmutr_report.Models +{ + public class external_research + { + public string budget_year { get; set; } + public string date_range { get; set; } + public string agency_name_th { get; set; } + public decimal? budget_amount { get; set; } + public decimal? budget_1 { get; set; } + public decimal? budget_2 { get; set; } + public decimal? budget_3 { get; set; } + public decimal? budget_4 { get; set; } + public decimal? budget_5 { get; set; } + public List data { get; set; } + public decimal? project_amount{ get; set; } + public decimal? institutional_subsidy_fee { 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 string save_data_name { get; set; } + public string position { get; set; } + public DateTime? data_date { get; set; } + public string data_day { get; set; } + public string data_month { get; set; } + public string data_year { get; set; } + public string phone_no { get; set; } + + } + + public class external_research_details + { + public string agency_name_th { get; set; } + public string project_name_th { get; set; } + public string contract_period { get; set; } + public decimal? budget_received { get; set; } + public decimal? expenses { get; set; } + public decimal? budget_1 { get; set; } + public decimal? budget_2 { get; set; } + public decimal? budget_3 { get; set; } + public decimal? budget_4 { get; set; } + public decimal? budget_5 { get; set; } + public decimal? total_budget { get; set; } + + + } +} \ No newline at end of file diff --git a/bin/Debug/net5.0/rmutr-report.dll b/bin/Debug/net5.0/rmutr-report.dll index d202c52..17d9386 100644 Binary files a/bin/Debug/net5.0/rmutr-report.dll and b/bin/Debug/net5.0/rmutr-report.dll differ diff --git a/bin/Debug/net5.0/rmutr-report.pdb b/bin/Debug/net5.0/rmutr-report.pdb index e9d6326..5eec90c 100644 Binary files a/bin/Debug/net5.0/rmutr-report.pdb and b/bin/Debug/net5.0/rmutr-report.pdb differ diff --git a/obj/Debug/net5.0/ref/rmutr-report.dll b/obj/Debug/net5.0/ref/rmutr-report.dll index ed9181c..159d3c0 100644 Binary files a/obj/Debug/net5.0/ref/rmutr-report.dll and b/obj/Debug/net5.0/ref/rmutr-report.dll differ diff --git a/obj/Debug/net5.0/refint/rmutr-report.dll b/obj/Debug/net5.0/refint/rmutr-report.dll index ed9181c..159d3c0 100644 Binary files a/obj/Debug/net5.0/refint/rmutr-report.dll and b/obj/Debug/net5.0/refint/rmutr-report.dll differ diff --git a/obj/Debug/net5.0/rmutr-report.csproj.CoreCompileInputs.cache b/obj/Debug/net5.0/rmutr-report.csproj.CoreCompileInputs.cache index 6b9ddf0..2885292 100644 --- a/obj/Debug/net5.0/rmutr-report.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net5.0/rmutr-report.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -fd3e7cbd0b298300a8f9594e98013d068c4edd53 +0aa423cbcd6170f5d81cd7d9d88fda71ff7fb01c diff --git a/obj/Debug/net5.0/rmutr-report.dll b/obj/Debug/net5.0/rmutr-report.dll index d202c52..17d9386 100644 Binary files a/obj/Debug/net5.0/rmutr-report.dll and b/obj/Debug/net5.0/rmutr-report.dll differ diff --git a/obj/Debug/net5.0/rmutr-report.pdb b/obj/Debug/net5.0/rmutr-report.pdb index e9d6326..5eec90c 100644 Binary files a/obj/Debug/net5.0/rmutr-report.pdb and b/obj/Debug/net5.0/rmutr-report.pdb differ diff --git a/wwwroot/reports/external_research.frx b/wwwroot/reports/external_research.frx new file mode 100644 index 0000000..f9a35de --- /dev/null +++ b/wwwroot/reports/external_research.frx @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +