รายงาน กพ7

This commit is contained in:
Nakorn Rientrakrunchai
2020-09-07 17:39:34 +07:00
parent 717af2bf38
commit 8762bcaead
14 changed files with 526 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
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_kp7")]
public class rep_kp7Controller : BaseController
{
#region Private Variables
private ILogger<rep_kp7Controller> _logger;
private Irep_kp7Service _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_kp7Controller(ILogger<rep_kp7Controller> logger, Irep_kp7Service 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_kp7WithSelectionViewModel), 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_kp7_report")]
[ProducesResponseType(typeof(FileStreamResult), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult rep_kp7_report(rep_kp7ReportRequestModel model)
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
var httpclient = new WebClient();
var stream = new MemoryStream();
Document document = new Document();
PdfCopy writer = new PdfCopy(document, stream);
document.Open();
// Get Main KP7 report from HR
try
{
var data = GetKP7MainReport(model.employee_id);
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();
}
catch (Exception ex)
{
}
// Get Jasper Section report
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");
string url = $"{mainurl}{reportsite}/rep_kp7.{model.filetype}?{MyHelper.GetParameterForJasperReport(model)}&j_username={username}&j_password={password}";
var data2 = httpclient.DownloadData(url);
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}");
}
}
private byte[] GetKP7MainReport(int? employee_id)
{
string kp7_main_api = MyHelper.GetConfig(Configuration, "SiteInformation:hr_svc") + "/hrm/employeeReportKP/" + employee_id.ToString();
var httpclient = new WebClient();
return httpclient.DownloadData(kp7_main_api);
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using TodoAPI2.Models;
namespace TodoAPI2.Models
{
public interface Irep_kp7Service
{
rep_kp7WithSelectionViewModel GetBlankItem();
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class rep_kp7InputModel
{
public Guid? id { get; set; }
public int? employee_id { get; set; }
public string active_mode { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class rep_kp7ReportRequestModel : rep_kp7SearchModel
{
public string filetype { get; set; }
public string contentType { get { return MyHelper.GetContentType(filetype); } }
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class rep_kp7SearchModel
{
public Guid id { get; set; }
public int? employee_id { get; set; }
}
}

View File

@@ -0,0 +1,42 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
using TodoAPI2.Models;
using System.IO;
using System.Web;
using System.Net;
using TTSW.Configure;
using Microsoft.Extensions.Options;
using System.Data;
namespace TodoAPI2.Models
{
public class rep_kp7Service : Irep_kp7Service
{
private IMyDatabase db;
private Iexternal_linkageService ext;
private Iexternal_employeeService emp;
public rep_kp7Service(IMyDatabase mydb, Iexternal_linkageService inext, Iexternal_employeeService inemp)
{
db = mydb;
ext = inext;
emp = inemp;
}
public rep_kp7WithSelectionViewModel GetBlankItem()
{
var i = new rep_kp7WithSelectionViewModel();
i.item_employee_id = (from x in emp.GetAllEmployee() select x).ToList();
return i;
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TTSW.EF;
using TTSW.Utils;
using TTSW.Constant;
using TTSW.Common;
namespace TodoAPI2.Models
{
public class rep_kp7ViewModel : BaseViewModel2<Guid>
{
public int? employee_id { get; set; }
public string employee_id_external_linkage_external_name { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TodoAPI2.Models
{
public class rep_kp7WithSelectionViewModel: rep_kp7ViewModel
{
public List<external_employeeViewModel> item_employee_id { get; set; }
}
}

View File

@@ -291,6 +291,8 @@ namespace Test01
services.AddScoped<Irep_eva_xService, rep_eva_xService>();
services.AddScoped<Irep_kp7Service, rep_kp7Service>();
#endregion
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TodoAPI2.Models;
using STAFF_API.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using TodoAPI2.Controllers;
namespace TodoAPI2.Controllers
{
public class rep_kp7ViewController : Controller
{
private ILogger<rep_kp7Controller> _logger;
private Irep_kp7Service _repository;
private IConfiguration Configuration { get; set; }
/// <summary>
/// Default constructure for dependency injection
/// </summary>
/// <param name="repository"></param>
/// <param name="configuration"></param>
/// <param name="logger"></param>
public rep_kp7ViewController(ILogger<rep_kp7Controller> logger, Irep_kp7Service repository, IConfiguration configuration)
{
_logger = logger;
_repository = repository;
Configuration = configuration;
}
public IActionResult rep_kp7_report()
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); // Or UnauthorizedView
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}

View File

@@ -0,0 +1,56 @@
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
@{
ViewData["Title"] = "rep_kp7";
}
<div class="row page-title">
<div class="col-md-5">
<div class="page-title">
@Configuration["SiteInformation:modulename"]
</div>
</div>
<div class="col-md-7">
<ol class="breadcrumb" style="">
<li class="breadcrumb-item "><a href="javascript:window_open_from_root('@Configuration["SiteInformation:mainsite"]');">หน้าแรก</a></li>
<li class="breadcrumb-item "><a href="javascript:window_open_from_root('@Configuration["SiteInformation:modulesite"]');">@Configuration["SiteInformation:modulename"]</a></li>
<li class="breadcrumb-item active">รายงาน rep_kp7</li>
</ol>
</div>
</div>
<section class="wrapper">
<div class="title"><div class="line"></div>รายงาน rep_kp7</div>
<div class="tools">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="form-group col-md-3">
<label id='lab_s_rep_kp7_employee_id' for='s_rep_kp7_employee_id'>ชื่อ - สกุล</label>
<select class="form-control" id="s_rep_kp7_employee_id" iLabel="ชื่อ - สกุล" iRequire="true" iGroup="s_rep_kp7" title='ชื่อ - สกุล' placeholder='ชื่อ - สกุล'></select>
</div>
</div>
</div>
<div class="col-md-12">
<button class="btn btn-info" onclick="javascript:rep_kp7_DoSearch('pdf');">แสดงรายงาน</button>
<button class="btn btn-info" onclick="javascript:rep_kp7_DoSearch('xlsx');">ดาวน์โหลดเป็น Excel</button>
</div>
</div>
</div>
</section>
<br/>
<iframe id="report_result" style="display:none; height:500px; width:100%;"></iframe>
@section FooterPlaceHolder{
<script src="~/js/rep_kp7/rep_kp7_report.js"></script>
<script>
$(document).ready(function () {
rep_kp7_InitialForm();
SetupValidationRemark("s_rep_kp7");
$("#s_rep_kp7_employee_id").select2();
});
</script>
}

View File

@@ -3418,6 +3418,34 @@
<response code="200">Returns the item</response>
<response code="500">Error Occurred</response>
</member>
<member name="M:TodoAPI2.Controllers.rep_kp7Controller.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.rep_kp7Controller},TodoAPI2.Models.Irep_kp7Service,Microsoft.Extensions.Configuration.IConfiguration)">
<summary>
Default constructure for dependency injection
</summary>
<param name="repository"></param>
<param name="configuration"></param>
<param name="logger"></param>
</member>
<member name="M:TodoAPI2.Controllers.rep_kp7Controller.GetBlankItem">
<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>
</member>
<member name="M:TodoAPI2.Controllers.rep_kp7Controller.rep_kp7_report(TodoAPI2.Models.rep_kp7ReportRequestModel)">
<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>
</member>
<member name="M:TodoAPI2.Controllers.rep_leave_summaryController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.rep_leave_summaryController},TodoAPI2.Models.Irep_leave_summaryService,Microsoft.Extensions.Configuration.IConfiguration)">
<summary>
Default constructure for dependency injection
@@ -3900,6 +3928,14 @@
<param name="logger"></param>
<param name="inemp"></param>
</member>
<member name="M:TodoAPI2.Controllers.rep_kp7ViewController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.rep_kp7Controller},TodoAPI2.Models.Irep_kp7Service,Microsoft.Extensions.Configuration.IConfiguration)">
<summary>
Default constructure for dependency injection
</summary>
<param name="repository"></param>
<param name="configuration"></param>
<param name="logger"></param>
</member>
<member name="M:TodoAPI2.Controllers.rep_leave_summaryViewController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.rep_leave_summaryController},TodoAPI2.Models.Iexternal_employeeService,TodoAPI2.Models.Irep_leave_summaryService,Microsoft.Extensions.Configuration.IConfiguration)">
<summary>
Default constructure for dependency injection

View File

@@ -0,0 +1,58 @@
var rep_kp7_API = "/api/rep_kp7/";
//================= Search Customizaiton =========================================
function rep_kp7_GetSearchParameter(fileType) {
var rep_kp7SearchObject = new Object();
rep_kp7SearchObject.employee_id = $("#s_rep_kp7_employee_id").val();
rep_kp7SearchObject.fileType = fileType;
console.log(rep_kp7SearchObject);
return rep_kp7SearchObject;
}
function rep_kp7_FeedDataToSearchForm(data) {
DropDownClearFormAndFeedWithData($("#s_rep_kp7_employee_id"), data, "id", "fullname", "item_employee_id", data.employee_id);
}
//================= Form Data Customizaiton =========================================
function rep_kp7_InitialForm(s) {
var successFunc = function (result) {
rep_kp7_FeedDataToSearchForm(result);
endLoad();
};
startLoad();
AjaxGetRequest(apisite + rep_kp7_API + "GetBlankItem", successFunc, AlertDanger);
}
//================= Data Table =========================================
var s_rep_kp7_customValidation = function (group) {
return "";
};
function rep_kp7_DoSearch(fileType) {
if (!ValidateForm('s_rep_kp7', s_rep_kp7_customValidation)) {
return;
}
var p = $.param(rep_kp7_GetSearchParameter(fileType));
var report_url = apisite + "/api/rep_kp7/rep_kp7_report?" + p;
if (fileType === "pdf") {
$("#report_result").attr("src", report_url);
$("#report_result").show();
//window.open(report_url);
} else {
$("#report_result").hide();
window.open(report_url);
}
}