From a3236b51b5691b8c47f4ebaf1d885314a4bab3bd Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期二, 13 八月 2024 11:17:18 +0800 Subject: [PATCH] 拼箱功能开发 --- Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs | 2257 ++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 1,378 insertions(+), 879 deletions(-) diff --git a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs index 4558ce5..7c124fd 100644 --- a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs +++ b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs @@ -261,7 +261,7 @@ { throw new Exception("褰撳墠鍗曞彿瀛樺湪寮傚父锛�"); } - + return notice; } @@ -310,14 +310,14 @@ { throw new Exception("绌烘墭鐩樻暟閲忎笉鍙负绌�"); } - var stockDetail = Db.Queryable<DataStockDetail>().Where(m=>m.IsDel == "0" && m.PalletNo == model.PalletNo).ToList(); + var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == model.PalletNo).ToList(); if (stockDetail.Count > 0) { throw new Exception("褰撳墠鎵樼洏鍦ㄥ簱鍐呭凡鏈夊簱瀛樹俊鎭紝璇锋牳瀹�"); } - + //鑾峰彇鎵樼洏淇℃伅 - var pallet = Db.Queryable<SysPallets>().First(m=>m.IsDel == "0" && m.PalletNo == model.PalletNo); + var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); if (pallet == null) { throw new Exception("鏈煡璇㈠埌鎵樼洏淇℃伅"); @@ -327,11 +327,11 @@ throw new Exception("鎵樼洏鐘舵�佷笉鑳芥湭浣跨敤鐘舵��"); } //鑾峰彇鎵樼洏淇℃伅 - var sku = Db.Queryable<SysMaterials>().First(m=>m.IsDel == "0" && m.SkuNo == "100099"); + var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == "100099"); var pNum = 0; var bNum = 0; - new Common().GetPackQtyInfo(sku.PackagNo,ref pNum,ref bNum); + new Common().GetPackQtyInfo(sku.PackagNo, ref pNum, ref bNum); var datetime = Db.GetDate(); Db.BeginTran(); @@ -352,8 +352,8 @@ LotNo = "", LotText = "", SupplierLot = "", - InspectMark ="0", //0 鍚� 1 鏄� - BitPalletMark = pNum== (int)model.Qty? "0":"1", + InspectMark = "0", //0 鍚� 1 鏄� + BitPalletMark = pNum == (int)model.Qty ? "0" : "1", IsBale = "0", IsBelt = "0", CreateUser = (int)model.CreateUser, @@ -372,7 +372,7 @@ Status = "2", CompleteTime = DateTime.Now, Qty = (int)model.Qty, - FullQty = pNum, + FullQty = pNum, SkuNo = sku.SkuNo, SkuName = sku.PackagNo, LotNo = "", @@ -392,7 +392,7 @@ Db.Insertable(modelbb).ExecuteCommand(); //娣诲姞搴撳瓨 - + #region 搴撳瓨鏄庣粏 var sd1 = new DataStockDetail() { @@ -464,7 +464,7 @@ CreateUser = 0, CreateTime = datetime - }; + }; Db.Insertable(box2).ExecuteCommand(); #endregion @@ -541,12 +541,12 @@ throw new Exception("褰撳墠鎵樼洏宸叉湁浠诲姟锛岃鍏堝彇娑堜换鍔″啀瑙g粦鎵樼洏"); } //鑾峰彇浠诲姟淇℃伅 - var logtask = Db.Queryable<LogTask>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" &&( a.Status == "1" || a.Status == "0")); + var logtask = Db.Queryable<LogTask>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && (a.Status == "1" || a.Status == "0")); if (logtask != null) { throw new Exception("璇ユ墭鐩樻湁浠诲姟浠诲姟姝e湪鎵ц 璇锋牳瀹烇紒"); } - + //鑾峰彇绠辩爜淇℃伅 var box = Db.Queryable<BllBoxInfo>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && a.BindNo == bind.Id); //鍒ゆ柇绌烘墭鍏ュ簱鐨勬墭鐩樻槸鍚︽湁璇ユ墭鐩� @@ -555,8 +555,8 @@ strMsg = "璇ユ墭鐩樹笉鏄┖鎵樻墭鐩� 鎴栨湭缁戝畾 璇锋牳瀹炴墭鐩�"; return strMsg; } - - + + Db.BeginTran(); var time = DateTime.Now; @@ -589,13 +589,13 @@ Db.Insertable(modelpb).ExecuteCommand(); //鍒犻櫎搴撳瓨淇℃伅 - var stockDetail = Db.Queryable<DataStockDetail>().First(m=>m.IsDel == "0" && m.PalletNo == upBindPalletNo); + var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == upBindPalletNo); Db.Deleteable(stockDetail).ExecuteCommand(); var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.StockDetailId == stockDetail.Id).ToList(); Db.Deleteable(boxInfo).ExecuteCommand(); var stock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == box.SkuNo); stock.Qty -= bind.Qty; - if (stock.Qty==0) + if (stock.Qty == 0) { Db.Deleteable(stock).ExecuteCommand(); } @@ -607,8 +607,8 @@ { Db.Updateable(stock).ExecuteCommand(); } - - + + // 鏇存敼鎵樼洏浣跨敤鐘舵�� string sqlStr = string.Empty; sqlStr = $"update SysPallets set Status = '0' where PalletNo = '{upBindPalletNo}';"; @@ -773,10 +773,10 @@ throw new Exception("-1:鏈幏鍙栧埌瀵瑰簲鍏ュ簱鍗曞崟鎹槑缁嗕俊鎭紝璇锋牳瀹烇紒"); } var bind2 = Db.Queryable<BllPalletBind>().Where(a => a.IsDel == "0" && a.Id != model.Id && model.ASNDetailNo == noticeDetail.Id).ToList(); - + Db.BeginTran(); - if (bind2.Count(m=>m.InspectMark == "1")>0) + if (bind2.Count(m => m.InspectMark == "1") > 0) { noticeDetail.IsSampling = "1"; } @@ -789,9 +789,9 @@ //鍒ゆ柇宸茬粍鏁伴噺鏄惁涓�0 if (noticeDetail.FactQty == 0) { - + noticeDetail.Status = "0"; //鍏ュ簱鍗曟槑缁嗙姸鎬� - + //鑾峰彇鐘舵�佷笉鏄瓑寰呮墽琛岀殑鏄庣粏淇℃伅 var count = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.Id != noticeDetail.Id && m.ASNNo == bind.ASNNo && m.Status != "0"); if (count == 0) @@ -1901,7 +1901,7 @@ { throw new Exception("绠辩爜淇℃伅涓嶅瓨鍦�!"); } - + return models; } catch (Exception ex) @@ -2454,9 +2454,9 @@ } } - + int isTextTable = model.TableType; - + #endregion Db.BeginTran(); @@ -2648,7 +2648,7 @@ //box.Qty = box.Qty; //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1"; - + factQty += box.Qty; boxFullQty += box.Qty; if (box.InspectMark == "1") //鍒ゆ柇鏄惁鍙栨牱 @@ -2684,7 +2684,7 @@ if (isSample == "1") { bind.InspectMark = "1"; - bind.SamplingQty = bind.SamplingQty == null? sampleQty : bind.SamplingQty + sampleQty; + bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; } Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); @@ -2717,7 +2717,7 @@ var sqlString2 = string.Empty; sqlString2 += $"update BllArrivalNotice set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='0';"; sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='0';"; - + Db.Ado.ExecuteCommand(sqlString2); } else if (detail.Status == "1") @@ -2725,7 +2725,7 @@ var sqlString2 = string.Empty; sqlString2 += $"update BllArrivalNotice set UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='1';"; sqlString2 += $"update BllArrivalNoticeDetail set UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='1';"; - + Db.Ado.ExecuteCommand(sqlString2); } @@ -2780,7 +2780,7 @@ if (string.IsNullOrEmpty(model.LotNo)) { - throw new Exception("鐗╂枡涓嶄负绌�!"); + throw new Exception("鐗╂枡涓嶄负绌�!"); } else { @@ -2839,7 +2839,7 @@ } //鍒ゆ柇鎵樼洏鏄惁鍦ㄥ簱澶� var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); - if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo)) + if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo)) { throw new Exception("璇ユ墭鐩樺凡鏈夊偍浣嶄俊鎭紝璇锋牳瀹烇紒"); } @@ -2847,7 +2847,7 @@ { throw new Exception("璇ユ墭鐩樺湪搴撳瓨宸叉湁鍏跺畠鐗╂枡鎵规淇℃伅锛岃鏍稿疄锛�"); } - + #region 鍖呰 var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0"); var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo); @@ -2859,39 +2859,39 @@ //鍒ゆ柇鏄惁鏍囩椤靛垽鏂寘瑁� //if (isTextTable == 0) //{ - if (pack == null) - { - throw new Exception("鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!"); - } - if (pack.L5Num.HasValue) - { - pNum = (int)pack.L5Num; - bNum = (int)pack.L4Num; - } - else if (pack.L4Num.HasValue) - { - pNum = (int)pack.L4Num; - bNum = (int)pack.L3Num; - } - else if (pack.L3Num.HasValue) - { - pNum = (int)pack.L3Num; - bNum = (int)pack.L2Num; - } - else if (pack.L2Num.HasValue) - { - pNum = (int)pack.L2Num; - bNum = (int)pack.L1Num; - } - else if (pack.L1Num.HasValue) - { - pNum = (int)pack.L1Num; - bNum = (int)pack.L1Num; - } - if (pNum == 0 || bNum == 0) - { - throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒"); - } + if (pack == null) + { + throw new Exception("鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!"); + } + if (pack.L5Num.HasValue) + { + pNum = (int)pack.L5Num; + bNum = (int)pack.L4Num; + } + else if (pack.L4Num.HasValue) + { + pNum = (int)pack.L4Num; + bNum = (int)pack.L3Num; + } + else if (pack.L3Num.HasValue) + { + pNum = (int)pack.L3Num; + bNum = (int)pack.L2Num; + } + else if (pack.L2Num.HasValue) + { + pNum = (int)pack.L2Num; + bNum = (int)pack.L1Num; + } + else if (pack.L1Num.HasValue) + { + pNum = (int)pack.L1Num; + bNum = (int)pack.L1Num; + } + if (pNum == 0 || bNum == 0) + { + throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒"); + } //} #endregion @@ -2911,7 +2911,7 @@ } #endregion //liudl && m.Status != "2" 缁勭洏鏃㈠叆搴撳畬鎴愭棤闇�鏍规嵁鎵樼洏鐘舵�佸垽鏂� - var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo); + var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo); var bindId = 0; if (bind == null) { @@ -2988,7 +2988,7 @@ Db.Updateable(sd1).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 } - else + else { // 搴撳瓨涓嶅瓨鍦� 鎻掑叆鏁版嵁 sd1 = new DataStockDetail() @@ -3059,7 +3059,7 @@ } //娣诲姞搴撳瓨鏄庣粏 sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity(); - } + } #endregion #region 绠辩爜淇℃伅 @@ -3260,7 +3260,7 @@ #endregion #region 搴撳瓨鏄庣粏 - sd1.Qty = bind.Qty; + sd1.Qty = bind.Qty; //鏇存敼搴撳瓨鏄庣粏鏁伴噺 Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand(); #endregion @@ -3277,7 +3277,7 @@ { dataStock.Qty += model.SkuQty; } - + if (bind.InspectMark == "1") { dataStock.IsSampling = bind.InspectMark; @@ -3352,14 +3352,12 @@ } } - //JC26缁戝畾鎵樼洏 璐存爣鐗╂枡 public void BindPalletPasteCode(PdaPalletBindVm model, int userId) { try { #region 鍒ゆ柇 - //0锛氭垚鍝佸叆搴� 1锛氶噰璐叆搴� 3锛氶��璐у叆搴� 4锛氳溅闂翠綑鏂欏叆搴� 5锛氬叾瀹冨叆搴� 6锛氫唬鍌ㄥ叆搴� var TypeLot = "5, 6"; @@ -3375,7 +3373,6 @@ { throw new Exception("鎵樼洏鍙蜂笉鍙负绌�!"); } - //鏍规嵁鍗曟嵁鍙疯幏鍙栧叆搴撳崟鎬诲崟 var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo); if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2") @@ -3397,20 +3394,16 @@ } else { - if (!TypeLot.Contains(notice.Type)) - { - throw new Exception("鐗╂枡鎵规涓嶅彲涓虹┖!"); - } - - model.LotNo = ""; + throw new Exception("鐗╂枡鎵规涓嶅彲涓虹┖!"); } } + //鍒ゆ柇绠辩爜淇℃伅 if (string.IsNullOrEmpty(model.BoxNo)) { throw new Exception("绠辩爜淇℃伅涓嶅彲涓虹┖!"); } - + //鏄惁杩炵画缁勬墭 0锛氬惁 1锛氭槸 if (model.IsContinue == "1") { if (string.IsNullOrWhiteSpace(model.TailBoxNo)) @@ -3418,18 +3411,14 @@ throw new Exception("寮�鍚繛缁粍鎵樻椂锛屽熬绠辩爜淇℃伅涓嶅彲涓虹┖!"); } } - - #endregion - var comTime = DateTime.Now; - - //鎵樼洏鏄惁瀛樺湪 + //鎵樼洏淇℃伅鏄惁瀛樺湪 var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); if (pallet == null) { throw new Exception("鏈煡璇㈠埌鎵樼洏淇℃伅锛岃鏍稿疄锛�"); } - // 楠岃瘉鍏ュ簱鍗曟槑缁嗘槸鍚﹀瓨鍦� + //楠岃瘉鍏ュ簱鍗曟槑缁嗘槸鍚﹀瓨鍦� var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo)); if (detail == null) { @@ -3441,15 +3430,21 @@ { throw new Exception("璇ユ墭鐩樺凡鏈夊偍浣嶄俊鎭紝璇锋牳瀹烇紒"); } - if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo)) + /*if (stockDetail != null && stockDetail.SkuNo != detail.SkuNo) { - throw new Exception("璇ユ墭鐩樺湪搴撳瓨宸叉湁鍏跺畠鐗╂枡鎵规淇℃伅锛岃鏍稿疄锛�"); - } + throw new Exception("璇ユ墭鐩樺湪搴撳瓨宸叉湁鍏跺畠鐗╂枡淇℃伅锛岃鏍稿疄锛�"); + }*/ + #endregion + + //寮�鍚簨鍔� + Db.BeginTran(); + //褰撳墠鏃堕棿 + var comTime = DateTime.Now; #region 鍖呰 - + var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0"); var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo); - var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo); // liudl 鐢盨ku鍖呰缂栧彿鍙樻洿涓哄叆搴撳崟鏄庣粏鍖呰缂栧彿 + var pack = package.First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo); // liudl 鐢盨ku鍖呰缂栧彿鍙樻洿涓哄叆搴撳崟鏄庣粏鍖呰缂栧彿 var pNum = 0;//鎵樼洏鐗╁搧鏁伴噺 var bNum = 0;//绠辩爜鐗╁搧鏁伴噺 @@ -3487,7 +3482,7 @@ { throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒"); } - + #endregion #region 楠岃瘉鏄惁鍏佽绔嬪簱鍚屾墭鐩樹笉鍚岀墿鏂欏叆搴撴垨鍚屾墭鐩樺悓鐗╂枡涓嶅悓鎵规鍏ュ簱 @@ -3505,166 +3500,16 @@ } } #endregion - //liudl && m.Status != "2" 缁勭洏鏃㈠叆搴撳畬鎴愭棤闇�鏍规嵁鎵樼洏鐘舵�佸垽鏂� - var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo); - var bindId = 0; - if (bind == null) - { - bind = new BllPalletBind - { - ASNNo = model.AsnNo, - ASNDetailNo = (int)model.AsnDetailId, - PalletNo = model.PalletNo, - - Qty = model.SkuQty, - FullQty = pNum, - Status = "2",//鍏ュ簱瀹屾垚 - Type = "0", - LotNo = model.LotNo, - LotText = detail.LotText, - SupplierLot = detail.SupplierLot, - //InspectMark = model.IsSample, //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 - //SamplingQty = 0, //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 - BitPalletMark = "1", - IsBale = "0", - IsBelt = "0", - CreateUser = userId, - Demo = model.Demo, - - }; - // 鎻掑叆鎵樼洏缁戝畾琛� - bindId = Db.Insertable(bind).ExecuteReturnIdentity(); - } - else - { - bindId = bind.Id; - bind.Qty += model.SkuQty; - } - if (bind.Qty < 0) - { - throw new Exception("缁勭洏鏁伴噺涓嶈兘灏忎簬0"); - } - #region 搴撳瓨鏄庣粏 - //鑾峰彇璇ユ壒娆℃渶缁堣川妫�缁撴灉 - BllQualityInspect quality = new BllQualityInspect(); - //鍒ゆ柇鏄惁涓洪��璐у叆搴撳崟 - if (notice.Type == "3") - { - quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); - } - else - { - quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); - } - var tags = "0"; - if (notice.Type == "3" || notice.Type == "4") - { - tags = "1"; - } - - // 鍒ゆ柇搴撳瓨鏄庣粏鏄惁宸叉湁姝ゆ墭鐩樹俊鎭� - var sd1 = Db.Queryable<DataStockDetail>() - .First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo); - var sdId1 = 0; - if (sd1 != null) - { - sdId1 = sd1.Id; - // 搴撳瓨宸插瓨鍦� 鏇存柊鏁版嵁 - sd1.Qty = bind.Qty; - sd1.CompleteTime = comTime; - sd1.UpdateUser = userId; - sd1.UpdateTime = comTime; - - Db.Updateable(sd1).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 - } - else - { - // 搴撳瓨涓嶅瓨鍦� 鎻掑叆鏁版嵁 - sd1 = new DataStockDetail() - { - LotNo = bind.LotNo, - LotText = bind.LotText, - SupplierLot = bind.SupplierLot, - SkuNo = sku.SkuNo, - SkuName = sku.SkuName, - Standard = sku.Standard, - Qty = bind.Qty, - LockQty = 0, - FrozenQty = 0, - InspectQty = 0, - ASNNo = bind.ASNNo, - ASNDetailNo = bind.ASNDetailNo, - WareHouseNo = "",//鎵�灞炰粨搴� - RoadwayNo = "",//鎵�灞炲贩閬� - AreaNo = "",//鎵�灞炲尯鍩� - LocatNo = "",//鍌ㄤ綅鍦板潃 - PalletNo = bind.PalletNo, - PalletNo2 = bind.PalletNo2, - PalletNo3 = bind.PalletNo3, - PalletTags = tags, - CompleteTime = comTime, - ProductionTime = bind.ProductionTime, - ExpirationTime = bind.ExpirationTime, - Status = "0", - InspectMark = bind.InspectMark, - InspectStatus = sku.IsInspect, - BitPalletMark = bind.BitPalletMark, - PackagNo = detail.PackagNo, //liudl 鐢眘ku鐨勫寘瑁呯紪鍙峰彉涓哄叆搴撳崟鏄庣粏鐨勫寘瑁呯紪鐮� - IsBale = bind.IsBale, - IsBelt = bind.IsBelt, - - IsDel = "0", - CreateUser = 0, - CreateTime = comTime - }; - - //缁存姢搴撳瓨鏄庣粏璐т富/渚涘簲鍟嗕俊鎭� - if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 - { - sd1.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 - sd1.OwnerName = notice.CustomerName;//璐т富鍚嶇О - } - else if (notice.Type == "1" || notice.Type == "5")//1:閲囪喘鍏ュ簱,2:鍏跺畠鍏ュ簱 - { - sd1.SupplierNo = notice.CustomerNo;//渚涘簲鍟嗙紪鐮� - sd1.SupplierName = notice.CustomerName;//渚涘簲鍟嗗悕绉� - } - if (quality != null) - { - //淇敼鍚堟牸涓嶅悎鏍兼暟閲� - if (quality.IsQualified == "1") //鍚堟牸 - { - //澧炲姞鍚堟牸鏁伴噺 - quality.PassQty += bind.Qty; - sd1.InspectStatus = "1"; - } - else if (quality.IsQualified == "0") //涓嶅悎鏍� - { - //澧炲姞涓嶅悎鏍兼暟閲� - quality.FailQty += bind.Qty; - sd1.InspectStatus = "2"; - } - Db.Updateable(quality).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 - } - //娣诲姞搴撳瓨鏄庣粏 - sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity(); - } - #endregion #region 绠辩爜淇℃伅 var msgStr = $"绠卞彿涓簕model.BoxNo}"; var boxInfoList = new List<BllBoxInfo>(); - + //棣栫 var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).ToList(); if (boxInfo.Count == 0) { throw new Exception("绠辩爜淇℃伅涓嶅瓨鍦�!"); - } - boxInfo = boxInfo.Where(m => m.Status == "0").ToList(); - if (boxInfo.Count == 0) - { - throw new Exception("绠辩爜宸茶浣跨敤!"); } boxInfoList.AddRange(boxInfo); //鏄惁杩炵画缁勬墭 @@ -3676,238 +3521,891 @@ { throw new Exception("灏剧鐮佷俊鎭笉瀛樺湪!"); } - boxInfo2 = boxInfo2.Where(m => m.Status == "0").ToList(); - if (boxInfo2.Count == 0) - { - throw new Exception("灏剧绠辩爜宸茶浣跨敤!"); - } boxInfoList.AddRange(boxInfo2); - var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; "; + var sql = $"select * from BllBoxInfo where IsDel = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; "; var list = Db.Ado.SqlQuery<BllBoxInfo>(sql); boxInfoList.AddRange(list); msgStr += $"灏剧鍙蜂负{model.TailBoxNo}"; } - + //鍜岄�夋嫨鐨勬壒娆″悓鎵规鐨勭鐮佷俊鎭� + var sameBoxInfoList = boxInfoList.Where(w => w.LotNo == model.LotNo).ToList(); + //鍜岄�夋嫨鐨勬壒娆′笉鍚屾壒娆$殑绠辩爜淇℃伅锛堟嫾绠辨壒娆★級 + var notBoxInfoList = boxInfoList.Where(w => w.LotNo != model.LotNo).ToList(); + //鎷肩鏁伴噺(鍜岄�夋嫨鐨勬壒娆′笉鍚屾壒娆$殑绠辩爜鏁伴噺) + decimal pinBoxQty = notBoxInfoList.Sum(s => s.Qty); #endregion - // 鏇存敼绠辨敮鍏崇郴琛� - decimal factQty = 0.00m;//鎵樼洏鎬绘暟閲� - var isSample = "0";//鏄惁鍙栨牱 - var sampleQty = 0m;//鍙栨牱鏁伴噺 - - - var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList(); - foreach (var g in boxGroup) + if (sameBoxInfoList.Count <= 0) { - decimal boxFullQty = 0;//绠卞唴鎬绘暟閲� - foreach (var box in g) - { - if (box.BindNo != null && box.BindNo != 0) - { - continue; - } - //绠卞唴鐗╂枡鎵规涓庡崟鎹槑缁嗕笉绗﹀悎 - if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo) - { - throw new Exception($"-1:{box.BoxNo}绠卞唴鐗╂枡鍙婃壒娆′笌鍗曟嵁涓嶄竴鑷达紝璇锋牳瀹�!"); - } - - box.ASNNo = model.AsnNo; - box.ASNDetailNo = model.AsnDetailId; - box.BindNo = bindId; - box.PalletNo = model.PalletNo; - box.Status = "2"; - //box.InspectMark = model.IsSample; //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 - //box.SamplingQty = 0; //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 - box.CompleteTime = comTime; - box.UpdateTime = comTime; - box.UpdateUser = userId; - - //box.Qty = box.Qty; - //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1"; - - factQty += box.Qty; - boxFullQty += box.Qty; - if (box.InspectMark == "1") //鍒ゆ柇鏄惁鍙栨牱 - { - isSample = "1"; - sampleQty += (decimal)box.SamplingQty; - } - - #region 搴撳瓨绠辩爜鏄庣粏 - var box2 = new DataBoxInfo() - { - StockDetailId = sdId1, - BindNo = bind.Id, - BoxNo = box.BoxNo, - BoxNo2 = box.BoxNo2, - BoxNo3 = box.BoxNo3, - PalletNo = box.PalletNo, - PalletNo2 = box.PalletNo2, - PalletNo3 = box.PalletNo3, - Qty = box.Qty, - FullQty = box.FullQty, - Status = "2",//0锛氭湭缁勬墭 1锛氬凡缁勬墭 2锛氬凡鍏ュ簱 3锛氬凡鍑哄簱 4:宸插垎閰� 5锛氬凡鎷h揣 - LotNo = box.LotNo, - LotText = box.LotText, - SkuNo = box.SkuNo, - SkuName = box.SkuName, - Standard = sku.Standard, - ProductionTime = box.ProductionTime, - SupplierLot = box.SupplierLot, - InspectStatus = sku.IsInspect, - InspectMark = box.InspectMark, - BitBoxMark = box.BitBoxMark, - ExpirationTime = box.ExpirationTime, - - CreateUser = 0, - CreateTime = comTime - }; - //娣诲姞搴撳瓨绠辩爜鏄庣粏 - Db.Insertable(box2).ExecuteCommand(); - #endregion - } - if (boxFullQty > bNum) - { - throw new Exception($"缁戝畾澶辫触锛寋g.Key}绠辩爜缁戝畾鏁伴噺澶т簬璇ョ墿鍝佸寘瑁呮暟閲忥紒"); - } - } - Db.Updateable(boxInfoList).ExecuteCommand(); - - // 鏇存柊鎵樼洏缁戝畾琛� - bind.Qty += factQty; - - //if (bind.FullQty < bind.Qty && isTextTable == 0) - if (bind.FullQty < bind.Qty) - { - throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺"); - } - - if (bind.FullQty == bind.Qty) - { - bind.BitPalletMark = "0"; - sd1.BitPalletMark = "0"; - } - //if (bind.Qty > pNum && isTextTable == 0) - if (bind.Qty > pNum) - { - throw new Exception($"缁戝畾澶辫触锛寋bind.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒"); - } - - if (isSample == "1") - { - bind.InspectMark = "1"; - bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; - } - Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); - - #region 鍏ュ簱鍗曞強鏄庣粏 - decimal addQty = factQty; - - detail.FactQty += addQty;//宸茬粍鏁伴噺 - detail.CompleteQty += addQty;//瀹屾垚鏁伴噺 - if (isSample == "1") //鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�兼敼涓哄垽鏂槸鍚﹀彇鏍� - { - detail.IsSampling = "1"; - } - detail.Status = "1";//0锛氱瓑寰呮墽琛� 1锛氭鍦ㄦ墽琛� 2锛氭墽琛屽畬鎴� - if (detail.CompleteQty >= detail.Qty) - { - detail.Status = "2"; - detail.CompleteTime = comTime; - } - detail.UpdateUser = userId; - detail.UpdateTime = comTime; - //鏇存柊鍏ュ簱鍗曟槑缁� - Db.Updateable(detail).ExecuteCommand(); - - notice.UpdateUser = userId; - notice.UpdateTime = comTime; - if (notice.Status == "0") - { - notice.Status = "1"; - } - var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>() - .Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2"); - if (asnDetailNum == 0) - { - notice.Status = "2"; - notice.CompleteTime = comTime;//瀹屾垚鏃堕棿 - } - //鏇存柊鍏ュ簱鍗� - Db.Updateable(notice).ExecuteCommand(); - #endregion - - #region 搴撳瓨鏄庣粏 - sd1.Qty = bind.Qty; - //鏇存敼搴撳瓨鏄庣粏鏁伴噺 - Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand(); - #endregion - - #region 搴撳瓨 - var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo); - if (dataStock != null) - { - dataStock.Qty += factQty; - - if (bind.InspectMark == "1") - { - dataStock.IsSampling = bind.InspectMark; - } - Db.Updateable(dataStock).ExecuteCommand(); + throw new Exception("绠辩爜淇℃伅涓嶅瓨鍦�!"); } else { - var stock = new DataStock() + #region 鎵樼洏缁戝畾淇℃伅 + var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo); + var bindId = 0; + if (bind == null) { - SkuNo = sku.SkuNo, - SkuName = sku.SkuName, - Standard = sku.Standard, - LotNo = bind.LotNo, - LotText = bind.LotText, - Qty = bind.Qty, - LockQty = 0, - FrozenQty = 0, - IsSampling = bind.InspectMark, - IsDel = "0", - CreateUser = userId, - CreateTime = comTime - }; - //缁存姢搴撳瓨璐т富淇℃伅 - if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 - { - stock.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 - stock.OwnerName = notice.CustomerName;//璐т富鍚嶇О + bind = new BllPalletBind + { + ASNNo = model.AsnNo, + ASNDetailNo = (int)model.AsnDetailId, + PalletNo = model.PalletNo, + PalletNo2 = "", + PalletNo3 = "", + Qty = model.SkuQty - pinBoxQty,//涓嶅寘鍚嫾绠变腑闈炲悓鎵规鏁伴噺 + FullQty = pNum, + Status = "2",//鍏ュ簱瀹屾垚 + Type = "0", + LotNo = model.LotNo, + LotText = detail.LotText, + SupplierLot = detail.SupplierLot, + //InspectMark = model.IsSample, //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + //SamplingQty = 0, //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + BitPalletMark = "1", + IsBale = "0", + IsBelt = "0", + CreateUser = userId, + Demo = model.Demo, + }; + // 鎻掑叆鎵樼洏缁戝畾琛� + bindId = Db.Insertable(bind).ExecuteReturnIdentity(); } - Db.Insertable(stock).ExecuteCommand(); - } - #endregion + else + { + bindId = bind.Id; + bind.Qty += model.SkuQty; + } + if (bind.Qty < 0) + { + throw new Exception("缁勭洏鏁伴噺涓嶈兘灏忎簬0"); + } + #endregion - #region 璐ㄦ璇烽獙 - if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1") + #region 搴撳瓨鏄庣粏鍜岃川妫�淇℃伅 + //鑾峰彇璇ユ壒娆℃渶缁堣川妫�缁撴灉 + BllQualityInspect quality = new BllQualityInspect(); + //鍒ゆ柇鏄惁涓洪��璐у叆搴撳崟 + if (notice.Type == "3") + { + quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); + } + else + { + quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); + } + var tags = "0"; + if (notice.Type == "3" || notice.Type == "4") + { + tags = "1"; + } + + // 鍒ゆ柇搴撳瓨鏄庣粏鏄惁宸叉湁姝ゆ墭鐩樹俊鎭� + var sd1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo); + var sdId1 = 0; + if (sd1 != null) + { + sdId1 = sd1.Id; + // 搴撳瓨宸插瓨鍦� 鏇存柊鏁版嵁 + sd1.Qty = bind.Qty; + sd1.CompleteTime = comTime; + sd1.UpdateUser = userId; + sd1.UpdateTime = comTime; + + Db.Updateable(sd1).ExecuteCommand(); + } + else + { + // 搴撳瓨涓嶅瓨鍦� 鎻掑叆鏁版嵁 + sd1 = new DataStockDetail() + { + LotNo = bind.LotNo, + LotText = bind.LotText, + SupplierLot = bind.SupplierLot, + SkuNo = sku.SkuNo, + SkuName = sku.SkuName, + Standard = sku.Standard, + Qty = bind.Qty, + LockQty = 0, + FrozenQty = 0, + InspectQty = 0, + ASNNo = bind.ASNNo, + ASNDetailNo = bind.ASNDetailNo, + WareHouseNo = "",//鎵�灞炰粨搴� + RoadwayNo = "",//鎵�灞炲贩閬� + AreaNo = "",//鎵�灞炲尯鍩� + LocatNo = "",//鍌ㄤ綅鍦板潃 + PalletNo = bind.PalletNo, + PalletNo2 = bind.PalletNo2, + PalletNo3 = bind.PalletNo3, + PalletTags = tags, + CompleteTime = comTime, + ProductionTime = bind.ProductionTime, + ExpirationTime = bind.ExpirationTime, + Status = "0", + InspectMark = bind.InspectMark, + InspectStatus = sku.IsInspect, + BitPalletMark = bind.BitPalletMark, + PackagNo = detail.PackagNo, //liudl 鐢眘ku鐨勫寘瑁呯紪鍙峰彉涓哄叆搴撳崟鏄庣粏鐨勫寘瑁呯紪鐮� + IsBale = bind.IsBale, + IsBelt = bind.IsBelt, + + IsDel = "0", + CreateUser = 0, + CreateTime = comTime + }; + + //缁存姢搴撳瓨鏄庣粏璐т富/渚涘簲鍟嗕俊鎭� + if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 + { + sd1.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 + sd1.OwnerName = notice.CustomerName;//璐т富鍚嶇О + } + else if (notice.Type == "1" || notice.Type == "5")//1:閲囪喘鍏ュ簱,2:鍏跺畠鍏ュ簱 + { + sd1.SupplierNo = notice.CustomerNo;//渚涘簲鍟嗙紪鐮� + sd1.SupplierName = notice.CustomerName;//渚涘簲鍟嗗悕绉� + } + if (quality != null) + { + //淇敼鍚堟牸涓嶅悎鏍兼暟閲� + if (quality.IsQualified == "1") //鍚堟牸 + { + //澧炲姞鍚堟牸鏁伴噺 + quality.PassQty += bind.Qty; + sd1.InspectStatus = "1"; + } + else if (quality.IsQualified == "0") //涓嶅悎鏍� + { + //澧炲姞涓嶅悎鏍兼暟閲� + quality.FailQty += bind.Qty; + sd1.InspectStatus = "2"; + } + Db.Updateable(quality).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 + } + //娣诲姞搴撳瓨鏄庣粏 + sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity(); + } + #endregion + + // 鏇存敼绠辨敮鍏崇郴琛� + decimal factQty = 0.00m;//鎵樼洏鎬绘暟閲� + var isSample = "0";//鏄惁鍙栨牱 + var sampleQty = 0m;//鍙栨牱鏁伴噺 + + //鏍囩缁勬墭 + var boxGroup = sameBoxInfoList.GroupBy(m => m.BoxNo).ToList(); + foreach (var g in boxGroup) + { + decimal boxFullQty = 0;//绠卞唴鎬绘暟閲� + foreach (var box in g) + { + if (box.BindNo != null && box.BindNo != 0) + { + continue; + } + //绠卞唴鐗╂枡鎵规涓庡崟鎹槑缁嗕笉绗﹀悎 + if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo) + { + throw new Exception($"-1:{box.BoxNo}绠卞唴鐗╂枡鍙婃壒娆′笌鍗曟嵁涓嶄竴鑷达紝璇锋牳瀹�!"); + } + + box.ASNNo = model.AsnNo; + box.ASNDetailNo = model.AsnDetailId; + box.BindNo = bindId; + box.PalletNo = model.PalletNo; + box.Status = "2"; + //box.InspectMark = model.IsSample; //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + //box.SamplingQty = 0; //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + box.CompleteTime = comTime; + box.UpdateTime = comTime; + box.UpdateUser = userId; + + //box.Qty = box.Qty; + //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1"; + + factQty += box.Qty; + boxFullQty += box.Qty; + if (box.InspectMark == "1") //鍒ゆ柇鏄惁鍙栨牱 + { + isSample = "1"; + sampleQty += (decimal)box.SamplingQty; + } + + #region 搴撳瓨绠辩爜鏄庣粏 + var box2 = new DataBoxInfo() + { + StockDetailId = sdId1, + BindNo = bind.Id, + BoxNo = box.BoxNo, + BoxNo2 = box.BoxNo2, + BoxNo3 = box.BoxNo3, + PalletNo = box.PalletNo, + PalletNo2 = box.PalletNo2, + PalletNo3 = box.PalletNo3, + Qty = box.Qty, + FullQty = box.FullQty, + Status = "2",//0锛氭湭缁勬墭 1锛氬凡缁勬墭 2锛氬凡鍏ュ簱 3锛氬凡鍑哄簱 4:宸插垎閰� 5锛氬凡鎷h揣 + LotNo = box.LotNo, + LotText = box.LotText, + SkuNo = box.SkuNo, + SkuName = box.SkuName, + Standard = sku.Standard, + ProductionTime = box.ProductionTime, + SupplierLot = box.SupplierLot, + InspectStatus = sku.IsInspect, + InspectMark = box.InspectMark, + BitBoxMark = box.BitBoxMark, + ExpirationTime = box.ExpirationTime, + + CreateUser = 0, + CreateTime = comTime + }; + //娣诲姞搴撳瓨绠辩爜鏄庣粏 + Db.Insertable(box2).ExecuteCommand(); + #endregion + } + if (boxFullQty > bNum) + { + throw new Exception($"缁戝畾澶辫触锛寋g.Key}绠辩爜缁戝畾鏁伴噺澶т簬璇ョ墿鍝佸寘瑁呮暟閲忥紒"); + } + } + //鏇存敼绠辨敮鍏崇郴琛ㄤ俊鎭� + Db.Updateable(boxInfoList).ExecuteCommand(); + + // 鏇存柊鎵樼洏缁戝畾琛� + bind.Qty += factQty; + + if (bind.FullQty < bind.Qty) + { + throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺"); + } + + if (bind.FullQty == bind.Qty) + { + bind.BitPalletMark = "0"; + sd1.BitPalletMark = "0"; + } + if (bind.Qty > pNum) + { + throw new Exception($"缁戝畾澶辫触锛寋bind.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒"); + } + + if (isSample == "1") + { + bind.InspectMark = "1"; + bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; + } + Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); + + #region 鍏ュ簱鍗曞強鏄庣粏 + detail.FactQty += factQty;//宸茬粍鏁伴噺 + detail.CompleteQty += factQty;//瀹屾垚鏁伴噺 + if (isSample == "1") //鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�兼敼涓哄垽鏂槸鍚﹀彇鏍� + { + detail.IsSampling = "1"; + } + detail.Status = "1";//0锛氱瓑寰呮墽琛� 1锛氭鍦ㄦ墽琛� 2锛氭墽琛屽畬鎴� + if (detail.CompleteQty >= detail.Qty) + { + detail.Status = "2"; + detail.CompleteTime = comTime; + } + detail.UpdateUser = userId; + detail.UpdateTime = comTime; + //鏇存柊鍏ュ簱鍗曟槑缁� + Db.Updateable(detail).ExecuteCommand(); + + notice.UpdateUser = userId; + notice.UpdateTime = comTime; + if (notice.Status == "0") + { + notice.Status = "1"; + } + var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2"); + if (asnDetailNum == 0) + { + notice.Status = "2";//鎵ц瀹屾垚 + notice.CompleteTime = comTime;//瀹屾垚鏃堕棿 + } + //鏇存柊鍏ュ簱鍗� + Db.Updateable(notice).ExecuteCommand(); + #endregion + + #region 搴撳瓨鏄庣粏 + sd1.Qty = bind.Qty; + //鏇存敼搴撳瓨鏄庣粏鏁伴噺 + Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand(); + #endregion + + #region 搴撳瓨 + var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo); + if (dataStock != null) + { + dataStock.Qty += factQty; + + if (bind.InspectMark == "1") + { + dataStock.IsSampling = bind.InspectMark; + } + Db.Updateable(dataStock).ExecuteCommand(); + } + else + { + var stock = new DataStock() + { + SkuNo = sku.SkuNo, + SkuName = sku.SkuName, + Standard = sku.Standard, + LotNo = bind.LotNo, + LotText = bind.LotText, + Qty = bind.Qty, + LockQty = 0, + FrozenQty = 0, + IsSampling = bind.InspectMark, + IsDel = "0", + CreateUser = userId, + CreateTime = comTime + }; + //缁存姢搴撳瓨璐т富淇℃伅 + if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 + { + stock.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 + stock.OwnerName = notice.CustomerName;//璐т富鍚嶇О + } + Db.Insertable(stock).ExecuteCommand(); + } + #endregion + + #region 璐ㄦ璇烽獙 + if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1") + { + var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot); + if (qualityRequest == null) + { + string qcNo = new Common().GetMaxNo("QC"); + qualityRequest = new BllQualityInspectionRequest(); + qualityRequest.QcNo = qcNo; + qualityRequest.Status = "0"; + qualityRequest.SkuNo = sku.SkuNo; + qualityRequest.SkuName = sku.SkuName; + qualityRequest.LotNo = bind.LotNo; + qualityRequest.SupplierLot = bind.SupplierLot; + qualityRequest.Qty = detail.Qty; + qualityRequest.SamplingQty = 0; + qualityRequest.ASNNo = detail.ASNNo; + qualityRequest.CreateUser = userId; + qualityRequest.CreateTime = comTime; + //娣诲姞璐ㄦ璇烽獙鍗� + Db.Insertable(qualityRequest).ExecuteCommand(); + } + } + #endregion + } + //鎷肩 + if (notBoxInfoList.Count > 0) { - var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot); - if (qualityRequest == null) + var gbox = notBoxInfoList.GroupBy(g => g.BoxNo).ToList(); + if (gbox.Count > 1) { - string qcNo = new Common().GetMaxNo("QC"); - qualityRequest = new BllQualityInspectionRequest(); - qualityRequest.QcNo = qcNo; - qualityRequest.Status = "0"; - qualityRequest.SkuNo = sku.SkuNo; - qualityRequest.SkuName = sku.SkuName; - qualityRequest.LotNo = bind.LotNo; - qualityRequest.SupplierLot = bind.SupplierLot; - qualityRequest.Qty = detail.Qty; - qualityRequest.SamplingQty = 0; - qualityRequest.ASNNo = detail.ASNNo; - qualityRequest.CreateUser = userId; - qualityRequest.CreateTime = comTime; - //娣诲姞璐ㄦ璇烽獙鍗� - Db.Insertable(qualityRequest).ExecuteCommand(); + throw new Exception("涓�涓墭鐩樹笂鍙兘鏈�1涓嫾绠�!"); + } + gbox = notBoxInfoList.GroupBy(g => g.LotNo).ToList(); + if (gbox.Count > 1) + { + throw new Exception("涓�涓鍐呮渶澶氳兘鏈�2涓笉鍚屾壒娆$墿鏂�!"); + } + var pinBoxNo = notBoxInfoList[0].BoxNo;//鎷肩绠辩爜 + var pinBoxLotNo = notBoxInfoList[0].LotNo;//鎷肩鎵规鍙� + + var dataBoxList = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.BoxNo == pinBoxNo && w.LotNo == pinBoxLotNo).ToList(); + if (dataBoxList.Count > 0)//宸叉湁搴撳瓨 + { + //鍘熸墭鐩樼粦瀹氫俊鎭� + var oldPalletBind = Db.Queryable<BllPalletBind>().First(w => w.Id == notBoxInfoList[0].BindNo); + //鍘熷叆搴撳崟鏄庣粏 + var oldAsnDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.Id == oldPalletBind.ASNDetailNo); + #region 鎵樼洏缁戝畾淇℃伅 + var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == oldAsnDetail.Id && m.PalletNo == model.PalletNo); + var bindId = 0; + if (bind == null) + { + bind = new BllPalletBind + { + ASNNo = oldAsnDetail.ASNNo, + ASNDetailNo = oldAsnDetail.Id, + PalletNo = model.PalletNo, + PalletNo2 = "", + PalletNo3 = "", + Qty = pinBoxQty, + FullQty = pNum, + Status = "2",//鍏ュ簱瀹屾垚 + Type = "0", + LotNo = pinBoxLotNo, + LotText = oldAsnDetail.LotText, + SupplierLot = oldAsnDetail.SupplierLot, + //InspectMark = model.IsSample, //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + //SamplingQty = 0, //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + BitPalletMark = "1", + IsBale = "0", + IsBelt = "0", + CreateUser = userId, + Demo = model.Demo, + }; + // 鎻掑叆鎵樼洏缁戝畾琛� + bindId = Db.Insertable(bind).ExecuteReturnIdentity(); + } + else + { + bindId = bind.Id; + bind.Qty += pinBoxQty; + + Db.Updateable(bind).ExecuteCommand(); + } + #endregion + + // 鎻掑叆搴撳瓨鏄庣粏鏁版嵁 + var sd1 = new DataStockDetail() + { + LotNo = pinBoxNo, + LotText = notBoxInfoList[0].LotText, + SupplierLot = notBoxInfoList[0].SupplierLot, + SkuNo = sku.SkuNo, + SkuName = sku.SkuName, + Standard = sku.Standard, + Qty = pinBoxQty, + LockQty = 0, + FrozenQty = 0, + InspectQty = 0, + ASNNo = oldPalletBind.ASNNo, + ASNDetailNo = oldPalletBind.ASNDetailNo, + WareHouseNo = "",//鎵�灞炰粨搴� + RoadwayNo = "",//鎵�灞炲贩閬� + AreaNo = "",//鎵�灞炲尯鍩� + LocatNo = "",//鍌ㄤ綅鍦板潃 + PalletNo = oldPalletBind.PalletNo, + PalletNo2 = oldPalletBind.PalletNo2, + PalletNo3 = oldPalletBind.PalletNo3, + PalletTags = "0", + CompleteTime = comTime, + ProductionTime = oldPalletBind.ProductionTime, + ExpirationTime = oldPalletBind.ExpirationTime, + Status = "0", + InspectMark = oldPalletBind.InspectMark, + InspectStatus = sku.IsInspect, + BitPalletMark = oldPalletBind.BitPalletMark, + PackagNo = oldAsnDetail.PackagNo, + IsBale = oldPalletBind.IsBale, + IsBelt = oldPalletBind.IsBelt, + + IsDel = "0", + CreateUser = 0, + CreateTime = comTime + }; + //娣诲姞搴撳瓨鏄庣粏 + var sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity(); + foreach (var item in dataBoxList) + { + item.StockDetailId = sdId1;//搴撳瓨鏄庣粏id + item.BindNo = bind.Id;//鎵樼洏缁戝畾id + } + //鏇存柊搴撳瓨绠辨敮鏄庣粏琛� + Db.Updateable(dataBoxList).ExecuteCommand(); + + //鎵樼洏瑙g粦淇℃伅 + var palletUnbind = Db.Queryable<BllPalletUnbind>().First(w => w.IsDel == "0" && w.UpbindPalletNo == oldPalletBind.PalletNo && w.BoxNo == pinBoxNo); + if (palletUnbind == null) + { + throw new Exception("鎷肩鐨勬墭鐩樿В缁戜俊鎭笉瀛樺湪!"); + } + palletUnbind.BindPalletNo = model.PalletNo;//缁戝畾鎵樼洏鍙� + palletUnbind.UpdateTime = comTime; + palletUnbind.UpdateUser = userId; + //鏇存柊鎵樼洏瑙g粦缁戝畾琛ㄤ俊鎭� + Db.Updateable(palletUnbind).ExecuteCommand(); + } + else + { + string sql = $@"SELECT detail.* FROM BllArrivalNoticeDetail as detail + JOIN BllArrivalNotice as notice ON detail.ASNNo=notice.ASNNo + WHERE notice.IsDel='0' + AND notice.Status='1' + AND detail.IsDel='0' + AND detail.LotNo='{pinBoxLotNo}' + AND detail.SkuNo='{sku.SkuNo}' + ORDER BY detail.CreateTime "; + //鎵惧埌鎷肩鍐呭叾浠栨壒娆℃墍灞炲叆搴撳崟鏄庣粏 + var arrDetail = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql).FirstOrDefault(); + if (arrDetail == null) + { + throw new Exception("鎷肩鍐呯墿鏂欐墍灞炲叆搴撳崟鏄庣粏涓嶅瓨鍦�!"); + } + //鎵惧埌鎷肩鍐呭叾浠栨壒娆℃墍灞炲叆搴撳崟 + var arrNotice = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.ASNNo == arrDetail.ASNNo && w.Status == "1"); + if (arrNotice == null) + { + throw new Exception("鎷肩鍐呯墿鏂欐墍灞炲叆搴撳崟涓嶅瓨鍦�!"); + } + #region 鎵樼洏缁戝畾淇℃伅 + var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == arrDetail.Id && m.PalletNo == model.PalletNo); + var bindId = 0; + if (bind == null) + { + bind = new BllPalletBind + { + ASNNo = arrDetail.ASNNo, + ASNDetailNo = arrDetail.Id, + PalletNo = model.PalletNo, + PalletNo2 = "", + PalletNo3 = "", + Qty = pinBoxQty, + FullQty = pNum, + Status = "2",//鍏ュ簱瀹屾垚 + Type = "0", + LotNo = pinBoxLotNo, + LotText = arrDetail.LotText, + SupplierLot = arrDetail.SupplierLot, + //InspectMark = model.IsSample, //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + //SamplingQty = 0, //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + BitPalletMark = "1", + IsBale = "0", + IsBelt = "0", + CreateUser = userId, + Demo = model.Demo, + }; + // 鎻掑叆鎵樼洏缁戝畾琛� + bindId = Db.Insertable(bind).ExecuteReturnIdentity(); + } + else + { + bindId = bind.Id; + bind.Qty += pinBoxQty; + + Db.Updateable(bind).ExecuteCommand(); + } + #endregion + + #region 搴撳瓨鏄庣粏鍜岃川妫�淇℃伅 + //鑾峰彇璇ユ壒娆℃渶缁堣川妫�缁撴灉 + BllQualityInspect quality = new BllQualityInspect(); + //鍒ゆ柇鏄惁涓洪��璐у叆搴撳崟 + if (arrNotice.Type == "3") + { + quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == arrDetail.ASNNo && a.SkuNo == arrDetail.SkuNo && a.LotNo == arrDetail.LotNo).OrderByDescending(a => a.CreateTime).First(); + } + else + { + quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == arrDetail.SkuNo && a.LotNo == arrDetail.LotNo).OrderByDescending(a => a.CreateTime).First(); + } + var tags = "0"; + if (arrNotice.Type == "3" || arrNotice.Type == "4") + { + tags = "1"; + } + + // 鍒ゆ柇搴撳瓨鏄庣粏鏄惁宸叉湁姝ゆ墭鐩樹俊鎭� + var sd1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.ASNDetailNo == arrDetail.Id && m.PalletNo == model.PalletNo); + var sdId1 = 0; + if (sd1 != null) + { + sdId1 = sd1.Id; + // 搴撳瓨宸插瓨鍦� 鏇存柊鏁版嵁 + sd1.Qty = pinBoxQty; + sd1.CompleteTime = comTime; + sd1.UpdateUser = userId; + sd1.UpdateTime = comTime; + + Db.Updateable(sd1).ExecuteCommand(); + } + else + { + // 搴撳瓨涓嶅瓨鍦� 鎻掑叆鏁版嵁 + sd1 = new DataStockDetail() + { + LotNo = pinBoxLotNo, + LotText = notBoxInfoList[0].LotText, + SupplierLot = bind.SupplierLot, + SkuNo = sku.SkuNo, + SkuName = sku.SkuName, + Standard = sku.Standard, + Qty = pinBoxQty, + LockQty = 0, + FrozenQty = 0, + InspectQty = 0, + ASNNo = arrDetail.ASNNo, + ASNDetailNo = arrDetail.Id, + WareHouseNo = "",//鎵�灞炰粨搴� + RoadwayNo = "",//鎵�灞炲贩閬� + AreaNo = "",//鎵�灞炲尯鍩� + LocatNo = "",//鍌ㄤ綅鍦板潃 + PalletNo = bind.PalletNo, + PalletNo2 = bind.PalletNo2, + PalletNo3 = bind.PalletNo3, + PalletTags = tags, + CompleteTime = comTime, + ProductionTime = bind.ProductionTime, + ExpirationTime = bind.ExpirationTime, + Status = "0", + InspectMark = bind.InspectMark, + InspectStatus = sku.IsInspect, + BitPalletMark = bind.BitPalletMark, + PackagNo = detail.PackagNo, //liudl 鐢眘ku鐨勫寘瑁呯紪鍙峰彉涓哄叆搴撳崟鏄庣粏鐨勫寘瑁呯紪鐮� + IsBale = bind.IsBale, + IsBelt = bind.IsBelt, + + IsDel = "0", + CreateUser = 0, + CreateTime = comTime + }; + + //缁存姢搴撳瓨鏄庣粏璐т富/渚涘簲鍟嗕俊鎭� + if (arrNotice.Type == "0" || arrNotice.Type == "2" || arrNotice.Type == "4" || arrNotice.Type == "6" || arrNotice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 + { + sd1.OwnerNo = arrNotice.CustomerNo;//璐т富缂栫爜 + sd1.OwnerName = arrNotice.CustomerName;//璐т富鍚嶇О + } + else if (arrNotice.Type == "1" || arrNotice.Type == "5")//1:閲囪喘鍏ュ簱,2:鍏跺畠鍏ュ簱 + { + sd1.SupplierNo = arrNotice.CustomerNo;//渚涘簲鍟嗙紪鐮� + sd1.SupplierName = arrNotice.CustomerName;//渚涘簲鍟嗗悕绉� + } + if (quality != null) + { + //淇敼鍚堟牸涓嶅悎鏍兼暟閲� + if (quality.IsQualified == "1") //鍚堟牸 + { + //澧炲姞鍚堟牸鏁伴噺 + quality.PassQty += bind.Qty; + sd1.InspectStatus = "1"; + } + else if (quality.IsQualified == "0") //涓嶅悎鏍� + { + //澧炲姞涓嶅悎鏍兼暟閲� + quality.FailQty += bind.Qty; + sd1.InspectStatus = "2"; + } + Db.Updateable(quality).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 + } + //娣诲姞搴撳瓨鏄庣粏 + sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity(); + } + #endregion + + // 鏇存敼绠辨敮鍏崇郴琛� + decimal factQty = 0.00m;//鎵樼洏鎬绘暟閲� + var isSample = "0";//鏄惁鍙栨牱 + var sampleQty = 0m;//鍙栨牱鏁伴噺 + + //鏍囩缁勬墭 + var boxGroup = notBoxInfoList.GroupBy(m => m.BoxNo).ToList(); + foreach (var g in boxGroup) + { + decimal boxFullQty = 0;//绠卞唴鎬绘暟閲� + foreach (var box in g) + { + if (box.BindNo != null && box.BindNo != 0) + { + continue; + } + //绠卞唴鐗╂枡鎵规涓庡崟鎹槑缁嗕笉绗﹀悎 + if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo) + { + throw new Exception($"-1:{box.BoxNo}绠卞唴鐗╂枡鍙婃壒娆′笌鍗曟嵁涓嶄竴鑷达紝璇锋牳瀹�!"); + } + + box.ASNNo = arrDetail.ASNNo; + box.ASNDetailNo = arrDetail.Id; + box.BindNo = bindId; + box.PalletNo = model.PalletNo; + box.Status = "2"; + //box.InspectMark = model.IsSample; //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + //box.SamplingQty = 0; //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + box.CompleteTime = comTime; + box.UpdateTime = comTime; + box.UpdateUser = userId; + + //box.Qty = box.Qty; + //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1"; + + factQty += box.Qty; + boxFullQty += box.Qty; + if (box.InspectMark == "1") //鍒ゆ柇鏄惁鍙栨牱 + { + isSample = "1"; + sampleQty += (decimal)box.SamplingQty; + } + + #region 搴撳瓨绠辩爜鏄庣粏 + var box2 = new DataBoxInfo() + { + StockDetailId = sdId1, + BindNo = bind.Id, + BoxNo = box.BoxNo, + BoxNo2 = box.BoxNo2, + BoxNo3 = box.BoxNo3, + PalletNo = box.PalletNo, + PalletNo2 = box.PalletNo2, + PalletNo3 = box.PalletNo3, + Qty = box.Qty, + FullQty = box.FullQty, + Status = "2",//0锛氭湭缁勬墭 1锛氬凡缁勬墭 2锛氬凡鍏ュ簱 3锛氬凡鍑哄簱 4:宸插垎閰� 5锛氬凡鎷h揣 + LotNo = box.LotNo, + LotText = box.LotText, + SkuNo = box.SkuNo, + SkuName = box.SkuName, + Standard = sku.Standard, + ProductionTime = box.ProductionTime, + SupplierLot = box.SupplierLot, + InspectStatus = sku.IsInspect, + InspectMark = box.InspectMark, + BitBoxMark = box.BitBoxMark, + ExpirationTime = box.ExpirationTime, + + CreateUser = 0, + CreateTime = comTime + }; + //娣诲姞搴撳瓨绠辩爜鏄庣粏 + Db.Insertable(box2).ExecuteCommand(); + #endregion + } + if (boxFullQty > bNum) + { + throw new Exception($"缁戝畾澶辫触锛寋g.Key}绠辩爜缁戝畾鏁伴噺澶т簬璇ョ墿鍝佸寘瑁呮暟閲忥紒"); + } + } + //鏇存敼绠辨敮鍏崇郴琛ㄤ俊鎭� + Db.Updateable(boxInfoList).ExecuteCommand(); + + // 鏇存柊鎵樼洏缁戝畾琛� + bind.Qty += factQty; + + if (bind.FullQty < bind.Qty) + { + throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺"); + } + + if (bind.FullQty == bind.Qty) + { + bind.BitPalletMark = "0"; + sd1.BitPalletMark = "0"; + } + if (bind.Qty > pNum) + { + throw new Exception($"缁戝畾澶辫触锛寋bind.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒"); + } + + if (isSample == "1") + { + bind.InspectMark = "1"; + bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; + } + Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); + + #region 鍏ュ簱鍗曞強鏄庣粏 + arrDetail.FactQty += factQty;//宸茬粍鏁伴噺 + arrDetail.CompleteQty += factQty;//瀹屾垚鏁伴噺 + if (isSample == "1") //鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�兼敼涓哄垽鏂槸鍚﹀彇鏍� + { + arrDetail.IsSampling = "1"; + } + arrDetail.Status = "1";//0锛氱瓑寰呮墽琛� 1锛氭鍦ㄦ墽琛� 2锛氭墽琛屽畬鎴� + if (arrDetail.CompleteQty >= detail.Qty) + { + arrDetail.Status = "2"; + arrDetail.CompleteTime = comTime; + } + arrDetail.UpdateUser = userId; + arrDetail.UpdateTime = comTime; + //鏇存柊鍏ュ簱鍗曟槑缁� + Db.Updateable(arrDetail).ExecuteCommand(); + + arrNotice.UpdateUser = userId; + arrNotice.UpdateTime = comTime; + if (arrNotice.Status == "0") + { + arrNotice.Status = "1"; + } + var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.ASNNo == arrDetail.ASNNo && m.Status != "2"); + if (asnDetailNum == 0) + { + arrNotice.Status = "2";//鎵ц瀹屾垚 + arrNotice.CompleteTime = comTime;//瀹屾垚鏃堕棿 + } + //鏇存柊鍏ュ簱鍗� + Db.Updateable(arrNotice).ExecuteCommand(); + #endregion + + #region 搴撳瓨鏄庣粏 + sd1.Qty = bind.Qty; + //鏇存敼搴撳瓨鏄庣粏鏁伴噺 + Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand(); + #endregion + + #region 搴撳瓨 + var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo); + if (dataStock != null) + { + dataStock.Qty += factQty; + + if (bind.InspectMark == "1") + { + dataStock.IsSampling = bind.InspectMark; + } + Db.Updateable(dataStock).ExecuteCommand(); + } + else + { + var stock = new DataStock() + { + SkuNo = sku.SkuNo, + SkuName = sku.SkuName, + Standard = sku.Standard, + LotNo = bind.LotNo, + LotText = bind.LotText, + Qty = bind.Qty, + LockQty = 0, + FrozenQty = 0, + IsSampling = bind.InspectMark, + IsDel = "0", + CreateUser = userId, + CreateTime = comTime + }; + //缁存姢搴撳瓨璐т富淇℃伅 + if (arrNotice.Type == "0" || arrNotice.Type == "2" || arrNotice.Type == "4" || arrNotice.Type == "6" || arrNotice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 + { + stock.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 + stock.OwnerName = notice.CustomerName;//璐т富鍚嶇О + } + Db.Insertable(stock).ExecuteCommand(); + } + #endregion + + #region 璐ㄦ璇烽獙 + if ((arrNotice.Type == "1" || arrNotice.Type == "4" || arrNotice.Type == "5") && sku.IsInspect != "1") + { + var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot); + if (qualityRequest == null) + { + string qcNo = new Common().GetMaxNo("QC"); + qualityRequest = new BllQualityInspectionRequest(); + qualityRequest.QcNo = qcNo; + qualityRequest.Status = "0"; + qualityRequest.SkuNo = sku.SkuNo; + qualityRequest.SkuName = sku.SkuName; + qualityRequest.LotNo = bind.LotNo; + qualityRequest.SupplierLot = bind.SupplierLot; + qualityRequest.Qty = arrDetail.Qty; + qualityRequest.SamplingQty = 0; + qualityRequest.ASNNo = arrDetail.ASNNo; + qualityRequest.CreateUser = userId; + qualityRequest.CreateTime = comTime; + //娣诲姞璐ㄦ璇烽獙鍗� + Db.Insertable(qualityRequest).ExecuteCommand(); + } + } + #endregion } } - #endregion - // 鏇存敼鎵樼洏浣跨敤鐘舵�� var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';"; //娣诲姞鎵樼洏璁板綍琛ㄦ暟鎹� @@ -3915,453 +4413,454 @@ Db.Ado.ExecuteCommand(sqlStr); new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "鎵樼洏缁戝畾", model.AsnNo, "娣诲姞", $"娣诲姞浜嗘墭鐩樼爜涓猴細{model.PalletNo}銆亄msgStr}鐨勭粍鐩樹俊鎭�", userId); + //鎻愪氦浜嬪姟 Db.CommitTran(); } catch (Exception e) { + //鍥炴粴浜嬪姟 Db.RollbackTran(); throw new Exception(e.Message); } } - //JC26缁戝畾鎵樼洏 涓嶈创鏍囩墿鏂� public void BindPalletNoPasteCode(PdaPalletBindVm model, int userId) { - - #region 鍒ゆ柇 - - //0锛氭垚鍝佸叆搴� 1锛氶噰璐叆搴� 3锛氶��璐у叆搴� 4锛氳溅闂翠綑鏂欏叆搴� 5锛氬叾瀹冨叆搴� 6锛氫唬鍌ㄥ叆搴� - var TypeLot = "5, 6"; - if (string.IsNullOrEmpty(model.AsnNo)) - { - throw new Exception("鍗曟嵁鍙蜂笉鍙负绌�!"); - } - if (model.AsnDetailId == null || model.AsnDetailId == 0) - { - throw new Exception("鐗╂枡涓嶅彲涓虹┖!"); - } - if (string.IsNullOrEmpty(model.PalletNo)) - { - throw new Exception("鎵樼洏鍙蜂笉鍙负绌�!"); - } - if (model.SkuQty < 0) - { - throw new Exception("鐗╂枡鏁伴噺涓嶈兘灏忎簬0!"); - } - //鏍规嵁鍗曟嵁鍙疯幏鍙栧叆搴撳崟鎬诲崟 - var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo); - if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2") - { - throw new Exception("璇ュ崟鎹凡鍏冲崟!"); - } + #region 鍒ゆ柇 - if (string.IsNullOrEmpty(model.LotNo)) + //0锛氭垚鍝佸叆搴� 1锛氶噰璐叆搴� 3锛氶��璐у叆搴� 4锛氳溅闂翠綑鏂欏叆搴� 5锛氬叾瀹冨叆搴� 6锛氫唬鍌ㄥ叆搴� + var TypeLot = "5, 6"; + + if (string.IsNullOrEmpty(model.AsnNo)) + { + throw new Exception("鍗曟嵁鍙蜂笉鍙负绌�!"); + } + if (model.AsnDetailId == null || model.AsnDetailId == 0) + { + throw new Exception("鐗╂枡涓嶅彲涓虹┖!"); + } + if (string.IsNullOrEmpty(model.PalletNo)) + { + throw new Exception("鎵樼洏鍙蜂笉鍙负绌�!"); + } + if (model.SkuQty < 0) + { + throw new Exception("鐗╂枡鏁伴噺涓嶈兘灏忎簬0!"); + } + //鏍规嵁鍗曟嵁鍙疯幏鍙栧叆搴撳崟鎬诲崟 + var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo); + if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2") + { + throw new Exception("璇ュ崟鎹凡鍏冲崟!"); + } + + if (string.IsNullOrEmpty(model.LotNo)) + { + throw new Exception("鐗╂枡鎵规涓嶄负绌�!"); + } + else + { + //浠庣墿鏂欏悕绉�-鎵规涓彇鍑烘壒娆� + int indexOfDash = model.LotNo.IndexOf("-"); + if (indexOfDash != -1) { - throw new Exception("鐗╂枡鎵规涓嶄负绌�!"); + model.LotNo = model.LotNo.Substring(indexOfDash + 1); } else { - //浠庣墿鏂欏悕绉�-鎵规涓彇鍑烘壒娆� - int indexOfDash = model.LotNo.IndexOf("-"); - if (indexOfDash != -1) + if (!TypeLot.Contains(notice.Type)) { - model.LotNo = model.LotNo.Substring(indexOfDash + 1); + throw new Exception("鐗╂枡鎵规涓嶅彲涓虹┖!"); } - else - { - if (!TypeLot.Contains(notice.Type)) - { - throw new Exception("鐗╂枡鎵规涓嶅彲涓虹┖!"); - } - model.LotNo = ""; + model.LotNo = ""; + } + } + + //int isTextTable = model.TableType; + #endregion + + var comTime = DateTime.Now; + + //鎵樼洏鏄惁瀛樺湪 + var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); + if (pallet == null) + { + throw new Exception("鏈煡璇㈠埌鎵樼洏淇℃伅锛岃鏍稿疄锛�"); + } + // 楠岃瘉鍏ュ簱鍗曟槑缁嗘槸鍚﹀瓨鍦� + var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo)); + if (detail == null) + { + throw new Exception("褰撳墠鐗╂枡鍙婃壒娆′笌鍗曟嵁鏃犲叧鑱旓紝璇锋牳瀹�!"); + } + //鍒ゆ柇鎵樼洏鏄惁鍦ㄥ簱澶� + var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); + if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo)) + { + throw new Exception("璇ユ墭鐩樺凡鏈夊偍浣嶄俊鎭紝璇锋牳瀹烇紒"); + } + if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo)) + { + throw new Exception("璇ユ墭鐩樺湪搴撳瓨宸叉湁鍏跺畠鐗╂枡鎵规淇℃伅锛岃鏍稿疄锛�"); + } + + #region 鍖呰 + var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo); + var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo); // liudl 鐢盨ku鍖呰缂栧彿鍙樻洿涓哄叆搴撳崟鏄庣粏鍖呰缂栧彿 + + var pNum = 0;//鎵樼洏鐗╁搧鏁伴噺 + var bNum = 0;//绠辩爜鐗╁搧鏁伴噺 + + if (pack == null) + { + throw new Exception("鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!"); + } + if (pack.L5Num.HasValue) + { + pNum = (int)pack.L5Num; + bNum = (int)pack.L4Num; + } + else if (pack.L4Num.HasValue) + { + pNum = (int)pack.L4Num; + bNum = (int)pack.L3Num; + } + else if (pack.L3Num.HasValue) + { + pNum = (int)pack.L3Num; + bNum = (int)pack.L2Num; + } + else if (pack.L2Num.HasValue) + { + pNum = (int)pack.L2Num; + bNum = (int)pack.L1Num; + } + else if (pack.L1Num.HasValue) + { + pNum = (int)pack.L1Num; + bNum = (int)pack.L1Num; + } + if (pNum == 0 || bNum == 0) + { + throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒"); + } + + #endregion + + #region 楠岃瘉鏄惁鍏佽绔嬪簱鍚屾墭鐩樹笉鍚岀墿鏂欏叆搴撴垨鍚屾墭鐩樺悓鐗╂枡涓嶅悓鎵规鍏ュ簱 + var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId); + if (palletBind != null) + { + var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0"); + if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo))) + { + var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045"); + if (funSetting == null || funSetting.IsEnable == "OFF") + { + throw new Exception($"涓嶅厑璁哥珛搴撳悓鎵樼洏涓嶅悓鐗╂枡鍏ュ簱鎴栧悓鎵樼洏涓嶅悓鎵规鍏ュ簱锛�"); } } + } + #endregion + //liudl && m.Status != "2" 缁勭洏鏃㈠叆搴撳畬鎴愭棤闇�鏍规嵁鎵樼洏鐘舵�佸垽鏂� + var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo); + var bindId = 0; + if (bind == null) + { + bind = new BllPalletBind + { + ASNNo = model.AsnNo, + ASNDetailNo = (int)model.AsnDetailId, + PalletNo = model.PalletNo, - //int isTextTable = model.TableType; - #endregion + Qty = model.SkuQty, + FullQty = pNum, + Status = "2",//鍏ュ簱瀹屾垚 + Type = "0", + LotNo = model.LotNo, + LotText = detail.LotText, + SupplierLot = detail.SupplierLot, + //InspectMark = model.IsSample, //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + //SamplingQty = 0, //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 + BitPalletMark = "1", + IsBale = "0", + IsBelt = "0", + CreateUser = userId, + Demo = model.Demo, - var comTime = DateTime.Now; + }; + // 鎻掑叆鎵樼洏缁戝畾琛� + bindId = Db.Insertable(bind).ExecuteReturnIdentity(); + } + else + { + bindId = bind.Id; + bind.Qty += model.SkuQty; + } + if (bind.Qty < 0) + { + throw new Exception("缁勭洏鏁伴噺涓嶈兘灏忎簬0"); + } - //鎵樼洏鏄惁瀛樺湪 - var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); - if (pallet == null) - { - throw new Exception("鏈煡璇㈠埌鎵樼洏淇℃伅锛岃鏍稿疄锛�"); - } - // 楠岃瘉鍏ュ簱鍗曟槑缁嗘槸鍚﹀瓨鍦� - var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo)); - if (detail == null) - { - throw new Exception("褰撳墠鐗╂枡鍙婃壒娆′笌鍗曟嵁鏃犲叧鑱旓紝璇锋牳瀹�!"); - } - //鍒ゆ柇鎵樼洏鏄惁鍦ㄥ簱澶� - var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo); - if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo)) - { - throw new Exception("璇ユ墭鐩樺凡鏈夊偍浣嶄俊鎭紝璇锋牳瀹烇紒"); - } - if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo)) - { - throw new Exception("璇ユ墭鐩樺湪搴撳瓨宸叉湁鍏跺畠鐗╂枡鎵规淇℃伅锛岃鏍稿疄锛�"); - } + #region 搴撳瓨鏄庣粏 + //鑾峰彇璇ユ壒娆℃渶缁堣川妫�缁撴灉 + BllQualityInspect quality = new BllQualityInspect(); + //鍒ゆ柇鏄惁涓洪��璐у叆搴撳崟 + if (notice.Type == "3") + { + quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); + } + else + { + quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); + } + var tags = "0"; + if (notice.Type == "3" || notice.Type == "4") + { + tags = "1"; + } - #region 鍖呰 - var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo); - var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo); // liudl 鐢盨ku鍖呰缂栧彿鍙樻洿涓哄叆搴撳崟鏄庣粏鍖呰缂栧彿 - - var pNum = 0;//鎵樼洏鐗╁搧鏁伴噺 - var bNum = 0;//绠辩爜鐗╁搧鏁伴噺 - - if (pack == null) - { - throw new Exception("鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!"); - } - if (pack.L5Num.HasValue) - { - pNum = (int)pack.L5Num; - bNum = (int)pack.L4Num; - } - else if (pack.L4Num.HasValue) - { - pNum = (int)pack.L4Num; - bNum = (int)pack.L3Num; - } - else if (pack.L3Num.HasValue) - { - pNum = (int)pack.L3Num; - bNum = (int)pack.L2Num; - } - else if (pack.L2Num.HasValue) - { - pNum = (int)pack.L2Num; - bNum = (int)pack.L1Num; - } - else if (pack.L1Num.HasValue) - { - pNum = (int)pack.L1Num; - bNum = (int)pack.L1Num; - } - if (pNum == 0 || bNum == 0) - { - throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒"); - } - - #endregion - - #region 楠岃瘉鏄惁鍏佽绔嬪簱鍚屾墭鐩樹笉鍚岀墿鏂欏叆搴撴垨鍚屾墭鐩樺悓鐗╂枡涓嶅悓鎵规鍏ュ簱 - var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId); - if (palletBind != null) - { - var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0"); - if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo))) - { - var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045"); - if (funSetting == null || funSetting.IsEnable == "OFF") - { - throw new Exception($"涓嶅厑璁哥珛搴撳悓鎵樼洏涓嶅悓鐗╂枡鍏ュ簱鎴栧悓鎵樼洏涓嶅悓鎵规鍏ュ簱锛�"); - } - } - } - #endregion - //liudl && m.Status != "2" 缁勭洏鏃㈠叆搴撳畬鎴愭棤闇�鏍规嵁鎵樼洏鐘舵�佸垽鏂� - var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo); - var bindId = 0; - if (bind == null) - { - bind = new BllPalletBind - { - ASNNo = model.AsnNo, - ASNDetailNo = (int)model.AsnDetailId, - PalletNo = model.PalletNo, - - Qty = model.SkuQty, - FullQty = pNum, - Status = "2",//鍏ュ簱瀹屾垚 - Type = "0", - LotNo = model.LotNo, - LotText = detail.LotText, - SupplierLot = detail.SupplierLot, - //InspectMark = model.IsSample, //鏄惁鍙栨牱鎵樼洏 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 - //SamplingQty = 0, //鍙栨牱鏁伴噺 鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�奸渶娣诲姞瀵瑰簲瀛楁鍒ゆ柇 - BitPalletMark = "1", - IsBale = "0", - IsBelt = "0", - CreateUser = userId, - Demo = model.Demo, - - }; - // 鎻掑叆鎵樼洏缁戝畾琛� - bindId = Db.Insertable(bind).ExecuteReturnIdentity(); - } - else - { - bindId = bind.Id; - bind.Qty += model.SkuQty; - } - if (bind.Qty < 0) - { - throw new Exception("缁勭洏鏁伴噺涓嶈兘灏忎簬0"); - } - - #region 搴撳瓨鏄庣粏 - //鑾峰彇璇ユ壒娆℃渶缁堣川妫�缁撴灉 - BllQualityInspect quality = new BllQualityInspect(); - //鍒ゆ柇鏄惁涓洪��璐у叆搴撳崟 - if (notice.Type == "3") - { - quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); - } - else - { - quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First(); - } - var tags = "0"; - if (notice.Type == "3" || notice.Type == "4") - { - tags = "1"; - } - - // 鍒ゆ柇搴撳瓨鏄庣粏鏄惁宸叉湁姝ゆ墭鐩樹俊鎭� - var sd1 = Db.Queryable<DataStockDetail>() - .First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo && m.LotNo == bind.LotNo); - var sdId1 = 0; - if (sd1 != null) - { - sdId1 = sd1.Id; - // 搴撳瓨宸插瓨鍦� 鏇存柊鏁版嵁 - sd1.Qty = bind.Qty; - sd1.CompleteTime = comTime; - sd1.UpdateUser = userId; - sd1.UpdateTime = comTime; - - Db.Updateable(sd1).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 - } - else - { - // 搴撳瓨涓嶅瓨鍦� 鎻掑叆鏁版嵁 - sd1 = new DataStockDetail() - { - LotNo = bind.LotNo, - LotText = bind.LotText, - SupplierLot = bind.SupplierLot, - SkuNo = sku.SkuNo, - SkuName = sku.SkuName, - Standard = sku.Standard, - Qty = bind.Qty, - LockQty = 0, - FrozenQty = 0, - InspectQty = 0, - ASNNo = bind.ASNNo, - ASNDetailNo = bind.ASNDetailNo, - WareHouseNo = "",//鎵�灞炰粨搴� - RoadwayNo = "",//鎵�灞炲贩閬� - AreaNo = "",//鎵�灞炲尯鍩� - LocatNo = "",//鍌ㄤ綅鍦板潃 - PalletNo = bind.PalletNo, - PalletNo2 = bind.PalletNo2, - PalletNo3 = bind.PalletNo3, - PalletTags = tags, - CompleteTime = comTime, - ProductionTime = bind.ProductionTime, - ExpirationTime = bind.ExpirationTime, - Status = "0", - InspectMark = bind.InspectMark, - InspectStatus = sku.IsInspect, - BitPalletMark = bind.BitPalletMark, - PackagNo = detail.PackagNo, //liudl 鐢眘ku鐨勫寘瑁呯紪鍙峰彉涓哄叆搴撳崟鏄庣粏鐨勫寘瑁呯紪鐮� - IsBale = bind.IsBale, - IsBelt = bind.IsBelt, - - IsDel = "0", - CreateUser = 0, - CreateTime = comTime - }; - - //缁存姢搴撳瓨鏄庣粏璐т富/渚涘簲鍟嗕俊鎭� - if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 - { - sd1.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 - sd1.OwnerName = notice.CustomerName;//璐т富鍚嶇О - } - else if (notice.Type == "1" || notice.Type == "5")//1:閲囪喘鍏ュ簱,2:鍏跺畠鍏ュ簱 - { - sd1.SupplierNo = notice.CustomerNo;//渚涘簲鍟嗙紪鐮� - sd1.SupplierName = notice.CustomerName;//渚涘簲鍟嗗悕绉� - } - if (quality != null) - { - //淇敼鍚堟牸涓嶅悎鏍兼暟閲� - if (quality.IsQualified == "1") //鍚堟牸 - { - //澧炲姞鍚堟牸鏁伴噺 - quality.PassQty += bind.Qty; - sd1.InspectStatus = "1"; - } - else if (quality.IsQualified == "0") //涓嶅悎鏍� - { - //澧炲姞涓嶅悎鏍兼暟閲� - quality.FailQty += bind.Qty; - sd1.InspectStatus = "2"; - } - Db.Updateable(quality).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 - } - //娣诲姞搴撳瓨鏄庣粏 - sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity(); - } - #endregion - - - - // 鏇存敼绠辨敮鍏崇郴琛� - - var isSample = "0";//鏄惁鍙栨牱 - var sampleQty = 0m;//鍙栨牱鏁伴噺 - - - //if (bind.FullQty < bind.Qty && isTextTable == 0) - if (bind.FullQty < bind.Qty) - { - throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺"); - } - - if (bind.FullQty == bind.Qty) - { - bind.BitPalletMark = "0"; - sd1.BitPalletMark = "0"; - } - //if (bind.Qty > pNum && isTextTable == 0) - if (bind.Qty > pNum) - { - throw new Exception($"缁戝畾澶辫触锛寋bind.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒"); - } - - if (isSample == "1") - { - bind.InspectMark = "1"; - bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; - } - Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); - - #region 鍏ュ簱鍗曞強鏄庣粏 - decimal addQty = model.SkuQty; - - detail.FactQty += addQty;//宸茬粍鏁伴噺 - detail.CompleteQty += addQty;//瀹屾垚鏁伴噺 - if (isSample == "1") //鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�兼敼涓哄垽鏂槸鍚﹀彇鏍� - { - detail.IsSampling = "1"; - } - detail.Status = "1";//0锛氱瓑寰呮墽琛� 1锛氭鍦ㄦ墽琛� 2锛氭墽琛屽畬鎴� - if (detail.CompleteQty >= detail.Qty) - { - detail.Status = "2"; - detail.CompleteTime = comTime; - } - detail.UpdateUser = userId; - detail.UpdateTime = comTime; - //鏇存柊鍏ュ簱鍗曟槑缁� - Db.Updateable(detail).ExecuteCommand(); - - notice.UpdateUser = userId; - notice.UpdateTime = comTime; - if (notice.Status == "0") - { - notice.Status = "1"; - } - var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>() - .Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2"); - if (asnDetailNum == 0) - { - notice.Status = "2"; - notice.CompleteTime = comTime;//瀹屾垚鏃堕棿 - } - //鏇存柊鍏ュ簱鍗� - Db.Updateable(notice).ExecuteCommand(); - #endregion - - #region 搴撳瓨鏄庣粏 + // 鍒ゆ柇搴撳瓨鏄庣粏鏄惁宸叉湁姝ゆ墭鐩樹俊鎭� + var sd1 = Db.Queryable<DataStockDetail>() + .First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo && m.LotNo == bind.LotNo); + var sdId1 = 0; + if (sd1 != null) + { + sdId1 = sd1.Id; + // 搴撳瓨宸插瓨鍦� 鏇存柊鏁版嵁 sd1.Qty = bind.Qty; - //鏇存敼搴撳瓨鏄庣粏鏁伴噺 - Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand(); - #endregion + sd1.CompleteTime = comTime; + sd1.UpdateUser = userId; + sd1.UpdateTime = comTime; - #region 搴撳瓨 - var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo); - if (dataStock != null) + Db.Updateable(sd1).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 + } + else + { + // 搴撳瓨涓嶅瓨鍦� 鎻掑叆鏁版嵁 + sd1 = new DataStockDetail() { - dataStock.Qty += model.SkuQty; - + LotNo = bind.LotNo, + LotText = bind.LotText, + SupplierLot = bind.SupplierLot, + SkuNo = sku.SkuNo, + SkuName = sku.SkuName, + Standard = sku.Standard, + Qty = bind.Qty, + LockQty = 0, + FrozenQty = 0, + InspectQty = 0, + ASNNo = bind.ASNNo, + ASNDetailNo = bind.ASNDetailNo, + WareHouseNo = "",//鎵�灞炰粨搴� + RoadwayNo = "",//鎵�灞炲贩閬� + AreaNo = "",//鎵�灞炲尯鍩� + LocatNo = "",//鍌ㄤ綅鍦板潃 + PalletNo = bind.PalletNo, + PalletNo2 = bind.PalletNo2, + PalletNo3 = bind.PalletNo3, + PalletTags = tags, + CompleteTime = comTime, + ProductionTime = bind.ProductionTime, + ExpirationTime = bind.ExpirationTime, + Status = "0", + InspectMark = bind.InspectMark, + InspectStatus = sku.IsInspect, + BitPalletMark = bind.BitPalletMark, + PackagNo = detail.PackagNo, //liudl 鐢眘ku鐨勫寘瑁呯紪鍙峰彉涓哄叆搴撳崟鏄庣粏鐨勫寘瑁呯紪鐮� + IsBale = bind.IsBale, + IsBelt = bind.IsBelt, - if (bind.InspectMark == "1") - { - dataStock.IsSampling = bind.InspectMark; - } - Db.Updateable(dataStock).ExecuteCommand(); - } - else + IsDel = "0", + CreateUser = 0, + CreateTime = comTime + }; + + //缁存姢搴撳瓨鏄庣粏璐т富/渚涘簲鍟嗕俊鎭� + if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 { - var stock = new DataStock() - { - SkuNo = sku.SkuNo, - SkuName = sku.SkuName, - Standard = sku.Standard, - LotNo = bind.LotNo, - LotText = bind.LotText, - Qty = bind.Qty, - LockQty = 0, - FrozenQty = 0, - IsSampling = bind.InspectMark, - IsDel = "0", - CreateUser = userId, - CreateTime = comTime - }; - //缁存姢搴撳瓨璐т富淇℃伅 - if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 - { - stock.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 - stock.OwnerName = notice.CustomerName;//璐т富鍚嶇О - } - Db.Insertable(stock).ExecuteCommand(); + sd1.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 + sd1.OwnerName = notice.CustomerName;//璐т富鍚嶇О } - #endregion - - #region 璐ㄦ璇烽獙 - if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1") + else if (notice.Type == "1" || notice.Type == "5")//1:閲囪喘鍏ュ簱,2:鍏跺畠鍏ュ簱 { - var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot); - if (qualityRequest == null) - { - string qcNo = new Common().GetMaxNo("QC"); - qualityRequest = new BllQualityInspectionRequest(); - qualityRequest.QcNo = qcNo; - qualityRequest.Status = "0"; - qualityRequest.SkuNo = sku.SkuNo; - qualityRequest.SkuName = sku.SkuName; - qualityRequest.LotNo = bind.LotNo; - qualityRequest.SupplierLot = bind.SupplierLot; - qualityRequest.Qty = detail.Qty; - qualityRequest.SamplingQty = 0; - qualityRequest.ASNNo = detail.ASNNo; - qualityRequest.CreateUser = userId; - qualityRequest.CreateTime = comTime; - //娣诲姞璐ㄦ璇烽獙鍗� - Db.Insertable(qualityRequest).ExecuteCommand(); - } + sd1.SupplierNo = notice.CustomerNo;//渚涘簲鍟嗙紪鐮� + sd1.SupplierName = notice.CustomerName;//渚涘簲鍟嗗悕绉� } - #endregion + if (quality != null) + { + //淇敼鍚堟牸涓嶅悎鏍兼暟閲� + if (quality.IsQualified == "1") //鍚堟牸 + { + //澧炲姞鍚堟牸鏁伴噺 + quality.PassQty += bind.Qty; + sd1.InspectStatus = "1"; + } + else if (quality.IsQualified == "0") //涓嶅悎鏍� + { + //澧炲姞涓嶅悎鏍兼暟閲� + quality.FailQty += bind.Qty; + sd1.InspectStatus = "2"; + } + Db.Updateable(quality).ExecuteCommand(); //淇敼璐ㄦ淇℃伅 + } + //娣诲姞搴撳瓨鏄庣粏 + sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity(); + } + #endregion - // 鏇存敼鎵樼洏浣跨敤鐘舵�� - var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';"; - //娣诲姞鎵樼洏璁板綍琛ㄦ暟鎹� - sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','缁勭洏','0',getDate(),{userId},NULL,NULL);"; - Db.Ado.ExecuteCommand(sqlStr); - new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "鎵樼洏缁戝畾", model.AsnNo, "娣诲姞", $"娣诲姞浜嗘墭鐩樼爜涓猴細{model.PalletNo}鐨勭粍鐩樹俊鎭�", userId); - - + + // 鏇存敼绠辨敮鍏崇郴琛� + + var isSample = "0";//鏄惁鍙栨牱 + var sampleQty = 0m;//鍙栨牱鏁伴噺 + + + //if (bind.FullQty < bind.Qty && isTextTable == 0) + if (bind.FullQty < bind.Qty) + { + throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺"); + } + + if (bind.FullQty == bind.Qty) + { + bind.BitPalletMark = "0"; + sd1.BitPalletMark = "0"; + } + //if (bind.Qty > pNum && isTextTable == 0) + if (bind.Qty > pNum) + { + throw new Exception($"缁戝畾澶辫触锛寋bind.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒"); + } + + if (isSample == "1") + { + bind.InspectMark = "1"; + bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; + } + Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); + + #region 鍏ュ簱鍗曞強鏄庣粏 + decimal addQty = model.SkuQty; + + detail.FactQty += addQty;//宸茬粍鏁伴噺 + detail.CompleteQty += addQty;//瀹屾垚鏁伴噺 + if (isSample == "1") //鍚庢湡涓氬姟寮�鍙戞椂 鎺ュ彛浼犲�兼敼涓哄垽鏂槸鍚﹀彇鏍� + { + detail.IsSampling = "1"; + } + detail.Status = "1";//0锛氱瓑寰呮墽琛� 1锛氭鍦ㄦ墽琛� 2锛氭墽琛屽畬鎴� + if (detail.CompleteQty >= detail.Qty) + { + detail.Status = "2"; + detail.CompleteTime = comTime; + } + detail.UpdateUser = userId; + detail.UpdateTime = comTime; + //鏇存柊鍏ュ簱鍗曟槑缁� + Db.Updateable(detail).ExecuteCommand(); + + notice.UpdateUser = userId; + notice.UpdateTime = comTime; + if (notice.Status == "0") + { + notice.Status = "1"; + } + var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>() + .Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2"); + if (asnDetailNum == 0) + { + notice.Status = "2"; + notice.CompleteTime = comTime;//瀹屾垚鏃堕棿 + } + //鏇存柊鍏ュ簱鍗� + Db.Updateable(notice).ExecuteCommand(); + #endregion + + #region 搴撳瓨鏄庣粏 + sd1.Qty = bind.Qty; + //鏇存敼搴撳瓨鏄庣粏鏁伴噺 + Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand(); + #endregion + + #region 搴撳瓨 + var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo); + if (dataStock != null) + { + dataStock.Qty += model.SkuQty; + + + if (bind.InspectMark == "1") + { + dataStock.IsSampling = bind.InspectMark; + } + Db.Updateable(dataStock).ExecuteCommand(); + } + else + { + var stock = new DataStock() + { + SkuNo = sku.SkuNo, + SkuName = sku.SkuName, + Standard = sku.Standard, + LotNo = bind.LotNo, + LotText = bind.LotText, + Qty = bind.Qty, + LockQty = 0, + FrozenQty = 0, + IsSampling = bind.InspectMark, + IsDel = "0", + CreateUser = userId, + CreateTime = comTime + }; + //缁存姢搴撳瓨璐т富淇℃伅 + if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱 + { + stock.OwnerNo = notice.CustomerNo;//璐т富缂栫爜 + stock.OwnerName = notice.CustomerName;//璐т富鍚嶇О + } + Db.Insertable(stock).ExecuteCommand(); + } + #endregion + + #region 璐ㄦ璇烽獙 + if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1") + { + var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot); + if (qualityRequest == null) + { + string qcNo = new Common().GetMaxNo("QC"); + qualityRequest = new BllQualityInspectionRequest(); + qualityRequest.QcNo = qcNo; + qualityRequest.Status = "0"; + qualityRequest.SkuNo = sku.SkuNo; + qualityRequest.SkuName = sku.SkuName; + qualityRequest.LotNo = bind.LotNo; + qualityRequest.SupplierLot = bind.SupplierLot; + qualityRequest.Qty = detail.Qty; + qualityRequest.SamplingQty = 0; + qualityRequest.ASNNo = detail.ASNNo; + qualityRequest.CreateUser = userId; + qualityRequest.CreateTime = comTime; + //娣诲姞璐ㄦ璇烽獙鍗� + Db.Insertable(qualityRequest).ExecuteCommand(); + } + } + #endregion + + // 鏇存敼鎵樼洏浣跨敤鐘舵�� + var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';"; + //娣诲姞鎵樼洏璁板綍琛ㄦ暟鎹� + sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','缁勭洏','0',getDate(),{userId},NULL,NULL);"; + Db.Ado.ExecuteCommand(sqlStr); + new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "鎵樼洏缁戝畾", model.AsnNo, "娣诲姞", $"娣诲姞浜嗘墭鐩樼爜涓猴細{model.PalletNo}鐨勭粍鐩樹俊鎭�", userId); + + + } #endregion @@ -4805,7 +5304,7 @@ #region JC23鍙栨牱涓氬姟鎺ュ彛 //鑾峰彇鏈粍鎵樻垨宸茬粍鎵樼殑绠辩爜绾у埆 - public BoxInfoDto GetBoxLevel(string boxNo,string boxNo3) + public BoxInfoDto GetBoxLevel(string boxNo, string boxNo3) { try { @@ -4825,7 +5324,7 @@ } var str = "0"; var data = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo && m.Status != "2") - .GroupBy(m=>new {m.BoxNo,m.SkuNo,m.SkuName,m.LotNo}).Select(m=>new BoxInfoDto() + .GroupBy(m => new { m.BoxNo, m.SkuNo, m.SkuName, m.LotNo }).Select(m => new BoxInfoDto() { SkuNo = m.SkuNo, SkuName = m.SkuName, @@ -4840,7 +5339,7 @@ } var count = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.BoxNo == boxNo && !string.IsNullOrWhiteSpace(m.BoxNo3)); - str = count>0 ? "2" : "1"; + str = count > 0 ? "2" : "1"; data[0].BoxLevel = str; return data[0]; } @@ -4871,7 +5370,7 @@ throw new Exception("鏈煡璇㈠埌绛夊緟鎵ц鐨勬墭鐩樼粦瀹氫俊鎭�"); } - if (bindList.Count>1) + if (bindList.Count > 1) { throw new Exception("鎵樼洏缁戝畾淇℃伅瀛樺湪澶氭潯淇℃伅锛岃鏍稿疄"); } @@ -4918,7 +5417,7 @@ throw new Exception("鍙栨牱鏁伴噺涓嶈兘涓虹┖"); } - if (model.BoxLevel!= "1" && model.BoxLevel != "2") + if (model.BoxLevel != "1" && model.BoxLevel != "2") { throw new Exception("鍙栨牱鏍囪瘑閿欒锛岃鍒锋柊椤甸潰"); } @@ -4965,7 +5464,7 @@ { item.Qty -= sampleQty; item.InspectMark = "1";//鎶芥鎵樻爣璁� - item.SamplingQty = item.SamplingQty == null? sampleQty: item.SamplingQty + sampleQty; + item.SamplingQty = item.SamplingQty == null ? sampleQty : item.SamplingQty + sampleQty; } } Db.Updateable(boxList).ExecuteCommand(); @@ -4979,7 +5478,7 @@ throw new Exception("绠辩爜鐘舵�佸凡缁勬墭锛屼絾鏈煡璇㈠埌鎵樼洏缁戝畾淇℃伅"); } bind.BitPalletMark = "1"; - bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; + bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty; bind.Qty -= sampleQty; bind.InspectMark = "1"; Db.Updateable(bind).ExecuteCommand(); @@ -4996,11 +5495,11 @@ } - - } + + } else if (model.BoxLevel == "1") { - if (boxList.Count>1) + if (boxList.Count > 1) { throw new Exception("涓�绾х鐮佹煡璇㈤敊璇紝鍚湁澶氭潯鐩稿悓绠辩爜鏁版嵁"); } @@ -5080,7 +5579,7 @@ var bind = bindList.First(); var boxInfoCount = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.BindNo == bind.Id); - if (boxInfoCount>0) + if (boxInfoCount > 0) { throw new Exception("褰撳墠鎵樼洏缁戝畾淇℃伅鏄湁绠辩爜鐨勶紝璇峰湪鏍囩椤靛彇鏍�"); } -- Gitblit v1.8.0