เตรียมรายงาน แบบข้อตกลงการปฏิบัติงาน

This commit is contained in:
Nakorn Rientrakrunchai
2021-02-02 04:41:08 +07:00
parent ad42205726
commit 95277cedea
7 changed files with 272 additions and 44 deletions

View File

@@ -88,7 +88,97 @@ namespace TodoAPI2.Controllers
}
}
/// <summary>
/// <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_p01_report")]
[ProducesResponseType(typeof(FileStreamResult), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult rep_eva_p01_report(rep_eva_p01ReportRequestModel model)
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
var stream = new MemoryStream();
Document document = new Document();
PdfCopy writer = new PdfCopy(document, stream);
document.Open();
var data = GetReportP01(model);
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();
writer.Close();
document.Close();
var data2 = stream.ToArray();
var stream2 = new MemoryStream(data2);
return File(stream2, model.contentType);
}
catch (Exception ex)
{
_logger.LogCritical($"Exception while GetReport.", ex);
return StatusCode(500, $"{ex.Message}");
}
}
private byte[] GetReportP01(rep_eva_p01ReportRequestModel model)
{
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 p1 = GetParameter(model.detail_id);
var stream = new MemoryStream();
Document document = new Document();
PdfCopy writer = new PdfCopy(document, stream);
document.Open();
string url = $"{mainurl}{reportsite}/rep_eva_p01.{model.filetype}?{MyHelper.GetParameterForJasperReport(p1)}&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();
writer.Close();
document.Close();
var data2 = stream.ToArray();
return data2;
}
/// <summary>
/// Download Report
/// </summary>
/// <remarks>

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_eva_p01ReportRequestModel : rep_eva_p01SearchModel
{
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_eva_p01SearchModel
{
public Guid id { get; set; }
public int detail_id { get; set; }
}
}

View File

@@ -179,7 +179,7 @@
@section FooterPlaceHolder{
<script src="~/js/eva_create_evaluation/eva_create_evaluation_d.js?version=@MyHelper.GetDummyText()"></script>
<script src="~/js/eva_create_evaluation_detail/eva_create_evaluation_detail_summary.js?version=@MyHelper.GetDummyText()"></script>
<script src="~/js/rep_eva_x/rep_eva_x_report.js"></script>
<script src="~/js/rep_eva_x/rep_eva_x_report.js?version=@MyHelper.GetDummyText()"></script>
<script>
$(document).ready(function () {
var id = getUrlParameter("id");

View File

@@ -209,6 +209,30 @@
</div>
</div>
<div class="modal fade" id="report_xModel" style="z-index:1500" tabindex="-1" role="dialog" aria-labelledby="report_xModelLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="report_xModelLabel">พิมพ์แบบข้อตกลงการประเมิน</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<iframe id="report_result" style="display:none; height:500px; width:100%;"></iframe>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">ปิด</button>
</div>
</div>
</div>
</div>
<section class="wrapper">
<div class="title col-md-12"><div class="line"></div>การประเมินผลการปฏิบัติงานของพนักงานเนติบัณฑิตยสภา</div>
@@ -374,6 +398,7 @@
<div class="row">
<div class="form-group col-md-12">
<button class="btn btn-info" onclick="javascript:rep_eva_p01_DoSearch('pdf');">พิมพ์แบบข้อตกลง</button>
<button type="button" class="btn btn-submit status_self" onclick="javascript:eva_create_evaluation_detail_status_PutUpdate('next0')">ส่งข้อตกลงการประเมิน</button>
<button type="button" class="btn btn-submit status_self" onclick="javascript:alert('บันทึกเรียบร้อย')">บันทึก</button>
<button type="button" class="btn btn-danger" onclick="javascript:window_close()"><i class="fa fa-repeat"></i> กลับ</button>
@@ -388,56 +413,57 @@
<script src="~/js/eva_evaluation_behavior/eva_evaluation_behavior.js?version=@MyHelper.GetDummyText()"></script>
<script src="~/js/eva_create_evaluation_detail_status/eva_create_evaluation_detail_status_d.js?version=@MyHelper.GetDummyText()"></script>
<script src="~/js/eva_idp_plan_owner/eva_idp_plan_owner.js?version=@MyHelper.GetDummyText()"></script>
<script src="~/js/rep_eva_x/rep_eva_p01_report.js?version=@MyHelper.GetDummyText()"></script>
<script>
var status_self = "";
var status_self = "";
$(document).ready(function () {
var id = getUrlParameter("id");
if (id) {
eva_create_evaluation_detail_agreement_SetEditForm(id);
eva_evaluation_achievement_InitiateDataTable(id);
eva_evaluation_achievement_InitialForm();
eva_evaluation_behavior_InitiateDataTable(id);
eva_evaluation_behavior_InitialForm();
eva_create_evaluation_detail_status_SetEditForm(id);
eva_idp_plan_owner_InitiateDataTable(id);
eva_idp_plan_owner_InitialForm();
} else {
eva_create_evaluation_detail_agreement_SetCreateForm();
$(document).ready(function () {
var id = getUrlParameter("id");
if (id) {
eva_create_evaluation_detail_agreement_SetEditForm(id);
eva_evaluation_achievement_InitiateDataTable(id);
eva_evaluation_achievement_InitialForm();
eva_evaluation_behavior_InitiateDataTable(id);
eva_evaluation_behavior_InitialForm();
eva_create_evaluation_detail_status_SetEditForm(id);
eva_idp_plan_owner_InitiateDataTable(id);
eva_idp_plan_owner_InitialForm();
} else {
eva_create_evaluation_detail_agreement_SetCreateForm();
}
SetupValidationRemark("eva_create_evaluation_detail_agreement");
SetupValidationRemark("eva_evaluation_achievement");
SetupValidationRemark("eva_evaluation_behavior");
SetupValidationRemark("eva_idp_plan_owner");
setTimeout(CheckPermission, 1000);
});
function CheckPermission() {
if (status_self === "Y") {
$(".status_self").hide();
$("#status").text("คุณส่งแบบประเมินไปแล้ว");
}
}
SetupValidationRemark("eva_create_evaluation_detail_agreement");
SetupValidationRemark("eva_evaluation_achievement");
SetupValidationRemark("eva_evaluation_behavior");
SetupValidationRemark("eva_idp_plan_owner");
setTimeout(CheckPermission, 1000);
});
function CheckPermission(){
if(status_self === "Y"){
$(".status_self").hide();
$("#status").text("คุณส่งแบบประเมินไปแล้ว");
}
}
function OnWeightChanged(c){
if($(c).val() < 0){
$(c).val(0)
function OnWeightChanged(c) {
if ($(c).val() < 0) {
$(c).val(0)
}
if ($(c).val() > 100) {
$(c).val(100)
}
}
if($(c).val() > 100){
$(c).val(100)
}
}
function CheckWeightBeforeSubmitStatus(){
if(parseInt($("#sum_a").text()) !== 100){
return false;
}else{
return true;
function CheckWeightBeforeSubmitStatus() {
if (parseInt($("#sum_a").text()) !== 100) {
return false;
} else {
return true;
}
}
}
</script>
}

View File

@@ -3759,6 +3759,16 @@
<response code="200">Returns the item</response>
<response code="500">Error Occurred</response>
</member>
<member name="M:TodoAPI2.Controllers.rep_eva_xController.rep_eva_p01_report(TodoAPI2.Models.rep_eva_p01ReportRequestModel)">
<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_eva_xController.rep_eva_x_report(TodoAPI2.Models.rep_eva_xReportRequestModel)">
<summary>
Download Report

View File

@@ -0,0 +1,58 @@
var rep_eva_x_API = "/api/rep_eva_x/";
//================= Search Customizaiton =========================================
function rep_eva_x_GetSearchParameter(fileType) {
var rep_eva_xSearchObject = new Object();
rep_eva_xSearchObject.detail_id = getUrlParameter("id");
rep_eva_xSearchObject.fileType = fileType;
console.log(rep_eva_xSearchObject);
return rep_eva_xSearchObject;
}
function rep_eva_x_FeedDataToSearchForm(data) {
$("#s_rep_eva_x_detail_id").val(data.detail_id);
}
//================= Form Data Customizaiton =========================================
function rep_eva_x_InitialForm(s) {
var successFunc = function (result) {
rep_eva_x_FeedDataToSearchForm(result);
endLoad();
};
startLoad();
AjaxGetRequest(apisite + rep_eva_x_API + "GetBlankItem", successFunc, AlertDanger);
}
//================= Data Table =========================================
var s_rep_eva_x_customValidation = function (group) {
return "";
};
function rep_eva_p01_DoSearch(fileType) {
var p = $.param(rep_eva_x_GetSearchParameter(fileType));
//console.log(p);
var report_url = apisite + "/api/rep_eva_x/rep_eva_p01_report?" + p;
if (fileType === "pdf") {
$("#report_result").attr("src", "");
$("#report_result").attr("src", report_url);
$("#report_result").show();
//window.open(report_url);
$("#report_xModel").modal("show");
} else {
$("#report_result").hide();
window.open(report_url);
}
}