1
wangxinhui
3 天以前 75b59f8bd0ce2610f8c77e3188926cab20c933a9
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs
@@ -1,5 +1,6 @@
using AutoMapper;
using Castle.Core.Resource;
using Org.BouncyCastle.Asn1.Cmp;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -764,19 +765,14 @@
                .Select((master, detail) => detail)
                .ToList();
                proStockInfoDetails = proStockInfoDetails.OrderBy(x => x.DateCode).ThenBy(x => x.CreateDate).ToList();
                List<int> stockIds = proStockInfoDetails.Select(x => x.ProStockId).Distinct().ToList();
                //获取所有平库主表
                List<Dt_ProStockInfo> proStockInfos = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => stockIds.Contains(x.Id)).Includes(x => x.proStockInfoDetails).ToList();
                List<Dt_ProStockInfo> delProStockInfos = new List<Dt_ProStockInfo>();
                List<Dt_ProStockInfoDetail> delStockInfoDetails = new List<Dt_ProStockInfoDetail>();
                foreach (var item in outProStocks)
                {
                    //获取库存
                    List<Dt_ProStockInfoDetail> outStocks = proStockInfoDetails.Where(x=>x.ProductCode==item.Partnum).ToList();
                    if (outStocks.Count==0 || outStocks==null)
                    {
                        return content.Error($"{item.Partnum}产品型号库存不存在");
                    }
                    foreach (var itemOut in outStocks)
                    foreach (var itemOut in proStockInfoDetails.Where(x => x.ProductCode == item.Partnum).ToList())
                    {
                        if (item.Quantity==0)
                        {
@@ -810,7 +806,17 @@
                            proOutOrderDetail.OverQtyPcs += item.Quantity;
                            item.Quantity -= item.Quantity;
                            float Range = itemOut.StockPcsQty / itemOut.SETQty;
                            itemOut.SETQty = item.Quantity / Range;
                            if (Range == 0)
                            {
                                return content.Error($"{itemOut.BagNo}单元数量转换失败,请检查");
                            }
                            int outSet = (int)(item.Quantity / Range);
                            if (outSet == 0)
                            {
                                return content.Error($"{itemOut.BagNo}单元数量转换失败,请检查");
                            }
                            itemOut.SETQty -= outSet;
                            itemOut.StockPcsQty -= item.Quantity;
                            if (proOutOrderDetail.OverQtyPcs > proOutOrderDetail.QtyPcs)
                            {
@@ -826,6 +832,10 @@
                            }
                        }
                    }
                    if (item.Quantity>0)
                    {
                        return content.Error($"未找到{item.SoNumber}可扣减库存");
                    }
                }
                if (proOutOrder.Details.Count == proOutOrder.Details.Where(x => x.ProOrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count())
                {
@@ -836,12 +846,22 @@
                    Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.ProOrderDetailStatus <= OrderDetailStatusEnum.Over.ObjToInt());
                    return content.Error($"{proOutOrderDetail?.SaleOrder}销售订单数量需出{proOutOrderDetail?.QtyPcs},可出{proOutOrderDetail?.OverQtyPcs}");
                }
                //获取删除的库存主表
                List<int> delStockIds = delStockInfoDetails.Select(x => x.ProStockId).Distinct().ToList();
                List<int> delStockDetailIds = delStockInfoDetails.Select(x => x.Id).ToList();
                foreach (var item in delStockIds)
                {
                    Dt_ProStockInfo proStockInfo = proStockInfos.FirstOrDefault(x => x.Id == item);
                    Dt_ProStockInfoDetail? proStockInfoDetail = proStockInfo.proStockInfoDetails.FirstOrDefault(x => !delStockDetailIds.Contains(x.Id));
                    if (proStockInfoDetail == null)
                    {
                        delProStockInfos.Add(proStockInfo);
                    }
                }
                //更新数据
                _unitOfWorkManage.BeginTran();
                if (delStockInfoDetails.Count > 0)
                {
                    _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delStockInfoDetails, OperateTypeEnum.自动删除);
                }
                _stockRepository.ProStockInfoRepository.DeleteAndMoveIntoHty(delProStockInfos, OperateTypeEnum.自动完成);
                _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfoDetails);
                BaseDal.UpdateData(proOutOrder);
                _outboundRepository.ProOutOrderDetailRepository.UpdateData(proOutOrder.Details);