dengjunjie
3 天以前 d2a1ccd801f942381723c5a6001989d8da8ba6f5
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
@@ -36,6 +37,7 @@
                foreach (var item in inventory_Batches)
                {
                    var supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                    if (item.SupplyQuantity != 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在盘点差异!");
                    if (supplyTasks.Count > 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在盘点任务,请先完成当前盘点任务");
                    supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt()).ToList();
                    if (supplyTasks.Count > 0) throw new Exception($"物料编号【{item.MaterielCode}】批次号【{item.BatchNo}】已存在出库任务,请先完成当前出库任务");
@@ -234,7 +236,7 @@
                if (materielInfo == null) return WebResponseContent.Instance.Error($"请维护物料编号【{cabinOrderDetail.Goods_no}】的物料信息");
                cabinOrderDetail.Order_Outqty += supplyTask.SupplyQuantity;
                #region å¹³åº“盘点只能出现整箱差异
                if (supplyTask.WarehouseCode == WarehouseEnum.大件库.ObjToInt().ToString("000"))
                if (supplyTask.WarehouseCode == WarehouseEnum.大件库.ObjToInt().ToString("000") && materielInfo.MaterielSourceType != MaterielSourceTypeEnum.PurchasePart)
                {
                    var Qty = supplyTask.SupplyQuantity % materielInfo.BoxQty;
                    if (Qty != 0) return WebResponseContent.Instance.Error($"大件库库存为整箱!盘点数量不能存在散件");
@@ -247,45 +249,85 @@
                #endregion
                #region åº“å­˜
                Dt_InventoryInfo inventoryInfo = new Dt_InventoryInfo();
                List<Dt_Inventory_Batch> inventory_Batchs = _inventory_BatchServices.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode));
                List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => cabinOrder.Details.Select(x => x.Goods_no).Contains(x.MaterielCode) && x.WarehouseCode == supplyTask.WarehouseCode && x.StockStatus == StockStatusEmun.盘点锁定.ObjToInt());
                Dt_InventoryInfo? inventoryInfo = new();
                List<Dt_InventoryInfo> inventoryInfosDel = new List<Dt_InventoryInfo>();
                if (supplyTask.WarehouseCode != WarehouseEnum.立库.ObjToInt().ToString("000"))
                {
                    inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode && x.LocationCode == supplyTask.LocationCode);
                    inventoryInfo = inventoryInfos.FirstOrDefault(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == supplyTask.LocationCode);
                    if (inventoryInfo == null) return WebResponseContent.Instance.Error($"未找到货位【{LocationCode}】的库存信息");
                }
                else
                {
                    inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode);
                    inventoryInfo = inventoryInfos.FirstOrDefault(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                }
                if (inventoryInfo == null) return WebResponseContent.Instance.Error($"未找到立库的库存信息");
                inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity - inventoryInfo.StockQuantity;
                #endregion
                #region åˆ¤æ–­å½“前物料批次的盘点任务是否全部完成
                List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.WarehouseCode == supplyTask.WarehouseCode && x.TaskId != supplyTask.TaskId).ToList();
                List<Dt_SupplyTask> supplyTasks1 = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.TaskId != supplyTask.TaskId).ToList();
                Dt_Inventory_Batch inventory_Batch = new Dt_Inventory_Batch();
                List<Dt_InventoryInfo> inventoryInfos = new List<Dt_InventoryInfo>();
                if (supplyTasks1.Count < 1)
                List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.OrderNo == supplyTask.OrderNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.TaskId != supplyTask.TaskId).ToList();//查找当前盘点单的盘点任务
                if (!supplyTasks.Where(x => cabinOrderDetail.Goods_no == x.MaterielCode && x.BatchNo == cabinOrderDetail.Batch_num).Any())
                    cabinOrderDetail.OotDetailStatus = "已完成";
                #region åˆ¤æ–­å½“前盘点单任务是否全部完成
                if (supplyTasks.Count < 1)
                {
                    #region æŸ¥æ‰¾åº“å­˜
                    inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.Id != inventoryInfo.Id);
                    var SupplyQuantitys = inventoryInfos.Sum(x => x.SupplyQuantity) + inventoryInfo.SupplyQuantity;//计算盘点总数
                    #endregion
                    #region åº“存批次
                    inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                    #region å¤„理当前物料批次的库存和批次信息
                    Dt_Inventory_Batch inventory_Batch = inventory_Batchs.First(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode);
                    var SupplyQuantitys = inventoryInfos.Where(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode).Sum(x => x.SupplyQuantity);
                    if (SupplyQuantitys == 0)
                    {
                        foreach (var item in inventoryInfos)
                        foreach (var item in inventoryInfos.Where(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode))
                        {
                            item.StockQuantity += item.SupplyQuantity;
                            if (item.StockQuantity <= 0)
                            {
                                inventoryInfosDel.Add(item);
                                continue;
                            }
                            item.AvailableQuantity = item.StockQuantity;
                            item.SupplyQuantity = 0;
                            item.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                        }
                        inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                        inventoryInfo.SupplyQuantity = 0;
                        inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                        //inventoryInfo.StockQuantity += inventoryInfo.SupplyQuantity;
                        //if (inventoryInfo.StockQuantity <= 0)
                        //{
                        //    inventoryInfosDel.Add(inventoryInfo);
                        //    inventoryInfo = null;
                        //}
                        //else
                        //{
                        //    inventoryInfo.AvailableQuantity = inventoryInfo.StockQuantity;
                        //    inventoryInfo.SupplyQuantity = 0;
                        //    inventoryInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                        //}
                    }
                    else
                    {
                        inventory_Batch.SupplyQuantity += SupplyQuantitys;
                    }
                    #endregion
                    #region å¤„理其他库存批次和库存
                    foreach (var detail in cabinOrder.Details.Where(x => x.Id != cabinOrderDetail.Id))
                    {
                        SupplyQuantitys = inventoryInfos.Where(x => x.BatchNo == detail.Batch_num && x.MaterielCode == detail.Goods_no).Sum(x => x.SupplyQuantity);//计算盘点总数
                        inventory_Batch = inventory_Batchs.First(x => x.BatchNo == detail.Batch_num && x.MaterielCode == detail.Goods_no);
                        #region åº“存批次
                        if (SupplyQuantitys == 0)
                        {
                            foreach (var item in inventoryInfos.Where(x => x.BatchNo == detail.Batch_num && x.MaterielCode == detail.Goods_no))
                            {
                                item.StockQuantity += item.SupplyQuantity;
                                if (item.StockQuantity <= 0)
                                {
                                    inventoryInfosDel.Add(item);
                                    continue;
                                }
                                item.AvailableQuantity = item.StockQuantity;
                                item.SupplyQuantity = 0;
                                item.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                            }
                    }
                    else
                    {
@@ -293,6 +335,9 @@
                    }
                    #endregion
                }
                    #endregion
                }
                #endregion
                _unitOfWorkManage.BeginTran();
                #region å¤„理盘点单
                if (supplyTasks.Count < 1)
@@ -315,12 +360,12 @@
                    _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                }
                #endregion
                _inventoryInfoService.UpdateData(inventoryInfo);
                //_inventoryInfoService.UpdateData(inventoryInfo);
                _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.自动完成);
                _inventoryInfoService.UpdateData(inventoryInfos);
                _inventory_BatchServices.UpdateData(inventory_Batch);
                if (inventoryInfosDel.Count > 0) _inventoryInfoService.DeleteData(inventoryInfosDel);
                _inventory_BatchServices.UpdateData(inventory_Batchs);
                _unitOfWorkManage.CommitTran();
                #endregion
                content.OK();
            }
            catch (Exception ex)