| | |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | // 1. éªè¯æ¡ç æææ§ |
| | | var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(it => it.OrderNo == orderNo && |
| | | it.Status == (int)OutLockStockStatusEnum.åºåºä¸ && |
| | | it.PalletCode == palletCode && |
| | | it.CurrentBarcode == barcode) |
| | | .FirstAsync(); |
| | | |
| | | if (lockInfo == null) |
| | | throw new Exception($"æ¡ç {barcode}ä¸å±äºæç{palletCode}æä¸åå¨å¾
åæ£è®°å½"); |
| | | |
| | | |
| | | |
| | | var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>() |
| | | .Where(x => x.Barcode == barcode) |
| | | .Where(x => x.Barcode == barcode && x.StockId == lockInfo.StockId) |
| | | .FirstAsync(); |
| | | |
| | | if (stockDetail == null) |
| | | return WebResponseContent.Instance.Error("æ æçæ¡ç æç©æç¼ç "); |
| | | |
| | | //// 2. æ£æ¥åºåå¯ç¨æ°é |
| | | //var availableQty = stockDetail.StockQuantity - stockDetail.OutboundQuantity; |
| | | //if (availableQty <= 0) |
| | | // return WebResponseContent.Instance.Error("åºåæ°éä¸è¶³"); |
| | | |
| | | // 3. æ¥æ¾ç¸å
³çåºåºè¯¦æ
ä¿¡æ¯ |
| | | var outStockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.PalletCode == palletCode && |
| | | x.CurrentBarcode == barcode && |
| | | x.Status == (int)OutLockStockStatusEnum.åºåºä¸ && |
| | | x.AssignQuantity - x.PickedQty > 0) |
| | | .FirstAsync(); |
| | | decimal actualQty = lockInfo.AssignQuantity - lockInfo.PickedQty; |
| | | |
| | | // 4. æ´æ°åºå |
| | | stockDetail.StockQuantity -= actualQty; |
| | | stockDetail.OutboundQuantity -= actualQty; |
| | | await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync(); |
| | | |
| | | lockInfo.PickedQty += actualQty; |
| | | lockInfo.Status = (int)OutLockStockStatusEnum.æ£é宿; |
| | | await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync(); |
| | | |
| | | |
| | | if (outStockInfo == null) |
| | | return WebResponseContent.Instance.Error("æªæ¾å°å¯¹åºçæ£éä¿¡æ¯æå·²æ£é宿"); |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(it => it.PickedQty == it.PickedQty + actualQty) |
| | | .Where(it => it.Id == lockInfo.OrderDetailId) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | // 4. æ£æ¥åºåºè¯¦æ
é宿°é |
| | | if (outStockInfo.RemainQuantity <= 0) |
| | | return WebResponseContent.Instance.Error("该æ¡ç å·²æ å©ä½å¯æ£éæ°é"); |
| | | |
| | | // 5. æ´æ°åºåºè¯¦æ
çå·²æ£éæ°é |
| | | outStockInfo.PickedQty = outStockInfo.AssignQuantity; |
| | | outStockInfo.Status = (int)OutLockStockStatusEnum.å·²æ£é; |
| | | await _outStockLockInfoService.Db.Updateable(outStockInfo).ExecuteCommandAsync(); |
| | | |
| | | //// 6. æ´æ°åºååºåºæ°é |
| | | //await _stockInfoDetailService.Db.Updateable<Dt_StockInfoDetail>() |
| | | // .SetColumns(x => x.OutboundQuantity == x.OutboundQuantity + outStockInfo.AssignQuantity) |
| | | // .Where(x => x.Id == stockDetail.Id) |
| | | // .ExecuteCommandAsync(); |
| | | |
| | | // 7. æ´æ°åºåºåæç» |
| | | var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .Where(x => x.Id == outStockInfo.OrderDetailId) |
| | | .FirstAsync(); |
| | | if (orderDetail != null) |
| | | { |
| | | orderDetail.OverOutQuantity += outStockInfo.AssignQuantity; |
| | | orderDetail.LockQuantity -= outStockInfo.AssignQuantity; |
| | | await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync(); |
| | | } |
| | | // 8. æ£æ¥æ¯å¦å®æåºåº |
| | | await CheckAndUpdateOrderStatus(orderNo); |
| | | |
| | | //æ¥è¯¢ä»»å¡è¡¨ |
| | |
| | | // 9. è®°å½æ£éåå² |
| | | var pickingHistory = new Dt_PickingRecord |
| | | { |
| | | FactoryArea = outStockInfo.FactoryArea, |
| | | FactoryArea = lockInfo.FactoryArea, |
| | | TaskNo = task?.TaskNum ?? 0, |
| | | LocationCode = task?.SourceAddress ?? "", |
| | | StockId = stockDetail.Id, |
| | | OrderNo = orderNo, |
| | | OrderDetailId = orderDetail?.Id ?? 0, |
| | | OrderDetailId = lockInfo.OrderDetailId, |
| | | PalletCode = palletCode, |
| | | Barcode = barcode, |
| | | MaterielCode = outStockInfo.MaterielCode, |
| | | PickQuantity = outStockInfo.AssignQuantity, |
| | | MaterielCode = lockInfo.MaterielCode, |
| | | PickQuantity = lockInfo.AssignQuantity, |
| | | PickTime = DateTime.Now, |
| | | Operator = App.User.UserName, |
| | | OutStockLockId = outStockInfo.Id |
| | | OutStockLockId = lockInfo.Id |
| | | }; |
| | | await Db.Insertable(pickingHistory).ExecuteCommandAsync(); |
| | | |