From 101a25491c535c5fd4173e7f002aea57986512f6 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 24 十月 2025 23:16:05 +0800
Subject: [PATCH] 添加盘盈盘亏

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs |   35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs"
index 54f6325..e4c1574 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs"
@@ -4,6 +4,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
@@ -29,9 +30,12 @@
             {
                 List<Dt_DeliveryOrder> deliveryOrders = new List<Dt_DeliveryOrder>();
                 List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
+                List<Dt_InventoryInfo> _InventoryInfos = new List<Dt_InventoryInfo>();
                 List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => keys.Contains(x.Id));
                 foreach (var item in inventory_Batches)
                 {
+                    supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
+                    if (supplyTasks.Count > 0) throw new Exception($"鐗╂枡缂栧彿銆恵item.MaterielCode}銆戞壒娆″彿銆恵item.BatchNo}銆戝凡瀛樺湪鐩樼偣浠诲姟锛岃鍏堝畬鎴愬綋鍓嶇洏鐐逛换鍔�");
                     List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => item.MaterielCode == x.MaterielCode && x.BatchNo == item.BatchNo);
                     if (inventoryInfos.Count > 0)
                     {
@@ -83,13 +87,19 @@
                                     Remark = "鐩樼偣"
                                 };
                                 supplyTasks.Add(supplyTask);
+                                _InventoryInfos.Add(inventory);
                             }
                             //}
                             #endregion
                         }
                     }
                 }
+                _InventoryInfos.ForEach(x =>
+                {
+                    x.StockStatus = StockStatusEmun.鐩樼偣閿佸畾.ObjToInt();
+                });
                 _unitOfWorkManage.BeginTran();
+                _inventoryInfoService.UpdateData(_InventoryInfos);
                 _supplyTaskService.AddData(supplyTasks);
                 BaseDal.Db.InsertNav(deliveryOrders)
                         .Include(x => x.Details)
@@ -248,13 +258,6 @@
                 _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.鑷姩瀹屾垚);
                 #endregion
 
-                #region 搴撳瓨鎵规
-                Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode);
-                if (inventory_Batch == null) throw new Exception($"鏈壘鍒扮墿鏂欑紪鍙枫�恵inventoryInfo.MaterielCode}銆戠墿鏂欐壒娆°�恵inventoryInfo.BatchNo}銆戠殑搴撳瓨鎵规淇℃伅");
-                inventory_Batch.SupplyQuantity += supplyTask.SupplyQuantity;
-                _inventory_BatchServices.UpdateData(inventory_Batch);
-                #endregion
-
                 #region 鍒ゆ柇褰撳墠鐗╂枡鎵规鐨勭洏鐐逛换鍔℃槸鍚﹀叏閮ㄥ畬鎴�
                 List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.WarehouseCode == supplyTask.WarehouseCode).ToList();
                 if (supplyTasks.Count < 1)
@@ -272,20 +275,28 @@
                 supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                 if (supplyTasks.Count < 1)
                 {
-                    #region 妫�鏌ユ槸鍚︽湁鐩樼偣宸紓锛屾棤宸紓鐩存帴澶勭悊鏁版嵁
-                    if (inventory_Batch.SupplyQuantity == inventory_Batch.StockQuantity)
+                    #region 鏌ユ壘搴撳瓨
+                    var inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
+                    var SupplyQuantitys = inventoryInfos.Select(x => x.SupplyQuantity).ToList().Sum();
+                    #endregion
+
+                    #region 搴撳瓨鎵规
+                    Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
+                    if (SupplyQuantitys == inventory_Batch.StockQuantity)
                     {
-                        var inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == inventory_Batch.BatchNo && x.MaterielCode == inventory_Batch.MaterielCode);
                         foreach (var item in inventoryInfos)
                         {
                             item.StockQuantity = item.SupplyQuantity;
                             item.SupplyQuantity = 0;
+                            item.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                         }
                         _inventoryInfoService.UpdateData(inventoryInfos);
-                        inventory_Batch.SupplyQuantity = 0;
+                    }
+                    else
+                    {
+                        inventory_Batch.SupplyQuantity = SupplyQuantitys;
                         _inventory_BatchServices.UpdateData(inventory_Batch);
                     }
-                    #endregion
                 }
                 #endregion
 

--
Gitblit v1.9.3