From 2c5645166d55951f3dbf7999a57c029518de0fe7 Mon Sep 17 00:00:00 2001 From: Sai Date: Mon, 3 Jun 2024 02:27:15 +0800 Subject: [PATCH] 1. PTD --- .../Controllers/PTDController.cs | 159 +++++++++++++++-- AMESCoreStudio.Web/Views/PTD/PTD002.cshtml | 168 ++++++------------ .../Controllers/PTD/PTDController.cs | 2 +- .../Models/AMES/PTD101AMESModel.cs | 5 + 4 files changed, 206 insertions(+), 128 deletions(-) diff --git a/AMESCoreStudio.Web/Controllers/PTDController.cs b/AMESCoreStudio.Web/Controllers/PTDController.cs index d5fc54cb..321470f2 100644 --- a/AMESCoreStudio.Web/Controllers/PTDController.cs +++ b/AMESCoreStudio.Web/Controllers/PTDController.cs @@ -20,7 +20,7 @@ namespace AMESCoreStudio.Web.Controllers public readonly ISYS _sysApi; public readonly IPTD _ptdApi; - public PTDController(IPCS pcsApi, IKCS kcsApi, IBAS basApi, ISYS sysApi, IPTD ptdApi) + public PTDController(IPCS pcsApi, IKCS kcsApi, IBAS basApi, ISYS sysApi, IPTD ptdApi) { _pcsApi = pcsApi; _kcsApi = kcsApi; @@ -46,7 +46,7 @@ namespace AMESCoreStudio.Web.Controllers try { //組表頭 - IResultModel DNDetail = await _pcsApi.GetZDNDetail4PTD001(dnNo, lineNo); + IResultModel DNDetail = await _ptdApi.GetZDNDetail4PTD001(dnNo, lineNo); if (DNDetail.DataTotal > 0) { dataList = ""; @@ -104,7 +104,7 @@ namespace AMESCoreStudio.Web.Controllers } //組Detail - IResultModel result = await _pcsApi.GetDNInfo4PTD001(dnNo, lineNo); + IResultModel result = await _ptdApi.GetDNInfo4PTD001(dnNo, lineNo); if (result.DataTotal > 0) { @@ -269,8 +269,8 @@ namespace AMESCoreStudio.Web.Controllers List RecordTypes = await _ptdApi.GetRecordTypeInfo(); var allRecordType = new[] { "653", "632", "261", "262", "101R", "201", "202", "291", "292", "601", "601DB", "657", "952", "634" }; var filtered = from o in RecordTypes - where allRecordType.Contains(o.ID) - select o; + where allRecordType.Contains(o.ID) + select o; RecordTypes = filtered.ToList(); @@ -289,7 +289,7 @@ namespace AMESCoreStudio.Web.Controllers } [HttpPost] - public async Task GetZDNDetailJson(string recordNumber,string lineNo) + public async Task GetZDNDetailJson(string recordNumber, string lineNo) { var result = await _ptdApi.GetZDNDetail4PTD001(recordNumber, lineNo); @@ -308,8 +308,147 @@ namespace AMESCoreStudio.Web.Controllers [HttpPost] public async Task PTD002_CheckInputData(WebApi.Models.AMES.PTDCheckInputData model) { + var inputCheck = await CheckInputData(model); + if (!string.IsNullOrWhiteSpace(inputCheck)) + return Json(new Result() { success = false, msg = inputCheck }); + + // + var recordType = await _ptdApi.GetRecordTypeInfoById(model.RecordType); + + var zsnInfo = await _ptdApi.GetZSNInfoByIntervalNumber(model.FrontSN, model.EndSN); - return Json(new { data = "" }); + if (recordType.FirstOrDefault().Status == "WO") + { + + } + var datas = new List(); + foreach (var item in zsnInfo) + { + var newRowData = new + { + dnNo = model.RecordNumber, + lineNo = model.LineNo, + material = model.ProductId, + sn = item.serialNumber + }; + datas.Add(newRowData); + } + + return Json(new Result() { success = true, msg = "", data = datas }); + + return Json(new Result() { success = false, msg = "AAA" }); + } + + /// + /// 確認輸入資料是否正確 + /// + /// + /// + public async Task CheckInputData(WebApi.Models.AMES.PTDCheckInputData model) + { + // RecordNumber + if (string.IsNullOrWhiteSpace(model.RecordNumber)) + { + return "請輸入 RecordNumber"; + } + + // LineNo + if (string.IsNullOrWhiteSpace(model.LineNo)) + { + return "請輸入 LineNo"; + } + + //var recordType = await _ptdApi.GetRecordTypeInfoById(model.RecordType); + //if (recordType.Any()) + //{ + // var recordInfoItem = recordType.FirstOrDefault(); + // if (model.RecordNumber.Length != int.Parse((string)recordInfoItem.length)) + // return "RecordNumber長度與設定的長度不符,請在確認"; + + // if (!model.RecordNumber.StartsWith((string)recordInfoItem.prefixCode)) + // return "RecordNumber單據號碼開頭與設定開頭不符,請在確認"; + //} + //else + //{ + // return "請維護RecordNumber單投說明表"; + //} + + // ProductId + if (string.IsNullOrWhiteSpace(model.ProductId)) + { + return "請輸入 料號"; + } + + // 判斷RecordNumber 是601DB or 657 需要填 RMANo + if (model.RecordType == "601DB" || model.RecordType == "657") + { + if (string.IsNullOrWhiteSpace(model.RmaNo)) + return "請輸入 RMANo"; + } + + // 判斷是簍有輸入序號 + if (string.IsNullOrWhiteSpace(model.FrontSN) && string.IsNullOrWhiteSpace(model.SNData)) + { + return "請輸入 Scanner"; + } + + // 判斷序號區間格式正確 + if (!string.IsNullOrWhiteSpace(model.FrontSN)) + { + // 沒有指定單一序號就判斷 備貨量及流水碼 + if (model.PcsUnit == "N") + { + var sequential = model.Sequential; + var frontLength = model.FrontSN.Length; + var endLength = model.EndSN?.Length ?? 0; + var frontSequential = 0; + + // 流水碼長度不符 + if (sequential >= frontLength + 1) + return "請確認 流水碼長度是否正確"; + + // 流水碼格式不符 + if (!int.TryParse(model.FrontSN.Substring(frontLength - sequential, sequential), out _)) + { + return "請確認 序號區間流水碼格式是否正確"; + } + + frontSequential = int.Parse(model.FrontSN.Substring(frontLength - sequential, sequential)); + + // 當沒有輸入結束序號區間,就判斷備貨量 + if (string.IsNullOrWhiteSpace(model.EndSN)) + { + if (model.StockQty <= 0) + { + return "請輸入 備貨量"; + } + + // 判斷備貨量 加總 大於 流水碼數 + if ((frontSequential + model.StockQty - 1).ToString().Length > sequential) + { + return "備貨量加總超過設定流水碼長度,請在確認"; + } + } + else + { + // 確認開始序號與結束序號是否長度一致 + if (frontLength != endLength) + { + return "請確認 起始序號與結束序號區間長度不一致"; + } + + // 判斷前綴碼是否一致 + if (model.FrontSN.Substring(0, frontLength - sequential) != model.EndSN.Substring(0, frontLength - sequential)) + { + return "請確認 起始序號與結束序號區間前綴碼不一致"; + } + } + } + + } + + + return ""; } //public async Task CheckShipQty(string recordNumber, string lineNo, int addQty) //{ @@ -363,7 +502,7 @@ namespace AMESCoreStudio.Web.Controllers return View(); } - public async Task PTD003QueryAsync(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd, int autoLoad = 0 , string RBU = null) + public async Task PTD003QueryAsync(string recordType, string recordNumber, string lineNo, string materialNo, string shippingSN, string dateStart, string dateEnd, int autoLoad = 0, string RBU = null) { //if (recordNumber == null || recordNumber == "") // return Json(new Table() { count = 0, data = null }); @@ -375,7 +514,7 @@ namespace AMESCoreStudio.Web.Controllers { return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); } - return Json(new Table() { count = 0, data = null, msg =result.Msg }); + return Json(new Table() { count = 0, data = null, msg = result.Msg }); } [HttpPost] @@ -641,7 +780,7 @@ namespace AMESCoreStudio.Web.Controllers #endregion #region "PTD007 扣帳作業" - public async Task PTD007() + public async Task PTD007() { if (Request.Cookies["_AMESCookie"] != null) { diff --git a/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml b/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml index b5ff0052..d6ee21d1 100644 --- a/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml +++ b/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml @@ -108,8 +108,8 @@
- - + +
@@ -243,6 +243,7 @@ lineNo.focus(); } }); + $('#lineNo').on('keypress', function (event) { if (event.keyCode == 13) { @@ -278,6 +279,7 @@ getItemDesc(document.getElementById('PartNumber').value); } }); + $('#frontSN').on('keypress', function (event) { if (event.keyCode == 13) { checkInputData(); @@ -286,97 +288,33 @@ $('#endSN').on('keypress', function (event) { if (event.keyCode == 13) { - var frontSN = document.getElementById('frontSN'); - var endSN = document.getElementById('endSN'); - var dnNo = document.getElementById('recordNumber'); - var lineNo = document.getElementById('lineNo'); - var material = document.getElementById('PartNumber'); - var table = layui.table; - var rowAmount = table.cache['query'].length; - - var prefixCode = frontSN.value.slice(0, -5); - var currentSN = parseInt(frontSN.value.slice(-5)); - - while (currentSN <= parseInt(endSN.value.slice(-5))) { - rowAmount++; - var newRowData = { - itemNo: rowAmount, - dnNo: dnNo.value, - lineNo: lineNo.value, - material: material.value, - sn: prefixCode + currentSN.toString().padStart(5, "0") - }; - // Add the new row data to the table - hg.table.addRow('query', newRowData); - currentSN++; - } - + checkInputData(); frontSN.focus(); frontSN.select(); - } }); + $('#SNData').on('keypress', function (event) { if (event.keyCode == 13) { - var SNData = document.getElementById('SNData'); - var dnNo = document.getElementById('recordNumber'); - var lineNo = document.getElementById('lineNo'); - var material = document.getElementById('PartNumber'); - var table = layui.table; - var rowAmount = table.cache['query'].length; - if (SNData.value.trim() == "") { - hg.msg('SN不得為空!'); - return; - } - - var arr = SNData.value.split('\n'); - $.each(arr, function (index, SN) { - rowAmount++; - var newRowData = { - itemNo: rowAmount, - dnNo: dnNo.value, - lineNo: lineNo.value, - material: material.value, - sn: SN - }; - // Add the new row data to the table - hg.table.addRow('query', newRowData); - }); - + checkInputData(); SNData.select(); event.preventDefault(); } }); - $('#StockQty').on('keypress', function (event) { - if (event.keyCode == 13 && document.getElementById('pcs').checked && !document.getElementById('PCSUnit').checked) { - var frontSN = document.getElementById('frontSN'); - var StockQty = document.getElementById('StockQty'); - var dnNo = document.getElementById('recordNumber'); - var lineNo = document.getElementById('lineNo'); - var material = document.getElementById('PartNumber'); - var table = layui.table; - var rowAmount = table.cache['query'].length; - - var prefixCode = frontSN.value.slice(0, -5); - var currentSN = parseInt(frontSN.value.slice(-5)); - - for (var i = 1; i <= parseInt(StockQty.value); i++) { - rowAmount++; - var newRowData = { - itemNo: rowAmount, - dnNo: dnNo.value, - lineNo: lineNo.value, - material: material.value, - sn: prefixCode + currentSN.toString().padStart(5, "0") - }; - // Add the new row data to the table - hg.table.addRow('query', newRowData); - currentSN++; - } + $('#StockQty').on('keypress', function (event) { + if (event.keyCode == 13) { + checkInputData(); frontSN.focus(); frontSN.select(); + } + }); + $('#sequential').on('keypress', function (event) { + if (event.keyCode == 13) { + checkInputData(); + frontSN.focus(); + frontSN.select(); } }); @@ -390,18 +328,11 @@ var sequential = document.getElementById('sequential').value; var rMANo = document.getElementById('RMANo').value; var stockUnit = document.querySelector('input[name="StockUnit"]:checked').value; - var username = getCookie("UserID").value; + var pcsUnit = document.getElementById('PCSUnit').checked ? 'Y' : 'N'; var workCenter = document.getElementById('WorkCenter').value; var rbu = document.getElementById('RBU').value; var stockQty = document.getElementById('StockQty').value; - var table = layui.table; - var rowAmount = table.cache['query'].length; var sNData = document.getElementById('SNData').value; - var tableData = layui.table.cache['query']; - //if (isSNAlreadyExist(tableId, rowData.sn)) { - // hg.msg('SN 已存在!'); - // return; // Do not add the row - //} var postData = { RecordType: recordType, @@ -412,6 +343,7 @@ LineNo: lineNo, ProductId: material, StockUnit: stockUnit, + PcsUnit: pcsUnit, FrontSN: frontSN, EndSN: endSN, StockQty: stockQty, @@ -427,22 +359,29 @@ data: serializedData, success: function (res) { if (res.success) { - //// 重新加载表格数据 - //layui.table.reload('query', { - // data: rowData, - // page: false, - // limit: 2000 - //}); - //layer.msg('備貨成功!', { icon: 1 }); - //calculateRowCount(tableData); + // 用来统计重复的SN + var duplicateSNs = []; + + res.data.forEach(function (item) { + if (isSNAlreadyExist('query', item.sn)) { + // 将重复的SN加入到duplicateSNs数组中 + duplicateSNs.push(item.sn); + } else { + hg.table.addRow('query', item); + } + }); + if (duplicateSNs.length > 0) { + // 将所有重复的SN一次性显示 + var duplicateSNsMessage = duplicateSNs.join(', '); + layer.msg(`以下SN已存在: ${duplicateSNsMessage}`, { icon: 2, time: 5000}); + } } else { - hg.msg('備貨失敗,原因:' + res.msg); + hg.msg('加入失敗:' + res.msg); } - } - , + }, error: function (error) { - hg.msg('備貨失敗!原因:' + error.msg); + hg.msg('加入失敗:' + error.msg); return; } }); @@ -460,11 +399,6 @@ var tableData = layui.table.cache['query']; - - //if (customer === "") { - // hg.msg('Customer不得為空!'); - // return; // Do not add the row - //} if (material === "") { hg.msg('料號不得為空!'); return; // Do not add the row @@ -531,6 +465,7 @@ }); }); + // 取料號DESC function getItemDesc(itemNo) { $.ajax({ url: "/BAS/GetMaterialItemByItemNO", @@ -549,6 +484,7 @@ }); }; + // 判斷Table SN是否有重複 function isSNAlreadyExist(tableId, sn) { var table = layui.table; var currentData = table.cache[tableId]; @@ -560,6 +496,8 @@ return isExist; } + + // 刷入數量 function calculateRowCount(table) { var RowCount = table.length; $("#rowCount").html("刷入數量: " + RowCount + " pcs"); @@ -568,11 +506,12 @@ hg.table.addRow = function (tableId, rowData) { // Get the table instance var table = layui.table; + if (isSNAlreadyExist(tableId, rowData.sn)) { - // Handle the case where SN already exists - layer.msg('SN 已存在!', { icon: 2 }); - return; // Do not add the row + // 如果SN已经存在,返回,不添加该行 + return; } + // Add the new row data to the table table.reload(tableId, { data: [rowData].concat(table.cache[tableId]), @@ -585,14 +524,14 @@ }; function del(obj) { - if (obj.data.itemNo) { + if (obj.data.sn) { hg.confirm("SN:" + obj.data.sn + ",確定要刪除嗎?", function () { // 获取表格数据 var tableData = layui.table.cache['query']; // 找到要删除的行的索引 var rowIndex = tableData.findIndex(function (row) { - return row.itemNo === obj.data.itemNo; + return row.sn === obj.data.sn; }); // 从表格数据中删除该行 @@ -669,9 +608,9 @@ var tableCols = [[ { - field: 'itemNo', - width: 100, - title: 'Item(項次)' + field: 'sn', + title: 'SN', + width: 150 }, { field: 'dnNo', @@ -688,11 +627,6 @@ title: 'Material(料號)', width: 150 }, - { - field: 'sn', - title: 'SN', - width: 150 - }, { field: 'delete', width: 100, diff --git a/AMESCoreStudio.WebApi/Controllers/PTD/PTDController.cs b/AMESCoreStudio.WebApi/Controllers/PTD/PTDController.cs index 825bceb9..e186b4b1 100644 --- a/AMESCoreStudio.WebApi/Controllers/PTD/PTDController.cs +++ b/AMESCoreStudio.WebApi/Controllers/PTD/PTDController.cs @@ -117,7 +117,7 @@ namespace AMESCoreStudio.WebApi.Controllers.PTD AND LEN(SerialNumber) = LEN(@strNumber) "; DynamicParameters p = new DynamicParameters(); p.Add("strNumber", strNumber); - p.Add("endNuber", endNumber); + p.Add("endNumber", endNumber); var q = await ptdConnection.QueryAsync(query, p); return q.ToList(); } diff --git a/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs b/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs index 82f9e66d..8f3f57bb 100644 --- a/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs +++ b/AMESCoreStudio.WebApi/Models/AMES/PTD101AMESModel.cs @@ -171,6 +171,11 @@ namespace AMESCoreStudio.WebApi.Models.AMES /// public string EndSN { get; set; } + /// + /// Begin=End 單一序號 + /// + public string PcsUnit { get; set; } + /// /// 備貨量 ///