From 0b95afb125f92445205ad209c0652e9c8fc5d84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Fri, 13 Sep 2024 01:03:31 +0800 Subject: [PATCH] updates --- Controllers/ApiController.cs | 46 ++++ Modals/DbTableClass.cs | 2 +- Views/Home/ProjectList.cshtml | 89 +++++- .../assets/javascript/custom/projectlist.js | 259 +++++++++++++++++- 4 files changed, 393 insertions(+), 3 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index efbc8355..bbf5e069 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -29,6 +29,35 @@ namespace QuotationMaker.Controllers } + [Route("getHistoryList")] + public ActionResult GetHistoryList(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 quotation_uid = obj["quotation_uid"].ToString(); + + quotation quotation = conn.QueryFirstOrDefault("select * from quotation where quotation_isdel = 'N' and quotation_revoke = 'N' and quotation_uid = @quotation_uid ", new { quotation_uid = quotation_uid }); + + if (quotation == null) { + ret.ret = "no"; + ret.err_code = "0009"; + ret.message = "無此筆 quotation_uid 資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.quotationViews = conn.Query("select * from quotationView where quotation_isdel = 'N' and quotation_uid = @quotation_uid order by quotation_version desc ", new { quotation_uid = quotation_uid }).ToList(); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("addEditDelQuotation")] public ActionResult AddEditDelQuotation(IFormCollection obj) { quotationDetailResult ret = new quotationDetailResult(); @@ -271,6 +300,23 @@ namespace QuotationMaker.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } + if (method == "history") { + quotation objQuotation = conn.QueryFirstOrDefault("select * from quotation where quotation_isdel = 'N' and quotation_uid = @quotation_uid and quotation_version = @quotation_version order by quotation_version desc", new { quotation_uid = quotation_uid, quotation_version = quotation_version }); + + if (objQuotation == null) + { + ret.ret = "no"; + ret.err_code = "0009"; + ret.message = "此筆資料不存在或已被刪除!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.quotationDetail = new quotationDetail(objQuotation); + ret.quotationView = conn.QueryFirstOrDefault("select * from quotationView where quotation_isdel = 'N' and quotation_revoke = 'N' and quotation_uid = @quotation_uid ", new { quotation_uid = quotation_uid }); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + if (method == "get") { quotation objQuotation = conn.QueryFirstOrDefault("select * from quotation where quotation_isdel = 'N' and quotation_revoke = 'N' and quotation_uid = @quotation_uid order by quotation_version desc", new { quotation_uid = quotation_uid }); diff --git a/Modals/DbTableClass.cs b/Modals/DbTableClass.cs index 9b36fd5f..17285a98 100644 --- a/Modals/DbTableClass.cs +++ b/Modals/DbTableClass.cs @@ -135,7 +135,7 @@ public class DbTableClass [Table("quotation")] public class quotation { - [JsonIgnore] + [Key] public int quotation_sn { get; set; } public string quotation_uid { get; set; } = ""; diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index cd5b8177..b6e36b24 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -259,7 +259,7 @@ 報價單名稱 建立時間 窗口 - + @@ -276,6 +276,58 @@ + + +
+ +
@@ -649,4 +701,39 @@ +
+ + + +
+
\ No newline at end of file diff --git a/wwwroot/assets/javascript/custom/projectlist.js b/wwwroot/assets/javascript/custom/projectlist.js index cf3d2a8f..c071a214 100644 --- a/wwwroot/assets/javascript/custom/projectlist.js +++ b/wwwroot/assets/javascript/custom/projectlist.js @@ -6,6 +6,11 @@ var quotationTable; var quotationRowID; var quotationPos; +var historyTable; +var historyDataTable; +var historyRowID; +var historyPos; + var quotation_total; var deledMainItems = []; @@ -21,6 +26,7 @@ $(document).ready(function () { loadyearmonth(); loadQuotationTable(); initInvoiceSelectItem(); + loadHistoryTable(); var actualDate = new Date(); // convert to actual date var prevDate = new Date(actualDate.getFullYear(), actualDate.getMonth() - 13, actualDate.getDate()); @@ -166,6 +172,7 @@ $(document).ready(function () { $('#quotation_editType_div').show(); $('#quotation_sa').val(service_text()); $('#quotation_method').val('add'); + $('#modelQuotationDialogSaveBtn').show(); $('#clientModelQuotationModal').modal("toggle"); }); @@ -1097,6 +1104,67 @@ function loadQuotation_custom() { } }); } + +function buttonHistoryClick(obj) { + var type = obj.getAttribute('data-method'); + var quotation_uid = obj.getAttribute('data-uid'); + var quotation_version = obj.getAttribute('data-version'); + + historyRowID = $('#history_' + quotation_uid); + + historyRowPos = historyTable.fnGetPosition($('#history_' + quotation_uid)[0]); + + var quotation_row = historyDataTable.row(historyRowPos).data(); + + if (type == 'save_in_same') { + $('#save_to_same_quotation_uid').val(quotation_uid); + $('#save_to_same_quotation_name').val(quotation_row.quotation_name + ' - Copy').trigger('change'); + $('#clientSaveToSameModal').modal('toggle'); + } + + if (type == 'view') { + var formData = { + method: 'history', + quotation_uid: quotation_uid, + quotation_version: quotation_version + } + + $.ajax({ + url: "/Api/addEditDelQuotation", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.quotationDetail; + var objView = data.quotationView; + + $('#modelItem_div').html(''); + $('#payment_group').find('ol').html(''); + $('#invoice_group').find('ol').html(''); + + $("#quotation_method").val('edit'); + + quotationEditModelFillData(obj, objView); + + $('#quotationTitle_name').val('報價單內容 (檢視唯讀狀態)'); + $('#modelQuotationDialogSaveBtn').hide(); + + $('#clientModelQuotationModal').modal('toggle'); + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } + +} function buttonClick(obj) { var type = obj.getAttribute('data-method'); var uid = obj.getAttribute('data-uid'); @@ -1511,6 +1579,44 @@ function buttonQuotationClick(obj, view) { quotationRowPos = quotationTable.fnGetPosition($('#' + uid)[0]); + if (type == "history") { + var formData = { + method: 'get', + quotation_uid: uid, + version: version + } + + $.ajax({ + url: "/Api/getHistoryList", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.quotationViews; + + $('#now_version').val(version); + + $('#dt-responsive-history').dataTable().fnClearTable(); + if (obj.length > 0) { + + $('#dt-responsive-history').dataTable().fnAddData(obj); + } + + $('#clientHistoryListModal').modal('toggle'); + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } + if (type == "del") { if (confirm('確定要刪除此張報價單?')) { var formData = { @@ -1579,6 +1685,7 @@ function buttonQuotationClick(obj, view) { //$("#project_name").val(obj.project_name).trigger('change'); //$("#company_select").val(obj.company_uid); //$("#project_ps").val(obj.project_ps).trigger('change'); + $('#modelQuotationDialogSaveBtn').show(); $('#clientModelQuotationModal').modal('toggle'); } else { @@ -1595,6 +1702,156 @@ function buttonQuotationClick(obj, view) { }); } } + +//歷史清單 +function loadHistoryTable() { + 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-history').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: 25, + 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: function (row) { + return 'history_' + row.quotation_uid; + }, + deferRender: true, + initComplete: function () { + historyTable = $('#dt-responsive-history').dataTable(); + historyDataTable = $('#dt-responsive-history').DataTable(); + $('#dt-responsive-history').on('click', 'a', function () { + buttonHistoryClick(this); + }); + + $('#dt-responsive-history').on('click', 'button', function () { + buttonHistoryClick(this); + }); + + + }, + order: [[3, 'desc']], + info: true, + search: "搜尋:", + searching: true, + columns: [ + { data: 'quotation_uid', className: 'align-top text-center', orderable: false, searchable: false }, + { data: 'quotation_modifydate', className: 'align-top text-left', orderable: true, searchable: false }, + { data: 'quotation_name', className: 'align-top text-left', orderable: true, searchable: true }, + { data: 'quotation_version', className: 'align-top text-left', orderable: true, searchable: true } + + ], + columnDefs: [ + + { + targets: 0, + orderable: false, + searchable: false, + render: function render(data, type, row, meta) { + var ret = ''; + var drowdownHtml = ''; + drowdownHtml += ' '; + ret += drowdownHtml; + ret += ''; + + return ret; + } + }, { + targets: 1, + orderable: true, + searchable: true, + render: function render(data, type, row, meta) { + return (new Date(row.quotation_modifydate)).format("yyyy/MM/dd hh:mm:ss"); + } + } , + { + targets: 3, + orderable: false, + searchable: false, + render: function render(data, type, row, meta) { + var ret = row.quotation_version; + + if (ret == $('#now_version').val()) { + 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 loadQuotationTable() { var dataTables = { init: function init() { @@ -1680,7 +1937,7 @@ function loadQuotationTable() { searchable: false, render: function render(data, type, row, meta) { var ret = ''; - + ret += ''; ret += ''; ret += ''; return ret;