From 4cca607ddce9577864b8a5c9c8edf7c83915b787 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 23 十月 2025 12:32:34 +0800
Subject: [PATCH] 修改物料信息删除方法

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs |   88 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 70 insertions(+), 18 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
index 2daa804..5a66e35 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/InventoryServices.cs"
@@ -97,19 +97,21 @@
                 {
                     return new ApiResponse<Dt_InventoryInfo> { code = "500", msg = "璇锋眰鍙傛暟鏃犳晥" };
                 }
-               
+
+                //鏌ユ壘鍒板叏閮ㄧ殑
+
                 foreach (var detail in request.details)
                 {
-                     var goods = Db.Queryable<Dt_MaterielInfo>().Where(x => x.MaterielCode == detail.productCode).First();
+                    var goods = Db.Queryable<Dt_MaterielInfo>().Where(x => x.MaterielCode == detail.productCode).First();
 
-                    // 3锔忊儯 璁$畻鍏ュ簱鏁伴噺锛堝彇姝o級
+                    // 3锔� 璁$畻鍏ュ簱鏁伴噺锛堝彇姝o級閬嶅巻 orderDetails 涓殑姣忎釜 EdiOrderBoxDto 瀵硅薄
                     decimal orderQty = detail.orderDetails?
                         .Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0)
                         ?? 0;
 
                     // 5锔忊儯 鏌ヨ搴撳瓨璇︽儏
                     var entity = BaseDal.Db.Queryable<Dt_InventoryInfo>()
-                        .First(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo&&x.LocationCode=="绔嬪簱");
+                        .First(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo && x.LocationCode == "绔嬪簱");
                     //鏌ヨ鐗╂枡琛�
                     var Goods = BaseDal.Db.Queryable<Dt_MaterielInfo>().First(x => x.MaterielCode == detail.productCode);
 
@@ -163,44 +165,46 @@
                     switch (request.orderType)
                     {
                         case "1": //鍏ュ簱
-                            entity.StockQuantity += orderQty;
+                            entity.StockQuantity = orderQty; //瀹為檯搴撳瓨
                             entity.InDate = DateTime.Now;
                             entity.Remark = "鍏ュ簱鍗曞洖浼�";
-                            //Goods.Business_qty=
 
-                            batch.StockQuantity += orderQty;
+
+                            batch.StockQuantity = orderQty;
                             batch.Remark = "鍏ュ簱鍗曞洖浼�";
+                            UpdateInboundOrderDetailStatus(detail.batchNo, detail.productCode);
                             break;
 
-                        case "2": // 鍑哄簱
-                            entity.OutboundQuantity += orderQty; //鍑哄簱鏁伴噺
-                            entity.StockQuantity -= orderQty;
+                        case "2": // 鍑哄簱  鎬�100  鍑�20
+                            decimal actualOutQty = entity.StockQuantity - orderQty;// 璁$畻鏈瀹為檯鍑哄簱鏁伴噺 20
+                            entity.StockQuantity=orderQty; //瀹為檯搴撳瓨鏁� 100
+                            entity.OutboundQuantity =Math.Max(0,entity.OutboundQuantity-actualOutQty); //寰呭嚭搴撴暟閲�
                             if (entity.StockQuantity < 0) entity.StockQuantity = 0;
                             entity.Remark = "鍑哄簱鍗曞洖浼�";
 
-                            //CreateAllocatInOut()
-                            batch.OutboundQuantity += orderQty;
-                            batch.StockQuantity -= orderQty;
+
+                            batch.StockQuantity = orderQty;
+                            batch.OutboundQuantity =Math.Max(0,batch.OutboundQuantity-actualOutQty);//寰呭嚭搴撴暟閲�
                             if (batch.StockQuantity < 0) batch.StockQuantity = 0;
                             batch.Remark = "鍑哄簱鍗曞洖浼�";
+                            UpdateOutboundOrderDetailStatus(detail.batchNo, detail.productCode);
                             //璋冩嫧浠诲姟
                             _deliveryOrderServices.CreateAllocatInOut(goods);
-
-
                             break;
 
                         case "3": // 鐩樼偣
                             decimal diff = detail.ea ?? 0;             // 宸紓鏁�
                             int flag = detail.isLossOrProfit ?? 3;     // 1=鐩樹簭, 2=鐩樼泩, 3=鐩樹腑
-
                             if (flag == 1) // 鐩樹簭
                             {
-                                batch.SupplyQuantity = batch.StockQuantity - diff;
+                                //搴撳瓨鏁�-宸紓鏁�=鐩樹簭
+                                batch.SupplyQuantity +=( batch.StockQuantity - diff);
                                 batch.Remark = "鐩樼偣鍗曞洖浼� - 鐩樹簭";
                             }
                             else if (flag == 2) // 鐩樼泩
                             {
-                                batch.SupplyQuantity = batch.StockQuantity + diff;
+                                //搴撳瓨鏁�+宸紓鏁�=鐩樼泩
+                                batch.SupplyQuantity +=(batch.StockQuantity + diff);
                                 batch.Remark = "鐩樼偣鍗曞洖浼� - 鐩樼泩";
                             }
                             else // 鐩樹腑
@@ -246,6 +250,54 @@
         }
 
 
+        /// <summary>
+        /// 鏇存柊鍏ュ簱鍗曡缁�
+        /// </summary>
+        /// <param name="batchNo">鎵规鍙�</param>
+        /// <param name="productCode">鐗╂枡鍚嶇紪鐮�/param>
+        public void UpdateInboundOrderDetailStatus(string batchNo,string productCode)
+        {
+            try
+            {
+                //鏌ヨ璇︽儏
+                var detail = BaseDal.Db.Queryable<Dt_CabinOrderDetail>()
+                .First(x => x.Goods_no == productCode && x.Batch_num == batchNo && x.OrderDetailStatus == "寮�濮�" && x.Status == 1);
+                //鏌ユ壘鍒板悗鏍规嵁鐗╂枡鐘舵�侊紙OrderDetailStatus==寮�濮嬶級 璇ョ姸鎬丼tatus=1淇敼璇ユ潯璇︽儏鐨凮rderDetailStatus==宸插畬鎴�
+                detail.OrderDetailStatus = "宸插畬鎴�";
+                BaseDal.Db.Updateable(detail).ExecuteCommand();
+            }
+            catch (Exception ex)
+            {
+
+                throw;
+            }
+
+        }
+
+        /// <summary>
+        ///  //鏌ユ壘鍒板悗鏍规嵁鐗╂枡鐘舵�侊紙OrderDetailStatus==寮�濮嬶級 璇ョ姸鎬丼tatus=1淇敼璇ユ潯璇︽儏鐨凮rderDetailStatus==宸插畬鎴�
+        /// </summary>
+        /// <param name="batchNo"></param>
+        /// <param name="productCode"></param>
+        public void UpdateOutboundOrderDetailStatus(string batchNo, string productCode)
+        {
+            try
+            {
+                //鏌ヨ璇︽儏
+                var detail = BaseDal.Db.Queryable<Dt_DeliveryOrderDetail>()
+                .First(x => x.Goods_no == productCode && x.Batch_num == batchNo && x.OotDetailStatus == "寮�濮�" && x.Status == 1);
+                detail.OotDetailStatus = "宸插畬鎴�";
+                BaseDal.Db.Updateable(detail).ExecuteCommand();
+            }
+            catch (Exception ex)
+            {
+
+                throw;
+            }
+         
+
+        }
+
 
         /// <summary>
         /// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨

--
Gitblit v1.9.3