diff --git a/AMESCoreStudio.Web/Controllers/PTDController.cs b/AMESCoreStudio.Web/Controllers/PTDController.cs index 6a65f80b..c494b26f 100644 --- a/AMESCoreStudio.Web/Controllers/PTDController.cs +++ b/AMESCoreStudio.Web/Controllers/PTDController.cs @@ -295,6 +295,24 @@ namespace AMESCoreStudio.Web.Controllers //将数据Json化并传到前台视图 return Json(new { data = result }); } + //public async Task CheckShipQty(string recordNumber, string lineNo, int addQty) + //{ + // var result = await _pcsApi.CheckShipQty(recordNumber, lineNo, addQty); + // if (result.DataTotal > 0) + // { + // return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + // } + // return Json(new Table() { count = 0, data = null, msg = result.Msg }); + //} + //public async Task CheckFlowRules(string recordType, string serialNumber) + //{ + // var result = await _pcsApi.CheckFlowRules(recordType, serialNumber); + // if (result.DataTotal > 0) + // { + // return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + // } + // return Json(new Table() { count = 0, data = null, msg = result.Msg }); + //} #endregion diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index 1d508e08..2990ff5f 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -2001,6 +2001,11 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpPost("api/WipInfos/PostPTD002Commit")] ITask> PostPTD002Commit([FromBody, RawJsonContent] string model); + //[WebApiClient.Attributes.HttpGet("api/WipInfos/CheckShipQtyAsyn")] + //ITask> CheckShipQty(string recordNumber, string lineNo, int addQty); + + //[WebApiClient.Attributes.HttpGet("api/WipInfos/CheckFlowRulesAsyn")] + //ITask> CheckFlowRules(string recordType, string serialNumber); #endregion #region "PTD006 備貨作業" diff --git a/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml b/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml index 1b9a6b53..a42dc808 100644 --- a/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml +++ b/AMESCoreStudio.Web/Views/PTD/PTD002.cshtml @@ -282,7 +282,7 @@ var material = document.getElementById('PartNumber'); var table = layui.table; var rowAmount = table.cache['query'].length; - + if (document.getElementById('PCSUnit').checked) { rowAmount++; @@ -387,8 +387,6 @@ tableData: tableData }; - console.log(JSON.stringify(postData)); - $.ajax({ url: '@Url.Action("PTD002_Commit", "PTD")', dataType: 'json', @@ -429,7 +427,7 @@ } else { layer.msg('扣帳失敗,原因:' + result.data.msg, { icon: 2 }); - } + } }, error: function (error) { layer.msg('扣帳失敗!原因:' + error.msg, { icon: 2 }); @@ -486,6 +484,7 @@ }); calculateRowCount(table.cache[tableId]); + }; function del(obj) { if (obj.data.itemNo) { @@ -517,6 +516,30 @@ }); } } + @*function CheckShipQty(recordNumber, lineNo, addQty){ + $.ajax( + { + url: "@Url.Action("CheckShipQty", "PTD")", + dataType: 'json', + data: { "recordNumber": recordNumber, "lineNo": lineNo, "addQty": addQty}, + type: 'get', + async: false, + success: function (result) + { + console.info("CheckShipQty OK"); + console.log(result); + if (result.msg == "OK") { + return true + } else { + return false ; + } + }, + error: function (result) + { + return false; + } + }); + }*@ //Excel匯入 function importExcel() { diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs index 635659e6..9f030e14 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -2995,6 +2995,14 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); string strLocation = Data.Location; string strCustomer = Data.Customer; string strCreateDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); + + //確認備貨數量 + string strDNNo = Data.TableData[0].DnNo; + string strLineNo = Data.TableData[0].LineNo; + int intAddQty = Data.TableData.Count(); + + CheckShipQty(strDNNo, strLineNo, intAddQty); + //若選擇 DOA 出貨(601DB)、DOA 還貨(657),需加填 RMANo if (strRecordType == "601DB" || strRecordType == "657") { @@ -3012,6 +3020,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); foreach (SNDataModel SNData in Data.TableData) { + CheckFlowRules(strRecordType, SNData.Sn); string strLatest; //確認此出貨序號是否有ZHistoryKeyDefine strSQL = $@"select Seed FROM [SFIS_PTD].[dbo].[ZHistoryKeyDefine] where serialnumber ='{SNData.Sn}'"; @@ -3112,6 +3121,220 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); return result; } + private bool CheckShipQty(string recordNumber, string lineNo, int addQty) + { + ResultModel result = new ResultModel(); + try + { + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + connPTD.Open(); + } + //查剩餘數 + string strSQL = $@"select ShipQty - + (SELECT count(1) + FROM [SFIS_PTD].[dbo].[ZWHPickListDetail] + where RecordNumber =DNNO and RCLineNO =DNLineNO and TaskStatus ='Picked') as surplusQty + from [SFIS_PTD].[dbo].ZDNDetail where DNNO ='{recordNumber}' and DNLineNO ='{lineNo}'"; + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + + using (var reader = cmd.ExecuteReader()) + { + if (reader.Read()) + { + if (addQty > Convert.ToInt32(reader["surplusQty"])) + throw new Exception("數量已超過,不允許新增!"); + } + } + } + + } + catch (Exception ex) + { + throw ex; + } + return true; + } + private bool CheckFlowRules(string recordType, string serialNumber) + { + ResultModel result = new ResultModel(); + try + { + //安勤連線 + PTDContext _ptd_context = new PTDContext(); + DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + if (connPTD.State != ConnectionState.Open) + { + connPTD.Open(); + } + //用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯 + bool bolChkFlow = false; + string strSQL = $@"Select [FormID] FROM [SFIS_PTD].[dbo].[PTDFlowRules] + where [ToID] ='{recordType}'"; + DataTable dtPTDFlowRules = new DataTable(); + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + + using (var reader = cmd.ExecuteReader()) + { + if (reader.HasRows) + { + dtPTDFlowRules = DataReaderToDataTable(reader); + } + } + } + + strSQL = @$"Select [RecordTypeID] FROM [SFIS_PTD].[dbo].[ZProductTrans] + where [SerialNumber] ='{serialNumber}' + Order by [RecordDate] Desc"; + using (var cmd = connPTD.CreateCommand()) + { + cmd.CommandText = strSQL; + using (var reader = cmd.ExecuteReader()) + { + if (reader.Read()) + { + foreach (DataRow dr in dtPTDFlowRules.Rows) + { + if (reader["RecordTypeID"].ToString() == dr["FormID"].ToString()) + { + bolChkFlow = true; + break; + } + } + } + } + } + + if (!bolChkFlow) + throw new Exception("序號:" + serialNumber + " 流程狀態不允許!"); + + } + catch (Exception ex) + { + throw ex; + } + return true; + } + + //[Route("[action]")] + //[HttpGet] + //public async Task> CheckShipQtyAsyn(string recordNumber, string lineNo, int addQty) + //{ + // ResultModel result = new ResultModel(); + // try + // { + // //安勤連線 + // PTDContext _ptd_context = new PTDContext(); + // DbConnection connPTD = _ptd_context.Database.GetDbConnection(); + // if (connPTD.State != ConnectionState.Open) + // { + // await connPTD.OpenAsync(); + // } + // //查剩餘數 + // string strSQL = $@"select ShipQty - + // (SELECT count(1) + // FROM [SFIS_PTD].[dbo].[ZWHPickListDetail] + // where RecordNumber =DNNO and RCLineNO =DNLineNO and TaskStatus ='Picked') as surplusQty + // from [SFIS_PTD].[dbo].ZDNDetail where DNNO ='{recordNumber}' and DNLineNO ='{lineNo}'"; + // using (var cmd = connPTD.CreateCommand()) + // { + // cmd.CommandText = strSQL; + + // using (var reader = await cmd.ExecuteReaderAsync()) + // { + // if (reader.Read()) + // { + // if (addQty > Convert.ToInt32(reader["surplusQty"])) + // throw new Exception("數量已超過,不允許新增!"); + // } + // } + // } + + // result.Success = true; + // result.Msg = "OK"; + // } + // catch (Exception ex) + // { + // result.Success = false; + // result.Msg = ex.Message; + // } + // return result; + //} + + //[Route("[action]")] + //[HttpGet] + //public async Task> CheckFlowRulesAsyn(string recordType, string serialNumber) + //{ + // ResultModel result = new ResultModel(); + // try + // { + // //安勤連線 + // 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; + // string strSQL = $@"Select [FormID] FROM [SFIS_PTD].[dbo].[PTDFlowRules] + // where [ToID] ='{recordType}'"; + // 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] ='{serialNumber}' + // 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("流程狀態不允許!"); + + // result.Success = true; + // result.Msg = "OK"; + // } + // catch (Exception ex) + // { + // result.Success = false; + // result.Msg = ex.Message; + // } + // return result; + //} #endregion #region "PTD003 作業查詢" @@ -3583,7 +3806,7 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); public async Task> GetZWHPickListDetail(string recordNumber,string? LineNO) { ResultModel result = new ResultModel(); - + //安勤連線 PTDContext _ptd_context = new PTDContext(); DbConnection connPTD = _ptd_context.Database.GetDbConnection(); @@ -3662,6 +3885,8 @@ and b.item_no = '{0}' and a.barcode_no = '{1}'", kp_no, barcode_no); await connPTD.OpenAsync(); } + CheckShipQty(Data.RecordNumber, Data.RCLineNO, 1); + //用ZProductTrans最新RecordType 檢查PTDFlowRules邏輯 bool bolChkFlow = false; strSQL = $@"Select [FormID] FROM [SFIS_PTD].[dbo].[PTDFlowRules]