เพิ่ม source code แสดงรายงาน กรอบวงเงิน
This commit is contained in:
173
ApiControllers/rep_eva_limit_frame_planControllers.cs
Normal file
173
ApiControllers/rep_eva_limit_frame_planControllers.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TTSW.Controllers;
|
||||
using TTSW.EF;
|
||||
using TTSW.Utils;
|
||||
using TTSW.Constant;
|
||||
using TTSW.Common;
|
||||
using TodoAPI2.Models;
|
||||
using System.Data;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace TodoAPI2.Controllers
|
||||
{
|
||||
//[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("api/rep_eva_limit_frame_plan")]
|
||||
public class rep_eva_limit_frame_planController : BaseController
|
||||
{
|
||||
#region Private Variables
|
||||
private ILogger<rep_eva_limit_frame_planController> _logger;
|
||||
private Irep_eva_limit_frame_planService _repository;
|
||||
private IConfiguration Configuration { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Default constructure for dependency injection
|
||||
/// </summary>
|
||||
/// <param name="repository"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="logger"></param>
|
||||
public rep_eva_limit_frame_planController(ILogger<rep_eva_limit_frame_planController> logger, Irep_eva_limit_frame_planService repository, IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
_repository = repository;
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Blank Item
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <returns>Return a blank item</returns>
|
||||
/// <response code="200">Returns the item</response>
|
||||
/// <response code="500">Error Occurred</response>
|
||||
[HttpGet("GetBlankItem")]
|
||||
[ProducesResponseType(typeof(rep_eva_limit_frame_planWithSelectionViewModel), 200)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public IActionResult GetBlankItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
||||
var result = _repository.GetBlankItem();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception in IActionResult GetBlankItem.", ex);
|
||||
return StatusCode(500, $"{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download Report
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
/// <returns>Return list of items by specifced keyword</returns>
|
||||
/// <response code="200">Returns the item</response>
|
||||
/// <response code="500">Error Occurred</response>
|
||||
[HttpGet("rep_eva_limit_frame_plan_report")]
|
||||
[ProducesResponseType(typeof(FileStreamResult), 200)]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(500)]
|
||||
//[ValidateAntiForgeryToken]
|
||||
public IActionResult rep_eva_limit_frame_plan_report(rep_eva_limit_frame_planReportRequestModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
||||
var httpclient = new WebClient();
|
||||
string mainurl = MyHelper.GetConfig(Configuration, "JasperReportServer:MainURL");
|
||||
string reportsite = MyHelper.GetConfig(Configuration, "JasperReportServer:reportsite");
|
||||
string username = MyHelper.GetConfig(Configuration, "JasperReportServer:username");
|
||||
string password = MyHelper.GetConfig(Configuration, "JasperReportServer:password");
|
||||
|
||||
var plan = (from q in _repository.GetContext().eva_limit_frame_plan
|
||||
where q.id == model.frame_plan_guid
|
||||
select q).FirstOrDefault();
|
||||
var evaplan = (from r in _repository.GetContext().eva_performance_plan
|
||||
where r.id == plan.plan_guid
|
||||
select r).FirstOrDefault();
|
||||
var start_plan = (from s in _repository.GetContext().eva_performance_plan_detail
|
||||
where s.performance_plan_id == plan.plan_guid
|
||||
select s.start_date).Min();
|
||||
var end_plan = (from s in _repository.GetContext().eva_performance_plan_detail
|
||||
where s.performance_plan_id == plan.plan_guid
|
||||
select s.end_date).Max();
|
||||
|
||||
model.executed_date_text = MyHelper.GetDateStringForReport(plan.executed_date);
|
||||
model.salary_adjustment_date_text = MyHelper.GetDateStringForReport(plan.salary_adjustment_date);
|
||||
model.intro_desc = $"ปีงบประมาณ {evaplan.fiscal_year} รอบที่ {evaplan.theTime} ระหว่างวันที่ {MyHelper.GetDateStringForReport(start_plan)} ถึงวันที่ {MyHelper.GetDateStringForReport(end_plan)}";
|
||||
model.detail_desc = $"วงเงินในการพิจารณาเงินเดือน ปี {evaplan.fiscal_year} รอบที่ {evaplan.theTime} ( {MyHelper.GetDateStringForReport(start_plan)} ถึงวันที่ {MyHelper.GetDateStringForReport(end_plan)} )";
|
||||
|
||||
var stream = new MemoryStream();
|
||||
|
||||
Document document = new Document();
|
||||
PdfCopy writer = new PdfCopy(document, stream);
|
||||
document.Open();
|
||||
|
||||
string url = $"{mainurl}{reportsite}/rep_frame_intro.{model.filetype}?{MyHelper.GetParameterForJasperReport(model)}&j_username={username}&j_password={password}";
|
||||
var data = httpclient.DownloadData(url);
|
||||
PdfReader reader = new PdfReader(data);
|
||||
reader.ConsolidateNamedDestinations();
|
||||
for (int i = 1; i <= reader.NumberOfPages; i++)
|
||||
{
|
||||
PdfImportedPage page = writer.GetImportedPage(reader, i);
|
||||
writer.AddPage(page);
|
||||
}
|
||||
reader.Close();
|
||||
|
||||
var all_group = (from t in _repository.GetContext().eva_limit_frame_group
|
||||
where t.frame_plan_guid == model.frame_plan_guid
|
||||
select t);
|
||||
foreach(var u in all_group)
|
||||
{
|
||||
model.group_guid = u.id;
|
||||
string url2 = $"{mainurl}{reportsite}/rep_eva_frame_detail.{model.filetype}?{MyHelper.GetParameterForJasperReport(model)}&j_username={username}&j_password={password}";
|
||||
var data2 = httpclient.DownloadData(url2);
|
||||
PdfReader reader2 = new PdfReader(data2);
|
||||
reader2.ConsolidateNamedDestinations();
|
||||
for (int i = 1; i <= reader2.NumberOfPages; i++)
|
||||
{
|
||||
PdfImportedPage page = writer.GetImportedPage(reader2, i);
|
||||
writer.AddPage(page);
|
||||
}
|
||||
reader2.Close();
|
||||
}
|
||||
|
||||
writer.Close();
|
||||
document.Close();
|
||||
|
||||
var data3 = stream.ToArray();
|
||||
var stream3 = new MemoryStream(data3);
|
||||
|
||||
return File(stream3, model.contentType);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while GetReport.", ex);
|
||||
return StatusCode(500, $"{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user