diff --git a/Controllers/SummaryInvest.Controller.cs b/Controllers/SummaryInvest.Controller.cs index 11c8310..04b355a 100644 --- a/Controllers/SummaryInvest.Controller.cs +++ b/Controllers/SummaryInvest.Controller.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using FastReport; using FastReport.Export.OoXML; @@ -143,6 +144,11 @@ foreach (var summaryInvestYear in summaryInvest.years) { plan.total_budget = plan.unit_price; } + + if (!plan.asset_lists?.Any() ?? true) + { + plan.asset_lists = plan.construct_lists?.ToList() ?? new List(); + } foreach (var assetList in plan.asset_lists) { string formattedSeller = assetList.seller.Replace("
", " "); @@ -214,72 +220,109 @@ foreach (var summaryInvestYear in summaryInvest.years) [SwaggerOperation("จัดสรรค่าครุภัณฑ์")] [HttpPost, Route("reports/summary_invest_approve/{type}")] [ApiExplorerSettings(GroupName = "reports")] - public IActionResult GetSummaryInvestApproveReport([FromRoute] string type, - [FromBody] summary_invest_v2 summaryInvest) + public IActionResult GetSummaryInvestApproveReport([FromRoute] string type, + [FromBody] summary_invest_v2 summaryInvest) +{ + var summaryInvests = new List() { summaryInvest }; + + if (summaryInvest != null) +{ + foreach (var summaryInvestYear in summaryInvest.years) + { + foreach (var plan in summaryInvestYear.plans!) { - var summaryInvests = new List() { summaryInvest }; - if (summaryInvest != null) + if (!plan.asset_lists?.Any() ?? true) { - foreach (var summaryInvestYear in summaryInvest.years) + plan.asset_lists = plan.construct_lists?.ToList() ?? new List(); + } + + var validAssets = plan.asset_lists.Where(x => x.unit_price.HasValue && x.unit_price > 0); + + if (validAssets.Any()) + { + plan.unit_price = validAssets.Sum(x => x.unit_price) ?? 0; + plan.total_budget = validAssets.Sum(x => x.total_budget) ?? 0; + } + else + { + plan.unit_price = 0; + plan.total_budget = 0; + } + + if (summaryInvestYear.plans != null && summaryInvestYear.plans.Any()) + { + var validPlanAssets = summaryInvestYear.plans.SelectMany(p => p.asset_lists) + .Where(x => x.unit_price.HasValue && x.unit_price > 0); + + if (validPlanAssets.Any()) { - foreach (var plan in summaryInvestYear.plans) - { - foreach (var assetList in plan.asset_lists) - { - string formattedSeller = assetList.seller.Replace("
", " "); - string pattern = @"(.*?)<\/a>"; - MatchCollection matches = Regex.Matches(assetList.file, pattern); - - string formattedFile = ""; - if (assetList.is_approve == true) - { - assetList.approve_name = "อนุมัติแล้ว"; - } - - - assetList.seller2 = formattedSeller; - - - foreach (Match match in matches) - { - formattedFile += match.Groups[1].Value + " "; - } - - formattedFile = formattedFile.Trim(); - assetList.file2 = formattedFile; - - //Console.WriteLine("seller output: " + formattedSeller); - //Console.WriteLine("file output: " + formattedFile); - } - } + summaryInvest.unit_price = validPlanAssets.Sum(x => x.unit_price) ?? 0; + summaryInvest.total_budget = validPlanAssets.Sum(x => x.total_budget) ?? 0; + summaryInvestYear.unit_price = validPlanAssets.Sum(x => x.unit_price) ?? 0; + summaryInvestYear.total_budget = validPlanAssets.Sum(x => x.total_budget) ?? 0; + } + else + { + summaryInvest.unit_price = 0; + summaryInvest.total_budget = 0; + summaryInvestYear.unit_price = 0; + summaryInvestYear.total_budget = 0; } } - Report report = new Report(); - report.Load(_setting.report_path + "summary_invest_approve.frx"); - report.RegisterData(summaryInvests, "summary_invest"); - report.Prepare(); - MemoryStream stream = new MemoryStream(); - switch (type) + foreach (var assetList in plan.asset_lists) { - 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.openxmlformats-officedocument.spreadsheetml.sheet", - "summary_invest_approve" + ".xlsx"); - break; - } + string formattedSeller = assetList.seller.Replace("
", " "); + string pattern = @"
(.*?)<\/a>"; + MatchCollection matches = Regex.Matches(assetList.file, pattern); - return Ok(); + string formattedFile = ""; + if (assetList.is_approve == true) + { + assetList.approve_name = "อนุมัติแล้ว"; + } + + assetList.seller2 = formattedSeller; + + foreach (Match match in matches) + { + formattedFile += match.Groups[1].Value + " "; + } + + assetList.file2 = formattedFile.Trim(); + } } } +} + + + Report report = new Report(); + report.Load(_setting.report_path + "summary_invest_approve.frx"); + report.RegisterData(summaryInvests, "summary_invest"); + 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.openxmlformats-officedocument.spreadsheetml.sheet", + "summary_invest_approve.xlsx"); + } + + return Ok(); +} + + } } \ 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 b6ed210..8de6f61 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 f0a2e64..a399777 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/net5.0/rmutr_report.AssemblyInfo.cs b/obj/Debug/net5.0/rmutr_report.AssemblyInfo.cs index 9f70272..f1f75e5 100644 --- a/obj/Debug/net5.0/rmutr_report.AssemblyInfo.cs +++ b/obj/Debug/net5.0/rmutr_report.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a4b9c896dd6684ef18b94d0e0c44fdf79a3468a6")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c5e56063e2ef2d254a6fbb2035095a181b7103c3")] [assembly: System.Reflection.AssemblyProductAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyTitleAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net5.0/rmutr_report.AssemblyInfoInputs.cache b/obj/Debug/net5.0/rmutr_report.AssemblyInfoInputs.cache index 753540e..1f4e36e 100644 --- a/obj/Debug/net5.0/rmutr_report.AssemblyInfoInputs.cache +++ b/obj/Debug/net5.0/rmutr_report.AssemblyInfoInputs.cache @@ -1 +1 @@ -371c200e98a2676e758da94f74c0bc6363cbbc35d65b4f08b471b97250d1118e +a6497678f9a2aa9e7e5abc4d22eb7e42715ef7b2ca97041d4bf70762dfbe0fd9 diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfo.cs b/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfo.cs index 9f70272..f1f75e5 100644 --- a/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfo.cs +++ b/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a4b9c896dd6684ef18b94d0e0c44fdf79a3468a6")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c5e56063e2ef2d254a6fbb2035095a181b7103c3")] [assembly: System.Reflection.AssemblyProductAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyTitleAttribute("rmutr_report")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfoInputs.cache b/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfoInputs.cache index 753540e..1f4e36e 100644 --- a/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfoInputs.cache +++ b/obj/Debug/netcoreapp3.1/rmutr_report.AssemblyInfoInputs.cache @@ -1 +1 @@ -371c200e98a2676e758da94f74c0bc6363cbbc35d65b4f08b471b97250d1118e +a6497678f9a2aa9e7e5abc4d22eb7e42715ef7b2ca97041d4bf70762dfbe0fd9 diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.RazorTargetAssemblyInfo.cache b/obj/Debug/netcoreapp3.1/rmutr_report.RazorTargetAssemblyInfo.cache index ba51b69..d395b35 100644 --- a/obj/Debug/netcoreapp3.1/rmutr_report.RazorTargetAssemblyInfo.cache +++ b/obj/Debug/netcoreapp3.1/rmutr_report.RazorTargetAssemblyInfo.cache @@ -1 +1 @@ -d38f7f6bbd27710e139b96d62b84aa76d97b6926b9acb21af98f13c47c32ed09 +7b9ea42177d03ced8fb55213fec1b4d1c2989a406793ce7eea8fa8ff8087eae0 diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.dll b/obj/Debug/netcoreapp3.1/rmutr_report.dll index b6ed210..8de6f61 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 f0a2e64..a399777 100644 Binary files a/obj/Debug/netcoreapp3.1/rmutr_report.pdb and b/obj/Debug/netcoreapp3.1/rmutr_report.pdb differ diff --git a/obj/rider.project.model.nuget.info b/obj/rider.project.model.nuget.info index a6bca5a..8731d64 100644 --- a/obj/rider.project.model.nuget.info +++ b/obj/rider.project.model.nuget.info @@ -1 +1 @@ -17403867488254078 \ No newline at end of file +17404853499076394 \ No newline at end of file diff --git a/obj/rider.project.restore.info b/obj/rider.project.restore.info index 8731d64..bd04564 100644 --- a/obj/rider.project.restore.info +++ b/obj/rider.project.restore.info @@ -1 +1 @@ -17404853499076394 \ No newline at end of file +17408131531650790 \ No newline at end of file