From 8c149e555da7c7e1d860dd113502fadf1d83f7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Fri, 6 Sep 2024 23:23:28 +0800 Subject: [PATCH] updates --- Controllers/ApiController.cs | 53 +++++- Modals/DbTableClass.cs | 158 ++++++++++++++++ Modals/resultClass.cs | 8 + Views/Home/ProjectList.cshtml | 60 ++++++ .../assets/javascript/custom/projectlist.js | 179 +++++++++++++++++- 5 files changed, 456 insertions(+), 2 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 45b360fe..c5945e7d 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -28,6 +28,56 @@ namespace QuotationMaker.Controllers } + [Route("quotationList")] + public ActionResult QuotationList(IFormCollection obj) + { + quotationViewListResult ret = new quotationViewListResult(); + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string user_uid = token.user_uid; + string user_perm = token.user_perm; + string project_uid = obj["project_uid"].ToString(); + string dept_uid = obj["dept_uid"].ToString(); + + string user_uid_list = "'" + user_uid + "'"; + + if (user_perm == "system" && token.user_id != GlobalClass.appsettings("Admin:id")) + { + groupUser gpUser = conn.QueryFirstOrDefault("select * from groupUser where dept_uid = @dept_uid and user_uid = @user_uid ", new { dept_uid = dept_uid, user_uid = user_uid }); + + if (gpUser != null) + { + List groupUsers = conn.Query("select * from groupUser where group_uid = @group_uid", new { group_uid = gpUser.group_uid }).ToList(); + + foreach (groupUser groupUser in groupUsers) + { + user_uid_list += ", '" + groupUser.user_uid + "'"; + } + } + } + + if (token.user_id != GlobalClass.appsettings("Admin:id")) + { + ret.quotationViews = conn.Query("select * from quotationView where quotationView_isdel = 'N' and quotationView_revoke = 'N' and project_uid = @project_uid and quotation_create_uid in (@user_list) order by quotation_modifydate desc", new { project_uid = project_uid, user_list = user_uid_list }).ToList(); + + } + else { + ret.quotationViews = conn.Query("select * from quotationView where quotation_isdel = 'N' and quotation_revoke = 'N' and project_uid = @project_uid order by quotation_modifydate desc", new { project_uid = project_uid }).ToList(); + } + + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("deptList")] public ActionResult DeptList(IFormCollection obj) { @@ -125,6 +175,7 @@ namespace QuotationMaker.Controllers newProject.dept_uid = dept_uid; newProject.company_uid = company_uid; newProject.project_ps = project_ps; + newProject.project_creative_uid = token.user_uid; newProject.project_lastmodify_uid = token.user_uid; newProject.project_name = project_name; newProject.project_datetime = DateTime.Now.ToString("yyyy/MM/dd"); @@ -271,7 +322,7 @@ namespace QuotationMaker.Controllers } } - string sqlString = "select * from projectView where project_isdel = 'N' and project_lastmodify_uid in (" + user_uid_list + ") and project_createdate >= '" + startDateTime.ToString("yyyy/MM/dd") + "' and project_createdate <= '" + endDateTime.ToString("yyyy/MM/dd 23:59:59") + "'"; + string sqlString = "select * from projectView where project_isdel = 'N' and project_creative_uid in (" + user_uid_list + ") and project_createdate >= '" + startDateTime.ToString("yyyy/MM/dd") + "' and project_createdate <= '" + endDateTime.ToString("yyyy/MM/dd 23:59:59") + "'"; ret.projectViews = conn.Query(sqlString).ToList(); ret.ret = "yes"; diff --git a/Modals/DbTableClass.cs b/Modals/DbTableClass.cs index f578a6c1..9c79a7e3 100644 --- a/Modals/DbTableClass.cs +++ b/Modals/DbTableClass.cs @@ -9,6 +9,161 @@ using Org.BouncyCastle.Bcpg.OpenPgp; public class DbTableClass { + + [Table("quotationView")] + public class quotationView + { + [JsonIgnore] + [Key] + public int quotation_sn { get; set; } + public string quotation_uid { get; set; } = ""; + public string quotation_name { get; set; } = ""; + public string quotation_date { get; set; } = ""; + public string dept_uid { get; set; } = ""; + public string quotation_expStart { get; set; } = ""; + public string quotation_expEnd { get; set; } = ""; + public string quotation_prodMethod { get; set; } = ""; + public string project_uid { get; set; } = ""; + public string modelProj_uid { get; set; } = ""; + public string modelQuotation_uid { get; set; } = ""; + public string company_uid { get; set; } = ""; + public string contactPerson_uid { get; set; } = ""; + public double quotation_noTaxTotal { get; set; } = 0.0; + public double quotation_specTotal { get; set; } = 0.0; + public double quotation_tax { get; set; } = 0.0; + public double quotation_grandTotal { get; set; } = 0.0; + public string quotation_sa { get; set; } = ""; + public string quotation_isdel { get; set; } = ""; + public string quotation_revoke { get; set; } = ""; + public int quotation_version { get; set; } = 0; + public DateTime quotation_createdate { get; set; } = DateTime.Now; + public DateTime quotation_modifydate { get; set; } = DateTime.Now; + public string quotation_create_uid { get; set; } = ""; + public string quotation_modify_uid { get; set; } = ""; + public string contactPerson_name { get; set; } = ""; + public string contactPerson_email { get; set; } = ""; + public string contactPerson_tel { get; set; } = ""; + public string contactPerson_fax { get; set; } = ""; + } + + + + [Table("invoice")] + public class invoice + { + [JsonIgnore] + [Key] + public int invoice_sn { get; set; } + public string invoice_uid { get; set; } = ""; + public string quotation_uid { get; set; } = ""; + public string invoice_name { get; set; } = ""; + public string invoice_month { get; set; } = ""; + public int invoice_noTaxMoney { get; set; } = 0; + public string invoice_revoke { get; set; } = "N"; + public int invoice_version { get; set; } = 1; + public DateTime invoice_createdate { get; set; } = DateTime.Now; + public DateTime invoice_modifydate { get; set; } = DateTime.Now; + } + + + + [Table("payment")] + public class payment + { + [JsonIgnore] + [Key] + public int payment_sn { get; set; } + public string payment_uid { get; set; } = ""; + public string quotation_uid { get; set; } = ""; + public string payment_method { get; set; } = ""; + public string payment_descript { get; set; } = ""; + public string payment_revoke { get; set; } = "N"; + public int payment_version { get; set; } = 1; + public DateTime payment_createdate { get; set; } = DateTime.Now; + public DateTime payment_modifydate { get; set; } = DateTime.Now; + } + + + + [Table("quotationSubItem")] + public class quotationSubItem + { + [JsonIgnore] + [Key] + public int quotationSubItem_sn { get; set; } + public string quotationSubItem_uid { get; set; } = ""; + public string quotation_uid { get; set; } = ""; + public string subItem_uid { get; set; } = ""; + public string quotationMainItem_uid { get; set; } = ""; + public string quotationSubItem_name { get; set; } = ""; + public string quotationSubItem_descript { get; set; } = ""; + public double quotationSubItem_price { get; set; } = 0.0; + public string quotationSubItem_unitType { get; set; } = ""; + public double quotationSubItem_number { get; set; } = 0.0; + public double quotationSubItem_subTotal { get; set; } = 0.0; + public string quotationSubItem_hasAC { get; set; } = "Y"; + public string quotationSubItem_revoke { get; set; } = "N"; + public int quotationSubItem_version { get; set; } = 1; + public DateTime quotationSubItem_createdate { get; set; } = DateTime.Now; + public DateTime quotationSubItem_modifydate { get; set; } = DateTime.Now; + } + + + + [Table("quotationMainItem")] + public class quotationMainItem + { + [JsonIgnore] + [Key] + public int quotationMainItem_sn { get; set; } + public string quotation_uid { get; set; } = ""; + public string mainItem_uid { get; set; } = ""; + public string quotationMainItem_uid { get; set; } = ""; + public string quotationMainItem_name { get; set; } = ""; + public double quotationMainItem_ac { get; set; } = 0.0; + public double quotationMainItem_subTotal { get; set; } = 0.0; + public string quotationMainItem_revoke { get; set; } = "N"; + public int quotationMainItem_version { get; set; } = 1; + public DateTime quotationMainItem_createdate { get; set; } = DateTime.Now; + public DateTime quotationMainItem_modifydate { get; set; } = DateTime.Now; + } + + + + [Table("quotation")] + public class quotation + { + [JsonIgnore] + [Key] + public int quotation_sn { get; set; } + public string quotation_uid { get; set; } = ""; + public string quotation_name { get; set; } = ""; + public string quotation_date { get; set; } = ""; + public string dept_uid { get; set; } = ""; + public string quotation_expStart { get; set; } = ""; + public string quotation_expEnd { get; set; } = ""; + public string quotation_prodMethod { get; set; } = ""; + public string project_uid { get; set; } = ""; + public string modelProj_uid { get; set; } = ""; + public string modelQuotation_uid { get; set; } = ""; + public string company_uid { get; set; } = ""; + public string contactPerson_uid { get; set; } = ""; + public double quotation_noTaxTotal { get; set; } = 0.0; + public double quotation_specTotal { get; set; } = 0.0; + public double quotation_tax { get; set; } = 0.0; + public double quotation_grandTotal { get; set; } = 0.0; + public string quotation_sa { get; set; } = ""; + public string quotation_isdel { get; set; } = ""; + public string quotation_revoke { get; set; } = ""; + public int quotation_version { get; set; } = 1; + public DateTime quotation_createdate { get; set; } = DateTime.Now; + public DateTime quotation_modifydate { get; set; } = DateTime.Now; + public string quotation_create_uid { get; set; } = ""; + public string quotation_modify_uid { get; set; } = ""; + } + + + [Table("projectView")] public class projectView { @@ -21,6 +176,7 @@ public class DbTableClass public string project_name { get; set; } = ""; public string project_datetime { get; set; } = ""; public string company_uid { get; set; } = ""; + public string project_creative_uid { get; set; } = ""; public string project_lastmodify_uid { get; set; } = ""; public DateTime project_createdate { get; set; } = DateTime.Now; public DateTime project_modifydate { get; set; } = DateTime.Now; @@ -50,6 +206,8 @@ public class DbTableClass public string project_ps { get; set; } = ""; public string project_isdel { get; set; } = "N"; + + public string project_creative_uid { get; set; } = ""; public string project_lastmodify_uid { get; set; } = ""; public DateTime project_createdate { get; set; } = DateTime.Now; public DateTime project_modifydate { get; set; } = DateTime.Now; diff --git a/Modals/resultClass.cs b/Modals/resultClass.cs index 69db580f..fddd6080 100644 --- a/Modals/resultClass.cs +++ b/Modals/resultClass.cs @@ -4,6 +4,14 @@ using Dapper; using static DbTableClass; public class resultClass { + public class quotationViewListResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public List quotationViews = new List(); + } + public class projectViewResult { public string ret = "no"; diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index 9468cf42..5ff4df38 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -213,3 +213,63 @@ + +
+ +
\ No newline at end of file diff --git a/wwwroot/assets/javascript/custom/projectlist.js b/wwwroot/assets/javascript/custom/projectlist.js index 4c6bb8e5..83e56672 100644 --- a/wwwroot/assets/javascript/custom/projectlist.js +++ b/wwwroot/assets/javascript/custom/projectlist.js @@ -2,11 +2,15 @@ var projectRowID; var projectPos; +var quotationTable; +var quotationRowID; +var quotationPos; + $(document).ready(function () { deptList(); companyList(); loadyearmonth(); - + loadQuotationTable(); var actualDate = new Date(); // convert to actual date var prevDate = new Date(actualDate.getFullYear(), actualDate.getMonth() - 13, actualDate.getDate()); @@ -140,6 +144,55 @@ function buttonClick(obj) { projectRowPos = projectTable.fnGetPosition($('#' + uid)[0]); + if (type == "preview") { + var data = $('#dt-responsive').DataTable().row(projectRowPos).data(); + var project_name = data.project_name; + var company_name = data.company_name; + + var project_info_div = '專案名稱: ' + project_name + ", 客戶公司:" + company_name; + + var formData = { + project_uid: uid, + dept_uid: dept_uid + } + + $.ajax({ + url: "/Api/quotationList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + + var obj = data.quotationViews; + + $('#dt-responsive-quotation').dataTable().fnClearTable(); + if (obj.length > 0) { + + $('#dt-responsive-quotation').dataTable().fnAddData(obj); + } + + $('#project_info_div').text(project_info_div); + $('#clientQuotationListModal').modal('toggle'); + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + + + + + + } + if (type == "edit") { var formData = { method: 'get', @@ -213,6 +266,130 @@ function buttonClick(obj) { } } } + +function loadQuotationTable() { + var dataTables = { + init: function init() { + + this.bindUIActions(); + }, + bindUIActions: function bindUIActions() { + + // event handlers + this.table = this.handleDataTables(); + + // add buttons + //this.table.buttons().container().appendTo('#dt-buttons').unwrap(); + }, + handleDataTables: function handleDataTables() { + //$('#myTable').append(""); + return $('#dt-responsive-quotation').DataTable({ + dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>', + lengthChange: true, + lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]], + pageLength: 50, + buttons: [ + //{ + // text: '休假設定', + // action: function (e, dt, node, config) { + // vacationBtnFun(); + + // } + //}, + //'excelHtml5' + ], + language: { + paginate: { + previous: '', + next: '' + }, + buttons: { + copyTitle: 'Data copied', + copyKeys: 'Use your keyboard or menu to select the copy command' + } + }, + autoWidth: false, + rowId: 'quotation_uid', + deferRender: true, + initComplete: function () { + quotationTable = $('#dt-responsive-quotation').dataTable(); + $('#dt-responsive-quotation').on('click', 'a', function () { + buttonQuotationClick(this); + }); + + $('#dt-responsive-quotation').on('click', 'button', function () { + buttonQuotationClick(this); + }); + + + }, + order: [[0, 'desc']], + info: true, + search: "搜尋:", + searching: true, + columns: [ + { data: 'quotation_name', className: 'align-top text-left', orderable: true, searchable: true }, + { data: 'quotation_date', className: 'align-top text-left', orderable: false, searchable: true }, + { data: 'contactPerson_name', className: 'align-top text-left', orderable: false, searchable: true }, + { data: 'quotation_uid', className: 'align-top text-center', orderable: false, searchable: false } + ], + columnDefs: [ + { + targets: 0, + className: 'align-middle text-left', + orderable: false, + searchable: true, + render: function render(data, type, row, meta) { + + + return '' + row.quotation_name + ''; + + } + }, + { + targets: 3, + orderable: false, + searchable: false, + render: function render(data, type, row, meta) { + var ret = ''; + + ret += ''; + ret += ''; + return ret; + } + } + + ], + responsive: { + details: { + display: $.fn.dataTable.Responsive.display.childRowImmediate, + type: '' + } + } + }); + }, + handleSearchRecords: function handleSearchRecords() { + var self = this; + + $('#table-search, #filterBy').on('keyup change focus', function (e) { + var filterBy = $('#filterBy').val(); + var hasFilter = filterBy !== ''; + var value = $('#table-search').val(); + + self.table.search('').columns().search('').draw(); + + if (hasFilter) { + self.table.columns(filterBy).search(value).draw(); + } else { + self.table.search(value).draw(); + } + + }); + } + } + + dataTables.init(); +} function loadDataTable() { var dataTables = { init: function init() {