From d741e7a7ad7de5045e5c6b6145d9da1783cadecd Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 13 一月 2026 09:55:03 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs |  295 ++++++++++++++++++++++++++--------------------------------
 1 files changed, 133 insertions(+), 162 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs"
index b1f62ed..c49a425 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/TakeStockOrderService.cs"
@@ -80,10 +80,10 @@
                 {
                     return WebResponseContent.Instance.Error("璇ユ墭鐩樺浜庨潪鐩樼偣鐘舵�侊紝璇锋鏌ョ洏鐐逛换鍔�");
                 }
-                Dt_TakeStockOrder takeStockOrder = _takeStockOrder.QueryFirst(x=>x.OrderNo == orderNo);
+                Dt_TakeStockOrder takeStockOrder = _takeStockOrder.QueryFirst(x=>x.AllPalletCode.Contains(boxNo)&& x.TakeStockStatus == TakeStockStatusEnum.鐩樼偣涓�.ObjToInt());
                 if (takeStockOrder == null)
                 {
-                    return WebResponseContent.Instance.Error("鏈壘鍒拌鐩樼偣鍗曟嵁");
+                    return WebResponseContent.Instance.Error("璇ユ墭鐩樻湭鎵惧埌璇ョ洏鐐瑰崟鎹�");
                 }
                 if (takeStockOrder.AllPalletCode.Contains(","))
                 {
@@ -103,8 +103,8 @@
                         return WebResponseContent.Instance.Error($"绠卞彿銆恵boxNo}銆戞湭鍦ㄧ洏鐐瑰崟绠卞彿銆恵takeStockOrder.AllPalletCode}銆戜腑鎵惧埌鍖归厤椤�");
                     }
                 }
-
-                return WebResponseContent.Instance.OK();
+                var resultData = new { takeStockOrder = takeStockOrder.OrderNo };
+                return WebResponseContent.Instance.OK(data:resultData);
             }
             catch(Exception ex)
             {
@@ -148,10 +148,6 @@
         {
             try
             {
-                if(completeStockTakeDTO.actualQuantity == completeStockTakeDTO.stockQuantity)
-                {
-                    return WebResponseContent.Instance.OK("璇ユ潯鐮佷负骞宠处锛屾棤闇�璁板綍宸紓");
-                }
                 Dt_TakeStockOrder takeStockOrder = _takeStockOrder.QueryFirst(x=>x.OrderNo == completeStockTakeDTO.orderNo);
                 if (takeStockOrder == null)
                 {
@@ -167,7 +163,6 @@
                 {
                     return WebResponseContent.Instance.Error("鏉$爜搴撳瓨鏁版嵁鏈壘鍒板尮閰嶆暟鎹�");
                 }
-                List<Dt_AllocateMaterialInfo> allocateMaterialInfos = new List<Dt_AllocateMaterialInfo>();
                 Dt_TakeStockOrderDetail takeStockOrderDetail = new Dt_TakeStockOrderDetail()
                 {
                     TakeStockId = takeStockOrder.Id,
@@ -179,7 +174,7 @@
                     Unit = stockInfoDetail.Unit,
                     SysQty = completeStockTakeDTO.stockQuantity,
                     Qty = completeStockTakeDTO.actualQuantity,
-                    Remark = completeStockTakeDTO.actualQuantity - completeStockTakeDTO.stockQuantity >= 0 ? "鐩樼泩" : "鐩樹簭",
+                    Remark = "鐩樹簭",
                     barcode = completeStockTakeDTO.barcode,
                     WarehouseCode = stockInfoDetail.WarehouseCode ?? "",
                     FactoryArea = stockInfoDetail.FactoryArea,
@@ -188,25 +183,12 @@
                     DifferenceQty = completeStockTakeDTO.actualQuantity - completeStockTakeDTO.stockQuantity
 
                 };
-                foreach (var item in stockInfo.Details)
-                {
-                    Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo()
-                    {
-                        Barcode = item.Barcode,
-                        BatchNo = item.BatchNo,
-                        FactoryArea = item.FactoryArea,
-                        MaterialCode = item.MaterielCode,
-                        MaterialName = item.MaterielName,
-                        OrderId = takeStockOrder.Id,
-                        OrderNo = takeStockOrder.OrderNo,
-                        Quantity = item.StockQuantity,
-                        SupplyCode = item.SupplyCode,
-                        Unit = item.Unit
-                    };
-                }
+                stockInfoDetail.StockId = 0;
+                stockInfoDetail.OrderNo = takeStockOrder.OrderNo;
                 stockInfo.StockStatus = StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt();
                 _unitOfWorkManage.BeginTran();
                 _takeStockOrderDetail.AddData(takeStockOrderDetail);
+                _stockInfoDetailRepository.UpdateData(stockInfoDetail);
                 _stockInfoRepository.UpdateData(stockInfo);
                 _unitOfWorkManage.CommitTran();
                 return WebResponseContent.Instance.OK("鐩樼偣瀹屾垚锛岃鍙栬蛋璇ュ紓甯告枡绠辫繘琛屽钩璐﹀鐞嗭紒");
@@ -236,18 +218,14 @@
                 }
 
                 var task = _taskRepository.QueryFirst(x => x.PalletCode == boxNo);
-                    
-
                 if (task != null)
                 {
-                    return content.Error($"鎵樼洏{boxNo}瀛樺湪浠诲姟鍥炲簱澶辫触!");
+                    return content.Error($"鎵樼洏{boxNo}瀛樺湪浠诲姟锛屽洖搴撳け璐�!");
                 }
                 if(stock.StockStatus != StockStatusEmun.鐩樼偣鍑哄簱瀹屾垚.ObjToInt() && stock.StockStatus != StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt())
                 {
                     return content.Error("璇ユ墭鐩樼姸鎬佷笉瀵�,涓嶅厑璁哥洏鐐瑰叆搴�");
                 }
-                stock.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
-
                 var palletCodes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                 if (!string.IsNullOrEmpty(takeStockOrder.AllPalletCode))
                 {
@@ -256,19 +234,14 @@
                         .Select(p => p.Trim())
                         .ToHashSet(StringComparer.OrdinalIgnoreCase);
                 }
-                Dt_TakeStockOrderDetail isReturn = _takeStockOrderDetail.QueryFirst(x => x.TakePalletCode == boxNo && (x.TakeDetalStatus == TakeStockDetailStatusEnum.鏈繘琛屽钩璐﹀鐞�.ObjToInt() || x.TakeDetalStatus == TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊涓�.ObjToInt()));
-                if(isReturn != null)
-                {
-                    return WebResponseContent.Instance.Error("璇ユ墭鐩樿繕鏈夋潯鐮佸緟骞宠处锛岃鍏堝鐞嗗啀鍥炲簱");
-                }
-                bool hasRelatedTasks = _taskRepository.QueryData(x => palletCodes.Contains(x.PalletCode)).Any();
-                bool hasRelatedDetails = _takeStockOrderDetail.QueryData(x => palletCodes.Contains(x.TakePalletCode)).Any();
+                int overPalletCodeCount = _stockInfoRepository.QueryData(x => palletCodes.Contains(x.PalletCode) && (x.StockStatus == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt() || x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() || x.StockStatus == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()|| x.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())).Count();
+                bool hasRelatedTasks = palletCodes.Count == overPalletCodeCount + 1;
 
-                if (!hasRelatedTasks && !hasRelatedDetails)
+                if (hasRelatedTasks)
                 {
                     takeStockOrder.TakeStockStatus = (int)TakeStockStatusEnum.鐩樼偣瀹屾垚;
                 }
-
+                stock.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
                 // 鍒嗛厤鏂拌揣浣�
                 var newLocation = _locationInfoService.AssignLocation(stock.LocationType);
 
@@ -416,128 +389,123 @@
             }
         }
 
-        public WebResponseContent DocumentReconciliation(int orderId, int id)
+        public WebResponseContent DocumentReconciliation(string barcode)
         {
             WebResponseContent webResponseContent = new WebResponseContent();
             try
             {
-                Dt_TakeStockOrderDetail takeStockOrderDetail = _takeStockOrderDetail.QueryFirst(x => x.Id == id);
-                if(takeStockOrderDetail== null)
+                Dt_TakeStockOrderDetail takeStockOrderDetail = _takeStockOrderDetail.QueryFirst(x => x.barcode == barcode);
+                if (takeStockOrderDetail == null)
                 {
                     return WebResponseContent.Instance.Error("鏈壘鍒拌鐩樼偣宸紓鏁版嵁");
                 }
-                if(takeStockOrderDetail.Remark == "鐩樼泩")
+                //if(takeStockOrderDetail.Remark == "鐩樼泩")
+                //{
+                //    Dt_InboundOrderDetail inboundOrderDetail = _inboundOrderDetailRepository.QueryFirst(x => x.Id == orderId);
+                //    if(inboundOrderDetail == null)
+                //    {
+                //        return WebResponseContent.Instance.Error("鏈壘鍒伴�夋嫨鐨勬潅鏀跺钩璐﹀崟鎹�");
+                //    }
+                //    Dt_InboundOrder inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x=>x.Id == inboundOrderDetail.OrderId).Includes(x=>x.Details).First();
+                //    Dt_StockInfo  stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x=>x.PalletCode == takeStockOrderDetail.TakePalletCode && x.StockStatus == StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt()).Includes(x=>x.Details).First();
+                //    if(stockInfo== null)
+                //    {
+                //        return WebResponseContent.Instance.Error($"鐩樼偣鎵樼洏{takeStockOrderDetail.TakePalletCode}鐨勫簱瀛樹俊鎭湭鎵惧埌锛屾垨鎵樼洏鐘舵�佷笉姝g‘");
+                //    }
+                //    var datevaliDate = _inboundOrderRepository.Db.Queryable<Dt_MaterialExpirationDate>().Where(x => x.MaterialCode.Contains(inboundOrderDetail.MaterielCode.Substring(0, 6))).First();
+                //    var newStockDetail = new Dt_StockInfoDetail
+                //    {
+                //        StockId = stockInfo == null ? 0 : stockInfo.Id,
+                //        Barcode = inboundOrderDetail.Barcode,
+                //        MaterielCode = inboundOrderDetail.MaterielCode,
+                //        MaterielName = inboundOrderDetail.MaterielName,
+                //        BatchNo = inboundOrderDetail.BatchNo,
+                //        Unit = inboundOrderDetail.Unit,
+                //        InboundOrderRowNo = inboundOrderDetail.lineNo,
+                //        SupplyCode = inboundOrderDetail.SupplyCode,
+                //        WarehouseCode = inboundOrderDetail.WarehouseCode,
+                //        StockQuantity = inboundOrderDetail.OrderQuantity,
+                //        BarcodeQty = inboundOrderDetail.BarcodeQty,
+                //        BarcodeUnit = inboundOrderDetail.BarcodeUnit,
+                //        FactoryArea = inboundOrder.FactoryArea,
+                //        Status = 0,
+                //        OrderNo = inboundOrder.InboundOrderNo,
+                //        BusinessType = inboundOrder.BusinessType,
+                //        ValidDate = inboundOrder.BusinessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠�.ToString() ? inboundOrderDetail.ValidDate : datevaliDate == null ? null : Convert.ToDateTime(DateTime.Now).AddDays(Convert.ToDouble(datevaliDate.ValidityDays)),
+                //    };
+                //    stockInfo.Details.Add(newStockDetail);
+
+                //    inboundOrderDetail.ReceiptQuantity = inboundOrderDetail.OrderQuantity;
+                //    inboundOrderDetail.OverInQuantity = inboundOrderDetail.OrderQuantity;
+                //    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                //    int overCount = 1;
+                //    int moreOverCount = inboundOrder.Details.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
+                //    if (inboundOrder.Details.Count() == overCount + moreOverCount)
+                //    {
+                //        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+                //    }
+                //    else
+                //    {
+                //        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                //    }
+                //    takeStockOrderDetail.DifferenceQty -= inboundOrderDetail.OrderQuantity;
+                //    if(takeStockOrderDetail.DifferenceQty > 0)
+                //    {
+                //        takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊涓�.ObjToInt();
+                //    }
+                //    else if (takeStockOrderDetail.DifferenceQty == 0)
+                //    {
+                //        takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊.ObjToInt();
+                //    }
+                //    else
+                //    {
+                //        return WebResponseContent.Instance.Error("璇ユ潅鏀跺崟鎹槑缁嗘潯鐮佹暟閲忓ぇ浜庡緟骞宠处鏁伴噺锛岃鍙﹂�夊叾浠栧崟鎹钩璐�");
+                //    }
+
+                //    _unitOfWorkManage.BeginTran();
+                //    _inboundOrderRepository.UpdateData(inboundOrder);
+                //    _inboundOrderDetailRepository.UpdateData(inboundOrderDetail);
+                //    _takeStockOrderDetail.UpdateData(takeStockOrderDetail);
+                //    BaseDal.Db.Insertable(newStockDetail).ExecuteCommand();
+                //    _unitOfWorkManage.CommitTran();
+                //    List<string> barcodes = new List<string>();
+                //    barcodes.Add(inboundOrderDetail.Barcode);
+                //    _outboundPickingService.NoStockOutBatchInOrderFeedbackToMes(inboundOrder.Id, barcodes);
+
+
+                //}
+                //else
+                //{
+                Dt_OutboundOrderDetail outboundOrderDetail = _outboundOrderDetailRepository.QueryFirst(x => x.Remark == takeStockOrderDetail.TakeStockNo && (x.OrderQuantity-x.LockQuantity-x.MoveQty)>0);
+                if (outboundOrderDetail == null)
                 {
-                    Dt_InboundOrderDetail inboundOrderDetail = _inboundOrderDetailRepository.QueryFirst(x => x.Id == orderId);
-                    if(inboundOrderDetail == null)
-                    {
-                        return WebResponseContent.Instance.Error("鏈壘鍒伴�夋嫨鐨勬潅鏀跺钩璐﹀崟鎹�");
-                    }
-                    Dt_InboundOrder inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x=>x.Id == inboundOrderDetail.OrderId).Includes(x=>x.Details).First();
-                    Dt_StockInfo  stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x=>x.PalletCode == takeStockOrderDetail.TakePalletCode && x.StockStatus == StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt()).Includes(x=>x.Details).First();
-                    if(stockInfo== null)
-                    {
-                        return WebResponseContent.Instance.Error($"鐩樼偣鎵樼洏{takeStockOrderDetail.TakePalletCode}鐨勫簱瀛樹俊鎭湭鎵惧埌锛屾垨鎵樼洏鐘舵�佷笉姝g‘");
-                    }
-                    var datevaliDate = _inboundOrderRepository.Db.Queryable<Dt_MaterialExpirationDate>().Where(x => x.MaterialCode.Contains(inboundOrderDetail.MaterielCode.Substring(0, 6))).First();
-                    var newStockDetail = new Dt_StockInfoDetail
-                    {
-                        StockId = stockInfo == null ? 0 : stockInfo.Id,
-                        Barcode = inboundOrderDetail.Barcode,
-                        MaterielCode = inboundOrderDetail.MaterielCode,
-                        MaterielName = inboundOrderDetail.MaterielName,
-                        BatchNo = inboundOrderDetail.BatchNo,
-                        Unit = inboundOrderDetail.Unit,
-                        InboundOrderRowNo = inboundOrderDetail.lineNo,
-                        SupplyCode = inboundOrderDetail.SupplyCode,
-                        WarehouseCode = inboundOrderDetail.WarehouseCode,
-                        StockQuantity = inboundOrderDetail.OrderQuantity,
-                        BarcodeQty = inboundOrderDetail.BarcodeQty,
-                        BarcodeUnit = inboundOrderDetail.BarcodeUnit,
-                        FactoryArea = inboundOrder.FactoryArea,
-                        Status = 0,
-                        OrderNo = inboundOrder.InboundOrderNo,
-                        BusinessType = inboundOrder.BusinessType,
-                        ValidDate = inboundOrder.BusinessType == BusinessTypeEnum.澶栭儴浠撳簱璋冩櫤浠�.ToString() ? inboundOrderDetail.ValidDate : datevaliDate == null ? null : Convert.ToDateTime(DateTime.Now).AddDays(Convert.ToDouble(datevaliDate.ValidityDays)),
-                    };
-                    stockInfo.Details.Add(newStockDetail);
-
-                    inboundOrderDetail.ReceiptQuantity = inboundOrderDetail.OrderQuantity;
-                    inboundOrderDetail.OverInQuantity = inboundOrderDetail.OrderQuantity;
-                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
-                    int overCount = 1;
-                    int moreOverCount = inboundOrder.Details.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
-                    if (inboundOrder.Details.Count() == overCount + moreOverCount)
-                    {
-                        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
-                    }
-                    else
-                    {
-                        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
-                    }
-                    takeStockOrderDetail.DifferenceQty -= inboundOrderDetail.OrderQuantity;
-                    if(takeStockOrderDetail.DifferenceQty > 0)
-                    {
-                        takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊涓�.ObjToInt();
-                    }
-                    else if (takeStockOrderDetail.DifferenceQty == 0)
-                    {
-                        takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊.ObjToInt();
-                    }
-                    else
-                    {
-                        return WebResponseContent.Instance.Error("璇ユ潅鏀跺崟鎹槑缁嗘潯鐮佹暟閲忓ぇ浜庡緟骞宠处鏁伴噺锛岃鍙﹂�夊叾浠栧崟鎹钩璐�");
-                    }
-                    
-                    _unitOfWorkManage.BeginTran();
-                    _inboundOrderRepository.UpdateData(inboundOrder);
-                    _inboundOrderDetailRepository.UpdateData(inboundOrderDetail);
-                    _takeStockOrderDetail.UpdateData(takeStockOrderDetail);
-                    BaseDal.Db.Insertable(newStockDetail).ExecuteCommand();
-                    _unitOfWorkManage.CommitTran();
-                    List<string> barcodes = new List<string>();
-                    barcodes.Add(inboundOrderDetail.Barcode);
-                    _outboundPickingService.NoStockOutBatchInOrderFeedbackToMes(inboundOrder.Id, barcodes);
-
-
+                    return WebResponseContent.Instance.Error("鏈壘鍒伴�夋嫨鐨勬潅鍙戝钩璐﹀崟鎹�");
                 }
-                else
+                if(outboundOrderDetail.MaterielCode != takeStockOrderDetail.MaterielCode)
                 {
-                    Dt_OutboundOrderDetail outboundOrderDetail = _outboundOrderDetailRepository.QueryFirst(x => x.Id == orderId);
-                    if (outboundOrderDetail == null)
-                    {
-                        return WebResponseContent.Instance.Error("鏈壘鍒伴�夋嫨鐨勬潅鍙戝钩璐﹀崟鎹�");
-                    }
-                    Dt_OutboundOrder outboundOrder = _outboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First();
-                    Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == takeStockOrderDetail.TakePalletCode && x.StockStatus == StockStatusEmun.鐩樼偣搴撳瓨瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
-                    if (stockInfo == null)
-                    {
-                        return WebResponseContent.Instance.Error($"鐩樼偣鎵樼洏{takeStockOrderDetail.TakePalletCode}鐨勫簱瀛樹俊鎭湭鎵惧埌锛屾垨鎵樼洏鐘舵�佷笉姝g‘");
-                    }
-                    if(outboundOrderDetail.OrderQuantity + takeStockOrderDetail.DifferenceQty > 0)
-                    {
-                        return WebResponseContent.Instance.Error("璇ユ潅鍙戝崟鎹槑缁嗗彂鏂欐暟閲忓ぇ浜庡緟骞宠处鏁伴噺锛岃鍙﹂�夊叾浠栧崟鎹钩璐�");
-                    }
-                    else if(outboundOrderDetail.OrderQuantity + takeStockOrderDetail.DifferenceQty < 0)
-                    {
-                        takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊涓�.ObjToInt();
-                    }
-                    else
-                    {
-                        takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊.ObjToInt();
-                    }
-                    OutboundCompleteRequestDTO request = new OutboundCompleteRequestDTO()
-                    {
-                        OrderNo = outboundOrder.OrderNo,
-                        PalletCode = stockInfo.PalletCode,
-                        Barcode = takeStockOrderDetail.barcode,
-                        Operator = App.User.UserName
-                    };
-                    decimal stoQty = takeStockOrderDetail.SysQty;
-                  webResponseContent = CompleteOutboundWithBarcode(request, stoQty, orderId);
-                    takeStockOrderDetail.DifferenceQty = 0;
-                    _takeStockOrderDetail.UpdateData(takeStockOrderDetail);
+                    return WebResponseContent.Instance.Error("涓庢潅鍙戝钩璐﹀崟鎹墿鏂欑紪鐮佷笉鍖归厤");
                 }
+                if (!string.IsNullOrWhiteSpace(outboundOrderDetail.BatchNo)&& outboundOrderDetail.BatchNo != takeStockOrderDetail.BatchNo)
+                {
+                    return WebResponseContent.Instance.Error("涓庢潅鍙戝钩璐﹀崟鎹墿鏂欐壒娆′笉鍖归厤");
+                }
+                if (!string.IsNullOrWhiteSpace(outboundOrderDetail.SupplyCode) && outboundOrderDetail.SupplyCode != takeStockOrderDetail.SupplyCode)
+                {
+                    return WebResponseContent.Instance.Error("涓庢潅鍙戝钩璐﹀崟鎹緵搴斿晢涓嶅尮閰�");
+                }
+                Dt_OutboundOrder outboundOrder = _outboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First();
+
+                takeStockOrderDetail.TakeDetalStatus = TakeStockDetailStatusEnum.鏉傛敹鏉傚彂骞宠处澶勭悊.ObjToInt();
+                OutboundCompleteRequestDTO request = new OutboundCompleteRequestDTO()
+                {
+                    OrderNo = outboundOrder.OrderNo,
+                    PalletCode = takeStockOrderDetail.TakePalletCode,
+                    Barcode = takeStockOrderDetail.barcode,
+                    Operator = App.User.UserName
+                };
+                webResponseContent = CompleteOutboundWithBarcode(request,outboundOrderDetail.Id);
+                takeStockOrderDetail.DifferenceQty = 0;
+                _takeStockOrderDetail.UpdateData(takeStockOrderDetail);
                 return WebResponseContent.Instance.OK(data: webResponseContent);
             }
             catch(Exception ex)
@@ -547,7 +515,7 @@
 
             }
         }
-        public WebResponseContent CompleteOutboundWithBarcode(OutboundCompleteRequestDTO request ,decimal stoQty, int orderDetailId)
+        public WebResponseContent CompleteOutboundWithBarcode(OutboundCompleteRequestDTO request ,int orderDetailId)
         {
             WebResponseContent content = WebResponseContent.Instance;
 
@@ -572,13 +540,7 @@
                     return WebResponseContent.Instance.Error($"鏉$爜 {request.Barcode} 瀵瑰簲鐨勫簱瀛樻槑缁嗕笉瀛樺湪");
                 }
 
-                // 3. 楠岃瘉搴撳瓨鏄庣粏涓庢墭鐩樻槸鍚﹀尮閰�
-                if (stockDetail.StockId != stockInfo.Id)
-                {
-                    response.Success = false;
-                    response.Message = $"鏉$爜 {request.Barcode} 涓嶅睘浜庢墭鐩樺彿 {request.PalletCode} 鐨勫簱瀛樻槑缁�";
-                    return WebResponseContent.Instance.Error($"鏉$爜 {request.Barcode} 涓嶅睘浜庢墭鐩樺彿 {request.PalletCode} 鐨勫簱瀛樻槑缁�");
-                }
+
 
                 // 4. 鏌ユ壘鍑哄簱鍗曚俊鎭�
                 Dt_OutboundOrder outboundOrder = _outboundOrderRepository.QueryFirst(o => o.OrderNo == request.OrderNo);
@@ -595,11 +557,11 @@
                     return WebResponseContent.Instance.Error("鏈壘鍒板嚭搴撳崟鏄庣粏");
                 }
                 // 瀹為檯鍑哄簱閲�
-                decimal actualOutboundQuantity = outboundOrderDetail.OrderQuantity;
+                decimal actualOutboundQuantity = outboundOrderDetail.OrderQuantity-outboundOrderDetail.LockQuantity-outboundOrderDetail.MoveQty;
 
 
                 // 8. 鍒ゆ柇鏄惁闇�瑕佹媶鍖咃紙褰撳嚭搴撴暟閲忓皬浜庡簱瀛樻暟閲忔椂闇�瑕佹媶鍖咃級
-                bool isUnpacked = outboundOrderDetail.OrderQuantity < stockDetail.StockQuantity;
+                bool isUnpacked = actualOutboundQuantity < stockDetail.StockQuantity;
                 List<MaterialCodeReturnDTO> returnDTOs = new List<MaterialCodeReturnDTO>();
                 string newBarcode = string.Empty;
                 // 9. 寮�鍚簨鍔�
@@ -746,7 +708,12 @@
                         // 鐗╂枡鏂版潯鐮佸洖浼�
                         _feedbackMesService.BarcodeFeedback(newBarcode);
                     }
-
+                    List<Dt_OutboundOrderDetail> details = _outboundOrderDetailRepository.QueryData(x => x.OrderId == outboundOrder.Id);
+                    if(details.All(x => x.OverOutQuantity >= x.OrderQuantity - x.MoveQty))
+                    {
+                        outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                        _outboundOrderRepository.UpdateData(outboundOrder);
+                    }
                     _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo);
 
                 }
@@ -767,6 +734,10 @@
             return content;
         }
 
+        public WebResponseContent StockTakeGroupPallet(string barcode, string boxNo)
+        {
+            throw new NotImplementedException();
+        }
     }
     
 }

--
Gitblit v1.9.3