Merge branch 'feature/pond_20210714_001_savemessage_report' into develop

This commit is contained in:
Pairat Sangprasert
2021-07-16 16:33:45 +07:00
7 changed files with 213 additions and 11 deletions

View File

@@ -15,6 +15,7 @@ using TodoAPI2.Models;
using System.Data; using System.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using System.IO; using System.IO;
using System.Net;
namespace TodoAPI2.Controllers namespace TodoAPI2.Controllers
{ {
@@ -315,6 +316,47 @@ namespace TodoAPI2.Controllers
return BadRequest(ModelState); return BadRequest(ModelState);
} }
/// <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_savemessage")]
[ProducesResponseType(typeof(FileStreamResult), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
//[ValidateAntiForgeryToken]
public IActionResult rep_eva_savemessage(rep_eva_savemessageReportRequestModel model)
{
try
{
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
//var httpclient = MyHelper.getHttpClient(Configuration);
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");
_repository.setModelFor_rep_eva_savemessageReport(model);
string url = $"{mainurl}{reportsite}/rep_eva_savemessage.{model.filetype}?{MyHelper.GetParameterForJasperReport(model)}&j_username={username}&j_password={password}";
var data = httpclient.DownloadData(url);
var stream = new MemoryStream(data);
return File(stream, model.contentType);
}
catch (Exception ex)
{
_logger.LogCritical($"Exception while GetReport.", ex);
return StatusCode(500, $"Exception while GetReport. {ex.Message}");
}
}
} }
} }

View File

@@ -20,8 +20,8 @@ namespace TodoAPI2.Models
string UpdateMultiple(List<eva_adjust_postponement_quotaInputModel> model); string UpdateMultiple(List<eva_adjust_postponement_quotaInputModel> model);
eva_adjust_postponement_quotaWithSelectionViewModel GetWithSelection(int id); eva_adjust_postponement_quotaWithSelectionViewModel GetWithSelection(int id);
eva_adjust_postponement_quotaWithSelectionViewModel GetBlankItem(); eva_adjust_postponement_quotaWithSelectionViewModel GetBlankItem();
rep_eva_savemessageReportRequestModel setModelFor_rep_eva_savemessageReport(rep_eva_savemessageReportRequestModel model);
DataContext GetContext();
} }
} }

View File

@@ -59,6 +59,11 @@ namespace TodoAPI2.Models
#region Public Functions #region Public Functions
#region Query Functions #region Query Functions
public DataContext GetContext()
{
return _repository.Context;
}
public eva_adjust_postponement_quotaViewModel Get(int id) public eva_adjust_postponement_quotaViewModel Get(int id)
{ {
var entity = _repository.Get(id); var entity = _repository.Get(id);
@@ -506,6 +511,59 @@ namespace TodoAPI2.Models
return; return;
} }
public rep_eva_savemessageReportRequestModel setModelFor_rep_eva_savemessageReport(rep_eva_savemessageReportRequestModel model)
{
model.theDate = MyHelper.GetDateFromString(model.theDate_text);
model.theDate_text = MyHelper.GetDateStringForReport(model.theDate);
model.decimal_limit_quota = Convert.ToDecimal(model.limit_quota);
var postponement_data = (from postponement in _repository.Context.eva_adjust_postponement
join create_evaluation in _repository.Context.eva_create_evaluation on postponement.create_evaluation_id equals create_evaluation.id
where postponement.id == model.quota_id
select new
{
create_evaluation.performance_plan_id,
postponement.fiscal_year,
postponement.theDate,
postponement.limit_frame,
postponement.limit_frame_quota
}).FirstOrDefault();
if(postponement_data != null)
{
var plan_id = postponement_data.performance_plan_id;
if(plan_id == null)
{
plan_id = (from plan_in_db in _repository.Context.eva_performance_plan
where plan_in_db.fiscal_year == postponement_data.fiscal_year
&& plan_in_db.theTime == plan_in_db.theTime
select plan_in_db.id).FirstOrDefault();
}
if (plan_id.HasValue)
{
var plan = (from eva_p_p in _repository.Context.eva_performance_plan
where eva_p_p.id == plan_id
select eva_p_p).FirstOrDefault();
var start_plan = (from s in _repository.Context.eva_performance_plan_detail
where s.performance_plan_id == postponement_data.performance_plan_id
select s.start_date).Min();
var end_plan = (from s in _repository.Context.eva_performance_plan_detail
where s.performance_plan_id == postponement_data.performance_plan_id
select s.end_date).Max();
model.theTime = plan.theTime;
model.min_plan_start_date = MyHelper.GetDateStringForReport(start_plan);
model.max_plan_end_date = MyHelper.GetDateStringForReport(end_plan);
}
}
return model;
}
#endregion #endregion
#region Match Item #region Match Item

View File

@@ -0,0 +1,32 @@
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_savemessageReportRequestModel
{
public int? quota_id { get; set; }
public int? fiscal_year { get; set; }
public int? theRound { get; set; }
public decimal? limit_frame_quota { get; set; }
public string limit_quota { get; set; }
public decimal? decimal_limit_quota { get; set; }
public string command_no { get; set; }
public string theDate_text { get; set; }
public DateTime? theDate { get; set; }
public int? theTime { get; set; }
public string min_plan_start_date { get; set; }
public string max_plan_end_date { get; set; }
public string filetype { get; set; }
public string contentType { get { return MyHelper.GetContentType(filetype); } }
}
}

View File

@@ -5,6 +5,29 @@
Layout = "_LayoutDirect"; Layout = "_LayoutDirect";
} }
<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>
<div class="row page-title"> <div class="row page-title">
<div class="col-md-5"> <div class="col-md-5">
@@ -103,6 +126,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<button class="btn btn-info" type="button" onclick="javascript:CalculateRemainQuota(true)">คำนวณค่าครองชีพใหม่ ตามเกณฑ์เงินเดือน 13,285</button> <button class="btn btn-info" type="button" onclick="javascript:CalculateRemainQuota(true)">คำนวณค่าครองชีพใหม่ ตามเกณฑ์เงินเดือน 13,285</button>
<button type="button" class="btn btn-submit" onclick="javascript:rep_eva_savemessage_DoSearch('pdf')">พิมพ์ บันทึกข้อความ</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -886,6 +886,16 @@
<response code="400">If the model is invalid</response> <response code="400">If the model is invalid</response>
<response code="500">Error Occurred</response> <response code="500">Error Occurred</response>
</member> </member>
<member name="M:TodoAPI2.Controllers.eva_adjust_postponement_quotaController.rep_eva_savemessage(TodoAPI2.Models.rep_eva_savemessageReportRequestModel)">
<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.eva_create_evaluationController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.eva_create_evaluationController},TodoAPI2.Models.Ieva_create_evaluationService,Microsoft.Extensions.Configuration.IConfiguration)"> <member name="M:TodoAPI2.Controllers.eva_create_evaluationController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.eva_create_evaluationController},TodoAPI2.Models.Ieva_create_evaluationService,Microsoft.Extensions.Configuration.IConfiguration)">
<summary> <summary>
Default constructure for dependency injection Default constructure for dependency injection

View File

@@ -10,7 +10,7 @@ function eva_adjust_postponement_quota_FeedDataToForm(data) {
$("#eva_adjust_postponement_quota_theRound").val(data.theRound); $("#eva_adjust_postponement_quota_theRound").val(data.theRound);
$("#eva_adjust_postponement_quota_limit_quota").val(data.limit_quota); $("#eva_adjust_postponement_quota_limit_quota").val(data.limit_quota);
//$("#eva_adjust_postponement_quota_limit_quota").maskMoney('mask', data.limit_quota); //$("#eva_adjust_postponement_quota_limit_quota").maskMoney('mask', data.limit_quota);
// $("#eva_adjust_postponement_quota_limit_frame_quota").val(data.limit_frame_quota); // $("#eva_adjust_postponement_quota_limit_frame_quota").val(data.limit_frame_quota);
$("#eva_adjust_postponement_quota_limit_frame_quota").maskMoney('mask', data.limit_frame_quota); $("#eva_adjust_postponement_quota_limit_frame_quota").maskMoney('mask', data.limit_frame_quota);
$("#eva_adjust_postponement_quota_command_no").val(data.command_no); $("#eva_adjust_postponement_quota_command_no").val(data.command_no);
@@ -25,11 +25,11 @@ function eva_adjust_postponement_quota_GetFromForm() {
eva_adjust_postponement_quotaObject.fiscal_year = $("#eva_adjust_postponement_quota_fiscal_year").val(); eva_adjust_postponement_quotaObject.fiscal_year = $("#eva_adjust_postponement_quota_fiscal_year").val();
eva_adjust_postponement_quotaObject.theDate = getDate($("#eva_adjust_postponement_quota_theDate").val()); eva_adjust_postponement_quotaObject.theDate = getDate($("#eva_adjust_postponement_quota_theDate").val());
eva_adjust_postponement_quotaObject.theRound = $("#eva_adjust_postponement_quota_theRound").val(); eva_adjust_postponement_quotaObject.theRound = $("#eva_adjust_postponement_quota_theRound").val();
eva_adjust_postponement_quotaObject.limit_quota = $("#eva_adjust_postponement_quota_limit_quota").val().replace(/[,-]/g,''); eva_adjust_postponement_quotaObject.limit_quota = $("#eva_adjust_postponement_quota_limit_quota").val().replace(/[,-]/g, '');
eva_adjust_postponement_quotaObject.limit_frame_quota = $("#eva_adjust_postponement_quota_limit_frame_quota").val().replace(/[,-]/g,''); eva_adjust_postponement_quotaObject.limit_frame_quota = $("#eva_adjust_postponement_quota_limit_frame_quota").val().replace(/[,-]/g, '');
eva_adjust_postponement_quotaObject.command_no = $("#eva_adjust_postponement_quota_command_no").val(); eva_adjust_postponement_quotaObject.command_no = $("#eva_adjust_postponement_quota_command_no").val();
eva_adjust_postponement_quotaObject.managed_by = $("#eva_adjust_postponement_quota_managed_by").val(); eva_adjust_postponement_quotaObject.managed_by = $("#eva_adjust_postponement_quota_managed_by").val();
eva_adjust_postponement_quotaObject.limit = $("#eva_adjust_postponement_quota_limit").val().replace(/[,-]/g,''); eva_adjust_postponement_quotaObject.limit = $("#eva_adjust_postponement_quota_limit").val().replace(/[,-]/g, '');
var eva_adjust_postponement_detail_quota_02 = []; var eva_adjust_postponement_detail_quota_02 = [];
$('#eva_adjust_postponement_detail_quota_02Body tr').each(function () { $('#eva_adjust_postponement_detail_quota_02Body tr').each(function () {
@@ -136,20 +136,20 @@ function Oneva_adjust_postponement_quota_limit_frame_quotaChange() {
//$("#eva_adjust_postponement_quota_limit_quota").val(Math.ceil(limit_quota/10)*10); //$("#eva_adjust_postponement_quota_limit_quota").val(Math.ceil(limit_quota/10)*10);
//console.log(limit); //console.log(limit);
$("#eva_adjust_postponement_quota_limit_quota").maskMoney('mask', Math.ceil(limit_quota/10)*10); $("#eva_adjust_postponement_quota_limit_quota").maskMoney('mask', Math.ceil(limit_quota / 10) * 10);
CalculateRemainQuota(false); CalculateRemainQuota(false);
} }
function CalculateRemainQuota(m) { function CalculateRemainQuota(m) {
//console.log("xx"); //console.log("xx");
var sum_receive_quota = 0; var sum_receive_quota = 0;
var limit_quota = parseFloat($("#eva_adjust_postponement_quota_limit_quota").val().replace(/[,-]/g,'')); var limit_quota = parseFloat($("#eva_adjust_postponement_quota_limit_quota").val().replace(/[,-]/g, ''));
var eva_adjust_postponement_detail_quota_02 = []; var eva_adjust_postponement_detail_quota_02 = [];
$('#eva_adjust_postponement_detail_quota_02Body tr').each(function () { $('#eva_adjust_postponement_detail_quota_02Body tr').each(function () {
var i = $(this).find("#rowCount").text(); var i = $(this).find("#rowCount").text();
if (i) { if (i) {
var current_salary = parseFloat($("#eva_adjust_postponement_detail_quota_02_sarary_" + i).text().replace(/[,-]/g,'')); var current_salary = parseFloat($("#eva_adjust_postponement_detail_quota_02_sarary_" + i).text().replace(/[,-]/g, ''));
var new_sarary = parseFloat($("#eva_adjust_postponement_detail_quota_02_new_sarary_" + i).text()); var new_sarary = parseFloat($("#eva_adjust_postponement_detail_quota_02_new_sarary_" + i).text());
var receive_quota = parseFloat($("#eva_adjust_postponement_detail_quota_02_receive_quota_" + i).val()); var receive_quota = parseFloat($("#eva_adjust_postponement_detail_quota_02_receive_quota_" + i).val());
@@ -167,7 +167,7 @@ function CalculateRemainQuota(m) {
$("#eva_adjust_postponement_detail_quota_02_new_cost_living_" + i).val(0); $("#eva_adjust_postponement_detail_quota_02_new_cost_living_" + i).val(0);
} }
} }
sum_receive_quota += receive_quota; sum_receive_quota += receive_quota;
} }
@@ -180,3 +180,39 @@ function CalculateRemainQuota(m) {
} }
// ================================================= report rep_eva_savemessage ==================================================
function rep_eva_savemessage_GetSearchParameter(fileType) {
var eva_adjust_postponement_quotaObject = new Object();
eva_adjust_postponement_quotaObject.quota_id = $("#eva_adjust_postponement_quota_id").val();
eva_adjust_postponement_quotaObject.fiscal_year = $("#eva_adjust_postponement_quota_fiscal_year").val();
eva_adjust_postponement_quotaObject.theRound = $("#eva_adjust_postponement_quota_theRound").val();
eva_adjust_postponement_quotaObject.limit_frame_quota = $("#eva_adjust_postponement_quota_limit_frame_quota").val();
eva_adjust_postponement_quotaObject.limit_quota = $("#eva_adjust_postponement_quota_limit_quota").val();
eva_adjust_postponement_quotaObject.command_no = $("#eva_adjust_postponement_quota_command_no").val();
eva_adjust_postponement_quotaObject.theDate_text = $("#eva_adjust_postponement_quota_theDate").val();
eva_adjust_postponement_quotaObject.fileType = fileType;
return eva_adjust_postponement_quotaObject;
}
function rep_eva_savemessage_DoSearch(fileType) {
if (!ValidateForm('eva_adjust_postponement_quota', eva_adjust_postponement_quota_customValidation)) {
return;
}
var p = $.param(rep_eva_savemessage_GetSearchParameter(fileType));
var report_url = apisite + eva_adjust_postponement_quota_API + "rep_eva_savemessage?" + p;
if (fileType === "pdf") {
$("#report_result").attr("src", report_url);
$("#report_result").show();
$("#report_xModel").modal("show");
} else {
$("#report_result").hide();
window.open(report_url);
}
}