dengjunjie
6 天以前 528badf2f1efe5355975de7942fb7a26e71a8e18
н¨Îļþ¼Ð/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs
@@ -29,12 +29,15 @@
            try
            {
                List<Dt_DeliveryOrder> deliveryOrders = new List<Dt_DeliveryOrder>();
                List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
                //List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
                List<Dt_SupplyTask> supplyTasks1 = new List<Dt_SupplyTask>();
                List<Dt_InventoryInfo> _InventoryInfos = new List<Dt_InventoryInfo>();
                List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => keys.Contains(x.Id));
                foreach (var item in inventory_Batches)
                {
                    supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                    var supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                    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}】已存在盘点任务,请先完成当前盘点任务");
                    List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => item.MaterielCode == x.MaterielCode && x.BatchNo == item.BatchNo);
                    if (inventoryInfos.Count > 0)
@@ -65,8 +68,6 @@
                            deliveryOrder.Details.Add(deliveryOrderDetail);
                            deliveryOrders.Add(deliveryOrder);
                            #region åˆ›å»ºç›˜ç‚¹ä»»åŠ¡
                            //if (items.Key != "001")// éžç«‹åº“区域需要创建盘点任务
                            //{
                            foreach (var inventory in items)
                            {
                                Dt_SupplyTask supplyTask = new Dt_SupplyTask()
@@ -86,7 +87,7 @@
                                    SupplyQuantity = 0,
                                    Remark = "盘点"
                                };
                                supplyTasks.Add(supplyTask);
                                supplyTasks1.Add(supplyTask);
                                _InventoryInfos.Add(inventory);
                            }
                            //}
@@ -100,7 +101,7 @@
                });
                _unitOfWorkManage.BeginTran();
                _inventoryInfoService.UpdateData(_InventoryInfos);
                _supplyTaskService.AddData(supplyTasks);
                _supplyTaskService.AddData(supplyTasks1);
                BaseDal.Db.InsertNav(deliveryOrders)
                        .Include(x => x.Details)
                        .ExecuteCommand();
@@ -222,27 +223,20 @@
                if (cabinOrder == null) return WebResponseContent.Instance.Error($"盘点单已完成");
                Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == supplyTask.BatchNo && x.Reservoirarea == supplyTask.WarehouseCode && x.Goods_no == supplyTask.MaterielCode).First();
                if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"盘点单明细已完成");
                Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
                Dt_MaterielInfo materielInfo = _materielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
                if (materielInfo == null) return WebResponseContent.Instance.Error($"请维护物料编号【{cabinOrderDetail.Goods_no}】的物料信息");
                cabinOrderDetail.Order_Outqty += supplyTask.SupplyQuantity;
                #region å¹³åº“盘点只能出现整箱差异
                if (supplyTask.WarehouseCode == WarehouseEnum.大件库.ObjToInt().ToString())
                if (supplyTask.WarehouseCode == WarehouseEnum.大件库.ObjToInt().ToString("000"))
                {
                    var Qty = supplyTask.SupplyQuantity % materielInfo.BoxQty;
                    if (Qty != 0) return WebResponseContent.Instance.Error($"大件库库存为整箱!盘点数量不能存在散件");
                }
                #endregion
                //if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
                //    return WebResponseContent.Instance.Error($"实盘数量不可超出账面数量");
                #region å¤„理出库单,货位,库存,库存批次信息
                _unitOfWorkManage.BeginTran();
                #region ä¿®æ”¹ç›˜ç‚¹å•
                cabinOrder.OutStatus = "开始";
                cabinOrderDetail.OotDetailStatus = "开始";
                Repository.UpdateData(cabinOrder);
                _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                #endregion
                #region åº“å­˜
@@ -257,38 +251,23 @@
                    inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode);
                }
                inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity;
                _inventoryInfoService.UpdateData(inventoryInfo);
                #endregion
                #region ä»»åŠ¡è®°å½•
                //_supplyTaskService.UpdateData(supplyTask);
                _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.自动完成);
                #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).ToList();
                if (supplyTasks.Count < 1)
                {
                    #region å®Œæˆç›˜ç‚¹å•
                    cabinOrder.OutStatus = "已完成";
                    cabinOrder.Details.ForEach(x =>
                    {
                        x.OotDetailStatus = "已完成";
                    });
                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.自动完成);
                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrder.Details, OperateTypeEnum.自动完成);
                    #endregion
                }
                supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                if (supplyTasks.Count < 1)
                List<Dt_SupplyTask> supplyTasks1 = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
                Dt_Inventory_Batch inventory_Batch = new Dt_Inventory_Batch();
                List<Dt_InventoryInfo> inventoryInfos = new List<Dt_InventoryInfo>();
                if (supplyTasks1.Count < 1)
                {
                    #region æŸ¥æ‰¾åº“å­˜
                    var inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                    var SupplyQuantitys = inventoryInfos.Select(x => x.SupplyQuantity).ToList().Sum();
                    inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                    var SupplyQuantitys = inventoryInfos.Sum(x => x.SupplyQuantity);
                    #endregion
                    #region åº“存批次
                    Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                    inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
                    //如果盘点数和批次总数对上了,盘点数赋值为0,赋值就添加盘点数
                    if (SupplyQuantitys == inventory_Batch.StockQuantity)
                    {
                        foreach (var item in inventoryInfos)
@@ -297,20 +276,45 @@
                            item.SupplyQuantity = 0;
                            item.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                        }
                        _inventoryInfoService.UpdateData(inventoryInfos);
                    }
                    else
                    {
                        inventory_Batch.SupplyQuantity = SupplyQuantitys;
                        _inventory_BatchServices.UpdateData(inventory_Batch);
                    }
                    #endregion
                }
                _unitOfWorkManage.BeginTran();
                #region å¤„理盘点单
                if (supplyTasks.Count < 1)
                {
                    #region å®Œæˆç›˜ç‚¹å•
                    cabinOrder.OutStatus = "已完成";
                    cabinOrder.Details.ForEach(x =>
                    {
                        x.OotDetailStatus = "已完成";
                    });
                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrder.Details, OperateTypeEnum.自动完成);
                    cabinOrder.Details = null;
                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.自动完成);
                    #endregion
                }
                else
                {
                    Repository.UpdateData(cabinOrder);
                    _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                }
                #endregion
                _inventoryInfoService.UpdateData(inventoryInfo);
                _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.自动完成);
                if (inventoryInfos.Count > 1)
                {
                    _inventoryInfoService.UpdateData(inventoryInfos);
                    _inventory_BatchServices.UpdateData(inventory_Batch);
                }
                _unitOfWorkManage.CommitTran();
                #endregion
                content.OK();
                #endregion
            }
            catch (Exception ex)
            {