yanjinhui
10 小时以前 07b532a6a6adf0a9d965b037cf98c1f98accd138
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/LKBusiness/DeliveryOrderServicesLK.cs
@@ -11,6 +11,8 @@
using WIDESEA_Core.Enums;
using WIDESEA_ISquareCabinServices;
using WIDESEA_Core.Helper;
using WIDESEA_Common;
using static WIDESEA_DTO.SquareCabin.OrderDto;
namespace WIDESEA_SquareCabinServices
{
@@ -25,6 +27,8 @@
                List<Dt_SupplyTask_Hty> supplyTask_Hties = new List<Dt_SupplyTask_Hty>();
                List<Dt_InventoryInfo> infosUp = new List<Dt_InventoryInfo>();
                List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>();
                List<Dt_InventoryInfo> infosDel = new List<Dt_InventoryInfo>();//添加删除
                List<Dt_Inventory_Batch> batchesDel = new List<Dt_Inventory_Batch>();
                List<Dt_MaterielInfo> materielInfos = _materielInfoService.Repository.QueryData(x => deliveryOrder.Details.Select(x => x.Goods_no).ToList().Contains(x.MaterielCode));
                List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => deliveryOrder.Warehouse_no == x.WarehouseCode && deliveryOrder.Details.Select(x => x.Goods_no).ToList().Contains(x.MaterielCode));
                List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => deliveryOrder.Details.Select(x => x.Goods_no).ToList().Contains(x.MaterielCode));
@@ -37,11 +41,20 @@
                        foreach (var detail in request.details)
                        {
                            Dt_DeliveryOrderDetail? orderDetail = deliveryOrder.Details.FirstOrDefault(x => x.Goods_no == detail.productCode && x.Batch_num == detail.batchNo);
                            if (orderDetail == null) throw new Exception($"未找到盘点单【{deliveryOrder.Out_no}】物料编号【{detail.productCode}】物料批次【{detail.batchNo}】的明细信息");
                            if (orderDetail == null)
                            {
                                _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "盘亏出库单", $"未找到盘点单【{deliveryOrder.Out_no}】物料编号【{detail.productCode}】物料批次【{detail.batchNo}】的明细信息");
                                throw new Exception($"未找到盘点单【{deliveryOrder.Out_no}】物料编号【{detail.productCode}】物料批次【{detail.batchNo}】的明细信息");
                            }
                            decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0) ?? 0;
                            Dt_InventoryInfo inventoryInfo = inventoryInfos.Where(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo).First();
                            if (orderQty != Math.Abs(inventoryInfo.SupplyQuantity))
                            {
                                _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "盘亏出库单", $"盘亏出库数量不一致,上传数量【{orderQty}】,库存盘亏数量【{Math.Abs(inventoryInfo.SupplyQuantity)}】");
                                throw new Exception($"盘亏出库数量不一致,上传数量【{orderQty}】,库存盘亏数量【{Math.Abs(inventoryInfo.SupplyQuantity)}】");
                            }
                            //添加物料信息中的立库业务库存信息
                            var mater = materielInfos.FirstOrDefault(x => x.MaterielCode == detail.productCode);
                            if (mater != null)
@@ -53,13 +66,24 @@
                            inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                            inventoryInfo.SupplyQuantity = 0;
                            inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                            infosUp.Add(inventoryInfo);
                            // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                            if (inventoryInfo.StockQuantity <= 0)
                                infosDel.Add(inventoryInfo);
                            else
                                infosUp.Add(inventoryInfo);
                            //infosUp.Add(inventoryInfo);
                            //库存批次
                            Dt_Inventory_Batch inventory_Batch = inventory_Batches.First(x => x.MaterielCode == inventoryInfo.MaterielCode && x.BatchNo == inventoryInfo.BatchNo);
                            inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                            inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                            inventory_Batch.SupplyQuantity = 0;
                            batchesUp.Add(inventory_Batch);
                            orderDetail.OotDetailStatus = "已完成";
                            orderDetail.Order_Outqty = orderQty; //完成数量
                            if (inventory_Batch.StockQuantity<=0)
                                batchesDel.Add(inventory_Batch);
                            else
                                batchesUp.Add(inventory_Batch);
                            cabinOrderDetailsUp.Add(orderDetail);
                            #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
                            Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
@@ -85,6 +109,7 @@
                            #endregion
                        }
                        deliveryOrder.OutStatus = "已完成";
                        //从所有出库明细中,筛选出那些不在已完成列表中的明细项
                        if (deliveryOrder.Details.Where(x => !cabinOrderDetailsUp.Select(x => x.Id).Contains(x.Id)).Any())
                            deliveryOrder.OutStatus = "开始";
                        _unitOfWorkManage.BeginTran();
@@ -111,9 +136,17 @@
                    {
                        decimal orderQty = detail.orderDetails?.Sum(x => decimal.TryParse(x.quantity, out var q) ? Math.Abs(q) : 0) ?? 0;
                        Dt_SupplyTask? supplyTask = supplyTasks.FirstOrDefault(x => x.MaterielCode == detail.productCode && x.BatchNo == detail.batchNo);
                        if (supplyTask == null) throw new Exception($"未找到订单号【{request.externalOrderNo}】物料编号【{detail.productCode}】的出库任务");
                        if (supplyTask == null)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "出库单", $"未找到订单号【{request.externalOrderNo}】物料编号【{detail.productCode}】的出库任务");
                            throw new Exception($"未找到订单号【{request.externalOrderNo}】物料编号【{detail.productCode}】的出库任务");
                        }
                        if (supplyTask.StockQuantity != orderQty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "出库单", $"订单号【{request.orderNo}】物料编号【{detail.productCode}】的出库数量与出库任务数量不相等");
                            throw new Exception($"订单号【{request.orderNo}】物料编号【{detail.productCode}】的出库数量与出库任务数量不相等");
                        }
                        //处理出库单、库存信息、出库任务、调拨任务
                        content = OutTaskFinish(supplyTask, deliveryOrder);
                        if (!content.Status) throw new Exception(content.Message);
                    }