From 04dc32710b622641d4e17ec903c698c65269e12c Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期二, 24 十二月 2024 08:58:13 +0800
Subject: [PATCH] 出库详情记录修改

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs |   74 ++++++++++++++++++++++++-------------
 1 files changed, 48 insertions(+), 26 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
index f44093e..1c3fe6f 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs"
@@ -234,38 +234,52 @@
                 float needQuantity = originalNeedQuantity;
 
                 List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, outboundOrder.WarehouseId);
+                if (!stockInfos.Any())
+                {
+                    throw new Exception($"鏈壘鍒板彲鍒嗛厤搴撳瓨");
+                }
                 List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, item.MaterielCode, needQuantity, out float residueQuantity);
                 item.LockQuantity += needQuantity - residueQuantity;
                 outStocks.AddRange(autoAssignStocks);
                 float assignQuantity = needQuantity - residueQuantity;
-                //for (int i = 0; i < outboundOrderDetails.Count; i++)
-                //{
-                //    for (int j = 0; j < outStocks.Count; j++)
-                //    {
-                //        if(assignQuantity > 0)
-                //        {
-                //            if (outboundOrderDetails[i].OrderQuantity - outboundOrderDetails[i].LockQuantity >= outStocks[j].)
-                //            {
 
-                //            }
-                //        }
-                //    }
+                List<Dt_OutboundOrderDetail> details = outboundOrderDetails.Where(x => !string.IsNullOrEmpty(x.BatchNo) ? x.BatchNo == item.BatchNo : true && x.MaterielCode == item.MaterielCode).ToList();
 
-                //    if (assignQuantity > 0 && outboundOrderDetails[i].LockQuantity < outboundOrderDetails[i].OrderQuantity)
-                //    {
-                //        outStockLockInfos.AddRange(_outStockLockInfoService.GetOutStockLockInfos(outboundOrder, outboundOrderDetails[i], outStocks));
-                //        if (outboundOrderDetails[i].OrderQuantity - outboundOrderDetails[i].LockQuantity >= assignQuantity)
-                //        {
-                //            outboundOrderDetails[i].LockQuantity += assignQuantity;
-                //            break;
-                //        }
-                //        else
-                //        {
-                //            assignQuantity -= (outboundOrderDetails[i].OrderQuantity - outboundOrderDetails[i].LockQuantity);
-                //            outboundOrderDetails[i].LockQuantity = outboundOrderDetails[i].OrderQuantity;
-                //        }
-                //    }
-                //}
+                for (int i = 0; i < details.Count; i++)
+                {
+                    float orderQuantity = details[i].OrderQuantity;
+                    for (int j = 0; j < autoAssignStocks.Count; j++)
+                    {
+                        float detailAssignQuantity = outStockLockInfos.Where(x => !string.IsNullOrEmpty(x.BatchNo) ? x.BatchNo == item.BatchNo : true && x.MaterielCode == item.MaterielCode && x.OrderDetailId == details[i].Id).Sum(x => x.AssignQuantity);//鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲�
+
+                        float palletAssignQuantity = outStockLockInfos.Where(x => x.BatchNo == item.BatchNo && x.MaterielCode == item.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//鍑哄簱璇︽儏宸插垎閰嶆暟閲�
+                        if (string.IsNullOrEmpty(item.BatchNo))
+                        {
+                            palletAssignQuantity = outStockLockInfos.Where(x => x.MaterielCode == item.MaterielCode && x.PalletCode == autoAssignStocks[j].PalletCode).Sum(x => x.AssignQuantity);//鍑哄簱璇︽儏宸插垎閰嶆暟閲�
+                        }
+                        float palletOutboundQuantity = autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity);
+                        if (palletAssignQuantity < palletOutboundQuantity)//濡傛灉鍑哄簱璇︽儏宸插垎閰嶆暟閲忓皬浜庢墭鐩樺凡鍒嗛厤鏁伴噺锛屽垯鍙互缁х画娣诲姞璇ユ墭鐩樺嚭搴撲俊鎭�
+                        {
+                            float orderDetailNeedQuantity = details[i].OrderQuantity - detailAssignQuantity;
+                            if (orderDetailNeedQuantity > autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity)
+                            {
+                                details[i].LockQuantity += autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity;
+                                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, details[i], autoAssignStocks[j], autoAssignStocks[j].Details.Sum(x => x.OutboundQuantity) - palletAssignQuantity);
+                                outStockLockInfos.Add(outStockLockInfo);
+                            }
+                            else
+                            {
+                                Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, details[i], autoAssignStocks[j], details[i].OrderQuantity - details[i].LockQuantity);
+                                outStockLockInfos.Add(outStockLockInfo);
+                                details[i].LockQuantity = details[i].OrderQuantity;
+                                break;
+                            }
+
+                        }
+                    }
+                }
+
+
                 locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()));
             }
 
@@ -385,6 +399,14 @@
                 List<Dt_OutStockLockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList();
                 if (addOutStockLockInfos != null && addOutStockLockInfos.Any())
                 {
+                    if(tasks != null)
+                    {
+                        addOutStockLockInfos.ForEach(x =>
+                        {
+                            x.TaskNum = tasks.FirstOrDefault(v => v.PalletCode == x.PalletCode)?.TaskNum;
+                        });
+                    }
+                   
                     _outStockLockInfoService.Repository.AddData(addOutStockLockInfos);
                 }
                 List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList();

--
Gitblit v1.9.3