using System; using System.Collections.Generic; using System.IO; using System.Linq; using ClosedXML; using FastReport; using FastReport.Export.OoXML; using FastReport.Export.Pdf; using Microsoft.AspNetCore.Mvc; using rmutr_report.Models; using rmutr_report.Models.RoThree; using Swashbuckle.AspNetCore.Annotations; namespace rmutr_report.Controllers { [SwaggerTag("สำหรับรายงาน ร.3 คำชี้แจงงบดำเนินงาน")] public class RoThree : Controller { readonly Setting _setting; public RoThree(Setting setting) { this._setting = setting; } [SwaggerOperation("ร.3 คำชี้แจงงบดำเนินงาน")] [HttpPost, Route("reports/operating_budget_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetRoThreeReport([FromRoute] string type, [FromBody] operating_budget_ro_three three) { var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "operating_budget_ro_three.frx"); report.RegisterData(threes, "operating_budget_ro_three"); 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; 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(); } [SwaggerOperation("รายงาน ค่าตอบแทนหัวหน้าภาควิชา")] [HttpPost, Route("reports/compensation_head_department/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetComReport([FromRoute] string type, [FromBody] compensation_head three) { if (three.data != null) { var s = three.data.Sum(f => f.budget_amount); three.total_amount = s; } var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "compensation_head_department.frx"); report.RegisterData(threes, "compensation_head"); 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; 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(); } [SwaggerOperation("รายงาน ค่าตอบแทนหัวหน้าสาขาวิชา")] [HttpPost, Route("reports/compensation_head_major/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetCom2Report([FromRoute] string type, [FromBody] compensation_head three) { if (three.data != null) { var s = three.data.Sum(f => f.budget_amount); three.total_amount = s; } var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "compensation_head_major.frx"); report.RegisterData(threes, "compensation_head"); 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; 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(); } [SwaggerOperation("รายงานค่าสอนพิเศษ")] [HttpPost, Route("reports/teaching_fee_extra_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetTeachExReport([FromRoute] string type, [FromBody] teaching_fee_extra_ro_three three) { var s = three.data.ToList(); int r = 1; foreach (var d in three.data) { d.row_no = r.ToString(); r++; d.total = d.month_1 + d.month_2 + d.month_3 + d.month_4 + d.month_5 + d.month_6 + d.month_7 + d.month_8 + d.month_9 + d.month_10 + d.month_11 + d.month_12; } three.month_1 = three.data.Sum(d => d.month_1); three.month_2 = three.data.Sum(d => d.month_2); three.month_3 = three.data.Sum(d => d.month_3); three.month_4 = three.data.Sum(d => d.month_4); three.month_5 = three.data.Sum(d => d.month_5); three.month_6 = three.data.Sum(d => d.month_6); three.month_7 = three.data.Sum(d => d.month_7); three.month_8 = three.data.Sum(d => d.month_8); three.month_9 = three.data.Sum(d => d.month_9); three.month_10 = three.data.Sum(d => d.month_10); three.month_11 = three.data.Sum(d => d.month_11); three.month_12 = three.data.Sum(d => d.month_12); three.total = s.Sum(d => d.total); var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "teaching_fee_extra.frx"); report.RegisterData(threes, "teaching_fee_extra_ro_three"); 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; 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(); } [SwaggerOperation("รายงานค่าสอน")] [HttpPost, Route("reports/teaching_fee_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetTeachReport([FromRoute] string type, [FromBody] teaching_fee_ro_three three) { // three.table_1_ba_2 = three.data.Sum(d => d.number_of_hours_ba_2); // three.table_1_ma_2 = three.data.Sum(d => d.number_of_hours_ma_2); // three.table_1_teaching_fee_1 = three.data.Sum(d => d.teaching_fee_1); // three.table_1_teaching_fee_2 = three.data.Sum(d => d.teaching_fee_2); // three.table_1_total = three.data.Sum(d => d.total); var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "teaching_fee.frx"); report.RegisterData(threes, "teaching_fee_ro_three"); 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; 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(); } [SwaggerOperation("รายงานค่าสอนเกินภาระงาน")] [HttpPost, Route("reports/teaching_fee_workload/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetTeachWorkloadReport([FromRoute] string type, [FromBody] teaching_fee_ro_three three) { // three.table_1_ba_1 = three.data.Sum(d => d.number_of_hours_ba_1); // three.table_1_ma_1 = three.data.Sum(d => d.number_of_hours_ma_1); // three.table_1_ba_2 = three.data.Sum(d => d.number_of_hours_ba_2); // three.table_1_ma_2 = three.data.Sum(d => d.number_of_hours_ma_2); // three.table_1_ba_3 = three.data.Sum(d => d.number_of_hours_ba_3); // three.table_1_ma_3 = three.data.Sum(d => d.number_of_hours_ma_3); // three.table_1_teaching_fee_1 = three.data.Sum(d => d.teaching_fee_1); // three.table_1_teaching_fee_2 = three.data.Sum(d => d.teaching_fee_2); // three.table_1_total = three.data.Sum(d => d.total); var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "teaching_fee_workload.frx"); report.RegisterData(threes, "teaching_fee_ro_three"); 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; 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(); } // [SwaggerOperation("รายงานค่าวัสดุสำนักงาน")] // [HttpPost, Route("reports/material_office/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial1Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_office.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } // [SwaggerOperation("รายงานวัสดุคอมพิวเตอร์")] // [HttpPost, Route("reports/material_computer/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial2Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_computer.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } [SwaggerOperation("รายงานวัสดุการศึกษา")] [HttpPost, Route("reports/material_education/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetMaterial3Report([FromRoute] string type, [FromBody] material_education three) { var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "material_education.frx"); report.RegisterData(threes, "material_education"); 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; 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(); } // [SwaggerOperation("รายงานวัสดุหนังสือ")] // [HttpPost, Route("reports/material_book/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial4Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_book.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } // [SwaggerOperation("รายงานวัสดุโฆษณาและเผยแพร่")] // [HttpPost, Route("reports/material_advertise/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial5Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_advertise.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } // [SwaggerOperation("รายงานวัสดุงานสิ่งก่อสร้าง")] // [HttpPost, Route("reports/material_construction/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial6Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_construction.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } [SwaggerOperation("รายงานวัสดุเชื้อเพลิงและหล่อลื่น")] [HttpPost, Route("reports/material_fuel_lubricant/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetMaterial7Report([FromRoute] string type, [FromBody] material_fuel_lubricant three) { var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "material_fuel_lubricant.frx"); report.RegisterData(threes, "material_fuel_lubricant"); 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; 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(); } // [SwaggerOperation("รายงานวัสดุไฟฟ้าและวิทยุ")] // [HttpPost, Route("reports/material_electric/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial8Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_electric.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } // [SwaggerOperation("รายงานวัสดุการเกษตร")] // [HttpPost, Route("reports/material_agricultural/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial9Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_agricultural.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } // [SwaggerOperation("รายงานวัสดุงานบ้านงานครัว")] // [HttpPost, Route("reports/material_housework/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial10Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_housework.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } // [SwaggerOperation("รายงานวัสดุวิทยาศาสตร์หรือการแพทย์")] // [HttpPost, Route("reports/material_science_medical/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetMaterial11Report([FromRoute] string type, [FromBody] material_ro_three three) // { // if (three.data != null) // { // var s = three.data.Sum(f => f.material_amount); // // three.total_amount = s; // } // // var threes = new List() { three }; // // Report report = new Report(); // report.Load(_setting.report_path + "material_science_medical.frx"); // report.RegisterData(threes, "material_ro_three"); // 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; // 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(); // } // [SwaggerOperation("รายงานวัสดุกีฬา")] // [HttpPost, Route("reports/material_sport/{type}")] // [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetMaterial12Report([FromRoute] string type, [FromBody] material_ro_three three) { if (three.data != null) { var s = three.data.Sum(f => f.material_amount); three.total_amount = s; } var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "material_sport.frx"); report.RegisterData(threes, "material_ro_three"); 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; 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(); } [SwaggerOperation("รายงานวัสดุ ร3")] [HttpPost, Route("reports/material_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetMaterialRoThreeReport([FromRoute] string type, [FromBody] material_ro_three three) { if (three.data != null) { var s = three.data.Sum(f => f.material_amount); three.total_amount = s; } var threes = new List() { three }; Report report = new Report(); report.Load(_setting.report_path + "material_ro_three.frx"); report.RegisterData(threes, "material_ro_three"); 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; 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(); } [SwaggerOperation("ค่าตอบแทนอื่นๆ")] [HttpPost, Route("reports/other_compensation/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetCompensationReport([FromRoute] string type, [FromBody] parcel_inspection_committee committee) { int no = 1; foreach (var data in committee.data) { data.list = "รายการ " + no; no++; foreach (var detail in data.data_detail) { if (detail != null) { detail.total_amount = (detail.quantity_person * detail.amount); } } data.total_amount = data.data_detail.Sum(f => f.total_amount); var s = committee.data.Sum(d => d.total_amount); committee.total_all_amount = s; } var expenses = new List() { committee }; Report report = new Report(); report.Load(_setting.report_path + "other_compensation.frx"); report.RegisterData(expenses, "parcel_inspection_committee"); 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", "other_compensation" + ".xlsx"); } return Ok(); } [SwaggerOperation("ค่าตอบแทน_ค่าเช่าบ้าน")] [HttpPost, Route("reports/house_rent_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetHouseRentReport([FromRoute] string type, [FromBody] house_rent_ro_three houseRent) { if (houseRent.topic_type == 1) { houseRent.topic_name = "ค่าเช่าบ้านชาวต่างประเทศ"; } if (houseRent.topic_type == 2) { houseRent.topic_name = "ค่าเช่าบ้านครูอาสาสมัคร(ชาวจีน)"; } if (houseRent.topic_type == 3) { houseRent.topic_name = "ค่าเช่าบ้านที่ปรึกษาชาวต่างประเทศ"; } var house = new List() { houseRent }; Report report = new Report(); report.Load(_setting.report_path + "house_rent_ro_three.frx"); report.RegisterData(house, "house_rent_ro_three"); 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", "house_rent_ro_three" + ".xlsx"); } return Ok(); } [SwaggerOperation("ค่าตอบแทนพิเศษรายเดือน_ค่าตอบแทนเงินประจำตำแหน่ง")] [HttpPost, Route("reports/compensation_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetCompensationMoneyReport([FromRoute] string type, [FromBody] compensation_ro_three compensationRoThree) { var compensation = compensationRoThree.data.ToList(); if (compensationRoThree.topic_type == 1) { compensationRoThree.topic_name = "ค่าตอบแทนพิเศษรายเดือน อาจารย์ชาวต่างประเทศ"; } if (compensationRoThree.topic_type == 2) { compensationRoThree.topic_name = "ค่าตอบแทนเงินประจำตำแหน่ง"; } foreach (var detail in compensationRoThree.data) { detail.budget_amount = (detail.salary_rate * 12); } compensationRoThree.total_amount = compensation.Sum(f => f.budget_amount); var compensationRoThrees = new List() { compensationRoThree }; Report report = new Report(); report.Load(_setting.report_path + "compensation_ro_three.frx"); report.RegisterData(compensationRoThrees, "compensation_ro_three"); 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", "compensation_ro_three" + ".xlsx"); } return Ok(); } [SwaggerOperation("เงินสมทบกองทุนประกันสังคม_เงินสมทบกองทุนเงินทดแทน")] [HttpPost, Route("reports/contributions/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetContributionsReport([FromRoute] string type, [FromBody] contributions contributions) { var compensation = contributions.data.ToList(); if (contributions.topic_type == 1) { contributions.topic_name = "เงินสมทบกองทุนประกันสังคม"; // foreach (var detail in contributions.data) // { // detail.amount = (detail.salary * 5) / 100; // detail.per_year = (detail.amount * 12); // } } if (contributions.topic_type == 2) { contributions.topic_name = "เงินสมทบกองทุนเงินทดแทน"; // foreach (var detail in contributions.data) // { // detail.amount = (detail.salary * (decimal?)0.2) / 100; // detail.per_year = (detail.amount * 12); // } } contributions.total_amount = compensation.Sum(f => f.per_year); var _contributions = new List() { contributions }; Report report = new Report(); report.Load(_setting.report_path + "contributions.frx"); report.RegisterData(_contributions, "contributions"); 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", "contributions" + ".xlsx"); } return Ok(); } [SwaggerOperation("ค่าใช้สอย ค่าจ้างเหมาบริการ")] [HttpPost, Route("reports/service_fee_ro_three/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetServiesReport([FromRoute] string type, [FromBody] service_fee_ro_three service) { var serviceFee = new List() { service }; Report report = new Report(); report.Load(_setting.report_path + "service_fee_ro_three.frx"); report.RegisterData(serviceFee, "service_fee_ro_three"); 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", "service_fee_ro_three" + ".xlsx"); } return Ok(); } [SwaggerOperation("2ค่าตอบแทนผู้ปฏิบัติงานให้ราชการ_6 7 8")] [HttpPost, Route("reports/consultant_compensation/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetConsultantReport([FromRoute] string type, [FromBody] consultant_compensation compensation) { var types = compensation.data.ToList(); if (compensation.topic_type == 1) { compensation.topic_name = "ค่าตอบแทนที่ปรึกษา"; } if (compensation.topic_type == 2) { compensation.topic_name = "ค่าตอบแทนเหมาจ่ายจัดหารถประจำตำแหน่ง"; } if (compensation.topic_type == 3) { compensation.topic_name = "ค่าตอบแทนอื่น ๆ"; } if (compensation.topic_type == 4) { compensation.topic_name = "ค่าคณะกรรมการตรวจการจ้าง"; } if (compensation.topic_type == 5) { compensation.topic_name = "ค่าคณะกรรมการตรวจรับพัสดุ"; } if (compensation.topic_type == 6) { compensation.topic_name = "ค่าคณะกรรมการกำหนดราคากลาง"; } foreach (var detail in compensation.data) { detail.total_amount = detail.quantity_day * detail.quantity_person * detail.rate; } compensation.total_amount = types.Sum(d => d.total_amount); var compensations = new List() { compensation }; Report report = new Report(); report.Load(_setting.report_path + "consultant_compensation.frx"); report.RegisterData(compensations, "consultant_compensation"); 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", "consultant_compensation" + ".xlsx"); } return Ok(); } // [SwaggerOperation("ค่าเช่าที่ดิน")] // [HttpPost, Route("reports/land_rent/{type}")] // [ApiExplorerSettings(GroupName = "reports")] // public IActionResult GetRentReport([FromRoute] string type, // [FromBody] land_rent service) // { // service.total_amount = service.data.Sum(d => d.total_amount); // var serviceFee = new List() { service }; // Report report = new Report(); // report.Load(_setting.report_path + "land_rent.frx"); // report.RegisterData(serviceFee, "land_rent"); // 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", // "land_rent" + ".xlsx"); // } // // return Ok(); // } [SwaggerOperation("1 ค่าอาหารว่าง 2 ค่าเบี้ยประชุมคณะกรรมการ")] [HttpPost, Route("reports/calculate_meeting_expenses/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetCalReport([FromRoute] string type, [FromBody] calculate_meeting_expenses calculate) { var c = calculate.data.ToList(); if (calculate.topic_type == 1) { calculate.text1 = "ค่าใช้สอย : ค่าอาหารว่าง และค่าอาหารกลางวันในการประชุม"; calculate.text2 = "ผลการเบิกจ่าย ค่าอาหารว่าง\nและค่าอาหารกลางวันเบิกจ่ายจริง"; calculate.text3 = "อัตราค่าใช้จ่ายค่าอาหารว่าง\nและค่าอาหารกลางวัน"; calculate.text4 = "รวมค่าอาหารว่างและค่าอาหารกลางวัน"; } if (calculate.topic_type == 2) { calculate.text1 = "ค่าตอบแทน : ค่าเบี้ยประชุมคณะกรรมการ"; calculate.text2 = "ผลการเบิกจ่าย ค่าเบี้ยประชุมเบิกจ่ายจริง"; calculate.text3 = "อัตราค่าเบี้ยประชุม"; calculate.text4 = "รวมค่าเบี้ยประชุม"; } //var newList = new List() { }; //var newList2 = newList.SelectMany(f => f.data).Where(d => d.topic_type == 2).Sum(g => g.disbursement_result); int n = 1; foreach (var data in calculate.data) { int r = 1; if (data.topic_type == 1) { data.row_no = null; data.no = n.ToString(); n++; } if (data.topic_type == 2) { data.total = data.expense_rate * data.count_person * data.count_meetings; } } calculate.disbursement_result = c.Where(e => e.topic_type == 1).Sum(d => d.disbursement_result); calculate.expense_rate = c.Where(e => e.topic_type == 1).Sum(d => d.expense_rate); calculate.count_person = c.Where(e => e.topic_type == 1).Sum(d => d.count_person); calculate.count_meetings = c.Where(e => e.topic_type == 1).Sum(d => d.count_meetings); calculate.total = c.Where(e => e.topic_type == 1).Sum(d => d.total); var calculateMeeting = new List() { calculate }; Report report = new Report(); report.Load(_setting.report_path + "calculate_meeting_expenses.frx"); report.RegisterData(calculateMeeting, "calculate_meeting_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.openxmlformats-officedocument.spreadsheetml.sheet", "calculate_meeting_expenses" + ".xlsx"); } return Ok(); } [SwaggerOperation("ค่าตอบแทนผู้ปฏิบัติงานให้ราชการ (ค่าควบคุมงานก่อสร้าง)")] [HttpPost, Route("reports/control_cost_construction_wages/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetConstructionReport([FromRoute] string type, [FromBody] control_cost_construction_wages _expense) { var wages = _expense.data.ToList(); foreach (var detail in _expense.data) { detail.total_amount = (detail.quantity_work*detail.quantity_day * detail.quantity_person * detail.amount); } _expense.total_amount = wages.Sum(f => f.total_amount); var expenses = new List() { _expense }; Report report = new Report(); report.Load(_setting.report_path + "control_cost_construction_wages.frx"); report.RegisterData(expenses, "control_cost_construction_wages"); 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", "control_cost_construction_wages" + ".xlsx"); } return Ok(); } } }