diff --git a/AMESCoreStudio.Web/Controllers/PTDController.cs b/AMESCoreStudio.Web/Controllers/PTDController.cs index 6fab7693..8f584af4 100644 --- a/AMESCoreStudio.Web/Controllers/PTDController.cs +++ b/AMESCoreStudio.Web/Controllers/PTDController.cs @@ -492,6 +492,18 @@ namespace AMESCoreStudio.Web.Controllers } return Json(new Table() { count = 0, data = null, msg = result.Msg }); } + [HttpPost] + public async Task PTD006_Commit(string data) + { + var result = await _pcsApi.PostPTD006Commit(data); + //将数据Json化并传到前台视图 + return Json(new { data = result }); + } + public async Task PTD006DAsync(string sn) + { + var result = await _pcsApi.DeleteZWHPickListDetail(sn); + return Json(new Result() { success = true, msg = "" }); + } #endregion #region "PTD007 扣帳作業" diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index 5502d35d..74d84c52 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -2006,6 +2006,11 @@ namespace AMESCoreStudio.Web #region "PTD006 備貨作業" [WebApiClient.Attributes.HttpGet("api/WipInfos/GetZWHPickListDetail")] ITask> GetZWHPickListDetail(string recordNumber, string LineNO); + + [WebApiClient.Attributes.HttpPost("api/WipInfos/PostPTD006Commit")] + ITask> PostPTD006Commit([FromBody, RawJsonContent] string model); + [WebApiClient.Attributes.HttpDelete("api/WipInfos/DeleteZWHPickListDetail/{sn}")] + ITask> DeleteZWHPickListDetail(string sn); #endregion #region "PTD007 扣帳作業" diff --git a/AMESCoreStudio.Web/Views/PTD/PTD006.cshtml b/AMESCoreStudio.Web/Views/PTD/PTD006.cshtml index 53d4b78e..5a25b3ac 100644 --- a/AMESCoreStudio.Web/Views/PTD/PTD006.cshtml +++ b/AMESCoreStudio.Web/Views/PTD/PTD006.cshtml @@ -148,7 +148,7 @@
- +
@@ -160,11 +160,6 @@
-
-
- -
-
@@ -206,13 +201,13 @@ //控項event $('#recordNumber').on('keypress', function (event) { if (event.keyCode == 13) { + var table = layui.table; var recordNumber = document.getElementById('recordNumber').value; var recordType = document.getElementById('recordType').value; var recordTypeInfo = @Html.Raw(Json.Serialize(ViewBag.RecordTypeInfo)); var filteredInfo = recordTypeInfo.find(function (info) { return info.id === recordType; }); - console.log(filteredInfo); //check recordNumber if (recordNumber.length !== filteredInfo.length) { layer.msg('請確認recordNumber碼長!', { icon: 2 }); @@ -227,12 +222,16 @@ return; } - layui.table.reload('query', { + table.reload('query', { where: { recordNumber: recordNumber }, page: { curr: 1 + }, + success: function () { + // 表格更新成功後計算資料筆數 + calculateRowCount(table.cache['query']); } }); @@ -241,12 +240,26 @@ } }); $('#lineNo').on('keypress', function (event) { - if (event.keyCode == 13) { + var table = layui.table; // 获取 recordNumber 和 lineNo 的值 var recordNumber = document.getElementById('recordNumber').value; var lineNo = document.getElementById('lineNo').value; + table.reload('query', { + where: { + recordNumber: recordNumber, + LineNO: lineNo + }, + page: { + curr: 1 + }, + success: function () { + // 表格更新成功後計算資料筆數 + calculateRowCount(table.cache['query']); + } + }); + // 发送 AJAX 请求到 Controller $.ajax({ url: '@Url.Action("GetZDNDetailJson", "PTD")', @@ -268,7 +281,6 @@ } }); } - }); $('#PartNumber').on('keypress', function (event) { if (event.keyCode == 13) { @@ -350,68 +362,6 @@ event.preventDefault(); } }); - $('#commit').on('click', function () { - var recordType = document.getElementById('recordType').value; - var workCenter = document.getElementById('WorkCenter').value; - var rbu = document.getElementById('RBU').value; - var location = document.getElementById('Location').value; - var customer = document.getElementById('Customer').value; - - var tableData = layui.table.cache['query']; - - var postData = { - recordType: recordType, - workCenter: workCenter, - rbu: rbu, - location: location, - customer: customer, - - tableData: tableData - }; - - console.log(JSON.stringify(postData)); - - $.ajax({ - url: '@Url.Action("PTD002_Commit", "PTD")', - dataType: 'json', - data: { data: JSON.stringify(postData) }, - type: 'POST', - success: function (result) { - console.log("扣帳結果:"); - console.log(result); - if (result.data.success) { - $.each(result.data.data, function (index, value) { - // 找到要删除的行的索引 - var rowIndex = tableData.findIndex(function (row) { - return row.sn === value; - }); - - // 从表格数据中删除该行 - if (rowIndex !== -1) { - tableData.splice(rowIndex, 1); - - // 重新加载表格数据 - layui.table.reload('query', { - data: tableData, - page: false, - limit: 2000 - }); - - calculateRowCount(tableData); - } else { - layer.msg('未找到要刪除的數據', { icon: 2 }); - } - }); - layer.msg('扣帳成功!', { icon: 1 }); - } else { - layer.msg('扣帳失敗,原因:' + result.data.msg, { icon: 2 }); - } - }, - error: function (error) { - layer.msg('扣帳失敗!原因:' + error.msg, { icon: 2 }); - } - }); - }); function getItemDesc(itemNo) { $.ajax({ @@ -448,23 +398,62 @@ hg.table.addRow = function (tableId, rowData) { // Get the table instance var table = layui.table; - console.log(table); if (isSNAlreadyExist(tableId, rowData.sn)) { // Handle the case where SN already exists layer.msg('SN 已存在!', { icon: 2 }); return; // Do not add the row } - // Add the new row data to the table - table.reload(tableId, { - data: [rowData].concat(table.cache[tableId]), - page: false, - limit: 2000 - }); + var ExtNotes = document.getElementById('ExtNotes'); + var username = getCookie("UserID"); + + var postData = { + RecordTypeID: rowData.recordType, + RecordNumber: rowData.dnNo, + RCLineNO: rowData.lineNo, + InputSN: rowData.sn, + ShipmentSN: rowData.sn, + ProductID: rowData.material, + EmplID: username, + ExtNotes: ExtNotes.value, + OwnerPlantID: WorkCenter.value, + OwnerCompanyID: RBU.value, + CreateDeptID: "", + CreatorID: username, + ModifyDeptID: "", + ModifierID: username, + }; - calculateRowCount(table.cache[tableId]); + $.ajax({ + url: '@Url.Action("PTD006_Commit", "PTD")', + dataType: 'json', + data: { data: JSON.stringify(postData) }, + type: 'POST', + success: function (result) { + if (result.data.success) { + // Add the new row data to the table + table.reload(tableId, { + data: [rowData].concat(table.cache[tableId]), + page: false, + limit: 2000, + success: function () { + // 表格更新成功後計算資料筆數 + calculateRowCount(table.cache[tableId]); + } + }); + layer.msg('備貨成功!', { icon: 1 }); + } else { + layer.msg('備貨失敗,原因:' + result.data.msg, { icon: 2 }); + return; + } + }, + error: function (error) { + layer.msg('備貨失敗!原因:' + error.msg, { icon: 2 }); + return; + } + }); }; function del(obj) { - if (obj.data.itemNo) { + if (obj.data.sn) { hg.confirm("SN:" + obj.data.sn + ",確定要刪除嗎?", function () { // 获取表格数据 var tableData = layui.table.cache['query']; @@ -478,21 +467,49 @@ if (rowIndex !== -1) { tableData.splice(rowIndex, 1); - // 重新加载表格数据 - layui.table.reload('query', { - data: tableData, - page: false, - limit: 2000 + $.ajax({ + url: '/PTD/PTD006D', + data: { sn: obj.data.sn }, + type: 'POST', + success: function (res) { + if (res.success) { + // 重新加载表格数据 + layui.table.reload('query', { + data: tableData, + page: false, + limit: 2000 + }); + layer.msg('刪除成功', { icon: 1 }); + calculateRowCount(tableData); + } + else { + hg.msg(data.msg); + } + }, + error: function () { + hg.msg("網路請求失敗!"); + } }); - layer.msg('刪除成功', { icon: 1 }); - calculateRowCount(tableData); } else { layer.msg('未找到要刪除的數據', { icon: 2 }); } }); } } + function getCookie(cookieName) { + var name = cookieName + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var cookieArray = decodedCookie.split(';'); + + for (var i = 0; i < cookieArray.length; i++) { + var cookie = cookieArray[i].trim(); + if (cookie.indexOf(name) === 0) { + return cookie.substring(name.length, cookie.length); + } + } + return null + } //Excel匯入 function importExcel() { @@ -567,7 +584,7 @@ } ]]; //基本数据表格 - var table = hg.table.datatable('query', '備貨資訊', '/PTD/PTD006Query', {recordNumber: $('#recordNumber').val() }, tableCols, "", true, 'full-100', ['filter', 'print', 'exports']); + var table = hg.table.datatable('query', '備貨資訊', '/PTD/PTD006Query', {}, tableCols, "", true, 'full-100', ['filter', 'print', 'exports']); } diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs index 7a64ada1..9da27b89 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -2523,7 +2523,11 @@ FROM [SFIS].[dbo].[ZPDKeyPart] B WHERE B.[IsActive] = 1 AND B.[ProductSN] = (S } string strSQL = $@"select DNNO,DNLineNO,ProductID,ShipQty,ShipCustomerID,SoldCustomerID,ExpectShipDate , CurrentShipDate - from SFIS_PTD.dbo.ZDNDetail where DNNO ='{dnNo}' and DNLineNO ='{lineNo}'"; + from SFIS_PTD.dbo.ZDNDetail where DNNO ='{dnNo}' "; + if (string.IsNullOrEmpty(lineNo)) + { + strSQL += $@"And DNLineNO ='{lineNo}'"; + } DataTable dtZDNDetail = new DataTable(); using (var cmd = connPTD.CreateCommand()) { @@ -3637,6 +3641,127 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); result.Msg = "OK"; return result; } + + [Route("[action]")] + [HttpPost] + public async Task> PostPTD006Commit(PTD006CommitDataModel Data) + { + ResultModel result = new ResultModel(); + List SNList = new List(); + Collection colSQL = new Collection(); + try + { + string strSQL = ""; + string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); + + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + await connPTD.OpenAsync(); + } + + //用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯 + bool bolChkFlow = false; + strSQL = $@"Select [FormID] FROM [SFIS_PTD].[dbo].[PTDFlowRules] + where [ToID] ='{Data.RecordTypeID}'"; + DataTable dtPTDFlowRules = new DataTable(); + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.HasRows) + { + dtPTDFlowRules = DataReaderToDataTable(reader); + } + } + } + + strSQL = @$"Select [RecordTypeID] FROM [SFIS_PTD].[dbo].[ZProductTrans] + where [SerialNumber] ='{Data.ShipmentSN}' + Order by [RecordDate] Desc"; + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + using (var reader = await cmd.ExecuteReaderAsync()) + { + if (reader.Read()) + { + foreach (DataRow dr in dtPTDFlowRules.Rows) + { + if (reader["RecordTypeID"].ToString() == dr["FormID"].ToString()) + { + bolChkFlow = true; + break; + } + } + } + } + } + if (!bolChkFlow) + throw new Exception("流程狀態不允許!"); + + //ZWHPickListDetail + strSQL = @$"INSERT INTO [dbo].[ZWHPickListDetail]([RecordTypeID],[RecordNumber],[RCLineNO],[InputSN],[SNFunction] + ,[ShipmentSN],[ProductID],[TaskStatus],[EmplID],[ExtNotes],[OwnerPlantID],[OwnerCompanyID] + ,[CreateDeptID],[CreatorID],[CreateDate],[ModifyDeptID],[ModifierID],[ModifyDate],[chkflag]) + VALUES ('{Data.RecordTypeID}','{Data.RecordNumber}','{Data.RCLineNO}','{Data.InputSN}','ShipmentSN', + '{Data.InputSN}','{Data.ProductID}','Picked','{Data.EmplID}',N'{Data.ExtNotes}','{Data.OwnerPlantID}','{Data.OwnerCompanyID}', + '{Data.CreateDeptID}','{Data.CreatorID}','{strCreateDate}','{Data.ModifyDeptID}','{Data.ModifierID}','{strCreateDate}','0')"; + + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + cmd.ExecuteNonQuery(); + } + + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.Message; + } + return result; + + } + [HttpDelete("DeleteZWHPickListDetail/{sn}")] + public async Task> DeleteZWHPickListDetail(string sn) + { + ResultModel result = new ResultModel(); + + try + { + string strSQL = $@"DELETE FROM SFIS_PTD.dbo.[ZWHPickListDetail] + WHERE [TaskStatus] = 'Picked' And [ShipmentSN] ='{sn}'"; + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + await connPTD.OpenAsync(); + } + + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + cmd.ExecuteNonQuery(); + } + + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + } #endregion #region "PTD007 扣帳作業" diff --git a/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs b/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs index d70b43bc..7846160a 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs @@ -119,4 +119,25 @@ namespace AMESCoreStudio.WebApi.Models.AMES #endregion + #region "PTD006 備貨作業" + + public class PTD006CommitDataModel + { + public string RecordTypeID { get; set; } + public string RecordNumber { get; set; } + public string RCLineNO { get; set; } + public string InputSN { get; set; } + public string ShipmentSN { get; set; } + public string ProductID { get; set; } + public string? EmplID { get; set; } + public string? ExtNotes { get; set; } + public string? OwnerPlantID { get; set; } + public string? OwnerCompanyID { get; set; } + public string? CreateDeptID { get; set; } + public string? CreatorID { get; set; } + public string? ModifyDeptID { get; set; } + public string? ModifierID { get; set; } + } + + #endregion }