diff --git a/ApiControllers/rpt_payroll_summaryControllers.cs b/ApiControllers/rpt_payroll_summaryControllers.cs new file mode 100644 index 0000000..604e6e1 --- /dev/null +++ b/ApiControllers/rpt_payroll_summaryControllers.cs @@ -0,0 +1,120 @@ +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; + +namespace TodoAPI2.Controllers +{ + //[Authorize] + [Produces("application/json")] + [Route("api/rpt_payroll_summary")] + public class rpt_payroll_summaryController : BaseController + { + #region Private Variables + private ILogger _logger; + private Irpt_payroll_summaryService _repository; + private IConfiguration Configuration { get; set; } + #endregion + + #region Properties + + #endregion + + /// + /// Default constructure for dependency injection + /// + /// + /// + /// + public rpt_payroll_summaryController(ILogger logger, Irpt_payroll_summaryService 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(rpt_payroll_summaryWithSelectionViewModel), 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("rpt_payroll_summary_report")] + [ProducesResponseType(typeof(FileStreamResult), 200)] + [ProducesResponseType(400)] + [ProducesResponseType(500)] + //[ValidateAntiForgeryToken] + public IActionResult rpt_payroll_summary_report(rpt_payroll_summaryReportRequestModel 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"); + + string url = $"{mainurl}{reportsite}/rpt_payroll_summary.{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, $"{ex.Message}"); + } + } + + } +} diff --git a/EXCEL/eva_level_score@rpt_payroll_summary.xlsx b/EXCEL/eva_level_score@rpt_payroll_summary.xlsx new file mode 100644 index 0000000..5bd01f9 Binary files /dev/null and b/EXCEL/eva_level_score@rpt_payroll_summary.xlsx differ diff --git a/Models/external_linkage/Iexternal_linkageService.cs b/Models/external_linkage/Iexternal_linkageService.cs index 6221276..e047137 100644 --- a/Models/external_linkage/Iexternal_linkageService.cs +++ b/Models/external_linkage/Iexternal_linkageService.cs @@ -33,6 +33,8 @@ namespace TodoAPI2.Models List GetAllChildInDep(int? dep_id); List GetChildInDep(int? dep_id); List GetSortingDep(); + List GetFiscalYear2(); + List GetThaiMonth(); } } diff --git a/Models/external_linkage/external_linkageService.cs b/Models/external_linkage/external_linkageService.cs index 6a0588b..1d7272b 100644 --- a/Models/external_linkage/external_linkageService.cs +++ b/Models/external_linkage/external_linkageService.cs @@ -14,6 +14,7 @@ using System.Net; using TTSW.Configure; using Microsoft.Extensions.Options; using System.Data; +using System.Globalization; namespace TodoAPI2.Models { @@ -354,6 +355,26 @@ namespace TodoAPI2.Models return result; } + public List GetFiscalYear2() + { + int start_year = DateTime.Now.Year - 10; + if (start_year < 2400) start_year += 543; + int end_year = DateTime.Now.Year + 3; + if (end_year < 2400) end_year += 543; + + var result = new List(); + for (int x = start_year; x <= end_year; x++) + { + var i = new external_linkageViewModel(); + i.external_id = x - 543; + i.external_code = x.ToString(); + i.external_name = x.ToString(); + result.Add(i); + } + + return result; + } + //public List GetEvaRound() //{ // var sql = string.Format("select distinct eva_performance_plan.id,eva_performance_plan.{0}theTime{0} , eva_performance_plan.fiscal_year from eva_performance_plan order by eva_performance_plan.fiscal_year,eva_performance_plan.{0}theTime{0}", '"'.ToString()); @@ -426,6 +447,26 @@ where detail.parent_department_id={1} or data1.id={1};", '"'.ToString(), dep_id. return result; } + public List GetThaiMonth() + { + var result = new List(); + + for (int monthNo = 1; monthNo <= 12; monthNo++) + { + var bar = new DateTime(DateTime.Now.Year, monthNo, 1); + string month = bar.ToString("MMMM", new CultureInfo("th-TH")); + + var i = new external_linkageViewModel(); + //i.external_guid = null; + i.external_id = monthNo; + i.external_code = monthNo.ToString(); + i.external_name = month; + result.Add(i); + } + + return result; + } + public List GetSortingDep() { var sql = string.Format(@" diff --git a/Models/rpt_payroll_summary/Irpt_payroll_summaryService.cs b/Models/rpt_payroll_summary/Irpt_payroll_summaryService.cs new file mode 100644 index 0000000..1e90dcd --- /dev/null +++ b/Models/rpt_payroll_summary/Irpt_payroll_summaryService.cs @@ -0,0 +1,20 @@ +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 Irpt_payroll_summaryService + { + rpt_payroll_summaryWithSelectionViewModel GetBlankItem(); + + + } +} + diff --git a/Models/rpt_payroll_summary/rpt_payroll_summaryInputModel.cs b/Models/rpt_payroll_summary/rpt_payroll_summaryInputModel.cs new file mode 100644 index 0000000..895fd27 --- /dev/null +++ b/Models/rpt_payroll_summary/rpt_payroll_summaryInputModel.cs @@ -0,0 +1,28 @@ +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 rpt_payroll_summaryInputModel + { + + public Guid? id { get; set; } + + public int? rpt_year { get; set; } + + public int? rpt_month { get; set; } + + public int? department_id { get; set; } + + public string active_mode { get; set; } + } +} + diff --git a/Models/rpt_payroll_summary/rpt_payroll_summaryReportRequestModel.cs b/Models/rpt_payroll_summary/rpt_payroll_summaryReportRequestModel.cs new file mode 100644 index 0000000..805683b --- /dev/null +++ b/Models/rpt_payroll_summary/rpt_payroll_summaryReportRequestModel.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 rpt_payroll_summaryReportRequestModel : rpt_payroll_summarySearchModel + { + public string filetype { get; set; } + + public string contentType { get { return MyHelper.GetContentType(filetype); } } + } +} + diff --git a/Models/rpt_payroll_summary/rpt_payroll_summarySearchModel.cs b/Models/rpt_payroll_summary/rpt_payroll_summarySearchModel.cs new file mode 100644 index 0000000..d45ec22 --- /dev/null +++ b/Models/rpt_payroll_summary/rpt_payroll_summarySearchModel.cs @@ -0,0 +1,27 @@ +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 rpt_payroll_summarySearchModel + { + + public Guid id { get; set; } + + public int? rpt_year { get; set; } + + public int? rpt_month { get; set; } + + public int? department_id { get; set; } + + } +} + diff --git a/Models/rpt_payroll_summary/rpt_payroll_summaryService.cs b/Models/rpt_payroll_summary/rpt_payroll_summaryService.cs new file mode 100644 index 0000000..621e50f --- /dev/null +++ b/Models/rpt_payroll_summary/rpt_payroll_summaryService.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 rpt_payroll_summaryService : Irpt_payroll_summaryService + { + private IMyDatabase db; + private Iexternal_linkageService ext; + + public rpt_payroll_summaryService(IMyDatabase mydb, Iexternal_linkageService inext) + { + db = mydb; + ext = inext; + } + + public rpt_payroll_summaryWithSelectionViewModel GetBlankItem() + { + var i = new rpt_payroll_summaryWithSelectionViewModel(); + i.item_rpt_year = (from x in ext.GetFiscalYear2() orderby x.external_id descending select x).ToList(); + i.item_rpt_month = (from x in ext.GetThaiMonth() select x).ToList(); + i.item_department_id = (from x in ext.GetSortingDep() select x).ToList(); + + + return i; + } + } +} \ No newline at end of file diff --git a/Models/rpt_payroll_summary/rpt_payroll_summaryViewModel.cs b/Models/rpt_payroll_summary/rpt_payroll_summaryViewModel.cs new file mode 100644 index 0000000..1334fdd --- /dev/null +++ b/Models/rpt_payroll_summary/rpt_payroll_summaryViewModel.cs @@ -0,0 +1,28 @@ +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 rpt_payroll_summaryViewModel : BaseViewModel2 + { + + public int? rpt_year { get; set; } + + public int? rpt_month { get; set; } + + public int? department_id { get; set; } + + public string rpt_year_external_linkage_external_name { get; set; } + public string rpt_month_external_linkage_external_name { get; set; } + public string department_id_external_linkage_external_name { get; set; } + + } +} \ No newline at end of file diff --git a/Models/rpt_payroll_summary/rpt_payroll_summaryWithSelectionViewModel.cs b/Models/rpt_payroll_summary/rpt_payroll_summaryWithSelectionViewModel.cs new file mode 100644 index 0000000..acd9f1e --- /dev/null +++ b/Models/rpt_payroll_summary/rpt_payroll_summaryWithSelectionViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace TodoAPI2.Models +{ + public class rpt_payroll_summaryWithSelectionViewModel: rpt_payroll_summaryViewModel + { + public List item_rpt_year { get; set; } + public List item_rpt_month { get; set; } + public List item_department_id { get; set; } + + } +} \ No newline at end of file diff --git a/Startup.cs b/Startup.cs index afe543d..3fca47b 100644 --- a/Startup.cs +++ b/Startup.cs @@ -287,6 +287,8 @@ namespace Test01 services.AddScoped(); + services.AddScoped(); + #endregion services.TryAddSingleton(); @@ -502,6 +504,10 @@ namespace Test01 cfg.CreateMap(); cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + }); #endregion diff --git a/ViewControllers/rpt_payroll_summaryViewControllers.cs b/ViewControllers/rpt_payroll_summaryViewControllers.cs new file mode 100644 index 0000000..197b827 --- /dev/null +++ b/ViewControllers/rpt_payroll_summaryViewControllers.cs @@ -0,0 +1,66 @@ +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 rpt_payroll_summaryViewController : Controller + { + private ILogger _logger; + private Irpt_payroll_summaryService _repository; + private IConfiguration Configuration { get; set; } + + /// + /// Default constructure for dependency injection + /// + /// + /// + /// + public rpt_payroll_summaryViewController(ILogger logger, Irpt_payroll_summaryService repository, IConfiguration configuration) + { + _logger = logger; + _repository = repository; + Configuration = configuration; + } + + // public IActionResult rpt_payroll_summary() + // { + //if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); // Or UnauthorizedView + // return View(); + // } + + // public IActionResult rpt_payroll_summary_d() + // { + //if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); // Or UnauthorizedView + // return View(); + // } + + public IActionResult rpt_payroll_summary_report() + { + if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized(); // Or UnauthorizedView + return View(); + } + + //public IActionResult rpt_payroll_summary_inline() + //{ + // 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/home/index.cshtml b/Views/home/index.cshtml index 3d53db9..c5d4f72 100644 --- a/Views/home/index.cshtml +++ b/Views/home/index.cshtml @@ -71,6 +71,9 @@ + diff --git a/Views/rpt_payroll_summaryView/rpt_payroll_summary_report.cshtml b/Views/rpt_payroll_summaryView/rpt_payroll_summary_report.cshtml new file mode 100644 index 0000000..448f01b --- /dev/null +++ b/Views/rpt_payroll_summaryView/rpt_payroll_summary_report.cshtml @@ -0,0 +1,66 @@ +@using Microsoft.Extensions.Configuration +@inject IConfiguration Configuration +@{ + ViewData["Title"] = "rpt_payroll_summary"; +} + +
+
+
+ @Configuration["SiteInformation:modulename"] +
+
+
+ +
+
+ +
+
รายงานเงินเดือน
+
+
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+ + +
+
+
+
+
+ + +@section FooterPlaceHolder{ + + +} + diff --git a/tb320eva.xml b/tb320eva.xml index 353655e..97749ca 100644 --- a/tb320eva.xml +++ b/tb320eva.xml @@ -3572,6 +3572,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 @@ -3884,6 +3912,14 @@ + + + Default constructure for dependency injection + + + + + Default constructure for dependency injection diff --git a/wwwroot/js/rpt_payroll_summary/rpt_payroll_summary_report.js b/wwwroot/js/rpt_payroll_summary/rpt_payroll_summary_report.js new file mode 100644 index 0000000..c6424d3 --- /dev/null +++ b/wwwroot/js/rpt_payroll_summary/rpt_payroll_summary_report.js @@ -0,0 +1,62 @@ +var rpt_payroll_summary_API = "/api/rpt_payroll_summary/"; + +//================= Search Customizaiton ========================================= + +function rpt_payroll_summary_GetSearchParameter(fileType) { + var rpt_payroll_summarySearchObject = new Object(); +rpt_payroll_summarySearchObject.rpt_year = $("#s_rpt_payroll_summary_rpt_year").val(); +rpt_payroll_summarySearchObject.rpt_month = $("#s_rpt_payroll_summary_rpt_month").val(); +rpt_payroll_summarySearchObject.department_id = $("#s_rpt_payroll_summary_department_id").val(); + + + rpt_payroll_summarySearchObject.fileType = fileType; + + console.log(rpt_payroll_summarySearchObject); + + return rpt_payroll_summarySearchObject; +} + +function rpt_payroll_summary_FeedDataToSearchForm(data) { +DropDownClearFormAndFeedWithData($("#s_rpt_payroll_summary_rpt_year"), data, "id", "external_name", "item_rpt_year", data.rpt_year); +DropDownClearFormAndFeedWithData($("#s_rpt_payroll_summary_rpt_month"), data, "id", "external_name", "item_rpt_month", data.rpt_month); +DropDownClearFormAndFeedWithData($("#s_rpt_payroll_summary_department_id"), data, "id", "external_name", "item_department_id", data.department_id); + +} + +//================= Form Data Customizaiton ========================================= + +function rpt_payroll_summary_InitialForm(s) { + var successFunc = function (result) { + rpt_payroll_summary_FeedDataToSearchForm(result); + endLoad(); + }; + startLoad(); + AjaxGetRequest(apisite + rpt_payroll_summary_API + "GetBlankItem", successFunc, AlertDanger); +} + +//================= Data Table ========================================= + +var s_rpt_payroll_summary_customValidation = function (group) { + return ""; +}; + + +function rpt_payroll_summary_DoSearch(fileType) { + if (!ValidateForm('s_rpt_payroll_summary', s_rpt_payroll_summary_customValidation)) { + return; + } + + var p = $.param(rpt_payroll_summary_GetSearchParameter(fileType)); + + var report_url = apisite + "/api/rpt_payroll_summary/rpt_payroll_summary_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); + } +} +