yanjinhui
10 小时以前 07b532a6a6adf0a9d965b037cf98c1f98accd138
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs
@@ -633,6 +633,340 @@
        #endregion
        #region åˆ›å»ºç›˜äºå‡ºåº“单
        //public WebResponseContent CreateCheckOutOrder(UpstramOutOrderInfo order)
        //{
        //    WebResponseContent content = new WebResponseContent();
        //    try
        //    {
        //        string WareCodeMJ = WarehouseEnum.麻精库.ObjToInt().ToString("000");
        //        string WareCodeLD = WarehouseEnum.冷冻库.ObjToInt().ToString("000");
        //        List<Dt_SupplyTask_Hty> supplyTask_Hties = new List<Dt_SupplyTask_Hty>();
        //        List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>();
        //        List<Dt_InventoryInfo> infosUp = new List<Dt_InventoryInfo>();
        //        var codes = order.details.Select(x => x.goods_no).ToList();
        //        #region ç‰¹æ®Šåº“房
        //        if (order.warehouse_no == WareCodeMJ || order.warehouse_no == WareCodeLD)
        //        {
        //            List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
        //            List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
        //            #region åº“存、库存批次平账
        //            foreach (var item in order.details)
        //            {
        //                //找库存批次信息
        //                Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
        //                var Qty = Math.Abs(inventory_Batch.SupplyQuantity);
        //                if (Qty != item.order_qty)
        //                {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "ERP报损出库错误", $"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
        //                    throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
        //                }
        //                    //找所有库存
        //                    List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
        //                foreach (var inventoryInfo in inventoryInfos)
        //                {
        //                    #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
        //                    if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
        //                    {
        //                        Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
        //                        {
        //                            WarehouseCode = inventoryInfo.WarehouseCode,
        //                            OperateType = OperateTypeEnum.自动完成.ToString(),
        //                            InsertTime = DateTime.Now,
        //                            TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(),
        //                            BatchNo = inventoryInfo.BatchNo,
        //                            MaterielName = inventoryInfo.MaterielName,
        //                            MaterielCode = inventoryInfo.MaterielCode,
        //                            MaterielSpec = inventoryInfo.MaterielSpec,
        //                            TaskType = TaskTypeEnum.ChenckOut.ObjToInt(),
        //                            CreateDate = DateTime.Now,
        //                            Creater = App.User.UserName,
        //                            LocationCode = inventoryInfo.LocationCode,
        //                            OrderNo = order.order_no,
        //                            StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity),
        //                            SupplyQuantity = 0,
        //                            Remark = "盘亏入库"
        //                        };
        //                        //_supplyTaskHtyService.AddData(supplyTask_Hty);
        //                        supplyTask_Hties.Add(supplyTask_Hty);
        //                    }
        //                    #endregion
        //                    inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
        //                    inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
        //                    inventoryInfo.SupplyQuantity = 0;
        //                    inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
        //                    // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
        //                }
        //                inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
        //                inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
        //                inventory_Batch.SupplyQuantity = 0;
        //                infosUp.AddRange(inventoryInfos);
        //                batchesUp.Add(inventory_Batch);
        //                // æ£€æŸ¥æ‰¹æ¬¡åº“存是否为0,如果是则标记为删除
        //                //_inventoryInfoService.UpdateData(inventoryInfos);
        //                //_inventory_BatchServices.UpdateData(inventory_Batch);
        //            }
        //            #endregion
        //            #region åˆ›å»ºç›˜ç‚¹å•
        //            var entityOrder = new Dt_DeliveryOrder
        //            {
        //                Out_no = order.order_no,
        //                Out_type = order.order_type,
        //                Client_no = order.client_no,
        //                Client_name = order.client_name,
        //                OutStatus = "已完成",
        //                Account_time = order.account_time,
        //                Warehouse_no = order.warehouse_no,
        //                Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                {
        //                    Goods_no = d.goods_no,
        //                    Order_qty = Math.Abs(d.order_qty),
        //                    Order_Outqty = Math.Abs(d.order_qty),
        //                    Batch_num = d.batch_num,
        //                    Exp_date = d.exp_date,
        //                    Reservoirarea = order.warehouse_no,
        //                    OotDetailStatus = "已完成",
        //                    Status = 2,
        //                }).ToList()
        //            };
        //            _unitOfWorkManage.BeginTran();
        //            _supplyTaskHtyService.AddData(supplyTask_Hties);
        //            _inventoryInfoService.UpdateData(infosUp);
        //            _inventory_BatchServices.UpdateData(batchesUp);
        //            //BaseDal.Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //            _unitOfWorkManage.CommitTran();
        //            #endregion
        //        }
        //        #endregion
        //        else
        //        {
        //            List<Dt_DeliveryOrder> deliveryOrdersAdd = new List<Dt_DeliveryOrder>();
        //            string WareCodeLK = WarehouseEnum.立库.ObjToInt().ToString("000");
        //            string WareCodeDJ = WarehouseEnum.大件库.ObjToInt().ToString("000");
        //            List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode));
        //            List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode));
        //            foreach (var item in order.details)
        //            {
        //                //找库存批次信息
        //                Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
        //                var Qty = Math.Abs(inventory_Batch.SupplyQuantity);
        //                if (Qty != item.order_qty)
        //                {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "ERP报损出库错误", $"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
        //                    throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
        //                }
        //                //找所有库存
        //                List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
        //                //获取立库盘点差异数
        //                var inventoryLK = inventoryInfos.Where(x => x.WarehouseCode == WareCodeLK).First();
        //                //var LkQty = Math.Abs(inventoryLK.SupplyQuantity);
        //                var LkQty = inventoryLK.SupplyQuantity;
        //                //获取大件库盘点差异数
        //                var inventoryDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
        //                //var DJQty = Math.Abs(inventoryDJ.Sum(x => x.SupplyQuantity));
        //                var DJQty = inventoryDJ.Sum(x => x.SupplyQuantity);
        //                var count = Math.Abs(LkQty + DJQty);
        //                if (count != Qty) {
        //                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "ERP报损出库错误", $"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
        //                    throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘亏数量不符");
        //                }
        //                if (LkQty == 0)//立库无盘点差异,只有大件库有差异
        //                {
        //                    #region åº“存、库存批次平账
        //                    foreach (var inventoryInfo in inventoryInfos)
        //                    {
        //                        #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
        //                        if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
        //                        {
        //                            Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
        //                            {
        //                                WarehouseCode = inventoryInfo.WarehouseCode,
        //                                OperateType = OperateTypeEnum.自动完成.ToString(),
        //                                InsertTime = DateTime.Now,
        //                                TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(),
        //                                BatchNo = inventoryInfo.BatchNo,
        //                                MaterielName = inventoryInfo.MaterielName,
        //                                MaterielCode = inventoryInfo.MaterielCode,
        //                                MaterielSpec = inventoryInfo.MaterielSpec,
        //                                TaskType = TaskTypeEnum.ChenckOut.ObjToInt(),
        //                                CreateDate = DateTime.Now,
        //                                Creater = App.User.UserName,
        //                                LocationCode = inventoryInfo.LocationCode,
        //                                OrderNo = order.order_no,
        //                                StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity),
        //                                SupplyQuantity = 0,
        //                                Remark = "盘亏入库"
        //                            };
        //                            //_supplyTaskHtyService.AddData(supplyTask_Hty);
        //                            supplyTask_Hties.Add(supplyTask_Hty);
        //                        }
        //                        #endregion
        //                        // æ›´æ–°åº“存信息
        //                        inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
        //                        inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
        //                        inventoryInfo.SupplyQuantity = 0;
        //                        inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
        //                        // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
        //                    }
        //                    //更新批次信息
        //                    //_inventoryInfoService.UpdateData(inventoryInfos);
        //                    inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
        //                    inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
        //                    inventory_Batch.SupplyQuantity = 0;
        //                    //_inventory_BatchServices.UpdateData(inventory_Batch);
        //                    infosUp.AddRange(inventoryInfos);
        //                    batchesUp.Add(inventory_Batch);
        //                    #endregion
        //                    #region åˆ›å»ºå¤§ä»¶åº“盘点单
        //                    var entityOrder = new Dt_DeliveryOrder
        //                    {
        //                        Out_no = order.order_no,
        //                        Out_type = order.order_type,
        //                        Client_no = order.client_no,
        //                        Account_time = order.account_time,
        //                        OutStatus = "已完成",
        //                        Client_name = order.client_name,
        //                        Warehouse_no = WareCodeDJ,
        //                        Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                        {
        //                            Goods_no = d.goods_no,
        //                            Order_qty = Math.Abs(d.order_qty),
        //                            Order_Outqty = Math.Abs(d.order_qty),
        //                            Batch_num = d.batch_num,
        //                            Exp_date = d.exp_date,
        //                            Reservoirarea = WareCodeDJ,
        //                            OotDetailStatus = "已完成",
        //                            Status = 2,
        //                        }).ToList()
        //                    };
        //                    //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //                    //Repository.AddData(entityOrder);
        //                    deliveryOrdersAdd.Add(entityOrder);
        //                    #endregion
        //                }
        //                else //立库有盘点差异(需要出库),大件库可能有或没有差异
        //                {
        //                    #region å¤§ä»¶åº“库存平账
        //                    inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
        //                    foreach (var inventoryInfo in inventoryInfos)
        //                    {
        //                        #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
        //                        if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
        //                        {
        //                            Dt_SupplyTask_Hty supplyTask_Hty = new Dt_SupplyTask_Hty()
        //                            {
        //                                WarehouseCode = inventoryInfo.WarehouseCode,
        //                                OperateType = OperateTypeEnum.自动完成.ToString(),
        //                                InsertTime = DateTime.Now,
        //                                TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(),
        //                                BatchNo = inventoryInfo.BatchNo,
        //                                MaterielName = inventoryInfo.MaterielName,
        //                                MaterielCode = inventoryInfo.MaterielCode,
        //                                MaterielSpec = inventoryInfo.MaterielSpec,
        //                                TaskType = TaskTypeEnum.ChenckOut.ObjToInt(),
        //                                CreateDate = DateTime.Now,
        //                                Creater = App.User.UserName,
        //                                LocationCode = inventoryInfo.LocationCode,
        //                                OrderNo = order.order_no,
        //                                StockQuantity = Math.Abs(inventoryInfo.SupplyQuantity),
        //                                SupplyQuantity = 0,
        //                                Remark = "盘亏出库"
        //                            };
        //                            //_supplyTaskHtyService.AddData(supplyTask_Hty);
        //                            supplyTask_Hties.Add(supplyTask_Hty);
        //                        }
        //                        #endregion
        //                        inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
        //                        inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
        //                        inventoryInfo.SupplyQuantity = 0;
        //                        inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
        //                    }
        //                    //_inventoryInfoService.UpdateData(inventoryInfos);
        //                    infosUp.AddRange(inventoryInfos);
        //                    #endregion
        //                    #region åˆ›å»ºå¤§ä»¶åº“盘点单
        //                    if (DJQty != 0)
        //                    {
        //                        var cabinOrder = new Dt_DeliveryOrder
        //                        {
        //                            Out_no = order.order_no,
        //                            Out_type = order.order_type,
        //                            Client_name = order.client_name,
        //                            Account_time = order.account_time,
        //                            OutStatus = "已完成",
        //                            Client_no = order.client_no,
        //                            Warehouse_no = WareCodeDJ,
        //                            Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                            {
        //                                Goods_no = d.goods_no,
        //                                Order_qty = DJQty,
        //                                Order_Outqty = DJQty,
        //                                Batch_num = d.batch_num,
        //                                Exp_date = d.exp_date,
        //                                Reservoirarea = WareCodeDJ,
        //                                OotDetailStatus = "已完成",
        //                                Status = 2,
        //                            }).ToList()
        //                        };
        //                        //Repository.AddData(cabinOrder);
        //                        //Db.InsertNav(cabinOrder).Include(it => it.Details).ExecuteCommand();
        //                        deliveryOrdersAdd.Add(cabinOrder);
        //                    }
        //                    #endregion
        //                    //这里
        //                    #region åˆ›å»ºç«‹åº“盘点单
        //                    var entityOrder = new Dt_DeliveryOrder
        //                    {
        //                        Out_no = order.order_no,
        //                        Out_type = order.order_type,
        //                        Client_no = order.client_no,
        //                        Account_time = order.account_time,
        //                        OutStatus = "新建",
        //                        Client_name = order.client_name,
        //                        Warehouse_no = WareCodeLK,
        //                        Details = order.details.Select(d => new Dt_DeliveryOrderDetail
        //                        {
        //                            Goods_no = d.goods_no,
        //                            Order_qty = Math.Abs(LkQty), //给下游WCS的是要整数
        //                            Batch_num = d.batch_num,
        //                            Exp_date = d.exp_date,
        //                            Reservoirarea = WareCodeLK,
        //                            OotDetailStatus = "新建",
        //                            Status = 0,
        //                        }).ToList()
        //                    };
        //                    //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
        //                    //Repository.AddData(entityOrder);
        //                    deliveryOrdersAdd.Add(entityOrder);
        //                    #endregion
        //                }
        //                //return WebResponseContent.Instance.OK("成功");
        //            }
        //            _unitOfWorkManage.BeginTran();
        //            _supplyTaskHtyService.AddData(supplyTask_Hties);
        //            _inventoryInfoService.UpdateData(infosUp);
        //            _inventory_BatchServices.UpdateData(batchesUp);
        //            BaseDal.Db.InsertNav(deliveryOrdersAdd).Include(it => it.Details).ExecuteCommand();
        //            _unitOfWorkManage.CommitTran();
        //        }
        //        return WebResponseContent.Instance.OK("成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        _unitOfWorkManage.RollbackTran();
        //        content.Error(ex.Message);
        //    }
        //    return content;
        //}
        #endregion
        #region åˆ›å»ºç›˜äºå‡ºåº“单 ï¼ˆæ·»åŠ åˆ é™¤åº“å­˜ä¸º0的情况)
        public WebResponseContent CreateCheckOutOrder(UpstramOutOrderInfo order)
        {
            WebResponseContent content = new WebResponseContent();
@@ -642,20 +976,29 @@
                string WareCodeLD = WarehouseEnum.冷冻库.ObjToInt().ToString("000");
                List<Dt_SupplyTask_Hty> supplyTask_Hties = new List<Dt_SupplyTask_Hty>();
                List<Dt_Inventory_Batch> batchesUp = new List<Dt_Inventory_Batch>();
                List<Dt_Inventory_Batch> batchesDel = new List<Dt_Inventory_Batch>();//删除
                List<Dt_InventoryInfo> infosUp = new List<Dt_InventoryInfo>();
                List<Dt_InventoryInfo> infosDel = new List<Dt_InventoryInfo>();//删除
                var codes = order.details.Select(x => x.goods_no).ToList();
                #region ç‰¹æ®Šåº“房
                if (order.warehouse_no == WareCodeMJ || order.warehouse_no == WareCodeLD)
                {
                    List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode));
                    List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode));
                    List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
                    List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode)).ToList();
                    #region åº“存、库存批次平账
                    foreach (var item in order.details)
                    {
                        //找库存批次信息
                        Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
                        var Qty = Math.Abs(inventory_Batch.SupplyQuantity);
                        if (Qty != item.order_qty) throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                        if (Qty != item.order_qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "ERP报损出库错误", $"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                            throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                        }
                        //找所有库存
                        List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
                        foreach (var inventoryInfo in inventoryInfos)
@@ -682,22 +1025,31 @@
                                    SupplyQuantity = 0,
                                    Remark = "盘亏入库"
                                };
                                //_supplyTaskHtyService.AddData(supplyTask_Hty);
                                supplyTask_Hties.Add(supplyTask_Hty);
                            }
                            #endregion
                            inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                            inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                            inventoryInfo.SupplyQuantity = 0;
                            inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                            // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                            if (inventoryInfo.StockQuantity <= 0)
                                infosDel.Add(inventoryInfo);
                            else
                                infosUp.Add(inventoryInfo);
                        }
                        inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                        inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                        inventory_Batch.SupplyQuantity = 0;
                        infosUp.AddRange(inventoryInfos);
                        batchesUp.Add(inventory_Batch);
                        //_inventoryInfoService.UpdateData(inventoryInfos);
                        //_inventory_BatchServices.UpdateData(inventory_Batch);
                        // æ£€æŸ¥æ‰¹æ¬¡åº“存是否为0,如果是则标记为删除
                        if (inventory_Batch.StockQuantity <= 0)
                            batchesDel.Add(inventory_Batch);
                        else
                            batchesUp.Add(inventory_Batch);
                    }
                    #endregion
@@ -723,10 +1075,19 @@
                            Status = 2,
                        }).ToList()
                    };
                    _unitOfWorkManage.BeginTran();
                    _supplyTaskHtyService.AddData(supplyTask_Hties);
                    _inventoryInfoService.UpdateData(infosUp);
                    _inventory_BatchServices.UpdateData(batchesUp);
                    if (infosUp.Any())
                        _inventoryInfoService.UpdateData(infosUp);
                    if (infosDel.Any())
                        _inventoryInfoService.DeleteData(infosDel);
                    if (batchesUp.Any())
                        _inventory_BatchServices.UpdateData(batchesUp);
                    if (batchesDel.Any())
                        _inventory_BatchServices.DeleteData(batchesDel);
                    BaseDal.Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                    #endregion
@@ -739,25 +1100,35 @@
                    string WareCodeDJ = WarehouseEnum.大件库.ObjToInt().ToString("000");
                    List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => codes.Contains(x.MaterielCode));
                    List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoService.Repository.QueryData(x => codes.Contains(x.MaterielCode));
                    foreach (var item in order.details)
                    {
                        //找库存批次信息
                        Dt_Inventory_Batch inventory_Batch = inventory_Batchs.Where(x => x.MaterielCode == item.goods_no && x.BatchNo == item.batch_num).First();
                        var Qty = Math.Abs(inventory_Batch.SupplyQuantity);
                        if (Qty != item.order_qty) throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                        if (Qty != item.order_qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "ERP报损出库错误", $"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                            throw new Exception($"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                        }
                        //找所有库存
                        List<Dt_InventoryInfo> inventoryInfos = _InventoryInfos.Where(x => x.MaterielCode == inventory_Batch.MaterielCode && x.BatchNo == inventory_Batch.BatchNo).ToList();
                        //获取立库盘点差异数.。。。。。。。。。。。。
                        //获取立库盘点差异数
                        var inventoryLK = inventoryInfos.Where(x => x.WarehouseCode == WareCodeLK).First();
                        //var LkQty = Math.Abs(inventoryLK.SupplyQuantity);
                        var LkQty = inventoryLK.SupplyQuantity;
                        //获取大件库盘点差异数
                        var inventoryDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
                        //var DJQty = Math.Abs(inventoryDJ.Sum(x => x.SupplyQuantity));
                        var DJQty = inventoryDJ.Sum(x => x.SupplyQuantity);
                        var count = Math.Abs(LkQty + DJQty);
                        if (count != Qty) throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘亏数量不符");
                        if (LkQty == 0)//立库无差异
                        if (count != Qty)
                        {
                            _messageInfoService.AddMessageInfo(MessageGroupByEnum.OutOrderAlarm, "ERP报损出库错误", $"盘亏出库单【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的盘亏数量有误");
                            throw new Exception($"【{order.order_no}】物料编号【{item.goods_no}】物料批次【{item.batch_num}】的物料信息与物料批次信息盘亏数量不符");
                        }
                        if (LkQty == 0)//立库无盘点差异,只有大件库有差异
                        {
                            #region åº“存、库存批次平账
                            foreach (var inventoryInfo in inventoryInfos)
@@ -784,22 +1155,33 @@
                                        SupplyQuantity = 0,
                                        Remark = "盘亏入库"
                                    };
                                    //_supplyTaskHtyService.AddData(supplyTask_Hty);
                                    supplyTask_Hties.Add(supplyTask_Hty);
                                }
                                #endregion
                                // æ›´æ–°åº“存信息
                                inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                                inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                                inventoryInfo.SupplyQuantity = 0;
                                inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                                // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                                if (inventoryInfo.StockQuantity <= 0)
                                    infosDel.Add(inventoryInfo);
                                else
                                    infosUp.Add(inventoryInfo);
                            }
                            //_inventoryInfoService.UpdateData(inventoryInfos);
                            //更新批次信息
                            inventory_Batch.StockQuantity += inventory_Batch.SupplyQuantity;
                            inventory_Batch.AvailableQuantity = inventory_Batch.StockQuantity;
                            inventory_Batch.SupplyQuantity = 0;
                            //_inventory_BatchServices.UpdateData(inventory_Batch);
                            infosUp.AddRange(inventoryInfos);
                            batchesUp.Add(inventory_Batch);
                            // æ£€æŸ¥æ‰¹æ¬¡åº“存是否为0,如果是则标记为删除
                            if (inventory_Batch.StockQuantity <= 0)
                                batchesDel.Add(inventory_Batch);
                            else
                                batchesUp.Add(inventory_Batch);
                            #endregion
                            #region åˆ›å»ºå¤§ä»¶åº“盘点单
@@ -824,16 +1206,14 @@
                                    Status = 2,
                                }).ToList()
                            };
                            //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                            //Repository.AddData(entityOrder);
                            deliveryOrdersAdd.Add(entityOrder);
                            #endregion
                        }
                        else
                        else //立库有盘点差异(需要出库),大件库可能有或没有差异
                        {
                            #region å¤§ä»¶åº“库存平账
                            inventoryInfos = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
                            foreach (var inventoryInfo in inventoryInfos)
                            var inventoryInfosDJ = inventoryInfos.Where(x => x.WarehouseCode == WareCodeDJ).ToList();
                            foreach (var inventoryInfo in inventoryInfosDJ)
                            {
                                #region æ·»åŠ ç›˜äºå‡ºåº“ä»»åŠ¡
                                if (inventoryInfo.StockQuantity != inventoryInfo.SupplyQuantity)
@@ -857,17 +1237,21 @@
                                        SupplyQuantity = 0,
                                        Remark = "盘亏出库"
                                    };
                                    //_supplyTaskHtyService.AddData(supplyTask_Hty);
                                    supplyTask_Hties.Add(supplyTask_Hty);
                                }
                                #endregion
                                inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                                inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                                inventoryInfo.SupplyQuantity = 0;
                                inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                                // æ£€æŸ¥åº“存是否为0,如果是则标记为删除
                                if (inventoryInfo.StockQuantity <= 0)
                                    infosDel.Add(inventoryInfo);
                                else
                                    infosUp.Add(inventoryInfo);
                            }
                            //_inventoryInfoService.UpdateData(inventoryInfos);
                            infosUp.AddRange(inventoryInfos);
                            #endregion
                            #region åˆ›å»ºå¤§ä»¶åº“盘点单
@@ -894,12 +1278,10 @@
                                        Status = 2,
                                    }).ToList()
                                };
                                //Repository.AddData(cabinOrder);
                                //Db.InsertNav(cabinOrder).Include(it => it.Details).ExecuteCommand();
                                deliveryOrdersAdd.Add(cabinOrder);
                            }
                            #endregion
                            //这里
                            #region åˆ›å»ºç«‹åº“盘点单
                            var entityOrder = new Dt_DeliveryOrder
                            {
@@ -921,20 +1303,27 @@
                                    Status = 0,
                                }).ToList()
                            };
                            //Db.InsertNav(entityOrder).Include(it => it.Details).ExecuteCommand();
                            //Repository.AddData(entityOrder);
                            deliveryOrdersAdd.Add(entityOrder);
                            #endregion
                        }
                        //return WebResponseContent.Instance.OK("成功");
                    }
                    _unitOfWorkManage.BeginTran();
                    _supplyTaskHtyService.AddData(supplyTask_Hties);
                    _inventoryInfoService.UpdateData(infosUp);
                    _inventory_BatchServices.UpdateData(batchesUp);
                    if (infosUp.Any())
                        _inventoryInfoService.UpdateData(infosUp);
                    if (infosDel.Any())
                        _inventoryInfoService.DeleteData(infosDel);
                    if (batchesUp.Any())
                        _inventory_BatchServices.UpdateData(batchesUp);
                    if (batchesDel.Any())
                        _inventory_BatchServices.DeleteData(batchesDel);
                    BaseDal.Db.InsertNav(deliveryOrdersAdd).Include(it => it.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                }
                return WebResponseContent.Instance.OK("成功");
            }
            catch (Exception ex)
@@ -1029,7 +1418,12 @@
            return content;
        }
        /// <summary>
        /// å¤„理出库单、库存信息、出库任务、调拨任务
        /// </summary>
        /// <param name="supplyTask"></param>
        /// <returns></returns>
        public WebResponseContent OutTaskFinish(Dt_SupplyTask supplyTask, Dt_DeliveryOrder deliveryOrder)
        {
            WebResponseContent content = new WebResponseContent();
@@ -1063,8 +1457,7 @@
                #endregion
                #region åº“存批次 å¦‚果任务类型是调拨出库任务(8)就不修改批次库存
                Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode ==
                    inventoryInfo.MaterielCode);
                Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode ==inventoryInfo.MaterielCode);
                if (supplyTask.TaskType != TaskTypeEnum.AllocatOut.ObjToInt())
                {
                    inventory_Batch.StockQuantity -= supplyTask.StockQuantity;
@@ -1074,12 +1467,12 @@
                supplyTask.TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt();
                _unitOfWorkManage.BeginTran();
                if (inventory_Batch.StockQuantity <= 0)
                if (inventory_Batch.StockQuantity <= 0)//如果库存数量小于0就删除库存批次信息
                    _inventory_BatchServices.DeleteData(inventory_Batch);
                else
                    _inventory_BatchServices.UpdateData(inventory_Batch);
                //_materielInfoService.UpdateData(materielInfo);
                if (inventoryInfo.StockQuantity <= 0)
                if (inventoryInfo.StockQuantity <= 0)//如果库存数量小于0就删除库存信息
                    _inventoryInfoService.DeleteData(inventoryInfo);
                else
                    _inventoryInfoService.UpdateData(inventoryInfo);
@@ -1118,6 +1511,7 @@
            return content;
        }
        public WebResponseContent OutTaskFinish(Dt_SupplyTask supplyTask)
        {
            WebResponseContent content = new WebResponseContent();