161 lines
6.7 KiB
C#
161 lines
6.7 KiB
C#
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 Swashbuckle.AspNetCore.Annotations;
|
|
|
|
namespace rmutr_report.Controllers
|
|
{
|
|
[SwaggerTag("สำหรับรายงาน ง.4")]
|
|
public class BuildingFour : Controller
|
|
{
|
|
readonly Setting _setting;
|
|
|
|
public BuildingFour(Setting setting)
|
|
{
|
|
this._setting = setting;
|
|
}
|
|
|
|
[HttpPost, Route("reports/building_four/{type}")]
|
|
[ApiExplorerSettings(GroupName = "reports")]
|
|
public IActionResult GetHrReport([FromRoute] string type,
|
|
[FromBody] building_four building_fours)
|
|
{
|
|
foreach (var a in building_fours.building_type)
|
|
{
|
|
if (a.usage_per_target != null)
|
|
{
|
|
var a1 = a.usage_per_target.Where(d => d.used_year == d.used_year)
|
|
.Sum(o => o.used_year);
|
|
building_fours.sum_year1 = a1;
|
|
var a2 = a.usage_per_target.Where(d => d.year1 == d.year1)
|
|
.Sum(o => o.year1);
|
|
building_fours.sum_year2 = a2;
|
|
var a3 = a.usage_per_target.Where(d => d.year2 == d.year2)
|
|
.Sum(o => o.year2);
|
|
building_fours.sum_year3 = a3;
|
|
var a4 = a.usage_per_target.Where(d => d.year3 == d.year3)
|
|
.Sum(o => o.year3);
|
|
building_fours.sum_year4 = a4;
|
|
var a5 = a.usage_per_target.Where(d => d.year4 == d.year4)
|
|
.Sum(o => o.year4);
|
|
building_fours.sum_year5 = a5;
|
|
var a6 = a.usage_per_target.Where(d => d.year5 == d.year5)
|
|
.Sum(o => o.year5);
|
|
building_fours.sum_year6 = a6;
|
|
}
|
|
|
|
}
|
|
|
|
foreach (var bb in building_fours.material_construction_labor)
|
|
{
|
|
if (bb != null)
|
|
{
|
|
// var a = building_fours.material_construction_labor.Where(d => d.amount == d.amount)
|
|
// .Sum(o => o.amount);
|
|
// building_fours.material_amount = a;
|
|
// var b = building_fours.material_construction_labor.Where(d => d.material_unit == d.material_unit)
|
|
// .Sum(o => o.material_unit);
|
|
// building_fours.material_unit = b;
|
|
// var c = building_fours.material_construction_labor.Where(d => d.material_cost == d.material_cost)
|
|
// .Sum(o => o.material_cost);
|
|
// building_fours.material_cost = c;
|
|
// var d = building_fours.material_construction_labor.Where(d => d.labor_unit == d.labor_unit)
|
|
// .Sum(o => o.labor_unit);
|
|
// building_fours.labor_unit = d;
|
|
// var e = building_fours.material_construction_labor.Where(d => d.labor_cost == d.labor_cost)
|
|
// .Sum(o => o.labor_cost);
|
|
// building_fours.labor_cost = e;
|
|
bb.total_amount = bb.material_cost + bb.labor_unit;
|
|
var f = building_fours.material_construction_labor.Where(d => d.total_amount == d.total_amount)
|
|
.Sum(o => o.total_amount);
|
|
building_fours.material_total_amount = f;
|
|
}
|
|
|
|
foreach (var cc in building_fours.budget_limit)
|
|
{
|
|
if (cc != null)
|
|
{
|
|
var a = building_fours.budget_limit.Where(d => d.amount == d.amount)
|
|
.Sum(o => o.amount);
|
|
building_fours.amount = a;
|
|
if (cc.outside_amount != null)
|
|
{
|
|
var b = building_fours.budget_limit.Where(d => d.outside_amount == d.outside_amount)
|
|
.Sum(o => o.outside_amount);
|
|
building_fours.outside_amount = b;
|
|
}
|
|
if (cc.outside_amount == null)
|
|
{
|
|
|
|
building_fours.outside_amount = null;
|
|
}
|
|
|
|
var c = building_fours.budget_limit.Where(d => d.total_amount == d.total_amount)
|
|
.Sum(o => o.total_amount);
|
|
building_fours.total_amount = c;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var _building_fours = new List<building_four>() {building_fours};
|
|
|
|
Report report = new Report();
|
|
report.Load(_setting.report_path + "building_fours.frx");
|
|
report.RegisterData(_building_fours, "building_four");
|
|
report.Prepare();
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
switch (type)
|
|
{
|
|
case "view":
|
|
return File(stream, "application/pdf");
|
|
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;
|
|
case "doc" : case "docx":
|
|
Word2007Export word = new Word2007Export();
|
|
report.Export(word, stream);
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
return File(stream, "appllication/vnd.ms-word");
|
|
break;
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
}
|
|
} |