diff --git a/ApiControllers/rep_kp7Controllers.cs b/ApiControllers/rep_kp7Controllers.cs new file mode 100644 index 0000000..77e0631 --- /dev/null +++ b/ApiControllers/rep_kp7Controllers.cs @@ -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 _logger; + private Irep_kp7Service _repository; + private IConfiguration Configuration { get; set; } + #endregion + + #region Properties + + #endregion + + /// + /// Default constructure for dependency injection + /// + /// + /// + /// + public rep_kp7Controller(ILogger logger, Irep_kp7Service repository, IConfiguration configuration) + { + _logger = logger; + _repository = repository; + Configuration = configuration; + } + + /// + /// Get Blank Item + /// + /// + /// + /// Return a blank item + /// Returns the item + /// Error Occurred + [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}"); + } + } + + /// + /// Download Report + /// + /// + /// + /// Return list of items by specifced keyword + /// Returns the item + /// Error Occurred + [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); + } + } +} diff --git a/EXCEL/eva_level_score@rep_kp7.xlsx b/EXCEL/eva_level_score@rep_kp7.xlsx new file mode 100644 index 0000000..841da10 Binary files /dev/null and b/EXCEL/eva_level_score@rep_kp7.xlsx differ diff --git a/Models/rep_kp7/Irep_kp7Service.cs b/Models/rep_kp7/Irep_kp7Service.cs new file mode 100644 index 0000000..dfe7ce5 --- /dev/null +++ b/Models/rep_kp7/Irep_kp7Service.cs @@ -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(); + } +} + diff --git a/Models/rep_kp7/rep_kp7InputModel.cs b/Models/rep_kp7/rep_kp7InputModel.cs new file mode 100644 index 0000000..2880866 --- /dev/null +++ b/Models/rep_kp7/rep_kp7InputModel.cs @@ -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; } + } +} + diff --git a/Models/rep_kp7/rep_kp7ReportRequestModel.cs b/Models/rep_kp7/rep_kp7ReportRequestModel.cs new file mode 100644 index 0000000..2b08ea0 --- /dev/null +++ b/Models/rep_kp7/rep_kp7ReportRequestModel.cs @@ -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); } } + } +} + diff --git a/Models/rep_kp7/rep_kp7SearchModel.cs b/Models/rep_kp7/rep_kp7SearchModel.cs new file mode 100644 index 0000000..e1a1a68 --- /dev/null +++ b/Models/rep_kp7/rep_kp7SearchModel.cs @@ -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; } + + } +} + diff --git a/Models/rep_kp7/rep_kp7Service.cs b/Models/rep_kp7/rep_kp7Service.cs new file mode 100644 index 0000000..c81d06b --- /dev/null +++ b/Models/rep_kp7/rep_kp7Service.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/Models/rep_kp7/rep_kp7ViewModel.cs b/Models/rep_kp7/rep_kp7ViewModel.cs new file mode 100644 index 0000000..4c82215 --- /dev/null +++ b/Models/rep_kp7/rep_kp7ViewModel.cs @@ -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 + { + + public int? employee_id { get; set; } + + public string employee_id_external_linkage_external_name { get; set; } + + } +} \ No newline at end of file diff --git a/Models/rep_kp7/rep_kp7WithSelectionViewModel.cs b/Models/rep_kp7/rep_kp7WithSelectionViewModel.cs new file mode 100644 index 0000000..d3a2ace --- /dev/null +++ b/Models/rep_kp7/rep_kp7WithSelectionViewModel.cs @@ -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 item_employee_id { get; set; } + + } +} \ No newline at end of file diff --git a/Startup.cs b/Startup.cs index dfacd9e..0c1f0ff 100644 --- a/Startup.cs +++ b/Startup.cs @@ -291,6 +291,8 @@ namespace Test01 services.AddScoped(); + services.AddScoped(); + #endregion services.TryAddSingleton(); diff --git a/ViewControllers/rep_kp7ViewControllers.cs b/ViewControllers/rep_kp7ViewControllers.cs new file mode 100644 index 0000000..4d34273 --- /dev/null +++ b/ViewControllers/rep_kp7ViewControllers.cs @@ -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 _logger; + private Irep_kp7Service _repository; + private IConfiguration Configuration { get; set; } + + /// + /// Default constructure for dependency injection + /// + /// + /// + /// + public rep_kp7ViewController(ILogger 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 }); + } + } +} + + diff --git a/Views/rep_kp7View/rep_kp7_report.cshtml b/Views/rep_kp7View/rep_kp7_report.cshtml new file mode 100644 index 0000000..d921431 --- /dev/null +++ b/Views/rep_kp7View/rep_kp7_report.cshtml @@ -0,0 +1,56 @@ +@using Microsoft.Extensions.Configuration +@inject IConfiguration Configuration +@{ + ViewData["Title"] = "rep_kp7"; +} + +
+
+
+ @Configuration["SiteInformation:modulename"] +
+
+ +
+ +
+
รายงาน rep_kp7
+
+
+
+
+ +
+ + +
+ +
+
+
+ + +
+
+
+
+
+ + +@section FooterPlaceHolder{ + + +} + diff --git a/tb320eva.xml b/tb320eva.xml index 275ba74..5f47d8a 100644 --- a/tb320eva.xml +++ b/tb320eva.xml @@ -3418,6 +3418,34 @@ Returns the item Error Occurred + + + Default constructure for dependency injection + + + + + + + + Get Blank Item + + + + Return a blank item + Returns the item + Error Occurred + + + + Download Report + + + + Return list of items by specifced keyword + Returns the item + Error Occurred + Default constructure for dependency injection @@ -3900,6 +3928,14 @@ + + + Default constructure for dependency injection + + + + + Default constructure for dependency injection diff --git a/wwwroot/js/rep_kp7/rep_kp7_report.js b/wwwroot/js/rep_kp7/rep_kp7_report.js new file mode 100644 index 0000000..e183e44 --- /dev/null +++ b/wwwroot/js/rep_kp7/rep_kp7_report.js @@ -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); + } +} +