This commit is contained in:
202
Controllers/SummaryInvest.Controller.cs
Normal file
202
Controllers/SummaryInvest.Controller.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using FastReport;
|
||||
using FastReport.Export.OoXML;
|
||||
using FastReport.Export.Pdf;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using rmutr_report.Models;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace rmutr_report.Controllers
|
||||
{
|
||||
[SwaggerTag("สำหรับรายงาน invest")]
|
||||
public class SummaryInvest : Controller
|
||||
{
|
||||
readonly Setting _setting;
|
||||
|
||||
public SummaryInvest(Setting setting)
|
||||
{
|
||||
_setting = setting;
|
||||
}
|
||||
|
||||
[SwaggerOperation("จัดทำค่าครุภัณฑ์ Key e-Budgeting")]
|
||||
[HttpPost, Route("reports/summary_invest/{type}")]
|
||||
[ApiExplorerSettings(GroupName = "reports")]
|
||||
public IActionResult GetEBudgetingReport([FromRoute] string type, [FromBody] summary_invest summaryInvest)
|
||||
{
|
||||
var summaryInvests = new List<summary_invest>() { summaryInvest };
|
||||
|
||||
Report report = new Report();
|
||||
report.Load(_setting.report_path + "summary_invest.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" + ".xlsx");
|
||||
break;
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[SwaggerOperation("จัดทำค่าครุภัณฑ์ (ใบเสนอราคา)")]
|
||||
[HttpPost, Route("reports/summary_invest_preview/{type}")]
|
||||
[ApiExplorerSettings(GroupName = "reports")]
|
||||
public IActionResult GetSummaryInvestPreviewReport([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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Report report = new Report();
|
||||
report.Load(_setting.report_path + "summary_invest_preview.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_preview" + ".xlsx");
|
||||
break;
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[SwaggerOperation("จัดสรรค่าครุภัณฑ์")]
|
||||
[HttpPost, Route("reports/summary_invest_approve/{type}")]
|
||||
[ApiExplorerSettings(GroupName = "reports")]
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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");
|
||||
break;
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user