299 lines
12 KiB
C#
299 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using FastReport;
|
|
using FastReport.Export.Csv;
|
|
using FastReport.Export.Mht;
|
|
using FastReport.Export.OoXML;
|
|
using FastReport.Export.Pdf;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using rmutr_report.Models;
|
|
using rmutr_report.Models.Hr;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
|
|
namespace rmutr_report.Controllers
|
|
{
|
|
[SwaggerTag("สำหรับรายงาน_budget")]
|
|
public class Budget: Controller
|
|
{
|
|
readonly Setting _setting;
|
|
|
|
public Budget(Setting setting)
|
|
{
|
|
this._setting = setting;
|
|
}
|
|
|
|
[HttpPost, Route("reports/budget_report/{type}")]
|
|
[ApiExplorerSettings(GroupName = "reports")]
|
|
public IActionResult GetSum1Report([FromRoute] string type, [FromBody] List<budget_report> budget_reports)
|
|
{
|
|
foreach (var x in budget_reports)
|
|
{
|
|
int sum1 = budget_reports.Sum(g => int.Parse(g.salaya));
|
|
x.sum1 = sum1;
|
|
int sum2 = budget_reports.Sum(g => int.Parse(g.bophitphimuk));
|
|
x.sum2 = sum2;
|
|
int sum3 = budget_reports.Sum(g => int.Parse(g.pohchang));
|
|
x.sum3 = sum3;
|
|
int sum4 = budget_reports.Sum(g => int.Parse(g.klai_kangwon));
|
|
x.sum4 = sum4;
|
|
int sum5 = budget_reports.Sum(g => int.Parse(g.total));
|
|
x.sum5 = sum5;
|
|
|
|
}
|
|
Report report = new Report();
|
|
report.Load(_setting.report_path + "budget_report.frx");
|
|
report.RegisterData(budget_reports, "budget_report");
|
|
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":
|
|
Excel2007Export excel = new Excel2007Export();
|
|
report.Export(excel, stream);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return File(stream, "application/vnd.ms-excel");
|
|
break;
|
|
case "mht":
|
|
MHTExport mht = new MHTExport();
|
|
report.Export(mht, stream);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return File(stream, "multipart/related");
|
|
break;
|
|
case "csv":
|
|
CSVExport csv = new CSVExport();
|
|
report.Export(csv, stream);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return File(stream, "text/csv");
|
|
break;
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
[HttpPost, Route("reports/budget_summary_report/{type}")]
|
|
[ApiExplorerSettings(GroupName = "reports")]
|
|
public IActionResult GetSumReport([FromRoute] string type, [FromBody] budget_summary_report budget_summary_reports)
|
|
{
|
|
var _budget_summary_report = new List<budget_summary_report>() { budget_summary_reports };
|
|
var s1 = budget_summary_reports.summary.Sum(d => d.budget_1);
|
|
var s2 = budget_summary_reports.summary.Sum(d => d.budget_2);
|
|
var s3 = budget_summary_reports.summary.Sum(d => d.budget_3);
|
|
var s4 = budget_summary_reports.summary.Sum(d => d.budget_4);
|
|
var s5 = budget_summary_reports.summary.Sum(d => d.budget_5);
|
|
if (s1 != null || s2 != null || s3 != null || s4 != null || s5 != null)
|
|
{
|
|
var s6 = s1 + s2 + s3 + s4 + s5;
|
|
budget_summary_reports.total_budget = s6;
|
|
|
|
}
|
|
|
|
if (s1!=null || s2!=null||s3 !=null|| s4!= null|| s5!=null)
|
|
{
|
|
budget_summary_reports.budget_1 = s1;
|
|
budget_summary_reports.budget_2 = s2;
|
|
budget_summary_reports.budget_3 = s3;
|
|
budget_summary_reports.budget_4 = s4;
|
|
budget_summary_reports.budget_5 = s5;
|
|
//budget_summary_reports.total_budget = s6;
|
|
}
|
|
if (s1==null)
|
|
{
|
|
budget_summary_reports.budget_1 = null;
|
|
|
|
}
|
|
if (s2==null)
|
|
{
|
|
budget_summary_reports.budget_2 = null;
|
|
|
|
}
|
|
if (s3==null)
|
|
{
|
|
budget_summary_reports.budget_3 = null;
|
|
|
|
}
|
|
if (s4==null)
|
|
{
|
|
budget_summary_reports.budget_4 = null;
|
|
|
|
}
|
|
if (s5==null)
|
|
{
|
|
budget_summary_reports.budget_5 = null;
|
|
|
|
}
|
|
foreach (var budget in budget_summary_reports.summary)
|
|
{
|
|
if (budget.budget_1 != null || budget.budget_2 != null || budget.budget_3 != null ||
|
|
budget.budget_4 != null || budget.budget_5 != null)
|
|
{
|
|
|
|
|
|
budget.total_budget = budget.budget_1 + budget.budget_2 + budget.budget_3 + budget.budget_4 +
|
|
budget.budget_5;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
if (budget_summary_reports.durable_articles_1 != null)
|
|
{
|
|
|
|
foreach (var bDetail in budget_summary_reports.durable_articles_1)
|
|
{
|
|
if (bDetail.color == 1)
|
|
{
|
|
budget_summary_reports.list = bDetail.list;
|
|
budget_summary_reports.total_amount = bDetail.total_amount;
|
|
}
|
|
|
|
// if (bDetail.color == 2)
|
|
// {
|
|
// budget_summary_reports.list = bDetail.list;
|
|
// budget_summary_reports.total_amount = bDetail.total_amount;
|
|
// }
|
|
// foreach (var bDetail2 in bDetail.durable_articles_2)
|
|
// {
|
|
// if (bDetail2.color == 3)
|
|
// {
|
|
// budget_summary_reports.list = bDetail2.list;
|
|
// budget_summary_reports.total_amount = bDetail2.total_amount;
|
|
// }
|
|
// foreach (var bDetail3 in bDetail2.durable_articles_3)
|
|
// {
|
|
// if (bDetail3.color == 4)
|
|
// {
|
|
// budget_summary_reports.list = bDetail3.list;
|
|
// budget_summary_reports.total_amount = bDetail3.total_amount;
|
|
// }
|
|
// foreach (var bDetail4 in bDetail3.durable_articles_4)
|
|
// {
|
|
// if (bDetail4.color == 5)
|
|
// {
|
|
// budget_summary_reports.list = bDetail4.list;
|
|
// budget_summary_reports.total_amount = bDetail4.total_amount;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
|
|
if (budget_summary_reports.building_1 != null)
|
|
{
|
|
foreach (var bDetail in budget_summary_reports.building_1)
|
|
{
|
|
if (bDetail.color == 1)
|
|
{
|
|
budget_summary_reports.list1 = bDetail.list;
|
|
budget_summary_reports.total_amount1 = bDetail.total_amount;
|
|
}
|
|
|
|
// if (bDetail.color == 2)
|
|
// {
|
|
// budget_summary_reports.list1 = bDetail.list;
|
|
// budget_summary_reports.total_amount1 = bDetail.total_amount;
|
|
// }
|
|
}
|
|
}
|
|
Report report = new Report();
|
|
report.Load(_setting.report_path + "budget_summary_report.frx");
|
|
report.RegisterData(_budget_summary_report, "budget_summary_report");
|
|
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.ms-excel");
|
|
break;
|
|
case "mht":
|
|
MHTExport mht = new MHTExport();
|
|
report.Export(mht, stream);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return File(stream, "multipart/related");
|
|
break;
|
|
case "csv":
|
|
CSVExport csv = new CSVExport();
|
|
report.Export(csv, stream);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return File(stream, "text/csv");
|
|
break;
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
[HttpPost, Route("reports/summary_project_budget_proposals/{type}")]
|
|
[ApiExplorerSettings(GroupName = "reports")]
|
|
public IActionResult GetSumPReport([FromRoute] string type, [FromBody] summary_project_budget_proposals eleven)
|
|
{
|
|
int a = 1;
|
|
foreach (var d1 in eleven.data_1)
|
|
{
|
|
foreach (var d2 in d1.data_2)
|
|
{
|
|
foreach (var d3 in d2.data_3)
|
|
{
|
|
foreach (var d4 in d3.data_4)
|
|
{
|
|
d4.row_no = a;
|
|
a++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var ele = new List<summary_project_budget_proposals>() { eleven };
|
|
|
|
Report report = new Report();
|
|
report.Load(_setting.report_path + "summary_project_budget_proposals.frx");
|
|
report.RegisterData(ele, "summary_project_budget_proposals");
|
|
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.ms-excel");
|
|
string date = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
return File(
|
|
stream,
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
date + ".xlsx");
|
|
break;
|
|
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
}
|
|
} |