From 600f659aa5cbfc0cca52d883f4299cbb8dd66dcd Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期一, 02 三月 2026 15:30:04 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs |   48 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
index 3f465c6..94278e9 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
@@ -39,7 +39,7 @@
                 {
                     throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
                 }
-                if (outboundOrderDetails.FirstOrDefault()?.LPNNo == null)
+                if (outboundOrderDetails.FirstOrDefault()?.LPNNo == null || outboundOrderDetails.FirstOrDefault()?.LPNNo == "")
                 {
                     outboundOrderDetails.Clear();
                     try
@@ -405,14 +405,46 @@
                     //}
 
                     var stockdetailbox = BaseDal.Db.Queryable<Dt_StockInfo>().LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId).LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId).Where((s, d, cp) => allBoxCodes.Contains(cp.BoxCode)).Select((s, d, cp) => cp.BoxCode)
-                .Distinct()
-                .ToList();
+                        .Distinct()
+                        .ToList();
 
                     var stockInfoDetailCPList = _stockInfoDetailCPRepository.QueryData(x => stockdetailbox.Contains(x.BoxCode)).ToList();
                     if (stockInfoDetailCPList != null)
                     {
                         _stockInfoDetailCPRepository.DeleteAndMoveIntoHty(stockInfoDetailCPList, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+
+                        for (int i = 0; i < stockInfoDetailCPList.Count(); i++)
+                        {
+                            Dt_StockInfo dt_StockInfo = BaseDal.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == item.LPNNo).Includes(x => x.Details).First();
+                            if (dt_StockInfo == null)
+                            {
+                                return WebResponseContent.Instance.Error($"鎵樼洏{item.LPNNo}鏃犵鐮佹槑缁嗕俊鎭�");
+                            }
+                            List<Dt_StockInfoDetail> stockdetails = dt_StockInfo.Details;
+
+                            var matchedDetail = stockdetails.FirstOrDefault(d => d.MaterielCode.Contains(stockInfoDetailCPList[i].PartNum) && d.BatchNo.Contains(item.BatchNo));
+                            if (matchedDetail != null)
+                            {
+                                matchedDetail.StockQuantity -= (decimal)stockInfoDetailCPList[i].QtyOfpcs;
+                                matchedDetail.OutboundQuantity += (decimal)stockInfoDetailCPList[i].QtyOfpcs;
+                                _stockInfoDetailRepository.UpdateData(matchedDetail);
+
+                                if (matchedDetail.StockQuantity == 0)
+                                {
+                                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(matchedDetail, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                                }
+                            }
+                            else
+                            {
+                                return WebResponseContent.Instance.Error($"鎵樼洏{item.LPNNo}涓湭鎵惧埌鐗╂枡{stockInfoDetailCPList[i].PartNum}鍜屾壒娆item.BatchNo}鐨勬槑缁�");
+                            }
+                            if (dt_StockInfo.Details.Sum(x => x.StockQuantity) == 0)
+                            {
+                                _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(dt_StockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                            }
+                        }
                     }
+
                 }
                 _unitOfWorkManage.CommitTran();
             }
@@ -466,11 +498,17 @@
                     });
                     result.Item2.ForEach(x =>
                     {
-                        x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+                        foreach (var item in result.Item2)
+                        {
+                            if (item.LockQuantity > 0)
+                            {
+                                item.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+                            }
+                        }
+
                     });
                     result.Item3.ForEach(x =>
                     {
-
                         x.Status = OutStockStatus.鍑哄簱涓�.ObjToInt();
                     });
 

--
Gitblit v1.9.3