Files
rmutr_report/Controllers/Expenses.Controller.cs
kamonwan taengsuk ca12ecf690
All checks were successful
continuous-integration/drone/push Build is passing
edited font
2023-12-08 14:58:14 +07:00

196 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using ClosedXML.Excel;
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("สำหรับรายงานค่าใช้จ่ายในการดำเนินงาน")]
public class Expenses : Controller
{
readonly Setting _setting;
public Expenses(Setting setting)
{
this._setting = setting;
}
[HttpPost, Route("reports/operating_expenses/{type}")]
[ApiExplorerSettings(GroupName = "reports")]
public IActionResult GetExpensesReport([FromRoute] string type,
[FromBody] operating_expenses _operating_expenses)
{
var _operating_expensess = new List<operating_expenses>() { _operating_expenses };
Report report = new Report();
report.Load(_setting.report_path + "operating_expenses.frx");
report.RegisterData(_operating_expensess, "operating_expenses");
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",
"operating_expenses_"+date + ".xlsx");
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();
}
//{
// var workbook = new XLWorkbook();
// var ws = workbook.Worksheets.Add("ค่าใช้จ่ายดำเนินงาน");
// ws.Range("A1:D1").Merge().Value = "ปีงบประมาณ " + _operating_expenses.budget_year + " แผน " + _operating_expenses.plan;
// ws.Range("A1:D1").Style.Alignment.WrapText = true;
// ws.Range("A1:D1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Range("A1:D1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
// ws.Cell("A1").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("A1").Style.Font.FontSize = 14;
// ws.Range("A1:D1").Style.Font.Bold = true;
// ws.Range("A2:D2").Merge().Value = "ผลผลิต " + _operating_expenses.product+ " หน่วยงาน " + _operating_expenses.agency + " พื้นที่ "+_operating_expenses.area;
// ws.Range("A2:D2").Style.Alignment.WrapText = true;
// ws.Range("A2:D2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Range("A2:D2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
// ws.Cell("A2").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("A2").Style.Font.FontSize = 14;
// ws.Range("A2:D2").Style.Font.Bold = true;
// ws.Cell("D3").Value = "หน่วย : "+ _operating_expenses.total_amount +" บาท";
// ws.Cell("D3").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("D3").Style.Font.FontSize = 14;
// ws.Cell("D3").Style.Font.Bold = true;
// ws.Cell("D3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right;
// ws.Cell("D3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
// //ws.Cell("D3").DataType = XLDataType.Number;
// ws.Cell("D3").Style.NumberFormat.NumberFormatId = 2;
// ws.Cell("A4").Value = "ลำดับที่";
// ws.Cell("A4").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("A4").Style.Font.FontSize = 14;
// ws.Cell("A4").Style.Font.Bold = true;
// ws.Cell("A4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Cell("A4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
// ws.Cell("A4").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("A4").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("A5").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("A5").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("B4").Value = "งบรายจ่าย";
// ws.Cell("B4").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("B4").Style.Font.FontSize = 14;
// ws.Cell("B4").Style.Font.Bold = true;
// ws.Cell("B4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Cell("B4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
// ws.Cell("B4").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("B4").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("B5").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("B5").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("C4").Value = "คำขอตั้ง";
// ws.Cell("C4").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("C4").Style.Font.FontSize = 14;
// ws.Cell("C4").Style.Font.Bold = true;
// ws.Cell("C4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Cell("C4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
// ws.Cell("C4").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("C4").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("C5").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("C5").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("D4").Value = "สรุปคำชี้แจง";
// ws.Cell("D4").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("D4").Style.Font.FontSize = 14;
// ws.Cell("D4").Style.Font.Bold = true;
// ws.Cell("D4").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Cell("D4").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
// ws.Cell("D4").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("D4").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("D5").Style.Border.TopBorder = XLBorderStyleValues.Thin;
// ws.Cell("D5").Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell("A5").Style.Border.TopBorder = XLBorderStyleValues.None;
// ws.Cell("B5").Style.Border.TopBorder = XLBorderStyleValues.None;
// ws.Cell("C5").Style.Border.TopBorder = XLBorderStyleValues.None;
// ws.Cell("D5").Style.Border.TopBorder = XLBorderStyleValues.None;
//
// ws.Column(1).Width = 10;
// ws.Column(2).Width = 40;
// ws.Column(3).Width = 30;
// ws.Column(4).Width = 50;
// int row = 6;
// ws.Cell(row, 3).SetDataType(XLDataType.Number);
// if (_operating_expenses != null)
// {
// ws.Cell("C5").Value = "ปี "+_operating_expenses.request_year;
// ws.Cell("C5").Style.Alignment.WrapText = true;
// ws.Cell("C5").Style.Font.FontName = "TH SarabunPSK";
// ws.Cell("C5").Style.Font.FontSize = 14;
// ws.Cell("C5").Style.Font.Bold = true;
// ws.Cell("C5").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Cell("C5").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
//
// foreach (var expenses in _operating_expenses.data)
// {
// ws.Cell(row, 1).Value = "'"+expenses.no;
// ws.Cell(row, 2).Value = expenses.expenditure_budget;
// ws.Cell(row, 3).Value = expenses.amount;
// ws.Cell(row, 4).Value = expenses.clarification_summary;
//
// ws.Range(ws.Cell(row, 1), ws.Cell(row, 4)).Style.Font.FontName =
// "TH SarabunPSK";
// ws.Range(ws.Cell(row, 1), ws.Cell(row, 4)).Style.Font.FontSize = 14;
// ws.Range(ws.Cell(row, 1), ws.Cell(row, 4)).Style.Alignment.WrapText = true;
// ws.Range(ws.Cell(row, 1), ws.Cell(row, 4)).Style.Alignment.Vertical =
// XLAlignmentVerticalValues.Center;
// ws.Range(ws.Cell(row, 1), ws.Cell(row, 4)).Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
// ws.Range(ws.Cell(row, 1), ws.Cell(row, 4)).Style.Border.RightBorder = XLBorderStyleValues.Thin;
// ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
// ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
// ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right;
// ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
// ws.Range(ws.Cell(5, 1), ws.Cell(5, 4)).Style.Font.Bold = true;
// ws.Range(ws.Cell(6, 1), ws.Cell(6, 4)).Style.Border.BottomBorder = XLBorderStyleValues.Double;
// ws.Range(ws.Cell(6, 1), ws.Cell(6, 4)).Style.Font.Bold = true;
// //ws.Cell(row, 3).Style.NumberFormat.NumberFormatId = 2;
// //ws.Cell(row, 3).DataType = XLDataType.Number;
// //ws.Cell(row,3).SetDataType(XLDataType.Number);
// ws.Cell(row,3).Style.NumberFormat.SetFormat("#,#");
//
// row++;
// }
// }
// using (var stream = new MemoryStream())
// {
// workbook.SaveAs(stream);
// var content = stream.ToArray();
// string date = DateTime.Now.ToString("yyyyMMddHHmmss");
// return File(
// content,
// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
// "operatingexpenses_" + date + ".xlsx");
// }
//}
//}
}
}