From 0e9f21b97c6d0d38350586d43c2b4e3e6949bc07 Mon Sep 17 00:00:00 2001
From: admin <qiutairan163@163.com>
Date: 星期五, 12 十二月 2025 11:40:39 +0800
Subject: [PATCH] 库存统计GetDataStockList默认统计去除LotText分组

---
 Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs |  136 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 102 insertions(+), 34 deletions(-)

diff --git a/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs b/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
index c9bc7b9..02bf227 100644
--- a/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
+++ b/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
@@ -450,8 +450,8 @@
                                 WaveNo = "",
                                 IsIssueLotNo = string.IsNullOrWhiteSpace(d.lotNo) ? "0" : "1",
                                 IsMixBox = "0",
-
                                 OrderDetailCode = d.lineNo,
+                                Status = "0",//榛樿绛夊緟鎵ц
 
                                 CreateUser = 0,
                             };
@@ -580,7 +580,7 @@
                                     WaveNo = "",
                                     IsIssueLotNo = string.IsNullOrWhiteSpace(d.lotNo) ? "0" : "1",
                                     IsMixBox = "0",
-
+                                    Status = "0",//榛樿绛夊緟鎵ц
                                     CreateUser = 0,
                                 };
                                 list.Add(item);
@@ -613,11 +613,11 @@
 
                         CreateUser = 0,
                     };
-                    if (houseNo == "1000" || houseNo == "1001" || houseNo == "2000" || houseNo == "2002" || houseNo == "2003" || houseNo == "2004")
+                    if (houseNo == "1000" || houseNo == "1001" || houseNo == "1002" || houseNo == "1003" || houseNo == "1098" || houseNo == "2000" || houseNo == "2001" || houseNo == "2002" || houseNo == "2003" || houseNo == "2004" || houseNo == "3101" || houseNo == "3102" || houseNo == "3103" || houseNo == "3104")
                     {
                         notice.WareHouseNo = "W02";
                     }
-                    else if (houseNo == "4000")
+                    else if (houseNo == "4000" | houseNo == "4001")
                     {
                         notice.WareHouseNo = "W01";
                     }
@@ -753,12 +753,12 @@
                     //绯荤粺瀵规帴鍚庢斁寮�
                     var jsonData = JsonConvert.SerializeObject(soInfo);
 
-                    var response = HttpHelper.DoPost(url, jsonData, "鍑哄簱鍗曞畬鎴愪笂浼�", "ERP");
+                    var response = HttpHelper.DoPost(url, jsonData, "鍑哄簱鍗曞畬鎴愪笂浼�", "SAP");
 
-                    var obj = JsonConvert.DeserializeObject<ErpModel>(response);//瑙f瀽杩斿洖鏁版嵁
-                    if (obj.Success != 0)
+                    var obj = JsonConvert.DeserializeObject<SapResultModel>(response);//瑙f瀽杩斿洖鏁版嵁
+                    if (obj.RESULT != true)
                     {
-                        throw new Exception("涓婁紶澶辫触" + obj.Message);
+                        throw new Exception("涓婁紶澶辫触" + obj.MESSAGE);
                     }
                     #endregion
                 }
@@ -1231,7 +1231,7 @@
                     //娣诲姞鍑哄簱鍗�
                     foreach (var d in model.Detail)
                     {
-                        if (d.Qty < 1)
+                        if (d.Qty <= 0)
                         {
                             throw new Exception("鍑哄簱鏁伴噺蹇呴』澶т簬0");
                         }
@@ -1452,7 +1452,8 @@
                 {
                     throw new Exception("鏈煡璇㈠埌鍑哄簱鍗曟嵁淇℃伅");
                 }
-                if (notice.Origin != "WMS" || notice.Status != "0")
+                //if (notice.Origin != "WMS" || notice.Status != "0")
+                if (notice.Status != "0")
                 {
                     throw new Exception("鍙傛暟寮傚父,璇锋鏌ョ姸鎬佹槸鍚︽湭绛夊緟鎵ц鎴栨潵婧愭槸鍚︽槸WMS");
                 }
@@ -1509,7 +1510,7 @@
                         //鏇存柊鍑哄簱鍗�
                         foreach (var d in model.Detail)
                         {
-                            if (d.Qty < 1)
+                            if (d.Qty <= 0)
                             {
                                 throw new Exception("鍑哄簱鏁版嵁蹇呴』澶т簬0");
                             }
@@ -1913,12 +1914,14 @@
                 {
                     throw new Exception("鏈煡璇㈠埌鍑哄簱鍗曟嵁淇℃伅");
                 }
-                if (notice.Status != "4")
+                //2025骞�12鏈�08鏃ュ彲鎴疯姹傚皯鎷h揣涔熷彲浠ユ甯稿叧鍗�
+                List<string> statusList = new List<string>() { "3", "4" };
+                if (!statusList.Contains(notice.Status))
                 {
                     throw new Exception("鍙傛暟寮傚父,璇锋鏌ョ姸鎬佹槸鍚︿负鎵ц瀹屾垚鎴栬鍗曞叧闂�");
                 }
-                //鎬诲簱瀛樹俊鎭�
-                var stockList = Db.Queryable<DataStock>().ToList();
+                ////鎬诲簱瀛樹俊鎭�
+                //var stockList = Db.Queryable<DataStock>().ToList();
                 //鍑哄簱鍗曟槑缁�
                 var noticeDetail = Db.Queryable<BllExportNoticeDetail>().Where(m => m.IsDel == "0" && m.SONo == notice.SONo).ToList();
 
@@ -1931,11 +1934,14 @@
                     notice.UpdateTime = DateTime.Now;
                     Db.Updateable(notice).ExecuteCommand();
 
-                    var skuList = noticeDetail.Select(d => d.SkuNo).ToList();
-                    var stocks = stockList.Where(s => skuList.Contains(s.SkuNo)).ToList();
+                    //var skuList = noticeDetail.Select(d => d.SkuNo).ToList();
+                    //var stocks = stockList.Where(s => skuList.Contains(s.SkuNo)).ToList();
+
+                    List<string> sqlList = new List<string>();
 
                     foreach (var d in noticeDetail)
                     {
+                        #region MyRegion
                         //鏇存敼搴撳瓨鏄庣粏閿佸畾鏁伴噺
                         //var orders = dataContext.WmsExportOrder.Where(o => o.ExportDetailId == d.Id
                         //                && o.ExportExecuteFlag != "4" && o.ExportExecuteFlag == "3" && o.pickingType == 0).ToList();
@@ -1967,7 +1973,8 @@
                         //{
                         //    throw new Exception("褰撳墠鍗曟嵁鏄庣粏涓鍒掓暟閲忎笌鎷h揣鏁伴噺涓嶇锛岃鏍稿疄");
                         //}
-                        #region 搴撳瓨琛ㄥ噺鍘婚攣瀹氭暟閲忎笌鎬绘暟閲�(PDA鎷h揣鐨勬椂鍊欏凡缁忓噺鍘绘暟閲忎簡)
+
+                        //搴撳瓨琛ㄥ噺鍘婚攣瀹氭暟閲忎笌鎬绘暟閲�(PDA鎷h揣鐨勬椂鍊欏凡缁忓噺鍘绘暟閲忎簡)
                         /*var sq = stocks.Where(s => s.SkuNo == d.SkuNo);
                         if (!string.IsNullOrWhiteSpace(d.LotNo))
                         {
@@ -1994,7 +2001,58 @@
                             Db.Updateable(st).UpdateColumns(it => new { it.Qty, it.LockQty }).ExecuteCommand();
                         }*/
                         #endregion
+                        //瀹為檯鎷h揣琛�
+                        string completeSql = $@"select PalletNo,Qty-CompleteQty as lessQty
+	from BllExportAllot
+	where IsDel='0' and SONo='{d.SONo}' and SkuNo='{d.SkuNo}' and LotNo='{d.LotNo}'";
+                        DataTable completeDt = Db.Ado.GetDataTable(completeSql);
+                        //淇敼鎵樼洏鏄庣粏鐨勯攣瀹氭暟閲�
+                        foreach (DataRow dr in completeDt.Rows)
+                        {
+                            decimal lessQty = Convert.ToDecimal(dr["lessQty"]);
+                            if (lessQty > 0)
+                            {
+                                //鏌ョ湅搴撳瓨鏄庣粏閿佸畾鏁伴噺-lessQty
+                                string stockDetailSql = $@"select LockQty-{lessQty} as morelockQty from DataStockDetail where IsDel='0' and SkuNo='{d.SkuNo}' and LotNo='{d.LotNo}' and PalletNo='{dr["PalletNo"] + ""}'";
+                                decimal morelockQty = Db.Ado.GetDecimal(stockDetailSql);
+
+                                if (morelockQty >= 0)
+                                {
+                                    sqlList.Add($@"update DataStockDetail set LockQty=LockQty-{morelockQty} where IsDel='0' and SkuNo='{d.SkuNo}' and LotNo='{d.LotNo}' and PalletNo='{dr["PalletNo"] + ""}'");
+                                }
+                            }
+
+                        }
                     }
+
+                    //淇敼搴撳瓨鎬昏〃
+                    string exportDetailSql = $@"select SkuNo,LotNo,sum(Qty)-sum(CompleteQty) as lessQty
+	from BllExportNoticeDetail
+	where IsDel='0' and SONo='{notice.SONo}'
+	group by SkuNo,LotNo";
+                    DataTable exportDetailDt = Db.Ado.GetDataTable(exportDetailSql);
+
+                    foreach (DataRow dr in exportDetailDt.Rows)
+                    {
+                        decimal lessQty = Convert.ToDecimal(dr["lessQty"]);
+                        if (lessQty > 0)
+                        {
+                            //鏌ョ湅搴撳瓨閿佸畾鏁伴噺-lessQty
+                            string stockDetailSql = $@"select LockQty-{lessQty} as morelockQty from DataStock where IsDel='0' and SkuNo='{dr["SkuNo"] + ""}' and LotNo='{dr["LotNo"] + ""}'";
+                            decimal morelockQty = Db.Ado.GetDecimal(stockDetailSql);
+
+                            if (morelockQty >= 0)
+                            {
+                                sqlList.Add($@"update DataStock set LockQty=LockQty-{morelockQty} where IsDel='0' and SkuNo='{dr["SkuNo"] + ""}' and LotNo='{dr["LotNo"] + ""}'");
+                            }
+                        }
+                    }
+
+                    foreach (string sqlStr in sqlList)
+                    {
+                        var end = Db.Ado.ExecuteCommand(sqlStr);
+                    }
+
                     //娣诲姞鎿嶄綔鏃ュ織璁板綍
                     var k = new OperationSOServer().AddLogOperationSo("鍑哄簱浣滀笟", "鍑哄簱鍗曟嵁", notice.SONo, "鍏冲崟", $"鍏抽棴浜嗗崟鎹彿涓簕notice.SONo}鐨勫崟鎹俊鎭�", userId);
 
@@ -2455,7 +2513,7 @@
                 var allot = new AllotLocation();
 
                 #region 闆嗗悎 
-              
+
                 Db.BeginTran();
                 try
                 {
@@ -2790,11 +2848,11 @@
                         }
                         //杩橀渶瑕佸垎閰嶇殑鏁伴噺
                         decimal needQty = detail.Qty - (detail.AllotQty == null ? 0 : decimal.Parse(detail.AllotQty.ToString()));
+                        
+                        //鎺掗櫎杞﹂棿搴撳瓨
+                        List<string> areaNoList = new List<string>() { "B06", "B07", "B09", "B24", "B26", "B27", "B28", "B29" };
                         //搴撳瓨鏄庣粏 Status 0锛氬緟鍒嗛厤 1锛氶儴鍒嗗垎閰�  2锛氬凡鍒嗛厤 
-                        var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.SkuNo == detail.SkuNo && (m.Qty - m.FrozenQty - m.LockQty + m.InspectQty) > 0 && (m.Status == "0" || m.Status == "1") && m.IsDel == "0"
-                        && m.AreaNo != "B06" && m.AreaNo != "B07" && m.AreaNo != "B09" && m.AreaNo != "B24")//鎺掗櫎杞﹂棿搴撳瓨
-                            .ToList();
-
+                        var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.SkuNo == detail.SkuNo && (m.Qty - m.FrozenQty - m.LockQty + m.InspectQty) > 0 && (m.Status == "0" || m.Status == "1") && m.IsDel == "0" && !areaNoList.Contains(m.AreaNo)).ToList();
 
                         //鍒ゆ柇鍗曞彿鏄惁鎸囧畾鎵规
                         if (!string.IsNullOrWhiteSpace(detail.LotNo))
@@ -2879,7 +2937,9 @@
                                 CreateUser = userId,
                                 CreateTime = DateTime.Now
                             };
-                            if (s.WareHouseNo == "W04")
+                            //2025骞�12鏈�08鏃ヨ揣鏋跺簱鍜屽钩搴擄紝鐩存帴寰呮嫞璐�
+                            List<string> wareHouseList = new List<string>() { "W02", "W04" };
+                            if (wareHouseList.Contains(s.WareHouseNo))
                             {
                                 allot.Status = "2";//寰呮嫞璐�
                                 xQty += allot.Qty;
@@ -2896,7 +2956,7 @@
                             {
                                 s.Status = "1";
                             }
-                           
+
                             var sd = Db.Updateable(s).UpdateColumns(it => new { it.LockQty, it.Status }).ExecuteCommand();
 
                         }
@@ -2973,7 +3033,7 @@
                             notice.Status = "3";//姝e湪鎵ц
                         }
                     }
-                    
+
                     notice.UpdateUser = userId;
                     notice.UpdateTime = DateTime.Now;
                     var zd = Db.Updateable(notice).ExecuteCommand();
@@ -3335,7 +3395,9 @@
                             CreateUser = userId,
                             CreateTime = DateTime.Now
                         };
-                        if (stock.WareHouseNo == "W04")
+                        //2025骞�12鏈�08鏃ヨ揣鏋跺簱鍜屽钩搴擄紝鐩存帴寰呮嫞璐�
+                        List<string> wareHouseList = new List<string>() { "W02", "W04" };
+                        if (wareHouseList.Contains(stock.WareHouseNo))
                         {
                             allot.Status = "2";//寰呮嫞璐�
                             xQty += allot.Qty;
@@ -4430,7 +4492,7 @@
                                 }
                             }
                         }
-                        if(string.IsNullOrEmpty(newAddress))
+                        if (string.IsNullOrEmpty(newAddress))
                         {
                             //宸叉湁鐗╁搧鐨勫贩閬�
                             var roadwayHave = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.WareHouseNo == "W01").GroupBy(g => g.RoadwayNo).Select(s => s.RoadwayNo).ToList();
@@ -4461,7 +4523,7 @@
                                 }
                             }
                         }
-                        
+
                     }
                 }
 
@@ -4642,7 +4704,7 @@
                 else
                 {
                     // 鍙栨渶涓婇潰涓�鎺�
-                    location = slotModel[0].LocatNo;                    
+                    location = slotModel[0].LocatNo;
                 }
 
                 bl = true;
@@ -4763,7 +4825,9 @@
 
                     }
 
-                    var endLocateList = Db.Queryable<SysStorageLocat>().Where(m => m.IsDel == "0" && (m.AreaNo == "B02" || m.AreaNo == "B05")).Select(m => m.LocatNo).ToList();
+                    //鎵�灞炲尯鍩熼泦鍚�
+                    List<string> areNolist = new List<string>() { "B01", "B02", "B05" };
+                    var endLocateList = Db.Queryable<SysStorageLocat>().Where(m => m.IsDel == "0" && areNolist.Contains(m.AreaNo)).Select(m => m.LocatNo).ToList();
                     //鍒ゆ柇鏄惁鏄師杈呮枡鍑哄簱浠诲姟  璐ф灦鍌ㄤ綅=銆嬪钩搴撳偍浣�
                     if (endLocateList.Contains(task.EndLocat) && PalletType == "0")
                     {
@@ -6522,19 +6586,22 @@
                         throw new Exception("鏈煡璇㈠埌浠诲姟淇℃伅");
                     }
                     //鑾峰彇瀵瑰簲搴撲綅淇℃伅
-                    var startlocat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == task.StartLocat);
+                    //var startlocat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == task.StartLocat);
+                    var startlocat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == task.StartLocat);
                     if (startlocat == null)
                     {
                         throw new Exception("鏈煡璇㈠埌鍌ㄤ綅淇℃伅");
                     }
                     startlocat.Status = "0";//淇敼鍒嗛厤淇℃伅鐘舵��
                     //鑾峰彇鍌ㄤ綅淇℃伅
-                    var locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == task.StartLocat);
+                    //var locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == task.StartLocat);
+                    var locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == task.StartLocat);
                     //鑾峰彇绉诲簱浠籨鍔″搴旂洰鏍囧偍浣嶄俊鎭�
                     SysStorageLocat endlocat = new SysStorageLocat();
                     if (task.Type == "2")
                     {
-                        endlocat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == task.EndLocat);
+                        //endlocat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == task.EndLocat);
+                        endlocat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == task.EndLocat);
                         if (endlocat == null)
                         {
                             throw new Exception("鏈煡璇㈠埌鐩爣鍌ㄤ綅淇℃伅");
@@ -6598,7 +6665,8 @@
                         //鑾峰彇搴撳瓨
                         var datastock = Db.Queryable<DataStock>().First(a => a.IsDel == "0" && a.SkuNo == stockDetail.SkuNo);
                         //鑾峰彇鍌ㄤ綅淇℃伅
-                        var locate = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == stockDetail.LocatNo);
+                        //var locate = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == "W01" && a.LocatNo == stockDetail.LocatNo);
+                        var locate = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == stockDetail.LocatNo);
 
                         //鍒ゆ柇鏄惁涓虹┖鎵樼洏
                         if (stockDetail.SkuNo == "100099")

--
Gitblit v1.8.0