Bug Fixed
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kamonwan taengsuk
2025-03-01 14:12:56 +07:00
parent c5e56063e2
commit fc127f2ab6
12 changed files with 108 additions and 65 deletions

View File

@@ -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<summary_invest_list_v2>();
}
foreach (var assetList in plan.asset_lists)
{
string formattedSeller = assetList.seller.Replace("<br>", " ");
@@ -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<summary_invest_v2>() { summaryInvest };
if (summaryInvest != null)
{
foreach (var summaryInvestYear in summaryInvest.years)
{
foreach (var plan in summaryInvestYear.plans!)
{
var summaryInvests = new List<summary_invest_v2>() { 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<summary_invest_list_v2>();
}
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("<br>", " ");
string pattern = @"<a href=.*?>(.*?)<\/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("<br>", " ");
string pattern = @"<a href=.*?>(.*?)<\/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();
}
}
}